diff options
author | James Booth <boothj5@gmail.com> | 2013-01-20 03:32:51 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-01-20 03:32:51 +0000 |
commit | cae7717e73ccc90ab10bed037744ccb2dea1bd69 (patch) | |
tree | 84e4bb045d5a2d2a04ddd9fc0d00b7cd5ecea8d0 | |
parent | e9695c83aa7ff69782a4a012a9e36fe07c967881 (diff) | |
download | profani-tty-cae7717e73ccc90ab10bed037744ccb2dea1bd69.tar.gz |
Added basic room /info command
-rw-r--r-- | src/command.c | 4 | ||||
-rw-r--r-- | src/ui.h | 1 | ||||
-rw-r--r-- | src/windows.c | 149 |
3 files changed, 90 insertions, 64 deletions
diff --git a/src/command.c b/src/command.c index 7d709315..c4fe9353 100644 --- a/src/command.c +++ b/src/command.c @@ -1424,7 +1424,6 @@ _cmd_who(gchar **args, struct cmd_help_t help) if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); } else { - cons_show(""); char *presence = args[0]; // bad arg @@ -1519,6 +1518,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) // not in groupchat window } else { + cons_show(""); GSList *list = get_contact_list(); // no arg, show all contacts @@ -1674,7 +1674,7 @@ _cmd_info(gchar **args, struct cmd_help_t help) } else { if (win_current_is_groupchat()) { if (usr != NULL) { - win_room_show_status(usr); + win_room_show_info(usr); } else { win_current_show("You must specify a nickname."); } diff --git a/src/ui.h b/src/ui.h index eb528e67..9dc9cb4e 100644 --- a/src/ui.h +++ b/src/ui.h @@ -133,6 +133,7 @@ void win_show_room_nick_change(const char * const room, const char * const nick) void win_show_room_member_presence(const char * const room, const char * const nick, const char * const show, const char * const status); void win_room_show_status(const char * const contact); +void win_room_show_info(const char * const contact); void win_show_status(void); void win_private_show_status(void); diff --git a/src/windows.c b/src/windows.c index b08ccd82..c3aa14ec 100644 --- a/src/windows.c +++ b/src/windows.c @@ -110,6 +110,7 @@ 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); @@ -1149,74 +1150,25 @@ cons_show_wins(void) } void -cons_show_info(const char * const contact) +win_room_show_info(const char * const contact) { - PContact pcontact = contact_list_get_contact(contact); + PContact pcontact = muc_get_participant(win_current_get_recipient(), contact); if (pcontact != NULL) { - 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); - - cons_show(""); - _win_show_time(console->win, '-'); - _presence_colour_on(console->win, presence); - wprintw(console->win, "%s:\n", jid); - _presence_colour_off(console->win, presence); - - if (name != NULL) { - cons_show("Name : %s", name); - } - - if (sub != NULL) { - cons_show("Subscription : %s", sub); - } - - _win_show_time(console->win, '-'); - wprintw(console->win, "Presence : "); - _presence_colour_on(console->win, presence); - wprintw(console->win, "%s\n", presence); - _presence_colour_off(console->win, presence); - - if (status != NULL) { - cons_show("Message : %s", 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(console->win, '-'); - wprintw(console->win, "Last activity : "); - - int hours = span / G_TIME_SPAN_HOUR; - span = span - hours * G_TIME_SPAN_HOUR; - if (hours > 0) { - wprintw(console->win, "%dh", hours); - } - - int minutes = span / G_TIME_SPAN_MINUTE; - span = span - minutes * G_TIME_SPAN_MINUTE; - wprintw(console->win, "%dm", minutes); - - int seconds = span / G_TIME_SPAN_SECOND; - wprintw(console->win, "%ds", seconds); + _win_show_info(current->win, pcontact); + } else { + win_current_show("No such participant \"%s\" in room.", contact); + } - wprintw(console->win, "\n"); +} - g_date_time_unref(now); - } +void +cons_show_info(const char * const contact) +{ + PContact pcontact = contact_list_get_contact(contact); - if (caps_str != NULL) { - Capabilities *caps = caps_get(caps_str); - if ((caps != NULL) && (caps->client != NULL)) { - cons_show("Client : %s", caps->client); - } - } + if (pcontact != NULL) { + _win_show_info(console->win, pcontact); } else { cons_show("No such contact \"%s\" in roster.", contact); } @@ -2382,6 +2334,79 @@ _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) { |