about summary refs log tree commit diff stats
path: root/src/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/command.c')
-rw-r--r--src/command.c241
1 files changed, 187 insertions, 54 deletions
diff --git a/src/command.c b/src/command.c
index 69f260fa..2fab3c0a 100644
--- a/src/command.c
+++ b/src/command.c
@@ -36,6 +36,7 @@
 #include "chat_log.h"
 #include "history.h"
 #include "jabber.h"
+#include "jid.h"
 #include "log.h"
 #include "parser.h"
 #include "preferences.h"
@@ -118,6 +119,7 @@ static gboolean _cmd_set_gone(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_set_autoping(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_set_titlebar(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_set_autoaway(gchar **args, struct cmd_help_t help);
+static gboolean _cmd_set_mouse(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_set_statuses(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_vercheck(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_away(gchar **args, struct cmd_help_t help);
@@ -240,23 +242,26 @@ static struct cmd_t main_commands[] =
 
     { "/msg",
         _cmd_msg, parse_args_with_freetext, 1, 2,
-        { "/msg jid [message]", "Start chat with user.",
-        { "/msg jid [message]",
-          "------------------",
+        { "/msg jid|nick [message]", "Start chat with user.",
+        { "/msg jid|nick [message]",
+          "-----------------------",
           "Open a chat window with for the user JID (Jabber ID)  and send the message if one is supplied.",
-          "When in a chat room, will start private chat with the room member.",
+          "When in a chat room, supply the nickname to start private chat with the room member.",
+          "Use quotes if the nickname includes spaces.",
           "",
           "Example : /msg myfriend@server.com Hey, here's a message!",
           "Example : /msg otherfriend@server.com",
-          "Example : /msg room@conference.server.com/nick A private message",
+          "Example : /msg Bob Here is a private message",
+          "Example : /msg \"My Friend\" Hi, how are you?",
           NULL } } },
 
     { "/info",
-        _cmd_info, parse_args, 1, 1,
-        { "/info jid", "Find out a contacts presence information.",
-        { "/info jid",
-          "---------",
-          "Find out a contacts presence information.",
+        _cmd_info, parse_args, 0, 1,
+        { "/info [jid|nick]", "Find out a contacts presence information.",
+        { "/info [jid|nick]",
+          "----------------",
+          "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.",
           NULL } } },
 
     { "/join",
@@ -322,24 +327,22 @@ static struct cmd_t main_commands[] =
         { "/tiny url",
           "---------",
           "Send the url as a tiny url.",
-          "This command can only be called when in a chat window, not from the console.",
           "",
           "Example : /tiny http://www.google.com",
           NULL } } },
 
     { "/who",
         _cmd_who, parse_args, 0, 1,
-        { "/who [status]", "Show contacts with chosen status.",
+        { "/who [status]", "Show contacts/room participants with chosen status.",
         { "/who [status]",
           "-------------",
           "Show contacts with the specified status, no status shows all contacts.",
           "Possible statuses are: online, offline, away, dnd, xa, chat, available, unavailable.",
+          "If in a chat room, the participants with the supplied status are displayed.",
           "",
           "online      : Contacts that are connected, i.e. online, chat, away, xa, dnd",
           "available   : Contacts that are available for chat, i.e. online, chat.",
           "unavailable : Contacts that are not available for chat, i.e. offline, away, xa, dnd.",
-          "",
-          "If in a chat room, this command shows the room roster in the room.",
           NULL } } },
 
     { "/close",
@@ -437,6 +440,17 @@ static struct cmd_t setting_commands[] =
           "Possible properties are 'version'.",
           NULL  } } },
 
+    { "/mouse",
+        _cmd_set_mouse, parse_args, 1, 1,
+        { "/mouse on|off", "Use profanity mouse handling.",
+        { "/mouse on|off",
+          "-------------",
+          "If set to 'on', profanity will handle mouse actions, which enabled scrolling the main window with the mouse wheel.",
+          "To select text, use the shift key while selcting an area.",
+          "If set to 'off', profanity leaves mouse handling to the terminal implementation.",
+          "The default is 'on', if you have strange behaviour with mouse actions, set to 'off'.",
+          NULL } } },
+
     { "/chlog",
         _cmd_set_chlog, parse_args, 1, 1,
         { "/chlog on|off", "Chat logging to file",
@@ -786,10 +800,9 @@ cmd_reset_autocomplete()
         if (nick_ac != NULL) {
             p_autocomplete_reset(nick_ac);
         }
-    } else {
-        p_autocomplete_reset(who_ac);
     }
 
+    p_autocomplete_reset(who_ac);
     p_autocomplete_reset(prefs_ac);
     p_autocomplete_reset(log_ac);
     p_autocomplete_reset(commands_ac);
@@ -889,7 +902,7 @@ cmd_execute_default(const char * const inp)
             char *recipient = win_current_get_recipient();
             jabber_send(inp, recipient);
 
-            if (prefs_get_chlog()) {
+            if (win_current_is_chat() && prefs_get_chlog()) {
                 const char *jid = jabber_get_jid();
                 chat_log_chat(jid, recipient, inp, PROF_OUT_LOG, NULL);
             }
@@ -921,6 +934,8 @@ _cmd_complete_parameters(char *input, int *size)
         prefs_autocomplete_boolean_choice);
     _parameter_autocomplete(input, size, "/chlog",
         prefs_autocomplete_boolean_choice);
+    _parameter_autocomplete(input, size, "/mouse",
+        prefs_autocomplete_boolean_choice);
     _parameter_autocomplete(input, size, "/history",
         prefs_autocomplete_boolean_choice);
     _parameter_autocomplete(input, size, "/vercheck",
@@ -1440,7 +1455,81 @@ _cmd_who(gchar **args, struct cmd_help_t help)
         } else {
             if (win_current_is_groupchat()) {
                 char *room = win_current_get_recipient();
-                win_show_room_roster(room);
+                GList *list = muc_get_roster(room);
+
+                // no arg, show all contacts
+                if (presence == NULL) {
+                    win_show_room_roster(room, list, NULL);
+
+                // available
+                } else if (strcmp("available", presence) == 0) {
+                    GList *filtered = NULL;
+
+                    while (list != NULL) {
+                        PContact contact = list->data;
+                        const char * const contact_presence = (p_contact_presence(contact));
+                        if ((strcmp(contact_presence, "online") == 0)
+                                || (strcmp(contact_presence, "chat") == 0)) {
+                            filtered = g_list_append(filtered, contact);
+                        }
+                        list = g_list_next(list);
+                    }
+
+                    win_show_room_roster(room, filtered, "available");
+
+                // unavailable
+                } else if (strcmp("unavailable", presence) == 0) {
+                    GList *filtered = NULL;
+
+                    while (list != NULL) {
+                        PContact contact = list->data;
+                        const char * const contact_presence = (p_contact_presence(contact));
+                        if ((strcmp(contact_presence, "offline") == 0)
+                                || (strcmp(contact_presence, "away") == 0)
+                                || (strcmp(contact_presence, "dnd") == 0)
+                                || (strcmp(contact_presence, "xa") == 0)) {
+                            filtered = g_list_append(filtered, contact);
+                        }
+                        list = g_list_next(list);
+                    }
+
+                    win_show_room_roster(room, filtered, "unavailable");
+
+                // online, show all status that indicate online
+                } else if (strcmp("online", presence) == 0) {
+                    GList *filtered = NULL;
+
+                    while (list != NULL) {
+                        PContact contact = list->data;
+                        const char * const contact_presence = (p_contact_presence(contact));
+                        if ((strcmp(contact_presence, "online") == 0)
+                                || (strcmp(contact_presence, "away") == 0)
+                                || (strcmp(contact_presence, "dnd") == 0)
+                                || (strcmp(contact_presence, "xa") == 0)
+                                || (strcmp(contact_presence, "chat") == 0)) {
+                            filtered = g_list_append(filtered, contact);
+                        }
+                        list = g_list_next(list);
+                    }
+
+                    win_show_room_roster(room, filtered, "online");
+
+                // show specific status
+                } else {
+                    GList *filtered = NULL;
+
+                    while (list != NULL) {
+                        PContact contact = list->data;
+                        if (strcmp(p_contact_presence(contact), presence) == 0) {
+                            filtered = g_list_append(filtered, contact);
+                        }
+                        list = g_list_next(list);
+                    }
+
+                    win_show_room_roster(room, filtered, presence);
+                }
+
+            // not in groupchat window
             } else {
                 GSList *list = get_contact_list();
 
@@ -1552,18 +1641,17 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
             g_string_append(full_jid, "/");
             g_string_append(full_jid, usr);
 
-            jabber_send(msg, full_jid->str);
-            win_show_outgoing_msg("me", full_jid->str, msg);
-
-            if (prefs_get_chlog()) {
-                const char *jid = jabber_get_jid();
-                chat_log_chat(jid, full_jid->str, msg, PROF_OUT_LOG, NULL);
+            if (msg != NULL) {
+                jabber_send(msg, full_jid->str);
+                win_show_outgoing_msg("me", full_jid->str, msg);
+            } else {
+                win_new_chat_win(full_jid->str);
             }
 
             g_string_free(full_jid, TRUE);
 
         } else {
-            cons_show("No such nick \"%s\" in room %s.", usr, room_name);
+            win_current_show("No such participant \"%s\" in room.", usr);
         }
 
         return TRUE;
@@ -1573,7 +1661,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
             jabber_send(msg, usr);
             win_show_outgoing_msg("me", usr, msg);
 
-            if (prefs_get_chlog()) {
+            if (win_current_is_chat() && prefs_get_chlog()) {
                 const char *jid = jabber_get_jid();
                 chat_log_chat(jid, usr, msg, PROF_OUT_LOG, NULL);
             }
@@ -1596,7 +1684,31 @@ _cmd_info(gchar **args, struct cmd_help_t help)
     if (conn_status != JABBER_CONNECTED) {
         cons_show("You are not currently connected.");
     } else {
-        cons_show_status(usr);
+        if (win_current_is_groupchat()) {
+            if (usr != NULL) {
+                win_room_show_status(usr);
+            } else {
+                win_current_show("You must specify a nickname.");
+            }
+        } else if (win_current_is_chat()) {
+            if (usr != NULL) {
+                win_current_show("No parameter required when in chat.");
+            } else {
+                win_show_status();
+            }
+        } else if (win_current_is_private()) {
+            if (usr != NULL) {
+                win_current_show("No parameter required when in chat.");
+            } else {
+                win_private_show_status();
+            }
+        } else {
+            if (usr != NULL) {
+                cons_show_status(usr);
+            } else {
+                cons_show("Usage: %s", help.usage);
+            }
+        }
     }
 
     return TRUE;
@@ -1605,33 +1717,36 @@ _cmd_info(gchar **args, struct cmd_help_t help)
 static gboolean
 _cmd_join(gchar **args, struct cmd_help_t help)
 {
+    jabber_conn_status_t conn_status = jabber_get_connection_status();
+
+    if (conn_status != JABBER_CONNECTED) {
+        cons_show("You are not currently connected.");
+        return TRUE;
+    }
+
+    if (ui_windows_full()) {
+        cons_bad_show("Windows all used, close a window and try again.");
+        return TRUE;
+    }
+
     char *room = args[0];
     char *nick = NULL;
 
     int num_args = g_strv_length(args);
     if (num_args == 2) {
         nick = args[1];
+    } else {
+        Jid *jid = jid_create(jabber_get_jid());
+        nick = strdup(jid->localpart);
+        jid_destroy(jid);
     }
 
-    jabber_conn_status_t conn_status = jabber_get_connection_status();
+    Jid *room_jid = jid_create_room_jid(room, nick);
 
-    if (conn_status != JABBER_CONNECTED) {
-        cons_show("You are not currently connected.");
-    } else if (ui_windows_full()) {
-        cons_bad_show("Windows all used, close a window and try again.");
-    } else {
-        // if no nick, set to first part of jid
-        if (nick == NULL) {
-            const char *jid = jabber_get_jid();
-            char jid_cpy[strlen(jid) + 1];
-            strcpy(jid_cpy, jid);
-            nick = strdup(strtok(jid_cpy, "@"));
-        }
-        if (!muc_room_is_active(room)) {
-            jabber_join(room, nick);
-        }
-        win_join_chat(room, nick);
+    if (!muc_room_is_active(room_jid)) {
+        jabber_join(room_jid);
     }
+    win_join_chat(room_jid);
 
     return TRUE;
 }
@@ -1666,24 +1781,35 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
         GString *error = g_string_new("/tiny, badly formed URL: ");
         g_string_append(error, url);
         cons_bad_show(error->str);
-        if (win_current_is_chat()) {
+        if (!win_current_is_console()) {
             win_current_bad_show(error->str);
         }
         g_string_free(error, TRUE);
-    } else if (win_current_is_chat()) {
+    } else if (!win_current_is_console()) {
         char *tiny = tinyurl_get(url);
 
         if (tiny != NULL) {
-            char *recipient = win_current_get_recipient();
-            jabber_send(tiny, recipient);
+            if (win_current_is_chat()) {
+                char *recipient = win_current_get_recipient();
+                jabber_send(tiny, recipient);
 
-            if (prefs_get_chlog()) {
-                const char *jid = jabber_get_jid();
-                chat_log_chat(jid, recipient, tiny, PROF_OUT_LOG, NULL);
-            }
+                if (prefs_get_chlog()) {
+                    const char *jid = jabber_get_jid();
+                    chat_log_chat(jid, recipient, tiny, PROF_OUT_LOG, NULL);
+                }
 
-            win_show_outgoing_msg("me", recipient, tiny);
-            free(recipient);
+                win_show_outgoing_msg("me", recipient, tiny);
+                free(recipient);
+            } else if (win_current_is_private()) {
+                char *recipient = win_current_get_recipient();
+                jabber_send(tiny, recipient);
+                win_show_outgoing_msg("me", recipient, tiny);
+                free(recipient);
+            } else { // groupchat
+                char *recipient = win_current_get_recipient();
+                jabber_send_groupchat(tiny, recipient);
+                free(recipient);
+            }
             free(tiny);
         } else {
             cons_bad_show("Couldn't get tinyurl.");
@@ -2022,6 +2148,13 @@ _cmd_set_chlog(gchar **args, struct cmd_help_t help)
 }
 
 static gboolean
+_cmd_set_mouse(gchar **args, struct cmd_help_t help)
+{
+    return _cmd_set_boolean_preference(args[0], help,
+        "Mouse handling", prefs_set_mouse);
+}
+
+static gboolean
 _cmd_set_history(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,