2022-03-03 05:47:10 +05:30
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
2022-03-08 00:52:57 +05:30
|
|
|
#include "modplatform/ModIndex.h"
|
2022-03-03 05:47:10 +05:30
|
|
|
#include "net/NetJob.h"
|
|
|
|
|
|
|
|
class ModPage;
|
2022-04-03 03:04:26 +05:30
|
|
|
class Version;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
namespace ModPlatform {
|
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
using LogoMap = QMap<QString, QIcon>;
|
|
|
|
using LogoCallback = std::function<void (QString)>;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
class ListModel : public QAbstractListModel {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
ListModel(ModPage* parent);
|
2022-08-02 03:04:15 +05:30
|
|
|
~ListModel() override;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
inline auto rowCount(const QModelIndex& parent) const -> int override { return modpacks.size(); };
|
|
|
|
inline auto columnCount(const QModelIndex& parent) const -> int override { return 1; };
|
|
|
|
inline auto flags(const QModelIndex& index) const -> Qt::ItemFlags override { return QAbstractListModel::flags(index); };
|
2022-03-07 00:34:24 +05:30
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
auto debugName() const -> QString;
|
2022-03-08 01:16:08 +05:30
|
|
|
|
|
|
|
/* Retrieve information from the model at a given index with the given role */
|
2022-03-08 19:42:35 +05:30
|
|
|
auto data(const QModelIndex& index, int role) const -> QVariant override;
|
2022-07-19 03:47:44 +05:30
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
2022-03-07 00:34:24 +05:30
|
|
|
|
2022-03-08 02:16:18 +05:30
|
|
|
inline void setActiveJob(NetJob::Ptr ptr) { jobPtr = ptr; }
|
2022-07-15 21:48:12 +05:30
|
|
|
inline NetJob* activeJob() { return jobPtr.get(); }
|
2022-03-08 00:52:57 +05:30
|
|
|
|
2022-03-08 02:16:18 +05:30
|
|
|
/* Ask the API for more information */
|
2022-03-03 05:47:10 +05:30
|
|
|
void fetchMore(const QModelIndex& parent) override;
|
2022-04-03 03:51:02 +05:30
|
|
|
void refresh();
|
2022-04-14 18:57:03 +05:30
|
|
|
void searchWithTerm(const QString& term, const int sort, const bool filter_changed);
|
2022-07-19 03:47:44 +05:30
|
|
|
void requestModInfo(ModPlatform::IndexedPack& current, QModelIndex index);
|
2022-07-19 03:58:46 +05:30
|
|
|
void requestModVersions(const ModPlatform::IndexedPack& current, QModelIndex index);
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-03-08 03:59:59 +05:30
|
|
|
virtual void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) = 0;
|
2022-05-24 18:08:48 +05:30
|
|
|
virtual void loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj) {};
|
2022-03-08 03:59:59 +05:30
|
|
|
virtual void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) = 0;
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback);
|
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
inline auto canFetchMore(const QModelIndex& parent) const -> bool override { return searchState == CanPossiblyFetchMore; };
|
2022-03-06 23:53:00 +05:30
|
|
|
|
2022-03-08 00:52:57 +05:30
|
|
|
public slots:
|
2022-03-08 02:16:18 +05:30
|
|
|
void searchRequestFinished(QJsonDocument& doc);
|
2022-03-07 00:34:24 +05:30
|
|
|
void searchRequestFailed(QString reason);
|
2022-10-24 17:37:41 +05:30
|
|
|
void searchRequestAborted();
|
2022-03-03 07:31:23 +05:30
|
|
|
|
2022-07-19 03:47:44 +05:30
|
|
|
void infoRequestFinished(QJsonDocument& doc, ModPlatform::IndexedPack& pack, const QModelIndex& index);
|
2022-05-24 18:08:48 +05:30
|
|
|
|
2022-07-19 03:58:46 +05:30
|
|
|
void versionRequestSucceeded(QJsonDocument doc, QString addonId, const QModelIndex& index);
|
2022-03-08 00:52:57 +05:30
|
|
|
|
|
|
|
protected slots:
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
void logoFailed(QString logo);
|
|
|
|
void logoLoaded(QString logo, QIcon out);
|
|
|
|
|
2022-03-07 00:34:24 +05:30
|
|
|
void performPaginatedSearch();
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
protected:
|
2022-03-08 19:42:35 +05:30
|
|
|
virtual auto documentToArray(QJsonDocument& obj) const -> QJsonArray = 0;
|
|
|
|
virtual auto getSorts() const -> const char** = 0;
|
2022-03-03 07:31:23 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
void requestLogo(QString file, QString url);
|
|
|
|
|
2022-04-03 03:04:26 +05:30
|
|
|
inline auto getMineVersions() const -> std::list<Version>;
|
2022-03-25 03:09:53 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
protected:
|
|
|
|
ModPage* m_parent;
|
|
|
|
|
|
|
|
QList<ModPlatform::IndexedPack> modpacks;
|
2022-03-07 00:34:24 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
LogoMap m_logoMap;
|
|
|
|
QMap<QString, LogoCallback> waitingCallbacks;
|
2022-03-07 00:34:24 +05:30
|
|
|
QStringList m_failedLogos;
|
|
|
|
QStringList m_loadingLogos;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
QString currentSearchTerm;
|
|
|
|
int currentSort = 0;
|
|
|
|
int nextSearchOffset = 0;
|
|
|
|
enum SearchState { None, CanPossiblyFetchMore, ResetRequested, Finished } searchState = None;
|
2022-03-07 00:34:24 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
NetJob::Ptr jobPtr;
|
|
|
|
};
|
|
|
|
} // namespace ModPlatform
|