1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Allow "account" setting in [connection] to autconnect the account

closes #251
This commit is contained in:
James Booth 2013-11-07 23:04:12 +00:00
parent bde205cfe3
commit f0947ccce7
6 changed files with 53 additions and 2 deletions

View File

@ -92,6 +92,7 @@ static int _strtoi(char *str, int *saveptr, int min, int max);
static gboolean _cmd_about(gchar **args, struct cmd_help_t help); static gboolean _cmd_about(gchar **args, struct cmd_help_t help);
static gboolean _cmd_account(gchar **args, struct cmd_help_t help); static gboolean _cmd_account(gchar **args, struct cmd_help_t help);
static gboolean _cmd_autoaway(gchar **args, struct cmd_help_t help); static gboolean _cmd_autoaway(gchar **args, struct cmd_help_t help);
static gboolean _cmd_autoconnect(gchar **args, struct cmd_help_t help);
static gboolean _cmd_autoping(gchar **args, struct cmd_help_t help); static gboolean _cmd_autoping(gchar **args, struct cmd_help_t help);
static gboolean _cmd_away(gchar **args, struct cmd_help_t help); static gboolean _cmd_away(gchar **args, struct cmd_help_t help);
static gboolean _cmd_beep(gchar **args, struct cmd_help_t help); static gboolean _cmd_beep(gchar **args, struct cmd_help_t help);
@ -558,6 +559,16 @@ static struct cmd_t command_defs[] =
"Switch on or off the ascii logo on start up and when the /about command is called.", "Switch on or off the ascii logo on start up and when the /about command is called.",
NULL } } }, 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.",
NULL } } },
{ "/vercheck", { "/vercheck",
_cmd_vercheck, parse_args, 0, 1, NULL, _cmd_vercheck, parse_args, 0, 1, NULL,
{ "/vercheck [on|off]", "Check for a new release.", { "/vercheck [on|off]", "Check for a new release.",
@ -1267,6 +1278,13 @@ _cmd_complete_parameters(char *input, int *size)
return; 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" }; gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins" };
Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac }; Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac };
@ -1760,7 +1778,7 @@ _cmd_help(gchar **args, struct cmd_help_t help)
_cmd_show_filtered_help("Service discovery commands", filter, ARRAY_SIZE(filter)); _cmd_show_filtered_help("Service discovery commands", filter, ARRAY_SIZE(filter));
} else if (strcmp(args[0], "settings") == 0) { } else if (strcmp(args[0], "settings") == 0) {
gchar *filter[] = { "/account", "/autoaway", "/autoping", "/beep", gchar *filter[] = { "/account", "/autoaway", "/autoping", "/autoconnect", "/beep",
"/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype",
"/log", "/mouse", "/notify", "/outtype", "/prefs", "/priority", "/log", "/mouse", "/notify", "/outtype", "/prefs", "/priority",
"/reconnect", "/roster", "/splash", "/states", "/statuses", "/theme", "/reconnect", "/roster", "/splash", "/states", "/statuses", "/theme",
@ -3365,6 +3383,19 @@ _cmd_splash(gchar **args, struct cmd_help_t help)
"Splash screen", PREF_SPLASH); "Splash screen", PREF_SPLASH);
} }
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.");
} else {
prefs_set_string(PREF_CONNECT_ACCOUNT, args[0]);
cons_show("Autoconnect account set to: %s.", args[0]);
}
return true;
}
static gboolean static gboolean
_cmd_chlog(gchar **args, struct cmd_help_t help) _cmd_chlog(gchar **args, struct cmd_help_t help)
{ {

View File

@ -309,6 +309,8 @@ _get_group(preference_t pref)
case PREF_AUTOAWAY_MODE: case PREF_AUTOAWAY_MODE:
case PREF_AUTOAWAY_MESSAGE: case PREF_AUTOAWAY_MESSAGE:
return "presence"; return "presence";
case PREF_CONNECT_ACCOUNT:
return "connection";
default: default:
return NULL; return NULL;
} }
@ -361,6 +363,8 @@ _get_key(preference_t pref)
return "autoaway.mode"; return "autoaway.mode";
case PREF_AUTOAWAY_MESSAGE: case PREF_AUTOAWAY_MESSAGE:
return "autoaway.message"; return "autoaway.message";
case PREF_CONNECT_ACCOUNT:
return "account";
default: default:
return NULL; return NULL;
} }

View File

@ -56,7 +56,8 @@ typedef enum {
PREF_GRLOG, PREF_GRLOG,
PREF_AUTOAWAY_CHECK, PREF_AUTOAWAY_CHECK,
PREF_AUTOAWAY_MODE, PREF_AUTOAWAY_MODE,
PREF_AUTOAWAY_MESSAGE PREF_AUTOAWAY_MESSAGE,
PREF_CONNECT_ACCOUNT
} preference_t; } preference_t;
void prefs_load(void); void prefs_load(void);

View File

@ -72,6 +72,10 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
char *cmd = "/connect"; char *cmd = "/connect";
snprintf(inp, sizeof(inp), "%s %s", cmd, account_name); snprintf(inp, sizeof(inp), "%s %s", cmd, account_name);
_process_input(inp); _process_input(inp);
} else if (prefs_get_string(PREF_CONNECT_ACCOUNT) != NULL) {
char *cmd = "/connect";
snprintf(inp, sizeof(inp), "%s %s", cmd, prefs_get_string(PREF_CONNECT_ACCOUNT));
_process_input(inp);
} }
while(cmd_result == TRUE) { while(cmd_result == TRUE) {

View File

@ -950,6 +950,15 @@ cons_splash_setting(void)
cons_show("Splash screen (/splash) : OFF"); cons_show("Splash screen (/splash) : OFF");
} }
void
cons_autoconnect_setting(void)
{
if (prefs_get_string(PREF_CONNECT_ACCOUNT) != NULL)
cons_show("Autoconnect (/autoconnect) : %s", prefs_get_string(PREF_CONNECT_ACCOUNT));
else
cons_show("Autoconnect (/autoconnect) : OFF");
}
void void
cons_vercheck_setting(void) cons_vercheck_setting(void)
{ {
@ -1226,6 +1235,7 @@ cons_show_connection_prefs(void)
cons_show(""); cons_show("");
cons_reconnect_setting(); cons_reconnect_setting();
cons_autoping_setting(); cons_autoping_setting();
cons_autoconnect_setting();
ui_console_dirty(); ui_console_dirty();
cons_alert(); cons_alert();

View File

@ -217,6 +217,7 @@ void cons_autoaway_setting(void);
void cons_reconnect_setting(void); void cons_reconnect_setting(void);
void cons_autoping_setting(void); void cons_autoping_setting(void);
void cons_priority_setting(void); void cons_priority_setting(void);
void cons_autoconnect_setting(void);
// status bar actions // status bar actions
void status_bar_refresh(void); void status_bar_refresh(void);