diff options
-rw-r--r-- | src/command.c | 66 | ||||
-rw-r--r-- | src/ui.h | 2 | ||||
-rw-r--r-- | src/windows.c | 77 |
3 files changed, 101 insertions, 44 deletions
diff --git a/src/command.c b/src/command.c index 524c6c04..45f4f00c 100644 --- a/src/command.c +++ b/src/command.c @@ -27,6 +27,7 @@ #include "command.h" #include "common.h" +#include "contact.h" #include "contact_list.h" #include "chat_log.h" #include "history.h" @@ -558,8 +559,69 @@ _cmd_who(const char * const inp, struct cmd_help_t help) if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); } else { - GSList *list = get_contact_list(); - cons_show_online_contacts(list); + // copy input + char inp_cpy[strlen(inp) + 1]; + strcpy(inp_cpy, inp); + + // get show + strtok(inp_cpy, " "); + char *show = strtok(NULL, " "); + + // bad arg + if ((show != NULL) + && (strcmp(show, "online") != 0) + && (strcmp(show, "offline") != 0) + && (strcmp(show, "away") != 0) + && (strcmp(show, "chat") != 0) + && (strcmp(show, "xa") != 0) + && (strcmp(show, "dnd") != 0)) { + cons_show("Usage: %s", help.usage); + + // valid arg + } else { + GSList *list = get_contact_list(); + + // no arg, show all contacts + if (show == NULL) { + cons_show("All contacts:"); + cons_show_contacts(list); + + // online, show all status that indicate online + } else if (strcmp("online", show) == 0) { + cons_show("Contacts (%s):", show); + GSList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + const char * const contact_show = (p_contact_show(contact)); + if ((strcmp(contact_show, "online") == 0) + || (strcmp(contact_show, "away") == 0) + || (strcmp(contact_show, "dnd") == 0) + || (strcmp(contact_show, "xa") == 0) + || (strcmp(contact_show, "chat") == 0)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } + + cons_show_contacts(filtered); + + // show specific status + } else { + cons_show("Contacts (%s):", show); + GSList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (strcmp(p_contact_show(contact), show) == 0) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } + + cons_show_contacts(filtered); + } + } } return TRUE; diff --git a/src/ui.h b/src/ui.h index 08c6bee9..df1eab66 100644 --- a/src/ui.h +++ b/src/ui.h @@ -107,7 +107,7 @@ void cons_bad_command(const char * const cmd); void cons_show(const char * const cmd, ...); void cons_bad_show(const char * const cmd); void cons_highlight_show(const char * const cmd); -void cons_show_online_contacts(GSList * list); +void cons_show_contacts(GSList * list); // status bar actions void status_bar_refresh(void); diff --git a/src/windows.c b/src/windows.c index fca84286..724a904f 100644 --- a/src/windows.c +++ b/src/windows.c @@ -554,55 +554,50 @@ cons_help(void) } void -cons_show_online_contacts(GSList *list) +cons_show_contacts(GSList *list) { - _win_show_time(_cons_win); - wprintw(_cons_win, "Online contacts:\n"); - GSList *curr = list; while(curr) { PContact contact = curr->data; const char *show = p_contact_show(contact); - if (strcmp(show, "offline") != 0) { - _win_show_time(_cons_win); - - if (strcmp(show, "online") == 0) { - wattron(_cons_win, COLOUR_ONLINE); - } else if (strcmp(show, "away") == 0) { - wattron(_cons_win, COLOUR_AWAY); - } else if (strcmp(show, "chat") == 0) { - wattron(_cons_win, COLOUR_CHAT); - } else if (strcmp(show, "dnd") == 0) { - wattron(_cons_win, COLOUR_DND); - } else if (strcmp(show, "xa") == 0) { - wattron(_cons_win, COLOUR_XA); - } else { - wattron(_cons_win, COLOUR_OFFLINE); - } + _win_show_time(_cons_win); - wprintw(_cons_win, "%s", p_contact_name(contact)); - wprintw(_cons_win, " is %s", show); - - if (p_contact_status(contact)) - wprintw(_cons_win, ", \"%s\"", p_contact_status(contact)); - - wprintw(_cons_win, "\n"); - - if (strcmp(show, "online") == 0) { - wattroff(_cons_win, COLOUR_ONLINE); - } else if (strcmp(show, "away") == 0) { - wattroff(_cons_win, COLOUR_AWAY); - } else if (strcmp(show, "chat") == 0) { - wattroff(_cons_win, COLOUR_CHAT); - } else if (strcmp(show, "dnd") == 0) { - wattroff(_cons_win, COLOUR_DND); - } else if (strcmp(show, "xa") == 0) { - wattroff(_cons_win, COLOUR_XA); - } else { - wattroff(_cons_win, COLOUR_OFFLINE); - } + if (strcmp(show, "online") == 0) { + wattron(_cons_win, COLOUR_ONLINE); + } else if (strcmp(show, "away") == 0) { + wattron(_cons_win, COLOUR_AWAY); + } else if (strcmp(show, "chat") == 0) { + wattron(_cons_win, COLOUR_CHAT); + } else if (strcmp(show, "dnd") == 0) { + wattron(_cons_win, COLOUR_DND); + } else if (strcmp(show, "xa") == 0) { + wattron(_cons_win, COLOUR_XA); + } else { + wattron(_cons_win, COLOUR_OFFLINE); + } + + wprintw(_cons_win, "%s", p_contact_name(contact)); + wprintw(_cons_win, " is %s", show); + + if (p_contact_status(contact)) + wprintw(_cons_win, ", \"%s\"", p_contact_status(contact)); + + wprintw(_cons_win, "\n"); + + if (strcmp(show, "online") == 0) { + wattroff(_cons_win, COLOUR_ONLINE); + } else if (strcmp(show, "away") == 0) { + wattroff(_cons_win, COLOUR_AWAY); + } else if (strcmp(show, "chat") == 0) { + wattroff(_cons_win, COLOUR_CHAT); + } else if (strcmp(show, "dnd") == 0) { + wattroff(_cons_win, COLOUR_DND); + } else if (strcmp(show, "xa") == 0) { + wattroff(_cons_win, COLOUR_XA); + } else { + wattroff(_cons_win, COLOUR_OFFLINE); } curr = g_slist_next(curr); |