commit 65a85c59ca226fbf65ada003c57f0d77e61ef073
parent 1bdb0791ee56fa081f8af1c18b457a1cf1c471fd
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Fri, 18 Feb 2022 21:06:04 +0100
Update accounts in dialog as well as main window
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
4 files changed, 65 insertions(+), 15 deletions(-)
diff --git a/src/application.c b/src/application.c
@@ -49,6 +49,7 @@ _application_accounts(gpointer user_data)
MESSENGER_Application *app = (MESSENGER_Application*) user_data;
ui_accounts_dialog_init(app, &(app->ui.accounts));
+ ui_accounts_dialog_refresh(app, &(app->ui.accounts));
gtk_widget_show(GTK_WIDGET(app->ui.accounts.dialog));
return FALSE;
diff --git a/src/event.c b/src/event.c
@@ -127,6 +127,8 @@ event_refresh_accounts(MESSENGER_Application *app)
UI_MESSENGER_Handle *ui = &(app->ui.messenger);
CHAT_MESSENGER_Handle *chat = &(app->chat.messenger);
+ ui_accounts_dialog_refresh(app, &(app->ui.accounts));
+
if (!(ui->accounts_listbox))
return;
diff --git a/src/ui/accounts.c b/src/ui/accounts.c
@@ -181,18 +181,11 @@ ui_accounts_dialog_init(MESSENGER_Application *app,
G_CALLBACK(handle_dialog_destroy),
app
);
-
- GNUNET_CHAT_iterate_accounts(
- app->chat.messenger.handle,
- _iterate_accounts,
- app
- );
-
- gtk_list_box_unselect_all(handle->accounts_listbox);
}
-void
-ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle)
+static void
+_clear_accounts_listbox_rows(UI_ACCOUNTS_Handle *handle,
+ gboolean bindings_only)
{
GList *list = gtk_container_get_children(
GTK_CONTAINER(handle->accounts_listbox)
@@ -200,15 +193,28 @@ ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle)
while (list)
{
- if (list->data)
- g_hash_table_remove(handle->bindings, list->data);
+ GtkListBoxRow *row = GTK_LIST_BOX_ROW(list->data);
+ if ((!row) || (!gtk_list_box_row_get_selectable(row)))
+ goto skip_row;
+
+ g_hash_table_remove(handle->bindings, row);
+
+ if (!bindings_only)
+ gtk_container_remove(
+ GTK_CONTAINER(handle->accounts_listbox),
+ GTK_WIDGET(row)
+ );
+
+ skip_row:
list = list->next;
}
+}
- g_object_unref(handle->builder);
-
- list = handle->account_entries;
+static void
+_clear_accounts_entries(UI_ACCOUNTS_Handle *handle)
+{
+ GList *list = handle->account_entries;
while (list) {
if (list->data)
@@ -219,4 +225,41 @@ ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle)
if (handle->account_entries)
g_list_free(handle->account_entries);
+
+ handle->account_entries = NULL;
+}
+
+void
+ui_accounts_dialog_refresh(MESSENGER_Application *app,
+ UI_ACCOUNTS_Handle *handle)
+{
+ if (!(handle->accounts_listbox))
+ return;
+
+ if (!(handle->account_entries))
+ goto add_account_entries;
+
+ _clear_accounts_listbox_rows(handle, FALSE);
+ _clear_accounts_entries(handle);
+
+add_account_entries:
+ GNUNET_CHAT_iterate_accounts(
+ app->chat.messenger.handle,
+ _iterate_accounts,
+ app
+ );
+
+ gtk_list_box_unselect_all(handle->accounts_listbox);
+}
+
+void
+ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle)
+{
+ _clear_accounts_listbox_rows(handle, TRUE);
+
+ g_object_unref(handle->builder);
+
+ _clear_accounts_entries(handle);
+
+ handle->accounts_listbox = NULL;
}
diff --git a/src/ui/accounts.h b/src/ui/accounts.h
@@ -46,6 +46,10 @@ ui_accounts_dialog_init(MESSENGER_Application *app,
UI_ACCOUNTS_Handle *handle);
void
+ui_accounts_dialog_refresh(MESSENGER_Application *app,
+ UI_ACCOUNTS_Handle *handle);
+
+void
ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle);
#endif /* UI_ACCOUNTS_H_ */