diff --git a/src/frontend/CMakeLists.txt b/src/frontend/CMakeLists.txt index a2f0b10..34c70af 100644 --- a/src/frontend/CMakeLists.txt +++ b/src/frontend/CMakeLists.txt @@ -31,6 +31,9 @@ add_executable(threeSD select_files_dialog.cpp select_files_dialog.h select_files_dialog.ui + select_nand_dialog.cpp + select_nand_dialog.h + select_nand_dialog.ui title_info_dialog.cpp title_info_dialog.h title_info_dialog.ui diff --git a/src/frontend/main.cpp b/src/frontend/main.cpp index f9c141c..867e280 100644 --- a/src/frontend/main.cpp +++ b/src/frontend/main.cpp @@ -14,6 +14,7 @@ #include "common/file_util.h" #include "frontend/import_dialog.h" #include "frontend/main.h" +#include "frontend/select_nand_dialog.h" #include "frontend/utilities.h" #include "ui_main.h" @@ -205,6 +206,15 @@ void MainDialog::LaunchImportDialog() { "correctly.")); } + if (config.nands.size() > 1) { + SelectNandDialog dialog(this, config.nands); + if (dialog.exec() != QDialog::Accepted) { + return; + } + // Swap the selected NAND to the front + std::swap(config.nands[0], config.nands[dialog.GetResult()]); + } + ImportDialog dialog(this, config); dialog.exec(); } diff --git a/src/frontend/select_nand_dialog.cpp b/src/frontend/select_nand_dialog.cpp new file mode 100644 index 0000000..dd9cb4e --- /dev/null +++ b/src/frontend/select_nand_dialog.cpp @@ -0,0 +1,49 @@ +// Copyright 2021 Pengfei Zhu +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "frontend/select_nand_dialog.h" +#include "ui_select_nand_dialog.h" + +SelectNandDialog::SelectNandDialog(QWidget* parent, + const std::vector& nands_) + : QDialog(parent), ui(std::make_unique()), nands(nands_) { + + ui->setupUi(this); + setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); + + // Initialize radio buttons + for (std::size_t i = 0; i < nands.size(); ++i) { + const auto& nand = nands[i]; + + // TODO: this is currently hardcoded + QString display_name; + if (nand.nand_name == "Sys") { + display_name = tr("SysNAND"); + } else { + display_name = + tr("EmuNAND at 0x%1").arg(QString::fromStdString(nand.nand_name.substr(3))); + } + + QRadioButton* button = new QRadioButton(display_name); + connect(button, &QRadioButton::toggled, this, [this, i](bool checked) { + if (checked) { + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + result = i; + } + }); + ui->contentLayout->addWidget(button); + } + + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); +} + +SelectNandDialog::~SelectNandDialog() = default; + +int SelectNandDialog::GetResult() const { + return result; +} diff --git a/src/frontend/select_nand_dialog.h b/src/frontend/select_nand_dialog.h new file mode 100644 index 0000000..69d7887 --- /dev/null +++ b/src/frontend/select_nand_dialog.h @@ -0,0 +1,27 @@ +// Copyright 2021 Pengfei Zhu +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "core/importer.h" + +namespace Ui { +class SelectNandDialog; +} + +class SelectNandDialog final : public QDialog { +public: + explicit SelectNandDialog(QWidget* parent, const std::vector& nands); + ~SelectNandDialog(); + + int GetResult() const; + +private: + std::unique_ptr ui; + + const std::vector& nands; + int result = -1; +}; diff --git a/src/frontend/select_nand_dialog.ui b/src/frontend/select_nand_dialog.ui new file mode 100644 index 0000000..7845fce --- /dev/null +++ b/src/frontend/select_nand_dialog.ui @@ -0,0 +1,53 @@ + + + SelectNandDialog + + + Select NAND + + + + 0 + 0 + 400 + 0 + + + + + + + Select primary NAND: + + + + + + + + + + true + + + This determines which NAND's System Titles and System Data will be used. + + + + + + + Qt::Vertical + + + + + + + QDialogButtonBox::Ok|QDialogButtonBox::Cancel + + + + + +