about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-10-29 21:21:41 +0000
committerJames Booth <boothj5@gmail.com>2015-10-29 21:21:41 +0000
commitdda753da3bbad6ecebadf605b0e34fe5674953eb (patch)
tree260307b6ebe3d2d068aba57013392f5cb16f190d
parentf3c65496c7d442d2120081937ca79814b49a56ea (diff)
downloadprofani-tty-dda753da3bbad6ecebadf605b0e34fe5674953eb.tar.gz
Added /subject edit <subject>
-rw-r--r--src/command/command.c47
-rw-r--r--src/command/commands.c9
2 files changed, 54 insertions, 2 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 76890725..9e8ebe02 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -110,6 +110,7 @@ static char* _help_autocomplete(ProfWin *window, const char *const input);
 static char* _wins_autocomplete(ProfWin *window, const char *const input);
 static char* _tls_autocomplete(ProfWin *window, const char *const input);
 static char* _script_autocomplete(ProfWin *window, const char *const input);
+static char* _subject_autocomplete(ProfWin *window, const char *const input);
 
 GHashTable *commands = NULL;
 
@@ -561,6 +562,7 @@ static struct cmd_t command_defs[] =
             CMD_TAG_GROUPCHAT)
         CMD_SYN(
             "/subject set <subject>",
+            "/subject edit <subject>",
             "/subject prepend <text>",
             "/subject append <text>",
             "/subject clear")
@@ -568,6 +570,7 @@ static struct cmd_t command_defs[] =
             "Set, modify, or clear room subject.")
         CMD_ARGS(
             { "set <subject>",  "Set the room subject." },
+            { "edit <subject>", "Edit the current room subject, tab autocompletion will display the subject to edit." },
             { "prepend <text>", "Prepend text to the current room subject, use double quotes if a trailing space is needed." },
             { "append <text>",  "Append text to the current room subject, use double quotes if a preceeding space is needed." },
             { "clear",          "Clear the room subject." })
@@ -2139,6 +2142,7 @@ cmd_init(void)
 
     subject_ac = autocomplete_new();
     autocomplete_add(subject_ac, "set");
+    autocomplete_add(subject_ac, "edit");
     autocomplete_add(subject_ac, "prepend");
     autocomplete_add(subject_ac, "append");
     autocomplete_add(subject_ac, "clear");
@@ -2700,8 +2704,8 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
         }
     }
 
-    gchar *cmds[] = { "/prefs", "/disco", "/close", "/subject", "/room" };
-    Autocomplete completers[] = { prefs_ac, disco_ac, close_ac, subject_ac, room_ac };
+    gchar *cmds[] = { "/prefs", "/disco", "/close", "/room" };
+    Autocomplete completers[] = { prefs_ac, disco_ac, close_ac, room_ac };
 
     for (i = 0; i < ARRAY_SIZE(cmds); i++) {
         result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE);
@@ -2743,6 +2747,7 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
     g_hash_table_insert(ac_funcs, "/wins",          _wins_autocomplete);
     g_hash_table_insert(ac_funcs, "/tls",           _tls_autocomplete);
     g_hash_table_insert(ac_funcs, "/script",        _script_autocomplete);
+    g_hash_table_insert(ac_funcs, "/subject",        _subject_autocomplete);
 
     int len = strlen(input);
     char parsed[len+1];
@@ -3939,6 +3944,44 @@ _join_autocomplete(ProfWin *window, const char *const input)
 }
 
 static char*
+_subject_autocomplete(ProfWin *window, const char *const input)
+{
+    char *result = NULL;
+
+    if (window->type == WIN_MUC) {
+        if ((g_strcmp0(input, "/subject e") == 0)
+                || (g_strcmp0(input, "/subject ed") == 0)
+                || (g_strcmp0(input, "/subject edi") == 0)
+                || (g_strcmp0(input, "/subject edit") == 0)
+                || (g_strcmp0(input, "/subject edit ") == 0)
+                || (g_strcmp0(input, "/subject edit \"") == 0)) {
+            ProfMucWin *mucwin = (ProfMucWin*)window;
+            assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+
+            char *subject = muc_subject(mucwin->roomjid);
+            if (subject) {
+                GString *result_str = g_string_new("/subject edit \"");
+                g_string_append(result_str, subject);
+                g_string_append(result_str, "\"");
+
+                result = result_str->str;
+                g_string_free(result_str, FALSE);
+            }
+        }
+    }
+    if (result) {
+        return result;
+    }
+
+    result = autocomplete_param_with_ac(input, "/subject", subject_ac, TRUE);
+    if (result) {
+        return result;
+    }
+
+    return NULL;
+}
+
+static char*
 _account_autocomplete(ProfWin *window, const char *const input)
 {
     char *found = NULL;
diff --git a/src/command/commands.c b/src/command/commands.c
index c8a516cd..8a0787b8 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -2851,6 +2851,15 @@ cmd_subject(ProfWin *window, const char *const command, gchar **args)
         return TRUE;
     }
 
+    if (g_strcmp0(args[0], "edit") == 0) {
+        if (args[1]) {
+            message_send_groupchat_subject(mucwin->roomjid, args[1]);
+        } else {
+            cons_bad_cmd_usage(command);
+        }
+        return TRUE;
+    }
+
     if (g_strcmp0(args[0], "prepend") == 0) {
         if (args[1]) {
             char *old_subject = muc_subject(mucwin->roomjid);