From 1a8b1d4dfb1af936ec68b30af475dcfbeff6453c Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Wed, 20 Oct 2021 12:48:09 +0100 Subject: Implement saving attachment to filesystem --- qml/Message.qml | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'qml') diff --git a/qml/Message.qml b/qml/Message.qml index 9d8f377..fc69e8f 100644 --- a/qml/Message.qml +++ b/qml/Message.qml @@ -12,6 +12,8 @@ RowLayout { property DcMessage message property DcContext context + property var saveAsUrl: "" + property var saveSuccess: false readonly property DcContact from: context.getContact(message.fromId) readonly property DcMessage quoteMessage: message.quotedMessage readonly property DcContact quoteFrom: quoteMessage ? context.getContact(quoteMessage.fromId) : null @@ -33,6 +35,49 @@ RowLayout { } } + Popup { + id: saveAsPopup + + modal: true + focus: true + anchors.centerIn: parent + width: 400 + height: 100 + padding: 10 + onClosed: saveAsUrl = "" + contentChildren: [ + Text { + text: saveSuccess == true ? "Success !" : "Failure !" + bottomPadding: 10 + font.bold: true + font.pixelSize: 14 + }, + Text { + text: saveSuccess == true ? "The file has been saved locally at
" + saveAsUrl + "" : "An error was detected. Maybe you
dont have enough permissions to copy the file to
" + saveAsUrl + "" + topPadding: 20 + leftPadding: 10 + bottomPadding: 20 + } + ] + } + + FileDialog { + id: saveAsDialog + + title: "Save attachment `" + root.message.filename + "` as ..." + folder: shortcuts.home + selectFolder: false + selectExisting: false + onAccepted: { + var url = saveAsDialog.fileUrl.toString(); + if (url.startsWith("file://")) { + saveAsUrl = url.substring(7); + saveSuccess = root.message.saveAttach(saveAsUrl); + saveAsPopup.open(); + } + } + } + Rectangle { Layout.leftMargin: Kirigami.Units.largeSpacing Layout.preferredWidth: messageContents.width @@ -174,7 +219,7 @@ RowLayout { padding: 5 icon.name: "document-save-as" text: "Save attachment" - onClicked: console.log("dummy") + onClicked: saveAsDialog.open() } } @@ -220,11 +265,24 @@ RowLayout { Menu { id: contextMenu + Component.onCompleted: { + if (!root.message.filename.length > 0) + contextMenu.removeAction(saveAsContext); + + } + Action { text: "Info" onTriggered: messageDialog.open() } + Action { + id: saveAsContext + + text: "Save attachment as ..." + onTriggered: saveAsDialog.open() + } + } } -- cgit v1.2.3-70-g09d2