diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-02-11 00:12:25 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-02-11 00:12:25 +0100 |
commit | d533c72c5729ae7715b464f88e169b7993e77eb7 (patch) | |
tree | 0e5cb608f2641dcab3be93712b7a1b47fe1c4c67 | |
parent | 8ef26852ac4da54e6784e738452346c4f9873c02 (diff) | |
download | messenger-gtk-d533c72c5729ae7715b464f88e169b7993e77eb7.tar.gz messenger-gtk-d533c72c5729ae7715b464f88e169b7993e77eb7.zip |
Added search filter to chats listing
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | resources/ui/messenger.ui | 4 | ||||
-rw-r--r-- | src/event.c | 20 | ||||
-rw-r--r-- | src/ui/messenger.c | 68 | ||||
-rw-r--r-- | src/ui/messenger.h | 1 |
4 files changed, 77 insertions, 16 deletions
diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui index fd34ea5..3d0ca2d 100644 --- a/resources/ui/messenger.ui +++ b/resources/ui/messenger.ui | |||
@@ -747,10 +747,6 @@ Author: Tobias Frisch | |||
747 | </packing> | 747 | </packing> |
748 | </child> | 748 | </child> |
749 | </object> | 749 | </object> |
750 | <packing> | ||
751 | <property name="name">page0</property> | ||
752 | <property name="title" translatable="yes">page0</property> | ||
753 | </packing> | ||
754 | </child> | 750 | </child> |
755 | </object> | 751 | </object> |
756 | <packing> | 752 | <packing> |
diff --git a/src/event.c b/src/event.c index 4b3e580..193ecfa 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -91,15 +91,9 @@ _add_new_chat_entry(MESSENGER_Application *app, | |||
91 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); | 91 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); |
92 | GNUNET_CHAT_context_set_user_pointer(context, entry); | 92 | GNUNET_CHAT_context_set_user_pointer(context, entry); |
93 | 93 | ||
94 | char context_id [9]; | 94 | gtk_container_add( |
95 | g_snprintf(context_id, sizeof(context_id), "%08lx", (gulong) context); | 95 | GTK_CONTAINER(ui->chats_stack), |
96 | 96 | entry->chat->chat_box | |
97 | gtk_widget_set_name(entry->entry_box, context_id); | ||
98 | |||
99 | gtk_stack_add_named( | ||
100 | ui->chats_stack, | ||
101 | entry->chat->chat_box, | ||
102 | context_id | ||
103 | ); | 97 | ); |
104 | 98 | ||
105 | g_hash_table_insert( | 99 | g_hash_table_insert( |
@@ -114,7 +108,15 @@ _add_new_chat_entry(MESSENGER_Application *app, | |||
114 | gtk_widget_get_parent(entry->entry_box) | 108 | gtk_widget_get_parent(entry->entry_box) |
115 | ); | 109 | ); |
116 | 110 | ||
111 | g_hash_table_insert( | ||
112 | app->ui.bindings, | ||
113 | row, | ||
114 | entry | ||
115 | ); | ||
116 | |||
117 | gtk_list_box_select_row(ui->chats_listbox, row); | 117 | gtk_list_box_select_row(ui->chats_listbox, row); |
118 | gtk_list_box_invalidate_filter(ui->chats_listbox); | ||
119 | |||
118 | gtk_widget_activate(GTK_WIDGET(row)); | 120 | gtk_widget_activate(GTK_WIDGET(row)); |
119 | } | 121 | } |
120 | 122 | ||
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index a926332..7a2ddff 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -161,6 +161,16 @@ handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, | |||
161 | { | 161 | { |
162 | UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; | 162 | UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; |
163 | 163 | ||
164 | if (!gtk_list_box_row_get_selectable(row)) | ||
165 | return; | ||
166 | |||
167 | UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) g_hash_table_lookup( | ||
168 | handle->bindings, row | ||
169 | ); | ||
170 | |||
171 | if ((!entry) || (!(entry->chat)) || (!(entry->chat->chat_box))) | ||
172 | return; | ||
173 | |||
164 | GtkStack *stack = handle->chats_stack; | 174 | GtkStack *stack = handle->chats_stack; |
165 | HdyLeaflet *leaflet = handle->leaflet_chat; | 175 | HdyLeaflet *leaflet = handle->leaflet_chat; |
166 | 176 | ||
@@ -170,11 +180,48 @@ handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, | |||
170 | hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->next->data)); | 180 | hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->next->data)); |
171 | } | 181 | } |
172 | 182 | ||
173 | GtkWidget *entry = GTK_WIDGET( | 183 | gtk_stack_set_visible_child(stack, entry->chat->chat_box); |
174 | gtk_container_get_children(GTK_CONTAINER(row))->data | 184 | } |
185 | |||
186 | static gboolean | ||
187 | handle_chats_listbox_filter_func(GtkListBoxRow *row, | ||
188 | gpointer user_data) | ||
189 | { | ||
190 | UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; | ||
191 | |||
192 | if ((!gtk_list_box_row_get_selectable(row)) || | ||
193 | (gtk_list_box_row_is_selected(row))) | ||
194 | return TRUE; | ||
195 | |||
196 | const gchar *filter = gtk_entry_get_text( | ||
197 | GTK_ENTRY(handle->chats_search) | ||
175 | ); | 198 | ); |
176 | 199 | ||
177 | gtk_stack_set_visible_child_name(stack, gtk_widget_get_name(entry)); | 200 | if (!filter) |
201 | return TRUE; | ||
202 | |||
203 | UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) g_hash_table_lookup( | ||
204 | handle->bindings, row | ||
205 | ); | ||
206 | |||
207 | if (!entry) | ||
208 | return FALSE; | ||
209 | |||
210 | const gchar *title = gtk_label_get_text(entry->title_label); | ||
211 | |||
212 | if (!title) | ||
213 | return FALSE; | ||
214 | |||
215 | return g_str_match_string(filter, title, TRUE); | ||
216 | } | ||
217 | |||
218 | static void | ||
219 | handle_chats_search_changed(UNUSED GtkSearchEntry *search, | ||
220 | gpointer user_data) | ||
221 | { | ||
222 | GtkListBox *listbox = GTK_LIST_BOX(user_data); | ||
223 | |||
224 | gtk_list_box_invalidate_filter(listbox); | ||
178 | } | 225 | } |
179 | 226 | ||
180 | static void | 227 | static void |
@@ -193,6 +240,7 @@ ui_messenger_init(MESSENGER_Application *app, | |||
193 | UI_MESSENGER_Handle *handle) | 240 | UI_MESSENGER_Handle *handle) |
194 | { | 241 | { |
195 | handle->chat_entries = NULL; | 242 | handle->chat_entries = NULL; |
243 | handle->bindings = app->ui.bindings; | ||
196 | 244 | ||
197 | handle->builder = gtk_builder_new_from_resource( | 245 | handle->builder = gtk_builder_new_from_resource( |
198 | application_get_resource_path(app, "ui/messenger.ui") | 246 | application_get_resource_path(app, "ui/messenger.ui") |
@@ -377,6 +425,20 @@ ui_messenger_init(MESSENGER_Application *app, | |||
377 | gtk_builder_get_object(handle->builder, "chats_listbox") | 425 | gtk_builder_get_object(handle->builder, "chats_listbox") |
378 | ); | 426 | ); |
379 | 427 | ||
428 | gtk_list_box_set_filter_func( | ||
429 | handle->chats_listbox, | ||
430 | handle_chats_listbox_filter_func, | ||
431 | handle, | ||
432 | NULL | ||
433 | ); | ||
434 | |||
435 | g_signal_connect( | ||
436 | handle->chats_search, | ||
437 | "search-changed", | ||
438 | G_CALLBACK(handle_chats_search_changed), | ||
439 | handle->chats_listbox | ||
440 | ); | ||
441 | |||
380 | g_signal_connect( | 442 | g_signal_connect( |
381 | handle->chats_listbox, | 443 | handle->chats_listbox, |
382 | "row-activated", | 444 | "row-activated", |
diff --git a/src/ui/messenger.h b/src/ui/messenger.h index e16487b..08ea78e 100644 --- a/src/ui/messenger.h +++ b/src/ui/messenger.h | |||
@@ -36,6 +36,7 @@ typedef struct MESSENGER_Application MESSENGER_Application; | |||
36 | typedef struct UI_MESSENGER_Handle | 36 | typedef struct UI_MESSENGER_Handle |
37 | { | 37 | { |
38 | GList *chat_entries; | 38 | GList *chat_entries; |
39 | GHashTable *bindings; | ||
39 | 40 | ||
40 | GtkBuilder *builder; | 41 | GtkBuilder *builder; |
41 | GtkApplicationWindow *main_window; | 42 | GtkApplicationWindow *main_window; |