messenger-gtk

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

commit bcafd9825e1c676675ea21797b5c4cda57945ddf
parent 1e86c50e857ce0e6c28236652417206353e70b08
Author: Jacki <jacki@thejackimonster.de>
Date:   Mon, 15 Apr 2024 03:07:20 +0200

Implement input form to add attributes to account

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Mresources/ui/contact_info.ui | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/event.c | 2--
Msrc/ui/contact_info.c | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/ui/contact_info.h | 4++++
4 files changed, 219 insertions(+), 2 deletions(-)

diff --git a/resources/ui/contact_info.ui b/resources/ui/contact_info.ui @@ -565,6 +565,95 @@ Author: Tobias Frisch <property name="position">1</property> </packing> </child> + <child> + <object class="GtkBox" id="new_attribute_box"> + <property name="width-request">250</property> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="halign">center</property> + <property name="margin-top">8</property> + <property name="orientation">vertical</property> + <property name="spacing">4</property> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes">New Attribute:</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="attribute_name_entry"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="placeholder-text" translatable="yes">Name</property> + <property name="input-purpose">name</property> + </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> + <property name="spacing">4</property> + <child> + <object class="GtkEntry" id="attribute_value_entry"> + <property name="visible">True</property> + <property name="sensitive">False</property> + <property name="can-focus">True</property> + <property name="placeholder-text" translatable="yes">Value</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="add_attribute_button"> + <property name="visible">True</property> + <property name="sensitive">False</property> + <property name="can-focus">True</property> + <property name="receives-default">True</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="icon-name">list-add-symbolic</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack-type">end</property> + <property name="position">2</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack-type">end</property> + <property name="position">3</property> + </packing> + </child> </object> <packing> <property name="name">attributes_page</property> diff --git a/src/event.c b/src/event.c @@ -374,8 +374,6 @@ _cleanup_profile_contacts(void *cls, UNUSED struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Contact *contact) { - g_assert((cls) && (contact)); - if (contact) contact_destroy_info(contact); return GNUNET_YES; diff --git a/src/ui/contact_info.c b/src/ui/contact_info.c @@ -470,6 +470,66 @@ handle_value_renderer_edit(GtkCellRendererText *renderer, g_value_unset(&value); } +static void +handle_attribute_entry_changed(GtkEditable *editable, + gpointer user_data) +{ + g_assert((editable) && (user_data)); + + GtkEntry *entry = GTK_ENTRY(editable); + GtkWidget *target = GTK_WIDGET(user_data); + + const gchar *text = gtk_entry_get_text(entry); + + gtk_widget_set_sensitive(target, (text) && (strlen(text))); +} + +static void +handle_add_attribute_button_click(UNUSED GtkButton *button, + gpointer user_data) +{ + g_assert(user_data); + + UI_CONTACT_INFO_Handle *handle = (UI_CONTACT_INFO_Handle*) user_data; + + struct GNUNET_CHAT_Handle *chat = handle->app->chat.messenger.handle; + + if (!chat) + return; + + const gchar *name = gtk_entry_get_text(handle->attribute_name_entry); + const gchar *value = gtk_entry_get_text(handle->attribute_value_entry); + + if ((name) && (value)) + { + GNUNET_CHAT_set_attribute(chat, name, value, GNUNET_TIME_relative_get_forever_()); + gtk_list_store_insert_with_values( + handle->attributes_list, + NULL, + -1, + 0, + name, + 1, + value, + -1 + ); + } + + gtk_entry_set_text(handle->attribute_name_entry, ""); + gtk_entry_set_text(handle->attribute_value_entry, ""); +} + +static void +handle_attribute_value_entry_activate(UNUSED GtkEntry *entry, + gpointer user_data) +{ + g_assert(user_data); + + UI_CONTACT_INFO_Handle *handle = (UI_CONTACT_INFO_Handle*) user_data; + + handle_add_attribute_button_click(handle->add_attribute_button, handle); +} + void ui_contact_info_dialog_init(MESSENGER_Application *app, UI_CONTACT_INFO_Handle *handle) @@ -634,6 +694,50 @@ ui_contact_info_dialog_init(MESSENGER_Application *app, handle ); + handle->new_attribute_box = GTK_WIDGET( + gtk_builder_get_object(handle->builder, "new_attribute_box") + ); + + handle->attribute_name_entry = GTK_ENTRY( + gtk_builder_get_object(handle->builder, "attribute_name_entry") + ); + + handle->attribute_value_entry = GTK_ENTRY( + gtk_builder_get_object(handle->builder, "attribute_value_entry") + ); + + handle->add_attribute_button = GTK_BUTTON( + gtk_builder_get_object(handle->builder, "add_attribute_button") + ); + + g_signal_connect( + handle->attribute_name_entry, + "changed", + G_CALLBACK(handle_attribute_entry_changed), + handle->attribute_value_entry + ); + + g_signal_connect( + handle->attribute_value_entry, + "changed", + G_CALLBACK(handle_attribute_entry_changed), + handle->add_attribute_button + ); + + g_signal_connect( + handle->attribute_value_entry, + "activate", + G_CALLBACK(handle_attribute_value_entry_activate), + handle + ); + + g_signal_connect( + handle->add_attribute_button, + "clicked", + G_CALLBACK(handle_add_attribute_button_click), + handle + ); + handle->back_button = GTK_BUTTON( gtk_builder_get_object(handle->builder, "back_button") ); @@ -688,6 +792,28 @@ ui_contact_info_dialog_update(UI_CONTACT_INFO_Handle *handle, contact ); + const gboolean editable = ( + (!contact) || + (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)) + ); + + GValue value = G_VALUE_INIT; + g_value_init(&value, G_TYPE_BOOLEAN); + g_value_set_boolean(&value, editable); + + g_object_set_property( + G_OBJECT(handle->value_renderer), + "editable", + &value + ); + + g_value_unset(&value); + + gtk_widget_set_visible( + handle->new_attribute_box, + editable + ); + const char *key = GNUNET_CHAT_contact_get_key(contact); if (handle->qr) diff --git a/src/ui/contact_info.h b/src/ui/contact_info.h @@ -65,6 +65,10 @@ typedef struct UI_CONTACT_INFO_Handle GtkTreeView *attributes_tree; GtkListStore *attributes_list; GtkCellRendererText *value_renderer; + GtkWidget *new_attribute_box; + GtkEntry *attribute_name_entry; + GtkEntry *attribute_value_entry; + GtkButton *add_attribute_button; GtkButton *back_button; GtkButton *close_button;