diff options
Diffstat (limited to 'src/ui/new_platform.c')
-rw-r--r-- | src/ui/new_platform.c | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c new file mode 100644 index 0000000..46384c0 --- /dev/null +++ b/src/ui/new_platform.c | |||
@@ -0,0 +1,122 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 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_platform.h | ||
23 | */ | ||
24 | |||
25 | #include "new_platform.h" | ||
26 | |||
27 | #include "../application.h" | ||
28 | |||
29 | static void | ||
30 | handle_platform_entry_changed(GtkEditable *editable, | ||
31 | gpointer user_data) | ||
32 | { | ||
33 | HdyAvatar *avatar = HDY_AVATAR(user_data); | ||
34 | GtkEntry *entry = GTK_ENTRY(editable); | ||
35 | |||
36 | hdy_avatar_set_text(avatar, gtk_entry_get_text(entry)); | ||
37 | } | ||
38 | |||
39 | static void | ||
40 | handle_cancel_button_click(UNUSED GtkButton *button, | ||
41 | gpointer user_data) | ||
42 | { | ||
43 | GtkDialog *dialog = GTK_DIALOG(user_data); | ||
44 | gtk_window_close(GTK_WINDOW(dialog)); | ||
45 | } | ||
46 | |||
47 | static void | ||
48 | handle_confirm_button_click(UNUSED GtkButton *button, | ||
49 | gpointer user_data) | ||
50 | { | ||
51 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
52 | |||
53 | const char *topic = gtk_entry_get_text(app->ui.new_platform.platform_entry); | ||
54 | |||
55 | GNUNET_CHAT_group_create(app->chat.messenger.handle, topic); | ||
56 | |||
57 | gtk_window_close(GTK_WINDOW(app->ui.new_platform.platform_dialog)); | ||
58 | } | ||
59 | |||
60 | void | ||
61 | ui_new_platform_dialog_init(MESSENGER_Application *app, | ||
62 | UI_NEW_PLATFORM_Handle *handle) | ||
63 | { | ||
64 | GtkBuilder* builder = gtk_builder_new_from_file("resources/ui/new_platform.ui"); | ||
65 | |||
66 | handle->platform_dialog = GTK_DIALOG( | ||
67 | gtk_builder_get_object(builder, "platform_dialog") | ||
68 | ); | ||
69 | |||
70 | gtk_window_set_title( | ||
71 | GTK_WINDOW(handle->platform_dialog), | ||
72 | "New Platform" | ||
73 | ); | ||
74 | |||
75 | gtk_window_set_transient_for( | ||
76 | GTK_WINDOW(handle->platform_dialog), | ||
77 | GTK_WINDOW(app->ui.messenger.main_window) | ||
78 | ); | ||
79 | |||
80 | gtk_window_set_modal(GTK_WINDOW(handle->platform_dialog), TRUE); | ||
81 | |||
82 | handle->platform_avatar = HDY_AVATAR( | ||
83 | gtk_builder_get_object(builder, "platform_avatar") | ||
84 | ); | ||
85 | |||
86 | handle->platform_avatar_file = GTK_FILE_CHOOSER_BUTTON( | ||
87 | gtk_builder_get_object(builder, "platform_avatar_file") | ||
88 | ); | ||
89 | |||
90 | handle->platform_entry = GTK_ENTRY( | ||
91 | gtk_builder_get_object(builder, "platform_entry") | ||
92 | ); | ||
93 | |||
94 | g_signal_connect( | ||
95 | handle->platform_entry, | ||
96 | "changed", | ||
97 | G_CALLBACK(handle_platform_entry_changed), | ||
98 | handle->platform_avatar | ||
99 | ); | ||
100 | |||
101 | handle->cancel_button = GTK_BUTTON( | ||
102 | gtk_builder_get_object(builder, "cancel_button") | ||
103 | ); | ||
104 | |||
105 | g_signal_connect( | ||
106 | handle->cancel_button, | ||
107 | "clicked", | ||
108 | G_CALLBACK(handle_cancel_button_click), | ||
109 | handle->platform_dialog | ||
110 | ); | ||
111 | |||
112 | handle->confirm_button = GTK_BUTTON( | ||
113 | gtk_builder_get_object(builder, "confirm_button") | ||
114 | ); | ||
115 | |||
116 | g_signal_connect( | ||
117 | handle->confirm_button, | ||
118 | "clicked", | ||
119 | G_CALLBACK(handle_confirm_button_click), | ||
120 | app | ||
121 | ); | ||
122 | } | ||