diff --git a/src/command/command.c b/src/command/command.c index 3bc865fb..b53610de 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -115,6 +115,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; @@ -790,12 +791,30 @@ static struct cmd_t command_defs[] = CMD_TAGS( CMD_TAG_UI) CMD_SYN( - "/win ") + "/win console", + "/win ", + "/win ", + "/win ", + "/win ", + "/win ", + "/win xmlconsole") CMD_DESC( "Move to the specified window.") CMD_ARGS( - { "", "Window number to display." }) - CMD_NOEXAMPLES + { "console", "Go to the Console window." }, + { "", "Go to specified window number." }, + { "", "Go to chat window with contact by JID if open." }, + { "", "Go to chat window with contact by nickname if open." }, + { "", "Go to chat room window with roomjid if open." }, + { "", "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", @@ -2734,6 +2753,7 @@ cmd_reset_autocomplete(ProfWin *window) bookmark_autocomplete_reset(); prefs_reset_room_trigger_ac(); + win_reset_search_attempts(); plugins_reset_autocomplete(); } @@ -2972,6 +2992,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]; @@ -4253,6 +4274,19 @@ _console_autocomplete(ProfWin *window, const char *const input) return NULL; } +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) { diff --git a/src/command/commands.c b/src/command/commands.c index 56e3b967..105ff7df 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -44,6 +44,7 @@ #include #include #include +#include #include "chat_session.h" #include "command/commands.h" @@ -1067,13 +1068,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; + } + } - ProfWin *focuswin = wins_get_by_num(num); - if (!focuswin) { - cons_show("Window %d does not exist.", num); + 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); + } 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 cd7772d9..75359ad1 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* @@ -230,6 +234,56 @@ wins_get_by_num(int i) return g_hash_table_lookup(windows, GINT_TO_POINTER(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) { @@ -334,6 +388,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); } @@ -359,6 +457,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; } @@ -370,6 +469,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; } @@ -381,6 +490,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; } @@ -403,6 +513,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; } @@ -718,8 +829,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 8ac325a5..34459344 100644 --- a/src/window_list.h +++ b/src/window_list.h @@ -61,6 +61,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); @@ -83,4 +84,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