diff --git a/KomplexHubContent/CMakeLists.txt b/KomplexHubContent/CMakeLists.txt index 6c80f2b..5d59352 100644 --- a/KomplexHubContent/CMakeLists.txt +++ b/KomplexHubContent/CMakeLists.txt @@ -18,10 +18,20 @@ qt6_add_qml_module(KomplexHubContent "pages/UserProfilePage.qml" "pages/WallpaperSettingsPage.qml" "pages/VideoSearchPage.qml" - QML_FILES pages/FeaturedVideosPage.qml - QML_FILES pages/FeaturedPacksPage.qml - QML_FILES pages/FeaturedImagesPage.qml - QML_FILES pages/NewestPacksPage.qml + "pages/FeaturedVideosPage.qml" + "pages/FeaturedPacksPage.qml" + "pages/FeaturedImagesPage.qml" + "pages/NewestPacksPage.qml" + "views/CompletedView.qml" + "views/DownloadView.qml" + "views/ErrorView.qml" + "views/ImageView.qml" + "views/PackView.qml" + "views/VideoView.qml" + RESOURCES views/CMakeLists.txt + RESOURCES pages/CMakeLists.txt ) +add_subdirectory(pages) +add_subdirectory(views) diff --git a/KomplexHubContent/MainScreen.qml b/KomplexHubContent/MainScreen.qml index a1e0acc..6e13f2d 100644 --- a/KomplexHubContent/MainScreen.qml +++ b/KomplexHubContent/MainScreen.qml @@ -81,7 +81,7 @@ Rectangle { height: 64 width: 100 - text: "Home" + text: qsTr("Home") icon.height: 32 icon.width: 32 @@ -109,7 +109,7 @@ Rectangle { height: 64 width: 100 - text: "Images" + text: qsTr("Images") icon.height: 32 icon.width: 32 @@ -132,7 +132,7 @@ Rectangle { height: 64 width: 100 - text: "Videos" + text: qsTr("Videos") icon.height: 32 icon.width: 32 @@ -155,7 +155,7 @@ Rectangle { height: 64 width: 100 - text: "Live" + text: qsTr("Komplex") icon.height: 32 icon.width: 32 @@ -178,7 +178,7 @@ Rectangle { height: 64 width: 100 - text: "Installed" + text: qsTr("Installed") icon.height: 32 icon.width: 32 @@ -207,7 +207,7 @@ Rectangle { height: 64 width: 100 - text: "Settings" + text: qsTr("Settings") icon.height: 32 icon.width: 32 @@ -369,7 +369,7 @@ Rectangle { function isSearchPage() { - return ( + return( pageLoader.item instanceof ImageSearchPage || pageLoader.item instanceof LiveSearchPage || pageLoader.item instanceof VideoSearchPage diff --git a/KomplexHubContent/pages/CMakeLists.txt b/KomplexHubContent/pages/CMakeLists.txt new file mode 100644 index 0000000..0b51fe9 --- /dev/null +++ b/KomplexHubContent/pages/CMakeLists.txt @@ -0,0 +1,20 @@ +qt_add_library(KomplexHubPages STATIC) +qt6_add_qml_module(KomplexHubPages + URI "KomplexHub.Pages" + VERSION 1.0 + RESOURCE_PREFIX "/qt/qml" + QML_FILES + "HomePage.qml" + "ImageSearchPage.qml" + "InstalledWallpaperPage.qml" + "LiveSearchPage.qml" + "LoginPage.qml" + "SettingsPage.qml" + "UserProfilePage.qml" + "WallpaperSettingsPage.qml" + "VideoSearchPage.qml" + "FeaturedVideosPage.qml" + "FeaturedPacksPage.qml" + "FeaturedImagesPage.qml" + "NewestPacksPage.qml" +) \ No newline at end of file diff --git a/KomplexHubContent/pages/FeaturedImagesPage.qml b/KomplexHubContent/pages/FeaturedImagesPage.qml index f0fa3a3..700f7d1 100644 --- a/KomplexHubContent/pages/FeaturedImagesPage.qml +++ b/KomplexHubContent/pages/FeaturedImagesPage.qml @@ -6,6 +6,8 @@ import KomplexHub import KomplexHub.Controls import KomplexHub.Kero import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Rectangle { diff --git a/KomplexHubContent/pages/FeaturedPacksPage.qml b/KomplexHubContent/pages/FeaturedPacksPage.qml index 1cfb482..f7c3839 100644 --- a/KomplexHubContent/pages/FeaturedPacksPage.qml +++ b/KomplexHubContent/pages/FeaturedPacksPage.qml @@ -6,6 +6,8 @@ import KomplexHub import KomplexHub.Controls import KomplexHub.Kero import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Rectangle { diff --git a/KomplexHubContent/pages/FeaturedVideosPage.qml b/KomplexHubContent/pages/FeaturedVideosPage.qml index e63e82b..8dbbe6a 100644 --- a/KomplexHubContent/pages/FeaturedVideosPage.qml +++ b/KomplexHubContent/pages/FeaturedVideosPage.qml @@ -6,6 +6,8 @@ import KomplexHub import KomplexHub.Controls import KomplexHub.Kero import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Rectangle { diff --git a/KomplexHubContent/pages/HomePage.qml b/KomplexHubContent/pages/HomePage.qml index b3b6350..89c4769 100644 --- a/KomplexHubContent/pages/HomePage.qml +++ b/KomplexHubContent/pages/HomePage.qml @@ -7,6 +7,7 @@ import KomplexHub import KomplexHub.Controls import KomplexHub.Kero import KomplexHub.Plugin +import KomplexHubContent Item { @@ -111,7 +112,7 @@ Item color: palette.text font.pixelSize: Constants.h2Font.pixelSize font.bold: true - text: qsTr("Featured Live Wallpapers") + text: qsTr("Featured Komplex Wallpapers") verticalAlignment: Qt.AlignVCenter } @@ -198,7 +199,7 @@ Item SearchResultItem { anchors.fill: parent - title: parent.author + author: parent.author description: parent.description thumbnail: parent.thumbnail uuid: parent.uuid @@ -220,13 +221,13 @@ Item } } - VerticalSpacer{ height: Constants.largeMargin; width: Constants.largeMargin } + VerticalSpacer { height: Constants.largeMargin; width: Constants.largeMargin } } } } } - VerticalSpacer{ height: Constants.largeMargin; width: Constants.largeMargin } + VerticalSpacer { height: Constants.largeMargin; width: Constants.largeMargin } Rectangle { @@ -257,8 +258,8 @@ Item anchors.left: parent.left anchors.right: parent.right anchors.margins: Constants.largeMargin - height: childrenRect.height + height: childrenRect.height color: palette.window Column @@ -363,7 +364,7 @@ Item SearchResultItem { anchors.fill: parent - title: parent.author + author: parent.author thumbnail: parent.thumbnail uuid: parent.uuid pexels: true @@ -388,7 +389,6 @@ Item VerticalSpacer{ height: Constants.largeMargin; width: Constants.largeMargin } } - } Component.onCompleted: () => @@ -422,7 +422,8 @@ Item opacity: 0 visible: opacity > 0.01 - Behavior on opacity { + Behavior on opacity + { NumberAnimation { duration: 250 @@ -437,7 +438,8 @@ Item opacity: 0 visible: opacity > 0.01 - Behavior on opacity { + Behavior on opacity + { NumberAnimation { duration: 250 @@ -452,7 +454,8 @@ Item opacity: 0 visible: opacity > 0.01 - Behavior on opacity { + Behavior on opacity + { NumberAnimation { duration: 250 @@ -460,7 +463,8 @@ Item } } - Behavior on opacity { + Behavior on opacity + { NumberAnimation { duration: 250 @@ -478,7 +482,8 @@ Item anchors.fill: parent opacity: 0 - Behavior on opacity { + Behavior on opacity + { NumberAnimation { duration: 250 @@ -548,8 +553,10 @@ Item } } - states: [ - State { + states: + [ + State + { name: "loading" when: homePageRoot.loading @@ -571,7 +578,8 @@ Item opacity: 0 } }, - State { + State + { name: "idle" when: !popup && !loading @@ -606,7 +614,8 @@ Item } ] - transitions: [ + transitions: + [ Transition { from: "loading" @@ -692,6 +701,7 @@ Item viewMoreWallpaperPopup.authorId = packsModel.data(packsModel.index(index,0), NewestPacksModel.AuthorIdRole) viewMoreWallpaperPopup.description = packsModel.data(packsModel.index(index,0), NewestPacksModel.DescriptionRole) viewMoreWallpaperPopup.thumbnail = packsModel.data(packsModel.index(index,0), NewestPacksModel.ThumbnailRole) + viewMoreWallpaperPopup.name = packsModel.data(packsModel.index(index,0), NewestPacksModel.NameRole) viewMoreWallpaperPopup.opacity = 1 popupContainer.opacity = 1 pageArea.opacity = 0 diff --git a/KomplexHubContent/pages/ImageSearchPage.qml b/KomplexHubContent/pages/ImageSearchPage.qml index e22906f..15a9187 100644 --- a/KomplexHubContent/pages/ImageSearchPage.qml +++ b/KomplexHubContent/pages/ImageSearchPage.qml @@ -6,6 +6,8 @@ import KomplexHub import KomplexHub.Controls import KomplexHub.Kero import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Item { diff --git a/KomplexHubContent/pages/InstalledWallpaperPage.qml b/KomplexHubContent/pages/InstalledWallpaperPage.qml index 75ed181..42a50a4 100644 --- a/KomplexHubContent/pages/InstalledWallpaperPage.qml +++ b/KomplexHubContent/pages/InstalledWallpaperPage.qml @@ -2,10 +2,13 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts import QtQuick.Dialogs + import KomplexHub import KomplexHub.Controls import KomplexHub.Kero import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Rectangle { id: root diff --git a/KomplexHubContent/pages/LiveSearchPage.qml b/KomplexHubContent/pages/LiveSearchPage.qml index 11fc194..cc24dbb 100644 --- a/KomplexHubContent/pages/LiveSearchPage.qml +++ b/KomplexHubContent/pages/LiveSearchPage.qml @@ -1,9 +1,12 @@ import QtQuick import QtQuick.Controls + import KomplexHub import KomplexHub.Controls import KomplexHub.Kero import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Item { diff --git a/KomplexHubContent/pages/LoginPage.qml b/KomplexHubContent/pages/LoginPage.qml index 098a40c..a2ef49b 100644 --- a/KomplexHubContent/pages/LoginPage.qml +++ b/KomplexHubContent/pages/LoginPage.qml @@ -1,8 +1,13 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts + import KomplexHub import KomplexHub.Controls +import KomplexHub.Kero +import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Item { id: loginFormRoot diff --git a/KomplexHubContent/pages/NewestPacksPage.qml b/KomplexHubContent/pages/NewestPacksPage.qml index 04772b0..f9e1208 100644 --- a/KomplexHubContent/pages/NewestPacksPage.qml +++ b/KomplexHubContent/pages/NewestPacksPage.qml @@ -6,6 +6,8 @@ import KomplexHub import KomplexHub.Controls import KomplexHub.Kero import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Rectangle { diff --git a/KomplexHubContent/pages/SettingsPage.qml b/KomplexHubContent/pages/SettingsPage.qml index 4712282..5067921 100644 --- a/KomplexHubContent/pages/SettingsPage.qml +++ b/KomplexHubContent/pages/SettingsPage.qml @@ -1,8 +1,13 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts + import KomplexHub +import KomplexHub.Controls import KomplexHub.Kero +import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Item { readonly property bool searchable: false diff --git a/KomplexHubContent/pages/UserProfilePage.qml b/KomplexHubContent/pages/UserProfilePage.qml index cc69395..55605d3 100644 --- a/KomplexHubContent/pages/UserProfilePage.qml +++ b/KomplexHubContent/pages/UserProfilePage.qml @@ -1,7 +1,13 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts + import KomplexHub +import KomplexHub.Controls +import KomplexHub.Kero +import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Item { id: root diff --git a/KomplexHubContent/pages/VideoSearchPage.qml b/KomplexHubContent/pages/VideoSearchPage.qml index fdf3969..dc3f76a 100644 --- a/KomplexHubContent/pages/VideoSearchPage.qml +++ b/KomplexHubContent/pages/VideoSearchPage.qml @@ -6,6 +6,8 @@ import KomplexHub import KomplexHub.Controls import KomplexHub.Kero import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages Item { diff --git a/KomplexHubContent/pages/WallpaperSettingsPage.qml b/KomplexHubContent/pages/WallpaperSettingsPage.qml index bd60786..b65d02f 100644 --- a/KomplexHubContent/pages/WallpaperSettingsPage.qml +++ b/KomplexHubContent/pages/WallpaperSettingsPage.qml @@ -31,9 +31,12 @@ import QtQuick.Layouts //import org.kde.plasma.core as PlasmaCore import QtCore import Qt.labs.folderlistmodel 2.15 + import KomplexHub import KomplexHub.Controls import KomplexHub.Plugin +import KomplexHub.Views +import KomplexHub.Pages //import com.github.digitalartifex.komplex 1.0 as Komplex diff --git a/KomplexHubContent/views/CMakeLists.txt b/KomplexHubContent/views/CMakeLists.txt new file mode 100644 index 0000000..c55e139 --- /dev/null +++ b/KomplexHubContent/views/CMakeLists.txt @@ -0,0 +1,13 @@ +qt_add_library(KomplexHubViews STATIC) +qt6_add_qml_module(KomplexHubViews + URI "KomplexHub.Views" + VERSION 1.0 + RESOURCE_PREFIX "/qt/qml" + QML_FILES + "CompletedView.qml" + "DownloadView.qml" + "ErrorView.qml" + "ImageView.qml" + "PackView.qml" + "VideoView.qml" +) \ No newline at end of file diff --git a/KomplexHubModule/Controls/CMakeLists.txt b/KomplexHubModule/Controls/CMakeLists.txt index 8fc39a5..27b64d1 100644 --- a/KomplexHubModule/Controls/CMakeLists.txt +++ b/KomplexHubModule/Controls/CMakeLists.txt @@ -14,18 +14,11 @@ qt6_add_qml_module(KomplexHubModule_Controls "Throbber.qml" "SearchResultItem.qml" "SearchResultList.qml" - QML_FILES PaginationBox.qml - QML_FILES PaginatorGrid.qml - QML_FILES HorizontalPaginator.qml - QML_FILES ImageView.qml - QML_FILES - QML_FILES VideoView.qml - QML_FILES PackView.qml - QML_FILES VerticalSpacer.qml - QML_FILES DownloadView.qml - QML_FILES ImageFrame.qml - QML_FILES BackgroundImage.qml - QML_FILES CompletedView.qml - QML_FILES ErrorView.qml + "PaginationBox.qml" + "PaginatorGrid.qml" + "HorizontalPaginator.qml" + "VerticalSpacer.qml" + "ImageFrame.qml" + "BackgroundImage.qml" ) diff --git a/KomplexHubModule/Controls/SearchResultItem.qml b/KomplexHubModule/Controls/SearchResultItem.qml index 1fd6605..11059a5 100644 --- a/KomplexHubModule/Controls/SearchResultItem.qml +++ b/KomplexHubModule/Controls/SearchResultItem.qml @@ -74,7 +74,7 @@ Item { width: 24 height: 24 - transform: Image.PreserveAspectFit + fillMode: Image.PreserveAspectFit opacity: 0.5 source: "qrc:/images/icons/pexels-icon-filled-256.svg" @@ -82,49 +82,6 @@ Item { } } - // Rectangle - // { - // Layout.preferredWidth: 250 - // Layout.preferredHeight: 141 - // Layout.alignment: Qt.AlignHCenter | Qt.AlignTop - // Layout.topMargin: 3 - - // border.color: palette.alternateBase.lighter(1.75) - - // color: palette.base.lighter(1.25) - - // // Throbber - // // { - // // anchors.fill: parent - // // id: loadingThrobber - // // visible: viewImage.status === Image.Loading - // // } - - // // Image - // // { - // // property int retries: 0 - // // id: viewImage - // // anchors.fill: parent - // // source: rootItem.thumbnail - // // visible: !(status === Image.Loading) - // // fillMode: Image.PreserveAspectCrop - - // // onStatusChanged: () => - // // { - // // // if(status === Image.Error) - // // // { - // // // if(retries <= 3) - // // // { - // // // ++retries - // // // let src = source - // // // source = "" - // // // source = src - // // // } - // // // } - // // } - // // } - // } - Text { color: palette.text @@ -140,18 +97,6 @@ Item { Item { Layout.fillHeight: true } - Text - { - color: palette.text - font.pixelSize: 12 - text: "By: " + rootItem.author - leftPadding: 12 - - Layout.alignment: Qt.AlignLeft | Qt.AlignBottom - Layout.preferredWidth: 250 - visible: !rootItem.pexels - } - Text { id: descriptionText @@ -171,6 +116,19 @@ Item { Layout.bottomMargin: 3 } + Text + { + color: palette.text + font.pixelSize: 12 + text: "By: " + rootItem.author + leftPadding: Constants.mediumMargin + rightPadding: Constants.mediumMargin + horizontalAlignment: Qt.AlignRight + + Layout.alignment: Qt.AlignLeft | Qt.AlignBottom + Layout.fillWidth: true + } + SquareButton { id: viewMoreButton diff --git a/KomplexHubPlugin/downloadmanager.cpp b/KomplexHubPlugin/downloadmanager.cpp index 6d94b9a..1bf383c 100644 --- a/KomplexHubPlugin/downloadmanager.cpp +++ b/KomplexHubPlugin/downloadmanager.cpp @@ -79,305 +79,334 @@ DownloadManager::DownloadManager(QObject *parent) */ auto DownloadManager::downloadImage(const QString &author, const QString &authorId, const QString &description, const QUrl &url) -> void { - // QFuture future = QtConcurrent::run - // ( - // [this, url, author, authorId, description]() - // { - QNetworkRequest request(url); - QString requestUrl = request.url().toString(); - QString id = QUuid::createUuidV7().toString(QUuid::WithoutBraces); + QNetworkRequest request(url); + QString requestUrl = request.url().toString(); + QString id = QUuid::createUuidV7().toString(QUuid::WithoutBraces); - setState(Downloading); + setState(Downloading); - //QFuture downloadUri = download(request, id, Get); - if(m_downloadFuture.isRunning()) + //QFuture downloadUri = download(request, id, Get); + if(m_downloadFuture.isRunning()) + { + m_downloadFuture.cancelChain(); + } + + m_downloadFuture = download(request, id, Get); + + m_downloadFuture + .then + ( + [this, author, description, id](QUrl result) -> QUrl { - m_downloadFuture.cancelChain(); - } + setState(Installing); - m_downloadFuture = download(request, id, Get); + ShaderPack metadata; + metadata.setAuthor(author); + metadata.setDescription(description); + metadata.setName(QStringLiteral("Pexels Image (%1)").arg(id)); + metadata.setSource(QStringLiteral("./images/%1").arg(result.fileName())); - m_downloadFuture - .then + QUrl packUri ( - [this, author, description, id](QUrl result) -> QUrl - { - setState(Installing); - - ShaderPack metadata; - metadata.setAuthor(author); - metadata.setDescription(description); - metadata.setName(QStringLiteral("Pexels Image (%1)").arg(id)); - metadata.setSource(QStringLiteral("./images/%1").arg(result.fileName())); - - QUrl packUri - ( - QStringLiteral("file://%1/%2").arg - ( - QStandardPaths::writableLocation(QStandardPaths::TempLocation), - id - ) - ); - - QUrl packImageUri - ( - QStringLiteral("file://%1/%2/images/%3").arg - ( - QStandardPaths::writableLocation(QStandardPaths::TempLocation), - id, - result.fileName() - ) - ); - - QDir packDirectory(packUri.toLocalFile()); - - if(!packDirectory.mkpath(packUri.toLocalFile())) - { - throw FileException(QStringLiteral("Could not create directory")); - } - - packDirectory.mkdir(QStringLiteral("images")); - - QFile::rename(result.toLocalFile(), packImageUri.toLocalFile()); - - QFile packFile - ( - packDirectory.absoluteFilePath - ( - QStringLiteral("pack.json") - ) - ); - - if(!packFile.open(QFile::ReadWrite)) - { - setError(QStringLiteral("File Error"), packFile.errorString()); - throw FileException(packFile.errorString()); - } - - QByteArray data = metadata.json().toJson(QJsonDocument::Indented); - - if(packFile.write(data) != data.length()) - { - setError(QStringLiteral("File Error"), packFile.errorString()); - throw FileException(packFile.errorString()); - } - - packFile.close(); - - return packUri; - } - ) - .then - ( - [this](QUrl result) -> QUrl - { - return install(result); - } - ) - .then - ( - [this](QUrl result) - { - setLastInstalledFile(result.toLocalFile()); - setState(Complete); - } - ) - .onCanceled - ( - [this]() - { - reset(); - } - ) - .onFailed - ( - [this] (const NetworkException &e) - { - reset(); - setError(QStringLiteral("Network Exception %1").arg(QString::number(e.errorCode)), e.message); - } - ) - .onFailed - ( - [this] (const FileException &e) - { - reset(); - setError(QStringLiteral("File Exception %1").arg(QString::number(e.errorCode)), e.message); - } - ) - .onFailed - ( - [this] () - { - reset(); - setError(QStringLiteral("Unknown Exception"), QString()); - } + QStringLiteral("file://%1/%2").arg + ( + QStandardPaths::writableLocation(QStandardPaths::TempLocation), + id + ) ); - // downloadUri.waitForFinished(); - // } - // ); + QUrl packImageUri + ( + QStringLiteral("file://%1/%2/images/%3").arg + ( + QStandardPaths::writableLocation(QStandardPaths::TempLocation), + id, + result.fileName() + ) + ); + + QDir packDirectory(packUri.toLocalFile()); + + if(!packDirectory.mkpath(packUri.toLocalFile())) + { + throw FileException(QStringLiteral("Could not create directory")); + } + + packDirectory.mkdir(QStringLiteral("images")); + + QFile::rename(result.toLocalFile(), packImageUri.toLocalFile()); + + QFile packFile + ( + packDirectory.absoluteFilePath + ( + QStringLiteral("pack.json") + ) + ); + + if(!packFile.open(QFile::ReadWrite)) + { + setError(QStringLiteral("File Error"), packFile.errorString()); + throw FileException(packFile.errorString()); + } + + QByteArray data = metadata.json().toJson(QJsonDocument::Indented); + + if(packFile.write(data) != data.length()) + { + setError(QStringLiteral("File Error"), packFile.errorString()); + throw FileException(packFile.errorString()); + } + + packFile.close(); + + return packUri; + } + ) + .then + ( + [this](QUrl result) -> QUrl + { + return install(result); + } + ) + .then + ( + [this](QUrl result) + { + setLastInstalledFile(result.toLocalFile()); + setState(Complete); + } + ) + .onCanceled + ( + [this]() + { + reset(); + } + ) + .onFailed + ( + [this] (const NetworkException &e) + { + reset(); + setError(QStringLiteral("Network Exception %1").arg(QString::number(e.errorCode)), e.message); + } + ) + .onFailed + ( + [this] (const FileException &e) + { + reset(); + setError(QStringLiteral("File Exception %1").arg(QString::number(e.errorCode)), e.message); + } + ) + .onFailed + ( + [this] () + { + reset(); + setError(QStringLiteral("Unknown Exception"), QString()); + } + ); } -auto DownloadManager::downloadVideo(const QString &author, const QString &authorId, const QString &description, const QUrl &url) -> void +auto DownloadManager::downloadVideo(const QString &author, const QString &authorId, const QUrl &url) -> void { - QFuture future = QtConcurrent::run - ( - [this, url, author, authorId, description]() - { - QNetworkRequest request(url); - QString id = QUuid::createUuidV7().toString(QUuid::WithoutBraces); + QNetworkRequest request(url); + QString id = QUuid::createUuidV7().toString(QUuid::WithoutBraces); - QFuture downloadUri = download(request, id); + setState(Downloading); - downloadUri - .then + if(m_downloadFuture.isRunning()) + { + m_downloadFuture.cancelChain(); + } + + m_downloadFuture = download(request, id, Get); + + m_downloadFuture + .then + ( + [this, author, id](QUrl result) -> QUrl + { + ShaderPack metadata; + metadata.setAuthor(author); + metadata.setType(ShaderPack::Video); + metadata.setName(QStringLiteral("Pexels Video (%1)").arg(id)); + metadata.setSource(QStringLiteral("./videos/%1").arg(result.fileName())); + + QUrl packUri ( - [this, author, description, id](QUrl result) -> QUrl - { - ShaderPack metadata; - metadata.setAuthor(author); - metadata.setDescription(description); - metadata.setName(QStringLiteral("Pexels Video (%1)").arg(id)); - metadata.setType(ShaderPack::Video); - - QUrl packUri - ( - QStringLiteral("%1/%2").arg - ( - QStandardPaths::writableLocation(QStandardPaths::TempLocation), - id - ) - ); - - QUrl packImageUri - ( - QStringLiteral("%1/%2/images/%3").arg - ( - QStandardPaths::writableLocation(QStandardPaths::TempLocation), - id, - result.fileName() - ) - ); - - QDir packDirectory(packUri.toLocalFile()); - packDirectory.mkpath(packUri.toLocalFile()); - packDirectory.mkdir(QStringLiteral("images")); - - QFile::rename(result.toLocalFile(), packImageUri.toLocalFile()); - - QFile packFile - ( - packDirectory.absoluteFilePath - ( - QStringLiteral("pack.json") - ) - ); - - if(!packFile.open(QFile::ReadWrite)) - { - setError(QStringLiteral("File Error"), packFile.errorString()); - throw FileException(packFile.errorString()); - } - - QByteArray data = metadata.json().toJson(QJsonDocument::Compact); - - if(packFile.write(data) != data.length()) - { - setError(QStringLiteral("File Error"), packFile.errorString()); - throw FileException(packFile.errorString()); - } - - packFile.close(); - - return packUri; - } - ) - .then - ( - [this](QUrl result) - { - install(result); - } - ) - .onCanceled - ( - [this]() - { - reset(); - } - ) - .onFailed - ( - [this] () - { - reset(); - } + QStringLiteral("%1/%2").arg + ( + QStandardPaths::writableLocation(QStandardPaths::TempLocation), + id + ) ); - } - ); + + QUrl packVideoUri + ( + QStringLiteral("%1/%2/videos/%3").arg + ( + QStandardPaths::writableLocation(QStandardPaths::TempLocation), + id, + result.fileName() + ) + ); + + QDir packDirectory(packUri.toLocalFile()); + packDirectory.mkpath(packUri.toLocalFile()); + packDirectory.mkdir(QStringLiteral("images")); + + QFile::rename(result.toLocalFile(), packVideoUri.toLocalFile()); + + QFile packFile + ( + packDirectory.absoluteFilePath + ( + QStringLiteral("pack.json") + ) + ); + + if(!packFile.open(QFile::ReadWrite)) + { + setError(QStringLiteral("File Error"), packFile.errorString()); + throw FileException(packFile.errorString()); + } + + QByteArray data = metadata.json().toJson(QJsonDocument::Compact); + + if(packFile.write(data) != data.length()) + { + setError(QStringLiteral("File Error"), packFile.errorString()); + throw FileException(packFile.errorString()); + } + + packFile.close(); + + return packUri; + } + ) + .then + ( + [this](QUrl result) -> QUrl + { + return install(result); + } + ) + .then + ( + [this](QUrl result) + { + setLastInstalledFile(result.toLocalFile()); + setState(Complete); + } + ) + .onCanceled + ( + [this]() + { + reset(); + } + ) + .onFailed + ( + [this] (const NetworkException &e) + { + reset(); + setError(QStringLiteral("Network Exception %1").arg(QString::number(e.errorCode)), e.message); + } + ) + .onFailed + ( + [this] (const FileException &e) + { + reset(); + setError(QStringLiteral("File Exception %1").arg(QString::number(e.errorCode)), e.message); + } + ) + .onFailed + ( + [this] () + { + reset(); + setError(QStringLiteral("Unknown Exception"), QString()); + } + ); } auto DownloadManager::downloadPack(const QString &id) -> void { - QFuture aether = QtConcurrent::run + QUrl downloadUrl = QUrl ( - [this, id]() - { - QUrl downloadUrl = QUrl - ( - QStringLiteral("%1/%2/%3").arg - ( - KOMPLEX_API_HOST, - KOMPLEX_API_VERSION, - KOMPLEX_ENDPOINT_PACKS_ITEM - ) - ); - - QNetworkRequest request(downloadUrl); - request.setRawHeader(QByteArray("uuid"), id.toUtf8()); - - QFuture downloadUri = download(request, id, Post); - - downloadUri - .then - ( - [this](QUrl result) -> QUrl - { - return m_compiler->process(result).result(); - } - ) - .then - ( - [this](QUrl result) -> QUrl - { - return install(result); - } - ) - .then - ( - [this] (QUrl result) - { - setState(Complete); - } - ) - .onFailed - ( - [this]() - { - reset(); - setError(m_compiler->errorTitle(), m_compiler->errorMessage()); - } - ) - .onCanceled - ( - [this]() - { - reset(); - } - ); - } + QStringLiteral("%1/%2/%3").arg + ( + KOMPLEX_API_HOST, + KOMPLEX_API_VERSION, + KOMPLEX_ENDPOINT_PACKS_ITEM + ) ); + + QNetworkRequest request(downloadUrl); + request.setRawHeader(QByteArray("uuid"), id.toUtf8()); + + QFuture downloadUri = download(request, id, Post); + + downloadUri + .then + ( + [this](QUrl result) -> QUrl + { + return m_compiler->process(result).result(); + } + ) + .then + ( + [this](QUrl result) -> QUrl + { + return install(result); + } + ) + .then + ( + [this](QUrl result) + { + setLastInstalledFile(result.toLocalFile()); + setState(Complete); + } + ) + .onCanceled + ( + [this]() + { + reset(); + } + ) + .onFailed + ( + [this] (const NetworkException &e) + { + reset(); + setError(QStringLiteral("Network Exception %1").arg(QString::number(e.errorCode)), e.message); + } + ) + .onFailed + ( + [this] (const FileException &e) + { + reset(); + setError(QStringLiteral("File Exception %1").arg(QString::number(e.errorCode)), e.message); + } + ) + .onFailed + ( + [this] () + { + reset(); + setError(QStringLiteral("Unknown Exception"), QString()); + } + ); } auto DownloadManager::reset() -> void diff --git a/KomplexHubPlugin/downloadmanager.h b/KomplexHubPlugin/downloadmanager.h index cd0a95c..600b9f6 100644 --- a/KomplexHubPlugin/downloadmanager.h +++ b/KomplexHubPlugin/downloadmanager.h @@ -89,7 +89,6 @@ public: ( const QString &author, const QString &authorId, - const QString &description, const QUrl &url ) -> void;