From 8ae6d359d7000c8c950859777c9e953e76bfc871 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Jun 2014 21:14:21 +0100 Subject: [PATCH] Moved info display code to window.c --- src/ui/console.c | 125 +-------------------------------------------- src/ui/core.c | 13 +++++ src/ui/window.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++ src/ui/window.h | 1 + 4 files changed, 145 insertions(+), 124 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 59cfdc5a..3d26dcd9 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -337,130 +337,7 @@ static void _cons_show_info(PContact pcontact) { ProfWin *console = wins_get_console(); - const char *barejid = p_contact_barejid(pcontact); - const char *name = p_contact_name(pcontact); - const char *presence = p_contact_presence(pcontact); - const char *sub = p_contact_subscription(pcontact); - GList *resources = p_contact_get_available_resources(pcontact); - GList *ordered_resources = NULL; - GDateTime *last_activity = p_contact_last_activity(pcontact); - WINDOW *win = console->win; - - win_print_time(console, '-'); - wprintw(win, "\n"); - win_print_time(console, '-'); - win_presence_colour_on(console, presence); - wprintw(win, "%s", barejid); - if (name != NULL) { - wprintw(win, " (%s)", name); - } - win_presence_colour_off(console, presence); - wprintw(win, ":\n"); - - if (sub != NULL) { - win_print_time(console, '-'); - wprintw(win, "Subscription: %s\n", sub); - } - - if (last_activity != NULL) { - GDateTime *now = g_date_time_new_now_local(); - GTimeSpan span = g_date_time_difference(now, last_activity); - - win_print_time(console, '-'); - wprintw(win, "Last activity: "); - - int hours = span / G_TIME_SPAN_HOUR; - span = span - hours * G_TIME_SPAN_HOUR; - if (hours > 0) { - wprintw(win, "%dh", hours); - } - - int minutes = span / G_TIME_SPAN_MINUTE; - span = span - minutes * G_TIME_SPAN_MINUTE; - wprintw(win, "%dm", minutes); - - int seconds = span / G_TIME_SPAN_SECOND; - wprintw(win, "%ds", seconds); - - wprintw(win, "\n"); - - g_date_time_unref(now); - } - - if (resources != NULL) { - win_print_time(console, '-'); - wprintw(win, "Resources:\n"); - - // sort in order of availabiltiy - while (resources != NULL) { - Resource *resource = resources->data; - ordered_resources = g_list_insert_sorted(ordered_resources, - resource, (GCompareFunc)resource_compare_availability); - resources = g_list_next(resources); - } - } - - 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); - 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); - - 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, '-'); - wprintw(win, " Identity: "); - if (caps->name != NULL) { - wprintw(win, "%s", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { - wprintw(win, " "); - } - } - if (caps->type != NULL) { - wprintw(win, "%s", caps->type); - if (caps->category != NULL) { - wprintw(win, " "); - } - } - if (caps->category != NULL) { - wprintw(win, "%s", caps->category); - } - wprintw(win, "\n"); - } - if (caps->software != NULL) { - win_print_time(console, '-'); - wprintw(win, " Software: %s", caps->software); - } - if (caps->software_version != NULL) { - wprintw(win, ", %s", caps->software_version); - } - if ((caps->software != NULL) || (caps->software_version != NULL)) { - wprintw(win, "\n"); - } - if (caps->os != NULL) { - win_print_time(console, '-'); - wprintw(win, " OS: %s", caps->os); - } - if (caps->os_version != NULL) { - wprintw(win, ", %s", caps->os_version); - } - if ((caps->os != NULL) || (caps->os_version != NULL)) { - wprintw(win, "\n"); - } - } - } - - ordered_resources = g_list_next(ordered_resources); - } + win_show_info(console, pcontact); if (wins_is_current(console)) { win_update_virtual(console); diff --git a/src/ui/core.c b/src/ui/core.c index 8f946d68..511facfb 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1832,7 +1832,20 @@ _ui_status_room(const char * const contact) win_vprint_line(current, '-', 0, "No such participant \"%s\" in room.", contact); } } +/* +static void +_ui_info_room(const char * const contact) +{ + PContact pcontact = muc_get_participant(ui_current_recipient(), contact); + ProfWin *current = wins_get_current(); + if (pcontact != NULL) { + win_show_info(current, pcontact); + } else { + win_vprint_line(current, '-', 0, "No such participant \"%s\" in room.", contact); + } +} +*/ static gint _ui_unread(void) { diff --git a/src/ui/window.c b/src/ui/window.c index 7237599a..11559421 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -35,6 +35,7 @@ #include "config/theme.h" #include "ui/window.h" +#include "xmpp/xmpp.h" static void _win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, const char * const from, const char * const message); @@ -219,6 +220,135 @@ win_show_contact(ProfWin *window, PContact contact) win_presence_colour_off(window, presence); } +void +win_show_info(ProfWin *window, PContact contact) +{ + const char *barejid = p_contact_barejid(contact); + const char *name = p_contact_name(contact); + const char *presence = p_contact_presence(contact); + const char *sub = p_contact_subscription(contact); + GList *resources = p_contact_get_available_resources(contact); + GList *ordered_resources = NULL; + GDateTime *last_activity = p_contact_last_activity(contact); + WINDOW *win = window->win; + + win_print_time(window, '-'); + wprintw(win, "\n"); + win_print_time(window, '-'); + win_presence_colour_on(window, presence); + wprintw(win, "%s", barejid); + if (name != NULL) { + wprintw(win, " (%s)", name); + } + win_presence_colour_off(window, presence); + wprintw(win, ":\n"); + + if (sub != NULL) { + win_print_time(window, '-'); + wprintw(win, "Subscription: %s\n", sub); + } + + if (last_activity != NULL) { + GDateTime *now = g_date_time_new_now_local(); + GTimeSpan span = g_date_time_difference(now, last_activity); + + win_print_time(window, '-'); + wprintw(win, "Last activity: "); + + int hours = span / G_TIME_SPAN_HOUR; + span = span - hours * G_TIME_SPAN_HOUR; + if (hours > 0) { + wprintw(win, "%dh", hours); + } + + int minutes = span / G_TIME_SPAN_MINUTE; + span = span - minutes * G_TIME_SPAN_MINUTE; + wprintw(win, "%dm", minutes); + + int seconds = span / G_TIME_SPAN_SECOND; + wprintw(win, "%ds", seconds); + + wprintw(win, "\n"); + + g_date_time_unref(now); + } + + if (resources != NULL) { + win_print_time(window, '-'); + wprintw(win, "Resources:\n"); + + // sort in order of availabiltiy + while (resources != NULL) { + Resource *resource = resources->data; + ordered_resources = g_list_insert_sorted(ordered_resources, + resource, (GCompareFunc)resource_compare_availability); + resources = g_list_next(resources); + } + } + + while (ordered_resources != NULL) { + Resource *resource = ordered_resources->data; + const char *resource_presence = string_from_resource_presence(resource->presence); + win_print_time(window, '-'); + win_presence_colour_on(window, 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(window, 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(window, '-'); + wprintw(win, " Identity: "); + if (caps->name != NULL) { + wprintw(win, "%s", caps->name); + if ((caps->category != NULL) || (caps->type != NULL)) { + wprintw(win, " "); + } + } + if (caps->type != NULL) { + wprintw(win, "%s", caps->type); + if (caps->category != NULL) { + wprintw(win, " "); + } + } + if (caps->category != NULL) { + wprintw(win, "%s", caps->category); + } + wprintw(win, "\n"); + } + if (caps->software != NULL) { + win_print_time(window, '-'); + wprintw(win, " Software: %s", caps->software); + } + if (caps->software_version != NULL) { + wprintw(win, ", %s", caps->software_version); + } + if ((caps->software != NULL) || (caps->software_version != NULL)) { + wprintw(win, "\n"); + } + if (caps->os != NULL) { + win_print_time(window, '-'); + wprintw(win, " OS: %s", caps->os); + } + if (caps->os_version != NULL) { + wprintw(win, ", %s", caps->os_version); + } + if ((caps->os != NULL) || (caps->os_version != NULL)) { + wprintw(win, "\n"); + } + } + } + + ordered_resources = g_list_next(ordered_resources); + } +} + void win_show_status_string(ProfWin *window, const char * const from, const char * const show, const char * const status, diff --git a/src/ui/window.h b/src/ui/window.h index 9208e497..4d10874c 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -76,5 +76,6 @@ void win_show_status_string(ProfWin *window, const char * const from, const char * const default_show); void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, const char * const from, const char * const message); +void win_show_info(ProfWin *window, PContact contact); #endif