harbour-fernschreiber/qml/components/messageContent/MessageDocument.qml

126 lines
4.2 KiB
QML
Raw Normal View History

2020-08-28 17:18:33 +03:00
/*
Copyright (C) 2020 Sebastian J. Wolf and other contributors
2020-08-28 17:18:33 +03:00
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
2020-10-31 22:49:03 +03:00
import QtQuick 2.6
2020-08-28 17:18:33 +03:00
import Sailfish.Silica 1.0
MessageContentBase {
2020-08-28 17:18:33 +03:00
id: documentPreviewItem
height: Theme.itemSizeLarge
property var documentData: rawMessage.content.document
2020-09-30 00:37:56 +03:00
property bool openRequested: false;
2020-08-28 17:18:33 +03:00
Component.onCompleted: {
updateDocument();
}
function updateDocument() {
2020-08-29 17:58:48 +03:00
if (documentData) {
2020-08-28 17:18:33 +03:00
if (documentData.document.local.is_downloading_completed) {
downloadDocumentButton.visible = false;
openDocumentArea.visible = true;
2020-08-28 17:18:33 +03:00
} else {
openDocumentArea.visible = false;
2020-08-28 17:18:33 +03:00
downloadDocumentButton.visible = true;
}
}
}
Connections {
target: tdLibWrapper
onFileUpdated: {
2020-08-29 17:58:48 +03:00
if (documentData) {
2020-09-30 00:37:56 +03:00
if (!fileInformation.remote.is_uploading_active && fileId === documentData.document.id && fileInformation.local.is_downloading_completed) {
downloadingProgressBar.visible = false;
2020-08-28 17:18:33 +03:00
documentData.document = fileInformation;
downloadDocumentButton.visible = false;
openDocumentArea.visible = true;
2020-09-30 00:37:56 +03:00
if (documentPreviewItem.openRequested) {
documentPreviewItem.openRequested = false;
tdLibWrapper.openFileOnDevice(documentData.document.local.path);
}
2020-08-28 17:18:33 +03:00
}
if (fileId === documentData.document.id) {
downloadingProgressBar.maximumValue = fileInformation.size;
downloadingProgressBar.value = fileInformation.local.downloaded_size;
}
2020-08-28 17:18:33 +03:00
}
}
}
Button {
id: downloadDocumentButton
preferredWidth: Theme.buttonWidthMedium
anchors.centerIn: parent
text: qsTr("Download Document")
visible: false
2020-12-28 23:20:10 +03:00
highlighted: documentPreviewItem.highlighted || down
2020-08-28 17:18:33 +03:00
onClicked: {
downloadDocumentButton.visible = false;
downloadingProgressBar.visible = true;
2020-08-28 17:18:33 +03:00
tdLibWrapper.downloadFile(documentData.document.id);
}
}
ProgressBar {
id: downloadingProgressBar
minimumValue: 0
maximumValue: 100
value: 0
visible: false
width: parent.width
2020-08-28 17:18:33 +03:00
anchors.centerIn: parent
}
Column {
id: openDocumentArea
2020-08-28 17:18:33 +03:00
visible: false
spacing: Theme.paddingMedium
width: parent.width
onVisibleChanged: {
visible ? (documentPreviewItem.height = openDocumentArea.height) : (documentPreviewItem.height = Theme.itemSizeLarge);
}
Button {
id: openDocumentButton
preferredWidth: Theme.buttonWidthMedium
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Open Document")
highlighted: documentPreviewItem.highlighted || down
onClicked: {
documentPreviewItem.openRequested = true;
tdLibWrapper.openFileOnDevice(documentData.document.local.path);
}
}
Button {
id: copyDocumentButton
preferredWidth: Theme.buttonWidthMedium
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Copy Document to Downloads")
highlighted: documentPreviewItem.highlighted || down
onClicked: {
tdLibWrapper.copyFileToDownloads(documentData.document.local.path);
}
2020-08-28 17:18:33 +03:00
}
}
}