refactor: move "get versions" task from page to model
This seems more reasonable
This commit is contained in:
parent
5e9d49a910
commit
5a638fa977
@ -97,6 +97,26 @@ void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallbac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ListModel::populateVersions(ModPlatform::IndexedPack const& current)
|
||||||
|
{
|
||||||
|
auto netJob = new NetJob(QString("%1::ModVersions(%2)").arg(m_parent->debugName()).arg(current.name), APPLICATION->network());
|
||||||
|
auto response = new QByteArray();
|
||||||
|
QString addonId = current.addonId.toString();
|
||||||
|
|
||||||
|
netJob->addNetAction(Net::Download::makeByteArray(m_parent->apiProvider()->getVersionsURL(addonId), response));
|
||||||
|
|
||||||
|
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId]{
|
||||||
|
m_parent->onGetVersionsSucceeded(m_parent, response, addonId);
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(netJob, &NetJob::finished, this, [response, netJob] {
|
||||||
|
netJob->deleteLater();
|
||||||
|
delete response;
|
||||||
|
});
|
||||||
|
|
||||||
|
netJob->start();
|
||||||
|
}
|
||||||
|
|
||||||
void ListModel::performPaginatedSearch()
|
void ListModel::performPaginatedSearch()
|
||||||
{
|
{
|
||||||
QString mcVersion = ((MinecraftInstance*)((ModPage*)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft");
|
QString mcVersion = ((MinecraftInstance*)((ModPage*)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft");
|
||||||
|
@ -30,6 +30,8 @@ class ListModel : public QAbstractListModel {
|
|||||||
void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback);
|
void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback);
|
||||||
void searchWithTerm(const QString& term, const int sort);
|
void searchWithTerm(const QString& term, const int sort);
|
||||||
|
|
||||||
|
virtual void populateVersions(const ModPlatform::IndexedPack& current);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void searchRequestFinished() = 0;
|
virtual void searchRequestFinished() = 0;
|
||||||
|
|
||||||
|
@ -98,22 +98,7 @@ void ModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
ui->modSelectionButton->setText(tr("Loading versions..."));
|
ui->modSelectionButton->setText(tr("Loading versions..."));
|
||||||
ui->modSelectionButton->setEnabled(false);
|
ui->modSelectionButton->setEnabled(false);
|
||||||
|
|
||||||
auto netJob = new NetJob(QString("%1::ModVersions(%2)").arg(debugName()).arg(current.name), APPLICATION->network());
|
listModel->populateVersions(current);
|
||||||
auto response = new QByteArray();
|
|
||||||
QString addonId = current.addonId.toString();
|
|
||||||
|
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(apiProvider()->getVersionsURL(addonId), response));
|
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId]{
|
|
||||||
onModVersionSucceed(this, response, addonId);
|
|
||||||
});
|
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::finished, this, [response, netJob] {
|
|
||||||
netJob->deleteLater();
|
|
||||||
delete response;
|
|
||||||
});
|
|
||||||
|
|
||||||
netJob->start();
|
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < current.versions.size(); i++) {
|
for (int i = 0; i < current.versions.size(); i++) {
|
||||||
ui->versionSelectionBox->addItem(current.versions[i].version, QVariant(i));
|
ui->versionSelectionBox->addItem(current.versions[i].version, QVariant(i));
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Application.h>
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
#include "modplatform/ModAPI.h"
|
#include "modplatform/ModAPI.h"
|
||||||
#include "modplatform/ModIndex.h"
|
#include "modplatform/ModIndex.h"
|
||||||
#include "tasks/Task.h"
|
|
||||||
#include "ui/pages/BasePage.h"
|
#include "ui/pages/BasePage.h"
|
||||||
#include "ui/pages/modplatform/ModModel.h"
|
#include "ui/pages/modplatform/ModModel.h"
|
||||||
|
|
||||||
@ -37,13 +36,14 @@ class ModPage : public QWidget, public BasePage {
|
|||||||
virtual bool shouldDisplay() const override = 0;
|
virtual bool shouldDisplay() const override = 0;
|
||||||
const ModAPI* apiProvider() const { return api.get(); };
|
const ModAPI* apiProvider() const { return api.get(); };
|
||||||
|
|
||||||
|
virtual void onGetVersionsSucceeded(ModPage*, QByteArray*, QString) = 0;
|
||||||
|
|
||||||
void openedImpl() override;
|
void openedImpl() override;
|
||||||
bool eventFilter(QObject* watched, QEvent* event) override;
|
bool eventFilter(QObject* watched, QEvent* event) override;
|
||||||
|
|
||||||
BaseInstance* m_instance;
|
BaseInstance* m_instance;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void onModVersionSucceed(ModPage*, QByteArray*, QString) = 0;
|
|
||||||
|
|
||||||
void updateSelectionButton();
|
void updateSelectionButton();
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance* instance)
|
|||||||
|
|
||||||
bool FlameModPage::shouldDisplay() const { return true; }
|
bool FlameModPage::shouldDisplay() const { return true; }
|
||||||
|
|
||||||
void FlameModPage::onModVersionSucceed(ModPage* instance, QByteArray* response, QString addonId)
|
void FlameModPage::onGetVersionsSucceeded(ModPage* instance, QByteArray* response, QString addonId)
|
||||||
{
|
{
|
||||||
if (addonId != current.addonId) {
|
if (addonId != current.addonId) {
|
||||||
return; // wrong request
|
return; // wrong request
|
||||||
|
@ -22,5 +22,5 @@ class FlameModPage : public ModPage {
|
|||||||
bool shouldDisplay() const override;
|
bool shouldDisplay() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onModVersionSucceed(ModPage*, QByteArray*, QString) override;
|
void onGetVersionsSucceeded(ModPage*, QByteArray*, QString) override;
|
||||||
};
|
};
|
||||||
|
@ -35,7 +35,7 @@ ModrinthPage::ModrinthPage(ModDownloadDialog* dialog, BaseInstance* instance)
|
|||||||
|
|
||||||
bool ModrinthPage::shouldDisplay() const { return true; }
|
bool ModrinthPage::shouldDisplay() const { return true; }
|
||||||
|
|
||||||
void ModrinthPage::onModVersionSucceed(ModPage* instance, QByteArray* response, QString addonId)
|
void ModrinthPage::onGetVersionsSucceeded(ModPage* instance, QByteArray* response, QString addonId)
|
||||||
{
|
{
|
||||||
if (addonId != current.addonId) { return; }
|
if (addonId != current.addonId) { return; }
|
||||||
QJsonParseError parse_error;
|
QJsonParseError parse_error;
|
||||||
|
@ -22,5 +22,5 @@ class ModrinthPage : public ModPage {
|
|||||||
bool shouldDisplay() const override;
|
bool shouldDisplay() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onModVersionSucceed(ModPage*, QByteArray*, QString) override;
|
void onGetVersionsSucceeded(ModPage*, QByteArray*, QString) override;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user