PrismLauncher/launcher/ui/pages/modplatform/ModModel.h

79 lines
2.1 KiB
C
Raw Normal View History

#pragma once
#include <QAbstractListModel>
#include "modplatform/ModAPI.h"
#include "modplatform/ModIndex.h"
#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
QString debugName() const;
/* Retrieve information from the model at a given index with the given role */
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
void setActiveJob(NetJob::Ptr ptr) { jobPtr = ptr; }
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);
public slots:
virtual void searchRequestFinished(QJsonDocument& doc) = 0;
2022-03-06 19:04:24 +00:00
void searchRequestFailed(QString reason);
void versionRequestSucceeded(QJsonDocument doc, QString addonId);
protected slots:
void logoFailed(QString logo);
void logoLoaded(QString logo, QIcon out);
2022-03-06 19:04:24 +00:00
void performPaginatedSearch();
protected:
virtual const char** getSorts() const = 0;
void requestLogo(QString file, QString url);
protected:
ModPage* m_parent;
QList<ModPlatform::IndexedPack> modpacks;
2022-03-06 19:04:24 +00:00
LogoMap m_logoMap;
QMap<QString, LogoCallback> waitingCallbacks;
2022-03-06 19:04:24 +00:00
QStringList m_failedLogos;
QStringList m_loadingLogos;
QString currentSearchTerm;
int currentSort = 0;
int nextSearchOffset = 0;
enum SearchState { None, CanPossiblyFetchMore, ResetRequested, Finished } searchState = None;
2022-03-06 19:04:24 +00:00
NetJob::Ptr jobPtr;
QByteArray response;
};
} // namespace ModPlatform