diff options
Diffstat (limited to 'src/ui/messenger.c')
-rw-r--r-- | src/ui/messenger.c | 68 |
1 files changed, 65 insertions, 3 deletions
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", |