1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added result to add and remove from autocomplete

This commit is contained in:
James Booth 2012-05-23 23:46:54 +01:00
parent 375d9336ef
commit cac0ea0742
5 changed files with 25 additions and 21 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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);