about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c180
-rw-r--r--src/command/command.h9
-rw-r--r--src/command/commands.c4
-rw-r--r--src/command/commands.h4
4 files changed, 98 insertions, 99 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 00223b29..5dc0a582 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -70,38 +70,38 @@
 
 typedef char*(*autocompleter)(char*, int*);
 
-static gboolean _cmd_execute(const char * const command, const char * const inp);
-
-static char * _cmd_complete_parameters(const char * const input);
-
-static char * _sub_autocomplete(const char * const input);
-static char * _notify_autocomplete(const char * const input);
-static char * _theme_autocomplete(const char * const input);
-static char * _autoaway_autocomplete(const char * const input);
-static char * _autoconnect_autocomplete(const char * const input);
-static char * _account_autocomplete(const char * const input);
-static char * _who_autocomplete(const char * const input);
-static char * _roster_autocomplete(const char * const input);
-static char * _group_autocomplete(const char * const input);
-static char * _bookmark_autocomplete(const char * const input);
-static char * _otr_autocomplete(const char * const input);
-static char * _connect_autocomplete(const char * const input);
-static char * _statuses_autocomplete(const char * const input);
-static char * _alias_autocomplete(const char * const input);
-static char * _join_autocomplete(const char * const input);
-static char * _log_autocomplete(const char * const input);
-static char * _form_autocomplete(const char * const input);
-static char * _form_field_autocomplete(const char * const input);
-static char * _occupants_autocomplete(const char * const input);
-static char * _kick_autocomplete(const char * const input);
-static char * _ban_autocomplete(const char * const input);
-static char * _affiliation_autocomplete(const char * const input);
-static char * _role_autocomplete(const char * const input);
-static char * _resource_autocomplete(const char * const input);
-static char * _titlebar_autocomplete(const char * const input);
-static char * _inpblock_autocomplete(const char * const input);
-static char * _time_autocomplete(const char * const input);
-static char * _receipts_autocomplete(const char * const input);
+static gboolean _cmd_execute(ProfWin *window, const char * const command, const char * const inp);
+
+static char * _cmd_complete_parameters(ProfWin *window, const char * const input);
+
+static char * _sub_autocomplete(ProfWin *window, const char * const input);
+static char * _notify_autocomplete(ProfWin *window, const char * const input);
+static char * _theme_autocomplete(ProfWin *window, const char * const input);
+static char * _autoaway_autocomplete(ProfWin *window, const char * const input);
+static char * _autoconnect_autocomplete(ProfWin *window, const char * const input);
+static char * _account_autocomplete(ProfWin *window, const char * const input);
+static char * _who_autocomplete(ProfWin *window, const char * const input);
+static char * _roster_autocomplete(ProfWin *window, const char * const input);
+static char * _group_autocomplete(ProfWin *window, const char * const input);
+static char * _bookmark_autocomplete(ProfWin *window, const char * const input);
+static char * _otr_autocomplete(ProfWin *window, const char * const input);
+static char * _connect_autocomplete(ProfWin *window, const char * const input);
+static char * _statuses_autocomplete(ProfWin *window, const char * const input);
+static char * _alias_autocomplete(ProfWin *window, const char * const input);
+static char * _join_autocomplete(ProfWin *window, const char * const input);
+static char * _log_autocomplete(ProfWin *window, const char * const input);
+static char * _form_autocomplete(ProfWin *window, const char * const input);
+static char * _form_field_autocomplete(ProfWin *window, const char * const input);
+static char * _occupants_autocomplete(ProfWin *window, const char * const input);
+static char * _kick_autocomplete(ProfWin *window, const char * const input);
+static char * _ban_autocomplete(ProfWin *window, const char * const input);
+static char * _affiliation_autocomplete(ProfWin *window, const char * const input);
+static char * _role_autocomplete(ProfWin *window, const char * const input);
+static char * _resource_autocomplete(ProfWin *window, const char * const input);
+static char * _titlebar_autocomplete(ProfWin *window, const char * const input);
+static char * _inpblock_autocomplete(ProfWin *window, const char * const input);
+static char * _time_autocomplete(ProfWin *window, const char * const input);
+static char * _receipts_autocomplete(ProfWin *window, const char * const input);
 
 GHashTable *commands = NULL;
 
