diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-18 00:52:46 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-18 00:52:46 +0100 |
commit | af8c864f72b0beafbd63c063bf257069af830b21 (patch) | |
tree | d29a00e708181ba289a9a9da2f6c3a5b41bcdc35 | |
parent | fbeb2aa851dee6cfb83cea0b044df609e029f46c (diff) | |
download | messenger-gtk-af8c864f72b0beafbd63c063bf257069af830b21.tar.gz messenger-gtk-af8c864f72b0beafbd63c063bf257069af830b21.zip |
Added dialog to send files
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | resources/ui/send_file.ui | 113 | ||||
-rw-r--r-- | src/application.h | 4 | ||||
-rw-r--r-- | src/event.c | 4 | ||||
-rw-r--r-- | src/ui/chat.c | 82 | ||||
-rw-r--r-- | src/ui/contacts.c | 2 | ||||
-rw-r--r-- | src/ui/new_contact.c | 2 | ||||
-rw-r--r-- | src/ui/new_group.c | 2 | ||||
-rw-r--r-- | src/ui/new_group.h | 2 | ||||
-rw-r--r-- | src/ui/new_platform.c | 2 | ||||
-rw-r--r-- | src/ui/new_profile.c | 2 | ||||
-rw-r--r-- | src/ui/send_file.c | 148 | ||||
-rw-r--r-- | src/ui/send_file.h | 55 |
13 files changed, 403 insertions, 16 deletions
@@ -20,6 +20,7 @@ SOURCES = messenger_gtk.c\ | |||
20 | ui/new_profile.c\ | 20 | ui/new_profile.c\ |
21 | ui/picker.c\ | 21 | ui/picker.c\ |
22 | ui/profile_entry.c\ | 22 | ui/profile_entry.c\ |
23 | ui/send_file.c\ | ||
23 | ui/settings.c | 24 | ui/settings.c |
24 | 25 | ||
25 | HEADERS = | 26 | HEADERS = |
diff --git a/resources/ui/send_file.ui b/resources/ui/send_file.ui new file mode 100644 index 0000000..38bd5e8 --- /dev/null +++ b/resources/ui/send_file.ui | |||
@@ -0,0 +1,113 @@ | |||
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 | <object class="GtkDialog" id="send_file_dialog"> | ||
26 | <property name="can-focus">False</property> | ||
27 | <property name="modal">True</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="send_button"> | ||
54 | <property name="label" translatable="yes">Send</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="border-width">8</property> | ||
77 | <property name="orientation">vertical</property> | ||
78 | <property name="spacing">4</property> | ||
79 | <child> | ||
80 | <object class="GtkDrawingArea" id="file_drawing_area"> | ||
81 | <property name="height-request">250</property> | ||
82 | <property name="visible">True</property> | ||
83 | <property name="can-focus">False</property> | ||
84 | </object> | ||
85 | <packing> | ||
86 | <property name="expand">True</property> | ||
87 | <property name="fill">True</property> | ||
88 | <property name="position">1</property> | ||
89 | </packing> | ||
90 | </child> | ||
91 | <child> | ||
92 | <object class="GtkFileChooserButton" id="file_chooser_button"> | ||
93 | <property name="visible">True</property> | ||
94 | <property name="can-focus">False</property> | ||
95 | <property name="title" translatable="yes"/> | ||
96 | </object> | ||
97 | <packing> | ||
98 | <property name="expand">False</property> | ||
99 | <property name="fill">True</property> | ||
100 | <property name="position">2</property> | ||
101 | </packing> | ||
102 | </child> | ||
103 | </object> | ||
104 | <packing> | ||
105 | <property name="expand">True</property> | ||
106 | <property name="fill">True</property> | ||
107 | <property name="position">1</property> | ||
108 | </packing> | ||
109 | </child> | ||
110 | </object> | ||
111 | </child> | ||
112 | </object> | ||
113 | </interface> | ||
diff --git a/src/application.h b/src/application.h index 125b294..f8bfc6b 100644 --- a/src/application.h +++ b/src/application.h | |||
@@ -36,6 +36,7 @@ | |||
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/new_profile.h" |
39 | #include "ui/send_file.h" | ||
39 | #include "ui/settings.h" | 40 | #include "ui/settings.h" |
40 | 41 | ||
41 | #include "util.h" | 42 | #include "util.h" |
@@ -72,10 +73,13 @@ typedef struct MESSENGER_Application | |||
72 | 73 | ||
73 | UI_MESSENGER_Handle messenger; | 74 | UI_MESSENGER_Handle messenger; |
74 | 75 | ||
76 | UI_SEND_FILE_Handle send_file; | ||
77 | |||
75 | UI_NEW_CONTACT_Handle new_contact; | 78 | UI_NEW_CONTACT_Handle new_contact; |
76 | UI_NEW_GROUP_Handle new_group; | 79 | UI_NEW_GROUP_Handle new_group; |
77 | UI_NEW_PLATFORM_Handle new_platform; | 80 | UI_NEW_PLATFORM_Handle new_platform; |
78 | UI_NEW_PROFILE_Handle new_profile; | 81 | UI_NEW_PROFILE_Handle new_profile; |
82 | |||
79 | UI_CONTACTS_Handle contacts; | 83 | UI_CONTACTS_Handle contacts; |
80 | UI_SETTINGS_Handle settings; | 84 | UI_SETTINGS_Handle settings; |
81 | } ui; | 85 | } ui; |
diff --git a/src/event.c b/src/event.c index 732d76c..b10045f 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -200,7 +200,7 @@ event_joining_contact(MESSENGER_Application *app, | |||
200 | contact_add_name_avatar_to_info(contact, message->sender_avatar); | 200 | contact_add_name_avatar_to_info(contact, message->sender_avatar); |
201 | contact_add_name_label_to_info(contact, message->sender_label); | 201 | contact_add_name_label_to_info(contact, message->sender_label); |
202 | 202 | ||
203 | gtk_label_set_text(message->text_label, "joined the chat"); | 203 | gtk_label_set_text(message->text_label, _("joined the chat")); |
204 | 204 | ||
205 | gtk_container_add( | 205 | gtk_container_add( |
206 | GTK_CONTAINER(handle->chat->messages_listbox), | 206 | GTK_CONTAINER(handle->chat->messages_listbox), |
@@ -266,7 +266,7 @@ event_invitation(UNUSED MESSENGER_Application *app, | |||
266 | contact_add_name_avatar_to_info(contact, message->sender_avatar); | 266 | contact_add_name_avatar_to_info(contact, message->sender_avatar); |
267 | contact_add_name_label_to_info(contact, message->sender_label); | 267 | contact_add_name_label_to_info(contact, message->sender_label); |
268 | 268 | ||
269 | gtk_label_set_text(message->text_label, "invited you to a chat"); | 269 | gtk_label_set_text(message->text_label, _("invited you to a chat")); |
270 | 270 | ||
271 | g_signal_connect( | 271 | g_signal_connect( |
272 | message->accept_button, | 272 | message->accept_button, |
diff --git a/src/ui/chat.c b/src/ui/chat.c index f19ee1e..c45b7b5 100644 --- a/src/ui/chat.c +++ b/src/ui/chat.c | |||
@@ -34,10 +34,10 @@ | |||
34 | #include "../contact.h" | 34 | #include "../contact.h" |
35 | 35 | ||
36 | static void | 36 | static void |
37 | handle_flap_via_button_click(UNUSED GtkButton* button, | 37 | handle_flap_via_button_click(UNUSED GtkButton *button, |
38 | gpointer user_data) | 38 | gpointer user_data) |
39 | { | 39 | { |
40 | HdyFlap* flap = HDY_FLAP(user_data); | 40 | HdyFlap *flap = HDY_FLAP(user_data); |
41 | 41 | ||
42 | if (TRUE == hdy_flap_get_reveal_flap(flap)) { | 42 | if (TRUE == hdy_flap_get_reveal_flap(flap)) { |
43 | hdy_flap_set_reveal_flap(flap, FALSE); | 43 | hdy_flap_set_reveal_flap(flap, FALSE); |
@@ -47,8 +47,8 @@ handle_flap_via_button_click(UNUSED GtkButton* button, | |||
47 | } | 47 | } |
48 | 48 | ||
49 | static void | 49 | static void |
50 | handle_chat_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, | 50 | handle_chat_contacts_listbox_row_activated(UNUSED GtkListBox *listbox, |
51 | GtkListBoxRow* row, | 51 | GtkListBoxRow *row, |
52 | gpointer user_data) | 52 | gpointer user_data) |
53 | { | 53 | { |
54 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | 54 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
@@ -79,12 +79,12 @@ handle_chat_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, | |||
79 | } | 79 | } |
80 | 80 | ||
81 | static void | 81 | static void |
82 | handle_back_button_click(UNUSED GtkButton* button, | 82 | handle_back_button_click(UNUSED GtkButton *button, |
83 | gpointer user_data) | 83 | gpointer user_data) |
84 | { | 84 | { |
85 | HdyLeaflet* leaflet = HDY_LEAFLET(user_data); | 85 | HdyLeaflet *leaflet = HDY_LEAFLET(user_data); |
86 | 86 | ||
87 | GList* children = gtk_container_get_children(GTK_CONTAINER(leaflet)); | 87 | GList *children = gtk_container_get_children(GTK_CONTAINER(leaflet)); |
88 | 88 | ||
89 | if (children) { | 89 | if (children) { |
90 | hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->data)); | 90 | hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->data)); |
@@ -92,6 +92,57 @@ handle_back_button_click(UNUSED GtkButton* button, | |||
92 | } | 92 | } |
93 | 93 | ||
94 | static void | 94 | static void |
95 | handle_attach_file_button_click(GtkButton *button, | ||
96 | gpointer user_data) | ||
97 | { | ||
98 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
99 | |||
100 | GtkTextView *text_view = GTK_TEXT_VIEW( | ||
101 | g_hash_table_lookup(app->ui.bindings, button) | ||
102 | ); | ||
103 | |||
104 | if (!text_view) | ||
105 | return; | ||
106 | |||
107 | GtkWidget *dialog = gtk_file_chooser_dialog_new( | ||
108 | _("Select file"), | ||
109 | GTK_WINDOW(app->ui.messenger.main_window), | ||
110 | GTK_FILE_CHOOSER_ACTION_OPEN, | ||
111 | _("Cancel"), | ||
112 | GTK_RESPONSE_CANCEL, | ||
113 | _("Confirm"), | ||
114 | GTK_RESPONSE_ACCEPT, | ||
115 | NULL | ||
116 | ); | ||
117 | |||
118 | if (GTK_RESPONSE_ACCEPT != gtk_dialog_run(GTK_DIALOG(dialog))) | ||
119 | goto close_dialog; | ||
120 | |||
121 | gchar *filename = gtk_file_chooser_get_filename( | ||
122 | GTK_FILE_CHOOSER(dialog) | ||
123 | ); | ||
124 | |||
125 | if (!filename) | ||
126 | return; | ||
127 | |||
128 | ui_send_file_dialog_init(app, &(app->ui.send_file)); | ||
129 | ui_send_file_dialog_update(&(app->ui.send_file), filename); | ||
130 | |||
131 | g_free(filename); | ||
132 | |||
133 | g_hash_table_insert( | ||
134 | app->ui.bindings, | ||
135 | app->ui.send_file.send_button, | ||
136 | text_view | ||
137 | ); | ||
138 | |||
139 | gtk_widget_show(GTK_WIDGET(app->ui.send_file.dialog)); | ||
140 | |||
141 | close_dialog: | ||
142 | gtk_widget_destroy(dialog); | ||
143 | } | ||
144 | |||
145 | static void | ||
95 | handle_send_text_buffer_changed(GtkTextBuffer *buffer, | 146 | handle_send_text_buffer_changed(GtkTextBuffer *buffer, |
96 | gpointer user_data) | 147 | gpointer user_data) |
97 | { | 148 | { |
@@ -128,7 +179,7 @@ _send_text_from_view(MESSENGER_Application *app, | |||
128 | return FALSE; | 179 | return FALSE; |
129 | 180 | ||
130 | struct GNUNET_CHAT_Context *context = g_hash_table_lookup( | 181 | struct GNUNET_CHAT_Context *context = g_hash_table_lookup( |
131 | app->ui.bindings, text_view | 182 | app->ui.bindings, text_view |
132 | ); | 183 | ); |
133 | 184 | ||
134 | if (context) | 185 | if (context) |
@@ -274,6 +325,13 @@ ui_chat_new(MESSENGER_Application *app) | |||
274 | gtk_builder_get_object(handle->builder, "attach_file_button") | 325 | gtk_builder_get_object(handle->builder, "attach_file_button") |
275 | ); | 326 | ); |
276 | 327 | ||
328 | g_signal_connect( | ||
329 | handle->attach_file_button, | ||
330 | "clicked", | ||
331 | G_CALLBACK(handle_attach_file_button_click), | ||
332 | app | ||
333 | ); | ||
334 | |||
277 | handle->send_text_view = GTK_TEXT_VIEW( | 335 | handle->send_text_view = GTK_TEXT_VIEW( |
278 | gtk_builder_get_object(handle->builder, "send_text_view") | 336 | gtk_builder_get_object(handle->builder, "send_text_view") |
279 | ); | 337 | ); |
@@ -317,6 +375,12 @@ ui_chat_new(MESSENGER_Application *app) | |||
317 | 375 | ||
318 | g_hash_table_insert( | 376 | g_hash_table_insert( |
319 | app->ui.bindings, | 377 | app->ui.bindings, |
378 | handle->attach_file_button, | ||
379 | handle->send_text_view | ||
380 | ); | ||
381 | |||
382 | g_hash_table_insert( | ||
383 | app->ui.bindings, | ||
320 | handle->send_record_button, | 384 | handle->send_record_button, |
321 | handle->send_text_view | 385 | handle->send_text_view |
322 | ); | 386 | ); |
@@ -398,7 +462,7 @@ ui_chat_update(UI_CHAT_Handle *handle, | |||
398 | 462 | ||
399 | g_string_append_printf( | 463 | g_string_append_printf( |
400 | subtitle, | 464 | subtitle, |
401 | "%d members", | 465 | _("%d members"), |
402 | GNUNET_CHAT_group_iterate_contacts(group, NULL, NULL) | 466 | GNUNET_CHAT_group_iterate_contacts(group, NULL, NULL) |
403 | ); | 467 | ); |
404 | } | 468 | } |
diff --git a/src/ui/contacts.c b/src/ui/contacts.c index f19c93f..fac9e62 100644 --- a/src/ui/contacts.c +++ b/src/ui/contacts.c | |||
@@ -147,7 +147,7 @@ ui_contacts_dialog_init(MESSENGER_Application *app, | |||
147 | 147 | ||
148 | gtk_window_set_title( | 148 | gtk_window_set_title( |
149 | GTK_WINDOW(handle->dialog), | 149 | GTK_WINDOW(handle->dialog), |
150 | "Contacts" | 150 | _("Contacts") |
151 | ); | 151 | ); |
152 | 152 | ||
153 | gtk_window_set_transient_for( | 153 | gtk_window_set_transient_for( |
diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c index db40140..5a74089 100644 --- a/src/ui/new_contact.c +++ b/src/ui/new_contact.c | |||
@@ -259,7 +259,7 @@ ui_new_contact_dialog_init(MESSENGER_Application *app, | |||
259 | 259 | ||
260 | gtk_window_set_title( | 260 | gtk_window_set_title( |
261 | GTK_WINDOW(handle->dialog), | 261 | GTK_WINDOW(handle->dialog), |
262 | "New Contact" | 262 | _("New Contact") |
263 | ); | 263 | ); |
264 | 264 | ||
265 | gtk_window_set_transient_for( | 265 | gtk_window_set_transient_for( |
diff --git a/src/ui/new_group.c b/src/ui/new_group.c index 3741768..e161fbb 100644 --- a/src/ui/new_group.c +++ b/src/ui/new_group.c | |||
@@ -206,7 +206,7 @@ ui_new_group_dialog_init(MESSENGER_Application *app, | |||
206 | 206 | ||
207 | gtk_window_set_title( | 207 | gtk_window_set_title( |
208 | GTK_WINDOW(handle->dialog), | 208 | GTK_WINDOW(handle->dialog), |
209 | "New Group" | 209 | _("New Group") |
210 | ); | 210 | ); |
211 | 211 | ||
212 | gtk_window_set_transient_for( | 212 | gtk_window_set_transient_for( |
diff --git a/src/ui/new_group.h b/src/ui/new_group.h index 634039e..0b8dd44 100644 --- a/src/ui/new_group.h +++ b/src/ui/new_group.h | |||
@@ -25,6 +25,8 @@ | |||
25 | #ifndef UI_NEW_GROUP_H_ | 25 | #ifndef UI_NEW_GROUP_H_ |
26 | #define UI_NEW_GROUP_H_ | 26 | #define UI_NEW_GROUP_H_ |
27 | 27 | ||
28 | #include "messenger.h" | ||
29 | |||
28 | typedef struct UI_NEW_GROUP_Handle | 30 | typedef struct UI_NEW_GROUP_Handle |
29 | { | 31 | { |
30 | GList *contact_entries; | 32 | GList *contact_entries; |
diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c index 43fadb7..dad4ad1 100644 --- a/src/ui/new_platform.c +++ b/src/ui/new_platform.c | |||
@@ -108,7 +108,7 @@ ui_new_platform_dialog_init(MESSENGER_Application *app, | |||
108 | 108 | ||
109 | gtk_window_set_title( | 109 | gtk_window_set_title( |
110 | GTK_WINDOW(handle->dialog), | 110 | GTK_WINDOW(handle->dialog), |
111 | "New Platform" | 111 | _("New Platform") |
112 | ); | 112 | ); |
113 | 113 | ||
114 | gtk_window_set_transient_for( | 114 | gtk_window_set_transient_for( |
diff --git a/src/ui/new_profile.c b/src/ui/new_profile.c index 48c2bb5..d845fdf 100644 --- a/src/ui/new_profile.c +++ b/src/ui/new_profile.c | |||
@@ -85,7 +85,7 @@ ui_new_profile_dialog_init(MESSENGER_Application *app, | |||
85 | 85 | ||
86 | gtk_window_set_title( | 86 | gtk_window_set_title( |
87 | GTK_WINDOW(handle->dialog), | 87 | GTK_WINDOW(handle->dialog), |
88 | "New Profile" | 88 | _("New Profile") |
89 | ); | 89 | ); |
90 | 90 | ||
91 | gtk_window_set_transient_for( | 91 | gtk_window_set_transient_for( |
diff --git a/src/ui/send_file.c b/src/ui/send_file.c new file mode 100644 index 0000000..cde2c4d --- /dev/null +++ b/src/ui/send_file.c | |||
@@ -0,0 +1,148 @@ | |||
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/send_file.c | ||
23 | */ | ||
24 | |||
25 | #include "send_file.h" | ||
26 | |||
27 | #include "../application.h" | ||
28 | |||
29 | static void | ||
30 | handle_cancel_button_click(UNUSED GtkButton *button, | ||
31 | gpointer user_data) | ||
32 | { | ||
33 | GtkDialog *dialog = GTK_DIALOG(user_data); | ||
34 | gtk_window_close(GTK_WINDOW(dialog)); | ||
35 | } | ||
36 | |||
37 | static void | ||
38 | handle_send_button_click(GtkButton *button, | ||
39 | gpointer user_data) | ||
40 | { | ||
41 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
42 | |||
43 | GtkTextView *text_view = GTK_TEXT_VIEW( | ||
44 | g_hash_table_lookup(app->ui.bindings, button) | ||
45 | ); | ||
46 | |||
47 | if (!text_view) | ||
48 | return; | ||
49 | |||
50 | gchar *filename = gtk_file_chooser_get_filename( | ||
51 | GTK_FILE_CHOOSER(app->ui.send_file.file_chooser_button) | ||
52 | ); | ||
53 | |||
54 | if (!filename) | ||
55 | return; | ||
56 | |||
57 | struct GNUNET_CHAT_Context *context = g_hash_table_lookup( | ||
58 | app->ui.bindings, text_view | ||
59 | ); | ||
60 | |||
61 | if (context) | ||
62 | GNUNET_CHAT_context_send_file(context, filename, NULL, NULL); // TODO: callbacks! | ||
63 | |||
64 | g_free(filename); | ||
65 | } | ||
66 | |||
67 | static void | ||
68 | handle_dialog_destroy(UNUSED GtkWidget *window, | ||
69 | gpointer user_data) | ||
70 | { | ||
71 | ui_send_file_dialog_cleanup((UI_SEND_FILE_Handle*) user_data); | ||
72 | } | ||
73 | |||
74 | void | ||
75 | ui_send_file_dialog_init(MESSENGER_Application *app, | ||
76 | UI_SEND_FILE_Handle *handle) | ||
77 | { | ||
78 | handle->builder = gtk_builder_new_from_file("resources/ui/send_file.ui"); | ||
79 | |||
80 | handle->dialog = GTK_DIALOG( | ||
81 | gtk_builder_get_object(handle->builder, "send_file_dialog") | ||
82 | ); | ||
83 | |||
84 | gtk_window_set_title( | ||
85 | GTK_WINDOW(handle->dialog), | ||
86 | _("Send File") | ||
87 | ); | ||
88 | |||
89 | gtk_window_set_transient_for( | ||
90 | GTK_WINDOW(handle->dialog), | ||
91 | GTK_WINDOW(app->ui.messenger.main_window) | ||
92 | ); | ||
93 | |||
94 | handle->file_drawing_area = GTK_DRAWING_AREA( | ||
95 | gtk_builder_get_object(handle->builder, "file_drawing_area") | ||
96 | ); | ||
97 | |||
98 | handle->file_chooser_button = GTK_FILE_CHOOSER_BUTTON( | ||
99 | gtk_builder_get_object(handle->builder, "file_chooser_button") | ||
100 | ); | ||
101 | |||
102 | handle->cancel_button = GTK_BUTTON( | ||
103 | gtk_builder_get_object(handle->builder, "cancel_button") | ||
104 | ); | ||
105 | |||
106 | g_signal_connect( | ||
107 | handle->cancel_button, | ||
108 | "clicked", | ||
109 | G_CALLBACK(handle_cancel_button_click), | ||
110 | handle->dialog | ||
111 | ); | ||
112 | |||
113 | handle->send_button = GTK_BUTTON( | ||
114 | gtk_builder_get_object(handle->builder, "send_button") | ||
115 | ); | ||
116 | |||
117 | g_signal_connect( | ||
118 | handle->send_button, | ||
119 | "clicked", | ||
120 | G_CALLBACK(handle_send_button_click), | ||
121 | app | ||
122 | ); | ||
123 | |||
124 | g_signal_connect( | ||
125 | handle->dialog, | ||
126 | "destroy", | ||
127 | G_CALLBACK(handle_dialog_destroy), | ||
128 | handle | ||
129 | ); | ||
130 | } | ||
131 | |||
132 | void | ||
133 | ui_send_file_dialog_update(UI_SEND_FILE_Handle *handle, | ||
134 | const gchar *filename) | ||
135 | { | ||
136 | if ((!filename) || (!gtk_file_chooser_set_filename( | ||
137 | GTK_FILE_CHOOSER(handle->file_chooser_button), | ||
138 | filename))) | ||
139 | return; | ||
140 | |||
141 | // TODO: update preview | ||
142 | } | ||
143 | |||
144 | void | ||
145 | ui_send_file_dialog_cleanup(UI_SEND_FILE_Handle *handle) | ||
146 | { | ||
147 | g_object_unref(handle->builder); | ||
148 | } | ||
diff --git a/src/ui/send_file.h b/src/ui/send_file.h new file mode 100644 index 0000000..cb58285 --- /dev/null +++ b/src/ui/send_file.h | |||
@@ -0,0 +1,55 @@ | |||
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/send_file.h | ||
23 | */ | ||
24 | |||
25 | #ifndef UI_SEND_FILE_H_ | ||
26 | #define UI_SEND_FILE_H_ | ||
27 | |||
28 | #include "messenger.h" | ||
29 | |||
30 | typedef struct UI_SEND_FILE_Handle | ||
31 | { | ||
32 | GList *contact_entries; | ||
33 | |||
34 | GtkBuilder *builder; | ||
35 | GtkDialog *dialog; | ||
36 | |||
37 | GtkDrawingArea *file_drawing_area; | ||
38 | GtkFileChooserButton *file_chooser_button; | ||
39 | |||
40 | GtkButton *cancel_button; | ||
41 | GtkButton *send_button; | ||
42 | } UI_SEND_FILE_Handle; | ||
43 | |||
44 | void | ||
45 | ui_send_file_dialog_init(MESSENGER_Application *app, | ||
46 | UI_SEND_FILE_Handle *handle); | ||
47 | |||
48 | void | ||
49 | ui_send_file_dialog_update(UI_SEND_FILE_Handle *handle, | ||
50 | const gchar *filename); | ||
51 | |||
52 | void | ||
53 | ui_send_file_dialog_cleanup(UI_SEND_FILE_Handle *handle); | ||
54 | |||
55 | #endif /* UI_SEND_FILE_H_ */ | ||