2020-08-28 17:18:33 +03:00
|
|
|
/*
|
2020-10-19 20:34:47 +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
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
|
|
|
id: documentPreviewItem
|
|
|
|
width: parent.width
|
|
|
|
height: Theme.itemSizeLarge
|
|
|
|
|
|
|
|
property variant documentData;
|
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;
|
|
|
|
openDocumentButton.visible = true;
|
|
|
|
} else {
|
|
|
|
openDocumentButton.visible = false;
|
|
|
|
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) {
|
2020-08-28 17:18:33 +03:00
|
|
|
downloadBusyIndicator.running = false;
|
|
|
|
documentData.document = fileInformation;
|
|
|
|
downloadDocumentButton.visible = false;
|
|
|
|
openDocumentButton.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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: downloadDocumentButton
|
|
|
|
preferredWidth: Theme.buttonWidthMedium
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: qsTr("Download Document")
|
|
|
|
visible: false
|
|
|
|
onClicked: {
|
|
|
|
downloadDocumentButton.visible = false;
|
|
|
|
downloadBusyIndicator.running = true;
|
|
|
|
tdLibWrapper.downloadFile(documentData.document.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BusyIndicator {
|
|
|
|
id: downloadBusyIndicator
|
|
|
|
running: false
|
|
|
|
size: BusyIndicatorSize.Medium
|
|
|
|
visible: running
|
|
|
|
anchors.centerIn: parent
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: openDocumentButton
|
|
|
|
preferredWidth: Theme.buttonWidthMedium
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: qsTr("Open Document")
|
|
|
|
visible: false
|
|
|
|
onClicked: {
|
2020-09-30 00:37:56 +03:00
|
|
|
documentPreviewItem.openRequested = true;
|
2020-08-28 17:18:33 +03:00
|
|
|
tdLibWrapper.openFileOnDevice(documentData.document.local.path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|