From 51a23728694a3f1312cc9396fc093ca178457c3c Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 22 Apr 2020 15:44:12 +0200 Subject: [PATCH] Add file upload preview fixes #756 --- libdino/src/service/file_manager.vala | 12 +- .../src/service/jingle_file_transfers.vala | 11 ++ main/CMakeLists.txt | 3 + .../image_toolbar.ui | 2 +- main/data/conversation_view.ui | 120 +++++++++------- main/data/file_default_widget.ui | 1 - main/data/file_send_overlay.ui | 97 +++++++++++++ main/data/theme.css | 14 +- .../ui/chat_input/chat_input_controller.vala | 15 +- main/src/ui/chat_input/view.vala | 17 +-- .../conversation_item_skeleton.vala | 4 +- .../file_default_widget.vala | 4 +- .../file_image_widget.vala | 86 ++++++++++++ .../file_widget.vala | 129 ++++++------------ main/src/ui/conversation_view.vala | 27 +++- main/src/ui/conversation_view_controller.vala | 69 +++++++++- main/src/ui/file_send_overlay.vala | 88 ++++++++++++ main/src/ui/util/helper.vala | 2 +- main/src/ui/util/scaling_image.vala | 70 +++++++--- main/src/ui/util/sizing_bin.vala | 4 +- plugins/http-files/src/file_sender.vala | 8 ++ 21 files changed, 588 insertions(+), 195 deletions(-) create mode 100644 main/data/file_send_overlay.ui create mode 100644 main/src/ui/conversation_content_view/file_image_widget.vala create mode 100644 main/src/ui/file_send_overlay.vala diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala index 20540e6e..00abe517 100644 --- a/libdino/src/service/file_manager.vala +++ b/libdino/src/service/file_manager.vala @@ -38,7 +38,15 @@ public class FileManager : StreamInteractionModule, Object { this.add_sender(new JingleFileSender(stream_interactor)); } - public async void send_file(string uri, Conversation conversation) { + public HashMap get_file_size_limits(Conversation conversation) { + HashMap ret = new HashMap(); + foreach (FileSender sender in file_senders) { + ret[sender.get_id()] = sender.get_file_size_limit(conversation); + } + return ret; + } + + public async void send_file(File file, Conversation conversation) { FileTransfer file_transfer = new FileTransfer(); file_transfer.account = conversation.account; file_transfer.counterpart = conversation.counterpart; @@ -53,7 +61,6 @@ public class FileManager : StreamInteractionModule, Object { file_transfer.encryption = conversation.encryption; try { - File file = File.new_for_path(uri); FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); file_transfer.file_name = file_info.get_display_name(); file_transfer.mime_type = file_info.get_content_type(); @@ -394,6 +401,7 @@ public interface FileSender : Object { public signal void upload_available(Account account); public abstract bool is_upload_available(Conversation conversation); + public abstract long get_file_size_limit(Conversation conversation); public abstract bool can_send(Conversation conversation, FileTransfer file_transfer); public abstract async FileSendData? prepare_send_file(Conversation conversation, FileTransfer file_transfer, FileMeta file_meta) throws FileSendError; public abstract async void send_file(Conversation conversation, FileTransfer file_transfer, FileSendData file_send_data, FileMeta file_meta) throws FileSendError; diff --git a/libdino/src/service/jingle_file_transfers.vala b/libdino/src/service/jingle_file_transfers.vala index 3a5fa95e..4c3646b3 100644 --- a/libdino/src/service/jingle_file_transfers.vala +++ b/libdino/src/service/jingle_file_transfers.vala @@ -164,7 +164,18 @@ public class JingleFileSender : FileSender, Object { return false; } + public long get_file_size_limit(Conversation conversation) { + if (can_send_(conversation)) { + return int.MAX; + } + return -1; + } + public bool can_send(Conversation conversation, FileTransfer file_transfer) { + return can_send_(conversation); + } + + private bool can_send_(Conversation conversation) { if (conversation.type_ != Conversation.Type.CHAT) return false; // No file specific restrictions apply to Jingle file transfers diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 278daf76..2a247ba9 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -51,6 +51,7 @@ set(RESOURCE_LIST conversation_row.ui conversation_view.ui file_default_widget.ui + file_send_overlay.ui emojichooser.ui global_search.ui conversation_content_view/image_toolbar.ui @@ -104,6 +105,7 @@ SOURCES src/ui/conversation_list_titlebar.vala src/ui/conversation_view.vala src/ui/conversation_view_controller.vala + src/ui/file_send_overlay.vala src/ui/global_search.vala src/ui/notifications.vala src/ui/settings_dialog.vala @@ -142,6 +144,7 @@ SOURCES src/ui/conversation_content_view/conversation_view.vala src/ui/conversation_content_view/date_separator_populator.vala src/ui/conversation_content_view/file_default_widget.vala + src/ui/conversation_content_view/file_image_widget.vala src/ui/conversation_content_view/file_widget.vala src/ui/conversation_content_view/message_widget.vala src/ui/conversation_content_view/subscription_notification.vala diff --git a/main/data/conversation_content_view/image_toolbar.ui b/main/data/conversation_content_view/image_toolbar.ui index 562f944b..4046658b 100644 --- a/main/data/conversation_content_view/image_toolbar.ui +++ b/main/data/conversation_content_view/image_toolbar.ui @@ -13,7 +13,7 @@ True - 25 + 18 middle True 5 diff --git a/main/data/conversation_view.ui b/main/data/conversation_view.ui index df9df7e0..3c157960 100644 --- a/main/data/conversation_view.ui +++ b/main/data/conversation_view.ui @@ -1,54 +1,76 @@ -