From 843c2d67eb04ecd215c9bc3de6f458c8d293b54f Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 13 Jul 2023 18:41:29 +0300 Subject: Added FTBAPP Import Signed-off-by: Trial97 --- .../pages/modplatform/import_ftb/ImportFTBPage.cpp | 104 +++++++++++++++++++++ .../pages/modplatform/import_ftb/ImportFTBPage.h | 67 +++++++++++++ .../pages/modplatform/import_ftb/ImportFTBPage.ui | 28 ++++++ .../ui/pages/modplatform/import_ftb/ListModel.cpp | 89 ++++++++++++++++++ .../ui/pages/modplatform/import_ftb/ListModel.h | 46 +++++++++ 5 files changed, 334 insertions(+) create mode 100644 launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp create mode 100644 launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h create mode 100644 launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui create mode 100644 launcher/ui/pages/modplatform/import_ftb/ListModel.cpp create mode 100644 launcher/ui/pages/modplatform/import_ftb/ListModel.h (limited to 'launcher/ui/pages/modplatform') diff --git a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp new file mode 100644 index 00000000..5c9ff63b --- /dev/null +++ b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (c) 2023 Trial97 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ImportFTBPage.h" +#include "ui_ImportFTBPage.h" + +#include +#include "FileSystem.h" +#include "ListModel.h" +#include "modplatform/import_ftb/PackInstallTask.h" +#include "ui/dialogs/NewInstanceDialog.h" + +namespace FTBImportAPP { + +ImportFTBPage::ImportFTBPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), dialog(dialog), ui(new Ui::ImportFTBPage) +{ + ui->setupUi(this); + + { + listModel = new ListModel(this); + + ui->modpackList->setModel(listModel); + ui->modpackList->setSortingEnabled(true); + ui->modpackList->header()->hide(); + ui->modpackList->setIndentation(0); + ui->modpackList->setIconSize(QSize(42, 42)); + } + + connect(ui->modpackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &ImportFTBPage::onPublicPackSelectionChanged); + + ui->modpackList->selectionModel()->reset(); +} + +ImportFTBPage::~ImportFTBPage() +{ + delete ui; +} + +void ImportFTBPage::openedImpl() +{ + if (!initialized) { + listModel->update(); + initialized = true; + } + suggestCurrent(); +} + +void ImportFTBPage::retranslate() +{ + ui->retranslateUi(this); +} + +void ImportFTBPage::suggestCurrent() +{ + if (!isOpened) + return; + + if (selected.path.isEmpty()) { + dialog->setSuggestedPack(); + return; + } + + dialog->setSuggestedPack(selected.name, new PackInstallTask(selected)); + QString editedLogoName = QString("ftb_%1").arg(selected.id); + dialog->setSuggestedIconFromFile(FS::PathCombine(selected.path, "folder.jpg"), editedLogoName); +} + +void ImportFTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev) +{ + if (!now.isValid()) { + onPackSelectionChanged(); + return; + } + Modpack selectedPack = listModel->data(now, Qt::UserRole).value(); + onPackSelectionChanged(&selectedPack); +} + +void ImportFTBPage::onPackSelectionChanged(Modpack* pack) +{ + if (pack) { + selected = *pack; + suggestCurrent(); + return; + } + if (isOpened) + dialog->setSuggestedPack(); +} + +} // namespace FTBImportAPP diff --git a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h new file mode 100644 index 00000000..437fb62a --- /dev/null +++ b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (c) 2023 Trial97 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include +#include + +#include +#include "modplatform/import_ftb/PackHelpers.h" +#include "ui/pages/BasePage.h" +#include "ui/pages/modplatform/import_ftb/ListModel.h" + +class NewInstanceDialog; + +namespace FTBImportAPP { +namespace Ui { +class ImportFTBPage; +} + +class ImportFTBPage : public QWidget, public BasePage { + Q_OBJECT + + public: + explicit ImportFTBPage(NewInstanceDialog* dialog, QWidget* parent = 0); + virtual ~ImportFTBPage(); + QString displayName() const override { return "FTB App Import"; } + QIcon icon() const override { return APPLICATION->getThemedIcon("ftb_logo"); } + QString id() const override { return "import_ftb"; } + QString helpPage() const override { return "FTB-platform"; } + bool shouldDisplay() const override { return true; } + void openedImpl() override; + void retranslate() override; + + private: + void suggestCurrent(); + void onPackSelectionChanged(Modpack* pack = nullptr); + private slots: + void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second); + + private: + bool initialized = false; + Modpack selected; + ListModel* listModel = nullptr; + + NewInstanceDialog* dialog = nullptr; + Ui::ImportFTBPage* ui = nullptr; +}; + +} // namespace FTBImportAPP diff --git a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui new file mode 100644 index 00000000..32d548b0 --- /dev/null +++ b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui @@ -0,0 +1,28 @@ + + + FTBImportAPP::ImportFTBPage + + + + 0 + 0 + 1461 + 1011 + + + + + + + + 16777215 + 16777215 + + + + + + + + + diff --git a/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp b/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp new file mode 100644 index 00000000..35d0334b --- /dev/null +++ b/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (c) 2023 Trial97 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ListModel.h" +#include +#include +#include +#include +#include +#include +#include "FileSystem.h" +#include "modplatform/import_ftb/PackHelpers.h" + +namespace FTBImportAPP { + +QString getPath() +{ + QString partialPath; +#if defined(Q_OS_OSX) + partialPath = FS::PathCombine(QDir::homePath(), "Library/Application Support"); +#elif defined(Q_OS_WIN32) + partialPath = QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA", ""); +#else + partialPath = QDir::homePath(); +#endif + return FS::PathCombine(partialPath, ".ftba"); +} + +const QString ListModel::FTB_APP_PATH = getPath(); + +void ListModel::update() +{ + beginResetModel(); + modpacks.clear(); + + QString instancesPath = FS::PathCombine(FTB_APP_PATH, "instances"); + if (auto instancesInfo = QFileInfo(instancesPath); instancesInfo.exists() && instancesInfo.isDir()) { + QDirIterator directoryIterator(instancesPath, QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable | QDir::Hidden, + QDirIterator::FollowSymlinks); + while (directoryIterator.hasNext()) { + auto modpack = parseDirectory(directoryIterator.next()); + if (!modpack.path.isEmpty()) + modpacks.append(modpack); + } + } else { + qDebug() << "Couldn't find ftb instances folder: " << instancesPath; + } + + endResetModel(); +} + +QVariant ListModel::data(const QModelIndex& index, int role) const +{ + int pos = index.row(); + if (pos >= modpacks.size() || pos < 0 || !index.isValid()) { + return QVariant(); + } + + auto pack = modpacks.at(pos); + if (role == Qt::DisplayRole) { + return pack.name; + } else if (role == Qt::DecorationRole) { + return pack.icon; + } else if (role == Qt::UserRole) { + QVariant v; + v.setValue(pack); + return v; + } else if (role == Qt::ToolTipRole) { + return tr("Minecraft %1").arg(pack.mcVersion); + } + + return QVariant(); +} +} // namespace FTBImportAPP \ No newline at end of file diff --git a/launcher/ui/pages/modplatform/import_ftb/ListModel.h b/launcher/ui/pages/modplatform/import_ftb/ListModel.h new file mode 100644 index 00000000..c67aa896 --- /dev/null +++ b/launcher/ui/pages/modplatform/import_ftb/ListModel.h @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (c) 2023 Trial97 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include +#include "modplatform/import_ftb/PackHelpers.h" + +namespace FTBImportAPP { + +class ListModel : public QAbstractListModel { + Q_OBJECT + + public: + ListModel(QObject* parent) : QAbstractListModel(parent) {} + virtual ~ListModel() = default; + + int rowCount(const QModelIndex& parent) const { return modpacks.size(); } + int columnCount(const QModelIndex& parent) const { return 1; } + QVariant data(const QModelIndex& index, int role) const; + + void update(); + + static const QString FTB_APP_PATH; + + private: + ModpackList modpacks; +}; +} // namespace FTBImportAPP \ No newline at end of file -- cgit From 7befd63ccedd96c52b94c1845fff36f24ee3f1d1 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 15 Jul 2023 00:28:58 +0300 Subject: fixed settings Signed-off-by: Trial97 --- launcher/ui/pages/modplatform/import_ftb/ListModel.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'launcher/ui/pages/modplatform') diff --git a/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp b/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp index 35d0334b..dc78f451 100644 --- a/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp +++ b/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp @@ -17,7 +17,6 @@ */ #include "ListModel.h" -#include #include #include #include -- cgit From 06fc8358d9836a203cd31580fa57f055c9bcef05 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 15 Jul 2023 23:57:32 +0300 Subject: auto focus search line on resource download Signed-off-by: Trial97 --- launcher/ui/pages/modplatform/ResourcePage.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'launcher/ui/pages/modplatform') diff --git a/launcher/ui/pages/modplatform/ResourcePage.cpp b/launcher/ui/pages/modplatform/ResourcePage.cpp index aab2ee89..48afbd90 100644 --- a/launcher/ui/pages/modplatform/ResourcePage.cpp +++ b/launcher/ui/pages/modplatform/ResourcePage.cpp @@ -104,6 +104,7 @@ void ResourcePage::openedImpl() updateSelectionButton(); triggerSearch(); + m_ui->searchEdit->setFocus(); } auto ResourcePage::eventFilter(QObject* watched, QEvent* event) -> bool -- cgit From f13eccb03d053453fd063850a35d7d17d76f9ce3 Mon Sep 17 00:00:00 2001 From: Alexandru Ionut Tripon Date: Wed, 2 Aug 2023 19:24:58 +0300 Subject: Update launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h Co-authored-by: Sefa Eyeoglu Signed-off-by: Alexandru Ionut Tripon --- launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launcher/ui/pages/modplatform') diff --git a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h index 437fb62a..54c49f7b 100644 --- a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h +++ b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h @@ -41,7 +41,7 @@ class ImportFTBPage : public QWidget, public BasePage { public: explicit ImportFTBPage(NewInstanceDialog* dialog, QWidget* parent = 0); virtual ~ImportFTBPage(); - QString displayName() const override { return "FTB App Import"; } + QString displayName() const override { return tr("FTB App Import"); } QIcon icon() const override { return APPLICATION->getThemedIcon("ftb_logo"); } QString id() const override { return "import_ftb"; } QString helpPage() const override { return "FTB-platform"; } -- cgit From 1d468ac35ad88d8c77cc83f25e3704d9bd7df01b Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 2 Aug 2023 18:35:35 +0200 Subject: chore: reformat Signed-off-by: Sefa Eyeoglu --- launcher/ui/pages/modplatform/CustomPage.cpp | 83 +++++------- launcher/ui/pages/modplatform/CustomPage.h | 44 +++--- launcher/ui/pages/modplatform/ImportPage.cpp | 66 +++------ launcher/ui/pages/modplatform/ImportPage.h | 43 ++---- launcher/ui/pages/modplatform/ResourcePackPage.cpp | 6 +- launcher/ui/pages/modplatform/ResourcePackPage.h | 2 +- launcher/ui/pages/modplatform/TexturePackPage.h | 5 +- .../modplatform/atlauncher/AtlFilterModel.cpp | 16 +-- .../pages/modplatform/atlauncher/AtlFilterModel.h | 16 +-- .../atlauncher/AtlOptionalModDialog.cpp | 132 +++++++++--------- .../modplatform/atlauncher/AtlOptionalModDialog.h | 37 +++--- .../ui/pages/modplatform/atlauncher/AtlPage.cpp | 34 ++--- launcher/ui/pages/modplatform/atlauncher/AtlPage.h | 46 +++---- .../atlauncher/AtlUserInteractionSupportImpl.cpp | 16 +-- launcher/ui/pages/modplatform/flame/FlameModel.cpp | 8 +- launcher/ui/pages/modplatform/flame/FlamePage.cpp | 9 +- launcher/ui/pages/modplatform/flame/FlamePage.h | 46 +++---- .../pages/modplatform/flame/FlameResourcePages.cpp | 28 ++-- .../pages/modplatform/flame/FlameResourcePages.h | 29 +++- .../ui/pages/modplatform/legacy_ftb/ListModel.h | 49 +++---- launcher/ui/pages/modplatform/legacy_ftb/Page.cpp | 147 +++++++-------------- launcher/ui/pages/modplatform/legacy_ftb/Page.h | 62 ++++----- .../pages/modplatform/modrinth/ModrinthModel.cpp | 28 ++-- .../ui/pages/modplatform/modrinth/ModrinthModel.h | 9 +- .../modplatform/modrinth/ModrinthResourcePages.cpp | 30 +++-- .../modplatform/modrinth/ModrinthResourcePages.h | 30 ++++- .../ui/pages/modplatform/technic/TechnicData.h | 2 +- .../ui/pages/modplatform/technic/TechnicPage.cpp | 98 ++++++-------- .../ui/pages/modplatform/technic/TechnicPage.h | 44 +++--- 29 files changed, 490 insertions(+), 675 deletions(-) (limited to 'launcher/ui/pages/modplatform') diff --git a/launcher/ui/pages/modplatform/CustomPage.cpp b/launcher/ui/pages/modplatform/CustomPage.cpp index e164171a..ae5cae30 100644 --- a/launcher/ui/pages/modplatform/CustomPage.cpp +++ b/launcher/ui/pages/modplatform/CustomPage.cpp @@ -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..273a6079 100644 --- a/launcher/ui/pages/modplatform/CustomPage.h +++ b/launcher/ui/pages/modplatform/CustomPage.h @@ -37,40 +37,26 @@ #include -#include "ui/pages/BasePage.h" #include #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 30196aad..b7f4d1ba 100644 --- a/launcher/ui/pages/modplatform/ImportPage.cpp +++ b/launcher/ui/pages/modplatform/ImportPage.cpp @@ -44,32 +44,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, 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)); @@ -98,16 +90,13 @@ void ImportPage::openedImpl() void ImportPage::updateState() { - if(!isOpened) - { + if (!isOpened) { return; } - if(ui->modpackEdit->hasAcceptableInput()) - { + if (ui->modpackEdit->hasAcceptableInput()) { QString input = ui->modpackEdit->text(); auto url = QUrl::fromUserInput(input); - if(url.isLocalFile()) - { + if (url.isLocalFile()) { // FIXME: actually do some validation of what's inside here... this is fake AF QFileInfo fi(input); @@ -116,28 +105,23 @@ void ImportPage::updateState() // mrpack is a modrinth pack bool isMRPack = fi.suffix() == "mrpack"; - if(fi.exists() && (isZip || isMRPack)) - { + if (fi.exists() && (isZip || isMRPack)) { QFileInfo fi(url.fileName()); - dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url,this)); + dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this)); dialog->setSuggestedIcon("default"); } - } - else - { - if(input.endsWith("?client=y")) { + } else { + if (input.endsWith("?client=y")) { input.chop(9); input.append("/file"); url = QUrl::fromUserInput(input); } // hook, line and sinker. QFileInfo fi(url.fileName()); - dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url,this)); + dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this)); dialog->setSuggestedIcon("default"); } - } - else - { + } else { dialog->setSuggestedPack(); } } @@ -154,29 +138,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 c2acb92d..66c452b9 100644 --- a/launcher/ui/pages/modplatform/ImportPage.h +++ b/launcher/ui/pages/modplatform/ImportPage.h @@ -37,55 +37,40 @@ #include -#include "ui/pages/BasePage.h" #include #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; -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; }; - 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 ResourcePackResourcePage::urlHandlers() const { QMap 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/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 -#include #include +#include #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 rightPack = sourceModel()->data(right, Qt::UserRole).value(); 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 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 7b61daa7..9b0206f9 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp +++ b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp @@ -38,15 +38,13 @@ #include #include +#include "Application.h" #include "BuildConfig.h" #include "Json.h" #include "modplatform/atlauncher/ATLShareCode.h" -#include "Application.h" AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector 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++) { @@ -62,7 +60,8 @@ AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent, ATLauncher::Pa } } -QVector AtlOptionalModListModel::getResult() { +QVector AtlOptionalModListModel::getResult() +{ QVector result; for (const auto& mod : m_mods) { @@ -74,16 +73,19 @@ QVector 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); @@ -94,18 +96,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; } @@ -114,7 +113,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, const QVariant& value, int role) +{ if (role == Qt::CheckStateRole) { auto row = index.row(); auto mod = m_mods.at(row); @@ -126,7 +126,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: @@ -141,7 +142,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; @@ -149,23 +151,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::Download::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(); @@ -177,8 +179,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; @@ -202,44 +203,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(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

