aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/pages/modplatform/modrinth
diff options
context:
space:
mode:
authorflow <thiagodonato300@gmail.com>2022-03-07 17:46:18 -0300
committerflow <thiagodonato300@gmail.com>2022-03-07 18:28:24 -0300
commitb131d3b2ecbe6a9be35088d8411927bcd30de896 (patch)
treec4696b10263981845608730f00f7f7d0d175e8b4 /launcher/ui/pages/modplatform/modrinth
parent16bfafa29e2cb54e1553c813cab0fff5203f8c60 (diff)
downloadPrismLauncher-b131d3b2ecbe6a9be35088d8411927bcd30de896.tar.gz
PrismLauncher-b131d3b2ecbe6a9be35088d8411927bcd30de896.tar.bz2
PrismLauncher-b131d3b2ecbe6a9be35088d8411927bcd30de896.zip
refactor: move more common code to base class
Also removes unused imports and organize the ModModel header
Diffstat (limited to 'launcher/ui/pages/modplatform/modrinth')
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp44
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.h31
2 files changed, 9 insertions, 66 deletions
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
index 784b1128..9361546e 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
@@ -1,49 +1,7 @@
#include "ModrinthModel.h"
-#include "ModrinthPage.h"
-#include "minecraft/MinecraftInstance.h"
-
-#include <Json.h>
namespace Modrinth {
-ListModel::ListModel(ModrinthPage* parent) : ModPlatform::ListModel(parent) {}
-
-ListModel::~ListModel() {}
-
-void Modrinth::ListModel::searchRequestFinished(QJsonDocument& doc)
-{
- jobPtr.reset();
-
- QList<ModPlatform::IndexedPack> newList;
- auto packs = doc.object().value("hits").toArray();
- for (auto packRaw : packs) {
- auto packObj = packRaw.toObject();
-
- ModPlatform::IndexedPack pack;
- try {
- Modrinth::loadIndexedPack(pack, packObj);
- newList.append(pack);
- } catch (const JSONValidationError& e) {
- qWarning() << "Error while loading mod from Modrinth: " << e.cause();
- continue;
- }
- }
- if (packs.size() < 25) {
- searchState = Finished;
- } else {
- nextSearchOffset += 25;
- searchState = CanPossiblyFetchMore;
- }
- beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1);
- modpacks.append(newList);
- endInsertRows();
-}
-
-const char* sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" };
-
-const char** Modrinth::ListModel::getSorts() const
-{
- return sorts;
-}
+const char* ListModel::sorts[5] { "relevance", "downloads", "follows", "updated", "newest" };
} // namespace Modrinth
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
index d095b18c..9137190d 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
@@ -1,39 +1,24 @@
#pragma once
-#include <RWStorage.h>
-
-#include <QIcon>
-#include <QList>
-#include <QMetaType>
-#include <QSortFilterProxyModel>
-#include <QString>
-#include <QStringList>
-#include <QStyledItemDelegate>
-#include <QThreadPool>
-
-#include <net/NetJob.h>
-#include <functional>
-
-#include "BaseInstance.h"
#include "ModrinthPage.h"
#include "modplatform/modrinth/ModrinthPackIndex.h"
namespace Modrinth {
-typedef std::function<void(QString)> LogoCallback;
-
class ListModel : public ModPlatform::ListModel {
Q_OBJECT
public:
- ListModel(ModrinthPage* parent);
- virtual ~ListModel();
-
- public slots:
- void searchRequestFinished(QJsonDocument& doc) override;
+ ListModel(ModrinthPage* parent) : ModPlatform::ListModel(parent){};
+ virtual ~ListModel() = default;
private:
- const char** getSorts() const override;
+ void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override { Modrinth::loadIndexedPack(m, obj); };
+
+ QJsonArray documentToArray(QJsonDocument& obj) const override { return obj.object().value("hits").toArray(); };
+
+ static const char* sorts[5];
+ const char** getSorts() const override { return sorts; };
};
} // namespace Modrinth