diff options
Diffstat (limited to 'src/windows.c')
-rw-r--r-- | src/windows.c | 187 |
1 files changed, 130 insertions, 57 deletions
diff --git a/src/windows.c b/src/windows.c index c56ceb70..da4b664f 100644 --- a/src/windows.c +++ b/src/windows.c @@ -44,6 +44,7 @@ #include <ncurses.h> #endif +#include "capabilities.h" #include "chat_log.h" #include "chat_session.h" #include "command.h" @@ -109,8 +110,11 @@ static void _win_resize_all(void); static gint _win_get_unread(void); static void _win_show_history(WINDOW *win, int win_index, const char * const contact); +static void _win_show_info(WINDOW *win, PContact pcontact); static gboolean _new_release(char *found_version); static void _ui_draw_win_title(void); +static void _presence_colour_on(WINDOW *win, const char * const presence); +static void _presence_colour_off(WINDOW *win, const char * const presence); static void _notify(const char * const message, int timeout, const char * const category); @@ -850,35 +854,9 @@ win_show_room_roster(const char * const room, GList *roster, const char * const const char const *name = p_contact_jid(member); const char const *show = p_contact_presence(member); - if (strcmp(show, "away") == 0) { - wattron(win, COLOUR_AWAY); - } else if (strcmp(show, "chat") == 0) { - wattron(win, COLOUR_CHAT); - } else if (strcmp(show, "dnd") == 0) { - wattron(win, COLOUR_DND); - } else if (strcmp(show, "xa") == 0) { - wattron(win, COLOUR_XA); - } else if (strcmp(show, "online") == 0) { - wattron(win, COLOUR_ONLINE); - } else { - wattron(win, COLOUR_OFFLINE); - } - + _presence_colour_on(win, show); wprintw(win, "%s", name); - - if (strcmp(show, "away") == 0) { - wattroff(win, COLOUR_AWAY); - } else if (strcmp(show, "chat") == 0) { - wattroff(win, COLOUR_CHAT); - } else if (strcmp(show, "dnd") == 0) { - wattroff(win, COLOUR_DND); - } else if (strcmp(show, "xa") == 0) { - wattroff(win, COLOUR_XA); - } else if (strcmp(show, "online") == 0) { - wattroff(win, COLOUR_ONLINE); - } else { - wattroff(win, COLOUR_OFFLINE); - } + _presence_colour_off(win, show); if (roster->next != NULL) { wprintw(win, ", "); @@ -1181,6 +1159,18 @@ cons_show_wins(void) } void +cons_show_info(PContact pcontact) +{ + _win_show_info(console->win, pcontact); + + if (current_index == 0) { + dirty = TRUE; + } else { + status_bar_new(0); + } +} + +void cons_show_status(const char * const contact) { PContact pcontact = contact_list_get_contact(contact); @@ -2035,6 +2025,42 @@ _win_resize_all(void) } static void +_presence_colour_on(WINDOW *win, const char * const presence) +{ + if (g_strcmp0(presence, "online") == 0) { + wattron(win, COLOUR_ONLINE); + } else if (g_strcmp0(presence, "away") == 0) { + wattron(win, COLOUR_AWAY); + } else if (g_strcmp0(presence, "chat") == 0) { + wattron(win, COLOUR_CHAT); + } else if (g_strcmp0(presence, "dnd") == 0) { + wattron(win, COLOUR_DND); + } else if (g_strcmp0(presence, "xa") == 0) { + wattron(win, COLOUR_XA); + } else { + wattron(win, COLOUR_OFFLINE); + } +} + +static void +_presence_colour_off(WINDOW *win, const char * const presence) +{ + if (g_strcmp0(presence, "online") == 0) { + wattroff(win, COLOUR_ONLINE); + } else if (g_strcmp0(presence, "away") == 0) { + wattroff(win, COLOUR_AWAY); + } else if (g_strcmp0(presence, "chat") == 0) { + wattroff(win, COLOUR_CHAT); + } else if (g_strcmp0(presence, "dnd") == 0) { + wattroff(win, COLOUR_DND); + } else if (g_strcmp0(presence, "xa") == 0) { + wattroff(win, COLOUR_XA); + } else { + wattroff(win, COLOUR_OFFLINE); + } +} + +static void _show_status_string(WINDOW *win, const char * const from, const char * const show, const char * const status, GDateTime *last_activity, const char * const pre, @@ -2146,21 +2172,7 @@ _win_show_contact(ProfWin *window, PContact contact) GDateTime *last_activity = p_contact_last_activity(contact); _win_show_time(window->win, '-'); - - if (strcmp(presence, "online") == 0) { - wattron(window->win, COLOUR_ONLINE); - } else if (strcmp(presence, "away") == 0) { - wattron(window->win, COLOUR_AWAY); - } else if (strcmp(presence, "chat") == 0) { - wattron(window->win, COLOUR_CHAT); - } else if (strcmp(presence, "dnd") == 0) { - wattron(window->win, COLOUR_DND); - } else if (strcmp(presence, "xa") == 0) { - wattron(window->win, COLOUR_XA); - } else { - wattron(window->win, COLOUR_OFFLINE); - } - + _presence_colour_on(window->win, presence); wprintw(window->win, "%s", jid); if (name != NULL) { @@ -2194,20 +2206,7 @@ _win_show_contact(ProfWin *window, PContact contact) } wprintw(window->win, "\n"); - - if (strcmp(presence, "online") == 0) { - wattroff(window->win, COLOUR_ONLINE); - } else if (strcmp(presence, "away") == 0) { - wattroff(window->win, COLOUR_AWAY); - } else if (strcmp(presence, "chat") == 0) { - wattroff(window->win, COLOUR_CHAT); - } else if (strcmp(presence, "dnd") == 0) { - wattroff(window->win, COLOUR_DND); - } else if (strcmp(presence, "xa") == 0) { - wattroff(window->win, COLOUR_XA); - } else { - wattroff(window->win, COLOUR_OFFLINE); - } + _presence_colour_off(window->win, presence); } static void @@ -2339,6 +2338,80 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact) } } +static void +_win_show_info(WINDOW *win, PContact pcontact) +{ + const char *jid = p_contact_jid(pcontact); + const char *name = p_contact_name(pcontact); + const char *presence = p_contact_presence(pcontact); + const char *status = p_contact_status(pcontact); + const char *sub = p_contact_subscription(pcontact); + const char *caps_str = p_contact_caps_str(pcontact); + GDateTime *last_activity = p_contact_last_activity(pcontact); + + _win_show_time(win, '-'); + wprintw(win, "\n"); + _win_show_time(win, '-'); + _presence_colour_on(win, presence); + wprintw(win, "%s:\n", jid); + _presence_colour_off(win, presence); + + if (name != NULL) { + _win_show_time(win, '-'); + wprintw(win, "Name : %s\n", name); + } + + if (sub != NULL) { + _win_show_time(win, '-'); + wprintw(win, "Subscription : %s\n", sub); + } + + _win_show_time(win, '-'); + wprintw(win, "Presence : "); + _presence_colour_on(win, presence); + wprintw(win, "%s\n", presence); + _presence_colour_off(win, presence); + + if (status != NULL) { + _win_show_time(win, '-'); + wprintw(win, "Message : %s\n", status); + } + + if (last_activity != NULL) { + GDateTime *now = g_date_time_new_now_local(); + GTimeSpan span = g_date_time_difference(now, last_activity); + + _win_show_time(win, '-'); + 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 (caps_str != NULL) { + Capabilities *caps = caps_get(caps_str); + if ((caps != NULL) && (caps->client != NULL)) { + _win_show_time(win, '-'); + wprintw(win, "Client : %s\n", caps->client); + } + } + +} + void _set_current(int index) { |