2022-01-14 14:13:42 +05:30
|
|
|
#include "ModrinthModel.h"
|
2022-03-03 05:47:10 +05:30
|
|
|
#include "ModrinthPage.h"
|
2022-01-15 13:21:47 +05:30
|
|
|
#include "minecraft/MinecraftInstance.h"
|
2022-01-14 14:13:42 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
#include <Json.h>
|
2022-01-14 14:13:42 +05:30
|
|
|
|
|
|
|
namespace Modrinth {
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
ListModel::ListModel(ModrinthPage* parent) : ModPlatform::ListModel(parent) {}
|
2022-01-14 14:13:42 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
ListModel::~ListModel() {}
|
2022-01-14 14:13:42 +05:30
|
|
|
|
|
|
|
void Modrinth::ListModel::searchRequestFinished()
|
|
|
|
{
|
|
|
|
jobPtr.reset();
|
|
|
|
|
|
|
|
QJsonParseError parse_error;
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error);
|
2022-03-03 05:47:10 +05:30
|
|
|
if (parse_error.error != QJsonParseError::NoError) {
|
|
|
|
qWarning() << "Error while parsing JSON response from Modrinth at " << parse_error.offset
|
|
|
|
<< " reason: " << parse_error.errorString();
|
2022-01-14 14:13:42 +05:30
|
|
|
qWarning() << response;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
QList<ModPlatform::IndexedPack> newList;
|
2022-01-14 14:13:42 +05:30
|
|
|
auto packs = doc.object().value("hits").toArray();
|
2022-03-03 05:47:10 +05:30
|
|
|
for (auto packRaw : packs) {
|
2022-01-14 14:13:42 +05:30
|
|
|
auto packObj = packRaw.toObject();
|
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
ModPlatform::IndexedPack pack;
|
2022-03-03 05:47:10 +05:30
|
|
|
try {
|
2022-01-14 14:13:42 +05:30
|
|
|
Modrinth::loadIndexedPack(pack, packObj);
|
|
|
|
newList.append(pack);
|
2022-03-03 05:47:10 +05:30
|
|
|
} catch (const JSONValidationError& e) {
|
2022-01-14 14:13:42 +05:30
|
|
|
qWarning() << "Error while loading mod from Modrinth: " << e.cause();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2022-03-03 05:47:10 +05:30
|
|
|
if (packs.size() < 25) {
|
2022-01-14 14:13:42 +05:30
|
|
|
searchState = Finished;
|
|
|
|
} else {
|
|
|
|
nextSearchOffset += 25;
|
|
|
|
searchState = CanPossiblyFetchMore;
|
|
|
|
}
|
|
|
|
beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1);
|
|
|
|
modpacks.append(newList);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
2022-03-03 07:31:23 +05:30
|
|
|
const char* sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" };
|
|
|
|
|
|
|
|
const char** Modrinth::ListModel::getSorts() const
|
|
|
|
{
|
|
|
|
return sorts;
|
|
|
|
}
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
} // namespace Modrinth
|