about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-01-07 00:38:17 +0000
committerJames Booth <boothj5@gmail.com>2016-01-07 00:38:17 +0000
commite5447cf37b949286ee0f497ee820ca096e23b0f1 (patch)
tree861a40bc32d12257393a72d0d058c87cab621959 /src
parent393e69016575c0e0dc3669f43b916b3742866cf3 (diff)
downloadprofani-tty-e5447cf37b949286ee0f497ee820ca096e23b0f1.tar.gz
Added /win navigation by jid, win title
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c40
-rw-r--r--src/command/commands.c29
-rw-r--r--src/window_list.c124
-rw-r--r--src/window_list.h4
4 files changed, 189 insertions, 8 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 9a542606..1a72f74a 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -114,6 +114,7 @@ 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);
 static char* _console_autocomplete(ProfWin *window, const char *const input);
+static char* _win_autocomplete(ProfWin *window, const char *const input);
 
 GHashTable *commands = NULL;
 
@@ -789,12 +790,30 @@ static struct cmd_t command_defs[] =
         CMD_TAGS(
             CMD_TAG_UI)
         CMD_SYN(
-            "/win <num>")
+            "/win console",
+            "/win <num>",
+            "/win <barejid>",
+            "/win <nick>",
+            "/win <roomjid>",
+            "/win <roomoccupantjid>",
+            "/win xmlconsole")
         CMD_DESC(
             "Move to the specified window.")
         CMD_ARGS(
-            { "<num>", "Window number to display." })
-        CMD_NOEXAMPLES
+            { "console",            "Go to the Console window." },
+            { "<num>",              "Go to specified window number." },
+            { "<barejid>",          "Go to chat window with contact by JID if open." },
+            { "<nick>",             "Go to chat window with contact by nickname if open." },
+            { "<roomjid>",          "Go to chat room window with roomjid if open." },
+            { "<roomoccupantjid>",  "Go to private chat roomjidoccupant if open." },
+            { "xmlconsole",         "Go to the XML Console window if open." })
+        CMD_EXAMPLES(
+            "/win console",
+            "/win 4",
+            "/win friend@chat.org",
+            "/win Eddie",
+            "/win bigroom@conference.chat.org",
+            "/win bigroom@conference.chat.org/bruce")
     },
 
     { "/wins",
@@ -2722,6 +2741,7 @@ cmd_reset_autocomplete(ProfWin *window)
 
     bookmark_autocomplete_reset();
     prefs_reset_room_trigger_ac();
+    win_reset_search_attempts();
 }
 
 gboolean
@@ -2957,6 +2977,7 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
     g_hash_table_insert(ac_funcs, "/script",        _script_autocomplete);
     g_hash_table_insert(ac_funcs, "/subject",       _subject_autocomplete);
     g_hash_table_insert(ac_funcs, "/console",       _console_autocomplete);
+    g_hash_table_insert(ac_funcs, "/win",           _win_autocomplete);
 
     int len = strlen(input);
     char parsed[len+1];
@@ -4232,6 +4253,19 @@ _console_autocomplete(ProfWin *window, const char *const input)
 }
 
 static char*
