aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-02-10 23:05:06 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-02-10 23:05:06 +0100
commit1f04a82681ca1dade08ce371c1fcd4181fe68675 (patch)
treec3af49aaf651ed617c826e006ae7111d17e3e3ed
parentd739a0214d83b1fd366c167a610b8dbf1205f483 (diff)
downloadmessenger-gtk-1f04a82681ca1dade08ce371c1fcd4181fe68675.tar.gz
messenger-gtk-1f04a82681ca1dade08ce371c1fcd4181fe68675.zip
Added search filter for contacts
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/ui/contacts.c57
-rw-r--r--src/ui/contacts.h1
2 files changed, 58 insertions, 0 deletions
diff --git a/src/ui/contacts.c b/src/ui/contacts.c
index 3969446..63157ff 100644
--- a/src/ui/contacts.c
+++ b/src/ui/contacts.c
@@ -82,6 +82,46 @@ close_dialog:
82 gtk_window_close(GTK_WINDOW(app->ui.contacts.dialog)); 82 gtk_window_close(GTK_WINDOW(app->ui.contacts.dialog));
83} 83}
84 84
85static gboolean
86handle_contacts_listbox_filter_func(GtkListBoxRow *row,
87 gpointer user_data)
88{
89 UI_CONTACTS_Handle *handle = (UI_CONTACTS_Handle*) user_data;
90
91 if (!gtk_list_box_row_get_selectable(row))
92 return TRUE;
93
94 const gchar *filter = gtk_entry_get_text(
95 GTK_ENTRY(handle->contact_search_entry)
96 );
97
98 if (!filter)
99 return TRUE;
100
101 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) (
102 g_hash_table_lookup(handle->bindings, row)
103 );
104
105 if (!contact)
106 return FALSE;
107
108 const gchar *name = GNUNET_CHAT_contact_get_name(contact);
109
110 if (!name)
111 return FALSE;
112
113 return g_str_match_string(filter, name, TRUE);
114}
115
116static void
117handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry,
118 gpointer user_data)
119{
120 GtkListBox *listbox = GTK_LIST_BOX(user_data);
121
122 gtk_list_box_invalidate_filter(listbox);
123}
124
85static void 125static void
86handle_dialog_destroy(UNUSED GtkWidget *window, 126handle_dialog_destroy(UNUSED GtkWidget *window,
87 gpointer user_data) 127 gpointer user_data)
@@ -138,6 +178,7 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
138 UI_CONTACTS_Handle *handle) 178 UI_CONTACTS_Handle *handle)
139{ 179{
140 handle->contact_entries = NULL; 180 handle->contact_entries = NULL;
181 handle->bindings = app->ui.bindings;
141 182
142 handle->builder = gtk_builder_new_from_resource( 183 handle->builder = gtk_builder_new_from_resource(
143 application_get_resource_path(app, "ui/contacts.ui") 184 application_get_resource_path(app, "ui/contacts.ui")
@@ -165,6 +206,20 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
165 gtk_builder_get_object(handle->builder, "contacts_listbox") 206 gtk_builder_get_object(handle->builder, "contacts_listbox")
166 ); 207 );
167 208
209 gtk_list_box_set_filter_func(
210 handle->contacts_listbox,
211 handle_contacts_listbox_filter_func,
212 handle,
213 NULL
214 );
215
216 g_signal_connect(
217 handle->contact_search_entry,
218 "search-changed",
219 G_CALLBACK(handle_contact_search_entry_search_changed),
220 handle->contacts_listbox
221 );
222
168 g_signal_connect( 223 g_signal_connect(
169 handle->contacts_listbox, 224 handle->contacts_listbox,
170 "row-activated", 225 "row-activated",
@@ -195,6 +250,8 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
195 _iterate_contacts, 250 _iterate_contacts,
196 app 251 app
197 ); 252 );
253
254 gtk_list_box_invalidate_filter(handle->contacts_listbox);
198} 255}
199 256
200void 257void
diff --git a/src/ui/contacts.h b/src/ui/contacts.h
index 90b4b4c..499c3fe 100644
--- a/src/ui/contacts.h
+++ b/src/ui/contacts.h
@@ -30,6 +30,7 @@
30typedef struct UI_CONTACTS_Handle 30typedef struct UI_CONTACTS_Handle
31{ 31{
32 GList *contact_entries; 32 GList *contact_entries;
33 GHashTable *bindings;
33 34
34 GtkBuilder *builder; 35 GtkBuilder *builder;
35 GtkDialog *dialog; 36 GtkDialog *dialog;