about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-05-05 23:42:11 +0100
committerJames Booth <boothj5@gmail.com>2013-05-05 23:42:11 +0100
commit3d8d5214bb93808252be6259980759ae3f3a2bbe (patch)
tree9449cb67af46e5a773a4fc3253b49875ba41d498 /src/command
parent53eeb0ef45dd7cd871d4dca2c59b1dd208ee23c6 (diff)
downloadprofani-tty-3d8d5214bb93808252be6259980759ae3f3a2bbe.tar.gz
Autocomplete "/sub allow" parameter from subscription requests
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/command/command.c b/src/command/command.c
index cebb10c2..d22e3953 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -74,6 +74,7 @@ static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
     const char * const display, preference_t pref);
 
 static void _cmd_complete_parameters(char *input, int *size);
+static void _sub_autocomplete(char *input, int *size);
 static void _notify_autocomplete(char *input, int *size);
 static void _titlebar_autocomplete(char *input, int *size);
 static void _theme_autocomplete(char *input, int *size);
@@ -965,6 +966,7 @@ cmd_reset_autocomplete()
     accounts_reset_all_search();
     accounts_reset_enabled_search();
     prefs_reset_boolean_choice();
+    presence_reset_sub_request_search();
     autocomplete_reset(help_ac);
     autocomplete_reset(notify_ac);
     autocomplete_reset(sub_ac);
@@ -1181,13 +1183,13 @@ _cmd_complete_parameters(char *input, int *size)
 
     _parameter_autocomplete(input, size, "/connect",
         accounts_find_enabled);
-    _parameter_autocomplete_with_ac(input, size, "/sub", sub_ac);
     _parameter_autocomplete_with_ac(input, size, "/help", help_ac);
     _parameter_autocomplete_with_ac(input, size, "/who", who_ac);
     _parameter_autocomplete_with_ac(input, size, "/prefs", prefs_ac);
     _parameter_autocomplete_with_ac(input, size, "/log", log_ac);
     _parameter_autocomplete_with_ac(input, size, "/disco", disco_ac);
 
+    _sub_autocomplete(input, size);
     _notify_autocomplete(input, size);
     _autoaway_autocomplete(input, size);
     _titlebar_autocomplete(input, size);
@@ -3074,6 +3076,33 @@ _parameter_autocomplete_with_ac(char *input, int *size, char *command,
 }
 
 static void
+_sub_autocomplete(char *input, int *size)
+{
+    char *found = NULL;
+    char *auto_msg = NULL;
+    char inp_cpy[*size];
+    int i;
+
+    if ((strncmp(input, "/sub allow ", 11) == 0) && (*size > 11)) {
+        for (i = 11; i < *size; i++) {
+            inp_cpy[i-11] = input[i];
+        }
+        inp_cpy[(*size) - 11] = '\0';
+        found = presence_sub_request_find(inp_cpy);
+        if (found != NULL) {
+            auto_msg = (char *) malloc((11 + (strlen(found) + 1)) * sizeof(char));
+            strcpy(auto_msg, "/sub allow ");
+            strcat(auto_msg, found);
+            inp_replace_input(input, auto_msg, size);
+            free(auto_msg);
+            free(found);
+        }
+    } else if ((strncmp(input, "/sub ", 5) == 0) && (*size > 5)) {
+        _parameter_autocomplete_with_ac(input, size, "/sub", sub_ac);
+    }
+}
+
+static void
 _notify_autocomplete(char *input, int *size)
 {
     char *found = NULL;