commit 078942ede53ba5c4180d673283e3495e4b4cc879
parent fb702eab745cdb539eb1858b3a66403e7001b8a4
Author: Jacki <jacki@thejackimonster.de>
Date: Sun, 5 May 2024 20:57:20 +0200
Adjust account management regarding latest changes in message kinds
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
10 files changed, 91 insertions(+), 50 deletions(-)
diff --git a/src/account.c b/src/account.c
@@ -176,12 +176,7 @@ _task_update_avatars(gpointer data)
{
g_assert(data);
- struct GNUNET_CHAT_Account *account = (struct GNUNET_CHAT_Account*) data;
-
- MESSENGER_AccountInfo *info = GNUNET_CHAT_account_get_user_pointer(account);
-
- if (!info)
- return FALSE;
+ MESSENGER_AccountInfo *info = (MESSENGER_AccountInfo*) data;
info->task = 0;
@@ -237,7 +232,7 @@ skip_comparison:
info->icon = g_file_icon_new(file_object);
if (!(info->task))
- info->task = util_idle_add(G_SOURCE_FUNC(_task_update_avatars), account);
+ info->task = util_idle_add(G_SOURCE_FUNC(_task_update_avatars), info);
}
static enum GNUNET_GenericReturnValue
diff --git a/src/application.c b/src/application.c
@@ -26,6 +26,8 @@
#include "request.h"
#include "resources.h"
+#include <gnunet/gnunet_chat_lib.h>
+#include <gnunet/gnunet_common.h>
#include <gstreamer-1.0/gst/gst.h>
#include <gtk-3.0/gtk/gtk.h>
#include <libhandy-1/handy.h>
@@ -72,6 +74,24 @@ _application_accounts(gpointer user_data)
return FALSE;
}
+static enum GNUNET_GenericReturnValue
+_application_select_account(void *cls,
+ const struct GNUNET_CHAT_Handle *handle,
+ struct GNUNET_CHAT_Account *account)
+{
+ g_assert((cls) && (account));
+
+ MESSENGER_Application *app = (MESSENGER_Application*) cls;
+
+ const char *name = GNUNET_CHAT_account_get_name(account);
+
+ if ((!name) || (0 != g_strcmp0(app->chat.identity, name)))
+ return GNUNET_YES;
+
+ GNUNET_CHAT_connect(app->chat.messenger.handle, account);
+ return GNUNET_NO;
+}
+
static void
_application_init(MESSENGER_Application *app)
{
@@ -85,7 +105,15 @@ _application_init(MESSENGER_Application *app)
#endif
if (app->chat.identity)
+ {
+ GNUNET_CHAT_iterate_accounts(
+ app->chat.messenger.handle,
+ _application_select_account,
+ app
+ );
+
application_show_window(app);
+ }
else
app->init = util_idle_add(G_SOURCE_FUNC(_application_accounts), app);
}
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
@@ -117,6 +117,17 @@ _chat_messenger_message(void *cls,
application_call_sync_event(app, event_cleanup_profile);
break;
}
+ case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
+ case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
+ {
+ application_call_message_event(
+ app,
+ event_select_profile,
+ context,
+ message
+ );
+ break;
+ }
case GNUNET_CHAT_KIND_UPDATE_CONTEXT:
{
application_call_message_event(
diff --git a/src/event.c b/src/event.c
@@ -135,11 +135,22 @@ _iterate_reload_account(void *cls,
static void
_reload_accounts(MESSENGER_Application *app)
{
+ UI_MESSENGER_Handle *ui = &(app->ui.messenger);
+ CHAT_MESSENGER_Handle *chat = &(app->chat.messenger);
+
GNUNET_CHAT_iterate_accounts(
- app->chat.messenger.handle,
+ chat->handle,
_iterate_reload_account,
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
@@ -156,11 +167,6 @@ _idle_refresh_accounts(gpointer user_data)
_reload_accounts(app);
- if (gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))
- ui_messenger_refresh(app, &(app->ui.messenger));
- else
- ui_accounts_dialog_refresh(app, &(app->ui.accounts));
-
return FALSE;
}
@@ -423,6 +429,24 @@ event_cleanup_profile(MESSENGER_Application *app)
GNUNET_CHAT_iterate_files(chat->handle, _cleanup_profile_files, NULL);
}
+void
+event_select_profile(MESSENGER_Application *app,
+ struct GNUNET_CHAT_Context *context,
+ const struct GNUNET_CHAT_Message *msg)
+{
+ 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
_delayed_context_drop(gpointer user_data)
{
diff --git a/src/event.h b/src/event.h
@@ -71,6 +71,19 @@ event_cleanup_profile(MESSENGER_Application *app);
/**
* Event for the UI to be called whenever a the user
+ * creates or updates an account.
+ *
+ * @param app Messenger application
+ * @param context Chat context
+ * @param msg Create/Update message
+ */
+void
+event_select_profile(MESSENGER_Application *app,
+ struct GNUNET_CHAT_Context *context,
+ const struct GNUNET_CHAT_Message *msg);
+
+/**
+ * Event for the UI to be called whenever a the user
* joins or leaves a chat (context) via message.
*
* @param app Messenger application
diff --git a/src/ui/account_entry.c b/src/ui/account_entry.c
@@ -65,7 +65,7 @@ ui_account_entry_set_account(UI_ACCOUNT_ENTRY_Handle* handle,
g_assert(handle);
if (handle->account)
- account_remove_name_avatar_from_info(account, handle->entry_avatar);
+ account_remove_name_avatar_from_info(handle->account, handle->entry_avatar);
if (account)
{
diff --git a/src/ui/accounts.c b/src/ui/accounts.c
@@ -60,9 +60,6 @@ _show_messenger_main_window(gpointer user_data)
MESSENGER_Application *app = (MESSENGER_Application*) user_data;
- // Refresh the account list
- ui_messenger_refresh(app, &(app->ui.messenger));
-
application_show_window(app);
return FALSE;
}
@@ -101,6 +98,9 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
GNUNET_CHAT_connect(app->chat.messenger.handle, account);
+ gtk_list_box_unselect_all(app->ui.messenger.accounts_listbox);
+ gtk_widget_set_sensitive(GTK_WIDGET(app->ui.accounts.dialog), FALSE);
+
close_dialog:
gtk_window_close(GTK_WINDOW(app->ui.accounts.dialog));
}
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
@@ -708,8 +708,6 @@ _messenger_iterate_accounts(void *cls,
MESSENGER_Application *app = (MESSENGER_Application*) cls;
UI_MESSENGER_Handle *ui = &(app->ui.messenger);
- const char *name = GNUNET_CHAT_account_get_name(account);
-
UI_ACCOUNT_ENTRY_Handle *entry = ui_account_entry_new(app);
ui_account_entry_set_account(entry, account);
@@ -720,8 +718,7 @@ _messenger_iterate_accounts(void *cls,
g_object_set_qdata(G_OBJECT(row), app->quarks.data, account);
- if ((account == GNUNET_CHAT_get_connected(handle)) ||
- ((app->chat.identity) && (0 == g_strcmp0(app->chat.identity, name))))
+ if (account == GNUNET_CHAT_get_connected(handle))
gtk_widget_activate(row);
ui_account_entry_delete(entry);
diff --git a/src/ui/new_account.c b/src/ui/new_account.c
@@ -29,17 +29,6 @@
#include "../file.h"
#include "../ui.h"
-static gboolean
-_show_messenger_main_window(gpointer user_data)
-{
- g_assert(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)
@@ -52,18 +41,7 @@ _open_new_account(GtkEntry *entry,
return;
gtk_list_box_unselect_all(app->ui.messenger.accounts_listbox);
-
- if (app->chat.identity)
- GNUNET_free(app->chat.identity);
-
- app->chat.identity = GNUNET_strdup(name);
-
gtk_widget_set_sensitive(GTK_WIDGET(app->ui.new_account.dialog), FALSE);
-
- if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))
- app->ui.new_account.show_queued = util_idle_add(
- G_SOURCE_FUNC(_show_messenger_main_window), app
- );
}
static void
@@ -179,8 +157,7 @@ handle_dialog_destroy(UNUSED GtkWidget *window,
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))))
+ if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))
gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window));
}
@@ -190,8 +167,6 @@ ui_new_account_dialog_init(MESSENGER_Application *app,
{
g_assert((app) && (handle));
- handle->show_queued = 0;
-
handle->builder = ui_builder_from_resource(
application_get_resource_path(app, "ui/new_account.ui")
);
@@ -318,6 +293,7 @@ ui_new_account_dialog_update(MESSENGER_Application *app,
{
g_assert((app) && (handle));
+ gtk_widget_set_sensitive(GTK_WIDGET(app->ui.new_account.dialog), TRUE);
gtk_window_close(GTK_WINDOW(app->ui.new_account.dialog));
if (!(handle->filename))
@@ -344,7 +320,5 @@ ui_new_account_dialog_cleanup(UI_NEW_ACCOUNT_Handle *handle)
if (handle->filename)
g_free(handle->filename);
- guint show = handle->show_queued;
memset(handle, 0, sizeof(*handle));
- handle->show_queued = show;
}
diff --git a/src/ui/new_account.h b/src/ui/new_account.h
@@ -29,7 +29,6 @@
typedef struct UI_NEW_ACCOUNT_Handle
{
- guint show_queued;
gchar *filename;
GtkBuilder *builder;