commit 446862e5869e8888f829d9b6f4893663b7470274
parent 22504147521a36c513c200f9ed3f413b679d3f75
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Wed, 15 Dec 2021 23:17:01 +0100
-fixed usage of lists, synced avatars to names and added member count
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
10 files changed, 94 insertions(+), 78 deletions(-)
diff --git a/resources/ui/message-status.ui b/resources/ui/message-status.ui
@@ -66,7 +66,6 @@ Author: Tobias Frisch
<object class="GtkLabel" id="text_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
- <property name="label" translatable="yes">invited you to a chat</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<property name="xalign">0.5</property>
diff --git a/src/contact.c b/src/contact.c
@@ -32,7 +32,8 @@ contact_create_info(struct GNUNET_CHAT_Contact *contact)
MESSENGER_ContactInfo* info = g_malloc(sizeof(MESSENGER_ContactInfo));
- info->name_labels = g_list_alloc();
+ info->name_labels = NULL;
+ info->name_avatars = NULL;
GNUNET_CHAT_contact_set_user_pointer(contact, info);
}
@@ -45,7 +46,12 @@ contact_destroy_info(struct GNUNET_CHAT_Contact *contact)
if (!info)
return;
- g_list_free(info->name_labels);
+ if (info->name_labels)
+ g_list_free(info->name_labels);
+
+ if (info->name_avatars)
+ g_list_free(info->name_avatars);
+
g_free(info);
GNUNET_CHAT_contact_set_user_pointer(contact, NULL);
@@ -57,13 +63,31 @@ contact_add_name_label_to_info(const struct GNUNET_CHAT_Contact *contact,
{
MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact);
- if (!info)
+ if ((!info) || (!label))
return;
+ const char *name = GNUNET_CHAT_contact_get_name(contact);
+ gtk_label_set_text(label, name? name : "");
+
info->name_labels = g_list_append(info->name_labels, label);
}
void
+contact_add_name_avatar_to_info(const struct GNUNET_CHAT_Contact *contact,
+ HdyAvatar *avatar)
+{
+ MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact);
+
+ if ((!info) || (!avatar))
+ return;
+
+ const char *name = GNUNET_CHAT_contact_get_name(contact);
+ hdy_avatar_set_text(avatar, name? name : "");
+
+ info->name_avatars = g_list_append(info->name_avatars, avatar);
+}
+
+void
contact_update_info(const struct GNUNET_CHAT_Contact *contact)
{
MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact);
@@ -71,17 +95,15 @@ contact_update_info(const struct GNUNET_CHAT_Contact *contact)
if (!info)
return;
+ GList* list;
const char *name = GNUNET_CHAT_contact_get_name(contact);
- GList* name_label = info->name_labels;
+ for (list = info->name_labels; list; list = list->next)
+ gtk_label_set_text(GTK_LABEL(list->data), name? name : "");
- while (name_label)
- {
- GtkLabel *label = GTK_LABEL(name_label->data);
-
- if (label)
- gtk_label_set_text(label, name? name : "");
+ if (!name)
+ return;
- name_label = name_label->next;
- }
+ for (list = info->name_avatars; list; list = list->next)
+ hdy_avatar_set_text(HDY_AVATAR(list->data), name);
}
diff --git a/src/contact.h b/src/contact.h
@@ -30,6 +30,7 @@
typedef struct MESSENGER_ContactInfo
{
GList *name_labels;
+ GList *name_avatars;
} MESSENGER_ContactInfo;
void
@@ -43,6 +44,10 @@ contact_add_name_label_to_info(const struct GNUNET_CHAT_Contact *contact,
GtkLabel *label);
void
+contact_add_name_avatar_to_info(const struct GNUNET_CHAT_Contact *contact,
+ HdyAvatar *avatar);
+
+void
contact_update_info(const struct GNUNET_CHAT_Contact *contact);
#endif /* CONTACT_H_ */
diff --git a/src/event.c b/src/event.c
@@ -186,7 +186,7 @@ event_joining_contact(MESSENGER_Application *app,
ui_chat_entry_update(handle, app, context);
- UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS);
+ UI_MESSAGE_Handle *message = ui_message_new(UI_MESSAGE_STATUS);
struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
msg
@@ -195,11 +195,7 @@ event_joining_contact(MESSENGER_Application *app,
contact_create_info(contact);
_update_contact_context(app, contact);
- const char *sender = GNUNET_CHAT_contact_get_name(contact);
-
- hdy_avatar_set_text(message->sender_avatar, sender? sender : "");
- gtk_label_set_text(message->sender_label, sender? sender : "");
-
+ contact_add_name_avatar_to_info(contact, message->sender_avatar);
contact_add_name_label_to_info(contact, message->sender_label);
gtk_label_set_text(message->text_label, "joined the chat");
@@ -213,8 +209,8 @@ event_joining_contact(MESSENGER_Application *app,
}
void
-event_update_contacts(UNUSED MESSENGER_Application *app,
- UNUSED struct GNUNET_CHAT_Context *context,
+event_update_contacts(MESSENGER_Application *app,
+ struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *msg)
{
struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
@@ -223,6 +219,13 @@ event_update_contacts(UNUSED MESSENGER_Application *app,
contact_update_info(contact);
_update_contact_context(app, contact);
+
+ UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context);
+
+ if (!handle)
+ return;
+
+ ui_chat_entry_update(handle, app, context);
}
static void
@@ -237,7 +240,7 @@ _event_invitation_accept_click(UNUSED GtkButton *button,
}
void
-event_invitation(MESSENGER_Application *app,
+event_invitation(UNUSED MESSENGER_Application *app,
struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *msg)
{
@@ -252,16 +255,14 @@ event_invitation(MESSENGER_Application *app,
if (!invitation)
return;
- UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS);
+ UI_MESSAGE_Handle *message = ui_message_new(UI_MESSAGE_STATUS);
const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
msg
);
- const char *sender = GNUNET_CHAT_contact_get_name(contact);
-
- hdy_avatar_set_text(message->sender_avatar, sender? sender : "");
- gtk_label_set_text(message->sender_label, sender? sender : "");
+ contact_add_name_avatar_to_info(contact, message->sender_avatar);
+ contact_add_name_label_to_info(contact, message->sender_label);
gtk_label_set_text(message->text_label, "invited you to a chat");
@@ -284,7 +285,7 @@ event_invitation(MESSENGER_Application *app,
}
void
-event_receive_message(MESSENGER_Application *app,
+event_receive_message(UNUSED MESSENGER_Application *app,
struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *msg)
{
@@ -296,21 +297,15 @@ event_receive_message(MESSENGER_Application *app,
const int sent = GNUNET_CHAT_message_is_sent(msg);
UI_MESSAGE_Handle *message = ui_message_new(
- app,
GNUNET_YES == sent? UI_MESSAGE_SENT : UI_MESSAGE_DEFAULT
);
- if (GNUNET_YES != sent)
- {
- const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
- msg
- );
-
- const char *sender = GNUNET_CHAT_contact_get_name(contact);
+ const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
+ msg
+ );
- hdy_avatar_set_text(message->sender_avatar, sender? sender : "");
- gtk_label_set_text(message->sender_label, sender? sender : "");
- }
+ contact_add_name_avatar_to_info(contact, message->sender_avatar);
+ contact_add_name_label_to_info(contact, message->sender_label);
struct GNUNET_TIME_Absolute timestamp = GNUNET_CHAT_message_get_timestamp(
msg
diff --git a/src/ui/chat.c b/src/ui/chat.c
@@ -358,11 +358,8 @@ iterate_ui_chat_update_group_contacts(void *cls,
const char *name = GNUNET_CHAT_contact_get_name(contact);
- if (name)
- {
- gtk_label_set_text(entry->entry_label, name);
- hdy_avatar_set_text(entry->entry_avatar, name);
- }
+ gtk_label_set_text(entry->entry_label, name? name : "");
+ hdy_avatar_set_text(entry->entry_avatar, name? name : "");
gtk_list_box_prepend(listbox, entry->entry_box);
@@ -388,18 +385,32 @@ ui_chat_update(UI_CHAT_Handle *handle,
group = GNUNET_CHAT_context_get_group(context);
const char *title = NULL;
+ GString *subtitle = g_string_new("");
if (contact)
title = GNUNET_CHAT_contact_get_name(contact);
else if (group)
+ {
title = GNUNET_CHAT_group_get_name(group);
+ g_string_append_printf(
+ subtitle,
+ "%d members",
+ GNUNET_CHAT_group_iterate_contacts(group, NULL, NULL)
+ );
+ }
+
if (title)
{
gtk_label_set_text(handle->chat_title, title);
gtk_label_set_text(handle->chat_details_label, title);
}
+ if (subtitle->len > 0)
+ gtk_label_set_text(handle->chat_subtitle, subtitle->str);
+
+ g_string_free(subtitle, TRUE);
+
GList* children = gtk_container_get_children(
GTK_CONTAINER(handle->chat_contacts_listbox)
);
@@ -408,6 +419,9 @@ ui_chat_update(UI_CHAT_Handle *handle,
GtkWidget *widget = GTK_WIDGET(children->data);
children = children->next;
+ if (g_hash_table_contains(app->ui.bindings, widget))
+ g_hash_table_remove(app->ui.bindings, widget);
+
gtk_container_remove(
GTK_CONTAINER(handle->chat_contacts_listbox),
widget
diff --git a/src/ui/contacts.c b/src/ui/contacts.c
@@ -147,7 +147,7 @@ void
ui_contacts_dialog_init(MESSENGER_Application *app,
UI_CONTACTS_Handle *handle)
{
- handle->contact_entries = g_list_alloc();
+ handle->contact_entries = NULL;
handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui");
@@ -225,5 +225,6 @@ ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle)
list = list->next;
}
- g_list_free(handle->contact_entries);
+ if (handle->contact_entries)
+ g_list_free(handle->contact_entries);
}
diff --git a/src/ui/message.c b/src/ui/message.c
@@ -27,8 +27,7 @@
#include "../application.h"
UI_MESSAGE_Handle*
-ui_message_new(MESSENGER_Application *app,
- UI_MESSAGE_Type type)
+ui_message_new(UI_MESSAGE_Type type)
{
UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle));
@@ -63,14 +62,6 @@ ui_message_new(MESSENGER_Application *app,
gtk_builder_get_object(handle->builder, "sender_label")
);
- if (UI_MESSAGE_SENT == handle->type)
- {
- const char *sender = GNUNET_CHAT_get_name(app->chat.messenger.handle);
-
- hdy_avatar_set_text(handle->sender_avatar, sender);
- gtk_label_set_text(handle->sender_label, sender);
- }
-
handle->text_label = GTK_LABEL(
gtk_builder_get_object(handle->builder, "text_label")
);
diff --git a/src/ui/message.h b/src/ui/message.h
@@ -59,8 +59,7 @@ typedef struct UI_MESSAGE_Handle
} UI_MESSAGE_Handle;
UI_MESSAGE_Handle*
-ui_message_new(MESSENGER_Application *app,
- UI_MESSAGE_Type type);
+ui_message_new(UI_MESSAGE_Type type);
void
ui_message_delete(UI_MESSAGE_Handle *handle);
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
@@ -192,7 +192,7 @@ void
ui_messenger_init(MESSENGER_Application *app,
UI_MESSENGER_Handle *handle)
{
- handle->chat_entries = g_list_alloc();
+ handle->chat_entries = NULL;
handle->builder = gtk_builder_new_from_file("resources/ui/messenger.ui");
@@ -401,14 +401,9 @@ ui_messenger_cleanup(UI_MESSENGER_Handle *handle)
{
g_object_unref(handle->builder);
- GList *list = handle->chat_entries;
+ for (GList *list = handle->chat_entries; list; list = list->next)
+ ui_chat_entry_delete((UI_CHAT_ENTRY_Handle*) list->data);
- while (list) {
- if (list->data)
- ui_chat_entry_delete((UI_CHAT_ENTRY_Handle*) list->data);
-
- list = list->next;
- }
-
- g_list_free(handle->chat_entries);
+ if (handle->chat_entries)
+ g_list_free(handle->chat_entries);
}
diff --git a/src/ui/new_group.c b/src/ui/new_group.c
@@ -207,7 +207,7 @@ void
ui_new_group_dialog_init(MESSENGER_Application *app,
UI_NEW_GROUP_Handle *handle)
{
- handle->contact_entries = g_list_alloc();
+ handle->contact_entries = NULL;
handle->builder = gtk_builder_new_from_file("resources/ui/new_group.ui");
@@ -340,14 +340,9 @@ ui_new_group_dialog_cleanup(UI_NEW_GROUP_Handle *handle)
{
g_object_unref(handle->builder);
- GList *list = handle->contact_entries;
+ for (GList *list = handle->contact_entries; list; list = list->next)
+ ui_contact_entry_delete((UI_CONTACT_ENTRY_Handle*) list->data);
- while (list) {
- if (list->data)
- ui_contact_entry_delete((UI_CONTACT_ENTRY_Handle*) list->data);
-
- list = list->next;
- }
-
- g_list_free(handle->contact_entries);
+ if (handle->contact_entries)
+ g_list_free(handle->contact_entries);
}