about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-12-29 15:29:28 +0000
committerJames Booth <boothj5@gmail.com>2014-12-29 15:29:28 +0000
commitaebee209b2698eba40b1b220e162f87db23cc838 (patch)
treef5396a26e24e5fbee16a20a832284304dfa080c6 /src/command
parent1c35321cb315b7ce5bee3f5f281df103b0bc1f77 (diff)
parent1dca023c9f56a8c1a30d1b8de08dc9878b161bf6 (diff)
downloadprofani-tty-aebee209b2698eba40b1b220e162f87db23cc838.tar.gz
Merge remote-tracking branch 'incertia/connect-default'
Conflicts:
	CHANGELOG
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c27
-rw-r--r--src/command/commands.c57
2 files changed, 76 insertions, 8 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 9fbc0626..5c1f858d 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -129,16 +129,18 @@ static struct cmd_t command_defs[] =
           NULL  } } },
 
     { "/connect",
-        cmd_connect, parse_args, 1, 5, NULL,
-        { "/connect account [server value] [port value]", "Login to a chat service.",
-        { "/connect account [server value] [port value]",
-          "--------------------------------------------",
+        cmd_connect, parse_args, 0, 5, NULL,
+        { "/connect [account] [server value] [port value]", "Login to a chat service.",
+        { "/connect [account] [server value] [port value]",
+          "----------------------------------------------",
           "Connect to an XMPP service using the specified account.",
           "Use the server property to specify a server if required.",
           "Change the default port (5222, or 5223 for SSL) with the port property.",
           "An account is automatically created if one does not exist.",
+          "If no account is specified, then the default account is used."
           "See the /account command for more details.",
           "",
+          "Example: /connect",
           "Example: /connect myuser@gmail.com",
           "Example: /connect myuser@mycompany.com server talk.google.com",
           "Example: /connect bob@someplace port 5678",
@@ -911,6 +913,7 @@ static struct cmd_t command_defs[] =
           "show account                 : Show information about an account.",
           "enable account               : Enable the account, it will be used for autocomplete.",
           "disable account              : Disable the account.",
+          "default [set|off] [account]  : Set the default account.",
           "add account                  : Create a new account.",
           "remove account               : Remove an account.",
           "rename account newname       : Rename account to newname.",
@@ -1076,6 +1079,7 @@ static Autocomplete theme_load_ac;
 static Autocomplete account_ac;
 static Autocomplete account_set_ac;
 static Autocomplete account_clear_ac;
+static Autocomplete account_default_ac;
 static Autocomplete disco_ac;
 static Autocomplete close_ac;
 static Autocomplete wins_ac;
@@ -1239,6 +1243,7 @@ cmd_init(void)
     autocomplete_add(account_ac, "remove");
     autocomplete_add(account_ac, "enable");
     autocomplete_add(account_ac, "disable");
+    autocomplete_add(account_ac, "default");
     autocomplete_add(account_ac, "rename");
     autocomplete_add(account_ac, "set");
     autocomplete_add(account_ac, "clear");
@@ -1265,6 +1270,10 @@ cmd_init(void)
     autocomplete_add(account_clear_ac, "port");
     autocomplete_add(account_clear_ac, "otr");
 
+    account_default_ac = autocomplete_new();
+    autocomplete_add(account_default_ac, "set");
+    autocomplete_add(account_default_ac, "off");
+
     close_ac = autocomplete_new();
     autocomplete_add(close_ac, "read");
     autocomplete_add(close_ac, "all");
@@ -1473,6 +1482,7 @@ cmd_uninit(void)
     autocomplete_free(account_ac);
     autocomplete_free(account_set_ac);
     autocomplete_free(account_clear_ac);
+    autocomplete_free(account_default_ac);
     autocomplete_free(disco_ac);
     autocomplete_free(close_ac);
     autocomplete_free(wins_ac);
@@ -1639,6 +1649,7 @@ cmd_reset_autocomplete()
     autocomplete_reset(account_ac);
     autocomplete_reset(account_set_ac);
     autocomplete_reset(account_clear_ac);
+    autocomplete_reset(account_default_ac);
     autocomplete_reset(disco_ac);
     autocomplete_reset(close_ac);
     autocomplete_reset(wins_ac);
@@ -2878,9 +2889,15 @@ _account_autocomplete(char *input, int *size)
 
     g_strfreev(args);
 
+    found = autocomplete_param_with_ac(input, size, "/account default", account_default_ac, TRUE);
+    if(found){
+        return found;
+    }
+
     int i = 0;
     gchar *account_choice[] = { "/account set", "/account show", "/account enable",
-        "/account disable", "/account rename", "/account clear", "/account remove"  };
+        "/account disable", "/account rename", "/account clear", "/account remove",
+        "/account default set" };
 
     for (i = 0; i < ARRAY_SIZE(account_choice); i++) {
         found = autocomplete_param_with_func(input, size, account_choice[i],
diff --git a/src/command/commands.c b/src/command/commands.c
index 53d6782b..5b5bd95e 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -84,6 +84,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();
 
@@ -94,7 +95,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("");
@@ -113,9 +114,16 @@ 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;
 
@@ -126,6 +134,8 @@ cmd_connect(gchar **args, struct cmd_help_t help)
                 account->password = ui_ask_password();
             }
             cons_show("Connecting with account %s as %s", account->name, jid);
+            if(g_hash_table_contains(options, "port") || g_hash_table_contains(options, "server"))
+                cons_show("Ignoring extra connect options. Please set them with /account set");
             conn_status = jabber_connect_with_account(account);
             account_free(account);
         } else {
@@ -142,11 +152,15 @@ cmd_connect(gchar **args, struct cmd_help_t help)
             log_info("Connection attempt for %s failed", jid);
         }
 
+        options_destroy(options);
+
         free(jid);
 
         result = TRUE;
     }
 
+    g_free(def);
+
     return result;
 }
 
@@ -195,13 +209,19 @@ cmd_account(gchar **args, struct cmd_help_t help)
         if(!account_name) {
             cons_show("Usage: %s", help.usage);
         } else {
+            char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
             if(accounts_remove(account_name)){
                 cons_show("Account %s removed.", account_name);
+                if(def && strcmp(def, account_name) == 0){
+                    prefs_set_string(PREF_DEFAULT_ACCOUNT, NULL);
+                    cons_show("Default account removed because the corresponding account was removed.");
+                }
             } else {
                 cons_show("Failed to remove account %s.", account_name);
                 cons_show("Either the account does not exist, or an unknown error occurred.");
             }
             cons_show("");
+            g_free(def);
         }
     } else if (strcmp(command, "enable") == 0) {
         char *account_name = args[1];
@@ -244,6 +264,37 @@ cmd_account(gchar **args, struct cmd_help_t help)
                 cons_show("");
             }
         }
