about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-08-19 22:51:00 +0100
committerJames Booth <boothj5@gmail.com>2014-08-19 22:52:04 +0100
commit7bac097d604371cac604ca75d6b2ea242575e9cd (patch)
treeb33dfa31fed4b8ca530727d6c35a14e88243d506 /src/command
parent5b40696ea0a0ca7dfc1d8702745df17c9662a3e5 (diff)
downloadprofani-tty-7bac097d604371cac604ca75d6b2ea242575e9cd.tar.gz
Added /bookmark with no args usage when in chat room
issue #402
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c7
-rw-r--r--src/command/commands.c140
2 files changed, 86 insertions, 61 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 9e8283e2..9c587324 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -304,9 +304,9 @@ static struct cmd_t command_defs[] =
           NULL } } },
 
     { "/bookmark",
-        cmd_bookmark, parse_args, 1, 8, NULL,
-        { "/bookmark list|add|update|remove|join [room@server] [nick value] [password value] [autojoin on|off]", "Manage bookmarks.",
-        { "/bookmark list|add|update|remove|join [room@server] [nick value] [password value] [autojoin on|off]",
+        cmd_bookmark, parse_args, 0, 8, NULL,
+        { "/bookmark [list|add|update|remove|join] [room@server] [nick value] [password value] [autojoin on|off]", "Manage bookmarks.",
+        { "/bookmark [list|add|update|remove|join] [room@server] [nick value] [password value] [autojoin on|off]",
           "---------------------------------------------------------------------------------------------------",
           "Manage bookmarks.",
           "list: List all bookmarks.",
@@ -317,6 +317,7 @@ static struct cmd_t command_defs[] =
           "update: Update any of the above properties associated with the bookmark.",
           "remove: Remove the bookmark for room@server.",
           "join: Join room@server using the properties associated with the bookmark.",
+          "When in a chat room, the /bookmark command with no arguments will bookmark the current room with the current settings, and set autojoin to \"on\".",
           NULL } } },
 
     { "/disco",
diff --git a/src/command/commands.c b/src/command/commands.c
index fdb4017c..2fed4c3e 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1807,86 +1807,110 @@ cmd_bookmark(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
-    gchar *cmd = args[0];
-    if (cmd == NULL) {
-        cons_show("Usage: %s", help.usage);
-        return TRUE;
-    }
-
-    if (strcmp(cmd, "list") == 0) {
-        const GList *bookmarks = bookmark_get_list();
-        cons_show_bookmarks(bookmarks);
-    } else {
-        char *jid = args[1];
-        if (jid == NULL) {
-            cons_show("Usage: %s", help.usage);
-            cons_show("");
-            return TRUE;
-        }
+    win_type_t win_type = ui_current_win_type();
 
-        if (strcmp(cmd, "remove") == 0) {
-            gboolean removed = bookmark_remove(jid);
-            if (removed) {
-                cons_show("Bookmark removed for %s.", jid);
+    if (win_type == WIN_MUC) {
+        gchar *cmd = args[0];
+
+        // default to current nickname, password, and autojoin "on"
+        if (cmd == NULL) {
+            char *jid = ui_current_recipient();
+            char *nick = muc_get_room_nick(jid);
+            char *password = muc_get_room_password(jid);
+            gboolean added = bookmark_add(jid, nick, password, "on");
+            if (added) {
+                ui_current_print_formatted_line('!', 0, "Bookmark added for %s.", jid);
             } else {
-                cons_show("No bookmark exists for %s.", jid);
+                ui_current_print_formatted_line('!', 0, "Bookmark already exists for %s.", jid);
             }
             return TRUE;
-        }
-
-        if (strcmp(cmd, "join") == 0) {
-            gboolean joined = bookmark_join(jid);
-            if (!joined) {
-                cons_show("No bookmark exists for %s.", jid);
-            }
+        } else {
+            ui_current_print_formatted_line('!', 0, "No arguments required for /bookmark in a chat room");
             return TRUE;
         }
 
-        gchar *opt_keys[] = { "autojoin", "nick", "password", NULL };
-        gboolean parsed;
-
-        GHashTable *options = parse_options(&args[2], opt_keys, &parsed);
-        if (!parsed) {
+    } else {
+        gchar *cmd = args[0];
+        if (cmd == NULL) {
             cons_show("Usage: %s", help.usage);
-            cons_show("");
             return TRUE;
         }
 
-        char *nick = g_hash_table_lookup(options, "nick");
-        char *password = g_hash_table_lookup(options, "password");
-        char *autojoin = g_hash_table_lookup(options, "autojoin");
-
-        if (autojoin != NULL) {
-            if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) {
+        if (strcmp(cmd, "list") == 0) {
+            const GList *bookmarks = bookmark_get_list();
+            cons_show_bookmarks(bookmarks);
+        } else {
+            char *jid = args[1];
+            if (jid == NULL) {
                 cons_show("Usage: %s", help.usage);
                 cons_show("");
                 return TRUE;
             }
-        }
 
-        if (strcmp(cmd, "add") == 0) {
-            if (strchr(jid, '@')==NULL) {
-                cons_show("Can't add bookmark with JID '%s'; should be '%s@domain.tld'", jid, jid);
-            } else {
-                gboolean added = bookmark_add(jid, nick, password, autojoin);
-                if (added) {
-                    cons_show("Bookmark added for %s.", jid);
+            if (strcmp(cmd, "remove") == 0) {
+                gboolean removed = bookmark_remove(jid);
+                if (removed) {
+                    cons_show("Bookmark removed for %s.", jid);
                 } else {
-                    cons_show("Bookmark already exists, use /bookmark update to edit.");
+                    cons_show("No bookmark exists for %s.", jid);
+                }
+                return TRUE;
+            }
+
+            if (strcmp(cmd, "join") == 0) {
+                gboolean joined = bookmark_join(jid);
+                if (!joined) {
+                    cons_show("No bookmark exists for %s.", jid);
+                }
+                return TRUE;
+            }
+
+            gchar *opt_keys[] = { "autojoin", "nick", "password", NULL };
+            gboolean parsed;
+
+            GHashTable *options = parse_options(&args[2], opt_keys, &parsed);
+            if (!parsed) {
+                cons_show("Usage: %s", help.usage);
+                cons_show("");
+                return TRUE;
+            }
+
+            char *nick = g_hash_table_lookup(options, "nick");
+            char *password = g_hash_table_lookup(options, "password");
+            char *autojoin = g_hash_table_lookup(options, "autojoin");
+
+            if (autojoin != NULL) {
+                if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) {
+                    cons_show("Usage: %s", help.usage);
+                    cons_show("");
+                    return TRUE;
                 }
             }
-        } else if (strcmp(cmd, "update") == 0) {
-            gboolean updated = bookmark_update(jid, nick, password, autojoin);
-            if (updated) {
-                cons_show("Bookmark updated.");
+
+            if (strcmp(cmd, "add") == 0) {
+                if (strchr(jid, '@')==NULL) {
+                    cons_show("Can't add bookmark with JID '%s'; should be '%s@domain.tld'", jid, jid);
+                } else {
+                    gboolean added = bookmark_add(jid, nick, password, autojoin);
+                    if (added) {
+                        cons_show("Bookmark added for %s.", jid);
+                    } else {
+                        cons_show("Bookmark already exists, use /bookmark update to edit.");
+                    }
+                }
+            } else if (strcmp(cmd, "update") == 0) {
+                gboolean updated = bookmark_update(jid, nick, password, autojoin);
+                if (updated) {
+                    cons_show("Bookmark updated.");
+                } else {
+                    cons_show("No bookmark exists for %s.", jid);
+                }
             } else {
-                cons_show("No bookmark exists for %s.", jid);
+                cons_show("Usage: %s", help.usage);
             }
-        } else {
-            cons_show("Usage: %s", help.usage);
-        }
 
-        options_destroy(options);
+            options_destroy(options);
+        }
     }
 
     return TRUE;