commit 9629a36b31ea3110e83ebac0ea97ab22798b7ea6
parent 44417e6c8b85449f2cea77b2cb672da94729de0d
Author: Jacki <jacki@thejackimonster.de>
Date: Thu, 25 Apr 2024 15:23:17 +0200
Update UI widgets regarding own account on attribute changes
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
6 files changed, 84 insertions(+), 8 deletions(-)
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
@@ -197,6 +197,11 @@ _chat_messenger_message(void *cls,
);
break;
}
+ case GNUNET_CHAT_KIND_ATTRIBUTES:
+ {
+ application_call_event(app, event_update_attributes);
+ break;
+ }
default:
break;
}
diff --git a/src/event.c b/src/event.c
@@ -136,7 +136,7 @@ static void
_reload_accounts(MESSENGER_Application *app)
{
account_cleanup_infos();
-
+
GNUNET_CHAT_iterate_accounts(
app->chat.messenger.handle,
_iterate_reload_account,
@@ -936,3 +936,44 @@ event_tag_message(MESSENGER_Application *app,
enqueue_chat_entry_update(handle);
}
+
+static enum GNUNET_GenericReturnValue
+_iterate_contacts_update_own(void *cls,
+ UNUSED struct GNUNET_CHAT_Handle *handle,
+ struct GNUNET_CHAT_Contact *contact)
+{
+ g_assert((cls) && (contact));
+
+ MESSENGER_Application *app = (MESSENGER_Application*) cls;
+
+ if (GNUNET_YES != GNUNET_CHAT_contact_is_owned(contact))
+ return GNUNET_YES;
+
+ printf("contact-update! %s\n", GNUNET_CHAT_contact_get_name(contact));
+
+ contact_update_attributes(contact, app);
+ return GNUNET_YES;
+}
+
+void
+event_update_attributes(MESSENGER_Application *app)
+{
+ g_assert(app);
+
+ CHAT_MESSENGER_Handle *chat = &(app->chat.messenger);
+
+ const struct GNUNET_CHAT_Account *account = GNUNET_CHAT_get_connected(
+ chat->handle
+ );
+
+ if (account)
+ account_update_attributes(account, app);
+
+ printf("update!\n");
+
+ GNUNET_CHAT_iterate_contacts(
+ chat->handle,
+ _iterate_contacts_update_own,
+ app
+ );
+}
diff --git a/src/event.h b/src/event.h
@@ -162,4 +162,13 @@ event_tag_message(MESSENGER_Application *app,
struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *msg);
+/**
+ * Event for the UI to be called whenever an attribute
+ * gets changed.
+ *
+ * @param app Messenger application
+ */
+void
+event_update_attributes(MESSENGER_Application *app);
+
#endif /* EVENT_H_ */
diff --git a/src/ui/accounts.c b/src/ui/accounts.c
@@ -25,6 +25,8 @@
#include "accounts.h"
#include "account_entry.h"
+
+#include "../account.h"
#include "../application.h"
#include "../ui.h"
diff --git a/src/ui/contact_entry.c b/src/ui/contact_entry.c
@@ -25,6 +25,7 @@
#include "contact_entry.h"
#include "../application.h"
+#include "../contact.h"
#include "../ui.h"
UI_CONTACT_ENTRY_Handle*
@@ -34,6 +35,8 @@ ui_contact_entry_new(MESSENGER_Application *app)
UI_CONTACT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CONTACT_ENTRY_Handle));
+ handle->contact = NULL;
+
handle->builder = ui_builder_from_resource(
application_get_resource_path(app, "ui/contact_entry.ui")
);
@@ -61,14 +64,25 @@ void
ui_contact_entry_set_contact(UI_CONTACT_ENTRY_Handle* handle,
const struct GNUNET_CHAT_Contact *contact)
{
- g_assert((handle) && (contact));
+ g_assert(handle);
+
+ if (handle->contact)
+ {
+ contact_remove_name_avatar_from_info(handle->contact, handle->entry_avatar);
+ contact_remove_name_label_from_info(handle->contact, handle->title_label);
+ }
- const char *name = GNUNET_CHAT_contact_get_name(contact);
- const char *key = GNUNET_CHAT_contact_get_key(contact);
+ if (contact)
+ {
+ const char *key = GNUNET_CHAT_contact_get_key(contact);
- ui_avatar_set_text(handle->entry_avatar, name);
- ui_label_set_text(handle->title_label, name);
- ui_label_set_text(handle->subtitle_label, key);
+ contact_add_name_avatar_to_info(contact, handle->entry_avatar);
+ contact_add_name_label_to_info(contact, handle->title_label);
+
+ ui_label_set_text(handle->subtitle_label, key);
+ }
+
+ handle->contact = contact;
}
void
@@ -76,6 +90,8 @@ ui_contact_entry_delete(UI_CONTACT_ENTRY_Handle *handle)
{
g_assert(handle);
+ ui_contact_entry_set_contact(handle, NULL);
+
g_object_unref(handle->builder);
g_free(handle);
diff --git a/src/ui/contact_entry.h b/src/ui/contact_entry.h
@@ -27,12 +27,15 @@
#include "messenger.h"
+#include <gnunet/gnunet_chat_lib.h>
+
typedef struct UI_CONTACT_ENTRY_Handle
{
+ const struct GNUNET_CHAT_Contact *contact;
+
GtkBuilder *builder;
GtkWidget *entry_box;
-
HdyAvatar *entry_avatar;
GtkLabel *title_label;