From 5c6b6ef68a8c7b784d657d0715331fe315a3622b Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 6 Nov 2019 16:31:38 -0400 Subject: [PATCH] Have a dedicated SendFilePicker component --- TODO.md | 3 +++ src/qml/Chat/Composer.qml | 11 ++++------- src/qml/Dialogs/SendFilePicker.qml | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 src/qml/Dialogs/SendFilePicker.qml diff --git a/TODO.md b/TODO.md index f430085a..1dbd60c9 100644 --- a/TODO.md +++ b/TODO.md @@ -3,6 +3,9 @@ - Bottom/top bar - Verify things work with chat.privacytools.io (subdomain weirdness) - Show real progression for mxc thumbnail loadings, uploads and downloads + - Confirmation box after picking file to upload + - Handle upload errors, file too big, etc + - Allow multiple file selection - Support m.file thumbnails - Generate video thumbnails diff --git a/src/qml/Chat/Composer.qml b/src/qml/Chat/Composer.qml index 9c644c3b..d61e2c3f 100644 --- a/src/qml/Chat/Composer.qml +++ b/src/qml/Chat/Composer.qml @@ -210,16 +210,13 @@ Rectangle { icon.name: "upload-file" backgroundColor: theme.chat.composer.uploadButton.background toolTip.text: qsTr("Send files") + onClicked: sendFilePicker.dialog.open() Layout.fillHeight: true - HFileDialogOpener { - dialog.title: qsTr("Select files to upload") - onFilePicked: { - let path = Qt.resolvedUrl(file).replace(/^file:/, "") - let args = [chatPage.roomId, path] - py.callClientCoro(chatPage.userId, "send_file", args) - } + SendFilePicker { + id: sendFilePicker + roomId: chatPage.roomId } } } diff --git a/src/qml/Dialogs/SendFilePicker.qml b/src/qml/Dialogs/SendFilePicker.qml new file mode 100644 index 00000000..bc1fb4f0 --- /dev/null +++ b/src/qml/Dialogs/SendFilePicker.qml @@ -0,0 +1,20 @@ +import QtQuick 2.12 + +HFileDialogOpener { + fill: false + dialog.title: qsTr("Select a file to send") + + onFilePicked: { + let path = Qt.resolvedUrl(file).replace(/^file:/, "") + py.callClientCoro(userId, "send_file", [roomId, path], () => { + if (destroyWhenDone) destroy() + }) + } + + onCancelled: if (destroyWhenDone) destroy() + + + property string userId + property string roomId + property bool destroyWhenDone: false +}