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
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
21 changed files with 156 additions and 81 deletions

View File

@ -24,6 +24,8 @@
#include "ui/pages/modplatform/flame/FlameResourcePages.h" #include "ui/pages/modplatform/flame/FlameResourcePages.h"
#include "ui/pages/modplatform/modrinth/ModrinthResourcePages.h" #include "ui/pages/modplatform/modrinth/ModrinthResourcePages.h"
namespace ResourceDownload {
ModDownloadDialog::ModDownloadDialog(QWidget* parent, const std::shared_ptr<ModFolderModel>& mods, BaseInstance* instance) ModDownloadDialog::ModDownloadDialog(QWidget* parent, const std::shared_ptr<ModFolderModel>& mods, BaseInstance* instance)
: ResourceDownloadDialog(parent, mods), m_instance(instance) : ResourceDownloadDialog(parent, mods), m_instance(instance)
{ {
@ -57,3 +59,5 @@ QList<BasePage*> ModDownloadDialog::getPages()
return pages; return pages;
} }
} // namespace ResourceDownload

View File

@ -25,8 +25,9 @@
class QDialogButtonBox; class QDialogButtonBox;
class ModDownloadDialog final : public ResourceDownloadDialog namespace ResourceDownload {
{
class ModDownloadDialog final : public ResourceDownloadDialog {
Q_OBJECT Q_OBJECT
public: public:
@ -45,3 +46,5 @@ class ModDownloadDialog final : public ResourceDownloadDialog
private: private:
BaseInstance* m_instance; BaseInstance* m_instance;
}; };
} // namespace ResourceDownload

View File

@ -9,6 +9,8 @@
#include "ui/pages/modplatform/ResourcePage.h" #include "ui/pages/modplatform/ResourcePage.h"
#include "ui/widgets/PageContainer.h" #include "ui/widgets/PageContainer.h"
namespace ResourceDownload {
ResourceDownloadDialog::ResourceDownloadDialog(QWidget* parent, const std::shared_ptr<ResourceFolderModel> base_model) ResourceDownloadDialog::ResourceDownloadDialog(QWidget* parent, const std::shared_ptr<ResourceFolderModel> base_model)
: QDialog(parent), m_base_model(base_model), m_buttons(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel), m_vertical_layout(this) : QDialog(parent), m_base_model(base_model), m_buttons(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel), m_vertical_layout(this)
{ {
@ -150,3 +152,5 @@ void ResourceDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* s
// Same effect as having a global search bar // Same effect as having a global search bar
m_selectedPage->setSearchTerm(prev_page->getSearchTerm()); m_selectedPage->setSearchTerm(prev_page->getSearchTerm());
} }
} // namespace ResourceDownload

View File

@ -7,12 +7,15 @@
#include "ui/pages/BasePageProvider.h" #include "ui/pages/BasePageProvider.h"
class ResourceDownloadTask; class ResourceDownloadTask;
class ResourcePage;
class ResourceFolderModel; class ResourceFolderModel;
class PageContainer; class PageContainer;
class QVBoxLayout; class QVBoxLayout;
class QDialogButtonBox; class QDialogButtonBox;
namespace ResourceDownload {
class ResourcePage;
class ResourceDownloadDialog : public QDialog, public BasePageProvider { class ResourceDownloadDialog : public QDialog, public BasePageProvider {
Q_OBJECT Q_OBJECT
@ -53,3 +56,5 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
QHash<QString, ResourceDownloadTask*> m_selected; QHash<QString, ResourceDownloadTask*> m_selected;
}; };
} // namespace ResourceDownload

View File

