chore(clang-tidy): fix clang tidy warnings

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2026-05-07 00:03:03 +03:00
parent ac7c8adea2
commit 4463c21c98
11 changed files with 527 additions and 416 deletions

View file

@ -22,6 +22,7 @@
#include <QPushButton>
#include <algorithm>
#include <utility>
#include "Application.h"
#include "ResourceDownloadTask.h"
@ -49,9 +50,9 @@
namespace ResourceDownload {
ResourceDownloadDialog::ResourceDownloadDialog(QWidget* parent, ResourceFolderModel* base_model)
ResourceDownloadDialog::ResourceDownloadDialog(QWidget* parent, ResourceFolderModel* baseModel)
: QDialog(parent)
, m_base_model(base_model)
, m_base_model(baseModel)
, m_buttons(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel)
, m_vertical_layout(this)
{
@ -61,34 +62,35 @@ ResourceDownloadDialog::ResourceDownloadDialog(QWidget* parent, ResourceFolderMo
setWindowIcon(QIcon::fromTheme("new"));
// small margins look ugly on macOS on modal windows
#ifndef Q_OS_MACOS
// small margins look ugly on macOS on modal windows
#ifndef Q_OS_MACOS
m_buttons.setContentsMargins(0, 0, 6, 6);
#endif
#endif
// Bonk Qt over its stupid head and make sure it understands which button is the default one...
// See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button
auto OkButton = m_buttons.button(QDialogButtonBox::Ok);
OkButton->setEnabled(false);
OkButton->setDefault(true);
OkButton->setAutoDefault(true);
OkButton->setText(tr("Review and confirm"));
OkButton->setShortcut(tr("Ctrl+Return"));
auto* okButton = m_buttons.button(QDialogButtonBox::Ok);
okButton->setEnabled(false);
okButton->setDefault(true);
okButton->setAutoDefault(true);
okButton->setText(tr("Review and confirm"));
okButton->setShortcut(tr("Ctrl+Return"));
auto CancelButton = m_buttons.button(QDialogButtonBox::Cancel);
CancelButton->setDefault(false);
CancelButton->setAutoDefault(false);
auto* cancelButton = m_buttons.button(QDialogButtonBox::Cancel);
cancelButton->setDefault(false);
cancelButton->setAutoDefault(false);
auto HelpButton = m_buttons.button(QDialogButtonBox::Help);
HelpButton->setDefault(false);
HelpButton->setAutoDefault(false);
auto* helpButton = m_buttons.button(QDialogButtonBox::Help);
helpButton->setDefault(false);
helpButton->setAutoDefault(false);
setWindowModality(Qt::WindowModal);
}
void ResourceDownloadDialog::accept()
{
if (!geometrySaveKey().isEmpty())
if (!geometrySaveKey().isEmpty()) {
APPLICATION->settings()->set(geometrySaveKey(), QString::fromUtf8(saveGeometry().toBase64()));
}
QDialog::accept();
}
@ -108,8 +110,9 @@ void ResourceDownloadDialog::reject()
}
}
if (!geometrySaveKey().isEmpty())
if (!geometrySaveKey().isEmpty()) {
APPLICATION->settings()->set(geometrySaveKey(), QString::fromUtf8(saveGeometry().toBase64()));
}
QDialog::reject();
}
@ -118,10 +121,10 @@ void ResourceDownloadDialog::reject()
// won't work with subclasses if we put it in this ctor.
void ResourceDownloadDialog::initializeContainer()
{
// small margins look ugly on macOS on modal windows
#ifndef Q_OS_MACOS
// small margins look ugly on macOS on modal windows
#ifndef Q_OS_MACOS
layout()->setContentsMargins(0, 0, 0, 0);
#endif
#endif
m_container = new PageContainer(this, {}, this);
m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
@ -135,28 +138,28 @@ void ResourceDownloadDialog::initializeContainer()
void ResourceDownloadDialog::connectButtons()
{
auto OkButton = m_buttons.button(QDialogButtonBox::Ok);
OkButton->setToolTip(
auto* okButton = m_buttons.button(QDialogButtonBox::Ok);
okButton->setToolTip(
tr("Opens a new popup to review your selected %1 and confirm your selection. Shortcut: Ctrl+Return").arg(resourcesString()));
connect(OkButton, &QPushButton::clicked, this, &ResourceDownloadDialog::confirm);
connect(okButton, &QPushButton::clicked, this, &ResourceDownloadDialog::confirm);
auto CancelButton = m_buttons.button(QDialogButtonBox::Cancel);
connect(CancelButton, &QPushButton::clicked, this, &ResourceDownloadDialog::reject);
auto* cancelButton = m_buttons.button(QDialogButtonBox::Cancel);
connect(cancelButton, &QPushButton::clicked, this, &ResourceDownloadDialog::reject);
auto HelpButton = m_buttons.button(QDialogButtonBox::Help);
connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help);
auto* helpButton = m_buttons.button(QDialogButtonBox::Help);
connect(helpButton, &QPushButton::clicked, m_container, &PageContainer::help);
}
void ResourceDownloadDialog::confirm()
{
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
confirm_dialog->retranslateUi(resourcesString());
auto* confirmDialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
confirmDialog->retranslateUi(resourcesString());
QHash<QString, GetModDependenciesTask::PackDependencyExtraInfo> dependencyExtraInfo;
QStringList depNames;
if (auto task = getModDependenciesTask(); task) {
connect(task.get(), &Task::failed, this,
[this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
[this](const QString& reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
auto weak = task.toWeakRef();
connect(task.get(), &Task::succeeded, this, [this, weak]() {
@ -170,57 +173,62 @@ void ResourceDownloadDialog::confirm()
});
// Check for updates
ProgressDialog progress_dialog(this);
progress_dialog.setSkipButton(true, tr("Abort"));
progress_dialog.setWindowTitle(tr("Checking for dependencies..."));
auto ret = progress_dialog.execWithTask(task.get());
ProgressDialog progressDialog(this);
progressDialog.setSkipButton(true, tr("Abort"));
progressDialog.setWindowTitle(tr("Checking for dependencies..."));
auto ret = progressDialog.execWithTask(task.get());
// If the dialog was skipped / some download error happened
if (ret == QDialog::DialogCode::Rejected) {
QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
return;
} else {
for (auto dep : task->getDependecies()) {
addResource(dep->pack, dep->version);
depNames << dep->pack->name;
}
dependencyExtraInfo = task->getExtraInfo();
}
for (const auto& dep : task->getDependecies()) {
addResource(dep->pack, dep->version);
depNames << dep->pack->name;
}
dependencyExtraInfo = task->getExtraInfo();
}
auto selected = getTasks();
std::sort(selected.begin(), selected.end(), [](const DownloadTaskPtr& a, const DownloadTaskPtr& b) {
std::ranges::sort(selected, [](const DownloadTaskPtr& a, const DownloadTaskPtr& b) {
return QString::compare(a->getName(), b->getName(), Qt::CaseInsensitive) < 0;
});
for (auto& task : selected) {
auto extraInfo = dependencyExtraInfo.value(task->getPack()->addonId.toString());
confirm_dialog->appendResource({ task->getName(), task->getFilename(), ModPlatform::ProviderCapabilities::name(task->getProvider()),
extraInfo.required_by, task->getVersion().version_type.toString(), !extraInfo.maybe_installed });
confirmDialog->appendResource({ .name = task->getName(),
.filename = task->getFilename(),
.provider = ModPlatform::ProviderCapabilities::name(task->getProvider()),
.required_by = extraInfo.required_by,
.version_type = task->getVersion().version_type.toString(),
.enabled = !extraInfo.maybe_installed });
}
if (confirm_dialog->exec()) {
auto deselected = confirm_dialog->deselectedResources();
for (auto page : m_container->getPages()) {
auto res = static_cast<ResourcePage*>(page);
for (auto name : deselected)
if (confirmDialog->exec() != 0) {
auto deselected = confirmDialog->deselectedResources();
for (auto* page : m_container->getPages()) {
auto* res = static_cast<ResourcePage*>(page);
for (const auto& name : deselected) {
res->removeResourceFromPage(name);
}
}
this->accept();
} else {
for (auto name : depNames)
for (const auto& name : depNames) {
removeResource(name);
}
}
}
bool ResourceDownloadDialog::selectPage(QString pageId)
{
return m_container->selectPage(pageId);
return m_container->selectPage(std::move(pageId));
}
ResourcePage* ResourceDownloadDialog::selectedPage()
{
ResourcePage* result = dynamic_cast<ResourcePage*>(m_container->selectedPage());
auto* result = dynamic_cast<ResourcePage*>(m_container->selectedPage());
Q_ASSERT(result != nullptr);
return result;
}
@ -232,10 +240,10 @@ void ResourceDownloadDialog::addResource(ModPlatform::IndexedPack::Ptr pack, Mod
setButtonStatus();
}
void ResourceDownloadDialog::removeResource(const QString& pack_name)
void ResourceDownloadDialog::removeResource(const QString& packName)
{
for (auto page : m_container->getPages()) {
static_cast<ResourcePage*>(page)->removeResourceFromPage(pack_name);
for (auto* page : m_container->getPages()) {
static_cast<ResourcePage*>(page)->removeResourceFromPage(packName);
}
setButtonStatus();
}
@ -243,18 +251,18 @@ void ResourceDownloadDialog::removeResource(const QString& pack_name)
void ResourceDownloadDialog::setButtonStatus()
{
auto selected = false;
for (auto page : m_container->getPages()) {
auto res = static_cast<ResourcePage*>(page);
for (auto* page : m_container->getPages()) {
auto* res = static_cast<ResourcePage*>(page);
selected = selected || res->hasSelectedPacks();
}
m_buttons.button(QDialogButtonBox::Ok)->setEnabled(selected);
}
const QList<ResourceDownloadDialog::DownloadTaskPtr> ResourceDownloadDialog::getTasks()
QList<ResourceDownloadDialog::DownloadTaskPtr> ResourceDownloadDialog::getTasks()
{
QList<DownloadTaskPtr> selected;
for (auto page : m_container->getPages()) {
auto res = static_cast<ResourcePage*>(page);
for (auto* page : m_container->getPages()) {
auto* res = static_cast<ResourcePage*>(page);
selected.append(res->selectedPacks());
}
return selected;
@ -262,16 +270,16 @@ const QList<ResourceDownloadDialog::DownloadTaskPtr> ResourceDownloadDialog::get
void ResourceDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* selected)
{
auto* prev_page = dynamic_cast<ResourcePage*>(previous);
if (!prev_page) {
auto* prevPage = dynamic_cast<ResourcePage*>(previous);
if (!prevPage) {
qCritical() << "Page '" << previous->displayName() << "' in ResourceDownloadDialog is not a ResourcePage!";
return;
}
// Same effect as having a global search bar
ResourcePage* result = dynamic_cast<ResourcePage*>(selected);
auto* result = dynamic_cast<ResourcePage*>(selected);
Q_ASSERT(result != nullptr);
result->setSearchTerm(prev_page->getSearchTerm());
result->setSearchTerm(prevPage->getSearchTerm());
}
ModDownloadDialog::ModDownloadDialog(QWidget* parent, ModFolderModel* mods, BaseInstance* instance)
@ -282,8 +290,9 @@ ModDownloadDialog::ModDownloadDialog(QWidget* parent, ModFolderModel* mods, Base
initializeContainer();
connectButtons();
if (!geometrySaveKey().isEmpty())
if (!geometrySaveKey().isEmpty()) {
restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get(geometrySaveKey()).toString().toUtf8()));
}
}
QList<BasePage*> ModDownloadDialog::getPages()
@ -292,10 +301,12 @@ QList<BasePage*> ModDownloadDialog::getPages()
auto loaders = static_cast<MinecraftInstance*>(m_instance)->getPackProfile()->getSupportedModLoaders().value();
if (ModrinthAPI::validateModLoaders(loaders))
if (ModrinthAPI::validateModLoaders(loaders)) {
pages.append(ModrinthModPage::create(this, *m_instance));
if (APPLICATION->capabilities() & Application::SupportsFlame && FlameAPI::validateModLoaders(loaders))
}
if (APPLICATION->capabilities() & Application::SupportsFlame && FlameAPI::validateModLoaders(loaders)) {
pages.append(FlameModPage::create(this, *m_instance));
}
return pages;
}
@ -303,9 +314,9 @@ QList<BasePage*> ModDownloadDialog::getPages()
GetModDependenciesTask::Ptr ModDownloadDialog::getModDependenciesTask()
{
if (!APPLICATION->settings()->get("ModDependenciesDisabled").toBool()) { // dependencies
if (auto model = dynamic_cast<ModFolderModel*>(getBaseModel()); model) {
if (auto* model = dynamic_cast<ModFolderModel*>(getBaseModel()); model) {
QList<std::shared_ptr<GetModDependenciesTask::PackDependency>> selectedVers;
for (auto& selected : getTasks()) {
for (const auto& selected : getTasks()) {
selectedVers.append(std::make_shared<GetModDependenciesTask::PackDependency>(selected->getPack(), selected->getVersion()));
}
@ -315,16 +326,17 @@ GetModDependenciesTask::Ptr ModDownloadDialog::getModDependenciesTask()
return nullptr;
}
ResourcePackDownloadDialog::ResourcePackDownloadDialog(QWidget* parent, ResourcePackFolderModel* resource_packs, BaseInstance* instance)
: ResourceDownloadDialog(parent, resource_packs), m_instance(instance)
ResourcePackDownloadDialog::ResourcePackDownloadDialog(QWidget* parent, ResourcePackFolderModel* resourcePacks, BaseInstance* instance)
: ResourceDownloadDialog(parent, resourcePacks), m_instance(instance)
{
setWindowTitle(dialogTitle());
initializeContainer();
connectButtons();
if (!geometrySaveKey().isEmpty())
if (!geometrySaveKey().isEmpty()) {
restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get(geometrySaveKey()).toString().toUtf8()));
}
}
QList<BasePage*> ResourcePackDownloadDialog::getPages()
@ -332,22 +344,24 @@ QList<BasePage*> ResourcePackDownloadDialog::getPages()
QList<BasePage*> pages;
pages.append(ModrinthResourcePackPage::create(this, *m_instance));
if (APPLICATION->capabilities() & Application::SupportsFlame)
if (APPLICATION->capabilities() & Application::SupportsFlame) {
pages.append(FlameResourcePackPage::create(this, *m_instance));
}
return pages;
}
TexturePackDownloadDialog::TexturePackDownloadDialog(QWidget* parent, TexturePackFolderModel* resource_packs, BaseInstance* instance)
: ResourceDownloadDialog(parent, resource_packs), m_instance(instance)
TexturePackDownloadDialog::TexturePackDownloadDialog(QWidget* parent, TexturePackFolderModel* resourcePacks, BaseInstance* instance)
: ResourceDownloadDialog(parent, resourcePacks), m_instance(instance)
{
setWindowTitle(dialogTitle());
initializeContainer();
connectButtons();
if (!geometrySaveKey().isEmpty())
if (!geometrySaveKey().isEmpty()) {
restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get(geometrySaveKey()).toString().toUtf8()));
}
}
QList<BasePage*> TexturePackDownloadDialog::getPages()
@ -355,8 +369,9 @@ QList<BasePage*> TexturePackDownloadDialog::getPages()
QList<BasePage*> pages;
pages.append(ModrinthTexturePackPage::create(this, *m_instance));
if (APPLICATION->capabilities() & Application::SupportsFlame)
if (APPLICATION->capabilities() & Application::SupportsFlame) {
pages.append(FlameTexturePackPage::create(this, *m_instance));
}
return pages;
}
@ -369,16 +384,18 @@ ShaderPackDownloadDialog::ShaderPackDownloadDialog(QWidget* parent, ShaderPackFo
initializeContainer();
connectButtons();
if (!geometrySaveKey().isEmpty())
if (!geometrySaveKey().isEmpty()) {
restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get(geometrySaveKey()).toString().toUtf8()));
}
}
QList<BasePage*> ShaderPackDownloadDialog::getPages()
{
QList<BasePage*> pages;
pages.append(ModrinthShaderPackPage::create(this, *m_instance));
if (APPLICATION->capabilities() & Application::SupportsFlame)
if (APPLICATION->capabilities() & Application::SupportsFlame) {
pages.append(FlameShaderPackPage::create(this, *m_instance));
}
return pages;
}
@ -395,28 +412,30 @@ void ResourceDownloadDialog::setResourceMetadata(const std::shared_ptr<Metadata:
setWindowTitle(tr("Change %1 version").arg(meta->name));
m_container->hidePageList();
m_buttons.hide();
auto page = selectedPage();
auto* page = selectedPage();
page->openProject(meta->project_id);
}
DataPackDownloadDialog::DataPackDownloadDialog(QWidget* parent, DataPackFolderModel* data_packs, BaseInstance* instance)
: ResourceDownloadDialog(parent, data_packs), m_instance(instance)
DataPackDownloadDialog::DataPackDownloadDialog(QWidget* parent, DataPackFolderModel* dataPacks, BaseInstance* instance)
: ResourceDownloadDialog(parent, dataPacks), m_instance(instance)
{
setWindowTitle(dialogTitle());
initializeContainer();
connectButtons();
if (!geometrySaveKey().isEmpty())
if (!geometrySaveKey().isEmpty()) {
restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get(geometrySaveKey()).toByteArray()));
}
}
QList<BasePage*> DataPackDownloadDialog::getPages()
{
QList<BasePage*> pages;
pages.append(ModrinthDataPackPage::create(this, *m_instance));
if (APPLICATION->capabilities() & Application::SupportsFlame)
if (APPLICATION->capabilities() & Application::SupportsFlame) {
pages.append(FlameDataPackPage::create(this, *m_instance));
}
return pages;
}

View file

@ -51,7 +51,7 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
public:
using DownloadTaskPtr = shared_qobject_ptr<ResourceDownloadTask>;
ResourceDownloadDialog(QWidget* parent, ResourceFolderModel* base_model);
ResourceDownloadDialog(QWidget* parent, ResourceFolderModel* baseModel);
void initializeContainer();
void connectButtons();
@ -67,7 +67,7 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
void addResource(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&);
void removeResource(const QString&);
const QList<DownloadTaskPtr> getTasks();
QList<DownloadTaskPtr> getTasks();
ResourceFolderModel* getBaseModel() const { return m_base_model; }
void setResourceMetadata(const std::shared_ptr<Metadata::ModStruct>& meta);
@ -118,7 +118,7 @@ class ResourcePackDownloadDialog final : public ResourceDownloadDialog {
Q_OBJECT
public:
explicit ResourcePackDownloadDialog(QWidget* parent, ResourcePackFolderModel* resource_packs, BaseInstance* instance);
explicit ResourcePackDownloadDialog(QWidget* parent, ResourcePackFolderModel* resourcePacks, BaseInstance* instance);
~ResourcePackDownloadDialog() override = default;
//: String that gets appended to the resource pack download dialog title ("Download " + resourcesString())
@ -135,7 +135,7 @@ class TexturePackDownloadDialog final : public ResourceDownloadDialog {
Q_OBJECT
public:
explicit TexturePackDownloadDialog(QWidget* parent, TexturePackFolderModel* resource_packs, BaseInstance* instance);
explicit TexturePackDownloadDialog(QWidget* parent, TexturePackFolderModel* resourcePacks, BaseInstance* instance);
~TexturePackDownloadDialog() override = default;
//: String that gets appended to the texture pack download dialog title ("Download " + resourcesString())
@ -152,7 +152,7 @@ class ShaderPackDownloadDialog final : public ResourceDownloadDialog {
Q_OBJECT
public:
explicit ShaderPackDownloadDialog(QWidget* parent, ShaderPackFolderModel* shader_packs, BaseInstance* instance);
explicit ShaderPackDownloadDialog(QWidget* parent, ShaderPackFolderModel* shaders, BaseInstance* instance);
~ShaderPackDownloadDialog() override = default;
//: String that gets appended to the shader pack download dialog title ("Download " + resourcesString())
@ -169,7 +169,7 @@ class DataPackDownloadDialog final : public ResourceDownloadDialog {
Q_OBJECT
public:
explicit DataPackDownloadDialog(QWidget* parent, DataPackFolderModel* data_packs, BaseInstance* instance);
explicit DataPackDownloadDialog(QWidget* parent, DataPackFolderModel* dataPacks, BaseInstance* instance);
~DataPackDownloadDialog() override = default;
//: String that gets appended to the data pack download dialog title ("Download " + resourcesString())

View file

@ -39,9 +39,9 @@ DataPackPage::DataPackPage(BaseInstance* instance, DataPackFolderModel* model, Q
connect(ui->actionUpdateItem, &QAction::triggered, this, &DataPackPage::updateDataPacks);
ui->actionsToolbar->insertActionBefore(ui->actionAddItem, ui->actionUpdateItem);
auto updateMenu = new QMenu(this);
auto* updateMenu = new QMenu(this);
auto update = updateMenu->addAction(ui->actionUpdateItem->text());
auto* update = updateMenu->addAction(ui->actionUpdateItem->text());
connect(update, &QAction::triggered, this, &DataPackPage::updateDataPacks);
updateMenu->addAction(ui->actionResetItemMetadata);
@ -64,8 +64,9 @@ void DataPackPage::updateFrame(const QModelIndex& current, [[maybe_unused]] cons
void DataPackPage::downloadDataPacks()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
m_downloadDialog = new ResourceDownload::DataPackDownloadDialog(this, m_model, m_instance);
connect(this, &QObject::destroyed, m_downloadDialog, &QDialog::close);
@ -76,9 +77,9 @@ void DataPackPage::downloadDataPacks()
void DataPackPage::downloadDialogFinished(int result)
{
if (result) {
auto tasks = new ConcurrentTask(tr("Download Data Packs"), APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (result != 0) {
auto* tasks = new ConcurrentTask(tr("Download Data Packs"), APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -88,8 +89,9 @@ void DataPackPage::downloadDialogFinished(int result)
});
connect(tasks, &Task::succeeded, [this, tasks]() {
QStringList warnings = tasks->warnings();
if (warnings.count())
if (warnings.count()) {
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
}
tasks->deleteLater();
});
@ -108,14 +110,16 @@ void DataPackPage::downloadDialogFinished(int result)
m_model->update();
}
if (m_downloadDialog)
if (m_downloadDialog) {
m_downloadDialog->deleteLater();
}
}
void DataPackPage::updateDataPacks()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
QMessageBox::critical(this, tr("Error"), tr("Data pack updates are unavailable when metadata is disabled!"));
@ -130,27 +134,29 @@ void DataPackPage::updateDataPacks()
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto mods_list = m_model->selectedResources(selection);
bool use_all = mods_list.empty();
if (use_all)
mods_list = m_model->allResources();
auto modsList = m_model->selectedResources(selection);
bool useAll = modsList.empty();
if (useAll) {
modsList = m_model->allResources();
}
ResourceUpdateDialog update_dialog(this, m_instance, m_model, mods_list, false, { ModPlatform::ModLoaderType::DataPack });
update_dialog.checkCandidates();
ResourceUpdateDialog updateDialog(this, m_instance, m_model, modsList, false, { ModPlatform::ModLoaderType::DataPack });
updateDialog.checkCandidates();
if (update_dialog.aborted()) {
if (updateDialog.aborted()) {
CustomMessageBox::selectable(this, tr("Aborted"), tr("The data pack updater was aborted!"), QMessageBox::Warning)->show();
return;
}
if (update_dialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(mods_list.front()->name()) };
if (mods_list.size() > 1) {
if (use_all) {
if (updateDialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(modsList.front()->name()) };
if (modsList.size() > 1) {
if (useAll) {
message = tr("All data packs are up-to-date! :)");
} else {
message = tr("All selected data packs are up-to-date! :)");
@ -160,9 +166,9 @@ void DataPackPage::updateDataPacks()
return;
}
if (update_dialog.exec()) {
auto tasks = new ConcurrentTask("Download Data Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (updateDialog.exec() != 0) {
auto* tasks = new ConcurrentTask("Download Data Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -178,7 +184,7 @@ void DataPackPage::updateDataPacks()
tasks->deleteLater();
});
for (auto task : update_dialog.getTasks()) {
for (const auto& task : updateDialog.getTasks()) {
tasks->addTask(task);
}
@ -194,8 +200,9 @@ void DataPackPage::deleteDataPackMetadata()
{
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto selectionCount = m_model->selectedDataPacks(selection).length();
if (selectionCount == 0)
if (selectionCount == 0) {
return;
}
if (selectionCount > 1) {
auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"),
tr("You are about to remove the metadata for %1 data packs.\n"
@ -204,8 +211,9 @@ void DataPackPage::deleteDataPackMetadata()
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
m_model->deleteMetadata(selection);
@ -213,8 +221,9 @@ void DataPackPage::deleteDataPackMetadata()
void DataPackPage::changeDataPackVersion()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
QMessageBox::critical(this, tr("Error"), tr("Data pack updates are unavailable when metadata is disabled!"));
@ -223,19 +232,21 @@ void DataPackPage::changeDataPackVersion()
const QModelIndexList rows = ui->treeView->selectionModel()->selectedRows();
if (rows.count() != 1)
if (rows.count() != 1) {
return;
}
Resource& resource = m_model->at(m_filterModel->mapToSource(rows[0]).row());
if (resource.metadata() == nullptr)
if (resource.metadata() == nullptr) {
return;
}
ResourceDownload::DataPackDownloadDialog mdownload(this, m_model, m_instance);
mdownload.setResourceMetadata(resource.metadata());
if (mdownload.exec()) {
auto tasks = new ConcurrentTask("Download Data Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (mdownload.exec() != 0) {
auto* tasks = new ConcurrentTask("Download Data Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -245,8 +256,9 @@ void DataPackPage::changeDataPackVersion()
});
connect(tasks, &Task::succeeded, [this, tasks]() {
QStringList warnings = tasks->warnings();
if (warnings.count())
if (warnings.count()) {
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
}
tasks->deleteLater();
});
@ -265,14 +277,15 @@ void DataPackPage::changeDataPackVersion()
GlobalDataPackPage::GlobalDataPackPage(MinecraftInstance* instance, QWidget* parent) : QWidget(parent), m_instance(instance)
{
auto layout = new QVBoxLayout(this);
auto* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);
connect(instance->settings()->getSetting("GlobalDataPacksEnabled").get(), &Setting::SettingChanged, this, [this] {
updateContent();
if (m_container != nullptr)
if (m_container != nullptr) {
m_container->refreshContainer();
}
});
connect(instance->settings()->getSetting("GlobalDataPacksPath").get(), &Setting::SettingChanged, this,
@ -281,24 +294,27 @@ GlobalDataPackPage::GlobalDataPackPage(MinecraftInstance* instance, QWidget* par
QString GlobalDataPackPage::displayName() const
{
if (m_underlyingPage == nullptr)
if (m_underlyingPage == nullptr) {
return {};
}
return m_underlyingPage->displayName();
}
QIcon GlobalDataPackPage::icon() const
{
if (m_underlyingPage == nullptr)
if (m_underlyingPage == nullptr) {
return {};
}
return m_underlyingPage->icon();
}
QString GlobalDataPackPage::helpPage() const
{
if (m_underlyingPage == nullptr)
if (m_underlyingPage == nullptr) {
return {};
}
return m_underlyingPage->helpPage();
}
@ -315,21 +331,24 @@ bool GlobalDataPackPage::apply()
void GlobalDataPackPage::openedImpl()
{
if (m_underlyingPage != nullptr)
if (m_underlyingPage != nullptr) {
m_underlyingPage->openedImpl();
}
}
void GlobalDataPackPage::closedImpl()
{
if (m_underlyingPage != nullptr)
if (m_underlyingPage != nullptr) {
m_underlyingPage->closedImpl();
}
}
void GlobalDataPackPage::updateContent()
{
if (m_underlyingPage != nullptr) {
if (m_container->selectedPage() == this)
if (m_container->selectedPage() == this) {
m_underlyingPage->closedImpl();
}
m_underlyingPage->apply();
@ -344,8 +363,9 @@ void GlobalDataPackPage::updateContent()
m_underlyingPage->setParentContainer(m_container);
m_underlyingPage->updateExtraInfo = [this](QString id, QString value) { updateExtraInfo(std::move(id), std::move(value)); };
if (m_container->selectedPage() == this)
if (m_container->selectedPage() == this) {
m_underlyingPage->openedImpl();
}
layout()->addWidget(m_underlyingPage);
}

View file

@ -81,9 +81,9 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, ModFolderModel* model, QWidget*
connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods);
ui->actionsToolbar->insertActionBefore(ui->actionAddItem, ui->actionUpdateItem);
auto updateMenu = new QMenu(this);
auto* updateMenu = new QMenu(this);
auto update = updateMenu->addAction(tr("Check for Updates"));
auto* update = updateMenu->addAction(tr("Check for Updates"));
connect(update, &QAction::triggered, this, &ModFolderPage::updateMods);
updateMenu->addAction(ui->actionVerifyItemDependencies);
@ -134,8 +134,9 @@ void ModFolderPage::removeItems(const QItemSelection& selection)
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
auto indexes = selection.indexes();
@ -161,10 +162,11 @@ void ModFolderPage::removeItems(const QItemSelection& selection)
void ModFolderPage::downloadMods()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
auto profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
auto* profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
if (!profile->getModLoaders().has_value()) {
if (handleNoModLoader()) {
return;
@ -180,9 +182,9 @@ void ModFolderPage::downloadMods()
void ModFolderPage::downloadDialogFinished(int result)
{
if (result) {
auto tasks = new ConcurrentTask(tr("Download Mods"), APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (result != 0) {
auto* tasks = new ConcurrentTask(tr("Download Mods"), APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -192,8 +194,9 @@ void ModFolderPage::downloadDialogFinished(int result)
});
connect(tasks, &Task::succeeded, [this, tasks]() {
QStringList warnings = tasks->warnings();
if (warnings.count())
if (warnings.count()) {
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
}
tasks->deleteLater();
});
@ -212,16 +215,18 @@ void ModFolderPage::downloadDialogFinished(int result)
m_model->update();
}
if (m_downloadDialog)
if (m_downloadDialog) {
m_downloadDialog->deleteLater();
}
}
void ModFolderPage::updateMods(bool includeDeps)
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
auto profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
auto* profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
if (!profile->getModLoaders().has_value()) {
if (handleNoModLoader()) {
return;
@ -240,27 +245,29 @@ void ModFolderPage::updateMods(bool includeDeps)
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto mods_list = m_model->selectedResources(selection);
bool use_all = mods_list.empty();
if (use_all)
mods_list = m_model->allResources();
auto modsList = m_model->selectedResources(selection);
bool useAll = modsList.empty();
if (useAll) {
modsList = m_model->allResources();
}
ResourceUpdateDialog update_dialog(this, m_instance, m_model, mods_list, includeDeps, profile->getModLoadersList());
update_dialog.checkCandidates();
ResourceUpdateDialog updateDialog(this, m_instance, m_model, modsList, includeDeps, profile->getModLoadersList());
updateDialog.checkCandidates();
if (update_dialog.aborted()) {
if (updateDialog.aborted()) {
CustomMessageBox::selectable(this, tr("Aborted"), tr("The mod updater was aborted!"), QMessageBox::Warning)->show();
return;
}
if (update_dialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(mods_list.front()->name()) };
if (mods_list.size() > 1) {
if (use_all) {
if (updateDialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(modsList.front()->name()) };
if (modsList.size() > 1) {
if (useAll) {
message = tr("All mods are up-to-date! :)");
} else {
message = tr("All selected mods are up-to-date! :)");
@ -270,9 +277,9 @@ void ModFolderPage::updateMods(bool includeDeps)
return;
}
if (update_dialog.exec()) {
auto tasks = new ConcurrentTask("Download Mods", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (updateDialog.exec() != 0) {
auto* tasks = new ConcurrentTask("Download Mods", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -288,7 +295,7 @@ void ModFolderPage::updateMods(bool includeDeps)
tasks->deleteLater();
});
for (auto task : update_dialog.getTasks()) {
for (const auto& task : updateDialog.getTasks()) {
tasks->addTask(task);
}
@ -304,8 +311,9 @@ void ModFolderPage::deleteModMetadata()
{
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto selectionCount = m_model->selectedMods(selection).length();
if (selectionCount == 0)
if (selectionCount == 0) {
return;
}
if (selectionCount > 1) {
auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"),
tr("You are about to remove the metadata for %1 mods.\n"
@ -314,8 +322,9 @@ void ModFolderPage::deleteModMetadata()
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
m_model->deleteMetadata(selection);
@ -323,10 +332,11 @@ void ModFolderPage::deleteModMetadata()
void ModFolderPage::changeModVersion()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
auto profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
auto* profile = static_cast<MinecraftInstance*>(m_instance)->getPackProfile();
if (!profile->getModLoaders().has_value()) {
if (handleNoModLoader()) {
return;
@ -337,15 +347,16 @@ void ModFolderPage::changeModVersion()
return;
}
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto mods_list = m_model->selectedMods(selection);
if (mods_list.length() != 1 || mods_list[0]->metadata() == nullptr)
auto modsList = m_model->selectedMods(selection);
if (modsList.length() != 1 || modsList[0]->metadata() == nullptr) {
return;
}
m_downloadDialog = new ResourceDownload::ModDownloadDialog(this, m_model, m_instance);
connect(this, &QObject::destroyed, m_downloadDialog, &QDialog::close);
connect(m_downloadDialog, &QDialog::finished, this, &ModFolderPage::downloadDialogFinished);
m_downloadDialog->setResourceMetadata((*mods_list.begin())->metadata());
m_downloadDialog->setResourceMetadata((*modsList.begin())->metadata());
m_downloadDialog->open();
}
@ -353,20 +364,21 @@ void ModFolderPage::exportModMetadata()
{
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto selectedMods = m_model->selectedMods(selection);
if (selectedMods.length() == 0)
if (selectedMods.length() == 0) {
selectedMods = m_model->allMods();
}
std::sort(selectedMods.begin(), selectedMods.end(), [](const Mod* a, const Mod* b) { return a->name() < b->name(); });
std::ranges::sort(selectedMods, [](const Mod* a, const Mod* b) { return a->name() < b->name(); });
ExportToModListDialog dlg(m_instance->name(), selectedMods, this);
dlg.exec();
}
CoreModFolderPage::CoreModFolderPage(BaseInstance* inst, ModFolderModel* mods, QWidget* parent) : ModFolderPage(inst, mods, parent)
{
auto mcInst = dynamic_cast<MinecraftInstance*>(m_instance);
auto* mcInst = dynamic_cast<MinecraftInstance*>(m_instance);
if (mcInst) {
auto version = mcInst->getPackProfile();
if (version && version->getComponent("net.minecraftforge") && version->getComponent("net.minecraft")) {
auto* version = mcInst->getPackProfile();
if ((version != nullptr) && version->getComponent("net.minecraftforge") && version->getComponent("net.minecraft")) {
auto minecraftCmp = version->getComponent("net.minecraft");
if (!minecraftCmp->m_loaded) {
version->reload(Net::Mode::Offline);
@ -389,13 +401,15 @@ CoreModFolderPage::CoreModFolderPage(BaseInstance* inst, ModFolderModel* mods, Q
bool CoreModFolderPage::shouldDisplay() const
{
if (ModFolderPage::shouldDisplay()) {
auto inst = dynamic_cast<MinecraftInstance*>(m_instance);
if (!inst)
auto* inst = dynamic_cast<MinecraftInstance*>(m_instance);
if (!inst) {
return true;
}
auto version = inst->getPackProfile();
if (!version || !version->getComponent("net.minecraftforge") || !version->getComponent("net.minecraft"))
auto* version = inst->getPackProfile();
if ((version == nullptr) || !version->getComponent("net.minecraftforge") || !version->getComponent("net.minecraft")) {
return false;
}
auto minecraftCmp = version->getComponent("net.minecraft");
return minecraftCmp->m_loaded && minecraftCmp->getReleaseDateTime() < g_VersionFilterData.legacyCutoffDate;
}
@ -412,31 +426,22 @@ bool NilModFolderPage::shouldDisplay() const
// Helper function so this doesn't need to be duplicated 3 times
inline bool ModFolderPage::handleNoModLoader()
{
int resp =
QMessageBox::question(this, this->tr("Missing Mod Loader"),
this->tr("You need to install a compatible mod loader before installing mods. Would you like to do so?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
switch (resp) {
case QMessageBox::Yes: {
// Should be safe
auto profile = static_cast<MinecraftInstance*>(this->m_instance)->getPackProfile();
InstallLoaderDialog dialog(profile, QString(), this);
bool ret = dialog.exec();
this->m_container->refreshContainer();
int resp = QMessageBox::question(
this, ModFolderPage::tr("Missing Mod Loader"),
ModFolderPage::tr("You need to install a compatible mod loader before installing mods. Would you like to do so?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (resp == QMessageBox::Yes) {
// Should be safe
auto* profile = static_cast<MinecraftInstance*>(this->m_instance)->getPackProfile();
InstallLoaderDialog dialog(profile, QString(), this);
bool ret = dialog.exec() != 0;
this->m_container->refreshContainer();
// returning negation of dialog.exec which'll be true if the install loader dialog got canceled/closed
// and false if the user went through and installed a loader
return !ret;
}
case QMessageBox::No: {
// Nothing happens the dialog is already closing
// returning true so the caller doesn't go and continue with opening it's dialog without a mod loader
return true;
}
default: {
// Unreachable
// returning true as a safety measure
return true;
}
// returning negation of dialog.exec which'll be true if the install loader dialog got canceled/closed
// and false if the user went through and installed a loader
return !ret;
}
// Nothing happens the dialog is already closing
// returning true so the caller doesn't go and continue with opening it's dialog without a mod loader
return true;
}

View file

@ -56,9 +56,9 @@ ResourcePackPage::ResourcePackPage(MinecraftInstance* instance, ResourcePackFold
connect(ui->actionUpdateItem, &QAction::triggered, this, &ResourcePackPage::updateResourcePacks);
ui->actionsToolbar->insertActionBefore(ui->actionAddItem, ui->actionUpdateItem);
auto updateMenu = new QMenu(this);
auto* updateMenu = new QMenu(this);
auto update = updateMenu->addAction(ui->actionUpdateItem->text());
auto* update = updateMenu->addAction(ui->actionUpdateItem->text());
connect(update, &QAction::triggered, this, &ResourcePackPage::updateResourcePacks);
updateMenu->addAction(ui->actionResetItemMetadata);
@ -75,14 +75,15 @@ void ResourcePackPage::updateFrame(const QModelIndex& current, [[maybe_unused]]
{
auto sourceCurrent = m_filterModel->mapToSource(current);
int row = sourceCurrent.row();
auto& rp = static_cast<ResourcePack&>(m_model->at(row));
auto& rp = m_model->at(row);
ui->frame->updateWithResourcePack(rp);
}
void ResourcePackPage::downloadResourcePacks()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
m_downloadDialog = new ResourceDownload::ResourcePackDownloadDialog(this, m_model, m_instance);
connect(this, &QObject::destroyed, m_downloadDialog, &QDialog::close);
@ -93,9 +94,9 @@ void ResourcePackPage::downloadResourcePacks()
void ResourcePackPage::downloadDialogFinished(int result)
{
if (result) {
auto tasks = new ConcurrentTask("Download Resource Pack", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (result != 0) {
auto* tasks = new ConcurrentTask("Download Resource Pack", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -105,8 +106,9 @@ void ResourcePackPage::downloadDialogFinished(int result)
});
connect(tasks, &Task::succeeded, [this, tasks]() {
QStringList warnings = tasks->warnings();
if (warnings.count())
if (warnings.count()) {
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
}
tasks->deleteLater();
});
@ -125,14 +127,16 @@ void ResourcePackPage::downloadDialogFinished(int result)
m_model->update();
}
if (m_downloadDialog)
if (m_downloadDialog) {
m_downloadDialog->deleteLater();
}
}
void ResourcePackPage::updateResourcePacks()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
QMessageBox::critical(this, tr("Error"), tr("Resource pack updates are unavailable when metadata is disabled!"));
@ -147,27 +151,29 @@ void ResourcePackPage::updateResourcePacks()
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto mods_list = m_model->selectedResources(selection);
bool use_all = mods_list.empty();
if (use_all)
mods_list = m_model->allResources();
auto modsList = m_model->selectedResources(selection);
bool useAll = modsList.empty();
if (useAll) {
modsList = m_model->allResources();
}
ResourceUpdateDialog update_dialog(this, m_instance, m_model, mods_list, false);
update_dialog.checkCandidates();
ResourceUpdateDialog updateDialog(this, m_instance, m_model, modsList, false);
updateDialog.checkCandidates();
if (update_dialog.aborted()) {
if (updateDialog.aborted()) {
CustomMessageBox::selectable(this, tr("Aborted"), tr("The resource pack updater was aborted!"), QMessageBox::Warning)->show();
return;
}
if (update_dialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(mods_list.front()->name()) };
if (mods_list.size() > 1) {
if (use_all) {
if (updateDialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(modsList.front()->name()) };
if (modsList.size() > 1) {
if (useAll) {
message = tr("All resource packs are up-to-date! :)");
} else {
message = tr("All selected resource packs are up-to-date! :)");
@ -177,9 +183,9 @@ void ResourcePackPage::updateResourcePacks()
return;
}
if (update_dialog.exec()) {
auto tasks = new ConcurrentTask("Download Resource Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (updateDialog.exec() != 0) {
auto* tasks = new ConcurrentTask("Download Resource Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -195,7 +201,7 @@ void ResourcePackPage::updateResourcePacks()
tasks->deleteLater();
});
for (auto task : update_dialog.getTasks()) {
for (const auto& task : updateDialog.getTasks()) {
tasks->addTask(task);
}
@ -211,8 +217,9 @@ void ResourcePackPage::deleteResourcePackMetadata()
{
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto selectionCount = m_model->selectedResourcePacks(selection).length();
if (selectionCount == 0)
if (selectionCount == 0) {
return;
}
if (selectionCount > 1) {
auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"),
tr("You are about to remove the metadata for %1 resource packs.\n"
@ -221,8 +228,9 @@ void ResourcePackPage::deleteResourcePackMetadata()
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
m_model->deleteMetadata(selection);
@ -230,8 +238,9 @@ void ResourcePackPage::deleteResourcePackMetadata()
void ResourcePackPage::changeResourcePackVersion()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
QMessageBox::critical(this, tr("Error"), tr("Resource pack updates are unavailable when metadata is disabled!"));
@ -240,13 +249,15 @@ void ResourcePackPage::changeResourcePackVersion()
const QModelIndexList rows = ui->treeView->selectionModel()->selectedRows();
if (rows.count() != 1)
if (rows.count() != 1) {
return;
}
Resource& resource = m_model->at(m_filterModel->mapToSource(rows[0]).row());
if (resource.metadata() == nullptr)
if (resource.metadata() == nullptr) {
return;
}
m_downloadDialog = new ResourceDownload::ResourcePackDownloadDialog(this, m_model, m_instance);
connect(this, &QObject::destroyed, m_downloadDialog, &QDialog::close);

View file

@ -61,9 +61,9 @@ ShaderPackPage::ShaderPackPage(MinecraftInstance* instance, ShaderPackFolderMode
connect(ui->actionUpdateItem, &QAction::triggered, this, &ShaderPackPage::updateShaderPacks);
ui->actionsToolbar->insertActionBefore(ui->actionAddItem, ui->actionUpdateItem);
auto updateMenu = new QMenu(this);
auto* updateMenu = new QMenu(this);
auto update = updateMenu->addAction(ui->actionUpdateItem->text());
auto* update = updateMenu->addAction(ui->actionUpdateItem->text());
connect(update, &QAction::triggered, this, &ShaderPackPage::updateShaderPacks);
updateMenu->addAction(ui->actionResetItemMetadata);
@ -78,8 +78,9 @@ ShaderPackPage::ShaderPackPage(MinecraftInstance* instance, ShaderPackFolderMode
void ShaderPackPage::downloadShaderPack()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
m_downloadDialog = new ResourceDownload::ShaderPackDownloadDialog(this, m_model, m_instance);
connect(this, &QObject::destroyed, m_downloadDialog, &QDialog::close);
@ -90,9 +91,9 @@ void ShaderPackPage::downloadShaderPack()
void ShaderPackPage::downloadDialogFinished(int result)
{
if (result) {
auto tasks = new ConcurrentTask("Download Shader Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (result != 0) {
auto* tasks = new ConcurrentTask("Download Shader Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -102,8 +103,9 @@ void ShaderPackPage::downloadDialogFinished(int result)
});
connect(tasks, &Task::succeeded, [this, tasks]() {
QStringList warnings = tasks->warnings();
if (warnings.count())
if (warnings.count()) {
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
}
tasks->deleteLater();
});
@ -122,14 +124,16 @@ void ShaderPackPage::downloadDialogFinished(int result)
m_model->update();
}
if (m_downloadDialog)
if (m_downloadDialog) {
m_downloadDialog->deleteLater();
}
}
void ShaderPackPage::updateShaderPacks()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
QMessageBox::critical(this, tr("Error"), tr("Shader pack updates are unavailable when metadata is disabled!"));
@ -144,27 +148,29 @@ void ShaderPackPage::updateShaderPacks()
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto mods_list = m_model->selectedResources(selection);
bool use_all = mods_list.empty();
if (use_all)
mods_list = m_model->allResources();
auto modsList = m_model->selectedResources(selection);
bool useAll = modsList.empty();
if (useAll) {
modsList = m_model->allResources();
}
ResourceUpdateDialog update_dialog(this, m_instance, m_model, mods_list, false);
update_dialog.checkCandidates();
ResourceUpdateDialog updateDialog(this, m_instance, m_model, modsList, false);
updateDialog.checkCandidates();
if (update_dialog.aborted()) {
if (updateDialog.aborted()) {
CustomMessageBox::selectable(this, tr("Aborted"), tr("The shader pack updater was aborted!"), QMessageBox::Warning)->show();
return;
}
if (update_dialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(mods_list.front()->name()) };
if (mods_list.size() > 1) {
if (use_all) {
if (updateDialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(modsList.front()->name()) };
if (modsList.size() > 1) {
if (useAll) {
message = tr("All shader packs are up-to-date! :)");
} else {
message = tr("All selected shader packs are up-to-date! :)");
@ -174,9 +180,9 @@ void ShaderPackPage::updateShaderPacks()
return;
}
if (update_dialog.exec()) {
auto tasks = new ConcurrentTask("Download Shader Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (updateDialog.exec() != 0) {
auto* tasks = new ConcurrentTask("Download Shader Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -192,7 +198,7 @@ void ShaderPackPage::updateShaderPacks()
tasks->deleteLater();
});
for (auto task : update_dialog.getTasks()) {
for (const auto& task : updateDialog.getTasks()) {
tasks->addTask(task);
}
@ -208,8 +214,9 @@ void ShaderPackPage::deleteShaderPackMetadata()
{
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto selectionCount = m_model->selectedShaderPacks(selection).length();
if (selectionCount == 0)
if (selectionCount == 0) {
return;
}
if (selectionCount > 1) {
auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"),
tr("You are about to remove the metadata for %1 shader packs.\n"
@ -218,8 +225,9 @@ void ShaderPackPage::deleteShaderPackMetadata()
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
m_model->deleteMetadata(selection);
@ -227,8 +235,9 @@ void ShaderPackPage::deleteShaderPackMetadata()
void ShaderPackPage::changeShaderPackVersion()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
QMessageBox::critical(this, tr("Error"), tr("Shader pack updates are unavailable when metadata is disabled!"));
@ -237,13 +246,15 @@ void ShaderPackPage::changeShaderPackVersion()
const QModelIndexList rows = ui->treeView->selectionModel()->selectedRows();
if (rows.count() != 1)
if (rows.count() != 1) {
return;
}
Resource& resource = m_model->at(m_filterModel->mapToSource(rows[0]).row());
if (resource.metadata() == nullptr)
if (resource.metadata() == nullptr) {
return;
}
m_downloadDialog = new ResourceDownload::ShaderPackDownloadDialog(this, m_model, m_instance);
connect(this, &QObject::destroyed, m_downloadDialog, &QDialog::close);

View file

@ -60,9 +60,9 @@ TexturePackPage::TexturePackPage(MinecraftInstance* instance, TexturePackFolderM
connect(ui->actionUpdateItem, &QAction::triggered, this, &TexturePackPage::updateTexturePacks);
ui->actionsToolbar->insertActionBefore(ui->actionAddItem, ui->actionUpdateItem);
auto updateMenu = new QMenu(this);
auto* updateMenu = new QMenu(this);
auto update = updateMenu->addAction(ui->actionUpdateItem->text());
auto* update = updateMenu->addAction(ui->actionUpdateItem->text());
connect(update, &QAction::triggered, this, &TexturePackPage::updateTexturePacks);
updateMenu->addAction(ui->actionResetItemMetadata);
@ -81,14 +81,15 @@ void TexturePackPage::updateFrame(const QModelIndex& current, [[maybe_unused]] c
{
auto sourceCurrent = m_filterModel->mapToSource(current);
int row = sourceCurrent.row();
auto& rp = static_cast<TexturePack&>(m_model->at(row));
auto& rp = m_model->at(row);
ui->frame->updateWithTexturePack(rp);
}
void TexturePackPage::downloadTexturePacks()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
m_downloadDialog = new ResourceDownload::TexturePackDownloadDialog(this, m_model, m_instance);
connect(this, &QObject::destroyed, m_downloadDialog, &QDialog::close);
@ -98,9 +99,9 @@ void TexturePackPage::downloadTexturePacks()
void TexturePackPage::downloadDialogFinished(int result)
{
if (result) {
auto tasks = new ConcurrentTask("Download Texture Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (result != 0) {
auto* tasks = new ConcurrentTask("Download Texture Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -110,8 +111,9 @@ void TexturePackPage::downloadDialogFinished(int result)
});
connect(tasks, &Task::succeeded, [this, tasks]() {
QStringList warnings = tasks->warnings();
if (warnings.count())
if (warnings.count()) {
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
}
tasks->deleteLater();
});
@ -130,14 +132,16 @@ void TexturePackPage::downloadDialogFinished(int result)
m_model->update();
}
if (m_downloadDialog)
if (m_downloadDialog) {
m_downloadDialog->deleteLater();
}
}
void TexturePackPage::updateTexturePacks()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
QMessageBox::critical(this, tr("Error"), tr("Texture pack updates are unavailable when metadata is disabled!"));
@ -152,27 +156,29 @@ void TexturePackPage::updateTexturePacks()
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto mods_list = m_model->selectedResources(selection);
bool use_all = mods_list.empty();
if (use_all)
mods_list = m_model->allResources();
auto modsList = m_model->selectedResources(selection);
bool useAll = modsList.empty();
if (useAll) {
modsList = m_model->allResources();
}
ResourceUpdateDialog update_dialog(this, m_instance, m_model, mods_list, false);
update_dialog.checkCandidates();
ResourceUpdateDialog updateDialog(this, m_instance, m_model, modsList, false);
updateDialog.checkCandidates();
if (update_dialog.aborted()) {
if (updateDialog.aborted()) {
CustomMessageBox::selectable(this, tr("Aborted"), tr("The texture pack updater was aborted!"), QMessageBox::Warning)->show();
return;
}
if (update_dialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(mods_list.front()->name()) };
if (mods_list.size() > 1) {
if (use_all) {
if (updateDialog.noUpdates()) {
QString message{ tr("'%1' is up-to-date! :)").arg(modsList.front()->name()) };
if (modsList.size() > 1) {
if (useAll) {
message = tr("All texture packs are up-to-date! :)");
} else {
message = tr("All selected texture packs are up-to-date! :)");
@ -182,9 +188,9 @@ void TexturePackPage::updateTexturePacks()
return;
}
if (update_dialog.exec()) {
auto tasks = new ConcurrentTask("Download Texture Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
if (updateDialog.exec() != 0) {
auto* tasks = new ConcurrentTask("Download Texture Packs", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
});
@ -200,7 +206,7 @@ void TexturePackPage::updateTexturePacks()
tasks->deleteLater();
});
for (auto task : update_dialog.getTasks()) {
for (const auto& task : updateDialog.getTasks()) {
tasks->addTask(task);
}
@ -216,8 +222,9 @@ void TexturePackPage::deleteTexturePackMetadata()
{
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
auto selectionCount = m_model->selectedTexturePacks(selection).length();
if (selectionCount == 0)
if (selectionCount == 0) {
return;
}
if (selectionCount > 1) {
auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"),
tr("You are about to remove the metadata for %1 texture packs.\n"
@ -226,8 +233,9 @@ void TexturePackPage::deleteTexturePackMetadata()
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response != QMessageBox::Yes)
if (response != QMessageBox::Yes) {
return;
}
}
m_model->deleteMetadata(selection);
@ -235,8 +243,9 @@ void TexturePackPage::deleteTexturePackMetadata()
void TexturePackPage::changeTexturePackVersion()
{
if (m_instance->typeName() != "Minecraft")
if (m_instance->typeName() != "Minecraft") {
return; // this is a null instance or a legacy instance
}
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
QMessageBox::critical(this, tr("Error"), tr("Texture pack updates are unavailable when metadata is disabled!"));
@ -245,13 +254,15 @@ void TexturePackPage::changeTexturePackVersion()
const QModelIndexList rows = ui->treeView->selectionModel()->selectedRows();
if (rows.count() != 1)
if (rows.count() != 1) {
return;
}
Resource& resource = m_model->at(m_filterModel->mapToSource(rows[0]).row());
if (resource.metadata() == nullptr)
if (resource.metadata() == nullptr) {
return;
}
m_downloadDialog = new ResourceDownload::TexturePackDownloadDialog(this, m_model, m_instance);
connect(this, &QObject::destroyed, m_downloadDialog, &QDialog::close);

View file

@ -39,12 +39,14 @@
#include "ResourcePage.h"
#include "modplatform/ModIndex.h"
#include "ui/dialogs/CustomMessageBox.h"
#include "ui_ResourcePage.h"
#include <StringUtils.h>
#include <QDesktopServices>
#include <QKeyEvent>
#include <QMessageBox>
#include <algorithm>
#include <utility>
#include "Markdown.h"
@ -55,8 +57,8 @@
namespace ResourceDownload {
ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_instance)
: QWidget(parent), m_baseInstance(base_instance), m_ui(new Ui::ResourcePage), m_parentDialog(parent), m_fetchProgress(this, false)
ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& baseInstance)
: QWidget(parent), m_baseInstance(baseInstance), m_ui(new Ui::ResourcePage), m_parentDialog(parent), m_fetchProgress(this, false)
{
m_ui->setupUi(this);
@ -79,7 +81,7 @@ ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_in
m_ui->verticalLayout->insertWidget(1, &m_fetchProgress);
auto delegate = new ProjectItemDelegate(this);
auto* delegate = new ProjectItemDelegate(this);
m_ui->packView->setItemDelegate(delegate);
m_ui->packView->installEventFilter(this);
m_ui->packView->viewport()->installEventFilter(this);
@ -93,8 +95,7 @@ ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_in
ResourcePage::~ResourcePage()
{
delete m_ui;
if (m_model)
delete m_model;
delete m_model;
}
void ResourcePage::retranslate()
@ -127,12 +128,13 @@ auto ResourcePage::eventFilter(QObject* watched, QEvent* event) -> bool
triggerSearch();
keyEvent->accept();
return true;
} else {
if (m_searchTimer.isActive())
m_searchTimer.stop();
m_searchTimer.start(350);
}
if (m_searchTimer.isActive()) {
m_searchTimer.stop();
}
m_searchTimer.start(350);
} else if (watched == m_ui->packView) {
// stop the event from going to the confirm button
if (keyEvent->key() == Qt::Key_Return) {
@ -158,7 +160,7 @@ QString ResourcePage::getSearchTerm() const
return m_ui->searchEdit->text();
}
void ResourcePage::setSearchTerm(QString term)
void ResourcePage::setSearchTerm(const QString& term)
{
m_ui->searchEdit->setText(term);
}
@ -168,10 +170,11 @@ void ResourcePage::addSortings()
Q_ASSERT(m_model);
auto sorts = m_model->getSortingMethods();
std::sort(sorts.begin(), sorts.end(), [](auto const& l, auto const& r) { return l.index < r.index; });
std::ranges::sort(sorts, [](const auto& l, const auto& r) { return l.index < r.index; });
for (auto&& sorting : sorts)
for (auto&& sorting : sorts) {
m_ui->sortByBox->addItem(sorting.readable_name, QVariant(sorting.index));
}
}
bool ResourcePage::setCurrentPack(ModPlatform::IndexedPack::Ptr pack)
@ -188,24 +191,26 @@ ModPlatform::IndexedPack::Ptr ResourcePage::getCurrentPack() const
void ResourcePage::updateUi(const QModelIndex& index)
{
if (index != m_ui->packView->currentIndex())
if (index != m_ui->packView->currentIndex()) {
return;
}
auto current_pack = getCurrentPack();
if (!current_pack) {
auto currentPack = getCurrentPack();
if (!currentPack) {
m_ui->packDescription->setHtml({});
m_ui->packDescription->flush();
return;
}
QString text = "";
QString name = current_pack->name;
QString name = currentPack->name;
if (current_pack->websiteUrl.isEmpty())
if (currentPack->websiteUrl.isEmpty()) {
text = name;
else
text = "<a href=\"" + current_pack->websiteUrl + "\">" + name + "</a>";
} else {
text = "<a href=\"" + currentPack->websiteUrl + "\">" + name + "</a>";
}
if (!current_pack->authors.empty()) {
if (!currentPack->authors.empty()) {
auto authorToStr = [](ModPlatform::ModpackAuthor& author) -> QString {
if (author.url.isEmpty()) {
return author.name;
@ -213,49 +218,53 @@ void ResourcePage::updateUi(const QModelIndex& index)
return QString("<a href=\"%1\">%2</a>").arg(author.url, author.name);
};
QStringList authorStrs;
for (auto& author : current_pack->authors) {
for (auto& author : currentPack->authors) {
authorStrs.push_back(authorToStr(author));
}
text += "<br>" + tr(" by ") + authorStrs.join(", ");
}
if (current_pack->extraDataLoaded) {
if (current_pack->extraData.status == "archived") {
if (currentPack->extraDataLoaded) {
if (currentPack->extraData.status == "archived") {
text += "<br><br>" + tr("<b>This project has been archived. It will not receive any further updates unless the author decides "
"to unarchive the project.</b>");
}
if (!current_pack->extraData.donate.isEmpty()) {
if (!currentPack->extraData.donate.isEmpty()) {
text += "<br><br>" + tr("Donate information: ");
auto donateToStr = [](ModPlatform::DonationData& donate) -> QString {
return QString("<a href=\"%1\">%2</a>").arg(donate.url, donate.platform);
};
QStringList donates;
for (auto& donate : current_pack->extraData.donate) {
for (auto& donate : currentPack->extraData.donate) {
donates.append(donateToStr(donate));
}
text += donates.join(", ");
}
if (!current_pack->extraData.issuesUrl.isEmpty() || !current_pack->extraData.sourceUrl.isEmpty() ||
!current_pack->extraData.wikiUrl.isEmpty() || !current_pack->extraData.discordUrl.isEmpty()) {
if (!currentPack->extraData.issuesUrl.isEmpty() || !currentPack->extraData.sourceUrl.isEmpty() ||
!currentPack->extraData.wikiUrl.isEmpty() || !currentPack->extraData.discordUrl.isEmpty()) {
text += "<br><br>" + tr("External links:") + "<br>";
}
if (!current_pack->extraData.issuesUrl.isEmpty())
text += "- " + tr("Issues: <a href=%1>%1</a>").arg(current_pack->extraData.issuesUrl) + "<br>";
if (!current_pack->extraData.wikiUrl.isEmpty())
text += "- " + tr("Wiki: <a href=%1>%1</a>").arg(current_pack->extraData.wikiUrl) + "<br>";
if (!current_pack->extraData.sourceUrl.isEmpty())
text += "- " + tr("Source code: <a href=%1>%1</a>").arg(current_pack->extraData.sourceUrl) + "<br>";
if (!current_pack->extraData.discordUrl.isEmpty())
text += "- " + tr("Discord: <a href=%1>%1</a>").arg(current_pack->extraData.discordUrl) + "<br>";
if (!currentPack->extraData.issuesUrl.isEmpty()) {
text += "- " + tr("Issues: <a href=%1>%1</a>").arg(currentPack->extraData.issuesUrl) + "<br>";
}
if (!currentPack->extraData.wikiUrl.isEmpty()) {
text += "- " + tr("Wiki: <a href=%1>%1</a>").arg(currentPack->extraData.wikiUrl) + "<br>";
}
if (!currentPack->extraData.sourceUrl.isEmpty()) {
text += "- " + tr("Source code: <a href=%1>%1</a>").arg(currentPack->extraData.sourceUrl) + "<br>";
}
if (!currentPack->extraData.discordUrl.isEmpty()) {
text += "- " + tr("Discord: <a href=%1>%1</a>").arg(currentPack->extraData.discordUrl) + "<br>";
}
}
text += "<hr>";
m_ui->packDescription->setHtml(StringUtils::htmlListPatch(
text + (current_pack->extraData.body.isEmpty() ? current_pack->description : markdownToHTML(current_pack->extraData.body))));
text + (currentPack->extraData.body.isEmpty() ? currentPack->description : markdownToHTML(currentPack->extraData.body))));
m_ui->packDescription->flush();
}
@ -267,14 +276,15 @@ void ResourcePage::updateSelectionButton()
}
m_ui->resourceSelectionButton->setEnabled(true);
if (auto current_pack = getCurrentPack(); current_pack) {
if (current_pack->versionsLoaded && current_pack->versions.empty()) {
if (auto currentPack = getCurrentPack(); currentPack) {
if (currentPack->versionsLoaded && currentPack->versions.empty()) {
m_ui->resourceSelectionButton->setEnabled(false);
qWarning() << tr("No version available for the selected pack");
} else if (!current_pack->isVersionSelected(m_selectedVersionIndex))
} else if (!currentPack->isVersionSelected(m_selectedVersionIndex)) {
m_ui->resourceSelectionButton->setText(tr("Select %1 for download").arg(resourceString()));
else
} else {
m_ui->resourceSelectionButton->setText(tr("Deselect %1 for download").arg(resourceString()));
}
} else {
qWarning() << "Tried to update the selected button but there is not a pack selected";
}
@ -283,19 +293,20 @@ void ResourcePage::updateSelectionButton()
void ResourcePage::versionListUpdated(const QModelIndex& index)
{
if (index == m_ui->packView->currentIndex()) {
auto current_pack = getCurrentPack();
auto currentPack = getCurrentPack();
m_ui->versionSelectionBox->blockSignals(true);
m_ui->versionSelectionBox->clear();
m_ui->versionSelectionBox->blockSignals(false);
if (current_pack) {
auto installedVersion = m_model->getInstalledPackVersion(current_pack);
if (currentPack) {
auto installedVersion = m_model->getInstalledPackVersion(currentPack);
for (int i = 0; i < current_pack->versions.size(); i++) {
auto& version = current_pack->versions[i];
if (!m_model->checkVersionFilters(version))
for (int i = 0; i < currentPack->versions.size(); i++) {
auto& version = currentPack->versions[i];
if (!m_model->checkVersionFilters(version)) {
continue;
}
auto versionText = version.version;
if (version.version_type.isValid()) {
@ -316,8 +327,9 @@ void ResourcePage::versionListUpdated(const QModelIndex& index)
if (m_enableQueue.contains(index.row())) {
m_enableQueue.remove(index.row());
onResourceToggle(index);
} else
} else {
updateSelectionButton();
}
} else if (m_enableQueue.contains(index.row())) {
m_enableQueue.remove(index.row());
onResourceToggle(index);
@ -330,27 +342,30 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
return;
}
auto current_pack = getCurrentPack();
auto currentPack = getCurrentPack();
bool request_load = false;
if (!current_pack || !current_pack->versionsLoaded) {
bool requestLoad = false;
if (!currentPack || !currentPack->versionsLoaded) {
m_ui->resourceSelectionButton->setText(tr("Loading versions..."));
m_ui->resourceSelectionButton->setEnabled(false);
request_load = true;
requestLoad = true;
} else {
versionListUpdated(curr);
}
if (current_pack && !current_pack->extraDataLoaded)
request_load = true;
if (currentPack && !currentPack->extraDataLoaded) {
requestLoad = true;
}
// we are already requesting this
if (m_enableQueue.contains(curr.row()))
request_load = false;
if (m_enableQueue.contains(curr.row())) {
requestLoad = false;
}
if (request_load)
if (requestLoad) {
m_model->loadEntry(curr);
}
updateUi(curr);
}
@ -363,18 +378,18 @@ void ResourcePage::onVersionSelectionChanged(int index)
void ResourcePage::addResourceToDialog(ModPlatform::IndexedPack::Ptr pack, ModPlatform::IndexedVersion& version)
{
m_parentDialog->addResource(pack, version);
m_parentDialog->addResource(std::move(pack), version);
}
void ResourcePage::removeResourceFromDialog(const QString& pack_name)
void ResourcePage::removeResourceFromDialog(const QString& packName)
{
m_parentDialog->removeResource(pack_name);
m_parentDialog->removeResource(packName);
}
void ResourcePage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack, ModPlatform::IndexedVersion& ver, ResourceFolderModel* base_model)
void ResourcePage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack, ModPlatform::IndexedVersion& ver, ResourceFolderModel* baseModel)
{
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_model->addPack(pack, ver, base_model, is_indexed);
bool isIndexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_model->addPack(std::move(pack), ver, baseModel, isIndexed);
}
void ResourcePage::modelReset()
@ -389,22 +404,25 @@ void ResourcePage::removeResourceFromPage(const QString& name)
void ResourcePage::onResourceSelected()
{
if (m_selectedVersionIndex < 0)
if (m_selectedVersionIndex < 0) {
return;
}
auto current_pack = getCurrentPack();
if (!current_pack || !current_pack->versionsLoaded || current_pack->versions.size() < m_selectedVersionIndex)
auto currentPack = getCurrentPack();
if (!currentPack || !currentPack->versionsLoaded || currentPack->versions.size() < m_selectedVersionIndex) {
return;
}
auto& version = current_pack->versions[m_selectedVersionIndex];
auto& version = currentPack->versions[m_selectedVersionIndex];
Q_ASSERT(!version.downloadUrl.isNull());
if (version.is_currently_selected)
removeResourceFromDialog(current_pack->name);
else
addResourceToDialog(current_pack, version);
if (version.is_currently_selected) {
removeResourceFromDialog(currentPack->name);
} else {
addResourceToDialog(currentPack, version);
}
// Save the modified pack (and prevent warning in release build)
[[maybe_unused]] bool set = setCurrentPack(current_pack);
[[maybe_unused]] bool set = setCurrentPack(currentPack);
Q_ASSERT(set);
updateSelectionButton();
@ -419,26 +437,28 @@ void ResourcePage::onResourceToggle(const QModelIndex& index)
auto pack = m_model->data(index, Qt::UserRole).value<ModPlatform::IndexedPack::Ptr>();
if (pack->versionsLoaded) {
if (pack->isAnyVersionSelected())
if (pack->isAnyVersionSelected()) {
removeResourceFromDialog(pack->name);
else {
} else {
auto version = std::find_if(pack->versions.begin(), pack->versions.end(), [this](const ModPlatform::IndexedVersion& version) {
return m_model->checkVersionFilters(version);
});
if (version == pack->versions.end()) {
auto errorMessage = new QMessageBox(
auto* errorMessage = new QMessageBox(
QMessageBox::Warning, tr("No versions available"),
tr("No versions for '%1' are available.\nThe author likely blocked third-party launchers.").arg(pack->name),
QMessageBox::Ok, this);
errorMessage->open();
} else
} else {
addResourceToDialog(pack, *version);
}
}
if (isSelected)
if (isSelected) {
updateSelectionButton();
}
// force update
QVariant variant;
@ -450,8 +470,9 @@ void ResourcePage::onResourceToggle(const QModelIndex& index)
// we can't be sure that this hasn't already been requested...
// but this does the job well enough and there's not much point preventing edgecases
if (!isSelected)
if (!isSelected) {
m_model->loadEntry(index);
}
}
}
@ -482,13 +503,13 @@ void ResourcePage::openUrl(const QUrl& url)
const QString slug = match.captured(1);
// ensure the user isn't opening the same mod
if (auto current_pack = getCurrentPack(); current_pack && slug != current_pack->slug) {
if (auto currentPack = getCurrentPack(); currentPack && slug != currentPack->slug) {
m_parentDialog->selectPage(page);
auto newPage = m_parentDialog->selectedPage();
auto* newPage = m_parentDialog->selectedPage();
QLineEdit* searchEdit = newPage->m_ui->searchEdit;
auto model = newPage->m_model;
auto* model = newPage->m_model;
QListView* view = newPage->m_ui->packView;
auto jump = [url, slug, model, view] {
@ -509,10 +530,11 @@ void ResourcePage::openUrl(const QUrl& url)
searchEdit->setText(slug);
newPage->triggerSearch();
if (model->hasActiveSearchJob())
if (model->hasActiveSearchJob()) {
connect(model->activeSearchJob().get(), &Task::finished, jump);
else
} else {
jump();
}
return;
}
@ -522,7 +544,7 @@ void ResourcePage::openUrl(const QUrl& url)
QDesktopServices::openUrl(url);
}
void ResourcePage::openProject(QVariant projectID)
void ResourcePage::openProject(const QVariant& projectID)
{
m_ui->sortByBox->hide();
m_ui->searchEdit->hide();
@ -531,16 +553,16 @@ void ResourcePage::openProject(QVariant projectID)
m_ui->resourceSelectionButton->hide();
m_doNotJumpToMod = true;
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
auto okBtn = buttonBox->button(QDialogButtonBox::Ok);
auto* okBtn = buttonBox->button(QDialogButtonBox::Ok);
okBtn->setDefault(true);
okBtn->setAutoDefault(true);
okBtn->setText(tr("Reinstall"));
okBtn->setShortcut(tr("Ctrl+Return"));
okBtn->setEnabled(false);
auto cancelBtn = buttonBox->button(QDialogButtonBox::Cancel);
auto* cancelBtn = buttonBox->button(QDialogButtonBox::Cancel);
cancelBtn->setDefault(false);
cancelBtn->setAutoDefault(false);
cancelBtn->setText(tr("Cancel"));
@ -567,9 +589,10 @@ void ResourcePage::openProject(QVariant projectID)
m_ui->searchEdit->setText("#" + projectID.toString());
triggerSearch();
if (m_model->hasActiveSearchJob())
if (m_model->hasActiveSearchJob()) {
connect(m_model->activeSearchJob().get(), &Task::finished, jump);
else
} else {
jump();
}
}
} // namespace ResourceDownload

View file

@ -44,9 +44,9 @@ class ResourcePage : public QWidget, public BasePage {
virtual auto debugName() const -> QString = 0;
//: The plural version of 'resource'
virtual inline QString resourcesString() const { return tr("resources"); }
virtual QString resourcesString() const { return tr("resources"); }
//: The singular version of 'resources'
virtual inline QString resourceString() const { return tr("resource"); }
virtual QString resourceString() const { return tr("resource"); }
/* Features this resource's page supports */
virtual bool supportsFiltering() const = 0;
@ -58,7 +58,7 @@ class ResourcePage : public QWidget, public BasePage {
/** Get the current term in the search bar. */
auto getSearchTerm() const -> QString;
/** Programatically set the term in the search bar. */
void setSearchTerm(QString);
void setSearchTerm(const QString&);
bool setCurrentPack(ModPlatform::IndexedPack::Ptr);
auto getCurrentPack() const -> ModPlatform::IndexedPack::Ptr;
@ -76,7 +76,7 @@ class ResourcePage : public QWidget, public BasePage {
virtual void versionListUpdated(const QModelIndex& index);
void addResourceToDialog(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&);
void removeResourceFromDialog(const QString& pack_name);
void removeResourceFromDialog(const QString& packName);
virtual void removeResourceFromPage(const QString& name);
virtual void addResourceToPage(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&, ResourceFolderModel*);
@ -90,7 +90,7 @@ class ResourcePage : public QWidget, public BasePage {
protected slots:
virtual void triggerSearch() = 0;
void onSelectionChanged(QModelIndex first, QModelIndex second);
void onSelectionChanged(QModelIndex curr, QModelIndex prev);
void onVersionSelectionChanged(int index);
void onResourceSelected();
void onResourceToggle(const QModelIndex& index);

View file

@ -49,6 +49,7 @@
#include <QStackedLayout>
#include <QStyledItemDelegate>
#include <QUrl>
#include <utility>
#include "settings/SettingsObject.h"
@ -59,40 +60,43 @@
class PageEntryFilterModel : public QSortFilterProxyModel {
public:
explicit PageEntryFilterModel(QObject* parent = 0) : QSortFilterProxyModel(parent) {}
explicit PageEntryFilterModel(QObject* parent = nullptr) : QSortFilterProxyModel(parent) {}
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override
{
const QString pattern = filterRegularExpression().pattern();
const auto model = static_cast<PageModel*>(sourceModel());
const auto page = model->pages().at(sourceRow);
if (!page->shouldDisplay())
auto* const model = static_cast<PageModel*>(sourceModel());
auto* const page = model->pages().at(sourceRow);
if (!page->shouldDisplay()) {
return false;
}
// Regular contents check, then check page-filter.
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
};
PageContainer::PageContainer(BasePageProvider* pageProvider, QString defaultId, QWidget* parent) : QWidget(parent)
PageContainer::PageContainer(BasePageProvider* pageProvider, QString defaultId, QWidget* parent)
: QWidget(parent)
, m_proxyModel(new PageEntryFilterModel(this))
, m_model(new PageModel(this))
{
createUI();
useSidebarStyle(true);
m_model = new PageModel(this);
m_proxyModel = new PageEntryFilterModel(this);
int counter = 0;
auto pages = pageProvider->getPages();
for (auto page : pages) {
auto widget = dynamic_cast<QWidget*>(page);
for (auto* page : pages) {
auto* widget = dynamic_cast<QWidget*>(page);
widget->setParent(this);
page->stackIndex = m_pageStack->addWidget(widget);
page->listIndex = counter;
page->setParentContainer(this);
counter++;
page->updateExtraInfo = [this](QString id, QString info) {
if (m_currentPage && id == m_currentPage->id())
page->updateExtraInfo = [this](const QString& id, const QString& info) {
if (m_currentPage && id == m_currentPage->id()) {
m_header->setText(m_currentPage->displayName() + info);
}
};
}
m_model->setPages(pages);
@ -108,13 +112,13 @@ PageContainer::PageContainer(BasePageProvider* pageProvider, QString defaultId,
connect(m_pageList->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &PageContainer::currentChanged);
m_pageStack->setStackingMode(QStackedLayout::StackOne);
m_pageList->setFocus();
selectPage(defaultId);
selectPage(std::move(defaultId));
}
bool PageContainer::selectPage(QString pageId)
{
// now find what we want to have selected...
auto page = m_model->findPageEntryById(pageId);
auto* page = m_model->findPageEntryById(pageId);
QModelIndex index;
if (page) {
index = m_proxyModel->mapFromSource(m_model->index(page->listIndex));
@ -166,11 +170,12 @@ void PageContainer::createUI()
QFont headerLabelFont = m_header->font();
headerLabelFont.setBold(true);
const int pointSize = headerLabelFont.pointSize();
if (pointSize > 0)
if (pointSize > 0) {
headerLabelFont.setPointSize(pointSize + 2);
}
m_header->setFont(headerLabelFont);
QHBoxLayout* headerHLayout = new QHBoxLayout;
auto* headerHLayout = new QHBoxLayout;
const int leftMargin = APPLICATION->style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
headerHLayout->addSpacerItem(new QSpacerItem(leftMargin, 0, QSizePolicy::Fixed, QSizePolicy::Ignored));
headerHLayout->addWidget(m_header);
@ -190,11 +195,13 @@ void PageContainer::createUI()
void PageContainer::retranslate()
{
if (m_currentPage)
if (m_currentPage) {
m_header->setText(m_currentPage->displayName());
}
for (auto page : m_model->pages())
for (auto* page : m_model->pages()) {
page->retranslate();
}
}
void PageContainer::addButtons(QWidget* buttons)
@ -236,22 +243,23 @@ void PageContainer::help()
{
if (m_currentPage) {
QString pageId = m_currentPage->helpPage();
if (pageId.isEmpty())
if (pageId.isEmpty()) {
return;
}
DesktopServices::openUrl(QUrl(BuildConfig.HELP_URL.arg(pageId)));
}
}
void PageContainer::currentChanged(const QModelIndex& current)
{
int selected_index = current.isValid() ? m_proxyModel->mapToSource(current).row() : -1;
int selectedIndex = current.isValid() ? m_proxyModel->mapToSource(current).row() : -1;
auto* selected = m_model->pages().at(selected_index);
auto* selected = m_model->pages().at(selectedIndex);
auto* previous = m_currentPage;
emit selectedPageChanged(previous, selected);
showPage(selected_index);
showPage(selectedIndex);
}
bool PageContainer::prepareToClose()
@ -267,9 +275,10 @@ bool PageContainer::prepareToClose()
bool PageContainer::saveAll()
{
for (auto page : m_model->pages()) {
if (!page->apply())
for (auto* page : m_model->pages()) {
if (!page->apply()) {
return false;
}
}
return true;
}

View file

@ -56,8 +56,10 @@ class QGridLayout;
class PageContainer : public QWidget, public BasePageContainer {
Q_OBJECT
public:
explicit PageContainer(BasePageProvider* pageProvider, QString defaultId = QString(), QWidget* parent = 0);
virtual ~PageContainer() {}
explicit PageContainer(BasePageProvider* pageProvider,
QString defaultId = QString(),
QWidget* parent = nullptr);
~PageContainer() override = default;
void addButtons(QWidget* buttons);
void addButtons(QLayout* buttons);