From 8415f57b3293742547f07323fbefdd278bdcb24d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 10 Dec 2012 00:23:55 +0000 Subject: [PATCH] Added /account set command, set server or jid --- src/accounts.c | 25 +++++++++++++++++++++++++ src/accounts.h | 3 +++ src/command.c | 26 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/src/accounts.c b/src/accounts.c index 22fe8693..7729cfb4 100644 --- a/src/accounts.c +++ b/src/accounts.c @@ -218,6 +218,31 @@ accounts_rename(const char * const account_name, const char * const new_name) return TRUE; } +gboolean +accounts_account_exists(const char * const account_name) +{ + return g_key_file_has_group(accounts, account_name); + +} + +void +accounts_set_jid(const char * const account_name, const char * const value) +{ + if (accounts_account_exists(account_name)) { + g_key_file_set_string(accounts, account_name, "jid", value); + _save_accounts(); + } +} + +void +accounts_set_server(const char * const account_name, const char * const value) +{ + if (accounts_account_exists(account_name)) { + g_key_file_set_string(accounts, account_name, "server", value); + _save_accounts(); + } +} + static void _save_accounts(void) { diff --git a/src/accounts.h b/src/accounts.h index 391da849..042eb058 100644 --- a/src/accounts.h +++ b/src/accounts.h @@ -43,5 +43,8 @@ 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); +gboolean accounts_account_exists(const char * const account_name); +void accounts_set_jid(const char * const account_name, const char * const value); +void accounts_set_server(const char * const account_name, const char * const value); #endif diff --git a/src/command.c b/src/command.c index 5a2efa4c..600a5065 100644 --- a/src/command.c +++ b/src/command.c @@ -1048,6 +1048,32 @@ _cmd_account(gchar **args, struct cmd_help_t help) cons_show(""); } } + } else if (strcmp(command, "set") == 0) { + if (g_strv_length(args) != 4) { + cons_show("Usage: %s", help.usage); + } else { + char *account_name = args[1]; + char *property = args[2]; + char *value = args[3]; + + if (!accounts_account_exists(account_name)) { + cons_show("Account %s doesn't exist"); + cons_show(""); + } else { + if (strcmp(property, "jid") == 0) { + accounts_set_jid(account_name, value); + cons_show("Updated jid for account %s: %s", account_name, value); + cons_show(""); + } else if (strcmp(property, "server") == 0) { + accounts_set_server(account_name, value); + cons_show("Updated server for account %s: %s", account_name, value); + cons_show(""); + } else { + cons_show("Invalid property: %s", property); + cons_show(""); + } + } + } } else { cons_show(""); }