@ -158,7 +158,7 @@ void ModFolderPage::installMods()
return; return;
} }
ModDownloadDialog mdownload(this, m_model, m_instance); ResourceDownload::ModDownloadDialog mdownload(this, m_model, m_instance);
if (mdownload.exec()) { if (mdownload.exec()) {
ConcurrentTask* tasks = new ConcurrentTask(this); ConcurrentTask* tasks = new ConcurrentTask(this);
connect(tasks, &Task::failed, [this, tasks](QString reason) { connect(tasks, &Task::failed, [this, tasks](QString reason) {

View File

@ -7,19 +7,19 @@
#include <QMessageBox> #include <QMessageBox>
namespace ModPlatform { namespace ResourceDownload {
ListModel::ListModel(ModPage* parent, ResourceAPI* api) : ResourceModel(parent, api) {} ModModel::ModModel(ModPage* parent, ResourceAPI* api) : ResourceModel(parent, api) {}
/******** Make data requests ********/ /******** Make data requests ********/
ResourceAPI::SearchArgs ListModel::createSearchArguments() ResourceAPI::SearchArgs ModModel::createSearchArguments()
{ {
auto profile = static_cast<MinecraftInstance&>(m_associated_page->m_base_instance).getPackProfile(); auto profile = static_cast<MinecraftInstance&>(m_associated_page->m_base_instance).getPackProfile();
return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term,
getSorts()[currentSort], profile->getModLoaders(), getMineVersions() }; getSorts()[currentSort], profile->getModLoaders(), getMineVersions() };
} }
ResourceAPI::SearchCallbacks ListModel::createSearchCallbacks() ResourceAPI::SearchCallbacks ModModel::createSearchCallbacks()
{ {
return { [this](auto& doc) { return { [this](auto& doc) {
if (!s_running_models.constFind(this).value()) if (!s_running_models.constFind(this).value())
@ -28,14 +28,14 @@ ResourceAPI::SearchCallbacks ListModel::createSearchCallbacks()
} }; } };
} }
ResourceAPI::VersionSearchArgs ListModel::createVersionsArguments(QModelIndex& entry) ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry)
{ {
auto const& pack = m_packs[entry.row()]; auto const& pack = m_packs[entry.row()];
auto profile = static_cast<MinecraftInstance&>(m_associated_page->m_base_instance).getPackProfile(); auto profile = static_cast<MinecraftInstance&>(m_associated_page->m_base_instance).getPackProfile();
return { pack.addonId.toString(), getMineVersions(), profile->getModLoaders() }; return { pack.addonId.toString(), getMineVersions(), profile->getModLoaders() };
} }
ResourceAPI::VersionSearchCallbacks ListModel::createVersionsCallbacks(QModelIndex& entry) ResourceAPI::VersionSearchCallbacks ModModel::createVersionsCallbacks(QModelIndex& entry)
{ {
auto const& pack = m_packs[entry.row()]; auto const& pack = m_packs[entry.row()];
@ -46,12 +46,12 @@ ResourceAPI::VersionSearchCallbacks ListModel::createVersionsCallbacks(QModelInd
} }; } };
} }
ResourceAPI::ProjectInfoArgs ListModel::createInfoArguments(QModelIndex& entry) ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(QModelIndex& entry)
{ {
auto& pack = m_packs[entry.row()]; auto& pack = m_packs[entry.row()];
return { pack }; return { pack };
} }
ResourceAPI::ProjectInfoCallbacks ListModel::createInfoCallbacks(QModelIndex& entry) ResourceAPI::ProjectInfoCallbacks ModModel::createInfoCallbacks(QModelIndex& entry)
{ {
return { [this, entry](auto& doc, auto& pack) { return { [this, entry](auto& doc, auto& pack) {
if (!s_running_models.constFind(this).value()) if (!s_running_models.constFind(this).value())
@ -60,7 +60,7 @@ ResourceAPI::ProjectInfoCallbacks ListModel::createInfoCallbacks(QModelIndex& en
} }; } };
} }
void ListModel::searchWithTerm(const QString& term, const int sort, const bool filter_changed) void ModModel::searchWithTerm(const QString& term, const int sort, const bool filter_changed)
{ {
if (m_search_term == term && m_search_term.isNull() == term.isNull() && currentSort == sort && !filter_changed) { if (m_search_term == term && m_search_term.isNull() == term.isNull() && currentSort == sort && !filter_changed) {
return; return;
@ -74,7 +74,7 @@ void ListModel::searchWithTerm(const QString& term, const int sort, const bool f
/******** Request callbacks ********/ /******** Request callbacks ********/
void ListModel::searchRequestFinished(QJsonDocument& doc) void ModModel::searchRequestFinished(QJsonDocument& doc)
{ {
QList<ModPlatform::IndexedPack> newList; QList<ModPlatform::IndexedPack> newList;
auto packs = documentToArray(doc); auto packs = documentToArray(doc);
@ -108,7 +108,7 @@ void ListModel::searchRequestFinished(QJsonDocument& doc)
endInsertRows(); endInsertRows();
} }
void ListModel::infoRequestFinished(QJsonDocument& doc, ModPlatform::IndexedPack& pack, const QModelIndex& index) void ModModel::infoRequestFinished(QJsonDocument& doc, ModPlatform::IndexedPack& pack, const QModelIndex& index)
{ {
qDebug() << "Loading mod info"; qDebug() << "Loading mod info";
@ -133,7 +133,7 @@ void ListModel::infoRequestFinished(QJsonDocument& doc, ModPlatform::IndexedPack
m_associated_page->updateUi(); m_associated_page->updateUi();
} }
void ListModel::versionRequestSucceeded(QJsonDocument doc, QString addonId, const QModelIndex& index) void ModModel::versionRequestSucceeded(QJsonDocument doc, QString addonId, const QModelIndex& index)
{ {
auto current = m_associated_page->getCurrentPack(); auto current = m_associated_page->getCurrentPack();
if (addonId != current.addonId) { if (addonId != current.addonId) {
@ -159,16 +159,16 @@ void ListModel::versionRequestSucceeded(QJsonDocument doc, QString addonId, cons
m_associated_page->updateVersionList(); m_associated_page->updateVersionList();
} }
} // namespace ModPlatform
/******** Helpers ********/ /******** Helpers ********/
#define MOD_PAGE(x) static_cast<ModPage*>(x) #define MOD_PAGE(x) static_cast<ModPage*>(x)
auto ModPlatform::ListModel::getMineVersions() const -> std::optional<std::list<Version>> auto ModModel::getMineVersions() const -> std::optional<std::list<Version>>
{ {
auto versions = MOD_PAGE(m_associated_page)->getFilter()->versions; auto versions = MOD_PAGE(m_associated_page)->getFilter()->versions;
if (!versions.empty()) if (!versions.empty())
return versions; return versions;
return {}; return {};
} }
} // namespace ResourceDownload

View File

@ -7,16 +7,17 @@
#include "ui/pages/modplatform/ResourceModel.h" #include "ui/pages/modplatform/ResourceModel.h"
class ModPage;
class Version; class Version;
namespace ModPlatform { namespace ResourceDownload {
class ListModel : public ResourceModel { class ModPage;
class ModModel : public ResourceModel {
Q_OBJECT Q_OBJECT
public: public:
ListModel(ModPage* parent, ResourceAPI* api); ModModel(ModPage* parent, ResourceAPI* api);
/* Ask the API for more information */ /* Ask the API for more information */
void searchWithTerm(const QString& term, const int sort, const bool filter_changed); void searchWithTerm(const QString& term, const int sort, const bool filter_changed);
@ -51,4 +52,5 @@ class ListModel : public ResourceModel {
protected: protected:
int currentSort = 0; int currentSort = 0;
}; };
} // namespace ModPlatform
} // namespace ResourceDownload

View File

@ -53,6 +53,8 @@
#include "ui/pages/modplatform/ModModel.h" #include "ui/pages/modplatform/ModModel.h"
namespace ResourceDownload {
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance) ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance)
: ResourcePage(dialog, instance) : ResourcePage(dialog, instance)
{ {
@ -100,7 +102,7 @@ void ModPage::triggerSearch()
updateSelectionButton(); updateSelectionButton();
} }
static_cast<ModPlatform::ListModel*>(m_model)->searchWithTerm(getSearchTerm(), m_ui->sortByBox->currentIndex(), changed); static_cast<ModModel*>(m_model)->searchWithTerm(getSearchTerm(), m_ui->sortByBox->currentIndex(), changed);
m_fetch_progress.watch(&m_model->activeJob()); m_fetch_progress.watch(&m_model->activeJob());
} }
@ -151,3 +153,5 @@ void ModPage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::I
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool(); bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_parent_dialog->addResource(pack.name, new ResourceDownloadTask(pack, version, m_parent_dialog->getBaseModel(), is_indexed)); m_parent_dialog->addResource(pack.name, new ResourceDownloadTask(pack, version, m_parent_dialog->getBaseModel(), is_indexed));
} }
} // namespace ResourceDownload

View File

@ -7,12 +7,14 @@
#include "ui/pages/modplatform/ResourcePage.h" #include "ui/pages/modplatform/ResourcePage.h"
#include "ui/widgets/ModFilterWidget.h" #include "ui/widgets/ModFilterWidget.h"
class ModDownloadDialog;
namespace Ui { namespace Ui {
class ResourcePage; class ResourcePage;
} }
namespace ResourceDownload {
class ModDownloadDialog;
/* This page handles most logic related to browsing and selecting mods to download. */ /* This page handles most logic related to browsing and selecting mods to download. */
class ModPage : public ResourcePage { class ModPage : public ResourcePage {
Q_OBJECT Q_OBJECT
@ -57,3 +59,5 @@ class ModPage : public ResourcePage {
unique_qobject_ptr<ModFilterWidget> m_filter_widget; unique_qobject_ptr<ModFilterWidget> m_filter_widget;
std::shared_ptr<ModFilterWidget::Filter> m_filter; std::shared_ptr<ModFilterWidget::Filter> m_filter;
}; };
} // namespace ResourceDownload

View File

@ -20,6 +20,8 @@
#include "ui/pages/modplatform/ResourcePage.h" #include "ui/pages/modplatform/ResourcePage.h"
#include "ui/widgets/ProjectItem.h" #include "ui/widgets/ProjectItem.h"
namespace ResourceDownload {
QHash<ResourceModel*, bool> ResourceModel::s_running_models; QHash<ResourceModel*, bool> ResourceModel::s_running_models;
ResourceModel::ResourceModel(ResourcePage* parent, ResourceAPI* api) : QAbstractListModel(), m_api(api), m_associated_page(parent) ResourceModel::ResourceModel(ResourcePage* parent, ResourceAPI* api) : QAbstractListModel(), m_api(api), m_associated_page(parent)
@ -256,3 +258,5 @@ void ResourceModel::searchRequestAborted()
m_next_search_offset = 0; m_next_search_offset = 0;
search(); search();
} }
} // namespace ResourceDownload

View File

@ -9,13 +9,15 @@
#include "tasks/ConcurrentTask.h" #include "tasks/ConcurrentTask.h"
class NetJob; class NetJob;
class ResourcePage;
class ResourceAPI; class ResourceAPI;
namespace ModPlatform { namespace ModPlatform {
struct IndexedPack; struct IndexedPack;
} }
namespace ResourceDownload {
class ResourcePage;
class ResourceModel : public QAbstractListModel { class ResourceModel : public QAbstractListModel {
Q_OBJECT Q_OBJECT
@ -99,3 +101,5 @@ class ResourceModel : public QAbstractListModel {
void searchRequestFailed(QString reason, int network_error_code); void searchRequestFailed(QString reason, int network_error_code);
void searchRequestAborted(); void searchRequestAborted();
}; };
} // namespace ResourceDownload

View File

@ -13,6 +13,8 @@
#include "ui/pages/modplatform/ResourceModel.h" #include "ui/pages/modplatform/ResourceModel.h"
#include "ui/widgets/ProjectItem.h" #include "ui/widgets/ProjectItem.h"
namespace ResourceDownload {
ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_instance) ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_instance)
: QWidget(parent), m_base_instance(base_instance), m_ui(new Ui::ResourcePage), m_parent_dialog(parent), m_fetch_progress(this, false) : QWidget(parent), m_base_instance(base_instance), m_ui(new Ui::ResourcePage), m_parent_dialog(parent), m_fetch_progress(this, false)
{ {
@ -345,3 +347,5 @@ void ResourcePage::openUrl(const QUrl& url)
// open in the user's web browser // open in the user's web browser
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }
} // namespace ResourceDownload

View File

@ -14,8 +14,11 @@ class ResourcePage;
} }
class BaseInstance; class BaseInstance;
class ResourceModel;
namespace ResourceDownload {
class ResourceDownloadDialog; class ResourceDownloadDialog;
class ResourceModel;
class ResourcePage : public QWidget, public BasePage { class ResourcePage : public QWidget, public BasePage {
Q_OBJECT Q_OBJECT
@ -93,3 +96,5 @@ class ResourcePage : public QWidget, public BasePage {
// Used to do instant searching with a delay to cache quick changes // Used to do instant searching with a delay to cache quick changes
QTimer m_search_timer; QTimer m_search_timer;
}; };
} // namespace ResourceDownload

View File

@ -1,31 +1,35 @@
#include "FlameResourceModels.h" #include "FlameResourceModels.h"
#include "Json.h" #include "Json.h"
#include "modplatform/flame/FlameModIndex.h" #include "modplatform/flame/FlameModIndex.h"
namespace FlameMod { namespace ResourceDownload {
// NOLINTNEXTLINE(modernize-avoid-c-arrays) // NOLINTNEXTLINE(modernize-avoid-c-arrays)
const char* ListModel::sorts[6]{ "Featured", "Popularity", "LastUpdated", "Name", "Author", "TotalDownloads" }; const char* FlameModModel::sorts[6]{ "Featured", "Popularity", "LastUpdated", "Name", "Author", "TotalDownloads" };
void ListModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) FlameModModel::FlameModModel(FlameModPage* parent) : ModModel(parent, new FlameAPI) {}
void FlameModModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
{ {
FlameMod::loadIndexedPack(m, obj); FlameMod::loadIndexedPack(m, obj);
} }
// We already deal with the URLs when initializing the pack, due to the API response's structure // We already deal with the URLs when initializing the pack, due to the API response's structure
void ListModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj) void FlameModModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj)
{ {
FlameMod::loadBody(m, obj); FlameMod::loadBody(m, obj);
} }
void ListModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) void FlameModModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
{ {
FlameMod::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_associated_page->m_base_instance); FlameMod::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_associated_page->m_base_instance);
} }
auto ListModel::documentToArray(QJsonDocument& obj) const -> QJsonArray auto FlameModModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
{ {
return Json::ensureArray(obj.object(), "data"); return Json::ensureArray(obj.object(), "data");
} }
} // namespace FlameMod } // namespace ResourceDownload

