about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-13 23:45:56 +0100
committerJames Booth <boothj5@gmail.com>2014-09-13 23:45:56 +0100
commitb52911f7b4de2212dd699eb0419ae4e442497a03 (patch)
tree9814e34ed4eb80aa4fa683b50d98cceceb0f649a /src
parent0239a81c382bcf1e793b35770b9bb5fd45b01836 (diff)
downloadprofani-tty-b52911f7b4de2212dd699eb0419ae4e442497a03.tar.gz
Added add/remove subcommands to room config
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c20
-rw-r--r--src/command/commands.c56
2 files changed, 71 insertions, 5 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 2a9efc0f..91971911 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -307,15 +307,17 @@ static struct cmd_t command_defs[] =
 
     { "/room",
         cmd_room, parse_args, 1, 3, NULL,
-        { "/room config accept|destroy|config|submit|cancel [tag value]", "Room configuration.",
-        { "/room config accept|destroy|config|submit|cancel [tag value]",
-          "------------------------------------------------------------",
+        { "/room config accept|destroy|config|submit|cancel|set|add|remove [tag value]", "Room configuration.",
+        { "/room config accept|destroy|config|submit|cancel|set|add|remove [tag value]",
+          "---------------------------------------------------------------------------",
           "config accept  - Accept default room configuration.",
           "config destroy - Cancel default room configuration.",
           "config config  - Edit room configuration.",
           "config submit  - Cancel room configuration.",
           "config cancel  - Cancel room configuration.",
-          "config set tag value - Set room configuration field to value.",
+          "config set tag value    - Set room configuration field to value.",
+          "config add tag value    - Add value to room configuration field.",
+          "config remove tag value - Remove value from room configuration field.",
           NULL } } },
 
     { "/rooms",
@@ -1217,6 +1219,8 @@ cmd_init(void)
     autocomplete_add(room_ac, "submit");
     autocomplete_add(room_ac, "cancel");
     autocomplete_add(room_ac, "set");
+    autocomplete_add(room_ac, "add");
+    autocomplete_add(room_ac, "remove");
 
     cmd_history_init();
 }
@@ -2087,6 +2091,14 @@ _room_autocomplete(char *input, int *size)
             if (result != NULL) {
                 return result;
             }
+            result = autocomplete_param_with_ac(input, size, "/room add", form->tag_ac, TRUE);
+            if (result != NULL) {
+                return result;
+            }
+            result = autocomplete_param_with_ac(input, size, "/room remove", form->tag_ac, TRUE);
+            if (result != NULL) {
+                return result;
+            }
         }
     }
 
diff --git a/src/command/commands.c b/src/command/commands.c
index e7409a3e..81e8660b 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1810,6 +1810,8 @@ cmd_room(gchar **args, struct cmd_help_t help)
             (g_strcmp0(args[0], "config") != 0) &&
             (g_strcmp0(args[0], "submit") != 0) &&
             (g_strcmp0(args[0], "set") != 0) &&
+            (g_strcmp0(args[0], "add") != 0) &&
+            (g_strcmp0(args[0], "remove") != 0) &&
             (g_strcmp0(args[0], "cancel") != 0)) {
         cons_show("Usage: %s", help.usage);
         return TRUE;
@@ -1819,6 +1821,8 @@ cmd_room(gchar **args, struct cmd_help_t help)
     if (win_type == WIN_MUC &&
             ((g_strcmp0(args[0], "submit") == 0) ||
             (g_strcmp0(args[0], "cancel") == 0) ||
+            (g_strcmp0(args[0], "add") == 0) ||
+            (g_strcmp0(args[0], "remove") == 0) ||
             (g_strcmp0(args[0], "set") == 0))) {
         cons_show("Command '/room %s' only allowed in room configuration windows.", args[0]);
         return TRUE;
@@ -1882,6 +1886,8 @@ cmd_room(gchar **args, struct cmd_help_t help)
     // commands allowed in room config
     if ((g_strcmp0(args[0], "submit") == 0) ||
             (g_strcmp0(args[0], "cancel") == 0) ||
+            (g_strcmp0(args[0], "add") == 0) ||
+            (g_strcmp0(args[0], "remove") == 0) ||
             (g_strcmp0(args[0], "set") == 0)) {
 
         ProfWin *current = wins_get_current();
@@ -1945,12 +1951,60 @@ cmd_room(gchar **args, struct cmd_help_t help)
                     }
                     break;
                 default:
-                    ui_current_print_line("Value %s not valid for field: %s", value, tag);
+                    ui_current_print_line("Set command not valid for field: %s", value, tag);
                     break;
                 }
             }
         }
 
+        if (g_strcmp0(args[0], "add") == 0) {
+            char *tag = NULL;
+            char *value = NULL;
+            if (args[1] != NULL) {
+                tag = args[1];
+            } else {
+                ui_current_print_line("/room add command requires a field tag and value");
+                g_strfreev(split_recipient);
+                return TRUE;
+            }
+            if (args[2] != NULL) {
+                value = args[2];
+            } else {
+                ui_current_print_line("/room add command requires a field tag and value");
+                g_strfreev(split_recipient);
+                return TRUE;
+            }
+            if (!form_tag_exists(current->form, tag)) {
+                ui_current_print_line("Form does not contain a field with tag %s", tag);
+            } else {
+                ui_current_print_line("Add Tag: %s, Value: %s", tag, value);
+            }
+        }
+
+        if (g_strcmp0(args[0], "remove") == 0) {
+            char *tag = NULL;
+            char *value = NULL;
+            if (args[1] != NULL) {
+                tag = args[1];
+            } else {
+                ui_current_print_line("/room remove command requires a field tag and value");
+                g_strfreev(split_recipient);
+                return TRUE;
+            }
+            if (args[2] != NULL) {
+                value = args[2];
+            } else {
+                ui_current_print_line("/room remove command requires a field tag and value");
+                g_strfreev(split_recipient);
+                return TRUE;
+            }
+            if (!form_tag_exists(current->form, tag)) {
+                ui_current_print_line("Form does not contain a field with tag %s", tag);
+            } else {
+                ui_current_print_line("Remove Tag: %s, Value: %s", tag, value);
+            }
+        }
+
         if ((g_strcmp0(args[0], "submit") == 0) ||
                 (g_strcmp0(args[0], "cancel") == 0)) {
             wins_close_current();