messenger-gtk

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

commit 724f7738ed6d60bccabb428c2ae87faba9033b0c
parent a59f8fc86118a2cc871e1ad50140e9187ca488d9
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Mon, 22 Nov 2021 23:02:12 +0100

Added profile entries, identity selection parameter and other tweaks

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

Diffstat:
MMakefile | 1+
Mresources/css/style.css | 16++++++++++++++++
Mresources/ui/chat.ui | 20+++++++++++---------
Mresources/ui/contact_entry.ui | 11++++++++---
Mresources/ui/contacts.ui | 46++++++++++++++++++++++++++++++++++++++++++++++
Mresources/ui/messenger.ui | 139++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Aresources/ui/profile_entry.ui | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/application.c | 19++++++++++++++++++-
Msrc/application.h | 1+
Msrc/chat/messenger.c | 2+-
Msrc/event.c | 21+++++++++++++++++++++
Msrc/ui/contacts.c | 21+++++++++++++++++++--
Msrc/ui/messenger.c | 5++++-
Msrc/ui/messenger.h | 1+
Asrc/ui/profile_entry.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ui/profile_entry.h | 46++++++++++++++++++++++++++++++++++++++++++++++
16 files changed, 397 insertions(+), 71 deletions(-)

diff --git a/Makefile b/Makefile @@ -15,6 +15,7 @@ SOURCES = messenger_gtk.c\ ui/messenger.c\ ui/new_contact.c\ ui/new_platform.c\ + ui/profile_entry.c\ ui/settings.c HEADERS = diff --git a/resources/css/style.css b/resources/css/style.css @@ -3,10 +3,26 @@ background-color: @theme_bg_color; } +.header-box { + min-height: 36px; +} + +.header-subtitle { + font-size: small; +} + +.profile-key { + font-size: xx-small; +} + .profile-entry { padding: 4px 20px; } +.contact-entry { + padding: 2px; +} + .chat-entry { padding: 4px; } diff --git a/resources/ui/chat.ui b/resources/ui/chat.ui @@ -27,13 +27,10 @@ Author: Tobias Frisch <property name="can-focus">False</property> <property name="orientation">vertical</property> <child> - <object class="GtkBox" id="chat-header-box"> + <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">8</property> - <property name="margin-end">8</property> - <property name="margin-top">8</property> - <property name="margin-bottom">8</property> + <property name="border-width">8</property> <property name="spacing">8</property> <child> <object class="GtkButton" id="back_button"> @@ -88,6 +85,9 @@ Author: Tobias Frisch <attributes> <attribute name="weight" value="light"/> </attributes> + <style> + <class name="header-subtitle"/> + </style> </object> <packing> <property name="expand">True</property> @@ -123,6 +123,9 @@ Author: Tobias Frisch <property name="position">1</property> </packing> </child> + <style> + <class name=".header-box"/> + </style> </object> <packing> <property name="expand">False</property> @@ -169,10 +172,9 @@ Author: Tobias Frisch <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">8</property> - <property name="margin-end">8</property> - <property name="margin-top">4</property> - <property name="margin-bottom">4</property> + <property name="margin-start">4</property> + <property name="margin-end">4</property> + <property name="border-width">4</property> <property name="spacing">4</property> <child> <object class="GtkButton" id="attach_file_button"> diff --git a/resources/ui/contact_entry.ui b/resources/ui/contact_entry.ui @@ -54,12 +54,13 @@ Author: Tobias Frisch <property name="wrap-mode">word-char</property> <property name="ellipsize">end</property> <property name="xalign">0</property> + <property name="yalign">1</property> <attributes> <attribute name="weight" value="bold"/> </attributes> </object> <packing> - <property name="expand">False</property> + <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> </packing> @@ -76,10 +77,14 @@ Author: Tobias Frisch <attributes> <attribute name="weight" value="semilight"/> </attributes> + <style> + <class name="profile-key"/> + </style> </object> <packing> - <property name="expand">True</property> + <property name="expand">False</property> <property name="fill">True</property> + <property name="pack-type">end</property> <property name="position">1</property> </packing> </child> @@ -92,7 +97,7 @@ Author: Tobias Frisch </packing> </child> <style> - <class name="chat-entry"/> + <class name="contact-entry"/> </style> </object> </interface> diff --git a/resources/ui/contacts.ui b/resources/ui/contacts.ui @@ -85,6 +85,52 @@ Author: Tobias Frisch <object class="GtkListBox" id="contacts_listbox"> <property name="visible">True</property> <property name="can-focus">False</property> + <child> + <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> + <property name="can-focus">False</property> + <property name="spacing">8</property> + <child> + <object class="GtkImage"> + <property name="width-request">48</property> + <property name="height-request">48</property> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="icon-name">contact-new-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">Add Contact</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="pack-type">end</property> + <property name="position">1</property> + </packing> + </child> + <style> + <class name="contact-entry"/> + </style> + </object> + </child> + </object> + </child> </object> </child> </object> diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui @@ -50,13 +50,10 @@ Author: Tobias Frisch <property name="can-focus">False</property> <property name="orientation">vertical</property> <child> - <object class="GtkBox" id="chats-header-box"> + <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">8</property> - <property name="margin-end">8</property> - <property name="margin-top">8</property> - <property name="margin-bottom">8</property> + <property name="border-width">8</property> <property name="spacing">8</property> <child> <object class="GtkButton" id="user_details_button"> @@ -93,6 +90,9 @@ Author: Tobias Frisch <property name="position">1</property> </packing> </child> + <style> + <class name="header-box"/> + </style> </object> <packing> <property name="expand">False</property> @@ -146,10 +146,7 @@ Author: Tobias Frisch <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">16</property> - <property name="margin-end">16</property> - <property name="margin-top">16</property> - <property name="margin-bottom">16</property> + <property name="border-width">16</property> <property name="orientation">vertical</property> <property name="spacing">16</property> <child> @@ -166,11 +163,44 @@ Author: Tobias Frisch </packing> </child> <child> - <object class="GtkLabel" id="profile_label"> + <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="label" translatable="yes">Profile name</property> - <property name="xalign">0</property> + <property name="orientation">vertical</property> + <property name="spacing">2</property> + <child> + <object class="GtkLabel" id="profile_label"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="ellipsize">end</property> + <property name="xalign">0</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="profile_key_label"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="ellipsize">end</property> + <property name="max-width-chars">30</property> + <property name="xalign">0</property> + <style> + <class name="profile-key"/> + </style> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> </object> <packing> <property name="expand">False</property> @@ -189,10 +219,7 @@ Author: Tobias Frisch <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">8</property> - <property name="margin-end">8</property> - <property name="margin-top">8</property> - <property name="margin-bottom">8</property> + <property name="border-width">8</property> <property name="orientation">vertical</property> <property name="spacing">8</property> <property name="homogeneous">True</property> @@ -306,21 +333,24 @@ Author: Tobias Frisch <object class="GtkListBox" id="accounts_listbox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="selection-mode">none</property> <child> <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> <property name="can-focus">False</property> <property name="spacing">8</property> <child> - <object class="HdyAvatar"> + <object class="GtkImage"> + <property name="width-request">36</property> + <property name="height-request">36</property> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="size">36</property> + <property name="icon-name">list-add-symbolic</property> + <property name="icon_size">3</property> </object> <packing> <property name="expand">False</property> @@ -332,14 +362,10 @@ Author: Tobias Frisch <object class="GtkLabel"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="label" translatable="yes">Name</property> - <property name="wrap">True</property> - <property name="wrap-mode">word-char</property> - <property name="ellipsize">end</property> - <property name="xalign">0</property> + <property name="label" translatable="yes">Add Account</property> </object> <packing> - <property name="expand">True</property> + <property name="expand">False</property> <property name="fill">True</property> <property name="position">1</property> </packing> @@ -380,10 +406,7 @@ Author: Tobias Frisch <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">4</property> - <property name="margin-end">4</property> - <property name="margin-top">4</property> - <property name="margin-bottom">4</property> + <property name="border-width">4</property> <property name="spacing">16</property> <child> <object class="GtkImage"> @@ -431,10 +454,7 @@ Author: Tobias Frisch <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">4</property> - <property name="margin-end">4</property> - <property name="margin-top">4</property> - <property name="margin-bottom">4</property> + <property name="border-width">4</property> <property name="spacing">16</property> <child> <object class="GtkImage"> @@ -482,10 +502,7 @@ Author: Tobias Frisch <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">4</property> - <property name="margin-end">4</property> - <property name="margin-top">4</property> - <property name="margin-bottom">4</property> + <property name="border-width">4</property> <property name="spacing">16</property> <child> <object class="GtkImage"> @@ -533,10 +550,7 @@ Author: Tobias Frisch <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">4</property> - <property name="margin-end">4</property> - <property name="margin-top">4</property> - <property name="margin-bottom">4</property> + <property name="border-width">4</property> <property name="spacing">16</property> <child> <object class="GtkImage"> @@ -584,10 +598,7 @@ Author: Tobias Frisch <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">4</property> - <property name="margin-end">4</property> - <property name="margin-top">4</property> - <property name="margin-bottom">4</property> + <property name="border-width">4</property> <property name="spacing">16</property> <child> <object class="GtkImage"> @@ -635,10 +646,7 @@ Author: Tobias Frisch <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">16</property> - <property name="margin-end">16</property> - <property name="margin-top">16</property> - <property name="margin-bottom">16</property> + <property name="border-width">16</property> <property name="orientation">vertical</property> <child> <object class="GtkLabel"> @@ -721,7 +729,33 @@ Author: Tobias Frisch <property name="visible">True</property> <property name="can-focus">False</property> <child> - <placeholder/> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="halign">center</property> + <property name="valign">center</property> + <property name="label" translatable="yes">Select a chat to start messaging...</property> + <style> + <class name="message-box"/> + <class name="status"/> + </style> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="name">page0</property> + <property name="title" translatable="yes">page0</property> + </packing> </child> </object> </child> @@ -741,10 +775,7 @@ Author: Tobias Frisch <property name="width-request">250</property> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-start">8</property> - <property name="margin-end">8</property> - <property name="margin-top">8</property> - <property name="margin-bottom">8</property> + <property name="border-width">8</property> <child> <object class="GtkStack"> <property name="visible">True</property> diff --git a/resources/ui/profile_entry.ui b/resources/ui/profile_entry.ui @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.38.2 + +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 + +--> +<interface> + <requires lib="gtk+" version="3.24"/> + <requires lib="libhandy" version="1.2"/> + <object class="GtkBox" id="entry_box"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="spacing">8</property> + <child> + <object class="HdyAvatar" id="entry_avatar"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="size">36</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="entry_label"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="wrap">True</property> + <property name="wrap-mode">word-char</property> + <property name="ellipsize">end</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="pack-type">end</property> + <property name="position">1</property> + </packing> + </child> + <style> + <class name="profile-entry"/> + </style> + </object> +</interface> diff --git a/src/application.c b/src/application.c @@ -91,6 +91,16 @@ application_init(MESSENGER_Application *app, NULL ); + g_application_add_main_option( + G_APPLICATION(app->application), + "ego", + 'e', + G_OPTION_FLAG_NONE, + G_OPTION_ARG_STRING, + "Identity to select for messaging", + "IDENTITY" + ); + g_signal_connect( app->application, "activate", @@ -111,6 +121,13 @@ _application_chat_thread(void *args) "Optimize UI spacing for mobile devices", &(app->ui.mobile) ), + GNUNET_GETOPT_option_string ( + 'e', + "ego", + "IDENTITY", + "Identity to select for messaging", + &(app->chat.identity) + ), GNUNET_GETOPT_OPTION_END }; @@ -198,7 +215,7 @@ application_call_event(MESSENGER_Application *app, } } - g_idle_add(_application_event_call, call); + g_idle_add(G_SOURCE_FUNC(_application_event_call), call); } void diff --git a/src/application.h b/src/application.h @@ -54,6 +54,7 @@ typedef struct MESSENGER_Application struct { int status; pthread_t tid; + char *identity; MESSENGER_ApplicationSignal signal; diff --git a/src/chat/messenger.c b/src/chat/messenger.c @@ -119,7 +119,7 @@ chat_messenger_run(void *cls, app->chat.messenger.handle = GNUNET_CHAT_start( cfg, "messenger-gtk", - "test", + app->chat.identity, &_chat_messenger_message, app ); diff --git a/src/event.c b/src/event.c @@ -27,6 +27,7 @@ #include "ui/chat_entry.h" #include "ui/contact_entry.h" #include "ui/message.h" +#include "ui/profile_entry.h" static void _add_new_chat_entry(MESSENGER_Application *app, @@ -129,8 +130,28 @@ event_update_profile(MESSENGER_Application *app, { hdy_avatar_set_text(ui->profile_avatar, name); gtk_label_set_text(ui->profile_label, name); + + UI_PROFILE_ENTRY_Handle *profile = ui_profile_entry_new(); + + hdy_avatar_set_text(profile->entry_avatar, name); + gtk_label_set_text(profile->entry_label, name); + + gtk_list_box_prepend(ui->accounts_listbox, profile->entry_box); + + GtkListBoxRow *row = GTK_LIST_BOX_ROW( + gtk_widget_get_parent(profile->entry_box) + ); + + gtk_list_box_select_row(ui->accounts_listbox, row); + + ui_profile_entry_delete(profile); } + const char *key = GNUNET_CHAT_get_key(chat->handle); + + if (key) + gtk_label_set_text(ui->profile_key_label, key); + gtk_container_foreach( GTK_CONTAINER(ui->chats_listbox), _clear_each_widget, diff --git a/src/ui/contacts.c b/src/ui/contacts.c @@ -36,6 +36,17 @@ handle_close_button_click(UNUSED GtkButton *button, gtk_window_close(GTK_WINDOW(dialog)); } +static gboolean +_open_new_contact_dialog(gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + ui_new_contact_dialog_init(app, &(app->ui.new_contact)); + + gtk_widget_show(GTK_WIDGET(app->ui.new_contact.dialog)); + return FALSE; +} + static void handle_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, GtkListBoxRow* row, @@ -43,6 +54,12 @@ handle_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, { 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); + goto close_dialog; + } + struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( g_hash_table_lookup(app->ui.bindings, row) ); @@ -135,8 +152,8 @@ _iterate_contacts(void *cls, const char *key = GNUNET_CHAT_contact_get_key(contact); UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(); - gtk_container_add( - GTK_CONTAINER(app->ui.contacts.contacts_listbox), + gtk_list_box_prepend( + app->ui.contacts.contacts_listbox, entry->entry_box ); diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -60,7 +60,6 @@ handle_account_details_button_click(UNUSED GtkButton* button, gboolean old_state = gtk_revealer_get_reveal_child(revealer); gtk_revealer_set_reveal_child(revealer, !old_state); - gtk_image_set_from_icon_name( symbol, old_state? @@ -218,6 +217,10 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "profile_label") ); + handle->profile_key_label = GTK_LABEL( + gtk_builder_get_object(handle->builder, "profile_key_label") + ); + handle->hide_user_details_button = GTK_BUTTON( gtk_builder_get_object(handle->builder, "hide_user_details_button") ); diff --git a/src/ui/messenger.h b/src/ui/messenger.h @@ -46,6 +46,7 @@ typedef struct UI_MESSENGER_Handle HdyAvatar *profile_avatar; GtkLabel *profile_label; + GtkLabel *profile_key_label; GtkButton *hide_user_details_button; GtkButton *favourites_button; diff --git a/src/ui/profile_entry.c b/src/ui/profile_entry.c @@ -0,0 +1,57 @@ +/* + 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 ui/profile_entry.c + */ + +#include "profile_entry.h" + +#include "../application.h" + +UI_PROFILE_ENTRY_Handle* +ui_profile_entry_new(void) +{ + UI_PROFILE_ENTRY_Handle* handle = g_malloc(sizeof(UI_PROFILE_ENTRY_Handle)); + + handle->builder = gtk_builder_new_from_file("resources/ui/profile_entry.ui"); + + handle->entry_box = GTK_WIDGET( + gtk_builder_get_object(handle->builder, "entry_box") + ); + + handle->entry_avatar = HDY_AVATAR( + gtk_builder_get_object(handle->builder, "entry_avatar") + ); + + handle->entry_label = GTK_LABEL( + gtk_builder_get_object(handle->builder, "entry_label") + ); + + return handle; +} + +void +ui_profile_entry_delete(UI_PROFILE_ENTRY_Handle *handle) +{ + g_object_unref(handle->builder); + + g_free(handle); +} diff --git a/src/ui/profile_entry.h b/src/ui/profile_entry.h @@ -0,0 +1,46 @@ +/* + 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 ui/profile_entry.h + */ + +#ifndef UI_PROFILE_ENTRY_H_ +#define UI_PROFILE_ENTRY_H_ + +#include "messenger.h" + +typedef struct UI_PROFILE_ENTRY_Handle +{ + GtkBuilder *builder; + + GtkWidget *entry_box; + + HdyAvatar *entry_avatar; + GtkLabel *entry_label; +} UI_PROFILE_ENTRY_Handle; + +UI_PROFILE_ENTRY_Handle* +ui_profile_entry_new(void); + +void +ui_profile_entry_delete(UI_PROFILE_ENTRY_Handle *handle); + +#endif /* UI_PROFILE_ENTRY_H_ */