diff options
Diffstat (limited to 'launcher/ui/dialogs')
-rw-r--r-- | launcher/ui/dialogs/ModDownloadDialog.cpp | 64 | ||||
-rw-r--r-- | launcher/ui/dialogs/ModDownloadDialog.h | 9 |
2 files changed, 64 insertions, 9 deletions
diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index 6b807b8c..439f22c4 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -5,6 +5,7 @@ #include <InstanceList.h> #include "ProgressDialog.h" +#include "CustomMessageBox.h" #include <QLayout> #include <QPushButton> @@ -41,7 +42,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel> &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); @@ -52,6 +53,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel> &mods HelpButton->setDefault(false); HelpButton->setAutoDefault(false); connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help); + QMetaObject::connectSlotsByName(this); setWindowModality(Qt::WindowModal); setWindowTitle("Download mods"); @@ -67,6 +69,34 @@ void ModDownloadDialog::reject() QDialog::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 : 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(); @@ -83,16 +113,38 @@ QList<BasePage *> ModDownloadDialog::getPages() }; } -void ModDownloadDialog::setSuggestedMod(const QString& name, ModDownloadTask* task) +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); + + 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 { - modTask.reset(task); - m_buttons->button(QDialogButtonBox::Ok)->setEnabled(task); + // 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<ModDownloadTask*> ModDownloadDialog::getTasks() { + return modTask.values(); } diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h index ece8e328..309d89d0 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.h +++ b/launcher/ui/dialogs/ModDownloadDialog.h @@ -29,12 +29,15 @@ public: QString dialogTitle() override; QList<BasePage *> 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<ModDownloadTask*> getTasks(); const std::shared_ptr<ModFolderModel> &mods; public slots: + void confirm(); void accept() override; void reject() override; @@ -49,6 +52,6 @@ private: ModrinthPage *modrinthPage = nullptr; FlameModPage *flameModPage = nullptr; - std::unique_ptr<ModDownloadTask> modTask; + QHash<QString, ModDownloadTask*> modTask; BaseInstance *m_instance; }; |