Spectral/qml/component/DownloadableContent.qml

39 lines
1.1 KiB
QML
Raw Normal View History

2018-07-12 01:44:41 +00:00
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
2018-08-17 04:55:57 +00:00
import Qt.labs.platform 1.0
Item {
property bool openOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed
Rectangle {
2018-07-20 04:14:02 +00:00
z: -2
height: parent.height
width: progressInfo.active && !progressInfo.completed ? progressInfo.progress / progressInfo.total * parent.width : 0
2018-09-04 13:13:14 +00:00
color: Material.accent
opacity: 0.4
}
2018-09-04 13:13:14 +00:00
onDownloadedChanged: if (downloaded && openOnFinished) openSavedFile()
2018-07-19 13:02:06 +00:00
2018-09-04 13:13:14 +00:00
function saveFileAs() { currentRoom.saveFileAs(eventId) }
function downloadAndOpen()
{
2018-09-04 13:13:14 +00:00
if (downloaded) openSavedFile()
else
{
openOnFinished = true
2018-08-17 04:55:57 +00:00
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_") + ".tmp")
}
}
function openSavedFile()
{
2018-09-04 13:13:14 +00:00
if (Qt.openUrlExternally(progressInfo.localPath)) return;
if (Qt.openUrlExternally(progressInfo.localDir)) return;
}
}