diff options
Diffstat (limited to 'src/ui/messenger.c')
-rw-r--r-- | src/ui/messenger.c | 93 |
1 files changed, 82 insertions, 11 deletions
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 612f568..aff450e 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <gtk-3.0/gdk/gdkkeys.h> | 27 | #include <gtk-3.0/gdk/gdkkeys.h> |
28 | 28 | ||
29 | #include "account_entry.h" | ||
29 | #include "chat_entry.h" | 30 | #include "chat_entry.h" |
30 | #include "contacts.h" | 31 | #include "contacts.h" |
31 | #include "message.h" | 32 | #include "message.h" |
@@ -105,7 +106,7 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, | |||
105 | } | 106 | } |
106 | 107 | ||
107 | struct GNUNET_CHAT_Account *account = (struct GNUNET_CHAT_Account*) ( | 108 | struct GNUNET_CHAT_Account *account = (struct GNUNET_CHAT_Account*) ( |
108 | g_hash_table_lookup(app->ui.bindings, row) | 109 | bindings_get(app->bindings, row) |
109 | ); | 110 | ); |
110 | 111 | ||
111 | if (!account) | 112 | if (!account) |
@@ -192,8 +193,8 @@ handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, | |||
192 | if (!gtk_list_box_row_get_selectable(row)) | 193 | if (!gtk_list_box_row_get_selectable(row)) |
193 | return; | 194 | return; |
194 | 195 | ||
195 | UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) g_hash_table_lookup( | 196 | UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) ( |
196 | handle->bindings, row | 197 | bindings_get(handle->app->bindings, row) |
197 | ); | 198 | ); |
198 | 199 | ||
199 | if ((!entry) || (!(entry->chat)) || (!(entry->chat->chat_box))) | 200 | if ((!entry) || (!(entry->chat)) || (!(entry->chat->chat_box))) |
@@ -217,7 +218,7 @@ handle_chats_listbox_filter_func(GtkListBoxRow *row, | |||
217 | { | 218 | { |
218 | UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; | 219 | UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; |
219 | 220 | ||
220 | if ((!gtk_list_box_row_get_selectable(row)) || | 221 | if ((!row) || (!gtk_list_box_row_get_selectable(row)) || |
221 | (gtk_list_box_row_is_selected(row))) | 222 | (gtk_list_box_row_is_selected(row))) |
222 | return TRUE; | 223 | return TRUE; |
223 | 224 | ||
@@ -228,8 +229,8 @@ handle_chats_listbox_filter_func(GtkListBoxRow *row, | |||
228 | if (!filter) | 229 | if (!filter) |
229 | return TRUE; | 230 | return TRUE; |
230 | 231 | ||
231 | UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) g_hash_table_lookup( | 232 | UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) ( |
232 | handle->bindings, row | 233 | bindings_get(handle->app->bindings, row) |
233 | ); | 234 | ); |
234 | 235 | ||
235 | if ((!entry) || (!(entry->title_label))) | 236 | if ((!entry) || (!(entry->title_label))) |
@@ -267,8 +268,8 @@ void | |||
267 | ui_messenger_init(MESSENGER_Application *app, | 268 | ui_messenger_init(MESSENGER_Application *app, |
268 | UI_MESSENGER_Handle *handle) | 269 | UI_MESSENGER_Handle *handle) |
269 | { | 270 | { |
271 | handle->app = app; | ||
270 | handle->chat_entries = NULL; | 272 | handle->chat_entries = NULL; |
271 | handle->bindings = app->ui.bindings; | ||
272 | 273 | ||
273 | handle->builder = gtk_builder_new_from_resource( | 274 | handle->builder = gtk_builder_new_from_resource( |
274 | application_get_resource_path(app, "ui/messenger.ui") | 275 | application_get_resource_path(app, "ui/messenger.ui") |
@@ -490,6 +491,79 @@ ui_messenger_init(MESSENGER_Application *app, | |||
490 | ); | 491 | ); |
491 | } | 492 | } |
492 | 493 | ||
494 | static void | ||
495 | _messenger_clear_accounts_listbox_rows(UI_MESSENGER_Handle *handle) | ||
496 | { | ||
497 | GList *list = gtk_container_get_children( | ||
498 | GTK_CONTAINER(handle->accounts_listbox) | ||
499 | ); | ||
500 | |||
501 | while (list) | ||
502 | { | ||
503 | GtkListBoxRow *row = GTK_LIST_BOX_ROW(list->data); | ||
504 | |||
505 | if ((!row) || (!gtk_list_box_row_get_selectable(row))) | ||
506 | goto skip_row; | ||
507 | |||
508 | bindings_remove(handle->app->bindings, row, NULL, NULL); | ||
509 | |||
510 | gtk_container_remove( | ||
511 | GTK_CONTAINER(handle->accounts_listbox), | ||
512 | GTK_WIDGET(row) | ||
513 | ); | ||
514 | |||
515 | skip_row: | ||
516 | list = list->next; | ||
517 | } | ||
518 | } | ||
519 | |||
520 | static int | ||
521 | _messenger_iterate_accounts(void *cls, | ||
522 | const struct GNUNET_CHAT_Handle *handle, | ||
523 | struct GNUNET_CHAT_Account *account) | ||
524 | { | ||
525 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | ||
526 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | ||
527 | |||
528 | const gchar *name = GNUNET_CHAT_account_get_name(account); | ||
529 | |||
530 | UI_ACCOUNT_ENTRY_Handle *entry = ui_account_entry_new(app); | ||
531 | |||
532 | hdy_avatar_set_text(entry->entry_avatar, name); | ||
533 | gtk_label_set_text(entry->entry_label, name); | ||
534 | |||
535 | gtk_list_box_prepend(ui->accounts_listbox, entry->entry_box); | ||
536 | |||
537 | GtkListBoxRow *row = GTK_LIST_BOX_ROW( | ||
538 | gtk_widget_get_parent(entry->entry_box) | ||
539 | ); | ||
540 | |||
541 | bindings_put(app->bindings, row, account); | ||
542 | |||
543 | if ((account == GNUNET_CHAT_get_connected(handle)) || | ||
544 | ((app->chat.identity) && (0 == g_strcmp0(app->chat.identity, name)))) | ||
545 | gtk_widget_activate(GTK_WIDGET(row)); | ||
546 | |||
547 | ui_account_entry_delete(entry); | ||
548 | return GNUNET_YES; | ||
549 | } | ||
550 | |||
551 | void | ||
552 | ui_messenger_refresh(MESSENGER_Application *app, | ||
553 | UI_MESSENGER_Handle *handle) | ||
554 | { | ||
555 | if (!(handle->accounts_listbox)) | ||
556 | return; | ||
557 | |||
558 | _messenger_clear_accounts_listbox_rows(handle); | ||
559 | |||
560 | GNUNET_CHAT_iterate_accounts( | ||
561 | app->chat.messenger.handle, | ||
562 | _messenger_iterate_accounts, | ||
563 | app | ||
564 | ); | ||
565 | } | ||
566 | |||
493 | gboolean | 567 | gboolean |
494 | ui_messenger_is_context_active(UI_MESSENGER_Handle *handle, | 568 | ui_messenger_is_context_active(UI_MESSENGER_Handle *handle, |
495 | struct GNUNET_CHAT_Context *context) | 569 | struct GNUNET_CHAT_Context *context) |
@@ -514,11 +588,8 @@ ui_messenger_cleanup(UI_MESSENGER_Handle *handle) | |||
514 | { | 588 | { |
515 | g_object_unref(handle->builder); | 589 | g_object_unref(handle->builder); |
516 | 590 | ||
517 | for (GList *list = handle->chat_entries; list; list = list->next) | ||
518 | ui_chat_entry_delete((UI_CHAT_ENTRY_Handle*) list->data); | ||
519 | |||
520 | if (handle->chat_entries) | 591 | if (handle->chat_entries) |
521 | g_list_free(handle->chat_entries); | 592 | g_list_free_full(handle->chat_entries, (GDestroyNotify) ui_chat_entry_delete); |
522 | 593 | ||
523 | memset(handle, 0, sizeof(*handle)); | 594 | memset(handle, 0, sizeof(*handle)); |
524 | } | 595 | } |