View File

@ -2,14 +2,18 @@
#include "modplatform/flame/FlameAPI.h" #include "modplatform/flame/FlameAPI.h"
namespace FlameMod { #include "ui/pages/modplatform/ModModel.h"
class ListModel : public ModPlatform::ListModel { #include "ui/pages/modplatform/flame/FlameResourcePages.h"
namespace ResourceDownload {
class FlameModModel : public ModModel {
Q_OBJECT Q_OBJECT
public: public:
ListModel(FlameModPage* parent) : ModPlatform::ListModel(parent, new FlameAPI) {} FlameModModel(FlameModPage* parent);
~ListModel() override = default; ~FlameModModel() override = default;
private: private:
void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override; void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
@ -23,4 +27,4 @@ class ListModel : public ModPlatform::ListModel {
inline auto getSorts() const -> const char** override { return sorts; }; inline auto getSorts() const -> const char** override { return sorts; };
}; };
} // namespace FlameMod } // namespace ResourceDownload

View File

@ -40,10 +40,12 @@
#include "FlameResourceModels.h" #include "FlameResourceModels.h"
#include "ui/dialogs/ModDownloadDialog.h" #include "ui/dialogs/ModDownloadDialog.h"
namespace ResourceDownload {
FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance) FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance)
: ModPage(dialog, instance) : ModPage(dialog, instance)
{ {
m_model = new FlameMod::ListModel(this); m_model = new FlameModModel(this);
m_ui->packView->setModel(m_model); m_ui->packView->setModel(m_model);
// index is used to set the sorting with the flame api // index is used to set the sorting with the flame api
@ -95,3 +97,5 @@ void FlameModPage::openUrl(const QUrl& url)
ModPage::openUrl(url); ModPage::openUrl(url);
} }
} // namespace ResourceDownload

