about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/cmd_ac.c73
-rw-r--r--src/command/cmd_defs.c108
-rw-r--r--src/command/cmd_funcs.c65
-rw-r--r--src/command/cmd_funcs.h8
4 files changed, 113 insertions, 141 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index a63a3ee8..f5a6e0c8 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -109,6 +109,7 @@ static char* _rooms_autocomplete(ProfWin *window, const char *const input, gbool
 static char* _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _clear_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _invite_autocomplete(ProfWin *window, const char *const input, gboolean previous);
+static char* _status_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 
 static char* _script_autocomplete_func(const char *const prefix, gboolean previous);
 
@@ -224,6 +225,8 @@ static Autocomplete statusbar_room_ac;
 static Autocomplete statusbar_show_ac;
 static Autocomplete clear_ac;
 static Autocomplete invite_ac;
+static Autocomplete status_ac;
+static Autocomplete status_state_ac;
 
 void
 cmd_ac_init(void)
@@ -882,6 +885,17 @@ cmd_ac_init(void)
     statusbar_show_ac = autocomplete_new();
     autocomplete_add(statusbar_show_ac, "name");
     autocomplete_add(statusbar_show_ac, "number");
+
+    status_ac = autocomplete_new();
+    autocomplete_add(status_ac, "set");
+    autocomplete_add(status_ac, "get");
+
+    status_state_ac = autocomplete_new();
+    autocomplete_add(status_state_ac, "online");
+    autocomplete_add(status_state_ac, "chat");
+    autocomplete_add(status_state_ac, "away");
+    autocomplete_add(status_state_ac, "xa");
+    autocomplete_add(status_state_ac, "dnd");
 }
 
 void
@@ -1181,6 +1195,8 @@ cmd_ac_reset(ProfWin *window)
     autocomplete_reset(statusbar_show_ac);
     autocomplete_reset(clear_ac);
     autocomplete_reset(invite_ac);
+    autocomplete_reset(status_ac);
+    autocomplete_reset(status_state_ac);
 
     autocomplete_reset(script_ac);
     if (script_show_ac) {
@@ -1322,6 +1338,8 @@ cmd_ac_uninit(void)
     autocomplete_free(statusbar_show_ac);
     autocomplete_free(clear_ac);
     autocomplete_free(invite_ac);
+    autocomplete_free(status_ac);
+    autocomplete_free(status_state_ac);
 }
 
 static void
@@ -1467,7 +1485,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
         assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
         Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
         if (nick_ac) {
-            gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ;
+            gchar *nick_choices[] = { "/msg", "/info", "/caps", "/software" } ;
 
             // Remove quote character before and after names when doing autocomplete
             char *unquoted = strip_arg_quotes(input);
@@ -1483,7 +1501,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
 
     // otherwise autocomplete using roster
     } else if (conn_status == JABBER_CONNECTED) {
-        gchar *contact_choices[] = { "/msg", "/info", "/status" };
+        gchar *contact_choices[] = { "/msg", "/info" };
         // Remove quote character before and after names when doing autocomplete
         char *unquoted = strip_arg_quotes(input);
         for (i = 0; i < ARRAY_SIZE(contact_choices); i++) {
@@ -1569,6 +1587,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
     g_hash_table_insert(ac_funcs, "/statusbar",     _statusbar_autocomplete);
     g_hash_table_insert(ac_funcs, "/clear",         _clear_autocomplete);
     g_hash_table_insert(ac_funcs, "/invite",        _invite_autocomplete);
+    g_hash_table_insert(ac_funcs, "/status",        _status_autocomplete);
 
     int len = strlen(input);
     char parsed[len+1];
@@ -3507,3 +3526,53 @@ _invite_autocomplete(ProfWin *window, const char *const input, gboolean previous
 
     return NULL;
 }
+
+static char*
+_status_autocomplete(ProfWin *window, const char *const input, gboolean previous)
+{
+    char *result = NULL;
+
+    result = autocomplete_param_with_ac(input, "/status", status_ac, TRUE, previous);
+    if (result) {
+        return result;
+    }
+
+    jabber_conn_status_t conn_status = connection_get_status();
+
+    if (conn_status == JABBER_CONNECTED) {
+
+        // complete with: online, away etc.
+        result = autocomplete_param_with_ac(input, "/status set", account_status_ac, TRUE, previous);
+        if (result) {
+            return result;
+        }
+
+        // Remove quote character before and after names when doing autocomplete
+        char *unquoted = strip_arg_quotes(input);
+
+        // MUC completion with nicknames
+        if (window->type == WIN_MUC) {
+            ProfMucWin *mucwin = (ProfMucWin*)window;
+            assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+            Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
+            if (nick_ac) {
+                result = autocomplete_param_with_ac(unquoted, "/status get", nick_ac, TRUE, previous);
+                if (result) {
+                    free(unquoted);
+                    return result;
+                }
+            }
+        // roster completion
+        } else {
+            result = autocomplete_param_with_func(unquoted, "/status get", roster_contact_autocomplete, previous);
+            if (result) {
+                free(unquoted);
+                return result;
+            }
+        }
+
+        free(unquoted);
+    }
+
+    return NULL;
+}
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 17f845e1..2f103d22 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -507,24 +507,29 @@ static struct cmd_t command_defs[] =
     },
 
     { "/status",
-        parse_args, 0, 1, NULL,
-        CMD_NOSUBFUNCS
-        CMD_MAINFUNC(cmd_status)
+        parse_args, 2, 3, NULL,
+        CMD_SUBFUNCS(
+            { "get",   cmd_status_get },
+            { "set",   cmd_status_set })
+        CMD_NOMAINFUNC
         CMD_TAGS(
             CMD_TAG_CHAT,
             CMD_TAG_GROUPCHAT)
         CMD_SYN(
-            "/status",
-            "/status <contact>|<nick>")
+            "/status set <state> [<message>]",
+            "/status get <contact>|<nick>")
         CMD_DESC(
-            "Find out a contact, or room members presence information. "
-            "If in a chat window the parameter is not required, the current recipient will be used.")
+            "/status get: Find out a contact, or room members presence information. "
+            "/status set: set own status.")
         CMD_ARGS(
+            { "<state>",   "Own status. Possible values: chat, online, away, dnd, xa" },
+            { "<message>", "Optional message to use with the status." },
             { "<contact>", "The contact who's presence you which to see." },
             { "<nick>",    "If in a chat room, the occupant who's presence you wish to see." })
         CMD_EXAMPLES(
-            "/status buddy@server.com",
-            "/status jon")
+            "/status get buddy@server.com",
+            "/status get jon",
+            "/status set online")
     },
 
     { "/resource",
@@ -2170,91 +2175,6 @@ static struct cmd_t command_defs[] =
         CMD_NOEXAMPLES
     },
 
