refactor: move NetJob away from ModModel to ModAPI
This is done so that 1. ModAPI behaves more like an actual API instead of just a helper, and 2. Allows for more easily creating other mod providers that may or may not use network tasks (foreshadowing lol)
This commit is contained in:
@ -11,18 +11,10 @@ ListModel::ListModel(FlameModPage* parent) : ModPlatform::ListModel(parent) {}
|
||||
ListModel::~ListModel() {}
|
||||
|
||||
|
||||
void FlameMod::ListModel::searchRequestFinished()
|
||||
void FlameMod::ListModel::searchRequestFinished(QJsonDocument& doc)
|
||||
{
|
||||
jobPtr.reset();
|
||||
|
||||
QJsonParseError parse_error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error);
|
||||
if(parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from Flame at " << parse_error.offset << " reason: " << parse_error.errorString();
|
||||
qWarning() << response;
|
||||
return;
|
||||
}
|
||||
|
||||
QList<ModPlatform::IndexedPack> newList;
|
||||
auto packs = doc.array();
|
||||
for(auto packRaw : packs) {
|
||||
|
@ -30,7 +30,7 @@ class ListModel : public ModPlatform::ListModel {
|
||||
virtual ~ListModel();
|
||||
|
||||
private slots:
|
||||
void searchRequestFinished() override;
|
||||
void searchRequestFinished(QJsonDocument& doc) override;
|
||||
|
||||
private:
|
||||
const char** getSorts() const override;
|
||||
|
@ -36,23 +36,17 @@ FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance* instance)
|
||||
|
||||
bool FlameModPage::shouldDisplay() const { return true; }
|
||||
|
||||
void FlameModPage::onRequestVersionsSucceeded(ModPage* instance, QByteArray* response, QString addonId)
|
||||
void FlameModPage::onRequestVersionsSucceeded(QJsonDocument& doc, QString addonId)
|
||||
{
|
||||
if (addonId != current.addonId) {
|
||||
return; // wrong request
|
||||
}
|
||||
QJsonParseError parse_error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||
if (parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response from Flame at " << parse_error.offset << " reason: " << parse_error.errorString();
|
||||
qWarning() << *response;
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonArray arr = doc.array();
|
||||
try {
|
||||
FlameMod::loadIndexedPackVersions(current, arr, APPLICATION->network(), m_instance);
|
||||
} catch (const JSONValidationError& e) {
|
||||
qDebug() << *response;
|
||||
qDebug() << doc;
|
||||
qWarning() << "Error while reading Flame mod version: " << e.cause();
|
||||
}
|
||||
auto packProfile = ((MinecraftInstance*)m_instance)->getPackProfile();
|
||||
|
@ -22,5 +22,5 @@ class FlameModPage : public ModPage {
|
||||
bool shouldDisplay() const override;
|
||||
|
||||
private:
|
||||
void onRequestVersionsSucceeded(ModPage*, QByteArray*, QString) override;
|
||||
void onRequestVersionsSucceeded(QJsonDocument&, QString) override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user