diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-01 23:55:21 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-01 23:55:21 +0100 |
commit | 89363b9edd1d54c07d22ae563104d1d8a2a3a8cd (patch) | |
tree | f7899dfe15671a1c7dc6464d149bac4081822e55 | |
parent | e17fc4e572c37a421337362d52832aca75796182 (diff) | |
download | messenger-gtk-89363b9edd1d54c07d22ae563104d1d8a2a3a8cd.tar.gz messenger-gtk-89363b9edd1d54c07d22ae563104d1d8a2a3a8cd.zip |
Added dialog to create a new platform and connected new events
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | resources/css/style.css | 5 | ||||
-rw-r--r-- | resources/ui/message-sent.ui | 4 | ||||
-rw-r--r-- | resources/ui/message.ui | 4 | ||||
-rw-r--r-- | resources/ui/new_platform.ui | 146 | ||||
-rw-r--r-- | src/application.c | 7 | ||||
-rw-r--r-- | src/application.h | 9 | ||||
-rw-r--r-- | src/chat/messenger.c | 32 | ||||
-rw-r--r-- | src/event.c | 28 | ||||
-rw-r--r-- | src/event.h | 7 | ||||
-rw-r--r-- | src/ui/messenger.c | 21 | ||||
-rw-r--r-- | src/ui/new_platform.c | 122 | ||||
-rw-r--r-- | src/ui/new_platform.h | 47 |
13 files changed, 419 insertions, 16 deletions
@@ -9,7 +9,8 @@ SOURCES = messenger_gtk.c\ | |||
9 | chat/messenger.c\ | 9 | chat/messenger.c\ |
10 | ui/chat_entry.c\ | 10 | ui/chat_entry.c\ |
11 | ui/message.c\ | 11 | ui/message.c\ |
12 | ui/messenger.c | 12 | ui/messenger.c\ |
13 | ui/new_platform.c | ||
13 | 14 | ||
14 | HEADERS = | 15 | HEADERS = |
15 | 16 | ||
diff --git a/resources/css/style.css b/resources/css/style.css index 27eec48..0a39d21 100644 --- a/resources/css/style.css +++ b/resources/css/style.css | |||
@@ -33,3 +33,8 @@ | |||
33 | color: @theme_selected_fg_color; | 33 | color: @theme_selected_fg_color; |
34 | margin-left: 20px; | 34 | margin-left: 20px; |
35 | } | 35 | } |
36 | |||
37 | .message-content { | ||
38 | padding-top: 4px; | ||
39 | } | ||
40 | |||
diff --git a/resources/ui/message-sent.ui b/resources/ui/message-sent.ui index 88a87e3..a046788 100644 --- a/resources/ui/message-sent.ui +++ b/resources/ui/message-sent.ui | |||
@@ -54,6 +54,7 @@ Author: Tobias Frisch | |||
54 | <property name="visible">True</property> | 54 | <property name="visible">True</property> |
55 | <property name="can-focus">False</property> | 55 | <property name="can-focus">False</property> |
56 | <property name="orientation">vertical</property> | 56 | <property name="orientation">vertical</property> |
57 | <property name="spacing">4</property> | ||
57 | <child> | 58 | <child> |
58 | <object class="GtkLabel" id="text_label"> | 59 | <object class="GtkLabel" id="text_label"> |
59 | <property name="visible">True</property> | 60 | <property name="visible">True</property> |
@@ -109,6 +110,9 @@ Author: Tobias Frisch | |||
109 | <property name="position">1</property> | 110 | <property name="position">1</property> |
110 | </packing> | 111 | </packing> |
111 | </child> | 112 | </child> |
113 | <style> | ||
114 | <class name="message-content"/> | ||
115 | </style> | ||
112 | </object> | 116 | </object> |
113 | </child> | 117 | </child> |
114 | <child type="label"> | 118 | <child type="label"> |
diff --git a/resources/ui/message.ui b/resources/ui/message.ui index 32d04d6..41c2284 100644 --- a/resources/ui/message.ui +++ b/resources/ui/message.ui | |||
@@ -53,6 +53,7 @@ Author: Tobias Frisch | |||
53 | <property name="visible">True</property> | 53 | <property name="visible">True</property> |
54 | <property name="can-focus">False</property> | 54 | <property name="can-focus">False</property> |
55 | <property name="orientation">vertical</property> | 55 | <property name="orientation">vertical</property> |
56 | <property name="spacing">4</property> | ||
56 | <child> | 57 | <child> |
57 | <object class="GtkLabel" id="text_label"> | 58 | <object class="GtkLabel" id="text_label"> |
58 | <property name="visible">True</property> | 59 | <property name="visible">True</property> |
@@ -107,6 +108,9 @@ Author: Tobias Frisch | |||
107 | <property name="position">1</property> | 108 | <property name="position">1</property> |
108 | </packing> | 109 | </packing> |
109 | </child> | 110 | </child> |
111 | <style> | ||
112 | <class name="message-content"/> | ||
113 | </style> | ||
110 | </object> | 114 | </object> |
111 | </child> | 115 | </child> |
112 | <child type="label"> | 116 | <child type="label"> |
diff --git a/resources/ui/new_platform.ui b/resources/ui/new_platform.ui new file mode 100644 index 0000000..80ff925 --- /dev/null +++ b/resources/ui/new_platform.ui | |||
@@ -0,0 +1,146 @@ | |||
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="platform_dialog"> | ||
27 | <property name="can-focus">False</property> | ||
28 | <property name="window-position">center-on-parent</property> | ||
29 | <property name="type-hint">dialog</property> | ||
30 | <child internal-child="vbox"> | ||
31 | <object class="GtkBox"> | ||
32 | <property name="can-focus">False</property> | ||
33 | <property name="orientation">vertical</property> | ||
34 | <property name="spacing">2</property> | ||
35 | <child internal-child="action_area"> | ||
36 | <object class="GtkButtonBox"> | ||
37 | <property name="can-focus">False</property> | ||
38 | <property name="layout-style">end</property> | ||
39 | <child> | ||
40 | <object class="GtkButton" id="cancel_button"> | ||
41 | <property name="label" translatable="yes">Cancel</property> | ||
42 | <property name="visible">True</property> | ||
43 | <property name="can-focus">True</property> | ||
44 | <property name="receives-default">True</property> | ||
45 | </object> | ||
46 | <packing> | ||
47 | <property name="expand">True</property> | ||
48 | <property name="fill">True</property> | ||
49 | <property name="position">0</property> | ||
50 | </packing> | ||
51 | </child> | ||
52 | <child> | ||
53 | <object class="GtkButton" id="confirm_button"> | ||
54 | <property name="label" translatable="yes">Confirm</property> | ||
55 | <property name="visible">True</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 | </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="margin-start">8</property> | ||
78 | <property name="margin-end">8</property> | ||
79 | <property name="margin-top">8</property> | ||
80 | <property name="margin-bottom">8</property> | ||
81 | <property name="orientation">vertical</property> | ||
82 | <property name="spacing">4</property> | ||
83 | <child> | ||
84 | <object class="HdyAvatar" id="platform_avatar"> | ||
85 | <property name="visible">True</property> | ||
86 | <property name="can-focus">False</property> | ||
87 | <property name="halign">center</property> | ||
88 | <property name="margin-top">8</property> | ||
89 | <property name="margin-bottom">8</property> | ||
90 | <property name="icon-name">network-wired-symbolic</property> | ||
91 | <property name="size">128</property> | ||
92 | </object> | ||
93 | <packing> | ||
94 | <property name="expand">False</property> | ||
95 | <property name="fill">True</property> | ||
96 | <property name="position">0</property> | ||
97 | </packing> | ||
98 | </child> | ||
99 | <child> | ||
100 | <object class="GtkLabel"> | ||
101 | <property name="visible">True</property> | ||
102 | <property name="can-focus">False</property> | ||
103 | <property name="label" translatable="yes">Platform:</property> | ||
104 | <property name="xalign">0</property> | ||
105 | </object> | ||
106 | <packing> | ||
107 | <property name="expand">False</property> | ||
108 | <property name="fill">True</property> | ||
109 | <property name="position">1</property> | ||
110 | </packing> | ||
111 | </child> | ||
112 | <child> | ||
113 | <object class="GtkEntry" id="platform_entry"> | ||
114 | <property name="width-request">250</property> | ||
115 | <property name="visible">True</property> | ||
116 | <property name="can-focus">True</property> | ||
117 | </object> | ||
118 | <packing> | ||
119 | <property name="expand">False</property> | ||
120 | <property name="fill">True</property> | ||
121 | <property name="position">2</property> | ||
122 | </packing> | ||
123 | </child> | ||
124 | <child> | ||
125 | <object class="GtkFileChooserButton" id="platform_avatar_file"> | ||
126 | <property name="visible">True</property> | ||
127 | <property name="can-focus">False</property> | ||
128 | <property name="title" translatable="yes"/> | ||
129 | </object> | ||
130 | <packing> | ||
131 | <property name="expand">False</property> | ||
132 | <property name="fill">True</property> | ||
133 | <property name="position">3</property> | ||
134 | </packing> | ||
135 | </child> | ||
136 | </object> | ||
137 | <packing> | ||
138 | <property name="expand">True</property> | ||
139 | <property name="fill">True</property> | ||
140 | <property name="position">1</property> | ||
141 | </packing> | ||
142 | </child> | ||
143 | </object> | ||
144 | </child> | ||
145 | </object> | ||
146 | </interface> | ||
diff --git a/src/application.c b/src/application.c index 2f367a5..0db05bb 100644 --- a/src/application.c +++ b/src/application.c | |||
@@ -147,6 +147,7 @@ typedef struct MESSENGER_ApplicationEventCall | |||
147 | { | 147 | { |
148 | MESSENGER_Application *app; | 148 | MESSENGER_Application *app; |
149 | MESSENGER_ApplicationEvent event; | 149 | MESSENGER_ApplicationEvent event; |
150 | void *cls; | ||
150 | } MESSENGER_ApplicationEventCall; | 151 | } MESSENGER_ApplicationEventCall; |
151 | 152 | ||
152 | static gboolean | 153 | static gboolean |
@@ -155,7 +156,7 @@ _application_event_call(gpointer user_data) | |||
155 | MESSENGER_ApplicationEventCall *call; | 156 | MESSENGER_ApplicationEventCall *call; |
156 | 157 | ||
157 | call = (MESSENGER_ApplicationEventCall*) user_data; | 158 | call = (MESSENGER_ApplicationEventCall*) user_data; |
158 | call->event(call->app); | 159 | call->event(call->app, call->cls); |
159 | 160 | ||
160 | GNUNET_free(call); | 161 | GNUNET_free(call); |
161 | return FALSE; | 162 | return FALSE; |
@@ -163,7 +164,8 @@ _application_event_call(gpointer user_data) | |||
163 | 164 | ||
164 | void | 165 | void |
165 | application_call_event(MESSENGER_Application *app, | 166 | application_call_event(MESSENGER_Application *app, |
166 | MESSENGER_ApplicationEvent event) | 167 | MESSENGER_ApplicationEvent event, |
168 | void *cls) | ||
167 | { | 169 | { |
168 | MESSENGER_ApplicationEventCall *call; | 170 | MESSENGER_ApplicationEventCall *call; |
169 | 171 | ||
@@ -173,6 +175,7 @@ application_call_event(MESSENGER_Application *app, | |||
173 | 175 | ||
174 | call->app = app; | 176 | call->app = app; |
175 | call->event = event; | 177 | call->event = event; |
178 | call->cls = cls; | ||
176 | 179 | ||
177 | g_idle_add(_application_event_call, call); | 180 | g_idle_add(_application_event_call, call); |
178 | } | 181 | } |
diff --git a/src/application.h b/src/application.h index 5801f6d..61aed2a 100644 --- a/src/application.h +++ b/src/application.h | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "chat/messenger.h" | 30 | #include "chat/messenger.h" |
31 | 31 | ||
32 | #include "ui/messenger.h" | 32 | #include "ui/messenger.h" |
33 | #include "ui/new_platform.h" | ||
33 | 34 | ||
34 | #include "util.h" | 35 | #include "util.h" |
35 | 36 | ||
@@ -61,6 +62,8 @@ typedef struct MESSENGER_Application | |||
61 | gboolean mobile; | 62 | gboolean mobile; |
62 | 63 | ||
63 | UI_MESSENGER_Handle messenger; | 64 | UI_MESSENGER_Handle messenger; |
65 | |||
66 | UI_NEW_PLATFORM_Handle new_platform; | ||
64 | } ui; | 67 | } ui; |
65 | } MESSENGER_Application; | 68 | } MESSENGER_Application; |
66 | 69 | ||
@@ -72,11 +75,13 @@ application_init(MESSENGER_Application *app, | |||
72 | void | 75 | void |
73 | application_run(MESSENGER_Application *app); | 76 | application_run(MESSENGER_Application *app); |
74 | 77 | ||
75 | typedef void (*MESSENGER_ApplicationEvent) (MESSENGER_Application *app); | 78 | typedef void (*MESSENGER_ApplicationEvent) (MESSENGER_Application *app, |
79 | void *cls); | ||
76 | 80 | ||
77 | void | 81 | void |
78 | application_call_event(MESSENGER_Application *app, | 82 | application_call_event(MESSENGER_Application *app, |
79 | MESSENGER_ApplicationEvent event); | 83 | MESSENGER_ApplicationEvent event, |
84 | void *cls); | ||
80 | 85 | ||
81 | void | 86 | void |
82 | application_exit(MESSENGER_Application *app, | 87 | application_exit(MESSENGER_Application *app, |
diff --git a/src/chat/messenger.c b/src/chat/messenger.c index 62b93e8..72ba93a 100644 --- a/src/chat/messenger.c +++ b/src/chat/messenger.c | |||
@@ -57,10 +57,34 @@ _chat_messenger_message(void *cls, | |||
57 | { | 57 | { |
58 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | 58 | MESSENGER_Application *app = (MESSENGER_Application*) cls; |
59 | 59 | ||
60 | if (GNUNET_CHAT_KIND_LOGIN == GNUNET_CHAT_message_get_kind(message)) | 60 | const enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); |
61 | application_call_event(app, event_update_profile); | 61 | const struct GNUNET_CHAT_Contact* sender = GNUNET_CHAT_message_get_sender(message); |
62 | else if (GNUNET_CHAT_KIND_TEXT == GNUNET_CHAT_message_get_kind(message)) | 62 | |
63 | printf("%s\n", GNUNET_CHAT_message_get_text(message)); | 63 | struct GNUNET_TIME_Absolute time = GNUNET_CHAT_message_get_timestamp(message); |
64 | |||
65 | printf("- %d, %lu", kind, time.abs_value_us); | ||
66 | |||
67 | if (sender) | ||
68 | printf(", %s\n", GNUNET_CHAT_contact_get_name(sender)); | ||
69 | else | ||
70 | printf("\n"); | ||
71 | |||
72 | switch (kind) | ||
73 | { | ||
74 | case GNUNET_CHAT_KIND_LOGIN: | ||
75 | application_call_event(app, event_update_profile, NULL); | ||
76 | break; | ||
77 | case GNUNET_CHAT_KIND_TEXT: | ||
78 | printf("text: %s\n", GNUNET_CHAT_message_get_text(message)); | ||
79 | break; | ||
80 | case GNUNET_CHAT_KIND_JOIN: | ||
81 | if (GNUNET_YES == GNUNET_CHAT_message_is_sent(message)) | ||
82 | application_call_event(app, event_update_chats, context); | ||
83 | |||
84 | break; | ||
85 | default: | ||
86 | break; | ||
87 | } | ||
64 | 88 | ||
65 | return GNUNET_YES; | 89 | return GNUNET_YES; |
66 | } | 90 | } |
diff --git a/src/event.c b/src/event.c index e023613..5ad3016 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -73,7 +73,8 @@ _clear_each_widget(GtkWidget *widget, | |||
73 | } | 73 | } |
74 | 74 | ||
75 | void | 75 | void |
76 | event_update_profile(MESSENGER_Application *app) | 76 | event_update_profile(MESSENGER_Application *app, |
77 | UNUSED void *cls) | ||
77 | { | 78 | { |
78 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | 79 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); |
79 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); | 80 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); |
@@ -95,13 +96,28 @@ event_update_profile(MESSENGER_Application *app) | |||
95 | GNUNET_CHAT_iterate_contacts(chat->handle, _iterate_profile_contacts, app); | 96 | GNUNET_CHAT_iterate_contacts(chat->handle, _iterate_profile_contacts, app); |
96 | GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); | 97 | GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); |
97 | 98 | ||
98 | UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(); | ||
99 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); | ||
100 | g_free(entry); | ||
101 | |||
102 | for (int i = 0; i < 8; i++) { | 99 | for (int i = 0; i < 8; i++) { |
103 | UI_MESSAGE_Handle *message = ui_message_new(app, i % 2 == 0); | 100 | UI_MESSAGE_Handle *message = ui_message_new(app, i % 2 == 0); |
104 | gtk_container_add(GTK_CONTAINER(ui->messages_listbox), message->message_box); | 101 | gtk_container_add(GTK_CONTAINER(ui->messages_listbox), message->message_box); |
105 | g_free(message); | 102 | g_free(message); // TODO: this is just a test! |
106 | } | 103 | } |
107 | } | 104 | } |
105 | |||
106 | void | ||
107 | event_update_chats(MESSENGER_Application *app, | ||
108 | void *cls) | ||
109 | { | ||
110 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) cls; | ||
111 | |||
112 | if (GNUNET_CHAT_context_get_user_pointer(context)) | ||
113 | return; | ||
114 | |||
115 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | ||
116 | |||
117 | UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(); | ||
118 | gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); | ||
119 | g_free(entry); // TODO: free already? | ||
120 | |||
121 | // TODO: put something better here to attach it! | ||
122 | GNUNET_CHAT_context_set_user_pointer(context, ui); | ||
123 | } | ||
diff --git a/src/event.h b/src/event.h index 4beb589..6b5dce3 100644 --- a/src/event.h +++ b/src/event.h | |||
@@ -28,6 +28,11 @@ | |||
28 | #include "application.h" | 28 | #include "application.h" |
29 | 29 | ||
30 | void | 30 | void |
31 | event_update_profile(MESSENGER_Application *app); | 31 | event_update_profile(MESSENGER_Application *app, |
32 | void *cls); | ||
33 | |||
34 | void | ||
35 | event_update_chats(MESSENGER_Application *app, | ||
36 | void *cls); | ||
32 | 37 | ||
33 | #endif /* EVENT_H_ */ | 38 | #endif /* EVENT_H_ */ |
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 196b00a..4e31952 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include "messenger.h" | 25 | #include "messenger.h" |
26 | 26 | ||
27 | #include "new_platform.h" | ||
27 | #include "../application.h" | 28 | #include "../application.h" |
28 | 29 | ||
29 | static void | 30 | static void |
@@ -53,6 +54,19 @@ handle_account_details_button_click(UNUSED GtkButton* button, | |||
53 | } | 54 | } |
54 | 55 | ||
55 | static void | 56 | static void |
57 | handle_new_platform_button_click(UNUSED GtkButton* button, | ||
58 | gpointer user_data) | ||
59 | { | ||
60 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
61 | |||
62 | hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); | ||
63 | |||
64 | ui_new_platform_dialog_init(app, &(app->ui.new_platform)); | ||
65 | |||
66 | gtk_widget_show(GTK_WIDGET(app->ui.new_platform.platform_dialog)); | ||
67 | } | ||
68 | |||
69 | static void | ||
56 | handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, | 70 | handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, |
57 | UNUSED GtkListBoxRow* row, | 71 | UNUSED GtkListBoxRow* row, |
58 | gpointer user_data) | 72 | gpointer user_data) |
@@ -215,6 +229,13 @@ ui_messenger_init(MESSENGER_Application *app, | |||
215 | gtk_builder_get_object(builder, "new_platform_button") | 229 | gtk_builder_get_object(builder, "new_platform_button") |
216 | ); | 230 | ); |
217 | 231 | ||
232 | g_signal_connect( | ||
233 | handle->new_platform_button, | ||
234 | "clicked", | ||
235 | G_CALLBACK(handle_new_platform_button_click), | ||
236 | app | ||
237 | ); | ||
238 | |||
218 | handle->contacts_button = GTK_BUTTON( | 239 | handle->contacts_button = GTK_BUTTON( |
219 | gtk_builder_get_object(builder, "contacts_button") | 240 | gtk_builder_get_object(builder, "contacts_button") |
220 | ); | 241 | ); |
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 | } | ||
diff --git a/src/ui/new_platform.h b/src/ui/new_platform.h new file mode 100644 index 0000000..745c4de --- /dev/null +++ b/src/ui/new_platform.h | |||
@@ -0,0 +1,47 @@ | |||
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 | #ifndef UI_NEW_PLATFORM_H_ | ||
26 | #define UI_NEW_PLATFORM_H_ | ||
27 | |||
28 | #include "messenger.h" | ||
29 | |||
30 | typedef struct UI_NEW_PLATFORM_Handle | ||
31 | { | ||
32 | GtkDialog* platform_dialog; | ||
33 | |||
34 | HdyAvatar* platform_avatar; | ||
35 | GtkFileChooserButton* platform_avatar_file; | ||
36 | |||
37 | GtkEntry* platform_entry; | ||
38 | |||
39 | GtkButton* cancel_button; | ||
40 | GtkButton* confirm_button; | ||
41 | } UI_NEW_PLATFORM_Handle; | ||
42 | |||
43 | void | ||
44 | ui_new_platform_dialog_init(MESSENGER_Application *app, | ||
45 | UI_NEW_PLATFORM_Handle *handle); | ||
46 | |||
47 | #endif /* UI_NEW_PLATFORM_H_ */ | ||