2016-06-01 07:43:33 +00:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-05-06 00:55:51 +00:00
|
|
|
#include <QMessageBox>
|
2016-12-22 04:49:36 +00:00
|
|
|
#include "citra_qt/configuration/configure_system.h"
|
2016-06-01 07:43:33 +00:00
|
|
|
#include "citra_qt/ui_settings.h"
|
2017-02-20 02:37:14 +00:00
|
|
|
#include "core/core.h"
|
2016-06-01 07:43:33 +00:00
|
|
|
#include "core/hle/service/cfg/cfg.h"
|
2016-09-18 00:38:01 +00:00
|
|
|
#include "core/hle/service/fs/archive.h"
|
2016-09-20 15:21:23 +00:00
|
|
|
#include "ui_configure_system.h"
|
2016-06-01 07:43:33 +00:00
|
|
|
|
2016-09-19 01:01:46 +00:00
|
|
|
static const std::array<int, 12> days_in_month = {{
|
2018-03-09 17:54:43 +00:00
|
|
|
31,
|
|
|
|
29,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
2016-09-19 01:01:46 +00:00
|
|
|
}};
|
2016-06-01 07:43:33 +00:00
|
|
|
|
2016-09-18 00:38:01 +00:00
|
|
|
ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) {
|
2016-06-01 07:43:33 +00:00
|
|
|
ui->setupUi(this);
|
2017-05-06 00:55:51 +00:00
|
|
|
connect(ui->combo_birthmonth,
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ConfigureSystem::updateBirthdayComboBox);
|
|
|
|
connect(ui->button_regenerate_console_id, &QPushButton::clicked, this,
|
|
|
|
&ConfigureSystem::refreshConsoleID);
|
2016-09-13 05:04:17 +00:00
|
|
|
|
|
|
|
this->setConfiguration();
|
2016-06-01 07:43:33 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 01:01:46 +00:00
|
|
|
ConfigureSystem::~ConfigureSystem() {}
|
2016-06-01 07:43:33 +00:00
|
|
|
|
2016-09-02 12:18:45 +00:00
|
|
|
void ConfigureSystem::setConfiguration() {
|
2016-11-05 03:14:38 +00:00
|
|
|
enabled = !Core::System::GetInstance().IsPoweredOn();
|
2016-06-01 07:43:33 +00:00
|
|
|
|
|
|
|
if (!enabled) {
|
2018-03-06 08:43:24 +00:00
|
|
|
cfg = Service::CFG::GetCurrentModule();
|
2016-06-01 07:43:33 +00:00
|
|
|
ReadSystemSettings();
|
|
|
|
ui->group_system_settings->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
// This tab is enabled only when game is not running (i.e. all service are not initialized).
|
|
|
|
// Temporarily register archive types and load the config savegame file to memory.
|
|
|
|
Service::FS::RegisterArchiveTypes();
|
2018-03-06 08:43:24 +00:00
|
|
|
cfg = std::make_shared<Service::CFG::Module>();
|
2016-06-01 07:43:33 +00:00
|
|
|
Service::FS::UnregisterArchiveTypes();
|
|
|
|
|
|
|
|
ReadSystemSettings();
|
|
|
|
ui->label_disable_info->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureSystem::ReadSystemSettings() {
|
|
|
|
// set username
|
2018-03-06 08:43:24 +00:00
|
|
|
username = cfg->GetUsername();
|
2016-09-19 01:01:46 +00:00
|
|
|
// TODO(wwylele): Use this when we move to Qt 5.5
|
|
|
|
// ui->edit_username->setText(QString::fromStdU16String(username));
|
2016-09-18 00:38:01 +00:00
|
|
|
ui->edit_username->setText(
|
|
|
|
QString::fromUtf16(reinterpret_cast<const ushort*>(username.data())));
|
2016-06-01 07:43:33 +00:00
|
|
|
|
|
|
|
// set birthday
|
2018-03-06 08:43:24 +00:00
|
|
|
std::tie(birthmonth, birthday) = cfg->GetBirthday();
|
2016-06-01 07:43:33 +00:00
|
|
|
ui->combo_birthmonth->setCurrentIndex(birthmonth - 1);
|
2016-09-18 00:38:01 +00:00
|
|
|
updateBirthdayComboBox(
|
|
|
|
birthmonth -
|
|
|
|
1); // explicitly update it because the signal from setCurrentIndex is not reliable
|
2016-06-01 07:43:33 +00:00
|
|
|
ui->combo_birthday->setCurrentIndex(birthday - 1);
|
|
|
|
|
|
|
|
// set system language
|
2018-03-06 08:43:24 +00:00
|
|
|
language_index = cfg->GetSystemLanguage();
|
2016-06-01 07:43:33 +00:00
|
|
|
ui->combo_language->setCurrentIndex(language_index);
|
|
|
|
|
|
|
|
// set sound output mode
|
2018-03-06 08:43:24 +00:00
|
|
|
sound_index = cfg->GetSoundOutputMode();
|
2016-06-01 07:43:33 +00:00
|
|
|
ui->combo_sound->setCurrentIndex(sound_index);
|
2017-05-06 00:55:51 +00:00
|
|
|
|
|
|
|
// set the console id
|
2018-03-06 08:43:24 +00:00
|
|
|
u64 console_id = cfg->GetConsoleUniqueId();
|
2017-09-24 14:52:11 +00:00
|
|
|
ui->label_console_id->setText(
|
|
|
|
tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper()));
|
2016-06-01 07:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureSystem::applyConfiguration() {
|
|
|
|
if (!enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool modified = false;
|
|
|
|
|
|
|
|
// apply username
|
2016-09-19 01:01:46 +00:00
|
|
|
// TODO(wwylele): Use this when we move to Qt 5.5
|
|
|
|
// std::u16string new_username = ui->edit_username->text().toStdU16String();
|
2016-09-18 00:38:01 +00:00
|
|
|
std::u16string new_username(
|
|
|
|
reinterpret_cast<const char16_t*>(ui->edit_username->text().utf16()));
|
2016-06-01 07:43:33 +00:00
|
|
|
if (new_username != username) {
|
2018-03-06 08:43:24 +00:00
|
|
|
cfg->SetUsername(new_username);
|
2016-06-01 07:43:33 +00:00
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply birthday
|
|
|
|
int new_birthmonth = ui->combo_birthmonth->currentIndex() + 1;
|
|
|
|
int new_birthday = ui->combo_birthday->currentIndex() + 1;
|
|
|
|
if (birthmonth != new_birthmonth || birthday != new_birthday) {
|
2018-03-06 08:43:24 +00:00
|
|
|
cfg->SetBirthday(new_birthmonth, new_birthday);
|
2016-06-01 07:43:33 +00:00
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply language
|
|
|
|
int new_language = ui->combo_language->currentIndex();
|
|
|
|
if (language_index != new_language) {
|
2018-03-06 08:43:24 +00:00
|
|
|
cfg->SetSystemLanguage(static_cast<Service::CFG::SystemLanguage>(new_language));
|
2016-06-01 07:43:33 +00:00
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply sound
|
|
|
|
int new_sound = ui->combo_sound->currentIndex();
|
|
|
|
if (sound_index != new_sound) {
|
2018-03-06 08:43:24 +00:00
|
|
|
cfg->SetSoundOutputMode(static_cast<Service::CFG::SoundOutputMode>(new_sound));
|
2016-06-01 07:43:33 +00:00
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the config savegame if any item is modified.
|
|
|
|
if (modified)
|
2018-03-06 08:43:24 +00:00
|
|
|
cfg->UpdateConfigNANDSavegame();
|
2016-06-01 07:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureSystem::updateBirthdayComboBox(int birthmonth_index) {
|
|
|
|
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 00:55:51 +00:00
|
|
|
|
|
|
|
void ConfigureSystem::refreshConsoleID() {
|
|
|
|
QMessageBox::StandardButton reply;
|
|
|
|
QString warning_text = tr("This will replace your current virtual 3DS with a new one. "
|
|
|
|
"Your current virtual 3DS will not be recoverable. "
|
|
|
|
"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;
|
|
|
|
u32 random_number;
|
|
|
|
u64 console_id;
|
2018-03-06 08:43:24 +00:00
|
|
|
cfg->GenerateConsoleUniqueId(random_number, console_id);
|
|
|
|
cfg->SetConsoleUniqueId(random_number, console_id);
|
|
|
|
cfg->UpdateConfigNANDSavegame();
|
2017-05-06 00:55:51 +00:00
|
|
|
ui->label_console_id->setText("Console ID: 0x" + QString::number(console_id, 16).toUpper());
|
|
|
|
}
|
2017-09-23 13:13:59 +00:00
|
|
|
|
|
|
|
void ConfigureSystem::retranslateUi() {
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|