From 0f2035e4adc361b7f850adbbe82f6edea7f18d8b Mon Sep 17 00:00:00 2001 From: Will Song Date: Sun, 23 Nov 2014 01:33:23 -0600 Subject: [PATCH 1/6] add functions for getting roster list without offline contacts (but not implemented) --- src/roster_list.c | 17 +++++++++++++++++ src/roster_list.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/roster_list.c b/src/roster_list.c index 941b6321..792d804c 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -307,6 +307,23 @@ roster_get_contacts(void) return result; } +GSList * +roster_get_contacts_nooffline(void) +{ + GSList *result = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; + + g_hash_table_iter_init(&iter, contacts); + while (g_hash_table_iter_next(&iter, &key, &value)) { + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); + } + + // resturn all contact structs + return result; +} + gboolean roster_has_pending_subscriptions(void) { diff --git a/src/roster_list.h b/src/roster_list.h index 13b0bac7..c3ef44cb 100644 --- a/src/roster_list.h +++ b/src/roster_list.h @@ -57,6 +57,7 @@ gboolean roster_add(const char * const barejid, const char * const name, GSList const char * const subscription, gboolean pending_out); char * roster_barejid_from_name(const char * const name); GSList * roster_get_contacts(void); +GSList * roster_get_contacts_nooffline(void); gboolean roster_has_pending_subscriptions(void); char * roster_contact_autocomplete(char *search_str); char * roster_fulljid_autocomplete(char *search_str); From a980fbe0bdc3a1673baf5b86d0a8072ed3e45ac0 Mon Sep 17 00:00:00 2001 From: Will Song Date: Sun, 23 Nov 2014 01:34:09 -0600 Subject: [PATCH 2/6] add nooffline option to roster --- src/command/commands.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/command/commands.c b/src/command/commands.c index ad1ef1a9..c1e499e5 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1345,6 +1345,12 @@ cmd_roster(gchar **args, struct cmd_help_t help) cons_show_roster(list); return TRUE; + // show roster, no offline contacts + } else if(g_strcmp0(args[0], "nooffline") == 0){ + GSList *list = roster_get_contacts_nooffline(); + cons_show_roster(list); + return TRUE; + // set roster size } else if (g_strcmp0(args[0], "size") == 0) { int intval = 0; @@ -4041,4 +4047,3 @@ gint _compare_commands(Command *a, Command *b) return result; } - From e113fd2b1d0e6170eae606524f35d129042ba001 Mon Sep 17 00:00:00 2001 From: Will Song Date: Sun, 23 Nov 2014 02:00:56 -0600 Subject: [PATCH 3/6] roster_get_contacts_nooffline only gets contacts that are not offline --- src/roster_list.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/roster_list.c b/src/roster_list.c index 792d804c..ca777033 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -317,7 +317,8 @@ roster_get_contacts_nooffline(void) g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); + if(strcmp(p_contact_presence(value), "offline")) + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); } // resturn all contact structs From 553f8b54cce83bddf51af8244a3661f82f0a0d44 Mon Sep 17 00:00:00 2001 From: Will Song Date: Sun, 23 Nov 2014 02:03:26 -0600 Subject: [PATCH 4/6] updated description for /roster --- src/command/command.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 967a2fe4..f690331a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -169,11 +169,12 @@ static struct cmd_t command_defs[] = { "/roster", cmd_roster, parse_args_with_freetext, 0, 3, NULL, - { "/roster [show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]", "Manage your roster.", - { "/roster [show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]", + { "/roster [nooffline|show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]", "Manage your roster.", + { "/roster [nooffline|show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]", "-------------------------------------------------------------------------------------------------------------------------", "View, add to, and remove from your roster.", "Passing no arguments lists all contacts in your roster.", + "nooffline - List all contacts in your roster without the clutter of offline contacts.", "show - Show the roster panel in the console window.", "hide - Hide the roster panel.", "show offline - Show offline contacts in the roster panel.", From 035dc313dd6310e98311f8429f409790d29c0ee0 Mon Sep 17 00:00:00 2001 From: Will Song Date: Sun, 23 Nov 2014 02:06:04 -0600 Subject: [PATCH 5/6] add nooffline to /roster autocomplete --- src/command/command.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command/command.c b/src/command/command.c index f690331a..2c73ca1a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1251,6 +1251,7 @@ cmd_init(void) roster_ac = autocomplete_new(); autocomplete_add(roster_ac, "add"); + autocomplete_add(roster_ac, "nooffline"); autocomplete_add(roster_ac, "nick"); autocomplete_add(roster_ac, "clearnick"); autocomplete_add(roster_ac, "remove"); From 915c3633e80a9a8bab76f5b06b967c319cfc10b1 Mon Sep 17 00:00:00 2001 From: Will Song Date: Sun, 23 Nov 2014 15:37:10 -0600 Subject: [PATCH 6/6] implement account removal --- src/command/command.c | 4 +++- src/command/commands.c | 13 +++++++++++++ src/config/accounts.c | 11 +++++++++++ src/config/accounts.h | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) 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);