diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/chat.c | 131 | ||||
-rw-r--r-- | src/ui/chat.h | 28 | ||||
-rw-r--r-- | src/ui/chat_entry.c | 6 | ||||
-rw-r--r-- | src/ui/file_load_entry.c | 90 | ||||
-rw-r--r-- | src/ui/file_load_entry.h | 56 | ||||
-rw-r--r-- | src/ui/new_contact.c | 2 | ||||
-rw-r--r-- | src/ui/send_file.c | 52 |
7 files changed, 346 insertions, 19 deletions
diff --git a/src/ui/chat.c b/src/ui/chat.c index 71f7ebc..0039a5d 100644 --- a/src/ui/chat.c +++ b/src/ui/chat.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021--2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <gdk/gdkkeysyms.h> | 27 | #include <gdk/gdkkeysyms.h> |
28 | 28 | ||
29 | #include "file_load_entry.h" | ||
29 | #include "message.h" | 30 | #include "message.h" |
30 | #include "messenger.h" | 31 | #include "messenger.h" |
31 | #include "picker.h" | 32 | #include "picker.h" |
@@ -40,11 +41,22 @@ handle_flap_via_button_click(UNUSED GtkButton *button, | |||
40 | { | 41 | { |
41 | HdyFlap *flap = HDY_FLAP(user_data); | 42 | HdyFlap *flap = HDY_FLAP(user_data); |
42 | 43 | ||
43 | if (TRUE == hdy_flap_get_reveal_flap(flap)) { | 44 | if (TRUE == hdy_flap_get_reveal_flap(flap)) |
44 | hdy_flap_set_reveal_flap(flap, FALSE); | 45 | hdy_flap_set_reveal_flap(flap, FALSE); |
45 | } else { | 46 | else |
46 | hdy_flap_set_reveal_flap(flap, TRUE); | 47 | hdy_flap_set_reveal_flap(flap, TRUE); |
47 | } | 48 | } |
49 | |||
50 | static void | ||
51 | handle_popover_via_button_click(UNUSED GtkButton *button, | ||
52 | gpointer user_data) | ||
53 | { | ||
54 | GtkPopover *popover = GTK_POPOVER(user_data); | ||
55 | |||
56 | if (gtk_widget_is_visible(GTK_WIDGET(popover))) | ||
57 | gtk_popover_popdown(popover); | ||
58 | else | ||
59 | gtk_popover_popup(popover); | ||
48 | } | 60 | } |
49 | 61 | ||
50 | static void | 62 | static void |
@@ -273,12 +285,16 @@ handle_picker_button_click(UNUSED GtkButton *button, | |||
273 | UI_CHAT_Handle* | 285 | UI_CHAT_Handle* |
274 | ui_chat_new(MESSENGER_Application *app) | 286 | ui_chat_new(MESSENGER_Application *app) |
275 | { | 287 | { |
288 | GNUNET_assert(app); | ||
289 | |||
276 | UI_CHAT_Handle *handle = g_malloc(sizeof(UI_CHAT_Handle)); | 290 | UI_CHAT_Handle *handle = g_malloc(sizeof(UI_CHAT_Handle)); |
277 | UI_MESSENGER_Handle *messenger = &(app->ui.messenger); | 291 | UI_MESSENGER_Handle *messenger = &(app->ui.messenger); |
278 | 292 | ||
279 | handle->messages = NULL; | 293 | handle->messages = NULL; |
280 | handle->edge_value = 0; | 294 | handle->edge_value = 0; |
281 | 295 | ||
296 | handle->loads = NULL; | ||
297 | |||
282 | handle->builder = gtk_builder_new_from_resource( | 298 | handle->builder = gtk_builder_new_from_resource( |
283 | application_get_resource_path(app, "ui/chat.ui") | 299 | application_get_resource_path(app, "ui/chat.ui") |
284 | ); | 300 | ); |
@@ -318,6 +334,25 @@ ui_chat_new(MESSENGER_Application *app) | |||
318 | gtk_builder_get_object(handle->builder, "chat_subtitle") | 334 | gtk_builder_get_object(handle->builder, "chat_subtitle") |
319 | ); | 335 | ); |
320 | 336 | ||
337 | handle->chat_load_button = GTK_BUTTON( | ||
338 | gtk_builder_get_object(handle->builder, "chat_load_button") | ||
339 | ); | ||
340 | |||
341 | handle->chat_load_popover = GTK_POPOVER( | ||
342 | gtk_builder_get_object(handle->builder, "chat_load_popover") | ||
343 | ); | ||
344 | |||
345 | handle->chat_load_listbox = GTK_LIST_BOX( | ||
346 | gtk_builder_get_object(handle->builder, "chat_load_listbox") | ||
347 | ); | ||
348 | |||
349 | g_signal_connect( | ||
350 | handle->chat_load_button, | ||
351 | "clicked", | ||
352 | G_CALLBACK(handle_popover_via_button_click), | ||
353 | handle->chat_load_popover | ||
354 | ); | ||
355 | |||
321 | handle->chat_details_button = GTK_BUTTON( | 356 | handle->chat_details_button = GTK_BUTTON( |
322 | gtk_builder_get_object(handle->builder, "chat_details_button") | 357 | gtk_builder_get_object(handle->builder, "chat_details_button") |
323 | ); | 358 | ); |
@@ -505,6 +540,8 @@ ui_chat_update(UI_CHAT_Handle *handle, | |||
505 | MESSENGER_Application *app, | 540 | MESSENGER_Application *app, |
506 | const struct GNUNET_CHAT_Context* context) | 541 | const struct GNUNET_CHAT_Context* context) |
507 | { | 542 | { |
543 | GNUNET_assert((handle) && (app) && (context)); | ||
544 | |||
508 | const struct GNUNET_CHAT_Contact* contact; | 545 | const struct GNUNET_CHAT_Contact* contact; |
509 | const struct GNUNET_CHAT_Group* group; | 546 | const struct GNUNET_CHAT_Group* group; |
510 | 547 | ||
@@ -586,7 +623,7 @@ ui_chat_update(UI_CHAT_Handle *handle, | |||
586 | gtk_widget_set_sensitive(GTK_WIDGET(handle->emoji_button), activated); | 623 | gtk_widget_set_sensitive(GTK_WIDGET(handle->emoji_button), activated); |
587 | gtk_widget_set_sensitive(GTK_WIDGET(handle->send_record_button), activated); | 624 | gtk_widget_set_sensitive(GTK_WIDGET(handle->send_record_button), activated); |
588 | 625 | ||
589 | if (!handle->messages) | 626 | if (!(handle->messages)) |
590 | return; | 627 | return; |
591 | 628 | ||
592 | UI_MESSAGE_Handle *message = ( | 629 | UI_MESSAGE_Handle *message = ( |
@@ -602,6 +639,8 @@ ui_chat_update(UI_CHAT_Handle *handle, | |||
602 | void | 639 | void |
603 | ui_chat_delete(UI_CHAT_Handle *handle) | 640 | ui_chat_delete(UI_CHAT_Handle *handle) |
604 | { | 641 | { |
642 | GNUNET_assert(handle); | ||
643 | |||
605 | ui_picker_delete(handle->picker); | 644 | ui_picker_delete(handle->picker); |
606 | 645 | ||
607 | g_object_unref(handle->builder); | 646 | g_object_unref(handle->builder); |
@@ -615,8 +654,90 @@ ui_chat_delete(UI_CHAT_Handle *handle) | |||
615 | list = list->next; | 654 | list = list->next; |
616 | } | 655 | } |
617 | 656 | ||
657 | list = handle->loads; | ||
658 | |||
659 | while (list) { | ||
660 | if (list->data) | ||
661 | ui_file_load_entry_delete((UI_FILE_LOAD_ENTRY_Handle*) list->data); | ||
662 | |||
663 | list = list->next; | ||
664 | } | ||
665 | |||
618 | if (handle->messages) | 666 | if (handle->messages) |
619 | g_list_free(handle->messages); | 667 | g_list_free(handle->messages); |
620 | 668 | ||
669 | if (handle->loads) | ||
670 | g_list_free(handle->loads); | ||
671 | |||
621 | g_free(handle); | 672 | g_free(handle); |
622 | } | 673 | } |
674 | |||
675 | void | ||
676 | ui_chat_add_message(UI_CHAT_Handle *handle, | ||
677 | UI_MESSAGE_Handle *message) | ||
678 | { | ||
679 | GNUNET_assert((handle) && (message)); | ||
680 | |||
681 | gtk_container_add( | ||
682 | GTK_CONTAINER(handle->messages_listbox), | ||
683 | message->message_box | ||
684 | ); | ||
685 | |||
686 | handle->messages = g_list_prepend(handle->messages, message); | ||
687 | } | ||
688 | |||
689 | void | ||
690 | ui_chat_remove_message(UI_CHAT_Handle *handle, | ||
691 | UI_MESSAGE_Handle *message) | ||
692 | { | ||
693 | GNUNET_assert((handle) && (message)); | ||
694 | |||
695 | handle->messages = g_list_remove(handle->messages, message); | ||
696 | |||
697 | gtk_container_remove( | ||
698 | GTK_CONTAINER(handle->messages_listbox), | ||
699 | gtk_widget_get_parent(GTK_WIDGET(message->message_box)) | ||
700 | ); | ||
701 | } | ||
702 | |||
703 | void | ||
704 | ui_chat_add_file_load(UI_CHAT_Handle *handle, | ||
705 | UI_FILE_LOAD_ENTRY_Handle *file_load) | ||
706 | { | ||
707 | GNUNET_assert((handle) && (file_load)); | ||
708 | |||
709 | gtk_container_add( | ||
710 | GTK_CONTAINER(handle->chat_load_listbox), | ||
711 | file_load->entry_box | ||
712 | ); | ||
713 | |||
714 | handle->loads = g_list_append(handle->loads, file_load); | ||
715 | |||
716 | gtk_widget_show(GTK_WIDGET(handle->chat_load_button)); | ||
717 | |||
718 | file_load->chat = handle; | ||
719 | } | ||
720 | |||
721 | void | ||
722 | ui_chat_remove_file_load(UI_CHAT_Handle *handle, | ||
723 | UI_FILE_LOAD_ENTRY_Handle *file_load) | ||
724 | { | ||
725 | GNUNET_assert((handle) && (file_load) && (handle == file_load->chat)); | ||
726 | |||
727 | handle->loads = g_list_remove(handle->loads, file_load); | ||
728 | |||
729 | gtk_container_remove( | ||
730 | GTK_CONTAINER(handle->chat_load_listbox), | ||
731 | gtk_widget_get_parent(GTK_WIDGET(file_load->entry_box)) | ||
732 | ); | ||
733 | |||
734 | if (handle->loads) | ||
735 | return; | ||
736 | |||
737 | if (gtk_widget_is_visible(GTK_WIDGET(handle->chat_load_popover))) | ||
738 | gtk_popover_popdown(handle->chat_load_popover); | ||
739 | |||
740 | gtk_widget_hide(GTK_WIDGET(handle->chat_load_button)); | ||
741 | |||
742 | file_load->chat = NULL; | ||
743 | } | ||
diff --git a/src/ui/chat.h b/src/ui/chat.h index 6619506..6ce6064 100644 --- a/src/ui/chat.h +++ b/src/ui/chat.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021--2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -32,13 +32,17 @@ | |||
32 | #include <gnunet/gnunet_chat_lib.h> | 32 | #include <gnunet/gnunet_chat_lib.h> |
33 | 33 | ||
34 | typedef struct MESSENGER_Application MESSENGER_Application; | 34 | typedef struct MESSENGER_Application MESSENGER_Application; |
35 | typedef struct UI_MESSAGE_Handle UI_MESSAGE_Handle; | ||
35 | typedef struct UI_PICKER_Handle UI_PICKER_Handle; | 36 | typedef struct UI_PICKER_Handle UI_PICKER_Handle; |
37 | typedef struct UI_FILE_LOAD_ENTRY_Handle UI_FILE_LOAD_ENTRY_Handle; | ||
36 | 38 | ||
37 | typedef struct UI_CHAT_Handle | 39 | typedef struct UI_CHAT_Handle |
38 | { | 40 | { |
39 | GList *messages; | 41 | GList *messages; |
40 | gdouble edge_value; | 42 | gdouble edge_value; |
41 | 43 | ||
44 | GList *loads; | ||
45 | |||
42 | GtkBuilder *builder; | 46 | GtkBuilder *builder; |
43 | GtkWidget *chat_box; | 47 | GtkWidget *chat_box; |
44 | 48 | ||
@@ -48,8 +52,12 @@ typedef struct UI_CHAT_Handle | |||
48 | 52 | ||
49 | GtkLabel *chat_title; | 53 | GtkLabel *chat_title; |
50 | GtkLabel *chat_subtitle; | 54 | GtkLabel *chat_subtitle; |
51 | GtkButton *chat_details_button; | ||
52 | 55 | ||
56 | GtkButton *chat_load_button; | ||
57 | GtkPopover *chat_load_popover; | ||
58 | GtkListBox *chat_load_listbox; | ||
59 | |||
60 | GtkButton *chat_details_button; | ||
53 | GtkLabel *chat_details_label; | 61 | GtkLabel *chat_details_label; |
54 | GtkButton *hide_chat_details_button; | 62 | GtkButton *hide_chat_details_button; |
55 | GtkBox *chat_details_contacts_box; | 63 | GtkBox *chat_details_contacts_box; |
@@ -81,4 +89,20 @@ ui_chat_update(UI_CHAT_Handle *handle, | |||
81 | void | 89 | void |
82 | ui_chat_delete(UI_CHAT_Handle *handle); | 90 | ui_chat_delete(UI_CHAT_Handle *handle); |
83 | 91 | ||
92 | void | ||
93 | ui_chat_add_message(UI_CHAT_Handle *handle, | ||
94 | UI_MESSAGE_Handle *message); | ||
95 | |||
96 | void | ||
97 | ui_chat_remove_message(UI_CHAT_Handle *handle, | ||
98 | UI_MESSAGE_Handle *message); | ||
99 | |||
100 | void | ||
101 | ui_chat_add_file_load(UI_CHAT_Handle *handle, | ||
102 | UI_FILE_LOAD_ENTRY_Handle *file_load); | ||
103 | |||
104 | void | ||
105 | ui_chat_remove_file_load(UI_CHAT_Handle *handle, | ||
106 | UI_FILE_LOAD_ENTRY_Handle *file_load); | ||
107 | |||
84 | #endif /* UI_CHAT_H_ */ | 108 | #endif /* UI_CHAT_H_ */ |
diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c index 1dabec8..c065fc7 100644 --- a/src/ui/chat_entry.c +++ b/src/ui/chat_entry.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021--2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -100,12 +100,12 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, | |||
100 | hdy_avatar_set_text(handle->entry_avatar, title); | 100 | hdy_avatar_set_text(handle->entry_avatar, title); |
101 | } | 101 | } |
102 | 102 | ||
103 | if (!handle->chat) | 103 | if (!(handle->chat)) |
104 | return; | 104 | return; |
105 | 105 | ||
106 | ui_chat_update(handle->chat, app, context); | 106 | ui_chat_update(handle->chat, app, context); |
107 | 107 | ||
108 | if (!handle->chat->messages) | 108 | if (!(handle->chat->messages)) |
109 | return; | 109 | return; |
110 | 110 | ||
111 | UI_MESSAGE_Handle *message = ( | 111 | UI_MESSAGE_Handle *message = ( |
diff --git a/src/ui/file_load_entry.c b/src/ui/file_load_entry.c new file mode 100644 index 0000000..a722787 --- /dev/null +++ b/src/ui/file_load_entry.c | |||
@@ -0,0 +1,90 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2022 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/file_load_entry.c | ||
23 | */ | ||
24 | |||
25 | #include "file_load_entry.h" | ||
26 | |||
27 | #include "../application.h" | ||
28 | |||
29 | #include "chat.h" | ||
30 | |||
31 | static void | ||
32 | handle_cancel_button_click(GNUNET_UNUSED GtkButton *button, | ||
33 | gpointer user_data) | ||
34 | { | ||
35 | UI_FILE_LOAD_ENTRY_Handle* handle = (UI_FILE_LOAD_ENTRY_Handle*) user_data; | ||
36 | |||
37 | if (handle->chat) | ||
38 | ui_chat_remove_file_load(handle->chat, handle); | ||
39 | |||
40 | // TODO: cancel upload? | ||
41 | } | ||
42 | |||
43 | UI_FILE_LOAD_ENTRY_Handle* | ||
44 | ui_file_load_entry_new(MESSENGER_Application *app) | ||
45 | { | ||
46 | UI_FILE_LOAD_ENTRY_Handle* handle = g_malloc(sizeof(UI_FILE_LOAD_ENTRY_Handle)); | ||
47 | |||
48 | handle->chat = NULL; | ||
49 | |||
50 | handle->builder = gtk_builder_new_from_resource( | ||
51 | application_get_resource_path(app, "ui/file_load_entry.ui") | ||
52 | ); | ||
53 | |||
54 | handle->entry_box = GTK_WIDGET( | ||
55 | gtk_builder_get_object(handle->builder, "entry_box") | ||
56 | ); | ||
57 | |||
58 | handle->file_image = GTK_IMAGE( | ||
59 | gtk_builder_get_object(handle->builder, "file_image") | ||
60 | ); | ||
61 | |||
62 | handle->file_label = GTK_LABEL( | ||
63 | gtk_builder_get_object(handle->builder, "file_label") | ||
64 | ); | ||
65 | |||
66 | handle->load_progress_bar = GTK_PROGRESS_BAR( | ||
67 | gtk_builder_get_object(handle->builder, "load_progress_bar") | ||
68 | ); | ||
69 | |||
70 | handle->cancel_button = GTK_BUTTON( | ||
71 | gtk_builder_get_object(handle->builder, "cancel_button") | ||
72 | ); | ||
73 | |||
74 | g_signal_connect( | ||
75 | handle->cancel_button, | ||
76 | "clicked", | ||
77 | G_CALLBACK(handle_cancel_button_click), | ||
78 | handle | ||
79 | ); | ||
80 | |||
81 | return handle; | ||
82 | } | ||
83 | |||
84 | void | ||
85 | ui_file_load_entry_delete(UI_FILE_LOAD_ENTRY_Handle *handle) | ||
86 | { | ||
87 | g_object_unref(handle->builder); | ||
88 | |||
89 | g_free(handle); | ||
90 | } | ||
diff --git a/src/ui/file_load_entry.h b/src/ui/file_load_entry.h new file mode 100644 index 0000000..f24d3d5 --- /dev/null +++ b/src/ui/file_load_entry.h | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2022 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/file_load_entry.h | ||
23 | */ | ||
24 | |||
25 | #ifndef UI_FILE_LOAD_ENTRY_H_ | ||
26 | #define UI_FILE_LOAD_ENTRY_H_ | ||
27 | |||
28 | #include <gnunet/gnunet_chat_lib.h> | ||
29 | |||
30 | #include "messenger.h" | ||
31 | |||
32 | typedef struct UI_CHAT_Handle UI_CHAT_Handle; | ||
33 | |||
34 | typedef struct UI_FILE_LOAD_ENTRY_Handle | ||
35 | { | ||
36 | UI_CHAT_Handle *chat; | ||
37 | |||
38 | GtkBuilder *builder; | ||
39 | |||
40 | GtkWidget *entry_box; | ||
41 | |||
42 | GtkImage *file_image; | ||
43 | GtkLabel *file_label; | ||
44 | |||
45 | GtkProgressBar *load_progress_bar; | ||
46 | |||
47 | GtkButton *cancel_button; | ||
48 | } UI_FILE_LOAD_ENTRY_Handle; | ||
49 | |||
50 | UI_FILE_LOAD_ENTRY_Handle* | ||
51 | ui_file_load_entry_new(MESSENGER_Application *app); | ||
52 | |||
53 | void | ||
54 | ui_file_load_entry_delete(UI_FILE_LOAD_ENTRY_Handle *handle); | ||
55 | |||
56 | #endif /* UI_FILE_LOAD_ENTRY_H_ */ | ||
diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c index 2a030fe..0713aa9 100644 --- a/src/ui/new_contact.c +++ b/src/ui/new_contact.c | |||
@@ -68,7 +68,7 @@ handle_id_drawing_area_draw(GtkWidget* drawing_area, | |||
68 | 68 | ||
69 | GdkPixbuf *image = NULL; | 69 | GdkPixbuf *image = NULL; |
70 | 70 | ||
71 | if (!handle->image) | 71 | if (!(handle->image)) |
72 | return FALSE; | 72 | return FALSE; |
73 | 73 | ||
74 | uint w, h; | 74 | uint w, h; |
diff --git a/src/ui/send_file.c b/src/ui/send_file.c index 7e1e270..d998e24 100644 --- a/src/ui/send_file.c +++ b/src/ui/send_file.c | |||
@@ -24,7 +24,12 @@ | |||
24 | 24 | ||
25 | #include "send_file.h" | 25 | #include "send_file.h" |
26 | 26 | ||
27 | #include "chat.h" | ||
28 | #include "chat_entry.h" | ||
29 | #include "file_load_entry.h" | ||
30 | |||
27 | #include "../application.h" | 31 | #include "../application.h" |
32 | #include "../file.h" | ||
28 | 33 | ||
29 | static void | 34 | static void |
30 | handle_cancel_button_click(UNUSED GtkButton *button, | 35 | handle_cancel_button_click(UNUSED GtkButton *button, |
@@ -36,11 +41,21 @@ handle_cancel_button_click(UNUSED GtkButton *button, | |||
36 | 41 | ||
37 | static void | 42 | static void |
38 | handle_sending_upload_file(UNUSED void *cls, | 43 | handle_sending_upload_file(UNUSED void *cls, |
39 | UNUSED const struct GNUNET_CHAT_File *file, | 44 | const struct GNUNET_CHAT_File *file, |
40 | uint64_t completed, | 45 | uint64_t completed, |
41 | uint64_t size) | 46 | uint64_t size) |
42 | { | 47 | { |
43 | printf("UPLOAD: %lu / %lu\n", completed, size); | 48 | UI_FILE_LOAD_ENTRY_Handle *file_load = cls; |
49 | |||
50 | gtk_progress_bar_set_fraction( | ||
51 | file_load->load_progress_bar, | ||
52 | 1.0 * completed / size | ||
53 | ); | ||
54 | |||
55 | file_update_upload_info(file, completed, size); | ||
56 | |||
57 | if ((completed >= size) && (file_load->chat)) | ||
58 | ui_chat_remove_file_load(file_load->chat, file_load); | ||
44 | } | 59 | } |
45 | 60 | ||
46 | static void | 61 | static void |
@@ -67,17 +82,38 @@ handle_send_button_click(GtkButton *button, | |||
67 | app->ui.bindings, text_view | 82 | app->ui.bindings, text_view |
68 | ); | 83 | ); |
69 | 84 | ||
70 | if (context) | 85 | UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(context); |
71 | GNUNET_CHAT_context_send_file( | 86 | UI_CHAT_Handle *handle = entry? entry->chat : NULL; |
87 | |||
88 | struct GNUNET_CHAT_File *file = NULL; | ||
89 | |||
90 | if ((context) && (handle)) | ||
91 | { | ||
92 | UI_FILE_LOAD_ENTRY_Handle *file_load = ui_file_load_entry_new(app); | ||
93 | |||
94 | gtk_label_set_text(file_load->file_label, filename); | ||
95 | gtk_progress_bar_set_fraction(file_load->load_progress_bar, 0.0); | ||
96 | |||
97 | ui_chat_add_file_load(handle, file_load); | ||
98 | |||
99 | file = GNUNET_CHAT_context_send_file( | ||
72 | context, | 100 | context, |
73 | filename, | 101 | filename, |
74 | handle_sending_upload_file, | 102 | handle_sending_upload_file, |
75 | NULL | 103 | file_load |
76 | ); | 104 | ); |
105 | } | ||
77 | 106 | ||
78 | g_free(filename); | 107 | g_free(filename); |
79 | 108 | ||
80 | gtk_window_close(GTK_WINDOW(app->ui.send_file.dialog)); | 109 | gtk_window_close(GTK_WINDOW(app->ui.send_file.dialog)); |
110 | |||
111 | if (!file) | ||
112 | return; | ||
113 | |||
114 | file_create_info(file); | ||
115 | |||
116 | // TODO: create UI component? | ||
81 | } | 117 | } |
82 | 118 | ||
83 | static void | 119 | static void |
@@ -117,7 +153,7 @@ handle_file_drawing_area_draw(GtkWidget* drawing_area, | |||
117 | 153 | ||
118 | GdkPixbuf *image = handle->image; | 154 | GdkPixbuf *image = handle->image; |
119 | 155 | ||
120 | if (!handle->animation) | 156 | if (!(handle->animation)) |
121 | goto render_image; | 157 | goto render_image; |
122 | 158 | ||
123 | if (handle->animation_iter) | 159 | if (handle->animation_iter) |
@@ -219,7 +255,7 @@ handle_file_chooser_button_file_set(GtkFileChooserButton *file_chooser_button, | |||
219 | { | 255 | { |
220 | handle->animation = gdk_pixbuf_animation_new_from_file(filename, NULL); | 256 | handle->animation = gdk_pixbuf_animation_new_from_file(filename, NULL); |
221 | 257 | ||
222 | if (!handle->animation) | 258 | if (!(handle->animation)) |
223 | handle->image = gdk_pixbuf_new_from_file(filename, NULL); | 259 | handle->image = gdk_pixbuf_new_from_file(filename, NULL); |
224 | 260 | ||
225 | g_free(filename); | 261 | g_free(filename); |
@@ -313,7 +349,7 @@ void | |||
313 | ui_send_file_dialog_update(UI_SEND_FILE_Handle *handle, | 349 | ui_send_file_dialog_update(UI_SEND_FILE_Handle *handle, |
314 | const gchar *filename) | 350 | const gchar *filename) |
315 | { | 351 | { |
316 | if (!handle->file_chooser_button) | 352 | if (!(handle->file_chooser_button)) |
317 | return; | 353 | return; |
318 | 354 | ||
319 | gtk_file_chooser_set_filename( | 355 | gtk_file_chooser_set_filename( |