1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Merge remote-tracking branch 'incertia/connect-default'

Conflicts:
	CHANGELOG
This commit is contained in:
James Booth 2014-12-29 15:29:28 +00:00
commit aebee209b2
5 changed files with 81 additions and 8 deletions

View File

@ -7,3 +7,4 @@
- Show hide time (/time) - Show hide time (/time)
- Show or hide and customise roster panel (/roster) - Show or hide and customise roster panel (/roster)
- /account remove - /account remove
- Added default account for /connect

View File

@ -129,16 +129,18 @@ static struct cmd_t command_defs[] =
NULL } } }, NULL } } },
{ "/connect", { "/connect",
cmd_connect, parse_args, 1, 5, NULL, cmd_connect, parse_args, 0, 5, NULL,
{ "/connect account [server value] [port value]", "Login to a chat service.", { "/connect [account] [server value] [port value]", "Login to a chat service.",
{ "/connect account [server value] [port value]", { "/connect [account] [server value] [port value]",
"--------------------------------------------", "----------------------------------------------",
"Connect to an XMPP service using the specified account.", "Connect to an XMPP service using the specified account.",
"Use the server property to specify a server if required.", "Use the server property to specify a server if required.",
"Change the default port (5222, or 5223 for SSL) with the port property.", "Change the default port (5222, or 5223 for SSL) with the port property.",
"An account is automatically created if one does not exist.", "An account is automatically created if one does not exist.",
"If no account is specified, then the default account is used."
"See the /account command for more details.", "See the /account command for more details.",
"", "",
"Example: /connect",
"Example: /connect myuser@gmail.com", "Example: /connect myuser@gmail.com",
"Example: /connect myuser@mycompany.com server talk.google.com", "Example: /connect myuser@mycompany.com server talk.google.com",
"Example: /connect bob@someplace port 5678", "Example: /connect bob@someplace port 5678",
@ -911,6 +913,7 @@ static struct cmd_t command_defs[] =
"show account : Show information about an account.", "show account : Show information about an account.",
"enable account : Enable the account, it will be used for autocomplete.", "enable account : Enable the account, it will be used for autocomplete.",
"disable account : Disable the account.", "disable account : Disable the account.",
"default [set|off] [account] : Set the default account.",
"add account : Create a new account.", "add account : Create a new account.",
"remove account : Remove an account.", "remove account : Remove an account.",
"rename account newname : Rename account to newname.", "rename account newname : Rename account to newname.",
@ -1076,6 +1079,7 @@ static Autocomplete theme_load_ac;
static Autocomplete account_ac; static Autocomplete account_ac;
static Autocomplete account_set_ac; static Autocomplete account_set_ac;
static Autocomplete account_clear_ac; static Autocomplete account_clear_ac;
static Autocomplete account_default_ac;
static Autocomplete disco_ac; static Autocomplete disco_ac;
static Autocomplete close_ac; static Autocomplete close_ac;
static Autocomplete wins_ac; static Autocomplete wins_ac;
@ -1239,6 +1243,7 @@ cmd_init(void)
autocomplete_add(account_ac, "remove"); autocomplete_add(account_ac, "remove");
autocomplete_add(account_ac, "enable"); autocomplete_add(account_ac, "enable");
autocomplete_add(account_ac, "disable"); autocomplete_add(account_ac, "disable");
autocomplete_add(account_ac, "default");
autocomplete_add(account_ac, "rename"); autocomplete_add(account_ac, "rename");
autocomplete_add(account_ac, "set"); autocomplete_add(account_ac, "set");
autocomplete_add(account_ac, "clear"); autocomplete_add(account_ac, "clear");
@ -1265,6 +1270,10 @@ cmd_init(void)
autocomplete_add(account_clear_ac, "port"); autocomplete_add(account_clear_ac, "port");
autocomplete_add(account_clear_ac, "otr"); autocomplete_add(account_clear_ac, "otr");
account_default_ac = autocomplete_new();
autocomplete_add(account_default_ac, "set");
autocomplete_add(account_default_ac, "off");
close_ac = autocomplete_new(); close_ac = autocomplete_new();
autocomplete_add(close_ac, "read"); autocomplete_add(close_ac, "read");
autocomplete_add(close_ac, "all"); autocomplete_add(close_ac, "all");
@ -1473,6 +1482,7 @@ cmd_uninit(void)
autocomplete_free(account_ac); autocomplete_free(account_ac);
autocomplete_free(account_set_ac); autocomplete_free(account_set_ac);
autocomplete_free(account_clear_ac); autocomplete_free(account_clear_ac);
autocomplete_free(account_default_ac);
autocomplete_free(disco_ac); autocomplete_free(disco_ac);
autocomplete_free(close_ac); autocomplete_free(close_ac);
autocomplete_free(wins_ac); autocomplete_free(wins_ac);
@ -1639,6 +1649,7 @@ cmd_reset_autocomplete()
autocomplete_reset(account_ac); autocomplete_reset(account_ac);
autocomplete_reset(account_set_ac); autocomplete_reset(account_set_ac);
autocomplete_reset(account_clear_ac); autocomplete_reset(account_clear_ac);
autocomplete_reset(account_default_ac);
autocomplete_reset(disco_ac); autocomplete_reset(disco_ac);
autocomplete_reset(close_ac); autocomplete_reset(close_ac);
autocomplete_reset(wins_ac); autocomplete_reset(wins_ac);
@ -2878,9 +2889,15 @@ _account_autocomplete(char *input, int *size)
g_strfreev(args); g_strfreev(args);
found = autocomplete_param_with_ac(input, size, "/account default", account_default_ac, TRUE);
if(found){
return found;
}
int i = 0; int i = 0;
gchar *account_choice[] = { "/account set", "/account show", "/account enable", gchar *account_choice[] = { "/account set", "/account show", "/account enable",
"/account disable", "/account rename", "/account clear", "/account remove" }; "/account disable", "/account rename", "/account clear", "/account remove",
"/account default set" };
for (i = 0; i < ARRAY_SIZE(account_choice); i++) { for (i = 0; i < ARRAY_SIZE(account_choice); i++) {
found = autocomplete_param_with_func(input, size, account_choice[i], found = autocomplete_param_with_func(input, size, account_choice[i],

View File

@ -84,6 +84,7 @@ gboolean
cmd_connect(gchar **args, struct cmd_help_t help) cmd_connect(gchar **args, struct cmd_help_t help)
{ {
gboolean result = FALSE; gboolean result = FALSE;
char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
@ -94,7 +95,7 @@ cmd_connect(gchar **args, struct cmd_help_t help)
gchar *opt_keys[] = { "server", "port", NULL }; gchar *opt_keys[] = { "server", "port", NULL };
gboolean parsed; gboolean parsed;
GHashTable *options = parse_options(&args[1], opt_keys, &parsed); GHashTable *options = parse_options(&args[args[0] ? 1 : 0], opt_keys, &parsed);
if (!parsed) { if (!parsed) {
cons_show("Usage: %s", help.usage); cons_show("Usage: %s", help.usage);
cons_show(""); cons_show("");
@ -113,9 +114,16 @@ cmd_connect(gchar **args, struct cmd_help_t help)
} }
} }
options_destroy(options);
char *user = args[0]; char *user = args[0];
if(!user){
if(def){
user = def;
cons_show("Using default account %s.", user);
} else {
cons_show("No default account.");
return TRUE;
}
}
char *lower = g_utf8_strdown(user, -1); char *lower = g_utf8_strdown(user, -1);
char *jid; char *jid;
@ -126,6 +134,8 @@ cmd_connect(gchar **args, struct cmd_help_t help)
account->password = ui_ask_password(); account->password = ui_ask_password();
} }
cons_show("Connecting with account %s as %s", account->name, jid); cons_show("Connecting with account %s as %s", account->name, jid);
if(g_hash_table_contains(options, "port") || g_hash_table_contains(options, "server"))
cons_show("Ignoring extra connect options. Please set them with /account set");
conn_status = jabber_connect_with_account(account); conn_status = jabber_connect_with_account(account);
account_free(account); account_free(account);
} else { } else {
@ -142,11 +152,15 @@ cmd_connect(gchar **args, struct cmd_help_t help)
log_info("Connection attempt for %s failed", jid); log_info("Connection attempt for %s failed", jid);
} }
options_destroy(options);
free(jid); free(jid);
result = TRUE; result = TRUE;
} }
g_free(def);
return result; return result;
} }
@ -195,13 +209,19 @@ cmd_account(gchar **args, struct cmd_help_t help)
if(!account_name) { if(!account_name) {
cons_show("Usage: %s", help.usage); cons_show("Usage: %s", help.usage);
} else { } else {
char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
if(accounts_remove(account_name)){ if(accounts_remove(account_name)){
cons_show("Account %s removed.", account_name); cons_show("Account %s removed.", account_name);
if(def && strcmp(def, account_name) == 0){
prefs_set_string(PREF_DEFAULT_ACCOUNT, NULL);
cons_show("Default account removed because the corresponding account was removed.");
}
} else { } else {
cons_show("Failed to remove account %s.", account_name); cons_show("Failed to remove account %s.", account_name);
cons_show("Either the account does not exist, or an unknown error occurred."); cons_show("Either the account does not exist, or an unknown error occurred.");
} }
cons_show(""); cons_show("");
g_free(def);
} }
} else if (strcmp(command, "enable") == 0) { } else if (strcmp(command, "enable") == 0) {
char *account_name = args[1]; char *account_name = args[1];
@ -244,6 +264,37 @@ cmd_account(gchar **args, struct cmd_help_t help)
cons_show(""); cons_show("");
} }
} }
} else if (strcmp(command, "default") == 0) {
if(g_strv_length(args) == 1){
char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
if(def){
cons_show("The default account is %s.", def);
free(def);
} else {
cons_show("No default account.");
}
} else if(g_strv_length(args) == 2){
if(strcmp(args[1], "off") == 0){
prefs_set_string(PREF_DEFAULT_ACCOUNT, NULL);
cons_show("Removed default account.");
} else {
cons_show("Usage: %s", help.usage);
}
} else if(g_strv_length(args) == 3) {
if(strcmp(args[1], "set") == 0){
if(accounts_get_account(args[2])){
prefs_set_string(PREF_DEFAULT_ACCOUNT, args[2]);
cons_show("Default account set to %s.", args[2]);
} else {
cons_show("Account %s does not exist.", args[2]);
}
} else {
cons_show("Usage: %s", help.usage);
}
} else {
cons_show("Usage: %s", help.usage);
}
} else if (strcmp(command, "set") == 0) { } else if (strcmp(command, "set") == 0) {
if (g_strv_length(args) != 4) { if (g_strv_length(args) != 4) {
cons_show("Usage: %s", help.usage); cons_show("Usage: %s", help.usage);

View File

@ -539,6 +539,7 @@ _get_group(preference_t pref)
case PREF_AUTOAWAY_MESSAGE: case PREF_AUTOAWAY_MESSAGE:
return PREF_GROUP_PRESENCE; return PREF_GROUP_PRESENCE;
case PREF_CONNECT_ACCOUNT: case PREF_CONNECT_ACCOUNT:
case PREF_DEFAULT_ACCOUNT:
return PREF_GROUP_CONNECTION; return PREF_GROUP_CONNECTION;
case PREF_OTR_WARN: case PREF_OTR_WARN:
case PREF_OTR_LOG: case PREF_OTR_LOG:
@ -620,6 +621,8 @@ _get_key(preference_t pref)
return "autoaway.message"; return "autoaway.message";
case PREF_CONNECT_ACCOUNT: case PREF_CONNECT_ACCOUNT:
return "account"; return "account";
case PREF_DEFAULT_ACCOUNT:
return "defaccount";
case PREF_OTR_LOG: case PREF_OTR_LOG:
return "log"; return "log";
case PREF_OTR_WARN: case PREF_OTR_WARN:

View File

@ -90,6 +90,7 @@ typedef enum {
PREF_AUTOAWAY_MODE, PREF_AUTOAWAY_MODE,
PREF_AUTOAWAY_MESSAGE, PREF_AUTOAWAY_MESSAGE,
PREF_CONNECT_ACCOUNT, PREF_CONNECT_ACCOUNT,
PREF_DEFAULT_ACCOUNT,
PREF_LOG_ROTATE, PREF_LOG_ROTATE,
PREF_LOG_SHARED, PREF_LOG_SHARED,
PREF_OTR_LOG, PREF_OTR_LOG,