Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a7f85e5ad | |||
| cb4985b291 | |||
| b8f437c203 | |||
| 66cc7beb41 | |||
| 63850186fd | |||
| f73b26a9cc | |||
| 59a2204386 |
+29
-1
@@ -8,4 +8,32 @@ 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)
|
||||||
|
message(STATUS "Building with AddressSanitizer")
|
||||||
|
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
|
||||||
|
message(FATAL_ERROR "ASan supported only with Clang/GCC")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -fsanitize=address -fno-omit-frame-pointer)
|
||||||
|
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -fsanitize=address)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_CLANG_TIDY)
|
||||||
|
if(NOT DEFINED CLANG_TIDY)
|
||||||
|
if(DEFINED ENV{CLANG_TIDY})
|
||||||
|
set(CLANG_TIDY $ENV{CLANG_TIDY})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_program(CLANG_TIDY_EXE NAMES ${CLANG_TIDY} clang-tidy)
|
||||||
|
if(CLANG_TIDY_EXE)
|
||||||
|
message(STATUS "Plugin Found clang-tidy: ${CLANG_TIDY_EXE}")
|
||||||
|
else()
|
||||||
|
message(STATUS "clang-tidy not found")
|
||||||
|
endif()
|
||||||
|
if(CLANG_TIDY_EXE)
|
||||||
|
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-checks=modernize-*,performance-*,readability-*,header-filter=.*;--warnings-as-errors=*;--extra-arg=-Qunused-arguments")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
+3
-1
@@ -10,6 +10,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOU
|
|||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_AUTORCC ON)
|
set(CMAKE_AUTORCC ON)
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
@@ -22,7 +23,8 @@ set(QML_IMPORT_PATH ${QT_QML_OUTPUT_DIRECTORY}
|
|||||||
find_package(Qt6 6.8 REQUIRED COMPONENTS Core Gui Widgets Qml Quick QuickControls2 QuickTimeline ShaderTools)
|
find_package(Qt6 6.8 REQUIRED COMPONENTS Core Gui Widgets Qml Quick QuickControls2 QuickTimeline ShaderTools)
|
||||||
qt_standard_project_setup()
|
qt_standard_project_setup()
|
||||||
|
|
||||||
qt_add_executable(${CMAKE_PROJECT_NAME})
|
qt_add_executable(${CMAKE_PROJECT_NAME}
|
||||||
|
README.md)
|
||||||
qt_add_resources(${CMAKE_PROJECT_NAME} "configuration"
|
qt_add_resources(${CMAKE_PROJECT_NAME} "configuration"
|
||||||
PREFIX "/"
|
PREFIX "/"
|
||||||
FILES
|
FILES
|
||||||
|
|||||||
@@ -10,15 +10,56 @@ qt_add_qml_module(
|
|||||||
VERSION
|
VERSION
|
||||||
1.0
|
1.0
|
||||||
SOURCES
|
SOURCES
|
||||||
SettingsManager.h
|
settingsmanager.h
|
||||||
SettingsManager.cpp
|
settingsmanager.cpp
|
||||||
InstalledPackManager.h
|
installedpackmanager.h
|
||||||
InstalledPackManager.cpp
|
installedpackmanager.cpp
|
||||||
SOURCES WallpaperMetaData.h
|
common/wallpapercache.h
|
||||||
|
newestpacksmodel.h
|
||||||
|
newestpacksmodel.cpp
|
||||||
|
common/komplex_global.h
|
||||||
|
common/slidingcachecontroller.h
|
||||||
|
common/slidingcachecontroller.cpp
|
||||||
|
common/paginator.h
|
||||||
|
common/paginator.cpp
|
||||||
|
common/coreservices.h
|
||||||
|
common/coreservices.cpp
|
||||||
|
common/logging.h
|
||||||
|
common/fetchresult.h
|
||||||
|
paginators/newestpackspaginator.h
|
||||||
|
paginators/newestpackspaginator.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(
|
target_compile_definitions(
|
||||||
KomplexHubPlugin
|
KomplexHubPlugin
|
||||||
PUBLIC
|
PUBLIC
|
||||||
KOMPLEX_PLUGIN
|
KOMPLEX_PLUGIN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_ASAN)
|
||||||
|
message(STATUS "Building with AddressSanitizer")
|
||||||
|
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
|
||||||
|
message(FATAL_ERROR "ASan supported only with Clang/GCC")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_compile_options(KomplexHubPlugin PRIVATE -fsanitize=address -fno-omit-frame-pointer)
|
||||||
|
target_link_options(KomplexHubPlugin PRIVATE -fsanitize=address)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_CLANG_TIDY)
|
||||||
|
if(NOT DEFINED CLANG_TIDY)
|
||||||
|
if(DEFINED ENV{CLANG_TIDY})
|
||||||
|
set(CLANG_TIDY $ENV{CLANG_TIDY})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_program(CLANG_TIDY_EXE NAMES ${CLANG_TIDY} clang-tidy)
|
||||||
|
if(CLANG_TIDY_EXE)
|
||||||
|
message(STATUS "Plugin Found clang-tidy: ${CLANG_TIDY_EXE}")
|
||||||
|
else()
|
||||||
|
message(STATUS "clang-tidy not found")
|
||||||
|
endif()
|
||||||
|
if(CLANG_TIDY_EXE)
|
||||||
|
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-checks=modernize-*,performance-*,readability-*,header-filter=.*;--warnings-as-errors=*;--extra-arg=-Qunused-arguments")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#ifndef WALLPAPERMETADATA_H
|
|
||||||
#define WALLPAPERMETADATA_H
|
|
||||||
|
|
||||||
#include "Komplex_global.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QDateTime>
|
|
||||||
|
|
||||||
struct KOMPLEX_EXPORT WallpaperMetaData {
|
|
||||||
QString uri;
|
|
||||||
QString name;
|
|
||||||
QString author;
|
|
||||||
QString description;
|
|
||||||
QString thumbnail;
|
|
||||||
QDateTime installDate;
|
|
||||||
};
|
|
||||||
Q_DECLARE_METATYPE(WallpaperMetaData)
|
|
||||||
|
|
||||||
#endif // WALLPAPERMETADATA_H
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include "coreservices.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
QNetworkAccessManager *CoreServices::m_networkAccessManager = new QNetworkAccessManager();
|
||||||
|
|
||||||
|
auto CoreServices::networkAccessManager() -> QNetworkAccessManager *
|
||||||
|
{
|
||||||
|
return m_networkAccessManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CoreServices::sessionToken() -> QByteArray
|
||||||
|
{
|
||||||
|
LOG_ERROR_X(true,
|
||||||
|
"CoreServices::sessionToken",
|
||||||
|
"User services not yet implements",
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef CORESERVICES_H
|
||||||
|
#define CORESERVICES_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
|
||||||
|
class CoreServices
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief networkAccessManager
|
||||||
|
* Plugin-wide QNetworkAccessManager
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static auto networkAccessManager() -> QNetworkAccessManager*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief getSessionToken
|
||||||
|
* Plugin-wide access to current user session token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static auto sessionToken() -> QByteArray;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static QNetworkAccessManager *m_networkAccessManager;
|
||||||
|
};
|
||||||
|
#endif // CORESERVICES_H
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef FETCHRESULT_H
|
||||||
|
#define FETCHRESULT_H
|
||||||
|
#include <qtypes.h>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct FetchResult
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief total
|
||||||
|
* Total number of results in the query
|
||||||
|
*/
|
||||||
|
qsizetype total = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief count
|
||||||
|
* Number of results returned in this result
|
||||||
|
*/
|
||||||
|
qsizetype count = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief results
|
||||||
|
* Results list
|
||||||
|
*/
|
||||||
|
QList<T*> data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FETCHRESULT_H
|
||||||
@@ -7,4 +7,9 @@
|
|||||||
#define KOMPLEX_EXPORT Q_DECL_IMPORT
|
#define KOMPLEX_EXPORT Q_DECL_IMPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // KOMPLEX_GLOBAL_H
|
#define SLIDING_CACHE_WINDOW_SIZE 100
|
||||||
|
#define SLIDING_CACHE_PREFETCH_THRESHOLD 20
|
||||||
|
|
||||||
|
#define NETWORK_TIMEOUT 10000
|
||||||
|
|
||||||
|
#endif // KOMPLEX_GLOBAL_H
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#ifndef LOGGING_H
|
||||||
|
#define LOGGING_H
|
||||||
|
// clazy:exclude=clazy-unused-headers
|
||||||
|
|
||||||
|
#include <iostream> // NOLINT(clazy-unused-headers)
|
||||||
|
#include <cstdlib> // NOLINT(clazy-unused-headers)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LOG_ERROR
|
||||||
|
*
|
||||||
|
* When cond is true, logs where and what as an error
|
||||||
|
* @param cond
|
||||||
|
* @param where
|
||||||
|
* @param what
|
||||||
|
*/
|
||||||
|
#define LOG_ERROR(cond, where, what) \
|
||||||
|
do { \
|
||||||
|
if ((cond)) { \
|
||||||
|
std::cerr << "Assertion failed: (" << #cond << ")\n" \
|
||||||
|
<< " Location: " << (where) << "\n" \
|
||||||
|
<< " Message: " << (what) << "\n" \
|
||||||
|
<< " File: " << __FILE__ << ":" << __LINE__ << "\n"; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define LOG_ERROR_X(cond, where, what, ret) \
|
||||||
|
do { \
|
||||||
|
if ((cond)) { \
|
||||||
|
std::cout << "Assertion failed: (" << #cond << ")\n" \
|
||||||
|
<< " Location: " << (where) << "\n" \
|
||||||
|
<< " Message: " << (what) << "\n" \
|
||||||
|
<< " File: " << __FILE__ << ":" << __LINE__ << "\n"; \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#ifndef ASSERT_X
|
||||||
|
#define ASSERT_X(cond, where, what) \
|
||||||
|
do { \
|
||||||
|
if (!(cond)) { \
|
||||||
|
std::cout << "Assertion failed: (" << #cond << ")\n" \
|
||||||
|
<< " Location: " << (where) << "\n" \
|
||||||
|
<< " Message: " << (what) << "\n" \
|
||||||
|
<< " File: " << __FILE__ << ":" << __LINE__ << "\n"; \
|
||||||
|
std::abort(); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#endif
|
||||||
|
#endif // LOGGING_H
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
#ifndef PAGINATOR_H
|
||||||
|
#define PAGINATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "komplex_global.h"
|
||||||
|
#include "slidingcachecontroller.h"
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class KOMPLEX_EXPORT Paginator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Paginator() = default;
|
||||||
|
~Paginator() = default;
|
||||||
|
|
||||||
|
auto next() const -> void
|
||||||
|
{
|
||||||
|
setOffset(m_offset + m_resultsPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto previous() const -> void
|
||||||
|
{
|
||||||
|
setOffset(m_offset - m_resultsPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto resultsPerPage() const -> qsizetype
|
||||||
|
{
|
||||||
|
return m_resultsPerPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto setResultsPerPage(qsizetype resultsPerPage) -> void
|
||||||
|
{
|
||||||
|
m_resultsPerPage = resultsPerPage;
|
||||||
|
m_data = m_cacheController.chunk(m_offset, m_resultsPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data() const -> QList<T*>
|
||||||
|
{
|
||||||
|
return m_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto count() const -> qsizetype
|
||||||
|
{
|
||||||
|
return m_data.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto at(qsizetype index) const -> T*
|
||||||
|
{
|
||||||
|
if(index < 0 || index >= m_data.count())
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_data.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto controller() -> SlidingCacheController<T>*
|
||||||
|
{
|
||||||
|
return &m_cacheController;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto offset() const -> qsizetype
|
||||||
|
{
|
||||||
|
return m_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto setOffset(qsizetype offset) -> void
|
||||||
|
{
|
||||||
|
m_offset = offset;
|
||||||
|
|
||||||
|
if(m_offset < 0 || m_offset == std::numeric_limits<qsizetype>::max())
|
||||||
|
m_offset = 0;
|
||||||
|
|
||||||
|
m_data = m_cacheController.chunk(m_offset, m_resultsPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
qsizetype m_offset = 0;
|
||||||
|
qsizetype m_resultsPerPage = 0;
|
||||||
|
|
||||||
|
SlidingCacheController<T> m_cacheController;
|
||||||
|
QList<T*> m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PAGINATOR_H
|
||||||
@@ -0,0 +1,284 @@
|
|||||||
|
#ifndef SLIDINGCACHECONTROLLER_H
|
||||||
|
#define SLIDINGCACHECONTROLLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QList>
|
||||||
|
#include <functional>
|
||||||
|
#include "fetchresult.h"
|
||||||
|
#include "komplex_global.h"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class KOMPLEX_EXPORT SlidingCacheController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit SlidingCacheController()
|
||||||
|
{
|
||||||
|
m_cache.reserve(SLIDING_CACHE_WINDOW_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
~SlidingCacheController()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setFetch
|
||||||
|
* Used to set the fetch method for the cache controller. Method should return a QList
|
||||||
|
* of CacheObjects based on the offset and limit provided. CacheObject must derive from
|
||||||
|
* QObject
|
||||||
|
*
|
||||||
|
* @param fetch
|
||||||
|
*/
|
||||||
|
auto setFetch(
|
||||||
|
const std::function<FetchResult<T> (qsizetype offset, qsizetype limit)> &fetch
|
||||||
|
) -> void
|
||||||
|
{
|
||||||
|
m_fetch = std::move(fetch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief at
|
||||||
|
* Retrieves the CacheObject reference at the specified index. If data is outside the
|
||||||
|
* current window, a fetch will be attempted
|
||||||
|
* @param index
|
||||||
|
* @return CacheObject* or nullptr
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
auto at(qsizetype index) const -> T*
|
||||||
|
{
|
||||||
|
//OOB check for expected index
|
||||||
|
if (index < 0 ||
|
||||||
|
(m_totalCount != std::numeric_limits<qsizetype>::infinity() &&
|
||||||
|
index >= m_totalCount))
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (index >= m_windowOffset + (SLIDING_CACHE_WINDOW_SIZE - SLIDING_CACHE_PREFETCH_THRESHOLD))
|
||||||
|
{
|
||||||
|
if(!slideForward())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (index <= m_windowOffset - (SLIDING_CACHE_WINDOW_SIZE - SLIDING_CACHE_PREFETCH_THRESHOLD))
|
||||||
|
{
|
||||||
|
if(!slideBackward())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
index = trueIndex(index);
|
||||||
|
|
||||||
|
//OOB check for actual index
|
||||||
|
if(index < 0 || index >= m_cache.count())
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_cache.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief chunk
|
||||||
|
* Returns a chunk of data from cache. If data is outside the current window, a
|
||||||
|
* fetch will be attempted
|
||||||
|
* @param index
|
||||||
|
* @param count
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
auto chunk(qsizetype index, qsizetype count) -> QList<T*>
|
||||||
|
{
|
||||||
|
QList<T*> dataChunk;
|
||||||
|
|
||||||
|
for(qsizetype i = index; i < count; ++i)
|
||||||
|
{
|
||||||
|
T* data = at(i);
|
||||||
|
|
||||||
|
if(data == nullptr)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dataChunk.append(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief count
|
||||||
|
*
|
||||||
|
* @return The total number of results available
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
auto count() const -> qsizetype
|
||||||
|
{
|
||||||
|
return m_totalCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief clear
|
||||||
|
* Clears the current cache
|
||||||
|
*/
|
||||||
|
auto clear() -> void
|
||||||
|
{
|
||||||
|
while(!m_cache.isEmpty())
|
||||||
|
{
|
||||||
|
T *object = m_cache.takeFirst();
|
||||||
|
delete object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief slideForward
|
||||||
|
* Attempts to slide the cache window forward
|
||||||
|
* @return true if successful
|
||||||
|
*/
|
||||||
|
auto slideForward() -> bool
|
||||||
|
{
|
||||||
|
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE;
|
||||||
|
|
||||||
|
//after initial inflation we should only arrive here when the prefetch threshold is reached
|
||||||
|
if(!m_cache.isEmpty())
|
||||||
|
{
|
||||||
|
movementSize -= SLIDING_CACHE_PREFETCH_THRESHOLD;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_windowOffset += movementSize;
|
||||||
|
|
||||||
|
QList<T*> newCache = m_fetch(
|
||||||
|
m_windowOffset,
|
||||||
|
movementSize
|
||||||
|
);
|
||||||
|
|
||||||
|
if(newCache.isEmpty())
|
||||||
|
{
|
||||||
|
m_windowOffset -= movementSize;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!newCache.isEmpty() && !m_cache.isEmpty())
|
||||||
|
{
|
||||||
|
T *object = newCache.takeFirst();
|
||||||
|
T *oldObject = m_cache.takeFirst();
|
||||||
|
|
||||||
|
delete oldObject;
|
||||||
|
m_cache.append(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!newCache.isEmpty())
|
||||||
|
{
|
||||||
|
LOG_ERROR_X((newCache.count() + m_cache.count()) > SLIDING_CACHE_WINDOW_SIZE,
|
||||||
|
"SlidingCacheController::slideForward",
|
||||||
|
"Cache size imbalance",
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
m_cache.append(newCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief slideBackward
|
||||||
|
* Attempts to slide the cache window backward
|
||||||
|
* @return true if successful
|
||||||
|
*/
|
||||||
|
auto slideBackward() -> bool
|
||||||
|
{
|
||||||
|
LOG_ERROR_X(!m_fetch,
|
||||||
|
"SlidingCacheController::slideBackward",
|
||||||
|
"Fetch function not set",
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
qsizetype movementSize = SLIDING_CACHE_WINDOW_SIZE - SLIDING_CACHE_PREFETCH_THRESHOLD;
|
||||||
|
m_windowOffset -= movementSize;
|
||||||
|
|
||||||
|
if(m_windowOffset < 0)
|
||||||
|
{
|
||||||
|
m_windowOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FetchResult<T> result = m_fetch(
|
||||||
|
m_windowOffset,
|
||||||
|
movementSize
|
||||||
|
);
|
||||||
|
|
||||||
|
if(result.count == 0)
|
||||||
|
{
|
||||||
|
m_windowOffset += movementSize;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!result.data.isEmpty() && !m_cache.isEmpty())
|
||||||
|
{
|
||||||
|
T *object = result.data.takeLast();
|
||||||
|
T *oldObject = m_cache.takeLast();
|
||||||
|
|
||||||
|
delete oldObject;
|
||||||
|
m_cache.push_front(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!result.results.isEmpty())
|
||||||
|
{
|
||||||
|
LOG_ERROR_X((result.count + m_cache.count()) > SLIDING_CACHE_WINDOW_SIZE,
|
||||||
|
"SlidingCacheController::slideBackward",
|
||||||
|
"Cache size imbalance",
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
m_cache.push_front(std::move(result.data));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief trueIndex
|
||||||
|
* Translates the global object index to the current cache index
|
||||||
|
* @param index Global object index
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
auto trueIndex(qsizetype index) -> qsizetype
|
||||||
|
{
|
||||||
|
return index - m_windowOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief m_windowOffset
|
||||||
|
* Current window offset
|
||||||
|
*/
|
||||||
|
qsizetype m_windowOffset = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief m_totalCount
|
||||||
|
* Total number of results available. Data comes from the return data of
|
||||||
|
* m_fetch
|
||||||
|
*/
|
||||||
|
qsizetype m_totalCount = std::numeric_limits<qsizetype>::infinity();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief m_fetch
|
||||||
|
* The fetch function for retreiving external data. This must be set by the paginator
|
||||||
|
* or other controller class for the cachecontroller to work
|
||||||
|
*/
|
||||||
|
std::function<FetchResult<T>(qsizetype offset, qsizetype limit)> m_fetch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief m_cache
|
||||||
|
* The working cache
|
||||||
|
*/
|
||||||
|
QVector<T*> m_cache;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SLIDINGCACHECONTROLLER_H
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef WALLPAPERCACHE_H
|
||||||
|
#define WALLPAPERCACHE_H
|
||||||
|
|
||||||
|
#include "komplex_global.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
struct KOMPLEX_EXPORT WallpaperInstallData
|
||||||
|
{
|
||||||
|
QString uri;
|
||||||
|
QString name;
|
||||||
|
QString author;
|
||||||
|
QString description;
|
||||||
|
QString thumbnail;
|
||||||
|
QDateTime installDate;
|
||||||
|
};
|
||||||
|
Q_DECLARE_METATYPE(WallpaperInstallData)
|
||||||
|
|
||||||
|
struct KOMPLEX_EXPORT WallpaperCache
|
||||||
|
{
|
||||||
|
QString uri;
|
||||||
|
QString name;
|
||||||
|
QString author;
|
||||||
|
QString authorId;
|
||||||
|
QString description;
|
||||||
|
QString thumbnail;
|
||||||
|
QDateTime createdDate;
|
||||||
|
qreal price = 0;
|
||||||
|
QString currency;
|
||||||
|
quint64 downloadCount = 0;
|
||||||
|
qint8 type = -1;
|
||||||
|
};
|
||||||
|
Q_DECLARE_METATYPE(WallpaperCache)
|
||||||
|
|
||||||
|
#endif // WALLPAPERCACHE_H
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
#include "InstalledPackManager.h"
|
#include "installedpackmanager.h"
|
||||||
|
|
||||||
InstalledPackManager::InstalledPackManager(QObject *parent)
|
InstalledPackManager::InstalledPackManager(QObject *parent)
|
||||||
: QAbstractListModel{parent}
|
: QAbstractListModel{parent}
|
||||||
@@ -100,7 +100,7 @@ auto InstalledPackManager::setData(const QModelIndex &index, const QVariant &val
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto InstalledPackManager::installedWallpapers() const -> QList<WallpaperMetaData>
|
auto InstalledPackManager::installedWallpapers() const -> QList<WallpaperInstallData>
|
||||||
{
|
{
|
||||||
return m_installedWallpapers;
|
return m_installedWallpapers;
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ auto InstalledPackManager::rescan() -> void
|
|||||||
|
|
||||||
QFileInfo packFileInfo(packFile);
|
QFileInfo packFileInfo(packFile);
|
||||||
|
|
||||||
WallpaperMetaData data
|
WallpaperInstallData data
|
||||||
{
|
{
|
||||||
packDirectory.absoluteFilePath(QString("pack.json")),
|
packDirectory.absoluteFilePath(QString("pack.json")),
|
||||||
rootObject["name"].toString(),
|
rootObject["name"].toString(),
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
#include "WallpaperMetaData.h"
|
#include "common/wallpapercache.h"
|
||||||
|
|
||||||
class InstalledPackManager : public QAbstractListModel
|
class InstalledPackManager : public QAbstractListModel
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
int role = Qt::EditRole
|
int role = Qt::EditRole
|
||||||
) -> bool override;
|
) -> bool override;
|
||||||
|
|
||||||
auto installedWallpapers() const -> QList<WallpaperMetaData>;
|
auto installedWallpapers() const -> QList<WallpaperInstallData>;
|
||||||
|
|
||||||
auto resetInstalledWallpapers() -> void;
|
auto resetInstalledWallpapers() -> void;
|
||||||
Q_INVOKABLE auto rescan() -> void;
|
Q_INVOKABLE auto rescan() -> void;
|
||||||
@@ -118,9 +118,9 @@ private:
|
|||||||
QString m_errorString = QString();
|
QString m_errorString = QString();
|
||||||
|
|
||||||
QString m_installDirectoryUri;
|
QString m_installDirectoryUri;
|
||||||
QList<WallpaperMetaData> m_installedWallpapers;
|
QList<WallpaperInstallData> m_installedWallpapers;
|
||||||
|
|
||||||
Q_PROPERTY(QList<WallpaperMetaData> installedWallpapers READ installedWallpapers RESET resetInstalledWallpapers NOTIFY installedWallpapersChanged FINAL)
|
Q_PROPERTY(QList<WallpaperInstallData> installedWallpapers READ installedWallpapers RESET resetInstalledWallpapers NOTIFY installedWallpapersChanged FINAL)
|
||||||
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)
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
#include "newestpacksmodel.h"
|
||||||
|
#include "common/coreservices.h"
|
||||||
|
#include "common/logging.h"
|
||||||
|
|
||||||
|
NewestPacksModel::NewestPacksModel(QObject *parent) : QAbstractListModel{parent}
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::rowCount(const QModelIndex &) const -> int
|
||||||
|
{
|
||||||
|
return m_wallpaperCache.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::data(const QModelIndex &index, int role) const -> QVariant
|
||||||
|
{
|
||||||
|
if(index.row() < 0)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
WallpaperCache *dataPoint = m_wallpaperCache.at(index.row());
|
||||||
|
|
||||||
|
if(dataPoint == nullptr)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant data;
|
||||||
|
|
||||||
|
switch(static_cast<DataRole>(role))
|
||||||
|
{
|
||||||
|
case UriRole:
|
||||||
|
data = dataPoint->uri;
|
||||||
|
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 NewestPacksModel::index(int row, int column, const QModelIndex &parent) const -> QModelIndex
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
|
return createIndex(row, column, m_wallpaperCache.at(row));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::columnCount(const QModelIndex &) const -> int
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::parent(const QModelIndex &) const -> QModelIndex
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::setData(const QModelIndex &, const QVariant &, int) -> bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::state() const -> NewestPacksModel::State
|
||||||
|
{
|
||||||
|
return m_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::setState(State state) -> void
|
||||||
|
{
|
||||||
|
if (m_state == state)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_state = state;
|
||||||
|
emit stateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::resetState() -> void
|
||||||
|
{
|
||||||
|
setState(Idle);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::roleNames() const -> QHash<int, QByteArray>
|
||||||
|
{
|
||||||
|
return m_dataRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::errorString() const -> QString
|
||||||
|
{
|
||||||
|
return m_errorString;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NewestPacksModel::setErrorString(const QString &errorString) -> void
|
||||||
|
{
|
||||||
|
if (m_errorString == errorString)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_errorString = errorString;
|
||||||
|
emit errorStringChanged();
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
#ifndef NEWESTPACKSMODEL_H
|
||||||
|
#define NEWESTPACKSMODEL_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 "paginators/newestpackspaginator.h"
|
||||||
|
#include "common/wallpapercache.h"
|
||||||
|
|
||||||
|
class KOMPLEX_EXPORT NewestPacksModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
QML_ELEMENT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum State
|
||||||
|
{
|
||||||
|
Idle,
|
||||||
|
Loading,
|
||||||
|
Error
|
||||||
|
};
|
||||||
|
Q_ENUM(State)
|
||||||
|
|
||||||
|
enum DataRole {
|
||||||
|
UriRole = Qt::UserRole + 1,
|
||||||
|
AuthorRole,
|
||||||
|
AuthorIdRole,
|
||||||
|
DescriptionRole,
|
||||||
|
NameRole,
|
||||||
|
ThumbnailRole,
|
||||||
|
CreatedDateRole,
|
||||||
|
PriceRole,
|
||||||
|
CurrencyRole,
|
||||||
|
DownloadCountRole,
|
||||||
|
TypeRole
|
||||||
|
};
|
||||||
|
Q_ENUM(DataRole)
|
||||||
|
|
||||||
|
explicit NewestPacksModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override;
|
||||||
|
auto data(const QModelIndex &index, int role = Qt::DisplayRole) const -> QVariant override;
|
||||||
|
|
||||||
|
auto index(
|
||||||
|
int row,
|
||||||
|
int column,
|
||||||
|
const QModelIndex &parent = QModelIndex()
|
||||||
|
) const -> QModelIndex override;
|
||||||
|
|
||||||
|
auto columnCount(
|
||||||
|
const QModelIndex &parent = QModelIndex()
|
||||||
|
) const -> int override;
|
||||||
|
|
||||||
|
auto parent(const QModelIndex &index) const -> QModelIndex override;
|
||||||
|
|
||||||
|
auto setData(
|
||||||
|
const QModelIndex &index,
|
||||||
|
const QVariant &value,
|
||||||
|
int role = Qt::EditRole
|
||||||
|
) -> bool override;
|
||||||
|
|
||||||
|
auto state() const -> State;
|
||||||
|
auto setState(State state) -> void;
|
||||||
|
auto resetState() -> void;
|
||||||
|
auto roleNames() const -> QHash<int, QByteArray> override;
|
||||||
|
|
||||||
|
auto errorString() const -> QString;
|
||||||
|
auto setErrorString(const QString &errorString) -> void;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
auto installedWallpapersChanged() -> void;
|
||||||
|
|
||||||
|
auto stateChanged() -> void;
|
||||||
|
|
||||||
|
auto errorStringChanged() -> void;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static inline const QHash<int, QByteArray> m_dataRoles =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
static_cast<int>(UriRole),
|
||||||
|
QByteArray("uri")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
static_cast<int>(AuthorRole),
|
||||||
|
QByteArray("author")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline const QString m_endpointUri = QString("");
|
||||||
|
State m_state = Idle;
|
||||||
|
|
||||||
|
QString m_errorString = QString();
|
||||||
|
|
||||||
|
QString m_installDirectoryUri;
|
||||||
|
|
||||||
|
qint64 m_page = 0;
|
||||||
|
qint64 m_resultsPerPage = 0;
|
||||||
|
|
||||||
|
NewestPacksPaginator m_wallpaperCache;
|
||||||
|
|
||||||
|
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(NewestPacksModel)
|
||||||
|
|
||||||
|
#endif // NEWESTPACKSMODEL_H
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#include "newestpackspaginator.h"
|
||||||
|
#include "common/coreservices.h"
|
||||||
|
#include "common/logging.h"
|
||||||
|
|
||||||
|
NewestPacksPaginator::NewestPacksPaginator() : Paginator<WallpaperCache>()
|
||||||
|
{
|
||||||
|
SlidingCacheController<WallpaperCache> *controller = this->controller();
|
||||||
|
controller->setFetch(
|
||||||
|
std::bind(&NewestPacksPaginator::fetch, this, std::placeholders::_1, std::placeholders::_2)
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
#ifndef NEWESTPACKSPAGINATOR_H
|
||||||
|
#define NEWESTPACKSPAGINATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
|
#include "common/paginator.h"
|
||||||
|
#include "common/wallpapercache.h"
|
||||||
|
#include "common/coreservices.h"
|
||||||
|
|
||||||
|
class KOMPLEX_EXPORT NewestPacksPaginator : public Paginator<WallpaperCache>
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit NewestPacksPaginator();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief fetch
|
||||||
|
* Used to fetch results from the API endpoint
|
||||||
|
* for the CacheController. It is intended to be passed
|
||||||
|
* to the Cache Controller not meant to be called directly.
|
||||||
|
* @param offset Offset index to start the results from
|
||||||
|
* @param limit Number of results to attempt to fetch
|
||||||
|
* @return FetchResult<WallpaperCache>
|
||||||
|
*/
|
||||||
|
auto fetch(
|
||||||
|
qsizetype offset,
|
||||||
|
qsizetype limit
|
||||||
|
) const -> FetchResult<WallpaperCache>
|
||||||
|
{
|
||||||
|
QUrl url(
|
||||||
|
"https://www.digitalartifex.dev/v2/packs/newest/"
|
||||||
|
);
|
||||||
|
|
||||||
|
QNetworkRequest request(url);
|
||||||
|
request.setHeaders(
|
||||||
|
QHttpHeaders::fromMultiMap(
|
||||||
|
{
|
||||||
|
{
|
||||||
|
QByteArray("Offset"),
|
||||||
|
QString::number(offset).toUtf8()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
QByteArray("Limit"),
|
||||||
|
QString::number(limit).toUtf8()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
QByteArray("SessionToken"),
|
||||||
|
CoreServices::sessionToken()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
QNetworkReply *reply = getNetworkReply(request);
|
||||||
|
|
||||||
|
if(reply == nullptr)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonDocument document = getDocument(reply);
|
||||||
|
|
||||||
|
QJsonObject rootObject = document.object();
|
||||||
|
const QJsonArray resultsArray = rootObject.value(QString::fromUtf8("results")).toArray();
|
||||||
|
|
||||||
|
QList<WallpaperCache*> fetchedResults;
|
||||||
|
|
||||||
|
for(const auto result : resultsArray)
|
||||||
|
{
|
||||||
|
if(!result.isObject())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject resultObject = result.toObject();
|
||||||
|
|
||||||
|
fetchedResults.append(
|
||||||
|
new WallpaperCache
|
||||||
|
{
|
||||||
|
resultObject.value(QString::fromUtf8("uri")).toString(),
|
||||||
|
resultObject.value(QString::fromUtf8("name")).toString(),
|
||||||
|
resultObject.value(QString::fromUtf8("author")).toString(),
|
||||||
|
resultObject.value(QString::fromUtf8("authorId")).toString(),
|
||||||
|
resultObject.value(QString::fromUtf8("description")).toString(),
|
||||||
|
resultObject.value(QString::fromUtf8("thumbnail")).toString(),
|
||||||
|
QDateTime::fromString(
|
||||||
|
resultObject.value(QString::fromUtf8("createdDate")).toString()
|
||||||
|
),
|
||||||
|
resultObject.value(QString::fromUtf8("price")).toDouble(),
|
||||||
|
resultObject.value(QString::fromUtf8("currency")).toString(),
|
||||||
|
static_cast<quint64>(resultObject.value(QString::fromUtf8("downloadCount")).toInteger()),
|
||||||
|
static_cast<qint8>(resultObject.value(QString::fromUtf8("description")).toInt()),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
{
|
||||||
|
static_cast<qsizetype>(rootObject.value(QString::fromUtf8("total_results")).toInteger()),
|
||||||
|
fetchedResults.count(),
|
||||||
|
std::move(fetchedResults)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief getNetworkReply
|
||||||
|
* Processes the request and blocks until completion.
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
auto getNetworkReply(const QNetworkRequest &request) const -> QNetworkReply*
|
||||||
|
{
|
||||||
|
QEventLoop loop;
|
||||||
|
QNetworkAccessManager *manager = CoreServices::networkAccessManager();
|
||||||
|
QNetworkReply *reply = manager->post(request, nullptr);
|
||||||
|
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||||
|
QObject::connect(reply, &QNetworkReply::errorOccurred, &loop,
|
||||||
|
[&loop](QNetworkReply::NetworkError error) -> void
|
||||||
|
{
|
||||||
|
loop.quit();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!reply->isFinished())
|
||||||
|
{
|
||||||
|
loop.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_ERROR_X(reply->error() != QNetworkReply::NoError,
|
||||||
|
"NewestPacksPaginator::getNetworkReply",
|
||||||
|
reply->errorString().toStdString().c_str(),
|
||||||
|
nullptr
|
||||||
|
);
|
||||||
|
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto getDocument(QNetworkReply *reply) const -> QJsonDocument
|
||||||
|
{
|
||||||
|
QJsonParseError documentError;
|
||||||
|
QJsonDocument document = QJsonDocument::fromJson(reply->readAll(), &documentError);
|
||||||
|
|
||||||
|
LOG_ERROR_X(documentError.error != QJsonParseError::NoError,
|
||||||
|
"NewestPacksPaginator::getDocument",
|
||||||
|
documentError.errorString().toStdString().c_str(),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NEWESTPACKSPAGINATOR_H
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "SettingsManager.h"
|
#include "settingsmanager.h"
|
||||||
#include <qassert.h>
|
#include <qassert.h>
|
||||||
#include <qcontainerfwd.h>
|
#include <qcontainerfwd.h>
|
||||||
#include <qjsondocument.h>
|
#include <qjsondocument.h>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#ifndef SETTINGSMANAGER_H
|
#ifndef SETTINGSMANAGER_H
|
||||||
#define SETTINGSMANAGER_H
|
#define SETTINGSMANAGER_H
|
||||||
#include "Komplex_global.h"
|
#include "common/komplex_global.h"
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@@ -224,4 +224,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(SettingsManager)
|
Q_DECLARE_METATYPE(SettingsManager)
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Komplex Hub
|
||||||
|
|
||||||
|
> Media Hub and Settings Manager for the Komplex Wallpaper Plugin
|
||||||
|
|
||||||
|
Most of the development of Komplex and it's associated apps will now happen here, instead of Github.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
|
||||||
|
- Qt 6.10+
|
||||||
|
|
||||||
|
This app is currently under development and is pre-alpha
|
||||||
Reference in New Issue
Block a user