summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/configuration/configure_system.cpp165
-rw-r--r--src/yuzu/configuration/configure_system.h19
-rw-r--r--src/yuzu/configuration/configure_system.ui242
3 files changed, 350 insertions, 76 deletions
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp
index e9ed9c38f..9a41c1f6c 100644
--- a/src/yuzu/configuration/configure_system.cpp
+++ b/src/yuzu/configuration/configure_system.cpp
@@ -2,7 +2,12 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <QGraphicsItem>
6#include <QList>
5#include <QMessageBox> 7#include <QMessageBox>
8#include <qinputdialog.h>
9#include "common/common_paths.h"
10#include "common/logging/backend.h"
6#include "core/core.h" 11#include "core/core.h"
7#include "core/settings.h" 12#include "core/settings.h"
8#include "ui_configure_system.h" 13#include "ui_configure_system.h"
@@ -24,6 +29,17 @@ static const std::array<int, 12> days_in_month = {{
24 31, 29 31,
25}}; 30}};
26 31
32// Same backup JPEG used by acc IProfile::GetImage if no jpeg found
33static constexpr std::array<u8, 107> backup_jpeg{
34 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02,
35 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05,
36 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e,
37 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13,
38 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01,
39 0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08,
40 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9,
41};
42
27ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) { 43ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) {
28 ui->setupUi(this); 44 ui->setupUi(this);
29 connect(ui->combo_birthmonth, 45 connect(ui->combo_birthmonth,
@@ -32,6 +48,44 @@ ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::
32 connect(ui->button_regenerate_console_id, &QPushButton::clicked, this, 48 connect(ui->button_regenerate_console_id, &QPushButton::clicked, this,
33 &ConfigureSystem::refreshConsoleID); 49 &ConfigureSystem::refreshConsoleID);
34 50
51 layout = new QVBoxLayout;
52 tree_view = new QTreeView;
53 item_model = new QStandardItemModel(tree_view);
54 tree_view->setModel(item_model);
55
56 tree_view->setAlternatingRowColors(true);
57 tree_view->setSelectionMode(QHeaderView::SingleSelection);
58 tree_view->setSelectionBehavior(QHeaderView::SelectRows);
59 tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel);
60 tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel);
61 tree_view->setSortingEnabled(true);
62 tree_view->setEditTriggers(QHeaderView::NoEditTriggers);
63 tree_view->setUniformRowHeights(true);
64 tree_view->setIconSize({64, 64});
65 tree_view->setContextMenuPolicy(Qt::NoContextMenu);
66
67 item_model->insertColumns(0, 1);
68 item_model->setHeaderData(0, Qt::Horizontal, "Users");
69
70 // We must register all custom types with the Qt Automoc system so that we are able to use it
71 // with signals/slots. In this case, QList falls under the umbrells of custom types.
72 qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>");
73
74 layout->setContentsMargins(0, 0, 0, 0);
75 layout->setSpacing(0);
76 layout->addWidget(tree_view);
77
78 ui->scrollArea->setLayout(layout);
79
80 connect(tree_view, &QTreeView::clicked, this, &ConfigureSystem::SelectUser);
81
82 connect(ui->pm_add, &QPushButton::pressed, this, &ConfigureSystem::AddUser);
83 connect(ui->pm_rename, &QPushButton::pressed, this, &ConfigureSystem::RenameUser);
84 connect(ui->pm_remove, &QPushButton::pressed, this, &ConfigureSystem::DeleteUser);
85
86 scene = new QGraphicsScene;
87 ui->current_user_icon->setScene(scene);
88
35 this->setConfiguration(); 89 this->setConfiguration();
36} 90}
37 91
@@ -39,8 +93,51 @@ ConfigureSystem::~ConfigureSystem() = default;
39 93
40void ConfigureSystem::setConfiguration() { 94void ConfigureSystem::setConfiguration() {
41 enabled = !Core::System::GetInstance().IsPoweredOn(); 95 enabled = !Core::System::GetInstance().IsPoweredOn();
42 ui->edit_username->setText(QString::fromStdString(Settings::values.username)); 96
43 ui->combo_language->setCurrentIndex(Settings::values.language_index); 97 ui->combo_language->setCurrentIndex(Settings::values.language_index);
98
99 item_model->removeRows(0, item_model->rowCount());
100 list_items.clear();
101
102 std::transform(Settings::values.users.begin(), Settings::values.users.end(),
103 std::back_inserter(list_items),
104 [](const std::pair<std::string, Service::Account::UUID>& user) {
105 const auto icon_url = QString::fromStdString(
106 FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "users" +
107 DIR_SEP + user.first + ".jpg");
108 QPixmap icon{icon_url};
109
110 if (!icon) {
111 icon.fill(QColor::fromRgb(0, 0, 0));
112 icon.loadFromData(backup_jpeg.data(), backup_jpeg.size());
113 }
114
115 return QList{new QStandardItem{
116 icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
117 QString::fromStdString(user.first + "\n" + user.second.Format())}};
118 });
119
120 for (const auto& item : list_items)
121 item_model->appendRow(item);
122
123 UpdateCurrentUser();
124}
125
126void ConfigureSystem::UpdateCurrentUser() {
127 const auto& current_user = Settings::values.users[Settings::values.current_user];
128 const auto icon_url =
129 QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "users" +
130 DIR_SEP + current_user.first + ".jpg");
131 QPixmap icon{icon_url};
132
133 if (!icon) {
134 icon.fill(QColor::fromRgb(0, 0, 0));
135 icon.loadFromData(backup_jpeg.data(), backup_jpeg.size());
136 }
137
138 scene->clear();
139 scene->addPixmap(icon.scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
140 ui->current_user_username->setText(QString::fromStdString(current_user.first));
44} 141}
45 142
46void ConfigureSystem::ReadSystemSettings() {} 143void ConfigureSystem::ReadSystemSettings() {}
@@ -48,7 +145,7 @@ void ConfigureSystem::ReadSystemSettings() {}
48void ConfigureSystem::applyConfiguration() { 145void ConfigureSystem::applyConfiguration() {
49 if (!enabled) 146 if (!enabled)
50 return; 147 return;
51 Settings::values.username = ui->edit_username->text().toStdString(); 148
52 Settings::values.language_index = ui->combo_language->currentIndex(); 149 Settings::values.language_index = ui->combo_language->currentIndex();
53 Settings::Apply(); 150 Settings::Apply();
54} 151}
@@ -92,3 +189,67 @@ void ConfigureSystem::refreshConsoleID() {
92 ui->label_console_id->setText( 189 ui->label_console_id->setText(
93 tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper())); 190 tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper()));
94} 191}
192
193void ConfigureSystem::SelectUser(const QModelIndex& index) {
194 Settings::values.current_user =
195 std::clamp<std::size_t>(index.row(), 0, Settings::values.users.size() - 1);
196
197 UpdateCurrentUser();
198
199 if (Settings::values.users.size() >= 2)
200 ui->pm_remove->setEnabled(true);
201 else
202 ui->pm_remove->setEnabled(false);
203
204 ui->pm_rename->setEnabled(true);
205}
206
207void ConfigureSystem::AddUser() {
208 Service::Account::UUID uuid;
209 uuid.Generate();
210
211 bool ok = false;
212 const auto username =
213 QInputDialog::getText(this, tr("Enter Username"), tr("Enter a username for the new user:"),
214 QLineEdit::Normal, QString(), &ok);
215
216 Settings::values.users.emplace_back(username.toStdString(), uuid);
217
218 setConfiguration();
219}
220
221void ConfigureSystem::RenameUser() {
222 const auto user = tree_view->currentIndex().row();
223
224 bool ok = false;
225 const auto new_username = QInputDialog::getText(
226 this, tr("Enter Username"), tr("Enter a new username:"), QLineEdit::Normal,
227 QString::fromStdString(Settings::values.users[user].first), &ok);
228
229 if (!ok)
230 return;
231
232 Settings::values.users[user].first = new_username.toStdString();
233
234 setConfiguration();
235}
236
237void ConfigureSystem::DeleteUser() {
238 const auto user = Settings::values.users.begin() + tree_view->currentIndex().row();
239 const auto confirm = QMessageBox::question(
240 this, tr("Confirm Delete"),
241 tr("You are about to delete user with name %1. Are you sure?").arg(user->first.c_str()));
242
243 if (confirm == QMessageBox::No)
244 return;
245
246 if (Settings::values.current_user == tree_view->currentIndex().row())
247 Settings::values.current_user = 0;
248
249 Settings::values.users.erase(user);
250
251 setConfiguration();
252
253 ui->pm_remove->setEnabled(false);
254 ui->pm_rename->setEnabled(false);
255}
diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h
index f13de17d4..aa20a3c30 100644
--- a/src/yuzu/configuration/configure_system.h
+++ b/src/yuzu/configuration/configure_system.h
@@ -5,6 +5,11 @@
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <memory>
8#include <QGraphicsScene>
9#include <QList>
10#include <QStandardItemModel>
11#include <QTreeView>
12#include <QVBoxLayout>
8#include <QWidget> 13#include <QWidget>
9 14
10namespace Ui { 15namespace Ui {
@@ -21,13 +26,27 @@ public:
21 void applyConfiguration(); 26 void applyConfiguration();
22 void setConfiguration(); 27 void setConfiguration();
23 28
29 void UpdateCurrentUser();
30
24public slots: 31public slots:
25 void updateBirthdayComboBox(int birthmonth_index); 32 void updateBirthdayComboBox(int birthmonth_index);
26 void refreshConsoleID(); 33 void refreshConsoleID();
27 34
35 void SelectUser(const QModelIndex& index);
36 void AddUser();
37 void RenameUser();
38 void DeleteUser();
39
28private: 40private:
29 void ReadSystemSettings(); 41 void ReadSystemSettings();
30 42
43 QVBoxLayout* layout;
44 QTreeView* tree_view;
45 QStandardItemModel* item_model;
46 QGraphicsScene* scene;
47
48 std::vector<QList<QStandardItem*>> list_items;
49
31 std::unique_ptr<Ui::ConfigureSystem> ui; 50 std::unique_ptr<Ui::ConfigureSystem> ui;
32 bool enabled; 51 bool enabled;
33 52
diff --git a/src/yuzu/configuration/configure_system.ui b/src/yuzu/configuration/configure_system.ui
index f3f8db038..2a6dcdb24 100644
--- a/src/yuzu/configuration/configure_system.ui
+++ b/src/yuzu/configuration/configure_system.ui
@@ -7,7 +7,7 @@
7 <x>0</x> 7 <x>0</x>
8 <y>0</y> 8 <y>0</y>
9 <width>360</width> 9 <width>360</width>
10 <height>377</height> 10 <height>483</height>
11 </rect> 11 </rect>
12 </property> 12 </property>
13 <property name="windowTitle"> 13 <property name="windowTitle">
@@ -22,34 +22,28 @@
22 <string>System Settings</string> 22 <string>System Settings</string>
23 </property> 23 </property>
24 <layout class="QGridLayout" name="gridLayout"> 24 <layout class="QGridLayout" name="gridLayout">
25 <item row="0" column="0"> 25 <item row="1" column="0">
26 <widget class="QLabel" name="label_username"> 26 <widget class="QLabel" name="label_language">
27 <property name="text"> 27 <property name="text">
28 <string>Username</string> 28 <string>Language</string>
29 </property> 29 </property>
30 </widget> 30 </widget>
31 </item> 31 </item>
32 <item row="0" column="1"> 32 <item row="0" column="0">
33 <widget class="QLineEdit" name="edit_username"> 33 <widget class="QLabel" name="label_birthday">
34 <property name="sizePolicy"> 34 <property name="text">
35 <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> 35 <string>Birthday</string>
36 <horstretch>0</horstretch>
37 <verstretch>0</verstretch>
38 </sizepolicy>
39 </property>
40 <property name="maxLength">
41 <number>32</number>
42 </property> 36 </property>
43 </widget> 37 </widget>
44 </item> 38 </item>
45 <item row="1" column="0"> 39 <item row="3" column="0">
46 <widget class="QLabel" name="label_birthday"> 40 <widget class="QLabel" name="label_console_id">
47 <property name="text"> 41 <property name="text">
48 <string>Birthday</string> 42 <string>Console ID:</string>
49 </property> 43 </property>
50 </widget> 44 </widget>
51 </item> 45 </item>
52 <item row="1" column="1"> 46 <item row="0" column="1">
53 <layout class="QHBoxLayout" name="horizontalLayout_birthday2"> 47 <layout class="QHBoxLayout" name="horizontalLayout_birthday2">
54 <item> 48 <item>
55 <widget class="QComboBox" name="combo_birthmonth"> 49 <widget class="QComboBox" name="combo_birthmonth">
@@ -120,14 +114,7 @@
120 </item> 114 </item>
121 </layout> 115 </layout>
122 </item> 116 </item>
123 <item row="2" column="0"> 117 <item row="1" column="1">
124 <widget class="QLabel" name="label_language">
125 <property name="text">
126 <string>Language</string>
127 </property>
128 </widget>
129 </item>
130 <item row="2" column="1">
131 <widget class="QComboBox" name="combo_language"> 118 <widget class="QComboBox" name="combo_language">
132 <property name="toolTip"> 119 <property name="toolTip">
133 <string>Note: this can be overridden when region setting is auto-select</string> 120 <string>Note: this can be overridden when region setting is auto-select</string>
@@ -187,31 +174,31 @@
187 <string>Russian (Русский)</string> 174 <string>Russian (Русский)</string>
188 </property> 175 </property>
189 </item> 176 </item>
190 <item> 177 <item>
191 <property name="text"> 178 <property name="text">
192 <string>Taiwanese</string> 179 <string>Taiwanese</string>
193 </property> 180 </property>
194 </item> 181 </item>
195 <item> 182 <item>
196 <property name="text"> 183 <property name="text">
197 <string>British English</string> 184 <string>British English</string>
198 </property> 185 </property>
199 </item> 186 </item>
200 <item> 187 <item>
201 <property name="text"> 188 <property name="text">
202 <string>Canadian French</string> 189 <string>Canadian French</string>
203 </property> 190 </property>
204 </item> 191 </item>
205 <item> 192 <item>
206 <property name="text"> 193 <property name="text">
207 <string>Latin American Spanish</string> 194 <string>Latin American Spanish</string>
208 </property> 195 </property>
209 </item> 196 </item>
210 <item> 197 <item>
211 <property name="text"> 198 <property name="text">
212 <string>Simplified Chinese</string> 199 <string>Simplified Chinese</string>
213 </property> 200 </property>
214 </item> 201 </item>
215 <item> 202 <item>
216 <property name="text"> 203 <property name="text">
217 <string>Traditional Chinese (正體中文)</string> 204 <string>Traditional Chinese (正體中文)</string>
@@ -219,14 +206,14 @@
219 </item> 206 </item>
220 </widget> 207 </widget>
221 </item> 208 </item>
222 <item row="3" column="0"> 209 <item row="2" column="0">
223 <widget class="QLabel" name="label_sound"> 210 <widget class="QLabel" name="label_sound">
224 <property name="text"> 211 <property name="text">
225 <string>Sound output mode</string> 212 <string>Sound output mode</string>
226 </property> 213 </property>
227 </widget> 214 </widget>
228 </item> 215 </item>
229 <item row="3" column="1"> 216 <item row="2" column="1">
230 <widget class="QComboBox" name="combo_sound"> 217 <widget class="QComboBox" name="combo_sound">
231 <item> 218 <item>
232 <property name="text"> 219 <property name="text">
@@ -245,14 +232,7 @@
245 </item> 232 </item>
246 </widget> 233 </widget>
247 </item> 234 </item>
248 <item row="4" column="0"> 235 <item row="3" column="1">
249 <widget class="QLabel" name="label_console_id">
250 <property name="text">
251 <string>Console ID:</string>
252 </property>
253 </widget>
254 </item>
255 <item row="4" column="1">
256 <widget class="QPushButton" name="button_regenerate_console_id"> 236 <widget class="QPushButton" name="button_regenerate_console_id">
257 <property name="sizePolicy"> 237 <property name="sizePolicy">
258 <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> 238 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -272,6 +252,133 @@
272 </widget> 252 </widget>
273 </item> 253 </item>
274 <item> 254 <item>
255 <widget class="QGroupBox" name="gridGroupBox">
256 <property name="title">
257 <string>Profile Manager</string>
258 </property>
259 <layout class="QGridLayout" name="gridLayout_2">
260 <property name="sizeConstraint">
261 <enum>QLayout::SetNoConstraint</enum>
262 </property>
263 <item row="0" column="0">
264 <layout class="QHBoxLayout" name="horizontalLayout_2">
265 <item>
266 <widget class="QLabel" name="label">
267 <property name="sizePolicy">
268 <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
269 <horstretch>0</horstretch>
270 <verstretch>0</verstretch>
271 </sizepolicy>
272 </property>
273 <property name="text">
274 <string>Current User</string>
275 </property>
276 </widget>
277 </item>
278 <item>
279 <widget class="QGraphicsView" name="current_user_icon">
280 <property name="minimumSize">
281 <size>
282 <width>48</width>
283 <height>48</height>
284 </size>
285 </property>
286 <property name="maximumSize">
287 <size>
288 <width>48</width>
289 <height>48</height>
290 </size>
291 </property>
292 <property name="verticalScrollBarPolicy">
293 <enum>Qt::ScrollBarAlwaysOff</enum>
294 </property>
295 <property name="horizontalScrollBarPolicy">
296 <enum>Qt::ScrollBarAlwaysOff</enum>
297 </property>
298 <property name="interactive">
299 <bool>false</bool>
300 </property>
301 </widget>
302 </item>
303 <item>
304 <widget class="QLabel" name="current_user_username">
305 <property name="sizePolicy">
306 <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
307 <horstretch>0</horstretch>
308 <verstretch>0</verstretch>
309 </sizepolicy>
310 </property>
311 <property name="text">
312 <string>Username</string>
313 </property>
314 </widget>
315 </item>
316 </layout>
317 </item>
318 <item row="1" column="0">
319 <widget class="QScrollArea" name="scrollArea">
320 <property name="sizePolicy">
321 <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
322 <horstretch>0</horstretch>
323 <verstretch>0</verstretch>
324 </sizepolicy>
325 </property>
326 <property name="frameShape">
327 <enum>QFrame::StyledPanel</enum>
328 </property>
329 <property name="widgetResizable">
330 <bool>false</bool>
331 </property>
332 </widget>
333 </item>
334 <item row="2" column="0">
335 <layout class="QHBoxLayout" name="horizontalLayout_3">
336 <item>
337 <spacer name="horizontalSpacer">
338 <property name="orientation">
339 <enum>Qt::Horizontal</enum>
340 </property>
341 <property name="sizeHint" stdset="0">
342 <size>
343 <width>40</width>
344 <height>20</height>
345 </size>
346 </property>
347 </spacer>
348 </item>
349 <item>
350 <widget class="QPushButton" name="pm_add">
351 <property name="text">
352 <string>Add</string>
353 </property>
354 </widget>
355 </item>
356 <item>
357 <widget class="QPushButton" name="pm_rename">
358 <property name="enabled">
359 <bool>false</bool>
360 </property>
361 <property name="text">
362 <string>Rename</string>
363 </property>
364 </widget>
365 </item>
366 <item>
367 <widget class="QPushButton" name="pm_remove">
368 <property name="enabled">
369 <bool>false</bool>
370 </property>
371 <property name="text">
372 <string>Remove</string>
373 </property>
374 </widget>
375 </item>
376 </layout>
377 </item>
378 </layout>
379 </widget>
380 </item>
381 <item>
275 <widget class="QLabel" name="label_disable_info"> 382 <widget class="QLabel" name="label_disable_info">
276 <property name="text"> 383 <property name="text">
277 <string>System settings are available only when game is not running.</string> 384 <string>System settings are available only when game is not running.</string>
@@ -281,19 +388,6 @@
281 </property> 388 </property>
282 </widget> 389 </widget>
283 </item> 390 </item>
284 <item>
285 <spacer name="verticalSpacer">
286 <property name="orientation">
287 <enum>Qt::Vertical</enum>
288 </property>
289 <property name="sizeHint" stdset="0">
290 <size>
291 <width>20</width>
292 <height>40</height>
293 </size>
294 </property>
295 </spacer>
296 </item>
297 </layout> 391 </layout>
298 </item> 392 </item>
299 </layout> 393 </layout>