diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 0a04807..5811deb 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -30,6 +30,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \ qml/pages/InitializationPage.qml \ qml/pages/OverviewPage.qml \ qml/pages/AboutPage.qml \ + qml/pages/VideoPage.qml \ rpm/harbour-fernschreiber.changes.in \ rpm/harbour-fernschreiber.changes.run.in \ rpm/harbour-fernschreiber.spec \ diff --git a/qml/components/VideoPreview.qml b/qml/components/VideoPreview.qml index d0e442c..bc806e5 100644 --- a/qml/components/VideoPreview.qml +++ b/qml/components/VideoPreview.qml @@ -29,6 +29,7 @@ Item { property int previewFileId; property int videoFileId; property bool fullscreen : false; + property bool onScreen; width: parent.width height: parent.height @@ -105,7 +106,9 @@ Item { videoDownloadBusyIndicator.running = false; videoData.video = fileInformation; videoUrl = fileInformation.local.path; - videoComponentLoader.active = true; + if (onScreen) { + videoComponentLoader.active = true; + } } } } @@ -187,8 +190,7 @@ Item { MouseArea { anchors.fill: parent onClicked: { - // TODO show video page once it's there... - //pageStack.push(Qt.resolvedUrl("../pages/VideoPage.qml"), {"tweetModel": tweet.retweeted_status ? tweet.retweeted_status : tweet}); + pageStack.push(Qt.resolvedUrl("../pages/VideoPage.qml"), {"videoData": videoData}); } } } @@ -417,8 +419,7 @@ Item { MouseArea { anchors.fill: parent onClicked: { - // TODO go to video page once it's done - // pageStack.push(Qt.resolvedUrl("../pages/VideoPage.qml"), {"tweetModel": videoMessageComponent.tweet}); + pageStack.push(Qt.resolvedUrl("../pages/VideoPage.qml"), {"videoData": videoData}); } } } diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 6bd548b..f428a56 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -446,6 +446,7 @@ Page { width: parent.width height: Functions.getVideoHeight(width, display.content.video) visible: display.content['@type'] === "messageVideo" + onScreen: chatPage.status === PageStatus.Active } // Row { diff --git a/qml/pages/ImagePage.qml b/qml/pages/ImagePage.qml index 513eb0c..b02bb17 100644 --- a/qml/pages/ImagePage.qml +++ b/qml/pages/ImagePage.qml @@ -99,7 +99,7 @@ Page { MenuItem { text: qsTr("Download Picture") onClicked: { - tdLibWrapper.copyPictureToDownloads(imagePage.imageUrl); + tdLibWrapper.copyFileToDownloads(imagePage.imageUrl); } } } diff --git a/qml/pages/VideoPage.qml b/qml/pages/VideoPage.qml new file mode 100644 index 0000000..928bcef --- /dev/null +++ b/qml/pages/VideoPage.qml @@ -0,0 +1,103 @@ +/* + Copyright (C) 2020 Sebastian J. Wolf + + 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 . +*/ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import QtMultimedia 5.0 +import "../components" +import "../js/functions.js" as Functions + +Page { + id: videoPage + allowedOrientations: Orientation.All + + property variant videoData; + + property int videoWidth : videoData.width + property int videoHeight : videoData.height + property string videoUrl; + + property real imageSizeFactor : videoWidth / videoHeight; + property real screenSizeFactor: videoPage.width / videoPage.height; + property real sizingFactor : imageSizeFactor >= screenSizeFactor ? videoPage.width / videoWidth : videoPage.height / videoHeight; + + Component.onCompleted: { + updateVideoData(); + } + + function updateVideoData() { + if (typeof videoData === "object") { + if (videoData.video.local.is_downloading_completed) { + videoPage.videoUrl = videoData.video.local.path; + } + } + } + + SilicaFlickable { + anchors.fill: parent + + PullDownMenu { + id: videoPagePullDownMenu + visible: (videoPage.videoUrl !== "") + MenuItem { + text: qsTr("Download Video") + onClicked: { + tdLibWrapper.copyFileToDownloads(videoPage.videoUrl); + } + } + } + + Connections { + target: tdLibWrapper + onFileUpdated: { + if (fileId === videoPage.video.id) { + if (fileInformation.local.is_downloading_completed) { + videoPage.video = fileInformation; + videoPage.videoUrl = fileInformation.local.path; + videoPagePullDownMenu.visible = true; + } + } + } + onCopyToDownloadsSuccessful: { + videoNotification.show(qsTr("Download of %1 successful.").arg(fileName), filePath); + } + + onCopyToDownloadsError: { + videoNotification.show(qsTr("Download failed.")); + } + } + + AppNotification { + id: videoNotification + } + + Item { + width: videoPage.videoWidth * videoPage.sizingFactor + height: videoPage.videoHeight * videoPage.sizingFactor + anchors.centerIn: parent + + VideoPreview { + videoData: videoPage.videoData + fullscreen: true + onScreen: videoPage.status === PageStatus.Active + } + } + + } +} + diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index d172603..96dafaf 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -246,9 +246,9 @@ QVariantMap TDLibWrapper::getSuperGroup(const QString &groupId) return this->superGroups.value(groupId).toMap(); } -void TDLibWrapper::copyPictureToDownloads(const QString &filePath) +void TDLibWrapper::copyFileToDownloads(const QString &filePath) { - qDebug() << "[TDLibWrapper] Copy picture to downloads " << filePath; + qDebug() << "[TDLibWrapper] Copy file to downloads " << filePath; QFileInfo fileInfo(filePath); if (fileInfo.exists()) { QString downloadFilePath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + fileInfo.fileName(); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index b7fc8c4..adcd487 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -67,7 +67,7 @@ public: Q_INVOKABLE QVariantMap getUnreadChatInformation(); Q_INVOKABLE QVariantMap getBasicGroup(const QString &groupId); Q_INVOKABLE QVariantMap getSuperGroup(const QString &groupId); - Q_INVOKABLE void copyPictureToDownloads(const QString &filePath); + Q_INVOKABLE void copyFileToDownloads(const QString &filePath); Q_INVOKABLE void handleAdditionalInformation(const QString &additionalInformation); Q_INVOKABLE void controlScreenSaver(const bool &enabled); diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index bd08fcf..d5bd1fe 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -282,6 +282,21 @@ + + VideoPage + + Download Video + + + + Download of %1 successful. + + + + Download failed. + + + functions diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index bd08fcf..d5bd1fe 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -282,6 +282,21 @@ + + VideoPage + + Download Video + + + + Download of %1 successful. + + + + Download failed. + + + functions