diff options
Diffstat (limited to 'launcher/ui/pages/modplatform/ModModel.cpp')
-rw-r--r-- | launcher/ui/pages/modplatform/ModModel.cpp | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp index 015fcf7d..b8b90f84 100644 --- a/launcher/ui/pages/modplatform/ModModel.cpp +++ b/launcher/ui/pages/modplatform/ModModel.cpp @@ -1,6 +1,6 @@ #include "ModModel.h" -#include "ModPage.h" +#include "Json.h" #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" #include "ui/dialogs/ModDownloadDialog.h" @@ -11,18 +11,6 @@ namespace ModPlatform { ListModel::ListModel(ModPage* parent) : QAbstractListModel(parent), m_parent(parent) {} -ListModel::~ListModel() {} - -int ListModel::rowCount(const QModelIndex& parent) const -{ - return modpacks.size(); -} - -int ListModel::columnCount(const QModelIndex& parent) const -{ - return 1; -} - QVariant ListModel::data(const QModelIndex& index, int role) const { int pos = index.row(); @@ -73,16 +61,6 @@ void ListModel::logoFailed(QString logo) m_loadingLogos.removeAll(logo); } -Qt::ItemFlags ListModel::flags(const QModelIndex& index) const -{ - return QAbstractListModel::flags(index); -} - -bool ListModel::canFetchMore(const QModelIndex& parent) const -{ - return searchState == CanPossiblyFetchMore; -} - void ListModel::fetchMore(const QModelIndex& parent) { if (parent.isValid()) return; @@ -140,6 +118,38 @@ void ListModel::searchWithTerm(const QString& term, const int sort) performPaginatedSearch(); } +void ListModel::searchRequestFinished(QJsonDocument& doc) +{ + jobPtr.reset(); + + QList<ModPlatform::IndexedPack> newList; + auto packs = documentToArray(doc); + + for (auto packRaw : packs) { + auto packObj = packRaw.toObject(); + + ModPlatform::IndexedPack pack; + try { + loadIndexedPack(pack, packObj); + newList.append(pack); + } catch (const JSONValidationError& e) { + qWarning() << "Error while loading mod from " << m_parent->debugName() << ": " << 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(); +} + void ListModel::searchRequestFailed(QString reason) { if (jobPtr->first()->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 409) { |