From 60832b2fcd2b0db4fa76d975a84442182165d070 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 15 Jul 2020 20:22:29 -0400 Subject: [PATCH] Confirm uploading from path in clipboard --- TODO.md | 2 +- src/gui/Pages/Chat/Composer/UploadButton.qml | 10 +++- src/gui/Popups/ConfirmUploadPopup.qml | 62 ++++++++++++++++++++ src/gui/Utils.qml | 5 ++ src/icons/thin/confirm-uploading-file.svg | 3 + 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/gui/Popups/ConfirmUploadPopup.qml create mode 100644 src/icons/thin/confirm-uploading-file.svg diff --git a/TODO.md b/TODO.md index 6535b6b6..d1f41422 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,6 @@ # TODO +- power control focus - idlemanager: what if setPresence call fails due to network? - block power level change when offline - fix power level control button layout when apply button is loading @@ -158,7 +159,6 @@ - Add upload keybindings (close failed upload, pause, resume) - Handle errors when setting an avatar -- Show confirmation box when picking file to upload or uploading from clipboard - Show proper progress ring for mxc thumbnails loading - Sentinel function to report local file paths for already downloaded media, diff --git a/src/gui/Pages/Chat/Composer/UploadButton.qml b/src/gui/Pages/Chat/Composer/UploadButton.qml index 00390b66..ce2cb164 100644 --- a/src/gui/Pages/Chat/Composer/UploadButton.qml +++ b/src/gui/Pages/Chat/Composer/UploadButton.qml @@ -21,8 +21,14 @@ HButton { HShortcut { sequences: window.settings.keys.sendFileFromPathInClipboard - onActivated: utils.sendFile( - chat.userId, chat.roomId, Clipboard.text.trim(), + onActivated: utils.makePopup( + "Popups/ConfirmUploadPopup.qml", + { + userId: chat.userId, + roomId: chat.roomId, + roomName: chat.roomInfo.display_name, + filePath: Clipboard.text.trim(), + }, ) } diff --git a/src/gui/Popups/ConfirmUploadPopup.qml b/src/gui/Popups/ConfirmUploadPopup.qml new file mode 100644 index 00000000..523cf53a --- /dev/null +++ b/src/gui/Popups/ConfirmUploadPopup.qml @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 +import "../Base" +import "../Base/Buttons" + +HColumnPopup { + id: popup + + property string userId + property string roomId + property string roomName + property string filePath + + readonly property string fileName: filePath.split("/").slice(-1)[0] + + + page.footer: AutoDirectionLayout { + ApplyButton { + id: uploadButton + text: qsTr("Send") + icon.name: "confirm-uploading-file" + onClicked: { + utils.sendFile(popup.userId, popup.roomId, filePath) + popup.close() + } + } + + CancelButton { + id: cancelButton + onClicked: popup.close() + } + } + + onOpened: uploadButton.forceActiveFocus() + + SummaryLabel { + text: + qsTr("Send %1 to %2?") + .arg(utils.htmlColorize(fileName, theme.colors.accentText)) + .arg(utils.htmlColorize(roomName, theme.colors.accentText)) + + textFormat: Text.StyledText + } + + HImage { + source: popup.filePath + fillMode: Image.PreserveAspectFit + visible: status !== Image.Error + + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: + status === Image.Ready ? + width / (implicitWidth / implicitHeight) : + 0 + + Behavior on Layout.preferredHeight { HNumberAnimation {} } + } +} diff --git a/src/gui/Utils.qml b/src/gui/Utils.qml index 1de9ab02..2f2d827a 100644 --- a/src/gui/Utils.qml +++ b/src/gui/Utils.qml @@ -191,6 +191,11 @@ QtObject { } + function htmlColorize(text, color) { + return `${text}` + } + + function processedEventText(ev) { const type = ev.event_type const unknownMsg = type === "RoomMessageUnknown" diff --git a/src/icons/thin/confirm-uploading-file.svg b/src/icons/thin/confirm-uploading-file.svg new file mode 100644 index 00000000..2eed4d1d --- /dev/null +++ b/src/icons/thin/confirm-uploading-file.svg @@ -0,0 +1,3 @@ + + +