View File

@ -42,6 +42,16 @@
#include "ui/pages/modplatform/ModPage.h" #include "ui/pages/modplatform/ModPage.h"
namespace ResourceDownload {
namespace Flame {
static inline QString displayName() { return "CurseForge"; }
static inline QIcon icon() { return APPLICATION->getThemedIcon("flame"); }
static inline QString id() { return "curseforge"; }
static inline QString debugName() { return "Flame"; }
static inline QString metaEntryBase() { return "FlameMods"; };
}
class FlameModPage : public ModPage { class FlameModPage : public ModPage {
Q_OBJECT Q_OBJECT
@ -54,18 +64,20 @@ class FlameModPage : public ModPage {
FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance); FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance);
~FlameModPage() override = default; ~FlameModPage() override = default;
inline auto displayName() const -> QString override { return "CurseForge"; } [[nodiscard]] bool shouldDisplay() const override;
inline auto icon() const -> QIcon override { return APPLICATION->getThemedIcon("flame"); }
inline auto id() const -> QString override { return "curseforge"; }
inline auto helpPage() const -> QString override { return "Mod-platform"; }
inline auto debugName() const -> QString override { return "Flame"; } [[nodiscard]] inline auto displayName() const -> QString override { return Flame::displayName(); }
inline auto metaEntryBase() const -> QString override { return "FlameMods"; }; [[nodiscard]] inline auto icon() const -> QIcon override { return Flame::icon(); }
[[nodiscard]] inline auto id() const -> QString override { return Flame::id(); }
[[nodiscard]] inline auto debugName() const -> QString override { return Flame::debugName(); }
[[nodiscard]] inline auto metaEntryBase() const -> QString override { return Flame::metaEntryBase(); }
auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const -> bool override; [[nodiscard]] inline auto helpPage() const -> QString override { return "Mod-platform"; }
bool validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const override;
bool optedOut(ModPlatform::IndexedVersion& ver) const override; bool optedOut(ModPlatform::IndexedVersion& ver) const override;
auto shouldDisplay() const -> bool override;
void openUrl(const QUrl& url) override; void openUrl(const QUrl& url) override;
}; };
} // namespace ResourceDownload

