From 5e9d49a91082c53907db84df809d21c3bdc8bcac Mon Sep 17 00:00:00 2001 From: flow Date: Sun, 6 Mar 2022 13:54:05 -0300 Subject: [PATCH] refactor: use only a single unique_ptr for the api --- launcher/ui/pages/modplatform/ModPage.cpp | 4 ++-- launcher/ui/pages/modplatform/ModPage.h | 12 +++++++++--- launcher/ui/pages/modplatform/flame/FlameModPage.cpp | 2 +- launcher/ui/pages/modplatform/flame/FlameModPage.h | 4 ---- .../ui/pages/modplatform/modrinth/ModrinthPage.cpp | 2 +- .../ui/pages/modplatform/modrinth/ModrinthPage.h | 4 ---- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index 2d47e31c..f427d32a 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -5,8 +5,8 @@ #include "ui/dialogs/ModDownloadDialog.h" -ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance) - : QWidget(dialog), m_instance(instance), ui(new Ui::ModPage), dialog(dialog) +ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api) + : QWidget(dialog), m_instance(instance), ui(new Ui::ModPage), dialog(dialog), api(api) { ui->setupUi(this); connect(ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch); diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h index f79d494f..cd034a3a 100644 --- a/launcher/ui/pages/modplatform/ModPage.h +++ b/launcher/ui/pages/modplatform/ModPage.h @@ -15,23 +15,27 @@ namespace Ui { class ModPage; } +/* This page handles most logic related to browsing and selecting mods to download. + * By default, the methods provided work with net requests, to fetch data from remote APIs. */ class ModPage : public QWidget, public BasePage { Q_OBJECT public: - explicit ModPage(ModDownloadDialog* dialog, BaseInstance* instance); + explicit ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api); virtual ~ModPage(); + /* The name visible to the user */ virtual QString displayName() const override = 0; virtual QIcon icon() const override = 0; virtual QString id() const override = 0; virtual QString helpPage() const override = 0; - virtual QString debugName() const = 0; virtual QString metaEntryBase() const = 0; + /* This only appears in the debug console */ + virtual QString debugName() const = 0; virtual bool shouldDisplay() const override = 0; - virtual const ModAPI* apiProvider() const = 0; + const ModAPI* apiProvider() const { return api.get(); }; void openedImpl() override; bool eventFilter(QObject* watched, QEvent* event) override; @@ -55,5 +59,7 @@ class ModPage : public QWidget, public BasePage { ModPlatform::ListModel* listModel = nullptr; ModPlatform::IndexedPack current; + std::unique_ptr api; + int selectedVersion = -1; }; diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index ef33f972..47a79bd6 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -13,7 +13,7 @@ #include "ui/dialogs/ModDownloadDialog.h" FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance* instance) - : ModPage(dialog, instance) + : ModPage(dialog, instance, new FlameAPI()) { listModel = new FlameMod::ListModel(this); ui->packView->setModel(listModel); diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.h b/launcher/ui/pages/modplatform/flame/FlameModPage.h index e7d98cb0..89311e7f 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.h +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.h @@ -20,11 +20,7 @@ class FlameModPage : public ModPage { inline QString metaEntryBase() const override { return "FlameMods"; }; bool shouldDisplay() const override; - const ModAPI* apiProvider() const override { return &api; }; private: void onModVersionSucceed(ModPage*, QByteArray*, QString) override; - - private: - FlameAPI api; }; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index aa3efe55..4e4a9db4 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -13,7 +13,7 @@ #include "ui/dialogs/ModDownloadDialog.h" ModrinthPage::ModrinthPage(ModDownloadDialog* dialog, BaseInstance* instance) - : ModPage(dialog, instance) + : ModPage(dialog, instance, new ModrinthAPI()) { listModel = new Modrinth::ListModel(this); ui->packView->setModel(listModel); diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index 504f42ad..d92274dd 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -20,11 +20,7 @@ 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; };