about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-10-09 22:39:57 +0100
committerJames Booth <boothj5@gmail.com>2014-10-09 22:39:57 +0100
commit36157367628633f96ef3e7a473bd8b7823a3226a (patch)
tree9c65a4e58e23540f1fe2d0d25f83be7e07febdb6 /src/command
parentce7cb3f40fd600e6c073945ea56868bd6f5aa05f (diff)
downloadprofani-tty-36157367628633f96ef3e7a473bd8b7823a3226a.tar.gz
Renamed args to /occupants default
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c45
-rw-r--r--src/command/commands.c17
2 files changed, 53 insertions, 9 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 76183575..fe0c4adf 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -89,6 +89,7 @@ static char * _join_autocomplete(char *input, int *size);
 static char * _log_autocomplete(char *input, int *size);
 static char * _form_autocomplete(char *input, int *size);
 static char * _room_autocomplete(char *input, int *size);
+static char * _occupants_autocomplete(char *input, int *size);
 
 GHashTable *commands = NULL;
 
@@ -318,12 +319,13 @@ static struct cmd_t command_defs[] =
           NULL } } },
 
     { "/occupants",
-        cmd_occupants, parse_args, 1, 1, NULL,
-        { "/occupants show|hide", "Room configuration.",
-        { "/occupants show|hide",
-          "--------------------",
-          "show - Show the occupants panel in chat rooms.",
-          "hide - Hide the occupants panel in chat rooms.",
+        cmd_occupants, parse_args, 1, 2, &cons_occupants_setting,
+        { "/occupants show|hide|default [show|hide]", "Show or hide room occupants.",
+        { "/occupants show|hide|default [show|hide]",
+          "----------------------------------------",
+          "show    - Show the occupants panel in chat rooms.",
+          "hide    - Hide the occupants panel in chat rooms.",
+          "default - Whether occupants are shown by default in new rooms, 'show' or 'hide'",
           NULL } } },
 
     { "/form",
@@ -988,6 +990,7 @@ static Autocomplete room_cmd_ac;
 static Autocomplete room_subject_ac;
 static Autocomplete form_ac;
 static Autocomplete occupants_ac;
+static Autocomplete occupants_default_ac;
 
 /*
  * Initialise command autocompleter and history
@@ -1299,6 +1302,11 @@ cmd_init(void)
     occupants_ac = autocomplete_new();
     autocomplete_add(occupants_ac, "show");
     autocomplete_add(occupants_ac, "hide");
+    autocomplete_add(occupants_ac, "default");
+
+    occupants_default_ac = autocomplete_new();
+    autocomplete_add(occupants_default_ac, "show");
+    autocomplete_add(occupants_default_ac, "hide");
 
     cmd_history_init();
 }
@@ -1349,6 +1357,7 @@ cmd_uninit(void)
     autocomplete_free(room_subject_ac);
     autocomplete_free(form_ac);
     autocomplete_free(occupants_ac);
+    autocomplete_free(occupants_default_ac);
 }
 
 gboolean
@@ -1481,6 +1490,7 @@ cmd_reset_autocomplete()
     autocomplete_reset(room_subject_ac);
     autocomplete_reset(form_ac);
     autocomplete_reset(occupants_ac);
+    autocomplete_reset(occupants_default_ac);
 
     if (ui_current_win_type() == WIN_MUC_CONFIG) {
         ProfWin *window = wins_get_current();
@@ -1738,8 +1748,8 @@ _cmd_complete_parameters(char *input, int *size)
         }
     }
 
-    gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/occupants" };
-    Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, occupants_ac };
+    gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins" };
+    Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac };
 
     for (i = 0; i < ARRAY_SIZE(cmds); i++) {
         result = autocomplete_param_with_ac(input, size, cmds[i], completers[i], TRUE);
@@ -1769,6 +1779,7 @@ _cmd_complete_parameters(char *input, int *size)
     g_hash_table_insert(ac_funcs, "/join",          _join_autocomplete);
     g_hash_table_insert(ac_funcs, "/form",          _form_autocomplete);
     g_hash_table_insert(ac_funcs, "/room",          _room_autocomplete);
+    g_hash_table_insert(ac_funcs, "/occupants",     _occupants_autocomplete);
 
     char parsed[*size+1];
     i = 0;
@@ -2292,6 +2303,24 @@ _form_autocomplete(char *input, int *size)
 }
 
 static char *
+_occupants_autocomplete(char *input, int *size)
+{
+    char *found = NULL;
+
+    found = autocomplete_param_with_ac(input, size, "/occupants default", occupants_default_ac, TRUE);
+    if (found != NULL) {
+        return found;
+    }
+
+    found = autocomplete_param_with_ac(input, size, "/occupants", occupants_ac, TRUE);
+    if (found != NULL) {
+        return found;
+    }
+
+    return NULL;
+}
+
+static char *
 _room_autocomplete(char *input, int *size)
 {
     char *result = NULL;
diff --git a/src/command/commands.c b/src/command/commands.c
index f3f9e4eb..2309b008 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -2336,9 +2336,24 @@ cmd_occupants(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
+    if (g_strcmp0(args[0], "default") == 0) {
+        if (g_strcmp0(args[1], "show") == 0) {
+            cons_show("Occupant list enabled.");
+            prefs_set_boolean(PREF_OCCUPANTS, TRUE);
+            return TRUE;
+        } else if (g_strcmp0(args[1], "hide") == 0) {
+            cons_show("Occupant list disabled.");
+            prefs_set_boolean(PREF_OCCUPANTS, FALSE);
+            return TRUE;
+        } else {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        }
+    }
+
     win_type_t win_type = ui_current_win_type();
     if (win_type != WIN_MUC) {
-        cons_show("Command '/occupants' does not apply to this window.");
+        cons_show("Cannot show/hide occupant list when not in chat room.");
         return TRUE;
     }