diff options
author | James Booth <boothj5@gmail.com> | 2014-07-22 23:37:21 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-07-22 23:37:21 +0100 |
commit | 3eaebeb002cc2df579e9fd075a2e1a56938bc7e3 (patch) | |
tree | 07b66683f4636c581ab986c9b67b8a7d2f9d229d | |
parent | 79c857fb2a1290d9b70cf3acacc7fbe6a194458c (diff) | |
parent | 9123675c9c203fcf21f86ec49043fa58d63bea5e (diff) | |
download | profani-tty-3eaebeb002cc2df579e9fd075a2e1a56938bc7e3.tar.gz |
Merge branch 'master' into winbuffers
-rw-r--r-- | src/command/commands.c | 449 |
1 files changed, 261 insertions, 188 deletions
diff --git a/src/command/commands.c b/src/command/commands.c index 3e7dffd9..be6f4dfb 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -61,6 +61,8 @@ static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, static int _strtoi(char *str, int *saveptr, int min, int max); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); static gint _compare_commands(Command *a, Command *b); +static void _who_room(const char * const presence); +static void _who_roster(const char * const group, const char * const presence); extern GHashTable *commands; @@ -711,234 +713,305 @@ cmd_theme(gchar **args, struct cmd_help_t help) return TRUE; } -gboolean -cmd_who(gchar **args, struct cmd_help_t help) +static void +_who_room(const char * const presence) { - jabber_conn_status_t conn_status = jabber_get_connection_status(); - win_type_t win_type = ui_current_win_type(); + char *room = ui_current_recipient(); + GList *list = muc_get_roster(room); - if (conn_status != JABBER_CONNECTED) { - cons_show("You are not currently connected."); - } else { - char *presence = args[0]; - char *group = NULL; - if ((g_strv_length(args) == 2) && (args[1] != NULL)) { - group = args[1]; - } + // no arg, show all contacts + if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { + ui_room_roster(room, list, NULL); - // bad arg - if ((presence != NULL) - && (strcmp(presence, "online") != 0) - && (strcmp(presence, "available") != 0) - && (strcmp(presence, "unavailable") != 0) - && (strcmp(presence, "offline") != 0) - && (strcmp(presence, "away") != 0) - && (strcmp(presence, "chat") != 0) - && (strcmp(presence, "xa") != 0) - && (strcmp(presence, "dnd") != 0) - && (strcmp(presence, "any") != 0)) { - cons_show("Usage: %s", help.usage); + // available + } else if (strcmp("available", presence) == 0) { + GList *filtered = NULL; - // valid arg - } else { - if (win_type == WIN_MUC) { - if (group != NULL) { - cons_show("The group argument is not valid when in a chat room."); - return TRUE; - } + while (list != NULL) { + PContact contact = list->data; + if (p_contact_is_available(contact)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } - char *room = ui_current_recipient(); - GList *list = muc_get_roster(room); + ui_room_roster(room, filtered, "available"); - // no arg, show all contacts - if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { - ui_room_roster(room, list, NULL); + // unavailable + } else if (strcmp("unavailable", presence) == 0) { + GList *filtered = NULL; - // available - } else if (strcmp("available", presence) == 0) { - GList *filtered = NULL; + while (list != NULL) { + PContact contact = list->data; + if (!p_contact_is_available(contact)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } - while (list != NULL) { - PContact contact = list->data; - if (p_contact_is_available(contact)) { - filtered = g_list_append(filtered, contact); - } - list = g_list_next(list); - } + ui_room_roster(room, filtered, "unavailable"); - ui_room_roster(room, filtered, "available"); + // online, available resources + } else if (strcmp("online", presence) == 0) { + GList *filtered = NULL; - // unavailable - } else if (strcmp("unavailable", presence) == 0) { - GList *filtered = NULL; + while (list != NULL) { + PContact contact = list->data; + if (p_contact_has_available_resource(contact)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } - while (list != NULL) { - PContact contact = list->data; - if (!p_contact_is_available(contact)) { - filtered = g_list_append(filtered, contact); - } - list = g_list_next(list); - } + ui_room_roster(room, filtered, "online"); - ui_room_roster(room, filtered, "unavailable"); + // offline, no available resources + } else if (strcmp("offline", presence) == 0) { + GList *filtered = NULL; - // online, available resources - } else if (strcmp("online", presence) == 0) { - GList *filtered = NULL; + while (list != NULL) { + PContact contact = list->data; + if (!p_contact_has_available_resource(contact)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } - while (list != NULL) { - PContact contact = list->data; - if (p_contact_has_available_resource(contact)) { - filtered = g_list_append(filtered, contact); - } - list = g_list_next(list); - } + ui_room_roster(room, filtered, "offline"); - ui_room_roster(room, filtered, "online"); + // show specific status + } else { + GList *filtered = NULL; - // offline, no available resources - } else if (strcmp("offline", presence) == 0) { - GList *filtered = NULL; + while (list != NULL) { + PContact contact = list->data; + if (strcmp(p_contact_presence(contact), presence) == 0) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } - while (list != NULL) { - PContact contact = list->data; - if (!p_contact_has_available_resource(contact)) { - filtered = g_list_append(filtered, contact); - } - list = g_list_next(list); - } + ui_room_roster(room, filtered, presence); + } +} - ui_room_roster(room, filtered, "offline"); +static void +_who_roster(const char * const group, const char * const presence) +{ + cons_show(""); + GSList *list = NULL; + if (group != NULL) { + list = roster_get_group(group); + if (list == NULL) { + cons_show("No such group: %s.", group); + return; + } + } else { + list = roster_get_contacts(); + if (list == NULL) { + cons_show("No contacts in roster."); + return; + } + } - // show specific status - } else { - GList *filtered = NULL; + // no arg, show all contacts + if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { + if (group != NULL) { + if (list == NULL) { + cons_show("No contacts in group %s.", group); + } else { + cons_show("%s:", group); + cons_show_contacts(list); + } + } else { + if (list == NULL) { + cons_show("You have no contacts."); + } else { + cons_show("All contacts:"); + cons_show_contacts(list); + } + } - while (list != NULL) { - PContact contact = list->data; - if (strcmp(p_contact_presence(contact), presence) == 0) { - filtered = g_list_append(filtered, contact); - } - list = g_list_next(list); - } + // available + } else if (strcmp("available", presence) == 0) { + GSList *filtered = NULL; - ui_room_roster(room, filtered, presence); - } + while (list != NULL) { + PContact contact = list->data; + if (p_contact_is_available(contact)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } - // not in groupchat window + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); } else { - cons_show(""); - GSList *list = NULL; - if (group != NULL) { - list = roster_get_group(group); - } else { - list = roster_get_contacts(); - } + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } - // no arg, show all contacts - if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { - if (group != NULL) { - cons_show("%s:", group); - } else { - cons_show("All contacts:"); - } - cons_show_contacts(list); + // unavailable + } else if (strcmp("unavailable", presence) == 0) { + GSList *filtered = NULL; - // available - } else if (strcmp("available", presence) == 0) { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } - GSList *filtered = NULL; + while (list != NULL) { + PContact contact = list->data; + if (!p_contact_is_available(contact)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } - while (list != NULL) { - PContact contact = list->data; - if (p_contact_is_available(contact)) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } - cons_show_contacts(filtered); + // online, available resources + } else if (strcmp("online", presence) == 0) { + GSList *filtered = NULL; - // unavailable - } else if (strcmp("unavailable", presence) == 0) { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } - GSList *filtered = NULL; + while (list != NULL) { + PContact contact = list->data; + if (p_contact_has_available_resource(contact)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } - while (list != NULL) { - PContact contact = list->data; - if (!p_contact_is_available(contact)) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } - cons_show_contacts(filtered); + // offline, no available resources + } else if (strcmp("offline", presence) == 0) { + GSList *filtered = NULL; - // online, available resources - } else if (strcmp("online", presence) == 0) { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } - GSList *filtered = NULL; + while (list != NULL) { + PContact contact = list->data; + if (!p_contact_has_available_resource(contact)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } - while (list != NULL) { - PContact contact = list->data; - if (p_contact_has_available_resource(contact)) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } - cons_show_contacts(filtered); + // show specific status + } else { + GSList *filtered = NULL; - // offline, no available resources - } else if (strcmp("offline", presence) == 0) { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } - GSList *filtered = NULL; + while (list != NULL) { + PContact contact = list->data; + if (strcmp(p_contact_presence(contact), presence) == 0) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } - while (list != NULL) { - PContact contact = list->data; - if (!p_contact_has_available_resource(contact)) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } + } +} - cons_show_contacts(filtered); +gboolean +cmd_who(gchar **args, struct cmd_help_t help) +{ + jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); - // show specific status - } else { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } - GSList *filtered = NULL; + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); + } else { + char *presence = args[0]; + char *group = NULL; + if ((g_strv_length(args) == 2) && (args[1] != NULL)) { + group = args[1]; + } - while (list != NULL) { - PContact contact = list->data; - if (strcmp(p_contact_presence(contact), presence) == 0) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } + // bad arg + if ((presence != NULL) + && (strcmp(presence, "online") != 0) + && (strcmp(presence, "available") != 0) + && (strcmp(presence, "unavailable") != 0) + && (strcmp(presence, "offline") != 0) + && (strcmp(presence, "away") != 0) + && (strcmp(presence, "chat") != 0) + && (strcmp(presence, "xa") != 0) + && (strcmp(presence, "dnd") != 0) + && (strcmp(presence, "any") != 0)) { + cons_show("Usage: %s", help.usage); - cons_show_contacts(filtered); + } else { + if (win_type == WIN_MUC) { + if (group != NULL) { + cons_show("The group argument is not valid when in a chat room."); + } else { + _who_room(presence); } + + } else { + _who_roster(group, presence); } } } |