PrismLauncher/launcher/ui/pages/modplatform/flame/FlameModModel.cpp

54 lines
1.3 KiB
C++
Raw Normal View History

2022-01-16 10:20:21 +00:00
#include "FlameModModel.h"
#include "FlameModPage.h"
2022-01-16 10:20:21 +00:00
#include "minecraft/PackProfile.h"
#include <Json.h>
2022-01-16 10:20:21 +00:00
namespace FlameMod {
ListModel::ListModel(FlameModPage* parent) : ModPlatform::ListModel(parent) {}
2022-01-16 10:20:21 +00:00
ListModel::~ListModel() {}
2022-01-16 10:20:21 +00:00
void FlameMod::ListModel::searchRequestFinished(QJsonDocument& doc)
2022-01-16 10:20:21 +00:00
{
jobPtr.reset();
QList<ModPlatform::IndexedPack> newList;
2022-01-16 10:20:21 +00:00
auto packs = doc.array();
for(auto packRaw : packs) {
auto packObj = packRaw.toObject();
ModPlatform::IndexedPack pack;
2022-01-16 10:20:21 +00:00
try
{
FlameMod::loadIndexedPack(pack, packObj);
newList.append(pack);
}
catch(const JSONValidationError &e)
{
qWarning() << "Error while loading mod from Flame: " << 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[6]{ "Featured", "Popularity", "LastUpdated", "Name", "Author", "TotalDownloads" };
const char** FlameMod::ListModel::getSorts() const
{
return sorts;
}
} // namespace FlameMod