messenger-gtk

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

commit 3a3d5049bfef54bdaf33f7e184fe437d06c1a209
parent f887357406c51121f7530716f8ddf73f62d8c135
Author: Jacki <jacki@thejackimonster.de>
Date:   Mon, 22 Apr 2024 21:56:37 +0200

Implement using profile pictures on most avatars

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

Diffstat:
Msrc/contact.c | 5+++--
Msrc/contact.h | 3++-
Msrc/event.c | 9++++++---
Msrc/ui/chat.c | 60+++++++++++++++++++++++++++++++++++++++++++++++++-----------
Msrc/ui/chat_entry.c | 52+++++++++++++++++++++++++++++++++++++++++++---------
5 files changed, 103 insertions(+), 26 deletions(-)

diff --git a/src/contact.c b/src/contact.c @@ -29,11 +29,11 @@ #include <gnunet/gnunet_common.h> #include <string.h> -void +enum GNUNET_GenericReturnValue contact_create_info(struct GNUNET_CHAT_Contact *contact) { if ((!contact) || (GNUNET_CHAT_contact_get_user_pointer(contact))) - return; + return GNUNET_NO; MESSENGER_ContactInfo* info = g_malloc(sizeof(MESSENGER_ContactInfo)); @@ -45,6 +45,7 @@ contact_create_info(struct GNUNET_CHAT_Contact *contact) info->visible_widgets = NULL; GNUNET_CHAT_contact_set_user_pointer(contact, info); + return GNUNET_YES; } void diff --git a/src/contact.h b/src/contact.h @@ -46,8 +46,9 @@ typedef struct MESSENGER_ContactInfo * once. * * @param contact Chat contact + * @return #GNUNET_YES on info creation, otherwise #GNUNET_NO */ -void +enum GNUNET_GenericReturnValue contact_create_info(struct GNUNET_CHAT_Contact *contact); /** diff --git a/src/event.c b/src/event.c @@ -445,8 +445,8 @@ event_update_chats(MESSENGER_Application *app, if (!contact) return; - contact_create_info(contact); - contact_update_attributes(contact, app); + if (GNUNET_YES == contact_create_info(contact)) + contact_update_attributes(contact, app); } static void @@ -560,7 +560,7 @@ event_update_contacts(UNUSED MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - g_assert((app) && (context) && (msg)); + g_assert((app) && (msg)); struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( msg @@ -575,6 +575,9 @@ event_update_contacts(UNUSED MESSENGER_Application *app, contact_update_info(contact); _update_contact_context(contact); + if (!context) + return; + UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); if (!handle) diff --git a/src/ui/chat.c b/src/ui/chat.c @@ -41,6 +41,7 @@ #include "delete_messages.h" #include "../application.h" +#include "../contact.h" #include "../file.h" #include "../ui.h" @@ -2089,6 +2090,43 @@ _chat_update_media(UI_CHAT_Handle *handle, ); } +static void +_chat_update_contact(UI_CHAT_Handle *handle, + MESSENGER_Application *app, + struct GNUNET_CHAT_Contact* contact) +{ + g_assert((handle) && (app)); + + struct GNUNET_CHAT_Contact *prev = g_object_get_qdata( + G_OBJECT(handle->chat_avatar), + app->quarks.data + ); + + if (prev) + { + contact_remove_name_label_from_info(contact, handle->chat_title); + contact_remove_name_avatar_from_info(contact, handle->chat_avatar); + + contact_remove_name_label_from_info(contact, handle->chat_details_label); + contact_remove_name_avatar_from_info(contact, handle->chat_details_avatar); + } + + if (contact) + { + contact_add_name_label_to_info(contact, handle->chat_title); + contact_add_name_avatar_to_info(contact, handle->chat_avatar); + + contact_add_name_label_to_info(contact, handle->chat_details_label); + contact_add_name_avatar_to_info(contact, handle->chat_details_avatar); + } + + g_object_set_qdata( + G_OBJECT(handle->chat_avatar), + app->quarks.data, + contact + ); +} + void ui_chat_update(UI_CHAT_Handle *handle, MESSENGER_Application *app, @@ -2102,19 +2140,17 @@ ui_chat_update(UI_CHAT_Handle *handle, contact = GNUNET_CHAT_context_get_contact(context); group = GNUNET_CHAT_context_get_group(context); - const char *title = NULL; const char *icon = "action-unavailable-symbolic"; GString *subtitle = g_string_new(""); + _chat_update_contact(handle, app, contact); + if (contact) - { - title = GNUNET_CHAT_contact_get_name(contact); icon = "avatar-default-symbolic"; - } else if (group) { - title = GNUNET_CHAT_group_get_name(group); + const char *title = GNUNET_CHAT_group_get_name(group); if ((title) && ('#' == *title)) icon = "network-wired-symbolic"; @@ -2126,17 +2162,17 @@ ui_chat_update(UI_CHAT_Handle *handle, _("%d members"), GNUNET_CHAT_group_iterate_contacts(group, NULL, NULL) ); + + ui_label_set_text(handle->chat_title, title); + ui_avatar_set_text(handle->chat_avatar, title); + + ui_label_set_text(handle->chat_details_label, title); + ui_avatar_set_text(handle->chat_details_avatar, title); } - ui_avatar_set_text(handle->chat_avatar, title); hdy_avatar_set_icon_name(handle->chat_avatar, icon); - - ui_avatar_set_text(handle->chat_details_avatar, title); hdy_avatar_set_icon_name(handle->chat_details_avatar, icon); - ui_label_set_text(handle->chat_title, title); - ui_label_set_text(handle->chat_details_label, title); - if (subtitle->len > 0) gtk_label_set_text(handle->chat_subtitle, subtitle->str); @@ -2225,6 +2261,8 @@ ui_chat_delete(UI_CHAT_Handle *handle) { g_assert(handle); + _chat_update_contact(handle, handle->app, NULL); + GList *message_rows = gtk_container_get_children(GTK_CONTAINER(handle->messages_listbox)); GList *row_element = message_rows; diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c @@ -27,7 +27,9 @@ #include "message.h" #include "../application.h" +#include "../contact.h" #include "../ui.h" + #include <gnunet/gnunet_chat_lib.h> #include <gnunet/gnunet_time_lib.h> @@ -74,6 +76,37 @@ ui_chat_entry_new(MESSENGER_Application *app) return handle; } +static void +_chat_entry_update_contact(UI_CHAT_ENTRY_Handle *handle, + MESSENGER_Application *app, + struct GNUNET_CHAT_Contact* contact) +{ + g_assert((handle) && (app)); + + struct GNUNET_CHAT_Contact *prev = g_object_get_qdata( + G_OBJECT(handle->entry_avatar), + app->quarks.data + ); + + if (prev) + { + contact_remove_name_label_from_info(contact, handle->title_label); + contact_remove_name_avatar_from_info(contact, handle->entry_avatar); + } + + if (contact) + { + contact_add_name_label_to_info(contact, handle->title_label); + contact_add_name_avatar_to_info(contact, handle->entry_avatar); + } + + g_object_set_qdata( + G_OBJECT(handle->entry_avatar), + app->quarks.data, + contact + ); +} + void ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, MESSENGER_Application *app, @@ -81,32 +114,31 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, { g_assert((handle) && (app)); - const struct GNUNET_CHAT_Contact* contact; - const struct GNUNET_CHAT_Group* group; + struct GNUNET_CHAT_Contact* contact; + struct GNUNET_CHAT_Group* group; contact = GNUNET_CHAT_context_get_contact(context); group = GNUNET_CHAT_context_get_group(context); - const char *title = NULL; const char *icon = "action-unavailable-symbolic"; + _chat_entry_update_contact(handle, app, contact); + if (contact) - { - title = GNUNET_CHAT_contact_get_name(contact); icon = "avatar-default-symbolic"; - } else if (group) { - title = GNUNET_CHAT_group_get_name(group); + const char *title = GNUNET_CHAT_group_get_name(group); if ((title) && ('#' == *title)) icon = "network-wired-symbolic"; else icon = "system-users-symbolic"; + + ui_label_set_text(handle->title_label, title); + ui_avatar_set_text(handle->entry_avatar, title); } - ui_label_set_text(handle->title_label, title); - ui_avatar_set_text(handle->entry_avatar, title); hdy_avatar_set_icon_name(handle->entry_avatar, icon); if (!(handle->chat)) @@ -240,6 +272,8 @@ ui_chat_entry_dispose(UI_CHAT_ENTRY_Handle *handle, if (context) GNUNET_CHAT_context_set_user_pointer(context, NULL); + _chat_entry_update_contact(handle, app, NULL); + gtk_container_remove( GTK_CONTAINER(ui->chats_stack), handle->chat->chat_box