about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-10-04 22:43:22 +0100
committerJames Booth <boothj5@gmail.com>2014-10-04 22:43:22 +0100
commit719dbfaacc79fe56da8dcf1d9c9711c0de26f2bf (patch)
tree3defee75f891d5aed10353cf4d2430ddf51affe0 /src/command
parent2d05601259816894aef524bc3f60463a28b5de46 (diff)
downloadprofani-tty-719dbfaacc79fe56da8dcf1d9c9711c0de26f2bf.tar.gz
Split autocompleters for roster and rooms
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c74
-rw-r--r--src/command/commands.c184
2 files changed, 157 insertions, 101 deletions
diff --git a/src/command/command.c b/src/command/command.c
index cc373ef7..7748b1f6 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -937,7 +937,8 @@ static struct cmd_t command_defs[] =
 };
 
 static Autocomplete commands_ac;
-static Autocomplete who_ac;
+static Autocomplete who_room_ac;
+static Autocomplete who_roster_ac;
 static Autocomplete help_ac;
 static Autocomplete notify_ac;
 static Autocomplete notify_room_ac;
@@ -1152,16 +1153,32 @@ cmd_init(void)
 
     theme_load_ac = NULL;
 
-    who_ac = autocomplete_new();
-    autocomplete_add(who_ac, "chat");
-    autocomplete_add(who_ac, "online");
-    autocomplete_add(who_ac, "away");
-    autocomplete_add(who_ac, "xa");
-    autocomplete_add(who_ac, "dnd");
-    autocomplete_add(who_ac, "offline");
-    autocomplete_add(who_ac, "available");
-    autocomplete_add(who_ac, "unavailable");
-    autocomplete_add(who_ac, "any");
+    who_roster_ac = autocomplete_new();
+    autocomplete_add(who_roster_ac, "chat");
+    autocomplete_add(who_roster_ac, "online");
+    autocomplete_add(who_roster_ac, "away");
+    autocomplete_add(who_roster_ac, "xa");
+    autocomplete_add(who_roster_ac, "dnd");
+    autocomplete_add(who_roster_ac, "offline");
+    autocomplete_add(who_roster_ac, "available");
+    autocomplete_add(who_roster_ac, "unavailable");
+    autocomplete_add(who_roster_ac, "any");
+
+    who_room_ac = autocomplete_new();
+    autocomplete_add(who_room_ac, "chat");
+    autocomplete_add(who_room_ac, "online");
+    autocomplete_add(who_room_ac, "away");
+    autocomplete_add(who_room_ac, "xa");
+    autocomplete_add(who_room_ac, "dnd");
+    autocomplete_add(who_room_ac, "available");
+    autocomplete_add(who_room_ac, "unavailable");
+    autocomplete_add(who_room_ac, "moderator");
+    autocomplete_add(who_room_ac, "participant");
+    autocomplete_add(who_room_ac, "visitor");
+    autocomplete_add(who_room_ac, "owner");
+    autocomplete_add(who_room_ac, "admin");
+    autocomplete_add(who_room_ac, "member");
+    autocomplete_add(who_room_ac, "outcast");
 
     bookmark_ac = autocomplete_new();
     autocomplete_add(bookmark_ac, "list");
@@ -1253,7 +1270,8 @@ void
 cmd_uninit(void)
 {
     autocomplete_free(commands_ac);
-    autocomplete_free(who_ac);
+    autocomplete_free(who_room_ac);
+    autocomplete_free(who_roster_ac);
     autocomplete_free(help_ac);
     autocomplete_free(notify_ac);
     autocomplete_free(notify_message_ac);
@@ -1381,7 +1399,8 @@ cmd_reset_autocomplete()
         muc_autocomplete_reset(recipient);
     }
 
-    autocomplete_reset(who_ac);
+    autocomplete_reset(who_room_ac);
+    autocomplete_reset(who_roster_ac);
     autocomplete_reset(prefs_ac);
     autocomplete_reset(log_ac);
     autocomplete_reset(commands_ac);
