refactor: put resource downloading classes in common namespace

Puts them all inside the 'ResourceDownload' namespace, so that it's a
bit clearer from the outside that those belong to the same 'module'.

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow
2022-12-16 19:03:52 -03:00
parent 6a18079953
commit 433a802c6e
21 changed files with 156 additions and 81 deletions

View File

@ -23,31 +23,31 @@
#include "modplatform/modrinth/ModrinthAPI.h"
#include "modplatform/modrinth/ModrinthPackIndex.h"
namespace Modrinth {
namespace ResourceDownload {
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
const char* ListModel::sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" };
const char* ModrinthModModel::sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" };
void ListModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
ModrinthModModel::ModrinthModModel(ModrinthModPage* parent) : ModModel(parent, new ModrinthAPI){};
void ModrinthModModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
{
Modrinth::loadIndexedPack(m, obj);
::Modrinth::loadIndexedPack(m, obj);
}
void ListModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj)
void ModrinthModModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj)
{
Modrinth::loadExtraPackData(m, obj);
::Modrinth::loadExtraPackData(m, obj);
}
void ListModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
void ModrinthModModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
{
Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_associated_page->m_base_instance);
::Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_associated_page->m_base_instance);
}
auto ListModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
auto ModrinthModModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
{
return obj.object().value("hits").toArray();
}
} // namespace Modrinth
} // namespace ResourceDownload

View File

@ -20,24 +20,22 @@
#include "ui/pages/modplatform/ModModel.h"
#include "ui/pages/modplatform/modrinth/ModrinthResourcePages.h"
namespace ResourceDownload {
#include "modplatform/modrinth/ModrinthAPI.h"
class ModrinthModPage;
namespace Modrinth {
class ListModel : public ModPlatform::ListModel {
class ModrinthModModel : public ModModel {
Q_OBJECT
public:
ListModel(ModrinthModPage* parent) : ModPlatform::ListModel(parent, new ModrinthAPI){};
~ListModel() override = default;
ModrinthModModel(ModrinthModPage* parent);
~ModrinthModModel() override = default;
private:
void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
void loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) override;
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override;
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
@ -45,5 +43,4 @@ class ListModel : public ModPlatform::ListModel {
inline auto getSorts() const -> const char** override { return sorts; };
};
} // namespace Modrinth
} // namespace ResourceDownload

View File

@ -38,13 +38,16 @@
#include "modplatform/modrinth/ModrinthAPI.h"
#include "ModrinthResourceModels.h"
#include "ui/dialogs/ModDownloadDialog.h"
#include "ui/pages/modplatform/modrinth/ModrinthResourceModels.h"
namespace ResourceDownload {
ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instance)
: ModPage(dialog, instance)
{
m_model = new Modrinth::ListModel(this);
m_model = new ModrinthModModel(this);
m_ui->packView->setModel(m_model);
// index is used to set the sorting with the modrinth api
@ -87,3 +90,4 @@ auto ModrinthModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString
// my Qt, so we need to implement this in every derived class...
auto ModrinthModPage::shouldDisplay() const -> bool { return true; }
} // namespace ResourceDownload

View File

@ -41,11 +41,15 @@
#include "ui/pages/modplatform/ModPage.h"
namespace ResourceDownload {
namespace Modrinth {
static inline QString displayName() { return "Modrinth"; }
static inline QIcon icon() { return APPLICATION->getThemedIcon("modrinth"); }
static inline QString id() { return "modrinth"; }
static inline QString debugName() { return "Modrinth"; }
static inline QString metaEntryBase() { return "ModrinthPacks"; };
}
class ModrinthModPage : public ModPage {
Q_OBJECT
@ -61,12 +65,15 @@ class ModrinthModPage : public ModPage {
[[nodiscard]] bool shouldDisplay() const override;
[[nodiscard]] inline auto displayName() const -> QString override { return ::displayName(); } \
[[nodiscard]] inline auto icon() const -> QIcon override { return ::icon(); } \
[[nodiscard]] inline auto id() const -> QString override { return ::id(); } \
[[nodiscard]] inline auto debugName() const -> QString override { return ::debugName(); } \
[[nodiscard]] inline auto metaEntryBase() const -> QString override { return ::metaEntryBase(); }
inline auto helpPage() const -> QString override { return "Mod-platform"; }
[[nodiscard]] inline auto displayName() const -> QString override { return Modrinth::displayName(); }
[[nodiscard]] inline auto icon() const -> QIcon override { return Modrinth::icon(); }
[[nodiscard]] inline auto id() const -> QString override { return Modrinth::id(); }
[[nodiscard]] inline auto debugName() const -> QString override { return Modrinth::debugName(); }
[[nodiscard]] inline auto metaEntryBase() const -> QString override { return Modrinth::metaEntryBase(); }
[[nodiscard]] inline auto helpPage() const -> QString override { return "Mod-platform"; }
auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const -> bool override;
};
} // namespace ResourceDownload