about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_ac.c43
-rw-r--r--src/command/cmd_defs.c17
-rw-r--r--src/command/cmd_funcs.c80
3 files changed, 126 insertions, 14 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 8e53bb10..5ecdfbe7 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -98,6 +98,7 @@ static char* _sendfile_autocomplete(ProfWin *window, const char *const input, gb
 static char* _blocked_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _tray_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _presence_autocomplete(ProfWin *window, const char *const input, gboolean previous);
+static char* _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 
 static char* _script_autocomplete_func(const char *const prefix, gboolean previous);
 
@@ -161,6 +162,7 @@ static Autocomplete alias_ac;
 static Autocomplete aliases_ac;
 static Autocomplete join_property_ac;
 static Autocomplete room_ac;
+static Autocomplete rooms_ac;
 static Autocomplete affiliation_ac;
 static Autocomplete role_ac;
 static Autocomplete privilege_cmd_ac;
@@ -591,6 +593,10 @@ cmd_ac_init(void)
     autocomplete_add(room_ac, "destroy");
     autocomplete_add(room_ac, "config");
 
+    rooms_ac = autocomplete_new();
+    autocomplete_add(rooms_ac, "service");
+    autocomplete_add(rooms_ac, "match");
+
     affiliation_ac = autocomplete_new();
     autocomplete_add(affiliation_ac, "owner");
     autocomplete_add(affiliation_ac, "admin");
@@ -1005,6 +1011,7 @@ cmd_ac_reset(ProfWin *window)
     autocomplete_reset(aliases_ac);
     autocomplete_reset(join_property_ac);
     autocomplete_reset(room_ac);
+    autocomplete_reset(rooms_ac);
     autocomplete_reset(affiliation_ac);
     autocomplete_reset(role_ac);
     autocomplete_reset(privilege_cmd_ac);
@@ -1124,6 +1131,7 @@ cmd_ac_uninit(void)
     autocomplete_free(aliases_ac);
     autocomplete_free(join_property_ac);
     autocomplete_free(room_ac);
+    autocomplete_free(rooms_ac);
     autocomplete_free(affiliation_ac);
     autocomplete_free(role_ac);
     autocomplete_free(privilege_cmd_ac);
@@ -1395,6 +1403,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
     g_hash_table_insert(ac_funcs, "/blocked",       _blocked_autocomplete);
     g_hash_table_insert(ac_funcs, "/tray",          _tray_autocomplete);
     g_hash_table_insert(ac_funcs, "/presence",      _presence_autocomplete);
+    g_hash_table_insert(ac_funcs, "/rooms",         _rooms_autocomplete);
 
     int len = strlen(input);
     char parsed[len+1];
@@ -3090,3 +3099,37 @@ _presence_autocomplete(ProfWin *window, const char *const input, gboolean previo
     return NULL;
 }
 
+static char*
+_rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous)
+{
+    char *found = NULL;
+    gboolean result = FALSE;
+
+    gchar **args = parse_args(input, 0, 4, &result);
+
+    if (result) {
+        gboolean space_at_end = g_str_has_suffix(input, " ");
+        int num_args = g_strv_length(args);
+        if (num_args <= 1) {
+            found = autocomplete_param_with_ac(input, "/rooms", rooms_ac, TRUE, previous);
+            if (found) {
+                g_strfreev(args);
+                return found;
+            }
+        }
+        if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) {
+            GString *beginning = g_string_new("/rooms");
+            g_string_append_printf(beginning, " %s %s", args[0], args[1]);
+            found = autocomplete_param_with_ac(input, beginning->str, rooms_ac, TRUE, previous);
+            g_string_free(beginning, TRUE);
+            if (found) {
+                g_strfreev(args);
+                return found;
+            }
+        }
+    }
+
+    g_strfreev(args);
+
+    return NULL;
+}
\ No newline at end of file
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index fa7e50d0..8d483fe0 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -788,20 +788,27 @@ static struct cmd_t command_defs[] =
     },
 
     { "/rooms",
-        parse_args, 0, 1, NULL,
+        parse_args, 0, 4, NULL,
         CMD_NOSUBFUNCS
         CMD_MAINFUNC(cmd_rooms)
         CMD_TAGS(
             CMD_TAG_GROUPCHAT)
         CMD_SYN(
-            "/rooms [<service>]")
+            "/rooms",
+            "/rooms match <glob>",
+            "/rooms service <service>",
+            "/rooms service <service> match <glob>")
         CMD_DESC(
             "List the chat rooms available at the specified conference service. "
-            "If no argument is supplied, the account preference 'muc.service' is used, 'conference.<domain-part>' by default.")
+            "If no argument is supplied, the account preference 'muc.service' is used, 'conference.<domain-part>' by default. "
+            "The match argument accepts a glob and returns only room names that match.")
         CMD_ARGS(
-            { "<service>", "The conference service to query." })
+            { "service <service>", "The conference service to query." },
+            { "match <glob>", "The string to match before displaying results."})
         CMD_EXAMPLES(
-            "/rooms conference.jabber.org")
+            "/rooms",
+            "/rooms match *development*",
+            "/rooms service conference.jabber.org")
     },
 
     { "/bookmark",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 509e19ee..90c4b567 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -4393,18 +4393,80 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args)
         return TRUE;
     }
 
