summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/configuration/configure_system.cpp56
-rw-r--r--src/yuzu/configuration/configure_system.h35
2 files changed, 46 insertions, 45 deletions
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp
index 0bc307e99..20ffb0a9a 100644
--- a/src/yuzu/configuration/configure_system.cpp
+++ b/src/yuzu/configuration/configure_system.cpp
@@ -21,12 +21,8 @@
21#include "yuzu/configuration/configure_system.h" 21#include "yuzu/configuration/configure_system.h"
22#include "yuzu/main.h" 22#include "yuzu/main.h"
23 23
24static std::string GetImagePath(Service::Account::UUID uuid) { 24namespace {
25 return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + 25constexpr std::array<int, 12> days_in_month = {{
26 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
27}
28
29static const std::array<int, 12> days_in_month = {{
30 31, 26 31,
31 29, 27 29,
32 31, 28 31,
@@ -42,7 +38,7 @@ static const std::array<int, 12> days_in_month = {{
42}}; 38}};
43 39
44// Same backup JPEG used by acc IProfile::GetImage if no jpeg found 40// Same backup JPEG used by acc IProfile::GetImage if no jpeg found
45static constexpr std::array<u8, 107> backup_jpeg{ 41constexpr std::array<u8, 107> backup_jpeg{
46 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 42 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02,
47 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, 43 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05,
48 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, 44 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e,
@@ -52,15 +48,32 @@ static constexpr std::array<u8, 107> backup_jpeg{
52 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, 48 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9,
53}; 49};
54 50
51std::string GetImagePath(Service::Account::UUID uuid) {
52 return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
53 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
54}
55
56std::string GetAccountUsername(const Service::Account::ProfileManager& manager,
57 Service::Account::UUID uuid) {
58 Service::Account::ProfileBase profile;
59 if (!manager.GetProfileBase(uuid, profile)) {
60 return "";
61 }
62
63 return Common::StringFromFixedZeroTerminatedBuffer(
64 reinterpret_cast<const char*>(profile.username.data()), profile.username.size());
65}
66} // Anonymous namespace
67
55ConfigureSystem::ConfigureSystem(QWidget* parent) 68ConfigureSystem::ConfigureSystem(QWidget* parent)
56 : QWidget(parent), ui(new Ui::ConfigureSystem), 69 : QWidget(parent), ui(new Ui::ConfigureSystem),
57 profile_manager(std::make_unique<Service::Account::ProfileManager>()) { 70 profile_manager(std::make_unique<Service::Account::ProfileManager>()) {
58 ui->setupUi(this); 71 ui->setupUi(this);
59 connect(ui->combo_birthmonth, 72 connect(ui->combo_birthmonth,
60 static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, 73 static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
61 &ConfigureSystem::updateBirthdayComboBox); 74 &ConfigureSystem::UpdateBirthdayComboBox);
62 connect(ui->button_regenerate_console_id, &QPushButton::clicked, this, 75 connect(ui->button_regenerate_console_id, &QPushButton::clicked, this,
63 &ConfigureSystem::refreshConsoleID); 76 &ConfigureSystem::RefreshConsoleID);
64 77
65 layout = new QVBoxLayout; 78 layout = new QVBoxLayout;
66 tree_view = new QTreeView; 79 tree_view = new QTreeView;
@@ -154,7 +167,7 @@ void ConfigureSystem::UpdateCurrentUser() {
154 167
155 const auto& current_user = profile_manager->GetUser(Settings::values.current_user); 168 const auto& current_user = profile_manager->GetUser(Settings::values.current_user);
156 ASSERT(current_user != std::nullopt); 169 ASSERT(current_user != std::nullopt);
157 const auto username = GetAccountUsername(*current_user); 170 const auto username = GetAccountUsername(*profile_manager, *current_user);
158 171
159 scene->clear(); 172 scene->clear();
160 scene->addPixmap( 173 scene->addPixmap(
@@ -164,14 +177,6 @@ void ConfigureSystem::UpdateCurrentUser() {
164 177
165void ConfigureSystem::ReadSystemSettings() {} 178void ConfigureSystem::ReadSystemSettings() {}
166 179
167std::string ConfigureSystem::GetAccountUsername(Service::Account::UUID uuid) const {
168 Service::Account::ProfileBase profile;
169 if (!profile_manager->GetProfileBase(uuid, profile))
170 return "";
171 return Common::StringFromFixedZeroTerminatedBuffer(
172 reinterpret_cast<const char*>(profile.username.data()), profile.username.size());
173}
174
175void ConfigureSystem::applyConfiguration() { 180void ConfigureSystem::applyConfiguration() {
176 if (!enabled) 181 if (!enabled)
177 return; 182 return;
@@ -180,7 +185,7 @@ void ConfigureSystem::applyConfiguration() {
180 Settings::Apply(); 185 Settings::Apply();
181} 186}
182 187
183void ConfigureSystem::updateBirthdayComboBox(int birthmonth_index) { 188void ConfigureSystem::UpdateBirthdayComboBox(int birthmonth_index) {
184 if (birthmonth_index < 0 || birthmonth_index >= 12) 189 if (birthmonth_index < 0 || birthmonth_index >= 12)
185 return; 190 return;
186 191
@@ -205,7 +210,7 @@ void ConfigureSystem::updateBirthdayComboBox(int birthmonth_index) {
205 ui->combo_birthday->setCurrentIndex(birthday_index); 210 ui->combo_birthday->setCurrentIndex(birthday_index);
206} 211}
207 212
208void ConfigureSystem::refreshConsoleID() { 213void ConfigureSystem::RefreshConsoleID() {
209 QMessageBox::StandardButton reply; 214 QMessageBox::StandardButton reply;
210 QString warning_text = tr("This will replace your current virtual Switch with a new one. " 215 QString warning_text = tr("This will replace your current virtual Switch with a new one. "
211 "Your current virtual Switch will not be recoverable. " 216 "Your current virtual Switch will not be recoverable. "
@@ -232,8 +237,7 @@ void ConfigureSystem::SelectUser(const QModelIndex& index) {
232} 237}
233 238
234void ConfigureSystem::AddUser() { 239void ConfigureSystem::AddUser() {
235 Service::Account::UUID uuid; 240 const auto uuid = Service::Account::UUID::Generate();
236 uuid.Generate();
237 241
238 bool ok = false; 242 bool ok = false;
239 const auto username = 243 const auto username =
@@ -253,7 +257,7 @@ void ConfigureSystem::RenameUser() {
253 const auto user = tree_view->currentIndex().row(); 257 const auto user = tree_view->currentIndex().row();
254 const auto uuid = profile_manager->GetUser(user); 258 const auto uuid = profile_manager->GetUser(user);
255 ASSERT(uuid != std::nullopt); 259 ASSERT(uuid != std::nullopt);
256 const auto username = GetAccountUsername(*uuid); 260 const auto username = GetAccountUsername(*profile_manager, *uuid);
257 261
258 Service::Account::ProfileBase profile; 262 Service::Account::ProfileBase profile;
259 if (!profile_manager->GetProfileBase(*uuid, profile)) 263 if (!profile_manager->GetProfileBase(*uuid, profile))
@@ -293,7 +297,7 @@ void ConfigureSystem::DeleteUser() {
293 const auto index = tree_view->currentIndex().row(); 297 const auto index = tree_view->currentIndex().row();
294 const auto uuid = profile_manager->GetUser(index); 298 const auto uuid = profile_manager->GetUser(index);
295 ASSERT(uuid != std::nullopt); 299 ASSERT(uuid != std::nullopt);
296 const auto username = GetAccountUsername(*uuid); 300 const auto username = GetAccountUsername(*profile_manager, *uuid);
297 301
298 const auto confirm = 302 const auto confirm =
299 QMessageBox::question(this, tr("Confirm Delete"), 303 QMessageBox::question(this, tr("Confirm Delete"),
@@ -321,10 +325,10 @@ void ConfigureSystem::SetUserImage() {
321 const auto index = tree_view->currentIndex().row(); 325 const auto index = tree_view->currentIndex().row();
322 const auto uuid = profile_manager->GetUser(index); 326 const auto uuid = profile_manager->GetUser(index);
323 ASSERT(uuid != std::nullopt); 327 ASSERT(uuid != std::nullopt);
324 const auto username = GetAccountUsername(*uuid); 328 const auto username = GetAccountUsername(*profile_manager, *uuid);
325 329
326 const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), 330 const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(),
327 "JPEG Images (*.jpg *.jpeg)"); 331 tr("JPEG Images (*.jpg *.jpeg)"));
328 332
329 if (file.isEmpty()) 333 if (file.isEmpty())
330 return; 334 return;
diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h
index b73e0719c..07764e1f7 100644
--- a/src/yuzu/configuration/configure_system.h
+++ b/src/yuzu/configuration/configure_system.h
@@ -9,17 +9,16 @@
9#include <QList> 9#include <QList>
10#include <QWidget> 10#include <QWidget>
11 11
12namespace Service::Account {
13class ProfileManager;
14struct UUID;
15} // namespace Service::Account
16
17class QGraphicsScene; 12class QGraphicsScene;
18class QStandardItem; 13class QStandardItem;
19class QStandardItemModel; 14class QStandardItemModel;
20class QTreeView; 15class QTreeView;
21class QVBoxLayout; 16class QVBoxLayout;
22 17
18namespace Service::Account {
19class ProfileManager;
20}
21
23namespace Ui { 22namespace Ui {
24class ConfigureSystem; 23class ConfigureSystem;
25} 24}
@@ -29,28 +28,25 @@ class ConfigureSystem : public QWidget {
29 28
30public: 29public:
31 explicit ConfigureSystem(QWidget* parent = nullptr); 30 explicit ConfigureSystem(QWidget* parent = nullptr);
32 ~ConfigureSystem(); 31 ~ConfigureSystem() override;
33 32
34 void applyConfiguration(); 33 void applyConfiguration();
35 void setConfiguration(); 34 void setConfiguration();
36 35
37 void PopulateUserList(); 36private:
38 void UpdateCurrentUser(); 37 void ReadSystemSettings();
39 38
40public slots: 39 void UpdateBirthdayComboBox(int birthmonth_index);
41 void updateBirthdayComboBox(int birthmonth_index); 40 void RefreshConsoleID();
42 void refreshConsoleID();
43 41
42 void PopulateUserList();
43 void UpdateCurrentUser();
44 void SelectUser(const QModelIndex& index); 44 void SelectUser(const QModelIndex& index);
45 void AddUser(); 45 void AddUser();
46 void RenameUser(); 46 void RenameUser();
47 void DeleteUser(); 47 void DeleteUser();
48 void SetUserImage(); 48 void SetUserImage();
49 49
50private:
51 void ReadSystemSettings();
52 std::string GetAccountUsername(Service::Account::UUID uuid) const;
53
54 QVBoxLayout* layout; 50 QVBoxLayout* layout;
55 QTreeView* tree_view; 51 QTreeView* tree_view;
56 QStandardItemModel* item_model; 52 QStandardItemModel* item_model;
@@ -59,11 +55,12 @@ private:
59 std::vector<QList<QStandardItem*>> list_items; 55 std::vector<QList<QStandardItem*>> list_items;
60 56
61 std::unique_ptr<Ui::ConfigureSystem> ui; 57 std::unique_ptr<Ui::ConfigureSystem> ui;
62 bool enabled; 58 bool enabled = false;
63 59
64 int birthmonth, birthday; 60 int birthmonth = 0;
65 int language_index; 61 int birthday = 0;
66 int sound_index; 62 int language_index = 0;
63 int sound_index = 0;
67 64
68 std::unique_ptr<Service::Account::ProfileManager> profile_manager; 65 std::unique_ptr<Service::Account::ProfileManager> profile_manager;
69}; 66};