about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorWill Song <incertia9474@gmail.com>2014-11-23 15:37:10 -0600
committerWill Song <incertia9474@gmail.com>2014-11-23 15:37:10 -0600
commit915c3633e80a9a8bab76f5b06b967c319cfc10b1 (patch)
tree397a36e0dc8be1aa8a7138b23bcae07c156d3cb8 /src
parent035dc313dd6310e98311f8429f409790d29c0ee0 (diff)
downloadprofani-tty-915c3633e80a9a8bab76f5b06b967c319cfc10b1.tar.gz
implement account removal
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c4
-rw-r--r--src/command/commands.c13
-rw-r--r--src/config/accounts.c11
-rw-r--r--src/config/accounts.h1
4 files changed, 28 insertions, 1 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 2c73ca1a..6d026103 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -890,6 +890,7 @@ static struct cmd_t command_defs[] =
           "enable account               : Enable the account, it will be used for autocomplete.",
           "disable account              : Disable the account.",
           "add account                  : Create a new account.",
+          "remove account               : Remove an account.",
           "rename account newname       : Rename account to newname.",
           "set account property value   : Set 'property' of 'account' to 'value'.",
           "clear account property value : Clear 'property' of 'account'.",
@@ -1212,6 +1213,7 @@ cmd_init(void)
     autocomplete_add(account_ac, "list");
     autocomplete_add(account_ac, "show");
     autocomplete_add(account_ac, "add");
+    autocomplete_add(account_ac, "remove");
     autocomplete_add(account_ac, "enable");
     autocomplete_add(account_ac, "disable");
     autocomplete_add(account_ac, "rename");
@@ -2782,7 +2784,7 @@ _account_autocomplete(char *input, int *size)
 
     int i = 0;
     gchar *account_choice[] = { "/account set", "/account show", "/account enable",
-        "/account disable", "/account rename", "/account clear" };
+        "/account disable", "/account rename", "/account clear", "/account remove"  };
 
     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 c1e499e5..58425358 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -189,6 +189,19 @@ cmd_account(gchar **args, struct cmd_help_t help)
             cons_show("Account created.");
             cons_show("");
         }
+    } else if (strcmp(command, "remove") == 0) {
+        char *account_name = args[1];
+        if(!account_name) {
+            cons_show("Usage: %s", help.usage);
+        } else {
+            if(accounts_remove(account_name)){
+                cons_show("Account %s removed.", account_name);
+            } 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("");
+        }
     } else if (strcmp(command, "enable") == 0) {
         char *account_name = args[1];
         if (account_name == NULL) {
diff --git a/src/config/accounts.c b/src/config/accounts.c
index 175cac5f..36007ddc 100644
--- a/src/config/accounts.c
+++ b/src/config/accounts.c
@@ -193,6 +193,16 @@ _accounts_add(const char *account_name, const char *altdomain, const int port)
     jid_destroy(jid);
 }
 
+static int
+_accounts_remove(const char *account_name)
+{
+    int r = g_key_file_remove_group(accounts, account_name, NULL);
+    _save_accounts();
+    autocomplete_remove(all_ac, account_name);
+    autocomplete_remove(enabled_ac, account_name);
+    return r;
+}
+
 static gchar**
 _accounts_get_list(void)
 {
@@ -861,6 +871,7 @@ accounts_init_module(void)
     accounts_reset_all_search = _accounts_reset_all_search;
     accounts_reset_enabled_search = _accounts_reset_enabled_search;
     accounts_add = _accounts_add;
+    accounts_remove = _accounts_remove;
     accounts_get_list = _accounts_get_list;
     accounts_get_account = _accounts_get_account;
     accounts_enable = _accounts_enable;
diff --git a/src/config/accounts.h b/src/config/accounts.h
index 97c125eb..0ca0d82c 100644
--- a/src/config/accounts.h
+++ b/src/config/accounts.h
@@ -50,6 +50,7 @@ char * (*accounts_find_enabled)(char *prefix);
 void (*accounts_reset_all_search)(void);
 void (*accounts_reset_enabled_search)(void);
 void (*accounts_add)(const char *jid, const char *altdomain, const int port);
+int  (*accounts_remove)(const char *jid);
 gchar** (*accounts_get_list)(void);
 ProfAccount* (*accounts_get_account)(const char * const name);
 gboolean (*accounts_enable)(const char * const name);
1' href='#n351'>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