aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/application.h4
-rw-r--r--src/event.c4
-rw-r--r--src/ui/chat.c82
-rw-r--r--src/ui/contacts.c2
-rw-r--r--src/ui/new_contact.c2
-rw-r--r--src/ui/new_group.c2
-rw-r--r--src/ui/new_group.h2
-rw-r--r--src/ui/new_platform.c2
-rw-r--r--src/ui/new_profile.c2
-rw-r--r--src/ui/send_file.c148
-rw-r--r--src/ui/send_file.h55
11 files changed, 289 insertions, 16 deletions
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
36static void 36static void
37handle_flap_via_button_click(UNUSED GtkButton* button, 37handle_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
49static void 49static void
50handle_chat_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, 50handle_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
81static void 81static void
82handle_back_button_click(UNUSED GtkButton* button, 82handle_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
94static void 94static void
95handle_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
141close_dialog:
142 gtk_widget_destroy(dialog);
143}
144
145static void
95handle_send_text_buffer_changed(GtkTextBuffer *buffer, 146handle_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
28typedef struct UI_NEW_GROUP_Handle 30typedef 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
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}
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
30typedef 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
44void
45ui_send_file_dialog_init(MESSENGER_Application *app,
46 UI_SEND_FILE_Handle *handle);
47
48void
49ui_send_file_dialog_update(UI_SEND_FILE_Handle *handle,
50 const gchar *filename);
51
52void
53ui_send_file_dialog_cleanup(UI_SEND_FILE_Handle *handle);
54
55#endif /* UI_SEND_FILE_H_ */