Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into import_zip

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2023-08-15 12:59:25 +03:00
219 changed files with 3290 additions and 1839 deletions

View File

@ -49,7 +49,7 @@ class UrlValidator : public QValidator {
public:
using QValidator::QValidator;
State validate(QString& in, int& pos) const
State validate(QString& in, [[maybe_unused]] int& pos) const
{
const QUrl url(in);
if (url.isValid() && !url.isRelative() && !url.isEmpty()) {
@ -107,8 +107,8 @@ void ImportPage::updateState()
bool isMRPack = fi.suffix() == "mrpack";
if (fi.exists() && (isZip || isMRPack)) {
QFileInfo fi(url.fileName());
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this));
QFileInfo file_info(url.fileName());
dialog->setSuggestedPack(file_info.completeBaseName(), new InstanceImportTask(url, this));
dialog->setSuggestedIcon("default");
}
} else {

View File

@ -17,7 +17,7 @@
#include "BuildConfig.h"
#include "Json.h"
#include "net/Download.h"
#include "net/ApiDownload.h"
#include "net/NetJob.h"
#include "modplatform/ModIndex.h"
@ -102,7 +102,7 @@ QHash<int, QByteArray> ResourceModel::roleNames() const
return roles;
}
bool ResourceModel::setData(const QModelIndex& index, const QVariant& value, int role)
bool ResourceModel::setData(const QModelIndex& index, const QVariant& value, [[maybe_unused]] int role)
{
int pos = index.row();
if (pos >= m_packs.size() || pos < 0 || !index.isValid())
@ -281,7 +281,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
auto cache_entry = APPLICATION->metacache()->resolveEntry(
metaEntryBase(),
QString("logos/%1").arg(QString(QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Algorithm::Sha1).toHex())));
auto icon_fetch_action = Net::Download::makeCached(url, cache_entry);
auto icon_fetch_action = Net::ApiDownload::makeCached(url, cache_entry);
auto full_file_path = cache_entry->getFullPath();
connect(icon_fetch_action.get(), &NetAction::succeeded, this, [=] {
@ -310,7 +310,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
#define NEED_FOR_CALLBACK_ASSERT(name) \
Q_ASSERT_X(0 != 0, #name, "You NEED to re-implement this if you intend on using the default callbacks.")
QJsonArray ResourceModel::documentToArray(QJsonDocument& doc) const
QJsonArray ResourceModel::documentToArray([[maybe_unused]] QJsonDocument& doc) const
{
NEED_FOR_CALLBACK_ASSERT("documentToArray");
return {};
@ -372,7 +372,7 @@ void ResourceModel::searchRequestSucceeded(QJsonDocument& doc)
endInsertRows();
}
void ResourceModel::searchRequestFailed(QString reason, int network_error_code)
void ResourceModel::searchRequestFailed([[maybe_unused]] QString reason, int network_error_code)
{
switch (network_error_code) {
default:

View File

@ -42,7 +42,10 @@ class ResourceModel : public QAbstractListModel {
[[nodiscard]] virtual auto debugName() const -> QString;
[[nodiscard]] virtual auto metaEntryBase() const -> QString = 0;
[[nodiscard]] inline int rowCount(const QModelIndex& parent) const override { return parent.isValid() ? 0 : m_packs.size(); }
[[nodiscard]] inline int rowCount(const QModelIndex& parent) const override
{
return parent.isValid() ? 0 : static_cast<int>(m_packs.size());
}
[[nodiscard]] inline int columnCount(const QModelIndex& parent) const override { return parent.isValid() ? 0 : 1; }
[[nodiscard]] inline auto flags(const QModelIndex& index) const -> Qt::ItemFlags override { return QAbstractListModel::flags(index); }

View File

@ -9,7 +9,8 @@
namespace ResourceDownload {
ResourcePackResourceModel::ResourcePackResourceModel(BaseInstance const& base_inst, ResourceAPI* api)
: ResourceModel(api), m_base_instance(base_inst){};
: ResourceModel(api), m_base_instance(base_inst)
{}
/******** Make data requests ********/

View File

@ -4,7 +4,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -280,7 +280,7 @@ void ResourcePage::updateVersionList()
updateSelectionButton();
}
void ResourcePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelIndex prev)
{
if (!curr.isValid()) {
return;
@ -307,9 +307,9 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
updateUi();
}
void ResourcePage::onVersionSelectionChanged(QString data)
void ResourcePage::onVersionSelectionChanged(QString versionData)
{
if (data.isNull() || data.isEmpty()) {
if (versionData.isNull() || versionData.isEmpty()) {
m_selected_version_index = -1;
return;
}
@ -395,7 +395,7 @@ void ResourcePage::openUrl(const QUrl& url)
if (auto current_pack = getCurrentPack(); current_pack && slug != current_pack->slug) {
m_parent_dialog->selectPage(page);
auto newPage = m_parent_dialog->getSelectedPage();
auto newPage = m_parent_dialog->selectedPage();
QLineEdit* searchEdit = newPage->m_ui->searchEdit;
auto model = newPage->m_model;

View File

@ -97,7 +97,11 @@ class ResourcePage : public QWidget, public BasePage {
virtual void openUrl(const QUrl&);
/** Whether the version is opted out or not. Currently only makes sense in CF. */
virtual bool optedOut(ModPlatform::IndexedVersion& ver) const { return false; };
virtual bool optedOut(ModPlatform::IndexedVersion& ver) const
{
Q_UNUSED(ver);
return false;
};
public:
BaseInstance& m_base_instance;

View File

@ -9,7 +9,8 @@
namespace ResourceDownload {
ShaderPackResourceModel::ShaderPackResourceModel(BaseInstance const& base_inst, ResourceAPI* api)
: ResourceModel(api), m_base_instance(base_inst){};
: ResourceModel(api), m_base_instance(base_inst)
{}
/******** Make data requests ********/

View File

@ -20,6 +20,8 @@
#include <BuildConfig.h>
#include <Json.h>
#include "net/ApiDownload.h"
namespace Atl {
ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {}
@ -75,7 +77,7 @@ void ListModel::request()
auto netJob = makeShared<NetJob>("Atl::Request", APPLICATION->network());
auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/json/packsnew.json");
netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), response));
netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(url), response));
jobPtr = netJob;
jobPtr->start();
@ -137,8 +139,7 @@ void ListModel::requestFailed(QString reason)
void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
callback(
APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
callback(APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
@ -168,9 +169,9 @@ void ListModel::requestLogo(QString file, QString url)
return;
}
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(file));
auto job = new NetJob(QString("ATLauncher Icon Download %1").arg(file), APPLICATION->network());
job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::succeeded, this, [this, file, fullPath, job] {

View File

@ -43,6 +43,8 @@
#include "Json.h"
#include "modplatform/atlauncher/ATLShareCode.h"
#include "net/ApiDownload.h"
AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods)
: QAbstractListModel(parent), m_version(version), m_mods(mods)
{
@ -113,7 +115,7 @@ QVariant AtlOptionalModListModel::data(const QModelIndex& index, int role) const
return {};
}
bool AtlOptionalModListModel::setData(const QModelIndex& index, const QVariant& value, int role)
bool AtlOptionalModListModel::setData(const QModelIndex& index, [[maybe_unused]] const QVariant& value, int role)
{
if (role == Qt::CheckStateRole) {
auto row = index.row();
@ -155,7 +157,7 @@ void AtlOptionalModListModel::useShareCode(const QString& code)
{
m_jobPtr.reset(new NetJob("Atl::Request", APPLICATION->network()));
auto url = QString(BuildConfig.ATL_API_BASE_URL + "share-codes/" + code);
m_jobPtr->addNetAction(Net::Download::makeByteArray(QUrl(url), m_response));
m_jobPtr->addNetAction(Net::ApiDownload::makeByteArray(QUrl(url), m_response));
connect(m_jobPtr.get(), &NetJob::succeeded, this, &AtlOptionalModListModel::shareCodeSuccess);
connect(m_jobPtr.get(), &NetJob::failed, this, &AtlOptionalModListModel::shareCodeFailure);
@ -206,7 +208,7 @@ void AtlOptionalModListModel::shareCodeSuccess()
emit dataChanged(AtlOptionalModListModel::index(0, EnabledColumn), AtlOptionalModListModel::index(m_mods.size() - 1, EnabledColumn));
}
void AtlOptionalModListModel::shareCodeFailure(const QString& reason)
void AtlOptionalModListModel::shareCodeFailure([[maybe_unused]] const QString& reason)
{
m_jobPtr.reset();
@ -281,15 +283,15 @@ void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool
// if the dependency is 'effectively hidden', then track which mods
// depend on it - so we can efficiently disable it when no more dependents
// depend on it.
auto dependants = m_dependants[dependencyName];
auto dependents = m_dependents[dependencyName];
if (enable) {
dependants.append(mod.name);
dependents.append(mod.name);
} else {
dependants.removeAll(mod.name);
dependents.removeAll(mod.name);
// if there are no longer any dependents, let's disable the mod
if (dependencyMod.effectively_hidden && dependants.isEmpty()) {
if (dependencyMod.effectively_hidden && dependents.isEmpty()) {
setMod(dependencyMod, dependencyIndex, false, shouldEmit);
}
}
@ -297,8 +299,8 @@ void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool
// disable mods that depend on this one, if disabling
if (!enable) {
auto dependants = m_dependants[mod.name];
for (const auto& dependencyName : dependants) {
auto dependents = m_dependents[mod.name];
for (const auto& dependencyName : dependents) {
auto dependencyIndex = m_index[dependencyName];
auto dependencyMod = m_mods.at(dependencyIndex);

View File

@ -90,7 +90,7 @@ class AtlOptionalModListModel : public QAbstractListModel {
QMap<QString, bool> m_selection;
QMap<QString, int> m_index;
QMap<QString, QVector<QString>> m_dependants;
QMap<QString, QVector<QString>> m_dependents;
};
class AtlOptionalModDialog : public QDialog {

View File

@ -123,13 +123,13 @@ void AtlPage::triggerSearch()
filterModel->setSearchTerm(ui->searchEdit->text());
}
void AtlPage::onSortingSelectionChanged(QString data)
void AtlPage::onSortingSelectionChanged(QString sort)
{
auto toSet = filterModel->getAvailableSortings().value(data);
auto toSet = filterModel->getAvailableSortings().value(sort);
filterModel->setSorting(toSet);
}
void AtlPage::onSelectionChanged(QModelIndex first, QModelIndex second)
void AtlPage::onSelectionChanged(QModelIndex first, [[maybe_unused]] QModelIndex second)
{
ui->versionSelectionBox->clear();
@ -151,13 +151,13 @@ void AtlPage::onSelectionChanged(QModelIndex first, QModelIndex second)
suggestCurrent();
}
void AtlPage::onVersionSelectionChanged(QString data)
void AtlPage::onVersionSelectionChanged(QString version)
{
if (data.isNull() || data.isEmpty()) {
if (version.isNull() || version.isEmpty()) {
selectedVersion = "";
return;
}
selectedVersion = data;
selectedVersion = version;
suggestCurrent();
}

View File

@ -3,6 +3,8 @@
#include "Application.h"
#include "ui/widgets/ProjectItem.h"
#include "net/ApiDownload.h"
#include <Version.h>
#include <QtMath>
@ -70,7 +72,7 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
return QVariant();
}
bool ListModel::setData(const QModelIndex& index, const QVariant& value, int role)
bool ListModel::setData(const QModelIndex& index, const QVariant& value, [[maybe_unused]] int role)
{
int pos = index.row();
if (pos >= modpacks.size() || pos < 0 || !index.isValid())
@ -104,9 +106,9 @@ void ListModel::requestLogo(QString logo, QString url)
return;
}
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0)));
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo));
auto job = new NetJob(QString("Flame Icon Download %1").arg(logo), APPLICATION->network());
job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::succeeded, this, [this, logo, fullPath, job] {
@ -130,7 +132,7 @@ void ListModel::requestLogo(QString logo, QString url)
void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
callback(APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
callback(APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
@ -141,7 +143,7 @@ Qt::ItemFlags ListModel::flags(const QModelIndex& index) const
return QAbstractListModel::flags(index);
}
bool ListModel::canFetchMore(const QModelIndex& parent) const
bool ListModel::canFetchMore([[maybe_unused]] const QModelIndex& parent) const
{
return searchState == CanPossiblyFetchMore;
}
@ -173,7 +175,7 @@ void ListModel::performPaginatedSearch()
.arg(currentSearchTerm)
.arg(currentSort + 1);
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl), response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::searchRequestFinished);

View File

@ -46,6 +46,8 @@
#include "ui/dialogs/NewInstanceDialog.h"
#include "ui/widgets/ProjectItem.h"
#include "net/ApiDownload.h"
static FlameAPI api;
FlamePage::FlamePage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::FlamePage), dialog(dialog)
@ -114,7 +116,7 @@ void FlamePage::triggerSearch()
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
}
void FlamePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
void FlamePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelIndex prev)
{
ui->versionSelectionBox->clear();
@ -132,7 +134,8 @@ void FlamePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
auto netJob = new NetJob(QString("Flame::PackVersions(%1)").arg(current.name), APPLICATION->network());
auto response = std::make_shared<QByteArray>();
int addonId = current.addonId;
netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response));
netJob->addNetAction(
Net::ApiDownload::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId, curr] {
if (addonId != current.addonId) {
@ -207,17 +210,17 @@ void FlamePage::suggestCurrent()
dialog->setSuggestedPack(current.name, new InstanceImportTask(version.downloadUrl, this, std::move(extra_info)));
QString editedLogoName;
editedLogoName = "curseforge_" + current.logoName.section(".", 0, 0);
editedLogoName = "curseforge_" + current.logoName;
listModel->getLogo(current.logoName, current.logoUrl,
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
}
void FlamePage::onVersionSelectionChanged(QString data)
void FlamePage::onVersionSelectionChanged(QString version)
{
bool is_blocked = false;
ui->versionSelectionBox->currentData().toInt(&is_blocked);
if (data.isNull() || data.isEmpty() || is_blocked) {
if (version.isNull() || version.isEmpty() || is_blocked) {
m_selected_version_index = -1;
return;
}

View File

@ -32,7 +32,7 @@ void FlameModModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonAr
auto FlameModModel::loadDependencyVersions(const ModPlatform::Dependency& m, QJsonArray& arr) -> ModPlatform::IndexedVersion
{
return FlameMod::loadDependencyVersions(m, arr);
};
}
auto FlameModModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
{

View File

@ -35,6 +35,7 @@
#include "ListModel.h"
#include "Application.h"
#include "net/ApiDownload.h"
#include "net/HttpMetaCache.h"
#include "net/NetJob.h"
@ -76,7 +77,7 @@ bool FilterModel::lessThan(const QModelIndex& left, const QModelIndex& right) co
return true;
}
bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
bool FilterModel::filterAcceptsRow([[maybe_unused]] int sourceRow, [[maybe_unused]] const QModelIndex& sourceParent) const
{
return true;
}
@ -173,10 +174,10 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
return QVariant();
}
void ListModel::fill(ModpackList modpacks)
void ListModel::fill(ModpackList modpacks_)
{
beginResetModel();
this->modpacks = modpacks;
this->modpacks = modpacks_;
endResetModel();
}
@ -229,9 +230,9 @@ void ListModel::requestLogo(QString file)
return;
}
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file));
NetJob* job = new NetJob(QString("FTB Icon Download for %1").arg(file), APPLICATION->network());
job->addNetAction(Net::Download::makeCached(QUrl(QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/%1").arg(file)), entry));
job->addNetAction(Net::ApiDownload::makeCached(QUrl(QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/%1").arg(file)), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath, job] {
@ -255,7 +256,7 @@ void ListModel::requestLogo(QString file)
void ListModel::getLogo(const QString& logo, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
callback(APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
callback(APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo);
}

View File

@ -215,7 +215,7 @@ void Page::ftbPrivatePackDataDownloadSuccessfully(Modpack pack)
privateListModel->addPack(pack);
}
void Page::ftbPrivatePackDataDownloadFailed(QString reason, QString packCode)
void Page::ftbPrivatePackDataDownloadFailed([[maybe_unused]] QString reason, QString packCode)
{
auto reply = QMessageBox::question(this, tr("FTB private packs"),
tr("Failed to download pack information for code %1.\nShould it be removed now?").arg(packCode));
@ -224,7 +224,7 @@ void Page::ftbPrivatePackDataDownloadFailed(QString reason, QString packCode)
}
}
void Page::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
void Page::onPublicPackSelectionChanged(QModelIndex now, [[maybe_unused]] QModelIndex prev)
{
if (!now.isValid()) {
onPackSelectionChanged();
@ -234,7 +234,7 @@ void Page::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
onPackSelectionChanged(&selectedPack);
}
void Page::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
void Page::onThirdPartyPackSelectionChanged(QModelIndex now, [[maybe_unused]] QModelIndex prev)
{
if (!now.isValid()) {
onPackSelectionChanged();
@ -244,7 +244,7 @@ void Page::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
onPackSelectionChanged(&selectedPack);
}
void Page::onPrivatePackSelectionChanged(QModelIndex now, QModelIndex prev)
void Page::onPrivatePackSelectionChanged(QModelIndex now, [[maybe_unused]] QModelIndex prev)
{
if (!now.isValid()) {
onPackSelectionChanged();
@ -284,20 +284,20 @@ void Page::onPackSelectionChanged(Modpack* pack)
suggestCurrent();
}
void Page::onVersionSelectionItemChanged(QString data)
void Page::onVersionSelectionItemChanged(QString version)
{
if (data.isNull() || data.isEmpty()) {
if (version.isNull() || version.isEmpty()) {
selectedVersion = "";
return;
}
selectedVersion = data;
selectedVersion = version;
suggestCurrent();
}
void Page::onSortingSelectionChanged(QString data)
void Page::onSortingSelectionChanged(QString sort)
{
FilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
FilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(sort);
publicFilterModel->setSorting(toSet);
thirdPartyFilterModel->setSorting(toSet);
privateFilterModel->setSorting(toSet);

View File

@ -42,6 +42,8 @@
#include "minecraft/PackProfile.h"
#include "ui/widgets/ProjectItem.h"
#include "net/ApiDownload.h"
#include <QMessageBox>
namespace Modrinth {
@ -115,7 +117,7 @@ auto ModpackListModel::data(const QModelIndex& index, int role) const -> QVarian
return {};
}
bool ModpackListModel::setData(const QModelIndex& index, const QVariant& value, int role)
bool ModpackListModel::setData(const QModelIndex& index, const QVariant& value, [[maybe_unused]] int role)
{
int pos = index.row();
if (pos >= modpacks.size() || pos < 0 || !index.isValid())
@ -142,7 +144,7 @@ void ModpackListModel::performPaginatedSearch()
.arg(currentSearchTerm)
.arg(currentSort);
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchAllUrl), m_all_response));
netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchAllUrl), m_all_response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, [this] {
QJsonParseError parse_error_all{};
@ -194,8 +196,6 @@ static auto sortFromIndex(int index) -> QString
case 4:
return "updated";
}
return {};
}
void ModpackListModel::searchWithTerm(const QString& term, const int sort)
@ -218,9 +218,7 @@ void ModpackListModel::searchWithTerm(const QString& term, const int sort)
void ModpackListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
callback(APPLICATION->metacache()
->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo.section(".", 0, 0)))
->getFullPath());
callback(APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
@ -232,10 +230,9 @@ void ModpackListModel::requestLogo(QString logo, QString url)
return;
}
MetaEntryPtr entry =
APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo.section(".", 0, 0)));
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo));
auto job = new NetJob(QString("%1 Icon Download %2").arg(m_parent->debugName()).arg(logo), APPLICATION->network());
job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::succeeded, this, [this, logo, fullPath, job] {

View File

@ -46,6 +46,8 @@
#include "ui/widgets/ProjectItem.h"
#include "net/ApiDownload.h"
#include <QComboBox>
#include <QKeyEvent>
#include <QPushButton>
@ -105,7 +107,7 @@ bool ModrinthPage::eventFilter(QObject* watched, QEvent* event)
return QObject::eventFilter(watched, event);
}
void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelIndex prev)
{
ui->versionSelectionBox->clear();
@ -127,7 +129,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
QString id = current.id;
netJob->addNetAction(Net::Download::makeByteArray(QString("%1/project/%2").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
netJob->addNetAction(Net::ApiDownload::makeByteArray(QString("%1/project/%2").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id, curr] {
if (id != current.id) {
@ -176,7 +178,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
QString id = current.id;
netJob->addNetAction(
Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
Net::ApiDownload::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id, curr] {
if (id != current.id) {
@ -309,9 +311,9 @@ void ModrinthPage::triggerSearch()
m_model->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
}
void ModrinthPage::onVersionSelectionChanged(QString data)
void ModrinthPage::onVersionSelectionChanged(QString version)
{
if (data.isNull() || data.isEmpty()) {
if (version.isNull() || version.isEmpty()) {
selectedVersion = "";
return;
}

View File

@ -45,7 +45,7 @@ void ModrinthModModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJso
auto ModrinthModModel::loadDependencyVersions(const ModPlatform::Dependency& m, QJsonArray& arr) -> ModPlatform::IndexedVersion
{
return ::Modrinth::loadDependencyVersions(m, arr);
};
}
auto ModrinthModModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
{

View File

@ -38,6 +38,8 @@
#include "BuildConfig.h"
#include "Json.h"
#include "net/ApiDownload.h"
#include <QIcon>
Technic::ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {}
@ -116,7 +118,7 @@ void Technic::ListModel::performSearch()
QString("%1search?build=%2&q=%3").arg(BuildConfig.TECHNIC_API_BASE_URL, BuildConfig.TECHNIC_API_BUILD, currentSearchTerm);
searchMode = List;
}
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl), response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::searchRequestFinished);
@ -157,7 +159,7 @@ void Technic::ListModel::searchRequestFinished()
pack.logoName = "null";
} else {
pack.logoUrl = rawURL;
pack.logoName = rawURL.section(QLatin1Char('/'), -1).section(QLatin1Char('.'), 0, 0);
pack.logoName = rawURL.section(QLatin1Char('/'), -1);
}
pack.broken = false;
newList.append(pack);
@ -179,7 +181,7 @@ void Technic::ListModel::searchRequestFinished()
auto iconUrl = Json::requireString(iconObj, "url");
pack.logoUrl = iconUrl;
pack.logoName = iconUrl.section(QLatin1Char('/'), -1).section(QLatin1Char('.'), 0, 0);
pack.logoName = iconUrl.section(QLatin1Char('/'), -1);
} else {
pack.logoUrl = "null";
pack.logoName = "null";
@ -254,7 +256,7 @@ void Technic::ListModel::requestLogo(QString logo, QString url)
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("TechnicPacks", QString("logos/%1").arg(logo));
auto job = new NetJob(QString("Technic Icon Download %1").arg(logo), APPLICATION->network());
job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();

View File

@ -49,6 +49,8 @@
#include "Application.h"
#include "modplatform/technic/SolderPackManifest.h"
#include "net/ApiDownload.h"
TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog)
{
ui->setupUi(this);
@ -100,7 +102,7 @@ void TechnicPage::triggerSearch()
model->searchWithTerm(ui->searchEdit->text());
}
void TechnicPage::onSelectionChanged(QModelIndex first, QModelIndex second)
void TechnicPage::onSelectionChanged(QModelIndex first, [[maybe_unused]] QModelIndex second)
{
ui->versionSelectionBox->clear();
@ -125,7 +127,7 @@ void TechnicPage::suggestCurrent()
return;
}
QString editedLogoName = "technic_" + current.logoName.section(".", 0, 0);
QString editedLogoName = "technic_" + current.logoName;
model->getLogo(current.logoName, current.logoUrl,
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
@ -136,7 +138,7 @@ void TechnicPage::suggestCurrent()
auto netJob = makeShared<NetJob>(QString("Technic::PackMeta(%1)").arg(current.name), APPLICATION->network());
QString slug = current.slug;
netJob->addNetAction(Net::Download::makeByteArray(
netJob->addNetAction(Net::ApiDownload::makeByteArray(
QString("%1modpack/%2?build=%3").arg(BuildConfig.TECHNIC_API_BASE_URL, slug, BuildConfig.TECHNIC_API_BUILD), response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, [this, slug] {
jobPtr.reset();
@ -232,7 +234,7 @@ void TechnicPage::metadataLoaded()
auto netJob = makeShared<NetJob>(QString("Technic::SolderMeta(%1)").arg(current.name), APPLICATION->network());
auto url = QString("%1/modpack/%2").arg(current.url, current.slug);
netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), response));
netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(url), response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, &TechnicPage::onSolderLoaded);
@ -304,13 +306,13 @@ void TechnicPage::onSolderLoaded()
metadataLoaded();
}
void TechnicPage::onVersionSelectionChanged(QString data)
void TechnicPage::onVersionSelectionChanged(QString version)
{
if (data.isNull() || data.isEmpty()) {
if (version.isNull() || version.isEmpty()) {
selectedVersion = "";
return;
}
selectedVersion = data;
selectedVersion = version;
selectVersion();
}