diff options
Diffstat (limited to 'launcher/ui/pages/modplatform')
44 files changed, 560 insertions, 724 deletions
diff --git a/launcher/ui/pages/modplatform/CustomPage.cpp b/launcher/ui/pages/modplatform/CustomPage.cpp index e164171a..4ac21b01 100644 --- a/launcher/ui/pages/modplatform/CustomPage.cpp +++ b/launcher/ui/pages/modplatform/CustomPage.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -46,8 +46,7 @@ #include "minecraft/VanillaInstanceCreationTask.h" #include "ui/dialogs/NewInstanceDialog.h" -CustomPage::CustomPage(NewInstanceDialog *dialog, QWidget *parent) - : QWidget(parent), dialog(dialog), ui(new Ui::CustomPage) +CustomPage::CustomPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), dialog(dialog), ui(new Ui::CustomPage) { ui->setupUi(this); ui->tabWidget->tabBar()->hide(); @@ -68,19 +67,15 @@ CustomPage::CustomPage(NewInstanceDialog *dialog, QWidget *parent) connect(ui->quiltFilter, &QRadioButton::toggled, this, &CustomPage::loaderFilterChanged); connect(ui->liteLoaderFilter, &QRadioButton::toggled, this, &CustomPage::loaderFilterChanged); connect(ui->loaderRefreshBtn, &QPushButton::clicked, this, &CustomPage::loaderRefresh); - } void CustomPage::openedImpl() { - if(!initialized) - { + if (!initialized) { auto vlist = APPLICATION->metadataIndex()->get("net.minecraft"); ui->versionList->initialize(vlist.get()); initialized = true; - } - else - { + } else { suggestCurrent(); } } @@ -92,7 +87,7 @@ void CustomPage::refresh() void CustomPage::loaderRefresh() { - if(ui->noneFilter->isChecked()) + if (ui->noneFilter->isChecked()) return; ui->loaderVersionList->loadList(); } @@ -100,17 +95,17 @@ void CustomPage::loaderRefresh() void CustomPage::filterChanged() { QStringList out; - if(ui->alphaFilter->isChecked()) + if (ui->alphaFilter->isChecked()) out << "(old_alpha)"; - if(ui->betaFilter->isChecked()) + if (ui->betaFilter->isChecked()) out << "(old_beta)"; - if(ui->snapshotFilter->isChecked()) + if (ui->snapshotFilter->isChecked()) out << "(snapshot)"; - if(ui->oldSnapshotFilter->isChecked()) + if (ui->oldSnapshotFilter->isChecked()) out << "(old_snapshot)"; - if(ui->releaseFilter->isChecked()) + if (ui->releaseFilter->isChecked()) out << "(release)"; - if(ui->experimentsFilter->isChecked()) + if (ui->experimentsFilter->isChecked()) out << "(experiment)"; auto regexp = out.join('|'); ui->versionList->setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false)); @@ -119,49 +114,37 @@ void CustomPage::filterChanged() void CustomPage::loaderFilterChanged() { QString minecraftVersion; - if (m_selectedVersion) - { + if (m_selectedVersion) { minecraftVersion = m_selectedVersion->descriptor(); - } - else - { - ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, "AAA"); // empty list + } else { + ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, "AAA"); // empty list ui->loaderVersionList->setEmptyString(tr("No Minecraft version is selected.")); ui->loaderVersionList->setEmptyMode(VersionListView::String); return; } - if(ui->noneFilter->isChecked()) - { - ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, "AAA"); // empty list + if (ui->noneFilter->isChecked()) { + ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, "AAA"); // empty list ui->loaderVersionList->setEmptyString(tr("No mod loader is selected.")); ui->loaderVersionList->setEmptyMode(VersionListView::String); return; - } - else if(ui->forgeFilter->isChecked()) - { + } else if (ui->forgeFilter->isChecked()) { ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion); m_selectedLoader = "net.minecraftforge"; - } - else if(ui->fabricFilter->isChecked()) - { + } else if (ui->fabricFilter->isChecked()) { // FIXME: dirty hack because the launcher is unaware of Fabric's dependencies - if (Version(minecraftVersion) >= Version("1.14")) // Fabric/Quilt supported + if (Version(minecraftVersion) >= Version("1.14")) // Fabric/Quilt supported ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, ""); - else // Fabric/Quilt unsupported - ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, "AAA"); // clear list + else // Fabric/Quilt unsupported + ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, "AAA"); // clear list m_selectedLoader = "net.fabricmc.fabric-loader"; - } - else if(ui->quiltFilter->isChecked()) - { + } else if (ui->quiltFilter->isChecked()) { // FIXME: dirty hack because the launcher is unaware of Quilt's dependencies (same as Fabric) - if (Version(minecraftVersion) >= Version("1.14")) // Fabric/Quilt supported + if (Version(minecraftVersion) >= Version("1.14")) // Fabric/Quilt supported ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, ""); - else // Fabric/Quilt unsupported - ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, "AAA"); // clear list + else // Fabric/Quilt unsupported + ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, "AAA"); // clear list m_selectedLoader = "org.quiltmc.quilt-loader"; - } - else if(ui->liteLoaderFilter->isChecked()) - { + } else if (ui->liteLoaderFilter->isChecked()) { ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion); m_selectedLoader = "com.mumfrey.liteloader"; } @@ -204,25 +187,21 @@ QString CustomPage::selectedLoader() const void CustomPage::suggestCurrent() { - if (!isOpened) - { + if (!isOpened) { return; } - - if(!m_selectedVersion) - { + + if (!m_selectedVersion) { dialog->setSuggestedPack(); return; } // There isn't a selected version if the version list is empty - if(ui->loaderVersionList->selectedVersion() == nullptr) + if (ui->loaderVersionList->selectedVersion() == nullptr) dialog->setSuggestedPack(m_selectedVersion->descriptor(), new VanillaCreationTask(m_selectedVersion)); - else - { + else { dialog->setSuggestedPack(m_selectedVersion->descriptor(), - new VanillaCreationTask(m_selectedVersion, m_selectedLoader, - m_selectedLoaderVersion)); + new VanillaCreationTask(m_selectedVersion, m_selectedLoader, m_selectedLoaderVersion)); } dialog->setSuggestedIcon("default"); } diff --git a/launcher/ui/pages/modplatform/CustomPage.h b/launcher/ui/pages/modplatform/CustomPage.h index 8b5a5011..c5d6d5af 100644 --- a/launcher/ui/pages/modplatform/CustomPage.h +++ b/launcher/ui/pages/modplatform/CustomPage.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -37,40 +37,26 @@ #include <QWidget> -#include "ui/pages/BasePage.h" #include <Application.h> #include "tasks/Task.h" +#include "ui/pages/BasePage.h" -namespace Ui -{ +namespace Ui { class CustomPage; } class NewInstanceDialog; -class CustomPage : public QWidget, public BasePage -{ +class CustomPage : public QWidget, public BasePage { Q_OBJECT -public: - explicit CustomPage(NewInstanceDialog *dialog, QWidget *parent = 0); + public: + explicit CustomPage(NewInstanceDialog* dialog, QWidget* parent = 0); virtual ~CustomPage(); - virtual QString displayName() const override - { - return tr("Custom"); - } - virtual QIcon icon() const override - { - return APPLICATION->getThemedIcon("minecraft"); - } - virtual QString id() const override - { - return "vanilla"; - } - virtual QString helpPage() const override - { - return "Vanilla-platform"; - } + virtual QString displayName() const override { return tr("Custom"); } + virtual QIcon icon() const override { return APPLICATION->getThemedIcon("minecraft"); } + virtual QString id() const override { return "vanilla"; } + virtual QString helpPage() const override { return "Vanilla-platform"; } virtual bool shouldDisplay() const override; void retranslate() override; @@ -80,23 +66,23 @@ public: BaseVersion::Ptr selectedLoaderVersion() const; QString selectedLoader() const; -public slots: + public slots: void setSelectedVersion(BaseVersion::Ptr version); void setSelectedLoaderVersion(BaseVersion::Ptr version); -private slots: + private slots: void filterChanged(); void loaderFilterChanged(); -private: + private: void refresh(); void loaderRefresh(); void suggestCurrent(); -private: + private: bool initialized = false; - NewInstanceDialog *dialog = nullptr; - Ui::CustomPage *ui = nullptr; + NewInstanceDialog* dialog = nullptr; + Ui::CustomPage* ui = nullptr; bool m_versionSetByUser = false; BaseVersion::Ptr m_selectedVersion; BaseVersion::Ptr m_selectedLoaderVersion; diff --git a/launcher/ui/pages/modplatform/ImportPage.cpp b/launcher/ui/pages/modplatform/ImportPage.cpp index 8250193a..ee8757f8 100644 --- a/launcher/ui/pages/modplatform/ImportPage.cpp +++ b/launcher/ui/pages/modplatform/ImportPage.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * @@ -43,8 +43,8 @@ #include <QValidator> #include <utility> -#include "ui/dialogs/NewInstanceDialog.h" #include "ui/dialogs/CustomMessageBox.h" +#include "ui/dialogs/NewInstanceDialog.h" #include "modplatform/flame/FlameAPI.h" @@ -52,32 +52,24 @@ #include "InstanceImportTask.h" - -class UrlValidator : public QValidator -{ -public: +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()) - { + if (url.isValid() && !url.isRelative() && !url.isEmpty()) { return Acceptable; - } - else if (QFile::exists(in)) - { + } else if (QFile::exists(in)) { return Acceptable; - } - else - { + } else { return Intermediate; } } }; -ImportPage::ImportPage(NewInstanceDialog* dialog, QWidget *parent) - : QWidget(parent), ui(new Ui::ImportPage), dialog(dialog) +ImportPage::ImportPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::ImportPage), dialog(dialog) { ui->setupUi(this); ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit)); @@ -138,7 +130,7 @@ void ImportPage::updateState() auto api = FlameAPI(); auto job = api.getFile(addonId, fileId, array); - + connect(job.get(), &NetJob::failed, this, [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); }); connect(job.get(), &NetJob::succeeded, this, [this, array, addonId, fileId] { @@ -201,7 +193,8 @@ void ImportPage::setUrl(const QString& url) updateState(); } -void ImportPage::setExtraInfo(const QMap<QString, QString>& extra_info) { +void ImportPage::setExtraInfo(const QMap<QString, QString>& extra_info) +{ m_extra_info = extra_info; updateState(); } @@ -212,29 +205,21 @@ void ImportPage::on_modpackBtn_clicked() //: Option for filtering for *.mrpack files when importing filter += ";;" + tr("Modrinth pack") + " (*.mrpack)"; const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), filter); - if (url.isValid()) - { - if (url.isLocalFile()) - { + if (url.isValid()) { + if (url.isLocalFile()) { ui->modpackEdit->setText(url.toLocalFile()); - } - else - { + } else { ui->modpackEdit->setText(url.toString()); } } } - QUrl ImportPage::modpackUrl() const { const QUrl url(ui->modpackEdit->text()); - if (url.isValid() && !url.isRelative() && !url.host().isEmpty()) - { + if (url.isValid() && !url.isRelative() && !url.host().isEmpty()) { return url; - } - else - { + } else { return QUrl::fromLocalFile(ui->modpackEdit->text()); } } diff --git a/launcher/ui/pages/modplatform/ImportPage.h b/launcher/ui/pages/modplatform/ImportPage.h index 54640752..70d7736e 100644 --- a/launcher/ui/pages/modplatform/ImportPage.h +++ b/launcher/ui/pages/modplatform/ImportPage.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -37,56 +37,41 @@ #include <QWidget> -#include "ui/pages/BasePage.h" #include <Application.h> #include "tasks/Task.h" +#include "ui/pages/BasePage.h" -namespace Ui -{ +namespace Ui { class ImportPage; } class NewInstanceDialog; -class ImportPage : public QWidget, public BasePage -{ +class ImportPage : public QWidget, public BasePage { Q_OBJECT -public: - explicit ImportPage(NewInstanceDialog* dialog, QWidget *parent = 0); + public: + explicit ImportPage(NewInstanceDialog* dialog, QWidget* parent = 0); virtual ~ImportPage(); - virtual QString displayName() const override - { - return tr("Import"); - } - virtual QIcon icon() const override - { - return APPLICATION->getThemedIcon("viewfolder"); - } - virtual QString id() const override - { - return "import"; - } - virtual QString helpPage() const override - { - return "Zip-import"; - } + virtual QString displayName() const override { return tr("Import"); } + virtual QIcon icon() const override { return APPLICATION->getThemedIcon("viewfolder"); } + virtual QString id() const override { return "import"; } + virtual QString helpPage() const override { return "Zip-import"; } virtual bool shouldDisplay() const override; void retranslate() override; - void setUrl(const QString & url); + void setUrl(const QString& url); void openedImpl() override; void setExtraInfo(const QMap<QString, QString>& extra_info); -private slots: + private slots: void on_modpackBtn_clicked(); void updateState(); -private: + private: QUrl modpackUrl() const; -private: - Ui::ImportPage *ui = nullptr; + private: + Ui::ImportPage* ui = nullptr; NewInstanceDialog* dialog = nullptr; QMap<QString, QString> m_extra_info = {}; }; - diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp index 3e0c0257..0a7edb7b 100644 --- a/launcher/ui/pages/modplatform/ResourceModel.cpp +++ b/launcher/ui/pages/modplatform/ResourceModel.cpp @@ -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()) @@ -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: diff --git a/launcher/ui/pages/modplatform/ResourceModel.h b/launcher/ui/pages/modplatform/ResourceModel.h index 6533d9c6..cc813d6e 100644 --- a/launcher/ui/pages/modplatform/ResourceModel.h +++ b/launcher/ui/pages/modplatform/ResourceModel.h @@ -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); } diff --git a/launcher/ui/pages/modplatform/ResourcePackModel.cpp b/launcher/ui/pages/modplatform/ResourcePackModel.cpp index 18c14bf8..d436f320 100644 --- a/launcher/ui/pages/modplatform/ResourcePackModel.cpp +++ b/launcher/ui/pages/modplatform/ResourcePackModel.cpp @@ -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 ********/ diff --git a/launcher/ui/pages/modplatform/ResourcePackPage.cpp b/launcher/ui/pages/modplatform/ResourcePackPage.cpp index 52fb4802..2a4d0281 100644 --- a/launcher/ui/pages/modplatform/ResourcePackPage.cpp +++ b/launcher/ui/pages/modplatform/ResourcePackPage.cpp @@ -13,8 +13,7 @@ namespace ResourceDownload { -ResourcePackResourcePage::ResourcePackResourcePage(ResourceDownloadDialog* dialog, BaseInstance& instance) - : ResourcePage(dialog, instance) +ResourcePackResourcePage::ResourcePackResourcePage(ResourceDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance) { connect(m_ui->searchButton, &QPushButton::clicked, this, &ResourcePackResourcePage::triggerSearch); connect(m_ui->packView, &QListView::doubleClicked, this, &ResourcePackResourcePage::onResourceSelected); @@ -38,7 +37,8 @@ QMap<QString, QString> ResourcePackResourcePage::urlHandlers() const { QMap<QString, QString> map; map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/resourcepack\\/([^\\/]+)\\/?"), "modrinth"); - map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/texture-packs\\/([^\\/]+)\\/?"), "curseforge"); + map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/texture-packs\\/([^\\/]+)\\/?"), + "curseforge"); map.insert(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"), "curseforge"); return map; } diff --git a/launcher/ui/pages/modplatform/ResourcePackPage.h b/launcher/ui/pages/modplatform/ResourcePackPage.h index 8c5cf08b..6015aec0 100644 --- a/launcher/ui/pages/modplatform/ResourcePackPage.h +++ b/launcher/ui/pages/modplatform/ResourcePackPage.h @@ -4,8 +4,8 @@ #pragma once -#include "ui/pages/modplatform/ResourcePage.h" #include "ui/pages/modplatform/ResourcePackModel.h" +#include "ui/pages/modplatform/ResourcePage.h" namespace Ui { class ResourcePage; diff --git a/launcher/ui/pages/modplatform/ResourcePage.cpp b/launcher/ui/pages/modplatform/ResourcePage.cpp index d16ac6fd..c087e2be 100644 --- a/launcher/ui/pages/modplatform/ResourcePage.cpp +++ b/launcher/ui/pages/modplatform/ResourcePage.cpp @@ -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; } diff --git a/launcher/ui/pages/modplatform/ResourcePage.h b/launcher/ui/pages/modplatform/ResourcePage.h index b4a87f57..7bec0a37 100644 --- a/launcher/ui/pages/modplatform/ResourcePage.h +++ b/launcher/ui/pages/modplatform/ResourcePage.h @@ -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; diff --git a/launcher/ui/pages/modplatform/ShaderPackModel.cpp b/launcher/ui/pages/modplatform/ShaderPackModel.cpp index aabd3be6..8c913657 100644 --- a/launcher/ui/pages/modplatform/ShaderPackModel.cpp +++ b/launcher/ui/pages/modplatform/ShaderPackModel.cpp @@ -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 ********/ diff --git a/launcher/ui/pages/modplatform/TexturePackPage.h b/launcher/ui/pages/modplatform/TexturePackPage.h index 0bdce2f9..948e5286 100644 --- a/launcher/ui/pages/modplatform/TexturePackPage.h +++ b/launcher/ui/pages/modplatform/TexturePackPage.h @@ -4,10 +4,10 @@ #pragma once -#include "ui_ResourcePage.h" #include "ui/dialogs/ResourceDownloadDialog.h" #include "ui/pages/modplatform/ResourcePackPage.h" #include "ui/pages/modplatform/TexturePackModel.h" +#include "ui_ResourcePage.h" namespace Ui { class ResourcePage; @@ -39,8 +39,7 @@ class TexturePackResourcePage : public ResourcePackResourcePage { [[nodiscard]] inline QString resourceString() const override { return tr("texture pack"); } protected: - TexturePackResourcePage(TexturePackDownloadDialog* dialog, BaseInstance& instance) - : ResourcePackResourcePage(dialog, instance) + TexturePackResourcePage(TexturePackDownloadDialog* dialog, BaseInstance& instance) : ResourcePackResourcePage(dialog, instance) { connect(m_ui->searchButton, &QPushButton::clicked, this, &TexturePackResourcePage::triggerSearch); connect(m_ui->packView, &QListView::doubleClicked, this, &TexturePackResourcePage::onResourceSelected); diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp index 0887ebee..9cd5eed5 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp +++ b/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp @@ -18,14 +18,14 @@ #include <QDebug> -#include <modplatform/atlauncher/ATLPackIndex.h> #include <Version.h> +#include <modplatform/atlauncher/ATLPackIndex.h> #include "StringUtils.h" namespace Atl { -FilterModel::FilterModel(QObject *parent) : QSortFilterProxyModel(parent) +FilterModel::FilterModel(QObject* parent) : QSortFilterProxyModel(parent) { currentSorting = Sorting::ByPopularity; sortings.insert(tr("Sort by Popularity"), Sorting::ByPopularity); @@ -62,7 +62,7 @@ void FilterModel::setSearchTerm(const QString term) invalidate(); } -bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { if (searchTerm.isEmpty()) { return true; @@ -73,20 +73,18 @@ bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParen return pack.name.contains(searchTerm, Qt::CaseInsensitive); } -bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const +bool FilterModel::lessThan(const QModelIndex& left, const QModelIndex& right) const { ATLauncher::IndexedPack leftPack = sourceModel()->data(left, Qt::UserRole).value<ATLauncher::IndexedPack>(); ATLauncher::IndexedPack rightPack = sourceModel()->data(right, Qt::UserRole).value<ATLauncher::IndexedPack>(); if (currentSorting == ByPopularity) { return leftPack.position > rightPack.position; - } - else if (currentSorting == ByGameVersion) { + } else if (currentSorting == ByGameVersion) { Version lv(leftPack.versions.at(0).minecraft); Version rv(rightPack.versions.at(0).minecraft); return lv < rv; - } - else if (currentSorting == ByName) { + } else if (currentSorting == ByName) { return StringUtils::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0; } @@ -95,4 +93,4 @@ bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) co return true; } -} +} // namespace Atl diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.h b/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.h index 5235ccdb..0ab46ed2 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.h +++ b/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.h @@ -20,10 +20,9 @@ namespace Atl { -class FilterModel : public QSortFilterProxyModel -{ +class FilterModel : public QSortFilterProxyModel { Q_OBJECT -public: + public: FilterModel(QObject* parent = Q_NULLPTR); enum Sorting { ByPopularity, @@ -36,15 +35,14 @@ public: Sorting getCurrentSorting(); void setSearchTerm(QString term); -protected: - bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; - bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; + protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; + bool lessThan(const QModelIndex& left, const QModelIndex& right) const override; -private: + private: QMap<QString, Sorting> sortings; Sorting currentSorting; QString searchTerm; - }; -} +} // namespace Atl diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp index 267894bf..6fb86773 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp +++ b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -38,17 +38,15 @@ #include <QInputDialog> #include <QMessageBox> +#include "Application.h" #include "BuildConfig.h" #include "Json.h" #include "modplatform/atlauncher/ATLShareCode.h" -#include "Application.h" #include "net/ApiDownload.h" AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods) - : QAbstractListModel(parent) - , m_version(version) - , m_mods(mods) + : QAbstractListModel(parent), m_version(version), m_mods(mods) { // fill mod index for (int i = 0; i < m_mods.size(); i++) { @@ -64,7 +62,8 @@ AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent, ATLauncher::Pa } } -QVector<QString> AtlOptionalModListModel::getResult() { +QVector<QString> AtlOptionalModListModel::getResult() +{ QVector<QString> result; for (const auto& mod : m_mods) { @@ -76,16 +75,19 @@ QVector<QString> AtlOptionalModListModel::getResult() { return result; } -int AtlOptionalModListModel::rowCount(const QModelIndex &parent) const { +int AtlOptionalModListModel::rowCount(const QModelIndex& parent) const +{ return parent.isValid() ? 0 : m_mods.size(); } -int AtlOptionalModListModel::columnCount(const QModelIndex &parent) const { +int AtlOptionalModListModel::columnCount(const QModelIndex& parent) const +{ // Enabled, Name, Description return parent.isValid() ? 0 : 3; } -QVariant AtlOptionalModListModel::data(const QModelIndex &index, int role) const { +QVariant AtlOptionalModListModel::data(const QModelIndex& index, int role) const +{ auto row = index.row(); auto mod = m_mods.at(row); @@ -96,18 +98,15 @@ QVariant AtlOptionalModListModel::data(const QModelIndex &index, int role) const if (index.column() == DescriptionColumn) { return mod.description; } - } - else if (role == Qt::ToolTipRole) { + } else if (role == Qt::ToolTipRole) { if (index.column() == DescriptionColumn) { return mod.description; } - } - else if (role == Qt::ForegroundRole) { + } else if (role == Qt::ForegroundRole) { if (!mod.colour.isEmpty() && m_version.colours.contains(mod.colour)) { return QColor(QString("#%1").arg(m_version.colours[mod.colour])); } - } - else if (role == Qt::CheckStateRole) { + } else if (role == Qt::CheckStateRole) { if (index.column() == EnabledColumn) { return m_selection[mod.name] ? Qt::Checked : Qt::Unchecked; } @@ -116,7 +115,8 @@ 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(); auto mod = m_mods.at(row); @@ -128,7 +128,8 @@ bool AtlOptionalModListModel::setData(const QModelIndex &index, const QVariant & return false; } -QVariant AtlOptionalModListModel::headerData(int section, Qt::Orientation orientation, int role) const { +QVariant AtlOptionalModListModel::headerData(int section, Qt::Orientation orientation, int role) const +{ if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { switch (section) { case EnabledColumn: @@ -143,7 +144,8 @@ QVariant AtlOptionalModListModel::headerData(int section, Qt::Orientation orient return {}; } -Qt::ItemFlags AtlOptionalModListModel::flags(const QModelIndex &index) const { +Qt::ItemFlags AtlOptionalModListModel::flags(const QModelIndex& index) const +{ auto flags = QAbstractListModel::flags(index); if (index.isValid() && index.column() == EnabledColumn) { flags |= Qt::ItemIsUserCheckable; @@ -151,23 +153,23 @@ Qt::ItemFlags AtlOptionalModListModel::flags(const QModelIndex &index) const { return flags; } -void AtlOptionalModListModel::useShareCode(const QString& code) { +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::ApiDownload::makeByteArray(QUrl(url), m_response)); - connect(m_jobPtr.get(), &NetJob::succeeded, - this, &AtlOptionalModListModel::shareCodeSuccess); - connect(m_jobPtr.get(), &NetJob::failed, - this, &AtlOptionalModListModel::shareCodeFailure); + connect(m_jobPtr.get(), &NetJob::succeeded, this, &AtlOptionalModListModel::shareCodeSuccess); + connect(m_jobPtr.get(), &NetJob::failed, this, &AtlOptionalModListModel::shareCodeFailure); m_jobPtr->start(); } -void AtlOptionalModListModel::shareCodeSuccess() { +void AtlOptionalModListModel::shareCodeSuccess() +{ m_jobPtr.reset(); - QJsonParseError parse_error {}; + QJsonParseError parse_error{}; auto doc = QJsonDocument::fromJson(*m_response, &parse_error); if (parse_error.error != QJsonParseError::NoError) { qWarning() << "Error while parsing JSON response from ATL at " << parse_error.offset << " reason: " << parse_error.errorString(); @@ -179,8 +181,7 @@ void AtlOptionalModListModel::shareCodeSuccess() { ATLauncher::ShareCodeResponse response; try { ATLauncher::loadShareCodeResponse(response, obj); - } - catch (const JSONValidationError& e) { + } catch (const JSONValidationError& e) { qDebug() << QString::fromUtf8(*m_response); qWarning() << "Error while reading response from ATLauncher: " << e.cause(); return; @@ -204,44 +205,44 @@ void AtlOptionalModListModel::shareCodeSuccess() { m_selection[mod.name] = mod.selected; } - emit dataChanged(AtlOptionalModListModel::index(0, EnabledColumn), - AtlOptionalModListModel::index(m_mods.size() - 1, EnabledColumn)); + 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(); // fixme: plumb in an error message } -void AtlOptionalModListModel::selectRecommended() { +void AtlOptionalModListModel::selectRecommended() +{ for (const auto& mod : m_mods) { m_selection[mod.name] = mod.recommended; } - emit dataChanged(AtlOptionalModListModel::index(0, EnabledColumn), - AtlOptionalModListModel::index(m_mods.size() - 1, EnabledColumn)); + emit dataChanged(AtlOptionalModListModel::index(0, EnabledColumn), AtlOptionalModListModel::index(m_mods.size() - 1, EnabledColumn)); } -void AtlOptionalModListModel::clearAll() { +void AtlOptionalModListModel::clearAll() +{ for (const auto& mod : m_mods) { m_selection[mod.name] = false; } - emit dataChanged(AtlOptionalModListModel::index(0, EnabledColumn), - AtlOptionalModListModel::index(m_mods.size() - 1, EnabledColumn)); + emit dataChanged(AtlOptionalModListModel::index(0, EnabledColumn), AtlOptionalModListModel::index(m_mods.size() - 1, EnabledColumn)); } -void AtlOptionalModListModel::toggleMod(ATLauncher::VersionMod mod, int index) { +void AtlOptionalModListModel::toggleMod(ATLauncher::VersionMod mod, int index) +{ auto enable = !m_selection[mod.name]; // If there is a warning for the mod, display that first (if we would be enabling the mod) if (enable && !mod.warning.isEmpty() && m_version.warnings.contains(mod.warning)) { - auto message = QString("%1<br><br>%2") - .arg(m_version.warnings[mod.warning], tr("Are you sure that you want to enable this mod?")); + auto message = QString("%1<br><br>%2").arg(m_version.warnings[mod.warning], tr("Are you sure that you want to enable this mod?")); // fixme: avoid casting here - auto result = QMessageBox::warning((QWidget*) this->parent(), tr("Warning"), message, QMessageBox::Yes | QMessageBox::No); + auto result = QMessageBox::warning((QWidget*)this->parent(), tr("Warning"), message, QMessageBox::Yes | QMessageBox::No); if (result != QMessageBox::Yes) { return; } @@ -250,15 +251,18 @@ void AtlOptionalModListModel::toggleMod(ATLauncher::VersionMod mod, int index) { setMod(mod, index, enable); } -void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool enable, bool shouldEmit) { - if (m_selection[mod.name] == enable) return; +void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool enable, bool shouldEmit) +{ + if (m_selection[mod.name] == enable) + return; m_selection[mod.name] = enable; // disable other mods in the group, if applicable if (enable && !mod.group.isEmpty()) { for (int i = 0; i < m_mods.size(); i++) { - if (index == i) continue; + if (index == i) + continue; auto other = m_mods.at(i); if (mod.group == other.group) { @@ -279,16 +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); - } - else { - dependants.removeAll(mod.name); + dependents.append(mod.name); + } else { + 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); } } @@ -296,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); @@ -306,14 +309,12 @@ void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool } if (shouldEmit) { - emit dataChanged(AtlOptionalModListModel::index(index, EnabledColumn), - AtlOptionalModListModel::index(index, EnabledColumn)); + emit dataChanged(AtlOptionalModListModel::index(index, EnabledColumn), AtlOptionalModListModel::index(index, EnabledColumn)); } } AtlOptionalModDialog::AtlOptionalModDialog(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods) - : QDialog(parent) - , ui(new Ui::AtlOptionalModDialog) + : QDialog(parent), ui(new Ui::AtlOptionalModDialog) { ui->setupUi(this); @@ -321,35 +322,24 @@ AtlOptionalModDialog::AtlOptionalModDialog(QWidget* parent, ATLauncher::PackVers ui->treeView->setModel(listModel); ui->treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - ui->treeView->header()->setSectionResizeMode( - AtlOptionalModListModel::NameColumn, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode( - AtlOptionalModListModel::DescriptionColumn, QHeaderView::Stretch); - - connect(ui->shareCodeButton, &QPushButton::clicked, - this, &AtlOptionalModDialog::useShareCode); - connect(ui->selectRecommendedButton, &QPushButton::clicked, - listModel, &AtlOptionalModListModel::selectRecommended); - connect(ui->clearAllButton, &QPushButton::clicked, - listModel, &AtlOptionalModListModel::clearAll); - connect(ui->installButton, &QPushButton::clicked, - this, &QDialog::accept); + ui->treeView->header()->setSectionResizeMode(AtlOptionalModListModel::NameColumn, QHeaderView::ResizeToContents); + ui->treeView->header()->setSectionResizeMode(AtlOptionalModListModel::DescriptionColumn, QHeaderView::Stretch); + + connect(ui->shareCodeButton, &QPushButton::clicked, this, &AtlOptionalModDialog::useShareCode); + connect(ui->selectRecommendedButton, &QPushButton::clicked, listModel, &AtlOptionalModListModel::selectRecommended); + connect(ui->clearAllButton, &QPushButton::clicked, listModel, &AtlOptionalModListModel::clearAll); + connect(ui->installButton, &QPushButton::clicked, this, &QDialog::accept); } -AtlOptionalModDialog::~AtlOptionalModDialog() { +AtlOptionalModDialog::~AtlOptionalModDialog() +{ delete ui; } -void AtlOptionalModDialog::useShareCode() { +void AtlOptionalModDialog::useShareCode() +{ bool ok; - auto shareCode = QInputDialog::getText( - this, - tr("Select a share code"), - tr("Share code:"), - QLineEdit::Normal, - "", - &ok - ); + auto shareCode = QInputDialog::getText(this, tr("Select a share code"), tr("Share code:"), QLineEdit::Normal, "", &ok); if (!ok) { // If the user cancels the dialog, we don't need to show any error dialogs. diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h index 639f0d48..55903003 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h +++ b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -35,8 +35,8 @@ #pragma once -#include <QDialog> #include <QAbstractListModel> +#include <QDialog> #include "modplatform/atlauncher/ATLPackIndex.h" #include "net/NetJob.h" @@ -48,37 +48,36 @@ class AtlOptionalModDialog; class AtlOptionalModListModel : public QAbstractListModel { Q_OBJECT -public: - enum Columns - { + public: + enum Columns { EnabledColumn = 0, NameColumn, DescriptionColumn, }; - AtlOptionalModListModel(QWidget *parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods); + AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods); QVector<QString> getResult(); - int rowCount(const QModelIndex &parent) const override; - int columnCount(const QModelIndex &parent) const override; + int rowCount(const QModelIndex& parent) const override; + int columnCount(const QModelIndex& parent) const override; - QVariant data(const QModelIndex &index, int role) const override; - bool setData(const QModelIndex &index, const QVariant &value, int role) override; + QVariant data(const QModelIndex& index, int role) const override; + bool setData(const QModelIndex& index, const QVariant& value, int role) override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - Qt::ItemFlags flags(const QModelIndex &index) const override; + Qt::ItemFlags flags(const QModelIndex& index) const override; void useShareCode(const QString& code); -public slots: + public slots: void shareCodeSuccess(); void shareCodeFailure(const QString& reason); void selectRecommended(); void clearAll(); -private: + private: void toggleMod(ATLauncher::VersionMod mod, int index); void setMod(ATLauncher::VersionMod mod, int index, bool enable, bool shouldEmit = true); @@ -91,24 +90,22 @@ private: 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 { Q_OBJECT -public: - AtlOptionalModDialog(QWidget *parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods); + public: + AtlOptionalModDialog(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods); ~AtlOptionalModDialog() override; - QVector<QString> getResult() { - return listModel->getResult(); - } + QVector<QString> getResult() { return listModel->getResult(); } void useShareCode(); -private: - Ui::AtlOptionalModDialog *ui; + private: + Ui::AtlOptionalModDialog* ui; - AtlOptionalModListModel *listModel; + AtlOptionalModListModel* listModel; }; diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp index 87544445..5e3b9ecf 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp +++ b/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -46,10 +46,7 @@ #include <QMessageBox> -AtlPage::AtlPage(NewInstanceDialog* dialog, QWidget* parent) - : QWidget(parent) - , ui(new Ui::AtlPage) - , dialog(dialog) +AtlPage::AtlPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::AtlPage), dialog(dialog) { ui->setupUi(this); @@ -65,8 +62,7 @@ AtlPage::AtlPage(NewInstanceDialog* dialog, QWidget* parent) ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300); - for(int i = 0; i < filterModel->getAvailableSortings().size(); i++) - { + for (int i = 0; i < filterModel->getAvailableSortings().size(); i++) { ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i)); } ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting()); @@ -94,8 +90,7 @@ void AtlPage::retranslate() void AtlPage::openedImpl() { - if(!initialized) - { + if (!initialized) { listModel->request(); initialized = true; } @@ -105,13 +100,11 @@ void AtlPage::openedImpl() void AtlPage::suggestCurrent() { - if(!isOpened) - { + if (!isOpened) { return; } - if (selectedVersion.isEmpty()) - { + if (selectedVersion.isEmpty()) { dialog->setSuggestedPack(); return; } @@ -121,10 +114,8 @@ void AtlPage::suggestCurrent() auto editedLogoName = selected.safeName; auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/images/%1.png").arg(selected.safeName.toLower()); - listModel->getLogo(selected.safeName, url, [this, editedLogoName](QString logo) - { - dialog->setSuggestedIconFromFile(logo, editedLogoName); - }); + listModel->getLogo(selected.safeName, url, + [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); }); } void AtlPage::triggerSearch() @@ -132,20 +123,18 @@ 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(); - if(!first.isValid()) - { - if(isOpened) - { + if (!first.isValid()) { + if (isOpened) { dialog->setSuggestedPack(); } return; @@ -155,21 +144,20 @@ void AtlPage::onSelectionChanged(QModelIndex first, QModelIndex second) ui->packDescription->setHtml(selected.description.replace("\n", "<br>")); - for(const auto& version : selected.versions) { + for (const auto& version : selected.versions) { ui->versionSelectionBox->addItem(version.version); } 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(); } diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlPage.h b/launcher/ui/pages/modplatform/atlauncher/AtlPage.h index 1b3b15c1..6bc44964 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlPage.h +++ b/launcher/ui/pages/modplatform/atlauncher/AtlPage.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -38,52 +38,38 @@ #include "AtlFilterModel.h" #include "AtlListModel.h" -#include <QWidget> #include <modplatform/atlauncher/ATLPackInstallTask.h> +#include <QWidget> #include "Application.h" -#include "ui/pages/BasePage.h" #include "tasks/Task.h" +#include "ui/pages/BasePage.h" -namespace Ui -{ - class AtlPage; +namespace Ui { +class AtlPage; } class NewInstanceDialog; -class AtlPage : public QWidget, public BasePage -{ -Q_OBJECT +class AtlPage : public QWidget, public BasePage { + Q_OBJECT -public: - explicit AtlPage(NewInstanceDialog* dialog, QWidget *parent = 0); + public: + explicit AtlPage(NewInstanceDialog* dialog, QWidget* parent = 0); virtual ~AtlPage(); - virtual QString displayName() const override - { - return "ATLauncher"; - } - virtual QIcon icon() const override - { - return APPLICATION->getThemedIcon("atlauncher"); - } - virtual QString id() const override - { - return "atl"; - } - virtual QString helpPage() const override - { - return "ATL-platform"; - } + virtual QString displayName() const override { return "ATLauncher"; } + virtual QIcon icon() const override { return APPLICATION->getThemedIcon("atlauncher"); } + virtual QString id() const override { return "atl"; } + virtual QString helpPage() const override { return "ATL-platform"; } virtual bool shouldDisplay() const override; void retranslate() override; void openedImpl() override; -private: + private: void suggestCurrent(); -private slots: + private slots: void triggerSearch(); void onSortingSelectionChanged(QString data); @@ -91,8 +77,8 @@ private slots: void onSelectionChanged(QModelIndex first, QModelIndex second); void onVersionSelectionChanged(QString data); -private: - Ui::AtlPage *ui = nullptr; + private: + Ui::AtlPage* ui = nullptr; NewInstanceDialog* dialog = nullptr; Atl::ListModel* listModel = nullptr; Atl::FilterModel* filterModel = nullptr; diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.cpp index 3d2d568a..0c725785 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.cpp +++ b/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -33,17 +33,16 @@ * limitations under the License. */ -#include <QMessageBox> #include "AtlUserInteractionSupportImpl.h" +#include <QMessageBox> #include "AtlOptionalModDialog.h" #include "ui/dialogs/VersionSelectDialog.h" -AtlUserInteractionSupportImpl::AtlUserInteractionSupportImpl(QWidget *parent) : m_parent(parent) -{ -} +AtlUserInteractionSupportImpl::AtlUserInteractionSupportImpl(QWidget* parent) : m_parent(parent) {} -std::optional<QVector<QString>> AtlUserInteractionSupportImpl::chooseOptionalMods(ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods) +std::optional<QVector<QString>> AtlUserInteractionSupportImpl::chooseOptionalMods(ATLauncher::PackVersion version, + QVector<ATLauncher::VersionMod> mods) { AtlOptionalModDialog optionalModDialog(m_parent, version, mods); auto result = optionalModDialog.exec(); @@ -59,8 +58,7 @@ QString AtlUserInteractionSupportImpl::chooseVersion(Meta::VersionList::Ptr vlis if (minecraftVersion != nullptr) { vselect.setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion); vselect.setEmptyString(tr("No versions are currently available for Minecraft %1").arg(minecraftVersion)); - } - else { + } else { vselect.setEmptyString(tr("No versions are currently available")); } vselect.setEmptyErrorString(tr("Couldn't load or download the version lists!")); @@ -72,9 +70,7 @@ QString AtlUserInteractionSupportImpl::chooseVersion(Meta::VersionList::Ptr vlis // filter by minecraft version, if the loader depends on a certain version. if (minecraftVersion != nullptr) { - auto iter = std::find_if(reqs.begin(), reqs.end(), [](const Meta::Require& req) { - return req.uid == "net.minecraft"; - }); + auto iter = std::find_if(reqs.begin(), reqs.end(), [](const Meta::Require& req) { return req.uid == "net.minecraft"; }); if (iter == reqs.end()) continue; if (iter->equalsVersion != minecraftVersion) diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.h b/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.h index adeb53cb..52ced261 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.h +++ b/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify diff --git a/launcher/ui/pages/modplatform/flame/FlameModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModel.cpp index e32024c4..ff21d010 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModel.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModel.cpp @@ -72,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()) @@ -143,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; } diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.cpp b/launcher/ui/pages/modplatform/flame/FlamePage.cpp index ada67644..183e16f9 100644 --- a/launcher/ui/pages/modplatform/flame/FlamePage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlamePage.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -116,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(); @@ -134,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::ApiDownload::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) { @@ -214,12 +215,12 @@ void FlamePage::suggestCurrent() [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; } diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.h b/launcher/ui/pages/modplatform/flame/FlamePage.h index 8bdca38e..ff5c7975 100644 --- a/launcher/ui/pages/modplatform/flame/FlamePage.h +++ b/launcher/ui/pages/modplatform/flame/FlamePage.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -37,45 +37,31 @@ #include <QWidget> -#include "ui/pages/BasePage.h" #include <Application.h> -#include "tasks/Task.h" #include <modplatform/flame/FlamePackIndex.h> +#include "tasks/Task.h" +#include "ui/pages/BasePage.h" -namespace Ui -{ +namespace Ui { class FlamePage; } class NewInstanceDialog; namespace Flame { - class ListModel; +class ListModel; } -class FlamePage : public QWidget, public BasePage -{ +class FlamePage : public QWidget, public BasePage { Q_OBJECT -public: - explicit FlamePage(NewInstanceDialog* dialog, QWidget *parent = 0); + public: + explicit FlamePage(NewInstanceDialog* dialog, QWidget* parent = 0); virtual ~FlamePage(); - virtual QString displayName() const override - { - return "CurseForge"; - } - virtual QIcon icon() const override - { - return APPLICATION->getThemedIcon("flame"); - } - virtual QString id() const override - { - return "flame"; - } - virtual QString helpPage() const override - { - return "Flame-platform"; - } + virtual QString displayName() const override { return "CurseForge"; } + virtual QIcon icon() const override { return APPLICATION->getThemedIcon("flame"); } + virtual QString id() const override { return "flame"; } + virtual QString helpPage() const override { return "Flame-platform"; } virtual bool shouldDisplay() const override; void retranslate() override; @@ -83,18 +69,18 @@ public: void openedImpl() override; - bool eventFilter(QObject * watched, QEvent * event) override; + bool eventFilter(QObject* watched, QEvent* event) override; -private: + private: void suggestCurrent(); -private slots: + private slots: void triggerSearch(); void onSelectionChanged(QModelIndex first, QModelIndex second); void onVersionSelectionChanged(QString data); -private: - Ui::FlamePage *ui = nullptr; + private: + Ui::FlamePage* ui = nullptr; NewInstanceDialog* dialog = nullptr; Flame::ListModel* listModel = nullptr; Flame::IndexedPack current; diff --git a/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp b/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp index 0fb67c50..2b020c48 100644 --- a/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp @@ -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 { diff --git a/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp b/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp index f93e27e6..dc17e705 100644 --- a/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp @@ -49,8 +49,7 @@ static bool isOptedOut(ModPlatform::IndexedVersion const& ver) return ver.downloadUrl.isEmpty(); } -FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance) - : ModPage(dialog, instance) +FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ModPage(dialog, instance) { m_model = new FlameModModel(instance); m_ui->packView->setModel(m_model); @@ -67,7 +66,9 @@ FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance) m_ui->packDescription->setMetaEntry(metaEntryBase()); } -auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders) const -> bool +auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, + QString mineVer, + std::optional<ResourceAPI::ModLoaderTypes> loaders) const -> bool { Q_UNUSED(loaders); return ver.mcVersion.contains(mineVer) && !ver.downloadUrl.isEmpty(); @@ -86,7 +87,7 @@ void FlameModPage::openUrl(const QUrl& url) if (query.startsWith("remoteUrl=")) { // attempt to resolve url from warning page query.remove(0, 10); - ModPage::openUrl({QUrl::fromPercentEncoding(query.toUtf8())}); // double decoding is necessary + ModPage::openUrl({ QUrl::fromPercentEncoding(query.toUtf8()) }); // double decoding is necessary return; } } @@ -125,7 +126,7 @@ void FlameResourcePackPage::openUrl(const QUrl& url) if (query.startsWith("remoteUrl=")) { // attempt to resolve url from warning page query.remove(0, 10); - ResourcePackResourcePage::openUrl({QUrl::fromPercentEncoding(query.toUtf8())}); // double decoding is necessary + ResourcePackResourcePage::openUrl({ QUrl::fromPercentEncoding(query.toUtf8()) }); // double decoding is necessary return; } } @@ -164,7 +165,7 @@ void FlameTexturePackPage::openUrl(const QUrl& url) if (query.startsWith("remoteUrl=")) { // attempt to resolve url from warning page query.remove(0, 10); - ResourcePackResourcePage::openUrl({QUrl::fromPercentEncoding(query.toUtf8())}); // double decoding is necessary + ResourcePackResourcePage::openUrl({ QUrl::fromPercentEncoding(query.toUtf8()) }); // double decoding is necessary return; } } @@ -175,8 +176,17 @@ void FlameTexturePackPage::openUrl(const QUrl& url) // I don't know why, but doing this on the parent class makes it so that // other mod providers start loading before being selected, at least with // my Qt, so we need to implement this in every derived class... -auto FlameModPage::shouldDisplay() const -> bool { return true; } -auto FlameResourcePackPage::shouldDisplay() const -> bool { return true; } -auto FlameTexturePackPage::shouldDisplay() const -> bool { return true; } +auto FlameModPage::shouldDisplay() const -> bool +{ + return true; +} +auto FlameResourcePackPage::shouldDisplay() const -> bool +{ + return true; +} +auto FlameTexturePackPage::shouldDisplay() const -> bool +{ + return true; +} } // namespace ResourceDownload diff --git a/launcher/ui/pages/modplatform/flame/FlameResourcePages.h b/launcher/ui/pages/modplatform/flame/FlameResourcePages.h index 103a6bb9..c6ebc1ea 100644 --- a/launcher/ui/pages/modplatform/flame/FlameResourcePages.h +++ b/launcher/ui/pages/modplatform/flame/FlameResourcePages.h @@ -49,12 +49,27 @@ namespace ResourceDownload { namespace Flame { -static inline QString displayName() { return "CurseForge"; } -static inline QIcon icon() { return APPLICATION->getThemedIcon("flame"); } -static inline QString id() { return "curseforge"; } -static inline QString debugName() { return "Flame"; } -static inline QString metaEntryBase() { return "FlameMods"; } +static inline QString displayName() +{ + return "CurseForge"; } +static inline QIcon icon() +{ + return APPLICATION->getThemedIcon("flame"); +} +static inline QString id() +{ + return "curseforge"; +} +static inline QString debugName() +{ + return "Flame"; +} +static inline QString metaEntryBase() +{ + return "FlameMods"; +} +} // namespace Flame class FlameModPage : public ModPage { Q_OBJECT @@ -78,7 +93,9 @@ class FlameModPage : public ModPage { [[nodiscard]] inline auto helpPage() const -> QString override { return "Mod-platform"; } - bool validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const override; + bool validateVersion(ModPlatform::IndexedVersion& ver, + QString mineVer, + std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const override; bool optedOut(ModPlatform::IndexedVersion& ver) const override; void openUrl(const QUrl& url) override; diff --git a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp index a42d4dad..356d919d 100644 --- a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp +++ b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * * This program is free software: you can redistribute it and/or modify @@ -35,9 +35,9 @@ #include "ListModel.h" #include "Application.h" +#include "net/ApiDownload.h" #include "net/HttpMetaCache.h" #include "net/NetJob.h" -#include "net/ApiDownload.h" #include <Version.h> #include "StringUtils.h" @@ -77,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; } @@ -174,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(); } diff --git a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.h b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.h index c55df000..51a58d99 100644 --- a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.h +++ b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.h @@ -1,13 +1,13 @@ #pragma once -#include <modplatform/legacy_ftb/PackHelpers.h> #include <RWStorage.h> +#include <modplatform/legacy_ftb/PackHelpers.h> #include <QAbstractListModel> -#include <QSortFilterProxyModel> -#include <QThreadPool> #include <QIcon> +#include <QSortFilterProxyModel> #include <QStyledItemDelegate> +#include <QThreadPool> #include <functional> @@ -16,34 +16,28 @@ namespace LegacyFTB { typedef QMap<QString, QIcon> FTBLogoMap; typedef std::function<void(QString)> LogoCallback; -class FilterModel : public QSortFilterProxyModel -{ +class FilterModel : public QSortFilterProxyModel { Q_OBJECT -public: + public: FilterModel(QObject* parent = Q_NULLPTR); - enum Sorting { - ByName, - ByGameVersion - }; + enum Sorting { ByName, ByGameVersion }; const QMap<QString, Sorting> getAvailableSortings(); QString translateCurrentSorting(); void setSorting(Sorting sorting); Sorting getCurrentSorting(); -protected: - bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; - bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; + protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; + bool lessThan(const QModelIndex& left, const QModelIndex& right) const override; -private: + private: QMap<QString, Sorting> sortings; Sorting currentSorting; - }; -class ListModel : public QAbstractListModel -{ +class ListModel : public QAbstractListModel { Q_OBJECT -private: + private: ModpackList modpacks; QStringList m_failedLogos; QStringList m_loadingLogos; @@ -53,18 +47,17 @@ private: void requestLogo(QString file); QString translatePackType(PackType type) const; - -private slots: + private slots: void logoFailed(QString logo); void logoLoaded(QString logo, QIcon out); -public: - ListModel(QObject *parent); + public: + ListModel(QObject* parent); ~ListModel(); - int rowCount(const QModelIndex &parent) const override; - int columnCount(const QModelIndex &parent) const override; - QVariant data(const QModelIndex &index, int role) const override; - Qt::ItemFlags flags(const QModelIndex &index) const override; + int rowCount(const QModelIndex& parent) const override; + int columnCount(const QModelIndex& parent) const override; + QVariant data(const QModelIndex& index, int role) const override; + Qt::ItemFlags flags(const QModelIndex& index) const override; void fill(ModpackList modpacks); void addPack(Modpack modpack); @@ -72,7 +65,7 @@ public: void remove(int row); Modpack at(int row); - void getLogo(const QString &logo, LogoCallback callback); + void getLogo(const QString& logo, LogoCallback callback); }; -} +} // namespace LegacyFTB diff --git a/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp b/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp index b3f6261f..0103bbaa 100644 --- a/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp +++ b/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * @@ -44,15 +44,14 @@ #include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/NewInstanceDialog.h" +#include "ListModel.h" #include "modplatform/legacy_ftb/PackFetchTask.h" #include "modplatform/legacy_ftb/PackInstallTask.h" #include "modplatform/legacy_ftb/PrivatePackManager.h" -#include "ListModel.h" namespace LegacyFTB { -Page::Page(NewInstanceDialog* dialog, QWidget *parent) - : QWidget(parent), dialog(dialog), ui(new Ui::Page) +Page::Page(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), dialog(dialog), ui(new Ui::Page) { ftbFetchTask.reset(new PackFetchTask(APPLICATION->network())); ftbPrivatePacks.reset(new PrivatePackManager()); @@ -70,8 +69,7 @@ Page::Page(NewInstanceDialog* dialog, QWidget *parent) ui->publicPackList->setIndentation(0); ui->publicPackList->setIconSize(QSize(42, 42)); - for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++) - { + for (int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++) { ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i)); } @@ -142,8 +140,7 @@ bool Page::shouldDisplay() const void Page::openedImpl() { - if(!initialized) - { + if (!initialized) { connect(ftbFetchTask.get(), &PackFetchTask::finished, this, &Page::ftbPackDataDownloadSuccessfully); connect(ftbFetchTask.get(), &PackFetchTask::failed, this, &Page::ftbPackDataDownloadFailed); connect(ftbFetchTask.get(), &PackFetchTask::aborted, this, &Page::ftbPackDataDownloadAborted); @@ -166,50 +163,34 @@ void Page::retranslate() void Page::suggestCurrent() { - if(!isOpened) - { + if (!isOpened) { return; } - if(selected.broken || selectedVersion.isEmpty()) - { + if (selected.broken || selectedVersion.isEmpty()) { dialog->setSuggestedPack(); return; } dialog->setSuggestedPack(selected.name, selectedVersion, new PackInstallTask(APPLICATION->network(), selected, selectedVersion)); QString editedLogoName; - if(selected.logo.toLower().startsWith("ftb")) - { + if (selected.logo.toLower().startsWith("ftb")) { editedLogoName = selected.logo; - } - else - { + } else { editedLogoName = "ftb_" + selected.logo; } editedLogoName = editedLogoName.left(editedLogoName.lastIndexOf(".png")); - if(selected.type == PackType::Public) - { - publicListModel->getLogo(selected.logo, [this, editedLogoName](QString logo) - { - dialog->setSuggestedIconFromFile(logo, editedLogoName); - }); - } - else if (selected.type == PackType::ThirdParty) - { - thirdPartyModel->getLogo(selected.logo, [this, editedLogoName](QString logo) - { - dialog->setSuggestedIconFromFile(logo, editedLogoName); - }); - } - else if (selected.type == PackType::Private) - { - privateListModel->getLogo(selected.logo, [this, editedLogoName](QString logo) - { - dialog->setSuggestedIconFromFile(logo, editedLogoName); - }); + if (selected.type == PackType::Public) { + publicListModel->getLogo(selected.logo, + [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); }); + } else if (selected.type == PackType::ThirdParty) { + thirdPartyModel->getLogo(selected.logo, + [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); }); + } else if (selected.type == PackType::Private) { + privateListModel->getLogo(selected.logo, + [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); }); } } @@ -234,23 +215,18 @@ 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) - ); - if(reply == QMessageBox::Yes) - { + 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)); + if (reply == QMessageBox::Yes) { ftbPrivatePacks->remove(packCode); } } -void Page::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev) +void Page::onPublicPackSelectionChanged(QModelIndex now, [[maybe_unused]] QModelIndex prev) { - if(!now.isValid()) - { + if (!now.isValid()) { onPackSelectionChanged(); return; } @@ -258,10 +234,9 @@ 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()) - { + if (!now.isValid()) { onPackSelectionChanged(); return; } @@ -269,10 +244,9 @@ 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()) - { + if (!now.isValid()) { onPackSelectionChanged(); return; } @@ -283,34 +257,26 @@ void Page::onPrivatePackSelectionChanged(QModelIndex now, QModelIndex prev) void Page::onPackSelectionChanged(Modpack* pack) { ui->versionSelectionBox->clear(); - if(pack) - { - currentModpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" + - "<br>Minecraft " + pack->mcVersion + "<br>" + "<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>") - + "</li></ul>"); + if (pack) { + currentModpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" + "<br>Minecraft " + pack->mcVersion + "<br>" + "<br>" + + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>") + "</li></ul>"); bool currentAdded = false; - for(int i = 0; i < pack->oldVersions.size(); i++) - { - if(pack->currentVersion == pack->oldVersions.at(i)) - { + for (int i = 0; i < pack->oldVersions.size(); i++) { + if (pack->currentVersion == pack->oldVersions.at(i)) { currentAdded = true; } ui->versionSelectionBox->addItem(pack->oldVersions.at(i)); } - if(!currentAdded) - { + if (!currentAdded) { ui->versionSelectionBox->addItem(pack->currentVersion); } selected = *pack; - } - else - { + } else { currentModpackInfo->setHtml(""); ui->versionSelectionBox->clear(); - if(isOpened) - { + if (isOpened) { dialog->setSuggestedPack(); } return; @@ -318,21 +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); @@ -340,20 +305,15 @@ void Page::onSortingSelectionChanged(QString data) void Page::onTabChanged(int tab) { - if(tab == 1) - { + if (tab == 1) { currentModel = thirdPartyFilterModel; currentList = ui->thirdPartyPackList; currentModpackInfo = ui->thirdPartyPackDescription; - } - else if(tab == 2) - { + } else if (tab == 2) { currentModel = privateFilterModel; currentList = ui->privatePackList; currentModpackInfo = ui->privatePackDescription; - } - else - { + } else { currentModel = publicFilterModel; currentList = ui->publicPackList; currentModpackInfo = ui->publicPackDescription; @@ -361,13 +321,10 @@ void Page::onTabChanged(int tab) currentList->selectionModel()->reset(); QModelIndex idx = currentList->currentIndex(); - if(idx.isValid()) - { + if (idx.isValid()) { auto pack = currentModel->data(idx, Qt::UserRole).value<Modpack>(); onPackSelectionChanged(&pack); - } - else - { + } else { onPackSelectionChanged(); } } @@ -375,38 +332,24 @@ void Page::onTabChanged(int tab) void Page::onAddPackClicked() { bool ok; - QString text = QInputDialog::getText( - this, - tr("Add FTB pack"), - tr("Enter pack code:"), - QLineEdit::Normal, - QString(), - &ok - ); - if(ok && !text.isEmpty()) - { + QString text = QInputDialog::getText(this, tr("Add FTB pack"), tr("Enter pack code:"), QLineEdit::Normal, QString(), &ok); + if (ok && !text.isEmpty()) { ftbPrivatePacks->add(text); - ftbFetchTask->fetchPrivate({text}); + ftbFetchTask->fetchPrivate({ text }); } } void Page::onRemovePackClicked() { auto index = ui->privatePackList->currentIndex(); - if(!index.isValid()) - { + if (!index.isValid()) { return; } auto row = index.row(); Modpack pack = privateListModel->at(row); - auto answer = QMessageBox::question( - this, - tr("Remove pack"), - tr("Are you sure you want to remove pack %1?").arg(pack.name), - QMessageBox::Yes | QMessageBox::No - ); - if(answer != QMessageBox::Yes) - { + auto answer = QMessageBox::question(this, tr("Remove pack"), tr("Are you sure you want to remove pack %1?").arg(pack.name), + QMessageBox::Yes | QMessageBox::No); + if (answer != QMessageBox::Yes) { return; } @@ -415,4 +358,4 @@ void Page::onRemovePackClicked() onPackSelectionChanged(); } -} +} // namespace LegacyFTB diff --git a/launcher/ui/pages/modplatform/legacy_ftb/Page.h b/launcher/ui/pages/modplatform/legacy_ftb/Page.h index 1de8b40a..a12b0745 100644 --- a/launcher/ui/pages/modplatform/legacy_ftb/Page.h +++ b/launcher/ui/pages/modplatform/legacy_ftb/Page.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -35,23 +35,22 @@ #pragma once -#include <QWidget> -#include <QTreeView> #include <QTextBrowser> +#include <QTreeView> +#include <QWidget> -#include "ui/pages/BasePage.h" #include <Application.h> -#include "tasks/Task.h" -#include "modplatform/legacy_ftb/PackHelpers.h" -#include "modplatform/legacy_ftb/PackFetchTask.h" #include "QObjectPtr.h" +#include "modplatform/legacy_ftb/PackFetchTask.h" +#include "modplatform/legacy_ftb/PackHelpers.h" +#include "tasks/Task.h" +#include "ui/pages/BasePage.h" class NewInstanceDialog; namespace LegacyFTB { -namespace Ui -{ +namespace Ui { class Page; } @@ -61,38 +60,25 @@ class PrivatePackListModel; class PrivatePackFilterModel; class PrivatePackManager; -class Page : public QWidget, public BasePage -{ +class Page : public QWidget, public BasePage { Q_OBJECT -public: - explicit Page(NewInstanceDialog * dialog, QWidget *parent = 0); + public: + explicit Page(NewInstanceDialog* dialog, QWidget* parent = 0); virtual ~Page(); - QString displayName() const override - { - return "FTB Legacy"; - } - QIcon icon() const override - { - return APPLICATION->getThemedIcon("ftb_logo"); - } - QString id() const override - { - return "legacy_ftb"; - } - QString helpPage() const override - { - return "FTB-platform"; - } + QString displayName() const override { return "FTB Legacy"; } + QIcon icon() const override { return APPLICATION->getThemedIcon("ftb_logo"); } + QString id() const override { return "legacy_ftb"; } + QString helpPage() const override { return "FTB-platform"; } bool shouldDisplay() const override; void openedImpl() override; void retranslate() override; -private: + private: void suggestCurrent(); - void onPackSelectionChanged(Modpack *pack = nullptr); + void onPackSelectionChanged(Modpack* pack = nullptr); -private slots: + private slots: void ftbPackDataDownloadSuccessfully(ModpackList publicPacks, ModpackList thirdPartyPacks); void ftbPackDataDownloadFailed(QString reason); void ftbPackDataDownloadAborted(); @@ -112,7 +98,7 @@ private slots: void onAddPackClicked(); void onRemovePackClicked(); -private: + private: FilterModel* currentModel = nullptr; QTreeView* currentList = nullptr; QTextBrowser* currentModpackInfo = nullptr; @@ -124,18 +110,18 @@ private: ListModel* publicListModel = nullptr; FilterModel* publicFilterModel = nullptr; - ListModel *thirdPartyModel = nullptr; - FilterModel *thirdPartyFilterModel = nullptr; + ListModel* thirdPartyModel = nullptr; + FilterModel* thirdPartyFilterModel = nullptr; - ListModel *privateListModel = nullptr; - FilterModel *privateFilterModel = nullptr; + ListModel* privateListModel = nullptr; + FilterModel* privateFilterModel = nullptr; unique_qobject_ptr<PackFetchTask> ftbFetchTask; std::unique_ptr<PrivatePackManager> ftbPrivatePacks; NewInstanceDialog* dialog = nullptr; - Ui::Page *ui = nullptr; + Ui::Page* ui = nullptr; }; -} +} // namespace LegacyFTB diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index ee498743..ebc5556c 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln <flowlnlnln@gmail.com> * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * @@ -117,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()) @@ -183,26 +183,24 @@ void ModpackListModel::refresh() static auto sortFromIndex(int index) -> QString { - switch(index){ - default: - case 0: - return "relevance"; - case 1: - return "downloads"; - case 2: - return "follows"; - case 3: - return "newest"; - case 4: - return "updated"; + switch (index) { + default: + case 0: + return "relevance"; + case 1: + return "downloads"; + case 2: + return "follows"; + case 3: + return "newest"; + case 4: + return "updated"; } - - return {}; } void ModpackListModel::searchWithTerm(const QString& term, const int sort) { - if(sort > 5 || sort < 0) + if (sort > 5 || sort < 0) return; auto sort_str = sortFromIndex(sort); diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h index b9e9c3da..721c69f5 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln <flowlnlnln@gmail.com> * * This program is free software: you can redistribute it and/or modify @@ -47,7 +47,7 @@ class Version; namespace Modrinth { using LogoMap = QMap<QString, QIcon>; -using LogoCallback = std::function<void (QString)>; +using LogoCallback = std::function<void(QString)>; class ModpackListModel : public QAbstractListModel { Q_OBJECT @@ -64,7 +64,7 @@ class ModpackListModel : public QAbstractListModel { /* Retrieve information from the model at a given index with the given role */ auto data(const QModelIndex& index, int role) const -> QVariant override; - bool setData(const QModelIndex &index, const QVariant &value, int role) override; + bool setData(const QModelIndex& index, const QVariant& value, int role) override; inline void setActiveJob(NetJob::Ptr ptr) { jobPtr = ptr; } @@ -75,7 +75,10 @@ class ModpackListModel : public QAbstractListModel { void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback); - inline auto canFetchMore(const QModelIndex& parent) const -> bool override { return parent.isValid() ? false : searchState == CanPossiblyFetchMore; }; + inline auto canFetchMore(const QModelIndex& parent) const -> bool override + { + return parent.isValid() ? false : searchState == CanPossiblyFetchMore; + }; public slots: void searchRequestFinished(QJsonDocument& doc_all); diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index e7d75dcf..41fd5003 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln <flowlnlnln@gmail.com> * * This program is free software: you can redistribute it and/or modify @@ -107,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(); @@ -311,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; } diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index db5e1a3d..b7054c88 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln <flowlnlnln@gmail.com> * * This program is free software: you can redistribute it and/or modify diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp index 8aa64989..ce7475b6 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * * This program is free software: you can redistribute it and/or modify @@ -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 { diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.h b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.h index d7c858f8..15cd5854 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.h @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * * This program is free software: you can redistribute it and/or modify diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp index dd143700..616c1a81 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * * This program is free software: you can redistribute it and/or modify @@ -46,8 +46,7 @@ namespace ResourceDownload { -ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instance) - : ModPage(dialog, instance) +ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ModPage(dialog, instance) { m_model = new ModrinthModModel(instance); m_ui->packView->setModel(m_model); @@ -64,14 +63,15 @@ ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instan m_ui->packDescription->setMetaEntry(metaEntryBase()); } -auto ModrinthModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders) const -> bool +auto ModrinthModPage::validateVersion(ModPlatform::IndexedVersion& ver, + QString mineVer, + std::optional<ResourceAPI::ModLoaderTypes> loaders) const -> bool { auto loaderCompatible = !loaders.has_value(); if (!loaderCompatible) { auto loaderStrings = ModrinthAPI::getModLoaderStrings(loaders.value()); - for (auto remoteLoader : ver.loaders) - { + for (auto remoteLoader : ver.loaders) { if (loaderStrings.contains(remoteLoader)) { loaderCompatible = true; break; @@ -139,9 +139,21 @@ ModrinthShaderPackPage::ModrinthShaderPackPage(ShaderPackDownloadDialog* dialog, // I don't know why, but doing this on the parent class makes it so that // other mod providers start loading before being selected, at least with // my Qt, so we need to implement this in every derived class... -auto ModrinthModPage::shouldDisplay() const -> bool { return true; } -auto ModrinthResourcePackPage::shouldDisplay() const -> bool { return true; } -auto ModrinthTexturePackPage::shouldDisplay() const -> bool { return true; } -auto ModrinthShaderPackPage::shouldDisplay() const -> bool { return true; } +auto ModrinthModPage::shouldDisplay() const -> bool +{ + return true; +} +auto ModrinthResourcePackPage::shouldDisplay() const -> bool +{ + return true; +} +auto ModrinthTexturePackPage::shouldDisplay() const -> bool +{ + return true; +} +auto ModrinthShaderPackPage::shouldDisplay() const -> bool +{ + return true; +} } // namespace ResourceDownload diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h index f4eb5ce0..86ba1ccb 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: GPL-3.0-only AND Apache-2.0 /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * * This program is free software: you can redistribute it and/or modify @@ -43,18 +43,33 @@ #include "ui/pages/modplatform/ModPage.h" #include "ui/pages/modplatform/ResourcePackPage.h" -#include "ui/pages/modplatform/TexturePackPage.h" #include "ui/pages/modplatform/ShaderPackPage.h" +#include "ui/pages/modplatform/TexturePackPage.h" namespace ResourceDownload { namespace Modrinth { -static inline QString displayName() { return "Modrinth"; } -static inline QIcon icon() { return APPLICATION->getThemedIcon("modrinth"); } -static inline QString id() { return "modrinth"; } -static inline QString debugName() { return "Modrinth"; } -static inline QString metaEntryBase() { return "ModrinthPacks"; } +static inline QString displayName() +{ + return "Modrinth"; +} +static inline QIcon icon() +{ + return APPLICATION->getThemedIcon("modrinth"); +} +static inline QString id() +{ + return "modrinth"; +} +static inline QString debugName() +{ + return "Modrinth"; +} +static inline QString metaEntryBase() +{ + return "ModrinthPacks"; } +} // namespace Modrinth class ModrinthModPage : public ModPage { Q_OBJECT @@ -78,7 +93,8 @@ class ModrinthModPage : public ModPage { [[nodiscard]] inline auto helpPage() const -> QString override { return "Mod-platform"; } - auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const -> bool override; + auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const + -> bool override; }; class ModrinthResourcePackPage : public ResourcePackResourcePage { diff --git a/launcher/ui/pages/modplatform/technic/TechnicData.h b/launcher/ui/pages/modplatform/technic/TechnicData.h index cd2ea8e1..fc7fa4d3 100644 --- a/launcher/ui/pages/modplatform/technic/TechnicData.h +++ b/launcher/ui/pages/modplatform/technic/TechnicData.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2021-2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -63,6 +63,6 @@ struct Modpack { QString recommended; QVector<QString> versions; }; -} +} // namespace Technic Q_DECLARE_METATYPE(Technic::Modpack) diff --git a/launcher/ui/pages/modplatform/technic/TechnicModel.cpp b/launcher/ui/pages/modplatform/technic/TechnicModel.cpp index 5ba804db..e8c5ac92 100644 --- a/launcher/ui/pages/modplatform/technic/TechnicModel.cpp +++ b/launcher/ui/pages/modplatform/technic/TechnicModel.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2021 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify diff --git a/launcher/ui/pages/modplatform/technic/TechnicModel.h b/launcher/ui/pages/modplatform/technic/TechnicModel.h index 0f1a814e..d7a635d4 100644 --- a/launcher/ui/pages/modplatform/technic/TechnicModel.h +++ b/launcher/ui/pages/modplatform/technic/TechnicModel.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2021 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify diff --git a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp index e066fa6f..54b86feb 100644 --- a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp +++ b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2021-2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -41,18 +41,17 @@ #include "ui/dialogs/NewInstanceDialog.h" #include "BuildConfig.h" +#include "Json.h" #include "TechnicModel.h" #include "modplatform/technic/SingleZipPackInstallTask.h" #include "modplatform/technic/SolderPackInstallTask.h" -#include "Json.h" #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) +TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog) { ui->setupUi(this); connect(ui->searchButton, &QPushButton::clicked, this, &TechnicPage::triggerSearch); @@ -98,18 +97,17 @@ void TechnicPage::openedImpl() triggerSearch(); } -void TechnicPage::triggerSearch() { +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(); - if(!first.isValid()) - { - if(isOpened) - { + if (!first.isValid()) { + if (isOpened) { dialog->setSuggestedPack(); } return; @@ -121,12 +119,10 @@ void TechnicPage::onSelectionChanged(QModelIndex first, QModelIndex second) void TechnicPage::suggestCurrent() { - if (!isOpened) - { + if (!isOpened) { return; } - if (current.broken) - { + if (current.broken) { dialog->setSuggestedPack(); return; } @@ -142,50 +138,41 @@ void TechnicPage::suggestCurrent() auto netJob = makeShared<NetJob>(QString("Technic::PackMeta(%1)").arg(current.name), APPLICATION->network()); QString slug = current.slug; - 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] - { + 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(); - if (current.slug != slug) - { + if (current.slug != slug) { return; } - QJsonParseError parse_error {}; + QJsonParseError parse_error{}; QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); QJsonObject obj = doc.object(); - if(parse_error.error != QJsonParseError::NoError) - { - qWarning() << "Error while parsing JSON response from Technic at " << parse_error.offset << " reason: " << parse_error.errorString(); + if (parse_error.error != QJsonParseError::NoError) { + qWarning() << "Error while parsing JSON response from Technic at " << parse_error.offset + << " reason: " << parse_error.errorString(); qWarning() << *response; return; } - if (!obj.contains("url")) - { + if (!obj.contains("url")) { qWarning() << "Json doesn't contain an url key"; return; } QJsonValueRef url = obj["url"]; - if (url.isString()) - { + if (url.isString()) { current.url = url.toString(); - } - else - { - if (!obj.contains("solder")) - { + } else { + if (!obj.contains("solder")) { qWarning() << "Json doesn't contain a valid url or solder key"; return; } QJsonValueRef solderUrl = obj["solder"]; - if (solderUrl.isString()) - { + if (solderUrl.isString()) { current.url = solderUrl.toString(); current.isSolder = true; - } - else - { + } else { qWarning() << "Json doesn't contain a valid url or solder key"; return; } @@ -226,22 +213,21 @@ void TechnicPage::metadataLoaded() // Strip trailing forward-slashes from Solder URL's if (current.isSolder) { - while (current.url.endsWith('/')) current.url.chop(1); + while (current.url.endsWith('/')) + current.url.chop(1); } // Display versions from Solder if (!current.isSolder) { // If the pack isn't a Solder pack, it only has the single version ui->versionSelectionBox->addItem(current.currentVersion); - } - else if (current.versionsLoaded) { + } else if (current.versionsLoaded) { // reverse foreach, so that the newest versions are first for (auto i = current.versions.size(); i--;) { ui->versionSelectionBox->addItem(current.versions.at(i)); } ui->versionSelectionBox->setCurrentText(current.recommended); - } - else { + } else { // For now, until the versions are pulled from the Solder instance, display the current // version so we can display something quicker ui->versionSelectionBox->addItem(current.currentVersion); @@ -259,7 +245,8 @@ void TechnicPage::metadataLoaded() selectVersion(); } -void TechnicPage::selectVersion() { +void TechnicPage::selectVersion() +{ if (!isOpened) { return; } @@ -268,17 +255,18 @@ void TechnicPage::selectVersion() { return; } - if (!current.isSolder) - { - dialog->setSuggestedPack(current.name, selectedVersion, new Technic::SingleZipPackInstallTask(current.url, current.minecraftVersion)); - } - else - { - dialog->setSuggestedPack(current.name, selectedVersion, new Technic::SolderPackInstallTask(APPLICATION->network(), current.url, current.slug, selectedVersion, current.minecraftVersion)); + if (!current.isSolder) { + dialog->setSuggestedPack(current.name, selectedVersion, + new Technic::SingleZipPackInstallTask(current.url, current.minecraftVersion)); + } else { + dialog->setSuggestedPack(current.name, selectedVersion, + new Technic::SolderPackInstallTask(APPLICATION->network(), current.url, current.slug, selectedVersion, + current.minecraftVersion)); } } -void TechnicPage::onSolderLoaded() { +void TechnicPage::onSolderLoaded() +{ jobPtr.reset(); auto fallback = [this]() { @@ -318,12 +306,13 @@ void TechnicPage::onSolderLoaded() { metadataLoaded(); } -void TechnicPage::onVersionSelectionChanged(QString data) { - if (data.isNull() || data.isEmpty()) { +void TechnicPage::onVersionSelectionChanged(QString version) +{ + if (version.isNull() || version.isEmpty()) { selectedVersion = ""; return; } - selectedVersion = data; + selectedVersion = version; selectVersion(); } diff --git a/launcher/ui/pages/modplatform/technic/TechnicPage.h b/launcher/ui/pages/modplatform/technic/TechnicPage.h index 753261b3..91b61eaf 100644 --- a/launcher/ui/pages/modplatform/technic/TechnicPage.h +++ b/launcher/ui/pages/modplatform/technic/TechnicPage.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2021-2022 Jamie Mansfield <jmansfield@cadixdev.org> * * This program is free software: you can redistribute it and/or modify @@ -37,46 +37,32 @@ #include <QWidget> -#include "ui/pages/BasePage.h" #include <Application.h> +#include "TechnicData.h" #include "net/NetJob.h" #include "tasks/Task.h" -#include "TechnicData.h" +#include "ui/pages/BasePage.h" -namespace Ui -{ +namespace Ui { class TechnicPage; } class NewInstanceDialog; namespace Technic { - class ListModel; +class ListModel; } -class TechnicPage : public QWidget, public BasePage -{ +class TechnicPage : public QWidget, public BasePage { Q_OBJECT -public: - explicit TechnicPage(NewInstanceDialog* dialog, QWidget *parent = 0); + public: + explicit TechnicPage(NewInstanceDialog* dialog, QWidget* parent = 0); virtual ~TechnicPage(); - virtual QString displayName() const override - { - return "Technic"; - } - virtual QIcon icon() const override - { - return APPLICATION->getThemedIcon("technic"); - } - virtual QString id() const override - { - return "technic"; - } - virtual QString helpPage() const override - { - return "Technic-platform"; - } + virtual QString displayName() const override { return "Technic"; } + virtual QIcon icon() const override { return APPLICATION->getThemedIcon("technic"); } + virtual QString id() const override { return "technic"; } + virtual QString helpPage() const override { return "Technic-platform"; } virtual bool shouldDisplay() const override; void retranslate() override; @@ -84,19 +70,19 @@ public: bool eventFilter(QObject* watched, QEvent* event) override; -private: + private: void suggestCurrent(); void metadataLoaded(); void selectVersion(); -private slots: + private slots: void triggerSearch(); void onSelectionChanged(QModelIndex first, QModelIndex second); void onSolderLoaded(); void onVersionSelectionChanged(QString data); -private: - Ui::TechnicPage *ui = nullptr; + private: + Ui::TechnicPage* ui = nullptr; NewInstanceDialog* dialog = nullptr; Technic::ListModel* model = nullptr; |