about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorWill Song <incertia9474@gmail.com>2014-11-27 13:18:54 -0600
committerWill Song <incertia9474@gmail.com>2014-11-27 13:18:54 -0600
commit3b13c00df4c99239180d42ea347413061342cf5a (patch)
tree46b7054b7c71d8e65f9c66f6de4d8e8e61e72683 /src/command
parentb23c60953f126277c7a06fa226c2eb10a0fe6638 (diff)
downloadprofani-tty-3b13c00df4c99239180d42ea347413061342cf5a.tar.gz
/connect supports default account
Diffstat (limited to 'src/command')
-rw-r--r--src/command/commands.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index ba6b44fc..e217e7e8 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -83,6 +83,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();
 
@@ -93,7 +94,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("");
@@ -115,6 +116,15 @@ 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;
 
@@ -146,6 +156,8 @@ cmd_connect(gchar **args, struct cmd_help_t help)
         result = TRUE;
     }
 
+    g_free(def);
+
     return result;
 }