View File

@ -23,31 +23,31 @@
#include "modplatform/modrinth/ModrinthAPI.h" #include "modplatform/modrinth/ModrinthAPI.h"
#include "modplatform/modrinth/ModrinthPackIndex.h" #include "modplatform/modrinth/ModrinthPackIndex.h"
namespace Modrinth { namespace ResourceDownload {
// NOLINTNEXTLINE(modernize-avoid-c-arrays) // 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(); return obj.object().value("hits").toArray();
} }
} // namespace Modrinth } // namespace ResourceDownload

View File

@ -20,18 +20,16 @@
#include "ui/pages/modplatform/ModModel.h" #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 ModrinthModModel : public ModModel {
class ListModel : public ModPlatform::ListModel {
Q_OBJECT Q_OBJECT
public: public:
ListModel(ModrinthModPage* parent) : ModPlatform::ListModel(parent, new ModrinthAPI){}; ModrinthModModel(ModrinthModPage* parent);
~ListModel() override = default; ~ModrinthModModel() override = default;
private: private:
void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override; void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
@ -45,5 +43,4 @@ class ListModel : public ModPlatform::ListModel {
inline auto getSorts() const -> const char** override { return sorts; }; 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 "modplatform/modrinth/ModrinthAPI.h"
#include "ModrinthResourceModels.h"
#include "ui/dialogs/ModDownloadDialog.h" #include "ui/dialogs/ModDownloadDialog.h"
#include "ui/pages/modplatform/modrinth/ModrinthResourceModels.h"
namespace ResourceDownload {
ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instance) ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instance)
: ModPage(dialog, instance) : ModPage(dialog, instance)
{ {
m_model = new Modrinth::ListModel(this); m_model = new ModrinthModModel(this);
m_ui->packView->setModel(m_model); m_ui->packView->setModel(m_model);
// index is used to set the sorting with the modrinth api // 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... // my Qt, so we need to implement this in every derived class...
auto ModrinthModPage::shouldDisplay() const -> bool { return true; } auto ModrinthModPage::shouldDisplay() const -> bool { return true; }
} // namespace ResourceDownload

View File

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