Compare commits
67 Commits
dev
..
53f95a775d
| Author | SHA1 | Date | |
|---|---|---|---|
| 53f95a775d | |||
| a100814875 | |||
| 8948946491 | |||
| 098c3f67e5 | |||
| 39988a555c | |||
| f4cd9c8c17 | |||
| 7833970236 | |||
| 520c1226da | |||
| f65026d173 | |||
| 7fe140ce7e | |||
| 9570aed12c | |||
| bfa2a50dfb | |||
| 22cdb351ca | |||
| 9e765837f5 | |||
| 43fc2d8455 | |||
| 112110a6f2 | |||
| 49ee8bb952 | |||
| 7bfe9f86bc | |||
| dfd789fb6c | |||
| 5e4c4f2b99 | |||
| 26fb04431e | |||
| be089a43f7 | |||
| d523b297f3 | |||
| c8cbdae511 | |||
| 3ceeac3e20 | |||
| eeee3f0c04 | |||
| 1522dbdbfc | |||
| 773f5946bd | |||
| c493758876 | |||
| c2efa5a005 | |||
| 5f31bc9fc2 | |||
| d5314b9066 | |||
| 81551df2e5 | |||
| 2a4eeab436 | |||
| 9d310850ac | |||
| fcd59ffd45 | |||
| e3c92133cf | |||
| 1dea9a6ae3 | |||
| 57568dba31 | |||
| 7534e0208d | |||
| 6b64994ae2 | |||
| b7dfe53e7e | |||
| 4004124a33 | |||
| 5d7bfc6a49 | |||
| 9b4510f518 | |||
| be263c934a | |||
| 25c27d70e8 | |||
| 6151edeb1c | |||
| 122ba7de13 | |||
| abbcc5b211 | |||
| 2debbf2102 | |||
| 39a06e0e8c | |||
| e309107f4d | |||
| 5eb160a792 | |||
| aa15cef4fe | |||
| cc8f1b8fad | |||
| 1154f9b004 | |||
| 3b7267c538 | |||
| 311b69a98c | |||
| 8cb213c3e3 | |||
| aa52a82ba2 | |||
| b88ec5b67b | |||
| 6ca41ada22 | |||
| 6c3c06b818 | |||
| c0e439ce6d | |||
| fb90713022 | |||
| 96a7c71a29 |
@@ -1,3 +0,0 @@
|
|||||||
[submodule "KomplexHubPlugin/3rdparty/qtkeychain"]
|
|
||||||
path = KomplexHubPlugin/3rdparty/qtkeychain
|
|
||||||
url = https://github.com/frankosterfeld/qtkeychain.git
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
;This file is used to denote what files have generative content
|
|
||||||
;Format: {file, class, model/version, ["message"]}
|
|
||||||
|
|
||||||
;Kero
|
|
||||||
{
|
|
||||||
{
|
|
||||||
images/kero/kero_build_1.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_build_2.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_build_3.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_build_4.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_build_error.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_choice.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_hello.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_login.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_no_results.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_run_1.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_run_2.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_run_3.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_run_4.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_warning.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_success.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_spotlight.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
images/kero/kero_star.png,
|
|
||||||
placeholders,
|
|
||||||
chatgpt5
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-2
@@ -8,8 +8,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
|
|||||||
Qt${QT_VERSION_MAJOR}::Gui
|
Qt${QT_VERSION_MAJOR}::Gui
|
||||||
Qt${QT_VERSION_MAJOR}::Widgets
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
Qt${QT_VERSION_MAJOR}::Quick
|
Qt${QT_VERSION_MAJOR}::Quick
|
||||||
Qt${QT_VERSION_MAJOR}::Qml
|
Qt${QT_VERSION_MAJOR}::Qml)
|
||||||
)
|
|
||||||
|
|
||||||
if(ENABLE_ASAN)
|
if(ENABLE_ASAN)
|
||||||
message(STATUS "Building with AddressSanitizer")
|
message(STATUS "Building with AddressSanitizer")
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QQmlNetworkAccessManagerFactory>
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <qobject.h>
|
#include <qobject.h>
|
||||||
#include <qqml.h>
|
#include <qqml.h>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
@@ -18,34 +15,7 @@
|
|||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QSurfaceFormat>
|
#include <QSurfaceFormat>
|
||||||
#include <QSGRendererInterface>
|
#include <QSGRendererInterface>
|
||||||
#include <QScreen>
|
|
||||||
#include "autogen/environment.h"
|
#include "autogen/environment.h"
|
||||||
#include "KomplexHubPlugin/common/komplex_global.h"
|
|
||||||
|
|
||||||
#ifdef KOMPLEX_LOCAL_DEV
|
|
||||||
class DebugNetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QNetworkAccessManager *create(QObject *parent) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
QNetworkAccessManager *DebugNetworkAccessManagerFactory::create(QObject *parent)
|
|
||||||
{
|
|
||||||
QNetworkAccessManager *nam = new QNetworkAccessManager(parent);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
nam,
|
|
||||||
&QNetworkAccessManager::sslErrors,
|
|
||||||
nam,
|
|
||||||
[] (QNetworkReply *reply, const QList<QSslError> &errors)
|
|
||||||
{
|
|
||||||
reply->ignoreSslErrors();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return nam;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -65,10 +35,6 @@ int main(int argc, char *argv[])
|
|||||||
QCoreApplication::exit(-1);
|
QCoreApplication::exit(-1);
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
|
|
||||||
#ifdef KOMPLEX_LOCAL_DEV
|
|
||||||
engine.setNetworkAccessManagerFactory(new DebugNetworkAccessManagerFactory);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
engine.addImportPath(QCoreApplication::applicationDirPath() + "/qml");
|
engine.addImportPath(QCoreApplication::applicationDirPath() + "/qml");
|
||||||
engine.addImportPath(":/");
|
engine.addImportPath(":/");
|
||||||
engine.load(url);
|
engine.load(url);
|
||||||
|
|||||||
+50
-81
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.21.1)
|
|||||||
option(LINK_INSIGHT "Link Qt Insight Tracker library" ON)
|
option(LINK_INSIGHT "Link Qt Insight Tracker library" ON)
|
||||||
option(BUILD_QDS_COMPONENTS "Build design studio components" ON)
|
option(BUILD_QDS_COMPONENTS "Build design studio components" ON)
|
||||||
|
|
||||||
project(KomplexHub VERSION 1.0 LANGUAGES CXX)
|
project(KomplexHub LANGUAGES CXX)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
@@ -20,94 +20,63 @@ set(QML_IMPORT_PATH ${QT_QML_OUTPUT_DIRECTORY}
|
|||||||
FORCE
|
FORCE
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(
|
find_package(Qt6 6.8 REQUIRED COMPONENTS Core Gui Widgets Qml Quick QuickControls2 QuickTimeline ShaderTools)
|
||||||
Qt6
|
|
||||||
REQUIRED COMPONENTS
|
|
||||||
Core
|
|
||||||
Gui
|
|
||||||
Widgets
|
|
||||||
Qml
|
|
||||||
Quick
|
|
||||||
QuickControls2
|
|
||||||
QuickTimeline
|
|
||||||
ShaderTools
|
|
||||||
Concurrent
|
|
||||||
)
|
|
||||||
|
|
||||||
qt_standard_project_setup()
|
qt_standard_project_setup()
|
||||||
|
|
||||||
qt_add_executable(${CMAKE_PROJECT_NAME}
|
qt_add_executable(${CMAKE_PROJECT_NAME}
|
||||||
|
README.md
|
||||||
|
LICENSE
|
||||||
|
images/icons/icons8-video.svg
|
||||||
)
|
)
|
||||||
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VERSION "1.0")
|
|
||||||
|
|
||||||
qt_add_resources(${CMAKE_PROJECT_NAME} "configuration"
|
qt_add_resources(${CMAKE_PROJECT_NAME} "configuration"
|
||||||
PREFIX "/"
|
PREFIX "/"
|
||||||
FILES
|
FILES
|
||||||
qtquickcontrols2.conf
|
qtquickcontrols2.conf
|
||||||
)
|
)
|
||||||
|
|
||||||
qt_add_resources(${CMAKE_PROJECT_NAME} "app_images"
|
qt_add_resources(${CMAKE_PROJECT_NAME} "app_images"
|
||||||
FILES
|
FILES
|
||||||
"images/icons/icons8-back.svg"
|
"images/icons/icons8-back.svg"
|
||||||
"images/icons/icons8-bill.svg"
|
"images/icons/icons8-bill.svg"
|
||||||
"images/icons/icons8-biotech.svg"
|
"images/icons/icons8-biotech.svg"
|
||||||
"images/icons/icons8-cancel.svg"
|
"images/icons/icons8-cancel.svg"
|
||||||
"images/icons/icons8-check-mark.svg"
|
"images/icons/icons8-check-mark.svg"
|
||||||
"images/icons/icons8-close-window.svg"
|
"images/icons/icons8-close-window.svg"
|
||||||
"images/icons/icons8-famous.svg"
|
"images/icons/icons8-famous.svg"
|
||||||
"images/icons/icons8-filter.svg"
|
"images/icons/icons8-filter.svg"
|
||||||
"images/icons/icons8-forward.svg"
|
"images/icons/icons8-forward.svg"
|
||||||
"images/icons/icons8-hdd.svg"
|
"images/icons/icons8-hdd.svg"
|
||||||
"images/icons/icons8-image.svg"
|
"images/icons/icons8-image.svg"
|
||||||
"images/icons/icons8-login.svg"
|
"images/icons/icons8-login.svg"
|
||||||
"images/icons/icons8-logout-rounded-left.svg"
|
"images/icons/icons8-logout-rounded-left.svg"
|
||||||
"images/icons/icons8-next.svg"
|
"images/icons/icons8-next.svg"
|
||||||
"images/icons/icons8-reply-arrow.svg"
|
"images/icons/icons8-reply-arrow.svg"
|
||||||
"images/icons/icons8-search.svg"
|
"images/icons/icons8-search.svg"
|
||||||
"images/icons/icons8-settings.svg"
|
"images/icons/icons8-settings.svg"
|
||||||
"images/icons/icons8-shopping-cart.svg"
|
"images/icons/icons8-shopping-cart.svg"
|
||||||
"images/icons/icons8-star-filled.svg"
|
"images/icons/icons8-star-filled.svg"
|
||||||
"images/icons/icons8-store.svg"
|
"images/icons/icons8-store.svg"
|
||||||
"images/icons/icons8-user-account.svg"
|
"images/icons/icons8-user-account.svg"
|
||||||
"images/icons/icons8-view-more.svg"
|
"images/icons/icons8-view-more.svg"
|
||||||
"images/icons/icons8-video.svg"
|
"images/icons/icons8-video.svg"
|
||||||
"images/icons/pexels-icon-filled-256.svg"
|
"images/kero/kero_build_1.png"
|
||||||
"images/icons/icons8-trash.svg"
|
"images/kero/kero_build_2.png"
|
||||||
"images/icons/icons8-download.svg"
|
"images/kero/kero_build_3.png"
|
||||||
"images/icons/icons8-play.svg"
|
"images/kero/kero_build_4.png"
|
||||||
"images/icons/icons8-stop.svg"
|
"images/kero/kero_build_error.png"
|
||||||
"images/icons/icons8-codepen.svg"
|
"images/kero/kero_choice.png"
|
||||||
"images/icons/icons8-cube.svg"
|
"images/kero/kero_error.png"
|
||||||
"images/icons/icons8-camera.svg"
|
"images/kero/kero_hello.png"
|
||||||
"images/icons/icons8-audio.svg"
|
"images/kero/kero_login.png"
|
||||||
"images/icons/icons8-3d-model.svg"
|
"images/kero/kero_no_results.png"
|
||||||
"images/icons/icons8-3d-glasses.svg"
|
"images/kero/kero_run_1.png"
|
||||||
"images/icons/kofi.gif"
|
"images/kero/kero_run_2.png"
|
||||||
"images/kero/kero_build_1.png"
|
"images/kero/kero_run_3.png"
|
||||||
"images/kero/kero_build_2.png"
|
"images/kero/kero_run_4.png"
|
||||||
"images/kero/kero_build_3.png"
|
"images/kero/kero_success.png"
|
||||||
"images/kero/kero_build_4.png"
|
"images/kero/kero_warning.png"
|
||||||
"images/kero/kero_build_error.png"
|
"images/icons/icons8-trash.svg"
|
||||||
"images/kero/kero_choice.png"
|
)
|
||||||
"images/kero/kero_error.png"
|
|
||||||
"images/kero/kero_hello.png"
|
|
||||||
"images/kero/kero_login.png"
|
|
||||||
"images/kero/kero_no_results.png"
|
|
||||||
"images/kero/kero_run_1.png"
|
|
||||||
"images/kero/kero_run_2.png"
|
|
||||||
"images/kero/kero_run_3.png"
|
|
||||||
"images/kero/kero_run_4.png"
|
|
||||||
"images/kero/kero_success.png"
|
|
||||||
"images/kero/kero_spotlight.png"
|
|
||||||
"images/kero/kero_star.png"
|
|
||||||
"images/kero/kero_warning.png"
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_definitions(
|
|
||||||
${CMAKE_PROJECT_NAME}
|
|
||||||
PUBLIC
|
|
||||||
KOMPLEX_LOCAL_DEV
|
|
||||||
)
|
|
||||||
|
|
||||||
include(qds)
|
include(qds)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Imported 3D assets and components imported from bundles will be created in this folder.
|
||||||
@@ -17,21 +17,7 @@ qt6_add_qml_module(KomplexHubContent
|
|||||||
"pages/SettingsPage.qml"
|
"pages/SettingsPage.qml"
|
||||||
"pages/UserProfilePage.qml"
|
"pages/UserProfilePage.qml"
|
||||||
"pages/WallpaperSettingsPage.qml"
|
"pages/WallpaperSettingsPage.qml"
|
||||||
"pages/VideoSearchPage.qml"
|
QML_FILES pages/VideoSearchPage.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)
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import KomplexHubContent
|
|||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
property MenuButton currentMenuButton
|
property MenuButton currentMenuButton
|
||||||
property bool popup: false
|
|
||||||
|
|
||||||
id: windowRoot
|
id: windowRoot
|
||||||
|
|
||||||
@@ -36,43 +35,8 @@ Rectangle {
|
|||||||
|
|
||||||
color: palette.base.lighter()
|
color: palette.base.lighter()
|
||||||
|
|
||||||
ColumnLayout
|
ColumnLayout {
|
||||||
{
|
|
||||||
height: popup ? 64 : 0
|
|
||||||
opacity: popup ? 1 : 0
|
|
||||||
|
|
||||||
MenuButton
|
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
|
||||||
|
|
||||||
height: 64
|
|
||||||
width: 100
|
|
||||||
text: qsTr("Back")
|
|
||||||
|
|
||||||
icon.height: 32
|
|
||||||
icon.width: 32
|
|
||||||
icon.url: "qrc:/images/icons/icons8-reply-arrow.svg"
|
|
||||||
|
|
||||||
onTriggered: () => {
|
|
||||||
pageLoader.item.closePopup()
|
|
||||||
selected = false
|
|
||||||
}
|
|
||||||
|
|
||||||
Behavior on opacity {
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
opacity: popup ? 0 : 1
|
|
||||||
visible: opacity > 0.01
|
|
||||||
id: windowMenuLayout
|
id: windowMenuLayout
|
||||||
Layout.fillHeight: true
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
MenuButton {
|
MenuButton {
|
||||||
@@ -81,14 +45,13 @@ Rectangle {
|
|||||||
|
|
||||||
height: 64
|
height: 64
|
||||||
width: 100
|
width: 100
|
||||||
text: qsTr("Home")
|
text: "Home"
|
||||||
|
|
||||||
icon.height: 32
|
icon.height: 32
|
||||||
icon.width: 32
|
icon.width: 32
|
||||||
icon.url: "qrc:/images/icons/icons8-famous.svg"
|
icon.url: "qrc:/images/icons/icons8-famous.svg"
|
||||||
|
|
||||||
onTriggered: () =>
|
onTriggered: () => {
|
||||||
{
|
|
||||||
pageLoader.page = "pages/HomePage.qml"
|
pageLoader.page = "pages/HomePage.qml"
|
||||||
|
|
||||||
if(currentMenuButton !== null)
|
if(currentMenuButton !== null)
|
||||||
@@ -99,17 +62,15 @@ Rectangle {
|
|||||||
currentMenuButton = this
|
currentMenuButton = this
|
||||||
|
|
||||||
searchContainer.preferredHeight = 0
|
searchContainer.preferredHeight = 0
|
||||||
searchContainer.reset()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuButton
|
MenuButton {
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
Layout.alignment: Qt.AlignTop
|
||||||
|
|
||||||
height: 64
|
height: 64
|
||||||
width: 100
|
width: 100
|
||||||
text: qsTr("Images")
|
text: "Images"
|
||||||
|
|
||||||
icon.height: 32
|
icon.height: 32
|
||||||
icon.width: 32
|
icon.width: 32
|
||||||
@@ -122,17 +83,15 @@ Rectangle {
|
|||||||
currentMenuButton = this
|
currentMenuButton = this
|
||||||
|
|
||||||
searchContainer.preferredHeight = 50
|
searchContainer.preferredHeight = 50
|
||||||
searchContainer.reset()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuButton
|
MenuButton {
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
Layout.alignment: Qt.AlignTop
|
||||||
|
|
||||||
height: 64
|
height: 64
|
||||||
width: 100
|
width: 100
|
||||||
text: qsTr("Videos")
|
text: "Videos"
|
||||||
|
|
||||||
icon.height: 32
|
icon.height: 32
|
||||||
icon.width: 32
|
icon.width: 32
|
||||||
@@ -145,17 +104,15 @@ Rectangle {
|
|||||||
currentMenuButton = this
|
currentMenuButton = this
|
||||||
|
|
||||||
searchContainer.preferredHeight = 50
|
searchContainer.preferredHeight = 50
|
||||||
searchContainer.reset()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuButton
|
MenuButton {
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
Layout.alignment: Qt.AlignTop
|
||||||
|
|
||||||
height: 64
|
height: 64
|
||||||
width: 100
|
width: 100
|
||||||
text: qsTr("Komplex")
|
text: "Live"
|
||||||
|
|
||||||
icon.height: 32
|
icon.height: 32
|
||||||
icon.width: 32
|
icon.width: 32
|
||||||
@@ -168,17 +125,16 @@ Rectangle {
|
|||||||
currentMenuButton = this
|
currentMenuButton = this
|
||||||
|
|
||||||
searchContainer.preferredHeight = 50
|
searchContainer.preferredHeight = 50
|
||||||
searchContainer.reset()
|
// searchContainer.searchTerm = pageLoader.page.query
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuButton
|
MenuButton {
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
Layout.alignment: Qt.AlignTop
|
||||||
|
|
||||||
height: 64
|
height: 64
|
||||||
width: 100
|
width: 100
|
||||||
text: qsTr("Installed")
|
text: "Installed"
|
||||||
|
|
||||||
icon.height: 32
|
icon.height: 32
|
||||||
icon.width: 32
|
icon.width: 32
|
||||||
@@ -191,23 +147,19 @@ Rectangle {
|
|||||||
currentMenuButton = this
|
currentMenuButton = this
|
||||||
|
|
||||||
searchContainer.preferredHeight = 0
|
searchContainer.preferredHeight = 0
|
||||||
searchContainer.reset()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item
|
Item {
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.minimumHeight: 100
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuButton
|
MenuButton {
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignBottom
|
Layout.alignment: Qt.AlignBottom
|
||||||
|
|
||||||
height: 64
|
height: 64
|
||||||
width: 100
|
width: 100
|
||||||
text: qsTr("Settings")
|
text: "Settings"
|
||||||
|
|
||||||
icon.height: 32
|
icon.height: 32
|
||||||
icon.width: 32
|
icon.width: 32
|
||||||
@@ -220,22 +172,14 @@ Rectangle {
|
|||||||
currentMenuButton = this
|
currentMenuButton = this
|
||||||
|
|
||||||
searchContainer.preferredHeight = 0
|
searchContainer.preferredHeight = 0
|
||||||
searchContainer.reset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Behavior on opacity
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle
|
Rectangle {
|
||||||
{
|
|
||||||
|
//Kirigami.Theme.colorSet: Kirigami.Theme.View
|
||||||
id: windowContainer
|
id: windowContainer
|
||||||
|
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
@@ -243,14 +187,12 @@ Rectangle {
|
|||||||
|
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
|
||||||
ColumnLayout
|
ColumnLayout {
|
||||||
{
|
|
||||||
id: windowContainerLayout
|
id: windowContainerLayout
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
SearchBar
|
SearchBar {
|
||||||
{
|
|
||||||
property int preferredHeight: 50
|
property int preferredHeight: 50
|
||||||
id: searchContainer
|
id: searchContainer
|
||||||
color: palette.base.lighter()
|
color: palette.base.lighter()
|
||||||
@@ -261,8 +203,7 @@ Rectangle {
|
|||||||
|
|
||||||
icon: "qrc:/images/icons/icons8-search.svg"
|
icon: "qrc:/images/icons/icons8-search.svg"
|
||||||
|
|
||||||
onSearchTermChanged: () =>
|
onSearchTermChanged: () => {
|
||||||
{
|
|
||||||
pageLoader.setSearchTerm()
|
pageLoader.setSearchTerm()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,8 +212,7 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle
|
Rectangle {
|
||||||
{
|
|
||||||
id: windowContent
|
id: windowContent
|
||||||
|
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
@@ -282,23 +222,20 @@ Rectangle {
|
|||||||
|
|
||||||
color: palette.base.darker()
|
color: palette.base.darker()
|
||||||
|
|
||||||
Loader
|
Loader {
|
||||||
{
|
|
||||||
property bool loading: false
|
property bool loading: false
|
||||||
property string page
|
property string page
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
onPageChanged: () =>
|
onPageChanged: () => {
|
||||||
{
|
|
||||||
loading = true
|
loading = true
|
||||||
fadeOutPage()
|
fadeOutPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
id: pageLoader
|
id: pageLoader
|
||||||
|
|
||||||
OpacityAnimator on opacity
|
OpacityAnimator on opacity {
|
||||||
{
|
|
||||||
id: pageLoaderAnimation
|
id: pageLoaderAnimation
|
||||||
|
|
||||||
target: pageLoader
|
target: pageLoader
|
||||||
@@ -313,7 +250,6 @@ Rectangle {
|
|||||||
{
|
{
|
||||||
pageLoader.loading = false
|
pageLoader.loading = false
|
||||||
pageLoader.updateSearchTerm();
|
pageLoader.updateSearchTerm();
|
||||||
popupConnection.target = pageLoader.item
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -369,7 +305,7 @@ Rectangle {
|
|||||||
|
|
||||||
function isSearchPage()
|
function isSearchPage()
|
||||||
{
|
{
|
||||||
return(
|
return (
|
||||||
pageLoader.item instanceof ImageSearchPage ||
|
pageLoader.item instanceof ImageSearchPage ||
|
||||||
pageLoader.item instanceof LiveSearchPage ||
|
pageLoader.item instanceof LiveSearchPage ||
|
||||||
pageLoader.item instanceof VideoSearchPage
|
pageLoader.item instanceof VideoSearchPage
|
||||||
@@ -381,34 +317,25 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeroBuildingAnimation
|
KeroBuildingAnimation {
|
||||||
{
|
|
||||||
id: buildingOverlay
|
id: buildingOverlay
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: false
|
visible: false
|
||||||
}
|
}
|
||||||
|
|
||||||
KeroLoadingAnimation
|
KeroLoadingAnimation {
|
||||||
{
|
|
||||||
id: loadingAnimation
|
id: loadingAnimation
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
|
// OpacityAnimator on opacity {
|
||||||
|
// duration: 150
|
||||||
|
// }
|
||||||
|
|
||||||
visible: opacity > 0
|
visible: opacity > 0
|
||||||
opacity: 0
|
opacity: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections
|
|
||||||
{
|
|
||||||
id: popupConnection
|
|
||||||
target: pageLoader.item
|
|
||||||
|
|
||||||
function onPopupChanged()
|
|
||||||
{
|
|
||||||
windowRoot.popup = pageLoader.item.popup
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: () => {
|
Component.onCompleted: () => {
|
||||||
homeMenubutton.selected = true
|
homeMenubutton.selected = true
|
||||||
currentMenuButton = homeMenubutton
|
currentMenuButton = homeMenubutton
|
||||||
@@ -434,15 +361,6 @@ Rectangle {
|
|||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "build_complete"
|
name: "build_complete"
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "popup"
|
|
||||||
when: popup
|
|
||||||
PropertyChanges {
|
|
||||||
target: searchContainer
|
|
||||||
preferredHeight: 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
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"
|
|
||||||
)
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
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
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
property string query
|
|
||||||
readonly property bool searchable: paginator.searchable
|
|
||||||
property bool popup: false
|
|
||||||
property int resultWidth: 256
|
|
||||||
property int resultHeight: 245
|
|
||||||
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
FeaturedImagesModel
|
|
||||||
{
|
|
||||||
id: searchModel
|
|
||||||
//query: rootItem.query
|
|
||||||
resultsPerPage: paginator.resultsPerPage
|
|
||||||
|
|
||||||
Component.onCompleted: () => nextPage()
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
id: resultsLayout
|
|
||||||
visible: opacity > 0.01
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.mediumMargin
|
|
||||||
|
|
||||||
KeroHeader
|
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 180
|
|
||||||
title: qsTr("Featured Images")
|
|
||||||
description: qsTr("A specially curated collection of images, courtesy of Pexels")
|
|
||||||
}
|
|
||||||
|
|
||||||
PaginatorGrid
|
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
id: paginator
|
|
||||||
model: searchModel
|
|
||||||
loading: model.state === FeaturedImagesModel.Loading
|
|
||||||
|
|
||||||
delegate: ItemDelegate
|
|
||||||
{
|
|
||||||
id: resultDelegate
|
|
||||||
|
|
||||||
width: resultWidth
|
|
||||||
height: resultHeight
|
|
||||||
|
|
||||||
required property string author
|
|
||||||
required property string description
|
|
||||||
required property string uuid
|
|
||||||
required property string thumbnail
|
|
||||||
required property string authorId
|
|
||||||
required property int index
|
|
||||||
|
|
||||||
SearchResultItem
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
title: parent.author
|
|
||||||
description: parent.description
|
|
||||||
thumbnail: parent.thumbnail
|
|
||||||
uuid: parent.uuid
|
|
||||||
pexels: true
|
|
||||||
selected: paginator.currentIndex === parent.index
|
|
||||||
|
|
||||||
onTriggered: () => paginator.currentIndex = parent.index
|
|
||||||
|
|
||||||
onViewMoreTriggered: () =>
|
|
||||||
{
|
|
||||||
showImagePopup(parent.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: popupContainer
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
ImageView
|
|
||||||
{
|
|
||||||
id: viewMoreImagePopup
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
|
|
||||||
Behavior on opacity {
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Behavior on opacity {
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function showImagePopup(index)
|
|
||||||
{
|
|
||||||
viewMoreImagePopup.author = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.AuthorRole)
|
|
||||||
viewMoreImagePopup.authorUrl = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.AuthorUrlRole)
|
|
||||||
viewMoreImagePopup.description = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.DescriptionRole)
|
|
||||||
viewMoreImagePopup.uuid = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.UuidRole)
|
|
||||||
viewMoreImagePopup.thumbnail = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.LargeThumbnailRole)
|
|
||||||
viewMoreImagePopup.original = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.OriginalUrlRole)
|
|
||||||
viewMoreImagePopup.portrait = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.PortraitUrlRole)
|
|
||||||
viewMoreImagePopup.landscape = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.LandscapeUrlRole)
|
|
||||||
viewMoreImagePopup.backgroundPortrait = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.BackgroundPortraitRole)
|
|
||||||
viewMoreImagePopup.backgroundLandscape = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.BackgroundLandscapeRole)
|
|
||||||
viewMoreImagePopup.fullScreen = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.ScreenUrlRole)
|
|
||||||
viewMoreImagePopup.portraitSize = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.PortraitSizeRole)
|
|
||||||
viewMoreImagePopup.landscapeSize = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.LandscapeSizeRole)
|
|
||||||
viewMoreImagePopup.fullScreenSize = searchModel.data(searchModel.index(index,0), FeaturedImagesModel.ScreenSizeRole)
|
|
||||||
viewMoreImagePopup.opacity = 1
|
|
||||||
popupContainer.opacity = 1
|
|
||||||
resultsLayout.opacity = 0
|
|
||||||
rootItem.popup = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function closePopup()
|
|
||||||
{
|
|
||||||
viewMoreImagePopup.opacity = 0
|
|
||||||
popupContainer.opacity = 0
|
|
||||||
resultsLayout.opacity = 1
|
|
||||||
rootItem.popup = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
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
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
property string query
|
|
||||||
readonly property bool searchable: false
|
|
||||||
property bool popup: false
|
|
||||||
property int resultWidth: 256
|
|
||||||
property int resultHeight: 245
|
|
||||||
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
NewestPacksModel
|
|
||||||
{
|
|
||||||
id: packsModel
|
|
||||||
resultsPerPage: paginator.resultsPerPage
|
|
||||||
|
|
||||||
Component.onCompleted: () => nextPage()
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
id: resultsLayout
|
|
||||||
visible: opacity > 0.01
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.mediumMargin
|
|
||||||
|
|
||||||
KeroHeader
|
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 180
|
|
||||||
title: qsTr("Featured Live Wallpapers")
|
|
||||||
description: qsTr("Live Wallpaper Packs from Komplex or ShaderToy")
|
|
||||||
}
|
|
||||||
|
|
||||||
PaginatorGrid
|
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
id: paginator
|
|
||||||
model: packsModel
|
|
||||||
loading: model.state === NewestPacksModel.Loading
|
|
||||||
|
|
||||||
delegate: ItemDelegate
|
|
||||||
{
|
|
||||||
id: resultDelegate
|
|
||||||
|
|
||||||
width: resultWidth
|
|
||||||
height: resultHeight
|
|
||||||
|
|
||||||
required property string name
|
|
||||||
required property string author
|
|
||||||
required property string description
|
|
||||||
required property string uuid
|
|
||||||
required property string thumbnail
|
|
||||||
required property string authorId
|
|
||||||
required property int index
|
|
||||||
|
|
||||||
SearchResultItem
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
title: parent.name
|
|
||||||
author: parent.author
|
|
||||||
description: parent.description
|
|
||||||
thumbnail: parent.thumbnail
|
|
||||||
uuid: parent.uuid
|
|
||||||
selected: paginator.currentIndex === parent.index
|
|
||||||
|
|
||||||
onTriggered: () => paginator.currentIndex = parent.index
|
|
||||||
|
|
||||||
onViewMoreTriggered: () =>
|
|
||||||
{
|
|
||||||
showWallpaperPopup(parent.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: popupContainer
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
PackView
|
|
||||||
{
|
|
||||||
id: viewMoreWallpaperPopup
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
|
|
||||||
Behavior on opacity {
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Behavior on opacity {
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function closePopup()
|
|
||||||
{
|
|
||||||
viewMoreWallpaperPopup.opacity = 0
|
|
||||||
popupContainer.opacity = 0
|
|
||||||
resultsLayout.opacity = 1
|
|
||||||
rootItem.popup = false
|
|
||||||
}
|
|
||||||
|
|
||||||
function showWallpaperPopup(index)
|
|
||||||
{
|
|
||||||
viewMoreWallpaperPopup.author = packsModel.data(packsModel.index(index,0), NewestPacksModel.AuthorRole)
|
|
||||||
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.uuid = packsModel.data(packsModel.index(index,0), NewestPacksModel.UuidRole)
|
|
||||||
viewMoreWallpaperPopup.opacity = 1
|
|
||||||
popupContainer.opacity = 1
|
|
||||||
resultsLayout.opacity = 0
|
|
||||||
rootItem.popup = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
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
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
readonly property bool searchable: false
|
|
||||||
property bool popup: false
|
|
||||||
property int resultWidth: 256
|
|
||||||
property int resultHeight: 245
|
|
||||||
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
FeaturedVideosModel
|
|
||||||
{
|
|
||||||
id: videosModel
|
|
||||||
resultsPerPage: paginator.resultsPerPage
|
|
||||||
windowSize: 80
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
id: resultsLayout
|
|
||||||
visible: opacity > 0.01
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.mediumMargin
|
|
||||||
|
|
||||||
KeroHeader
|
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 180
|
|
||||||
title: qsTr("Most Popular Videos")
|
|
||||||
description: qsTr("Most popular videos, provided courtesy of Pexels")
|
|
||||||
image: "qrc:/images/kero/kero_star.png"
|
|
||||||
}
|
|
||||||
|
|
||||||
PaginatorGrid
|
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
id: paginator
|
|
||||||
model: videosModel
|
|
||||||
loading: videosModel.state === FeaturedVideosModel.Loading
|
|
||||||
visible: opacity > 0.01
|
|
||||||
|
|
||||||
delegate: ItemDelegate
|
|
||||||
{
|
|
||||||
id: resultDelegate
|
|
||||||
|
|
||||||
width: resultWidth
|
|
||||||
height: resultHeight
|
|
||||||
|
|
||||||
required property string uuid
|
|
||||||
required property string author
|
|
||||||
required property string authorId
|
|
||||||
required property string authorUrl
|
|
||||||
required property string thumbnail
|
|
||||||
required property int index
|
|
||||||
|
|
||||||
SearchResultItem
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
author: parent.author
|
|
||||||
description: qsTr("")
|
|
||||||
thumbnail: parent.thumbnail
|
|
||||||
uuid: parent.uuid
|
|
||||||
pexels: true
|
|
||||||
selected: paginator.currentIndex === parent.index
|
|
||||||
|
|
||||||
onTriggered: () => paginator.currentIndex = parent.index
|
|
||||||
|
|
||||||
onViewMoreTriggered: () =>
|
|
||||||
{
|
|
||||||
showVideoPopup(parent.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: popupContainer
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
VideoView
|
|
||||||
{
|
|
||||||
id: videoDetailsPopup
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
|
|
||||||
Behavior on opacity
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Behavior on opacity
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: () =>
|
|
||||||
{
|
|
||||||
videosModel.nextPage()
|
|
||||||
}
|
|
||||||
|
|
||||||
function showVideoPopup(index)
|
|
||||||
{
|
|
||||||
videosModel.setItem(index)
|
|
||||||
videoDetailsPopup.author = searchModel.data(searchModel.index(index,0), VideoSearchModel.AuthorRole)
|
|
||||||
videoDetailsPopup.authorUrl = searchModel.data(searchModel.index(index,0), VideoSearchModel.AuthorUrlRole)
|
|
||||||
videoDetailsPopup.uuid = searchModel.data(searchModel.index(index,0), VideoSearchModel.UuidRole)
|
|
||||||
videoDetailsPopup.thumbnail = searchModel.data(searchModel.index(index,0), VideoSearchModel.ThumbnailRole)
|
|
||||||
videoDetailsPopup.modelIndex = index
|
|
||||||
videoDetailsPopup.model = searchModel.itemModel
|
|
||||||
videoDetailsPopup.opacity = 1
|
|
||||||
resultsLayout.opacity = 0
|
|
||||||
popupContainer.opacity = 1
|
|
||||||
rootItem.popup = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function closePopup()
|
|
||||||
{
|
|
||||||
videoDetailsPopup.opacity = 0
|
|
||||||
popupContainer.opacity = 0
|
|
||||||
resultsLayout.opacity = 1
|
|
||||||
rootItem.popup = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -5,124 +5,221 @@ import QtQuick.Layouts
|
|||||||
import KomplexHub
|
import KomplexHub
|
||||||
import KomplexHub.Controls
|
import KomplexHub.Controls
|
||||||
import KomplexHub.Kero
|
import KomplexHub.Kero
|
||||||
import KomplexHub.Plugin
|
import KomplexHubPlugin
|
||||||
import KomplexHub.Views
|
|
||||||
import KomplexHub.Pages
|
|
||||||
|
|
||||||
Item
|
Item
|
||||||
{
|
{
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
property string query
|
property string query
|
||||||
readonly property bool searchable: paginator.searchable
|
readonly property bool searchable: true
|
||||||
property bool popup: false
|
property int resultsPerRow: (resultsContainer.width - (Constants.largeMargin * 2)) / (resultWidth + Constants.mediumMargin)
|
||||||
|
property int rows: ((resultsContainer.height - (Constants.largeMargin * 2)) / (resultHeight + Constants.mediumMargin))
|
||||||
|
property int resultsPerPage: resultsPerRow * rows
|
||||||
|
property int emptyWidth: (resultsContainer.width - (Constants.largeMargin * 2)) - (resultsPerRow * (resultWidth + Constants.mediumMargin))
|
||||||
property int resultWidth: 256
|
property int resultWidth: 256
|
||||||
property int resultHeight: 245
|
property int resultHeight: 245
|
||||||
|
|
||||||
|
id: imageSearchPageRoot
|
||||||
|
|
||||||
ImageSearchModel
|
ImageSearchModel
|
||||||
{
|
{
|
||||||
id: searchModel
|
id: searchModel
|
||||||
query: rootItem.query
|
query: imageSearchPageRoot.query
|
||||||
resultsPerPage: paginator.resultsPerPage
|
resultsPerPage: imageSearchPageRoot.resultsPerPage
|
||||||
}
|
|
||||||
|
|
||||||
PaginatorGrid
|
|
||||||
{
|
|
||||||
id: paginator
|
|
||||||
anchors.fill: parent
|
|
||||||
model: searchModel
|
|
||||||
loading: model.state === ImageSearchModel.Loading
|
|
||||||
|
|
||||||
delegate: ItemDelegate
|
|
||||||
{
|
|
||||||
id: resultDelegate
|
|
||||||
|
|
||||||
width: resultWidth
|
|
||||||
height: resultHeight
|
|
||||||
|
|
||||||
required property string author
|
|
||||||
required property string description
|
|
||||||
required property string uuid
|
|
||||||
required property string thumbnail
|
|
||||||
required property string authorId
|
|
||||||
required property int index
|
|
||||||
|
|
||||||
SearchResultItem
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
title: parent.author
|
|
||||||
description: parent.description
|
|
||||||
thumbnail: parent.thumbnail
|
|
||||||
uuid: parent.uuid
|
|
||||||
pexels: true
|
|
||||||
selected: paginator.currentIndex === parent.index
|
|
||||||
|
|
||||||
onTriggered: () => paginator.currentIndex = parent.index
|
|
||||||
|
|
||||||
onViewMoreTriggered: () =>
|
|
||||||
{
|
|
||||||
showImagePopup(parent.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle
|
Rectangle
|
||||||
{
|
{
|
||||||
id: popupContainer
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
opacity: 0
|
|
||||||
color: palette.base
|
color: palette.base
|
||||||
|
|
||||||
ImageView
|
Rectangle
|
||||||
{
|
{
|
||||||
id: viewMoreImagePopup
|
id: resultsContainer
|
||||||
anchors.fill: parent
|
anchors.top: parent.top
|
||||||
opacity: 0
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: buttonBoxLayout.top
|
||||||
|
|
||||||
Behavior on opacity {
|
color: "transparent"
|
||||||
NumberAnimation
|
|
||||||
|
ScrollView
|
||||||
|
{
|
||||||
|
id: resultsView
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
RowLayout
|
||||||
{
|
{
|
||||||
duration: 250
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.margins: Constants.largeMargin
|
||||||
|
|
||||||
|
Item
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: emptyWidth / 2
|
||||||
|
Layout.maximumWidth: emptyWidth / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
GridLayout
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
columns: imageSearchPageRoot.resultsPerRow
|
||||||
|
columnSpacing: Constants.mediumMargin
|
||||||
|
rowSpacing: Constants.mediumMargin
|
||||||
|
|
||||||
|
Repeater
|
||||||
|
{
|
||||||
|
model: searchModel
|
||||||
|
|
||||||
|
delegate: Item
|
||||||
|
{
|
||||||
|
width: 256
|
||||||
|
height: 245
|
||||||
|
required property string author
|
||||||
|
required property string description
|
||||||
|
required property string uuid
|
||||||
|
required property string thumbnail
|
||||||
|
required property string authorId
|
||||||
|
|
||||||
|
SearchResultItem
|
||||||
|
{
|
||||||
|
anchors.fill: parent
|
||||||
|
title: parent.author
|
||||||
|
author: qsTr("Pexels Images")
|
||||||
|
description: parent.description
|
||||||
|
thumbnail: parent.thumbnail
|
||||||
|
uuid: parent.uuid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Behavior on opacity {
|
RowLayout
|
||||||
NumberAnimation
|
{
|
||||||
|
id: buttonBoxLayout
|
||||||
|
height: 35
|
||||||
|
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.margins: Constants.largeMargin
|
||||||
|
|
||||||
|
SquareButton
|
||||||
{
|
{
|
||||||
duration: 250
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: 128
|
||||||
|
|
||||||
|
icon.source: "qrc:/images/icons/icons8-back.svg"
|
||||||
|
icon.height: 16
|
||||||
|
icon.width: 16
|
||||||
|
text: qsTr("Previous")
|
||||||
|
enabled: searchModel.hasPreviousPage
|
||||||
|
|
||||||
|
onTriggered: () => searchModel.previousPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
|
SquareButton
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: 128
|
||||||
|
|
||||||
|
icon.source: "qrc:/images/icons/icons8-next.svg"
|
||||||
|
icon.height: 16
|
||||||
|
icon.width: 16
|
||||||
|
text: qsTr("Next")
|
||||||
|
enabled: searchModel.hasNextPage
|
||||||
|
|
||||||
|
onTriggered: () => searchModel.nextPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showImagePopup(index)
|
KeroErrorAvatar
|
||||||
{
|
{
|
||||||
viewMoreImagePopup.author = searchModel.data(searchModel.index(index,0), ImageSearchModel.AuthorRole)
|
id: errorOverlay
|
||||||
viewMoreImagePopup.authorUrl = searchModel.data(searchModel.index(index,0), ImageSearchModel.AuthorUrlRole)
|
|
||||||
viewMoreImagePopup.description = searchModel.data(searchModel.index(index,0), ImageSearchModel.DescriptionRole)
|
anchors.fill: parent
|
||||||
viewMoreImagePopup.uuid = searchModel.data(searchModel.index(index,0), ImageSearchModel.UuidRole)
|
opacity: 0
|
||||||
viewMoreImagePopup.thumbnail = searchModel.data(searchModel.index(index,0), ImageSearchModel.LargeThumbnailRole)
|
|
||||||
viewMoreImagePopup.original = searchModel.data(searchModel.index(index,0), ImageSearchModel.OriginalUrlRole)
|
|
||||||
viewMoreImagePopup.portrait = searchModel.data(searchModel.index(index,0), ImageSearchModel.PortraitUrlRole)
|
|
||||||
viewMoreImagePopup.landscape = searchModel.data(searchModel.index(index,0), ImageSearchModel.LandscapeUrlRole)
|
|
||||||
viewMoreImagePopup.backgroundPortrait = searchModel.data(searchModel.index(index,0), ImageSearchModel.BackgroundPortraitRole)
|
|
||||||
viewMoreImagePopup.backgroundLandscape = searchModel.data(searchModel.index(index,0), ImageSearchModel.BackgroundLandscapeRole)
|
|
||||||
viewMoreImagePopup.fullScreen = searchModel.data(searchModel.index(index,0), ImageSearchModel.ScreenUrlRole)
|
|
||||||
viewMoreImagePopup.portraitSize = searchModel.data(searchModel.index(index,0), ImageSearchModel.PortraitSizeRole)
|
|
||||||
viewMoreImagePopup.landscapeSize = searchModel.data(searchModel.index(index,0), ImageSearchModel.LandscapeSizeRole)
|
|
||||||
viewMoreImagePopup.fullScreenSize = searchModel.data(searchModel.index(index,0), ImageSearchModel.ScreenSizeRole)
|
|
||||||
viewMoreImagePopup.opacity = 1
|
|
||||||
popupContainer.opacity = 1
|
|
||||||
paginator.opacity = 0
|
|
||||||
rootItem.popup = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function closePopup()
|
KeroNoResultsAvatar
|
||||||
{
|
{
|
||||||
viewMoreImagePopup.opacity = 0
|
id: noResultsOverlay
|
||||||
popupContainer.opacity = 0
|
|
||||||
paginator.opacity = 1
|
anchors.fill: parent
|
||||||
rootItem.popup = false
|
opacity: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeroLoadingAnimation
|
||||||
|
{
|
||||||
|
id: loadingOverlay
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
states: [
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "loading"
|
||||||
|
when: searchModel.state == ImageSearchModel.Loading
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: loadingOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "empty"
|
||||||
|
when: searchModel.totalResults === 0
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: noResultsOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: buttonBoxLayout
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "error"
|
||||||
|
when: searchModel.state == ImageSearchModel.Error
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: errorOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ import QtQuick
|
|||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import QtQuick.Dialogs
|
import QtQuick.Dialogs
|
||||||
|
|
||||||
import KomplexHub
|
import KomplexHub
|
||||||
import KomplexHub.Controls
|
import KomplexHub.Controls
|
||||||
import KomplexHub.Kero
|
import KomplexHub.Kero
|
||||||
import KomplexHub.Plugin
|
import KomplexHubPlugin
|
||||||
import KomplexHub.Views
|
|
||||||
import KomplexHub.Pages
|
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: root
|
id: root
|
||||||
|
|||||||
@@ -1,121 +1,78 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
|
||||||
import KomplexHub
|
import KomplexHub
|
||||||
import KomplexHub.Controls
|
import KomplexHub.Controls
|
||||||
import KomplexHub.Kero
|
import KomplexHub.Kero
|
||||||
import KomplexHub.Plugin
|
|
||||||
import KomplexHub.Views
|
|
||||||
import KomplexHub.Pages
|
|
||||||
|
|
||||||
Item
|
Item {
|
||||||
{
|
id: imageSearchPageRoot
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
property string query
|
SearchResultList {
|
||||||
readonly property bool searchable: paginator.searchable
|
id: searchResultList
|
||||||
property bool popup: false
|
|
||||||
property int resultWidth: 256
|
|
||||||
property int resultHeight: 245
|
|
||||||
|
|
||||||
PackSearchModel
|
|
||||||
{
|
|
||||||
id: searchModel
|
|
||||||
query: rootItem.query
|
|
||||||
resultsPerPage: paginator.resultsPerPage
|
|
||||||
}
|
|
||||||
|
|
||||||
PaginatorGrid
|
|
||||||
{
|
|
||||||
id: paginator
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
model: searchModel
|
color: palette.base
|
||||||
loading: model.state === PackSearchModel.Loading
|
|
||||||
|
|
||||||
delegate: ItemDelegate
|
|
||||||
{
|
|
||||||
id: resultDelegate
|
|
||||||
|
|
||||||
width: resultWidth
|
|
||||||
height: resultHeight
|
|
||||||
|
|
||||||
required property string name
|
|
||||||
required property string author
|
|
||||||
required property string description
|
|
||||||
required property string uuid
|
|
||||||
required property string thumbnail
|
|
||||||
required property string authorId
|
|
||||||
required property int index
|
|
||||||
|
|
||||||
SearchResultItem
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
title: parent.name
|
|
||||||
author: parent.author
|
|
||||||
description: parent.description
|
|
||||||
thumbnail: parent.thumbnail
|
|
||||||
uuid: parent.uuid
|
|
||||||
selected: paginator.currentIndex === parent.index
|
|
||||||
|
|
||||||
onTriggered: () => paginator.currentIndex = parent.index
|
|
||||||
|
|
||||||
onViewMoreTriggered: () =>
|
|
||||||
{
|
|
||||||
showWallpaperPopup(parent.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle
|
KeroErrorAvatar {
|
||||||
{
|
id: errorOverlay
|
||||||
id: popupContainer
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
opacity: 0
|
opacity: 0
|
||||||
color: palette.base
|
}
|
||||||
|
|
||||||
PackView
|
KeroNoResultsAvatar {
|
||||||
{
|
id: noResultsOverlay
|
||||||
id: viewMoreWallpaperPopup
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
//model: videosModel.itemModel
|
|
||||||
|
|
||||||
Behavior on opacity {
|
anchors.fill: parent
|
||||||
NumberAnimation
|
opacity: 0
|
||||||
{
|
}
|
||||||
duration: 250
|
|
||||||
}
|
KeroLoadingAnimation {
|
||||||
|
id: loadingOverlay
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
states: [
|
||||||
|
State {
|
||||||
|
name: "loading"
|
||||||
|
when: searchResultList.state === "loading"
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
target: loadingOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges {
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State {
|
||||||
|
name: "empty"
|
||||||
|
when: searchResultList.state === "empty"
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
target: noResultsOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges {
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State {
|
||||||
|
name: "error"
|
||||||
|
when: searchResultList.state === "error"
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
target: errorOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges {
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
]
|
||||||
Behavior on opacity {
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function closePopup()
|
|
||||||
{
|
|
||||||
viewMoreWallpaperPopup.opacity = 0
|
|
||||||
popupContainer.opacity = 0
|
|
||||||
paginator.opacity = 1
|
|
||||||
rootItem.popup = false
|
|
||||||
}
|
|
||||||
|
|
||||||
function showWallpaperPopup(index)
|
|
||||||
{
|
|
||||||
viewMoreWallpaperPopup.author = searchModel.data(searchModel.index(index,0), PackSearchModel.AuthorRole)
|
|
||||||
viewMoreWallpaperPopup.authorId = searchModel.data(searchModel.index(index,0), PackSearchModel.AuthorIdRole)
|
|
||||||
viewMoreWallpaperPopup.description = searchModel.data(searchModel.index(index,0), PackSearchModel.DescriptionRole)
|
|
||||||
viewMoreWallpaperPopup.thumbnail = searchModel.data(searchModel.index(index,0), PackSearchModel.ThumbnailRole)
|
|
||||||
viewMoreWallpaperPopup.uuid = searchModel.data(searchModel.index(index,0), PackSearchModel.UuidRole)
|
|
||||||
viewMoreWallpaperPopup.opacity = 1
|
|
||||||
popupContainer.opacity = 1
|
|
||||||
paginator.opacity = 0
|
|
||||||
rootItem.popup = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
|
||||||
import KomplexHub
|
import KomplexHub
|
||||||
import KomplexHub.Controls
|
import KomplexHub.Controls
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
import KomplexHub.Views
|
|
||||||
import KomplexHub.Pages
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: loginFormRoot
|
id: loginFormRoot
|
||||||
|
|||||||
@@ -1,145 +0,0 @@
|
|||||||
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
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
property string query
|
|
||||||
readonly property bool searchable: false
|
|
||||||
property bool popup: false
|
|
||||||
property int resultWidth: 256
|
|
||||||
property int resultHeight: 245
|
|
||||||
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
NewestPacksModel
|
|
||||||
{
|
|
||||||
id: packsModel
|
|
||||||
resultsPerPage: paginator.resultsPerPage
|
|
||||||
|
|
||||||
Component.onCompleted: () => nextPage()
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
id: resultsLayout
|
|
||||||
visible: opacity > 0.01
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.mediumMargin
|
|
||||||
|
|
||||||
KeroHeader
|
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 180
|
|
||||||
title: qsTr("Newest Live Wallpapers")
|
|
||||||
description: qsTr("Live Wallpaper Packs from Komplex or ShaderToy")
|
|
||||||
image: "qrc:/images/kero/kero_star.png"
|
|
||||||
}
|
|
||||||
|
|
||||||
PaginatorGrid
|
|
||||||
{
|
|
||||||
Layout.alignment: Qt.AlignTop
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
id: paginator
|
|
||||||
model: packsModel
|
|
||||||
loading: model.state === NewestPacksModel.Loading
|
|
||||||
|
|
||||||
delegate: ItemDelegate
|
|
||||||
{
|
|
||||||
id: resultDelegate
|
|
||||||
|
|
||||||
width: resultWidth
|
|
||||||
height: resultHeight
|
|
||||||
|
|
||||||
required property string name
|
|
||||||
required property string author
|
|
||||||
required property string description
|
|
||||||
required property string uuid
|
|
||||||
required property string thumbnail
|
|
||||||
required property string authorId
|
|
||||||
required property int index
|
|
||||||
|
|
||||||
SearchResultItem
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
title: parent.name
|
|
||||||
author: parent.author
|
|
||||||
description: parent.description
|
|
||||||
thumbnail: parent.thumbnail
|
|
||||||
uuid: parent.uuid
|
|
||||||
selected: paginator.currentIndex === parent.index
|
|
||||||
|
|
||||||
onTriggered: () => paginator.currentIndex = parent.index
|
|
||||||
|
|
||||||
onViewMoreTriggered: () =>
|
|
||||||
{
|
|
||||||
showWallpaperPopup(parent.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: popupContainer
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
PackView
|
|
||||||
{
|
|
||||||
id: viewMoreWallpaperPopup
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
|
|
||||||
Behavior on opacity {
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Behavior on opacity {
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function closePopup()
|
|
||||||
{
|
|
||||||
viewMoreWallpaperPopup.opacity = 0
|
|
||||||
popupContainer.opacity = 0
|
|
||||||
resultsLayout.opacity = 1
|
|
||||||
rootItem.popup = false
|
|
||||||
}
|
|
||||||
|
|
||||||
function showWallpaperPopup(index)
|
|
||||||
{
|
|
||||||
viewMoreWallpaperPopup.author = packsModel.data(packsModel.index(index,0), NewestPacksModel.AuthorRole)
|
|
||||||
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.opacity = 1
|
|
||||||
popupContainer.opacity = 1
|
|
||||||
resultsLayout.opacity = 0
|
|
||||||
rootItem.popup = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
|
||||||
import KomplexHub
|
import KomplexHub
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Kero
|
import KomplexHub.Kero
|
||||||
import KomplexHub.Plugin
|
|
||||||
import KomplexHub.Views
|
|
||||||
import KomplexHub.Pages
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
readonly property bool searchable: false
|
readonly property bool searchable: false
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
|
||||||
import KomplexHub
|
import KomplexHub
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
import KomplexHub.Views
|
|
||||||
import KomplexHub.Pages
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|||||||
@@ -5,121 +5,221 @@ import QtQuick.Layouts
|
|||||||
import KomplexHub
|
import KomplexHub
|
||||||
import KomplexHub.Controls
|
import KomplexHub.Controls
|
||||||
import KomplexHub.Kero
|
import KomplexHub.Kero
|
||||||
import KomplexHub.Plugin
|
import KomplexHubPlugin
|
||||||
import KomplexHub.Views
|
|
||||||
import KomplexHub.Pages
|
|
||||||
|
|
||||||
Item
|
Item
|
||||||
{
|
{
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
property string query
|
property string query
|
||||||
readonly property bool searchable: paginator.searchable
|
readonly property bool searchable: true
|
||||||
property bool popup: false
|
property int resultsPerRow: (resultsContainer.width - (Constants.largeMargin * 2)) / (resultWidth + Constants.mediumMargin)
|
||||||
|
property int rows: ((resultsContainer.height - (Constants.largeMargin * 2)) / (resultHeight + Constants.mediumMargin))
|
||||||
|
property int resultsPerPage: resultsPerRow * rows
|
||||||
|
property int emptyWidth: (resultsContainer.width - (Constants.largeMargin * 2)) - (resultsPerRow * (resultWidth + Constants.mediumMargin))
|
||||||
property int resultWidth: 256
|
property int resultWidth: 256
|
||||||
property int resultHeight: 245
|
property int resultHeight: 245
|
||||||
|
|
||||||
|
id: videoSearchPageRoot
|
||||||
|
|
||||||
VideoSearchModel
|
VideoSearchModel
|
||||||
{
|
{
|
||||||
id: searchModel
|
id: searchModel
|
||||||
query: rootItem.query
|
query: videoSearchPageRoot.query
|
||||||
resultsPerPage: paginator.resultsPerPage
|
resultsPerPage: videoSearchPageRoot.resultsPerPage
|
||||||
}
|
|
||||||
|
|
||||||
PaginatorGrid
|
|
||||||
{
|
|
||||||
id: paginator
|
|
||||||
anchors.fill: parent
|
|
||||||
model: searchModel
|
|
||||||
loading: model.state === VideoSearchModel.Loading
|
|
||||||
visible: opacity > 0.01
|
|
||||||
|
|
||||||
delegate: ItemDelegate
|
|
||||||
{
|
|
||||||
id: resultDelegate
|
|
||||||
|
|
||||||
width: resultWidth
|
|
||||||
height: resultHeight
|
|
||||||
|
|
||||||
required property string uuid
|
|
||||||
required property string author
|
|
||||||
required property string authorId
|
|
||||||
required property string authorUrl
|
|
||||||
required property string thumbnail
|
|
||||||
required property int index
|
|
||||||
|
|
||||||
SearchResultItem
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
author: parent.author
|
|
||||||
description: qsTr("No description available")
|
|
||||||
thumbnail: parent.thumbnail
|
|
||||||
uuid: parent.uuid
|
|
||||||
pexels: true
|
|
||||||
selected: paginator.currentIndex === parent.index
|
|
||||||
|
|
||||||
onTriggered: () => paginator.currentIndex = parent.index
|
|
||||||
|
|
||||||
onViewMoreTriggered: () =>
|
|
||||||
{
|
|
||||||
showVideoPopup(parent.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle
|
Rectangle
|
||||||
{
|
{
|
||||||
id: popupContainer
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
color: palette.base
|
color: palette.base
|
||||||
|
|
||||||
VideoView
|
Rectangle
|
||||||
{
|
{
|
||||||
id: viewMoreVideoPopup
|
id: resultsContainer
|
||||||
anchors.fill: parent
|
anchors.top: parent.top
|
||||||
opacity: 0
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: buttonBoxLayout.top
|
||||||
|
|
||||||
Behavior on opacity
|
color: "transparent"
|
||||||
|
|
||||||
|
ScrollView
|
||||||
{
|
{
|
||||||
NumberAnimation
|
id: resultsView
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
RowLayout
|
||||||
{
|
{
|
||||||
duration: 250
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.margins: Constants.largeMargin
|
||||||
|
|
||||||
|
Item
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: emptyWidth / 2
|
||||||
|
Layout.maximumWidth: emptyWidth / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
GridLayout
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
columns: videoSearchPageRoot.resultsPerRow
|
||||||
|
columnSpacing: Constants.mediumMargin
|
||||||
|
rowSpacing: Constants.mediumMargin
|
||||||
|
|
||||||
|
Repeater
|
||||||
|
{
|
||||||
|
model: searchModel
|
||||||
|
|
||||||
|
delegate: Item {
|
||||||
|
width: resultWidth
|
||||||
|
height: resultHeight
|
||||||
|
|
||||||
|
required property string uuid
|
||||||
|
required property string author
|
||||||
|
required property string authorId
|
||||||
|
required property string authorUrl
|
||||||
|
required property string thumbnail
|
||||||
|
|
||||||
|
SearchResultItem
|
||||||
|
{
|
||||||
|
anchors.fill: parent
|
||||||
|
title: parent.author
|
||||||
|
author: parent.author
|
||||||
|
description: "Video provided by Pexels"
|
||||||
|
thumbnail: parent.thumbnail
|
||||||
|
uuid: parent.uuid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Behavior on opacity
|
RowLayout
|
||||||
{
|
{
|
||||||
NumberAnimation
|
id: buttonBoxLayout
|
||||||
|
height: 35
|
||||||
|
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.margins: Constants.largeMargin
|
||||||
|
|
||||||
|
SquareButton
|
||||||
{
|
{
|
||||||
duration: 250
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: 128
|
||||||
|
|
||||||
|
icon.source: "qrc:/images/icons/icons8-back.svg"
|
||||||
|
icon.height: 16
|
||||||
|
icon.width: 16
|
||||||
|
text: qsTr("Previous")
|
||||||
|
enabled: searchModel.hasPreviousPage
|
||||||
|
|
||||||
|
onTriggered: () => searchModel.previousPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
|
SquareButton
|
||||||
|
{
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: 128
|
||||||
|
|
||||||
|
icon.source: "qrc:/images/icons/icons8-next.svg"
|
||||||
|
icon.height: 16
|
||||||
|
icon.width: 16
|
||||||
|
text: qsTr("Next")
|
||||||
|
enabled: searchModel.hasNextPage
|
||||||
|
|
||||||
|
onTriggered: () => searchModel.nextPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showVideoPopup(index)
|
KeroErrorAvatar
|
||||||
{
|
{
|
||||||
searchModel.setItem(index)
|
id: errorOverlay
|
||||||
viewMoreVideoPopup.author = searchModel.data(searchModel.index(index,0), VideoSearchModel.AuthorRole)
|
|
||||||
viewMoreVideoPopup.authorUrl = searchModel.data(searchModel.index(index,0), VideoSearchModel.AuthorUrlRole)
|
anchors.fill: parent
|
||||||
viewMoreVideoPopup.uuid = searchModel.data(searchModel.index(index,0), VideoSearchModel.UuidRole)
|
opacity: 0
|
||||||
viewMoreVideoPopup.thumbnail = searchModel.data(searchModel.index(index,0), VideoSearchModel.ThumbnailRole)
|
|
||||||
viewMoreVideoPopup.modelIndex = index
|
|
||||||
viewMoreVideoPopup.model = searchModel.itemModel
|
|
||||||
viewMoreVideoPopup.opacity = 1
|
|
||||||
paginator.opacity = 0
|
|
||||||
popupContainer.opacity = 1
|
|
||||||
rootItem.popup = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function closePopup()
|
KeroNoResultsAvatar
|
||||||
{
|
{
|
||||||
viewMoreVideoPopup.opacity = 0
|
id: noResultsOverlay
|
||||||
popupContainer.opacity = 0
|
|
||||||
paginator.opacity = 1
|
anchors.fill: parent
|
||||||
rootItem.popup = false
|
opacity: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeroLoadingAnimation
|
||||||
|
{
|
||||||
|
id: loadingOverlay
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
states: [
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "loading"
|
||||||
|
when: searchModel.state == VideoSearchModel.Loading
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: loadingOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "empty"
|
||||||
|
when: searchModel.totalResults === 0
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: noResultsOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: buttonBoxLayout
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State
|
||||||
|
{
|
||||||
|
name: "error"
|
||||||
|
when: searchModel.state == VideoSearchModel.Error
|
||||||
|
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: errorOverlay
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
PropertyChanges
|
||||||
|
{
|
||||||
|
target: resultsView
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,12 +31,9 @@ import QtQuick.Layouts
|
|||||||
//import org.kde.plasma.core as PlasmaCore
|
//import org.kde.plasma.core as PlasmaCore
|
||||||
import QtCore
|
import QtCore
|
||||||
import Qt.labs.folderlistmodel 2.15
|
import Qt.labs.folderlistmodel 2.15
|
||||||
|
|
||||||
import KomplexHub
|
import KomplexHub
|
||||||
import KomplexHub.Controls
|
import KomplexHub.Controls
|
||||||
import KomplexHub.Plugin
|
import KomplexHubPlugin
|
||||||
import KomplexHub.Views
|
|
||||||
import KomplexHub.Pages
|
|
||||||
|
|
||||||
//import com.github.digitalartifex.komplex 1.0 as Komplex
|
//import com.github.digitalartifex.komplex 1.0 as Komplex
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
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"
|
|
||||||
)
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property DownloadManager manager: null
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
VerticalSpacer { }
|
|
||||||
|
|
||||||
KeroSuccessAvatar
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredHeight: 512
|
|
||||||
Layout.maximumHeight: 512
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 36
|
|
||||||
Layout.maximumHeight: 36
|
|
||||||
Layout.margins: Constants.largeMargin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.preferredWidth: 186
|
|
||||||
Layout.fillHeight: true
|
|
||||||
text: qsTr("Okay")
|
|
||||||
|
|
||||||
onTriggered: () =>
|
|
||||||
{
|
|
||||||
if(manager != null)
|
|
||||||
{
|
|
||||||
manager.reset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.preferredWidth: 186
|
|
||||||
Layout.fillHeight: true
|
|
||||||
|
|
||||||
text: qsTr("Set Wallpaper")
|
|
||||||
icon.source: "qrc:/images/icons/icons8-download.svg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VerticalSpacer {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
import QtQuick.Effects
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
import KomplexHub.Kero
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property string thumbnail
|
|
||||||
property DownloadManager manager
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
BackgroundImage
|
|
||||||
{
|
|
||||||
source: thumbnail
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.largeMargin
|
|
||||||
|
|
||||||
Item { Layout.preferredHeight: 64; Layout.fillWidth: true }
|
|
||||||
|
|
||||||
KeroBuildingAnimation
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.fillHeight: true
|
|
||||||
}
|
|
||||||
|
|
||||||
VerticalSpacer {}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: qsTr("Download Progress")
|
|
||||||
font: Constants.h3Font
|
|
||||||
color : palette.text
|
|
||||||
Layout.preferredHeight: Constants.largeMargin
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: Constants.largeMargin
|
|
||||||
|
|
||||||
ProgressBar
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
value: manager.downloadProgress
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: manager.downloadedBytes
|
|
||||||
font: Constants.h4Font
|
|
||||||
color : palette.text
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: "/"
|
|
||||||
font: Constants.h4Font
|
|
||||||
color : palette.text
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: manager.downloadSize
|
|
||||||
font: Constants.h4Font
|
|
||||||
color : palette.text
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: qsTr("Install Progress")
|
|
||||||
font: Constants.h3Font
|
|
||||||
color : palette.text
|
|
||||||
height: 32
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: Constants.largeMargin
|
|
||||||
|
|
||||||
ProgressBar
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
value: manager.compileProgress
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: manager.compileStepsCompleted
|
|
||||||
font: Constants.h4Font
|
|
||||||
color : palette.text
|
|
||||||
Layout.preferredHeight: Constants.largeMargin
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: "/"
|
|
||||||
font: Constants.h4Font
|
|
||||||
color : palette.text
|
|
||||||
Layout.preferredHeight: Constants.largeMargin
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: manager.compileSteps
|
|
||||||
font: Constants.h4Font
|
|
||||||
color : palette.text
|
|
||||||
Layout.preferredHeight: Constants.largeMargin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Item { Layout.preferredHeight: Constants.largeMargin * 2; Layout.fillWidth: true }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property DownloadManager manager: null
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
VerticalSpacer { }
|
|
||||||
|
|
||||||
KeroWarningAvatar
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredHeight: 512
|
|
||||||
Layout.maximumHeight: 512
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 36
|
|
||||||
Layout.maximumHeight: 36
|
|
||||||
Layout.margins: Constants.largeMargin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.preferredWidth: 186
|
|
||||||
Layout.fillHeight: true
|
|
||||||
text: qsTr("Okay")
|
|
||||||
|
|
||||||
onTriggered: () =>
|
|
||||||
{
|
|
||||||
if(manager != null)
|
|
||||||
{
|
|
||||||
manager.reset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VerticalSpacer {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,339 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
import QtQuick.Effects
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property string uuid
|
|
||||||
property string author
|
|
||||||
property string authorUrl
|
|
||||||
property string description
|
|
||||||
property string thumbnail
|
|
||||||
property string portrait
|
|
||||||
property string landscape
|
|
||||||
property string fullScreen
|
|
||||||
property string portraitSize
|
|
||||||
property string landscapeSize
|
|
||||||
property string fullScreenSize
|
|
||||||
property string backgroundPortrait
|
|
||||||
property string backgroundLandscape
|
|
||||||
|
|
||||||
property int imageHeight
|
|
||||||
property int imageWidth
|
|
||||||
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
DownloadManager
|
|
||||||
{
|
|
||||||
id: downloadManager
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: pageView
|
|
||||||
anchors.fill: parent
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
BackgroundImage
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
source: width > height ? backgroundLandscape : backgroundPortrait
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.largeMargin
|
|
||||||
spacing: Constants.largeMargin
|
|
||||||
|
|
||||||
ImageFrame
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
|
|
||||||
Layout.topMargin: Constants.largeMargin
|
|
||||||
Layout.preferredHeight: width / 1.77777777778
|
|
||||||
Layout.maximumWidth: 800
|
|
||||||
|
|
||||||
source: rootItem.thumbnail
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
id: titleText
|
|
||||||
text: rootItem.author
|
|
||||||
color: palette.text
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: Constants.h3Font.pixelSize
|
|
||||||
elide: Text.ElideRight
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignTop | Qt.AlignLeft
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
id: descriptionText
|
|
||||||
text: rootItem.description
|
|
||||||
color: palette.text
|
|
||||||
font.pointSize: Constants.h4Font.pixelSize
|
|
||||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignTop| Qt.AlignLeft
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Spacer **/
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: qsTr("Available Downloads")
|
|
||||||
color: palette.text
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: Constants.h3Font.pixelSize
|
|
||||||
elide: Text.ElideRight
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignTop| Qt.AlignLeft
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
ComboBox
|
|
||||||
{
|
|
||||||
id: downloadSelector
|
|
||||||
model:[
|
|
||||||
"Screen (" + fullScreenSize + ")",
|
|
||||||
"Portrait (" + portraitSize + ")",
|
|
||||||
"Landscape (" + landscapeSize + ")"
|
|
||||||
]
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 36
|
|
||||||
}
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.preferredHeight: 36
|
|
||||||
Layout.preferredWidth: 128
|
|
||||||
text: qsTr("Download")
|
|
||||||
icon.source: "qrc:/images/icons/icons8-download.svg"
|
|
||||||
|
|
||||||
onTriggered: () => rootItem.download()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Spacer **/
|
|
||||||
Item { Layout.fillWidth: true; Layout.fillHeight: true }
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignBottom
|
|
||||||
|
|
||||||
Text {
|
|
||||||
text: qsTr("Images Provided Courtesy of Pexels")
|
|
||||||
elide: Text.ElideLeft
|
|
||||||
color: palette.text
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: Constants.h6Font.pixelSize
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignLeft
|
|
||||||
}
|
|
||||||
|
|
||||||
Image
|
|
||||||
{
|
|
||||||
transform: Image.PreserveAspectFit
|
|
||||||
source: "qrc:/images/icons/pexels-icon-filled-256.svg"
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignRight
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
Layout.preferredWidth: 32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
states:
|
|
||||||
[
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "downloading"
|
|
||||||
when: downloadManager.state === DownloadManager.Downloading
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "complete"
|
|
||||||
when: downloadManager.state === DownloadManager.Complete
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "error"
|
|
||||||
when: downloadManager.state === DownloadManager.Error
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "idle"
|
|
||||||
when: downloadManager.state === DownloadManager.Idle
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
DownloadView
|
|
||||||
{
|
|
||||||
id: downloadView
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
manager: downloadManager
|
|
||||||
thumbnail: rootItem.thumbnail
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
}
|
|
||||||
|
|
||||||
CompletedView
|
|
||||||
{
|
|
||||||
id: completedView
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
manager: downloadManager
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorView
|
|
||||||
{
|
|
||||||
id: errorView
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
manager: downloadManager
|
|
||||||
}
|
|
||||||
|
|
||||||
function download()
|
|
||||||
{
|
|
||||||
let url = ""
|
|
||||||
|
|
||||||
switch(downloadSelector.currentIndex)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
url = portrait
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
url = landscape
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
default:
|
|
||||||
url = fullScreen
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
downloadManager.downloadImage(author, authorUrl, description, url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,309 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
import QtQuick.Effects
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property string uuid
|
|
||||||
property string author
|
|
||||||
property string authorId
|
|
||||||
property string description
|
|
||||||
property string thumbnail
|
|
||||||
property string name
|
|
||||||
|
|
||||||
property int imageHeight
|
|
||||||
property int imageWidth
|
|
||||||
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
DownloadManager
|
|
||||||
{
|
|
||||||
id: downloadManager
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: pageView
|
|
||||||
anchors.fill: parent
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
BackgroundImage
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
source: rootItem.thumbnail
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.largeMargin
|
|
||||||
spacing: Constants.largeMargin
|
|
||||||
|
|
||||||
ImageFrame
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignTop| Qt.AlignHCenter
|
|
||||||
Layout.topMargin: Constants.largeMargin
|
|
||||||
Layout.preferredHeight: width / 1.77777777778
|
|
||||||
Layout.maximumWidth: 800
|
|
||||||
|
|
||||||
source: rootItem.thumbnail
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
id: titleText
|
|
||||||
text: rootItem.name
|
|
||||||
color: palette.text
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: Constants.h3Font.pixelSize
|
|
||||||
elide: Text.ElideRight
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignTop| Qt.AlignLeft
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
id: descriptionText
|
|
||||||
text: rootItem.description
|
|
||||||
color: palette.text
|
|
||||||
font.pointSize: Constants.h4Font.pixelSize
|
|
||||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignTop| Qt.AlignLeft
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
id: authorText
|
|
||||||
text: qsTr("By: ") + rootItem.author
|
|
||||||
color: palette.text
|
|
||||||
font.pointSize: Constants.h5Font.pixelSize
|
|
||||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
|
||||||
horizontalAlignment: Qt.AlignRight
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignTop | Qt.AlignRight
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Spacer **/
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
Item { Layout.fillWidth: true }
|
|
||||||
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.preferredHeight: 36
|
|
||||||
Layout.preferredWidth: 128
|
|
||||||
text: qsTr("Download")
|
|
||||||
icon.source: "qrc:/images/icons/icons8-download.svg"
|
|
||||||
|
|
||||||
onTriggered: () => rootItem.download()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Spacer **/
|
|
||||||
Item { Layout.fillWidth: true; Layout.fillHeight: true }
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignBottom
|
|
||||||
|
|
||||||
Text {
|
|
||||||
text: qsTr("Shaders Provided Courtesy of ShaderToy, Komplex and Their Respective Authors")
|
|
||||||
elide: Text.ElideLeft
|
|
||||||
color: palette.text
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: Constants.h6Font.pixelSize
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignLeft
|
|
||||||
}
|
|
||||||
|
|
||||||
Image
|
|
||||||
{
|
|
||||||
transform: Image.PreserveAspectFit
|
|
||||||
source: "qrc:/images/icons/pexels-icon-filled-256.svg"
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignRight
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
Layout.preferredWidth: 32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
states:
|
|
||||||
[
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "downloading"
|
|
||||||
when: downloadManager.state === DownloadManager.Downloading
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "complete"
|
|
||||||
when: downloadManager.state === DownloadManager.Complete
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "error"
|
|
||||||
when: downloadManager.state === DownloadManager.Error
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "idle"
|
|
||||||
when: downloadManager.state === DownloadManager.Idle
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
DownloadView
|
|
||||||
{
|
|
||||||
id: downloadView
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
manager: downloadManager
|
|
||||||
thumbnail: rootItem.thumbnail
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
}
|
|
||||||
|
|
||||||
CompletedView
|
|
||||||
{
|
|
||||||
id: completedView
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
manager: downloadManager
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorView
|
|
||||||
{
|
|
||||||
id: errorView
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
manager: downloadManager
|
|
||||||
}
|
|
||||||
|
|
||||||
function download()
|
|
||||||
{
|
|
||||||
downloadManager.downloadPack(uuid)
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: () => downloadManager.reset()
|
|
||||||
}
|
|
||||||
@@ -1,313 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
import QtQuick.Effects
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property string uuid
|
|
||||||
property string author
|
|
||||||
property string authorUrl
|
|
||||||
property string thumbnail
|
|
||||||
property alias model: downloadSelector.model
|
|
||||||
property int modelIndex
|
|
||||||
|
|
||||||
property int imageHeight
|
|
||||||
property int imageWidth
|
|
||||||
|
|
||||||
visible: opacity > 0.01
|
|
||||||
|
|
||||||
Connections
|
|
||||||
{
|
|
||||||
target: model ? model : null
|
|
||||||
|
|
||||||
function onRowCountChanged()
|
|
||||||
{
|
|
||||||
downloadSelector.currentIndex = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DownloadManager
|
|
||||||
{
|
|
||||||
id: downloadManager
|
|
||||||
}
|
|
||||||
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: pageView
|
|
||||||
anchors.fill: parent
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
BackgroundImage
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
source: rootItem.thumbnail
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.largeMargin
|
|
||||||
spacing: Constants.largeMargin
|
|
||||||
|
|
||||||
ImageFrame
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignTop| Qt.AlignHCenter
|
|
||||||
Layout.topMargin: Constants.largeMargin
|
|
||||||
Layout.preferredHeight: width / 1.77777777778
|
|
||||||
Layout.maximumWidth: 800
|
|
||||||
|
|
||||||
source: rootItem.thumbnail
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
id: titleText
|
|
||||||
text: rootItem.author
|
|
||||||
color: palette.text
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: Constants.h3Font.pixelSize
|
|
||||||
elide: Text.ElideRight
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignTop| Qt.AlignLeft
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Spacer **/
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
text: qsTr("Available Downloads")
|
|
||||||
color: palette.text
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: Constants.h3Font.pixelSize
|
|
||||||
elide: Text.ElideRight
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignTop| Qt.AlignLeft
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
ComboBox
|
|
||||||
{
|
|
||||||
id: downloadSelector
|
|
||||||
textRole: "text"
|
|
||||||
valueRole: "url"
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: 36
|
|
||||||
}
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.preferredHeight: 36
|
|
||||||
Layout.preferredWidth: 128
|
|
||||||
text: qsTr("Download")
|
|
||||||
icon.source: "qrc:/images/icons/icons8-download.svg"
|
|
||||||
|
|
||||||
onTriggered: () => rootItem.download()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Spacer **/
|
|
||||||
Item { Layout.fillWidth: true; Layout.fillHeight: true }
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignBottom
|
|
||||||
|
|
||||||
Text {
|
|
||||||
text: qsTr("Videos Provided Courtesy of Pexels and Their Respective Authors")
|
|
||||||
elide: Text.ElideLeft
|
|
||||||
color: palette.text
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: Constants.h6Font.pixelSize
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignLeft
|
|
||||||
}
|
|
||||||
|
|
||||||
Image
|
|
||||||
{
|
|
||||||
transform: Image.PreserveAspectFit
|
|
||||||
source: "qrc:/images/icons/pexels-icon-filled-256.svg"
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignRight
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
Layout.preferredWidth: 32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
states:
|
|
||||||
[
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "downloading"
|
|
||||||
when: downloadManager.state === DownloadManager.Downloading
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "complete"
|
|
||||||
when: downloadManager.state === DownloadManager.Complete
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "error"
|
|
||||||
when: downloadManager.state === DownloadManager.Error
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "idle"
|
|
||||||
when: downloadManager.state === DownloadManager.Idle
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: pageView
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: downloadView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: completedView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorView
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
DownloadView
|
|
||||||
{
|
|
||||||
id: downloadView
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
manager: downloadManager
|
|
||||||
thumbnail: rootItem.thumbnail
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
}
|
|
||||||
|
|
||||||
CompletedView
|
|
||||||
{
|
|
||||||
id: completedView
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
manager: downloadManager
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorView
|
|
||||||
{
|
|
||||||
id: errorView
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
opacity: 0
|
|
||||||
visible: opacity > 0.01
|
|
||||||
manager: downloadManager
|
|
||||||
}
|
|
||||||
|
|
||||||
function download()
|
|
||||||
{
|
|
||||||
downloadManager.downloadImage(author, authorUrl, downloadSelector.currentValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,6 +18,5 @@ qt6_add_qml_module(KomplexHubModule
|
|||||||
"WallpaperModelData.qml"
|
"WallpaperModelData.qml"
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(KomplexHubModule PROPERTIES VERSION "1.0")
|
|
||||||
add_subdirectory("Controls")
|
add_subdirectory("Controls")
|
||||||
add_subdirectory("Kero")
|
add_subdirectory("Kero")
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ QtObject {
|
|||||||
readonly property int normalAnimationDuration: 250
|
readonly property int normalAnimationDuration: 250
|
||||||
readonly property int fastAnimationDuration: 125
|
readonly property int fastAnimationDuration: 125
|
||||||
|
|
||||||
// property StudioApplication application: StudioApplication {
|
property StudioApplication application: StudioApplication {
|
||||||
// fontPath: Qt.resolvedUrl("../KomplexHubContent/" + relativeFontDirectory)
|
fontPath: Qt.resolvedUrl("../KomplexHubContent/" + relativeFontDirectory)
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Effects
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property alias source: image.source
|
|
||||||
property alias imageOpacity: effect.opacity
|
|
||||||
property alias blur: effect.blur
|
|
||||||
property alias saturation: effect.saturation
|
|
||||||
|
|
||||||
Image
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
id: image
|
|
||||||
source: thumbnail
|
|
||||||
fillMode: Image.PreserveAspectFit
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
|
|
||||||
MultiEffect
|
|
||||||
{
|
|
||||||
id: effect
|
|
||||||
anchors.fill: image
|
|
||||||
source: image
|
|
||||||
blurEnabled: true
|
|
||||||
blurMax: 64
|
|
||||||
blur: 1.0
|
|
||||||
opacity: 0.25
|
|
||||||
saturation: -0.8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
### This file is automatically generated by Qt Design Studio.
|
### This file is automatically generated by Qt Design Studio.
|
||||||
### Do not change
|
### Do not change
|
||||||
|
|
||||||
qt_add_library(KomplexHubControls STATIC)
|
qt_add_library(KomplexHubModule_Controls STATIC)
|
||||||
qt6_add_qml_module(KomplexHubControls
|
qt6_add_qml_module(KomplexHubModule_Controls
|
||||||
URI "KomplexHub.Controls"
|
URI "KomplexHub.Controls"
|
||||||
VERSION 1.0
|
VERSION 1.0
|
||||||
RESOURCE_PREFIX "/qt/qml"
|
RESOURCE_PREFIX "/qt/qml"
|
||||||
@@ -14,12 +14,5 @@ qt6_add_qml_module(KomplexHubControls
|
|||||||
"Throbber.qml"
|
"Throbber.qml"
|
||||||
"SearchResultItem.qml"
|
"SearchResultItem.qml"
|
||||||
"SearchResultList.qml"
|
"SearchResultList.qml"
|
||||||
"PaginationBox.qml"
|
|
||||||
"PaginatorGrid.qml"
|
|
||||||
"HorizontalPaginator.qml"
|
|
||||||
"VerticalSpacer.qml"
|
|
||||||
"ImageFrame.qml"
|
|
||||||
"BackgroundImage.qml"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
#set_target_properties(KomplexHubControls PROPERTIES VERSION "1.0")
|
|
||||||
|
|||||||
@@ -1,173 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
readonly property bool searchable: false
|
|
||||||
property int resultsPerRow: (resultsContainer.width - (Constants.largeMargin * 2)) / (resultWidth + Constants.mediumMargin)
|
|
||||||
property int rows: ((resultsContainer.height - (Constants.largeMargin * 2)) / (resultHeight + Constants.mediumMargin))
|
|
||||||
property int resultsPerPage: resultsPerRow * rows
|
|
||||||
property int emptyWidth: (resultsContainer.width - (Constants.largeMargin * 2)) - (resultsPerRow * (resultWidth + Constants.mediumMargin))
|
|
||||||
property int resultWidth: 256
|
|
||||||
property int resultHeight: 245
|
|
||||||
property bool loading: false
|
|
||||||
|
|
||||||
property alias currentItem: resultsView.currentItem
|
|
||||||
property alias currentIndex: resultsView.currentIndex
|
|
||||||
|
|
||||||
property var model
|
|
||||||
|
|
||||||
property Component delegate
|
|
||||||
|
|
||||||
signal viewMoreTriggered()
|
|
||||||
|
|
||||||
id: rootItem
|
|
||||||
clip: true
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
id: resultsContainer
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
Component
|
|
||||||
{
|
|
||||||
id: highlight
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
width: 256
|
|
||||||
height: 245
|
|
||||||
color: palette.accent
|
|
||||||
radius: 5
|
|
||||||
Behavior on x { SpringAnimation { spring: 3; damping: 0.2 } }
|
|
||||||
Behavior on y { SpringAnimation { spring: 3; damping: 0.2 } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ListView
|
|
||||||
{
|
|
||||||
id: resultsView
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
clip: true
|
|
||||||
|
|
||||||
spacing: Constants.mediumMargin
|
|
||||||
|
|
||||||
orientation: ListView.Horizontal
|
|
||||||
model: rootItem.model
|
|
||||||
|
|
||||||
delegate: rootItem.delegate
|
|
||||||
highlight: Rectangle { color: palette.accent; radius: 5 }
|
|
||||||
highlightFollowsCurrentItem: true
|
|
||||||
focus: true
|
|
||||||
|
|
||||||
add: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x"
|
|
||||||
from: resultsContainer.width
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "opacity,scale"
|
|
||||||
to: 1.0
|
|
||||||
duration: 500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
move: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x,y"
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
displaced: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x,y"
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
populate: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "opacity,scale"
|
|
||||||
to: 1.0
|
|
||||||
duration: 500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remove: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x"
|
|
||||||
to: 0
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "opacity"
|
|
||||||
to: 0
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredWidth: 64
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: gradientMap
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.right: moreButton.left
|
|
||||||
height: resultHeight
|
|
||||||
width: resultWidth / 4
|
|
||||||
|
|
||||||
gradient: Gradient
|
|
||||||
{
|
|
||||||
orientation: Gradient.Horizontal
|
|
||||||
GradientStop { position: 0.0; color: "transparent" }
|
|
||||||
GradientStop { position: 1.0; color: palette.light }
|
|
||||||
}
|
|
||||||
opacity: 0.5
|
|
||||||
}
|
|
||||||
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
id: moreButton
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.right: parent.right
|
|
||||||
height: resultHeight
|
|
||||||
|
|
||||||
width: 64
|
|
||||||
|
|
||||||
icon.source: "qrc:/images/icons/icons8-forward.svg"
|
|
||||||
icon.height: 24
|
|
||||||
icon.width: 24
|
|
||||||
|
|
||||||
onTriggered: () => viewMoreTriggered()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property alias source: viewImage.source
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
Layout.alignment: Qt.AlignCenter
|
|
||||||
color: palette.base.darker()
|
|
||||||
border.color: palette.midlight
|
|
||||||
|
|
||||||
Throbber
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
id: loadingThrobber
|
|
||||||
visible: viewImage.status === Image.Loading
|
|
||||||
}
|
|
||||||
|
|
||||||
Image
|
|
||||||
{
|
|
||||||
id: viewImage
|
|
||||||
anchors.fill: parent
|
|
||||||
transform: Image.PreserveAspectCrop
|
|
||||||
source: rootItem.source
|
|
||||||
visible: !(status === Image.Loading)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -62,12 +62,10 @@ Item {
|
|||||||
|
|
||||||
id: lineEditRoot
|
id: lineEditRoot
|
||||||
|
|
||||||
ColumnLayout
|
ColumnLayout {
|
||||||
{
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
Rectangle
|
Rectangle {
|
||||||
{
|
|
||||||
id: lineEditBackground
|
id: lineEditBackground
|
||||||
|
|
||||||
border.color: lineEditRoot.border.color
|
border.color: lineEditRoot.border.color
|
||||||
@@ -89,8 +87,7 @@ Item {
|
|||||||
topLeftRadius: lineEditRoot.radius.topLeft
|
topLeftRadius: lineEditRoot.radius.topLeft
|
||||||
topRightRadius: lineEditRoot.radius.topRight
|
topRightRadius: lineEditRoot.radius.topRight
|
||||||
|
|
||||||
TextInput
|
TextInput {
|
||||||
{
|
|
||||||
id: lineEditInput
|
id: lineEditInput
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
color: lineEditRoot.color
|
color: lineEditRoot.color
|
||||||
@@ -104,14 +101,6 @@ Item {
|
|||||||
onAccepted: () => lineEditRoot.accepted()
|
onAccepted: () => lineEditRoot.accepted()
|
||||||
onTextChanged: () => lineEditRoot.text = lineEditInput.text
|
onTextChanged: () => lineEditRoot.text = lineEditInput.text
|
||||||
onEditingFinished: () => lineEditRoot.editingFinished()
|
onEditingFinished: () => lineEditRoot.editingFinished()
|
||||||
|
|
||||||
MouseArea
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
cursorShape: Qt.IBeamCursor
|
|
||||||
|
|
||||||
onClicked: () => lineEditInput.focus = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Layouts
|
|
||||||
import QtQuick.Controls
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
id: itemRoot
|
|
||||||
|
|
||||||
property int page: 0
|
|
||||||
property int totalPages: 0
|
|
||||||
|
|
||||||
property bool enablePrevious: false
|
|
||||||
property bool enableNext: false
|
|
||||||
|
|
||||||
signal next
|
|
||||||
signal previous
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
id: buttonBoxLayout
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredWidth: 128
|
|
||||||
|
|
||||||
icon.source: "qrc:/images/icons/icons8-back.svg"
|
|
||||||
icon.height: 16
|
|
||||||
icon.width: 16
|
|
||||||
text: qsTr("Previous")
|
|
||||||
enabled: itemRoot.enablePrevious
|
|
||||||
|
|
||||||
onTriggered: () => itemRoot.previous()
|
|
||||||
}
|
|
||||||
|
|
||||||
Item { Layout.fillWidth: true }
|
|
||||||
|
|
||||||
SquareButton
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredWidth: 128
|
|
||||||
|
|
||||||
icon.source: "qrc:/images/icons/icons8-next.svg"
|
|
||||||
icon.height: 16
|
|
||||||
icon.width: 16
|
|
||||||
text: qsTr("Next")
|
|
||||||
enabled: itemRoot.enableNext
|
|
||||||
|
|
||||||
onTriggered: () => itemRoot.next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,425 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
import KomplexHub.Controls
|
|
||||||
import KomplexHub.Kero
|
|
||||||
import KomplexHub.Plugin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property string query
|
|
||||||
readonly property bool searchable: true
|
|
||||||
property int resultsPerRow: (resultsContainer.width - (Constants.largeMargin * 2)) / (resultWidth + Constants.mediumMargin)
|
|
||||||
property int rows: ((resultsContainer.height - (Constants.largeMargin * 2)) / (resultHeight + Constants.mediumMargin))
|
|
||||||
property int resultsPerPage: resultsPerRow * rows
|
|
||||||
property int emptyWidth: (resultsContainer.width - (Constants.largeMargin * 2)) - (resultsPerRow * (resultWidth + Constants.mediumMargin))
|
|
||||||
property int resultWidth: 256
|
|
||||||
property int resultHeight: 245
|
|
||||||
property bool loading: false
|
|
||||||
|
|
||||||
property alias currentItem: resultsView.currentItem
|
|
||||||
property alias currentIndex: resultsView.currentIndex
|
|
||||||
|
|
||||||
property var model
|
|
||||||
|
|
||||||
property Component delegate
|
|
||||||
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
KeroErrorAvatar
|
|
||||||
{
|
|
||||||
id: errorOverlay
|
|
||||||
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
KeroNoResultsAvatar
|
|
||||||
{
|
|
||||||
id: noResultsOverlay
|
|
||||||
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
KeroChoiceAvatar
|
|
||||||
{
|
|
||||||
id: noSearchOverlay
|
|
||||||
|
|
||||||
title: qsTr("No Search Term")
|
|
||||||
description: qsTr("Kero needs a subject or term to search for wallpapers")
|
|
||||||
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
KeroLoadingAnimation
|
|
||||||
{
|
|
||||||
id: loadingOverlay
|
|
||||||
|
|
||||||
anchors.fill: parent
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
id: resultsContainer
|
|
||||||
anchors.fill: parent
|
|
||||||
color: palette.base
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: Constants.largeMargin
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredWidth: emptyWidth / 2
|
|
||||||
Layout.maximumWidth: emptyWidth / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
Component
|
|
||||||
{
|
|
||||||
id: highlight
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
width: view.cellWidth
|
|
||||||
height: view.cellHeight
|
|
||||||
color: palette.accent
|
|
||||||
radius: 5
|
|
||||||
x: view.currentItem.x
|
|
||||||
y: view.currentItem.y
|
|
||||||
Behavior on x { SpringAnimation { spring: 3; damping: 0.2 } }
|
|
||||||
Behavior on y { SpringAnimation { spring: 3; damping: 0.2 } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GridView
|
|
||||||
{
|
|
||||||
id: resultsView
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
cellWidth: 256 + Constants.mediumMargin
|
|
||||||
cellHeight: 245 + Constants.mediumMargin
|
|
||||||
model: rootItem.model
|
|
||||||
|
|
||||||
delegate: rootItem.delegate
|
|
||||||
highlight: Rectangle { color: palette.accent; radius: 5 }
|
|
||||||
highlightFollowsCurrentItem: true
|
|
||||||
focus: true
|
|
||||||
|
|
||||||
add: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x"
|
|
||||||
from: resultsContainer.width
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "opacity,scale"
|
|
||||||
to: 1.0
|
|
||||||
duration: 500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
move: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x,y"
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
displaced: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x,y"
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
populate: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "opacity,scale"
|
|
||||||
to: 1.0
|
|
||||||
duration: 500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remove: Transition
|
|
||||||
{
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "x"
|
|
||||||
to: 0
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
properties: "opacity"
|
|
||||||
to: 0
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PaginationBox
|
|
||||||
{
|
|
||||||
id: buttonBoxLayout
|
|
||||||
height: 35
|
|
||||||
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.margins: Constants.largeMargin
|
|
||||||
|
|
||||||
onNext: () => model.nextPage()
|
|
||||||
onPrevious: () => model.previousPage()
|
|
||||||
|
|
||||||
enablePrevious: model.hasPreviousPage
|
|
||||||
enableNext: model.hasNextPage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
states: [
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "loading"
|
|
||||||
when: loading
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorOverlay
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: buttonBoxLayout
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "empty"
|
|
||||||
when: model.totalResults === 0 && model.query.length > 0
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: buttonBoxLayout
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "nosearch"
|
|
||||||
when: model.query.length === 0
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: buttonBoxLayout
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "idle"
|
|
||||||
when: model.totalResults !== 0 && !loading
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
opacity: 0.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 1.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: buttonBoxLayout
|
|
||||||
visible: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "error"
|
|
||||||
when: model.errorString.length > 0
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: errorOverlay
|
|
||||||
opacity: 1.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: resultsContainer
|
|
||||||
opacity: 0.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
opacity: 0.0
|
|
||||||
}
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
opacity: 0.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
transitions: [
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "empty"
|
|
||||||
to: "loading"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "nosearch"
|
|
||||||
to: "loading"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "loading"
|
|
||||||
to: "nosearch"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: noSearchOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "loading"
|
|
||||||
to: "empty"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: noResultsOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "loading"
|
|
||||||
to: "idle"
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: loadingOverlay
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: resultsView
|
|
||||||
duration: 250
|
|
||||||
property: "opacity";
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -9,8 +9,7 @@ import QtQuick.Controls
|
|||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import KomplexHub
|
import KomplexHub
|
||||||
|
|
||||||
Item
|
Item {
|
||||||
{
|
|
||||||
property string searchTerm: ""
|
property string searchTerm: ""
|
||||||
property string icon: ""
|
property string icon: ""
|
||||||
property color color: "transparent"
|
property color color: "transparent"
|
||||||
@@ -18,18 +17,15 @@ Item
|
|||||||
id: searchBarRootItem
|
id: searchBarRootItem
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
Rectangle
|
Rectangle {
|
||||||
{
|
|
||||||
color: searchBarRootItem.color
|
color: searchBarRootItem.color
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
RowLayout
|
RowLayout {
|
||||||
{
|
|
||||||
id: searchContainerLayout
|
id: searchContainerLayout
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
LineEdit
|
LineEdit {
|
||||||
{
|
|
||||||
id: searchEdit
|
id: searchEdit
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
@@ -44,8 +40,7 @@ Item
|
|||||||
onAccepted: () => searchBarRootItem.searchTerm = text
|
onAccepted: () => searchBarRootItem.searchTerm = text
|
||||||
}
|
}
|
||||||
|
|
||||||
SquareButton
|
SquareButton {
|
||||||
{
|
|
||||||
id: searchButton
|
id: searchButton
|
||||||
|
|
||||||
Layout.fillHeight: searchEdit.height
|
Layout.fillHeight: searchEdit.height
|
||||||
@@ -72,9 +67,4 @@ Item
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
function reset()
|
|
||||||
{
|
|
||||||
searchEdit.text = ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,17 @@ import QtQuick
|
|||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
property string author: ""
|
property string author: "Author"
|
||||||
property string description: ""
|
property string description: "This is a description of the search result item"
|
||||||
property string title: ""
|
property string title: "Wallpaper Title"
|
||||||
property string thumbnail: ""
|
property string thumbnail: ""
|
||||||
property string uuid: ""
|
property string uuid: ""
|
||||||
property bool selected: false
|
property bool selected: false
|
||||||
property bool pexels: false
|
|
||||||
|
|
||||||
signal triggered
|
signal triggered
|
||||||
signal viewMoreTriggered
|
|
||||||
|
|
||||||
id: rootItem
|
id: searchResultItemRoot
|
||||||
width: 256
|
width: 256
|
||||||
height: 256
|
height: 256
|
||||||
clip: true
|
clip: true
|
||||||
@@ -25,67 +21,38 @@ Item {
|
|||||||
{
|
{
|
||||||
id: searchResultItemContainer
|
id: searchResultItemContainer
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
border.color: palette.alternateBase.lighter(1.75)
|
border.color: palette.alternateBase.lighter(1.75)
|
||||||
|
|
||||||
color: palette.alternateBase.lighter(1.25)
|
color: palette.alternateBase.lighter(1.25)
|
||||||
|
|
||||||
MouseArea
|
|
||||||
{
|
|
||||||
property string lastState
|
|
||||||
id: mouseArea
|
|
||||||
|
|
||||||
anchors.fill: parent
|
|
||||||
hoverEnabled: true
|
|
||||||
|
|
||||||
onEntered: () => {
|
|
||||||
states.hovered = true
|
|
||||||
}
|
|
||||||
|
|
||||||
onExited: () => {
|
|
||||||
if(!viewMoreButton.hovered)
|
|
||||||
states.hovered = false
|
|
||||||
}
|
|
||||||
|
|
||||||
onReleased: () => {
|
|
||||||
if(!states.selected)
|
|
||||||
{
|
|
||||||
rootItem.triggered()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
ColumnLayout
|
||||||
{
|
{
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
ImageFrame
|
Rectangle
|
||||||
{
|
{
|
||||||
Layout.preferredWidth: 250
|
Layout.preferredWidth: 250
|
||||||
Layout.preferredHeight: 141
|
Layout.preferredHeight: 141
|
||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
|
||||||
Layout.topMargin: 3
|
Layout.topMargin: 3
|
||||||
source: rootItem.thumbnail
|
|
||||||
|
border.color: palette.alternateBase.lighter(1.75)
|
||||||
|
|
||||||
|
color: palette.base.lighter(1.25)
|
||||||
|
|
||||||
Image
|
Image
|
||||||
{
|
{
|
||||||
antialiasing: true
|
anchors.fill: parent
|
||||||
anchors.right: parent.right
|
fillMode: Image.PreserveAspectCrop
|
||||||
anchors.bottom: parent.bottom
|
id: thumnailImage
|
||||||
anchors.margins: Constants.mediumMargin
|
source: searchResultItemRoot.thumbnail
|
||||||
|
|
||||||
width: 24
|
|
||||||
height: 24
|
|
||||||
fillMode: Image.PreserveAspectFit
|
|
||||||
opacity: 0.5
|
|
||||||
source: "qrc:/images/icons/pexels-icon-filled-256.svg"
|
|
||||||
|
|
||||||
visible: rootItem.pexels
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text
|
Text {
|
||||||
{
|
|
||||||
color: palette.text
|
color: palette.text
|
||||||
text: rootItem.title
|
text: searchResultItemRoot.title
|
||||||
|
|
||||||
font.pixelSize: 16
|
font.pixelSize: 16
|
||||||
font.bold: true
|
font.bold: true
|
||||||
@@ -95,85 +62,88 @@ Item {
|
|||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
|
||||||
}
|
}
|
||||||
|
|
||||||
Item { Layout.fillHeight: true }
|
Text {
|
||||||
|
color: palette.text
|
||||||
|
font.pixelSize: 12
|
||||||
|
text: "By: " + searchResultItemRoot.author
|
||||||
|
leftPadding: 12
|
||||||
|
|
||||||
Text
|
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
|
||||||
{
|
Layout.preferredWidth: 250
|
||||||
id: descriptionText
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
clip: true
|
clip: true
|
||||||
color: palette.text
|
color: palette.text
|
||||||
font.pixelSize: 12
|
font.pixelSize: 12
|
||||||
text: rootItem.description
|
text: searchResultItemRoot.description
|
||||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||||
textFormat: Text.PlainText
|
textFormat: Text.PlainText
|
||||||
|
Layout.maximumHeight: 32
|
||||||
|
Layout.preferredHeight: 32
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
||||||
Layout.maximumHeight: 32
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
Layout.preferredWidth: 236
|
Layout.preferredWidth: 236
|
||||||
Layout.maximumWidth: 236
|
Layout.maximumWidth: 236
|
||||||
Layout.bottomMargin: 3
|
Layout.bottomMargin: 3
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Text
|
Behavior on color {
|
||||||
{
|
ColorAnimation { duration: 200 }
|
||||||
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
|
|
||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
|
||||||
Layout.maximumHeight: 50
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
Layout.preferredWidth: 236
|
|
||||||
Layout.maximumWidth: 236
|
|
||||||
Layout.bottomMargin: 3
|
|
||||||
|
|
||||||
text: qsTr("View More")
|
|
||||||
opacity: 0
|
|
||||||
|
|
||||||
onTriggered: () => {
|
|
||||||
rootItem.viewMoreTriggered()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Item { Layout.fillHeight: true }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QtObject
|
MouseArea {
|
||||||
{
|
property string lastState
|
||||||
id: states
|
id: mouseArea
|
||||||
property bool clicked: false
|
|
||||||
property bool hovered: false
|
|
||||||
property alias selected: rootItem.selected
|
|
||||||
property bool idle: true
|
|
||||||
|
|
||||||
onIdleChanged: () =>
|
anchors.fill: parent
|
||||||
{
|
hoverEnabled: true
|
||||||
if(idle)
|
|
||||||
{
|
onEntered: () => {
|
||||||
clicked = false
|
if(!selected)
|
||||||
hovered = false
|
searchResultItemRoot.state = "hovered"
|
||||||
selected = false
|
}
|
||||||
|
|
||||||
|
onExited: () => {
|
||||||
|
lastState = ""
|
||||||
|
|
||||||
|
if(selected)
|
||||||
|
searchResultItemRoot.state = "selected"
|
||||||
|
else
|
||||||
|
searchResultItemRoot.state = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
onPressed: () => {
|
||||||
|
if(!selected) {
|
||||||
|
lastState = searchResultItemRoot.state
|
||||||
|
searchResultItemRoot.state = "clicked"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onReleased: () => {
|
||||||
|
if(!mouseArea.containsMouse)
|
||||||
|
return;
|
||||||
|
|
||||||
|
selected = !selected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelectedChanged: () => {
|
||||||
|
if(selected) {
|
||||||
|
searchResultItemRoot.triggered()
|
||||||
|
searchResultItemRoot.state = "selected"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
searchResultItemRoot.state = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "hovered"
|
name: "hovered"
|
||||||
when: states.hovered && !states.selected
|
|
||||||
|
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: searchResultItemContainer
|
target: searchResultItemContainer
|
||||||
@@ -183,140 +153,14 @@ Item {
|
|||||||
0.5, // Set custom lightness
|
0.5, // Set custom lightness
|
||||||
1.0)
|
1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: viewMoreButton
|
|
||||||
opacity: 0
|
|
||||||
|
|
||||||
Layout.preferredHeight: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: descriptionText
|
|
||||||
opacity: 1
|
|
||||||
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "selected"
|
name: "selected"
|
||||||
when: states.selected && !states.hovered
|
|
||||||
|
|
||||||
PropertyChanges
|
PropertyChanges {
|
||||||
{
|
|
||||||
target: searchResultItemContainer
|
target: searchResultItemContainer
|
||||||
color: palette.accent
|
color: palette.accent
|
||||||
}
|
}
|
||||||
},
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "view_more"
|
|
||||||
when: states.selected && states.hovered
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: viewMoreButton
|
|
||||||
opacity: 1
|
|
||||||
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: descriptionText
|
|
||||||
opacity: 0
|
|
||||||
|
|
||||||
Layout.preferredHeight: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
State
|
|
||||||
{
|
|
||||||
name: "default"
|
|
||||||
when: states.idle
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: viewMoreButton
|
|
||||||
opacity: 0
|
|
||||||
|
|
||||||
Layout.preferredHeight: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyChanges
|
|
||||||
{
|
|
||||||
target: descriptionText
|
|
||||||
opacity: 1
|
|
||||||
|
|
||||||
Layout.preferredHeight: 32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
]
|
|
||||||
|
|
||||||
transitions:
|
|
||||||
[
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
to: "selected"
|
|
||||||
|
|
||||||
ColorAnimation
|
|
||||||
{
|
|
||||||
target: searchResultItemContainer
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "selected"
|
|
||||||
to: "view_more"
|
|
||||||
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: viewMoreButton
|
|
||||||
property: "opacity"
|
|
||||||
duration: 250
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
from: "view_more"
|
|
||||||
to: "selected"
|
|
||||||
|
|
||||||
NumberAnimation
|
|
||||||
{
|
|
||||||
target: descriptionText
|
|
||||||
property: "opacity"
|
|
||||||
duration: 250
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
to: "default"
|
|
||||||
|
|
||||||
ColorAnimation
|
|
||||||
{
|
|
||||||
target: searchResultItemContainer
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
Transition
|
|
||||||
{
|
|
||||||
to: "hovered"
|
|
||||||
|
|
||||||
ColorAnimation
|
|
||||||
{
|
|
||||||
target: searchResultItemContainer
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ Item {
|
|||||||
property color color: palette.button
|
property color color: palette.button
|
||||||
property Gradient gradient: defaultGradient
|
property Gradient gradient: defaultGradient
|
||||||
property BorderSettings border: BorderSettings {}
|
property BorderSettings border: BorderSettings {}
|
||||||
readonly property bool hovered: state === "hovered"
|
|
||||||
|
|
||||||
signal triggered
|
signal triggered
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ Item {
|
|||||||
component IconSettings: QtObject {
|
component IconSettings: QtObject {
|
||||||
property int width: 16
|
property int width: 16
|
||||||
property int height: 16
|
property int height: 16
|
||||||
property string source: "qrc:/images/icons/icons8-next.svg"
|
property string source: "images/icons/icons8-next.svg"
|
||||||
}
|
}
|
||||||
|
|
||||||
component BorderSettings: QtObject {
|
component BorderSettings: QtObject {
|
||||||
@@ -107,6 +106,10 @@ Item {
|
|||||||
Behavior on color {
|
Behavior on color {
|
||||||
ColorAnimation { duration: 250 }
|
ColorAnimation { duration: 250 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Behavior on gradient {
|
||||||
|
// PropertyAnimation { duration: 250 }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
@@ -213,5 +216,7 @@ Item {
|
|||||||
color: palette.text.darker()
|
color: palette.text.darker()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,159 +1,126 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Shapes
|
import QtQuick.Shapes
|
||||||
import QtQuick.Effects
|
import QtQuick.Effects
|
||||||
import QtQuick.Layouts
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: throbberRoot
|
id: throbberRoot
|
||||||
|
|
||||||
onHeightChanged: () => {
|
Rectangle {
|
||||||
if(height > width)
|
|
||||||
{
|
|
||||||
layout.throbberSize = width - 24
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
layout.throbberSize = height - 24
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onWidthChanged: () => {
|
|
||||||
if(height > width)
|
|
||||||
{
|
|
||||||
layout.throbberSize = width - 24
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
layout.throbberSize = height - 24
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
property int throbberSize
|
|
||||||
id: layout
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
Rectangle
|
color: "transparent"
|
||||||
|
|
||||||
|
Item
|
||||||
{
|
{
|
||||||
Layout.alignment: Qt.AlignHCenter
|
id: outerRing
|
||||||
Layout.preferredHeight: parent.throbberSize
|
anchors.fill: parent
|
||||||
Layout.preferredWidth: parent.throbberSize
|
|
||||||
|
|
||||||
color: "transparent"
|
Shape
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
{
|
||||||
id: outerRing
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
asynchronous: true
|
||||||
|
|
||||||
Shape
|
ShapePath
|
||||||
{
|
{
|
||||||
anchors.fill: parent
|
property double progress: 0
|
||||||
asynchronous: true
|
property int dashSpaceLength: 15
|
||||||
|
property int dashLength: 1
|
||||||
|
|
||||||
ShapePath
|
id: outerRingPath
|
||||||
|
strokeColor: palette.accent.darker(1 + (progress - 0.25))
|
||||||
|
fillColor: "transparent"
|
||||||
|
strokeWidth: 3
|
||||||
|
strokeStyle: ShapePath.DashLine
|
||||||
|
|
||||||
|
startX: 0
|
||||||
|
startY: outerRing.height * 0.5
|
||||||
|
|
||||||
|
dashPattern: [
|
||||||
|
dashSpaceLength - (dashSpaceLength * progress),
|
||||||
|
dashSpaceLength * progress
|
||||||
|
]
|
||||||
|
|
||||||
|
PathArc
|
||||||
{
|
{
|
||||||
property double progress: 0
|
x: outerRing.width
|
||||||
property int dashSpaceLength: 15
|
y: outerRing.height * 0.5
|
||||||
property int dashLength: 1
|
|
||||||
|
|
||||||
id: outerRingPath
|
radiusX: outerRing.width / 2
|
||||||
strokeColor: palette.accent.darker(1 + (progress - 0.25))
|
radiusY: outerRing.height / 2
|
||||||
fillColor: "transparent"
|
|
||||||
strokeWidth: 3
|
|
||||||
strokeStyle: ShapePath.DashLine
|
|
||||||
|
|
||||||
startX: 0
|
useLargeArc: false
|
||||||
startY: outerRing.height * 0.5
|
|
||||||
|
|
||||||
dashPattern: [
|
|
||||||
dashSpaceLength - (dashSpaceLength * progress),
|
|
||||||
dashSpaceLength * progress
|
|
||||||
]
|
|
||||||
|
|
||||||
PathArc
|
|
||||||
{
|
|
||||||
x: outerRing.width
|
|
||||||
y: outerRing.height * 0.5
|
|
||||||
|
|
||||||
radiusX: outerRing.width / 2
|
|
||||||
radiusY: outerRing.height / 2
|
|
||||||
|
|
||||||
useLargeArc: false
|
|
||||||
}
|
|
||||||
|
|
||||||
PathArc
|
|
||||||
{
|
|
||||||
x: 0
|
|
||||||
y: outerRing.height * 0.5
|
|
||||||
|
|
||||||
radiusX: outerRing.width / 2
|
|
||||||
radiusY: outerRing.height / 2
|
|
||||||
|
|
||||||
useLargeArc: false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
transform: Rotation {
|
PathArc
|
||||||
id: outerRingRotation
|
{
|
||||||
origin.x: outerRing.width / 2
|
x: 0
|
||||||
origin.y: outerRing.height / 2
|
y: outerRing.height * 0.5
|
||||||
}
|
|
||||||
|
|
||||||
NumberAnimation {
|
radiusX: outerRing.width / 2
|
||||||
property bool reverse: false
|
radiusY: outerRing.height / 2
|
||||||
|
|
||||||
target: outerRingPath
|
useLargeArc: false
|
||||||
property: "progress"
|
|
||||||
duration: 1600
|
|
||||||
//easing.type: Easing.InOutQuad
|
|
||||||
|
|
||||||
from: 0
|
|
||||||
to: 1
|
|
||||||
loops: 1
|
|
||||||
running: true
|
|
||||||
|
|
||||||
onFinished: () => {
|
|
||||||
if(reverse)
|
|
||||||
{
|
|
||||||
from = 0
|
|
||||||
to = 1
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
from = 1
|
|
||||||
to = 0
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
|
|
||||||
reverse = !reverse
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberAnimation {
|
|
||||||
target: outerRingRotation
|
|
||||||
property: "angle"
|
|
||||||
duration: 16000
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
|
|
||||||
from: 0
|
|
||||||
to: (360 * 4)
|
|
||||||
loops: NumberAnimation.Infinite
|
|
||||||
running: true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiEffect {
|
transform: Rotation {
|
||||||
source: outerRing
|
id: outerRingRotation
|
||||||
anchors.fill: outerRing
|
origin.x: outerRing.width / 2
|
||||||
brightness: 0.4
|
origin.y: outerRing.height / 2
|
||||||
saturation: 0.2
|
|
||||||
blurEnabled: true
|
|
||||||
blurMax: 64
|
|
||||||
blur: 1.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NumberAnimation {
|
||||||
|
property bool reverse: false
|
||||||
|
|
||||||
|
target: outerRingPath
|
||||||
|
property: "progress"
|
||||||
|
duration: 1600
|
||||||
|
//easing.type: Easing.InOutQuad
|
||||||
|
|
||||||
|
from: 0
|
||||||
|
to: 1
|
||||||
|
loops: 1
|
||||||
|
running: true
|
||||||
|
|
||||||
|
onFinished: () => {
|
||||||
|
if(reverse)
|
||||||
|
{
|
||||||
|
from = 0
|
||||||
|
to = 1
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
from = 1
|
||||||
|
to = 0
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
|
||||||
|
reverse = !reverse
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NumberAnimation {
|
||||||
|
target: outerRingRotation
|
||||||
|
property: "angle"
|
||||||
|
duration: 16000
|
||||||
|
easing.type: Easing.InOutQuad
|
||||||
|
|
||||||
|
from: 0
|
||||||
|
to: (360 * 4)
|
||||||
|
loops: NumberAnimation.Infinite
|
||||||
|
running: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiEffect {
|
||||||
|
source: outerRing
|
||||||
|
anchors.fill: outerRing
|
||||||
|
brightness: 0.4
|
||||||
|
saturation: 0.2
|
||||||
|
blurEnabled: true
|
||||||
|
blurMax: 64
|
||||||
|
blur: 1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Layouts
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
|
|
||||||
color: "transparent"
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
qt_add_library(KomplexHubKero STATIC)
|
qt_add_library(KomplexHubModule_Kero STATIC)
|
||||||
qt6_add_qml_module(KomplexHubKero
|
qt6_add_qml_module(KomplexHubModule_Kero
|
||||||
URI "KomplexHub.Kero"
|
URI "KomplexHub.Kero"
|
||||||
VERSION 1.0
|
VERSION 1.0
|
||||||
RESOURCE_PREFIX "/qt/qml"
|
RESOURCE_PREFIX "/qt/qml"
|
||||||
@@ -11,7 +11,4 @@ qt6_add_qml_module(KomplexHubKero
|
|||||||
"KeroLoadingAnimation.qml"
|
"KeroLoadingAnimation.qml"
|
||||||
"KeroNoResultsAvatar.qml"
|
"KeroNoResultsAvatar.qml"
|
||||||
"KeroWarningAvatar.qml"
|
"KeroWarningAvatar.qml"
|
||||||
"KeroHeader.qml"
|
|
||||||
"KeroSuccessAvatar.qml"
|
|
||||||
)
|
)
|
||||||
#set_target_properties(KomplexHubKero PROPERTIES VERSION "1.0")
|
|
||||||
@@ -4,9 +4,9 @@ import QtQuick.Layouts
|
|||||||
import KomplexHub
|
import KomplexHub
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
property string title: qsTr("Building")
|
property string title: qsTr("Loading")
|
||||||
property string description: qsTr("Kero is getting your wallpaper ready")
|
property string description: qsTr("Kero is busy looking for wallpapers..we promise")
|
||||||
property color color: "transparent"
|
property color color: palette.window
|
||||||
|
|
||||||
id: keroLoadingOverlayRoot
|
id: keroLoadingOverlayRoot
|
||||||
|
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls 2.0
|
|
||||||
import QtQuick.Layouts
|
|
||||||
import KomplexHub
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
property string title: qsTr("Wallpaper Spotlight")
|
|
||||||
property string description: qsTr("Featured Images and Live Wallpaper Packs")
|
|
||||||
property color color: palette.alternateBase
|
|
||||||
property string image: "qrc:/images/kero/kero_spotlight.png"
|
|
||||||
|
|
||||||
id: rootItem
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
color: rootItem.color
|
|
||||||
border.color: palette.midlight
|
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.preferredWidth: height
|
|
||||||
Layout.alignment: Qt.AlignLeft
|
|
||||||
|
|
||||||
color: "transparent"
|
|
||||||
|
|
||||||
Image
|
|
||||||
{
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
source: image
|
|
||||||
antialiasing: true
|
|
||||||
fillMode: Image.PreserveAspectFit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.alignment: Qt.AlignLeft
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
color: palette.text
|
|
||||||
text: rootItem.title
|
|
||||||
font: Constants.h1Font
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
|
||||||
}
|
|
||||||
|
|
||||||
Text
|
|
||||||
{
|
|
||||||
id: errorText
|
|
||||||
text: rootItem.description
|
|
||||||
color: palette.text.darker()
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
|
||||||
Layout.bottomMargin: Constants.largeMargin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import QtQuick
|
|
||||||
import QtQuick.Controls
|
|
||||||
import QtQuick.Layouts
|
|
||||||
|
|
||||||
import KomplexHub
|
|
||||||
|
|
||||||
Item {
|
|
||||||
property string title: qsTr("Success!")
|
|
||||||
property string description: qsTr("Your new wallpaper is ready!")
|
|
||||||
property color color: "transparent"
|
|
||||||
|
|
||||||
id: keroHelloAvatarRoot
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
id: keroHelloAvatarBackground
|
|
||||||
anchors.fill: parent
|
|
||||||
color: keroHelloAvatarRoot.color
|
|
||||||
|
|
||||||
ColumnLayout {
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.minimumWidth: 64
|
|
||||||
Layout.minimumHeight: 64
|
|
||||||
Layout.maximumWidth: 512
|
|
||||||
Layout.maximumHeight: 512
|
|
||||||
Layout.alignment: Qt.AlignCenter
|
|
||||||
|
|
||||||
color: "transparent"
|
|
||||||
|
|
||||||
Image {
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
source: "qrc:/images/kero/kero_success.png"
|
|
||||||
antialiasing: true
|
|
||||||
fillMode: Image.PreserveAspectFit
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout {
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.right: parent.right
|
|
||||||
|
|
||||||
Text {
|
|
||||||
color: palette.text
|
|
||||||
text: keroHelloAvatarRoot.title
|
|
||||||
font: Constants.h1Font
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
|
||||||
}
|
|
||||||
|
|
||||||
Text {
|
|
||||||
id: errorText
|
|
||||||
text: keroHelloAvatarRoot.description
|
|
||||||
color: palette.text.darker()
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
|
||||||
Layout.bottomMargin: Constants.largeMargin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ import KomplexHub
|
|||||||
Item {
|
Item {
|
||||||
property string title: qsTr("Warning")
|
property string title: qsTr("Warning")
|
||||||
property string description: qsTr("Kero noticed there might be an issue")
|
property string description: qsTr("Kero noticed there might be an issue")
|
||||||
property color color: "transparent"
|
property color color: palette.window
|
||||||
|
|
||||||
id: keroWarningAvatarRoot
|
id: keroWarningAvatarRoot
|
||||||
|
|
||||||
|
|||||||
Vendored
-1
Submodule KomplexHubPlugin/3rdparty/qtkeychain deleted from 087369387c
@@ -1,113 +1,67 @@
|
|||||||
find_package(
|
|
||||||
Qt6
|
|
||||||
REQUIRED COMPONENTS
|
|
||||||
Core
|
|
||||||
Gui
|
|
||||||
GuiPrivate
|
|
||||||
Widgets
|
|
||||||
Qml
|
|
||||||
Quick
|
|
||||||
QuickControls2
|
|
||||||
QuickTimeline
|
|
||||||
ShaderTools
|
|
||||||
ShaderToolsPrivate
|
|
||||||
Concurrent
|
|
||||||
)
|
|
||||||
|
|
||||||
find_package(
|
|
||||||
OpenGL REQUIRED COMPONENTS OpenGL
|
|
||||||
)
|
|
||||||
|
|
||||||
find_package(
|
|
||||||
Vulkan REQUIRED COMPONENTS glslang SPIRV-Tools
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(
|
add_library(
|
||||||
KomplexHubPlugin
|
KomplexHubPlugin
|
||||||
STATIC
|
STATIC
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(KomplexHubPlugin PROPERTIES VERSION "1.0")
|
|
||||||
|
|
||||||
qt_add_qml_module(
|
qt_add_qml_module(
|
||||||
KomplexHubPlugin
|
KomplexHubPlugin
|
||||||
URI
|
URI
|
||||||
"KomplexHub.Plugin"
|
KomplexHubPlugin
|
||||||
VERSION
|
VERSION
|
||||||
1.0
|
1.0
|
||||||
SOURCES
|
SOURCES
|
||||||
settingsmanager.h
|
settingsmanager.h
|
||||||
settingsmanager.cpp
|
settingsmanager.cpp
|
||||||
installedpackmanager.h
|
installedpackmanager.h
|
||||||
installedpackmanager.cpp
|
installedpackmanager.cpp
|
||||||
common/wallpapercache.h
|
common/wallpapercache.h
|
||||||
newestpacksmodel.h
|
newestpacksmodel.h
|
||||||
newestpacksmodel.cpp
|
newestpacksmodel.cpp
|
||||||
common/komplex_global.h
|
common/komplex_global.h
|
||||||
common/slidingcachecontroller.h
|
common/slidingcachecontroller.h
|
||||||
common/coreservices.h
|
|
||||||
common/coreservices.cpp
|
common/paginator.h
|
||||||
common/logging.h
|
|
||||||
common/fetchresult.h
|
common/coreservices.h
|
||||||
paginators/paginator.h
|
common/coreservices.cpp
|
||||||
paginators/newestpackspaginator.h
|
common/logging.h
|
||||||
paginators/featuredpackspaginator.h
|
common/fetchresult.h
|
||||||
paginators/featuredimagespaginator.h
|
paginators/newestpackspaginator.h
|
||||||
paginators/wallpaperpaginator.h
|
SOURCES paginators/featuredpackspaginator.h
|
||||||
paginators/packsearchpaginator.h
|
SOURCES paginators/featuredimagespaginator.h
|
||||||
paginators/imagesearchpaginator.h
|
SOURCES paginators/wallpaperpaginator.h
|
||||||
paginators/videosearchpaginator.h
|
SOURCES paginators/searchpackspaginator.h
|
||||||
featuredpacksmodel.h
|
SOURCES paginators/imagesearchpaginator.h
|
||||||
featuredpacksmodel.cpp
|
SOURCES paginators/newestshaderspaginator.h
|
||||||
featuredimagesmodel.h
|
SOURCES paginators/newestcubemapspaginator.h
|
||||||
featuredimagesmodel.cpp
|
SOURCES paginators/featuredshaderspaginator.h
|
||||||
featuredvideosmodel.h
|
SOURCES paginators/featuredcubemapspaginator.h
|
||||||
featuredvideosmodel.cpp
|
SOURCES paginators/searchshaderspaginator.h
|
||||||
paginators/featuredvideospaginator.h
|
SOURCES paginators/searchcubemapspaginator.h
|
||||||
common/imagecache.h
|
SOURCES paginators/videosearchpaginator.h
|
||||||
paginators/imagepaginator.h
|
SOURCES featuredpacksmodel.h
|
||||||
common/videocache.h
|
SOURCES featuredpacksmodel.cpp
|
||||||
paginators/videopaginator.h
|
SOURCES featuredimagesmodel.h
|
||||||
imagesearchmodel.cpp
|
SOURCES featuredimagesmodel.cpp
|
||||||
imagesearchmodel.h
|
SOURCES featuredvideosmodel.h
|
||||||
videosearchmodel.h
|
SOURCES featuredvideosmodel.cpp
|
||||||
videosearchmodel.cpp
|
SOURCES paginators/featuredvideospaginator.h
|
||||||
packsearchmodel.cpp
|
SOURCES common/imagecache.h
|
||||||
packsearchmodel.h
|
SOURCES paginators/imagepaginator.h
|
||||||
videoitemmodel.h
|
SOURCES common/videocache.h
|
||||||
videoitemmodel.cpp
|
SOURCES paginators/videopaginator.h
|
||||||
downloadmanager.h downloadmanager.cpp
|
SOURCES imagesearchmodel.cpp
|
||||||
common/exceptions.h
|
SOURCES imagesearchmodel.h
|
||||||
common/shadertoymetadata.h
|
SOURCES videosearchmodel.h
|
||||||
common/shaderpack.h
|
SOURCES videosearchmodel.cpp
|
||||||
packcompiler.h
|
|
||||||
packcompiler.cpp
|
|
||||||
common/userservices.h
|
|
||||||
common/userservices.cpp
|
|
||||||
common/qwallet.h
|
|
||||||
common/qwallet.cpp
|
|
||||||
usermodel.h
|
|
||||||
usermodel.cpp
|
|
||||||
SOURCES
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(
|
target_compile_definitions(
|
||||||
KomplexHubPlugin
|
KomplexHubPlugin
|
||||||
PUBLIC
|
PUBLIC
|
||||||
KOMPLEX_PLUGIN
|
KOMPLEX_PLUGIN
|
||||||
)
|
KOMPLEX_LOCAL_DEV
|
||||||
|
|
||||||
add_subdirectory(3rdparty/qtkeychain)
|
|
||||||
|
|
||||||
target_link_libraries(KomplexHubPlugin PRIVATE
|
|
||||||
Qt6::Core
|
|
||||||
Qt6::Concurrent
|
|
||||||
Qt6::Gui
|
|
||||||
Qt6::GuiPrivate
|
|
||||||
Qt6::ShaderTools
|
|
||||||
Qt6::ShaderToolsPrivate
|
|
||||||
Vulkan::Vulkan
|
|
||||||
qt6keychain
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(ENABLE_ASAN)
|
if(ENABLE_ASAN)
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#include "coreservices.h"
|
#include "coreservices.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "userservices.h"
|
|
||||||
|
|
||||||
QNetworkAccessManager *CoreServices::s_networkAccessManager = nullptr;
|
QNetworkAccessManager *CoreServices::s_networkAccessManager = new QNetworkAccessManager();
|
||||||
QMutex CoreServices::s_networkAccessMutex;
|
QMutex CoreServices::s_networkAccessMutex;
|
||||||
QSharedPointer<QNetworkAccessManager> CoreServices::s_networkAccessPointer;
|
QSharedPointer<QNetworkAccessManager> CoreServices::s_networkAccessPointer;
|
||||||
|
|
||||||
@@ -12,31 +11,27 @@ auto CoreServices::networkAccessManager() -> QWeakPointer<QNetworkAccessManager>
|
|||||||
|
|
||||||
if(!s_networkAccessPointer)
|
if(!s_networkAccessPointer)
|
||||||
{
|
{
|
||||||
if(!s_networkAccessManager)
|
s_networkAccessManager = new QNetworkAccessManager;
|
||||||
{
|
|
||||||
s_networkAccessManager = new QNetworkAccessManager(QCoreApplication::instance());
|
|
||||||
s_networkAccessManager->setAutoDeleteReplies(true);
|
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
s_networkAccessManager,
|
s_networkAccessManager,
|
||||||
&QNetworkAccessManager::sslErrors,
|
&QNetworkAccessManager::sslErrors,
|
||||||
s_networkAccessManager,
|
s_networkAccessManager,
|
||||||
[] (QNetworkReply *reply, const QList<QSslError> &errors)
|
[] (QNetworkReply *reply, const QList<QSslError> &errors)
|
||||||
|
{
|
||||||
|
for(const auto &error : errors)
|
||||||
{
|
{
|
||||||
for(const auto &error : errors)
|
LOG_ERROR(
|
||||||
{
|
"CoreServices::networkAccessManager",
|
||||||
LOG_ERROR(
|
error.errorString().toStdString().c_str()
|
||||||
"CoreServices::networkAccessManager",
|
);
|
||||||
error.errorString().toStdString().c_str()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef KOMPLEX_LOCAL_DEV
|
|
||||||
reply->ignoreSslErrors();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
#ifdef KOMPLEX_LOCAL_DEV
|
||||||
|
reply->ignoreSslErrors();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
s_networkAccessPointer = QSharedPointer<QNetworkAccessManager>(
|
s_networkAccessPointer = QSharedPointer<QNetworkAccessManager>(
|
||||||
s_networkAccessManager,
|
s_networkAccessManager,
|
||||||
@@ -49,17 +44,9 @@ auto CoreServices::networkAccessManager() -> QWeakPointer<QNetworkAccessManager>
|
|||||||
|
|
||||||
auto CoreServices::sessionToken() -> QByteArray
|
auto CoreServices::sessionToken() -> QByteArray
|
||||||
{
|
{
|
||||||
return UserServices::userCredentials().sessionToken;
|
LOG_ERROR_X(true,
|
||||||
}
|
"CoreServices::sessionToken",
|
||||||
|
"User services not yet implemented",
|
||||||
auto CoreServices::screenSize() -> QSize
|
{}
|
||||||
{
|
);
|
||||||
QScreen *screen = QGuiApplication::primaryScreen();
|
|
||||||
|
|
||||||
if(screen == nullptr)
|
|
||||||
{
|
|
||||||
return QSize(0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return screen->size();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QWeakPointer>
|
#include <QWeakPointer>
|
||||||
#include <QScreen>
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
|
|
||||||
@@ -46,8 +45,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
static auto sessionToken() -> QByteArray;
|
static auto sessionToken() -> QByteArray;
|
||||||
|
|
||||||
static auto screenSize() -> QSize;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
CoreServices() = default;
|
CoreServices() = default;
|
||||||
|
|||||||
@@ -1,215 +0,0 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef EXCEPTIONS_H
|
|
||||||
#define EXCEPTIONS_H
|
|
||||||
#include <QString>
|
|
||||||
#include <string>
|
|
||||||
#include <filesystem>
|
|
||||||
#include "komplex_global.h"
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT network_exception : std::ios_base::failure
|
|
||||||
{
|
|
||||||
network_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
|
||||||
details(details),
|
|
||||||
std::ios_base::failure(message, code) { }
|
|
||||||
|
|
||||||
network_exception(const std::string &message, const std::error_code &code) :
|
|
||||||
std::ios_base::failure(message, code) { }
|
|
||||||
|
|
||||||
network_exception(const QString &message, const QString &details, const std::error_code &code) :
|
|
||||||
details(details.toStdString()),
|
|
||||||
std::ios_base::failure(message.toStdString(), code) { }
|
|
||||||
|
|
||||||
network_exception(const QString &message, const int code = errno) :
|
|
||||||
std::ios_base::failure
|
|
||||||
(
|
|
||||||
message.toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
code,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
) { }
|
|
||||||
|
|
||||||
const std::string details;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT file_exception : std::filesystem::filesystem_error
|
|
||||||
{
|
|
||||||
file_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
|
||||||
details(details),
|
|
||||||
std::filesystem::filesystem_error(message, code) { }
|
|
||||||
|
|
||||||
file_exception(const std::string &message, const std::error_code &code) :
|
|
||||||
std::filesystem::filesystem_error(message, code) { }
|
|
||||||
|
|
||||||
file_exception(const std::string &message, const int code = errno) :
|
|
||||||
std::filesystem::filesystem_error
|
|
||||||
(
|
|
||||||
message,
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
code,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
) { }
|
|
||||||
|
|
||||||
file_exception(const std::string &message, const std::string &details, const int code = errno) :
|
|
||||||
details(details),
|
|
||||||
std::filesystem::filesystem_error
|
|
||||||
(
|
|
||||||
message,
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
code,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
) { }
|
|
||||||
|
|
||||||
const std::string details;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT sql_exception : std::ios_base::failure
|
|
||||||
{
|
|
||||||
sql_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
|
||||||
details(details),
|
|
||||||
std::ios_base::failure(message, code) { }
|
|
||||||
|
|
||||||
sql_exception(const std::string &message, const std::error_code &code) :
|
|
||||||
std::ios_base::failure(message, code) { }
|
|
||||||
|
|
||||||
sql_exception(const std::string &message, const int code = errno) :
|
|
||||||
std::ios_base::failure
|
|
||||||
(
|
|
||||||
message,
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
code,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
) { }
|
|
||||||
|
|
||||||
const std::string details;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT wallet_exception : std::ios_base::failure
|
|
||||||
{
|
|
||||||
wallet_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
|
||||||
details(details),
|
|
||||||
std::ios_base::failure(message, code) { }
|
|
||||||
|
|
||||||
wallet_exception(const std::string &message, const std::error_code &code) :
|
|
||||||
std::ios_base::failure(message, code) { }
|
|
||||||
|
|
||||||
wallet_exception(const std::string &message, const std::string &details, const int code = errno) :
|
|
||||||
details(details),
|
|
||||||
std::ios_base::failure
|
|
||||||
(
|
|
||||||
message,
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
code,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
) { }
|
|
||||||
|
|
||||||
wallet_exception(const std::string &message, const int code = errno) :
|
|
||||||
std::ios_base::failure
|
|
||||||
(
|
|
||||||
message,
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
code,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
) { }
|
|
||||||
|
|
||||||
const std::string details;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT process_exception : std::runtime_error
|
|
||||||
{
|
|
||||||
process_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
|
||||||
details(details),
|
|
||||||
code(code),
|
|
||||||
std::runtime_error(message) { }
|
|
||||||
|
|
||||||
process_exception(const std::string &message, const std::error_code &code) :
|
|
||||||
code(code),
|
|
||||||
std::runtime_error(message) { }
|
|
||||||
|
|
||||||
process_exception(const std::string &message, const int code = errno) :
|
|
||||||
code
|
|
||||||
(
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
code,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
std::runtime_error
|
|
||||||
(
|
|
||||||
message
|
|
||||||
) { }
|
|
||||||
|
|
||||||
process_exception(const std::string &message, const std::string &details, const int code = errno) :
|
|
||||||
details(details),
|
|
||||||
code
|
|
||||||
(
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
code,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
std::runtime_error (message) { }
|
|
||||||
|
|
||||||
const std::string details;
|
|
||||||
const std::error_code code;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace shader
|
|
||||||
{
|
|
||||||
struct KOMPLEX_EXPORT logic_error : std::logic_error
|
|
||||||
{
|
|
||||||
logic_error(const std::string &message, const std::string &details, const std::error_code &code) :
|
|
||||||
details(details),
|
|
||||||
code(code),
|
|
||||||
std::logic_error(message) { }
|
|
||||||
|
|
||||||
logic_error(const std::string &message, const std::error_code &code) :
|
|
||||||
code(code),
|
|
||||||
std::logic_error(message) { }
|
|
||||||
|
|
||||||
logic_error(const std::string &message, const std::string &details = {}, const int code = errno) :
|
|
||||||
code
|
|
||||||
(
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
code,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
std::logic_error(message) { }
|
|
||||||
|
|
||||||
const std::string details;
|
|
||||||
const std::error_code code;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif // EXCEPTIONS_H
|
|
||||||
@@ -1,21 +1,3 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef IMAGECACHE_H
|
#ifndef IMAGECACHE_H
|
||||||
#define IMAGECACHE_H
|
#define IMAGECACHE_H
|
||||||
|
|
||||||
@@ -36,7 +18,6 @@ struct KOMPLEX_EXPORT ImageCache
|
|||||||
QString photographerUrl;
|
QString photographerUrl;
|
||||||
qint64 photographerId;
|
qint64 photographerId;
|
||||||
QMap<QString, QString> sources;
|
QMap<QString, QString> sources;
|
||||||
QMap<QString, QString> sourceSizes;
|
|
||||||
QString url;
|
QString url;
|
||||||
|
|
||||||
auto operator == (const ImageCache &other) const -> bool
|
auto operator == (const ImageCache &other) const -> bool
|
||||||
@@ -52,7 +33,6 @@ struct KOMPLEX_EXPORT ImageCache
|
|||||||
other.photographerUrl == photographerUrl &&
|
other.photographerUrl == photographerUrl &&
|
||||||
other.photographerId == photographerId &&
|
other.photographerId == photographerId &&
|
||||||
other.sources == sources &&
|
other.sources == sources &&
|
||||||
other.sourceSizes == sourceSizes &&
|
|
||||||
other.url == url
|
other.url == url
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef KOMPLEX_GLOBAL_H
|
#ifndef KOMPLEX_GLOBAL_H
|
||||||
#define KOMPLEX_GLOBAL_H
|
#define KOMPLEX_GLOBAL_H
|
||||||
#include <QtTypes>
|
|
||||||
#include <QString>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
#ifdef KOMPLEX_PLUGIN
|
#ifdef KOMPLEX_PLUGIN
|
||||||
#define KOMPLEX_EXPORT Q_DECL_EXPORT
|
#define KOMPLEX_EXPORT Q_DECL_EXPORT
|
||||||
@@ -32,46 +29,36 @@
|
|||||||
#define SLIDING_CACHE_PREFETCH_THRESHOLD 20
|
#define SLIDING_CACHE_PREFETCH_THRESHOLD 20
|
||||||
|
|
||||||
#define NETWORK_TIMEOUT 10000
|
#define NETWORK_TIMEOUT 10000
|
||||||
#define NETWORK_RETRY_LIMIT 3
|
|
||||||
|
|
||||||
#ifdef KOMPLEX_LOCAL_DEV
|
#ifdef KOMPLEX_LOCAL_DEV
|
||||||
#define KOMPLEX_API_HOST "https://komplexapi.hlab"
|
#define KOMPLEX_API_HOST "https://komplexapi.hlab"
|
||||||
#else
|
#else
|
||||||
inline const QString KOMPLEX_API_HOST = QStringLiteral("https://api.komplex.dev");
|
#define KOMPLEX_API_HOST "https://komplex.digitalartifex.dev"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline const QString KOMPLEX_API_VERSION = QStringLiteral("v2");
|
#define KOMPLEX_API_VERSION "v2"
|
||||||
|
|
||||||
inline const QString KOMPLEX_ENDPOINT_IMAGES_SEARCH = QStringLiteral("images/search");
|
#define KOMPLEX_ENDPOINT_IMAGES_SEARCH "images/search"
|
||||||
inline const QString KOMPLEX_ENDPOINT_IMAGES_FEATURED = QStringLiteral("featured/images");
|
#define KOMPLEX_ENDPOINT_IMAGES_FEATURED "featured/images"
|
||||||
inline const QString KOMPLEX_ENDPOINT_IMAGES_ITEM = QStringLiteral("images/item");
|
#define KOMPLEX_ENDPOINT_IMAGES_ITEM "images/item"
|
||||||
|
|
||||||
inline const QString KOMPLEX_ENDPOINT_VIDEOS_SEARCH = QStringLiteral("videos/search");
|
#define KOMPLEX_ENDPOINT_VIDEOS_SEARCH "videos/search"
|
||||||
inline const QString KOMPLEX_ENDPOINT_VIDEOS_FEATURED = QStringLiteral("featured/videos");
|
#define KOMPLEX_ENDPOINT_VIDEOS_FEATURED "featured/videos"
|
||||||
inline const QString KOMPLEX_ENDPOINT_VIDEOS_ITEM = QStringLiteral("videos/item");
|
#define KOMPLEX_ENDPOINT_VIDEOS_ITEM "videos/item"
|
||||||
|
|
||||||
inline const QString KOMPLEX_ENDPOINT_SHADERS_SEARCH = QStringLiteral("shaders/search");
|
#define KOMPLEX_ENDPOINT_SHADERS_SEARCH "shaders/search"
|
||||||
inline const QString KOMPLEX_ENDPOINT_SHADERS_FEATURED = QStringLiteral("shaders/featured");
|
#define KOMPLEX_ENDPOINT_SHADERS_FEATURED "shaders/featured"
|
||||||
inline const QString KOMPLEX_ENDPOINT_SHADERS_ITEM = QStringLiteral("shaders/item");
|
#define KOMPLEX_ENDPOINT_SHADERS_ITEM "shaders/item"
|
||||||
inline const QString KOMPLEX_ENDPOINT_SHADERS_NEWEST = QStringLiteral("shaders/newest");
|
#define KOMPLEX_ENDPOINT_SHADERS_NEWEST "shaders/newest"
|
||||||
|
|
||||||
inline const QString KOMPLEX_ENDPOINT_CUBEMAPS_SEARCH = QStringLiteral("cubemaps/search");
|
#define KOMPLEX_ENDPOINT_CUBEMAPS_SEARCH "cubemaps/search"
|
||||||
inline const QString KOMPLEX_ENDPOINT_CUBEMAPS_FEATURED = QStringLiteral("cubemaps/featured");
|
#define KOMPLEX_ENDPOINT_CUBEMAPS_FEATURED "cubemaps/featured"
|
||||||
inline const QString KOMPLEX_ENDPOINT_CUBEMAPS_ITEM = QStringLiteral("cubemaps/item");
|
#define KOMPLEX_ENDPOINT_CUBEMAPS_ITEM "cubemaps/item"
|
||||||
inline const QString KOMPLEX_ENDPOINT_CUBEMAPS_NEWEST = QStringLiteral("cubemaps/newest");
|
#define KOMPLEX_ENDPOINT_CUBEMAPS_NEWEST "cubemaps/newest"
|
||||||
|
|
||||||
inline const QString KOMPLEX_ENDPOINT_PACKS_SEARCH = QStringLiteral("packs/search");
|
#define KOMPLEX_ENDPOINT_PACKS_SEARCH "packs/search"
|
||||||
inline const QString KOMPLEX_ENDPOINT_PACKS_FEATURED = QStringLiteral("packs/featured");
|
#define KOMPLEX_ENDPOINT_PACKS_FEATURED "packs/featured"
|
||||||
inline const QString KOMPLEX_ENDPOINT_PACKS_ITEM = QStringLiteral("packs/item");
|
#define KOMPLEX_ENDPOINT_PACKS_ITEM "packs/item"
|
||||||
inline const QString KOMPLEX_ENDPOINT_PACKS_NEWEST = QStringLiteral("packs/newest");
|
#define KOMPLEX_ENDPOINT_PACKS_NEWEST "packs/newest"
|
||||||
|
|
||||||
inline const QString KOMPLEX_ENDPOINT_USER_AUTH = QStringLiteral("user/auth");
|
|
||||||
|
|
||||||
inline const qsizetype nullsize = std::numeric_limits<qsizetype>::min();
|
|
||||||
inline const std::chrono::milliseconds KOMPLEX_RATE_LIMIT(500);
|
|
||||||
inline const QString KOMPLEX_KEYCHAIN_SERVICE_NAME = QStringLiteral
|
|
||||||
(
|
|
||||||
"com.digitalartifex.komplex"
|
|
||||||
);
|
|
||||||
|
|
||||||
#endif // KOMPLEX_GLOBAL_H
|
#endif // KOMPLEX_GLOBAL_H
|
||||||
|
|||||||
@@ -23,12 +23,9 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonParseError>
|
|
||||||
|
|
||||||
#include "common/komplex_global.h"
|
#include "komplex_global.h"
|
||||||
#include "common/slidingcachecontroller.h"
|
#include "slidingcachecontroller.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The PaginationNotifier class
|
* @brief The PaginationNotifier class
|
||||||
@@ -42,15 +39,12 @@ class KOMPLEX_EXPORT PaginationNotifier : public QObject
|
|||||||
protected:
|
protected:
|
||||||
explicit PaginationNotifier(QObject *parent = nullptr) : QObject(parent) {}
|
explicit PaginationNotifier(QObject *parent = nullptr) : QObject(parent) {}
|
||||||
signals:
|
signals:
|
||||||
auto fetchComplete() -> void;
|
auto dataChanged() -> void;
|
||||||
auto fetching() -> void;
|
|
||||||
auto resultsPerPageChanged() -> void;
|
auto resultsPerPageChanged() -> void;
|
||||||
auto totalResultsChanged() -> void;
|
auto totalResultsChanged() -> void;
|
||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
auto pageChanged() -> void;
|
auto pageChanged() -> void;
|
||||||
auto countChanged() -> void;
|
auto countChanged() -> void;
|
||||||
auto queryChanged() -> void;
|
|
||||||
auto uriChanged() -> void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,21 +57,7 @@ class KOMPLEX_EXPORT Paginator : public PaginationNotifier
|
|||||||
public:
|
public:
|
||||||
explicit Paginator(QObject *parent = nullptr) : PaginationNotifier(parent)
|
explicit Paginator(QObject *parent = nullptr) : PaginationNotifier(parent)
|
||||||
{
|
{
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
&m_cacheController,
|
|
||||||
&SlidingCacheNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&PaginationNotifier::fetchComplete
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
&m_cacheController,
|
|
||||||
&SlidingCacheNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&PaginationNotifier::fetching
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,15 +67,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
auto next() -> void
|
auto next() -> void
|
||||||
{
|
{
|
||||||
if(m_offset != nullsize)
|
setOffset(m_offset + m_resultsPerPage);
|
||||||
{
|
|
||||||
setOffset(m_offset + m_resultsPerPage);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
controller()->init();
|
|
||||||
setOffset(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,22 +77,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
auto previous() -> void
|
auto previous() -> void
|
||||||
{
|
{
|
||||||
if(m_offset != nullsize && m_offset > m_resultsPerPage)
|
setOffset(m_offset - m_resultsPerPage);
|
||||||
{
|
|
||||||
setOffset(m_offset - m_resultsPerPage);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
controller()->init();
|
|
||||||
setOffset(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief resultsPerPage
|
* @brief resultsPerPage
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
|
||||||
auto resultsPerPage() const -> qsizetype
|
auto resultsPerPage() const -> qsizetype
|
||||||
{
|
{
|
||||||
return m_resultsPerPage;
|
return m_resultsPerPage;
|
||||||
@@ -132,6 +95,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
auto setResultsPerPage(qsizetype resultsPerPage) -> void
|
auto setResultsPerPage(qsizetype resultsPerPage) -> void
|
||||||
{
|
{
|
||||||
|
QMutexLocker dataLocker(&m_dataMutex);
|
||||||
|
|
||||||
if(resultsPerPage == m_resultsPerPage)
|
if(resultsPerPage == m_resultsPerPage)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -139,103 +104,27 @@ public:
|
|||||||
|
|
||||||
m_resultsPerPage = resultsPerPage;
|
m_resultsPerPage = resultsPerPage;
|
||||||
Q_EMIT static_cast<PaginationNotifier*>(this)->resultsPerPageChanged();
|
Q_EMIT static_cast<PaginationNotifier*>(this)->resultsPerPageChanged();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
m_data = m_cacheController.chunk(m_offset, m_resultsPerPage);
|
||||||
* @brief query
|
Q_EMIT static_cast<PaginationNotifier*>(this)->dataChanged();
|
||||||
* Current query string, if the API Endpoint supports queries
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
[[nodiscard]]
|
|
||||||
auto query() const -> QString
|
|
||||||
{
|
|
||||||
return m_query;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setQuery
|
|
||||||
* Sets the new query string and updates the controller
|
|
||||||
* @param query
|
|
||||||
*/
|
|
||||||
auto setQuery(const QString &query) -> void
|
|
||||||
{
|
|
||||||
if(query == m_query)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
m_query = query;
|
|
||||||
Q_EMIT queryChanged();
|
|
||||||
|
|
||||||
controller()->init();
|
|
||||||
setOffset(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief uri
|
|
||||||
* URI of the API Endpoint. This is set by the child class
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
[[nodiscard]]
|
|
||||||
auto uri() const -> QString
|
|
||||||
{
|
|
||||||
return m_uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setUri
|
|
||||||
* Sets the API Endpoint URI to fetch from
|
|
||||||
* @param uri
|
|
||||||
*/
|
|
||||||
auto setUri(const QString &uri) -> void
|
|
||||||
{
|
|
||||||
if(uri == m_uri)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_uri = uri;
|
|
||||||
|
|
||||||
Q_EMIT uriChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief data
|
* @brief data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
auto data() const -> QList<T>
|
||||||
auto data() const -> const QList<T>
|
|
||||||
{
|
{
|
||||||
if(boundaryCheck(m_resultsPerPage))
|
return m_data;
|
||||||
{
|
|
||||||
return m_cacheController.chunk(m_offset, m_resultsPerPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype count = (m_cacheController.totalCount() - m_offset);
|
|
||||||
return m_cacheController.chunk(m_offset, count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief count
|
* @brief count
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
|
||||||
auto count() const -> qsizetype
|
auto count() const -> qsizetype
|
||||||
{
|
{
|
||||||
if(m_offset == nullsize)
|
return m_data.count();
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(boundaryCheck(m_resultsPerPage))
|
|
||||||
{
|
|
||||||
return m_resultsPerPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype count = (m_cacheController.totalCount() - m_offset);
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -243,10 +132,16 @@ public:
|
|||||||
* @param index
|
* @param index
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
auto at(qsizetype index) const -> T
|
||||||
auto at(qsizetype index) const -> const T&
|
|
||||||
{
|
{
|
||||||
return m_cacheController.at(m_offset + index);
|
QMutexLocker dataLocker(&m_dataMutex);
|
||||||
|
|
||||||
|
if(index < 0 || index >= m_data.count())
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_data.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -255,7 +150,6 @@ public:
|
|||||||
* The total number of results as reported by the controller
|
* The total number of results as reported by the controller
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
|
||||||
auto totalResults() const -> qsizetype
|
auto totalResults() const -> qsizetype
|
||||||
{
|
{
|
||||||
return m_cacheController.totalCount();
|
return m_cacheController.totalCount();
|
||||||
@@ -266,7 +160,6 @@ public:
|
|||||||
* Calculates the current page
|
* Calculates the current page
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
|
||||||
auto page() const -> qsizetype
|
auto page() const -> qsizetype
|
||||||
{
|
{
|
||||||
return std::floor(
|
return std::floor(
|
||||||
@@ -279,7 +172,6 @@ public:
|
|||||||
* Calculates the total number of pages available
|
* Calculates the total number of pages available
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
|
||||||
auto totalPages() const -> qsizetype
|
auto totalPages() const -> qsizetype
|
||||||
{
|
{
|
||||||
return std::ceil(
|
return std::ceil(
|
||||||
@@ -287,34 +179,8 @@ public:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setWindowSize
|
|
||||||
* Sets the controller window size
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto setWindowSize(qsizetype size) -> void
|
|
||||||
{
|
|
||||||
m_cacheController.setWindowSize(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
auto windowSize() const -> qsizetype
|
|
||||||
{
|
|
||||||
return m_cacheController.windowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto queryable() const -> bool
|
|
||||||
{
|
|
||||||
return m_queryable;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
auto setQueryable(bool queryable) -> void
|
|
||||||
{
|
|
||||||
m_queryable = queryable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief controller
|
* @brief controller
|
||||||
* Reference to the underlying cache controller
|
* Reference to the underlying cache controller
|
||||||
@@ -332,11 +198,16 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto setOffset(qsizetype offset) -> void
|
auto setOffset(qsizetype offset) -> void
|
||||||
{
|
{
|
||||||
if(offset == m_offset)
|
if(offset == m_offset && offset != std::numeric_limits<qsizetype>::infinity())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(offset == std::numeric_limits<qsizetype>::infinity())
|
||||||
|
{
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
m_offset = offset;
|
m_offset = offset;
|
||||||
|
|
||||||
if(m_offset >= totalResults())
|
if(m_offset >= totalResults())
|
||||||
@@ -349,11 +220,26 @@ protected:
|
|||||||
m_offset = 0;
|
m_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cacheController.focus(offset, m_resultsPerPage);
|
QList<T> data = m_cacheController.chunk(m_offset, m_resultsPerPage);
|
||||||
|
setData(data);
|
||||||
|
|
||||||
Q_EMIT totalResultsChanged();
|
Q_EMIT this->pageChanged();
|
||||||
Q_EMIT totalPagesChanged();
|
}
|
||||||
Q_EMIT pageChanged();
|
|
||||||
|
/**
|
||||||
|
* @brief setData
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
auto setData(const QList<T> &data)
|
||||||
|
{
|
||||||
|
m_dataMutex.lock();
|
||||||
|
|
||||||
|
m_data.clear();
|
||||||
|
m_data.append(std::move(data));
|
||||||
|
m_dataMutex.unlock();
|
||||||
|
|
||||||
|
Q_EMIT this->countChanged();
|
||||||
|
Q_EMIT this->dataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -371,59 +257,26 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto reset() -> void
|
auto reset() -> void
|
||||||
{
|
{
|
||||||
m_query.clear();
|
m_dataMutex.lock();
|
||||||
m_offset = nullsize;
|
|
||||||
|
m_data.clear();
|
||||||
controller()->reset();
|
controller()->reset();
|
||||||
}
|
m_dataMutex.unlock();
|
||||||
|
|
||||||
/**
|
Q_EMIT totalPagesChanged();
|
||||||
* @brief getDocument
|
Q_EMIT dataChanged();
|
||||||
* Extracts the JSON document from the server reply and deletes the reply
|
Q_EMIT pageChanged();
|
||||||
* object.
|
|
||||||
* @param reply
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
[[nodiscard]]
|
|
||||||
auto getDocument(QNetworkReply *reply) const -> QJsonDocument
|
|
||||||
{
|
|
||||||
QByteArray data = reply->readAll();
|
|
||||||
QJsonParseError documentError;
|
|
||||||
QJsonDocument document = QJsonDocument::fromJson(data, &documentError);
|
|
||||||
|
|
||||||
reply->deleteLater();
|
setOffset(std::numeric_limits<qsizetype>::infinity());
|
||||||
|
|
||||||
LOG_ERROR_X(documentError.error != QJsonParseError::NoError,
|
|
||||||
"NewestPacksPaginator::getDocument",
|
|
||||||
documentError.errorString().toStdString().c_str(),
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
|
|
||||||
return document;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Checks if the index is within the bounds of the dataset
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
if(index < 0 || (m_offset + index) >= m_cacheController.totalCount())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief m_offset
|
* @brief m_offset
|
||||||
* Current absolute offset. Used in fetch operations
|
* Current absolute offset. Used in fetch operations
|
||||||
*/
|
*/
|
||||||
mutable qsizetype m_offset = nullsize;
|
qsizetype m_offset = std::numeric_limits<qsizetype>::infinity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief m_resultsPerPage
|
* @brief m_resultsPerPage
|
||||||
@@ -441,28 +294,16 @@ private:
|
|||||||
*/
|
*/
|
||||||
SlidingCacheController<T> m_cacheController;
|
SlidingCacheController<T> m_cacheController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief m_data
|
||||||
|
* Internal data copy
|
||||||
|
*/
|
||||||
|
QList<T> m_data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief m_dataMutex
|
* @brief m_dataMutex
|
||||||
*/
|
*/
|
||||||
mutable QMutex m_dataMutex;
|
mutable QMutex m_dataMutex;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_query
|
|
||||||
* The query string used in fetch operations
|
|
||||||
*/
|
|
||||||
QString m_query;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_queryable
|
|
||||||
* Controls the queryable state of the paginator
|
|
||||||
*/
|
|
||||||
bool m_queryable = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_uri
|
|
||||||
* API Endpoint URI
|
|
||||||
*/
|
|
||||||
QString m_uri;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PAGINATOR_H
|
#endif // PAGINATOR_H
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
#include "qwallet.h"
|
|
||||||
#include "../3rdparty/qtkeychain/qtkeychain/keychain.h"
|
|
||||||
#include "common/exceptions.h"
|
|
||||||
|
|
||||||
auto QWallet::read(const QString &service, const QString &key) const -> QFuture<QByteArray>
|
|
||||||
{
|
|
||||||
return QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, service(service), key(key)]() -> QByteArray
|
|
||||||
{
|
|
||||||
QEventLoop loop;
|
|
||||||
QByteArray value;
|
|
||||||
|
|
||||||
auto readCredentialJob = new QKeychain::ReadPasswordJob(service);
|
|
||||||
readCredentialJob->setAutoDelete(true);
|
|
||||||
readCredentialJob->setKey(key);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
readCredentialJob,
|
|
||||||
&QKeychain::ReadPasswordJob::finished,
|
|
||||||
this,
|
|
||||||
[this, key, &loop, &value](QKeychain::Job *job)
|
|
||||||
{
|
|
||||||
auto j = static_cast<QKeychain::ReadPasswordJob*>(job);
|
|
||||||
if (j->error() == QKeychain::NoError)
|
|
||||||
{
|
|
||||||
value = j->binaryData();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_errorString = qPrintable(j->errorString());
|
|
||||||
throw wallet_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("Wallet read error").toStdString(),
|
|
||||||
errorString().toStdString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
loop.quit();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
readCredentialJob->start();
|
|
||||||
loop.exec();
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto QWallet::write(const QString &service, const QString &key, const QByteArray &value) -> QFuture<void>
|
|
||||||
{
|
|
||||||
return QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, service(service), key(key), value(value)]() -> void
|
|
||||||
{
|
|
||||||
QEventLoop loop;
|
|
||||||
bool success;
|
|
||||||
|
|
||||||
auto writeCredentialJob = new QKeychain::WritePasswordJob(service);
|
|
||||||
writeCredentialJob->setAutoDelete(true);
|
|
||||||
writeCredentialJob->setKey(key);
|
|
||||||
writeCredentialJob->setBinaryData(value);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
writeCredentialJob,
|
|
||||||
&QKeychain::WritePasswordJob::finished,
|
|
||||||
this,
|
|
||||||
[this, key, &loop, &success](QKeychain::Job *job)
|
|
||||||
{
|
|
||||||
auto j = static_cast<QKeychain::WritePasswordJob*>(job);
|
|
||||||
if (j->error() != QKeychain::NoError)
|
|
||||||
{
|
|
||||||
setErrorString(qPrintable(j->errorString()));
|
|
||||||
throw wallet_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("Wallet write error").toStdString(),
|
|
||||||
errorString().toStdString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
loop.quit();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
writeCredentialJob->start();
|
|
||||||
loop.exec();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto QWallet::remove(const QString &service, const QString &key) -> QFuture<void>
|
|
||||||
{
|
|
||||||
return QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, service(service), key(key)]() -> void
|
|
||||||
{
|
|
||||||
QEventLoop loop;
|
|
||||||
bool value;
|
|
||||||
|
|
||||||
auto deleteCredentialJob = new QKeychain::DeletePasswordJob(service);
|
|
||||||
deleteCredentialJob->setAutoDelete(true);
|
|
||||||
deleteCredentialJob->setKey(key);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
deleteCredentialJob,
|
|
||||||
&QKeychain::DeletePasswordJob::finished,
|
|
||||||
this,
|
|
||||||
[this, key, &loop, &value](QKeychain::Job *job)
|
|
||||||
{
|
|
||||||
auto j = static_cast<QKeychain::DeletePasswordJob*>(job);
|
|
||||||
if (j->error() != QKeychain::NoError)
|
|
||||||
{
|
|
||||||
m_errorString = qPrintable(j->errorString());
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
loop.quit();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
deleteCredentialJob->start();
|
|
||||||
loop.exec();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QWallet::QWallet(QObject *parent) : QObject(parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QWallet::~QWallet()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
auto QWallet::errorString() const -> const QString &
|
|
||||||
{
|
|
||||||
return m_errorString;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto QWallet::setErrorString(const QString &errorString) const -> void
|
|
||||||
{
|
|
||||||
m_errorString = errorString;
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef QWALLET_H
|
|
||||||
#define QWALLET_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QFuture>
|
|
||||||
#include <QEventLoop>
|
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "komplex_global.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The QWallet class
|
|
||||||
* QWallet is a QFuture wrapper for QtKeychain to make interaction with the keychain easier
|
|
||||||
*/
|
|
||||||
class KOMPLEX_EXPORT QWallet : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit QWallet(QObject *parent = nullptr);
|
|
||||||
~QWallet();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief read
|
|
||||||
* Reads the provided key from the system keychain/wallet
|
|
||||||
* @param service
|
|
||||||
* Service name of the application making the request
|
|
||||||
* @param key
|
|
||||||
* Key to read
|
|
||||||
* @return
|
|
||||||
* QFuture for the binary value
|
|
||||||
*/
|
|
||||||
[[nodiscard]]
|
|
||||||
auto read(const QString &service, const QString &key) const -> QFuture<QByteArray>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief write
|
|
||||||
* Writes the provided value to the system kaychain/wallet
|
|
||||||
* @param service
|
|
||||||
* Service name of the application making the request
|
|
||||||
* @param key
|
|
||||||
* Key to read
|
|
||||||
* @param value
|
|
||||||
* Binary data to store
|
|
||||||
* @return
|
|
||||||
* QFuture
|
|
||||||
*/
|
|
||||||
[[nodiscard]]
|
|
||||||
auto write(const QString &service, const QString &key, const QByteArray &value) -> QFuture<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief write
|
|
||||||
* Removes the provided value from the system kaychain/wallet
|
|
||||||
* @param service
|
|
||||||
* Service name of the application making the request
|
|
||||||
* @param key
|
|
||||||
* Key to read
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
[[nodiscard]]
|
|
||||||
auto remove(const QString &service, const QString &key) -> QFuture<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorString
|
|
||||||
* String describing the last encountered error.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
[[nodiscard]]
|
|
||||||
auto errorString() const -> const QString &;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* @brief setErrorString
|
|
||||||
* Sets the error string
|
|
||||||
* @param errorString
|
|
||||||
*/
|
|
||||||
auto setErrorString(const QString &errorString) const -> void;
|
|
||||||
|
|
||||||
mutable QString m_errorString;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // QWALLET_H
|
|
||||||
@@ -1,630 +0,0 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef SHADERPACK_H
|
|
||||||
#define SHADERPACK_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonParseError>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QMap>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QEventLoop>
|
|
||||||
#include <QtQml/qqmlregistration.h>
|
|
||||||
|
|
||||||
#include "komplex_global.h"
|
|
||||||
|
|
||||||
class KOMPLEX_EXPORT ShaderChannel : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
QML_ELEMENT
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum Type
|
|
||||||
{
|
|
||||||
Image,
|
|
||||||
Video,
|
|
||||||
Shader,
|
|
||||||
Cubemap,
|
|
||||||
Audio,
|
|
||||||
Scene,
|
|
||||||
Model
|
|
||||||
};
|
|
||||||
Q_ENUM(Type)
|
|
||||||
|
|
||||||
enum MirrorMode
|
|
||||||
{
|
|
||||||
MirrorVertical,
|
|
||||||
MirrorHorizontal,
|
|
||||||
NoMirror
|
|
||||||
};
|
|
||||||
Q_ENUM(MirrorMode)
|
|
||||||
|
|
||||||
enum Format
|
|
||||||
{
|
|
||||||
RGB8A,
|
|
||||||
RGB16F,
|
|
||||||
RGB32F
|
|
||||||
};
|
|
||||||
Q_ENUM(Format)
|
|
||||||
|
|
||||||
enum TextureRepeat
|
|
||||||
{
|
|
||||||
ClampToEdge,
|
|
||||||
RepeatVertically,
|
|
||||||
RepeatHorizontally,
|
|
||||||
Repeat
|
|
||||||
};
|
|
||||||
Q_ENUM(TextureRepeat)
|
|
||||||
|
|
||||||
inline auto source() const -> QString { return m_source; }
|
|
||||||
inline auto setSource(const QString &source) -> void
|
|
||||||
{
|
|
||||||
if(source == this->source())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_source = source;
|
|
||||||
Q_EMIT sourceChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto type() const -> Type { return m_type; }
|
|
||||||
inline auto setType(Type type) -> void
|
|
||||||
{
|
|
||||||
if(type == this->type())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_type = type;
|
|
||||||
Q_EMIT typeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto mirrorMode() const -> MirrorMode { return m_mirrorMode; }
|
|
||||||
inline auto setMirrorMode(MirrorMode mode)
|
|
||||||
{
|
|
||||||
if(mirrorMode() == mode)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_mirrorMode = mode;
|
|
||||||
Q_EMIT mirrorModeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto textureRepeat() const -> TextureRepeat { return m_textureRepeat; }
|
|
||||||
inline auto setTextureRepeat(TextureRepeat mode) -> void
|
|
||||||
{
|
|
||||||
if(textureRepeat() == mode)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_textureRepeat = mode;
|
|
||||||
Q_EMIT textureRepeatChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto resolutionY() const -> qsizetype { return m_resolutionY; }
|
|
||||||
inline auto setResolutionY(qsizetype resolution)
|
|
||||||
{
|
|
||||||
if(resolutionY() == resolution)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_resolutionY = resolution;
|
|
||||||
Q_EMIT resolutionYChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto resolutionX() const -> qsizetype { return m_resolutionX; }
|
|
||||||
inline auto setResolutionX(qsizetype resolution)
|
|
||||||
{
|
|
||||||
if(resolutionX() == resolution)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_resolutionX = resolution;
|
|
||||||
Q_EMIT resolutionXChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto resolutionScale() const -> qreal { return m_resolutionScale; }
|
|
||||||
inline auto setResolutionScale(qreal scale)
|
|
||||||
{
|
|
||||||
if(qFuzzyCompare(resolutionScale(), scale))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_resolutionScale = scale;
|
|
||||||
Q_EMIT resolutionScaledChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto speed() const -> qreal { return m_speed; }
|
|
||||||
inline auto setSpeed(qreal speed)
|
|
||||||
{
|
|
||||||
if(qFuzzyCompare(this->speed(), speed))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_speed = speed;
|
|
||||||
Q_EMIT speedChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto mouseSpeedBias() const -> qreal { return m_mouseSpeedBias; }
|
|
||||||
inline auto setMouseSpeedBias(qreal bias)
|
|
||||||
{
|
|
||||||
if(qFuzzyCompare(mouseSpeedBias(), bias))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_mouseSpeedBias = bias;
|
|
||||||
Q_EMIT mouseSpeedBiasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto bufferA() const -> ShaderChannel* { return m_bufferA; }
|
|
||||||
inline auto setBufferA(ShaderChannel *buffer) -> void
|
|
||||||
{
|
|
||||||
if (m_bufferA == buffer)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_bufferA = buffer;
|
|
||||||
Q_EMIT bufferAChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto bufferB() const -> ShaderChannel* { return m_bufferB; }
|
|
||||||
inline auto setBufferB(ShaderChannel *buffer) -> void
|
|
||||||
{
|
|
||||||
if (m_bufferB == buffer)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_bufferB = buffer;
|
|
||||||
Q_EMIT bufferBChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto bufferC() const -> ShaderChannel* { return m_bufferC; }
|
|
||||||
inline auto setBufferC(ShaderChannel *buffer) -> void
|
|
||||||
{
|
|
||||||
if (m_bufferC == buffer)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_bufferC = buffer;
|
|
||||||
Q_EMIT bufferCChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto bufferD() const -> ShaderChannel* { return m_bufferD; }
|
|
||||||
inline auto setBufferD(ShaderChannel *buffer) -> void
|
|
||||||
{
|
|
||||||
if (m_bufferD == buffer)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_bufferD = buffer;
|
|
||||||
Q_EMIT bufferDChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto channel0() const -> ShaderChannel* { return m_channel0; }
|
|
||||||
inline auto setChannel0(ShaderChannel *channel) -> void
|
|
||||||
{
|
|
||||||
if (m_channel0 == channel)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_channel0 = channel;
|
|
||||||
Q_EMIT channel0Changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto channel1() const -> ShaderChannel* { return m_channel1; }
|
|
||||||
inline auto setChannel1(ShaderChannel *channel) -> void
|
|
||||||
{
|
|
||||||
if (m_channel1 == channel)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_channel1 = channel;
|
|
||||||
Q_EMIT channel1Changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto channel2() const -> ShaderChannel* { return m_channel2; }
|
|
||||||
inline auto setChannel2(ShaderChannel *channel) -> void
|
|
||||||
{
|
|
||||||
if (m_channel2 == channel)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_channel2 = channel;
|
|
||||||
Q_EMIT channel2Changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto channel3() const -> ShaderChannel* { return m_channel3; }
|
|
||||||
inline auto setChannel3(ShaderChannel *channel) -> void
|
|
||||||
{
|
|
||||||
if (m_channel3 == channel)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_channel3 = channel;
|
|
||||||
Q_EMIT channel3Changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto frameBufferChannel() const -> qint8 { return m_frameBufferChannel; };
|
|
||||||
inline auto setFrameBufferChannel(qint8 frameBufferChannel) -> void
|
|
||||||
{
|
|
||||||
if (m_frameBufferChannel == frameBufferChannel)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_frameBufferChannel = frameBufferChannel;
|
|
||||||
Q_EMIT frameBufferChannelChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto invert() const -> bool { return m_invert; }
|
|
||||||
inline auto setInvert(bool invert) -> void
|
|
||||||
{
|
|
||||||
if (m_invert == invert)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_invert = invert;
|
|
||||||
emit invertChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto mipmap() const -> bool { return m_mipmap; }
|
|
||||||
inline auto setMipmap(bool on)
|
|
||||||
{
|
|
||||||
if(on == mipmap())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_mipmap = on;
|
|
||||||
Q_EMIT mipmapChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto format() const -> Format { return m_format; }
|
|
||||||
inline auto setFormat(Format format)
|
|
||||||
{
|
|
||||||
if(this->format() == format)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_format = format;
|
|
||||||
Q_EMIT formatChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
auto sourceChanged() -> void;
|
|
||||||
auto typeChanged() -> void;
|
|
||||||
auto mirrorModeChanged() -> void;
|
|
||||||
auto textureRepeatChanged() -> void;
|
|
||||||
auto resolutionXChanged() -> void;
|
|
||||||
auto resolutionYChanged() -> void;
|
|
||||||
auto resolutionScaledChanged() -> void;
|
|
||||||
auto speedChanged() -> void;
|
|
||||||
auto mouseSpeedBiasChanged() -> void;
|
|
||||||
auto bufferAChanged() -> void;
|
|
||||||
auto bufferBChanged() -> void;
|
|
||||||
auto bufferCChanged() -> void;
|
|
||||||
auto bufferDChanged() -> void;
|
|
||||||
auto channel0Changed() -> void;
|
|
||||||
auto channel1Changed() -> void;
|
|
||||||
auto channel2Changed() -> void;
|
|
||||||
auto channel3Changed() -> void;
|
|
||||||
auto resolutionScaleChanged() -> void;
|
|
||||||
auto frameBufferChannelChanged() -> void;
|
|
||||||
auto invertChanged() -> void;
|
|
||||||
auto mipmapChanged() -> void;
|
|
||||||
auto formatChanged() -> void;
|
|
||||||
|
|
||||||
private:
|
|
||||||
ShaderChannel *m_bufferA = nullptr;
|
|
||||||
ShaderChannel *m_bufferB = nullptr;
|
|
||||||
ShaderChannel *m_bufferC = nullptr;
|
|
||||||
ShaderChannel *m_bufferD = nullptr;
|
|
||||||
|
|
||||||
ShaderChannel *m_channel0 = nullptr;
|
|
||||||
ShaderChannel *m_channel1 = nullptr;
|
|
||||||
ShaderChannel *m_channel2 = nullptr;
|
|
||||||
ShaderChannel *m_channel3 = nullptr;
|
|
||||||
|
|
||||||
QString m_source;
|
|
||||||
Type m_type = Image;
|
|
||||||
MirrorMode m_mirrorMode = MirrorVertical;
|
|
||||||
TextureRepeat m_textureRepeat = ClampToEdge;
|
|
||||||
Format m_format = RGB8A;
|
|
||||||
|
|
||||||
qsizetype m_resolutionX = 0;
|
|
||||||
qsizetype m_resolutionY = 0;
|
|
||||||
qreal m_resolutionScale = 1.0;
|
|
||||||
qreal m_speed = 1.0;
|
|
||||||
qreal m_mouseSpeedBias = 1.0;
|
|
||||||
|
|
||||||
qint8 m_frameBufferChannel = -1;
|
|
||||||
bool m_invert = false;
|
|
||||||
bool m_mipmap = false;
|
|
||||||
|
|
||||||
Q_PROPERTY(ShaderChannel *bufferA READ bufferA WRITE setBufferA NOTIFY bufferAChanged FINAL)
|
|
||||||
Q_PROPERTY(ShaderChannel *bufferB READ bufferB WRITE setBufferB NOTIFY bufferBChanged FINAL)
|
|
||||||
Q_PROPERTY(ShaderChannel *bufferC READ bufferC WRITE setBufferC NOTIFY bufferCChanged FINAL)
|
|
||||||
Q_PROPERTY(ShaderChannel *bufferD READ bufferD WRITE setBufferD NOTIFY bufferDChanged FINAL)
|
|
||||||
Q_PROPERTY(ShaderChannel *channel0 READ channel0 WRITE setChannel0 NOTIFY channel0Changed FINAL)
|
|
||||||
Q_PROPERTY(ShaderChannel *channel1 READ channel1 WRITE setChannel1 NOTIFY channel1Changed FINAL)
|
|
||||||
Q_PROPERTY(ShaderChannel *channel2 READ channel2 WRITE setChannel2 NOTIFY channel2Changed FINAL)
|
|
||||||
Q_PROPERTY(ShaderChannel *channel3 READ channel3 WRITE setChannel3 NOTIFY channel3Changed FINAL)
|
|
||||||
Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged FINAL)
|
|
||||||
Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged FINAL)
|
|
||||||
Q_PROPERTY(MirrorMode mirrorMode READ mirrorMode WRITE setMirrorMode NOTIFY mirrorModeChanged FINAL)
|
|
||||||
Q_PROPERTY(TextureRepeat textureRepeat READ textureRepeat WRITE setTextureRepeat NOTIFY textureRepeatChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype resolutionX READ resolutionX WRITE setResolutionX NOTIFY resolutionXChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype resolutionY READ resolutionY WRITE setResolutionY NOTIFY resolutionYChanged FINAL)
|
|
||||||
Q_PROPERTY(qreal resolutionScale READ resolutionScale WRITE setResolutionScale NOTIFY resolutionScaleChanged FINAL)
|
|
||||||
Q_PROPERTY(qreal speed READ speed WRITE setSpeed NOTIFY speedChanged FINAL)
|
|
||||||
Q_PROPERTY(qreal mouseSpeedBias READ mouseSpeedBias WRITE setMouseSpeedBias NOTIFY mouseSpeedBiasChanged FINAL)
|
|
||||||
Q_PROPERTY(qint8 frameBufferChannel READ frameBufferChannel WRITE setFrameBufferChannel NOTIFY frameBufferChannelChanged FINAL)
|
|
||||||
Q_PROPERTY(bool invert READ invert WRITE setInvert NOTIFY invertChanged FINAL)
|
|
||||||
Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged FINAL)
|
|
||||||
Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged FINAL)
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ShaderChannel)
|
|
||||||
|
|
||||||
class KOMPLEX_EXPORT ShaderPack : public ShaderChannel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
QML_ELEMENT
|
|
||||||
|
|
||||||
QString m_author;
|
|
||||||
QString m_description;
|
|
||||||
QString m_engine;
|
|
||||||
QString m_file;
|
|
||||||
QString m_id;
|
|
||||||
QString m_license;
|
|
||||||
QString m_name;
|
|
||||||
QString m_version;
|
|
||||||
|
|
||||||
Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
|
|
||||||
Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
|
|
||||||
Q_PROPERTY(QString engine READ engine WRITE setEngine NOTIFY engineChanged)
|
|
||||||
Q_PROPERTY(QString file READ file WRITE setFile NOTIFY fileChanged)
|
|
||||||
Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged)
|
|
||||||
Q_PROPERTY(QString license READ license WRITE setLicense NOTIFY licenseChanged)
|
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
|
||||||
Q_PROPERTY(QString version READ version WRITE setVersion NOTIFY versionChanged)
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void authorChanged();
|
|
||||||
void descriptionChanged();
|
|
||||||
void engineChanged();
|
|
||||||
void idChanged();
|
|
||||||
void licenseChanged();
|
|
||||||
void nameChanged();
|
|
||||||
void versionChanged();
|
|
||||||
void fileChanged();
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
QString author() const { return m_author; }
|
|
||||||
void setAuthor(const QString& author)
|
|
||||||
{
|
|
||||||
if(author != m_author)
|
|
||||||
{
|
|
||||||
m_author = author;
|
|
||||||
Q_EMIT authorChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString description() const { return m_description; }
|
|
||||||
void setDescription(const QString& description)
|
|
||||||
{
|
|
||||||
if(description != m_description)
|
|
||||||
{
|
|
||||||
m_description = description;
|
|
||||||
Q_EMIT descriptionChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString engine() const { return m_engine; }
|
|
||||||
void setEngine(const QString& engine)
|
|
||||||
{
|
|
||||||
if(engine != m_engine)
|
|
||||||
{
|
|
||||||
m_engine = engine;
|
|
||||||
Q_EMIT engineChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString file() const { return m_file; }
|
|
||||||
void setFile(const QString& file)
|
|
||||||
{
|
|
||||||
if(file != m_file)
|
|
||||||
{
|
|
||||||
m_file = file;
|
|
||||||
Q_EMIT fileChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString id() const { return m_id; }
|
|
||||||
void setId(const QString& id)
|
|
||||||
{
|
|
||||||
if(id != m_id)
|
|
||||||
{
|
|
||||||
m_id = id;
|
|
||||||
Q_EMIT idChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString license() const { return m_license; }
|
|
||||||
void setLicense(const QString& license)
|
|
||||||
{
|
|
||||||
if(license != m_license)
|
|
||||||
{
|
|
||||||
m_license = license;
|
|
||||||
Q_EMIT licenseChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString name() const { return m_name; }
|
|
||||||
void setName(const QString& name)
|
|
||||||
{
|
|
||||||
if(name != m_name)
|
|
||||||
{
|
|
||||||
m_name = name;
|
|
||||||
Q_EMIT nameChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString version() const { return m_version; }
|
|
||||||
void setVersion(const QString& version)
|
|
||||||
{
|
|
||||||
if(version != m_version)
|
|
||||||
{
|
|
||||||
m_version = version;
|
|
||||||
Q_EMIT versionChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto json() -> QJsonDocument
|
|
||||||
{
|
|
||||||
QJsonObject rootObject;
|
|
||||||
|
|
||||||
rootObject[QStringLiteral("author")] = author();
|
|
||||||
rootObject[QStringLiteral("version")] = version();
|
|
||||||
rootObject[QStringLiteral("name")] = name();
|
|
||||||
rootObject[QStringLiteral("id")] = id();
|
|
||||||
rootObject[QStringLiteral("engine")] = engine();
|
|
||||||
rootObject[QStringLiteral("license")] = license();
|
|
||||||
|
|
||||||
QJsonObject bufferObject = bufferJson(this);
|
|
||||||
const QStringList bufferKeys = bufferObject.keys();
|
|
||||||
for(const QString &key : bufferKeys)
|
|
||||||
{
|
|
||||||
rootObject[key] = bufferObject[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject channelObject = channelJson(this);
|
|
||||||
const QStringList channelKeys = channelObject.keys();
|
|
||||||
for(const QString &key : channelKeys)
|
|
||||||
{
|
|
||||||
rootObject[key] = channelObject[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
return QJsonDocument
|
|
||||||
{
|
|
||||||
rootObject
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
auto bufferJson(ShaderChannel *channel) -> QJsonObject
|
|
||||||
{
|
|
||||||
QJsonObject channelObject;
|
|
||||||
|
|
||||||
if(channel->bufferA())
|
|
||||||
{
|
|
||||||
channelObject[QStringLiteral("bufferA")] = channelJson(channel->bufferA());
|
|
||||||
}
|
|
||||||
if(channel->bufferB())
|
|
||||||
{
|
|
||||||
channelObject[QStringLiteral("bufferB")] = channelJson(channel->bufferB());
|
|
||||||
}
|
|
||||||
if(channel->bufferC())
|
|
||||||
{
|
|
||||||
channelObject[QStringLiteral("bufferC")] = channelJson(channel->bufferC());
|
|
||||||
}
|
|
||||||
if(channel->bufferD())
|
|
||||||
{
|
|
||||||
channelObject[QStringLiteral("bufferD")] = channelJson(channel->bufferD());
|
|
||||||
}
|
|
||||||
|
|
||||||
return channelObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto channelJson(ShaderChannel *channel) -> QJsonObject
|
|
||||||
{
|
|
||||||
if(channel == nullptr)
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject channelObject;
|
|
||||||
|
|
||||||
if(channel->channel0() != nullptr)
|
|
||||||
{
|
|
||||||
channelObject[QStringLiteral("channel0")] = channelJson(channel->channel0());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(channel->channel1() != nullptr)
|
|
||||||
{
|
|
||||||
channelObject[QStringLiteral("channel1")] = channelJson(channel->channel1());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(channel->channel2() != nullptr)
|
|
||||||
{
|
|
||||||
channelObject[QStringLiteral("channel2")] = channelJson(channel->channel2());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(channel->channel3() != nullptr)
|
|
||||||
{
|
|
||||||
channelObject[QStringLiteral("channel3")] = channelJson(channel->channel3());
|
|
||||||
}
|
|
||||||
|
|
||||||
channelObject[QStringLiteral("source")] = channel->source();
|
|
||||||
channelObject[QStringLiteral("type")] = channel->type();
|
|
||||||
channelObject[QStringLiteral("texture_mirroring")] = channel->mirrorMode();
|
|
||||||
channelObject[QStringLiteral("wrap_mode")] = channel->textureRepeat();
|
|
||||||
channelObject[QStringLiteral("invert")] = channel->invert();
|
|
||||||
channelObject[QStringLiteral("time_scale")] = channel->speed();
|
|
||||||
channelObject[QStringLiteral("resolution_scale")] = channel->resolutionScale();
|
|
||||||
channelObject[QStringLiteral("mouse_scale")] = channel->mouseSpeedBias();
|
|
||||||
channelObject[QStringLiteral("resolution_x")] = channel->resolutionX();
|
|
||||||
channelObject[QStringLiteral("resolution_y")] = channel->resolutionY();
|
|
||||||
channelObject[QStringLiteral("frame_buffer_channel")] = channel->frameBufferChannel();
|
|
||||||
channelObject[QStringLiteral("format")] = channel->format();
|
|
||||||
channelObject[QStringLiteral("mipmap")] = channel->mipmap();
|
|
||||||
|
|
||||||
return channelObject;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ShaderPack)
|
|
||||||
#endif
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef SHADERTOYMETADATA_H
|
|
||||||
#define SHADERTOYMETADATA_H
|
|
||||||
#include <QObject>
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <QUuid>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QMutex>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QEventLoop>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonParseError>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonValue>
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QPixmap>
|
|
||||||
#include <qqmlintegration.h>
|
|
||||||
|
|
||||||
#include "komplex_global.h"
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT ShaderToyMetadata
|
|
||||||
{
|
|
||||||
QDateTime date;
|
|
||||||
QString description;
|
|
||||||
quint64 flags = 0;
|
|
||||||
bool hasLiked = false;
|
|
||||||
QString id;
|
|
||||||
quint64 likes = 0;
|
|
||||||
QString name;
|
|
||||||
quint64 published = 0;
|
|
||||||
QStringList tags;
|
|
||||||
bool usePreview = false;
|
|
||||||
QString username;
|
|
||||||
QString version;
|
|
||||||
quint64 views = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT ShaderToyRenderInput
|
|
||||||
{
|
|
||||||
quint8 channel = 0;
|
|
||||||
QString ctype;
|
|
||||||
QString filter;
|
|
||||||
quint64 id = 0;
|
|
||||||
QString internal;
|
|
||||||
bool published = false;
|
|
||||||
QString source;
|
|
||||||
bool srgb = false;
|
|
||||||
bool verticalFlip = false;
|
|
||||||
QString wrap;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT ShaderToyRenderOutput
|
|
||||||
{
|
|
||||||
const quint8 channel = 0;
|
|
||||||
const quint64 id = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT ShaderToyRenderPass
|
|
||||||
{
|
|
||||||
QByteArray code;
|
|
||||||
QString description;
|
|
||||||
QList<ShaderToyRenderInput> inputs;
|
|
||||||
QString name;
|
|
||||||
QList<ShaderToyRenderOutput> outputs;
|
|
||||||
QString type;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum KOMPLEX_EXPORT ShaderToyErrorCode
|
|
||||||
{
|
|
||||||
NoError = 0,
|
|
||||||
NetworkError = (0x10 << 24),
|
|
||||||
MediaError = (0x20 << 24),
|
|
||||||
DiskError = (0x30 << 24),
|
|
||||||
CompileError = (0x40 << 24)
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT ShaderToyError
|
|
||||||
{
|
|
||||||
QString message;
|
|
||||||
ShaderToyErrorCode code;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT ShaderToyEntry
|
|
||||||
{
|
|
||||||
enum Status
|
|
||||||
{
|
|
||||||
Idle,
|
|
||||||
Loading,
|
|
||||||
Compiling,
|
|
||||||
Compiled,
|
|
||||||
Error
|
|
||||||
};
|
|
||||||
|
|
||||||
ShaderToyMetadata metadata;
|
|
||||||
QList<ShaderToyRenderPass> renderPasses;
|
|
||||||
QByteArray data;
|
|
||||||
ShaderToyError error;
|
|
||||||
QStringList videoSelections;
|
|
||||||
Status status = Idle;
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ShaderToyEntry)
|
|
||||||
Q_DECLARE_METATYPE(ShaderToyError)
|
|
||||||
#endif // SHADERTOYMETADATA_H
|
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "fetchresult.h"
|
#include "fetchresult.h"
|
||||||
@@ -41,9 +40,6 @@ class KOMPLEX_EXPORT SlidingCacheNotifier : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
auto countChanged() -> void;
|
auto countChanged() -> void;
|
||||||
auto fetching() -> void;
|
|
||||||
auto fetchComplete() -> void;
|
|
||||||
auto windowSizeChanged() -> void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,12 +50,6 @@ signals:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class KOMPLEX_EXPORT SlidingCacheController : public SlidingCacheNotifier
|
class KOMPLEX_EXPORT SlidingCacheController : public SlidingCacheNotifier
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @brief FetchFunction
|
|
||||||
* Convenience def used by setFetch
|
|
||||||
*/
|
|
||||||
typedef std::function<FetchResult<T> (qsizetype offset, qsizetype limit)> FetchFunction;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit SlidingCacheController() : SlidingCacheNotifier{}
|
explicit SlidingCacheController() : SlidingCacheNotifier{}
|
||||||
@@ -80,7 +70,9 @@ public:
|
|||||||
* QObject
|
* QObject
|
||||||
* @param fetch
|
* @param fetch
|
||||||
*/
|
*/
|
||||||
auto setFetch(const FetchFunction &fetch) -> void
|
auto setFetch(
|
||||||
|
const std::function<FetchResult<T> (qsizetype offset, qsizetype limit)> &fetch
|
||||||
|
) -> void
|
||||||
{
|
{
|
||||||
m_fetch = std::move(fetch);
|
m_fetch = std::move(fetch);
|
||||||
}
|
}
|
||||||
@@ -93,28 +85,28 @@ public:
|
|||||||
* @return CacheObject* or nullptr
|
* @return CacheObject* or nullptr
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
auto at(qsizetype index) const -> const T&
|
auto at(qsizetype index) const -> T
|
||||||
{
|
{
|
||||||
QMutexLocker cacheLocker(&m_cacheMutex);
|
QMutexLocker cacheLocker(&m_cacheMutex);
|
||||||
|
|
||||||
if(!externalBoundaryCheck(index))
|
if(!externalBoundaryCheck(index))
|
||||||
{
|
{
|
||||||
return defaultValue;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!const_cast<SlidingCacheController*>(this)->slideWindow(index))
|
if(!const_cast<SlidingCacheController*>(this)->slideWindow(index))
|
||||||
{
|
{
|
||||||
return defaultValue;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
qsizetype internalIndex = this->internalIndex(index);
|
qsizetype internalIndex = this->internalIndex(index);
|
||||||
|
|
||||||
if(!internalBoundaryCheck(internalIndex))
|
if(!internalBoundaryCheck(index))
|
||||||
{
|
{
|
||||||
return defaultValue;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_cache.at(internalIndex);
|
return m_cache.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,17 +134,29 @@ public:
|
|||||||
|
|
||||||
qsizetype internalIndex = this->internalIndex(index);
|
qsizetype internalIndex = this->internalIndex(index);
|
||||||
|
|
||||||
if(!internalBoundaryCheck(internalIndex))
|
if(!internalBoundaryCheck(index))
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!internalBoundaryCheck(count - 1))
|
if(!internalBoundaryCheck(count - 1))
|
||||||
{
|
{
|
||||||
count = m_cache.count() - internalIndex;
|
count = m_cache.count() - index;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_cache.mid(internalIndex, count);
|
QList<T> dataChunk;
|
||||||
|
|
||||||
|
for(qsizetype i = index; (i - index) < count; ++i)
|
||||||
|
{
|
||||||
|
T data = m_cache.at(i);
|
||||||
|
|
||||||
|
if(data != T{})
|
||||||
|
{
|
||||||
|
dataChunk.append(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataChunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,7 +167,7 @@ public:
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
auto totalCount() const -> qsizetype
|
auto totalCount() const -> qsizetype
|
||||||
{
|
{
|
||||||
if(m_totalCount == nullsize)
|
if(m_totalCount == std::numeric_limits<qsizetype>::infinity())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -191,54 +195,10 @@ public:
|
|||||||
QMutexLocker cacheLocker(&m_cacheMutex);
|
QMutexLocker cacheLocker(&m_cacheMutex);
|
||||||
|
|
||||||
m_cache.clear();
|
m_cache.clear();
|
||||||
setTotalCount(nullsize);
|
setTotalCount(std::numeric_limits<qsizetype>::infinity());
|
||||||
m_windowOffset = 0;
|
m_windowOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto focus(qsizetype index, qsizetype count) -> void
|
|
||||||
{
|
|
||||||
if(inFocus(index, count) || !externalBoundaryCheck(index))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(externalBoundaryCheck(index + count))
|
|
||||||
{
|
|
||||||
slideWindow(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto init() -> bool
|
|
||||||
{
|
|
||||||
if(m_totalCount != nullsize)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return slideForward();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto windowSize() const -> qsizetype
|
|
||||||
{
|
|
||||||
if(m_windowSize == nullsize)
|
|
||||||
{
|
|
||||||
return SLIDING_CACHE_WINDOW_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_windowSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto setWindowSize(qsizetype windowSize) -> void
|
|
||||||
{
|
|
||||||
if(windowSize == m_windowSize)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_windowSize = windowSize;
|
|
||||||
Q_EMIT windowSizeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief setTotalCount
|
* @brief setTotalCount
|
||||||
@@ -255,16 +215,6 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
auto inFocus(qsizetype index, qsizetype count) -> bool
|
|
||||||
{
|
|
||||||
qsizetype internalIndex = this->internalIndex(index);
|
|
||||||
|
|
||||||
return
|
|
||||||
(
|
|
||||||
internalBoundaryCheck(internalIndex, internalIndex + count)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief externalBoundaryCheck
|
* @brief externalBoundaryCheck
|
||||||
*
|
*
|
||||||
@@ -274,29 +224,12 @@ private:
|
|||||||
* @return True if index is within the external dataset boundary
|
* @return True if index is within the external dataset boundary
|
||||||
* OR an initial fetch has not been performed.
|
* OR an initial fetch has not been performed.
|
||||||
*/
|
*/
|
||||||
template<typename... Ts>
|
auto externalBoundaryCheck(qsizetype index) const -> bool
|
||||||
auto externalBoundaryCheck(Ts... index) const -> bool
|
|
||||||
{
|
{
|
||||||
static_assert
|
return (
|
||||||
(
|
|
||||||
(std::is_same_v<Ts, qsizetype> && ...),
|
|
||||||
"All arguments must be qsizetype"
|
|
||||||
);
|
|
||||||
|
|
||||||
bool safe = false;
|
|
||||||
|
|
||||||
((safe = externalBoundaryCheckHelper(index)),...);
|
|
||||||
|
|
||||||
return safe;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto externalBoundaryCheckHelper(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
return
|
|
||||||
(
|
|
||||||
index >= 0 &&
|
index >= 0 &&
|
||||||
(
|
(
|
||||||
m_totalCount == nullsize ||
|
m_totalCount == std::numeric_limits<qsizetype>::infinity() ||
|
||||||
index < m_totalCount
|
index < m_totalCount
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -309,18 +242,12 @@ private:
|
|||||||
* @param index
|
* @param index
|
||||||
* @return True if index is within the internal dataset boundary
|
* @return True if index is within the internal dataset boundary
|
||||||
*/
|
*/
|
||||||
template<typename... Ts>
|
auto internalBoundaryCheck(qsizetype index) const -> bool
|
||||||
auto internalBoundaryCheck(Ts... index) const -> bool
|
|
||||||
{
|
{
|
||||||
static_assert
|
return (
|
||||||
(
|
index >= 0 &&
|
||||||
(std::is_same_v<Ts, qsizetype> && ...),
|
index < m_cache.count()
|
||||||
"All arguments must be qsizetype"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
bool safe = false;
|
|
||||||
((safe = ((index >= 0) && (index < m_cache.count()))), ...);
|
|
||||||
return safe;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -337,17 +264,7 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qsizetype prefetchThreshold = SLIDING_CACHE_PREFETCH_THRESHOLD;
|
while (index >= m_windowOffset + (SLIDING_CACHE_WINDOW_SIZE - SLIDING_CACHE_PREFETCH_THRESHOLD))
|
||||||
|
|
||||||
if(prefetchThreshold >= windowSize())
|
|
||||||
{
|
|
||||||
prefetchThreshold = std::floor
|
|
||||||
(
|
|
||||||
static_cast<qreal>(windowSize()) * 0.8
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (index >= m_windowOffset + (windowSize() - prefetchThreshold))
|
|
||||||
{
|
{
|
||||||
if(!slideForward())
|
if(!slideForward())
|
||||||
{
|
{
|
||||||
@@ -355,7 +272,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (index < m_windowOffset)
|
while (index <= m_windowOffset - (SLIDING_CACHE_WINDOW_SIZE - SLIDING_CACHE_PREFETCH_THRESHOLD))
|
||||||
{
|
{
|
||||||
if(!slideBackward())
|
if(!slideBackward())
|
||||||
{
|
{
|
||||||
@@ -363,6 +280,14 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_totalCount == std::numeric_limits<qsizetype>::infinity())
|
||||||
|
{
|
||||||
|
if(!slideForward())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,41 +299,20 @@ private:
|
|||||||
auto slideForward() -> bool
|
auto slideForward() -> bool
|
||||||
{
|
{
|
||||||
LOG_ERROR_X(!m_fetch,
|
LOG_ERROR_X(!m_fetch,
|
||||||
"SlidingCacheController::slideForward",
|
"SlidingCacheController::slideBackward",
|
||||||
"Fetch function not set",
|
"Fetch function not set",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
Q_EMIT fetching();
|
|
||||||
|
|
||||||
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE;
|
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE;
|
||||||
qsizetype prefetchThreshold = SLIDING_CACHE_PREFETCH_THRESHOLD;
|
|
||||||
|
|
||||||
if(m_windowSize != nullsize)
|
|
||||||
{
|
|
||||||
movementSize = m_windowSize;
|
|
||||||
|
|
||||||
if(prefetchThreshold >= m_windowSize)
|
|
||||||
{
|
|
||||||
prefetchThreshold = std::floor(
|
|
||||||
static_cast<qreal>(movementSize) * 0.8
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_ERROR_X(movementSize <= 0 || prefetchThreshold <= 0,
|
|
||||||
"SlidingCacheController::slideForward",
|
|
||||||
"Invalid movement size",
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
//after initial inflation we should only arrive here when the prefetch threshold is reached
|
//after initial inflation we should only arrive here when the prefetch threshold is reached
|
||||||
if(!m_cache.isEmpty())
|
if(!m_cache.isEmpty())
|
||||||
{
|
{
|
||||||
movementSize -= prefetchThreshold;
|
movementSize -= SLIDING_CACHE_PREFETCH_THRESHOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_totalCount != nullsize)
|
if(m_totalCount != std::numeric_limits<qsizetype>::infinity())
|
||||||
{
|
{
|
||||||
m_windowOffset += movementSize;
|
m_windowOffset += movementSize;
|
||||||
}
|
}
|
||||||
@@ -417,8 +321,6 @@ private:
|
|||||||
m_windowOffset = 0;
|
m_windowOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// QThread::sleep(KOMPLEX_RATE_LIMIT);
|
|
||||||
|
|
||||||
FetchResult<T> result = m_fetch(
|
FetchResult<T> result = m_fetch(
|
||||||
m_windowOffset,
|
m_windowOffset,
|
||||||
movementSize
|
movementSize
|
||||||
@@ -435,8 +337,6 @@ private:
|
|||||||
if(result.data.isEmpty())
|
if(result.data.isEmpty())
|
||||||
{
|
{
|
||||||
m_windowOffset -= movementSize;
|
m_windowOffset -= movementSize;
|
||||||
|
|
||||||
Q_EMIT fetchComplete();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,8 +359,6 @@ private:
|
|||||||
m_cache.append(std::move(result.data));
|
m_cache.append(std::move(result.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT fetchComplete();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,31 +375,7 @@ private:
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
Q_EMIT fetching();
|
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE - SLIDING_CACHE_PREFETCH_THRESHOLD;
|
||||||
|
|
||||||
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE;
|
|
||||||
qsizetype prefetchThreshold = SLIDING_CACHE_PREFETCH_THRESHOLD;
|
|
||||||
|
|
||||||
if(m_windowSize != nullsize)
|
|
||||||
{
|
|
||||||
movementSize = m_windowSize;
|
|
||||||
|
|
||||||
if(prefetchThreshold >= m_windowSize)
|
|
||||||
{
|
|
||||||
prefetchThreshold = std::floor(
|
|
||||||
static_cast<qreal>(movementSize) * 0.8
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_ERROR_X(movementSize <= 0 || prefetchThreshold <= 0,
|
|
||||||
"SlidingCacheController::slideBackward",
|
|
||||||
"Invalid movement size",
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
// QThread::sleep(KOMPLEX_RATE_LIMIT);
|
|
||||||
|
|
||||||
m_windowOffset -= movementSize;
|
m_windowOffset -= movementSize;
|
||||||
|
|
||||||
if(m_windowOffset < 0)
|
if(m_windowOffset < 0)
|
||||||
@@ -517,8 +391,6 @@ private:
|
|||||||
if(result.count == 0)
|
if(result.count == 0)
|
||||||
{
|
{
|
||||||
m_windowOffset += movementSize;
|
m_windowOffset += movementSize;
|
||||||
|
|
||||||
Q_EMIT fetchComplete();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,8 +419,6 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT fetchComplete();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,7 +444,7 @@ private:
|
|||||||
* Total number of results available. Data comes from the return data of
|
* Total number of results available. Data comes from the return data of
|
||||||
* m_fetch
|
* m_fetch
|
||||||
*/
|
*/
|
||||||
qsizetype m_totalCount = nullsize;
|
qsizetype m_totalCount = std::numeric_limits<qsizetype>::infinity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief m_fetch
|
* @brief m_fetch
|
||||||
@@ -593,14 +463,6 @@ private:
|
|||||||
* @brief m_cacheMutex
|
* @brief m_cacheMutex
|
||||||
*/
|
*/
|
||||||
mutable QMutex m_cacheMutex;
|
mutable QMutex m_cacheMutex;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_windowSize
|
|
||||||
* Override for window size
|
|
||||||
*/
|
|
||||||
qsizetype m_windowSize = SLIDING_CACHE_WINDOW_SIZE;
|
|
||||||
|
|
||||||
T defaultValue;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SLIDINGCACHECONTROLLER_H
|
#endif // SLIDINGCACHECONTROLLER_H
|
||||||
|
|||||||
@@ -1,362 +0,0 @@
|
|||||||
#include "userservices.h"
|
|
||||||
#include "common/komplex_global.h"
|
|
||||||
#include "coreservices.h"
|
|
||||||
#include <QtConcurrent/qtconcurrentrun.h>
|
|
||||||
#include <exception>
|
|
||||||
#include <qcontainerfwd.h>
|
|
||||||
#include <qstandardpaths.h>
|
|
||||||
#include <qstringview.h>
|
|
||||||
|
|
||||||
UserServices::UserServices(QObject *parent) : QObject(parent)
|
|
||||||
{
|
|
||||||
m_wallet = new QWallet(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
UserServices::~UserServices()
|
|
||||||
{
|
|
||||||
if(m_wallet)
|
|
||||||
{
|
|
||||||
m_wallet->deleteLater();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::setUserCredentials(const UserCredentials &credentials) -> void
|
|
||||||
{
|
|
||||||
s_userCredentials = credentials;
|
|
||||||
Q_EMIT userCredentialsChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::errorString() const -> const QString &
|
|
||||||
{
|
|
||||||
return m_errorString;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::setErrorString(const QString &errorString) -> void
|
|
||||||
{
|
|
||||||
if (m_errorString == errorString)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_errorString = errorString;
|
|
||||||
emit errorStringChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::savePassword(const QString &username, const QByteArray &password) -> void
|
|
||||||
{
|
|
||||||
QFuture saveAttempt = m_wallet->write
|
|
||||||
(
|
|
||||||
KOMPLEX_KEYCHAIN_SERVICE_NAME,
|
|
||||||
username,
|
|
||||||
password
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::readPassword(const QString &username) -> QFuture<QByteArray>
|
|
||||||
{
|
|
||||||
return m_wallet->read(KOMPLEX_KEYCHAIN_SERVICE_NAME, username);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::readToken(const QString &username) -> QFuture<UserCredentials>
|
|
||||||
{
|
|
||||||
return QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, username] () -> UserCredentials
|
|
||||||
{
|
|
||||||
UserCredentials credentials;
|
|
||||||
|
|
||||||
QFuture readAttempt = m_wallet->read
|
|
||||||
(
|
|
||||||
KOMPLEX_KEYCHAIN_SERVICE_NAME,
|
|
||||||
username + QStringLiteral("_token")
|
|
||||||
);
|
|
||||||
|
|
||||||
QString _username = username;
|
|
||||||
|
|
||||||
readAttempt
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this, &credentials, _username] (const QByteArray &value) -> void
|
|
||||||
{
|
|
||||||
auto parts = value.split(PART_SEPARATOR);
|
|
||||||
QDateTime expiry;
|
|
||||||
|
|
||||||
if(parts.count() == 1)
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("Token malformed"));
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(parts[0].length() != sizeof(qint64))
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("Token expiry malformed"));
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray numericData = parts[0];
|
|
||||||
qint64 numericConversion = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < sizeof(qint64); ++i)
|
|
||||||
{
|
|
||||||
numericConversion |=
|
|
||||||
(
|
|
||||||
static_cast<qint64>
|
|
||||||
(
|
|
||||||
(
|
|
||||||
static_cast<qint8>(numericData[i]) &
|
|
||||||
0xFF
|
|
||||||
)
|
|
||||||
<< (i * sizeof(qint8))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
expiry = QDateTime::fromMSecsSinceEpoch(numericConversion);
|
|
||||||
|
|
||||||
if(parts[1].isEmpty() && parts.count() == 3)
|
|
||||||
{
|
|
||||||
parts[1] = parts[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
credentials = UserCredentials
|
|
||||||
{
|
|
||||||
.username = _username.toUtf8(),
|
|
||||||
.sessionToken = parts[1],
|
|
||||||
.expiry = expiry
|
|
||||||
};
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this] () -> void
|
|
||||||
{
|
|
||||||
setErrorString(m_wallet->errorString());
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
readAttempt.waitForFinished();
|
|
||||||
|
|
||||||
return credentials;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::saveToken(const QString &username, const QByteArray &token, const QDateTime &expiry) -> void
|
|
||||||
{
|
|
||||||
QByteArray data;
|
|
||||||
qint64 numericData = expiry.toMSecsSinceEpoch();
|
|
||||||
|
|
||||||
for(int i = 0; i < sizeof(qint64); ++i)
|
|
||||||
{
|
|
||||||
data[i] = 0xFF & static_cast<qint8>(numericData >> (i * sizeof(qint8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
data += PART_SEPARATOR + token;
|
|
||||||
|
|
||||||
QFuture saveAttempt = m_wallet->write
|
|
||||||
(
|
|
||||||
KOMPLEX_KEYCHAIN_SERVICE_NAME,
|
|
||||||
username + QString("_token"),
|
|
||||||
data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::instance() -> QWeakPointer<UserServices>
|
|
||||||
{
|
|
||||||
if(!s_pointer)
|
|
||||||
{
|
|
||||||
s_instance = new UserServices(QCoreApplication::instance());
|
|
||||||
s_pointer = QSharedPointer<UserServices>
|
|
||||||
(
|
|
||||||
s_instance,
|
|
||||||
&UserServices::deleteLater
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return s_pointer.toWeakRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::userCredentials() -> const UserCredentials &
|
|
||||||
{
|
|
||||||
return s_userCredentials;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::login(const QString &username, const QByteArray &password) -> QFuture<UserCredentials>
|
|
||||||
{
|
|
||||||
return QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, username, password] () -> UserCredentials
|
|
||||||
{
|
|
||||||
QSharedPointer<QNetworkAccessManager> manager = CoreServices::networkAccessManager().toStrongRef();
|
|
||||||
|
|
||||||
if(!manager)
|
|
||||||
{
|
|
||||||
Q_EMIT loginFailed();
|
|
||||||
setErrorString(QStringLiteral("Network manager reference deleted"));
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
saveDefaultUsername(username);
|
|
||||||
|
|
||||||
QNetworkRequest request
|
|
||||||
(
|
|
||||||
QUrl
|
|
||||||
(
|
|
||||||
QStringLiteral("%1/%2/%3").arg
|
|
||||||
(
|
|
||||||
KOMPLEX_API_HOST,
|
|
||||||
KOMPLEX_API_VERSION,
|
|
||||||
KOMPLEX_ENDPOINT_USER_AUTH
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
QJsonObject loginRootObject
|
|
||||||
{
|
|
||||||
{
|
|
||||||
QString("username"),
|
|
||||||
QJsonValue::fromVariant(username.toUtf8())
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString("password"),
|
|
||||||
QJsonValue::fromVariant(password.toBase64())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
QJsonDocument loginDocument(loginRootObject);
|
|
||||||
|
|
||||||
QNetworkReply *reply = manager->post(request, loginDocument.toJson(QJsonDocument::Compact));
|
|
||||||
|
|
||||||
while(!reply->isFinished())
|
|
||||||
{
|
|
||||||
std::chrono::milliseconds(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(reply->error() != QNetworkReply::NoError)
|
|
||||||
{
|
|
||||||
setErrorString(reply->errorString());
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray data = reply->readAll();
|
|
||||||
|
|
||||||
QJsonParseError parseError;
|
|
||||||
QJsonDocument document = QJsonDocument::fromJson(data, &parseError);
|
|
||||||
|
|
||||||
if(parseError.error != QJsonParseError::NoError)
|
|
||||||
{
|
|
||||||
setErrorString(parseError.errorString());
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject rootObject = document.object();
|
|
||||||
QJsonObject dataObject = rootObject.value(QStringLiteral("data")).toObject();
|
|
||||||
|
|
||||||
if(!rootObject.value("success").toBool())
|
|
||||||
{
|
|
||||||
setErrorString
|
|
||||||
(
|
|
||||||
QStringLiteral("Login failure (%1): %2").arg
|
|
||||||
(
|
|
||||||
dataObject.value(QStringLiteral("errorCode")).toString(),
|
|
||||||
dataObject.value(QStringLiteral("message")).toString()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString expiryData = dataObject.value(QStringLiteral("expires")).toString();
|
|
||||||
bool converted = false;
|
|
||||||
qint64 secsSinceEpoch = expiryData.toLongLong(&converted);
|
|
||||||
|
|
||||||
if(!converted)
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("Malformed expiry data"));
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserCredentials credentials
|
|
||||||
{
|
|
||||||
.username = username.toUtf8(),
|
|
||||||
.sessionToken = dataObject.value
|
|
||||||
(
|
|
||||||
QStringLiteral("jwt")
|
|
||||||
).toString().toUtf8(),
|
|
||||||
.expiry = QDateTime::fromSecsSinceEpoch(secsSinceEpoch)
|
|
||||||
};
|
|
||||||
|
|
||||||
savePassword(username, password);
|
|
||||||
saveToken(username, credentials.sessionToken, credentials.expiry);
|
|
||||||
setUserCredentials(credentials);
|
|
||||||
|
|
||||||
Q_EMIT loginComplete();
|
|
||||||
return credentials;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::saveDefaultUsername(const QString &username) -> void
|
|
||||||
{
|
|
||||||
QDir configDirectory(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
|
||||||
|
|
||||||
if(!configDirectory.exists())
|
|
||||||
{
|
|
||||||
if(!configDirectory.mkpath(configDirectory.absolutePath()))
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("Could not make config directory"));
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile usernameFile(configDirectory.absoluteFilePath(QStringLiteral("uname")));
|
|
||||||
|
|
||||||
if(!usernameFile.open(QFile::ReadWrite | QFile::Truncate))
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("Could not open uname file"));
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray data = username.toUtf8().toBase64();
|
|
||||||
|
|
||||||
if(usernameFile.write(data) != data.length())
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("Could not write uname file"));
|
|
||||||
}
|
|
||||||
|
|
||||||
usernameFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserServices::defaultUsername() -> QFuture<QString>
|
|
||||||
{
|
|
||||||
return QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this] () -> QString
|
|
||||||
{
|
|
||||||
QDir configDirectory(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
|
||||||
|
|
||||||
if(!configDirectory.exists())
|
|
||||||
{
|
|
||||||
if(!configDirectory.mkpath(configDirectory.absolutePath()))
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("Could not make config directory"));
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile usernameFile(configDirectory.absoluteFilePath(QStringLiteral("uname")));
|
|
||||||
|
|
||||||
if(!usernameFile.open(QFile::ReadOnly))
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("Could not open uname file"));
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray data = QByteArray::fromBase64(usernameFile.readAll());
|
|
||||||
|
|
||||||
usernameFile.close();
|
|
||||||
|
|
||||||
return QString(data);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QGuiApplication>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QFuture>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
|
|
||||||
#include "komplex_global.h"
|
|
||||||
#include "qwallet.h"
|
|
||||||
|
|
||||||
struct UserCredentials
|
|
||||||
{
|
|
||||||
QByteArray username;
|
|
||||||
QByteArray sessionToken;
|
|
||||||
QDateTime expiry;
|
|
||||||
|
|
||||||
UserCredentials &operator = (const UserCredentials &other)
|
|
||||||
{
|
|
||||||
username = other.username;
|
|
||||||
sessionToken = other.sessionToken;
|
|
||||||
expiry = other.expiry;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isValid()
|
|
||||||
{
|
|
||||||
return !username.isEmpty() && username.isValidUtf8() &&
|
|
||||||
!sessionToken.isEmpty() && sessionToken.isValidUtf8();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Q_DECLARE_METATYPE(UserCredentials)
|
|
||||||
|
|
||||||
class KOMPLEX_EXPORT UserServices : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
static auto instance() -> QWeakPointer<UserServices>;
|
|
||||||
static auto userCredentials() -> const UserCredentials &;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
auto login(const QString &username, const QByteArray &password) -> QFuture<UserCredentials>;
|
|
||||||
|
|
||||||
auto errorString() const -> const QString &;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
auto readPassword(const QString &username) -> QFuture<QByteArray>;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
auto readToken(const QString &username) -> QFuture<UserCredentials>;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
auto defaultUsername() -> QFuture<QString>;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
auto loginComplete() -> void;
|
|
||||||
auto loginFailed() -> void;
|
|
||||||
auto userCredentialsChanged() -> void;
|
|
||||||
auto errorStringChanged() -> void;
|
|
||||||
|
|
||||||
private:
|
|
||||||
inline static UserServices *s_instance = nullptr;
|
|
||||||
inline static QSharedPointer<UserServices> s_pointer;
|
|
||||||
|
|
||||||
explicit UserServices(QObject *parent);
|
|
||||||
~UserServices();
|
|
||||||
|
|
||||||
auto setUserCredentials(const UserCredentials &credentials) -> void;
|
|
||||||
auto setErrorString(const QString &errorString) -> void;
|
|
||||||
auto savePassword(const QString &username, const QByteArray &password) -> void;
|
|
||||||
auto saveToken(const QString &username, const QByteArray &token, const QDateTime &expiry) -> void;
|
|
||||||
auto saveDefaultUsername(const QString &username) -> void;
|
|
||||||
|
|
||||||
QWallet *m_wallet = nullptr;
|
|
||||||
QString m_errorString;
|
|
||||||
inline static UserCredentials s_userCredentials;
|
|
||||||
|
|
||||||
inline const static char PART_SEPARATOR = static_cast<char>('\x1f');
|
|
||||||
|
|
||||||
Q_PROPERTY(UserCredentials userCredentials READ userCredentials NOTIFY userCredentialsChanged FINAL)
|
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
|
||||||
};
|
|
||||||
Q_DECLARE_METATYPE(UserServices)
|
|
||||||
@@ -1,21 +1,3 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef VIDEOCACHE_H
|
#ifndef VIDEOCACHE_H
|
||||||
#define VIDEOCACHE_H
|
#define VIDEOCACHE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,914 +0,0 @@
|
|||||||
#include "downloadmanager.h"
|
|
||||||
#include "common/coreservices.h"
|
|
||||||
#include "common/exceptions.h"
|
|
||||||
#include "common/shaderpack.h"
|
|
||||||
|
|
||||||
DownloadManager::DownloadManager(QObject *parent)
|
|
||||||
: QObject{parent}
|
|
||||||
{
|
|
||||||
m_compiler = new PackCompiler(this);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
m_compiler,
|
|
||||||
&PackCompiler::progressChanged,
|
|
||||||
this,
|
|
||||||
&DownloadManager::compileProgressChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
m_compiler,
|
|
||||||
&PackCompiler::currentStepChanged,
|
|
||||||
this,
|
|
||||||
&DownloadManager::compileStepsCompletedChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
m_compiler,
|
|
||||||
&PackCompiler::totalStepsChanged,
|
|
||||||
this,
|
|
||||||
&DownloadManager::compileStepsChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
&m_moveProcess,
|
|
||||||
&QProcess::readyReadStandardOutput,
|
|
||||||
this,
|
|
||||||
[this]()
|
|
||||||
{
|
|
||||||
QByteArray processData = m_moveProcess.readAllStandardOutput();
|
|
||||||
|
|
||||||
if(!processData.isValidUtf8())
|
|
||||||
{
|
|
||||||
qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
&m_moveProcess,
|
|
||||||
&QProcess::readyReadStandardError,
|
|
||||||
this,
|
|
||||||
[this]()
|
|
||||||
{
|
|
||||||
QByteArray processData = m_moveProcess.readAllStandardError();
|
|
||||||
|
|
||||||
if(!processData.isValidUtf8())
|
|
||||||
{
|
|
||||||
qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [1] Download image from endpoint
|
|
||||||
* [2] Apply generic single-media template, with an image source
|
|
||||||
* [3] Optionally ask user if they would like to apply manipulative shader
|
|
||||||
* [4] Install locally
|
|
||||||
*/
|
|
||||||
auto DownloadManager::downloadImage(const QString &author, const QString &authorId, const QString &description, const QUrl &url) -> void
|
|
||||||
{
|
|
||||||
QNetworkRequest request(url);
|
|
||||||
QString requestUrl = request.url().toString();
|
|
||||||
QString id = QUuid::createUuidV7().toString(QUuid::WithoutBraces);
|
|
||||||
|
|
||||||
setState(Downloading);
|
|
||||||
|
|
||||||
//QFuture<QUrl> 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
|
|
||||||
{
|
|
||||||
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()));
|
|
||||||
metadata.setId(id);
|
|
||||||
|
|
||||||
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 file_exception(QStringLiteral("Could not create directory").toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
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 file_exception(packFile.errorString().toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray data = metadata.json().toJson(QJsonDocument::Indented);
|
|
||||||
|
|
||||||
if(packFile.write(data) != data.length())
|
|
||||||
{
|
|
||||||
setError(QStringLiteral("File Error"), packFile.errorString());
|
|
||||||
throw file_exception(packFile.errorString().toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
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 std::filesystem::filesystem_error &e)
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Network Exception %1").arg(QString::number(e.code().value())), e.what());
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this] (const std::logic_error &e)
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Logic Exception %1"), e.what());
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this] (const std::exception &e)
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Logic Exception %1"), e.what());
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this] ()
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Unknown Exception"), QString());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::downloadVideo(const QString &author, const QString &authorId, const QUrl &url) -> void
|
|
||||||
{
|
|
||||||
QNetworkRequest request(url);
|
|
||||||
QString id = QUuid::createUuidV7().toString(QUuid::WithoutBraces);
|
|
||||||
|
|
||||||
setState(Downloading);
|
|
||||||
|
|
||||||
if(m_downloadFuture.isRunning())
|
|
||||||
{
|
|
||||||
m_downloadFuture.cancelChain();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_downloadFuture = download(request, id, Get);
|
|
||||||
|
|
||||||
m_downloadFuture
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this, author, id](QUrl result) -> QUrl
|
|
||||||
{
|
|
||||||
setState(Installing);
|
|
||||||
|
|
||||||
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()));
|
|
||||||
metadata.setId(id);
|
|
||||||
|
|
||||||
QUrl packUri
|
|
||||||
(
|
|
||||||
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 file_exception(packFile.errorString().toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray data = metadata.json().toJson(QJsonDocument::Compact);
|
|
||||||
|
|
||||||
if(packFile.write(data) != data.length())
|
|
||||||
{
|
|
||||||
setError(QStringLiteral("File Error"), packFile.errorString());
|
|
||||||
throw file_exception(packFile.errorString().toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
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 std::filesystem::filesystem_error &e)
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Network Exception %1").arg(QString::number(e.code().value())), e.what());
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this] (const std::logic_error &e)
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Logic Exception %1"), e.what());
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this] (const std::exception &e)
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Logic Exception %1"), e.what());
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this] ()
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Unknown Exception"), QString());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::downloadPack(const QString &id) -> void
|
|
||||||
{
|
|
||||||
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());
|
|
||||||
QString tempFile(QString("%1.tar.gz").arg(id));
|
|
||||||
setState(Downloading);
|
|
||||||
|
|
||||||
QFuture<QUrl> downloadUri = download(request, id, Post, tempFile);
|
|
||||||
|
|
||||||
downloadUri
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this](QUrl result) -> QUrl
|
|
||||||
{
|
|
||||||
setState(Compiling);
|
|
||||||
return m_compiler->build(result);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this](QUrl result) -> QUrl
|
|
||||||
{
|
|
||||||
return install(result);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this](QUrl result)
|
|
||||||
{
|
|
||||||
setLastInstalledFile(result.toLocalFile());
|
|
||||||
setState(Complete);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onCanceled
|
|
||||||
(
|
|
||||||
[this, tempFile]()
|
|
||||||
{
|
|
||||||
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this, tempFile] (const std::filesystem::filesystem_error &e)
|
|
||||||
{
|
|
||||||
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Network Exception %1").arg(QString::number(e.code().value())), e.what());
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this, tempFile] (const shader::logic_error &e)
|
|
||||||
{
|
|
||||||
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
|
||||||
reset();
|
|
||||||
setError(e.what(), QString::fromStdString(e.details));
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this, tempFile] (const std::exception &e)
|
|
||||||
{
|
|
||||||
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Exception %1"), e.what());
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this, tempFile] ()
|
|
||||||
{
|
|
||||||
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
|
||||||
reset();
|
|
||||||
setError(QStringLiteral("Unknown Exception"), QString());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::reset() -> void
|
|
||||||
{
|
|
||||||
setError(QString(), QString());
|
|
||||||
setState(Idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::compileProgress() -> qreal
|
|
||||||
{
|
|
||||||
if(m_compiler == nullptr)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_compiler->progress();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::compileSteps() -> qint64
|
|
||||||
{
|
|
||||||
if(m_compiler == nullptr)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_compiler->totalSteps();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::compileStepsCompleted() -> qint64
|
|
||||||
{
|
|
||||||
if(nullptr == m_compiler)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_compiler->currentStep();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::setError(const QString &title, const QString &message) -> void
|
|
||||||
{
|
|
||||||
if(title == m_errorTitle && message == m_errorMessage)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_errorMessage = std::move(message);
|
|
||||||
m_errorTitle = std::move(title);
|
|
||||||
Q_EMIT errorChanged();
|
|
||||||
|
|
||||||
setState(Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownloadManager::setCompilerOutput(const QString &compilerOutput)
|
|
||||||
{
|
|
||||||
if (m_compilerOutput == compilerOutput)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_compilerOutput = compilerOutput;
|
|
||||||
emit compilerOutputChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::setState(State state) -> void
|
|
||||||
{
|
|
||||||
if(state == m_state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
|
||||||
Q_EMIT stateChanged();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::setDownloadProgress(qreal progress) -> void
|
|
||||||
{
|
|
||||||
if(qFuzzyCompare(progress, m_downloadProgress))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_downloadProgress = progress;
|
|
||||||
Q_EMIT downloadProgressChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::install(const QUrl &uri) noexcept(false) -> QUrl
|
|
||||||
{
|
|
||||||
validateUri(uri);
|
|
||||||
|
|
||||||
QDir tempDirectory(uri.toLocalFile());
|
|
||||||
|
|
||||||
QUrl installLocation = QStringLiteral("file://%1/.local/share/komplex/packs/%2").arg
|
|
||||||
(
|
|
||||||
QStandardPaths::writableLocation(QStandardPaths::HomeLocation),
|
|
||||||
tempDirectory.dirName()
|
|
||||||
);
|
|
||||||
|
|
||||||
QDir installDirectory(installLocation.toLocalFile());
|
|
||||||
|
|
||||||
if(installDirectory.exists())
|
|
||||||
installDirectory.removeRecursively();
|
|
||||||
|
|
||||||
QStringList arguments = QStringList
|
|
||||||
{
|
|
||||||
uri.toLocalFile(),
|
|
||||||
installLocation.toLocalFile()
|
|
||||||
};
|
|
||||||
|
|
||||||
m_moveProcess.start(QStringLiteral("mv"), arguments);
|
|
||||||
|
|
||||||
if(!m_moveProcess.waitForStarted(3000))
|
|
||||||
{
|
|
||||||
qWarning() << QStringLiteral("Could not start copy process: %1").arg(m_moveProcess.readAllStandardError());
|
|
||||||
throw file_exception(QStringLiteral("Could not start install process").toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!m_moveProcess.waitForFinished())
|
|
||||||
{
|
|
||||||
qWarning() << QStringLiteral("Copy process took longer than expected (>30s)");
|
|
||||||
throw file_exception(QStringLiteral("Install process took longer than expected (>30s)").toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return installLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::download(const QNetworkRequest &request, const QString &id, RequestType type, const QString &filename) -> QFuture<QUrl>
|
|
||||||
{
|
|
||||||
return QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, request, id, type, _filename = filename]() -> QUrl
|
|
||||||
{
|
|
||||||
QEventLoop loop;
|
|
||||||
QString filename = _filename;
|
|
||||||
|
|
||||||
if(filename.isEmpty() && !request.url().fileName().isEmpty())
|
|
||||||
{
|
|
||||||
filename = request.url().fileName();
|
|
||||||
}
|
|
||||||
else if(filename.isEmpty())
|
|
||||||
{
|
|
||||||
filename = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl downloadUri = QStringLiteral("file://%1/%2").arg
|
|
||||||
(
|
|
||||||
QStandardPaths::writableLocation(QStandardPaths::TempLocation),
|
|
||||||
filename
|
|
||||||
);
|
|
||||||
|
|
||||||
auto manager = CoreServices::networkAccessManager().toStrongRef();
|
|
||||||
|
|
||||||
if(manager == nullptr)
|
|
||||||
{
|
|
||||||
throw network_exception
|
|
||||||
{
|
|
||||||
QStringLiteral("Network Manager reference has already been deleted")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile downloadFile(downloadUri.toLocalFile());
|
|
||||||
|
|
||||||
if(downloadFile.exists() && !downloadFile.remove())
|
|
||||||
{
|
|
||||||
throw file_exception(downloadFile.errorString().toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkReply *reply = nullptr;
|
|
||||||
|
|
||||||
switch(type)
|
|
||||||
{
|
|
||||||
case Post:
|
|
||||||
reply = manager->post(request, nullptr);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case Get:
|
|
||||||
reply = manager->get(request, nullptr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
reply,
|
|
||||||
&QNetworkReply::errorOccurred,
|
|
||||||
&loop,
|
|
||||||
[&loop](QNetworkReply::NetworkError error) -> void
|
|
||||||
{
|
|
||||||
loop.quit();
|
|
||||||
|
|
||||||
throw network_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("Network Error %1").arg
|
|
||||||
(
|
|
||||||
QString::number(static_cast<qint64>(error))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
reply,
|
|
||||||
&QNetworkReply::downloadProgress,
|
|
||||||
this,
|
|
||||||
[this](qint64 bytesDownloaded, qint64 bytesTotal)
|
|
||||||
{
|
|
||||||
setDownloadSize(bytesTotal);
|
|
||||||
setDownloadedBytes(bytesDownloaded);
|
|
||||||
setDownloadProgress(static_cast<qreal>(bytesDownloaded) / bytesTotal);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
reply,
|
|
||||||
&QNetworkReply::readyRead,
|
|
||||||
this,
|
|
||||||
[this, downloadUri]()
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&m_fileMutex);
|
|
||||||
QFile downloadFile(downloadUri.toLocalFile());
|
|
||||||
|
|
||||||
if(!downloadFile.open(QFile::ReadWrite | QFile::Append))
|
|
||||||
{
|
|
||||||
throw file_exception(QStringLiteral("Could not open temp file location").toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
|
||||||
|
|
||||||
if(reply == nullptr)
|
|
||||||
{
|
|
||||||
throw std::system_error
|
|
||||||
{
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
ENOENT,
|
|
||||||
std::system_category()
|
|
||||||
),
|
|
||||||
QStringLiteral("Reply is not a qobject").toStdString()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 bytes = reply->bytesAvailable();
|
|
||||||
QByteArray data = reply->readAll();
|
|
||||||
quint64 bytesWritten = downloadFile.write(data/*bytes)*/);
|
|
||||||
|
|
||||||
downloadFile.close();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
reply,
|
|
||||||
&QNetworkReply::finished,
|
|
||||||
&loop,
|
|
||||||
&QEventLoop::quit
|
|
||||||
);
|
|
||||||
|
|
||||||
if(!reply->isFinished())
|
|
||||||
{
|
|
||||||
loop.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
manager.clear();
|
|
||||||
|
|
||||||
return downloadUri;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::validateUri(const QUrl &uri) noexcept(false) -> void
|
|
||||||
{
|
|
||||||
if(!uri.isValid() || !uri.isLocalFile())
|
|
||||||
{
|
|
||||||
throw std::filesystem::filesystem_error
|
|
||||||
(
|
|
||||||
QStringLiteral("URI %1 is not a local file uri").arg
|
|
||||||
(
|
|
||||||
uri.toString()
|
|
||||||
).toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
ENOENT,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::readShaderToyEntry(const QUrl &uri) noexcept(false) -> ShaderToyEntry
|
|
||||||
{
|
|
||||||
validateUri(uri);
|
|
||||||
|
|
||||||
QDir packDir(uri.toLocalFile());
|
|
||||||
|
|
||||||
if(!packDir.exists(QStringLiteral("pack.json")))
|
|
||||||
{
|
|
||||||
throw std::filesystem::filesystem_error
|
|
||||||
(
|
|
||||||
QStringLiteral("Pack file not found").arg
|
|
||||||
(
|
|
||||||
uri.toString()
|
|
||||||
).toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
ENOENT,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile packFile(packDir.absoluteFilePath(QStringLiteral("pack.json")));
|
|
||||||
|
|
||||||
if(!packFile.open(QFile::ReadOnly))
|
|
||||||
{
|
|
||||||
throw std::filesystem::filesystem_error
|
|
||||||
(
|
|
||||||
QStringLiteral("Could not open pack file").arg
|
|
||||||
(
|
|
||||||
uri.toString()
|
|
||||||
).toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
errno,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray data = packFile.readAll();
|
|
||||||
QJsonParseError jsonError;
|
|
||||||
|
|
||||||
QJsonDocument document = QJsonDocument::fromJson(data, &jsonError);
|
|
||||||
|
|
||||||
if(jsonError.error != QJsonParseError::NoError)
|
|
||||||
{
|
|
||||||
throw std::filesystem::filesystem_error
|
|
||||||
(
|
|
||||||
QStringLiteral("URI %1 is not a local file uri").arg
|
|
||||||
(
|
|
||||||
uri.toString()
|
|
||||||
).toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
EIO,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject documentObject = document.object();
|
|
||||||
QJsonObject rootObject = documentObject[QStringLiteral("Shader")].toObject();
|
|
||||||
QJsonObject infoObject = rootObject[QStringLiteral("info")].toObject();
|
|
||||||
QJsonArray tagsArray = infoObject[QStringLiteral("tags")].toArray();
|
|
||||||
|
|
||||||
QStringList tags;
|
|
||||||
|
|
||||||
for(const QJsonValue &tag : std::as_const(tagsArray))
|
|
||||||
tags += tag.toString();
|
|
||||||
|
|
||||||
ShaderToyEntry entry;
|
|
||||||
|
|
||||||
entry.metadata = ShaderToyMetadata
|
|
||||||
{
|
|
||||||
QDateTime::fromSecsSinceEpoch(infoObject[QStringLiteral("date")].toInt()),
|
|
||||||
infoObject[QStringLiteral("description")].toString(),
|
|
||||||
static_cast<quint64>(infoObject[QStringLiteral("flags")].toInt()),
|
|
||||||
static_cast<bool>(infoObject[QStringLiteral("hasLiked")].toInt()),
|
|
||||||
infoObject[QStringLiteral("id")].toString(),
|
|
||||||
static_cast<quint64>(infoObject[QStringLiteral("likes")].toInt()),
|
|
||||||
infoObject[QStringLiteral("name")].toString(),
|
|
||||||
static_cast<quint64>(infoObject[QStringLiteral("published")].toInt()),
|
|
||||||
tags,
|
|
||||||
static_cast<bool>(infoObject[QStringLiteral("usePreview")].toInt()),
|
|
||||||
infoObject[QStringLiteral("username")].toString(),
|
|
||||||
rootObject[QStringLiteral("ver")].toString(),
|
|
||||||
static_cast<quint64>(infoObject[QStringLiteral("views")].toInt())
|
|
||||||
};
|
|
||||||
|
|
||||||
QJsonArray ShaderToyRenderPassArray = rootObject[QStringLiteral("renderpass")].toArray();
|
|
||||||
|
|
||||||
for(const QJsonValue &ShaderToyRenderPassValue : std::as_const(ShaderToyRenderPassArray))
|
|
||||||
{
|
|
||||||
QJsonArray inputArray = ShaderToyRenderPassValue[QStringLiteral("inputs")].toArray();
|
|
||||||
QJsonArray outputArray = ShaderToyRenderPassValue[QStringLiteral("outputs")].toArray();
|
|
||||||
QList<ShaderToyRenderInput> inputs;
|
|
||||||
QList<ShaderToyRenderOutput> outputs;
|
|
||||||
|
|
||||||
for(const QJsonValue &inputValue : std::as_const(inputArray))
|
|
||||||
{
|
|
||||||
QJsonObject samplerObject = inputValue[QStringLiteral("sampler")].toObject();
|
|
||||||
inputs.append
|
|
||||||
(
|
|
||||||
ShaderToyRenderInput
|
|
||||||
{
|
|
||||||
static_cast<quint8>(inputValue[QStringLiteral("channel")].toInt()),
|
|
||||||
inputValue[QStringLiteral("ctype")].toString(),
|
|
||||||
samplerObject[QStringLiteral("filter")].toString(),
|
|
||||||
static_cast<quint64>(inputValue[QStringLiteral("id")].toInt()),
|
|
||||||
samplerObject[QStringLiteral("internal")].toString(),
|
|
||||||
static_cast<bool>(inputValue[QStringLiteral("published")].toInt()),
|
|
||||||
inputValue[QStringLiteral("src")].toString(),
|
|
||||||
samplerObject[QStringLiteral("srgb")].toBool(),
|
|
||||||
samplerObject[QStringLiteral("verticalFlip")].toBool(),
|
|
||||||
samplerObject[QStringLiteral("wrap")].toString()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(const QJsonValue &outputValue : std::as_const(outputArray))
|
|
||||||
{
|
|
||||||
outputs.append
|
|
||||||
(
|
|
||||||
ShaderToyRenderOutput
|
|
||||||
{
|
|
||||||
static_cast<quint8>(outputValue[QStringLiteral("channel")].toInt()),
|
|
||||||
static_cast<quint64>(outputValue[QStringLiteral("id")].toInt())
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.renderPasses.append
|
|
||||||
(
|
|
||||||
ShaderToyRenderPass
|
|
||||||
{
|
|
||||||
ShaderToyRenderPassValue[QStringLiteral("code")].toVariant().toByteArray(),
|
|
||||||
ShaderToyRenderPassValue[QStringLiteral("description")].toString(),
|
|
||||||
inputs,
|
|
||||||
ShaderToyRenderPassValue[QStringLiteral("name")].toString(),
|
|
||||||
outputs,
|
|
||||||
ShaderToyRenderPassValue[QStringLiteral("type")].toString()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::move(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::lastInstalledFile() const -> const QString &
|
|
||||||
{
|
|
||||||
return m_lastInstalledFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::setLastInstalledFile(const QString &lastInstalledFile) -> void
|
|
||||||
{
|
|
||||||
if (m_lastInstalledFile == lastInstalledFile)
|
|
||||||
return;
|
|
||||||
m_lastInstalledFile = lastInstalledFile;
|
|
||||||
emit lastInstalledFileChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::setDownloadedBytes(qint64 downloadedBytes) -> void
|
|
||||||
{
|
|
||||||
if (m_downloadedBytes == downloadedBytes)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_downloadedBytes = downloadedBytes;
|
|
||||||
emit downloadedBytesChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto DownloadManager::setDownloadSize(qint64 downloadSize) -> void
|
|
||||||
{
|
|
||||||
if (m_downloadSize == downloadSize)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_downloadSize = downloadSize;
|
|
||||||
emit downloadSizeChanged();
|
|
||||||
}
|
|
||||||
@@ -1,185 +0,0 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef DOWNLOADMANAGER_H
|
|
||||||
#define DOWNLOADMANAGER_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QUuid>
|
|
||||||
#include <QQmlEngine>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <QUuid>
|
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "common/komplex_global.h"
|
|
||||||
#include "common/shadertoymetadata.h"
|
|
||||||
#include "common/shaderpack.h"
|
|
||||||
#include "packcompiler.h"
|
|
||||||
|
|
||||||
class KOMPLEX_EXPORT DownloadManager : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
QML_ELEMENT
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum State
|
|
||||||
{
|
|
||||||
Idle,
|
|
||||||
Downloading,
|
|
||||||
Compiling,
|
|
||||||
Installing,
|
|
||||||
Complete,
|
|
||||||
Error
|
|
||||||
};
|
|
||||||
Q_ENUM(State)
|
|
||||||
|
|
||||||
enum RequestType
|
|
||||||
{
|
|
||||||
Get,
|
|
||||||
Post
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit DownloadManager(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief downloadImage
|
|
||||||
* Downloads the image to tmp from the given url and generates a pack
|
|
||||||
* out of it
|
|
||||||
* @param url
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE auto downloadImage
|
|
||||||
(
|
|
||||||
const QString &author,
|
|
||||||
const QString &authorId,
|
|
||||||
const QString &description,
|
|
||||||
const QUrl &url
|
|
||||||
) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief downloadVideo
|
|
||||||
* Downloads the video to tmp from the given url and generates a pack
|
|
||||||
* out of it
|
|
||||||
* @param author
|
|
||||||
* @param authorId
|
|
||||||
* @param description
|
|
||||||
* @param url
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE auto downloadVideo
|
|
||||||
(
|
|
||||||
const QString &author,
|
|
||||||
const QString &authorId,
|
|
||||||
const QUrl &url
|
|
||||||
) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief downloadPack
|
|
||||||
* Attempts to download, compile and install the wallpaper
|
|
||||||
* pack from the komplex endpoint.
|
|
||||||
* @param id
|
|
||||||
* @return File info of the installed pack
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE auto downloadPack(const QString &id) -> void;
|
|
||||||
|
|
||||||
auto compilerOutput() const -> const QString & { return m_compilerOutput; }
|
|
||||||
auto errorTitle() const -> const QString & { return m_errorTitle; }
|
|
||||||
auto errorMessage() const -> const QString & { return m_errorMessage; }
|
|
||||||
auto state() const -> State { return m_state; }
|
|
||||||
Q_INVOKABLE auto reset() -> void;
|
|
||||||
auto downloadProgress() -> qreal { return m_downloadProgress; }
|
|
||||||
auto compileProgress() -> qreal;
|
|
||||||
auto compileSteps() -> qint64;
|
|
||||||
auto compileStepsCompleted() -> qint64;
|
|
||||||
|
|
||||||
auto downloadSize() const -> qint64 { return m_downloadSize; }
|
|
||||||
auto setDownloadSize(qint64 downloadSize) -> void;
|
|
||||||
|
|
||||||
auto downloadedBytes() const -> qint64 { return m_downloadedBytes; }
|
|
||||||
auto setDownloadedBytes(qint64 downloadedBytes) -> void;
|
|
||||||
|
|
||||||
auto lastInstalledFile() const -> const QString &;
|
|
||||||
auto setLastInstalledFile(const QString &lastInstalledFile) -> void;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
auto setError(const QString &title, const QString &message) -> void;
|
|
||||||
auto setCompilerOutput(const QString &compilerOutput) -> void;
|
|
||||||
auto setState(State state) -> void;
|
|
||||||
auto setDownloadProgress(qreal progress) -> void;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
auto compilerOutputChanged() -> void;
|
|
||||||
auto errorChanged() -> void;
|
|
||||||
auto stateChanged() -> void;
|
|
||||||
auto downloadProgressChanged() -> void;
|
|
||||||
auto compileProgressChanged() -> void;
|
|
||||||
auto downloadComplete(const QString &uri) -> void;
|
|
||||||
auto downloadSizeChanged() -> void;
|
|
||||||
auto downloadedBytesChanged() -> void;
|
|
||||||
auto compileStepsChanged() -> void;
|
|
||||||
auto compileStepsCompletedChanged() -> void;
|
|
||||||
|
|
||||||
auto lastInstalledFileChanged() -> void;
|
|
||||||
|
|
||||||
private:
|
|
||||||
auto compile(const QUrl &uri) noexcept(false) -> QUrl;
|
|
||||||
auto install(const QUrl &uri) noexcept(false) -> QUrl;
|
|
||||||
auto download(const QNetworkRequest &request, const QString &id, RequestType type = Get, const QString &filename = QString()) -> QFuture<QUrl>;
|
|
||||||
auto readShaderToyEntry(const QUrl &uri) noexcept(false) -> ShaderToyEntry;
|
|
||||||
auto validateUri(const QUrl &uri) noexcept(false) -> void;
|
|
||||||
|
|
||||||
QString m_lastInstalledFile;
|
|
||||||
|
|
||||||
QString m_compilerOutput;
|
|
||||||
QString m_errorTitle;
|
|
||||||
QString m_errorMessage;
|
|
||||||
|
|
||||||
qreal m_downloadProgress = 0;
|
|
||||||
qint64 m_downloadSize = 0;
|
|
||||||
qint64 m_downloadedBytes = 0;
|
|
||||||
qreal m_compileProgress = 0;
|
|
||||||
State m_state;
|
|
||||||
|
|
||||||
QMutex m_downloadMutex;
|
|
||||||
QMutex m_fileMutex;
|
|
||||||
|
|
||||||
PackCompiler *m_compiler = nullptr;
|
|
||||||
|
|
||||||
QProcess m_moveProcess;
|
|
||||||
|
|
||||||
QFuture<QUrl> m_downloadFuture;
|
|
||||||
|
|
||||||
Q_PROPERTY(QString compilerOutput READ compilerOutput WRITE setCompilerOutput NOTIFY compilerOutputChanged FINAL)
|
|
||||||
Q_PROPERTY(QString errorTitle READ errorTitle NOTIFY errorChanged FINAL)
|
|
||||||
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorChanged FINAL)
|
|
||||||
Q_PROPERTY(qreal downloadProgress READ downloadProgress NOTIFY downloadProgressChanged FINAL)
|
|
||||||
Q_PROPERTY(qreal compileProgress READ compileProgress NOTIFY compileProgressChanged FINAL)
|
|
||||||
Q_PROPERTY(State state READ state NOTIFY stateChanged FINAL)
|
|
||||||
Q_PROPERTY(qint64 downloadSize READ downloadSize WRITE setDownloadSize NOTIFY downloadSizeChanged FINAL)
|
|
||||||
Q_PROPERTY(qint64 downloadedBytes READ downloadedBytes WRITE setDownloadedBytes NOTIFY downloadedBytesChanged FINAL)
|
|
||||||
Q_PROPERTY(qint64 compileSteps READ compileSteps NOTIFY compileStepsChanged FINAL)
|
|
||||||
Q_PROPERTY(qint64 compileStepsCompleted READ compileStepsCompleted NOTIFY compileStepsCompletedChanged FINAL)
|
|
||||||
Q_PROPERTY(QString lastInstalledFile READ lastInstalledFile WRITE setLastInstalledFile NOTIFY lastInstalledFileChanged FINAL)
|
|
||||||
};
|
|
||||||
Q_DECLARE_METATYPE(DownloadManager)
|
|
||||||
|
|
||||||
#endif // DOWNLOADMANAGER_H
|
|
||||||
@@ -2,72 +2,45 @@
|
|||||||
|
|
||||||
FeaturedImagesModel::FeaturedImagesModel(QObject *parent) : QAbstractListModel{parent}
|
FeaturedImagesModel::FeaturedImagesModel(QObject *parent) : QAbstractListModel{parent}
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
m_paginator = new FeaturedImagesPaginator(this);
|
m_paginator = new FeaturedImagesPaginator(this);
|
||||||
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
||||||
|
|
||||||
QObject::connect
|
QObject::connect(
|
||||||
(
|
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::resultsPerPageChanged,
|
&PaginationNotifier::resultsPerPageChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedImagesModel::resultsPerPageChanged
|
&FeaturedImagesModel::resultsPerPageChanged
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect
|
QObject::connect(
|
||||||
(
|
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::totalResultsChanged,
|
&PaginationNotifier::totalResultsChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedImagesModel::totalResultsChanged
|
&FeaturedImagesModel::totalResultsChanged
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect
|
QObject::connect(
|
||||||
(
|
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::totalPagesChanged,
|
&PaginationNotifier::totalPagesChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedImagesModel::totalPagesChanged
|
&FeaturedImagesModel::totalPagesChanged
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect
|
QObject::connect(
|
||||||
(
|
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::pageChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedImagesModel::pageChanged
|
&FeaturedImagesModel::pageChanged
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect
|
QObject::connect(
|
||||||
(
|
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedImagesModel::resetDataModel
|
&FeaturedImagesModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&FeaturedImagesModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&FeaturedImagesModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
FeaturedImagesModel::~FeaturedImagesModel()
|
|
||||||
{
|
|
||||||
if(m_paginator)
|
|
||||||
{
|
|
||||||
delete m_paginator;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::rowCount(const QModelIndex &) const -> int
|
auto FeaturedImagesModel::rowCount(const QModelIndex &) const -> int
|
||||||
@@ -82,12 +55,12 @@ auto FeaturedImagesModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto FeaturedImagesModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto FeaturedImagesModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(!boundaryCheck(index.row()))
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageCache dataPoint = m_paginator->at(index.row());
|
ImageCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -109,36 +82,28 @@ auto FeaturedImagesModel::data(const QModelIndex &index, int role) const -> QVar
|
|||||||
data = dataPoint.altText;
|
data = dataPoint.altText;
|
||||||
break;
|
break;
|
||||||
case ThumbnailRole:
|
case ThumbnailRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("thumbnail"));
|
data = dataPoint.sources.value(QString::fromUtf8("tiny"));
|
||||||
break;
|
|
||||||
case LargeThumbnailRole:
|
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("largeThumbnail"));
|
|
||||||
break;
|
break;
|
||||||
case PortraitUrlRole:
|
case PortraitUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("portrait"));
|
data = dataPoint.sources.value(QString::fromUtf8("portrait"));
|
||||||
break;
|
break;
|
||||||
case PortraitSizeRole:
|
case LandscapeUrlRole:
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("portrait"));
|
data = dataPoint.sources.value(QString::fromUtf8("landscape"));
|
||||||
break;
|
break;
|
||||||
case ScreenUrlRole:
|
case SmallUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("screen"));
|
data = dataPoint.sources.value(QString::fromUtf8("small"));
|
||||||
break;
|
|
||||||
case ScreenSizeRole:
|
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("screen"));
|
|
||||||
break;
|
break;
|
||||||
case OriginalUrlRole:
|
case OriginalUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("original"));
|
data = dataPoint.sources.value(QString::fromUtf8("original"));
|
||||||
break;
|
break;
|
||||||
case LandscapeUrlRole:
|
case MediumUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("landscape"));
|
data = dataPoint.sources.value(QString::fromUtf8("medium"));
|
||||||
break;
|
break;
|
||||||
case LandscapeSizeRole:
|
case LargeUrlRole:
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("landscape"));
|
data = dataPoint.sources.value(QString::fromUtf8("large"));
|
||||||
break;
|
break;
|
||||||
case BackgroundPortraitRole:
|
case ExtraLargeUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("backgroundPortrait"));
|
data = dataPoint.sources.value(QString::fromUtf8("large2x"));
|
||||||
case BackgroundLandscapeRole:
|
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("backgroundLandscape"));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,12 +114,10 @@ auto FeaturedImagesModel::index(int row, int column, const QModelIndex &parent)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(!boundaryCheck(row))
|
if(row < 0 || row >= m_data.count())
|
||||||
{
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::columnCount(const QModelIndex &) const -> int
|
auto FeaturedImagesModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -179,19 +142,13 @@ auto FeaturedImagesModel::state() const -> FeaturedImagesModel::State
|
|||||||
|
|
||||||
auto FeaturedImagesModel::setState(State state) -> void
|
auto FeaturedImagesModel::setState(State state) -> void
|
||||||
{
|
{
|
||||||
QFuture<void> aether = QtConcurrent::run
|
if (m_state == state)
|
||||||
(
|
{
|
||||||
[this, state]
|
return;
|
||||||
{
|
}
|
||||||
if (m_state == state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
m_state = state;
|
||||||
emit stateChanged();
|
emit stateChanged();
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::resetState() -> void
|
auto FeaturedImagesModel::resetState() -> void
|
||||||
@@ -201,28 +158,25 @@ auto FeaturedImagesModel::resetState() -> void
|
|||||||
|
|
||||||
auto FeaturedImagesModel::resetDataModel() -> void
|
auto FeaturedImagesModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
endInsertRows();
|
auto dataset = m_paginator->data();
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedImagesModel::onPaginatorFetching() -> void
|
for(const ImageCache& data : std::as_const(dataset))
|
||||||
{
|
|
||||||
setState(Loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedImagesModel::boundaryCheck(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
if(index < 0 || m_paginator == nullptr || index >= m_paginator->count())
|
|
||||||
{
|
{
|
||||||
return false;
|
m_data.append(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
endInsertRows();
|
||||||
|
|
||||||
|
setState(Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::roleNames() const -> QHash<int, QByteArray>
|
auto FeaturedImagesModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
@@ -260,42 +214,7 @@ auto FeaturedImagesModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
qsizetype difference = resultsPerPage - m_paginator->resultsPerPage();
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
|
|
||||||
if(difference > 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage() - difference;
|
|
||||||
|
|
||||||
beginInsertRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
m_paginator->count() - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(difference < 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage();
|
|
||||||
|
|
||||||
beginRemoveRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
firstIndex - difference
|
|
||||||
);
|
|
||||||
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,31 +228,19 @@ auto FeaturedImagesModel::totalResults() const -> qsizetype
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::nextPage() -> void
|
auto FeaturedImagesModel::nextPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::previousPage() -> void
|
auto FeaturedImagesModel::previousPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,23 +263,3 @@ auto FeaturedImagesModel::totalPages() const -> qsizetype
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedImagesModel::hasNextPage() const -> bool
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_paginator->page() < m_paginator->totalPages();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedImagesModel::hasPreviousPage() const -> bool
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_paginator->page() > 0;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/featuredimagespaginator.h"
|
#include "paginators/featuredimagespaginator.h"
|
||||||
|
|
||||||
@@ -69,21 +68,17 @@ public:
|
|||||||
AuthorUrlRole,
|
AuthorUrlRole,
|
||||||
DescriptionRole,
|
DescriptionRole,
|
||||||
ThumbnailRole,
|
ThumbnailRole,
|
||||||
LargeThumbnailRole,
|
|
||||||
OriginalUrlRole,
|
|
||||||
ScreenUrlRole,
|
|
||||||
PortraitUrlRole,
|
PortraitUrlRole,
|
||||||
LandscapeUrlRole,
|
LandscapeUrlRole,
|
||||||
ScreenSizeRole,
|
SmallUrlRole,
|
||||||
PortraitSizeRole,
|
OriginalUrlRole,
|
||||||
LandscapeSizeRole,
|
MediumUrlRole,
|
||||||
BackgroundPortraitRole,
|
LargeUrlRole,
|
||||||
BackgroundLandscapeRole
|
ExtraLargeUrlRole
|
||||||
};
|
};
|
||||||
Q_ENUM(DataRole)
|
Q_ENUM(DataRole)
|
||||||
|
|
||||||
explicit FeaturedImagesModel(QObject *parent = nullptr);
|
explicit FeaturedImagesModel(QObject *parent = nullptr);
|
||||||
~FeaturedImagesModel();
|
|
||||||
|
|
||||||
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
||||||
|
|
||||||
@@ -205,27 +200,13 @@ public:
|
|||||||
* @brief nextPage
|
* @brief nextPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
Q_INVOKABLE auto nextPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief previousPage
|
* @brief previousPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasNextPage
|
|
||||||
* Calculates if there are more pages based on the current page calculation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasNextPage() const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasPreviousPage
|
|
||||||
* If page is greater than 1, returns true
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasPreviousPage() const -> bool;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@@ -245,40 +226,18 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto resetState() -> void;
|
auto resetState() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetDataModel
|
|
||||||
* Clears the data model and creates a new one if data exists
|
|
||||||
*/
|
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief onPaginatorFetching
|
|
||||||
* Sets current state to loading. Triggered when paginator's cache controller
|
|
||||||
* needs to fetch data from the remote endpoint.
|
|
||||||
*/
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
auto resultsPerPageChanged() -> void;
|
auto resultsPerPageChanged() -> void;
|
||||||
|
|
||||||
auto pageChanged() -> void;
|
auto pageChanged() -> void;
|
||||||
auto totalResultsChanged() -> void;
|
auto totalResultsChanged() -> void;
|
||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Helper function to check the requested index boundary
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_dataRoles
|
|
||||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -305,14 +264,6 @@ private:
|
|||||||
static_cast<int>(ThumbnailRole),
|
static_cast<int>(ThumbnailRole),
|
||||||
QByteArray("thumbnail")
|
QByteArray("thumbnail")
|
||||||
},
|
},
|
||||||
{
|
|
||||||
static_cast<int>(LargeThumbnailRole),
|
|
||||||
QByteArray("largeThumbnail")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(OriginalUrlRole),
|
|
||||||
QByteArray("original")
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
static_cast<int>(PortraitUrlRole),
|
static_cast<int>(PortraitUrlRole),
|
||||||
QByteArray("portrait")
|
QByteArray("portrait")
|
||||||
@@ -322,28 +273,24 @@ private:
|
|||||||
QByteArray("landscape")
|
QByteArray("landscape")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
static_cast<int>(BackgroundPortraitRole),
|
static_cast<int>(SmallUrlRole),
|
||||||
QByteArray("backgroundPortrait")
|
QByteArray("small")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
static_cast<int>(BackgroundLandscapeRole),
|
static_cast<int>(OriginalUrlRole),
|
||||||
QByteArray("backgroundLandscape")
|
QByteArray("original")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
static_cast<int>(ScreenUrlRole),
|
static_cast<int>(MediumUrlRole),
|
||||||
QByteArray("fullScreen")
|
QByteArray("medium")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
static_cast<int>(ScreenSizeRole),
|
static_cast<int>(LargeUrlRole),
|
||||||
QByteArray("fullScreenSize")
|
QByteArray("large")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
static_cast<int>(PortraitSizeRole),
|
static_cast<int>(ExtraLargeUrlRole),
|
||||||
QByteArray("portraitSize")
|
QByteArray("extraLarge")
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(LandscapeSizeRole),
|
|
||||||
QByteArray("landscapeSize")
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
State m_state = Idle;
|
State m_state = Idle;
|
||||||
@@ -352,13 +299,13 @@ private:
|
|||||||
|
|
||||||
FeaturedImagesPaginator *m_paginator = nullptr;
|
FeaturedImagesPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<ImageCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
||||||
Q_PROPERTY(bool hasNextPage READ hasNextPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(bool hasPreviousPage READ hasPreviousPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(FeaturedImagesModel)
|
Q_DECLARE_METATYPE(FeaturedImagesModel)
|
||||||
|
|||||||
@@ -36,32 +36,10 @@ FeaturedPacksModel::FeaturedPacksModel(QObject *parent) : QAbstractListModel{par
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedPacksModel::resetDataModel
|
&FeaturedPacksModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&FeaturedPacksModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&FeaturedPacksModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
FeaturedPacksModel::~FeaturedPacksModel()
|
|
||||||
{
|
|
||||||
if(m_paginator)
|
|
||||||
{
|
|
||||||
delete m_paginator;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::rowCount(const QModelIndex &) const -> int
|
auto FeaturedPacksModel::rowCount(const QModelIndex &) const -> int
|
||||||
@@ -76,12 +54,12 @@ auto FeaturedPacksModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto FeaturedPacksModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto FeaturedPacksModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(index.row() < 0 || m_paginator == nullptr || index.row() >= m_paginator->count())
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
WallpaperCache dataPoint = m_paginator->at(index.row());
|
WallpaperCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -129,12 +107,10 @@ auto FeaturedPacksModel::index(int row, int column, const QModelIndex &parent) c
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
if(row < 0 || row >= m_data.count())
|
||||||
{
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::columnCount(const QModelIndex &) const -> int
|
auto FeaturedPacksModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -165,7 +141,7 @@ auto FeaturedPacksModel::setState(State state) -> void
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_state = state;
|
m_state = state;
|
||||||
Q_EMIT stateChanged();
|
emit stateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::resetState() -> void
|
auto FeaturedPacksModel::resetState() -> void
|
||||||
@@ -176,27 +152,20 @@ auto FeaturedPacksModel::resetState() -> void
|
|||||||
auto FeaturedPacksModel::resetDataModel() -> void
|
auto FeaturedPacksModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
endInsertRows();
|
auto dataset = m_paginator->data();
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedPacksModel::onPaginatorFetching() -> void
|
for(const WallpaperCache& data : std::as_const(dataset))
|
||||||
{
|
|
||||||
setState(Loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedPacksModel::boundaryCheck(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
if(index < 0 || m_paginator == nullptr || index >= m_paginator->count())
|
|
||||||
{
|
{
|
||||||
return false;
|
m_data.append(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::roleNames() const -> QHash<int, QByteArray>
|
auto FeaturedPacksModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
@@ -217,7 +186,7 @@ auto FeaturedPacksModel::setErrorString(const QString &errorString) -> void
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_errorString = errorString;
|
m_errorString = errorString;
|
||||||
Q_EMIT errorStringChanged();
|
emit errorStringChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::resultsPerPage() const -> qsizetype
|
auto FeaturedPacksModel::resultsPerPage() const -> qsizetype
|
||||||
@@ -234,42 +203,7 @@ auto FeaturedPacksModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
qsizetype difference = resultsPerPage - m_paginator->resultsPerPage();
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
|
|
||||||
if(difference > 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage() - difference;
|
|
||||||
|
|
||||||
beginInsertRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
m_paginator->count() - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(difference < 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage();
|
|
||||||
|
|
||||||
beginRemoveRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
firstIndex - difference
|
|
||||||
);
|
|
||||||
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,54 +217,22 @@ auto FeaturedPacksModel::totalResults() const -> qsizetype
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::nextPage() -> void
|
auto FeaturedPacksModel::nextPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::previousPage() -> void
|
auto FeaturedPacksModel::previousPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedPacksModel::hasNextPage() const -> bool
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_paginator->page() < m_paginator->totalPages();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedPacksModel::hasPreviousPage() const -> bool
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_paginator->page() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype FeaturedPacksModel::page() const
|
qsizetype FeaturedPacksModel::page() const
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/featuredpackspaginator.h"
|
#include "paginators/featuredpackspaginator.h"
|
||||||
|
|
||||||
@@ -78,7 +77,6 @@ public:
|
|||||||
Q_ENUM(DataRole)
|
Q_ENUM(DataRole)
|
||||||
|
|
||||||
explicit FeaturedPacksModel(QObject *parent = nullptr);
|
explicit FeaturedPacksModel(QObject *parent = nullptr);
|
||||||
~FeaturedPacksModel();
|
|
||||||
|
|
||||||
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
||||||
|
|
||||||
@@ -200,27 +198,13 @@ public:
|
|||||||
* @brief nextPage
|
* @brief nextPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
Q_INVOKABLE auto nextPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief previousPage
|
* @brief previousPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasNextPage
|
|
||||||
* Calculates if there are more pages based on the current page calculation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasNextPage() const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasPreviousPage
|
|
||||||
* If page is greater than 1, returns true
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasPreviousPage() const -> bool;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@@ -242,8 +226,6 @@ protected:
|
|||||||
|
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
@@ -254,18 +236,6 @@ signals:
|
|||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Helper function to check the requested index boundary
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_dataRoles
|
|
||||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -319,13 +289,13 @@ private:
|
|||||||
|
|
||||||
FeaturedPacksPaginator *m_paginator = nullptr;
|
FeaturedPacksPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<WallpaperCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
||||||
Q_PROPERTY(bool hasNextPage READ hasNextPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(bool hasPreviousPage READ hasPreviousPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(FeaturedPacksModel)
|
Q_DECLARE_METATYPE(FeaturedPacksModel)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
FeaturedVideosModel::FeaturedVideosModel(QObject *parent) : QAbstractListModel{parent}
|
FeaturedVideosModel::FeaturedVideosModel(QObject *parent) : QAbstractListModel{parent}
|
||||||
{
|
{
|
||||||
m_itemModel = new VideoItemModel(this);
|
setState(Loading);
|
||||||
|
|
||||||
m_paginator = new FeaturedVideosPaginator(this);
|
m_paginator = new FeaturedVideosPaginator(this);
|
||||||
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
||||||
@@ -38,37 +38,10 @@ FeaturedVideosModel::FeaturedVideosModel(QObject *parent) : QAbstractListModel{p
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&FeaturedVideosModel::resetDataModel
|
&FeaturedVideosModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&FeaturedVideosModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&FeaturedVideosModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
FeaturedVideosModel::~FeaturedVideosModel()
|
|
||||||
{
|
|
||||||
if(m_paginator)
|
|
||||||
{
|
|
||||||
delete m_paginator;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(m_itemModel)
|
|
||||||
{
|
|
||||||
delete m_itemModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::rowCount(const QModelIndex &) const -> int
|
auto FeaturedVideosModel::rowCount(const QModelIndex &) const -> int
|
||||||
@@ -83,12 +56,12 @@ auto FeaturedVideosModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto FeaturedVideosModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto FeaturedVideosModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(!boundaryCheck(index.row()))
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoCache dataPoint = m_paginator->at(index.row());
|
VideoCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -130,12 +103,10 @@ auto FeaturedVideosModel::index(int row, int column, const QModelIndex &parent)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(!boundaryCheck(row))
|
if(row < 0 || row >= m_data.count())
|
||||||
{
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::columnCount(const QModelIndex &) const -> int
|
auto FeaturedVideosModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -160,19 +131,13 @@ auto FeaturedVideosModel::state() const -> FeaturedVideosModel::State
|
|||||||
|
|
||||||
auto FeaturedVideosModel::setState(State state) -> void
|
auto FeaturedVideosModel::setState(State state) -> void
|
||||||
{
|
{
|
||||||
QFuture<void> aether = QtConcurrent::run
|
if (m_state == state)
|
||||||
(
|
{
|
||||||
[this, state]
|
return;
|
||||||
{
|
}
|
||||||
if (m_state == state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
m_state = state;
|
||||||
emit stateChanged();
|
emit stateChanged();
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::resetState() -> void
|
auto FeaturedVideosModel::resetState() -> void
|
||||||
@@ -182,51 +147,25 @@ auto FeaturedVideosModel::resetState() -> void
|
|||||||
|
|
||||||
auto FeaturedVideosModel::resetDataModel() -> void
|
auto FeaturedVideosModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
|
auto dataset = m_paginator->data();
|
||||||
|
|
||||||
|
for(const VideoCache& data : std::as_const(dataset))
|
||||||
|
{
|
||||||
|
m_data.append(data);
|
||||||
|
}
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedVideosModel::onPaginatorFetching() -> void
|
setState(Idle);
|
||||||
{
|
|
||||||
setState(Loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedVideosModel::boundaryCheck(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
if(index < 0 || m_paginator == nullptr || index >= m_paginator->count())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedVideosModel::itemModel() const -> VideoItemModel*
|
|
||||||
{
|
|
||||||
return m_itemModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedVideosModel::windowSize() const -> qsizetype
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_paginator->windowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedVideosModel::setWindowSize(qsizetype size) -> void
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
m_paginator->setWindowSize(size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::roleNames() const -> QHash<int, QByteArray>
|
auto FeaturedVideosModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
@@ -264,42 +203,7 @@ auto FeaturedVideosModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
qsizetype difference = resultsPerPage - m_paginator->resultsPerPage();
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
|
|
||||||
if(difference > 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage() - difference;
|
|
||||||
|
|
||||||
beginInsertRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
m_paginator->count() - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(difference < 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage();
|
|
||||||
|
|
||||||
beginRemoveRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
firstIndex - difference
|
|
||||||
);
|
|
||||||
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,45 +217,22 @@ auto FeaturedVideosModel::totalResults() const -> qsizetype
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::nextPage() -> void
|
auto FeaturedVideosModel::nextPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::previousPage() -> void
|
auto FeaturedVideosModel::previousPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::setItem(qint64 index) -> bool
|
|
||||||
{
|
|
||||||
if(!boundaryCheck(index))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_itemModel->setDataEntry(m_paginator->at(index));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype FeaturedVideosModel::page() const
|
qsizetype FeaturedVideosModel::page() const
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
@@ -371,23 +252,3 @@ auto FeaturedVideosModel::totalPages() const -> qsizetype
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FeaturedVideosModel::hasNextPage() const -> bool
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_paginator->page() < m_paginator->totalPages();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto FeaturedVideosModel::hasPreviousPage() const -> bool
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_paginator->page() > 0;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -35,10 +35,8 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/featuredvideospaginator.h"
|
#include "paginators/featuredvideospaginator.h"
|
||||||
#include "videoitemmodel.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The FeaturedVideosModel class
|
* @brief The FeaturedVideosModel class
|
||||||
@@ -77,7 +75,6 @@ public:
|
|||||||
Q_ENUM(DataRole)
|
Q_ENUM(DataRole)
|
||||||
|
|
||||||
explicit FeaturedVideosModel(QObject *parent = nullptr);
|
explicit FeaturedVideosModel(QObject *parent = nullptr);
|
||||||
~FeaturedVideosModel();
|
|
||||||
|
|
||||||
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
||||||
|
|
||||||
@@ -199,51 +196,13 @@ public:
|
|||||||
* @brief nextPage
|
* @brief nextPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
Q_INVOKABLE auto nextPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief previousPage
|
* @brief previousPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setItem
|
|
||||||
* Sets the current itemModel to the item at the specified index
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE auto setItem(qint64 index) -> bool;
|
|
||||||
|
|
||||||
VideoItemModel *itemModel() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief windowSize
|
|
||||||
* Paginator cache size
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto windowSize() const -> qsizetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setWindowSize
|
|
||||||
* Set the paginator cache size
|
|
||||||
* @param size
|
|
||||||
*/
|
|
||||||
auto setWindowSize(qsizetype size) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasNextPage
|
|
||||||
* Calculates if there are more pages based on the current page calculation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasNextPage() const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasPreviousPage
|
|
||||||
* If page is greater than 1, returns true
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasPreviousPage() const -> bool;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@@ -265,30 +224,16 @@ protected:
|
|||||||
|
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
auto resultsPerPageChanged() -> void;
|
auto resultsPerPageChanged() -> void;
|
||||||
auto windowSizeChanged() -> void;
|
|
||||||
auto pageChanged() -> void;
|
auto pageChanged() -> void;
|
||||||
auto totalResultsChanged() -> void;
|
auto totalResultsChanged() -> void;
|
||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Helper function to check the requested index boundary
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_dataRoles
|
|
||||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -333,7 +278,8 @@ private:
|
|||||||
QString m_errorString = QString();
|
QString m_errorString = QString();
|
||||||
|
|
||||||
FeaturedVideosPaginator *m_paginator = nullptr;
|
FeaturedVideosPaginator *m_paginator = nullptr;
|
||||||
VideoItemModel *m_itemModel = nullptr;
|
|
||||||
|
mutable QList<VideoCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
@@ -341,10 +287,6 @@ private:
|
|||||||
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
||||||
Q_PROPERTY(bool hasNextPage READ hasNextPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(bool hasPreviousPage READ hasPreviousPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(VideoItemModel *itemModel READ itemModel CONSTANT FINAL)
|
|
||||||
Q_PROPERTY(qsizetype windowSize READ windowSize WRITE setWindowSize NOTIFY windowSizeChanged FINAL)
|
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(FeaturedVideosModel)
|
Q_DECLARE_METATYPE(FeaturedVideosModel)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
ImageSearchModel::ImageSearchModel(QObject *parent) : QAbstractListModel{parent}
|
ImageSearchModel::ImageSearchModel(QObject *parent) : QAbstractListModel{parent}
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
m_paginator = new ImageSearchPaginator(this);
|
m_paginator = new ImageSearchPaginator(this);
|
||||||
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
||||||
|
|
||||||
@@ -35,25 +37,11 @@ ImageSearchModel::ImageSearchModel(QObject *parent) : QAbstractListModel{parent}
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&ImageSearchModel::resetDataModel
|
&ImageSearchModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&ImageSearchModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&ImageSearchModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
m_paginator,
|
m_paginator,
|
||||||
&ImageSearchPaginator::queryChanged,
|
&ImageSearchPaginator::queryChanged,
|
||||||
@@ -62,14 +50,6 @@ ImageSearchModel::ImageSearchModel(QObject *parent) : QAbstractListModel{parent}
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageSearchModel::~ImageSearchModel()
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
delete m_paginator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ImageSearchModel::rowCount(const QModelIndex &) const -> int
|
auto ImageSearchModel::rowCount(const QModelIndex &) const -> int
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
@@ -82,12 +62,12 @@ auto ImageSearchModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto ImageSearchModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto ImageSearchModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(index.row() < 0 || m_paginator == nullptr || index.row() >= m_paginator->count())
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageCache dataPoint = m_paginator->at(index.row());
|
ImageCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -109,36 +89,28 @@ auto ImageSearchModel::data(const QModelIndex &index, int role) const -> QVarian
|
|||||||
data = dataPoint.altText;
|
data = dataPoint.altText;
|
||||||
break;
|
break;
|
||||||
case ThumbnailRole:
|
case ThumbnailRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("thumbnail"));
|
data = dataPoint.sources.value(QString::fromUtf8("tiny"));
|
||||||
break;
|
|
||||||
case LargeThumbnailRole:
|
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("largeThumbnail"));
|
|
||||||
break;
|
break;
|
||||||
case PortraitUrlRole:
|
case PortraitUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("portrait"));
|
data = dataPoint.sources.value(QString::fromUtf8("portrait"));
|
||||||
break;
|
break;
|
||||||
case PortraitSizeRole:
|
case LandscapeUrlRole:
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("portrait"));
|
data = dataPoint.sources.value(QString::fromUtf8("landscape"));
|
||||||
break;
|
break;
|
||||||
case ScreenUrlRole:
|
case SmallUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("screen"));
|
data = dataPoint.sources.value(QString::fromUtf8("small"));
|
||||||
break;
|
|
||||||
case ScreenSizeRole:
|
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("screen"));
|
|
||||||
break;
|
break;
|
||||||
case OriginalUrlRole:
|
case OriginalUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("original"));
|
data = dataPoint.sources.value(QString::fromUtf8("original"));
|
||||||
break;
|
break;
|
||||||
case LandscapeUrlRole:
|
case MediumUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("landscape"));
|
data = dataPoint.sources.value(QString::fromUtf8("medium"));
|
||||||
break;
|
break;
|
||||||
case LandscapeSizeRole:
|
case LargeUrlRole:
|
||||||
data = dataPoint.sourceSizes.value(QString::fromUtf8("landscape"));
|
data = dataPoint.sources.value(QString::fromUtf8("large"));
|
||||||
break;
|
break;
|
||||||
case BackgroundPortraitRole:
|
case ExtraLargeUrlRole:
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("backgroundPortrait"));
|
data = dataPoint.sources.value(QString::fromUtf8("large2x"));
|
||||||
case BackgroundLandscapeRole:
|
|
||||||
data = dataPoint.sources.value(QString::fromUtf8("backgroundLandscape"));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,12 +121,10 @@ auto ImageSearchModel::index(int row, int column, const QModelIndex &parent) con
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
if(row < 0 || row >= m_data.count())
|
||||||
{
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator->at(row));
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::columnCount(const QModelIndex &) const -> int
|
auto ImageSearchModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -195,36 +165,33 @@ auto ImageSearchModel::resetState() -> void
|
|||||||
|
|
||||||
auto ImageSearchModel::resetDataModel() -> void
|
auto ImageSearchModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
|
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
endInsertRows();
|
auto dataset = m_paginator->data();
|
||||||
}
|
|
||||||
|
|
||||||
auto ImageSearchModel::onPaginatorFetching() -> void
|
for(const ImageCache& data : std::as_const(dataset))
|
||||||
{
|
|
||||||
setState(Loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ImageSearchModel::boundaryCheck(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
if(index < 0 || m_paginator == nullptr || index >= m_paginator->count())
|
|
||||||
{
|
{
|
||||||
return false;
|
m_data.append(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
endInsertRows();
|
||||||
|
|
||||||
|
setState(Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::hasNextPage() const -> bool
|
auto ImageSearchModel::hasNextPage() -> bool
|
||||||
{
|
{
|
||||||
return m_paginator->page() < m_paginator->totalPages();
|
return m_paginator->page() < m_paginator->totalPages();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::hasPreviousPage() const -> bool
|
auto ImageSearchModel::hasPreviousPage() -> bool
|
||||||
{
|
{
|
||||||
return m_paginator->page() > 0;
|
return m_paginator->page() > 0;
|
||||||
}
|
}
|
||||||
@@ -264,42 +231,7 @@ auto ImageSearchModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
qsizetype difference = resultsPerPage - m_paginator->resultsPerPage();
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
|
|
||||||
if(difference > 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage() - difference;
|
|
||||||
|
|
||||||
beginInsertRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
m_paginator->count() - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(difference < 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage();
|
|
||||||
|
|
||||||
beginRemoveRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
firstIndex - difference
|
|
||||||
);
|
|
||||||
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,31 +245,19 @@ auto ImageSearchModel::totalResults() const -> qsizetype
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::nextPage() -> void
|
auto ImageSearchModel::nextPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ImageSearchModel::previousPage() -> void
|
auto ImageSearchModel::previousPage() const -> void
|
||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,13 +275,7 @@ auto ImageSearchModel::setQuery(const QString &query) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> future = QtConcurrent::run
|
m_paginator->setQuery(query);
|
||||||
(
|
|
||||||
[this, query]
|
|
||||||
{
|
|
||||||
m_paginator->setQuery(query);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/imagesearchpaginator.h"
|
#include "paginators/imagesearchpaginator.h"
|
||||||
|
|
||||||
@@ -69,21 +68,17 @@ public:
|
|||||||
AuthorUrlRole,
|
AuthorUrlRole,
|
||||||
DescriptionRole,
|
DescriptionRole,
|
||||||
ThumbnailRole,
|
ThumbnailRole,
|
||||||
LargeThumbnailRole,
|
|
||||||
OriginalUrlRole,
|
|
||||||
ScreenUrlRole,
|
|
||||||
PortraitUrlRole,
|
PortraitUrlRole,
|
||||||
LandscapeUrlRole,
|
LandscapeUrlRole,
|
||||||
ScreenSizeRole,
|
SmallUrlRole,
|
||||||
PortraitSizeRole,
|
OriginalUrlRole,
|
||||||
LandscapeSizeRole,
|
MediumUrlRole,
|
||||||
BackgroundPortraitRole,
|
LargeUrlRole,
|
||||||
BackgroundLandscapeRole
|
ExtraLargeUrlRole
|
||||||
};
|
};
|
||||||
Q_ENUM(DataRole)
|
Q_ENUM(DataRole)
|
||||||
|
|
||||||
explicit ImageSearchModel(QObject *parent = nullptr);
|
explicit ImageSearchModel(QObject *parent = nullptr);
|
||||||
~ImageSearchModel();
|
|
||||||
|
|
||||||
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
||||||
|
|
||||||
@@ -205,13 +200,13 @@ public:
|
|||||||
* @brief nextPage
|
* @brief nextPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
Q_INVOKABLE auto nextPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief previousPage
|
* @brief previousPage
|
||||||
* Function for the QML frontend
|
* Function for the QML frontend
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief query
|
* @brief query
|
||||||
@@ -222,36 +217,20 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setQuery
|
* @brief setQuery
|
||||||
* Sets the current search query
|
* Sets the current
|
||||||
* @param query
|
* @param query
|
||||||
*/
|
*/
|
||||||
auto setQuery(const QString &query) -> void;
|
auto setQuery(const QString &query) -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasNextPage
|
|
||||||
* Calculates if there are more pages based on the current page calculation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasNextPage() const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasPreviousPage
|
|
||||||
* If page is greater than 1, returns true
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasPreviousPage() const -> bool;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief setErrorString
|
* @brief setErrorString
|
||||||
* Sets the error string to be displayed to the user
|
|
||||||
* @param errorString
|
* @param errorString
|
||||||
*/
|
*/
|
||||||
auto setErrorString(const QString &errorString) -> void;
|
auto setErrorString(const QString &errorString) -> void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setState
|
* @brief setState
|
||||||
* Sets the current state for QML
|
|
||||||
* @param state
|
* @param state
|
||||||
*/
|
*/
|
||||||
auto setState(State state) -> void;
|
auto setState(State state) -> void;
|
||||||
@@ -261,148 +240,86 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto resetState() -> void;
|
auto resetState() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetDataModel
|
|
||||||
* Clears the data model and creates a new one if data exists
|
|
||||||
*/
|
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
/**
|
auto hasNextPage() -> bool;
|
||||||
* @brief onPaginatorFetching
|
|
||||||
* Sets current state to loading. Triggered when paginator's cache controller
|
auto hasPreviousPage() -> bool;
|
||||||
* needs to fetch data from the remote endpoint.
|
|
||||||
*/
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
|
||||||
* @brief stateChanged
|
|
||||||
* Signaled when reported state changes
|
|
||||||
*/
|
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorStringChanged
|
|
||||||
* Signaled when reported error message changes
|
|
||||||
*/
|
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto resultsPerPageChanged() -> void;
|
auto resultsPerPageChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto pageChanged() -> void;
|
auto pageChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalResultsChanged() -> void;
|
auto totalResultsChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto queryChanged() -> void;
|
auto queryChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Helper function to check the requested index boundary
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_dataRoles
|
|
||||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
|
{
|
||||||
{
|
{
|
||||||
{
|
static_cast<int>(UuidRole),
|
||||||
static_cast<int>(UuidRole),
|
QByteArray("uuid")
|
||||||
QByteArray("uuid")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(AuthorRole),
|
||||||
static_cast<int>(AuthorRole),
|
QByteArray("author")
|
||||||
QByteArray("author")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(AuthorIdRole),
|
||||||
static_cast<int>(AuthorIdRole),
|
QByteArray("authorId")
|
||||||
QByteArray("authorId")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(AuthorUrlRole),
|
||||||
static_cast<int>(AuthorUrlRole),
|
QByteArray("authorUrl")
|
||||||
QByteArray("authorUrl")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(DescriptionRole),
|
||||||
static_cast<int>(DescriptionRole),
|
QByteArray("description")
|
||||||
QByteArray("description")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(ThumbnailRole),
|
||||||
static_cast<int>(ThumbnailRole),
|
QByteArray("thumbnail")
|
||||||
QByteArray("thumbnail")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(PortraitUrlRole),
|
||||||
static_cast<int>(LargeThumbnailRole),
|
QByteArray("portrait")
|
||||||
QByteArray("largeThumbnail")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(LandscapeUrlRole),
|
||||||
static_cast<int>(OriginalUrlRole),
|
QByteArray("landscape")
|
||||||
QByteArray("original")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(SmallUrlRole),
|
||||||
static_cast<int>(PortraitUrlRole),
|
QByteArray("small")
|
||||||
QByteArray("portrait")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(OriginalUrlRole),
|
||||||
static_cast<int>(LandscapeUrlRole),
|
QByteArray("original")
|
||||||
QByteArray("landscape")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(MediumUrlRole),
|
||||||
static_cast<int>(BackgroundPortraitRole),
|
QByteArray("medium")
|
||||||
QByteArray("backgroundPortrait")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(LargeUrlRole),
|
||||||
static_cast<int>(BackgroundLandscapeRole),
|
QByteArray("large")
|
||||||
QByteArray("backgroundLandscape")
|
},
|
||||||
},
|
{
|
||||||
{
|
static_cast<int>(ExtraLargeUrlRole),
|
||||||
static_cast<int>(ScreenUrlRole),
|
QByteArray("extraLarge")
|
||||||
QByteArray("fullScreen")
|
}
|
||||||
},
|
};
|
||||||
{
|
|
||||||
static_cast<int>(ScreenSizeRole),
|
|
||||||
QByteArray("fullScreenSize")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(PortraitSizeRole),
|
|
||||||
QByteArray("portraitSize")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(LandscapeSizeRole),
|
|
||||||
QByteArray("landscapeSize")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
State m_state = Idle;
|
State m_state = Idle;
|
||||||
|
|
||||||
QString m_errorString = QString();
|
QString m_errorString = QString();
|
||||||
|
|
||||||
ImageSearchPaginator *m_paginator = nullptr;
|
ImageSearchPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<ImageCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
|
|||||||
@@ -38,32 +38,10 @@ NewestPacksModel::NewestPacksModel(QObject *parent) : QAbstractListModel{parent}
|
|||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
notifier,
|
notifier,
|
||||||
&PaginationNotifier::pageChanged,
|
&PaginationNotifier::dataChanged,
|
||||||
this,
|
this,
|
||||||
&NewestPacksModel::resetDataModel
|
&NewestPacksModel::resetDataModel
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&NewestPacksModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&NewestPacksModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
NewestPacksModel::~NewestPacksModel()
|
|
||||||
{
|
|
||||||
if(m_paginator)
|
|
||||||
{
|
|
||||||
delete m_paginator;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NewestPacksModel::rowCount(const QModelIndex &) const -> int
|
auto NewestPacksModel::rowCount(const QModelIndex &) const -> int
|
||||||
@@ -78,12 +56,12 @@ auto NewestPacksModel::rowCount(const QModelIndex &) const -> int
|
|||||||
|
|
||||||
auto NewestPacksModel::data(const QModelIndex &index, int role) const -> QVariant
|
auto NewestPacksModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
{
|
{
|
||||||
if(index.row() < 0 || m_paginator == nullptr || index.row() >= m_paginator->count())
|
if(index.row() < 0 || m_paginator == nullptr)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
WallpaperCache dataPoint = m_paginator->at(index.row());
|
WallpaperCache dataPoint = m_data.at(index.row());
|
||||||
|
|
||||||
QVariant data;
|
QVariant data;
|
||||||
|
|
||||||
@@ -131,10 +109,10 @@ auto NewestPacksModel::index(int row, int column, const QModelIndex &parent) con
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
if(row < 0 || row >= m_data.count())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
return createIndex(row, column, &m_data[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NewestPacksModel::columnCount(const QModelIndex &) const -> int
|
auto NewestPacksModel::columnCount(const QModelIndex &) const -> int
|
||||||
@@ -159,19 +137,13 @@ auto NewestPacksModel::state() const -> NewestPacksModel::State
|
|||||||
|
|
||||||
auto NewestPacksModel::setState(State state) -> void
|
auto NewestPacksModel::setState(State state) -> void
|
||||||
{
|
{
|
||||||
QFuture<void> aether = QtConcurrent::run
|
if (m_state == state)
|
||||||
(
|
{
|
||||||
[this, state]
|
return;
|
||||||
{
|
}
|
||||||
if (m_state == state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
m_state = state;
|
||||||
emit stateChanged();
|
emit stateChanged();
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NewestPacksModel::resetState() -> void
|
auto NewestPacksModel::resetState() -> void
|
||||||
@@ -181,18 +153,23 @@ auto NewestPacksModel::resetState() -> void
|
|||||||
|
|
||||||
auto NewestPacksModel::resetDataModel() -> void
|
auto NewestPacksModel::resetDataModel() -> void
|
||||||
{
|
{
|
||||||
|
setState(Loading);
|
||||||
//invalidate previous model data
|
//invalidate previous model data
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
beginRemoveRows(QModelIndex(), 0, m_data.count());
|
||||||
|
m_data.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
//signal new data
|
//signal new data
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
||||||
endInsertRows();
|
auto dataset = m_paginator->data();
|
||||||
}
|
|
||||||
|
|
||||||
auto NewestPacksModel::onPaginatorFetching() -> void
|
for(const WallpaperCache& data : std::as_const(dataset))
|
||||||
{
|
{
|
||||||
setState(Loading);
|
m_data.append(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
endInsertRows();
|
||||||
|
setState(Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NewestPacksModel::roleNames() const -> QHash<int, QByteArray>
|
auto NewestPacksModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
@@ -230,42 +207,7 @@ auto NewestPacksModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> aether = QtConcurrent::run
|
m_paginator->setResultsPerPage(resultsPerPage);
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
qsizetype difference = resultsPerPage - m_paginator->resultsPerPage();
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
|
|
||||||
if(difference > 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage() - difference;
|
|
||||||
|
|
||||||
beginInsertRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
m_paginator->count() - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(difference < 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage();
|
|
||||||
|
|
||||||
beginRemoveRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
firstIndex - difference
|
|
||||||
);
|
|
||||||
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,13 +225,7 @@ auto NewestPacksModel::nextPage() const -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> aether = QtConcurrent::run
|
m_paginator->next();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,13 +233,7 @@ auto NewestPacksModel::previousPage() const -> void
|
|||||||
{
|
{
|
||||||
if(m_paginator != nullptr)
|
if(m_paginator != nullptr)
|
||||||
{
|
{
|
||||||
QFuture<void> aether = QtConcurrent::run
|
m_paginator->previous();
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,24 +256,3 @@ auto NewestPacksModel::totalPages() const -> qsizetype
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NewestPacksModel::hasNextPage() const -> bool
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_paginator->page() < m_paginator->totalPages();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
auto NewestPacksModel::hasPreviousPage() const -> bool
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_paginator->page() > 0;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/newestpackspaginator.h"
|
#include "paginators/newestpackspaginator.h"
|
||||||
|
|
||||||
@@ -78,7 +77,6 @@ public:
|
|||||||
Q_ENUM(DataRole)
|
Q_ENUM(DataRole)
|
||||||
|
|
||||||
explicit NewestPacksModel(QObject *parent = nullptr);
|
explicit NewestPacksModel(QObject *parent = nullptr);
|
||||||
~NewestPacksModel();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief rowCount
|
* @brief rowCount
|
||||||
@@ -215,20 +213,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE auto previousPage() const -> void;
|
Q_INVOKABLE auto previousPage() const -> void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasNextPage
|
|
||||||
* Calculates if there are more pages based on the current page calculation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasNextPage() const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasPreviousPage
|
|
||||||
* If page is greater than 1, returns true
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasPreviousPage() const -> bool;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief setErrorString
|
* @brief setErrorString
|
||||||
@@ -252,8 +236,6 @@ protected:
|
|||||||
*/
|
*/
|
||||||
auto resetDataModel() -> void;
|
auto resetDataModel() -> void;
|
||||||
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
auto stateChanged() -> void;
|
auto stateChanged() -> void;
|
||||||
auto errorStringChanged() -> void;
|
auto errorStringChanged() -> void;
|
||||||
@@ -264,18 +246,6 @@ signals:
|
|||||||
auto totalPagesChanged() -> void;
|
auto totalPagesChanged() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Helper function to check the requested index boundary
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief m_dataRoles
|
|
||||||
* Data role map that connects ImageSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -329,14 +299,14 @@ private:
|
|||||||
|
|
||||||
NewestPacksPaginator *m_paginator = nullptr;
|
NewestPacksPaginator *m_paginator = nullptr;
|
||||||
|
|
||||||
|
mutable QList<WallpaperCache> m_data;
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
||||||
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
||||||
Q_PROPERTY(bool hasNextPage READ hasNextPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(bool hasPreviousPage READ hasPreviousPage NOTIFY pageChanged FINAL)
|
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(NewestPacksModel)
|
Q_DECLARE_METATYPE(NewestPacksModel)
|
||||||
|
|
||||||
|
|||||||
@@ -1,632 +0,0 @@
|
|||||||
#include "packcompiler.h"
|
|
||||||
#include "common/exceptions.h"
|
|
||||||
|
|
||||||
PackCompiler::PackCompiler(QObject *parent)
|
|
||||||
: QObject{parent}
|
|
||||||
{
|
|
||||||
if(m_variableExpressions.isEmpty())
|
|
||||||
{
|
|
||||||
for(const QString &variable : m_updateVariables)
|
|
||||||
{
|
|
||||||
m_variableExpressions.append
|
|
||||||
(
|
|
||||||
QRegularExpression
|
|
||||||
(
|
|
||||||
QStringLiteral("\\b(?<!ubuf\\.)%1\\b").arg
|
|
||||||
(
|
|
||||||
variable
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::reset() -> void
|
|
||||||
{
|
|
||||||
setError({}, {});
|
|
||||||
setProgress(std::numeric_limits<qreal>::infinity());
|
|
||||||
setTotalSteps(0);
|
|
||||||
setCurrentStep(0);
|
|
||||||
setCompilerOutput({});
|
|
||||||
setStatus({});
|
|
||||||
setState(Idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::build(const QUrl &uri) -> QUrl
|
|
||||||
{
|
|
||||||
BuildContext *context = new BuildContext;
|
|
||||||
QUrl extractedUri = extract(uri);
|
|
||||||
|
|
||||||
validatePack(extractedUri);
|
|
||||||
context->commonData = loadCommonData(extractedUri);
|
|
||||||
processShaders(extractedUri, context);
|
|
||||||
|
|
||||||
delete context;
|
|
||||||
|
|
||||||
return extractedUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::extract(const QUrl &sourceUri) noexcept(false) -> const QUrl
|
|
||||||
{
|
|
||||||
validateUri(sourceUri);
|
|
||||||
|
|
||||||
QFileInfo info(sourceUri.toLocalFile());
|
|
||||||
|
|
||||||
QUrl outputUri
|
|
||||||
(
|
|
||||||
QStringLiteral("file:///tmp/%1").arg
|
|
||||||
(
|
|
||||||
info.baseName()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
QStringList arguments =
|
|
||||||
{
|
|
||||||
QStringLiteral("-xzf"),
|
|
||||||
sourceUri.toLocalFile(),
|
|
||||||
QStringLiteral("-C"),
|
|
||||||
outputUri.toLocalFile()
|
|
||||||
};
|
|
||||||
|
|
||||||
QDir outputDir(outputUri.toLocalFile());
|
|
||||||
|
|
||||||
if(!outputDir.exists())
|
|
||||||
{
|
|
||||||
createDirectory(outputUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
run(QStringLiteral("tar"), arguments);
|
|
||||||
|
|
||||||
QFile::remove(sourceUri.toLocalFile());
|
|
||||||
|
|
||||||
return std::move(outputUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::validatePack(const QUrl &uri) const noexcept(false) -> void
|
|
||||||
{
|
|
||||||
QDir directory(uri.toLocalFile());
|
|
||||||
|
|
||||||
if (!directory.exists(QStringLiteral("pack.json")))
|
|
||||||
{
|
|
||||||
throw shader::logic_error("Compiler Error", QStringLiteral("Invalid pack file").toStdString(), ENOEXEC);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!directory.exists(QStringLiteral("shaders")))
|
|
||||||
{
|
|
||||||
throw shader::logic_error("Compiler Error", QStringLiteral("Nothing to compile").toStdString(), ENOEXEC);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::loadCommonData(const QUrl &uri) -> QMap<QByteArray,QByteArray>
|
|
||||||
{
|
|
||||||
validateUri(uri);
|
|
||||||
|
|
||||||
QMap<QByteArray,QByteArray> commonData;
|
|
||||||
|
|
||||||
QDir packDirectory(uri.toLocalFile());
|
|
||||||
QDir shaderDirectory(packDirectory.absoluteFilePath(QStringLiteral("shaders")));
|
|
||||||
shaderDirectory.setNameFilters(m_shaderNameFilters);
|
|
||||||
shaderDirectory.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
|
||||||
|
|
||||||
const QStringList entries = shaderDirectory.entryList();
|
|
||||||
|
|
||||||
for(const QString &entry : entries)
|
|
||||||
{
|
|
||||||
if(entry.startsWith(QStringLiteral("common"), Qt::CaseInsensitive))
|
|
||||||
{
|
|
||||||
QFileInfo entryInfo(shaderDirectory.absoluteFilePath(entry));
|
|
||||||
QByteArray data = commonData.take(entryInfo.suffix().toUtf8());
|
|
||||||
data += readFile
|
|
||||||
(
|
|
||||||
QStringLiteral("file://%1").arg
|
|
||||||
(
|
|
||||||
entryInfo.absoluteFilePath()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
commonData.insert(entryInfo.suffix().toUpper().toUtf8(), data);
|
|
||||||
|
|
||||||
QFile::remove(entryInfo.absoluteFilePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(entry.toLower() == QStringLiteral("global.glsl"))
|
|
||||||
{
|
|
||||||
if(commonData.contains(QByteArray("GLOBAL")))
|
|
||||||
{
|
|
||||||
commonData.remove(QByteArray("GLOBAL"));
|
|
||||||
}
|
|
||||||
|
|
||||||
QFileInfo entryInfo(shaderDirectory.absoluteFilePath(entry));
|
|
||||||
QByteArray data = readFile
|
|
||||||
(
|
|
||||||
QStringLiteral("file://%1").arg
|
|
||||||
(
|
|
||||||
entryInfo.absoluteFilePath()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
commonData.insert(QByteArray("GLOBAL"), data);
|
|
||||||
|
|
||||||
QFile::remove(entryInfo.absoluteFilePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::move(commonData);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::processShaders(const QUrl &uri, BuildContext *context) -> void
|
|
||||||
{
|
|
||||||
validateUri(uri);
|
|
||||||
|
|
||||||
QDir packDirectory(uri.toLocalFile());
|
|
||||||
QDir shaderDirectory(packDirectory.absoluteFilePath(QStringLiteral("shaders")));
|
|
||||||
shaderDirectory.setNameFilters(m_shaderNameFilters);
|
|
||||||
shaderDirectory.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
|
||||||
|
|
||||||
const QStringList entries = shaderDirectory.entryList();
|
|
||||||
|
|
||||||
for(const QString &entry : entries)
|
|
||||||
{
|
|
||||||
QFileInfo entryInfo(shaderDirectory.absoluteFilePath(entry));
|
|
||||||
QByteArray shaderData;
|
|
||||||
QUrl entryUri = QStringLiteral("file://%1").arg
|
|
||||||
(
|
|
||||||
entryInfo.absoluteFilePath()
|
|
||||||
);
|
|
||||||
|
|
||||||
shaderData += readFile(entryUri);
|
|
||||||
|
|
||||||
QShader::Stage stage = getStageFromSuffix(entryInfo.suffix());
|
|
||||||
|
|
||||||
appendCommonData(&shaderData, entryInfo.suffix().toUtf8(), context);
|
|
||||||
replaceUniformVariables(&shaderData);
|
|
||||||
appendUniformHeader(&shaderData);
|
|
||||||
appendUniformFooter(&shaderData);
|
|
||||||
preprocess(&shaderData);
|
|
||||||
appendVersion(&shaderData);
|
|
||||||
|
|
||||||
QUrl outputUri = QStringLiteral
|
|
||||||
(
|
|
||||||
"file://%1.qsb"
|
|
||||||
).arg(entryInfo.absoluteFilePath());
|
|
||||||
|
|
||||||
QShader shader = compile(shaderData, outputUri.fileName(), stage);
|
|
||||||
save(outputUri, shader);
|
|
||||||
|
|
||||||
QFile::remove(entryUri.toLocalFile());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::preprocess(QByteArray *data) noexcept(false) -> void
|
|
||||||
{
|
|
||||||
QStringList arguments;
|
|
||||||
arguments << "-E" // Run only the preprocessor
|
|
||||||
<< "-P" // Omit #line markers
|
|
||||||
<< "-x" << "c++"
|
|
||||||
<< "-"; // Read source from stdin
|
|
||||||
|
|
||||||
QByteArray temp = run(QStringLiteral("clang"), arguments, *data);
|
|
||||||
data->clear();
|
|
||||||
data->swap(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::appendVersion(QByteArray *data) noexcept(true) -> void
|
|
||||||
{
|
|
||||||
data->push_front(m_version + QByteArray("\n\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::compile(const QByteArray &data, const QString &filename, const QShader::Stage stage) noexcept(false) -> QShader
|
|
||||||
{
|
|
||||||
QList<QShaderBaker::GeneratedShader> targets;
|
|
||||||
|
|
||||||
#ifdef HAS_VULKAN
|
|
||||||
targets.append({ QShader::SpirvShader, QShaderVersion(vulkanVersion()) });
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAS_OPENGL
|
|
||||||
targets.append({ QShader::GlslShader, QShaderVersion(openGlVersion()) });
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QShaderBaker baker;
|
|
||||||
baker.setGeneratedShaderVariants({ QShader::StandardShader });
|
|
||||||
baker.setGeneratedShaders(targets);
|
|
||||||
baker.setSourceString(data, stage, filename);
|
|
||||||
|
|
||||||
QShader shader = baker.bake();
|
|
||||||
|
|
||||||
if(!shader.isValid())
|
|
||||||
{
|
|
||||||
QUrl errorUri
|
|
||||||
(
|
|
||||||
QStringLiteral("file://tmp/_err")
|
|
||||||
);
|
|
||||||
|
|
||||||
writeFile(errorUri, data);
|
|
||||||
|
|
||||||
throw shader::logic_error
|
|
||||||
(
|
|
||||||
std::string("Compiler Error"),
|
|
||||||
baker.errorMessage().toStdString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAS_VULKAN
|
|
||||||
auto PackCompiler::vulkanVersion() const -> qint32
|
|
||||||
{
|
|
||||||
uint32_t instanceVersion = VK_API_VERSION_1_0;
|
|
||||||
auto FN_vkEnumerateInstanceVersion = PFN_vkEnumerateInstanceVersion(vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion"));
|
|
||||||
if(FN_vkEnumerateInstanceVersion)
|
|
||||||
{
|
|
||||||
FN_vkEnumerateInstanceVersion(&instanceVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t major = VK_VERSION_MAJOR(instanceVersion);
|
|
||||||
uint32_t minor = VK_VERSION_MINOR(instanceVersion);
|
|
||||||
|
|
||||||
QString versionString = QStringLiteral("%1%2%3").arg(major).arg(minor).arg(0);
|
|
||||||
return versionString.toInt();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto PackCompiler::save(const QUrl &uri, const QShader &shader) noexcept(false) -> void
|
|
||||||
{
|
|
||||||
writeFile(uri, shader.serialized());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::appendCommonData(QByteArray *data, const QByteArray &suffix, BuildContext *context) noexcept(true) -> void
|
|
||||||
{
|
|
||||||
if(context->commonData.contains(QByteArray("GLOBAL")))
|
|
||||||
{
|
|
||||||
data->push_front
|
|
||||||
(
|
|
||||||
context->commonData.value(QByteArray("GLOBAL")) + QByteArray("\n")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(context->commonData.contains(suffix.toUpper()))
|
|
||||||
{
|
|
||||||
data->push_front
|
|
||||||
(
|
|
||||||
context->commonData.value(suffix.toUpper()) + QByteArray("\n")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::appendUniformHeader(QByteArray *data) noexcept(true) -> void
|
|
||||||
{
|
|
||||||
data->push_front(m_header + QByteArray("\n\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::appendUniformFooter(QByteArray *data) noexcept(true) -> void
|
|
||||||
{
|
|
||||||
data->push_back(QByteArray("\n\n") + m_footer);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::replaceUniformVariables(QByteArray *data) noexcept(true) -> void
|
|
||||||
{
|
|
||||||
for(const QRegularExpression &expression : std::as_const(m_variableExpressions))
|
|
||||||
{
|
|
||||||
auto match = expression.match(*data);
|
|
||||||
|
|
||||||
if(match.hasMatch())
|
|
||||||
{
|
|
||||||
QByteArray replacement = QByteArray("ubuf.") + match.captured().toLocal8Bit();
|
|
||||||
data->replace(match.captured().toLocal8Bit(), replacement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::copyFile(const QUrl &sourceUri, const QUrl &destinationUri) noexcept(false) -> void
|
|
||||||
{
|
|
||||||
if(!QFile::exists(sourceUri.toLocalFile()))
|
|
||||||
{
|
|
||||||
throw file_exception(QStringLiteral("File does not exist").toStdString(), ENOENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!QFile::copy(sourceUri.toLocalFile(), destinationUri.toLocalFile()))
|
|
||||||
{
|
|
||||||
throw file_exception(QStringLiteral("Could not copy file").toStdString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::createDirectory(const QUrl &uri) -> void
|
|
||||||
{
|
|
||||||
validateUri(uri);
|
|
||||||
|
|
||||||
QStringList arguments =
|
|
||||||
{
|
|
||||||
QStringLiteral("-p"),
|
|
||||||
uri.toLocalFile()
|
|
||||||
};
|
|
||||||
|
|
||||||
run(QStringLiteral("mkdir"), arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::removeDirectory(const QUrl &uri) noexcept(false) -> void
|
|
||||||
{
|
|
||||||
QStringList arguments =
|
|
||||||
{
|
|
||||||
QStringLiteral("-rf"),
|
|
||||||
uri.toLocalFile()
|
|
||||||
};
|
|
||||||
|
|
||||||
run(QStringLiteral("rm"), arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::getStageFromSuffix(const QString &suffix) const -> QShader::Stage
|
|
||||||
{
|
|
||||||
return m_shaderStages.value(suffix.toLower(), QShader::FragmentStage);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAS_OPENGL
|
|
||||||
auto PackCompiler::openGlVersion() const -> qint32
|
|
||||||
{
|
|
||||||
qint32 glVersion = 330;
|
|
||||||
|
|
||||||
QString versionString = QString::fromUtf8(glGetString(GL_SHADING_LANGUAGE_VERSION));
|
|
||||||
QStringList parts = versionString.split(QChar(' '), Qt::SkipEmptyParts);
|
|
||||||
|
|
||||||
if(parts.count() >= 1)
|
|
||||||
{
|
|
||||||
QString version = parts.at(0);
|
|
||||||
version.remove(QChar('.'));
|
|
||||||
|
|
||||||
bool okay = true;
|
|
||||||
qint32 temp = version.toInt(&okay);
|
|
||||||
|
|
||||||
if(okay)
|
|
||||||
{
|
|
||||||
glVersion = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return glVersion;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto PackCompiler::validateUri(const QUrl &uri) const noexcept(false) -> void
|
|
||||||
{
|
|
||||||
if(!uri.isValid() || !uri.isLocalFile())
|
|
||||||
{
|
|
||||||
throw file_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("URI %1 is not a local file uri").arg
|
|
||||||
(
|
|
||||||
uri.toString()
|
|
||||||
).toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
ENOENT,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::run(const QString &command, const QStringList &arguments, const QByteArray &data) noexcept(false) -> QByteArray
|
|
||||||
{
|
|
||||||
QProcess process;
|
|
||||||
process.start(command, arguments);
|
|
||||||
|
|
||||||
if(!process.waitForStarted(3000))
|
|
||||||
{
|
|
||||||
throw process_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("Could not start process for %1").arg(command).toStdString(),
|
|
||||||
process.errorString().toStdString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(data.length() > 0)
|
|
||||||
{
|
|
||||||
process.write(data);
|
|
||||||
process.closeWriteChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!process.waitForFinished())
|
|
||||||
{
|
|
||||||
throw process_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("Process timeout for %1").arg(command).toStdString(),
|
|
||||||
process.errorString().toStdString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(process.exitCode() != 0)
|
|
||||||
{
|
|
||||||
throw process_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("Process exited abnormally: %1").arg
|
|
||||||
(
|
|
||||||
process.readAllStandardError()
|
|
||||||
).toStdString(),
|
|
||||||
process.errorString().toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
process.exitCode(),
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return process.readAllStandardOutput();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::readFile(const QUrl &uri) -> QByteArray
|
|
||||||
{
|
|
||||||
validateUri(uri);
|
|
||||||
QByteArray data;
|
|
||||||
QFile file(uri.toLocalFile());
|
|
||||||
|
|
||||||
if(!file.open(QFile::ReadOnly))
|
|
||||||
{
|
|
||||||
throw file_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("Could not file").toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
errno,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
data = file.readAll();
|
|
||||||
|
|
||||||
if(data.length() != file.size())
|
|
||||||
{
|
|
||||||
throw file_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("File read error").toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
EIO,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::writeFile(const QUrl &uri, const QByteArray &data) noexcept(false) -> void
|
|
||||||
{
|
|
||||||
validateUri(uri);
|
|
||||||
|
|
||||||
QFile file(uri.toLocalFile());
|
|
||||||
if(!file.open(QFile::ReadWrite))
|
|
||||||
{
|
|
||||||
throw file_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("Could not file").toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
errno,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
file.write(data);
|
|
||||||
|
|
||||||
if(data.length() != file.size())
|
|
||||||
{
|
|
||||||
throw file_exception
|
|
||||||
(
|
|
||||||
QStringLiteral("File write error").toStdString(),
|
|
||||||
std::error_code
|
|
||||||
(
|
|
||||||
EIO,
|
|
||||||
std::system_category()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::setProgress(qreal progress) -> void
|
|
||||||
{
|
|
||||||
if(qFuzzyCompare(progress, m_progress))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_progress = progress;
|
|
||||||
Q_EMIT progressChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PackCompiler::setCompilerOutput(const QString &compilerOutput)
|
|
||||||
{
|
|
||||||
if (m_compilerOutput == compilerOutput)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_compilerOutput = compilerOutput;
|
|
||||||
emit compilerOutputChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::setError(const QString &title, const QString &message, const QUrl &uri) -> void
|
|
||||||
{
|
|
||||||
if(title == m_errorTitle && message == m_errorMessage)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_errorMessage = std::move(message);
|
|
||||||
m_errorTitle = std::move(title);
|
|
||||||
|
|
||||||
if(uri.isValid() && uri.isLocalFile())
|
|
||||||
{
|
|
||||||
QFile errorFile(uri.toLocalFile());
|
|
||||||
|
|
||||||
if(errorFile.open(QFile::ReadWrite | QFile::Append))
|
|
||||||
{
|
|
||||||
errorFile.write(message.toLocal8Bit() + QByteArray("\n"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT errorTitleChanged();
|
|
||||||
Q_EMIT errorMessageChanged();
|
|
||||||
Q_EMIT errorOcurred();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::setState(State state) -> void
|
|
||||||
{
|
|
||||||
if(state == m_state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
|
||||||
Q_EMIT stateChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::setStatus(const QString &status) -> void
|
|
||||||
{
|
|
||||||
if (m_status == status)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_status = status;
|
|
||||||
Q_EMIT statusChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::setTotalSteps(qint64 steps) -> void
|
|
||||||
{
|
|
||||||
if(steps == m_totalSteps)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_totalSteps = steps;
|
|
||||||
Q_EMIT totalStepsChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::setCurrentStep(qint64 step) -> void
|
|
||||||
{
|
|
||||||
if(step == m_currentStep)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_currentStep = step;
|
|
||||||
Q_EMIT currentStepChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackCompiler::incrementCompileStep() -> void
|
|
||||||
{
|
|
||||||
setCurrentStep(m_currentStep + 1);
|
|
||||||
|
|
||||||
setProgress
|
|
||||||
(
|
|
||||||
static_cast<qreal>(m_currentStep) / m_totalSteps
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,392 +0,0 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef PACKCOMPILER_H
|
|
||||||
#define PACKCOMPILER_H
|
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QFuture>
|
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QMutex>
|
|
||||||
#include <QMutexLocker>
|
|
||||||
#include <QImage>
|
|
||||||
#include <QRgb>
|
|
||||||
#include <QColor>
|
|
||||||
#include <QtQuick/QQuickItem>
|
|
||||||
#include <qdir.h>
|
|
||||||
#include <qobject.h>
|
|
||||||
#include <qtmetamacros.h>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QtShaderTools>
|
|
||||||
#include <QtShaderTools/rhi/qshaderbaker.h>
|
|
||||||
#include <QtConcurrent/qtconcurrentrun.h>
|
|
||||||
#include <qcontainerfwd.h>
|
|
||||||
#include <qmargins.h>
|
|
||||||
#include <qstandardpaths.h>
|
|
||||||
#include <qtmetamacros.h>
|
|
||||||
#include <qurl.h>
|
|
||||||
#include "common/komplex_global.h"
|
|
||||||
|
|
||||||
#if __has_include("vulkan/vulkan_core.h")
|
|
||||||
#define HAS_VULKAN
|
|
||||||
#include <vulkan/vulkan_core.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __has_include("GL/gl.h")
|
|
||||||
#define HAS_OPENGL
|
|
||||||
#include <GL/gl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT BuildContext
|
|
||||||
{
|
|
||||||
QMap<QByteArray, QByteArray> commonData;
|
|
||||||
QPromise<QUrl> promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The PackCompiler class
|
|
||||||
* [1] Extract Pack (GZip)
|
|
||||||
* [2] Verify directory is a pack and has shaders
|
|
||||||
* [3] Load Common shader code
|
|
||||||
* [4] Walk the shader directory
|
|
||||||
* [5] Load shader code
|
|
||||||
* [6] Append type specific common code and global code
|
|
||||||
* [7] Replace uniform variable use
|
|
||||||
* [8] Add uniform header
|
|
||||||
* [9] Add uniform footer
|
|
||||||
* [10] Run preprocessor to process macros
|
|
||||||
* [11] Append version macro
|
|
||||||
* [12] Compile with QShaderBaker
|
|
||||||
* [13] Save
|
|
||||||
*/
|
|
||||||
class PackCompiler : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum State
|
|
||||||
{
|
|
||||||
Idle,
|
|
||||||
Compiling,
|
|
||||||
Complete,
|
|
||||||
Error
|
|
||||||
};
|
|
||||||
Q_ENUM(State)
|
|
||||||
|
|
||||||
explicit PackCompiler(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
auto compilerOutput() const -> const QString & { return m_compilerOutput; }
|
|
||||||
auto progress() -> qreal { return m_progress; }
|
|
||||||
auto currentStep() -> qint64 { return m_currentStep; }
|
|
||||||
auto totalSteps() -> qint64 { return m_totalSteps; }
|
|
||||||
auto errorTitle() const -> const QString & { return m_errorTitle; }
|
|
||||||
auto errorMessage() const -> const QString & { return m_errorMessage; }
|
|
||||||
auto status() const -> const QString & { return m_status; }
|
|
||||||
auto state() const -> State { return m_state; }
|
|
||||||
auto reset() -> void;
|
|
||||||
|
|
||||||
auto build(const QUrl &uri) -> QUrl;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
auto compilerOutputChanged() -> void;
|
|
||||||
auto errorOcurred() -> void;
|
|
||||||
auto errorTitleChanged() -> void;
|
|
||||||
auto errorMessageChanged() -> void;
|
|
||||||
auto stateChanged() -> void;
|
|
||||||
auto progressChanged() -> void;
|
|
||||||
auto currentStepChanged() -> void;
|
|
||||||
auto totalStepsChanged() -> void;
|
|
||||||
auto compileComplete(const QUrl &uri) -> void;
|
|
||||||
auto statusChanged() -> void;
|
|
||||||
auto packReady(const QString &) -> void;
|
|
||||||
auto errorStepChanged() -> void;
|
|
||||||
auto errorRatingChanged() -> void;
|
|
||||||
|
|
||||||
private:
|
|
||||||
//[1]
|
|
||||||
/**
|
|
||||||
* @brief extract
|
|
||||||
* Extracts the packfile and deletes the source
|
|
||||||
* @param uri of the tar.gz pack
|
|
||||||
* @return uri of the extracted directory
|
|
||||||
*/
|
|
||||||
auto extract(const QUrl &uri) noexcept(false) -> const QUrl;
|
|
||||||
|
|
||||||
//[2]
|
|
||||||
/**
|
|
||||||
* @brief validatePack
|
|
||||||
* Validates that the directory is a valid pack and has shaders to compile
|
|
||||||
* @param uri of the directory provided by extract
|
|
||||||
*/
|
|
||||||
auto validatePack(const QUrl &uri) const noexcept(false) -> void;
|
|
||||||
|
|
||||||
//[3]
|
|
||||||
/**
|
|
||||||
* @brief loadCommonData
|
|
||||||
* Loads the common and global shader code from the shader directory of the uri
|
|
||||||
* @param uri
|
|
||||||
*/
|
|
||||||
auto loadCommonData(const QUrl &uri) -> QMap<QByteArray,QByteArray>;
|
|
||||||
|
|
||||||
//[4-5]
|
|
||||||
/**
|
|
||||||
* @brief processShaders
|
|
||||||
* Walks the shader directory, loads the code and calls 6-13 for each
|
|
||||||
* @param uri
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
auto processShaders(const QUrl &uri, BuildContext *context) -> void;
|
|
||||||
|
|
||||||
//[6]
|
|
||||||
/**
|
|
||||||
* @brief appendCommonData
|
|
||||||
* Appends the type specific common code to the shader data
|
|
||||||
* @param data
|
|
||||||
* Pointer to shader data
|
|
||||||
* @param suffix
|
|
||||||
* Shader file suffix
|
|
||||||
* @param context
|
|
||||||
* Pointer to build context object
|
|
||||||
*/
|
|
||||||
auto appendCommonData(QByteArray *data, const QByteArray &suffix, BuildContext *context) noexcept(true) -> void;
|
|
||||||
|
|
||||||
//[7]
|
|
||||||
/**
|
|
||||||
* @brief replaceUniformVariables
|
|
||||||
* Replaces standard variables such as iFrame with their uniform buffer name
|
|
||||||
* @param data
|
|
||||||
* Pointer to the shader data
|
|
||||||
*/
|
|
||||||
auto replaceUniformVariables(QByteArray *data) noexcept(true) -> void;
|
|
||||||
|
|
||||||
//[8]
|
|
||||||
/**
|
|
||||||
* @brief appendUniformHeader
|
|
||||||
* Adds header and uniform buffer to the shader data
|
|
||||||
* @param data
|
|
||||||
* Pointer to the shader data
|
|
||||||
*/
|
|
||||||
auto appendUniformHeader(QByteArray *data) noexcept(true) -> void;
|
|
||||||
|
|
||||||
//[9]
|
|
||||||
/**
|
|
||||||
* @brief appendUniformFooter
|
|
||||||
* Adds the uniform footer to the shader data
|
|
||||||
* @param data
|
|
||||||
* Pointer to the shader data
|
|
||||||
*/
|
|
||||||
auto appendUniformFooter(QByteArray *data) noexcept(true) -> void;
|
|
||||||
|
|
||||||
//[10]
|
|
||||||
/**
|
|
||||||
* @brief preprocess
|
|
||||||
* I have had issues with defines in code so passing it to a c/c++
|
|
||||||
* preprocessor is required. I am now using clang for this as clang
|
|
||||||
* is more modern and can use stdin
|
|
||||||
* @param data
|
|
||||||
*/
|
|
||||||
auto preprocess(QByteArray *data) noexcept(false) -> void;
|
|
||||||
|
|
||||||
//[11]
|
|
||||||
/**
|
|
||||||
* @brief appendVersion
|
|
||||||
* The version header confuses the preprocessor, so add it at the end
|
|
||||||
* @param data
|
|
||||||
*/
|
|
||||||
auto appendVersion(QByteArray *data) noexcept(true) -> void;
|
|
||||||
|
|
||||||
//[12]
|
|
||||||
/**
|
|
||||||
* @brief compile
|
|
||||||
* Compiles the shader data in memory and returns the shader object.
|
|
||||||
* @param data
|
|
||||||
* Shader data
|
|
||||||
* @param filename
|
|
||||||
* Filename of the shader
|
|
||||||
* @param stage
|
|
||||||
* Type of shader, based on suffix of original file
|
|
||||||
* @return
|
|
||||||
* Compiled shader object
|
|
||||||
*/
|
|
||||||
auto compile(const QByteArray &data, const QString &filename, const QShader::Stage stage) noexcept(false) -> QShader;
|
|
||||||
|
|
||||||
//[13]
|
|
||||||
auto save(const QUrl &uri, const QShader &shader) noexcept(false) -> void;
|
|
||||||
|
|
||||||
//helpers
|
|
||||||
auto validateUri(const QUrl &uri) const noexcept(false) -> void;
|
|
||||||
auto run(const QString &command, const QStringList &arguments, const QByteArray &data = {}) noexcept(false) -> QByteArray;
|
|
||||||
auto readFile(const QUrl &uri) noexcept(false) -> QByteArray;
|
|
||||||
auto writeFile(const QUrl &uri, const QByteArray &data) noexcept(false) -> void;
|
|
||||||
auto copyFile(const QUrl &sourceUri, const QUrl &destinationUri) noexcept(false) -> void;
|
|
||||||
auto createDirectory(const QUrl &uri) noexcept(false) -> void;
|
|
||||||
auto removeDirectory(const QUrl &uri) noexcept(false) -> void;
|
|
||||||
auto getStageFromSuffix(const QString &suffix) const -> QShader::Stage;
|
|
||||||
|
|
||||||
auto setError(const QString &title, const QString &message, const QUrl &uri = {}) -> void;
|
|
||||||
auto setCompilerOutput(const QString &compilerOutput) -> void;
|
|
||||||
auto setState(State state) -> void;
|
|
||||||
auto setProgress(qreal progress) -> void;
|
|
||||||
auto setTotalSteps(qint64 steps) -> void;
|
|
||||||
auto setCurrentStep(qint64 step) -> void;
|
|
||||||
auto setStatus(const QString &status) -> void;
|
|
||||||
auto incrementCompileStep() -> void;
|
|
||||||
|
|
||||||
#ifdef HAS_VULKAN
|
|
||||||
auto vulkanVersion() const -> qint32;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAS_OPENGL
|
|
||||||
auto openGlVersion() const -> qint32;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//members
|
|
||||||
static inline const QStringList m_updateVariables
|
|
||||||
{
|
|
||||||
QStringLiteral("iTime"),
|
|
||||||
QStringLiteral("iTimeDelta"),
|
|
||||||
QStringLiteral("iFrameRate"),
|
|
||||||
QStringLiteral("iSampleRate"),
|
|
||||||
QStringLiteral("iFrame"),
|
|
||||||
QStringLiteral("iDate"),
|
|
||||||
QStringLiteral("iMouse"),
|
|
||||||
QStringLiteral("iResolution"),
|
|
||||||
QStringLiteral("iColorTheme"),
|
|
||||||
QStringLiteral("iChannelTime"),
|
|
||||||
QStringLiteral("iChannelResolution")
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline const QStringList m_shaderNameFilters
|
|
||||||
{
|
|
||||||
QStringLiteral("*.frag"),
|
|
||||||
QStringLiteral("*.vert"),
|
|
||||||
QStringLiteral("*.tese"),
|
|
||||||
QStringLiteral("*.tesc"),
|
|
||||||
QStringLiteral("*.geom"),
|
|
||||||
QStringLiteral("*.comp"),
|
|
||||||
QStringLiteral("*.glsl")
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline const QMap<QString, QShader::Stage> m_shaderStages
|
|
||||||
{
|
|
||||||
{
|
|
||||||
QStringLiteral("frag"),
|
|
||||||
QShader::FragmentStage
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QStringLiteral("vert"),
|
|
||||||
QShader::VertexStage
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QStringLiteral("tese"),
|
|
||||||
QShader::TessellationEvaluationStage
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QStringLiteral("tesc"),
|
|
||||||
QShader::TessellationControlStage
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QStringLiteral("geom"),
|
|
||||||
QShader::GeometryStage
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QStringLiteral("comp"),
|
|
||||||
QShader::ComputeStage
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline const QByteArray m_version
|
|
||||||
{
|
|
||||||
R"(#version 450)"
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline const QByteArray m_header
|
|
||||||
{
|
|
||||||
R"(layout(location = 0) in vec2 qt_TexCoord0;
|
|
||||||
layout(location = 0) out vec4 fragColor;
|
|
||||||
|
|
||||||
layout(std140, binding = 0) uniform buf {
|
|
||||||
mat4 qt_Matrix;
|
|
||||||
float qt_Opacity;
|
|
||||||
float iTime;
|
|
||||||
float iTimeDelta;
|
|
||||||
float iFrameRate;
|
|
||||||
float iSampleRate;
|
|
||||||
int iFrame;
|
|
||||||
vec4 iDate;
|
|
||||||
vec4 iMouse;
|
|
||||||
vec3 iResolution;
|
|
||||||
float iChannelTime[4];
|
|
||||||
vec3 iChannelResolution[4];
|
|
||||||
vec4 iColorTheme[4];
|
|
||||||
} ubuf;
|
|
||||||
|
|
||||||
layout(binding = 1) uniform sampler2D iChannel0;
|
|
||||||
layout(binding = 2) uniform sampler2D iChannel1;
|
|
||||||
layout(binding = 3) uniform sampler2D iChannel2;
|
|
||||||
layout(binding = 4) uniform sampler2D iChannel3;
|
|
||||||
|
|
||||||
vec2 fragCoord = vec2(qt_TexCoord0.x, 1.0 - qt_TexCoord0.y) * ubuf.iResolution.xy;)"
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline const QByteArray m_footer
|
|
||||||
{
|
|
||||||
R"(
|
|
||||||
void main() {
|
|
||||||
vec4 color = vec4(0.0);
|
|
||||||
mainImage(color, fragCoord);
|
|
||||||
fragColor = color;
|
|
||||||
})"
|
|
||||||
};
|
|
||||||
|
|
||||||
QMap<QByteArray, QByteArray> m_commonData;
|
|
||||||
QMap<QByteArray, QShaderBaker> m_shaders;
|
|
||||||
|
|
||||||
QString m_compilerOutput;
|
|
||||||
QString m_errorMessage;
|
|
||||||
QString m_errorTitle;
|
|
||||||
QString m_status;
|
|
||||||
|
|
||||||
State m_state;
|
|
||||||
|
|
||||||
qreal m_currentStep = 0;
|
|
||||||
qreal m_progress = 0;
|
|
||||||
qreal m_totalSteps = 0;
|
|
||||||
|
|
||||||
QMutex m_downloadMutex;
|
|
||||||
|
|
||||||
QFuture<QUrl> m_buildFuture;
|
|
||||||
|
|
||||||
static inline QList<QRegularExpression> m_variableExpressions;
|
|
||||||
|
|
||||||
Q_PROPERTY(QString compilerOutput READ compilerOutput WRITE setCompilerOutput NOTIFY compilerOutputChanged FINAL)
|
|
||||||
Q_PROPERTY(QString errorTitle READ errorTitle NOTIFY errorTitleChanged FINAL)
|
|
||||||
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged FINAL)
|
|
||||||
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged FINAL)
|
|
||||||
Q_PROPERTY(qint64 totalSteps READ totalSteps NOTIFY totalStepsChanged FINAL)
|
|
||||||
Q_PROPERTY(qint64 currentStep READ currentStep NOTIFY currentStepChanged FINAL)
|
|
||||||
Q_PROPERTY(QString status READ status WRITE setStatus NOTIFY statusChanged FINAL)
|
|
||||||
Q_PROPERTY(State state READ state NOTIFY stateChanged FINAL)
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(PackCompiler)
|
|
||||||
#endif // PackCompiler_H
|
|
||||||
@@ -1,375 +0,0 @@
|
|||||||
#include "packsearchmodel.h"
|
|
||||||
|
|
||||||
PackSearchModel::PackSearchModel(QObject *parent) : QAbstractListModel{parent}
|
|
||||||
{
|
|
||||||
m_paginator = new PackSearchPaginator(this);
|
|
||||||
PaginationNotifier *notifier = static_cast<PaginationNotifier*>(m_paginator);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::resultsPerPageChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::resultsPerPageChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::totalResultsChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::totalResultsChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::totalPagesChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::totalPagesChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::pageChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::pageChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::pageChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::resetDataModel
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetchComplete,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
notifier,
|
|
||||||
&PaginationNotifier::fetching,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::onPaginatorFetching
|
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
m_paginator,
|
|
||||||
&PaginationNotifier::queryChanged,
|
|
||||||
this,
|
|
||||||
&PackSearchModel::queryChanged
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
PackSearchModel::~PackSearchModel()
|
|
||||||
{
|
|
||||||
if(m_paginator)
|
|
||||||
{
|
|
||||||
delete m_paginator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::rowCount(const QModelIndex &) const -> int
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::data(const QModelIndex &index, int role) const -> QVariant
|
|
||||||
{
|
|
||||||
if(m_paginator == nullptr)
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if(index.row() < 0 || index.row() >= m_paginator->count() )
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
WallpaperCache dataPoint = m_paginator->at(index.row());
|
|
||||||
|
|
||||||
QVariant data;
|
|
||||||
|
|
||||||
switch(static_cast<DataRole>(role))
|
|
||||||
{
|
|
||||||
case UuidRole:
|
|
||||||
data = dataPoint.uuid;
|
|
||||||
break;
|
|
||||||
case AuthorRole:
|
|
||||||
data = dataPoint.author;
|
|
||||||
break;
|
|
||||||
case DescriptionRole:
|
|
||||||
data = dataPoint.description;
|
|
||||||
break;
|
|
||||||
case NameRole:
|
|
||||||
data = dataPoint.name;
|
|
||||||
break;
|
|
||||||
case ThumbnailRole:
|
|
||||||
data = dataPoint.thumbnail;
|
|
||||||
break;
|
|
||||||
case CreatedDateRole:
|
|
||||||
data = dataPoint.createdDate;
|
|
||||||
break;
|
|
||||||
case AuthorIdRole:
|
|
||||||
data = dataPoint.authorId;
|
|
||||||
break;
|
|
||||||
case PriceRole:
|
|
||||||
data = dataPoint.price;
|
|
||||||
break;
|
|
||||||
case CurrencyRole:
|
|
||||||
data = dataPoint.currency;
|
|
||||||
break;
|
|
||||||
case DownloadCountRole:
|
|
||||||
data = dataPoint.downloadCount;
|
|
||||||
break;
|
|
||||||
case TypeRole:
|
|
||||||
data = dataPoint.type;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::index(int row, int column, const QModelIndex &parent) const -> QModelIndex
|
|
||||||
{
|
|
||||||
Q_UNUSED(parent)
|
|
||||||
|
|
||||||
if(row < 0 || row >= m_paginator->count())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_paginator[row]);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::columnCount(const QModelIndex &) const -> int
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::parent(const QModelIndex &) const -> QModelIndex
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setData(const QModelIndex &, const QVariant &, int) -> bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::state() const -> PackSearchModel::State
|
|
||||||
{
|
|
||||||
return m_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setState(State state) -> void
|
|
||||||
{
|
|
||||||
if (m_state == state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
|
||||||
emit stateChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::resetState() -> void
|
|
||||||
{
|
|
||||||
setState(Idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::resetDataModel() -> void
|
|
||||||
{
|
|
||||||
//invalidate previous model data
|
|
||||||
beginRemoveRows(QModelIndex(), 0, m_paginator->count());
|
|
||||||
endRemoveRows();
|
|
||||||
|
|
||||||
//signal new data
|
|
||||||
beginInsertRows(QModelIndex(), 0, m_paginator->count() - 1);
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::boundaryCheck(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
if(index < 0 || m_paginator == nullptr || index >= m_paginator->count())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::hasNextPage() const -> bool
|
|
||||||
{
|
|
||||||
return m_paginator->page() < m_paginator->totalPages();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::hasPreviousPage() const -> bool
|
|
||||||
{
|
|
||||||
return m_paginator->page() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::onPaginatorFetching() -> void
|
|
||||||
{
|
|
||||||
setState(Loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::roleNames() const -> QHash<int, QByteArray>
|
|
||||||
{
|
|
||||||
return m_dataRoles;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::errorString() const -> QString
|
|
||||||
{
|
|
||||||
return m_errorString;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setErrorString(const QString &errorString) -> void
|
|
||||||
{
|
|
||||||
if (m_errorString == errorString)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_errorString = errorString;
|
|
||||||
emit errorStringChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::resultsPerPage() const -> qsizetype
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->resultsPerPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setResultsPerPage(qsizetype resultsPerPage) -> void
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
QFuture<void> future = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, resultsPerPage]
|
|
||||||
{
|
|
||||||
qsizetype difference = resultsPerPage - m_paginator->resultsPerPage();
|
|
||||||
m_paginator->setResultsPerPage(resultsPerPage);
|
|
||||||
|
|
||||||
if(difference > 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage() - difference;
|
|
||||||
|
|
||||||
beginInsertRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
m_paginator->count() - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(difference < 0)
|
|
||||||
{
|
|
||||||
qsizetype firstIndex = m_paginator->resultsPerPage();
|
|
||||||
|
|
||||||
beginRemoveRows
|
|
||||||
(
|
|
||||||
QModelIndex(),
|
|
||||||
firstIndex,
|
|
||||||
firstIndex - difference
|
|
||||||
);
|
|
||||||
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::totalResults() const -> qsizetype
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->totalResults();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::nextPage() -> void
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
QFuture<void> future = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::previousPage() -> void
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
QFuture<void> future = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
m_paginator->previous();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::query() const -> QString
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->query();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::setQuery(const QString &query) -> void
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
QFuture<void> future = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this, query]
|
|
||||||
{
|
|
||||||
m_paginator->setQuery(query);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype PackSearchModel::page() const
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->page();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto PackSearchModel::totalPages() const -> qsizetype
|
|
||||||
{
|
|
||||||
if(m_paginator != nullptr)
|
|
||||||
{
|
|
||||||
return m_paginator->totalPages();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,392 +0,0 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef PackSearchModel_H
|
|
||||||
#define PackSearchModel_H
|
|
||||||
#include <QObject>
|
|
||||||
#include <QQmlEngine>
|
|
||||||
#include <QList>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QJsonParseError>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QAbstractListModel>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QEventLoop>
|
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "paginators/packsearchpaginator.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The PackSearchModel class
|
|
||||||
*/
|
|
||||||
class KOMPLEX_EXPORT PackSearchModel : public QAbstractListModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
QML_ELEMENT
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Used to control the UI state
|
|
||||||
*/
|
|
||||||
enum State
|
|
||||||
{
|
|
||||||
Idle,
|
|
||||||
Loading,
|
|
||||||
Error
|
|
||||||
};
|
|
||||||
Q_ENUM(State)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data roles used by the view to request data
|
|
||||||
*/
|
|
||||||
enum DataRole {
|
|
||||||
UuidRole = Qt::UserRole + 1,
|
|
||||||
AuthorRole,
|
|
||||||
AuthorIdRole,
|
|
||||||
DescriptionRole,
|
|
||||||
NameRole,
|
|
||||||
ThumbnailRole,
|
|
||||||
CreatedDateRole,
|
|
||||||
PriceRole,
|
|
||||||
CurrencyRole,
|
|
||||||
DownloadCountRole,
|
|
||||||
TypeRole
|
|
||||||
};
|
|
||||||
Q_ENUM(DataRole)
|
|
||||||
|
|
||||||
explicit PackSearchModel(QObject *parent = nullptr);
|
|
||||||
~PackSearchModel();
|
|
||||||
|
|
||||||
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief data
|
|
||||||
* Used by the view to pull data from the model.
|
|
||||||
* Required by QAbstractListModel
|
|
||||||
* @param index
|
|
||||||
* @param role
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto data(
|
|
||||||
const QModelIndex &index,
|
|
||||||
int role = Qt::DisplayRole
|
|
||||||
) const -> QVariant override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief index
|
|
||||||
* Used by the view to create an index for the data point.
|
|
||||||
* Required by QAbstractListModel
|
|
||||||
* @param row
|
|
||||||
* @param column
|
|
||||||
* @param parent
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto index(
|
|
||||||
int row,
|
|
||||||
int column,
|
|
||||||
const QModelIndex &parent = QModelIndex()
|
|
||||||
) const -> QModelIndex override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief columnCount
|
|
||||||
* Required by QAbstractListModel, but just returns 0
|
|
||||||
* since we dont use cols
|
|
||||||
* @param parent
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto columnCount(
|
|
||||||
const QModelIndex &parent = QModelIndex()
|
|
||||||
) const -> int override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief parent
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto parent(const QModelIndex &index) const -> QModelIndex override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setData
|
|
||||||
* Required by QAbstractListModel but not used
|
|
||||||
* @param index
|
|
||||||
* @param value
|
|
||||||
* @param role
|
|
||||||
* @return true always
|
|
||||||
*/
|
|
||||||
auto setData(
|
|
||||||
const QModelIndex &index,
|
|
||||||
const QVariant &value,
|
|
||||||
int role = Qt::EditRole
|
|
||||||
) -> bool override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief state
|
|
||||||
* Current Model State
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto state() const -> State;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief roleNames
|
|
||||||
* Used to tell the view what data roles are available
|
|
||||||
* and their QML friendly names
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto roleNames() const -> QHash<int, QByteArray> override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorString
|
|
||||||
* User-friendly error string to be reported to the user
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto errorString() const -> QString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resultsPerPage
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto resultsPerPage() const -> qsizetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setResultsPerPage
|
|
||||||
* @param resultsPerPage
|
|
||||||
*/
|
|
||||||
auto setResultsPerPage(qsizetype resultsPerPage) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief totalResults
|
|
||||||
* Total number of results available
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto totalResults() const -> qsizetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief page
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto page() const -> qsizetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief totalPages
|
|
||||||
* Total pages based on the current resultsPerPage
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto totalPages() const -> qsizetype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief nextPage
|
|
||||||
* Function for the QML frontend
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE auto nextPage() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief previousPage
|
|
||||||
* Function for the QML frontend
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE auto previousPage() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief query
|
|
||||||
* Current search query
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto query() const -> QString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setQuery
|
|
||||||
* Sets the current search query
|
|
||||||
* @param query
|
|
||||||
*/
|
|
||||||
auto setQuery(const QString &query) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasNextPage
|
|
||||||
* Calculates if there are more pages based on the current page calculation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasNextPage() const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hasPreviousPage
|
|
||||||
* If page is greater than 1, returns true
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto hasPreviousPage() const -> bool;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief onPaginatorFetching
|
|
||||||
* Sets current state to loading. Triggered when paginator's cache controller
|
|
||||||
* needs to fetch data from the remote endpoint.
|
|
||||||
*/
|
|
||||||
auto onPaginatorFetching() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setErrorString
|
|
||||||
* @param errorString
|
|
||||||
*/
|
|
||||||
auto setErrorString(const QString &errorString) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setState
|
|
||||||
* @param state
|
|
||||||
*/
|
|
||||||
auto setState(State state) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetState
|
|
||||||
*/
|
|
||||||
auto resetState() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetDataModel
|
|
||||||
* Clears the data model and creates a new one if data exists
|
|
||||||
*/
|
|
||||||
auto resetDataModel() -> void;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
/**
|
|
||||||
* @brief stateChanged
|
|
||||||
* Signaled when reported state changes
|
|
||||||
*/
|
|
||||||
auto stateChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorStringChanged
|
|
||||||
* Signaled when reported error message changes
|
|
||||||
*/
|
|
||||||
auto errorStringChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto resultsPerPageChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto pageChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalResultsChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto totalPagesChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief pageChanged
|
|
||||||
* Forwarding signal connected in constructor
|
|
||||||
*/
|
|
||||||
auto queryChanged() -> void;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Helper function to check the requested index boundary
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data role map that connects PackSearchModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
|
||||||
{
|
|
||||||
{
|
|
||||||
static_cast<int>(UuidRole),
|
|
||||||
QByteArray("uuid")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(AuthorRole),
|
|
||||||
QByteArray("author")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(AuthorIdRole),
|
|
||||||
QByteArray("authorId")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(DescriptionRole),
|
|
||||||
QByteArray("description")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(NameRole),
|
|
||||||
QByteArray("name")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(ThumbnailRole),
|
|
||||||
QByteArray("thumbnail")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(CreatedDateRole),
|
|
||||||
QByteArray("createdDate")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(PriceRole),
|
|
||||||
QByteArray("price")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(CurrencyRole),
|
|
||||||
QByteArray("currency")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(DownloadCountRole),
|
|
||||||
QByteArray("downloadCount")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(TypeRole),
|
|
||||||
QByteArray("type")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
State m_state = Idle;
|
|
||||||
|
|
||||||
QString m_errorString = QString();
|
|
||||||
|
|
||||||
PackSearchPaginator *m_paginator = nullptr;
|
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype resultsPerPage READ resultsPerPage WRITE setResultsPerPage NOTIFY resultsPerPageChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype totalResults READ totalResults NOTIFY totalResultsChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype totalPages READ totalPages NOTIFY totalPagesChanged FINAL)
|
|
||||||
Q_PROPERTY(qsizetype page READ page NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(bool hasNextPage READ hasNextPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(bool hasPreviousPage READ hasPreviousPage NOTIFY pageChanged FINAL)
|
|
||||||
Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged FINAL)
|
|
||||||
};
|
|
||||||
Q_DECLARE_METATYPE(PackSearchModel)
|
|
||||||
|
|
||||||
#endif // PackSearchModel_H
|
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Komplex Wallpaper Engine
|
||||||
|
* Copyright (C) 2026 @DigitalArtifex
|
||||||
|
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
#ifndef FEATUREDCUBEMAPSPAGINATOR_H
|
||||||
|
#define FEATUREDCUBEMAPSPAGINATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "wallpaperpaginator.h"
|
||||||
|
|
||||||
|
class KOMPLEX_EXPORT FeaturedCubemapsPaginator : public WallpaperPaginator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit FeaturedCubemapsPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
|
{
|
||||||
|
setUri(
|
||||||
|
QString::fromUtf8(KOMPLEX_ENDPOINT_CUBEMAPS_FEATURED)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FEATUREDCUBEMAPSPAGINATOR_H
|
||||||
@@ -36,8 +36,9 @@ class KOMPLEX_EXPORT FeaturedImagesPaginator : public ImagePaginator
|
|||||||
public:
|
public:
|
||||||
explicit FeaturedImagesPaginator(QObject *parent = nullptr) : ImagePaginator(parent)
|
explicit FeaturedImagesPaginator(QObject *parent = nullptr) : ImagePaginator(parent)
|
||||||
{
|
{
|
||||||
setUri(KOMPLEX_ENDPOINT_IMAGES_FEATURED);
|
setUri(
|
||||||
controller()->setWindowSize(32);
|
QString::fromUtf8(KOMPLEX_ENDPOINT_IMAGES_FEATURED)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ class KOMPLEX_EXPORT FeaturedPacksPaginator : public WallpaperPaginator
|
|||||||
public:
|
public:
|
||||||
explicit FeaturedPacksPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
explicit FeaturedPacksPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
{
|
{
|
||||||
setUri(KOMPLEX_ENDPOINT_PACKS_FEATURED);
|
setUri(
|
||||||
controller()->setWindowSize(32);
|
QString::fromUtf8(KOMPLEX_ENDPOINT_PACKS_FEATURED)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Komplex Wallpaper Engine
|
||||||
|
* Copyright (C) 2026 @DigitalArtifex
|
||||||
|
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
#ifndef FEATUREDSHADERSPAGINATOR_H
|
||||||
|
#define FEATUREDSHADERSPAGINATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "wallpaperpaginator.h"
|
||||||
|
|
||||||
|
class KOMPLEX_EXPORT FeaturedShadersPaginator : public WallpaperPaginator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit FeaturedShadersPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
|
{
|
||||||
|
setUri(
|
||||||
|
QString::fromUtf8(KOMPLEX_ENDPOINT_SHADERS_FEATURED)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FEATUREDSHADERSPAGINATOR_H
|
||||||
@@ -36,8 +36,9 @@ class KOMPLEX_EXPORT FeaturedVideosPaginator : public VideoPaginator
|
|||||||
public:
|
public:
|
||||||
explicit FeaturedVideosPaginator(QObject *parent = nullptr) : VideoPaginator(parent)
|
explicit FeaturedVideosPaginator(QObject *parent = nullptr) : VideoPaginator(parent)
|
||||||
{
|
{
|
||||||
setUri(KOMPLEX_ENDPOINT_VIDEOS_FEATURED);
|
setUri(
|
||||||
controller()->setWindowSize(32);
|
QString::fromUtf8(KOMPLEX_ENDPOINT_VIDEOS_FEATURED)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,9 +30,9 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
|
#include "common/paginator.h"
|
||||||
#include "common/imagecache.h"
|
#include "common/imagecache.h"
|
||||||
#include "common/coreservices.h"
|
#include "common/coreservices.h"
|
||||||
#include "paginator.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ImagePaginator class
|
* @brief The ImagePaginator class
|
||||||
@@ -62,12 +62,46 @@ public:
|
|||||||
return m_uri;
|
return m_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief query
|
||||||
|
* Current query string, if the API Endpoint supports queries
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
auto query() const -> QString
|
||||||
|
{
|
||||||
|
return m_query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setQuery
|
||||||
|
* Sets the new query string and updates the controller
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
auto setQuery(const QString &query) -> void
|
||||||
|
{
|
||||||
|
if(query == m_query)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_query = query;
|
||||||
|
Q_EMIT queryChanged();
|
||||||
|
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* @brief uriChanged
|
* @brief uriChanged
|
||||||
*/
|
*/
|
||||||
auto uriChanged() -> void;
|
auto uriChanged() -> void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief queryChanged
|
||||||
|
*/
|
||||||
|
auto queryChanged() -> void;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief fetch
|
* @brief fetch
|
||||||
@@ -90,11 +124,6 @@ protected:
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
if(queryable() && query().isEmpty())
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl url(
|
QUrl url(
|
||||||
QString::fromUtf8("%1/%2/%3").arg(
|
QString::fromUtf8("%1/%2/%3").arg(
|
||||||
KOMPLEX_API_HOST,
|
KOMPLEX_API_HOST,
|
||||||
@@ -109,7 +138,7 @@ protected:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
QByteArray("query"),
|
QByteArray("query"),
|
||||||
query().toUtf8()
|
m_query.toUtf8()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
QByteArray("offset"),
|
QByteArray("offset"),
|
||||||
@@ -154,119 +183,13 @@ protected:
|
|||||||
QMap<QString, QString> sourceMap;
|
QMap<QString, QString> sourceMap;
|
||||||
|
|
||||||
QMapIterator<QString,QVariant> sourceIterator(sources);
|
QMapIterator<QString,QVariant> sourceIterator(sources);
|
||||||
QString original;
|
|
||||||
|
|
||||||
while(sourceIterator.hasNext())
|
while(sourceIterator.hasNext())
|
||||||
{
|
{
|
||||||
sourceIterator.next();
|
sourceIterator.next();
|
||||||
|
sourceMap.insert(sourceIterator.key(), sourceIterator.value().toString());
|
||||||
if(sourceIterator.key().toLower() == QString::fromUtf8("original"))
|
|
||||||
{
|
|
||||||
original = sourceIterator.value().toString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize screenSize = CoreServices::screenSize();
|
|
||||||
QSize portraitSize(screenSize.height(),screenSize.width());
|
|
||||||
QSize landscapeSize(screenSize.width(),screenSize.height());
|
|
||||||
|
|
||||||
if(screenSize.height() > screenSize.width())
|
|
||||||
{
|
|
||||||
portraitSize = screenSize;
|
|
||||||
landscapeSize = QSize(screenSize.height(),screenSize.width());
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceMap.clear();
|
|
||||||
sourceMap = QMap<QString,QString>
|
|
||||||
{
|
|
||||||
{
|
|
||||||
QString::fromUtf8("original"),
|
|
||||||
original
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("screen"),
|
|
||||||
QString::fromUtf8("%1?auto=compress&cs=tinysrgb&fit=crop&h=%2&w=%3").arg(
|
|
||||||
original,
|
|
||||||
QString::number(screenSize.height()),
|
|
||||||
QString::number(screenSize.width())
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("portrait"),
|
|
||||||
QString::fromUtf8("%1?auto=compress&cs=tinysrgb&fit=crop&h=%2&w=%3").arg(
|
|
||||||
original,
|
|
||||||
QString::number(portraitSize.height()),
|
|
||||||
QString::number(portraitSize.width())
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("landscape"),
|
|
||||||
QString::fromUtf8("%1?auto=compress&cs=tinysrgb&fit=crop&h=%2&w=%3").arg(
|
|
||||||
original,
|
|
||||||
QString::number(landscapeSize.height()),
|
|
||||||
QString::number(landscapeSize.width())
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("backgroundPortrait"),
|
|
||||||
QString::fromUtf8("%1?auto=compress&cs=tinysrgb&fit=crop&h=%2&w=%3").arg(
|
|
||||||
original,
|
|
||||||
QString::number(portraitSize.height() / 2),
|
|
||||||
QString::number(portraitSize.width() / 2)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("backgroundLandscape"),
|
|
||||||
QString::fromUtf8("%1?auto=compress&cs=tinysrgb&fit=crop&h=%2&w=%3").arg(
|
|
||||||
original,
|
|
||||||
QString::number(landscapeSize.height() / 2),
|
|
||||||
QString::number(landscapeSize.width() / 2)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("thumbnail"),
|
|
||||||
QString::fromUtf8("%1?auto=compress&cs=tinysrgb&fit=crop&h=144&w=256%3").arg(
|
|
||||||
original
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("largeThumbnail"),
|
|
||||||
QString::fromUtf8("%1?auto=compress&cs=tinysrgb&fit=crop&h=450&w=800%3").arg(
|
|
||||||
original
|
|
||||||
)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
QMap<QString, QString> sizeMap =
|
|
||||||
{
|
|
||||||
{
|
|
||||||
QString::fromUtf8("original"),
|
|
||||||
QString()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("screen"),
|
|
||||||
QString::fromUtf8("%1x%2").arg(
|
|
||||||
QString::number(screenSize.width()),
|
|
||||||
QString::number(screenSize.height())
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("portrait"),
|
|
||||||
QString::fromUtf8("%1x%2").arg(
|
|
||||||
QString::number(portraitSize.width()),
|
|
||||||
QString::number(portraitSize.height())
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
QString::fromUtf8("landscape"),
|
|
||||||
QString::fromUtf8("%1x%2").arg(
|
|
||||||
QString::number(landscapeSize.width()),
|
|
||||||
QString::number(landscapeSize.height())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchedResults.append(
|
fetchedResults.append(
|
||||||
{
|
{
|
||||||
resultObject.value(QString::fromUtf8("alt")).toString(),
|
resultObject.value(QString::fromUtf8("alt")).toString(),
|
||||||
@@ -279,7 +202,6 @@ protected:
|
|||||||
resultObject.value(QString::fromUtf8("photographer_url")).toString(),
|
resultObject.value(QString::fromUtf8("photographer_url")).toString(),
|
||||||
resultObject.value(QString::fromUtf8("photographer_id")).toInteger(),
|
resultObject.value(QString::fromUtf8("photographer_id")).toInteger(),
|
||||||
std::move(sourceMap),
|
std::move(sourceMap),
|
||||||
std::move(sizeMap),
|
|
||||||
resultObject.value(QString::fromUtf8("url")).toString()
|
resultObject.value(QString::fromUtf8("url")).toString()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -305,8 +227,8 @@ protected:
|
|||||||
auto getNetworkReply(const QNetworkRequest &request) const -> QNetworkReply*
|
auto getNetworkReply(const QNetworkRequest &request) const -> QNetworkReply*
|
||||||
{
|
{
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
|
||||||
QWeakPointer<QNetworkAccessManager> managerReference = CoreServices::networkAccessManager();
|
QWeakPointer<QNetworkAccessManager> managerReference = CoreServices::networkAccessManager();
|
||||||
|
|
||||||
QSharedPointer<QNetworkAccessManager> manager = managerReference.toStrongRef();
|
QSharedPointer<QNetworkAccessManager> manager = managerReference.toStrongRef();
|
||||||
|
|
||||||
LOG_ERROR_X(!manager,
|
LOG_ERROR_X(!manager,
|
||||||
@@ -329,8 +251,6 @@ protected:
|
|||||||
loop.exec();
|
loop.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.clear();
|
|
||||||
|
|
||||||
LOG_ERROR_X(reply->error() != QNetworkReply::NoError,
|
LOG_ERROR_X(reply->error() != QNetworkReply::NoError,
|
||||||
"NewestPacksPaginator::getNetworkReply",
|
"NewestPacksPaginator::getNetworkReply",
|
||||||
reply->errorString().toStdString().c_str(),
|
reply->errorString().toStdString().c_str(),
|
||||||
@@ -340,6 +260,28 @@ protected:
|
|||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief getDocument
|
||||||
|
* Extracts the JSON document from the server reply
|
||||||
|
* @param reply
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
auto getDocument(QNetworkReply *reply) const -> QJsonDocument
|
||||||
|
{
|
||||||
|
QByteArray data = reply->readAll();
|
||||||
|
QJsonParseError documentError;
|
||||||
|
QJsonDocument document = QJsonDocument::fromJson(data, &documentError);
|
||||||
|
|
||||||
|
LOG_ERROR_X(documentError.error != QJsonParseError::NoError,
|
||||||
|
"NewestPacksPaginator::getDocument",
|
||||||
|
documentError.errorString().toStdString().c_str(),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setUri
|
* @brief setUri
|
||||||
* Sets the API Endpoint URI to fetch from
|
* Sets the API Endpoint URI to fetch from
|
||||||
@@ -365,13 +307,10 @@ private:
|
|||||||
QString m_uri;
|
QString m_uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief s_sizeExpression
|
* @brief m_query
|
||||||
* Regular expression used to extract size data from the url
|
* The query string used in fetch operations
|
||||||
*/
|
*/
|
||||||
inline static QRegularExpression s_sizeExpression = QRegularExpression
|
QString m_query;
|
||||||
(
|
|
||||||
QString::fromUtf8("[h]\\=\\d{1,}\\&[w]\\=\\d{1,}")
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMAGEPAGINATOR_H
|
#endif // IMAGEPAGINATOR_H
|
||||||
|
|||||||
@@ -38,8 +38,9 @@ class KOMPLEX_EXPORT ImageSearchPaginator : public ImagePaginator
|
|||||||
public:
|
public:
|
||||||
explicit ImageSearchPaginator(QObject *parent = nullptr) : ImagePaginator(parent)
|
explicit ImageSearchPaginator(QObject *parent = nullptr) : ImagePaginator(parent)
|
||||||
{
|
{
|
||||||
setUri(KOMPLEX_ENDPOINT_IMAGES_SEARCH);
|
setUri(
|
||||||
setQueryable(true);
|
QString::fromUtf8(KOMPLEX_ENDPOINT_IMAGES_SEARCH)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Komplex Wallpaper Engine
|
||||||
|
* Copyright (C) 2026 @DigitalArtifex
|
||||||
|
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
#ifndef NEWESTCUBEMAPSPAGINATOR_H
|
||||||
|
#define NEWESTCUBEMAPSPAGINATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "wallpaperpaginator.h"
|
||||||
|
|
||||||
|
class KOMPLEX_EXPORT NewestCubemapsPaginator : public WallpaperPaginator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit NewestCubemapsPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
|
{
|
||||||
|
setUri(
|
||||||
|
QString::fromUtf8(KOMPLEX_ENDPOINT_CUBEMAPS_NEWEST)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NEWESTCUBEMAPSPAGINATOR_H
|
||||||
@@ -36,8 +36,9 @@ class KOMPLEX_EXPORT NewestPacksPaginator : public WallpaperPaginator
|
|||||||
public:
|
public:
|
||||||
explicit NewestPacksPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
explicit NewestPacksPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
{
|
{
|
||||||
setUri(KOMPLEX_ENDPOINT_PACKS_NEWEST);
|
setUri(
|
||||||
controller()->setWindowSize(20);
|
QString::fromUtf8(KOMPLEX_ENDPOINT_PACKS_NEWEST)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Komplex Wallpaper Engine
|
||||||
|
* Copyright (C) 2026 @DigitalArtifex
|
||||||
|
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
#ifndef NEWESTSHADERSPAGINATOR_H
|
||||||
|
#define NEWESTSHADERSPAGINATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "wallpaperpaginator.h"
|
||||||
|
|
||||||
|
class KOMPLEX_EXPORT NewestShadersPaginator : public WallpaperPaginator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit NewestShadersPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
|
{
|
||||||
|
setUri(
|
||||||
|
QString::fromUtf8(KOMPLEX_ENDPOINT_SHADERS_NEWEST)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NEWESTSHADERSPAGINATOR_H
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Komplex Wallpaper Engine
|
||||||
|
* Copyright (C) 2026 @DigitalArtifex
|
||||||
|
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
#ifndef SEARCHCUBEMAPSPAGINATOR_H
|
||||||
|
#define SEARCHCUBEMAPSPAGINATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "wallpaperpaginator.h"
|
||||||
|
|
||||||
|
class KOMPLEX_EXPORT SearchCubemapsPaginator : public WallpaperPaginator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit SearchCubemapsPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
|
{
|
||||||
|
setUri(
|
||||||
|
QString::fromUtf8(KOMPLEX_ENDPOINT_CUBEMAPS_SEARCH)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SEARCHCUBEMAPSPAGINATOR_H
|
||||||
+8
-7
@@ -16,8 +16,8 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
#ifndef PACKSEARCHPAGINATOR_H
|
#ifndef SEARCHPACKSPAGINATOR_H
|
||||||
#define PACKSEARCHPAGINATOR_H
|
#define SEARCHPACKSPAGINATOR_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
@@ -31,14 +31,15 @@
|
|||||||
|
|
||||||
#include "wallpaperpaginator.h"
|
#include "wallpaperpaginator.h"
|
||||||
|
|
||||||
class KOMPLEX_EXPORT PackSearchPaginator : public WallpaperPaginator
|
class KOMPLEX_EXPORT SearchPacksPaginator : public WallpaperPaginator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit PackSearchPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
explicit SearchPacksPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
{
|
{
|
||||||
setUri(KOMPLEX_ENDPOINT_PACKS_SEARCH);
|
setUri(
|
||||||
setQueryable(true);
|
QString::fromUtf8(KOMPLEX_ENDPOINT_PACKS_SEARCH)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PACKSEARCHPAGINATOR_H
|
#endif // SEARCHPACKSPAGINATOR_H
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Komplex Wallpaper Engine
|
||||||
|
* Copyright (C) 2026 @DigitalArtifex
|
||||||
|
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
#ifndef SEARCHSHADERSPAGINATOR_H
|
||||||
|
#define SEARCHSHADERSPAGINATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "wallpaperpaginator.h"
|
||||||
|
|
||||||
|
class KOMPLEX_EXPORT SearchShadersPaginator : public WallpaperPaginator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit SearchShadersPaginator(QObject *parent = nullptr) : WallpaperPaginator(parent)
|
||||||
|
{
|
||||||
|
setUri(
|
||||||
|
QString::fromUtf8(KOMPLEX_ENDPOINT_SHADERS_SEARCH)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SEARCHSHADERSPAGINATOR_H
|
||||||
@@ -30,9 +30,9 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
|
#include "common/paginator.h"
|
||||||
#include "common/videocache.h"
|
#include "common/videocache.h"
|
||||||
#include "common/coreservices.h"
|
#include "common/coreservices.h"
|
||||||
#include "paginator.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The VideoPaginator class
|
* @brief The VideoPaginator class
|
||||||
@@ -62,12 +62,47 @@ public:
|
|||||||
return m_uri;
|
return m_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief query
|
||||||
|
* Current query string, if the API Endpoint supports queries
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
auto query() const -> QString
|
||||||
|
{
|
||||||
|
return m_query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setQuery
|
||||||
|
* Sets the new query string and updates the controller
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
auto setQuery(const QString &query) -> void
|
||||||
|
{
|
||||||
|
if(query == m_query)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_query = query;
|
||||||
|
Q_EMIT queryChanged();
|
||||||
|
|
||||||
|
reset();
|
||||||
|
setOffset(0);
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* @brief uriChanged
|
* @brief uriChanged
|
||||||
*/
|
*/
|
||||||
auto uriChanged() -> void;
|
auto uriChanged() -> void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief queryChanged
|
||||||
|
*/
|
||||||
|
auto queryChanged() -> void;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief fetch
|
* @brief fetch
|
||||||
@@ -90,11 +125,6 @@ protected:
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
if(queryable() && query().isEmpty())
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl url(
|
QUrl url(
|
||||||
QString::fromUtf8("%1/%2/%3").arg(
|
QString::fromUtf8("%1/%2/%3").arg(
|
||||||
KOMPLEX_API_HOST,
|
KOMPLEX_API_HOST,
|
||||||
@@ -109,7 +139,7 @@ protected:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
QByteArray("query"),
|
QByteArray("query"),
|
||||||
query().toUtf8()
|
m_query.toUtf8()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
QByteArray("offset"),
|
QByteArray("offset"),
|
||||||
@@ -228,12 +258,7 @@ protected:
|
|||||||
|
|
||||||
QNetworkReply *reply = manager->post(request, nullptr);
|
QNetworkReply *reply = manager->post(request, nullptr);
|
||||||
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||||
|
QObject::connect(reply, &QNetworkReply::errorOccurred, &loop,
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
reply,
|
|
||||||
&QNetworkReply::errorOccurred,
|
|
||||||
&loop,
|
|
||||||
[&loop](QNetworkReply::NetworkError error) -> void
|
[&loop](QNetworkReply::NetworkError error) -> void
|
||||||
{
|
{
|
||||||
loop.quit();
|
loop.quit();
|
||||||
@@ -245,8 +270,6 @@ protected:
|
|||||||
loop.exec();
|
loop.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.clear();
|
|
||||||
|
|
||||||
LOG_ERROR_X(reply->error() != QNetworkReply::NoError,
|
LOG_ERROR_X(reply->error() != QNetworkReply::NoError,
|
||||||
"NewestPacksPaginator::getNetworkReply",
|
"NewestPacksPaginator::getNetworkReply",
|
||||||
reply->errorString().toStdString().c_str(),
|
reply->errorString().toStdString().c_str(),
|
||||||
@@ -256,6 +279,28 @@ protected:
|
|||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief getDocument
|
||||||
|
* Extracts the JSON document from the server reply
|
||||||
|
* @param reply
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
auto getDocument(QNetworkReply *reply) const -> QJsonDocument
|
||||||
|
{
|
||||||
|
QByteArray data = reply->readAll();
|
||||||
|
QJsonParseError documentError;
|
||||||
|
QJsonDocument document = QJsonDocument::fromJson(data, &documentError);
|
||||||
|
|
||||||
|
LOG_ERROR_X(documentError.error != QJsonParseError::NoError,
|
||||||
|
"NewestPacksPaginator::getDocument",
|
||||||
|
documentError.errorString().toStdString().c_str(),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setUri
|
* @brief setUri
|
||||||
* Sets the API Endpoint URI to fetch from
|
* Sets the API Endpoint URI to fetch from
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ class KOMPLEX_EXPORT VideoSearchPaginator : public VideoPaginator
|
|||||||
public:
|
public:
|
||||||
explicit VideoSearchPaginator(QObject *parent = nullptr) : VideoPaginator(parent)
|
explicit VideoSearchPaginator(QObject *parent = nullptr) : VideoPaginator(parent)
|
||||||
{
|
{
|
||||||
setUri(KOMPLEX_ENDPOINT_VIDEOS_SEARCH);
|
setUri(
|
||||||
setQueryable(true);
|
QString::fromUtf8(KOMPLEX_ENDPOINT_VIDEOS_SEARCH)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,9 +30,9 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
|
#include "common/paginator.h"
|
||||||
#include "common/wallpapercache.h"
|
#include "common/wallpapercache.h"
|
||||||
#include "common/coreservices.h"
|
#include "common/coreservices.h"
|
||||||
#include "paginator.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The WallpaperPaginator class
|
* @brief The WallpaperPaginator class
|
||||||
@@ -62,35 +62,35 @@ public:
|
|||||||
return m_uri;
|
return m_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * @brief query
|
* @brief query
|
||||||
// * Current query string, if the API Endpoint supports queries
|
* Current query string, if the API Endpoint supports queries
|
||||||
// * @return
|
* @return
|
||||||
// */
|
*/
|
||||||
// [[nodiscard]]
|
[[nodiscard]]
|
||||||
// auto query() const -> QString
|
auto query() const -> QString
|
||||||
// {
|
{
|
||||||
// return m_query;
|
return m_query;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * @brief setQuery
|
* @brief setQuery
|
||||||
// * Sets the new query string and updates the controller
|
* Sets the new query string and updates the controller
|
||||||
// * @param query
|
* @param query
|
||||||
// */
|
*/
|
||||||
// auto setQuery(const QString &query) -> void
|
auto setQuery(const QString &query) -> void
|
||||||
// {
|
{
|
||||||
// if(query == m_query)
|
if(query == m_query)
|
||||||
// {
|
{
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// m_query = query;
|
m_query = query;
|
||||||
// Q_EMIT queryChanged();
|
Q_EMIT queryChanged();
|
||||||
|
|
||||||
// reset();
|
reset();
|
||||||
// setOffset(0);
|
setOffset(0);
|
||||||
// }
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
@@ -98,6 +98,11 @@ signals:
|
|||||||
*/
|
*/
|
||||||
auto uriChanged() -> void;
|
auto uriChanged() -> void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief queryChanged
|
||||||
|
*/
|
||||||
|
auto queryChanged() -> void;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief fetch
|
* @brief fetch
|
||||||
@@ -120,11 +125,6 @@ protected:
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
if(queryable() && query().isEmpty())
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl url(
|
QUrl url(
|
||||||
QString::fromUtf8("%1/%2/%3").arg(
|
QString::fromUtf8("%1/%2/%3").arg(
|
||||||
KOMPLEX_API_HOST,
|
KOMPLEX_API_HOST,
|
||||||
@@ -139,7 +139,7 @@ protected:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
QByteArray("query"),
|
QByteArray("query"),
|
||||||
query().toUtf8()
|
m_query.toUtf8()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
QByteArray("offset"),
|
QByteArray("offset"),
|
||||||
@@ -248,8 +248,6 @@ protected:
|
|||||||
loop.exec();
|
loop.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.clear();
|
|
||||||
|
|
||||||
LOG_ERROR_X(reply->error() != QNetworkReply::NoError,
|
LOG_ERROR_X(reply->error() != QNetworkReply::NoError,
|
||||||
"NewestPacksPaginator::getNetworkReply",
|
"NewestPacksPaginator::getNetworkReply",
|
||||||
reply->errorString().toStdString().c_str(),
|
reply->errorString().toStdString().c_str(),
|
||||||
@@ -305,11 +303,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
QString m_uri;
|
QString m_uri;
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * @brief m_query
|
* @brief m_query
|
||||||
// * The query string used in fetch operations
|
* The query string used in fetch operations
|
||||||
// */
|
*/
|
||||||
// QString m_query;
|
QString m_query;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WALLPAPERPAGINATOR_H
|
#endif // WALLPAPERPAGINATOR_H
|
||||||
|
|||||||
@@ -1,288 +0,0 @@
|
|||||||
#include "usermodel.h"
|
|
||||||
#include "common/userservices.h"
|
|
||||||
#include <QtConcurrent/qtconcurrentrun.h>
|
|
||||||
#include <qdatetime.h>
|
|
||||||
#include <qfuture.h>
|
|
||||||
#include <qobjectdefs.h>
|
|
||||||
#include <qstringview.h>
|
|
||||||
|
|
||||||
UserModel::UserModel(QObject *parent)
|
|
||||||
: QObject{parent}
|
|
||||||
{
|
|
||||||
m_stateResetTimer = new QTimer(this);
|
|
||||||
m_stateResetTimer->setInterval(1000);
|
|
||||||
m_stateResetTimer->setSingleShot(true);
|
|
||||||
|
|
||||||
QObject::connect
|
|
||||||
(
|
|
||||||
m_stateResetTimer,
|
|
||||||
&QTimer::timeout,
|
|
||||||
this,
|
|
||||||
&UserModel::resetState
|
|
||||||
);
|
|
||||||
|
|
||||||
setState(Busy);
|
|
||||||
|
|
||||||
QSharedPointer<UserServices> service = UserServices::instance();
|
|
||||||
|
|
||||||
if(service == nullptr)
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("UserServices object deleted"));
|
|
||||||
setState(LoginFailure);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFuture<QString> usernameFuture = service->defaultUsername();
|
|
||||||
|
|
||||||
usernameFuture
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this] (const QString username)
|
|
||||||
{
|
|
||||||
login(username);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onCanceled
|
|
||||||
(
|
|
||||||
[this] () -> void
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this] () -> void
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
service.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserModel::~UserModel()
|
|
||||||
{
|
|
||||||
if(m_stateResetTimer != nullptr)
|
|
||||||
{
|
|
||||||
m_stateResetTimer->deleteLater();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserModel::login() -> void
|
|
||||||
{
|
|
||||||
QFuture aether = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this] () -> void
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&m_loginMutex);
|
|
||||||
setState(LoggingIn);
|
|
||||||
|
|
||||||
QSharedPointer<UserServices> service = UserServices::instance();
|
|
||||||
|
|
||||||
if(service == nullptr)
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("UserServices object deleted"));
|
|
||||||
setState(LoginFailure);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_loginAttempt = service->login(username(), password().toUtf8());
|
|
||||||
|
|
||||||
m_loginAttempt
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this] (UserCredentials credentials) -> void
|
|
||||||
{
|
|
||||||
setState(LoggedIn);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onCanceled
|
|
||||||
(
|
|
||||||
[this] () -> void
|
|
||||||
{
|
|
||||||
setState(LoginFailure);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.onFailed
|
|
||||||
(
|
|
||||||
[this] () -> void
|
|
||||||
{
|
|
||||||
setState(LoginCancelled);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserModel::login(const QString username) -> void
|
|
||||||
{
|
|
||||||
if(username == m_username)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_username = username;
|
|
||||||
Q_EMIT usernameChanged();
|
|
||||||
|
|
||||||
QSharedPointer<UserServices> service = UserServices::instance();
|
|
||||||
|
|
||||||
if(service == nullptr)
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("UserServices object deleted"));
|
|
||||||
setState(LoggedOut);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFuture<UserCredentials> tokenRead = service->readToken(username);
|
|
||||||
|
|
||||||
tokenRead
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this] (const UserCredentials credentials) -> void
|
|
||||||
{
|
|
||||||
if(QDateTime::currentDateTime() <= credentials.expiry)
|
|
||||||
{
|
|
||||||
setState(LoggedIn);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSharedPointer<UserServices> service = UserServices::instance();
|
|
||||||
|
|
||||||
if(service == nullptr)
|
|
||||||
{
|
|
||||||
setErrorString(QStringLiteral("UserServices object deleted"));
|
|
||||||
setState(LoggedOut);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFuture<QByteArray> passwordRead = service->readPassword(credentials.username);
|
|
||||||
|
|
||||||
passwordRead
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this] (const QByteArray password)
|
|
||||||
{
|
|
||||||
if(password.isEmpty())
|
|
||||||
{
|
|
||||||
setState(LoggedOut);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setPassword(password);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
service.clear();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
service.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserModel::cancelLogin() -> void
|
|
||||||
{
|
|
||||||
QFuture aether = QtConcurrent::run
|
|
||||||
(
|
|
||||||
[this] () -> void
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&m_loginMutex);
|
|
||||||
|
|
||||||
if(m_loginAttempt.isRunning())
|
|
||||||
{
|
|
||||||
m_loginAttempt.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserModel::reset() -> void
|
|
||||||
{
|
|
||||||
resetState();
|
|
||||||
setUsername({});
|
|
||||||
setPassword({});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserModel::setUsername(const QString &username) -> void
|
|
||||||
{
|
|
||||||
if(username == m_username)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_username = username;
|
|
||||||
Q_EMIT usernameChanged();
|
|
||||||
|
|
||||||
if(!password().isEmpty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(Busy);
|
|
||||||
|
|
||||||
QSharedPointer<UserServices> service = UserServices::instance();
|
|
||||||
|
|
||||||
if(service == nullptr)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFuture<QByteArray> passwordRead = service->readPassword(username);
|
|
||||||
passwordRead
|
|
||||||
.then
|
|
||||||
(
|
|
||||||
[this] (const QByteArray password) -> void
|
|
||||||
{
|
|
||||||
setPassword(password);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserModel::setPassword(const QString &password) -> void
|
|
||||||
{
|
|
||||||
if(password == m_password)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_password = password;
|
|
||||||
Q_EMIT passwordChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserModel::resetState() -> void
|
|
||||||
{
|
|
||||||
setState(Idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserModel::setState(State state) -> void
|
|
||||||
{
|
|
||||||
if(state == m_state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(state)
|
|
||||||
{
|
|
||||||
case LoginFailure:
|
|
||||||
case LoggedOut:
|
|
||||||
case LoginCancelled:
|
|
||||||
m_stateResetTimer->start();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
|
||||||
Q_EMIT stateChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto UserModel::setErrorString(const QString &string) -> void
|
|
||||||
{
|
|
||||||
if(string == m_errorString)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_errorString = string;
|
|
||||||
Q_EMIT errorStringChanged();
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
#ifndef USERMODEL_H
|
|
||||||
#define USERMODEL_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QMutex>
|
|
||||||
#include <QMutexLocker>
|
|
||||||
#include <qqmlintegration.h>
|
|
||||||
#include "common/userservices.h"
|
|
||||||
|
|
||||||
class UserModel : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
QML_ELEMENT
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum State
|
|
||||||
{
|
|
||||||
Idle,
|
|
||||||
LoggingIn,
|
|
||||||
LoggedIn,
|
|
||||||
LoginFailure,
|
|
||||||
LoginCancelled,
|
|
||||||
LoggedOut,
|
|
||||||
Busy
|
|
||||||
};
|
|
||||||
Q_ENUM(State)
|
|
||||||
|
|
||||||
explicit UserModel(QObject *parent = nullptr);
|
|
||||||
~UserModel();
|
|
||||||
|
|
||||||
Q_INVOKABLE auto login() -> void;
|
|
||||||
Q_INVOKABLE auto login(const QString username) -> void;
|
|
||||||
Q_INVOKABLE auto cancelLogin() -> void;
|
|
||||||
Q_INVOKABLE auto reset() -> void;
|
|
||||||
|
|
||||||
auto username() const -> const QString & { return m_username; }
|
|
||||||
auto setUsername(const QString &username) -> void;
|
|
||||||
|
|
||||||
auto password() const -> const QString & { return m_password; }
|
|
||||||
auto setPassword(const QString &password) -> void;
|
|
||||||
|
|
||||||
auto state() const -> State { return m_state; }
|
|
||||||
auto errorString() const -> QString { return m_errorString; }
|
|
||||||
|
|
||||||
signals:
|
|
||||||
auto loginSuccessful() -> void;
|
|
||||||
auto loginFailed() -> void;
|
|
||||||
auto stateChanged() -> void;
|
|
||||||
auto usernameChanged() -> void;
|
|
||||||
auto passwordChanged() -> void;
|
|
||||||
auto errorStringChanged() -> void;
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
auto resetState() -> void;
|
|
||||||
|
|
||||||
private:
|
|
||||||
auto setState(State state) -> void;
|
|
||||||
auto setErrorString(const QString &string) -> void;
|
|
||||||
|
|
||||||
State m_state = Idle;
|
|
||||||
QString m_errorString;
|
|
||||||
QString m_username;
|
|
||||||
QString m_password;
|
|
||||||
QTimer *m_stateResetTimer = nullptr;
|
|
||||||
QMutex m_loginMutex;
|
|
||||||
QFuture<UserCredentials> m_loginAttempt;
|
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state NOTIFY stateChanged FINAL)
|
|
||||||
Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY usernameChanged FINAL)
|
|
||||||
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged FINAL)
|
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // USERMODEL_H
|
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
#include "videoitemmodel.h"
|
|
||||||
|
|
||||||
VideoItemModel::VideoItemModel(QObject *parent) : QAbstractListModel{parent}
|
|
||||||
{
|
|
||||||
QObject::connect(
|
|
||||||
this,
|
|
||||||
&VideoItemModel::dataEntryChanged,
|
|
||||||
this,
|
|
||||||
&VideoItemModel::resetDataModel
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::rowCount(const QModelIndex &) const -> int
|
|
||||||
{
|
|
||||||
return m_dataEntry.files.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::data(const QModelIndex &index, int role) const -> QVariant
|
|
||||||
{
|
|
||||||
if(!boundaryCheck(index.row()))
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoEntry dataPoint = m_dataEntry.files.at(index.row());
|
|
||||||
|
|
||||||
QVariant data;
|
|
||||||
|
|
||||||
switch(static_cast<DataRole>(role))
|
|
||||||
{
|
|
||||||
case UuidRole:
|
|
||||||
data = dataPoint.id;
|
|
||||||
break;
|
|
||||||
case UrlRole:
|
|
||||||
data = dataPoint.url;
|
|
||||||
break;
|
|
||||||
case HeightRole:
|
|
||||||
data = dataPoint.height;
|
|
||||||
break;
|
|
||||||
case WidthRole:
|
|
||||||
data = dataPoint.width;
|
|
||||||
break;
|
|
||||||
case FileTypeRole:
|
|
||||||
data = dataPoint.type;
|
|
||||||
break;
|
|
||||||
case FpsRole:
|
|
||||||
data = dataPoint.fps;
|
|
||||||
break;
|
|
||||||
case SizeRole:
|
|
||||||
data = dataPoint.size;
|
|
||||||
break;
|
|
||||||
case QualityRole:
|
|
||||||
data = dataPoint.quality;
|
|
||||||
break;
|
|
||||||
case TextRole:
|
|
||||||
data = friendlyText(dataPoint);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::index(int row, int column, const QModelIndex &parent) const -> QModelIndex
|
|
||||||
{
|
|
||||||
Q_UNUSED(parent)
|
|
||||||
|
|
||||||
if(!boundaryCheck(row))
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex(row, column, &m_dataEntry.files[row]);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::columnCount(const QModelIndex &) const -> int
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::parent(const QModelIndex &) const -> QModelIndex
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::setData(const QModelIndex &, const QVariant &, int) -> bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::state() const -> VideoItemModel::State
|
|
||||||
{
|
|
||||||
return m_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::setState(State state) -> void
|
|
||||||
{
|
|
||||||
if (m_state == state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
|
||||||
emit stateChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::resetState() -> void
|
|
||||||
{
|
|
||||||
setState(Idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::resetDataModel() -> void
|
|
||||||
{
|
|
||||||
if(m_lastCount > 0)
|
|
||||||
{
|
|
||||||
//invalidate previous model data
|
|
||||||
beginRemoveRows(QModelIndex(), 0, m_lastCount - 1);
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_lastCount = m_dataEntry.files.count();
|
|
||||||
|
|
||||||
//signal new data
|
|
||||||
beginInsertRows(QModelIndex(), 0, m_dataEntry.files.count() - 1);
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::boundaryCheck(qsizetype index) const -> bool
|
|
||||||
{
|
|
||||||
if(index < 0 || index >= m_dataEntry.files.count())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::setDataEntry(const VideoCache &entry) -> void
|
|
||||||
{
|
|
||||||
if(entry == m_dataEntry)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_dataEntry = entry;
|
|
||||||
Q_EMIT dataEntryChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::friendlyText(const VideoEntry &video) const -> QString
|
|
||||||
{
|
|
||||||
qint64 size = video.size;
|
|
||||||
qint64 sizeIndex = 0;
|
|
||||||
|
|
||||||
while(size >= 1000)
|
|
||||||
{
|
|
||||||
size = static_cast<qint64>(std::ceil(static_cast<qreal>(size) / 1000));
|
|
||||||
++sizeIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!video.quality.isEmpty())
|
|
||||||
{
|
|
||||||
return QString("%1/%2 [%3x%4 %5FPS] (%6%7)").arg
|
|
||||||
(
|
|
||||||
video.quality.toUpper(),
|
|
||||||
video.type.toUpper(),
|
|
||||||
QString::number(video.width),
|
|
||||||
QString::number(video.height),
|
|
||||||
QString::number(video.fps),
|
|
||||||
QString::number(size),
|
|
||||||
m_sizeTexts[sizeIndex]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString("%1 [%2x%3 %4FPS] (%5%6)").arg
|
|
||||||
(
|
|
||||||
video.type.toUpper(),
|
|
||||||
QString::number(video.width),
|
|
||||||
QString::number(video.height),
|
|
||||||
QString::number(video.fps),
|
|
||||||
QString::number(size),
|
|
||||||
m_sizeTexts[sizeIndex]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::roleNames() const -> QHash<int, QByteArray>
|
|
||||||
{
|
|
||||||
return m_dataRoles;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::errorString() const -> QString
|
|
||||||
{
|
|
||||||
return m_errorString;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto VideoItemModel::setErrorString(const QString &errorString) -> void
|
|
||||||
{
|
|
||||||
if (m_errorString == errorString)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_errorString = errorString;
|
|
||||||
emit errorStringChanged();
|
|
||||||
}
|
|
||||||
@@ -1,294 +0,0 @@
|
|||||||
/*
|
|
||||||
* Komplex Wallpaper Engine
|
|
||||||
* Copyright (C) 2026 @DigitalArtifex
|
|
||||||
* https://digitalartifex.dev - https://github.com/DigitalArtifex
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
#ifndef VideoItemModel_H
|
|
||||||
#define VideoItemModel_H
|
|
||||||
#include <QObject>
|
|
||||||
#include <QQmlEngine>
|
|
||||||
#include <QList>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QJsonParseError>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QAbstractListModel>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QEventLoop>
|
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
|
||||||
|
|
||||||
#include "common/komplex_global.h"
|
|
||||||
#include "common/videocache.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The VideoItemModel class
|
|
||||||
*/
|
|
||||||
class KOMPLEX_EXPORT VideoItemModel : public QAbstractListModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
QML_ELEMENT
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Used to control the UI state
|
|
||||||
*/
|
|
||||||
enum State
|
|
||||||
{
|
|
||||||
Idle,
|
|
||||||
Loading,
|
|
||||||
Error
|
|
||||||
};
|
|
||||||
Q_ENUM(State)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data roles used by the view to request data
|
|
||||||
*/
|
|
||||||
enum DataRole {
|
|
||||||
UuidRole = Qt::UserRole + 1,
|
|
||||||
FileTypeRole,
|
|
||||||
FpsRole,
|
|
||||||
HeightRole,
|
|
||||||
WidthRole,
|
|
||||||
SizeRole,
|
|
||||||
UrlRole,
|
|
||||||
QualityRole,
|
|
||||||
TextRole
|
|
||||||
};
|
|
||||||
Q_ENUM(DataRole)
|
|
||||||
|
|
||||||
explicit VideoItemModel(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief data
|
|
||||||
* Used by the view to pull data from the model.
|
|
||||||
* Required by QAbstractListModel
|
|
||||||
* @param index
|
|
||||||
* @param role
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto data(
|
|
||||||
const QModelIndex &index,
|
|
||||||
int role = Qt::DisplayRole
|
|
||||||
) const -> QVariant override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief index
|
|
||||||
* Used by the view to create an index for the data point.
|
|
||||||
* Required by QAbstractListModel
|
|
||||||
* @param row
|
|
||||||
* @param column
|
|
||||||
* @param parent
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto index(
|
|
||||||
int row,
|
|
||||||
int column,
|
|
||||||
const QModelIndex &parent = QModelIndex()
|
|
||||||
) const -> QModelIndex override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief columnCount
|
|
||||||
* Required by QAbstractListModel, but just returns 0
|
|
||||||
* since we dont use cols
|
|
||||||
* @param parent
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto columnCount(
|
|
||||||
const QModelIndex &parent = QModelIndex()
|
|
||||||
) const -> int override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief parent
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto parent(const QModelIndex &index) const -> QModelIndex override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setData
|
|
||||||
* Required by QAbstractListModel but not used
|
|
||||||
* @param index
|
|
||||||
* @param value
|
|
||||||
* @param role
|
|
||||||
* @return true always
|
|
||||||
*/
|
|
||||||
auto setData(
|
|
||||||
const QModelIndex &index,
|
|
||||||
const QVariant &value,
|
|
||||||
int role = Qt::EditRole
|
|
||||||
) -> bool override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief state
|
|
||||||
* Current Model State
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto state() const -> State;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief roleNames
|
|
||||||
* Used to tell the view what data roles are available
|
|
||||||
* and their QML friendly names
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto roleNames() const -> QHash<int, QByteArray> override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorString
|
|
||||||
* User-friendly error string to be reported to the user
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto errorString() const -> QString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setDataEntry
|
|
||||||
* Set the dataEntry from the Search or List model
|
|
||||||
* @param entry
|
|
||||||
*/
|
|
||||||
auto setDataEntry(const VideoCache &entry) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief friendlyText
|
|
||||||
* Generates the friendly text for comboboxes and the like
|
|
||||||
* @param video
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto friendlyText(const VideoEntry &video) const -> QString;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setErrorString
|
|
||||||
* @param errorString
|
|
||||||
*/
|
|
||||||
auto setErrorString(const QString &errorString) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief setState
|
|
||||||
* @param state
|
|
||||||
*/
|
|
||||||
auto setState(State state) -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetState
|
|
||||||
*/
|
|
||||||
auto resetState() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief resetDataModel
|
|
||||||
* Clears the data model and creates a new one if data exists
|
|
||||||
*/
|
|
||||||
auto resetDataModel() -> void;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
auto dataEntryChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief stateChanged
|
|
||||||
* Signaled when reported state changes
|
|
||||||
*/
|
|
||||||
auto stateChanged() -> void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief errorStringChanged
|
|
||||||
* Signaled when reported error message changes
|
|
||||||
*/
|
|
||||||
auto errorStringChanged() -> void;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* @brief boundaryCheck
|
|
||||||
* Helper function to check the requested index boundary
|
|
||||||
* @param index
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
auto boundaryCheck(qsizetype index) const -> bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Size texts used in friendlyText()
|
|
||||||
*/
|
|
||||||
QStringList m_sizeTexts
|
|
||||||
{
|
|
||||||
QString::fromUtf8("B"),
|
|
||||||
QString::fromUtf8("KB"),
|
|
||||||
QString::fromUtf8("MB"),
|
|
||||||
QString::fromUtf8("GB")
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data role map that connects VideoItemModel::DataRole to it's QML accessor name
|
|
||||||
*/
|
|
||||||
static inline const QHash<int, QByteArray> m_dataRoles =
|
|
||||||
{
|
|
||||||
{
|
|
||||||
static_cast<int>(UuidRole),
|
|
||||||
QByteArray("uuid")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(FileTypeRole),
|
|
||||||
QByteArray("fileType")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(FpsRole),
|
|
||||||
QByteArray("fps")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(HeightRole),
|
|
||||||
QByteArray("height")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(WidthRole),
|
|
||||||
QByteArray("width")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(SizeRole),
|
|
||||||
QByteArray("size")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(UrlRole),
|
|
||||||
QByteArray("url")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(QualityRole),
|
|
||||||
QByteArray("quality")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
static_cast<int>(TextRole),
|
|
||||||
QByteArray("text")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
State m_state = Idle;
|
|
||||||
QString m_errorString = QString();
|
|
||||||
|
|
||||||
VideoCache m_dataEntry;
|
|
||||||
qint64 m_lastCount = 0;
|
|
||||||
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState RESET resetState NOTIFY stateChanged FINAL)
|
|
||||||
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged FINAL)
|
|
||||||
};
|
|
||||||
Q_DECLARE_METATYPE(VideoItemModel)
|
|
||||||
|
|
||||||
#endif // VideoItemModel_H
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user