-    { "/away",
-        parse_args_with_freetext, 0, 1, NULL,
-        CMD_NOSUBFUNCS
-        CMD_MAINFUNC(cmd_away)
-        CMD_TAGS(
-            CMD_TAG_PRESENCE)
-        CMD_SYN(
-            "/away [<message>]")
-        CMD_DESC(
-            "Set your status to 'away'.")
-        CMD_ARGS(
-            { "<message>",  "Optional message to use with the status." })
-        CMD_EXAMPLES(
-            "/away",
-            "/away Gone for lunch")
-    },
-
-    { "/chat",
-        parse_args_with_freetext, 0, 1, NULL,
-        CMD_NOSUBFUNCS
-        CMD_MAINFUNC(cmd_chat)
-        CMD_TAGS(
-            CMD_TAG_PRESENCE)
-        CMD_SYN(
-            "/chat [<message>]")
-        CMD_DESC(
-            "Set your status to 'chat' (available for chat).")
-        CMD_ARGS(
-            { "<message>",  "Optional message to use with the status." })
-        CMD_EXAMPLES(
-            "/chat",
-            "/chat Please talk to me!")
-    },
-
-    { "/dnd",
-        parse_args_with_freetext, 0, 1, NULL,
-        CMD_NOSUBFUNCS
-        CMD_MAINFUNC(cmd_dnd)
-        CMD_TAGS(
-            CMD_TAG_PRESENCE)
-        CMD_SYN(
-            "/dnd [<message>]")
-        CMD_DESC(
-            "Set your status to 'dnd' (do not disturb).")
-        CMD_ARGS(
-            { "<message>",  "Optional message to use with the status." })
-        CMD_EXAMPLES(
-            "/dnd",
-            "/dnd I'm in the zone")
-    },
-
-    { "/online",
-        parse_args_with_freetext, 0, 1, NULL,
-        CMD_NOSUBFUNCS
-        CMD_MAINFUNC(cmd_online)
-        CMD_TAGS(
-            CMD_TAG_PRESENCE)
-        CMD_SYN(
-            "/online [<message>]")
-        CMD_DESC(
-            "Set your status to 'online'.")
-        CMD_ARGS(
-            { "<message>",  "Optional message to use with the status." })
-        CMD_EXAMPLES(
-            "/online",
-            "/online Up the Irons!")
-    },
-
-    { "/xa",
-        parse_args_with_freetext, 0, 1, NULL,
-        CMD_NOSUBFUNCS
-        CMD_MAINFUNC(cmd_xa)
-        CMD_TAGS(
-            CMD_TAG_PRESENCE)
-        CMD_SYN(
-            "/xa [<message>]")
-        CMD_DESC(
-            "Set your status to 'xa' (extended away).")
-        CMD_ARGS(
-            { "<message>",  "Optional message to use with the status." })
-        CMD_EXAMPLES(
-            "/xa",
-            "/xa This meeting is going to be a long one")
-    },
-
     { "/script",
         parse_args, 1, 2, NULL,
         CMD_NOSUBFUNCS
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index e8c99901..f665bae1 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -3228,9 +3228,31 @@ _cmd_status_show_status(char* usr)
 }
 
 gboolean
