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

Added /account rename

This commit is contained in:
James Booth 2012-12-10 00:08:03 +00:00
parent 30cb06ed74
commit c80383e298
3 changed files with 125 additions and 1 deletions

View File

@ -95,6 +95,7 @@ accounts_add_login(const char *jid, const char *altdomain)
} }
_save_accounts(); _save_accounts();
p_autocomplete_add(login_ac, strdup(jid));
// already exists, update old style accounts // already exists, update old style accounts
} else { } 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 static void
_save_accounts(void) _save_accounts(void)
{ {

View File

@ -39,5 +39,9 @@ void accounts_add_login(const char *jid, const char *altdomain);
gchar** accounts_get_list(void); gchar** accounts_get_list(void);
ProfAccount* accounts_get_account(const char * const name); ProfAccount* accounts_get_account(const char * const name);
void accounts_free_account(ProfAccount *account); 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 #endif

View File

@ -188,6 +188,7 @@ static struct cmd_t main_commands[] =
"enable account : Enable the account, so it is used for autocomplete.", "enable account : Enable the account, so it is used for autocomplete.",
"disable account : Disable the account.", "disable account : Disable the account.",
"new account : Create a new account.", "new account : Create a new account.",
"rename account newname : Rename account to newname.",
"set account property value : Set 'property' of 'account' to 'value'.", "set account property value : Set 'property' of 'account' to 'value'.",
"", "",
"The 'property' may be one of.", "The 'property' may be one of.",
@ -197,8 +198,9 @@ static struct cmd_t main_commands[] =
"Example : /account new work", "Example : /account new work",
" : /account set work jid myuser@mycompany.com", " : /account set work jid myuser@mycompany.com",
" : /account set work server talk.google.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 } } }, NULL } } },
{ "/prefs", { "/prefs",
@ -662,6 +664,7 @@ cmd_init(void)
p_autocomplete_add(account_ac, strdup("new")); p_autocomplete_add(account_ac, strdup("new"));
p_autocomplete_add(account_ac, strdup("enable")); p_autocomplete_add(account_ac, strdup("enable"));
p_autocomplete_add(account_ac, strdup("disable")); p_autocomplete_add(account_ac, strdup("disable"));
p_autocomplete_add(account_ac, strdup("rename"));
p_autocomplete_add(account_ac, strdup("set")); p_autocomplete_add(account_ac, strdup("set"));
theme_load_ac = NULL; theme_load_ac = NULL;
@ -989,11 +992,62 @@ _cmd_account(gchar **args, struct cmd_help_t help)
ProfAccount *account = accounts_get_account(account_name); ProfAccount *account = accounts_get_account(account_name);
if (account == NULL) { if (account == NULL) {
cons_show("No such account."); cons_show("No such account.");
cons_show("");
} else { } else {
cons_show_account(account); cons_show_account(account);
accounts_free_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 { } else {
cons_show(""); cons_show("");
} }
@ -2141,6 +2195,12 @@ _account_autocomplete(char *input, int *size)
{ {
if ((strncmp(input, "/account show ", 14) == 0) && (*size > 14)) { if ((strncmp(input, "/account show ", 14) == 0) && (*size > 14)) {
_parameter_autocomplete(input, size, "/account show", accounts_find_login); _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)) { } else if ((strncmp(input, "/account ", 9) == 0) && (*size > 9)) {
_parameter_autocomplete_with_ac(input, size, "/account", account_ac); _parameter_autocomplete_with_ac(input, size, "/account", account_ac);
} }