aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-02-10 23:26:33 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-02-10 23:26:33 +0100
commit8ef26852ac4da54e6784e738452346c4f9873c02 (patch)
tree1a4eccb37783b45050a5ef90080950f7431b7b1e
parent1f04a82681ca1dade08ce371c1fcd4181fe68675 (diff)
downloadmessenger-gtk-8ef26852ac4da54e6784e738452346c4f9873c02.tar.gz
messenger-gtk-8ef26852ac4da54e6784e738452346c4f9873c02.zip
Added search filter to invite contact dialog
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/ui/invite_contact.c57
-rw-r--r--src/ui/invite_contact.h1
2 files changed, 58 insertions, 0 deletions
diff --git a/src/ui/invite_contact.c b/src/ui/invite_contact.c
index 8cbde0c..8e18860 100644
--- a/src/ui/invite_contact.c
+++ b/src/ui/invite_contact.c
@@ -74,6 +74,46 @@ close_dialog:
74 gtk_window_close(GTK_WINDOW(app->ui.invite_contact.dialog)); 74 gtk_window_close(GTK_WINDOW(app->ui.invite_contact.dialog));
75} 75}
76 76
77static gboolean
78handle_contacts_listbox_filter_func(GtkListBoxRow *row,
79 gpointer user_data)
80{
81 UI_CONTACTS_Handle *handle = (UI_CONTACTS_Handle*) user_data;
82
83 if (!gtk_list_box_row_get_selectable(row))
84 return TRUE;
85
86 const gchar *filter = gtk_entry_get_text(
87 GTK_ENTRY(handle->contact_search_entry)
88 );
89
90 if (!filter)
91 return TRUE;
92
93 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) (
94 g_hash_table_lookup(handle->bindings, row)
95 );
96
97 if (!contact)
98 return FALSE;
99
100 const gchar *name = GNUNET_CHAT_contact_get_name(contact);
101
102 if (!name)
103 return FALSE;
104
105 return g_str_match_string(filter, name, TRUE);
106}
107
108static void
109handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry,
110 gpointer user_data)
111{
112 GtkListBox *listbox = GTK_LIST_BOX(user_data);
113
114 gtk_list_box_invalidate_filter(listbox);
115}
116
77static void 117static void
78handle_dialog_destroy(UNUSED GtkWidget *window, 118handle_dialog_destroy(UNUSED GtkWidget *window,
79 gpointer user_data) 119 gpointer user_data)
@@ -130,6 +170,7 @@ ui_invite_contact_dialog_init(MESSENGER_Application *app,
130 UI_INVITE_CONTACT_Handle *handle) 170 UI_INVITE_CONTACT_Handle *handle)
131{ 171{
132 handle->contact_entries = NULL; 172 handle->contact_entries = NULL;
173 handle->bindings = app->ui.bindings;
133 174
134 handle->builder = gtk_builder_new_from_resource( 175 handle->builder = gtk_builder_new_from_resource(
135 application_get_resource_path(app, "ui/invite_contact.ui") 176 application_get_resource_path(app, "ui/invite_contact.ui")
@@ -157,6 +198,20 @@ ui_invite_contact_dialog_init(MESSENGER_Application *app,
157 gtk_builder_get_object(handle->builder, "contacts_listbox") 198 gtk_builder_get_object(handle->builder, "contacts_listbox")
158 ); 199 );
159 200
201 gtk_list_box_set_filter_func(
202 handle->contacts_listbox,
203 handle_contacts_listbox_filter_func,
204 handle,
205 NULL
206 );
207
208 g_signal_connect(
209 handle->contact_search_entry,
210 "search-changed",
211 G_CALLBACK(handle_contact_search_entry_search_changed),
212 handle->contacts_listbox
213 );
214
160 g_signal_connect( 215 g_signal_connect(
161 handle->contacts_listbox, 216 handle->contacts_listbox,
162 "row-activated", 217 "row-activated",
@@ -187,6 +242,8 @@ ui_invite_contact_dialog_init(MESSENGER_Application *app,
187 _iterate_contacts, 242 _iterate_contacts,
188 app 243 app
189 ); 244 );
245
246 gtk_list_box_invalidate_filter(handle->contacts_listbox);
190} 247}
191 248
192void 249void
diff --git a/src/ui/invite_contact.h b/src/ui/invite_contact.h
index 64d2f09..94a83e7 100644
--- a/src/ui/invite_contact.h
+++ b/src/ui/invite_contact.h
@@ -30,6 +30,7 @@
30typedef struct UI_INVITE_CONTACT_Handle 30typedef struct UI_INVITE_CONTACT_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;