about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/accounts.c14
-rw-r--r--src/accounts.h1
-rw-r--r--src/command.c49
3 files changed, 64 insertions, 0 deletions
diff --git a/src/accounts.c b/src/accounts.c
index 905904d3..7a84397b 100644
--- a/src/accounts.c
+++ b/src/accounts.c
@@ -84,14 +84,28 @@ accounts_reset_login_search(void)
 void
 accounts_add_login(const char *jid, const char *altdomain)
 {
+    // doesn't yet exist
     if (!g_key_file_has_group(accounts, jid)) {
         g_key_file_set_boolean(accounts, jid, "enabled", TRUE);
+        g_key_file_set_string(accounts, jid, "jid", jid);
         if (altdomain != NULL) {
             g_key_file_set_string(accounts, jid, "server", altdomain);
         }
 
         _save_accounts();
+
+    // already exists, update old style accounts
+    } else {
+        g_key_file_set_string(accounts, jid, "jid", jid);
+        _save_accounts();
     }
+
+}
+
+gchar**
+accounts_get_list(void)
+{
+    return g_key_file_get_groups(accounts, NULL);
 }
 
 static void
diff --git a/src/accounts.h b/src/accounts.h
index 1feaa1ab..e8f34bbe 100644
--- a/src/accounts.h
+++ b/src/accounts.h
@@ -29,5 +29,6 @@ void accounts_close(void);
 char * accounts_find_login(char *prefix);
 void accounts_reset_login_search(void);
 void accounts_add_login(const char *jid, const char *altdomain);
+gchar** accounts_get_list(void);
 
 #endif
diff --git a/src/command.c b/src/command.c
index 89b5654d..21457e4f 100644
--- a/src/command.c
+++ b/src/command.c
@@ -93,6 +93,7 @@ static gboolean _cmd_about(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_prefs(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_who(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_connect(gchar **args, struct cmd_help_t help);
+static gboolean _cmd_account(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_disconnect(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_sub(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_msg(gchar **args, struct cmd_help_t help);
@@ -175,6 +176,30 @@ static struct cmd_t main_commands[] =
           "Disconnect from the current session session.",
           NULL  } } },
 
+    { "/account",
+        _cmd_account, parse_args, 1, 4,
+        { "/account command [account] [property] [value]", "Manage accounts.",
+        { "/account command [account] [property] [value]",
+          "---------------------------------------------",
+          "Commands for creating and managing accounts.",
+          "list                       : List all accounts.",
+          "show account               : Show information about an account.",
+          "enable account             : Enable the account, so it is used for autocomplete.",
+          "disable account            : Disable the account.",
+          "new account                : Create a new account.",
+          "set account property value : Set 'property' of 'account' to 'value'.",
+          "",
+          "The 'property' may be one of.",
+          "jid    : The Jabber ID of the account, the account name will be used if this property is not set.",
+          "server : The chat service server, if different to the domain part of the JID.",
+          "",
+          "Example : /account new work",
+          "        : /account set work jid myuser@mycompany.com",
+          "        : /account set work server talk.google.com",
+          "",
+          "To log in to this account: '/connect work'",
+          NULL  } } },
+
     { "/prefs",
         _cmd_prefs, parse_args, 0, 1,
         { "/prefs [area]", "Show configuration.",
@@ -912,6 +937,30 @@ _cmd_connect(gchar **args, struct cmd_help_t help)
 }
 
 static gboolean
+_cmd_account(gchar **args, struct cmd_help_t help)
+{
+    char *command = args[0];
+
+    if (strcmp(command, "list") == 0) {
+        gchar **accounts = accounts_get_list();
+        int size = g_strv_length(accounts);
+
+        if (size > 0) {
+            cons_show("Accounts:");
+            int i = 0;
+            for (i = 0; i < size; i++) {
+                cons_show(accounts[i]);
+            }
+        } else {
+            cons_show("No accounts created yet.");
+        }
+    }
+    cons_show("");
+
+    return TRUE;
+}
+
+static gboolean
 _cmd_sub(gchar **args, struct cmd_help_t help)
 {
     jabber_conn_status_t conn_status = jabber_get_connection_status();