diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-03 22:23:37 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-03 22:23:37 +0100 |
commit | 53334c28a6a97e480299c6cef1e2e0402b4265ed (patch) | |
tree | 7368bd4e35506a59c643cd9e7e4d9fda05d0dd96 | |
parent | 965c55597da500e54c9cba061888ea4774fc056a (diff) | |
download | messenger-gtk-53334c28a6a97e480299c6cef1e2e0402b4265ed.tar.gz messenger-gtk-53334c28a6a97e480299c6cef1e2e0402b4265ed.zip |
Added new group dialog
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | resources/ui/new_group.ui | 231 | ||||
-rw-r--r-- | resources/ui/new_platform.ui | 5 | ||||
-rw-r--r-- | src/application.h | 2 | ||||
-rw-r--r-- | src/ui/messenger.c | 20 | ||||
-rw-r--r-- | src/ui/new_group.c | 353 | ||||
-rw-r--r-- | src/ui/new_group.h | 61 |
7 files changed, 669 insertions, 4 deletions
@@ -14,6 +14,7 @@ SOURCES = messenger_gtk.c\ | |||
14 | ui/message.c\ | 14 | ui/message.c\ |
15 | ui/messenger.c\ | 15 | ui/messenger.c\ |
16 | ui/new_contact.c\ | 16 | ui/new_contact.c\ |
17 | ui/new_group.c\ | ||
17 | ui/new_platform.c\ | 18 | ui/new_platform.c\ |
18 | ui/picker.c\ | 19 | ui/picker.c\ |
19 | ui/profile_entry.c\ | 20 | ui/profile_entry.c\ |
diff --git a/resources/ui/new_group.ui b/resources/ui/new_group.ui new file mode 100644 index 0000000..c6439ae --- /dev/null +++ b/resources/ui/new_group.ui | |||
@@ -0,0 +1,231 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <!-- Generated with glade 3.38.2 | ||
3 | |||
4 | Copyright (C) 2021 GNUnet e.V. | ||
5 | |||
6 | GNUnet is free software: you can redistribute it and/or modify it | ||
7 | under the terms of the GNU Affero General Public License as published | ||
8 | by the Free Software Foundation, either version 3 of the License, | ||
9 | or (at your option) any later version. | ||
10 | |||
11 | GNUnet is distributed in the hope that it will be useful, but | ||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Affero General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Affero General Public License | ||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | |||
19 | SPDX-License-Identifier: AGPL3.0-or-later | ||
20 | Author: Tobias Frisch | ||
21 | |||
22 | --> | ||
23 | <interface> | ||
24 | <requires lib="gtk+" version="3.24"/> | ||
25 | <requires lib="libhandy" version="1.2"/> | ||
26 | <object class="GtkDialog" id="new_group_dialog"> | ||
27 | <property name="can-focus">False</property> | ||
28 | <property name="modal">True</property> | ||
29 | <property name="window-position">center-on-parent</property> | ||
30 | <property name="type-hint">dialog</property> | ||
31 | <child internal-child="vbox"> | ||
32 | <object class="GtkBox"> | ||
33 | <property name="can-focus">False</property> | ||
34 | <property name="orientation">vertical</property> | ||
35 | <property name="spacing">2</property> | ||
36 | <child internal-child="action_area"> | ||
37 | <object class="GtkButtonBox"> | ||
38 | <property name="can-focus">False</property> | ||
39 | <property name="layout-style">end</property> | ||
40 | <child> | ||
41 | <object class="GtkButton" id="cancel_button"> | ||
42 | <property name="label" translatable="yes">Cancel</property> | ||
43 | <property name="visible">True</property> | ||
44 | <property name="can-focus">True</property> | ||
45 | <property name="receives-default">True</property> | ||
46 | </object> | ||
47 | <packing> | ||
48 | <property name="expand">True</property> | ||
49 | <property name="fill">True</property> | ||
50 | <property name="position">0</property> | ||
51 | </packing> | ||
52 | </child> | ||
53 | <child> | ||
54 | <object class="GtkButton" id="previous_button"> | ||
55 | <property name="label" translatable="yes">Previous</property> | ||
56 | <property name="can-focus">True</property> | ||
57 | <property name="receives-default">True</property> | ||
58 | </object> | ||
59 | <packing> | ||
60 | <property name="expand">True</property> | ||
61 | <property name="fill">True</property> | ||
62 | <property name="position">1</property> | ||
63 | </packing> | ||
64 | </child> | ||
65 | <child> | ||
66 | <object class="GtkButton" id="next_button"> | ||
67 | <property name="label" translatable="yes">Next</property> | ||
68 | <property name="visible">True</property> | ||
69 | <property name="can-focus">True</property> | ||
70 | <property name="receives-default">True</property> | ||
71 | </object> | ||
72 | <packing> | ||
73 | <property name="expand">True</property> | ||
74 | <property name="fill">True</property> | ||
75 | <property name="position">2</property> | ||
76 | </packing> | ||
77 | </child> | ||
78 | <child> | ||
79 | <object class="GtkButton" id="confirm_button"> | ||
80 | <property name="label" translatable="yes">Confirm</property> | ||
81 | <property name="can-focus">True</property> | ||
82 | <property name="receives-default">True</property> | ||
83 | </object> | ||
84 | <packing> | ||
85 | <property name="expand">True</property> | ||
86 | <property name="fill">True</property> | ||
87 | <property name="position">3</property> | ||
88 | </packing> | ||
89 | </child> | ||
90 | </object> | ||
91 | <packing> | ||
92 | <property name="expand">False</property> | ||
93 | <property name="fill">False</property> | ||
94 | <property name="position">0</property> | ||
95 | </packing> | ||
96 | </child> | ||
97 | <child> | ||
98 | <object class="GtkStack" id="new_group_stack"> | ||
99 | <property name="visible">True</property> | ||
100 | <property name="can-focus">False</property> | ||
101 | <child> | ||
102 | <object class="GtkBox" id="details_box"> | ||
103 | <property name="visible">True</property> | ||
104 | <property name="can-focus">False</property> | ||
105 | <property name="halign">center</property> | ||
106 | <property name="border-width">8</property> | ||
107 | <property name="orientation">vertical</property> | ||
108 | <property name="spacing">4</property> | ||
109 | <child> | ||
110 | <object class="HdyAvatar" id="group_avatar"> | ||
111 | <property name="visible">True</property> | ||
112 | <property name="can-focus">False</property> | ||
113 | <property name="halign">center</property> | ||
114 | <property name="margin-top">8</property> | ||
115 | <property name="margin-bottom">8</property> | ||
116 | <property name="icon-name">system-users-symbolic</property> | ||
117 | <property name="size">128</property> | ||
118 | </object> | ||
119 | <packing> | ||
120 | <property name="expand">False</property> | ||
121 | <property name="fill">True</property> | ||
122 | <property name="position">0</property> | ||
123 | </packing> | ||
124 | </child> | ||
125 | <child> | ||
126 | <object class="GtkLabel"> | ||
127 | <property name="visible">True</property> | ||
128 | <property name="can-focus">False</property> | ||
129 | <property name="label" translatable="yes">Group:</property> | ||
130 | <property name="xalign">0</property> | ||
131 | </object> | ||
132 | <packing> | ||
133 | <property name="expand">False</property> | ||
134 | <property name="fill">True</property> | ||
135 | <property name="position">1</property> | ||
136 | </packing> | ||
137 | </child> | ||
138 | <child> | ||
139 | <object class="GtkEntry" id="group_entry"> | ||
140 | <property name="width-request">250</property> | ||
141 | <property name="visible">True</property> | ||
142 | <property name="can-focus">True</property> | ||
143 | </object> | ||
144 | <packing> | ||
145 | <property name="expand">False</property> | ||
146 | <property name="fill">True</property> | ||
147 | <property name="position">2</property> | ||
148 | </packing> | ||
149 | </child> | ||
150 | <child> | ||
151 | <object class="GtkFileChooserButton" id="group_avatar_file"> | ||
152 | <property name="visible">True</property> | ||
153 | <property name="can-focus">False</property> | ||
154 | <property name="title" translatable="yes"/> | ||
155 | </object> | ||
156 | <packing> | ||
157 | <property name="expand">False</property> | ||
158 | <property name="fill">True</property> | ||
159 | <property name="position">3</property> | ||
160 | </packing> | ||
161 | </child> | ||
162 | </object> | ||
163 | <packing> | ||
164 | <property name="name">details_page</property> | ||
165 | </packing> | ||
166 | </child> | ||
167 | <child> | ||
168 | <object class="GtkBox" id="contacts_box"> | ||
169 | <property name="visible">True</property> | ||
170 | <property name="can-focus">False</property> | ||
171 | <property name="orientation">vertical</property> | ||
172 | <child> | ||
173 | <object class="GtkSearchEntry" id="contact_search_entry"> | ||
174 | <property name="width-request">250</property> | ||
175 | <property name="visible">True</property> | ||
176 | <property name="can-focus">True</property> | ||
177 | <property name="primary-icon-name">edit-find-symbolic</property> | ||
178 | <property name="primary-icon-activatable">False</property> | ||
179 | <property name="primary-icon-sensitive">False</property> | ||
180 | </object> | ||
181 | <packing> | ||
182 | <property name="expand">False</property> | ||
183 | <property name="fill">True</property> | ||
184 | <property name="position">0</property> | ||
185 | </packing> | ||
186 | </child> | ||
187 | <child> | ||
188 | <object class="GtkScrolledWindow"> | ||
189 | <property name="height-request">200</property> | ||
190 | <property name="visible">True</property> | ||
191 | <property name="can-focus">True</property> | ||
192 | <property name="shadow-type">in</property> | ||
193 | <child> | ||
194 | <object class="GtkViewport"> | ||
195 | <property name="visible">True</property> | ||
196 | <property name="can-focus">False</property> | ||
197 | <child> | ||
198 | <object class="GtkListBox" id="contacts_listbox"> | ||
199 | <property name="visible">True</property> | ||
200 | <property name="can-focus">False</property> | ||
201 | <property name="selection-mode">multiple</property> | ||
202 | <property name="activate-on-single-click">False</property> | ||
203 | </object> | ||
204 | </child> | ||
205 | </object> | ||
206 | </child> | ||
207 | </object> | ||
208 | <packing> | ||
209 | <property name="expand">True</property> | ||
210 | <property name="fill">True</property> | ||
211 | <property name="pack-type">end</property> | ||
212 | <property name="position">1</property> | ||
213 | </packing> | ||
214 | </child> | ||
215 | </object> | ||
216 | <packing> | ||
217 | <property name="name">contacts_page</property> | ||
218 | <property name="position">1</property> | ||
219 | </packing> | ||
220 | </child> | ||
221 | </object> | ||
222 | <packing> | ||
223 | <property name="expand">True</property> | ||
224 | <property name="fill">True</property> | ||
225 | <property name="position">2</property> | ||
226 | </packing> | ||
227 | </child> | ||
228 | </object> | ||
229 | </child> | ||
230 | </object> | ||
231 | </interface> | ||
diff --git a/resources/ui/new_platform.ui b/resources/ui/new_platform.ui index 4b3fa8f..0f4e057 100644 --- a/resources/ui/new_platform.ui +++ b/resources/ui/new_platform.ui | |||
@@ -75,10 +75,7 @@ Author: Tobias Frisch | |||
75 | <property name="visible">True</property> | 75 | <property name="visible">True</property> |
76 | <property name="can-focus">False</property> | 76 | <property name="can-focus">False</property> |
77 | <property name="halign">center</property> | 77 | <property name="halign">center</property> |
78 | <property name="margin-start">8</property> | 78 | <property name="border-width">8</property> |
79 | <property name="margin-end">8</property> | ||
80 | <property name="margin-top">8</property> | ||
81 | <property name="margin-bottom">8</property> | ||
82 | <property name="orientation">vertical</property> | 79 | <property name="orientation">vertical</property> |
83 | <property name="spacing">4</property> | 80 | <property name="spacing">4</property> |
84 | <child> | 81 | <child> |
diff --git a/src/application.h b/src/application.h index 4ffa2c8..b02b1df 100644 --- a/src/application.h +++ b/src/application.h | |||
@@ -33,6 +33,7 @@ | |||
33 | #include "ui/contacts.h" | 33 | #include "ui/contacts.h" |
34 | #include "ui/messenger.h" | 34 | #include "ui/messenger.h" |
35 | #include "ui/new_contact.h" | 35 | #include "ui/new_contact.h" |
36 | #include "ui/new_group.h" | ||
36 | #include "ui/new_platform.h" | 37 | #include "ui/new_platform.h" |
37 | #include "ui/settings.h" | 38 | #include "ui/settings.h" |
38 | 39 | ||
@@ -71,6 +72,7 @@ typedef struct MESSENGER_Application | |||
71 | UI_MESSENGER_Handle messenger; | 72 | UI_MESSENGER_Handle messenger; |
72 | 73 | ||
73 | UI_NEW_CONTACT_Handle new_contact; | 74 | UI_NEW_CONTACT_Handle new_contact; |
75 | UI_NEW_GROUP_Handle new_group; | ||
74 | UI_NEW_PLATFORM_Handle new_platform; | 76 | UI_NEW_PLATFORM_Handle new_platform; |
75 | UI_CONTACTS_Handle contacts; | 77 | UI_CONTACTS_Handle contacts; |
76 | UI_SETTINGS_Handle settings; | 78 | UI_SETTINGS_Handle settings; |
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 8f463ca..afea63e 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -83,6 +83,19 @@ handle_new_contact_button_click(UNUSED GtkButton* button, | |||
83 | } | 83 | } |
84 | 84 | ||
85 | static void | 85 | static void |
86 | handle_new_group_button_click(UNUSED GtkButton* button, | ||
87 | gpointer user_data) | ||
88 | { | ||
89 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
90 | |||
91 | hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); | ||
92 | |||
93 | ui_new_group_dialog_init(app, &(app->ui.new_group)); | ||
94 | |||
95 | gtk_widget_show(GTK_WIDGET(app->ui.new_group.dialog)); | ||
96 | } | ||
97 | |||
98 | static void | ||
86 | handle_new_platform_button_click(UNUSED GtkButton* button, | 99 | handle_new_platform_button_click(UNUSED GtkButton* button, |
87 | gpointer user_data) | 100 | gpointer user_data) |
88 | { | 101 | { |
@@ -281,6 +294,13 @@ ui_messenger_init(MESSENGER_Application *app, | |||
281 | ); | 294 | ); |
282 | 295 | ||
283 | g_signal_connect( | 296 | g_signal_connect( |
297 | handle->new_group_button, | ||
298 | "clicked", | ||
299 | G_CALLBACK(handle_new_group_button_click), | ||
300 | app | ||
301 | ); | ||
302 | |||
303 | g_signal_connect( | ||
284 | handle->new_platform_button, | 304 | handle->new_platform_button, |
285 | "clicked", | 305 | "clicked", |
286 | G_CALLBACK(handle_new_platform_button_click), | 306 | G_CALLBACK(handle_new_platform_button_click), |
diff --git a/src/ui/new_group.c b/src/ui/new_group.c new file mode 100644 index 0000000..ea19371 --- /dev/null +++ b/src/ui/new_group.c | |||
@@ -0,0 +1,353 @@ | |||
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_group.c | ||
23 | */ | ||
24 | |||
25 | #include "new_platform.h" | ||
26 | |||
27 | #include "contact_entry.h" | ||
28 | #include "../application.h" | ||
29 | |||
30 | static void | ||
31 | _open_new_group(GtkEntry *entry, | ||
32 | GtkListBox *listbox, | ||
33 | MESSENGER_Application *app) | ||
34 | { | ||
35 | const gchar *name = gtk_entry_get_text(entry); | ||
36 | |||
37 | struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create( | ||
38 | app->chat.messenger.handle, | ||
39 | NULL | ||
40 | ); | ||
41 | |||
42 | if ((name) && (strlen(name) > 0)) | ||
43 | GNUNET_CHAT_group_set_name(group, name); | ||
44 | |||
45 | GList *selected = gtk_list_box_get_selected_rows(listbox); | ||
46 | |||
47 | while (selected) | ||
48 | { | ||
49 | if (selected->data) | ||
50 | { | ||
51 | GtkListBoxRow *row = GTK_LIST_BOX_ROW(selected->data); | ||
52 | |||
53 | struct GNUNET_CHAT_Contact* contact = g_hash_table_lookup( | ||
54 | app->ui.bindings, row | ||
55 | ); | ||
56 | |||
57 | GNUNET_CHAT_group_invite_contact(group, contact); | ||
58 | } | ||
59 | |||
60 | selected = selected->next; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | static void | ||
65 | handle_group_entry_changed(GtkEditable *editable, | ||
66 | gpointer user_data) | ||
67 | { | ||
68 | HdyAvatar *avatar = HDY_AVATAR(user_data); | ||
69 | GtkEntry *entry = GTK_ENTRY(editable); | ||
70 | |||
71 | hdy_avatar_set_text(avatar, gtk_entry_get_text(entry)); | ||
72 | } | ||
73 | |||
74 | static void | ||
75 | _go_page_details(UI_NEW_GROUP_Handle *handle) | ||
76 | { | ||
77 | gtk_stack_set_visible_child(handle->stack, handle->details_box); | ||
78 | |||
79 | gtk_widget_hide(GTK_WIDGET(handle->previous_button)); | ||
80 | gtk_widget_hide(GTK_WIDGET(handle->confirm_button)); | ||
81 | |||
82 | gtk_widget_show(GTK_WIDGET(handle->cancel_button)); | ||
83 | gtk_widget_show(GTK_WIDGET(handle->next_button)); | ||
84 | } | ||
85 | |||
86 | static void | ||
87 | _go_page_contacts(UI_NEW_GROUP_Handle *handle) | ||
88 | { | ||
89 | gtk_stack_set_visible_child(handle->stack, handle->contacts_box); | ||
90 | |||
91 | gtk_widget_hide(GTK_WIDGET(handle->cancel_button)); | ||
92 | gtk_widget_hide(GTK_WIDGET(handle->next_button)); | ||
93 | |||
94 | gtk_widget_show(GTK_WIDGET(handle->previous_button)); | ||
95 | gtk_widget_show(GTK_WIDGET(handle->confirm_button)); | ||
96 | } | ||
97 | |||
98 | static void | ||
99 | handle_group_entry_activate(UNUSED GtkEntry *entry, | ||
100 | gpointer user_data) | ||
101 | { | ||
102 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
103 | |||
104 | _go_page_contacts(&(app->ui.new_group)); | ||
105 | } | ||
106 | |||
107 | static void | ||
108 | handle_cancel_button_click(UNUSED GtkButton *button, | ||
109 | gpointer user_data) | ||
110 | { | ||
111 | GtkDialog *dialog = GTK_DIALOG(user_data); | ||
112 | gtk_window_close(GTK_WINDOW(dialog)); | ||
113 | } | ||
114 | |||
115 | static void | ||
116 | handle_previous_button_click(UNUSED GtkButton *button, | ||
117 | gpointer user_data) | ||
118 | { | ||
119 | _go_page_details((UI_NEW_GROUP_Handle*) user_data); | ||
120 | } | ||
121 | |||
122 | static void | ||
123 | handle_next_button_click(UNUSED GtkButton *button, | ||
124 | gpointer user_data) | ||
125 | { | ||
126 | _go_page_contacts((UI_NEW_GROUP_Handle*) user_data); | ||
127 | } | ||
128 | |||
129 | static void | ||
130 | handle_confirm_button_click(UNUSED GtkButton *button, | ||
131 | gpointer user_data) | ||
132 | { | ||
133 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
134 | |||
135 | _open_new_group( | ||
136 | app->ui.new_group.group_entry, | ||
137 | app->ui.new_group.contacts_listbox, | ||
138 | app | ||
139 | ); | ||
140 | |||
141 | gtk_window_close(GTK_WINDOW(app->ui.new_group.dialog)); | ||
142 | } | ||
143 | |||
144 | static void | ||
145 | handle_dialog_destroy(UNUSED GtkWidget *window, | ||
146 | gpointer user_data) | ||
147 | { | ||
148 | ui_new_group_dialog_cleanup((UI_NEW_GROUP_Handle*) user_data); | ||
149 | } | ||
150 | |||
151 | static int | ||
152 | _iterate_clear_contacts(UNUSED void *cls, | ||
153 | UNUSED struct GNUNET_CHAT_Handle *handle, | ||
154 | struct GNUNET_CHAT_Contact *contact) | ||
155 | { | ||
156 | GNUNET_CHAT_contact_set_user_pointer(contact, NULL); | ||
157 | return GNUNET_YES; | ||
158 | } | ||
159 | |||
160 | static int | ||
161 | _iterate_contacts(void *cls, | ||
162 | UNUSED struct GNUNET_CHAT_Handle *handle, | ||
163 | struct GNUNET_CHAT_Contact *contact) | ||
164 | { | ||
165 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | ||
166 | |||
167 | if (GNUNET_CHAT_contact_get_user_pointer(contact)) | ||
168 | return GNUNET_YES; | ||
169 | |||
170 | const char *title; | ||
171 | title = GNUNET_CHAT_contact_get_name(contact); | ||
172 | |||
173 | const char *key = GNUNET_CHAT_contact_get_key(contact); | ||
174 | |||
175 | UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(); | ||
176 | gtk_list_box_prepend( | ||
177 | app->ui.new_group.contacts_listbox, | ||
178 | entry->entry_box | ||
179 | ); | ||
180 | |||
181 | GNUNET_CHAT_contact_set_user_pointer(contact, entry); | ||
182 | |||
183 | if (title) | ||
184 | { | ||
185 | gtk_label_set_text(entry->title_label, title); | ||
186 | hdy_avatar_set_text(entry->entry_avatar, title); | ||
187 | } | ||
188 | |||
189 | if (key) | ||
190 | gtk_label_set_text(entry->subtitle_label, key); | ||
191 | |||
192 | GtkListBoxRow *row = GTK_LIST_BOX_ROW( | ||
193 | gtk_widget_get_parent(entry->entry_box) | ||
194 | ); | ||
195 | |||
196 | g_hash_table_insert(app->ui.bindings, row, contact); | ||
197 | |||
198 | app->ui.new_group.contact_entries = g_list_append( | ||
199 | app->ui.new_group.contact_entries, | ||
200 | entry | ||
201 | ); | ||
202 | |||
203 | return GNUNET_YES; | ||
204 | } | ||
205 | |||
206 | void | ||
207 | ui_new_group_dialog_init(MESSENGER_Application *app, | ||
208 | UI_NEW_GROUP_Handle *handle) | ||
209 | { | ||
210 | handle->contact_entries = g_list_alloc(); | ||
211 | |||
212 | handle->builder = gtk_builder_new_from_file("resources/ui/new_group.ui"); | ||
213 | |||
214 | handle->dialog = GTK_DIALOG( | ||
215 | gtk_builder_get_object(handle->builder, "new_group_dialog") | ||
216 | ); | ||
217 | |||
218 | gtk_window_set_title( | ||
219 | GTK_WINDOW(handle->dialog), | ||
220 | "New Group" | ||
221 | ); | ||
222 | |||
223 | gtk_window_set_transient_for( | ||
224 | GTK_WINDOW(handle->dialog), | ||
225 | GTK_WINDOW(app->ui.messenger.main_window) | ||
226 | ); | ||
227 | |||
228 | handle->stack = GTK_STACK( | ||
229 | gtk_builder_get_object(handle->builder, "new_group_stack") | ||
230 | ); | ||
231 | |||
232 | handle->details_box = GTK_WIDGET( | ||
233 | gtk_builder_get_object(handle->builder, "details_box") | ||
234 | ); | ||
235 | |||
236 | handle->contacts_box = GTK_WIDGET( | ||
237 | gtk_builder_get_object(handle->builder, "contacts_box") | ||
238 | ); | ||
239 | |||
240 | handle->group_avatar = HDY_AVATAR( | ||
241 | gtk_builder_get_object(handle->builder, "group_avatar") | ||
242 | ); | ||
243 | |||
244 | handle->group_avatar_file = GTK_FILE_CHOOSER_BUTTON( | ||
245 | gtk_builder_get_object(handle->builder, "group_avatar_file") | ||
246 | ); | ||
247 | |||
248 | handle->group_entry = GTK_ENTRY( | ||
249 | gtk_builder_get_object(handle->builder, "group_entry") | ||
250 | ); | ||
251 | |||
252 | g_signal_connect( | ||
253 | handle->group_entry, | ||
254 | "changed", | ||
255 | G_CALLBACK(handle_group_entry_changed), | ||
256 | handle->group_avatar | ||
257 | ); | ||
258 | |||
259 | g_signal_connect( | ||
260 | handle->group_entry, | ||
261 | "activate", | ||
262 | G_CALLBACK(handle_group_entry_activate), | ||
263 | app | ||
264 | ); | ||
265 | |||
266 | handle->contact_search_entry = GTK_SEARCH_ENTRY( | ||
267 | gtk_builder_get_object(handle->builder, "contact_search_entry") | ||
268 | ); | ||
269 | |||
270 | handle->contacts_listbox = GTK_LIST_BOX( | ||
271 | gtk_builder_get_object(handle->builder, "contacts_listbox") | ||
272 | ); | ||
273 | |||
274 | handle->cancel_button = GTK_BUTTON( | ||
275 | gtk_builder_get_object(handle->builder, "cancel_button") | ||
276 | ); | ||
277 | |||
278 | g_signal_connect( | ||
279 | handle->cancel_button, | ||
280 | "clicked", | ||
281 | G_CALLBACK(handle_cancel_button_click), | ||
282 | handle->dialog | ||
283 | ); | ||
284 | |||
285 | handle->previous_button = GTK_BUTTON( | ||
286 | gtk_builder_get_object(handle->builder, "previous_button") | ||
287 | ); | ||
288 | |||
289 | g_signal_connect( | ||
290 | handle->previous_button, | ||
291 | "clicked", | ||
292 | G_CALLBACK(handle_previous_button_click), | ||
293 | handle | ||
294 | ); | ||
295 | |||
296 | handle->next_button = GTK_BUTTON( | ||
297 | gtk_builder_get_object(handle->builder, "next_button") | ||
298 | ); | ||
299 | |||
300 | g_signal_connect( | ||
301 | handle->next_button, | ||
302 | "clicked", | ||
303 | G_CALLBACK(handle_next_button_click), | ||
304 | handle | ||
305 | ); | ||
306 | |||
307 | handle->confirm_button = GTK_BUTTON( | ||
308 | gtk_builder_get_object(handle->builder, "confirm_button") | ||
309 | ); | ||
310 | |||
311 | g_signal_connect( | ||
312 | handle->confirm_button, | ||
313 | "clicked", | ||
314 | G_CALLBACK(handle_confirm_button_click), | ||
315 | app | ||
316 | ); | ||
317 | |||
318 | g_signal_connect( | ||
319 | handle->dialog, | ||
320 | "destroy", | ||
321 | G_CALLBACK(handle_dialog_destroy), | ||
322 | handle | ||
323 | ); | ||
324 | |||
325 | GNUNET_CHAT_iterate_contacts( | ||
326 | app->chat.messenger.handle, | ||
327 | _iterate_clear_contacts, | ||
328 | NULL | ||
329 | ); | ||
330 | |||
331 | GNUNET_CHAT_iterate_contacts( | ||
332 | app->chat.messenger.handle, | ||
333 | _iterate_contacts, | ||
334 | app | ||
335 | ); | ||
336 | } | ||
337 | |||
338 | void | ||
339 | ui_new_group_dialog_cleanup(UI_NEW_GROUP_Handle *handle) | ||
340 | { | ||
341 | g_object_unref(handle->builder); | ||
342 | |||
343 | GList *list = handle->contact_entries; | ||
344 | |||
345 | while (list) { | ||
346 | if (list->data) | ||
347 | ui_contact_entry_delete((UI_CONTACT_ENTRY_Handle*) list->data); | ||
348 | |||
349 | list = list->next; | ||
350 | } | ||
351 | |||
352 | g_list_free(handle->contact_entries); | ||
353 | } | ||
diff --git a/src/ui/new_group.h b/src/ui/new_group.h new file mode 100644 index 0000000..634039e --- /dev/null +++ b/src/ui/new_group.h | |||
@@ -0,0 +1,61 @@ | |||
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_group.h | ||
23 | */ | ||
24 | |||
25 | #ifndef UI_NEW_GROUP_H_ | ||
26 | #define UI_NEW_GROUP_H_ | ||
27 | |||
28 | typedef struct UI_NEW_GROUP_Handle | ||
29 | { | ||
30 | GList *contact_entries; | ||
31 | |||
32 | GtkBuilder *builder; | ||
33 | GtkDialog *dialog; | ||
34 | |||
35 | GtkStack *stack; | ||
36 | GtkWidget *details_box; | ||
37 | GtkWidget *contacts_box; | ||
38 | |||
39 | HdyAvatar *group_avatar; | ||
40 | GtkFileChooserButton *group_avatar_file; | ||
41 | |||
42 | GtkEntry *group_entry; | ||
43 | |||
44 | GtkSearchEntry *contact_search_entry; | ||
45 | |||
46 | GtkListBox *contacts_listbox; | ||
47 | |||
48 | GtkButton *cancel_button; | ||
49 | GtkButton *previous_button; | ||
50 | GtkButton *next_button; | ||
51 | GtkButton *confirm_button; | ||
52 | } UI_NEW_GROUP_Handle; | ||
53 | |||
54 | void | ||
55 | ui_new_group_dialog_init(MESSENGER_Application *app, | ||
56 | UI_NEW_GROUP_Handle *handle); | ||
57 | |||
58 | void | ||
59 | ui_new_group_dialog_cleanup(UI_NEW_GROUP_Handle *handle); | ||
60 | |||
61 | #endif /* UI_NEW_GROUP_H_ */ | ||