-    if (args[0]) {
-        iq_room_list_request(args[0]);
-        return TRUE;
+    char *service = NULL;
+    char *match = NULL;
+    if (args[0] != NULL) {
+        if (g_strcmp0(args[0], "service") == 0) {
+            if (args[1] == NULL) {
+                cons_bad_cmd_usage(command);
+                cons_show("");
+                return TRUE;
+            }
+            service = g_strdup(args[1]);
+        } else if (g_strcmp0(args[0], "match") == 0) {
+            if (args[1] == NULL) {
+                cons_bad_cmd_usage(command);
+                cons_show("");
+                return TRUE;
+            }
+            match = g_strdup(args[1]);
+        } else {
+            cons_bad_cmd_usage(command);
+            cons_show("");
+            return TRUE;
+        }
+    }
+    if (g_strv_length(args) >=3 ) {
+        if (g_strcmp0(args[2], "service") == 0) {
+            if (args[3] == NULL) {
+                cons_bad_cmd_usage(command);
+                cons_show("");
+                g_free(service);
+                g_free(match);
+                return TRUE;
+            }
+            g_free(service);
+            service = g_strdup(args[3]);
+        } else if (g_strcmp0(args[2], "match") == 0) {
+            if (args[3] == NULL) {
+                cons_bad_cmd_usage(command);
+                cons_show("");
+                g_free(service);
+                g_free(match);
+                return TRUE;
+            }
+            g_free(match);
+            match = g_strdup(args[3]);
+        } else {
+            cons_bad_cmd_usage(command);
+            cons_show("");
+            return TRUE;
+        }
     }
 
-    ProfAccount *account = accounts_get_account(session_get_account_name());
-    if (account->muc_service) {
-        iq_room_list_request(account->muc_service);
-    } else {
-        cons_show("Account MUC service property not found.");
+    GPatternSpec *glob = NULL;
+    if (match != NULL) {
+        glob = g_pattern_spec_new(match);
+        g_free(match);
     }
-    account_free(account);
+
+    if (service == NULL) {
+        ProfAccount *account = accounts_get_account(session_get_account_name());
+        if (account->muc_service) {
+            service = g_strdup(account->muc_service);
+            account_free(account);
+        } else {
+            cons_show("Account MUC service property not found.");
+            account_free(account);
+            g_free(service);
+            g_free(match);
+            return TRUE;
+        }
+    }
+
+    iq_room_list_request(service, glob);
+
+    g_free(service);
 
     return TRUE;
 }