@@ -1722,7 +1722,7 @@ cmd_alias_remove(char *value)
 
 // Command autocompletion functions
 char*
-cmd_autocomplete(const char * const input)
+cmd_autocomplete(ProfWin *window, const char * const input)
 {
     // autocomplete command
     if ((strncmp(input, "/", 1) == 0) && (!str_contains(input, strlen(input), ' '))) {
@@ -1734,7 +1734,7 @@ cmd_autocomplete(const char * const input)
 
     // autocomplete parameters
     } else {
-        char *found = _cmd_complete_parameters(input);
+        char *found = _cmd_complete_parameters(window, input);
         if (found) {
             return found;
         }
@@ -1744,7 +1744,7 @@ cmd_autocomplete(const char * const input)
 }
 
 void
-cmd_reset_autocomplete()
+cmd_reset_autocomplete(ProfWin *window)
 {
     roster_reset_search_attempts();
     muc_invites_reset_ac();
@@ -1811,7 +1811,7 @@ cmd_reset_autocomplete()
     autocomplete_reset(inpblock_ac);
     autocomplete_reset(receipts_ac);
 
-    if (ui_current_win_type() == WIN_CHAT) {
+    if (window->type == WIN_CHAT) {
         ProfChatWin *chatwin = wins_get_current_chat();
         PContact contact = roster_get_contact(chatwin->barejid);
         if (contact) {
@@ -1819,13 +1819,13 @@ cmd_reset_autocomplete()
         }
     }
 
-    if (ui_current_win_type() == WIN_MUC) {
+    if (window->type == WIN_MUC) {
         ProfMucWin *mucwin = wins_get_current_muc();
         muc_autocomplete_reset(mucwin->roomjid);
         muc_jid_autocomplete_reset(mucwin->roomjid);
     }
 
-    if (ui_current_win_type() == WIN_MUC_CONFIG) {
+    if (window->type == WIN_MUC_CONFIG) {
         ProfMucConfWin *confwin = wins_get_current_muc_conf();
         if (confwin->form) {
             form_reset_autocompleters(confwin->form);
@@ -1840,7 +1840,7 @@ cmd_reset_autocomplete()
  * continue, FALSE otherwise
  */
 gboolean
-cmd_process_input(char *inp)
+cmd_process_input(ProfWin *window, char *inp)
 {
     log_debug("Input received: %s", inp);
     gboolean result = FALSE;
@@ -1854,7 +1854,7 @@ cmd_process_input(char *inp)
     } else if (inp[0] == '/') {
         char *inp_cpy = strdup(inp);
         char *command = strtok(inp_cpy, " ");
-        result = _cmd_execute(command, inp);
+        result = _cmd_execute(window, command, inp);
         free(inp_cpy);
 
     // call a default handler if input didn't start with '/'
@@ -1868,18 +1868,18 @@ cmd_process_input(char *inp)
 // Command execution
 
 void
-cmd_execute_connect(const char * const account)
+cmd_execute_connect(ProfWin *window, const char * const account)
 {
     GString *command = g_string_new("/connect ");
     g_string_append(command, account);
-    cmd_process_input(command->str);
+    cmd_process_input(window, command->str);
     g_string_free(command, TRUE);
 }
 
 static gboolean
-_cmd_execute(const char * const command, const char * const inp)
+_cmd_execute(ProfWin *window, const char * const command, const char * const inp)
 {
-    if (g_str_has_prefix(command, "/field") && ui_current_win_type() == WIN_MUC_CONFIG) {
+    if (g_str_has_prefix(command, "/field") && window->type == WIN_MUC_CONFIG) {
         gboolean result = FALSE;
         gchar **args = parse_args_with_freetext(inp, 1, 2, &result);
         if (!result) {
@@ -1911,7 +1911,7 @@ _cmd_execute(const char * const command, const char * const inp)
         }
     } else {
         gboolean ran_alias = FALSE;
-        gboolean alias_result = cmd_execute_alias(inp, &ran_alias);
+        gboolean alias_result = cmd_execute_alias(window, inp, &ran_alias);
         if (!ran_alias) {
             return cmd_execute_default(inp);
         } else {
@@ -1921,7 +1921,7 @@ _cmd_execute(const char * const command, const char * const inp)
 }
 
 static char *
-_cmd_complete_parameters(const char * const input)
+_cmd_complete_parameters(ProfWin *window, const char * const input)
 {
     int i;
     char *result = NULL;
@@ -1939,7 +1939,7 @@ _cmd_complete_parameters(const char * const input)
     }
 
     // autocomplete nickname in chat rooms
-    if (ui_current_win_type() == WIN_MUC) {
+    if (window->type == WIN_MUC) {
         ProfMucWin *mucwin = wins_get_current_muc();
         Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
         if (nick_ac) {
@@ -2045,9 +2045,9 @@ _cmd_complete_parameters(const char * const input)
     }
     parsed[i] = '\0';
 
-    char * (*ac_func)(const char * const) = g_hash_table_lookup(ac_funcs, parsed);
+    char * (*ac_func)(ProfWin*, const char * const) = g_hash_table_lookup(ac_funcs, parsed);
     if (ac_func) {
-        result = ac_func(input);
+        result = ac_func(window, input);
         if (result) {
             g_hash_table_destroy(ac_funcs);
             return result;
@@ -2056,7 +2056,7 @@ _cmd_complete_parameters(const char * const input)
     g_hash_table_destroy(ac_funcs);
 
     if (g_str_has_prefix(input, "/field")) {
-        result = _form_field_autocomplete(input);
+        result = _form_field_autocomplete(window, input);
         if (result) {
             return result;
         }
@@ -2066,7 +2066,7 @@ _cmd_complete_parameters(const char * const input)
 }
 
 static char *
-_sub_autocomplete(const char * const input)
+_sub_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
     result = autocomplete_param_with_func(input, "/sub allow", presence_sub_request_find);
@@ -2086,12 +2086,11 @@ _sub_autocomplete(const char * const input)
 }
 
 static char *
-_who_autocomplete(const char * const input)
+_who_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
-    win_type_t win_type = ui_current_win_type();
 
-    if (win_type == WIN_MUC) {
+    if (window->type == WIN_MUC) {
         result = autocomplete_param_with_ac(input, "/who", who_room_ac, TRUE);
         if (result) {
             return result;
@@ -2119,7 +2118,7 @@ _who_autocomplete(const char * const input)
 }
 
 static char *
-_roster_autocomplete(const char * const input)
+_roster_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
     result = autocomplete_param_with_func(input, "/roster nick", roster_barejid_autocomplete);
@@ -2155,7 +2154,7 @@ _roster_autocomplete(const char * const input)
 }
 
 static char *
-_group_autocomplete(const char * const input)
+_group_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
     result = autocomplete_param_with_func(input, "/group show", roster_group_autocomplete);
@@ -2188,7 +2187,7 @@ _group_autocomplete(const char * const input)
 }
 
 static char *
-_bookmark_autocomplete(const char * const input)
+_bookmark_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
 
@@ -2267,7 +2266,7 @@ _bookmark_autocomplete(const char * const input)
 }
 
 static char *
-_notify_autocomplete(const char * const input)
+_notify_autocomplete(ProfWin *window, const char * const input)
 {
     int i = 0;
     char *result = NULL;
@@ -2330,7 +2329,7 @@ _notify_autocomplete(const char * const input)
 }
 
 static char *
-_autoaway_autocomplete(const char * const input)
+_autoaway_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
@@ -2352,7 +2351,7 @@ _autoaway_autocomplete(const char * const input)
 }
 
 static char *
-_log_autocomplete(const char * const input)
+_log_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
@@ -2375,7 +2374,7 @@ _log_autocomplete(const char * const input)
 }
 
 static char *
-_autoconnect_autocomplete(const char * const input)
+_autoconnect_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
@@ -2393,7 +2392,7 @@ _autoconnect_autocomplete(const char * const input)
 }
 
 static char *
-_otr_autocomplete(const char * const input)
+_otr_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
 
@@ -2446,7 +2445,7 @@ _otr_autocomplete(const char * const input)
 }
 
 static char *
-_theme_autocomplete(const char * const input)
+_theme_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
     if ((strncmp(input, "/theme load ", 12) == 0) && (strlen(input) > 12)) {
@@ -2475,12 +2474,11 @@ _theme_autocomplete(const char * const input)
 }
 
 static char *
-_resource_autocomplete(const char * const input)
+_resource_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
 
-    ProfWin *current = wins_get_current();
-    if (current && current->type == WIN_CHAT) {
+    if (window->type == WIN_CHAT) {
         ProfChatWin *chatwin = wins_get_current_chat();
         PContact contact = roster_get_contact(chatwin->barejid);
         if (contact) {
@@ -2511,7 +2509,7 @@ _resource_autocomplete(const char * const input)
 }
 
 static char *
-_titlebar_autocomplete(const char * const input)
+_titlebar_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
 
@@ -2534,7 +2532,7 @@ _titlebar_autocomplete(const char * const input)
 }
 
 static char *
-_inpblock_autocomplete(const char * const input)
+_inpblock_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
 
@@ -2552,16 +2550,15 @@ _inpblock_autocomplete(const char * const input)
 }
 
 static char *
-_form_autocomplete(const char * const input)
+_form_autocomplete(ProfWin *window, const char * const input)
 {
-    ProfWin *current = wins_get_current();
-    if (current->type != WIN_MUC_CONFIG) {
+    if (window->type != WIN_MUC_CONFIG) {
         return NULL;
     }
 
     char *found = NULL;
 
-    ProfMucConfWin *confwin = (ProfMucConfWin*)current;
+    ProfMucConfWin *confwin = (ProfMucConfWin*)window;
     DataForm *form = confwin->form;
     if (form) {
         found = autocomplete_param_with_ac(input, "/form help", form->tag_ac, TRUE);
@@ -2579,16 +2576,15 @@ _form_autocomplete(const char * const input)
 }
 
 static char *
-_form_field_autocomplete(const char * const input)
+_form_field_autocomplete(ProfWin *window, const char * const input)
 {
-    ProfWin *current = wins_get_current();
-    if (current->type != WIN_MUC_CONFIG) {
+    if (window->type != WIN_MUC_CONFIG) {
         return NULL;
     }
 
     char *found = NULL;
 
-    ProfMucConfWin *confwin = (ProfMucConfWin*)current;
+    ProfMucConfWin *confwin = (ProfMucConfWin*)window;
     DataForm *form = confwin->form;
     if (form == NULL) {
         return NULL;
@@ -2650,7 +2646,7 @@ _form_field_autocomplete(const char * const input)
 }
 
 static char *
-_occupants_autocomplete(const char * const input)
+_occupants_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
 
@@ -2688,7 +2684,7 @@ _occupants_autocomplete(const char * const input)
 }
 
 static char *
-_time_autocomplete(const char * const input)
+_time_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
 
@@ -2706,11 +2702,11 @@ _time_autocomplete(const char * const input)
 }
 
 static char *
-_kick_autocomplete(const char * const input)
+_kick_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
-    if (ui_current_win_type() == WIN_MUC) {
+    if (window->type == WIN_MUC) {
         ProfMucWin *mucwin = wins_get_current_muc();
         Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
 
@@ -2726,11 +2722,11 @@ _kick_autocomplete(const char * const input)
 }
 
 static char *
-_ban_autocomplete(const char * const input)
+_ban_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
-    if (ui_current_win_type() == WIN_MUC) {
+    if (window->type == WIN_MUC) {
         ProfMucWin *mucwin = wins_get_current_muc();
         Autocomplete jid_ac = muc_roster_jid_ac(mucwin->roomjid);
 
@@ -2746,11 +2742,11 @@ _ban_autocomplete(const char * const input)
 }
 
 static char *
-_affiliation_autocomplete(const char * const input)
+_affiliation_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
-    if (ui_current_win_type() == WIN_MUC) {
+    if (window->type == WIN_MUC) {
         ProfMucWin *mucwin = wins_get_current_muc();
         gboolean parse_result;
         Autocomplete jid_ac = muc_roster_jid_ac(mucwin->roomjid);
@@ -2793,11 +2789,11 @@ _affiliation_autocomplete(const char * const input)
 }
 
 static char *
-_role_autocomplete(const char * const input)
+_role_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
-    if (ui_current_win_type() == WIN_MUC) {
+    if (window->type == WIN_MUC) {
         ProfMucWin *mucwin = wins_get_current_muc();
         gboolean parse_result;
         Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
@@ -2840,7 +2836,7 @@ _role_autocomplete(const char * const input)
 }
 
 static char *
-_statuses_autocomplete(const char * const input)
+_statuses_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
@@ -2868,7 +2864,7 @@ _statuses_autocomplete(const char * const input)
 }
 
 static char *
-_receipts_autocomplete(const char * const input)
+_receipts_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
@@ -2891,7 +2887,7 @@ _receipts_autocomplete(const char * const input)
 }
 
 static char *
-_alias_autocomplete(const char * const input)
+_alias_autocomplete(ProfWin *window, const char * const input)
 {
     char *result = NULL;
 
@@ -2909,7 +2905,7 @@ _alias_autocomplete(const char * const input)
 }
 
 static char *
-_connect_autocomplete(const char * const input)
+_connect_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
     gboolean result = FALSE;
@@ -2944,7 +2940,7 @@ _connect_autocomplete(const char * const input)
 }
 
 static char *
-_join_autocomplete(const char * const input)
+_join_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
     gboolean result = FALSE;
@@ -2979,7 +2975,7 @@ _join_autocomplete(const char * const input)
 }
 
 static char *
-_account_autocomplete(const char * const input)
+_account_autocomplete(ProfWin *window, const char * const input)
 {
     char *found = NULL;
     gboolean result = FALSE;
diff --git a/src/command/command.h b/src/command/command.h
index b500404b..e6fc7ead 100644
--- a/src/command/command.h
+++ b/src/command/command.h
@@ -38,14 +38,15 @@
 #include <glib.h>
 
 #include "xmpp/form.h"
+#include "ui/ui.h"
 
 GHashTable *commands;
 
 void cmd_init(void);
 void cmd_uninit(void);
 
-char* cmd_autocomplete(const char * const input);
-void cmd_reset_autocomplete(void);
+char* cmd_autocomplete(ProfWin *window, const char * const input);
+void cmd_reset_autocomplete(ProfWin *window);
 void cmd_autocomplete_add(char *value);
 void cmd_autocomplete_remove(char *value);
 void cmd_autocomplete_add_form_fields(DataForm *form);
@@ -53,8 +54,8 @@ void cmd_autocomplete_remove_form_fields(DataForm *form);
 void cmd_alias_add(char *value);
 void cmd_alias_remove(char *value);
 
-gboolean cmd_process_input(char *inp);
-void cmd_execute_connect(const char * const account);
+gboolean cmd_process_input(ProfWin *window, char *inp);
+void cmd_execute_connect(ProfWin *window, const char * const account);
 
 gboolean cmd_exists(char *cmd);
 
diff --git a/src/command/commands.c b/src/command/commands.c
index 6ae4cf91..6d9a8732 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -133,7 +133,7 @@ cmd_execute_default(const char * inp)
 }
 
 gboolean
-cmd_execute_alias(const char * const inp, gboolean *ran)
+cmd_execute_alias(ProfWin *window, const char * const inp, gboolean *ran)
 {
     if (inp[0] != '/') {
         ran = FALSE;
@@ -145,7 +145,7 @@ cmd_execute_alias(const char * const inp, gboolean *ran)
     free(alias);
     if (value) {
         *ran = TRUE;
-        return cmd_process_input(value);
+        return cmd_process_input(window, value);
     }
 
     *ran = FALSE;
diff --git a/src/command/commands.h b/src/command/commands.h
index fb5372a6..2ede3996 100644
--- a/src/command/commands.h
+++ b/src/command/commands.h
@@ -35,6 +35,8 @@
 #ifndef COMMANDS_H
 #define COMMANDS_H
 
+#include "ui/ui.h"
+
 // Command help strings
 typedef struct cmd_help_t {
     const gchar *usage;
@@ -62,7 +64,7 @@ typedef struct cmd_t {
     CommandHelp help;
 } Command;
 
-gboolean cmd_execute_alias(const char * const inp, gboolean *ran);
+gboolean cmd_execute_alias(ProfWin *window, const char * const inp, gboolean *ran);
 gboolean cmd_execute_default(const char * inp);
 
 gboolean cmd_about(gchar **args, struct cmd_help_t help);