aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-12-12 18:30:26 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-12-12 18:30:26 +0100
commit1e666517d6f6bccb85b2a92fd51986efba2e2563 (patch)
tree769f9f1e0f8727b620b592c8f59b586b8a1a18d3
parent141e52eab14ae9f48844e175bc150753c8e3f002 (diff)
downloadmessenger-gtk-1e666517d6f6bccb85b2a92fd51986efba2e2563.tar.gz
messenger-gtk-1e666517d6f6bccb85b2a92fd51986efba2e2563.zip
Added dialog to add new profiles
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--Makefile1
-rw-r--r--resources/ui/messenger.ui2
-rw-r--r--resources/ui/new_profile.ui143
-rw-r--r--src/application.h2
-rw-r--r--src/ui/messenger.c31
-rw-r--r--src/ui/messenger.h1
-rw-r--r--src/ui/new_platform.c2
-rw-r--r--src/ui/new_profile.c156
-rw-r--r--src/ui/new_profile.h51
9 files changed, 387 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 1906073..58dc5f2 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ SOURCES = messenger_gtk.c\
16 ui/new_contact.c\ 16 ui/new_contact.c\
17 ui/new_group.c\ 17 ui/new_group.c\
18 ui/new_platform.c\ 18 ui/new_platform.c\
19 ui/new_profile.c\
19 ui/picker.c\ 20 ui/picker.c\
20 ui/profile_entry.c\ 21 ui/profile_entry.c\
21 ui/settings.c 22 ui/settings.c
diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui
index f301650..e917f98 100644
--- a/resources/ui/messenger.ui
+++ b/resources/ui/messenger.ui
@@ -334,7 +334,7 @@ Author: Tobias Frisch
334 <property name="visible">True</property> 334 <property name="visible">True</property>
335 <property name="can-focus">False</property> 335 <property name="can-focus">False</property>
336 <child> 336 <child>
337 <object class="GtkListBoxRow"> 337 <object class="GtkListBoxRow" id="add_account_listbox_row">
338 <property name="visible">True</property> 338 <property name="visible">True</property>
339 <property name="can-focus">True</property> 339 <property name="can-focus">True</property>
340 <property name="selectable">False</property> 340 <property name="selectable">False</property>
diff --git a/resources/ui/new_profile.ui b/resources/ui/new_profile.ui
new file mode 100644
index 0000000..e7c7c06
--- /dev/null
+++ b/resources/ui/new_profile.ui
@@ -0,0 +1,143 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- Generated with glade 3.38.2
3
4Copyright (C) 2021 GNUnet e.V.
5
6GNUnet is free software: you can redistribute it and/or modify it
7under the terms of the GNU Affero General Public License as published
8by the Free Software Foundation, either version 3 of the License,
9or (at your option) any later version.
10
11GNUnet is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19SPDX-License-Identifier: AGPL3.0-or-later
20Author: 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_profile_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="confirm_button">
55 <property name="label" translatable="yes">Confirm</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">3</property>
63 </packing>
64 </child>
65 </object>
66 <packing>
67 <property name="expand">False</property>
68 <property name="fill">False</property>
69 <property name="position">0</property>
70 </packing>
71 </child>
72 <child>
73 <object class="GtkBox">
74 <property name="visible">True</property>
75 <property name="can-focus">False</property>
76 <property name="halign">center</property>
77 <property name="border-width">8</property>
78 <property name="orientation">vertical</property>
79 <property name="spacing">4</property>
80 <child>
81 <object class="HdyAvatar" id="profile_avatar">
82 <property name="visible">True</property>
83 <property name="can-focus">False</property>
84 <property name="halign">center</property>
85 <property name="margin-top">8</property>
86 <property name="margin-bottom">8</property>
87 <property name="icon-name">avatar-default-symbolic</property>
88 <property name="size">128</property>
89 </object>
90 <packing>
91 <property name="expand">False</property>
92 <property name="fill">True</property>
93 <property name="position">0</property>
94 </packing>
95 </child>
96 <child>
97 <object class="GtkLabel">
98 <property name="visible">True</property>
99 <property name="can-focus">False</property>
100 <property name="label" translatable="yes">Name:</property>
101 <property name="xalign">0</property>
102 </object>
103 <packing>
104 <property name="expand">False</property>
105 <property name="fill">True</property>
106 <property name="position">1</property>
107 </packing>
108 </child>
109 <child>
110 <object class="GtkEntry" id="profile_entry">
111 <property name="width-request">250</property>
112 <property name="visible">True</property>
113 <property name="can-focus">True</property>
114 </object>
115 <packing>
116 <property name="expand">False</property>
117 <property name="fill">True</property>
118 <property name="position">2</property>
119 </packing>
120 </child>
121 <child>
122 <object class="GtkFileChooserButton" id="profile_avatar_file">
123 <property name="visible">True</property>
124 <property name="can-focus">False</property>
125 <property name="title" translatable="yes"/>
126 </object>
127 <packing>
128 <property name="expand">False</property>
129 <property name="fill">True</property>
130 <property name="position">3</property>
131 </packing>
132 </child>
133 </object>
134 <packing>
135 <property name="expand">False</property>
136 <property name="fill">True</property>
137 <property name="position">1</property>
138 </packing>
139 </child>
140 </object>
141 </child>
142 </object>
143</interface>
diff --git a/src/application.h b/src/application.h
index b02b1df..125b294 100644
--- a/src/application.h
+++ b/src/application.h
@@ -35,6 +35,7 @@
35#include "ui/new_contact.h" 35#include "ui/new_contact.h"
36#include "ui/new_group.h" 36#include "ui/new_group.h"
37#include "ui/new_platform.h" 37#include "ui/new_platform.h"
38#include "ui/new_profile.h"
38#include "ui/settings.h" 39#include "ui/settings.h"
39 40
40#include "util.h" 41#include "util.h"
@@ -74,6 +75,7 @@ typedef struct MESSENGER_Application
74 UI_NEW_CONTACT_Handle new_contact; 75 UI_NEW_CONTACT_Handle new_contact;
75 UI_NEW_GROUP_Handle new_group; 76 UI_NEW_GROUP_Handle new_group;
76 UI_NEW_PLATFORM_Handle new_platform; 77 UI_NEW_PLATFORM_Handle new_platform;
78 UI_NEW_PROFILE_Handle new_profile;
77 UI_CONTACTS_Handle contacts; 79 UI_CONTACTS_Handle contacts;
78 UI_SETTINGS_Handle settings; 80 UI_SETTINGS_Handle settings;
79 } ui; 81 } ui;
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
index afea63e..17b30a5 100644
--- a/src/ui/messenger.c
+++ b/src/ui/messenger.c
@@ -70,6 +70,26 @@ handle_account_details_button_click(UNUSED GtkButton* button,
70} 70}
71 71
72static void 72static void
73handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
74 GtkListBoxRow* row,
75 gpointer user_data)
76{
77 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
78
79 if (row == app->ui.messenger.add_account_listbox_row)
80 {
81 hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE);
82
83 ui_new_profile_dialog_init(app, &(app->ui.new_profile));
84
85 gtk_widget_show(GTK_WIDGET(app->ui.new_profile.dialog));
86 return;
87 }
88
89 // TODO: switch to selected profile
90}
91
92static void
73handle_new_contact_button_click(UNUSED GtkButton* button, 93handle_new_contact_button_click(UNUSED GtkButton* button,
74 gpointer user_data) 94 gpointer user_data)
75{ 95{
@@ -274,6 +294,17 @@ ui_messenger_init(MESSENGER_Application *app,
274 gtk_builder_get_object(handle->builder, "accounts_listbox") 294 gtk_builder_get_object(handle->builder, "accounts_listbox")
275 ); 295 );
276 296
297 handle->add_account_listbox_row = GTK_LIST_BOX_ROW(
298 gtk_builder_get_object(handle->builder, "add_account_listbox_row")
299 );
300
301 g_signal_connect(
302 handle->accounts_listbox,
303 "row-activated",
304 G_CALLBACK(handle_accounts_listbox_row_activated),
305 app
306 );
307
277 handle->new_contact_button = GTK_BUTTON( 308 handle->new_contact_button = GTK_BUTTON(
278 gtk_builder_get_object(handle->builder, "new_contact_button") 309 gtk_builder_get_object(handle->builder, "new_contact_button")
279 ); 310 );
diff --git a/src/ui/messenger.h b/src/ui/messenger.h
index 6a4a43e..da2155e 100644
--- a/src/ui/messenger.h
+++ b/src/ui/messenger.h
@@ -55,6 +55,7 @@ typedef struct UI_MESSENGER_Handle
55 55
56 GtkRevealer *account_details_revealer; 56 GtkRevealer *account_details_revealer;
57 GtkListBox *accounts_listbox; 57 GtkListBox *accounts_listbox;
58 GtkListBoxRow *add_account_listbox_row;
58 59
59 GtkButton *new_contact_button; 60 GtkButton *new_contact_button;
60 GtkButton *new_group_button; 61 GtkButton *new_group_button;
diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c
index 6521b83..43fadb7 100644
--- a/src/ui/new_platform.c
+++ b/src/ui/new_platform.c
@@ -19,7 +19,7 @@
19 */ 19 */
20/* 20/*
21 * @author Tobias Frisch 21 * @author Tobias Frisch
22 * @file ui/new_platform.h 22 * @file ui/new_platform.c
23 */ 23 */
24 24
25#include "new_platform.h" 25#include "new_platform.h"
diff --git a/src/ui/new_profile.c b/src/ui/new_profile.c
new file mode 100644
index 0000000..48c2bb5
--- /dev/null
+++ b/src/ui/new_profile.c
@@ -0,0 +1,156 @@
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_profile.c
23 */
24
25#include "new_profile.h"
26
27#include "../application.h"
28
29static void
30handle_profile_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
39static void
40handle_profile_entry_activate(UNUSED GtkEntry *entry,
41 gpointer user_data)
42{
43 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
44
45 // TODO: create new profile and switch to it
46
47 gtk_window_close(GTK_WINDOW(app->ui.new_profile.dialog));
48}
49
50static void
51handle_cancel_button_click(UNUSED GtkButton *button,
52 gpointer user_data)
53{
54 GtkDialog *dialog = GTK_DIALOG(user_data);
55 gtk_window_close(GTK_WINDOW(dialog));
56}
57
58static void
59handle_confirm_button_click(UNUSED GtkButton *button,
60 gpointer user_data)
61{
62 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
63
64 // TODO: create new profile and switch to it
65
66 gtk_window_close(GTK_WINDOW(app->ui.new_profile.dialog));
67}
68
69static void
70handle_dialog_destroy(UNUSED GtkWidget *window,
71 gpointer user_data)
72{
73 ui_new_profile_dialog_cleanup((UI_NEW_PROFILE_Handle*) user_data);
74}
75
76void
77ui_new_profile_dialog_init(MESSENGER_Application *app,
78 UI_NEW_PROFILE_Handle *handle)
79{
80 handle->builder = gtk_builder_new_from_file("resources/ui/new_profile.ui");
81
82 handle->dialog = GTK_DIALOG(
83 gtk_builder_get_object(handle->builder, "new_profile_dialog")
84 );
85
86 gtk_window_set_title(
87 GTK_WINDOW(handle->dialog),
88 "New Profile"
89 );
90
91 gtk_window_set_transient_for(
92 GTK_WINDOW(handle->dialog),
93 GTK_WINDOW(app->ui.messenger.main_window)
94 );
95
96 handle->profile_avatar = HDY_AVATAR(
97 gtk_builder_get_object(handle->builder, "profile_avatar")
98 );
99
100 handle->profile_avatar_file = GTK_FILE_CHOOSER_BUTTON(
101 gtk_builder_get_object(handle->builder, "profile_avatar_file")
102 );
103
104 handle->profile_entry = GTK_ENTRY(
105 gtk_builder_get_object(handle->builder, "profile_entry")
106 );
107
108 g_signal_connect(
109 handle->profile_entry,
110 "changed",
111 G_CALLBACK(handle_profile_entry_changed),
112 handle->profile_avatar
113 );
114
115 g_signal_connect(
116 handle->profile_entry,
117 "activate",
118 G_CALLBACK(handle_profile_entry_activate),
119 app
120 );
121
122 handle->cancel_button = GTK_BUTTON(
123 gtk_builder_get_object(handle->builder, "cancel_button")
124 );
125
126 g_signal_connect(
127 handle->cancel_button,
128 "clicked",
129 G_CALLBACK(handle_cancel_button_click),
130 handle->dialog
131 );
132
133 handle->confirm_button = GTK_BUTTON(
134 gtk_builder_get_object(handle->builder, "confirm_button")
135 );
136
137 g_signal_connect(
138 handle->confirm_button,
139 "clicked",
140 G_CALLBACK(handle_confirm_button_click),
141 app
142 );
143
144 g_signal_connect(
145 handle->dialog,
146 "destroy",
147 G_CALLBACK(handle_dialog_destroy),
148 handle
149 );
150}
151
152void
153ui_new_profile_dialog_cleanup(UI_NEW_PROFILE_Handle *handle)
154{
155 g_object_unref(handle->builder);
156}
diff --git a/src/ui/new_profile.h b/src/ui/new_profile.h
new file mode 100644
index 0000000..e675ae0
--- /dev/null
+++ b/src/ui/new_profile.h
@@ -0,0 +1,51 @@
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_profile.h
23 */
24
25#ifndef UI_NEW_PROFILE_H_
26#define UI_NEW_PROFILE_H_
27
28#include "messenger.h"
29
30typedef struct UI_NEW_PROFILE_Handle
31{
32 GtkBuilder *builder;
33 GtkDialog *dialog;
34
35 HdyAvatar *profile_avatar;
36 GtkFileChooserButton *profile_avatar_file;
37
38 GtkEntry *profile_entry;
39
40 GtkButton *cancel_button;
41 GtkButton *confirm_button;
42} UI_NEW_PROFILE_Handle;
43
44void
45ui_new_profile_dialog_init(MESSENGER_Application *app,
46 UI_NEW_PROFILE_Handle *handle);
47
48void
49ui_new_profile_dialog_cleanup(UI_NEW_PROFILE_Handle *handle);
50
51#endif /* UI_NEW_PROFILE_H_ */