diff options
-rw-r--r-- | src/accounts.c | 60 | ||||
-rw-r--r-- | src/accounts.h | 4 | ||||
-rw-r--r-- | src/command.c | 62 |
3 files changed, 125 insertions, 1 deletions
diff --git a/src/accounts.c b/src/accounts.c index f471fbdb..22fe8693 100644 --- a/src/accounts.c +++ b/src/accounts.c @@ -95,6 +95,7 @@ accounts_add_login(const char *jid, const char *altdomain) } _save_accounts(); + p_autocomplete_add(login_ac, strdup(jid)); // already exists, update old style accounts } else { @@ -158,6 +159,65 @@ accounts_free_account(ProfAccount *account) } } +gboolean +accounts_enable(const char * const name) +{ + if (g_key_file_has_group(accounts, name)) { + g_key_file_set_boolean(accounts, name, "enabled", TRUE); + _save_accounts(); + return TRUE; + } else { + return FALSE; + } +} + +gboolean +accounts_disable(const char * const name) +{ + if (g_key_file_has_group(accounts, name)) { + g_key_file_set_boolean(accounts, name, "enabled", FALSE); + _save_accounts(); + return TRUE; + } else { + return FALSE; + } +} + +gboolean +accounts_rename(const char * const account_name, const char * const new_name) +{ + if (g_key_file_has_group(accounts, new_name)) { + return FALSE; + } + + if (!g_key_file_has_group(accounts, account_name)) { + return FALSE; + } + + g_key_file_set_boolean(accounts, new_name, "enabled", + g_key_file_get_boolean(accounts, account_name, "enabled", NULL)); + + char *jid = g_key_file_get_string(accounts, account_name, "jid", NULL); + if (jid != NULL) { + g_key_file_set_string(accounts, new_name, "jid", jid); + free(jid); + } + + char *server = g_key_file_get_string(accounts, account_name, "server", NULL); + if (server != NULL) { + g_key_file_set_string(accounts, new_name, "server", server); + free(server); + } + + g_key_file_remove_group(accounts, account_name, NULL); + _save_accounts(); + + p_autocomplete_remove(login_ac, strdup(account_name)); + p_autocomplete_add(login_ac, strdup(new_name)); + + return TRUE; +} + static void _save_accounts(void) { diff --git a/src/accounts.h b/src/accounts.h index 5d8c6460..391da849 100644 --- a/src/accounts.h +++ b/src/accounts.h @@ -39,5 +39,9 @@ void accounts_add_login(const char *jid, const char *altdomain); gchar** accounts_get_list(void); ProfAccount* accounts_get_account(const char * const name); void accounts_free_account(ProfAccount *account); +gboolean accounts_enable(const char * const name); +gboolean accounts_disable(const char * const name); +gboolean accounts_rename(const char * const account_name, + const char * const new_name); #endif diff --git a/src/command.c b/src/command.c index 2f55426b..5a2efa4c 100644 --- a/src/command.c +++ b/src/command.c @@ -188,6 +188,7 @@ static struct cmd_t main_commands[] = "enable account : Enable the account, so it is used for autocomplete.", "disable account : Disable the account.", "new account : Create a new account.", + "rename account newname : Rename account to newname.", "set account property value : Set 'property' of 'account' to 'value'.", "", "The 'property' may be one of.", @@ -197,8 +198,9 @@ static struct cmd_t main_commands[] = "Example : /account new work", " : /account set work jid myuser@mycompany.com", " : /account set work server talk.google.com", + " : /account rename work gtalk", "", - "To log in to this account: '/connect work'", + "To log in to this account: '/connect gtalk'", NULL } } }, { "/prefs", @@ -662,6 +664,7 @@ cmd_init(void) p_autocomplete_add(account_ac, strdup("new")); p_autocomplete_add(account_ac, strdup("enable")); p_autocomplete_add(account_ac, strdup("disable")); + p_autocomplete_add(account_ac, strdup("rename")); p_autocomplete_add(account_ac, strdup("set")); theme_load_ac = NULL; @@ -989,11 +992,62 @@ _cmd_account(gchar **args, struct cmd_help_t help) ProfAccount *account = accounts_get_account(account_name); if (account == NULL) { cons_show("No such account."); + cons_show(""); } else { cons_show_account(account); accounts_free_account(account); } } + } else if (strcmp(command, "new") == 0) { + char *account_name = args[1]; + if (account_name == NULL) { + cons_show("Usage: %s", help.usage); + } else { + accounts_add_login(account_name, NULL); + cons_show("Account created."); + cons_show(""); + } + } else if (strcmp(command, "enable") == 0) { + char *account_name = args[1]; + if (account_name == NULL) { + cons_show("Usage: %s", help.usage); + } else { + if (accounts_enable(account_name)) { + cons_show("Account enabled."); + cons_show(""); + } else { + cons_show("No such account: %s", account_name); + cons_show(""); + } + } + } else if (strcmp(command, "disable") == 0) { + char *account_name = args[1]; + if (account_name == NULL) { + cons_show("Usage: %s", help.usage); + } else { + if (accounts_disable(account_name)) { + cons_show("Account disabled."); + cons_show(""); + } else { + cons_show("No such account: %s", account_name); + cons_show(""); + } + } + } else if (strcmp(command, "rename") == 0) { + if (g_strv_length(args) != 3) { + cons_show("Usage: %s", help.usage); + } else { + char *account_name = args[1]; + char *new_name = args[2]; + + if (accounts_rename(account_name, new_name)) { + cons_show("Account renamed."); + cons_show(""); + } else { + cons_show("Either account %s doesn't exist, or account %s already exists.", account_name, new_name); + cons_show(""); + } + } } else { cons_show(""); } @@ -2141,6 +2195,12 @@ _account_autocomplete(char *input, int *size) { if ((strncmp(input, "/account show ", 14) == 0) && (*size > 14)) { _parameter_autocomplete(input, size, "/account show", accounts_find_login); + } else if ((strncmp(input, "/account enable ", 16) == 0) && (*size > 16)) { + _parameter_autocomplete(input, size, "/account enable", accounts_find_login); + } else if ((strncmp(input, "/account disable ", 17) == 0) && (*size > 17)) { + _parameter_autocomplete(input, size, "/account disable", accounts_find_login); + } else if ((strncmp(input, "/account rename ", 16) == 0) && (*size > 16)) { + _parameter_autocomplete(input, size, "/account rename", accounts_find_login); } else if ((strncmp(input, "/account ", 9) == 0) && (*size > 9)) { _parameter_autocomplete_with_ac(input, size, "/account", account_ac); } |