mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Merge branch 'master' into plugins
Conflicts: src/ui/console.c
This commit is contained in:
commit
922289d01f
1
.gitignore
vendored
1
.gitignore
vendored
@ -43,5 +43,4 @@ libtool
|
||||
m4/
|
||||
*.so
|
||||
*.lo
|
||||
plugins/
|
||||
src/gitversion.c
|
||||
|
@ -162,6 +162,6 @@ void
|
||||
api_win_show(const char *tag, const char *line)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(tag);
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
wprintw(window->win, "%s\n", line);
|
||||
}
|
||||
|
@ -220,27 +220,16 @@ prof_handle_group_remove(const char * const contact,
|
||||
void
|
||||
prof_handle_error_message(const char *from, const char *err_msg)
|
||||
{
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
if (err_msg == NULL) {
|
||||
cons_show_error("Unknown error received from service.");
|
||||
} else if (strcmp(err_msg, "conflict") == 0) {
|
||||
if (win_type == WIN_MUC) {
|
||||
ui_current_print_line("Nickname already in use.");
|
||||
} else {
|
||||
cons_show_error("Error received from server: %s", err_msg);
|
||||
}
|
||||
ui_handle_error_message(from, err_msg);
|
||||
|
||||
if (g_strcmp0(err_msg, "conflict") == 0) {
|
||||
// remove the room from muc
|
||||
Jid *room_jid = jid_create(from);
|
||||
if (!muc_get_roster_received(room_jid->barejid)) {
|
||||
muc_leave_room(room_jid->barejid);
|
||||
}
|
||||
jid_destroy(room_jid);
|
||||
|
||||
} else {
|
||||
cons_show_error("Error received from server: %s", err_msg);
|
||||
}
|
||||
|
||||
ui_print_error_from_recipient(from, err_msg);
|
||||
}
|
||||
|
||||
void
|
||||
|
158
src/ui/console.c
158
src/ui/console.c
@ -51,7 +51,7 @@ void
|
||||
cons_show_time(void)
|
||||
{
|
||||
ProfWin *console = wins_get_console();
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wins_refresh_console();
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ cons_debug(const char * const msg, ...)
|
||||
va_start(arg, msg);
|
||||
GString *fmt_msg = g_string_new(NULL);
|
||||
g_string_vprintf(fmt_msg, msg, arg);
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "%s\n", fmt_msg->str);
|
||||
g_string_free(fmt_msg, TRUE);
|
||||
va_end(arg);
|
||||
@ -93,7 +93,7 @@ cons_show(const char * const msg, ...)
|
||||
va_start(arg, msg);
|
||||
GString *fmt_msg = g_string_new(NULL);
|
||||
g_string_vprintf(fmt_msg, msg, arg);
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "%s\n", fmt_msg->str);
|
||||
g_string_free(fmt_msg, TRUE);
|
||||
va_end(arg);
|
||||
@ -108,7 +108,7 @@ cons_show_error(const char * const msg, ...)
|
||||
va_start(arg, msg);
|
||||
GString *fmt_msg = g_string_new(NULL);
|
||||
g_string_vprintf(fmt_msg, msg, arg);
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_ERROR);
|
||||
wprintw(console->win, "%s\n", fmt_msg->str);
|
||||
wattroff(console->win, COLOUR_ERROR);
|
||||
@ -131,7 +131,7 @@ cons_show_typing(const char * const barejid)
|
||||
display_usr = barejid;
|
||||
}
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_TYPING);
|
||||
wprintw(console->win, "!! %s is typing a message...\n", display_usr);
|
||||
wattroff(console->win, COLOUR_TYPING);
|
||||
@ -149,7 +149,7 @@ cons_show_incoming_message(const char * const short_from, const int win_index)
|
||||
if (ui_index == 10) {
|
||||
ui_index = 0;
|
||||
}
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_INCOMING);
|
||||
wprintw(console->win, "<< incoming from %s (%d)\n", short_from, ui_index);
|
||||
wattroff(console->win, COLOUR_INCOMING);
|
||||
@ -168,7 +168,8 @@ cons_about(void)
|
||||
if (prefs_get_boolean(PREF_SPLASH)) {
|
||||
_cons_splash_logo();
|
||||
} else {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
|
||||
|
||||
if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) {
|
||||
#ifdef PROF_HAVE_GIT_VERSION
|
||||
@ -181,21 +182,22 @@ cons_about(void)
|
||||
}
|
||||
}
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PROF_PACKAGE_BUGREPORT);
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "\n");
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "This is free software; you are free to change and redistribute it.\n");
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
|
||||
wprintw(console->win, "There is NO WARRANTY, to the extent permitted by law.\n");
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "\n");
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "Type '/help' to show complete help.\n");
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "\n");
|
||||
|
||||
if (prefs_get_boolean(PREF_VERCHECK)) {
|
||||
@ -219,12 +221,12 @@ cons_check_version(gboolean not_available_msg)
|
||||
|
||||
if (relase_valid) {
|
||||
if (release_is_new(latest_release)) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "A new version of Profanity is available: %s", latest_release);
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "Check <http://www.profanity.im> for details.\n");
|
||||
free(latest_release);
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "\n");
|
||||
} else {
|
||||
if (not_available_msg) {
|
||||
@ -243,15 +245,15 @@ void
|
||||
cons_show_login_success(ProfAccount *account)
|
||||
{
|
||||
ProfWin *console = wins_get_console();
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "%s logged in successfully, ", account->jid);
|
||||
|
||||
resource_presence_t presence = accounts_get_login_presence(account->name);
|
||||
const char *presence_str = string_from_resource_presence(presence);
|
||||
|
||||
win_presence_colour_on(console, presence_str);
|
||||
console->presence_colour_on(console, presence_str);
|
||||
wprintw(console->win, "%s", presence_str);
|
||||
win_presence_colour_off(console, presence_str);
|
||||
console->presence_colour_off(console, presence_str);
|
||||
wprintw(console->win, " (priority %d)",
|
||||
accounts_get_priority_for_presence_type(account->name, presence));
|
||||
wprintw(console->win, ".\n");
|
||||
@ -269,7 +271,7 @@ cons_show_wins(void)
|
||||
|
||||
GSList *curr = window_strings;
|
||||
while (curr != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, curr->data);
|
||||
wprintw(console->win, "\n");
|
||||
curr = g_slist_next(curr);
|
||||
@ -311,19 +313,19 @@ cons_show_info(PContact pcontact)
|
||||
GDateTime *last_activity = p_contact_last_activity(pcontact);
|
||||
WINDOW *win = console->win;
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, "\n");
|
||||
win_print_time(console, '-');
|
||||
win_presence_colour_on(console, presence);
|
||||
console->print_time(console, '-');
|
||||
console->presence_colour_on(console, presence);
|
||||
wprintw(win, "%s", barejid);
|
||||
if (name != NULL) {
|
||||
wprintw(win, " (%s)", name);
|
||||
}
|
||||
win_presence_colour_off(console, presence);
|
||||
console->presence_colour_off(console, presence);
|
||||
wprintw(win, ":\n");
|
||||
|
||||
if (sub != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, "Subscription: %s\n", sub);
|
||||
}
|
||||
|
||||
@ -331,7 +333,7 @@ cons_show_info(PContact pcontact)
|
||||
GDateTime *now = g_date_time_new_now_local();
|
||||
GTimeSpan span = g_date_time_difference(now, last_activity);
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, "Last activity: ");
|
||||
|
||||
int hours = span / G_TIME_SPAN_HOUR;
|
||||
@ -353,7 +355,7 @@ cons_show_info(PContact pcontact)
|
||||
}
|
||||
|
||||
if (resources != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, "Resources:\n");
|
||||
|
||||
// sort in order of availabiltiy
|
||||
@ -368,21 +370,21 @@ cons_show_info(PContact pcontact)
|
||||
while (ordered_resources != NULL) {
|
||||
Resource *resource = ordered_resources->data;
|
||||
const char *resource_presence = string_from_resource_presence(resource->presence);
|
||||
win_print_time(console, '-');
|
||||
win_presence_colour_on(console, resource_presence);
|
||||
console->print_time(console, '-');
|
||||
console->presence_colour_on(console, resource_presence);
|
||||
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
|
||||
if (resource->status != NULL) {
|
||||
wprintw(win, ", \"%s\"", resource->status);
|
||||
}
|
||||
wprintw(win, "\n");
|
||||
win_presence_colour_off(console, resource_presence);
|
||||
console->presence_colour_off(console, resource_presence);
|
||||
|
||||
if (resource->caps_str != NULL) {
|
||||
Capabilities *caps = caps_get(resource->caps_str);
|
||||
if (caps != NULL) {
|
||||
// show identity
|
||||
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, " Identity: ");
|
||||
if (caps->name != NULL) {
|
||||
wprintw(win, "%s", caps->name);
|
||||
@ -402,7 +404,7 @@ cons_show_info(PContact pcontact)
|
||||
wprintw(win, "\n");
|
||||
}
|
||||
if (caps->software != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, " Software: %s", caps->software);
|
||||
}
|
||||
if (caps->software_version != NULL) {
|
||||
@ -412,7 +414,7 @@ cons_show_info(PContact pcontact)
|
||||
wprintw(win, "\n");
|
||||
}
|
||||
if (caps->os != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, " OS: %s", caps->os);
|
||||
}
|
||||
if (caps->os_version != NULL) {
|
||||
@ -438,10 +440,10 @@ cons_show_caps(const char * const contact, Resource *resource)
|
||||
WINDOW *win = console->win;
|
||||
cons_show("");
|
||||
const char *resource_presence = string_from_resource_presence(resource->presence);
|
||||
win_print_time(console, '-');
|
||||
win_presence_colour_on(console, resource_presence);
|
||||
console->print_time(console, '-');
|
||||
console->presence_colour_on(console, resource_presence);
|
||||
wprintw(console->win, "%s", contact);
|
||||
win_presence_colour_off(console, resource_presence);
|
||||
console->presence_colour_off(console, resource_presence);
|
||||
wprintw(win, ":\n");
|
||||
|
||||
if (resource->caps_str != NULL) {
|
||||
@ -449,7 +451,7 @@ cons_show_caps(const char * const contact, Resource *resource)
|
||||
if (caps != NULL) {
|
||||
// show identity
|
||||
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, "Identity: ");
|
||||
if (caps->name != NULL) {
|
||||
wprintw(win, "%s", caps->name);
|
||||
@ -469,7 +471,7 @@ cons_show_caps(const char * const contact, Resource *resource)
|
||||
wprintw(win, "\n");
|
||||
}
|
||||
if (caps->software != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, "Software: %s", caps->software);
|
||||
}
|
||||
if (caps->software_version != NULL) {
|
||||
@ -479,7 +481,7 @@ cons_show_caps(const char * const contact, Resource *resource)
|
||||
wprintw(win, "\n");
|
||||
}
|
||||
if (caps->os != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, "OS: %s", caps->os);
|
||||
}
|
||||
if (caps->os_version != NULL) {
|
||||
@ -490,11 +492,11 @@ cons_show_caps(const char * const contact, Resource *resource)
|
||||
}
|
||||
|
||||
if (caps->features != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, "Features:\n");
|
||||
GSList *feature = caps->features;
|
||||
while (feature != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, " %s\n", feature->data);
|
||||
feature = g_slist_next(feature);
|
||||
}
|
||||
@ -513,10 +515,10 @@ cons_show_software_version(const char * const jid, const char * const presence,
|
||||
ProfWin *console = wins_get_console();
|
||||
if ((name != NULL) || (version != NULL) || (os != NULL)) {
|
||||
cons_show("");
|
||||
win_print_time(console, '-');
|
||||
win_presence_colour_on(console, presence);
|
||||
console->print_time(console, '-');
|
||||
console->presence_colour_on(console, presence);
|
||||
wprintw(console->win, "%s", jid);
|
||||
win_presence_colour_off(console, presence);
|
||||
console->presence_colour_off(console, presence);
|
||||
wprintw(console->win, ":\n");
|
||||
}
|
||||
if (name != NULL) {
|
||||
@ -583,7 +585,7 @@ cons_show_room_list(GSList *rooms, const char * const conference_node)
|
||||
cons_show("Chat rooms at %s:", conference_node);
|
||||
while (rooms != NULL) {
|
||||
DiscoItem *room = rooms->data;
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, " %s", room->jid);
|
||||
if (room->name != NULL) {
|
||||
wprintw(console->win, ", (%s)", room->name);
|
||||
@ -613,7 +615,7 @@ cons_show_bookmarks(const GList *list)
|
||||
|
||||
ProfWin *console = wins_get_console();
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, " %s", item->jid);
|
||||
if (item->nick != NULL) {
|
||||
wprintw(console->win, "/%s", item->nick);
|
||||
@ -681,7 +683,7 @@ cons_show_disco_items(GSList *items, const char * const jid)
|
||||
cons_show("Service discovery items for %s:", jid);
|
||||
while (items != NULL) {
|
||||
DiscoItem *item = items->data;
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, " %s", item->jid);
|
||||
if (item->name != NULL) {
|
||||
wprintw(console->win, ", (%s)", item->name);
|
||||
@ -704,7 +706,7 @@ cons_show_status(const char * const barejid)
|
||||
PContact pcontact = roster_get_contact(barejid);
|
||||
|
||||
if (pcontact != NULL) {
|
||||
win_show_contact(console, pcontact);
|
||||
console->show_contact(console, pcontact);
|
||||
} else {
|
||||
cons_show("No such contact \"%s\" in roster.", barejid);
|
||||
}
|
||||
@ -761,10 +763,10 @@ cons_show_account_list(gchar **accounts)
|
||||
if ((jabber_get_connection_status() == JABBER_CONNECTED) &&
|
||||
(g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) {
|
||||
resource_presence_t presence = accounts_get_last_presence(accounts[i]);
|
||||
win_print_time(console, '-');
|
||||
win_presence_colour_on(console, string_from_resource_presence(presence));
|
||||
console->print_time(console, '-');
|
||||
console->presence_colour_on(console, string_from_resource_presence(presence));
|
||||
wprintw(console->win, "%s\n", accounts[i]);
|
||||
win_presence_colour_off(console, string_from_resource_presence(presence));
|
||||
console->presence_colour_off(console, string_from_resource_presence(presence));
|
||||
} else {
|
||||
cons_show(accounts[i]);
|
||||
}
|
||||
@ -820,7 +822,7 @@ cons_show_account(ProfAccount *account)
|
||||
|
||||
WINDOW *win = console->win;
|
||||
if (resources != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, "Resources:\n");
|
||||
|
||||
// sort in order of availabiltiy
|
||||
@ -835,21 +837,21 @@ cons_show_account(ProfAccount *account)
|
||||
while (ordered_resources != NULL) {
|
||||
Resource *resource = ordered_resources->data;
|
||||
const char *resource_presence = string_from_resource_presence(resource->presence);
|
||||
win_print_time(console, '-');
|
||||
win_presence_colour_on(console, resource_presence);
|
||||
console->print_time(console, '-');
|
||||
console->presence_colour_on(console, resource_presence);
|
||||
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
|
||||
if (resource->status != NULL) {
|
||||
wprintw(win, ", \"%s\"", resource->status);
|
||||
}
|
||||
wprintw(win, "\n");
|
||||
win_presence_colour_off(console, resource_presence);
|
||||
console->presence_colour_off(console, resource_presence);
|
||||
|
||||
if (resource->caps_str != NULL) {
|
||||
Capabilities *caps = caps_get(resource->caps_str);
|
||||
if (caps != NULL) {
|
||||
// show identity
|
||||
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, " Identity: ");
|
||||
if (caps->name != NULL) {
|
||||
wprintw(win, "%s", caps->name);
|
||||
@ -869,7 +871,7 @@ cons_show_account(ProfAccount *account)
|
||||
wprintw(win, "\n");
|
||||
}
|
||||
if (caps->software != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, " Software: %s", caps->software);
|
||||
}
|
||||
if (caps->software_version != NULL) {
|
||||
@ -879,7 +881,7 @@ cons_show_account(ProfAccount *account)
|
||||
wprintw(win, "\n");
|
||||
}
|
||||
if (caps->os != NULL) {
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(win, " OS: %s", caps->os);
|
||||
}
|
||||
if (caps->os_version != NULL) {
|
||||
@ -1342,7 +1344,7 @@ cons_show_contacts(GSList *list)
|
||||
PContact contact = curr->data;
|
||||
if ((strcmp(p_contact_subscription(contact), "to") == 0) ||
|
||||
(strcmp(p_contact_subscription(contact), "both") == 0)) {
|
||||
win_show_contact(console, contact);
|
||||
console->show_contact(console, contact);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
@ -1363,49 +1365,49 @@ static void
|
||||
_cons_splash_logo(void)
|
||||
{
|
||||
ProfWin *console = wins_get_console();
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "Welcome to\n");
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_SPLASH);
|
||||
wprintw(console->win, " ___ _ \n");
|
||||
wattroff(console->win, COLOUR_SPLASH);
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_SPLASH);
|
||||
wprintw(console->win, " / __) (_)_ \n");
|
||||
wattroff(console->win, COLOUR_SPLASH);
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_SPLASH);
|
||||
wprintw(console->win, " ____ ____ ___ | |__ ____ ____ _| |_ _ _ \n");
|
||||
wattroff(console->win, COLOUR_SPLASH);
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_SPLASH);
|
||||
wprintw(console->win, "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |\n");
|
||||
wattroff(console->win, COLOUR_SPLASH);
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_SPLASH);
|
||||
wprintw(console->win, "| | | | | | |_| | | ( ( | | | | | | |_| |_| |\n");
|
||||
wattroff(console->win, COLOUR_SPLASH);
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_SPLASH);
|
||||
wprintw(console->win, "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |\n");
|
||||
wattroff(console->win, COLOUR_SPLASH);
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wattron(console->win, COLOUR_SPLASH);
|
||||
wprintw(console->win, "|_| (____/ \n");
|
||||
wattroff(console->win, COLOUR_SPLASH);
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, "\n");
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) {
|
||||
#ifdef PROF_HAVE_GIT_VERSION
|
||||
#ifdef HAVE_GIT_VERSION
|
||||
wprintw(console->win, "Version %sdev.%s.%s\n", PROF_PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
|
||||
#else
|
||||
wprintw(console->win, "Version %sdev\n", PROF_PACKAGE_VERSION);
|
||||
@ -1432,20 +1434,20 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
|
||||
}
|
||||
|
||||
const char *presence = p_contact_presence(contact);
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
if (p_contact_subscribed(contact)) {
|
||||
win_presence_colour_on(console, presence);
|
||||
console->presence_colour_on(console, presence);
|
||||
wprintw(console->win, "%s\n", title->str);
|
||||
win_presence_colour_off(console, presence);
|
||||
console->presence_colour_off(console, presence);
|
||||
} else {
|
||||
win_presence_colour_on(console, "offline");
|
||||
console->presence_colour_on(console, "offline");
|
||||
wprintw(console->win, "%s\n", title->str);
|
||||
win_presence_colour_off(console, "offline");
|
||||
console->presence_colour_off(console, "offline");
|
||||
}
|
||||
|
||||
g_string_free(title, TRUE);
|
||||
|
||||
win_print_time(console, '-');
|
||||
console->print_time(console, '-');
|
||||
wprintw(console->win, " Subscription : ");
|
||||
GString *sub = g_string_new("");
|
||||
sub = g_string_append(sub, p_contact_subscription(contact));
|
||||
|
@ -283,7 +283,7 @@ ui_incoming_msg(const char * const from, const char * const message,
|
||||
// currently viewing chat window with sender
|
||||
if (wins_is_current(window)) {
|
||||
if (tv_stamp == NULL) {
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
} else {
|
||||
GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
|
||||
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
|
||||
@ -322,13 +322,13 @@ ui_incoming_msg(const char * const from, const char * const message,
|
||||
}
|
||||
|
||||
if (tv_stamp == NULL) {
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
} else {
|
||||
// show users status first, when receiving message via delayed delivery
|
||||
if (win_created) {
|
||||
PContact pcontact = roster_get_contact(from);
|
||||
if (pcontact != NULL) {
|
||||
win_show_contact(window, pcontact);
|
||||
window->show_contact(window, pcontact);
|
||||
}
|
||||
}
|
||||
GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
|
||||
@ -405,6 +405,22 @@ ui_group_removed(const char * const contact, const char * const group)
|
||||
cons_show("%s removed from group %s", contact, group);
|
||||
}
|
||||
|
||||
void
|
||||
ui_handle_error_message(const char * const from, const char * const err_msg)
|
||||
{
|
||||
if (err_msg == NULL) {
|
||||
cons_show_error("Unknown error received from service.");
|
||||
} else {
|
||||
ProfWin *win = wins_get_current();
|
||||
gboolean handled = win->handle_error_message(win, from, err_msg);
|
||||
if (handled != TRUE) {
|
||||
cons_show_error("Error received from server: %s", err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
ui_print_error_from_recipient(from, err_msg);
|
||||
}
|
||||
|
||||
void
|
||||
ui_contact_online(const char * const barejid, const char * const resource,
|
||||
const char * const show, const char * const status, GDateTime *last_activity)
|
||||
@ -599,6 +615,7 @@ ui_switch_win(const int i)
|
||||
|
||||
if (i == 1) {
|
||||
title_bar_title();
|
||||
status_bar_current(1);
|
||||
status_bar_active(1);
|
||||
} else {
|
||||
PContact contact = roster_get_contact(new_current->from);
|
||||
@ -611,7 +628,8 @@ ui_switch_win(const int i)
|
||||
} else {
|
||||
title_bar_set_recipient(new_current->from);
|
||||
}
|
||||
title_bar_draw();;
|
||||
title_bar_draw();
|
||||
status_bar_current(i);
|
||||
status_bar_active(i);
|
||||
}
|
||||
wins_refresh_current();
|
||||
@ -631,6 +649,7 @@ ui_next_win(void)
|
||||
|
||||
if (i == 1) {
|
||||
title_bar_title();
|
||||
status_bar_current(1);
|
||||
status_bar_active(1);
|
||||
} else {
|
||||
PContact contact = roster_get_contact(new_current->from);
|
||||
@ -643,7 +662,8 @@ ui_next_win(void)
|
||||
} else {
|
||||
title_bar_set_recipient(new_current->from);
|
||||
}
|
||||
title_bar_draw();;
|
||||
title_bar_draw();
|
||||
status_bar_current(i);
|
||||
status_bar_active(i);
|
||||
}
|
||||
wins_refresh_current();
|
||||
@ -662,6 +682,7 @@ ui_previous_win(void)
|
||||
|
||||
if (i == 1) {
|
||||
title_bar_title();
|
||||
status_bar_current(1);
|
||||
status_bar_active(1);
|
||||
} else {
|
||||
PContact contact = roster_get_contact(new_current->from);
|
||||
@ -674,7 +695,8 @@ ui_previous_win(void)
|
||||
} else {
|
||||
title_bar_set_recipient(new_current->from);
|
||||
}
|
||||
title_bar_draw();;
|
||||
title_bar_draw();
|
||||
status_bar_current(i);
|
||||
status_bar_active(i);
|
||||
}
|
||||
wins_refresh_current();
|
||||
@ -692,6 +714,7 @@ ui_close_current(void)
|
||||
int current_index = wins_get_current_num();
|
||||
status_bar_inactive(current_index);
|
||||
wins_close_current();
|
||||
status_bar_current(1);
|
||||
status_bar_active(1);
|
||||
title_bar_title();
|
||||
}
|
||||
@ -700,6 +723,7 @@ void
|
||||
ui_close_win(int index)
|
||||
{
|
||||
wins_close_by_num(index);
|
||||
status_bar_current(1);
|
||||
status_bar_active(1);
|
||||
title_bar_title();
|
||||
|
||||
@ -803,21 +827,16 @@ ui_current_print_line(const char * const msg, ...)
|
||||
ProfWin *current = wins_get_current();
|
||||
va_list arg;
|
||||
va_start(arg, msg);
|
||||
GString *fmt_msg = g_string_new(NULL);
|
||||
g_string_vprintf(fmt_msg, msg, arg);
|
||||
win_print_time(current, '-');
|
||||
wprintw(current->win, "%s\n", fmt_msg->str);
|
||||
g_string_free(fmt_msg, TRUE);
|
||||
current->print_line(current, msg, arg);
|
||||
va_end(arg);
|
||||
|
||||
wins_refresh_current();
|
||||
current->refresh_win(current);
|
||||
}
|
||||
|
||||
void
|
||||
ui_current_error_line(const char * const msg)
|
||||
{
|
||||
ProfWin *current = wins_get_current();
|
||||
win_print_time(current, '-');
|
||||
current->print_time(current, '-');
|
||||
wattron(current->win, COLOUR_ERROR);
|
||||
wprintw(current->win, "%s\n", msg);
|
||||
wattroff(current->win, COLOUR_ERROR);
|
||||
@ -851,7 +870,7 @@ ui_print_error_from_recipient(const char * const from, const char *err_msg)
|
||||
|
||||
ProfWin *window = wins_get_by_recipient(from);
|
||||
if (window != NULL) {
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
_win_show_error_msg(window->win, err_msg);
|
||||
if (wins_is_current(window)) {
|
||||
wins_refresh_current();
|
||||
@ -885,7 +904,7 @@ ui_print_system_msg_from_recipient(const char * const from, const char *message)
|
||||
}
|
||||
}
|
||||
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
wprintw(window->win, "*%s %s\n", bare_jid, message);
|
||||
|
||||
// this is the current window
|
||||
@ -910,7 +929,7 @@ ui_recipient_gone(const char * const barejid)
|
||||
|
||||
ProfWin *window = wins_get_by_recipient(barejid);
|
||||
if (window != NULL) {
|
||||
win_print_time(window, '!');
|
||||
window->print_time(window, '!');
|
||||
wattron(window->win, COLOUR_GONE);
|
||||
wprintw(window->win, "<- %s ", display_usr);
|
||||
wprintw(window->win, "has left the conversation.");
|
||||
@ -967,7 +986,7 @@ ui_create_duck_win(void)
|
||||
ProfWin *window = wins_new("DuckDuckGo search", WIN_DUCK);
|
||||
int num = wins_get_num(window);
|
||||
ui_switch_win(num);
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
wprintw(window->win, "Type ':help' to find out more.\n");
|
||||
}
|
||||
|
||||
@ -986,9 +1005,9 @@ ui_duck(const char * const query)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient("DuckDuckGo search");
|
||||
if (window != NULL) {
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
wprintw(window->win, "\n");
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
wattron(window->win, COLOUR_ME);
|
||||
wprintw(window->win, "Query : ");
|
||||
wattroff(window->win, COLOUR_ME);
|
||||
@ -1003,7 +1022,7 @@ ui_duck_result(const char * const result)
|
||||
ProfWin *window = wins_get_by_recipient("DuckDuckGo search");
|
||||
|
||||
if (window != NULL) {
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
wattron(window->win, COLOUR_THEM);
|
||||
wprintw(window->win, "Result : ");
|
||||
wattroff(window->win, COLOUR_THEM);
|
||||
@ -1014,7 +1033,7 @@ ui_duck_result(const char * const result)
|
||||
gunichar unichar = g_utf8_get_char(ptr);
|
||||
if (unichar == '\n') {
|
||||
wprintw(window->win, "\n");
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
} else {
|
||||
gchar *string = g_ucs4_to_utf8(&unichar, 1, NULL, NULL, NULL);
|
||||
if (string != NULL) {
|
||||
@ -1070,7 +1089,7 @@ ui_outgoing_msg(const char * const from, const char * const to,
|
||||
num = wins_get_num(window);
|
||||
}
|
||||
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
if (strncmp(message, "/me ", 4) == 0) {
|
||||
wattron(window->win, COLOUR_ME);
|
||||
wprintw(window->win, "*%s ", from);
|
||||
@ -1104,7 +1123,7 @@ ui_room_roster(const char * const room, GList *roster, const char * const presen
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(room);
|
||||
|
||||
win_print_time(window, '!');
|
||||
window->print_time(window, '!');
|
||||
if ((roster == NULL) || (g_list_length(roster) == 0)) {
|
||||
wattron(window->win, COLOUR_ROOMINFO);
|
||||
if (presence == NULL) {
|
||||
@ -1134,9 +1153,9 @@ ui_room_roster(const char * const room, GList *roster, const char * const presen
|
||||
const char const *nick = p_contact_barejid(member);
|
||||
const char const *show = p_contact_presence(member);
|
||||
|
||||
win_presence_colour_on(window, show);
|
||||
window->presence_colour_on(window, show);
|
||||
wprintw(window->win, "%s", nick);
|
||||
win_presence_colour_off(window, show);
|
||||
window->presence_colour_off(window, show);
|
||||
|
||||
if (roster->next != NULL) {
|
||||
wprintw(window->win, ", ");
|
||||
@ -1159,7 +1178,7 @@ ui_room_member_offline(const char * const room, const char * const nick)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(room);
|
||||
|
||||
win_print_time(window, '!');
|
||||
window->print_time(window, '!');
|
||||
wattron(window->win, COLOUR_OFFLINE);
|
||||
wprintw(window->win, "<- %s has left the room.\n", nick);
|
||||
wattroff(window->win, COLOUR_OFFLINE);
|
||||
@ -1175,7 +1194,7 @@ ui_room_member_online(const char * const room, const char * const nick,
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(room);
|
||||
|
||||
win_print_time(window, '!');
|
||||
window->print_time(window, '!');
|
||||
wattron(window->win, COLOUR_ONLINE);
|
||||
wprintw(window->win, "-> %s has joined the room.\n", nick);
|
||||
wattroff(window->win, COLOUR_ONLINE);
|
||||
@ -1206,7 +1225,7 @@ ui_room_member_nick_change(const char * const room,
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(room);
|
||||
|
||||
win_print_time(window, '!');
|
||||
window->print_time(window, '!');
|
||||
wattron(window->win, COLOUR_THEM);
|
||||
wprintw(window->win, "** %s is now known as %s\n", old_nick, nick);
|
||||
wattroff(window->win, COLOUR_THEM);
|
||||
@ -1221,7 +1240,7 @@ ui_room_nick_change(const char * const room, const char * const nick)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(room);
|
||||
|
||||
win_print_time(window, '!');
|
||||
window->print_time(window, '!');
|
||||
wattron(window->win, COLOUR_ME);
|
||||
wprintw(window->win, "** You are now known as %s\n", nick);
|
||||
wattroff(window->win, COLOUR_ME);
|
||||
@ -1264,7 +1283,7 @@ ui_room_message(const char * const room_jid, const char * const nick,
|
||||
ProfWin *window = wins_get_by_recipient(room_jid);
|
||||
int num = wins_get_num(window);
|
||||
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
if (strcmp(nick, muc_get_room_nick(room_jid)) != 0) {
|
||||
if (strncmp(message, "/me ", 4) == 0) {
|
||||
wattron(window->win, COLOUR_THEM);
|
||||
@ -1335,7 +1354,7 @@ ui_room_subject(const char * const room_jid, const char * const subject)
|
||||
ProfWin *window = wins_get_by_recipient(room_jid);
|
||||
int num = wins_get_num(window);
|
||||
|
||||
win_print_time(window, '!');
|
||||
window->print_time(window, '!');
|
||||
wattron(window->win, COLOUR_ROOMINFO);
|
||||
wprintw(window->win, "Room subject: ");
|
||||
wattroff(window->win, COLOUR_ROOMINFO);
|
||||
@ -1358,7 +1377,7 @@ ui_room_broadcast(const char * const room_jid, const char * const message)
|
||||
ProfWin *window = wins_get_by_recipient(room_jid);
|
||||
int num = wins_get_num(window);
|
||||
|
||||
win_print_time(window, '!');
|
||||
window->print_time(window, '!');
|
||||
wattron(window->win, COLOUR_ROOMINFO);
|
||||
wprintw(window->win, "Room message: ");
|
||||
wattroff(window->win, COLOUR_ROOMINFO);
|
||||
@ -1383,7 +1402,7 @@ ui_status(void)
|
||||
ProfWin *current = wins_get_current();
|
||||
|
||||
if (pcontact != NULL) {
|
||||
win_show_contact(current, pcontact);
|
||||
current->show_contact(current, pcontact);
|
||||
} else {
|
||||
ui_current_print_line("Error getting contact info.");
|
||||
}
|
||||
@ -1397,7 +1416,7 @@ ui_status_private(void)
|
||||
ProfWin *current = wins_get_current();
|
||||
|
||||
if (pcontact != NULL) {
|
||||
win_show_contact(current, pcontact);
|
||||
current->show_contact(current, pcontact);
|
||||
} else {
|
||||
ui_current_print_line("Error getting contact info.");
|
||||
}
|
||||
@ -1412,7 +1431,7 @@ ui_status_room(const char * const contact)
|
||||
ProfWin *current = wins_get_current();
|
||||
|
||||
if (pcontact != NULL) {
|
||||
win_show_contact(current, pcontact);
|
||||
current->show_contact(current, pcontact);
|
||||
} else {
|
||||
ui_current_print_line("No such participant \"%s\" in room.", contact);
|
||||
}
|
||||
@ -1524,7 +1543,7 @@ _show_status_string(ProfWin *window, const char * const from,
|
||||
if (!prefs_get_boolean(PREF_STATUSES))
|
||||
return;
|
||||
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
|
||||
if (show != NULL) {
|
||||
if (strcmp(show, "away") == 0) {
|
||||
|
@ -39,12 +39,14 @@ static WINDOW *status_bar;
|
||||
static char *message = NULL;
|
||||
// 1 2 3 4 5 6 7 8 9 0 >
|
||||
static char _active[34] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]";
|
||||
static char *bracket = "- -";
|
||||
static int is_active[12];
|
||||
static GHashTable *remaining_active;
|
||||
static int is_new[12];
|
||||
static GHashTable *remaining_new;
|
||||
static int dirty;
|
||||
static GDateTime *last_time;
|
||||
static int current;
|
||||
|
||||
static void _status_bar_update_time(void);
|
||||
static void _update_win_statuses(void);
|
||||
@ -66,11 +68,13 @@ create_status_bar(void)
|
||||
}
|
||||
remaining_active = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
|
||||
remaining_new = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
|
||||
current = 1;
|
||||
|
||||
status_bar = newwin(1, cols, rows-2, 0);
|
||||
wbkgd(status_bar, COLOUR_STATUS_TEXT);
|
||||
wattron(status_bar, COLOUR_STATUS_BRACKET);
|
||||
mvwprintw(status_bar, 0, cols - 34, _active);
|
||||
mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
|
||||
wattroff(status_bar, COLOUR_STATUS_BRACKET);
|
||||
|
||||
if (last_time != NULL)
|
||||
@ -116,6 +120,7 @@ status_bar_resize(void)
|
||||
werase(status_bar);
|
||||
wattron(status_bar, COLOUR_STATUS_BRACKET);
|
||||
mvwprintw(status_bar, 0, cols - 34, _active);
|
||||
mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
|
||||
wattroff(status_bar, COLOUR_STATUS_BRACKET);
|
||||
|
||||
_update_win_statuses();
|
||||
@ -143,6 +148,23 @@ status_bar_set_all_inactive(void)
|
||||
g_hash_table_remove_all(remaining_new);
|
||||
}
|
||||
|
||||
void
|
||||
status_bar_current(int i)
|
||||
{
|
||||
if (i == 0) {
|
||||
current = 10;
|
||||
} else if (i > 10) {
|
||||
current = 11;
|
||||
} else {
|
||||
current = i;
|
||||
}
|
||||
int cols = getmaxx(stdscr);
|
||||
wattron(status_bar, COLOUR_STATUS_BRACKET);
|
||||
mvwprintw(status_bar, 0, cols - 34, _active);
|
||||
mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
|
||||
wattroff(status_bar, COLOUR_STATUS_BRACKET);
|
||||
}
|
||||
|
||||
void
|
||||
status_bar_inactive(const int win)
|
||||
{
|
||||
@ -263,6 +285,7 @@ status_bar_print_message(const char * const msg)
|
||||
|
||||
wattron(status_bar, COLOUR_STATUS_BRACKET);
|
||||
mvwprintw(status_bar, 0, cols - 34, _active);
|
||||
mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
|
||||
wattroff(status_bar, COLOUR_STATUS_BRACKET);
|
||||
|
||||
_update_win_statuses();
|
||||
@ -291,6 +314,7 @@ status_bar_clear(void)
|
||||
|
||||
wattron(status_bar, COLOUR_STATUS_BRACKET);
|
||||
mvwprintw(status_bar, 0, cols - 34, _active);
|
||||
mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
|
||||
wattroff(status_bar, COLOUR_STATUS_BRACKET);
|
||||
|
||||
dirty = TRUE;
|
||||
@ -310,6 +334,7 @@ status_bar_clear_message(void)
|
||||
|
||||
wattron(status_bar, COLOUR_STATUS_BRACKET);
|
||||
mvwprintw(status_bar, 0, cols - 34, _active);
|
||||
mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
|
||||
wattroff(status_bar, COLOUR_STATUS_BRACKET);
|
||||
|
||||
_update_win_statuses();
|
||||
|
@ -59,6 +59,7 @@ void ui_reset_idle_time(void);
|
||||
void ui_new_chat_win(const char * const to);
|
||||
void ui_print_error_from_recipient(const char * const from, const char *err_msg);
|
||||
void ui_print_system_msg_from_recipient(const char * const from, const char *message);
|
||||
void ui_handle_error_message(const char * const from, const char * const err_msg);
|
||||
gint ui_unread(void);
|
||||
void ui_close_connected_win(int index);
|
||||
int ui_close_all_wins(void);
|
||||
@ -228,6 +229,7 @@ void status_bar_active(const int win);
|
||||
void status_bar_new(const int win);
|
||||
void status_bar_update_time(void);
|
||||
void status_bar_set_all_inactive(void);
|
||||
void status_bar_current(int i);
|
||||
|
||||
// input window actions
|
||||
wint_t inp_get_char(char *input, int *size);
|
||||
|
141
src/ui/window.c
141
src/ui/window.c
@ -35,6 +35,17 @@
|
||||
#include "config/theme.h"
|
||||
#include "ui/window.h"
|
||||
|
||||
static gboolean _muc_handle_error_message(ProfWin *self, const char * const from,
|
||||
const char * const err_msg);
|
||||
static gboolean _default_handle_error_message(ProfWin *self, const char * const from,
|
||||
const char * const err_msg);
|
||||
static void _win_print_time(ProfWin *self, char show_char);
|
||||
static void _win_print_line(ProfWin *self, const char * const msg, ...);
|
||||
static void _win_refresh(ProfWin *self);
|
||||
static void _win_presence_colour_on(ProfWin *self, const char * const presence);
|
||||
static void _win_presence_colour_off(ProfWin *self, const char * const presence);
|
||||
static void _win_show_contact(ProfWin *self, PContact contact);
|
||||
|
||||
ProfWin*
|
||||
win_create(const char * const title, int cols, win_type_t type)
|
||||
{
|
||||
@ -47,6 +58,24 @@ win_create(const char * const title, int cols, win_type_t type)
|
||||
new_win->unread = 0;
|
||||
new_win->history_shown = 0;
|
||||
new_win->type = type;
|
||||
|
||||
new_win->print_time = _win_print_time;
|
||||
new_win->print_line = _win_print_line;
|
||||
new_win->refresh_win = _win_refresh;
|
||||
new_win->presence_colour_on = _win_presence_colour_on;
|
||||
new_win->presence_colour_off = _win_presence_colour_off;
|
||||
new_win->show_contact = _win_show_contact;
|
||||
|
||||
switch (new_win->type)
|
||||
{
|
||||
case WIN_MUC:
|
||||
new_win->handle_error_message = _muc_handle_error_message;
|
||||
break;
|
||||
default:
|
||||
new_win->handle_error_message = _default_handle_error_message;
|
||||
break;
|
||||
}
|
||||
|
||||
scrollok(new_win->win, TRUE);
|
||||
|
||||
return new_win;
|
||||
@ -61,56 +90,77 @@ win_free(ProfWin* window)
|
||||
window = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
win_print_time(ProfWin* window, char show_char)
|
||||
static void
|
||||
_win_print_time(ProfWin* self, char show_char)
|
||||
{
|
||||
GDateTime *time = g_date_time_new_now_local();
|
||||
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
|
||||
wattron(window->win, COLOUR_TIME);
|
||||
wprintw(window->win, "%s %c ", date_fmt, show_char);
|
||||
wattroff(window->win, COLOUR_TIME);
|
||||
wattron(self->win, COLOUR_TIME);
|
||||
wprintw(self->win, "%s %c ", date_fmt, show_char);
|
||||
wattroff(self->win, COLOUR_TIME);
|
||||
g_date_time_unref(time);
|
||||
g_free(date_fmt);
|
||||
}
|
||||
|
||||
void
|
||||
win_presence_colour_on(ProfWin *window, const char * const presence)
|
||||
static void
|
||||
_win_print_line(ProfWin *self, const char * const msg, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, msg);
|
||||
GString *fmt_msg = g_string_new(NULL);
|
||||
g_string_vprintf(fmt_msg, msg, arg);
|
||||
_win_print_time(self, '-');
|
||||
wprintw(self->win, "%s\n", fmt_msg->str);
|
||||
g_string_free(fmt_msg, TRUE);
|
||||
va_end(arg);
|
||||
}
|
||||
|
||||
static void
|
||||
_win_refresh(ProfWin *self)
|
||||
{
|
||||
int rows, cols;
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
prefresh(self->win, self->y_pos, 0, 1, 0, rows-3, cols-1);
|
||||
}
|
||||
|
||||
static void
|
||||
_win_presence_colour_on(ProfWin *self, const char * const presence)
|
||||
{
|
||||
if (g_strcmp0(presence, "online") == 0) {
|
||||
wattron(window->win, COLOUR_ONLINE);
|
||||
wattron(self->win, COLOUR_ONLINE);
|
||||
} else if (g_strcmp0(presence, "away") == 0) {
|
||||
wattron(window->win, COLOUR_AWAY);
|
||||
wattron(self->win, COLOUR_AWAY);
|
||||
} else if (g_strcmp0(presence, "chat") == 0) {
|
||||
wattron(window->win, COLOUR_CHAT);
|
||||
wattron(self->win, COLOUR_CHAT);
|
||||
} else if (g_strcmp0(presence, "dnd") == 0) {
|
||||
wattron(window->win, COLOUR_DND);
|
||||
wattron(self->win, COLOUR_DND);
|
||||
} else if (g_strcmp0(presence, "xa") == 0) {
|
||||
wattron(window->win, COLOUR_XA);
|
||||
wattron(self->win, COLOUR_XA);
|
||||
} else {
|
||||
wattron(window->win, COLOUR_OFFLINE);
|
||||
wattron(self->win, COLOUR_OFFLINE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
win_presence_colour_off(ProfWin *window, const char * const presence)
|
||||
static void
|
||||
_win_presence_colour_off(ProfWin *self, const char * const presence)
|
||||
{
|
||||
if (g_strcmp0(presence, "online") == 0) {
|
||||
wattroff(window->win, COLOUR_ONLINE);
|
||||
wattroff(self->win, COLOUR_ONLINE);
|
||||
} else if (g_strcmp0(presence, "away") == 0) {
|
||||
wattroff(window->win, COLOUR_AWAY);
|
||||
wattroff(self->win, COLOUR_AWAY);
|
||||
} else if (g_strcmp0(presence, "chat") == 0) {
|
||||
wattroff(window->win, COLOUR_CHAT);
|
||||
wattroff(self->win, COLOUR_CHAT);
|
||||
} else if (g_strcmp0(presence, "dnd") == 0) {
|
||||
wattroff(window->win, COLOUR_DND);
|
||||
wattroff(self->win, COLOUR_DND);
|
||||
} else if (g_strcmp0(presence, "xa") == 0) {
|
||||
wattroff(window->win, COLOUR_XA);
|
||||
wattroff(self->win, COLOUR_XA);
|
||||
} else {
|
||||
wattroff(window->win, COLOUR_OFFLINE);
|
||||
wattroff(self->win, COLOUR_OFFLINE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
win_show_contact(ProfWin *window, PContact contact)
|
||||
static void
|
||||
_win_show_contact(ProfWin *self, PContact contact)
|
||||
{
|
||||
const char *barejid = p_contact_barejid(contact);
|
||||
const char *name = p_contact_name(contact);
|
||||
@ -118,41 +168,62 @@ win_show_contact(ProfWin *window, PContact contact)
|
||||
const char *status = p_contact_status(contact);
|
||||
GDateTime *last_activity = p_contact_last_activity(contact);
|
||||
|
||||
win_print_time(window, '-');
|
||||
win_presence_colour_on(window, presence);
|
||||
_win_print_time(self, '-');
|
||||
_win_presence_colour_on(self, presence);
|
||||
|
||||
if (name != NULL) {
|
||||
wprintw(window->win, "%s", name);
|
||||
wprintw(self->win, "%s", name);
|
||||
} else {
|
||||
wprintw(window->win, "%s", barejid);
|
||||
wprintw(self->win, "%s", barejid);
|
||||
}
|
||||
|
||||
wprintw(window->win, " is %s", presence);
|
||||
wprintw(self->win, " is %s", presence);
|
||||
|
||||
if (last_activity != NULL) {
|
||||
GDateTime *now = g_date_time_new_now_local();
|
||||
GTimeSpan span = g_date_time_difference(now, last_activity);
|
||||
|
||||
wprintw(window->win, ", idle ");
|
||||
wprintw(self->win, ", idle ");
|
||||
|
||||
int hours = span / G_TIME_SPAN_HOUR;
|
||||
span = span - hours * G_TIME_SPAN_HOUR;
|
||||
if (hours > 0) {
|
||||
wprintw(window->win, "%dh", hours);
|
||||
wprintw(self->win, "%dh", hours);
|
||||
}
|
||||
|
||||
int minutes = span / G_TIME_SPAN_MINUTE;
|
||||
span = span - minutes * G_TIME_SPAN_MINUTE;
|
||||
wprintw(window->win, "%dm", minutes);
|
||||
wprintw(self->win, "%dm", minutes);
|
||||
|
||||
int seconds = span / G_TIME_SPAN_SECOND;
|
||||
wprintw(window->win, "%ds", seconds);
|
||||
wprintw(self->win, "%ds", seconds);
|
||||
}
|
||||
|
||||
if (status != NULL) {
|
||||
wprintw(window->win, ", \"%s\"", p_contact_status(contact));
|
||||
wprintw(self->win, ", \"%s\"", p_contact_status(contact));
|
||||
}
|
||||
|
||||
wprintw(window->win, "\n");
|
||||
win_presence_colour_off(window, presence);
|
||||
wprintw(self->win, "\n");
|
||||
_win_presence_colour_off(self, presence);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_muc_handle_error_message(ProfWin *self, const char * const from,
|
||||
const char * const err_msg)
|
||||
{
|
||||
gboolean handled = FALSE;
|
||||
if (g_strcmp0(err_msg, "conflict") == 0) {
|
||||
_win_print_line(self, "Nickname already in use.");
|
||||
_win_refresh(self);
|
||||
handled = TRUE;
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_default_handle_error_message(ProfWin *self, const char * const from,
|
||||
const char * const err_msg)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -53,14 +53,17 @@ typedef struct prof_win_t {
|
||||
int paged;
|
||||
int unread;
|
||||
int history_shown;
|
||||
void (*print_time)(struct prof_win_t *self, char show_char);
|
||||
void (*print_line)(struct prof_win_t *self, const char * const msg, ...);
|
||||
void (*refresh_win)(struct prof_win_t *self);
|
||||
void (*presence_colour_on)(struct prof_win_t *self, const char * const presence);
|
||||
void (*presence_colour_off)(struct prof_win_t *self, const char * const presence);
|
||||
void (*show_contact)(struct prof_win_t *self, PContact contact);
|
||||
gboolean (*handle_error_message)(struct prof_win_t *self,
|
||||
const char * const from, const char * const err_msg);
|
||||
} ProfWin;
|
||||
|
||||
ProfWin* win_create(const char * const title, int cols, win_type_t type);
|
||||
void win_free(ProfWin *window);
|
||||
|
||||
void win_print_time(ProfWin *window, char show_char);
|
||||
void win_presence_colour_on(ProfWin *window, const char * const presence);
|
||||
void win_presence_colour_off(ProfWin *window, const char * const presence);
|
||||
void win_show_contact(ProfWin *window, PContact contact);
|
||||
|
||||
#endif
|
||||
|
@ -350,7 +350,7 @@ wins_lost_connection(void)
|
||||
while (curr != NULL) {
|
||||
ProfWin *window = curr->data;
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
win_print_time(window, '-');
|
||||
window->print_time(window, '-');
|
||||
wattron(window->win, COLOUR_ERROR);
|
||||
wprintw(window->win, "%s\n", "Lost connection.");
|
||||
wattroff(window->win, COLOUR_ERROR);
|
||||
@ -413,6 +413,8 @@ wins_tidy(void)
|
||||
}
|
||||
|
||||
windows = new_windows;
|
||||
current = 1;
|
||||
ui_switch_win(1);
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user