messenger-gtk

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

commit 22504147521a36c513c200f9ed3f413b679d3f75
parent cbefefb69b4db53fad2c01d45b66d9056bc98fdb
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Wed, 15 Dec 2021 01:11:43 +0100

Implemented updating of labels regarding contact names in chats

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
MMakefile | 1+
Mresources/ui/chat.ui | 77+++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/chat/messenger.c | 25+++++++++++++++++++++++--
Asrc/contact.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/contact.h | 48++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/event.c | 47+++++++++++++++++++++++++++++++++++++++++++----
Msrc/event.h | 5+++++
Msrc/ui/chat.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/ui/chat.h | 1+
Msrc/ui/chat_entry.c | 4+++-
Msrc/ui/chat_entry.h | 1+
11 files changed, 315 insertions(+), 47 deletions(-)

diff --git a/Makefile b/Makefile @@ -5,6 +5,7 @@ INSTALL_DIR ?= /usr/local/ BINARY = messenger-gtk SOURCES = messenger_gtk.c\ application.c\ + contact.c\ event.c\ chat/messenger.c\ ui/chat.c\ diff --git a/resources/ui/chat.ui b/resources/ui/chat.ui @@ -389,44 +389,6 @@ Author: Tobias Frisch <property name="can-focus">False</property> <property name="orientation">vertical</property> <child> - <object class="GtkBox"> - <property name="visible">True</property> - <property name="can-focus">False</property> - <child> - <object class="GtkLabel"> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="label" translatable="yes">Notifications</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkSwitch"> - <property name="visible">True</property> - <property name="can-focus">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="pack-type">end</property> - <property name="position">1</property> - </packing> - </child> - <style> - <class name="details-entry"/> - </style> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> <object class="GtkBox" id="chat_details_contacts_box"> <property name="visible">True</property> <property name="can-focus">False</property> @@ -459,6 +421,7 @@ Author: Tobias Frisch <object class="GtkListBoxRow"> <property name="visible">True</property> <property name="can-focus">True</property> + <property name="selectable">False</property> <child> <object class="GtkBox"> <property name="visible">True</property> @@ -512,6 +475,44 @@ Author: Tobias Frisch <packing> <property name="expand">False</property> <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes">Notifications</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkSwitch"> + <property name="visible">True</property> + <property name="can-focus">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack-type">end</property> + <property name="position">1</property> + </packing> + </child> + <style> + <class name="details-entry"/> + </style> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> <property name="position">1</property> </packing> </child> diff --git a/src/chat/messenger.c b/src/chat/messenger.c @@ -24,8 +24,19 @@ #include "messenger.h" +#include "../contact.h" #include "../event.h" +int +_chat_messenger_iterate_contacts(UNUSED void *cls, + UNUSED struct GNUNET_CHAT_Handle *handle, + struct GNUNET_CHAT_Contact *contact) +{ + if (contact) + contact_destroy_info(contact); + return GNUNET_YES; +} + static void _chat_messenger_idle(void *cls) { @@ -43,6 +54,12 @@ _chat_messenger_idle(void *cls) return; } + GNUNET_CHAT_iterate_contacts( + app->chat.messenger.handle, + _chat_messenger_iterate_contacts, + NULL + ); + GNUNET_CHAT_stop(app->chat.messenger.handle); app->chat.messenger.handle = NULL; @@ -98,8 +115,12 @@ _chat_messenger_message(void *cls, } case GNUNET_CHAT_KIND_CONTACT: { - // TODO: update messages and content related to a contacts information - // (name and key) + application_call_message_event( + app, + event_update_contacts, + context, + message + ); break; } case GNUNET_CHAT_KIND_INVITATION: diff --git a/src/contact.c b/src/contact.c @@ -0,0 +1,87 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file contact.c + */ + +#include "contact.h" + +void +contact_create_info(struct GNUNET_CHAT_Contact *contact) +{ + if (GNUNET_CHAT_contact_get_user_pointer(contact)) + return; + + MESSENGER_ContactInfo* info = g_malloc(sizeof(MESSENGER_ContactInfo)); + + info->name_labels = g_list_alloc(); + + GNUNET_CHAT_contact_set_user_pointer(contact, info); +} + +void +contact_destroy_info(struct GNUNET_CHAT_Contact *contact) +{ + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); + + if (!info) + return; + + g_list_free(info->name_labels); + g_free(info); + + GNUNET_CHAT_contact_set_user_pointer(contact, NULL); +} + +void +contact_add_name_label_to_info(const struct GNUNET_CHAT_Contact *contact, + GtkLabel *label) +{ + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); + + if (!info) + return; + + info->name_labels = g_list_append(info->name_labels, label); +} + +void +contact_update_info(const struct GNUNET_CHAT_Contact *contact) +{ + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); + + if (!info) + return; + + const char *name = GNUNET_CHAT_contact_get_name(contact); + + GList* name_label = info->name_labels; + + while (name_label) + { + GtkLabel *label = GTK_LABEL(name_label->data); + + if (label) + gtk_label_set_text(label, name? name : ""); + + name_label = name_label->next; + } +} diff --git a/src/contact.h b/src/contact.h @@ -0,0 +1,48 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file contact.h + */ + +#ifndef CONTACT_H_ +#define CONTACT_H_ + +#include "application.h" + +typedef struct MESSENGER_ContactInfo +{ + GList *name_labels; +} MESSENGER_ContactInfo; + +void +contact_create_info(struct GNUNET_CHAT_Contact *contact); + +void +contact_destroy_info(struct GNUNET_CHAT_Contact *contact); + +void +contact_add_name_label_to_info(const struct GNUNET_CHAT_Contact *contact, + GtkLabel *label); + +void +contact_update_info(const struct GNUNET_CHAT_Contact *contact); + +#endif /* CONTACT_H_ */ diff --git a/src/event.c b/src/event.c @@ -24,6 +24,8 @@ #include "event.h" +#include "contact.h" + #include "ui/chat_entry.h" #include "ui/contact_entry.h" #include "ui/message.h" @@ -37,7 +39,7 @@ _add_new_chat_entry(MESSENGER_Application *app, UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app); - ui_chat_entry_update(entry, context); + ui_chat_entry_update(entry, app, context); gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); GNUNET_CHAT_context_set_user_pointer(context, entry); @@ -153,6 +155,25 @@ event_update_chats(MESSENGER_Application *app, _add_new_chat_entry(app, context); } +static void +_update_contact_context(MESSENGER_Application *app, + struct GNUNET_CHAT_Contact *contact) +{ + struct GNUNET_CHAT_Context *context = GNUNET_CHAT_contact_get_context( + contact + ); + + if (!context) + return; + + UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); + + if (!handle) + return; + + ui_chat_entry_update(handle, app, context); +} + void event_joining_contact(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, @@ -163,19 +184,24 @@ event_joining_contact(MESSENGER_Application *app, if (!handle) return; - ui_chat_entry_update(handle, context); + ui_chat_entry_update(handle, app, context); UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS); - const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( - msg + struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( + msg ); + 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_label_to_info(contact, message->sender_label); + gtk_label_set_text(message->text_label, "joined the chat"); gtk_container_add( @@ -186,6 +212,19 @@ event_joining_contact(MESSENGER_Application *app, ui_message_delete(message); } +void +event_update_contacts(UNUSED MESSENGER_Application *app, + UNUSED struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg) +{ + struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( + msg + ); + + contact_update_info(contact); + _update_contact_context(app, contact); +} + static void _event_invitation_accept_click(UNUSED GtkButton *button, gpointer user_data) diff --git a/src/event.h b/src/event.h @@ -41,6 +41,11 @@ event_joining_contact(MESSENGER_Application *app, const struct GNUNET_CHAT_Message *msg); void +event_update_contacts(MESSENGER_Application *app, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); + +void event_invitation(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg); diff --git a/src/ui/chat.c b/src/ui/chat.c @@ -27,7 +27,9 @@ #include "messenger.h" #include "picker.h" #include "profile_entry.h" + #include "../application.h" +#include "../contact.h" static void handle_flap_via_button_click(UNUSED GtkButton* button, @@ -43,6 +45,37 @@ handle_flap_via_button_click(UNUSED GtkButton* button, } static void +handle_chat_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, + GtkListBoxRow* row, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + if (!gtk_list_box_row_get_selectable(row)) + { + //g_idle_add(G_SOURCE_FUNC(_open_new_contact_dialog), app); + return; + } + + struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( + g_hash_table_lookup(app->ui.bindings, row) + ); + + if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact))) + return; + + struct GNUNET_CHAT_Context *context = GNUNET_CHAT_contact_get_context( + contact + ); + + if (!context) + return; + + if (GNUNET_SYSERR == GNUNET_CHAT_context_get_status(context)) + GNUNET_CHAT_context_request(context); +} + +static void handle_back_button_click(UNUSED GtkButton* button, gpointer user_data) { @@ -223,6 +256,13 @@ ui_chat_new(MESSENGER_Application *app) gtk_builder_get_object(handle->builder, "chat_contacts_listbox") ); + g_signal_connect( + handle->chat_contacts_listbox, + "row-activated", + G_CALLBACK(handle_chat_contacts_listbox_row_activated), + app + ); + handle->messages_listbox = GTK_LIST_BOX( gtk_builder_get_object(handle->builder, "messages_listbox") ); @@ -299,12 +339,21 @@ ui_chat_new(MESSENGER_Application *app) return handle; } +struct IterateChatGroupClosure { + GHashTable *bindings; + GtkListBox *listbox; +}; + static int iterate_ui_chat_update_group_contacts(void *cls, UNUSED const struct GNUNET_CHAT_Group *group, struct GNUNET_CHAT_Contact *contact) { - GtkListBox *listbox = GTK_LIST_BOX(cls); + struct IterateChatGroupClosure *closure = ( + (struct IterateChatGroupClosure*) cls + ); + + GtkListBox *listbox = closure->listbox; UI_PROFILE_ENTRY_Handle* entry = ui_profile_entry_new(); const char *name = GNUNET_CHAT_contact_get_name(contact); @@ -317,12 +366,19 @@ iterate_ui_chat_update_group_contacts(void *cls, gtk_list_box_prepend(listbox, entry->entry_box); + GtkListBoxRow *row = GTK_LIST_BOX_ROW( + gtk_widget_get_parent(entry->entry_box) + ); + + g_hash_table_insert(closure->bindings, row, contact); + ui_profile_entry_delete(entry); return GNUNET_YES; } void ui_chat_update(UI_CHAT_Handle *handle, + MESSENGER_Application *app, const struct GNUNET_CHAT_Context* context) { const struct GNUNET_CHAT_Contact* contact; @@ -359,11 +415,17 @@ ui_chat_update(UI_CHAT_Handle *handle, } if (group) + { + struct IterateChatGroupClosure closure; + closure.bindings = app->ui.bindings; + closure.listbox = handle->chat_contacts_listbox; + GNUNET_CHAT_group_iterate_contacts( group, iterate_ui_chat_update_group_contacts, - handle->chat_contacts_listbox + &closure ); + } gtk_widget_set_visible( GTK_WIDGET(handle->chat_details_contacts_box), diff --git a/src/ui/chat.h b/src/ui/chat.h @@ -70,6 +70,7 @@ ui_chat_new(MESSENGER_Application *app); void ui_chat_update(UI_CHAT_Handle *handle, + MESSENGER_Application *app, const struct GNUNET_CHAT_Context* context); void diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c @@ -25,6 +25,7 @@ #include "chat_entry.h" #include "../application.h" +#include "../contact.h" UI_CHAT_ENTRY_Handle* ui_chat_entry_new(MESSENGER_Application *app) @@ -63,6 +64,7 @@ ui_chat_entry_new(MESSENGER_Application *app) void ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, + MESSENGER_Application *app, const struct GNUNET_CHAT_Context *context) { const struct GNUNET_CHAT_Contact* contact; @@ -85,7 +87,7 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, } if (handle->chat) - ui_chat_update(handle->chat, context); + ui_chat_update(handle->chat, app, context); } void diff --git a/src/ui/chat_entry.h b/src/ui/chat_entry.h @@ -48,6 +48,7 @@ ui_chat_entry_new(MESSENGER_Application *app); void ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, + MESSENGER_Application *app, const struct GNUNET_CHAT_Context *context); void