messenger-gtk

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

commit 275ac387f9248f2095297cec465fc2c0c90da2d8
parent 5e1a9a66817f14e2d39962b3ebcee7752925aa95
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Tue, 15 Mar 2022 19:19:30 +0100

Added button to leave the chat

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

Diffstat:
Mresources/ui/chat.ui | 211+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Msrc/event.c | 35+++++------------------------------
Msrc/ui/chat.c | 112++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/ui/chat.h | 10+++++++++-
Msrc/ui/chat_entry.c | 36++++++++++++++++++++++++++++++++----
Msrc/ui/chat_entry.h | 6+++++-
6 files changed, 330 insertions(+), 80 deletions(-)

diff --git a/resources/ui/chat.ui b/resources/ui/chat.ui @@ -607,6 +607,170 @@ Author: Tobias Frisch <property name="visible">True</property> <property name="can-focus">False</property> <property name="orientation">vertical</property> + <property name="spacing">4</property> + <child> + <object class="HdyAvatar" id="chat_details_avatar"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="margin-top">8</property> + <property name="margin-bottom">8</property> + <property name="size">128</property> + </object> + <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> + <property name="orientation">vertical</property> + <child> + <object class="GtkButton" id="reveal_identity_button"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="receives-default">True</property> + <property name="relief">none</property> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="border-width">4</property> + <property name="spacing">16</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="icon-name">user-info-symbolic</property> + <property name="icon_size">3</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes">Reveal Identity</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="leave_chat_button"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="receives-default">True</property> + <property name="relief">none</property> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="border-width">4</property> + <property name="spacing">16</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="icon-name">system-log-out-symbolic</property> + <property name="icon_size">3</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes">Leave Chat</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + <style> + <class name="delete-button"/> + </style> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <style> + <class name="details-group"/> + </style> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</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" id="chat_notifications_switch"> + <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">2</property> + </packing> + </child> <child> <object class="GtkBox" id="chat_details_contacts_box"> <property name="visible">True</property> @@ -694,50 +858,11 @@ 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> + <property name="position">3</property> </packing> </child> <child> - <object class="GtkBox"> - <property name="visible">True</property> + <object class="GtkBox" id="chat_details_files_box"> <property name="can-focus">False</property> <property name="orientation">vertical</property> <child> @@ -776,9 +901,9 @@ Author: Tobias Frisch </style> </object> <packing> - <property name="expand">False</property> + <property name="expand">True</property> <property name="fill">True</property> - <property name="position">2</property> + <property name="position">5</property> </packing> </child> </object> diff --git a/src/event.c b/src/event.c @@ -284,8 +284,6 @@ _clear_chat_entry(GtkWidget *widget, gpointer user_data) { MESSENGER_Application *app = (MESSENGER_Application*) user_data; - - UI_MESSENGER_Handle *ui = &(app->ui.messenger); GtkListBoxRow *row = GTK_LIST_BOX_ROW(widget); if (!gtk_list_box_row_get_selectable(row)) @@ -296,29 +294,7 @@ _clear_chat_entry(GtkWidget *widget, app->quarks.ui ); - ui->chat_entries = g_list_remove(ui->chat_entries, entry); - - gtk_container_remove( - GTK_CONTAINER(ui->chats_listbox), - widget - ); - - struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( - g_object_get_qdata( - G_OBJECT(entry->chat->send_text_view), - app->quarks.data - ) - ); - - if (context) - GNUNET_CHAT_context_set_user_pointer(context, NULL); - - gtk_container_remove( - GTK_CONTAINER(ui->chats_stack), - entry->chat->chat_box - ); - - ui_chat_entry_delete(entry); + ui_chat_entry_dispose(entry, app); } void @@ -375,8 +351,7 @@ event_update_chats(MESSENGER_Application *app, } static void -_update_contact_context(MESSENGER_Application *app, - struct GNUNET_CHAT_Contact *contact) +_update_contact_context(struct GNUNET_CHAT_Contact *contact) { struct GNUNET_CHAT_Context *context = GNUNET_CHAT_contact_get_context( contact @@ -425,7 +400,7 @@ event_presence_contact(MESSENGER_Application *app, ui_message_update(message, app, msg); contact_create_info(contact); - _update_contact_context(app, contact); + _update_contact_context(contact); contact_add_name_avatar_to_info(contact, message->sender_avatar); contact_add_name_label_to_info(contact, message->sender_label); @@ -461,7 +436,7 @@ event_presence_contact(MESSENGER_Application *app, } void -event_update_contacts(MESSENGER_Application *app, +event_update_contacts(UNUSED MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { @@ -473,7 +448,7 @@ event_update_contacts(MESSENGER_Application *app, return; contact_update_info(contact); - _update_contact_context(app, contact); + _update_contact_context(contact); UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); diff --git a/src/ui/chat.c b/src/ui/chat.c @@ -27,6 +27,7 @@ #include <gdk/gdkkeysyms.h> #include <stdlib.h> +#include "chat_entry.h" #include "file_load_entry.h" #include "message.h" #include "messenger.h" @@ -154,6 +155,55 @@ handle_back_button_click(UNUSED GtkButton *button, } } +static void +handle_reveal_identity_button_click(UNUSED GtkButton *button, + gpointer user_data) +{ + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; + + // TODO +} + +static void +handle_leave_chat_button_click(UNUSED GtkButton *button, + gpointer user_data) +{ + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; + + if ((!handle) || (!(handle->send_text_view))) + return; + + struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( + g_object_get_qdata( + G_OBJECT(handle->send_text_view), + handle->app->quarks.data + ) + ); + + if (!context) + return; + + struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_context_get_contact( + context + ); + + struct GNUNET_CHAT_Group *group = GNUNET_CHAT_context_get_group( + context + ); + + if (contact) + GNUNET_CHAT_contact_delete(contact); + else if (group) + GNUNET_CHAT_group_leave(group); + + UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(context); + + if ((!entry) || (!(handle->app))) + return; + + ui_chat_entry_dispose(entry, handle->app); +} + static gint handle_chat_messages_sort(GtkListBoxRow* row0, GtkListBoxRow* row1, @@ -1089,6 +1139,40 @@ ui_chat_new(MESSENGER_Application *app) gtk_builder_get_object(handle->builder, "chat_details_contacts_box") ); + handle->chat_details_files_box = GTK_BOX( + gtk_builder_get_object(handle->builder, "chat_details_files_box") + ); + + handle->chat_details_avatar = HDY_AVATAR( + gtk_builder_get_object(handle->builder, "chat_details_avatar") + ); + + handle->reveal_identity_button = GTK_BUTTON( + gtk_builder_get_object(handle->builder, "reveal_identity_button") + ); + + g_signal_connect( + handle->reveal_identity_button, + "clicked", + G_CALLBACK(handle_reveal_identity_button_click), + handle + ); + + handle->leave_chat_button = GTK_BUTTON( + gtk_builder_get_object(handle->builder, "leave_chat_button") + ); + + g_signal_connect( + handle->leave_chat_button, + "clicked", + G_CALLBACK(handle_leave_chat_button_click), + handle + ); + + handle->chat_notifications_switch = GTK_SWITCH( + gtk_builder_get_object(handle->builder, "chat_notifications_switch") + ); + handle->selection_close_button = GTK_BUTTON( gtk_builder_get_object(handle->builder, "selection_close_button") ); @@ -1355,7 +1439,7 @@ iterate_ui_chat_update_group_contacts(void *cls, void ui_chat_update(UI_CHAT_Handle *handle, MESSENGER_Application *app, - const struct GNUNET_CHAT_Context* context) + struct GNUNET_CHAT_Context* context) { GNUNET_assert((handle) && (app) && (context)); @@ -1366,14 +1450,24 @@ ui_chat_update(UI_CHAT_Handle *handle, group = GNUNET_CHAT_context_get_group(context); const char *title = NULL; + const char *icon = "action-unavailable-symbolic"; + GString *subtitle = g_string_new(""); if (contact) + { title = GNUNET_CHAT_contact_get_name(contact); + icon = "avatar-default-symbolic"; + } else if (group) { title = GNUNET_CHAT_group_get_name(group); + if ((title) && ('#' == *title)) + icon = "network-wired-symbolic"; + else + icon = "system-users-symbolic"; + g_string_append_printf( subtitle, _("%d members"), @@ -1381,6 +1475,12 @@ ui_chat_update(UI_CHAT_Handle *handle, ); } + hdy_avatar_set_text(handle->chat_avatar, title? title : ""); + hdy_avatar_set_icon_name(handle->chat_avatar, icon); + + hdy_avatar_set_text(handle->chat_details_avatar, title? title : ""); + hdy_avatar_set_icon_name(handle->chat_details_avatar, icon); + if (title) { gtk_label_set_text(handle->chat_title, title); @@ -1424,6 +1524,16 @@ ui_chat_update(UI_CHAT_Handle *handle, group? TRUE : FALSE ); + gtk_widget_set_visible( + GTK_WIDGET(handle->reveal_identity_button), + contact? TRUE : FALSE + ); + + gtk_widget_set_sensitive( + GTK_WIDGET(handle->leave_chat_button), + (contact) || (group)? TRUE : FALSE + ); + const int status = GNUNET_CHAT_context_get_status(context); const gboolean activated = (GNUNET_OK == status? TRUE : FALSE); diff --git a/src/ui/chat.h b/src/ui/chat.h @@ -90,6 +90,14 @@ typedef struct UI_CHAT_Handle GtkLabel *chat_details_label; GtkButton *hide_chat_details_button; GtkBox *chat_details_contacts_box; + GtkBox *chat_details_files_box; + + HdyAvatar *chat_details_avatar; + + GtkButton *reveal_identity_button; + GtkButton *leave_chat_button; + + GtkSwitch *chat_notifications_switch; GtkButton *selection_close_button; GtkLabel *selection_count_label; @@ -128,7 +136,7 @@ ui_chat_new(MESSENGER_Application *app); void ui_chat_update(UI_CHAT_Handle *handle, MESSENGER_Application *app, - const struct GNUNET_CHAT_Context* context); + 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 @@ -71,7 +71,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) + struct GNUNET_CHAT_Context *context) { const struct GNUNET_CHAT_Contact* contact; const struct GNUNET_CHAT_Group* group; @@ -107,9 +107,6 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, ui_chat_update(handle->chat, app, context); - hdy_avatar_set_text(handle->chat->chat_avatar, title? title : ""); - hdy_avatar_set_icon_name(handle->chat->chat_avatar, icon); - if (!(handle->chat->messages)) return; @@ -160,3 +157,34 @@ ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle) g_free(handle); } + +void +ui_chat_entry_dispose(UI_CHAT_ENTRY_Handle *handle, + MESSENGER_Application *app) +{ + UI_MESSENGER_Handle *ui = &(app->ui.messenger); + + ui->chat_entries = g_list_remove(ui->chat_entries, handle); + + gtk_container_remove( + GTK_CONTAINER(ui->chats_listbox), + gtk_widget_get_parent(handle->entry_box) + ); + + struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( + g_object_get_qdata( + G_OBJECT(handle->chat->send_text_view), + app->quarks.data + ) + ); + + if (context) + GNUNET_CHAT_context_set_user_pointer(context, NULL); + + gtk_container_remove( + GTK_CONTAINER(ui->chats_stack), + handle->chat->chat_box + ); + + ui_chat_entry_delete(handle); +} diff --git a/src/ui/chat_entry.h b/src/ui/chat_entry.h @@ -51,9 +51,13 @@ 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); + struct GNUNET_CHAT_Context *context); void ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle); +void +ui_chat_entry_dispose(UI_CHAT_ENTRY_Handle *handle, + MESSENGER_Application *app); + #endif /* UI_CHAT_ENTRY_H_ */