feat+fix: cache Flame modpack versions
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
64d123f524
commit
64776d6bac
@ -57,6 +57,17 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
int pos = index.row();
|
||||||
|
if (pos >= modpacks.size() || pos < 0 || !index.isValid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
modpacks[pos] = value.value<Flame::IndexedPack>();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void ListModel::logoLoaded(QString logo, QIcon out)
|
void ListModel::logoLoaded(QString logo, QIcon out)
|
||||||
{
|
{
|
||||||
m_loadingLogos.removeAll(logo);
|
m_loadingLogos.removeAll(logo);
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
int rowCount(const QModelIndex &parent) const override;
|
int rowCount(const QModelIndex &parent) const override;
|
||||||
int columnCount(const QModelIndex &parent) const override;
|
int columnCount(const QModelIndex &parent) const override;
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
bool canFetchMore(const QModelIndex & parent) const override;
|
bool canFetchMore(const QModelIndex & parent) const override;
|
||||||
void fetchMore(const QModelIndex & parent) override;
|
void fetchMore(const QModelIndex & parent) override;
|
||||||
|
@ -107,18 +107,18 @@ void FlamePage::triggerSearch()
|
|||||||
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
|
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
void FlamePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
|
||||||
{
|
{
|
||||||
ui->versionSelectionBox->clear();
|
ui->versionSelectionBox->clear();
|
||||||
|
|
||||||
if (!first.isValid()) {
|
if (!curr.isValid()) {
|
||||||
if (isOpened) {
|
if (isOpened) {
|
||||||
dialog->setSuggestedPack();
|
dialog->setSuggestedPack();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
current = listModel->data(first, Qt::UserRole).value<Flame::IndexedPack>();
|
current = listModel->data(curr, Qt::UserRole).value<Flame::IndexedPack>();
|
||||||
|
|
||||||
if (current.versionsLoaded == false) {
|
if (current.versionsLoaded == false) {
|
||||||
qDebug() << "Loading flame modpack versions";
|
qDebug() << "Loading flame modpack versions";
|
||||||
@ -127,7 +127,7 @@ void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
int addonId = current.addonId;
|
int addonId = current.addonId;
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response));
|
netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response));
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId] {
|
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId, curr] {
|
||||||
if (addonId != current.addonId) {
|
if (addonId != current.addonId) {
|
||||||
return; // wrong request
|
return; // wrong request
|
||||||
}
|
}
|
||||||
@ -151,6 +151,12 @@ void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl));
|
ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant current_updated;
|
||||||
|
current_updated.setValue(current);
|
||||||
|
|
||||||
|
if (!listModel->setData(curr, current_updated, Qt::UserRole))
|
||||||
|
qWarning() << "Failed to cache versions for the current pack!";
|
||||||
|
|
||||||
suggestCurrent();
|
suggestCurrent();
|
||||||
});
|
});
|
||||||
QObject::connect(netJob, &NetJob::finished, this, [response, netJob] {
|
QObject::connect(netJob, &NetJob::finished, this, [response, netJob] {
|
||||||
|
Loading…
Reference in New Issue
Block a user