Add SelectNandDialog

This commit is contained in:
Pengfei
2021-08-31 11:22:48 +08:00
parent fb2c4decdb
commit 0920462a94
5 changed files with 142 additions and 0 deletions
+3
View File
@@ -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
+10
View File
@@ -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();
}
+49
View File
@@ -0,0 +1,49 @@
// Copyright 2021 Pengfei Zhu
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <QPushButton>
#include <QRadioButton>
#include "frontend/select_nand_dialog.h"
#include "ui_select_nand_dialog.h"
SelectNandDialog::SelectNandDialog(QWidget* parent,
const std::vector<Core::Config::NandConfig>& nands_)
: QDialog(parent), ui(std::make_unique<Ui::SelectNandDialog>()), 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;
}
+27
View File
@@ -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 <memory>
#include <QDialog>
#include "core/importer.h"
namespace Ui {
class SelectNandDialog;
}
class SelectNandDialog final : public QDialog {
public:
explicit SelectNandDialog(QWidget* parent, const std::vector<Core::Config::NandConfig>& nands);
~SelectNandDialog();
int GetResult() const;
private:
std::unique_ptr<Ui::SelectNandDialog> ui;
const std::vector<Core::Config::NandConfig>& nands;
int result = -1;
};
+53
View File
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SelectNandDialog</class>
<widget class="QDialog" name="SelectNandDialog">
<property name="windowTitle">
<string>Select NAND</string>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>0</height>
</rect>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel">
<property name="text">
<string>Select primary NAND:</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="contentLayout" />
</item>
<item>
<widget class="QLabel">
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="text">
<string>This determines which NAND's System Titles and System Data will be used.</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Ok|QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
</layout>
</widget>
</ui>