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