aboutsummaryrefslogtreecommitdiff
path: root/src/ui/new_account.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/new_account.c')
-rw-r--r--src/ui/new_account.c174
1 files changed, 174 insertions, 0 deletions
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 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021--2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file ui/new_account.c
23 */
24
25#include "new_account.h"
26
27#include "../application.h"
28
29static void
30_open_new_account(GtkEntry *entry, MESSENGER_Application *app)
31{
32 const gchar *name = gtk_entry_get_text(entry);
33
34 if (GNUNET_OK != GNUNET_CHAT_account_create(app->chat.messenger.handle, name))
35 return;
36
37 gtk_list_box_unselect_all(app->ui.messenger.accounts_listbox);
38
39 if (app->chat.identity)
40 GNUNET_free(app->chat.identity);
41
42 app->chat.identity = GNUNET_strdup(name);
43}
44
45static void
46handle_account_entry_changed(GtkEditable *editable,
47 gpointer user_data)
48{
49 HdyAvatar *avatar = HDY_AVATAR(user_data);
50 GtkEntry *entry = GTK_ENTRY(editable);
51
52 hdy_avatar_set_text(avatar, gtk_entry_get_text(entry));
53}
54
55static void
56handle_account_entry_activate(UNUSED GtkEntry *entry,
57 gpointer user_data)
58{
59 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
60
61 _open_new_account(app->ui.new_account.account_entry, app);
62
63 gtk_window_close(GTK_WINDOW(app->ui.new_account.dialog));
64}
65
66static void
67handle_cancel_button_click(UNUSED GtkButton *button,
68 gpointer user_data)
69{
70 GtkDialog *dialog = GTK_DIALOG(user_data);
71 gtk_window_close(GTK_WINDOW(dialog));
72}
73
74static void
75handle_confirm_button_click(UNUSED GtkButton *button,
76 gpointer user_data)
77{
78 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
79
80 _open_new_account(app->ui.new_account.account_entry, app);
81
82 gtk_window_close(GTK_WINDOW(app->ui.new_account.dialog));
83}
84
85static void
86handle_dialog_destroy(UNUSED GtkWidget *window,
87 gpointer user_data)
88{
89 ui_new_account_dialog_cleanup((UI_NEW_ACCOUNT_Handle*) user_data);
90}
91
92void
93ui_new_account_dialog_init(MESSENGER_Application *app,
94 UI_NEW_ACCOUNT_Handle *handle)
95{
96 handle->builder = gtk_builder_new_from_resource(
97 application_get_resource_path(app, "ui/new_account.ui")
98 );
99
100 handle->dialog = GTK_DIALOG(
101 gtk_builder_get_object(handle->builder, "new_account_dialog")
102 );
103
104 gtk_window_set_title(
105 GTK_WINDOW(handle->dialog),
106 _("New Profile")
107 );
108
109 gtk_window_set_transient_for(
110 GTK_WINDOW(handle->dialog),
111 GTK_WINDOW(app->ui.messenger.main_window)
112 );
113
114 handle->account_avatar = HDY_AVATAR(
115 gtk_builder_get_object(handle->builder, "account_avatar")
116 );
117
118 handle->account_avatar_file = GTK_FILE_CHOOSER_BUTTON(
119 gtk_builder_get_object(handle->builder, "account_avatar_file")
120 );
121
122 handle->account_entry = GTK_ENTRY(
123 gtk_builder_get_object(handle->builder, "account_entry")
124 );
125
126 g_signal_connect(
127 handle->account_entry,
128 "changed",
129 G_CALLBACK(handle_account_entry_changed),
130 handle->account_avatar
131 );
132
133 g_signal_connect(
134 handle->account_entry,
135 "activate",
136 G_CALLBACK(handle_account_entry_activate),
137 app
138 );
139
140 handle->cancel_button = GTK_BUTTON(
141 gtk_builder_get_object(handle->builder, "cancel_button")
142 );
143
144 g_signal_connect(
145 handle->cancel_button,
146 "clicked",
147 G_CALLBACK(handle_cancel_button_click),
148 handle->dialog
149 );
150
151 handle->confirm_button = GTK_BUTTON(
152 gtk_builder_get_object(handle->builder, "confirm_button")
153 );
154
155 g_signal_connect(
156 handle->confirm_button,
157 "clicked",
158 G_CALLBACK(handle_confirm_button_click),
159 app
160 );
161
162 g_signal_connect(
163 handle->dialog,
164 "destroy",
165 G_CALLBACK(handle_dialog_destroy),
166 handle
167 );
168}
169
170void
171ui_new_account_dialog_cleanup(UI_NEW_ACCOUNT_Handle *handle)
172{
173 g_object_unref(handle->builder);
174}