aboutsummaryrefslogtreecommitdiff
path: root/src/ui/invite_contact.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/invite_contact.c')
-rw-r--r--src/ui/invite_contact.c57
1 files changed, 57 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