From cac0ea07424c86e276a6c1d91993abe4b37545d9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 23 May 2012 23:46:54 +0100 Subject: [PATCH] Added result to add and remove from autocomplete --- contact_list.c | 8 ++++---- contact_list.h | 4 ++-- jabber.c | 12 ++++++++---- prof_autocomplete.c | 18 +++++++++--------- prof_autocomplete.h | 4 ++-- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/contact_list.c b/contact_list.c index 3e0aca7e..3ffe91c6 100644 --- a/contact_list.c +++ b/contact_list.c @@ -49,15 +49,15 @@ void reset_search_attempts(void) p_autocomplete_reset(ac); } -void contact_list_remove(const char * const name) +gboolean contact_list_remove(const char * const name) { - p_autocomplete_remove(ac, name); + return p_autocomplete_remove(ac, name); } -void contact_list_add(const char * const name, const char * const show, +gboolean contact_list_add(const char * const name, const char * const show, const char * const status) { - p_autocomplete_add(ac, p_contact_new(name, show, status)); + return p_autocomplete_add(ac, p_contact_new(name, show, status)); } GSList * get_contact_list(void) diff --git a/contact_list.h b/contact_list.h index 72b8dd79..7bae9d87 100644 --- a/contact_list.h +++ b/contact_list.h @@ -30,9 +30,9 @@ void contact_list_init(void); void contact_list_clear(void); void reset_search_attempts(void); -void contact_list_add(const char * const name, const char * const show, +gboolean contact_list_add(const char * const name, const char * const show, const char * const status); -void contact_list_remove(const char * const name); +gboolean contact_list_remove(const char * const name); GSList * get_contact_list(void); char * find_contact(char *search_str); diff --git a/jabber.c b/jabber.c index 6d55d620..b795e8d1 100644 --- a/jabber.c +++ b/jabber.c @@ -335,11 +335,15 @@ static int _jabber_presence_handler(xmpp_conn_t * const conn, if (strcmp(short_jid, short_from) !=0) { if (type == NULL) {// online - win_contact_online(short_from, show_str, status_str); - contact_list_add(short_from, show_str, status_str); + gboolean result = contact_list_add(short_from, show_str, status_str); + if (result) { + win_contact_online(short_from, show_str, status_str); + } } else {// offline - win_contact_offline(short_from, show_str, status_str); - contact_list_remove(short_from); + gboolean result = contact_list_remove(short_from); + if (result) { + win_contact_offline(short_from, show_str, status_str); + } } win_page_off(); diff --git a/prof_autocomplete.c b/prof_autocomplete.c index 8ee0fbad..b8ff1e30 100644 --- a/prof_autocomplete.c +++ b/prof_autocomplete.c @@ -89,11 +89,11 @@ void p_autocomplete_reset(PAutocomplete ac) } } -void p_autocomplete_add(PAutocomplete ac, void *item) +gboolean p_autocomplete_add(PAutocomplete ac, void *item) { if (ac->items == NULL) { ac->items = g_slist_append(ac->items, item); - return; + return TRUE; } else { GSList *curr = ac->items; @@ -103,13 +103,13 @@ void p_autocomplete_add(PAutocomplete ac, void *item) if (g_strcmp0(ac->str_func(curr->data), ac->str_func(item)) > 0) { ac->items = g_slist_insert_before(ac->items, curr, item); - return; + return TRUE; // update } else if (g_strcmp0(ac->str_func(curr->data), ac->str_func(item)) == 0) { ac->free_func(curr->data); curr->data = item; - return; + return TRUE; } curr = g_slist_next(curr); @@ -118,11 +118,11 @@ void p_autocomplete_add(PAutocomplete ac, void *item) // hit end, append ac->items = g_slist_append(ac->items, item); - return; + return TRUE; } } -void p_autocomplete_remove(PAutocomplete ac, const char * const item) +gboolean p_autocomplete_remove(PAutocomplete ac, const char * const item) { // reset last found if it points to the item to be removed if (ac->last_found != NULL) @@ -130,7 +130,7 @@ void p_autocomplete_remove(PAutocomplete ac, const char * const item) ac->last_found = NULL; if (!ac->items) { - return; + return FALSE; } else { GSList *curr = ac->items; @@ -140,13 +140,13 @@ void p_autocomplete_remove(PAutocomplete ac, const char * const item) ac->items = g_slist_remove(ac->items, curr->data); ac->free_func(current_item); - return; + return TRUE; } curr = g_slist_next(curr); } - return; + return FALSE; } } diff --git a/prof_autocomplete.h b/prof_autocomplete.h index 02a1bdc1..637823fc 100644 --- a/prof_autocomplete.h +++ b/prof_autocomplete.h @@ -34,8 +34,8 @@ PAutocomplete p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func, GDestroyNotify free_func); void p_autocomplete_clear(PAutocomplete ac); void p_autocomplete_reset(PAutocomplete ac); -void p_autocomplete_add(PAutocomplete ac, void *item); -void p_autocomplete_remove(PAutocomplete ac, const char * const item); +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); gchar * p_autocomplete_complete(PAutocomplete ac, gchar *search_str);