Added individual paginators for API endpoints

This commit is contained in:
Digital Artifex
2026-06-08 22:15:17 -04:00
parent 5b84a007f6
commit 8be07c47cb
13 changed files with 511 additions and 158 deletions
+12
View File
@@ -27,6 +27,18 @@ qt_add_qml_module(
common/logging.h common/logging.h
common/fetchresult.h common/fetchresult.h
paginators/newestpackspaginator.h paginators/newestpackspaginator.h
SOURCES paginators/featuredpackspaginator.h
SOURCES paginators/featuredimagespaginator.h
SOURCES paginators/wallpaperpaginator.h
SOURCES paginators/searchpackspaginator.h
SOURCES paginators/searchimagespaginator.h
SOURCES paginators/newestshaderspaginator.h
SOURCES paginators/newestcubemapspaginator.h
SOURCES paginators/featuredshaderspaginator.h
SOURCES paginators/featuredcubemapspaginator.h
SOURCES paginators/searchshaderspaginator.h
SOURCES paginators/searchcubemapspaginator.h
SOURCES paginators/searchvideospaginator.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() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/cubemaps/featured/").arg(KOMPLEX_API_HOST)
);
}
};
#endif // FEATUREDCUBEMAPSPAGINATOR_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 FEATUREDIMAGESPAGINATOR_H
#define FEATUREDIMAGESPAGINATOR_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 FeaturedImagesPaginator : public WallpaperPaginator
{
public:
explicit FeaturedImagesPaginator() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/images/featured/").arg(KOMPLEX_API_HOST)
);
}
};
#endif // FEATUREDIMAGESPAGINATOR_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 FEATUREDPACKSPAGINATOR_H
#define FEATUREDPACKSPAGINATOR_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 FeaturedPacksPaginator : public WallpaperPaginator
{
public:
explicit FeaturedPacksPaginator() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/packs/featured/").arg(KOMPLEX_API_HOST)
);
}
};
#endif // FEATUREDPACKSPAGINATOR_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 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() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/shaders/featured/").arg(KOMPLEX_API_HOST)
);
}
};
#endif // FEATUREDSHADERSPAGINATOR_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 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() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/cubemaps/newest/").arg(KOMPLEX_API_HOST)
);
}
};
#endif // NEWESTCUBEMAPSPAGINATOR_H
@@ -29,170 +29,16 @@
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
#include "common/logging.h" #include "wallpaperpaginator.h"
#include "common/paginator.h"
#include "common/wallpapercache.h"
#include "common/coreservices.h"
class KOMPLEX_EXPORT NewestPacksPaginator : public Paginator<WallpaperCache> class KOMPLEX_EXPORT NewestPacksPaginator : public WallpaperPaginator
{ {
public: public:
explicit NewestPacksPaginator() : Paginator<WallpaperCache>() explicit NewestPacksPaginator() : WallpaperPaginator()
{ {
SlidingCacheController<WallpaperCache> *controller = this->controller(); setUri(
controller->setFetch(
std::bind(&NewestPacksPaginator::fetch, this, std::placeholders::_1, std::placeholders::_2)
);
}
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(
QString::fromUtf8("%1/v2/packs/newest/").arg(KOMPLEX_API_HOST) QString::fromUtf8("%1/v2/packs/newest/").arg(KOMPLEX_API_HOST)
); );
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(
{
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;
QWeakPointer<QNetworkAccessManager> managerReference = CoreServices::networkAccessManager();
QSharedPointer<QNetworkAccessManager> manager = managerReference.toStrongRef();
LOG_ERROR_X(!manager,
"NewestPacksPaginator::getNetworkReply",
"Network manager reference has already been deleted",
nullptr
);
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;
} }
}; };
@@ -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() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/shaders/newest/").arg(KOMPLEX_API_HOST)
);
}
};
#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() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/cubemaps/search/").arg(KOMPLEX_API_HOST)
);
}
};
#endif // SEARCHCUBEMAPSPAGINATOR_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 SEARCHIMAGESPAGINATOR_H
#define SEARCHIMAGESPAGINATOR_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 SearchImagesPaginator : public WallpaperPaginator
{
public:
explicit SearchImagesPaginator() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/images/search/").arg(KOMPLEX_API_HOST)
);
}
};
#endif // SEARCHIMAGESPAGINATOR_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 SEARCHPACKSPAGINATOR_H
#define SEARCHPACKSPAGINATOR_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 SearchPacksPaginator : public WallpaperPaginator
{
public:
explicit SearchPacksPaginator() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/packs/search/").arg(KOMPLEX_API_HOST)
);
}
};
#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() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/shaders/search/").arg(KOMPLEX_API_HOST)
);
}
};
#endif // SEARCHSHADERSPAGINATOR_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 SEARCHVIDEOSPAGINATOR_H
#define SEARCHVIDEOSPAGINATOR_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 SearchVideosPaginator : public WallpaperPaginator
{
public:
explicit SearchVideosPaginator() : WallpaperPaginator()
{
setUri(
QString::fromUtf8("%1/v2/videos/search/").arg(KOMPLEX_API_HOST)
);
}
};
#endif // SEARCHVIDEOSPAGINATOR_H