@@ -1753,22 +1772,31 @@ _sub_autocomplete(char *input, int *size)
 static char *
 _who_autocomplete(char *input, int *size)
 {
-    int i = 0;
     char *result = NULL;
-    gchar *group_commands[] = { "/who any", "/who online", "/who offline",
-        "/who chat", "/who away", "/who xa", "/who dnd", "/who available",
-        "/who unavailable" };
+    win_type_t win_type = ui_current_win_type();
 
-    for (i = 0; i < ARRAY_SIZE(group_commands); i++) {
-        result = autocomplete_param_with_func(input, size, group_commands[i], roster_find_group);
+    if (win_type == WIN_MUC) {
+        result = autocomplete_param_with_ac(input, size, "/who", who_room_ac, TRUE);
         if (result != NULL) {
             return result;
         }
-    }
+    } else {
+        int i = 0;
+        gchar *group_commands[] = { "/who any", "/who online", "/who offline",
+            "/who chat", "/who away", "/who xa", "/who dnd", "/who available",
+            "/who unavailable" };
 
-    result = autocomplete_param_with_ac(input, size, "/who", who_ac, TRUE);
-    if (result != NULL) {
-        return result;
+        for (i = 0; i < ARRAY_SIZE(group_commands); i++) {
+            result = autocomplete_param_with_func(input, size, group_commands[i], roster_find_group);
+            if (result != NULL) {
+                return result;
+            }
+        }
+
+        result = autocomplete_param_with_ac(input, size, "/who", who_roster_ac, TRUE);
+        if (result != NULL) {
+            return result;
+        }
     }
 
     return NULL;
diff --git a/src/command/commands.c b/src/command/commands.c
index 10b90310..6f962ce2 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -725,75 +725,128 @@ cmd_theme(gchar **args, struct cmd_help_t help)
 static void
 _who_room(gchar **args, struct cmd_help_t help)
 {
-    char *presence = args[0];
     if ((g_strv_length(args) == 2) && (args[1] != NULL)) {
         cons_show("Argument group is not applicable to chat rooms.");
         return;
     }
 
     // bad arg
-    if ((presence != NULL)
-            && (strcmp(presence, "online") != 0)
-            && (strcmp(presence, "available") != 0)
-            && (strcmp(presence, "unavailable") != 0)
-            && (strcmp(presence, "away") != 0)
-            && (strcmp(presence, "chat") != 0)
-            && (strcmp(presence, "xa") != 0)
-            && (strcmp(presence, "dnd") != 0)
-            && (strcmp(presence, "any") != 0)) {
+    if (args[0] != NULL &&
+            (g_strcmp0(args[0], "online") != 0) &&
+            (g_strcmp0(args[0], "available") != 0) &&
+            (g_strcmp0(args[0], "unavailable") != 0) &&
+            (g_strcmp0(args[0], "away") != 0) &&
+            (g_strcmp0(args[0], "chat") != 0) &&
+            (g_strcmp0(args[0], "xa") != 0) &&
+            (g_strcmp0(args[0], "dnd") != 0) &&
+            (g_strcmp0(args[0], "any") != 0) &&
+            (g_strcmp0(args[0], "moderator") != 0) &&
+            (g_strcmp0(args[0], "participant") != 0) &&
+            (g_strcmp0(args[0], "visitor") != 0) &&
+            (g_strcmp0(args[0], "owner") != 0) &&
+            (g_strcmp0(args[0], "admin") != 0) &&
+            (g_strcmp0(args[0], "member") != 0) &&
+            (g_strcmp0(args[0], "outcast") != 0)) {
         cons_show("Usage: %s", help.usage);
         return;
     }
 
     char *room = ui_current_recipient();
-    GList *list = muc_roster(room);
 
-    // no arg, show all contacts
-    if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
-        ui_room_roster(room, list, NULL);
+    // presence filter
+    if (args[0] == NULL ||
+            (g_strcmp0(args[0], "online") == 0) ||
+            (g_strcmp0(args[0], "available") == 0) ||
+            (g_strcmp0(args[0], "unavailable") == 0) ||
+            (g_strcmp0(args[0], "away") == 0) ||
+            (g_strcmp0(args[0], "chat") == 0) ||
+            (g_strcmp0(args[0], "xa") == 0) ||
+            (g_strcmp0(args[0], "dnd") == 0) ||
+            (g_strcmp0(args[0], "any") == 0)) {
+
+        char *presence = args[0];
+        GList *list = muc_roster(room);
+
+        // no arg, show all contacts
+        if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
+            ui_room_roster(room, list, NULL);
+
+        // available
+        } else if (strcmp("available", presence) == 0) {
+            GList *filtered = NULL;
+
+            while (list != NULL) {
+                Occupant *occupant = list->data;
+                if (muc_occupant_available(occupant)) {
+                    filtered = g_list_append(filtered, occupant);
+                }
+                list = g_list_next(list);
+            }
 
-    // available
-    } else if (strcmp("available", presence) == 0) {
-        GList *filtered = NULL;
+            ui_room_roster(room, filtered, "available");
 
-        while (list != NULL) {
-            Occupant *occupant = list->data;
-            if (muc_occupant_available(occupant)) {
-                filtered = g_list_append(filtered, occupant);
+        // unavailable
+        } else if (strcmp("unavailable", presence) == 0) {
+            GList *filtered = NULL;
+
+            while (list != NULL) {
+                Occupant *occupant = list->data;
+                if (!muc_occupant_available(occupant)) {
+                    filtered = g_list_append(filtered, occupant);
+                }
+                list = g_list_next(list);
             }
-            list = g_list_next(list);
-        }
 
-        ui_room_roster(room, filtered, "available");
+            ui_room_roster(room, filtered, "unavailable");
 
-    // unavailable
-    } else if (strcmp("unavailable", presence) == 0) {
-        GList *filtered = NULL;
+        // show specific status
+        } else {
+            GList *filtered = NULL;
 
-        while (list != NULL) {
-            Occupant *occupant = list->data;
-            if (!muc_occupant_available(occupant)) {
-                filtered = g_list_append(filtered, occupant);
+            while (list != NULL) {
+                Occupant *occupant = list->data;
+                const char *presence_str = string_from_resource_presence(occupant->presence);
+                if (strcmp(presence_str, presence) == 0) {
+                    filtered = g_list_append(filtered, occupant);
+                }
+                list = g_list_next(list);
             }
-            list = g_list_next(list);
-        }
 
-        ui_room_roster(room, filtered, "unavailable");
+            ui_room_roster(room, filtered, presence);
+        }
 
-    // show specific status
+    // role or affiliation filter
     } else {
-        GList *filtered = NULL;
-
-        while (list != NULL) {
-            Occupant *occupant = list->data;
-            const char *presence_str = string_from_resource_presence(occupant->presence);
-            if (strcmp(presence_str, presence) == 0) {
-                filtered = g_list_append(filtered, occupant);
-            }
-            list = g_list_next(list);
+        ProfWin *window = wins_get_by_recipient(room);
+        if (g_strcmp0(args[0], "moderator") == 0) {
+            ui_show_room_role_list(window, room, MUC_ROLE_MODERATOR);
+            return;
+        }
+        if (g_strcmp0(args[0], "participant") == 0) {
+            ui_show_room_role_list(window, room, MUC_ROLE_PARTICIPANT);
+            return;
+        }
+        if (g_strcmp0(args[0], "visitor") == 0) {
+            ui_show_room_role_list(window, room, MUC_ROLE_VISITOR);
+            return;
         }
 
-        ui_room_roster(room, filtered, presence);
+        if (g_strcmp0(args[0], "owner") == 0) {
+            ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OWNER);
+            return;
+        }
+        if (g_strcmp0(args[0], "admin") == 0) {
+            ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_ADMIN);
+            return;
+        }
+        if (g_strcmp0(args[0], "member") == 0) {
+            ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_MEMBER);
+            return;
+        }
+        if (g_strcmp0(args[0], "outcast") == 0) {
+            ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OUTCAST);
+            return;
+        }
     }
 }
 
@@ -1006,12 +1059,10 @@ cmd_who(gchar **args, struct cmd_help_t help)
 
     if (conn_status != JABBER_CONNECTED) {
         cons_show("You are not currently connected.");
+    } else if (win_type == WIN_MUC) {
+        _who_room(args, help);
     } else {
-        if (win_type == WIN_MUC) {
-            _who_room(args, help);
-        } else {
-            _who_roster(args, help);
-        }
+        _who_roster(args, help);
     }
 
     if (win_type != WIN_CONSOLE && win_type != WIN_MUC) {
@@ -2075,13 +2126,18 @@ cmd_room(gchar **args, struct cmd_help_t help)
     if ((g_strcmp0(args[0], "accept") != 0) &&
             (g_strcmp0(args[0], "destroy") != 0) &&
             (g_strcmp0(args[0], "config") != 0) &&
+
+            // roles
             (g_strcmp0(args[0], "moderators") != 0) &&
             (g_strcmp0(args[0], "participants") != 0) &&
             (g_strcmp0(args[0], "visitors") != 0) &&
+
+            // affiliations
             (g_strcmp0(args[0], "owners") != 0) &&
             (g_strcmp0(args[0], "admins") != 0) &&
             (g_strcmp0(args[0], "members") != 0) &&
             (g_strcmp0(args[0], "outcasts") != 0) &&
+
             (g_strcmp0(args[0], "info") != 0)) {
         cons_show("Usage: %s", help.usage);
         return TRUE;
@@ -2102,19 +2158,6 @@ cmd_room(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
-    if (g_strcmp0(args[0], "moderators") == 0) {
-        ui_show_room_role_list(window, room, MUC_ROLE_MODERATOR);
-        return TRUE;
-    }
-    if (g_strcmp0(args[0], "participants") == 0) {
-        ui_show_room_role_list(window, room, MUC_ROLE_PARTICIPANT);
-        return TRUE;
-    }
-    if (g_strcmp0(args[0], "visitors") == 0) {
-        ui_show_room_role_list(window, room, MUC_ROLE_VISITOR);
-        return TRUE;
-    }
-
     if (g_strcmp0(args[0], "owners") == 0) {
         if ((g_strcmp0(args[1], "add") == 0) || (g_strcmp0(args[1], "remove") == 0)) {
             char *nick = args[2];
@@ -2156,25 +2199,10 @@ cmd_room(gchar **args, struct cmd_help_t help)
             }
             jid_destroy(jidp);
             return TRUE;
-        } else {
-            ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OWNER);
-            return TRUE;
         }
-    }
-    if (g_strcmp0(args[0], "admins") == 0) {
-        ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_ADMIN);
-        return TRUE;
-    }
-    if (g_strcmp0(args[0], "members") == 0) {
-        ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_MEMBER);
-        return TRUE;
-    }
-    if (g_strcmp0(args[0], "outcasts") == 0) {
-        ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OUTCAST);
         return TRUE;
     }
 
-
     if (g_strcmp0(args[0], "accept") == 0) {
         gboolean requires_config = muc_requires_config(room);
         if (!requires_config) {