messenger-gtk

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

commit 97d85a753e7f7b81aba690aec482efc69c65367d
parent 90ca52fbdbb21f378fbf3081a679eac2256db02a
Author: Jacki <jacki@thejackimonster.de>
Date:   Mon, 22 Jul 2024 16:04:25 +0200

Fix account dialog issues

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/application.c | 6++++++
Msrc/application.h | 9+++++++++
Msrc/event.c | 69++++++++++++++++++++++++---------------------------------------------
Msrc/ui/accounts.c | 23++++++-----------------
Msrc/ui/messenger.c | 4++++
Msrc/ui/new_account.c | 8++++++--
6 files changed, 55 insertions(+), 64 deletions(-)

diff --git a/src/application.c b/src/application.c @@ -67,6 +67,7 @@ _application_accounts(gpointer user_data) MESSENGER_Application *app = (MESSENGER_Application*) user_data; app->init = 0; + app->ui.state = MESSENGER_STATE_ACCOUNTS; ui_accounts_dialog_init(app, &(app->ui.accounts)); ui_accounts_dialog_refresh(app, &(app->ui.accounts)); @@ -109,6 +110,8 @@ _application_init(MESSENGER_Application *app) if (app->chat.identity) { + app->ui.state = MESSENGER_STATE_MAIN_WINDOW; + GNUNET_CHAT_iterate_accounts( app->chat.messenger.handle, _application_select_account, @@ -592,6 +595,9 @@ void application_show_window(MESSENGER_Application *app) { g_assert(app); + + if (MESSENGER_STATE_MAIN_WINDOW != app->ui.state) + return; gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); diff --git a/src/application.h b/src/application.h @@ -72,6 +72,14 @@ typedef enum MESSENGER_ApplicationSignal MESSENGER_FAIL = 2 } MESSENGER_ApplicationSignal; +typedef enum MESSENGER_ApplicationState +{ + MESSENGER_STATE_UNKNOWN = 0, + MESSENGER_STATE_ACCOUNTS = 1, + MESSENGER_STATE_NEW_ACCOUNT = 2, + MESSENGER_STATE_MAIN_WINDOW = 3 +} MESSENGER_ApplicationState; + typedef struct MESSENGER_Application { char **argv; @@ -116,6 +124,7 @@ typedef struct MESSENGER_Application } chat; struct { + MESSENGER_ApplicationState state; int status; UI_MESSENGER_Handle messenger; diff --git a/src/event.c b/src/event.c @@ -135,11 +135,14 @@ _iterate_reload_account(void *cls, return GNUNET_YES; } -static void -_reload_accounts(MESSENGER_Application *app) +void +event_refresh_accounts(MESSENGER_Application *app) { + g_assert(app); + UI_MESSENGER_Handle *ui = &(app->ui.messenger); CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); + const struct GNUNET_CHAT_Account *account; GNUNET_CHAT_iterate_accounts( chat->handle, @@ -147,47 +150,22 @@ _reload_accounts(MESSENGER_Application *app) app ); - if (gtk_widget_is_visible(GTK_WIDGET(ui->main_window))) - ui_messenger_refresh(app, ui); - else - ui_accounts_dialog_refresh(app, &(app->ui.accounts)); - - if (GNUNET_CHAT_get_connected(chat->handle)) - application_show_window(app); -} - -static gboolean -_idle_refresh_accounts(gpointer user_data) -{ - g_assert(user_data); - - MESSENGER_Application *app = (MESSENGER_Application*) user_data; - - app->ui.messenger.account_refresh = 0; - - if (!(app->ui.messenger.main_window)) - return FALSE; - - _reload_accounts(app); - - return FALSE; -} - -void -event_refresh_accounts(MESSENGER_Application *app) -{ - g_assert(app); + switch (app->ui.state) + { + case MESSENGER_STATE_ACCOUNTS: + ui_accounts_dialog_refresh(app, &(app->ui.accounts)); + break; + case MESSENGER_STATE_MAIN_WINDOW: + ui_messenger_refresh(app, ui); + break; + default: + break; + } - if (app->ui.messenger.account_refresh) - util_source_remove(app->ui.messenger.account_refresh); + account = GNUNET_CHAT_get_connected(chat->handle); - if (app->ui.messenger.main_window) - app->ui.messenger.account_refresh = util_idle_add( - G_SOURCE_FUNC(_idle_refresh_accounts), - app - ); - else - app->ui.messenger.account_refresh = 0; + if (account) + application_show_window(app); } static gboolean @@ -342,8 +320,12 @@ event_update_profile(MESSENGER_Application *app) { g_assert(app); - if (app->ui.new_account.dialog) + if (MESSENGER_STATE_NEW_ACCOUNT == app->ui.state) + { + app->ui.state = MESSENGER_STATE_MAIN_WINDOW; + ui_new_account_dialog_update(app, &(app->ui.new_account)); + } UI_MESSENGER_Handle *ui = &(app->ui.messenger); CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); @@ -451,15 +433,12 @@ event_select_profile(MESSENGER_Application *app, { g_assert((app) && (!context) && (msg)); - UI_MESSENGER_Handle *ui = &(app->ui.messenger); CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); const struct GNUNET_CHAT_Account *account = GNUNET_CHAT_message_get_account(msg); if (GNUNET_CHAT_KIND_CREATED_ACCOUNT == GNUNET_CHAT_message_get_kind(msg)) GNUNET_CHAT_connect(chat->handle, account); - - ui_messenger_refresh(app, ui); } gboolean diff --git a/src/ui/accounts.c b/src/ui/accounts.c @@ -53,17 +53,6 @@ _open_new_account_dialog(gpointer user_data) return FALSE; } -static gboolean -_show_messenger_main_window(gpointer user_data) -{ - g_assert(user_data); - - MESSENGER_Application *app = (MESSENGER_Application*) user_data; - - application_show_window(app); - return FALSE; -} - static void handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, GtkListBoxRow* row, @@ -90,11 +79,7 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, if (!account) goto close_dialog; - // Handle the GUI swap asyncronously - if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window))) - app->ui.accounts.show_queued = util_idle_add( - G_SOURCE_FUNC(_show_messenger_main_window), app - ); + app->ui.state = MESSENGER_STATE_MAIN_WINDOW; application_chat_lock(app); GNUNET_CHAT_connect(app->chat.messenger.handle, account); @@ -118,7 +103,7 @@ handle_dialog_destroy(UNUSED GtkWidget *window, ui_accounts_dialog_cleanup(&(app->ui.accounts), app); if ((app->ui.accounts.show_queued) || - (gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))) + (MESSENGER_STATE_MAIN_WINDOW == app->ui.state)) return; gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window)); @@ -254,11 +239,15 @@ ui_accounts_dialog_refresh(MESSENGER_Application *app, _ui_accounts_cleanup_listbox(handle, app); + application_chat_lock(app); + GNUNET_CHAT_iterate_accounts( app->chat.messenger.handle, _iterate_accounts, app ); + + application_chat_unlock(app); } void diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -892,12 +892,16 @@ ui_messenger_refresh(MESSENGER_Application *app, handle->accounts_listbox ); + application_chat_lock(app); + GNUNET_CHAT_iterate_accounts( app->chat.messenger.handle, _messenger_iterate_accounts, app ); + application_chat_unlock(app); + if (gtk_list_box_get_selected_row(handle->accounts_listbox)) return; diff --git a/src/ui/new_account.c b/src/ui/new_account.c @@ -48,6 +48,8 @@ _open_new_account(GtkEntry *entry, if (GNUNET_OK != result) return; + app->ui.state = MESSENGER_STATE_NEW_ACCOUNT; + gtk_list_box_unselect_all(app->ui.messenger.accounts_listbox); gtk_widget_set_sensitive(GTK_WIDGET(app->ui.new_account.dialog), FALSE); } @@ -165,8 +167,10 @@ handle_dialog_destroy(UNUSED GtkWidget *window, ui_new_account_dialog_cleanup(&(app->ui.new_account)); - if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window))) - gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window)); + if (MESSENGER_STATE_MAIN_WINDOW == app->ui.state) + return; + + gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window)); } void