2022-03-03 00:17:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
2022-03-03 02:01:23 +00:00
|
|
|
#include "modplatform/ModAPI.h"
|
2022-03-07 19:22:57 +00:00
|
|
|
#include "modplatform/ModIndex.h"
|
2022-03-03 00:17:10 +00:00
|
|
|
#include "net/NetJob.h"
|
|
|
|
|
|
|
|
class ModPage;
|
|
|
|
|
|
|
|
namespace ModPlatform {
|
|
|
|
|
|
|
|
typedef QMap<QString, QIcon> LogoMap;
|
|
|
|
typedef std::function<void(QString)> LogoCallback;
|
|
|
|
|
|
|
|
class ListModel : public QAbstractListModel {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
ListModel(ModPage* parent);
|
|
|
|
virtual ~ListModel();
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex& parent) const override;
|
|
|
|
int columnCount(const QModelIndex& parent) const override;
|
2022-03-06 19:04:24 +00:00
|
|
|
|
2022-03-07 19:46:08 +00:00
|
|
|
QString debugName() const;
|
|
|
|
|
|
|
|
/* Retrieve information from the model at a given index with the given role */
|
2022-03-03 00:17:10 +00:00
|
|
|
QVariant data(const QModelIndex& index, int role) const override;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
2022-03-06 19:04:24 +00:00
|
|
|
|
2022-03-07 19:22:57 +00:00
|
|
|
void setActiveJob(NetJob::Ptr ptr) { jobPtr = ptr; }
|
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
bool canFetchMore(const QModelIndex& parent) const override;
|
|
|
|
void fetchMore(const QModelIndex& parent) override;
|
|
|
|
|
|
|
|
void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback);
|
|
|
|
void searchWithTerm(const QString& term, const int sort);
|
|
|
|
|
2022-03-06 19:04:24 +00:00
|
|
|
virtual void requestModVersions(const ModPlatform::IndexedPack& current);
|
2022-03-06 18:23:00 +00:00
|
|
|
|
2022-03-07 19:22:57 +00:00
|
|
|
public slots:
|
|
|
|
virtual void searchRequestFinished(QJsonDocument& doc) = 0;
|
2022-03-06 19:04:24 +00:00
|
|
|
void searchRequestFailed(QString reason);
|
2022-03-03 02:01:23 +00:00
|
|
|
|
2022-03-07 19:22:57 +00:00
|
|
|
void versionRequestSucceeded(QJsonDocument doc, QString addonId);
|
|
|
|
|
|
|
|
protected slots:
|
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
void logoFailed(QString logo);
|
|
|
|
void logoLoaded(QString logo, QIcon out);
|
|
|
|
|
2022-03-06 19:04:24 +00:00
|
|
|
void performPaginatedSearch();
|
2022-03-03 00:17:10 +00:00
|
|
|
|
|
|
|
protected:
|
2022-03-03 02:01:23 +00:00
|
|
|
virtual const char** getSorts() const = 0;
|
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
void requestLogo(QString file, QString url);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ModPage* m_parent;
|
|
|
|
|
|
|
|
QList<ModPlatform::IndexedPack> modpacks;
|
2022-03-06 19:04:24 +00:00
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
LogoMap m_logoMap;
|
|
|
|
QMap<QString, LogoCallback> waitingCallbacks;
|
2022-03-06 19:04:24 +00:00
|
|
|
QStringList m_failedLogos;
|
|
|
|
QStringList m_loadingLogos;
|
2022-03-03 00:17:10 +00:00
|
|
|
|
|
|
|
QString currentSearchTerm;
|
|
|
|
int currentSort = 0;
|
|
|
|
int nextSearchOffset = 0;
|
|
|
|
enum SearchState { None, CanPossiblyFetchMore, ResetRequested, Finished } searchState = None;
|
2022-03-06 19:04:24 +00:00
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
NetJob::Ptr jobPtr;
|
|
|
|
QByteArray response;
|
|
|
|
};
|
|
|
|
} // namespace ModPlatform
|