messenger-gtk

Gtk+3 graphical user interfaces for GNUnet Messenger
Log | Files | Refs | Submodules | README | LICENSE

commit 0fb7c2434bf60bf2650a11f0df866123dd064c10
parent 1de05a83d54cb363199c2767e56267533cc11f0d
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Mon, 14 Feb 2022 21:39:58 +0100

Implemented account overview to open main window with selection

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
MMakefile | 7++++---
Mresources/ui/accounts.ui | 26+++++++++++++++++++++++++-
Msrc/application.c | 16++++++++++++++++
Msrc/ui/accounts.c | 61+++++++++++++++++++++++++++++++++++++++++++++++++------------
Msrc/ui/accounts.h | 1+
Msrc/ui/contacts.c | 14+++++++++++++-
Msrc/ui/messenger.c | 4++--
Msrc/ui/new_account.c | 26++++++++++++++++++++++++--
Msrc/ui/new_account.h | 2++
9 files changed, 136 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile @@ -13,20 +13,21 @@ SOURCES = messenger_gtk.c\ file.c\ resources.c\ chat/messenger.c\ - ui/chat.c\ + ui/account_entry.c\ + ui/accounts.c\ ui/chat_entry.c\ + ui/chat.c\ ui/contact_entry.c\ ui/contacts.c\ ui/file_load_entry.c\ ui/invite_contact.c\ ui/message.c\ ui/messenger.c\ + ui/new_account.c\ ui/new_contact.c\ ui/new_group.c\ ui/new_platform.c\ - ui/new_account.c\ ui/picker.c\ - ui/account_entry.c\ ui/send_file.c\ ui/settings.c diff --git a/resources/ui/accounts.ui b/resources/ui/accounts.ui @@ -1,9 +1,31 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.38.2 --> +<!-- Generated with glade 3.38.2 + +Copyright (C) 2022 GNUnet e.V. + +GNUnet is free software: you can redistribute it and/or modify it +under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, +or (at your option) any later version. + +GNUnet is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +SPDX-License-Identifier: AGPL3.0-or-later +Author: Tobias Frisch + +--> <interface> <requires lib="gtk+" version="3.24"/> <object class="GtkDialog" id="accounts_dialog"> <property name="can-focus">False</property> + <property name="modal">True</property> + <property name="window-position">center-on-parent</property> <property name="type-hint">dialog</property> <child internal-child="vbox"> <object class="GtkBox"> @@ -36,6 +58,8 @@ </child> <child> <object class="GtkScrolledWindow"> + <property name="width-request">250</property> + <property name="height-request">150</property> <property name="visible">True</property> <property name="can-focus">True</property> <property name="shadow-type">in</property> diff --git a/src/application.c b/src/application.c @@ -43,6 +43,17 @@ _load_ui_stylesheets(MESSENGER_Application *app) ); } +static gboolean +_application_accounts(gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + ui_accounts_dialog_init(app, &(app->ui.accounts)); + + gtk_widget_show(GTK_WIDGET(app->ui.accounts.dialog)); + return FALSE; +} + static void _application_activate(UNUSED GtkApplication* application, gpointer user_data) @@ -50,6 +61,11 @@ _application_activate(UNUSED GtkApplication* application, MESSENGER_Application *app = (MESSENGER_Application*) user_data; ui_messenger_init(app, &(app->ui.messenger)); + + if (app->chat.identity) + gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); + else + g_idle_add(G_SOURCE_FUNC(_application_accounts), app); } void diff --git a/src/ui/accounts.c b/src/ui/accounts.c @@ -46,6 +46,15 @@ _open_new_account_dialog(gpointer user_data) return FALSE; } +static gboolean +_show_messenger_main_window(gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); + return FALSE; +} + static void handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, GtkListBoxRow* row, @@ -55,7 +64,10 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, if (!gtk_list_box_row_get_selectable(row)) { - g_idle_add(G_SOURCE_FUNC(_open_new_account_dialog), app); + app->ui.accounts.show_queued = g_idle_add( + G_SOURCE_FUNC(_open_new_account_dialog), app + ); + goto close_dialog; } @@ -66,7 +78,12 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, if (!account) goto close_dialog; - // TODO + if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window))) + app->ui.accounts.show_queued = g_idle_add( + G_SOURCE_FUNC(_show_messenger_main_window), app + ); + + GNUNET_CHAT_connect(app->chat.messenger.handle, account); close_dialog: gtk_window_close(GTK_WINDOW(app->ui.accounts.dialog)); @@ -76,16 +93,21 @@ static void handle_dialog_destroy(UNUSED GtkWidget *window, gpointer user_data) { - ui_accounts_dialog_cleanup((UI_ACCOUNTS_Handle*) user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + ui_accounts_dialog_cleanup(&(app->ui.accounts)); + + if ((!(app->ui.accounts.show_queued)) && + (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))) + gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window)); } static int _iterate_accounts(void *cls, - const struct GNUNET_CHAT_Handle *handle, + UNUSED const struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Account *account) { MESSENGER_Application *app = (MESSENGER_Application*) cls; - UI_MESSENGER_Handle *ui = &(app->ui.messenger); const gchar *name = GNUNET_CHAT_account_get_name(account); @@ -94,16 +116,16 @@ _iterate_accounts(void *cls, hdy_avatar_set_text(entry->entry_avatar, name); gtk_label_set_text(entry->entry_label, name); - gtk_list_box_prepend(ui->accounts_listbox, entry->entry_box); + gtk_list_box_prepend(app->ui.accounts.accounts_listbox, entry->entry_box); GtkListBoxRow *row = GTK_LIST_BOX_ROW( gtk_widget_get_parent(entry->entry_box) ); - g_hash_table_insert(ui->bindings, row, account); + g_hash_table_insert(app->ui.bindings, row, account); - ui.accounts.account_entries = g_list_append( - ui.accounts.account_entries, + app->ui.accounts.account_entries = g_list_append( + app->ui.accounts.account_entries, entry ); @@ -116,6 +138,7 @@ ui_accounts_dialog_init(MESSENGER_Application *app, { handle->account_entries = NULL; handle->bindings = app->ui.bindings; + handle->show_queued = 0; handle->builder = gtk_builder_new_from_resource( application_get_resource_path(app, "ui/accounts.ui") @@ -127,7 +150,7 @@ ui_accounts_dialog_init(MESSENGER_Application *app, gtk_window_set_title( GTK_WINDOW(handle->dialog), - _("Contacts") + _("Accounts") ); gtk_window_set_transient_for( @@ -161,7 +184,7 @@ ui_accounts_dialog_init(MESSENGER_Application *app, handle->dialog, "destroy", G_CALLBACK(handle_dialog_destroy), - handle + app ); GNUNET_CHAT_iterate_accounts( @@ -169,14 +192,28 @@ ui_accounts_dialog_init(MESSENGER_Application *app, _iterate_accounts, app ); + + gtk_list_box_unselect_all(handle->accounts_listbox); } void ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) { + GList *list = gtk_container_get_children( + GTK_CONTAINER(handle->accounts_listbox) + ); + + while (list) + { + if (list->data) + g_hash_table_remove(handle->bindings, list->data); + + list = list->next; + } + g_object_unref(handle->builder); - GList *list = handle->account_entries; + list = handle->account_entries; while (list) { if (list->data) diff --git a/src/ui/accounts.h b/src/ui/accounts.h @@ -31,6 +31,7 @@ typedef struct UI_ACCOUNTS_Handle { GList *account_entries; GHashTable *bindings; + guint show_queued; GtkBuilder *builder; GtkDialog *dialog; diff --git a/src/ui/contacts.c b/src/ui/contacts.c @@ -257,9 +257,21 @@ ui_contacts_dialog_init(MESSENGER_Application *app, void ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) { + GList *list = gtk_container_get_children( + GTK_CONTAINER(handle->contacts_listbox) + ); + + while (list) + { + if (list->data) + g_hash_table_remove(handle->bindings, list->data); + + list = list->next; + } + g_object_unref(handle->builder); - GList *list = handle->contact_entries; + list = handle->contact_entries; while (list) { if (list->data) diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -206,6 +206,8 @@ handle_chats_listbox_filter_func(GtkListBoxRow *row, { UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; + printf("-- %lu\n", (uint64_t) row); + if ((!gtk_list_box_row_get_selectable(row)) || (gtk_list_box_row_is_selected(row))) return TRUE; @@ -467,8 +469,6 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "chats_stack") ); - gtk_widget_show(GTK_WIDGET(handle->main_window)); - g_signal_connect( handle->main_window, "destroy", diff --git a/src/ui/new_account.c b/src/ui/new_account.c @@ -26,6 +26,15 @@ #include "../application.h" +static gboolean +_show_messenger_main_window(gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); + return FALSE; +} + static void _open_new_account(GtkEntry *entry, MESSENGER_Application *app) { @@ -40,6 +49,11 @@ _open_new_account(GtkEntry *entry, MESSENGER_Application *app) GNUNET_free(app->chat.identity); app->chat.identity = GNUNET_strdup(name); + + if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window))) + app->ui.new_account.show_queued = g_idle_add( + G_SOURCE_FUNC(_show_messenger_main_window), app + ); } static void @@ -86,13 +100,21 @@ static void handle_dialog_destroy(UNUSED GtkWidget *window, gpointer user_data) { - ui_new_account_dialog_cleanup((UI_NEW_ACCOUNT_Handle*) user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + ui_new_account_dialog_cleanup(&(app->ui.new_account)); + + if ((!(app->ui.new_account.show_queued)) && + (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))) + gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window)); } void ui_new_account_dialog_init(MESSENGER_Application *app, UI_NEW_ACCOUNT_Handle *handle) { + handle->show_queued = 0; + handle->builder = gtk_builder_new_from_resource( application_get_resource_path(app, "ui/new_account.ui") ); @@ -163,7 +185,7 @@ ui_new_account_dialog_init(MESSENGER_Application *app, handle->dialog, "destroy", G_CALLBACK(handle_dialog_destroy), - handle + app ); } diff --git a/src/ui/new_account.h b/src/ui/new_account.h @@ -29,6 +29,8 @@ typedef struct UI_NEW_ACCOUNT_Handle { + guint show_queued; + GtkBuilder *builder; GtkDialog *dialog;