-cmd_status(ProfWin *window, const char *const command, gchar **args)
+cmd_status_set(ProfWin *window, const char *const command, gchar **args)
+{
+    char *state = args[1];
+
+    if (g_strcmp0(state, "online") == 0) {
+        _update_presence(RESOURCE_ONLINE, "online", args);
+    } else if (g_strcmp0(state, "away") == 0) {
+        _update_presence(RESOURCE_AWAY, "away", args);
+    } else if (g_strcmp0(state, "dnd") == 0) {
+        _update_presence(RESOURCE_DND, "dnd", args);
+    } else if (g_strcmp0(state, "chat") == 0) {
+        _update_presence(RESOURCE_CHAT, "chat", args);
+    } else if (g_strcmp0(state, "xa") == 0) {
+        _update_presence(RESOURCE_XA, "xa", args);
+    } else {
+        cons_bad_cmd_usage(command);
+    }
+
+    return TRUE;
+}
+
+gboolean
+cmd_status_get(ProfWin *window, const char *const command, gchar **args)
 {
-    char *usr = args[0];
+    char *usr = args[1];
 
     jabber_conn_status_t conn_status = connection_get_status();
 
@@ -6765,41 +6787,6 @@ cmd_receipts(ProfWin *window, const char *const command, gchar **args)
 }
 
 gboolean
-cmd_away(ProfWin *window, const char *const command, gchar **args)
-{
-    _update_presence(RESOURCE_AWAY, "away", args);
-    return TRUE;
-}
-
-gboolean
-cmd_online(ProfWin *window, const char *const command, gchar **args)
-{
-    _update_presence(RESOURCE_ONLINE, "online", args);
-    return TRUE;
-}
-
-gboolean
-cmd_dnd(ProfWin *window, const char *const command, gchar **args)
-{
-    _update_presence(RESOURCE_DND, "dnd", args);
-    return TRUE;
-}
-
-gboolean
-cmd_chat(ProfWin *window, const char *const command, gchar **args)
-{
-    _update_presence(RESOURCE_CHAT, "chat", args);
-    return TRUE;
-}
-
-gboolean
-cmd_xa(ProfWin *window, const char *const command, gchar **args)
-{
-    _update_presence(RESOURCE_XA, "xa", args);
-    return TRUE;
-}
-
-gboolean
 cmd_plugins_sourcepath(ProfWin *window, const char *const command, gchar **args)
 {
     if (args[1] == NULL) {
@@ -8091,8 +8078,8 @@ _update_presence(const resource_presence_t resource_presence,
 {
     char *msg = NULL;
     int num_args = g_strv_length(args);
-    if (num_args == 1) {
-        msg = args[0];
+    if (num_args == 2) {
+        msg = args[1];
     }
 
     jabber_conn_status_t conn_status = connection_get_status();
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index 9b564aca..6c4afc3e 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -78,10 +78,8 @@ gboolean cmd_about(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_autoaway(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_autoconnect(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_autoping(ProfWin *window, const char *const command, gchar **args);
-gboolean cmd_away(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_beep(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_caps(ProfWin *window, const char *const command, gchar **args);
-gboolean cmd_chat(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_chlog(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_clear(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_close(ProfWin *window, const char *const command, gchar **args);
@@ -90,7 +88,6 @@ gboolean cmd_disco(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_sendfile(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_lastactivity(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_disconnect(ProfWin *window, const char *const command, gchar **args);
-gboolean cmd_dnd(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_flash(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_tray(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_gone(ProfWin *window, const char *const command, gchar **args);
@@ -109,7 +106,6 @@ gboolean cmd_log(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_msg(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_nick(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_notify(ProfWin *window, const char *const command, gchar **args);
-gboolean cmd_online(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_pgp(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_outtype(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_prefs(ProfWin *window, const char *const command, gchar **args);
@@ -123,7 +119,8 @@ gboolean cmd_roster(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_software(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_splash(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_states(ProfWin *window, const char *const command, gchar **args);
-gboolean cmd_status(ProfWin *window, const char *const command, gchar **args);
+gboolean cmd_status_get(ProfWin *window, const char *const command, gchar **args);
+gboolean cmd_status_set(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_sub(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_theme(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_tiny(ProfWin *window, const char *const command, gchar **args);
@@ -131,7 +128,6 @@ gboolean cmd_wintitle(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_vercheck(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_who(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_win(ProfWin *window, const char *const command, gchar **args);
-gboolean cmd_xa(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_alias(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_xmlconsole(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_ping(ProfWin *window, const char *const command, gchar **args);