diff options
author | flow <thiagodonato300@gmail.com> | 2022-03-02 23:01:23 -0300 |
---|---|---|
committer | flow <thiagodonato300@gmail.com> | 2022-03-02 23:13:04 -0300 |
commit | 2d68308d4920be4c28a73d7646814765eee7b7a2 (patch) | |
tree | ac0c9abf5a1f33bc13b8f885070904e7e7bfe43d /launcher/ui/pages/modplatform/modrinth | |
parent | 0dd1c26cf3cd68cd83f5d9da6cf34d4aa3f30db2 (diff) | |
download | PrismLauncher-2d68308d4920be4c28a73d7646814765eee7b7a2.tar.gz PrismLauncher-2d68308d4920be4c28a73d7646814765eee7b7a2.tar.bz2 PrismLauncher-2d68308d4920be4c28a73d7646814765eee7b7a2.zip |
refactor: move url creation for mods to modplatform/
Moves all things related to creating the URLs of the mod platforms
that go to network tasks to a single place, so that:
1. Maintaining and fixing eventual issues is more straightforward.
2. Makes it possible to factor out more common code between the
different modplatform pages
Diffstat (limited to 'launcher/ui/pages/modplatform/modrinth')
-rw-r--r-- | launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp | 39 | ||||
-rw-r--r-- | launcher/ui/pages/modplatform/modrinth/ModrinthModel.h | 4 | ||||
-rw-r--r-- | launcher/ui/pages/modplatform/modrinth/ModrinthPage.h | 6 |
3 files changed, 16 insertions, 33 deletions
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index d2e86ef8..dc3d1469 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -1,7 +1,6 @@ #include "ModrinthModel.h" #include "ModrinthPage.h" #include "minecraft/MinecraftInstance.h" -#include "minecraft/PackProfile.h" #include <Json.h> @@ -11,37 +10,6 @@ ListModel::ListModel(ModrinthPage* parent) : ModPlatform::ListModel(parent) {} ListModel::~ListModel() {} -const char* sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" }; - -void ListModel::performPaginatedSearch() -{ - QString mcVersion = ((MinecraftInstance*)((ModrinthPage*)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft"); - bool hasFabric = !((MinecraftInstance*)((ModrinthPage*)parent())->m_instance) - ->getPackProfile() - ->getComponentVersion("net.fabricmc.fabric-loader") - .isEmpty(); - auto netJob = new NetJob("Modrinth::Search", APPLICATION->network()); - auto searchUrl = QString( - "https://api.modrinth.com/v2/search?" - "offset=%1&" - "limit=25&" - "query=%2&" - "index=%3&" - "facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]") - .arg(nextSearchOffset) - .arg(currentSearchTerm) - .arg(sorts[currentSort]) - .arg(hasFabric ? "fabric" : "forge") - .arg(mcVersion); - - netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); - jobPtr = netJob; - jobPtr->start(); - - QObject::connect(netJob, &NetJob::succeeded, this, &Modrinth::ListModel::searchRequestFinished); - QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed); -} - void Modrinth::ListModel::searchRequestFinished() { jobPtr.reset(); @@ -80,4 +48,11 @@ void Modrinth::ListModel::searchRequestFinished() endInsertRows(); } +const char* sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" }; + +const char** Modrinth::ListModel::getSorts() const +{ + return sorts; +} + } // namespace Modrinth diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h index 73492356..b8937b50 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h @@ -30,8 +30,10 @@ class ListModel : public ModPlatform::ListModel { virtual ~ListModel(); private slots: - void performPaginatedSearch() override; void searchRequestFinished() override; + + private: + const char** getSorts() const override; }; } // namespace Modrinth diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index 41c6c31d..504f42ad 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -2,6 +2,8 @@ #include "ui/pages/modplatform/ModPage.h" +#include "modplatform/modrinth/ModrinthAPI.h" + class ModrinthPage : public ModPage { Q_OBJECT @@ -18,7 +20,11 @@ class ModrinthPage : public ModPage { inline QString metaEntryBase() const override { return "ModrinthPacks"; }; bool shouldDisplay() const override; + const ModAPI* apiProvider() const override { return &api; }; private: void onModVersionSucceed(ModPage*, QByteArray*, QString) override; + + private: + ModrinthAPI api; }; |