From 688eea083bd25af39d11b6f993b0d1bf02535959 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:13:35 +0100 Subject: [PATCH] Moved cons_show_status() to console module --- src/ui/console.c | 12 +++++++++ src/ui/window.c | 46 ++++++++++++++++++++++++++++++++ src/ui/window.h | 3 +++ src/ui/windows.c | 68 +++--------------------------------------------- 4 files changed, 65 insertions(+), 64 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 41b189c2..727fb606 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -584,6 +584,18 @@ cons_show_disco_items(GSList *items, const char * const jid) } } +void +cons_show_status(const char * const contact) +{ + PContact pcontact = contact_list_get_contact(contact); + + if (pcontact != NULL) { + window_show_contact(console, pcontact); + } else { + cons_show("No such contact \"%s\" in roster.", contact); + } +} + static void _cons_splash_logo(void) { diff --git a/src/ui/window.c b/src/ui/window.c index d07ce989..01eea071 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -113,3 +113,49 @@ window_presence_colour_off(ProfWin *window, const char * const presence) } } +void +window_show_contact(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 *status = p_contact_status(contact); + GDateTime *last_activity = p_contact_last_activity(contact); + + window_show_time(window, '-'); + window_presence_colour_on(window, presence); + wprintw(window->win, "%s", barejid); + + if (name != NULL) { + wprintw(window->win, " (%s)", name); + } + + wprintw(window->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 "); + + int hours = span / G_TIME_SPAN_HOUR; + span = span - hours * G_TIME_SPAN_HOUR; + if (hours > 0) { + wprintw(window->win, "%dh", hours); + } + + int minutes = span / G_TIME_SPAN_MINUTE; + span = span - minutes * G_TIME_SPAN_MINUTE; + wprintw(window->win, "%dm", minutes); + + int seconds = span / G_TIME_SPAN_SECOND; + wprintw(window->win, "%ds", seconds); + } + + if (status != NULL) { + wprintw(window->win, ", \"%s\"", p_contact_status(contact)); + } + + wprintw(window->win, "\n"); + window_presence_colour_off(window, presence); +} diff --git a/src/ui/window.h b/src/ui/window.h index 2793cd42..5c2e22d5 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -23,6 +23,8 @@ #ifndef WINDOW_H #define WINDOW_H +#include "contact.h" + #define PAD_SIZE 1000 typedef enum { @@ -49,5 +51,6 @@ void window_free(ProfWin *window); void window_show_time(ProfWin *window, char show_char); void window_presence_colour_on(ProfWin *window, const char * const presence); void window_presence_colour_off(ProfWin *window, const char * const presence); +void window_show_contact(ProfWin *window, PContact contact); #endif diff --git a/src/ui/windows.c b/src/ui/windows.c index c8252efa..9ae361f7 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -74,7 +74,6 @@ static GTimer *ui_idle_time; static void _set_current(int index); static void _cons_show_basic_help(void); -static void _win_show_contact(ProfWin *window, PContact contact); static int _find_prof_win_index(const char * const contact); static int _new_prof_win(const char * const contact, win_type_t type); static void _current_window_refresh(void); @@ -1106,18 +1105,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_status(const char * const contact) -{ - PContact pcontact = contact_list_get_contact(contact); - - if (pcontact != NULL) { - _win_show_contact(console, pcontact); - } else { - cons_show("No such contact \"%s\" in roster.", contact); - } -} - void cons_show_room_invite(const char * const invitor, const char * const room, const char * const reason) @@ -1292,7 +1279,7 @@ win_show_status(void) PContact pcontact = contact_list_get_contact(recipient); if (pcontact != NULL) { - _win_show_contact(current, pcontact); + window_show_contact(current, pcontact); } else { win_current_show("Error getting contact info."); } @@ -1306,7 +1293,7 @@ win_private_show_status(void) PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart); if (pcontact != NULL) { - _win_show_contact(current, pcontact); + window_show_contact(current, pcontact); } else { win_current_show("Error getting contact info."); } @@ -1320,7 +1307,7 @@ win_room_show_status(const char * const contact) PContact pcontact = muc_get_participant(win_current_get_recipient(), contact); if (pcontact != NULL) { - _win_show_contact(current, pcontact); + window_show_contact(current, pcontact); } else { win_current_show("No such participant \"%s\" in room.", contact); } @@ -1667,7 +1654,7 @@ cons_show_contacts(GSList *list) while(curr) { PContact contact = curr->data; if (strcmp(p_contact_subscription(contact), "none") != 0) { - _win_show_contact(console, contact); + window_show_contact(console, contact); } curr = g_slist_next(curr); } @@ -2036,53 +2023,6 @@ _cons_show_incoming_message(const char * const short_from, const int win_index) wattroff(console->win, COLOUR_INCOMING); } -static void -_win_show_contact(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 *status = p_contact_status(contact); - GDateTime *last_activity = p_contact_last_activity(contact); - - window_show_time(window, '-'); - window_presence_colour_on(window, presence); - wprintw(window->win, "%s", barejid); - - if (name != NULL) { - wprintw(window->win, " (%s)", name); - } - - wprintw(window->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 "); - - int hours = span / G_TIME_SPAN_HOUR; - span = span - hours * G_TIME_SPAN_HOUR; - if (hours > 0) { - wprintw(window->win, "%dh", hours); - } - - int minutes = span / G_TIME_SPAN_MINUTE; - span = span - minutes * G_TIME_SPAN_MINUTE; - wprintw(window->win, "%dm", minutes); - - int seconds = span / G_TIME_SPAN_SECOND; - wprintw(window->win, "%ds", seconds); - } - - if (status != NULL) { - wprintw(window->win, ", \"%s\"", p_contact_status(contact)); - } - - wprintw(window->win, "\n"); - window_presence_colour_off(window, presence); -} - static void _win_handle_switch(const wint_t * const ch) {