From 1de05a83d54cb363199c2767e56267533cc11f0d Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Mon, 14 Feb 2022 17:24:05 +0100 Subject: Added dialog to pick account Signed-off-by: TheJackiMonster --- Makefile | 4 +- resources/ui.gresource.xml | 5 +- resources/ui/account_entry.ui | 62 ++++++++++++++ resources/ui/accounts.ui | 107 ++++++++++++++++++++++++ resources/ui/messenger.ui | 2 +- resources/ui/new_account.ui | 144 ++++++++++++++++++++++++++++++++ resources/ui/new_profile.ui | 144 -------------------------------- resources/ui/profile_entry.ui | 62 -------------- src/application.h | 6 +- src/event.c | 14 ++-- src/ui/account_entry.c | 59 +++++++++++++ src/ui/account_entry.h | 46 ++++++++++ src/ui/accounts.c | 190 ++++++++++++++++++++++++++++++++++++++++++ src/ui/accounts.h | 50 +++++++++++ src/ui/chat.c | 7 +- src/ui/messenger.c | 6 +- src/ui/new_account.c | 174 ++++++++++++++++++++++++++++++++++++++ src/ui/new_account.h | 51 ++++++++++++ src/ui/new_profile.c | 174 -------------------------------------- src/ui/new_profile.h | 51 ------------ src/ui/profile_entry.c | 59 ------------- src/ui/profile_entry.h | 46 ---------- 22 files changed, 906 insertions(+), 557 deletions(-) create mode 100644 resources/ui/account_entry.ui create mode 100644 resources/ui/accounts.ui create mode 100644 resources/ui/new_account.ui delete mode 100644 resources/ui/new_profile.ui delete mode 100644 resources/ui/profile_entry.ui create mode 100644 src/ui/account_entry.c create mode 100644 src/ui/account_entry.h create mode 100644 src/ui/accounts.c create mode 100644 src/ui/accounts.h create mode 100644 src/ui/new_account.c create mode 100644 src/ui/new_account.h delete mode 100644 src/ui/new_profile.c delete mode 100644 src/ui/new_profile.h delete mode 100644 src/ui/profile_entry.c delete mode 100644 src/ui/profile_entry.h diff --git a/Makefile b/Makefile index 3c0cfc7..c30edfa 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,9 @@ SOURCES = messenger_gtk.c\ ui/new_contact.c\ ui/new_group.c\ ui/new_platform.c\ - ui/new_profile.c\ + ui/new_account.c\ ui/picker.c\ - ui/profile_entry.c\ + ui/account_entry.c\ ui/send_file.c\ ui/settings.c diff --git a/resources/ui.gresource.xml b/resources/ui.gresource.xml index 96b1f1a..e0942e5 100644 --- a/resources/ui.gresource.xml +++ b/resources/ui.gresource.xml @@ -15,10 +15,11 @@ ui/new_contact.ui ui/new_group.ui ui/new_platform.ui - ui/new_profile.ui + ui/new_account.ui ui/picker.ui - ui/profile_entry.ui + ui/account_entry.ui ui/send_file.ui ui/settings.ui + ui/accounts.ui diff --git a/resources/ui/account_entry.ui b/resources/ui/account_entry.ui new file mode 100644 index 0000000..827ae26 --- /dev/null +++ b/resources/ui/account_entry.ui @@ -0,0 +1,62 @@ + + + + + + + True + False + 8 + + + True + False + 36 + + + False + True + 0 + + + + + True + False + True + word-char + end + 0 + + + True + True + end + 1 + + + + + diff --git a/resources/ui/accounts.ui b/resources/ui/accounts.ui new file mode 100644 index 0000000..d4ffb4e --- /dev/null +++ b/resources/ui/accounts.ui @@ -0,0 +1,107 @@ + + + + + + False + dialog + + + False + vertical + 2 + + + False + end + + + Close + True + True + True + + + True + True + 0 + + + + + False + False + 0 + + + + + True + True + in + + + True + False + + + True + False + + + True + True + False + + + True + False + + + 36 + 36 + True + False + list-add-symbolic + 3 + + + False + True + 0 + + + + + True + False + Add Account + + + False + True + 1 + + + + + + + + + + + + + + True + True + 1 + + + + + + diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui index 3d0ca2d..9076e67 100644 --- a/resources/ui/messenger.ui +++ b/resources/ui/messenger.ui @@ -373,7 +373,7 @@ Author: Tobias Frisch diff --git a/resources/ui/new_account.ui b/resources/ui/new_account.ui new file mode 100644 index 0000000..46d46f7 --- /dev/null +++ b/resources/ui/new_account.ui @@ -0,0 +1,144 @@ + + + + + + + False + True + center-on-parent + dialog + + + False + vertical + 2 + + + False + end + + + Cancel + True + True + True + + + True + True + 0 + + + + + Confirm + True + True + True + + + True + True + 3 + + + + + False + False + 0 + + + + + True + False + center + 8 + vertical + 4 + + + True + False + center + 8 + 8 + avatar-default-symbolic + 128 + + + False + True + 0 + + + + + True + False + Name: + 0 + + + False + True + 1 + + + + + 250 + True + True + + + False + True + 2 + + + + + True + False + + + + False + True + 3 + + + + + False + True + 1 + + + + + + diff --git a/resources/ui/new_profile.ui b/resources/ui/new_profile.ui deleted file mode 100644 index 3cc568a..0000000 --- a/resources/ui/new_profile.ui +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - False - True - center-on-parent - dialog - - - False - vertical - 2 - - - False - end - - - Cancel - True - True - True - - - True - True - 0 - - - - - Confirm - True - True - True - - - True - True - 3 - - - - - False - False - 0 - - - - - True - False - center - 8 - vertical - 4 - - - True - False - center - 8 - 8 - avatar-default-symbolic - 128 - - - False - True - 0 - - - - - True - False - Name: - 0 - - - False - True - 1 - - - - - 250 - True - True - - - False - True - 2 - - - - - True - False - - - - False - True - 3 - - - - - False - True - 1 - - - - - - diff --git a/resources/ui/profile_entry.ui b/resources/ui/profile_entry.ui deleted file mode 100644 index 0545f55..0000000 --- a/resources/ui/profile_entry.ui +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - True - False - 8 - - - True - False - 36 - - - False - True - 0 - - - - - True - False - True - word-char - end - 0 - - - True - True - end - 1 - - - - - diff --git a/src/application.h b/src/application.h index 291bc1b..d7be05a 100644 --- a/src/application.h +++ b/src/application.h @@ -30,13 +30,14 @@ #include "chat/messenger.h" +#include "ui/accounts.h" #include "ui/contacts.h" #include "ui/invite_contact.h" #include "ui/messenger.h" +#include "ui/new_account.h" #include "ui/new_contact.h" #include "ui/new_group.h" #include "ui/new_platform.h" -#include "ui/new_profile.h" #include "ui/send_file.h" #include "ui/settings.h" @@ -82,8 +83,9 @@ 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_NEW_ACCOUNT_Handle new_account; + UI_ACCOUNTS_Handle accounts; UI_CONTACTS_Handle contacts; UI_SETTINGS_Handle settings; } ui; diff --git a/src/event.c b/src/event.c index 24b7771..4df457b 100644 --- a/src/event.c +++ b/src/event.c @@ -26,11 +26,11 @@ #include "contact.h" #include "file.h" +#include "ui/account_entry.h" #include "ui/chat_entry.h" #include "ui/contact_entry.h" #include "ui/message.h" -#include "ui/profile_entry.h" static void _close_notification(NotifyNotification* notification, @@ -100,15 +100,15 @@ _iterate_accounts(void *cls, const gchar *name = GNUNET_CHAT_account_get_name(account); - UI_PROFILE_ENTRY_Handle *profile = ui_profile_entry_new(app); + UI_ACCOUNT_ENTRY_Handle *entry = ui_account_entry_new(app); - hdy_avatar_set_text(profile->entry_avatar, name); - gtk_label_set_text(profile->entry_label, name); + hdy_avatar_set_text(entry->entry_avatar, name); + gtk_label_set_text(entry->entry_label, name); - gtk_list_box_prepend(ui->accounts_listbox, profile->entry_box); + gtk_list_box_prepend(ui->accounts_listbox, entry->entry_box); GtkListBoxRow *row = GTK_LIST_BOX_ROW( - gtk_widget_get_parent(profile->entry_box) + gtk_widget_get_parent(entry->entry_box) ); g_hash_table_insert(ui->bindings, row, account); @@ -117,7 +117,7 @@ _iterate_accounts(void *cls, ((app->chat.identity) && (0 == g_strcmp0(app->chat.identity, name)))) gtk_widget_activate(GTK_WIDGET(row)); - ui_profile_entry_delete(profile); + ui_account_entry_delete(entry); return GNUNET_YES; } diff --git a/src/ui/account_entry.c b/src/ui/account_entry.c new file mode 100644 index 0000000..3c0c52c --- /dev/null +++ b/src/ui/account_entry.c @@ -0,0 +1,59 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021--2022 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 . + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui/account_entry.c + */ + +#include "account_entry.h" + +#include "../application.h" + +UI_ACCOUNT_ENTRY_Handle* +ui_account_entry_new(MESSENGER_Application *app) +{ + UI_ACCOUNT_ENTRY_Handle* handle = g_malloc(sizeof(UI_ACCOUNT_ENTRY_Handle)); + + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/account_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_account_entry_delete(UI_ACCOUNT_ENTRY_Handle *handle) +{ + g_object_unref(handle->builder); + + g_free(handle); +} diff --git a/src/ui/account_entry.h b/src/ui/account_entry.h new file mode 100644 index 0000000..e5cc446 --- /dev/null +++ b/src/ui/account_entry.h @@ -0,0 +1,46 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021--2022 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 . + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui/account_entry.h + */ + +#ifndef UI_ACCOUNT_ENTRY_H_ +#define UI_ACCOUNT_ENTRY_H_ + +#include "messenger.h" + +typedef struct UI_ACCOUNT_ENTRY_Handle +{ + GtkBuilder *builder; + + GtkWidget *entry_box; + + HdyAvatar *entry_avatar; + GtkLabel *entry_label; +} UI_ACCOUNT_ENTRY_Handle; + +UI_ACCOUNT_ENTRY_Handle* +ui_account_entry_new(MESSENGER_Application *app); + +void +ui_account_entry_delete(UI_ACCOUNT_ENTRY_Handle *handle); + +#endif /* UI_ACCOUNT_ENTRY_H_ */ diff --git a/src/ui/accounts.c b/src/ui/accounts.c new file mode 100644 index 0000000..c55c009 --- /dev/null +++ b/src/ui/accounts.c @@ -0,0 +1,190 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022 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 . + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui/accounts.c + */ + +#include "accounts.h" + +#include "account_entry.h" +#include "../application.h" + +static void +handle_close_button_click(UNUSED GtkButton *button, + gpointer user_data) +{ + GtkDialog *dialog = GTK_DIALOG(user_data); + gtk_window_close(GTK_WINDOW(dialog)); +} + +static gboolean +_open_new_account_dialog(gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + ui_new_account_dialog_init(app, &(app->ui.new_account)); + + gtk_widget_show(GTK_WIDGET(app->ui.new_account.dialog)); + return FALSE; +} + +static void +handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, + GtkListBoxRow* row, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + if (!gtk_list_box_row_get_selectable(row)) + { + g_idle_add(G_SOURCE_FUNC(_open_new_account_dialog), app); + goto close_dialog; + } + + struct GNUNET_CHAT_Account *account = (struct GNUNET_CHAT_Account*) ( + g_hash_table_lookup(app->ui.bindings, row) + ); + + if (!account) + goto close_dialog; + + // TODO + +close_dialog: + gtk_window_close(GTK_WINDOW(app->ui.accounts.dialog)); +} + +static void +handle_dialog_destroy(UNUSED GtkWidget *window, + gpointer user_data) +{ + ui_accounts_dialog_cleanup((UI_ACCOUNTS_Handle*) user_data); +} + +static int +_iterate_accounts(void *cls, + const struct GNUNET_CHAT_Handle *handle, + struct GNUNET_CHAT_Account *account) +{ + MESSENGER_Application *app = (MESSENGER_Application*) cls; + UI_MESSENGER_Handle *ui = &(app->ui.messenger); + + const gchar *name = GNUNET_CHAT_account_get_name(account); + + UI_ACCOUNT_ENTRY_Handle *entry = ui_account_entry_new(app); + + hdy_avatar_set_text(entry->entry_avatar, name); + gtk_label_set_text(entry->entry_label, name); + + gtk_list_box_prepend(ui->accounts_listbox, entry->entry_box); + + GtkListBoxRow *row = GTK_LIST_BOX_ROW( + gtk_widget_get_parent(entry->entry_box) + ); + + g_hash_table_insert(ui->bindings, row, account); + + ui.accounts.account_entries = g_list_append( + ui.accounts.account_entries, + entry + ); + + return GNUNET_YES; +} + +void +ui_accounts_dialog_init(MESSENGER_Application *app, + UI_ACCOUNTS_Handle *handle) +{ + handle->account_entries = NULL; + handle->bindings = app->ui.bindings; + + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/accounts.ui") + ); + + handle->dialog = GTK_DIALOG( + gtk_builder_get_object(handle->builder, "accounts_dialog") + ); + + gtk_window_set_title( + GTK_WINDOW(handle->dialog), + _("Contacts") + ); + + gtk_window_set_transient_for( + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) + ); + + handle->accounts_listbox = GTK_LIST_BOX( + gtk_builder_get_object(handle->builder, "accounts_listbox") + ); + + g_signal_connect( + handle->accounts_listbox, + "row-activated", + G_CALLBACK(handle_accounts_listbox_row_activated), + app + ); + + handle->close_button = GTK_BUTTON( + gtk_builder_get_object(handle->builder, "close_button") + ); + + g_signal_connect( + handle->close_button, + "clicked", + G_CALLBACK(handle_close_button_click), + handle->dialog + ); + + g_signal_connect( + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle + ); + + GNUNET_CHAT_iterate_accounts( + app->chat.messenger.handle, + _iterate_accounts, + app + ); +} + +void +ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) +{ + g_object_unref(handle->builder); + + GList *list = handle->account_entries; + + while (list) { + if (list->data) + ui_account_entry_delete((UI_ACCOUNT_ENTRY_Handle*) list->data); + + list = list->next; + } + + if (handle->account_entries) + g_list_free(handle->account_entries); +} diff --git a/src/ui/accounts.h b/src/ui/accounts.h new file mode 100644 index 0000000..88cdcfa --- /dev/null +++ b/src/ui/accounts.h @@ -0,0 +1,50 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022 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 . + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui/accounts.h + */ + +#ifndef UI_ACCOUNTS_H_ +#define UI_ACCOUNTS_H_ + +#include "messenger.h" + +typedef struct UI_ACCOUNTS_Handle +{ + GList *account_entries; + GHashTable *bindings; + + GtkBuilder *builder; + GtkDialog *dialog; + + GtkListBox *accounts_listbox; + + GtkButton *close_button; +} UI_ACCOUNTS_Handle; + +void +ui_accounts_dialog_init(MESSENGER_Application *app, + UI_ACCOUNTS_Handle *handle); + +void +ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle); + +#endif /* UI_ACCOUNTS_H_ */ diff --git a/src/ui/chat.c b/src/ui/chat.c index bf5085c..45d361e 100644 --- a/src/ui/chat.c +++ b/src/ui/chat.c @@ -30,10 +30,9 @@ #include "message.h" #include "messenger.h" #include "picker.h" -#include "profile_entry.h" - #include "../application.h" #include "../contact.h" +#include "account_entry.h" static gboolean _flap_reveal_switch(gpointer user_data) @@ -638,7 +637,7 @@ iterate_ui_chat_update_group_contacts(void *cls, ); GtkListBox *listbox = closure->listbox; - UI_PROFILE_ENTRY_Handle* entry = ui_profile_entry_new(closure->app); + UI_ACCOUNT_ENTRY_Handle* entry = ui_account_entry_new(closure->app); const char *name = GNUNET_CHAT_contact_get_name(contact); @@ -653,7 +652,7 @@ iterate_ui_chat_update_group_contacts(void *cls, g_hash_table_insert(closure->bindings, row, contact); - ui_profile_entry_delete(entry); + ui_account_entry_delete(entry); return GNUNET_YES; } diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 398673c..d0324d0 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021 GNUnet e.V. + Copyright (C) 2021--2022 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 @@ -88,9 +88,9 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, { hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); - ui_new_profile_dialog_init(app, &(app->ui.new_profile)); + ui_new_account_dialog_init(app, &(app->ui.new_account)); - gtk_widget_show(GTK_WIDGET(app->ui.new_profile.dialog)); + gtk_widget_show(GTK_WIDGET(app->ui.new_account.dialog)); return; } diff --git a/src/ui/new_account.c b/src/ui/new_account.c new file mode 100644 index 0000000..854b2bd --- /dev/null +++ b/src/ui/new_account.c @@ -0,0 +1,174 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021--2022 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 . + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui/new_account.c + */ + +#include "new_account.h" + +#include "../application.h" + +static void +_open_new_account(GtkEntry *entry, MESSENGER_Application *app) +{ + const gchar *name = gtk_entry_get_text(entry); + + if (GNUNET_OK != GNUNET_CHAT_account_create(app->chat.messenger.handle, name)) + return; + + gtk_list_box_unselect_all(app->ui.messenger.accounts_listbox); + + if (app->chat.identity) + GNUNET_free(app->chat.identity); + + app->chat.identity = GNUNET_strdup(name); +} + +static void +handle_account_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_account_entry_activate(UNUSED GtkEntry *entry, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + _open_new_account(app->ui.new_account.account_entry, app); + + gtk_window_close(GTK_WINDOW(app->ui.new_account.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; + + _open_new_account(app->ui.new_account.account_entry, app); + + gtk_window_close(GTK_WINDOW(app->ui.new_account.dialog)); +} + +static void +handle_dialog_destroy(UNUSED GtkWidget *window, + gpointer user_data) +{ + ui_new_account_dialog_cleanup((UI_NEW_ACCOUNT_Handle*) user_data); +} + +void +ui_new_account_dialog_init(MESSENGER_Application *app, + UI_NEW_ACCOUNT_Handle *handle) +{ + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/new_account.ui") + ); + + handle->dialog = GTK_DIALOG( + gtk_builder_get_object(handle->builder, "new_account_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->account_avatar = HDY_AVATAR( + gtk_builder_get_object(handle->builder, "account_avatar") + ); + + handle->account_avatar_file = GTK_FILE_CHOOSER_BUTTON( + gtk_builder_get_object(handle->builder, "account_avatar_file") + ); + + handle->account_entry = GTK_ENTRY( + gtk_builder_get_object(handle->builder, "account_entry") + ); + + g_signal_connect( + handle->account_entry, + "changed", + G_CALLBACK(handle_account_entry_changed), + handle->account_avatar + ); + + g_signal_connect( + handle->account_entry, + "activate", + G_CALLBACK(handle_account_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_account_dialog_cleanup(UI_NEW_ACCOUNT_Handle *handle) +{ + g_object_unref(handle->builder); +} diff --git a/src/ui/new_account.h b/src/ui/new_account.h new file mode 100644 index 0000000..c355d12 --- /dev/null +++ b/src/ui/new_account.h @@ -0,0 +1,51 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021--2022 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 . + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui/new_account.h + */ + +#ifndef UI_NEW_ACCOUNT_H_ +#define UI_NEW_ACCOUNT_H_ + +#include "messenger.h" + +typedef struct UI_NEW_ACCOUNT_Handle +{ + GtkBuilder *builder; + GtkDialog *dialog; + + HdyAvatar *account_avatar; + GtkFileChooserButton *account_avatar_file; + + GtkEntry *account_entry; + + GtkButton *cancel_button; + GtkButton *confirm_button; +} UI_NEW_ACCOUNT_Handle; + +void +ui_new_account_dialog_init(MESSENGER_Application *app, + UI_NEW_ACCOUNT_Handle *handle); + +void +ui_new_account_dialog_cleanup(UI_NEW_ACCOUNT_Handle *handle); + +#endif /* UI_NEW_ACCOUNT_H_ */ diff --git a/src/ui/new_profile.c b/src/ui/new_profile.c deleted file mode 100644 index cc615f5..0000000 --- a/src/ui/new_profile.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2021--2022 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 . - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/* - * @author Tobias Frisch - * @file ui/new_profile.c - */ - -#include "new_profile.h" - -#include "../application.h" - -static void -_open_new_profile(GtkEntry *entry, MESSENGER_Application *app) -{ - const gchar *name = gtk_entry_get_text(entry); - - if (GNUNET_OK != GNUNET_CHAT_account_create(app->chat.messenger.handle, name)) - return; - - gtk_list_box_unselect_all(app->ui.messenger.accounts_listbox); - - if (app->chat.identity) - GNUNET_free(app->chat.identity); - - app->chat.identity = GNUNET_strdup(name); -} - -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; - - _open_new_profile(app->ui.new_profile.profile_entry, app); - - 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; - - _open_new_profile(app->ui.new_profile.profile_entry, app); - - 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_resource( - application_get_resource_path(app, "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 deleted file mode 100644 index e675ae0..0000000 --- a/src/ui/new_profile.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - 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 . - - 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_ */ diff --git a/src/ui/profile_entry.c b/src/ui/profile_entry.c deleted file mode 100644 index c2b232f..0000000 --- a/src/ui/profile_entry.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - 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 . - - 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(MESSENGER_Application *app) -{ - UI_PROFILE_ENTRY_Handle* handle = g_malloc(sizeof(UI_PROFILE_ENTRY_Handle)); - - handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "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 deleted file mode 100644 index 92d2fd0..0000000 --- a/src/ui/profile_entry.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - 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 . - - 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(MESSENGER_Application *app); - -void -ui_profile_entry_delete(UI_PROFILE_ENTRY_Handle *handle); - -#endif /* UI_PROFILE_ENTRY_H_ */ -- cgit v1.2.3