aboutsummaryrefslogtreecommitdiff
path: root/src/ui/send_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/send_file.c')
-rw-r--r--src/ui/send_file.c148
1 files changed, 148 insertions, 0 deletions
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
29static void
30handle_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
37static void
38handle_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
67static void
68handle_dialog_destroy(UNUSED GtkWidget *window,
69 gpointer user_data)
70{
71 ui_send_file_dialog_cleanup((UI_SEND_FILE_Handle*) user_data);
72}
73
74void
75ui_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
132void
133ui_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
144void
145ui_send_file_dialog_cleanup(UI_SEND_FILE_Handle *handle)
146{
147 g_object_unref(handle->builder);
148}