+_win_autocomplete(ProfWin *window, const char *const input)
+{
+    char *found = NULL;
+
+    found = autocomplete_param_with_func(input, "/win", win_autocomplete);
+    if (found) {
+        return found;
+    }
+
+    return NULL;
+}
+
+static char*
 _subject_autocomplete(ProfWin *window, const char *const input)
 {
     char *result = NULL;
diff --git a/src/command/commands.c b/src/command/commands.c
index 6674dce2..e94c9e3c 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -44,6 +44,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <langinfo.h>
+#include <ctype.h>
 
 #include "chat_session.h"
 #include "command/commands.h"
@@ -1059,13 +1060,31 @@ cmd_wins(ProfWin *window, const char *const command, gchar **args)
 gboolean
 cmd_win(ProfWin *window, const char *const command, gchar **args)
 {
-    int num = atoi(args[0]);
+    gboolean is_num = TRUE;
+    int i = 0;
+    for (i = 0; i < strlen(args[0]); i++) {
+        if (!isdigit(args[0][i])) {
+            is_num = FALSE;
+            break;
+        }
+    }
+
+    if (is_num) {
+        int num = atoi(args[0]);
 
-    ProfWin *focuswin = wins_get_by_num(num);
-    if (!focuswin) {
-        cons_show("Window %d does not exist.", num);
+        ProfWin *focuswin = wins_get_by_num(num);
+        if (!focuswin) {
+            cons_show("Window %d does not exist.", num);
+        } else {
+            ui_focus_win(focuswin);
+        }
     } else {
-        ui_focus_win(focuswin);
+        ProfWin *focuswin = wins_get_by_string(args[0]);
+        if (!focuswin) {
+            cons_show("Window \"%s\" does not exist.", args[0]);
+        } else {
+            ui_focus_win(focuswin);
+        }
     }
 
     return TRUE;
diff --git a/src/window_list.c b/src/window_list.c
index 87d20178..f2cd2062 100644
--- a/src/window_list.c
+++ b/src/window_list.c
@@ -49,6 +49,7 @@
 
 static GHashTable *windows;
 static int current;
+static Autocomplete wins_ac;
 
 void
 wins_init(void)
@@ -60,6 +61,9 @@ wins_init(void)
     g_hash_table_insert(windows, GINT_TO_POINTER(1), console);
 
     current = 1;
+
+    wins_ac = autocomplete_new();
+    autocomplete_add(wins_ac, "console");
 }
 
 ProfWin*
@@ -210,6 +214,56 @@ wins_get_by_num(int i)
 }
 
 ProfWin*
+wins_get_by_string(char *str)
+{
+    if (g_strcmp0(str, "console") == 0) {
+        ProfWin *conswin = wins_get_console();
+        if (conswin) {
+            return conswin;
+        } else {
+            return NULL;
+        }
+    }
+
+    if (g_strcmp0(str, "xmlconsole") == 0) {
+        ProfXMLWin *xmlwin = wins_get_xmlconsole();
+        if (xmlwin) {
+            return (ProfWin*)xmlwin;
+        } else {
+            return NULL;
+        }
+    }
+
+    ProfChatWin *chatwin = wins_get_chat(str);
+    if (chatwin) {
+        return (ProfWin*)chatwin;
+    }
+
+    jabber_conn_status_t conn_status = jabber_get_connection_status();
+    if (conn_status == JABBER_CONNECTED) {
+        char *barejid = roster_barejid_from_name(str);
+        if (barejid) {
+            ProfChatWin *chatwin = wins_get_chat(barejid);
+            if (chatwin) {
+                return (ProfWin*)chatwin;
+            }
+        }
+    }
+
+    ProfMucWin *mucwin = wins_get_muc(str);
+    if (mucwin) {
+        return (ProfWin*)mucwin;
+    }
+
+    ProfPrivateWin *privwin = wins_get_private(str);
+    if (privwin) {
+        return (ProfWin*)privwin;
+    }
+
+    return NULL;
+}
+
+ProfWin*
 wins_get_next(void)
 {
     // get and sort win nums
@@ -313,6 +367,50 @@ wins_close_by_num(int i)
             win_update_virtual(window);
         }
 
+        ProfWin *window = wins_get_by_num(i);
+        if (window) {
+            switch (window->type) {
+            case WIN_CHAT:
+            {
+                ProfChatWin *chatwin = (ProfChatWin*)window;
+                autocomplete_remove(wins_ac, chatwin->barejid);
+
+                jabber_conn_status_t conn_status = jabber_get_connection_status();
+                if (conn_status == JABBER_CONNECTED) {
+                    PContact contact = roster_get_contact(chatwin->barejid);
+                    if (contact) {
+                        const char* nick = p_contact_name(contact);
+                        if (nick) {
+                            autocomplete_remove(wins_ac, nick);
+                        }
+                    }
+                }
+
+                break;
+            }
+            case WIN_MUC:
+            {
+                ProfMucWin *mucwin = (ProfMucWin*)window;
+                autocomplete_remove(wins_ac, mucwin->roomjid);
+                break;
+            }
+            case WIN_PRIVATE:
+            {
+                ProfPrivateWin *privwin = (ProfPrivateWin*)window;
+                autocomplete_remove(wins_ac, privwin->fulljid);
+                break;
+            }
+            case WIN_XML:
+            {
+                autocomplete_remove(wins_ac, "xmlconsole");
+                break;
+            }
+            case WIN_MUC_CONFIG:
+            default:
+                break;
+            }
+        }
+
         g_hash_table_remove(windows, GINT_TO_POINTER(i));
         status_bar_inactive(i);
     }
@@ -338,6 +436,7 @@ wins_new_xmlconsole(void)
     g_list_free(keys);
     ProfWin *newwin = win_create_xmlconsole();
     g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
+    autocomplete_add(wins_ac, "xmlconsole");
     return newwin;
 }
 
@@ -349,6 +448,16 @@ wins_new_chat(const char *const barejid)
     g_list_free(keys);
     ProfWin *newwin = win_create_chat(barejid);
     g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
+
+    autocomplete_add(wins_ac, barejid);
+    PContact contact = roster_get_contact(barejid);
+    if (contact) {
+        const char* nick = p_contact_name(contact);
+        if (nick) {
+            autocomplete_add(wins_ac, nick);
+        }
+    }
+
     return newwin;
 }
 
@@ -360,6 +469,7 @@ wins_new_muc(const char *const roomjid)
     g_list_free(keys);
     ProfWin *newwin = win_create_muc(roomjid);
     g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
+    autocomplete_add(wins_ac, roomjid);
     return newwin;
 }
 
@@ -382,6 +492,7 @@ wins_new_private(const char *const fulljid)
     g_list_free(keys);
     ProfWin *newwin = win_create_private(fulljid);
     g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
+    autocomplete_add(wins_ac, fulljid);
     return newwin;
 }
 
@@ -686,8 +797,21 @@ wins_create_summary(gboolean unread)
     return result;
 }
 
+char*
+win_autocomplete(const char *const search_str)
+{
+    return autocomplete_complete(wins_ac, search_str, TRUE);
+}
+
+void
+win_reset_search_attempts(void)
+{
+    autocomplete_reset(wins_ac);
+}
+
 void
 wins_destroy(void)
 {
     g_hash_table_destroy(windows);
+    autocomplete_free(wins_ac);
 }
diff --git a/src/window_list.h b/src/window_list.h
index 6710c539..0cf22c2f 100644
--- a/src/window_list.h
+++ b/src/window_list.h
@@ -59,6 +59,7 @@ ProfWin* wins_get_current(void);
 void wins_set_current_by_num(int i);
 
 ProfWin* wins_get_by_num(int i);
+ProfWin* wins_get_by_string(char *str);
 
 ProfWin* wins_get_next(void);
 ProfWin* wins_get_previous(void);
@@ -81,4 +82,7 @@ gboolean wins_swap(int source_win, int target_win);
 void wins_hide_subwin(ProfWin *window);
 void wins_show_subwin(ProfWin *window);
 
+char* win_autocomplete(const char *const search_str);
+void win_reset_search_attempts(void);
+
 #endif