aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-12-29 15:29:28 +0000
committerJames Booth <boothj5@gmail.com>2014-12-29 15:29:28 +0000
commitaebee209b2698eba40b1b220e162f87db23cc838 (patch)
treef5396a26e24e5fbee16a20a832284304dfa080c6 /src/command
parent1c35321cb315b7ce5bee3f5f281df103b0bc1f77 (diff)
parent1dca023c9f56a8c1a30d1b8de08dc9878b161bf6 (diff)
downloadprofani-tty-aebee209b2698eba40b1b220e162f87db23cc838.tar.gz
Merge remote-tracking branch 'incertia/connect-default'
Conflicts: CHANGELOG
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c27
-rw-r--r--src/command/commands.c57
2 files changed, 76 insertions, 8 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 9fbc0626..5c1f858d 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -129,16 +129,18 @@ static struct cmd_t command_defs[] =
NULL } } },
{ "/connect",
- cmd_connect, parse_args, 1, 5, NULL,
- { "/connect account [server value] [port value]", "Login to a chat service.",
- { "/connect account [server value] [port value]",
- "--------------------------------------------",
+ cmd_connect, parse_args, 0, 5, NULL,
+ { "/connect [account] [server value] [port value]", "Login to a chat service.",
+ { "/connect [account] [server value] [port value]",
+ "----------------------------------------------",
"Connect to an XMPP service using the specified account.",
"Use the server property to specify a server if required.",
"Change the default port (5222, or 5223 for SSL) with the port property.",
"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.",
"",
+ "Example: /connect",
"Example: /connect myuser@gmail.com",
"Example: /connect myuser@mycompany.com server talk.google.com",
"Example: /connect bob@someplace port 5678",
@@ -911,6 +913,7 @@ static struct cmd_t command_defs[] =
"show account : Show information about an account.",
"enable account : Enable the account, it will be used for autocomplete.",
"disable account : Disable the account.",
+ "default [set|off] [account] : Set the default account.",
"add account : Create a new account.",
"remove account : Remove an account.",
"rename account newname : Rename account to newname.",
@@ -1076,6 +1079,7 @@ static Autocomplete theme_load_ac;
static Autocomplete account_ac;
static Autocomplete account_set_ac;
static Autocomplete account_clear_ac;
+static Autocomplete account_default_ac;
static Autocomplete disco_ac;
static Autocomplete close_ac;
static Autocomplete wins_ac;
@@ -1239,6 +1243,7 @@ cmd_init(void)
autocomplete_add(account_ac, "remove");
autocomplete_add(account_ac, "enable");
autocomplete_add(account_ac, "disable");
+ autocomplete_add(account_ac, "default");
autocomplete_add(account_ac, "rename");
autocomplete_add(account_ac, "set");
autocomplete_add(account_ac, "clear");
@@ -1265,6 +1270,10 @@ cmd_init(void)
autocomplete_add(account_clear_ac, "port");
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();
autocomplete_add(close_ac, "read");
autocomplete_add(close_ac, "all");
@@ -1473,6 +1482,7 @@ cmd_uninit(void)
autocomplete_free(account_ac);
autocomplete_free(account_set_ac);
autocomplete_free(account_clear_ac);
+ autocomplete_free(account_default_ac);
autocomplete_free(disco_ac);
autocomplete_free(close_ac);
autocomplete_free(wins_ac);
@@ -1639,6 +1649,7 @@ cmd_reset_autocomplete()
autocomplete_reset(account_ac);
autocomplete_reset(account_set_ac);
autocomplete_reset(account_clear_ac);
+ autocomplete_reset(account_default_ac);
autocomplete_reset(disco_ac);
autocomplete_reset(close_ac);
autocomplete_reset(wins_ac);
@@ -2878,9 +2889,15 @@ _account_autocomplete(char *input, int *size)
g_strfreev(args);
+ found = autocomplete_param_with_ac(input, size, "/account default", account_default_ac, TRUE);
+ if(found){
+ return found;
+ }
+
int i = 0;
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++) {
found = autocomplete_param_with_func(input, size, account_choice[i],
diff --git a/src/command/commands.c b/src/command/commands.c
index 53d6782b..5b5bd95e 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -84,6 +84,7 @@ gboolean
cmd_connect(gchar **args, struct cmd_help_t help)
{
gboolean result = FALSE;
+ char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
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 };
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) {
cons_show("Usage: %s", help.usage);
cons_show("");
@@ -113,9 +114,16 @@ cmd_connect(gchar **args, struct cmd_help_t help)
}
}
- options_destroy(options);
-
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 *jid;
@@ -126,6 +134,8 @@ cmd_connect(gchar **args, struct cmd_help_t help)
account->password = ui_ask_password();
}
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);
account_free(account);
} else {
@@ -142,11 +152,15 @@ cmd_connect(gchar **args, struct cmd_help_t help)
log_info("Connection attempt for %s failed", jid);
}
+ options_destroy(options);
+
free(jid);
result = TRUE;
}
+ g_free(def);
+
return result;
}
@@ -195,13 +209,19 @@ cmd_account(gchar **args, struct cmd_help_t help)
if(!account_name) {
cons_show("Usage: %s", help.usage);
} else {
+ char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
if(accounts_remove(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 {
cons_show("Failed to remove account %s.", account_name);
cons_show("Either the account does not exist, or an unknown error occurred.");
}
cons_show("");
+ g_free(def);
}
} else if (strcmp(command, "enable") == 0) {
char *account_name = args[1];
@@ -244,6 +264,37 @@ cmd_account(gchar **args, struct cmd_help_t help)
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) {
if (g_strv_length(args) != 4) {
cons_show("Usage: %s", help.usage);