From 3ce0d0f87770dbe9c992be76dc9bafa558c3f89b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Dec 2013 21:49:34 +0000 Subject: [PATCH] Added command parameter to /autoconnect (set, off) fixes #261 --- src/command/command.c | 63 +++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index f7737464..d86af195 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -82,6 +82,7 @@ static char * _notify_autocomplete(char *input, int *size); static char * _titlebar_autocomplete(char *input, int *size); static char * _theme_autocomplete(char *input, int *size); static char * _autoaway_autocomplete(char *input, int *size); +static char * _autoconnect_autocomplete(char *input, int *size); static char * _account_autocomplete(char *input, int *size); static char * _who_autocomplete(char *input, int *size); static char * _roster_autocomplete(char *input, int *size); @@ -581,13 +582,15 @@ static struct cmd_t command_defs[] = NULL } } }, { "/autoconnect", - _cmd_autoconnect, parse_args, 0, 1, cons_autoconnect_setting, - { "/autoconnect [account]", "Set account to autoconnect with.", - { "/autoconnect [account]", - "----------------------", - "Set the account to autoconnect with.", - "Will be overridden by any command line options specified.", - "Passing no account will clear the setting.", + _cmd_autoconnect, parse_args, 1, 2, cons_autoconnect_setting, + { "/autoconnect set|off [account]", "Set account to autoconnect with.", + { "/autoconnect set|off [account]", + "------------------------------", + "Enable or disable autoconnect on start up.", + "The setting can be overridden by the -a (--account) command line option.", + "", + "Example: /autoconnect set jc@stuntteam.org (autoconnect with the specified account).", + "Example: /autoconnect off (disable autoconnect).", NULL } } }, { "/vercheck", @@ -882,6 +885,7 @@ static Autocomplete sub_ac; static Autocomplete log_ac; static Autocomplete autoaway_ac; static Autocomplete autoaway_mode_ac; +static Autocomplete autoconnect_ac; static Autocomplete titlebar_ac; static Autocomplete theme_ac; static Autocomplete theme_load_ac; @@ -969,6 +973,10 @@ cmd_init(void) autocomplete_add(autoaway_mode_ac, "idle"); autocomplete_add(autoaway_mode_ac, "off"); + autoconnect_ac = autocomplete_new(); + autocomplete_add(autoconnect_ac, "set"); + autocomplete_add(autoconnect_ac, "off"); + theme_ac = autocomplete_new(); autocomplete_add(theme_ac, "list"); autocomplete_add(theme_ac, "set"); @@ -1038,6 +1046,7 @@ cmd_close(void) autocomplete_free(prefs_ac); autocomplete_free(autoaway_ac); autocomplete_free(autoaway_mode_ac); + autocomplete_free(autoconnect_ac); autocomplete_free(theme_ac); if (theme_load_ac != NULL) { autocomplete_free(theme_load_ac); @@ -1107,6 +1116,7 @@ cmd_reset_autocomplete() autocomplete_reset(commands_ac); autocomplete_reset(autoaway_ac); autocomplete_reset(autoaway_mode_ac); + autocomplete_reset(autoconnect_ac); autocomplete_reset(theme_ac); if (theme_load_ac != NULL) { autocomplete_reset(theme_load_ac); @@ -1314,13 +1324,6 @@ _cmd_complete_parameters(char *input, int *size) return; } - result = autocomplete_param_with_func(input, size, "/autoconnect", accounts_find_enabled); - if (result != NULL) { - inp_replace_input(input, result, size); - g_free(result); - return; - } - gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins" }; Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac }; @@ -1336,7 +1339,7 @@ _cmd_complete_parameters(char *input, int *size) autocompleter acs[] = { _who_autocomplete, _sub_autocomplete, _notify_autocomplete, _autoaway_autocomplete, _titlebar_autocomplete, _theme_autocomplete, _account_autocomplete, _roster_autocomplete, _group_autocomplete, - _bookmark_autocomplete }; + _bookmark_autocomplete, _autoconnect_autocomplete }; for (i = 0; i < ARRAY_SIZE(acs); i++) { result = acs[i](input, size); @@ -3473,12 +3476,14 @@ _cmd_splash(gchar **args, struct cmd_help_t help) static gboolean _cmd_autoconnect(gchar **args, struct cmd_help_t help) { - if (args[0] == NULL) { - prefs_set_string(PREF_CONNECT_ACCOUNT, NULL); - cons_show("Autoconnect account disabled."); + if (strcmp(args[0], "off") == 0) { + prefs_set_string(PREF_CONNECT_ACCOUNT, NULL); + cons_show("Autoconnect account disabled."); + } else if (strcmp(args[0], "set") == 0) { + prefs_set_string(PREF_CONNECT_ACCOUNT, args[1]); + cons_show("Autoconnect account set to: %s.", args[1]); } else { - prefs_set_string(PREF_CONNECT_ACCOUNT, args[0]); - cons_show("Autoconnect account set to: %s.", args[0]); + cons_show("Usage: %s", help.usage); } return true; } @@ -3826,6 +3831,24 @@ _autoaway_autocomplete(char *input, int *size) return NULL; } +static char * +_autoconnect_autocomplete(char *input, int *size) +{ + char *result = NULL; + + result = autocomplete_param_with_func(input, size, "/autoconnect set", accounts_find_enabled); + if (result != NULL) { + return result; + } + + result = autocomplete_param_with_ac(input, size, "/autoconnect", autoconnect_ac); + if (result != NULL) { + return result; + } + + return NULL; +} + static char * _theme_autocomplete(char *input, int *size) {