From cbefefb69b4db53fad2c01d45b66d9056bc98fdb Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Sun, 12 Dec 2021 22:31:42 +0100 Subject: Added chat details with a list of contacts for groups Signed-off-by: TheJackiMonster --- resources/css/style.css | 12 +- resources/ui/chat.ui | 644 ++++++++++++++++++++++++++++++++-------------- resources/ui/messenger.ui | 151 ++--------- src/event.c | 27 +- src/ui/chat.c | 113 +++++++- src/ui/chat.h | 12 +- src/ui/chat_entry.c | 25 +- src/ui/chat_entry.h | 3 +- src/ui/messenger.c | 15 -- src/ui/messenger.h | 3 - 10 files changed, 618 insertions(+), 387 deletions(-) diff --git a/resources/css/style.css b/resources/css/style.css index 1f923d6..afda9fe 100644 --- a/resources/css/style.css +++ b/resources/css/style.css @@ -69,7 +69,17 @@ font-size: large; } -.settings-entry { +.settings-entry, .details-entry { margin: 8px; } +.details-group { + margin-top: 16px; +} + +.details-group-title { + margin-left: 8px; + margin-right: 8px; + margin-bottom: 4px; +} + diff --git a/resources/ui/chat.ui b/resources/ui/chat.ui index ca93f9d..9b89023 100644 --- a/resources/ui/chat.ui +++ b/resources/ui/chat.ui @@ -22,53 +22,121 @@ Author: Tobias Frisch --> + True False vertical - + True False - 8 - 8 - - - True - True - True - none - - - True - False - go-previous-symbolic - - - - - False - True - 0 - - + end + False + always True False - start - 4 - 4 vertical - + True False - Chat title - 0 - - - + 8 + 8 + + + True + True + True + none + + + True + False + go-previous-symbolic + + + + + False + True + 0 + + + + + True + False + start + 4 + 4 + vertical + + + True + False + 0 + + + + + + False + True + 0 + + + + + True + False + 0 + + + + + + + True + True + 1 + + + + + True + True + 1 + + + + + True + True + True + none + + + True + False + view-more-symbolic + + + + + False + True + end + 1 + + + False @@ -77,17 +145,33 @@ Author: Tobias Frisch - + True - False - Chat subtitle - 0 - - - - + True + + + True + False + + + True + False + + + True + False + none + False + + + page0 + page0 + + + + + + True @@ -95,197 +179,363 @@ Author: Tobias Frisch 1 - - - True - True - 1 - - - - - True - True - True - none - + True False - view-more-symbolic + slide-up + + + + + False + True + end + 2 + - - - False - True - end - 1 - - - - - - False - True - 0 - - - - - True - True - - - True - False - + True False + 4 + 4 + 4 + 4 - + True - False - none - False + False + True + True + center + none + + + True + False + mail-attachment-symbolic + + - page0 - page0 + False + True + 0 + + + + + 210 + 48 + True + False + True + end + False + word-char + 8 + 8 + 8 + 8 + GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_WORD_COMPLETION | GTK_INPUT_HINT_INHIBIT_OSK | GTK_INPUT_HINT_EMOJI | GTK_INPUT_HINT_NONE + + + True + True + 1 + + + + + True + False + True + True + center + none + + + True + False + face-smile-symbolic + + + + + False + True + 2 + + + + + True + False + True + True + center + none + + + True + False + audio-input-microphone-symbolic + + + + + False + True + 3 + + False + True + end + 3 + - - - True - True - 1 - - - - - True - False - slide-up - - - - - - False - True - end - 2 - - - - - True - False - 4 - 4 - 4 - 4 - - - True - False - True - True - center - none - - - True - False - mail-attachment-symbolic - - - - - False - True - 0 - - - - - 210 - 48 + + True - False - True - end - False - word-char - 8 - 8 - 8 - 8 - GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_WORD_COMPLETION | GTK_INPUT_HINT_INHIBIT_OSK | GTK_INPUT_HINT_EMOJI | GTK_INPUT_HINT_NONE + False - - True - True - 1 - - - + + True - False - True - True - center - none + False + vertical - + + 250 True False - face-smile-symbolic + 8 + + + True + False + 8 + + + True + False + 8 + 0 + + + + + + True + True + 0 + + + + + True + True + True + none + + + True + False + window-close-symbolic + + + + + False + True + end + 1 + + + + + True + True + 0 + + + + False + True + 0 + - - - False - True - 2 - - - - - True - False - True - True - center - none - + True - False - audio-input-microphone-symbolic + True + + + True + False + none + + + True + False + vertical + + + True + False + + + True + False + Notifications + + + False + True + 0 + + + + + True + True + + + False + True + end + 1 + + + + + + False + True + 0 + + + + + True + False + vertical + + + True + False + Contacts + 0 + + + + + + + False + True + 0 + + + + + True + False + none + + + True + True + + + True + False + 8 + + + 36 + 36 + True + False + list-add-symbolic + 3 + + + False + True + 0 + + + + + True + False + Invite Contact + + + False + True + 1 + + + + + + + + + + False + True + 1 + + + + + + False + True + 1 + + + + + + + + True + True + 1 + + - - False - True - 3 - - False + True True - end - 3 + 1 diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui index e917f98..d79f875 100644 --- a/resources/ui/messenger.ui +++ b/resources/ui/messenger.ui @@ -718,164 +718,43 @@ Author: Tobias Frisch True vertical - + True False - end - False - always - - True - False - - - True - False - vertical - - - True - False - center - center - Select a chat to start messaging... - - - - True - True - 0 - - - - - page0 - page0 - - - - - - - True - False - - - True False vertical - - 250 + True False - 8 - - - True - False - - - True - False - 8 - - - True - False - 8 - Chat Details - 0 - - - True - True - 0 - - - - - True - True - True - none - - - True - False - window-close-symbolic - - - - - False - True - end - 1 - - - - - page0 - page0 - - - - - True - True - 0 - - - - - False - True - 0 - - - - - True - True - - - True - False - - - True - False - - - - - - - + center + center + Select a chat to start messaging... + True True - 1 + 0 - + + page0 + page0 + True True - 3 + 0 diff --git a/src/event.c b/src/event.c index a1cb4fc..f63598d 100644 --- a/src/event.c +++ b/src/event.c @@ -35,31 +35,13 @@ _add_new_chat_entry(MESSENGER_Application *app, { UI_MESSENGER_Handle *ui = &(app->ui.messenger); - const struct GNUNET_CHAT_Contact* contact; - const struct GNUNET_CHAT_Group* group; - - contact = GNUNET_CHAT_context_get_contact(context); - group = GNUNET_CHAT_context_get_group(context); - - const char *title = NULL; + UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app); - if (contact) - title = GNUNET_CHAT_contact_get_name(contact); - else if (group) - title = GNUNET_CHAT_group_get_name(group); + ui_chat_entry_update(entry, context); - UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app); gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); GNUNET_CHAT_context_set_user_pointer(context, entry); - if (title) - { - gtk_label_set_text(entry->title_label, title); - hdy_avatar_set_text(entry->entry_avatar, title); - - gtk_label_set_text(entry->chat->chat_title, title); - } - char context_id [9]; g_snprintf(context_id, sizeof(context_id), "%08lx", (gulong) context); @@ -181,10 +163,7 @@ event_joining_contact(MESSENGER_Application *app, if (!handle) return; - int status = GNUNET_CHAT_context_get_status(context); - - if (GNUNET_OK == status) - ui_chat_entry_activate(handle); + ui_chat_entry_update(handle, context); UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS); diff --git a/src/ui/chat.c b/src/ui/chat.c index 73e014c..0ddd59c 100644 --- a/src/ui/chat.c +++ b/src/ui/chat.c @@ -26,6 +26,7 @@ #include "messenger.h" #include "picker.h" +#include "profile_entry.h" #include "../application.h" static void @@ -176,6 +177,10 @@ ui_chat_new(MESSENGER_Application *app) messenger->leaflet_chat ); + handle->flap_chat_details = HDY_FLAP( + gtk_builder_get_object(handle->builder, "flap_chat_details") + ); + handle->chat_title = GTK_LABEL( gtk_builder_get_object(handle->builder, "chat_title") ); @@ -192,7 +197,30 @@ ui_chat_new(MESSENGER_Application *app) handle->chat_details_button, "clicked", G_CALLBACK(handle_flap_via_button_click), - messenger->flap_chat_details + handle->flap_chat_details + ); + + handle->chat_details_label = GTK_LABEL( + gtk_builder_get_object(handle->builder, "chat_details_label") + ); + + handle->hide_chat_details_button = GTK_BUTTON( + gtk_builder_get_object(handle->builder, "hide_chat_details_button") + ); + + g_signal_connect( + handle->hide_chat_details_button, + "clicked", + G_CALLBACK(handle_flap_via_button_click), + handle->flap_chat_details + ); + + handle->chat_details_contacts_box = GTK_BOX( + gtk_builder_get_object(handle->builder, "chat_details_contacts_box") + ); + + handle->chat_contacts_listbox = GTK_LIST_BOX( + gtk_builder_get_object(handle->builder, "chat_contacts_listbox") ); handle->messages_listbox = GTK_LIST_BOX( @@ -271,15 +299,86 @@ ui_chat_new(MESSENGER_Application *app) return handle; } +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); + UI_PROFILE_ENTRY_Handle* entry = ui_profile_entry_new(); + + 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_list_box_prepend(listbox, entry->entry_box); + + ui_profile_entry_delete(entry); + return GNUNET_YES; +} + void -ui_chat_activate(UI_CHAT_Handle *handle) +ui_chat_update(UI_CHAT_Handle *handle, + const struct GNUNET_CHAT_Context* context) { - gtk_text_view_set_editable(handle->send_text_view, TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(handle->send_text_view), TRUE); + const struct GNUNET_CHAT_Contact* contact; + const struct GNUNET_CHAT_Group* group; + + contact = GNUNET_CHAT_context_get_contact(context); + group = GNUNET_CHAT_context_get_group(context); + + const char *title = NULL; + + if (contact) + title = GNUNET_CHAT_contact_get_name(contact); + else if (group) + title = GNUNET_CHAT_group_get_name(group); + + if (title) + { + gtk_label_set_text(handle->chat_title, title); + gtk_label_set_text(handle->chat_details_label, title); + } + + GList* children = gtk_container_get_children( + GTK_CONTAINER(handle->chat_contacts_listbox) + ); + + while ((children) && (children->next)) { + GtkWidget *widget = GTK_WIDGET(children->data); + children = children->next; + + gtk_container_remove( + GTK_CONTAINER(handle->chat_contacts_listbox), + widget + ); + } + + if (group) + GNUNET_CHAT_group_iterate_contacts( + group, + iterate_ui_chat_update_group_contacts, + handle->chat_contacts_listbox + ); + + gtk_widget_set_visible( + GTK_WIDGET(handle->chat_details_contacts_box), + group? TRUE : FALSE + ); + + const int status = GNUNET_CHAT_context_get_status(context); + const gboolean activated = (GNUNET_OK == status? TRUE : FALSE); + + gtk_text_view_set_editable(handle->send_text_view, activated); + gtk_widget_set_sensitive(GTK_WIDGET(handle->send_text_view), activated); - gtk_widget_set_sensitive(GTK_WIDGET(handle->attach_file_button), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(handle->emoji_button), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(handle->send_record_button), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(handle->attach_file_button), activated); + gtk_widget_set_sensitive(GTK_WIDGET(handle->emoji_button), activated); + gtk_widget_set_sensitive(GTK_WIDGET(handle->send_record_button), activated); } void diff --git a/src/ui/chat.h b/src/ui/chat.h index 68b2eb3..ce1df94 100644 --- a/src/ui/chat.h +++ b/src/ui/chat.h @@ -29,6 +29,8 @@ #include #include +#include + typedef struct MESSENGER_Application MESSENGER_Application; typedef struct UI_PICKER_Handle UI_PICKER_Handle; @@ -39,10 +41,17 @@ typedef struct UI_CHAT_Handle GtkButton *back_button; + HdyFlap *flap_chat_details; + GtkLabel *chat_title; GtkLabel *chat_subtitle; GtkButton *chat_details_button; + GtkLabel *chat_details_label; + GtkButton *hide_chat_details_button; + GtkBox *chat_details_contacts_box; + + GtkListBox *chat_contacts_listbox; GtkListBox *messages_listbox; GtkButton *attach_file_button; @@ -60,7 +69,8 @@ UI_CHAT_Handle* ui_chat_new(MESSENGER_Application *app); void -ui_chat_activate(UI_CHAT_Handle *handle); +ui_chat_update(UI_CHAT_Handle *handle, + const struct GNUNET_CHAT_Context* context); void ui_chat_delete(UI_CHAT_Handle *handle); diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c index 33d969c..c7f07ff 100644 --- a/src/ui/chat_entry.c +++ b/src/ui/chat_entry.c @@ -62,9 +62,30 @@ ui_chat_entry_new(MESSENGER_Application *app) } void -ui_chat_entry_activate(UI_CHAT_ENTRY_Handle *handle) +ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, + const struct GNUNET_CHAT_Context *context) { - ui_chat_activate(handle->chat); + const struct GNUNET_CHAT_Contact* contact; + const struct GNUNET_CHAT_Group* group; + + contact = GNUNET_CHAT_context_get_contact(context); + group = GNUNET_CHAT_context_get_group(context); + + const char *title = NULL; + + if (contact) + title = GNUNET_CHAT_contact_get_name(contact); + else if (group) + title = GNUNET_CHAT_group_get_name(group); + + if (title) + { + gtk_label_set_text(handle->title_label, title); + hdy_avatar_set_text(handle->entry_avatar, title); + } + + if (handle->chat) + ui_chat_update(handle->chat, context); } void diff --git a/src/ui/chat_entry.h b/src/ui/chat_entry.h index 743429a..82b431a 100644 --- a/src/ui/chat_entry.h +++ b/src/ui/chat_entry.h @@ -47,7 +47,8 @@ UI_CHAT_ENTRY_Handle* ui_chat_entry_new(MESSENGER_Application *app); void -ui_chat_entry_activate(UI_CHAT_ENTRY_Handle *handle); +ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, + const struct GNUNET_CHAT_Context *context); void ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle); diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 17b30a5..1d09608 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c @@ -218,10 +218,6 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "flap_user_details") ); - handle->flap_chat_details = HDY_FLAP( - gtk_builder_get_object(handle->builder, "flap_chat_details") - ); - handle->title_bar = HDY_HEADER_BAR( gtk_builder_get_object(handle->builder, "title_bar") ); @@ -390,17 +386,6 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "chats_stack") ); - handle->hide_chat_details_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "hide_chat_details_button") - ); - - g_signal_connect( - handle->hide_chat_details_button, - "clicked", - G_CALLBACK(handle_flap_via_button_click), - handle->flap_chat_details - ); - gtk_widget_show(GTK_WIDGET(handle->main_window)); g_signal_connect( diff --git a/src/ui/messenger.h b/src/ui/messenger.h index da2155e..44deb3c 100644 --- a/src/ui/messenger.h +++ b/src/ui/messenger.h @@ -40,7 +40,6 @@ typedef struct UI_MESSENGER_Handle HdyLeaflet *leaflet_chat; HdyFlap *flap_user_details; - HdyFlap *flap_chat_details; HdyHeaderBar *title_bar; @@ -68,8 +67,6 @@ typedef struct UI_MESSENGER_Handle GtkListBox *chats_listbox; GtkStack *chats_stack; - - GtkButton *hide_chat_details_button; } UI_MESSENGER_Handle; void -- cgit v1.2.3