From 89967905dbc592811493d4c7ba1fda31a8c2b038 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 11 Jan 2013 00:17:18 +0000 Subject: Autocomplete: added free function Fixed tests --- src/accounts.c | 4 ++-- src/command.c | 24 ++++++++++++------------ src/contact_list.c | 6 ++++++ src/contact_list.h | 1 + src/preferences.c | 2 +- src/prof_autocomplete.c | 8 ++++++++ src/prof_autocomplete.h | 1 + src/profanity.c | 3 ++- src/room_chat.c | 2 +- tests/test_contact_list.c | 8 ++++---- 10 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/accounts.c b/src/accounts.c index bf5ef11b..36779402 100644 --- a/src/accounts.c +++ b/src/accounts.c @@ -72,8 +72,8 @@ accounts_load(void) void accounts_close(void) { - p_autocomplete_clear(all_ac); - p_autocomplete_clear(enabled_ac); + p_autocomplete_free(all_ac); + p_autocomplete_free(enabled_ac); g_key_file_free(accounts); } diff --git a/src/command.c b/src/command.c index 6fe78ae7..81412bb2 100644 --- a/src/command.c +++ b/src/command.c @@ -712,20 +712,20 @@ cmd_init(void) void cmd_close(void) { - p_autocomplete_clear(commands_ac); - p_autocomplete_clear(who_ac); - p_autocomplete_clear(help_ac); - p_autocomplete_clear(notify_ac); - p_autocomplete_clear(sub_ac); - p_autocomplete_clear(log_ac); - p_autocomplete_clear(prefs_ac); - p_autocomplete_clear(autoaway_ac); - p_autocomplete_clear(autoaway_mode_ac); - p_autocomplete_clear(theme_ac); + p_autocomplete_free(commands_ac); + p_autocomplete_free(who_ac); + p_autocomplete_free(help_ac); + p_autocomplete_free(notify_ac); + p_autocomplete_free(sub_ac); + p_autocomplete_free(log_ac); + p_autocomplete_free(prefs_ac); + p_autocomplete_free(autoaway_ac); + p_autocomplete_free(autoaway_mode_ac); + p_autocomplete_free(theme_ac); if (theme_load_ac != NULL) { - p_autocomplete_clear(theme_load_ac); + p_autocomplete_free(theme_load_ac); } - p_autocomplete_clear(account_ac); + p_autocomplete_free(account_ac); } // Command autocompletion functions diff --git a/src/contact_list.c b/src/contact_list.c index f277e2f0..b23c9627 100644 --- a/src/contact_list.c +++ b/src/contact_list.c @@ -48,6 +48,12 @@ contact_list_clear(void) g_hash_table_remove_all(contacts); } +void +contact_list_free() +{ + p_autocomplete_free(ac); +} + void contact_list_reset_search_attempts(void) { diff --git a/src/contact_list.h b/src/contact_list.h index 8c221b6f..b3cc7f37 100644 --- a/src/contact_list.h +++ b/src/contact_list.h @@ -29,6 +29,7 @@ void contact_list_init(void); void contact_list_clear(void); +void contact_list_free(void); void contact_list_reset_search_attempts(void); void contact_list_remove(const char * const jid); gboolean contact_list_add(const char * const jid, const char * const name, diff --git a/src/preferences.c b/src/preferences.c index 8c9b7918..91243dec 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -72,7 +72,7 @@ prefs_load(void) void prefs_close(void) { - p_autocomplete_clear(boolean_choice_ac); + p_autocomplete_free(boolean_choice_ac); g_key_file_free(prefs); } diff --git a/src/prof_autocomplete.c b/src/prof_autocomplete.c index b41c5368..0b947dc6 100644 --- a/src/prof_autocomplete.c +++ b/src/prof_autocomplete.c @@ -63,6 +63,14 @@ p_autocomplete_reset(PAutocomplete ac) } } +void +p_autocomplete_free(PAutocomplete ac) +{ + p_autocomplete_clear(ac); + g_free(ac); + ac = NULL; +} + gboolean p_autocomplete_add(PAutocomplete ac, void *item) { diff --git a/src/prof_autocomplete.h b/src/prof_autocomplete.h index 50b9e30c..5cb6f5e9 100644 --- a/src/prof_autocomplete.h +++ b/src/prof_autocomplete.h @@ -36,6 +36,7 @@ PAutocomplete p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func, PEqualDeepFunc equal_deep_func, GDestroyNotify free_func); void p_autocomplete_clear(PAutocomplete ac); void p_autocomplete_reset(PAutocomplete ac); +void p_autocomplete_free(PAutocomplete ac); gboolean p_autocomplete_add(PAutocomplete ac, void *item); gboolean p_autocomplete_remove(PAutocomplete ac, const char * const item); GSList * p_autocomplete_get_list(PAutocomplete ac); diff --git a/src/profanity.c b/src/profanity.c index d51310a0..b9d8d69b 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -545,11 +545,12 @@ static void _shutdown(void) { jabber_disconnect(); - contact_list_clear(); + contact_list_free(); ui_close(); chat_log_close(); prefs_close(); theme_close(); + accounts_close(); cmd_close(); log_close(); } diff --git a/src/room_chat.c b/src/room_chat.c index d70fca9c..0a0b41cd 100644 --- a/src/room_chat.c +++ b/src/room_chat.c @@ -358,7 +358,7 @@ _room_free(muc_room *room) room->roster = NULL; } if (room->nick_ac != NULL) { - p_autocomplete_clear(room->nick_ac); + p_autocomplete_free(room->nick_ac); } if (room->nick_changes != NULL) { g_hash_table_remove_all(room->nick_changes); diff --git a/tests/test_contact_list.c b/tests/test_contact_list.c index 4da4093d..f04e80d5 100644 --- a/tests/test_contact_list.c +++ b/tests/test_contact_list.c @@ -191,7 +191,7 @@ static void test_status_when_no_value(void) static void update_show(void) { contact_list_add("James", NULL, "away", NULL, NULL, FALSE); - contact_list_update_contact("James", "dnd", NULL); + contact_list_update_contact("James", "dnd", NULL, NULL); GSList *list = get_contact_list(); assert_int_equals(1, g_slist_length(list)); @@ -203,7 +203,7 @@ static void update_show(void) static void set_show_to_null(void) { contact_list_add("James", NULL, "away", NULL, NULL, FALSE); - contact_list_update_contact("James", NULL, NULL); + contact_list_update_contact("James", NULL, NULL, NULL); GSList *list = get_contact_list(); assert_int_equals(1, g_slist_length(list)); @@ -215,7 +215,7 @@ static void set_show_to_null(void) static void update_status(void) { contact_list_add("James", NULL, NULL, "I'm not here right now", NULL, FALSE); - contact_list_update_contact("James", NULL, "Gone to lunch"); + contact_list_update_contact("James", NULL, "Gone to lunch", NULL); GSList *list = get_contact_list(); assert_int_equals(1, g_slist_length(list)); @@ -227,7 +227,7 @@ static void update_status(void) static void set_status_to_null(void) { contact_list_add("James", NULL, NULL, "Gone to lunch", NULL, FALSE); - contact_list_update_contact("James", NULL, NULL); + contact_list_update_contact("James", NULL, NULL, NULL); GSList *list = get_contact_list(); assert_int_equals(1, g_slist_length(list)); -- cgit 1.4.1-2-gfad0