+    } else if (strcmp(command, "default") == 0) {
+        if(g_strv_length(args) == 1){
+            char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
+
+            if(def){
+                cons_show("The default account is %s.", def);
+                free(def);
+            } else {
+                cons_show("No default account.");
+            }
+        } else if(g_strv_length(args) == 2){
+            if(strcmp(args[1], "off") == 0){
+                prefs_set_string(PREF_DEFAULT_ACCOUNT, NULL);
+                cons_show("Removed default account.");
+            } else {
+                cons_show("Usage: %s", help.usage);
+            }
+        } else if(g_strv_length(args) == 3) {
+            if(strcmp(args[1], "set") == 0){
+                if(accounts_get_account(args[2])){
+                    prefs_set_string(PREF_DEFAULT_ACCOUNT, args[2]);
+                    cons_show("Default account set to %s.", args[2]);
+                } else {
+                    cons_show("Account %s does not exist.", args[2]);
+                }
+            } else {
+                cons_show("Usage: %s", help.usage);
+            }
+        } else {
+            cons_show("Usage: %s", help.usage);
+        }
     } else if (strcmp(command, "set") == 0) {
         if (g_strv_length(args) != 4) {
             cons_show("Usage: %s", help.usage);
author Kartik Agaram <vc@akkartik.com> 2020-06-12 07:57:27 -0700 committer Kartik Agaram <vc@akkartik.com> 2020-06-12 07:57:38 -0700 6513' href='/akkartik/mu/commit/html/092stack.subx.html?h=hlt&id=86351aafe218a7386f6578be3c4da3edcdcb0c98'>86351aaf ^
9a777801 ^
86351aaf ^







ec73ed12 ^
86351aaf ^





ec73ed12 ^
86351aaf ^


ec73ed12 ^
86351aaf ^





ec73ed12 ^
86351aaf ^


ec73ed12 ^
86351aaf ^





ec73ed12 ^
86351aaf ^


ec73ed12 ^
86351aaf ^





ec73ed12 ^
86351aaf ^


ec73ed12 ^
86351aaf ^







































ec73ed12 ^

86351aaf ^
ec73ed12 ^
86351aaf ^



ec73ed12 ^
86351aaf ^
ec73ed12 ^
86351aaf ^




















ec73ed12 ^
86351aaf ^



ec73ed12 ^
86351aaf ^


ec73ed12 ^
86351aaf ^





ec73ed12 ^
86351aaf ^


ec73ed12 ^
86351aaf ^





ec73ed12 ^
86351aaf ^


ec73ed12 ^
86351aaf ^




































ec73ed12 ^

86351aaf ^
ec73ed12 ^
86351aaf ^



ec73ed12 ^
86351aaf ^
ec73ed12 ^
86351aaf ^




















ec73ed12 ^
86351aaf ^



ec73ed12 ^
86351aaf ^


ec73ed12 ^
86351aaf ^







b1635a5c ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480