2016-06-01 09:43:33 +02:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-10-11 03:49:20 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <QFileDialog>
|
2018-10-10 03:53:04 +02:00
|
|
|
#include <QGraphicsItem>
|
2018-10-11 03:49:20 +02:00
|
|
|
#include <QGraphicsScene>
|
2018-10-28 23:11:17 +01:00
|
|
|
#include <QHeaderView>
|
2017-05-06 02:55:51 +02:00
|
|
|
#include <QMessageBox>
|
2018-10-11 03:49:20 +02:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QTreeView>
|
|
|
|
#include <QVBoxLayout>
|
2018-10-28 23:11:17 +01:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/file_util.h"
|
2018-10-11 15:16:32 +02:00
|
|
|
#include "common/string_util.h"
|
2017-02-20 03:37:14 +01:00
|
|
|
#include "core/core.h"
|
2018-08-03 17:02:55 +02:00
|
|
|
#include "core/settings.h"
|
2016-09-20 17:21:23 +02:00
|
|
|
#include "ui_configure_system.h"
|
2018-01-12 04:33:56 +01:00
|
|
|
#include "yuzu/configuration/configure_system.h"
|
2018-10-28 23:11:17 +01:00
|
|
|
#include "yuzu/util/limitable_input_dialog.h"
|
2018-01-12 04:33:56 +01:00
|
|
|
|
2018-10-25 22:58:37 +02:00
|
|
|
namespace {
|
|
|
|
constexpr std::array<int, 12> days_in_month = {{
|
2018-01-20 08:48:02 +01:00
|
|
|
31,
|
|
|
|
29,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
2016-09-19 03:01:46 +02:00
|
|
|
}};
|
2018-10-25 22:58:37 +02:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
2019-01-04 23:32:13 +01:00
|
|
|
ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) {
|
2016-06-01 09:43:33 +02:00
|
|
|
ui->setupUi(this);
|
2017-05-06 02:55:51 +02:00
|
|
|
connect(ui->combo_birthmonth,
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
2018-10-25 22:47:09 +02:00
|
|
|
&ConfigureSystem::UpdateBirthdayComboBox);
|
2017-05-06 02:55:51 +02:00
|
|
|
connect(ui->button_regenerate_console_id, &QPushButton::clicked, this,
|
2018-10-25 22:47:09 +02:00
|
|
|
&ConfigureSystem::RefreshConsoleID);
|
2016-09-13 07:04:17 +02:00
|
|
|
|
2018-11-12 04:34:23 +01:00
|
|
|
connect(ui->rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](bool checked) {
|
|
|
|
ui->rng_seed_edit->setEnabled(checked);
|
|
|
|
if (!checked)
|
2018-11-13 18:25:43 +01:00
|
|
|
ui->rng_seed_edit->setText(QStringLiteral("00000000"));
|
2018-11-12 04:34:23 +01:00
|
|
|
});
|
|
|
|
|
2018-12-29 00:36:14 +01:00
|
|
|
connect(ui->custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](bool checked) {
|
|
|
|
ui->custom_rtc_edit->setEnabled(checked);
|
|
|
|
if (!checked)
|
|
|
|
ui->custom_rtc_edit->setDateTime(QDateTime::currentDateTime());
|
|
|
|
});
|
|
|
|
|
2016-09-13 07:04:17 +02:00
|
|
|
this->setConfiguration();
|
2016-06-01 09:43:33 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 18:58:46 +02:00
|
|
|
ConfigureSystem::~ConfigureSystem() = default;
|
2016-06-01 09:43:33 +02:00
|
|
|
|
2016-09-02 14:18:45 +02:00
|
|
|
void ConfigureSystem::setConfiguration() {
|
2016-11-05 04:14:38 +01:00
|
|
|
enabled = !Core::System::GetInstance().IsPoweredOn();
|
2018-10-10 03:53:04 +02:00
|
|
|
|
2018-08-03 17:02:55 +02:00
|
|
|
ui->combo_language->setCurrentIndex(Settings::values.language_index);
|
2018-10-10 03:53:04 +02:00
|
|
|
|
2018-11-12 04:34:23 +01:00
|
|
|
ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.has_value());
|
|
|
|
ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.has_value());
|
2018-11-13 03:46:21 +01:00
|
|
|
|
2018-11-13 18:25:43 +01:00
|
|
|
const auto rng_seed =
|
|
|
|
QString("%1").arg(Settings::values.rng_seed.value_or(0), 8, 16, QLatin1Char{'0'}).toUpper();
|
2018-11-13 03:46:21 +01:00
|
|
|
ui->rng_seed_edit->setText(rng_seed);
|
2018-12-29 00:36:14 +01:00
|
|
|
|
|
|
|
ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.has_value());
|
|
|
|
ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.has_value());
|
|
|
|
|
|
|
|
const auto rtc_time = Settings::values.custom_rtc.value_or(QDateTime::currentSecsSinceEpoch());
|
|
|
|
ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time));
|
2018-10-10 03:53:04 +02:00
|
|
|
}
|
|
|
|
|
2018-01-12 04:33:56 +01:00
|
|
|
void ConfigureSystem::ReadSystemSettings() {}
|
2016-06-01 09:43:33 +02:00
|
|
|
|
|
|
|
void ConfigureSystem::applyConfiguration() {
|
|
|
|
if (!enabled)
|
|
|
|
return;
|
2018-10-10 03:53:04 +02:00
|
|
|
|
2018-08-03 17:02:55 +02:00
|
|
|
Settings::values.language_index = ui->combo_language->currentIndex();
|
2018-11-12 04:34:23 +01:00
|
|
|
|
|
|
|
if (ui->rng_seed_checkbox->isChecked())
|
|
|
|
Settings::values.rng_seed = ui->rng_seed_edit->text().toULongLong(nullptr, 16);
|
|
|
|
else
|
|
|
|
Settings::values.rng_seed = std::nullopt;
|
|
|
|
|
2018-12-29 00:36:14 +01:00
|
|
|
if (ui->custom_rtc_checkbox->isChecked())
|
|
|
|
Settings::values.custom_rtc = ui->custom_rtc_edit->dateTime().toSecsSinceEpoch();
|
|
|
|
else
|
|
|
|
Settings::values.custom_rtc = std::nullopt;
|
|
|
|
|
2018-08-03 17:02:55 +02:00
|
|
|
Settings::Apply();
|
2016-06-01 09:43:33 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 22:47:09 +02:00
|
|
|
void ConfigureSystem::UpdateBirthdayComboBox(int birthmonth_index) {
|
2016-06-01 09:43:33 +02:00
|
|
|
if (birthmonth_index < 0 || birthmonth_index >= 12)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// store current day selection
|
|
|
|
int birthday_index = ui->combo_birthday->currentIndex();
|
|
|
|
|
|
|
|
// get number of days in the new selected month
|
|
|
|
int days = days_in_month[birthmonth_index];
|
|
|
|
|
|
|
|
// if the selected day is out of range,
|
|
|
|
// reset it to 1st
|
|
|
|
if (birthday_index < 0 || birthday_index >= days)
|
|
|
|
birthday_index = 0;
|
|
|
|
|
|
|
|
// update the day combo box
|
|
|
|
ui->combo_birthday->clear();
|
|
|
|
for (int i = 1; i <= days; ++i) {
|
|
|
|
ui->combo_birthday->addItem(QString::number(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore the day selection
|
|
|
|
ui->combo_birthday->setCurrentIndex(birthday_index);
|
|
|
|
}
|
2017-05-06 02:55:51 +02:00
|
|
|
|
2018-10-25 22:47:09 +02:00
|
|
|
void ConfigureSystem::RefreshConsoleID() {
|
2017-05-06 02:55:51 +02:00
|
|
|
QMessageBox::StandardButton reply;
|
2018-01-14 00:49:16 +01:00
|
|
|
QString warning_text = tr("This will replace your current virtual Switch with a new one. "
|
|
|
|
"Your current virtual Switch will not be recoverable. "
|
2017-05-06 02:55:51 +02:00
|
|
|
"This might have unexpected effects in games. This might fail, "
|
|
|
|
"if you use an outdated config savegame. Continue?");
|
|
|
|
reply = QMessageBox::critical(this, tr("Warning"), warning_text,
|
|
|
|
QMessageBox::No | QMessageBox::Yes);
|
|
|
|
if (reply == QMessageBox::No)
|
|
|
|
return;
|
2017-10-13 03:21:49 +02:00
|
|
|
u64 console_id{};
|
2018-01-17 17:20:46 +01:00
|
|
|
ui->label_console_id->setText(
|
|
|
|
tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper()));
|
2017-05-06 02:55:51 +02:00
|
|
|
}
|