diff options
Diffstat (limited to 'src/ui/chat.c')
-rw-r--r-- | src/ui/chat.c | 131 |
1 files changed, 126 insertions, 5 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 | } | ||