From 9c6727e27f55dd888c8cfc5147fdf0f6f8378f46 Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 21 Feb 2022 21:34:06 -0300 Subject: [PATCH 1/8] feat: change task container in ModDownloadDialog to a QHash Previously, we used a unique_ptr to a ModDownloadTask to keep track of the selected mod to download when we accepted the dialog. In order to allow multiple mods to be selected at once for download, this has been changed to a QHash where the key is the mods name (since it doesn't seem right to allow for multiple versions of the same mod to be downloaded at once), and the value is a pointer to the corresponding ModDownloadTask. --- launcher/ModDownloadTask.h | 1 + launcher/ui/dialogs/ModDownloadDialog.cpp | 33 +++++++++++++++++--- launcher/ui/dialogs/ModDownloadDialog.h | 8 +++-- launcher/ui/pages/instance/ModFolderPage.cpp | 3 +- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/launcher/ModDownloadTask.h b/launcher/ModDownloadTask.h index 7e4f1b7d9..ddada5a21 100644 --- a/launcher/ModDownloadTask.h +++ b/launcher/ModDownloadTask.h @@ -10,6 +10,7 @@ class ModDownloadTask : public Task { Q_OBJECT public: explicit ModDownloadTask(const QUrl sourceUrl, const QString filename, const std::shared_ptr mods); + const QString& getFilename() const { return filename; } public slots: bool abort() override; diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index 6b807b8c6..c2bf2d6fd 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -52,6 +52,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr &mods HelpButton->setDefault(false); HelpButton->setAutoDefault(false); connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help); + QMetaObject::connectSlotsByName(this); setWindowModality(Qt::WindowModal); setWindowTitle("Download mods"); @@ -83,16 +84,38 @@ QList ModDownloadDialog::getPages() }; } -void ModDownloadDialog::setSuggestedMod(const QString& name, ModDownloadTask* task) +void ModDownloadDialog::addSelectedMod(const QString& name, ModDownloadTask* task) { - modTask.reset(task); - m_buttons->button(QDialogButtonBox::Ok)->setEnabled(task); + if(modTask.contains(name)) + delete modTask.find(name).value(); + + if(task) + modTask.insert(name, task); + else + modTask.remove(name); + + m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty()); +} + +void ModDownloadDialog::removeSelectedMod(const QString &name) +{ + if(modTask.contains(name)) + delete modTask.find(name).value(); + modTask.remove(name); +} + +bool ModDownloadDialog::isModSelected(const QString &name, const QString& filename) const +{ + // FIXME: Is there a way to check for versions without checking the filename + // as a heuristic, other than adding such info to ModDownloadTask itself? + auto iter = modTask.find(name); + return iter != modTask.end() && (iter.value()->getFilename() == filename); } ModDownloadDialog::~ModDownloadDialog() { } -ModDownloadTask *ModDownloadDialog::getTask() { - return modTask.release(); +const QList ModDownloadDialog::getTasks() { + return modTask.values(); } diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h index ece8e328f..02870c6c9 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.h +++ b/launcher/ui/dialogs/ModDownloadDialog.h @@ -29,9 +29,11 @@ public: QString dialogTitle() override; QList getPages() override; - void setSuggestedMod(const QString & name = QString(), ModDownloadTask * task = nullptr); + void addSelectedMod(const QString & name = QString(), ModDownloadTask * task = nullptr); + void removeSelectedMod(const QString & name = QString()); + bool isModSelected(const QString & name, const QString & filename) const; - ModDownloadTask * getTask(); + const QList getTasks(); const std::shared_ptr &mods; public slots: @@ -49,6 +51,6 @@ private: ModrinthPage *modrinthPage = nullptr; FlameModPage *flameModPage = nullptr; - std::unique_ptr modTask; + QHash modTask; BaseInstance *m_instance; }; diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index 494d32f03..b342accfc 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -365,8 +365,7 @@ void ModFolderPage::on_actionInstall_mods_triggered() } ModDownloadDialog mdownload(m_mods, this, m_inst); if(mdownload.exec()) { - ModDownloadTask *task = mdownload.getTask(); - if (task) { + for(auto task : mdownload.getTasks()){ connect(task, &Task::failed, [this, task](QString reason) { task->deleteLater(); CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); From 512395e3f1ada7e16fa547f7fbe050e20a6d3209 Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 21 Feb 2022 21:34:53 -0300 Subject: [PATCH 2/8] feat(ui): allow downloading multiple mods in Modrinth at once --- .../modplatform/modrinth/ModrinthPage.cpp | 54 ++++-- .../pages/modplatform/modrinth/ModrinthPage.h | 3 +- .../modplatform/modrinth/ModrinthPage.ui | 179 +++++++++--------- 3 files changed, 130 insertions(+), 106 deletions(-) diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index c5a54c296..5b209fa3e 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -34,6 +34,7 @@ ModrinthPage::ModrinthPage(ModDownloadDialog *dialog, BaseInstance *instance) connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch())); connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged); connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged); + connect(ui->modSelectionButton, &QPushButton::clicked, this, &ModrinthPage::onModSelected); } ModrinthPage::~ModrinthPage() @@ -61,7 +62,7 @@ bool ModrinthPage::shouldDisplay() const void ModrinthPage::openedImpl() { - suggestCurrent(); + updateSelectionButton(); triggerSearch(); } @@ -76,10 +77,6 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) if(!first.isValid()) { - if(isOpened) - { - dialog->setSuggestedMod(); - } return; } @@ -97,6 +94,10 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) if (!current.versionsLoaded) { qDebug() << "Loading Modrinth mod versions"; + + ui->modSelectionButton->setText(tr("Loading versions...")); + ui->modSelectionButton->setEnabled(false); + auto netJob = new NetJob(QString("Modrinth::ModVersions(%1)").arg(current.name), APPLICATION->network()); std::shared_ptr response = std::make_shared(); QString addonId = current.addonId; @@ -136,8 +137,9 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(-1)); } - suggestCurrent(); + updateSelectionButton(); }); + netJob->start(); } else @@ -148,33 +150,47 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) if(ui->versionSelectionBox->count() == 0){ ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(-1)); } - suggestCurrent(); + + updateSelectionButton(); } } -void ModrinthPage::suggestCurrent() +void ModrinthPage::updateSelectionButton() { - if(!isOpened) - { + if(!isOpened || selectedVersion < 0){ + ui->modSelectionButton->setEnabled(false); return; } - if (selectedVersion == -1) - { - dialog->setSuggestedMod(); - return; + ui->modSelectionButton->setEnabled(true); + auto& version = current.versions[selectedVersion]; + if(!dialog->isModSelected(current.name, version.fileName)){ + ui->modSelectionButton->setText(tr("Select mod for download")); + } + else{ + ui->modSelectionButton->setText(tr("Deselect mod for download")); } - auto version = current.versions[selectedVersion]; - dialog->setSuggestedMod(current.name, new ModDownloadTask(version.downloadUrl, version.fileName , dialog->mods)); } void ModrinthPage::onVersionSelectionChanged(QString data) { - if(data.isNull() || data.isEmpty()) - { + if (data.isNull() || data.isEmpty()){ selectedVersion = -1; return; } selectedVersion = ui->versionSelectionBox->currentData().toInt(); - suggestCurrent(); + updateSelectionButton(); +} + +void ModrinthPage::onModSelected() +{ + auto& version = current.versions[selectedVersion]; + if (dialog->isModSelected(current.name, version.fileName)){ + dialog->removeSelectedMod(current.name); + } + else{ + dialog->addSelectedMod(current.name, new ModDownloadTask(version.downloadUrl, version.fileName , dialog->mods)); + } + + updateSelectionButton(); } diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index 3c517069d..52b538e35 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -50,12 +50,13 @@ public: BaseInstance *m_instance; private: - void suggestCurrent(); + void updateSelectionButton(); private slots: void triggerSearch(); void onSelectionChanged(QModelIndex first, QModelIndex second); void onVersionSelectionChanged(QString data); + void onModSelected(); private: Ui::ModrinthPage *ui = nullptr; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui index 6d183de50..d0a8b8f78 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui @@ -1,90 +1,97 @@ - ModrinthPage - - - - 0 - 0 - 837 - 685 - - - - - - - - - - 48 - 48 - - - - Qt::ScrollBarAlwaysOff - - - true - - - - - - - true - - - true - - - - - - - - - - - - - - Version selected: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - Search - - - - - - - Search and filter ... - - - + ModrinthPage + + + + 0 + 0 + 837 + 685 + + + + + + + + + true + + + true + + + + + + + Qt::ScrollBarAlwaysOff + + + true + + + + 48 + 48 + + + + - - - searchEdit - searchButton - packView - packDescription - sortByBox - versionSelectionBox - - - + + + + + Search + + + + + + + Search and filter ... + + + + + + + + + + + + Version selected: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Select mod for download + + + + + + + + + searchEdit + searchButton + packView + packDescription + sortByBox + versionSelectionBox + + + From f5cf4eb45f6610851367bdcab7b87766bed14288 Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 21 Feb 2022 21:53:21 -0300 Subject: [PATCH 3/8] feat(ui): allow downloading multiple mods from CurseForge at once --- .../pages/modplatform/flame/FlameModPage.cpp | 51 +++-- .../ui/pages/modplatform/flame/FlameModPage.h | 3 +- .../pages/modplatform/flame/FlameModPage.ui | 179 +++++++++--------- 3 files changed, 128 insertions(+), 105 deletions(-) diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index a816c6818..728c36416 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -35,6 +35,7 @@ FlameModPage::FlameModPage(ModDownloadDialog *dialog, BaseInstance *instance) connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch())); connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameModPage::onSelectionChanged); connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameModPage::onVersionSelectionChanged); + connect(ui->modSelectionButton, &QPushButton::clicked, this, &FlameModPage::onModSelected); } FlameModPage::~FlameModPage() @@ -62,7 +63,7 @@ bool FlameModPage::shouldDisplay() const void FlameModPage::openedImpl() { - suggestCurrent(); + updateSelectionButton(); triggerSearch(); } @@ -77,10 +78,6 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second) if(!first.isValid()) { - if(isOpened) - { - dialog->setSuggestedMod(); - } return; } @@ -112,6 +109,10 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second) if (!current.versionsLoaded) { qDebug() << "Loading flame mod versions"; + + ui->modSelectionButton->setText(tr("Loading versions...")); + ui->modSelectionButton->setEnabled(false); + auto netJob = new NetJob(QString("Flame::ModVersions(%1)").arg(current.name), APPLICATION->network()); std::shared_ptr response = std::make_shared(); int addonId = current.addonId; @@ -151,7 +152,7 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second) ui->versionSelectionBox->addItem(tr("No Valid Version found!"), QVariant(-1)); } - suggestCurrent(); + updateSelectionButton(); }); netJob->start(); } @@ -163,25 +164,26 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second) if(ui->versionSelectionBox->count() == 0){ ui->versionSelectionBox->addItem(tr("No Valid Version found!"), QVariant(-1)); } - suggestCurrent(); + + updateSelectionButton(); } } -void FlameModPage::suggestCurrent() +void FlameModPage::updateSelectionButton() { - if(!isOpened) - { + if(!isOpened || selectedVersion < 0){ + ui->modSelectionButton->setEnabled(false); return; } - if (selectedVersion == -1) - { - dialog->setSuggestedMod(); - return; + ui->modSelectionButton->setEnabled(true); + auto& version = current.versions[selectedVersion]; + if(!dialog->isModSelected(current.name, version.fileName)){ + ui->modSelectionButton->setText(tr("Select mod for download")); + } + else{ + ui->modSelectionButton->setText(tr("Deselect mod for download")); } - - auto version = current.versions[selectedVersion]; - dialog->setSuggestedMod(current.name, new ModDownloadTask(version.downloadUrl, version.fileName , dialog->mods)); } void FlameModPage::onVersionSelectionChanged(QString data) @@ -192,5 +194,18 @@ void FlameModPage::onVersionSelectionChanged(QString data) return; } selectedVersion = ui->versionSelectionBox->currentData().toInt(); - suggestCurrent(); + updateSelectionButton(); +} + +void FlameModPage::onModSelected() +{ + auto& version = current.versions[selectedVersion]; + if (dialog->isModSelected(current.name, version.fileName)){ + dialog->removeSelectedMod(current.name); + } + else{ + dialog->addSelectedMod(current.name, new ModDownloadTask(version.downloadUrl, version.fileName , dialog->mods)); + } + + updateSelectionButton(); } diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.h b/launcher/ui/pages/modplatform/flame/FlameModPage.h index 8fa3248af..b5b19a4f3 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.h +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.h @@ -50,12 +50,13 @@ public: BaseInstance *m_instance; private: - void suggestCurrent(); + void updateSelectionButton(); private slots: void triggerSearch(); void onSelectionChanged(QModelIndex first, QModelIndex second); void onVersionSelectionChanged(QString data); + void onModSelected(); private: Ui::FlameModPage *ui = nullptr; diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.ui b/launcher/ui/pages/modplatform/flame/FlameModPage.ui index 7da0bb4aa..36df7e8a4 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.ui +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.ui @@ -1,90 +1,97 @@ - FlameModPage - - - - 0 - 0 - 837 - 685 - - - - - - - - - - 48 - 48 - - - - Qt::ScrollBarAlwaysOff - - - true - - - - - - - true - - - true - - - - - - - - - - - - - - Version selected: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - Search - - - - - - - Search and filter ... - - - + FlameModPage + + + + 0 + 0 + 837 + 685 + + + + + + + + + + + + + + + Version selected: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Select mod for download + + + - - - searchEdit - searchButton - packView - packDescription - sortByBox - versionSelectionBox - - - + + + + + Search and filter ... + + + + + + + + + Qt::ScrollBarAlwaysOff + + + true + + + + 48 + 48 + + + + + + + + true + + + true + + + + + + + + + Search + + + + + + + searchEdit + searchButton + packView + packDescription + sortByBox + versionSelectionBox + + + From 1004211a66370f2f39b81fdfc05e0e3645e91b90 Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 21 Feb 2022 22:51:58 -0300 Subject: [PATCH 4/8] fix(ui): change text in selection button when there's no valid version --- launcher/ui/pages/modplatform/flame/FlameModPage.cpp | 1 + launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index 728c36416..41ad9e28f 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -152,6 +152,7 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second) ui->versionSelectionBox->addItem(tr("No Valid Version found!"), QVariant(-1)); } + ui->modSelectionButton->setText(tr("Cannot select invalid version :(")); updateSelectionButton(); }); netJob->start(); diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index 5b209fa3e..513724311 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -137,6 +137,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(-1)); } + ui->modSelectionButton->setText(tr("Cannot select invalid version :(")); updateSelectionButton(); }); From 0102e9194075a53c2816966afb9d12b84ed4c276 Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 21 Feb 2022 23:00:50 -0300 Subject: [PATCH 5/8] feat: add confirm dialog for installing mods When selecting multiple mods at once, it can become hard to keep track of which ones you selected. To address this, a dialog is now displayed when you finish selecting the mods to download, showing you which ones you selected and their filenames. From there, you can either accept it and download the mods, or you can cancel it and go back to the mod selection dialog. --- launcher/ui/dialogs/ModDownloadDialog.cpp | 28 ++++++++++++++++++++++- launcher/ui/dialogs/ModDownloadDialog.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index c2bf2d6fd..6240ecdc1 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -5,6 +5,7 @@ #include #include "ProgressDialog.h" +#include "CustomMessageBox.h" #include #include @@ -41,7 +42,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr &mods auto OkButton = m_buttons->button(QDialogButtonBox::Ok); OkButton->setDefault(true); OkButton->setAutoDefault(true); - connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::accept); + connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::confirm); auto CancelButton = m_buttons->button(QDialogButtonBox::Cancel); CancelButton->setDefault(false); @@ -68,6 +69,31 @@ void ModDownloadDialog::reject() QDialog::reject(); } +void ModDownloadDialog::confirm() +{ + auto info = QString("You're about to download the following mods:\n\n"); + for(auto task : modTask.keys()){ + info.append(task); + info.append("\n --> File name: "); + info.append(modTask.find(task).value()->getFilename()); + info.append('\n'); + } + + auto confirm_dialog = CustomMessageBox::selectable( + this, + tr("Confirm mods to download"), + info, + QMessageBox::NoIcon, + {QMessageBox::Cancel, QMessageBox::Ok}, + QMessageBox::Ok + ); + + auto AcceptButton = confirm_dialog->button(QMessageBox::Ok); + connect(AcceptButton, &QPushButton::clicked, this, &ModDownloadDialog::accept); + + confirm_dialog->open(); +} + void ModDownloadDialog::accept() { QDialog::accept(); diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h index 02870c6c9..309d89d06 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.h +++ b/launcher/ui/dialogs/ModDownloadDialog.h @@ -37,6 +37,7 @@ public: const std::shared_ptr &mods; public slots: + void confirm(); void accept() override; void reject() override; From f8b0d6453ae81488ddfd4c83b329e2c88787c49e Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 21 Feb 2022 23:25:33 -0300 Subject: [PATCH 6/8] fix: sort mod list in confirmation dialog --- launcher/ui/dialogs/ModDownloadDialog.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index 6240ecdc1..439f22c4e 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -71,8 +71,11 @@ void ModDownloadDialog::reject() void ModDownloadDialog::confirm() { + auto keys = modTask.keys(); + keys.sort(Qt::CaseInsensitive); + auto info = QString("You're about to download the following mods:\n\n"); - for(auto task : modTask.keys()){ + for(auto task : keys){ info.append(task); info.append("\n --> File name: "); info.append(modTask.find(task).value()->getFilename()); From 04840d0638f933416a0d14b2ef822c6f8da5e373 Mon Sep 17 00:00:00 2001 From: flow Date: Wed, 23 Feb 2022 14:44:55 -0300 Subject: [PATCH 7/8] fix(ui): add translation func to text in the confirm dialog --- launcher/ui/dialogs/ModDownloadDialog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index 439f22c4e..a56c2e649 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -74,10 +74,12 @@ void ModDownloadDialog::confirm() auto keys = modTask.keys(); keys.sort(Qt::CaseInsensitive); - auto info = QString("You're about to download the following mods:\n\n"); + auto info = QString(tr("You're about to download the following mods:")); + info.append("\n\n"); for(auto task : keys){ info.append(task); - info.append("\n --> File name: "); + info.append("\n --> "); + info.append(tr("File name: ")); info.append(modTask.find(task).value()->getFilename()); info.append('\n'); } From 40a9828fbab0e9a8b7f070714bdd87d3f279e18c Mon Sep 17 00:00:00 2001 From: flow Date: Wed, 23 Feb 2022 19:17:33 -0300 Subject: [PATCH 8/8] fix: improve readability and set ok button as disabled by default --- launcher/ui/dialogs/ModDownloadDialog.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index a56c2e649..23ca87314 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -40,6 +40,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr &mods // Bonk Qt over its stupid head and make sure it understands which button is the default one... // See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button auto OkButton = m_buttons->button(QDialogButtonBox::Ok); + OkButton->setEnabled(false); OkButton->setDefault(true); OkButton->setAutoDefault(true); connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::confirm); @@ -89,7 +90,7 @@ void ModDownloadDialog::confirm() tr("Confirm mods to download"), info, QMessageBox::NoIcon, - {QMessageBox::Cancel, QMessageBox::Ok}, + QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Ok ); @@ -117,13 +118,8 @@ QList ModDownloadDialog::getPages() void ModDownloadDialog::addSelectedMod(const QString& name, ModDownloadTask* task) { - if(modTask.contains(name)) - delete modTask.find(name).value(); - - if(task) - modTask.insert(name, task); - else - modTask.remove(name); + removeSelectedMod(name); + modTask.insert(name, task); m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty()); } @@ -133,6 +129,8 @@ void ModDownloadDialog::removeSelectedMod(const QString &name) if(modTask.contains(name)) delete modTask.find(name).value(); modTask.remove(name); + + m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty()); } bool ModDownloadDialog::isModSelected(const QString &name, const QString& filename) const