messenger-gtk

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

commit 1e666517d6f6bccb85b2a92fd51986efba2e2563
parent 141e52eab14ae9f48844e175bc150753c8e3f002
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Sun, 12 Dec 2021 18:30:26 +0100

Added dialog to add new profiles

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

Diffstat:
MMakefile | 1+
Mresources/ui/messenger.ui | 2+-
Aresources/ui/new_profile.ui | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/application.h | 2++
Msrc/ui/messenger.c | 31+++++++++++++++++++++++++++++++
Msrc/ui/messenger.h | 1+
Msrc/ui/new_platform.c | 2+-
Asrc/ui/new_profile.c | 156+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ui/new_profile.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 387 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -16,6 +16,7 @@ SOURCES = messenger_gtk.c\ ui/new_contact.c\ ui/new_group.c\ ui/new_platform.c\ + ui/new_profile.c\ ui/picker.c\ ui/profile_entry.c\ ui/settings.c diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui @@ -334,7 +334,7 @@ Author: Tobias Frisch <property name="visible">True</property> <property name="can-focus">False</property> <child> - <object class="GtkListBoxRow"> + <object class="GtkListBoxRow" id="add_account_listbox_row"> <property name="visible">True</property> <property name="can-focus">True</property> <property name="selectable">False</property> diff --git a/resources/ui/new_profile.ui b/resources/ui/new_profile.ui @@ -0,0 +1,143 @@ +<?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="GtkDialog" id="new_profile_dialog"> + <property name="can-focus">False</property> + <property name="modal">True</property> + <property name="window-position">center-on-parent</property> + <property name="type-hint">dialog</property> + <child internal-child="vbox"> + <object class="GtkBox"> + <property name="can-focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">2</property> + <child internal-child="action_area"> + <object class="GtkButtonBox"> + <property name="can-focus">False</property> + <property name="layout-style">end</property> + <child> + <object class="GtkButton" id="cancel_button"> + <property name="label" translatable="yes">Cancel</property> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="receives-default">True</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="confirm_button"> + <property name="label" translatable="yes">Confirm</property> + <property name="can-focus">True</property> + <property name="receives-default">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</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="halign">center</property> + <property name="border-width">8</property> + <property name="orientation">vertical</property> + <property name="spacing">4</property> + <child> + <object class="HdyAvatar" id="profile_avatar"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="halign">center</property> + <property name="margin-top">8</property> + <property name="margin-bottom">8</property> + <property name="icon-name">avatar-default-symbolic</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="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes">Name:</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> + <child> + <object class="GtkEntry" id="profile_entry"> + <property name="width-request">250</property> + <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="position">2</property> + </packing> + </child> + <child> + <object class="GtkFileChooserButton" id="profile_avatar_file"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="title" translatable="yes"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> +</interface> diff --git a/src/application.h b/src/application.h @@ -35,6 +35,7 @@ #include "ui/new_contact.h" #include "ui/new_group.h" #include "ui/new_platform.h" +#include "ui/new_profile.h" #include "ui/settings.h" #include "util.h" @@ -74,6 +75,7 @@ typedef struct MESSENGER_Application UI_NEW_CONTACT_Handle new_contact; UI_NEW_GROUP_Handle new_group; UI_NEW_PLATFORM_Handle new_platform; + UI_NEW_PROFILE_Handle new_profile; UI_CONTACTS_Handle contacts; UI_SETTINGS_Handle settings; } ui; diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -70,6 +70,26 @@ handle_account_details_button_click(UNUSED GtkButton* button, } static void +handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, + GtkListBoxRow* row, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + if (row == app->ui.messenger.add_account_listbox_row) + { + hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); + + ui_new_profile_dialog_init(app, &(app->ui.new_profile)); + + gtk_widget_show(GTK_WIDGET(app->ui.new_profile.dialog)); + return; + } + + // TODO: switch to selected profile +} + +static void handle_new_contact_button_click(UNUSED GtkButton* button, gpointer user_data) { @@ -274,6 +294,17 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "accounts_listbox") ); + handle->add_account_listbox_row = GTK_LIST_BOX_ROW( + gtk_builder_get_object(handle->builder, "add_account_listbox_row") + ); + + g_signal_connect( + handle->accounts_listbox, + "row-activated", + G_CALLBACK(handle_accounts_listbox_row_activated), + app + ); + handle->new_contact_button = GTK_BUTTON( gtk_builder_get_object(handle->builder, "new_contact_button") ); diff --git a/src/ui/messenger.h b/src/ui/messenger.h @@ -55,6 +55,7 @@ typedef struct UI_MESSENGER_Handle GtkRevealer *account_details_revealer; GtkListBox *accounts_listbox; + GtkListBoxRow *add_account_listbox_row; GtkButton *new_contact_button; GtkButton *new_group_button; diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c @@ -19,7 +19,7 @@ */ /* * @author Tobias Frisch - * @file ui/new_platform.h + * @file ui/new_platform.c */ #include "new_platform.h" diff --git a/src/ui/new_profile.c b/src/ui/new_profile.c @@ -0,0 +1,156 @@ +/* + 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/new_profile.c + */ + +#include "new_profile.h" + +#include "../application.h" + +static void +handle_profile_entry_changed(GtkEditable *editable, + gpointer user_data) +{ + HdyAvatar *avatar = HDY_AVATAR(user_data); + GtkEntry *entry = GTK_ENTRY(editable); + + hdy_avatar_set_text(avatar, gtk_entry_get_text(entry)); +} + +static void +handle_profile_entry_activate(UNUSED GtkEntry *entry, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + // TODO: create new profile and switch to it + + gtk_window_close(GTK_WINDOW(app->ui.new_profile.dialog)); +} + +static void +handle_cancel_button_click(UNUSED GtkButton *button, + gpointer user_data) +{ + GtkDialog *dialog = GTK_DIALOG(user_data); + gtk_window_close(GTK_WINDOW(dialog)); +} + +static void +handle_confirm_button_click(UNUSED GtkButton *button, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + // TODO: create new profile and switch to it + + gtk_window_close(GTK_WINDOW(app->ui.new_profile.dialog)); +} + +static void +handle_dialog_destroy(UNUSED GtkWidget *window, + gpointer user_data) +{ + ui_new_profile_dialog_cleanup((UI_NEW_PROFILE_Handle*) user_data); +} + +void +ui_new_profile_dialog_init(MESSENGER_Application *app, + UI_NEW_PROFILE_Handle *handle) +{ + handle->builder = gtk_builder_new_from_file("resources/ui/new_profile.ui"); + + handle->dialog = GTK_DIALOG( + gtk_builder_get_object(handle->builder, "new_profile_dialog") + ); + + gtk_window_set_title( + GTK_WINDOW(handle->dialog), + "New Profile" + ); + + gtk_window_set_transient_for( + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) + ); + + handle->profile_avatar = HDY_AVATAR( + gtk_builder_get_object(handle->builder, "profile_avatar") + ); + + handle->profile_avatar_file = GTK_FILE_CHOOSER_BUTTON( + gtk_builder_get_object(handle->builder, "profile_avatar_file") + ); + + handle->profile_entry = GTK_ENTRY( + gtk_builder_get_object(handle->builder, "profile_entry") + ); + + g_signal_connect( + handle->profile_entry, + "changed", + G_CALLBACK(handle_profile_entry_changed), + handle->profile_avatar + ); + + g_signal_connect( + handle->profile_entry, + "activate", + G_CALLBACK(handle_profile_entry_activate), + app + ); + + handle->cancel_button = GTK_BUTTON( + gtk_builder_get_object(handle->builder, "cancel_button") + ); + + g_signal_connect( + handle->cancel_button, + "clicked", + G_CALLBACK(handle_cancel_button_click), + handle->dialog + ); + + handle->confirm_button = GTK_BUTTON( + gtk_builder_get_object(handle->builder, "confirm_button") + ); + + g_signal_connect( + handle->confirm_button, + "clicked", + G_CALLBACK(handle_confirm_button_click), + app + ); + + g_signal_connect( + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle + ); +} + +void +ui_new_profile_dialog_cleanup(UI_NEW_PROFILE_Handle *handle) +{ + g_object_unref(handle->builder); +} diff --git a/src/ui/new_profile.h b/src/ui/new_profile.h @@ -0,0 +1,51 @@ +/* + 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/new_profile.h + */ + +#ifndef UI_NEW_PROFILE_H_ +#define UI_NEW_PROFILE_H_ + +#include "messenger.h" + +typedef struct UI_NEW_PROFILE_Handle +{ + GtkBuilder *builder; + GtkDialog *dialog; + + HdyAvatar *profile_avatar; + GtkFileChooserButton *profile_avatar_file; + + GtkEntry *profile_entry; + + GtkButton *cancel_button; + GtkButton *confirm_button; +} UI_NEW_PROFILE_Handle; + +void +ui_new_profile_dialog_init(MESSENGER_Application *app, + UI_NEW_PROFILE_Handle *handle); + +void +ui_new_profile_dialog_cleanup(UI_NEW_PROFILE_Handle *handle); + +#endif /* UI_NEW_PROFILE_H_ */