summaryrefslogtreecommitdiff
path: root/src/citra_qt/configure_system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt/configure_system.cpp')
-rw-r--r--src/citra_qt/configure_system.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/citra_qt/configure_system.cpp b/src/citra_qt/configure_system.cpp
new file mode 100644
index 000000000..4f0d4dbfe
--- /dev/null
+++ b/src/citra_qt/configure_system.cpp
@@ -0,0 +1,136 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "citra_qt/configure_system.h"
6#include "citra_qt/ui_settings.h"
7#include "ui_configure_system.h"
8
9#include "core/hle/service/fs/archive.h"
10#include "core/hle/service/cfg/cfg.h"
11
12static const std::array<int, 12> days_in_month = {{
13 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
14}};
15
16ConfigureSystem::ConfigureSystem(QWidget *parent) :
17 QWidget(parent),
18 ui(new Ui::ConfigureSystem) {
19 ui->setupUi(this);
20
21 connect(ui->combo_birthmonth, SIGNAL(currentIndexChanged(int)), SLOT(updateBirthdayComboBox(int)));
22}
23
24ConfigureSystem::~ConfigureSystem() {
25}
26
27void ConfigureSystem::setConfiguration(bool emulation_running) {
28 enabled = !emulation_running;
29
30 if (!enabled) {
31 ReadSystemSettings();
32 ui->group_system_settings->setEnabled(false);
33 } else {
34 // This tab is enabled only when game is not running (i.e. all service are not initialized).
35 // Temporarily register archive types and load the config savegame file to memory.
36 Service::FS::RegisterArchiveTypes();
37 ResultCode result = Service::CFG::LoadConfigNANDSaveFile();
38 Service::FS::UnregisterArchiveTypes();
39
40 if (result.IsError()) {
41 ui->label_disable_info->setText(tr("Failed to load system settings data."));
42 ui->group_system_settings->setEnabled(false);
43 enabled = false;
44 return;
45 }
46
47 ReadSystemSettings();
48 ui->label_disable_info->hide();
49 }
50}
51
52void ConfigureSystem::ReadSystemSettings() {
53 // set username
54 username = Service::CFG::GetUsername();
55 // ui->edit_username->setText(QString::fromStdU16String(username)); // TODO(wwylele): Use this when we move to Qt 5.5
56 ui->edit_username->setText(QString::fromUtf16(reinterpret_cast<const ushort*>(username.data())));
57
58 // set birthday
59 std::tie(birthmonth, birthday) = Service::CFG::GetBirthday();
60 ui->combo_birthmonth->setCurrentIndex(birthmonth - 1);
61 ui->combo_birthday->setCurrentIndex(birthday - 1);
62
63 // set system language
64 language_index = Service::CFG::GetSystemLanguage();
65 ui->combo_language->setCurrentIndex(language_index);
66
67 // set sound output mode
68 sound_index = Service::CFG::GetSoundOutputMode();
69 ui->combo_sound->setCurrentIndex(sound_index);
70}
71
72void ConfigureSystem::applyConfiguration() {
73 if (!enabled)
74 return;
75
76 bool modified = false;
77
78 // apply username
79 // std::u16string new_username = ui->edit_username->text().toStdU16String(); // TODO(wwylele): Use this when we move to Qt 5.5
80 std::u16string new_username(reinterpret_cast<const char16_t*>(ui->edit_username->text().utf16()));
81 if (new_username != username) {
82 Service::CFG::SetUsername(new_username);
83 modified = true;
84 }
85
86 // apply birthday
87 int new_birthmonth = ui->combo_birthmonth->currentIndex() + 1;
88 int new_birthday = ui->combo_birthday->currentIndex() + 1;
89 if (birthmonth != new_birthmonth || birthday != new_birthday) {
90 Service::CFG::SetBirthday(new_birthmonth, new_birthday);
91 modified = true;
92 }
93
94 // apply language
95 int new_language = ui->combo_language->currentIndex();
96 if (language_index != new_language) {
97 Service::CFG::SetSystemLanguage(static_cast<Service::CFG::SystemLanguage>(new_language));
98 modified = true;
99 }
100
101 // apply sound
102 int new_sound = ui->combo_sound->currentIndex();
103 if (sound_index != new_sound) {
104 Service::CFG::SetSoundOutputMode(static_cast<Service::CFG::SoundOutputMode>(new_sound));
105 modified = true;
106 }
107
108 // update the config savegame if any item is modified.
109 if (modified)
110 Service::CFG::UpdateConfigNANDSavegame();
111}
112
113void ConfigureSystem::updateBirthdayComboBox(int birthmonth_index) {
114 if (birthmonth_index < 0 || birthmonth_index >= 12)
115 return;
116
117 // store current day selection
118 int birthday_index = ui->combo_birthday->currentIndex();
119
120 // get number of days in the new selected month
121 int days = days_in_month[birthmonth_index];
122
123 // if the selected day is out of range,
124 // reset it to 1st
125 if (birthday_index < 0 || birthday_index >= days)
126 birthday_index = 0;
127
128 // update the day combo box
129 ui->combo_birthday->clear();
130 for (int i = 1; i <= days; ++i) {
131 ui->combo_birthday->addItem(QString::number(i));
132 }
133
134 // restore the day selection
135 ui->combo_birthday->setCurrentIndex(birthday_index);
136}