%2") - .arg(m_version.warnings[mod.warning], tr("Are you sure that you want to enable this mod?")); + auto message = QString("%1

%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; } @@ -248,15 +249,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) { @@ -281,8 +285,7 @@ void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool if (enable) { dependants.append(mod.name); - } - else { + } else { dependants.removeAll(mod.name); // if there are no longer any dependents, let's disable the mod @@ -304,14 +307,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 mods) - : QDialog(parent) - , ui(new Ui::AtlOptionalModDialog) + : QDialog(parent), ui(new Ui::AtlOptionalModDialog) { ui->setupUi(this); @@ -319,35 +320,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..a23b1653 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h +++ b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h @@ -35,8 +35,8 @@ #pragma once -#include #include +#include #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 mods); + AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector mods); QVector 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); @@ -97,18 +96,16 @@ private: class AtlOptionalModDialog : public QDialog { Q_OBJECT -public: - AtlOptionalModDialog(QWidget *parent, ATLauncher::PackVersion version, QVector mods); + public: + AtlOptionalModDialog(QWidget* parent, ATLauncher::PackVersion version, QVector mods); ~AtlOptionalModDialog() override; - QVector getResult() { - return listModel->getResult(); - } + QVector 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..6e1e16a2 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp +++ b/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp @@ -46,10 +46,7 @@ #include -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() @@ -142,10 +133,8 @@ void AtlPage::onSelectionChanged(QModelIndex first, QModelIndex second) { ui->versionSelectionBox->clear(); - if(!first.isValid()) - { - if(isOpened) - { + if (!first.isValid()) { + if (isOpened) { dialog->setSuggestedPack(); } return; @@ -155,7 +144,7 @@ void AtlPage::onSelectionChanged(QModelIndex first, QModelIndex second) ui->packDescription->setHtml(selected.description.replace("\n", "
")); - for(const auto& version : selected.versions) { + for (const auto& version : selected.versions) { ui->versionSelectionBox->addItem(version.version); } @@ -164,8 +153,7 @@ void AtlPage::onSelectionChanged(QModelIndex first, QModelIndex second) void AtlPage::onVersionSelectionChanged(QString data) { - if(data.isNull() || data.isEmpty()) - { + if (data.isNull() || data.isEmpty()) { selectedVersion = ""; return; } diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlPage.h b/launcher/ui/pages/modplatform/atlauncher/AtlPage.h index 1b3b15c1..ac336ec1 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlPage.h +++ b/launcher/ui/pages/modplatform/atlauncher/AtlPage.h @@ -38,52 +38,38 @@ #include "AtlFilterModel.h" #include "AtlListModel.h" -#include #include +#include #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..9ed75bcc 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.cpp +++ b/launcher/ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.cpp @@ -33,17 +33,16 @@ * limitations under the License. */ -#include #include "AtlUserInteractionSupportImpl.h" +#include #include "AtlOptionalModDialog.h" #include "ui/dialogs/VersionSelectDialog.h" -AtlUserInteractionSupportImpl::AtlUserInteractionSupportImpl(QWidget *parent) : m_parent(parent) -{ -} +AtlUserInteractionSupportImpl::AtlUserInteractionSupportImpl(QWidget* parent) : m_parent(parent) {} -std::optional> AtlUserInteractionSupportImpl::chooseOptionalMods(ATLauncher::PackVersion version, QVector mods) +std::optional> AtlUserInteractionSupportImpl::chooseOptionalMods(ATLauncher::PackVersion version, + QVector 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/flame/FlameModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModel.cpp index fa55aa68..83c1270b 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModel.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModel.cpp @@ -40,14 +40,16 @@ QVariant ListModel::data(const QModelIndex& index, int role) const return edit; } return pack.description; - } case Qt::DecorationRole: { + } + case Qt::DecorationRole: { if (m_logoMap.contains(pack.logoName)) { return (m_logoMap.value(pack.logoName)); } QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder"); ((ListModel*)this)->requestLogo(pack.logoName, pack.logoUrl); return icon; - } case Qt::U