fix mod select (#4305)
This commit is contained in:
@@ -6,12 +6,14 @@
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "ui_ManagedPackPage.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QListView>
|
||||
#include <QProxyStyle>
|
||||
#include <QStyleFactory>
|
||||
#include <memory>
|
||||
|
||||
#include "Application.h"
|
||||
#include "BuildConfig.h"
|
||||
@@ -284,7 +286,8 @@ void ModrinthManagedPackPage::parseManagedPack()
|
||||
};
|
||||
callbacks.on_fail = [this](QString reason, int) { setFailState(); };
|
||||
callbacks.on_abort = [this]() { setFailState(); };
|
||||
m_fetch_job = m_api.getProjectVersions({ m_pack, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
|
||||
m_fetch_job = m_api.getProjectVersions(
|
||||
{ std::make_shared<ModPlatform::IndexedPack>(m_pack), {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
|
||||
|
||||
ui->changelogTextBrowser->setText(tr("Fetching changelogs..."));
|
||||
|
||||
@@ -455,7 +458,8 @@ void FlameManagedPackPage::parseManagedPack()
|
||||
};
|
||||
callbacks.on_fail = [this](QString reason, int) { setFailState(); };
|
||||
callbacks.on_abort = [this]() { setFailState(); };
|
||||
m_fetch_job = m_api.getProjectVersions({ m_pack, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
|
||||
m_fetch_job = m_api.getProjectVersions(
|
||||
{ std::make_shared<ModPlatform::IndexedPack>(m_pack), {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
|
||||
|
||||
m_fetch_job->start();
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ ResourceAPI::SearchArgs DataPackResourceModel::createSearchArguments()
|
||||
|
||||
ResourceAPI::VersionSearchArgs DataPackResourceModel::createVersionsArguments(const QModelIndex& entry)
|
||||
{
|
||||
auto& pack = m_packs[entry.row()];
|
||||
return { *pack, {}, ModPlatform::ModLoaderType::DataPack };
|
||||
auto pack = m_packs[entry.row()];
|
||||
return { pack, {}, ModPlatform::ModLoaderType::DataPack };
|
||||
}
|
||||
|
||||
ResourceAPI::ProjectInfoArgs DataPackResourceModel::createInfoArguments(const QModelIndex& entry)
|
||||
{
|
||||
auto& pack = m_packs[entry.row()];
|
||||
return { *pack };
|
||||
auto pack = m_packs[entry.row()];
|
||||
return { pack };
|
||||
}
|
||||
|
||||
void DataPackResourceModel::searchWithTerm(const QString& term, unsigned int sort)
|
||||
|
||||
@@ -49,7 +49,7 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
||||
|
||||
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(const QModelIndex& entry)
|
||||
{
|
||||
auto& pack = *m_packs[entry.row()];
|
||||
auto pack = m_packs[entry.row()];
|
||||
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
||||
|
||||
Q_ASSERT(profile);
|
||||
@@ -67,7 +67,7 @@ ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(const QModelInd
|
||||
|
||||
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(const QModelIndex& entry)
|
||||
{
|
||||
auto& pack = *m_packs[entry.row()];
|
||||
auto pack = m_packs[entry.row()];
|
||||
return { pack };
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ void ResourceModel::search()
|
||||
if (m_search_term.startsWith("#")) {
|
||||
auto projectId = m_search_term.mid(1);
|
||||
if (!projectId.isEmpty()) {
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks;
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
|
||||
|
||||
callbacks.on_fail = [this](QString reason, int) {
|
||||
if (!s_running_models.constFind(this).value())
|
||||
@@ -159,7 +159,9 @@ void ResourceModel::search()
|
||||
return;
|
||||
searchRequestForOneSucceeded(pack);
|
||||
};
|
||||
if (auto job = m_api->getProjectInfo({ projectId }, std::move(callbacks)); job)
|
||||
auto project = std::make_shared<ModPlatform::IndexedPack>();
|
||||
project->addonId = projectId;
|
||||
if (auto job = m_api->getProjectInfo({ project }, std::move(callbacks)); job)
|
||||
runSearchJob(job);
|
||||
return;
|
||||
}
|
||||
@@ -219,7 +221,7 @@ void ResourceModel::loadEntry(const QModelIndex& entry)
|
||||
|
||||
if (!pack->extraDataLoaded) {
|
||||
auto args{ createInfoArguments(entry) };
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks{};
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks{};
|
||||
|
||||
callbacks.on_succeed = [this, entry](auto& newpack) {
|
||||
if (!s_running_models.constFind(this).value())
|
||||
@@ -388,12 +390,12 @@ void ResourceModel::searchRequestSucceeded(QList<ModPlatform::IndexedPack::Ptr>&
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void ResourceModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack& pack)
|
||||
void ResourceModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr pack)
|
||||
{
|
||||
m_search_state = SearchState::Finished;
|
||||
|
||||
beginInsertRows(QModelIndex(), m_packs.size(), m_packs.size() + 1);
|
||||
m_packs.append(std::make_shared<ModPlatform::IndexedPack>(pack));
|
||||
m_packs.append(pack);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
@@ -448,18 +450,17 @@ void ResourceModel::versionRequestSucceeded(QVector<ModPlatform::IndexedVersion>
|
||||
emit versionListUpdated(index);
|
||||
}
|
||||
|
||||
void ResourceModel::infoRequestSucceeded(ModPlatform::IndexedPack& pack, const QModelIndex& index)
|
||||
void ResourceModel::infoRequestSucceeded(ModPlatform::IndexedPack::Ptr pack, const QModelIndex& index)
|
||||
{
|
||||
auto current_pack = data(index, Qt::UserRole).value<ModPlatform::IndexedPack::Ptr>();
|
||||
|
||||
// Check if the index is still valid for this resource or not
|
||||
if (pack.addonId != current_pack->addonId)
|
||||
if (pack->addonId != current_pack->addonId)
|
||||
return;
|
||||
|
||||
*current_pack = pack;
|
||||
// Cache info :^)
|
||||
QVariant new_pack;
|
||||
new_pack.setValue(current_pack);
|
||||
new_pack.setValue(pack);
|
||||
if (!setData(index, new_pack, Qt::UserRole)) {
|
||||
qWarning() << "Failed to cache resource info!";
|
||||
return;
|
||||
|
||||
@@ -138,13 +138,13 @@ class ResourceModel : public QAbstractListModel {
|
||||
private:
|
||||
/* Default search request callbacks */
|
||||
void searchRequestSucceeded(QList<ModPlatform::IndexedPack::Ptr>&);
|
||||
void searchRequestForOneSucceeded(ModPlatform::IndexedPack&);
|
||||
void searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr);
|
||||
void searchRequestFailed(QString reason, int network_error_code);
|
||||
void searchRequestAborted();
|
||||
|
||||
void versionRequestSucceeded(QVector<ModPlatform::IndexedVersion>&, QVariant, const QModelIndex&);
|
||||
|
||||
void infoRequestSucceeded(ModPlatform::IndexedPack&, const QModelIndex&);
|
||||
void infoRequestSucceeded(ModPlatform::IndexedPack::Ptr, const QModelIndex&);
|
||||
|
||||
signals:
|
||||
void versionListUpdated(const QModelIndex& index);
|
||||
|
||||
@@ -25,14 +25,14 @@ ResourceAPI::SearchArgs ResourcePackResourceModel::createSearchArguments()
|
||||
|
||||
ResourceAPI::VersionSearchArgs ResourcePackResourceModel::createVersionsArguments(const QModelIndex& entry)
|
||||
{
|
||||
auto& pack = m_packs[entry.row()];
|
||||
return { *pack, {}, {}, ModPlatform::ResourceType::ResourcePack };
|
||||
auto pack = m_packs[entry.row()];
|
||||
return { pack, {}, {}, ModPlatform::ResourceType::ResourcePack };
|
||||
}
|
||||
|
||||
ResourceAPI::ProjectInfoArgs ResourcePackResourceModel::createInfoArguments(const QModelIndex& entry)
|
||||
{
|
||||
auto& pack = m_packs[entry.row()];
|
||||
return { *pack };
|
||||
auto pack = m_packs[entry.row()];
|
||||
return { pack };
|
||||
}
|
||||
|
||||
void ResourcePackResourceModel::searchWithTerm(const QString& term, unsigned int sort)
|
||||
|
||||
@@ -22,14 +22,14 @@ ResourceAPI::SearchArgs ShaderPackResourceModel::createSearchArguments()
|
||||
|
||||
ResourceAPI::VersionSearchArgs ShaderPackResourceModel::createVersionsArguments(const QModelIndex& entry)
|
||||
{
|
||||
auto& pack = m_packs[entry.row()];
|
||||
return { *pack, {}, {}, ModPlatform::ResourceType::ShaderPack };
|
||||
auto pack = m_packs[entry.row()];
|
||||
return { pack, {}, {}, ModPlatform::ResourceType::ShaderPack };
|
||||
}
|
||||
|
||||
ResourceAPI::ProjectInfoArgs ShaderPackResourceModel::createInfoArguments(const QModelIndex& entry)
|
||||
{
|
||||
auto& pack = m_packs[entry.row()];
|
||||
return { *pack };
|
||||
auto pack = m_packs[entry.row()];
|
||||
return { pack };
|
||||
}
|
||||
|
||||
void ShaderPackResourceModel::searchWithTerm(const QString& term, unsigned int sort)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Version.h>
|
||||
|
||||
#include <QtMath>
|
||||
#include <memory>
|
||||
|
||||
namespace Flame {
|
||||
|
||||
@@ -167,7 +168,7 @@ void ListModel::performPaginatedSearch()
|
||||
if (m_currentSearchTerm.startsWith("#")) {
|
||||
auto projectId = m_currentSearchTerm.mid(1);
|
||||
if (!projectId.isEmpty()) {
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks;
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
|
||||
|
||||
callbacks.on_fail = [this](QString reason, int) { searchRequestFailed(reason); };
|
||||
callbacks.on_succeed = [this](auto& pack) { searchRequestForOneSucceeded(pack); };
|
||||
@@ -175,7 +176,9 @@ void ListModel::performPaginatedSearch()
|
||||
qCritical() << "Search task aborted by an unknown reason!";
|
||||
searchRequestFailed("Aborted");
|
||||
};
|
||||
if (auto job = api.getProjectInfo({ { projectId } }, std::move(callbacks)); job) {
|
||||
auto project = std::make_shared<ModPlatform::IndexedPack>();
|
||||
project->addonId = projectId;
|
||||
if (auto job = api.getProjectInfo({ project }, std::move(callbacks)); job) {
|
||||
m_jobPtr = job;
|
||||
m_jobPtr->start();
|
||||
}
|
||||
@@ -245,12 +248,12 @@ void Flame::ListModel::searchRequestFinished(QList<ModPlatform::IndexedPack::Ptr
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void Flame::ListModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack& pack)
|
||||
void Flame::ListModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr pack)
|
||||
{
|
||||
m_jobPtr.reset();
|
||||
|
||||
beginInsertRows(QModelIndex(), m_modpacks.size(), m_modpacks.size() + 1);
|
||||
m_modpacks.append(std::make_shared<ModPlatform::IndexedPack>(pack));
|
||||
m_modpacks.append(pack);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class ListModel : public QAbstractListModel {
|
||||
|
||||
void searchRequestFinished(QList<ModPlatform::IndexedPack::Ptr>&);
|
||||
void searchRequestFailed(QString reason);
|
||||
void searchRequestForOneSucceeded(ModPlatform::IndexedPack&);
|
||||
void searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr);
|
||||
|
||||
private:
|
||||
void requestLogo(QString file, QString url);
|
||||
|
||||
@@ -203,7 +203,7 @@ void FlamePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelInde
|
||||
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec();
|
||||
};
|
||||
|
||||
auto netJob = api.getProjectVersions({ *m_current, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
|
||||
auto netJob = api.getProjectVersions({ m_current, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
|
||||
|
||||
m_job = netJob;
|
||||
netJob->start();
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include "net/ApiDownload.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <memory>
|
||||
|
||||
namespace Modrinth {
|
||||
|
||||
@@ -137,7 +138,7 @@ void ModpackListModel::performPaginatedSearch()
|
||||
if (m_currentSearchTerm.startsWith("#")) {
|
||||
auto projectId = m_currentSearchTerm.mid(1);
|
||||
if (!projectId.isEmpty()) {
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks;
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
|
||||
|
||||
callbacks.on_fail = [this](QString reason, int) { searchRequestFailed(reason); };
|
||||
callbacks.on_succeed = [this](auto& pack) { searchRequestForOneSucceeded(pack); };
|
||||
@@ -145,7 +146,9 @@ void ModpackListModel::performPaginatedSearch()
|
||||
qCritical() << "Search task aborted by an unknown reason!";
|
||||
searchRequestFailed("Aborted");
|
||||
};
|
||||
if (auto job = api.getProjectInfo({ projectId }, std::move(callbacks)); job) {
|
||||
auto project = std::make_shared<ModPlatform::IndexedPack>();
|
||||
project->addonId = projectId;
|
||||
if (auto job = api.getProjectInfo({ project }, std::move(callbacks)); job) {
|
||||
m_jobPtr = job;
|
||||
m_jobPtr->start();
|
||||
}
|
||||
@@ -304,12 +307,12 @@ void ModpackListModel::searchRequestFinished(QList<ModPlatform::IndexedPack::Ptr
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void ModpackListModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack& pack)
|
||||
void ModpackListModel::searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr pack)
|
||||
{
|
||||
m_jobPtr.reset();
|
||||
|
||||
beginInsertRows(QModelIndex(), m_modpacks.size(), m_modpacks.size() + 1);
|
||||
m_modpacks.append(std::make_shared<ModPlatform::IndexedPack>(pack));
|
||||
m_modpacks.append(pack);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ class ModpackListModel : public QAbstractListModel {
|
||||
public slots:
|
||||
void searchRequestFinished(QList<ModPlatform::IndexedPack::Ptr>& doc_all);
|
||||
void searchRequestFailed(QString reason);
|
||||
void searchRequestForOneSucceeded(ModPlatform::IndexedPack&);
|
||||
void searchRequestForOneSucceeded(ModPlatform::IndexedPack::Ptr);
|
||||
|
||||
protected slots:
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
|
||||
|
||||
if (!m_current->extraDataLoaded) {
|
||||
qDebug() << "Loading modrinth modpack information";
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack> callbacks;
|
||||
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
|
||||
|
||||
auto id = m_current->addonId;
|
||||
callbacks.on_fail = [this](QString reason, int) {
|
||||
@@ -157,10 +157,8 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
|
||||
return; // wrong request?
|
||||
}
|
||||
|
||||
*m_current = pack;
|
||||
|
||||
QVariant current_updated;
|
||||
current_updated.setValue(m_current);
|
||||
current_updated.setValue(pack);
|
||||
|
||||
if (!m_model->setData(curr, current_updated, Qt::UserRole))
|
||||
qWarning() << "Failed to cache extra info for the current pack!";
|
||||
@@ -168,7 +166,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
|
||||
suggestCurrent();
|
||||
updateUI();
|
||||
};
|
||||
if (auto netJob = m_api.getProjectInfo({ { m_current->addonId } }, std::move(callbacks)); netJob) {
|
||||
if (auto netJob = m_api.getProjectInfo({ m_current }, std::move(callbacks)); netJob) {
|
||||
m_job = netJob;
|
||||
m_job->start();
|
||||
}
|
||||
@@ -220,7 +218,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
|
||||
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec();
|
||||
};
|
||||
|
||||
auto netJob = m_api.getProjectVersions({ *m_current, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
|
||||
auto netJob = m_api.getProjectVersions({ m_current, {}, {}, ModPlatform::ResourceType::Modpack }, std::move(callbacks));
|
||||
|
||||
m_job2 = netJob;
|
||||
m_job2->start();
|
||||
|
||||
Reference in New Issue
Block a user