From b2a8209c5be07f045ad6823eb6a0246a9a537a34 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 9 Oct 2018 21:53:04 -0400 Subject: qt: Add Profile Manager UI to system settings --- src/yuzu/configuration/configure_system.cpp | 165 +++++++++++++++++++++++++++- 1 file changed, 163 insertions(+), 2 deletions(-) (limited to 'src/yuzu/configuration/configure_system.cpp') 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 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include +#include #include +#include +#include "common/common_paths.h" +#include "common/logging/backend.h" #include "core/core.h" #include "core/settings.h" #include "ui_configure_system.h" @@ -24,6 +29,17 @@ static const std::array days_in_month = {{ 31, }}; +// Same backup JPEG used by acc IProfile::GetImage if no jpeg found +static constexpr std::array backup_jpeg{ + 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, + 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, + 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, + 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, + 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, + 0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, + 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, +}; + ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) { ui->setupUi(this); connect(ui->combo_birthmonth, @@ -32,6 +48,44 @@ ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui:: connect(ui->button_regenerate_console_id, &QPushButton::clicked, this, &ConfigureSystem::refreshConsoleID); + layout = new QVBoxLayout; + tree_view = new QTreeView; + item_model = new QStandardItemModel(tree_view); + tree_view->setModel(item_model); + + tree_view->setAlternatingRowColors(true); + tree_view->setSelectionMode(QHeaderView::SingleSelection); + tree_view->setSelectionBehavior(QHeaderView::SelectRows); + tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel); + tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel); + tree_view->setSortingEnabled(true); + tree_view->setEditTriggers(QHeaderView::NoEditTriggers); + tree_view->setUniformRowHeights(true); + tree_view->setIconSize({64, 64}); + tree_view->setContextMenuPolicy(Qt::NoContextMenu); + + item_model->insertColumns(0, 1); + item_model->setHeaderData(0, Qt::Horizontal, "Users"); + + // We must register all custom types with the Qt Automoc system so that we are able to use it + // with signals/slots. In this case, QList falls under the umbrells of custom types. + qRegisterMetaType>("QList"); + + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + layout->addWidget(tree_view); + + ui->scrollArea->setLayout(layout); + + connect(tree_view, &QTreeView::clicked, this, &ConfigureSystem::SelectUser); + + connect(ui->pm_add, &QPushButton::pressed, this, &ConfigureSystem::AddUser); + connect(ui->pm_rename, &QPushButton::pressed, this, &ConfigureSystem::RenameUser); + connect(ui->pm_remove, &QPushButton::pressed, this, &ConfigureSystem::DeleteUser); + + scene = new QGraphicsScene; + ui->current_user_icon->setScene(scene); + this->setConfiguration(); } @@ -39,8 +93,51 @@ ConfigureSystem::~ConfigureSystem() = default; void ConfigureSystem::setConfiguration() { enabled = !Core::System::GetInstance().IsPoweredOn(); - ui->edit_username->setText(QString::fromStdString(Settings::values.username)); + ui->combo_language->setCurrentIndex(Settings::values.language_index); + + item_model->removeRows(0, item_model->rowCount()); + list_items.clear(); + + std::transform(Settings::values.users.begin(), Settings::values.users.end(), + std::back_inserter(list_items), + [](const std::pair& user) { + const auto icon_url = QString::fromStdString( + FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "users" + + DIR_SEP + user.first + ".jpg"); + QPixmap icon{icon_url}; + + if (!icon) { + icon.fill(QColor::fromRgb(0, 0, 0)); + icon.loadFromData(backup_jpeg.data(), backup_jpeg.size()); + } + + return QList{new QStandardItem{ + icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(user.first + "\n" + user.second.Format())}}; + }); + + for (const auto& item : list_items) + item_model->appendRow(item); + + UpdateCurrentUser(); +} + +void ConfigureSystem::UpdateCurrentUser() { + const auto& current_user = Settings::values.users[Settings::values.current_user]; + const auto icon_url = + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "users" + + DIR_SEP + current_user.first + ".jpg"); + QPixmap icon{icon_url}; + + if (!icon) { + icon.fill(QColor::fromRgb(0, 0, 0)); + icon.loadFromData(backup_jpeg.data(), backup_jpeg.size()); + } + + scene->clear(); + scene->addPixmap(icon.scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + ui->current_user_username->setText(QString::fromStdString(current_user.first)); } void ConfigureSystem::ReadSystemSettings() {} @@ -48,7 +145,7 @@ void ConfigureSystem::ReadSystemSettings() {} void ConfigureSystem::applyConfiguration() { if (!enabled) return; - Settings::values.username = ui->edit_username->text().toStdString(); + Settings::values.language_index = ui->combo_language->currentIndex(); Settings::Apply(); } @@ -92,3 +189,67 @@ void ConfigureSystem::refreshConsoleID() { ui->label_console_id->setText( tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper())); } + +void ConfigureSystem::SelectUser(const QModelIndex& index) { + Settings::values.current_user = + std::clamp(index.row(), 0, Settings::values.users.size() - 1); + + UpdateCurrentUser(); + + if (Settings::values.users.size() >= 2) + ui->pm_remove->setEnabled(true); + else + ui->pm_remove->setEnabled(false); + + ui->pm_rename->setEnabled(true); +} + +void ConfigureSystem::AddUser() { + Service::Account::UUID uuid; + uuid.Generate(); + + bool ok = false; + const auto username = + QInputDialog::getText(this, tr("Enter Username"), tr("Enter a username for the new user:"), + QLineEdit::Normal, QString(), &ok); + + Settings::values.users.emplace_back(username.toStdString(), uuid); + + setConfiguration(); +} + +void ConfigureSystem::RenameUser() { + const auto user = tree_view->currentIndex().row(); + + bool ok = false; + const auto new_username = QInputDialog::getText( + this, tr("Enter Username"), tr("Enter a new username:"), QLineEdit::Normal, + QString::fromStdString(Settings::values.users[user].first), &ok); + + if (!ok) + return; + + Settings::values.users[user].first = new_username.toStdString(); + + setConfiguration(); +} + +void ConfigureSystem::DeleteUser() { + const auto user = Settings::values.users.begin() + tree_view->currentIndex().row(); + const auto confirm = QMessageBox::question( + this, tr("Confirm Delete"), + tr("You are about to delete user with name %1. Are you sure?").arg(user->first.c_str())); + + if (confirm == QMessageBox::No) + return; + + if (Settings::values.current_user == tree_view->currentIndex().row()) + Settings::values.current_user = 0; + + Settings::values.users.erase(user); + + setConfiguration(); + + ui->pm_remove->setEnabled(false); + ui->pm_rename->setEnabled(false); +} -- cgit v1.2.3 From 702622b8f1eaa1b297a27a305ac56faeadf542d7 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Wed, 10 Oct 2018 21:49:20 -0400 Subject: profile_manager: Load user icons, names, and UUIDs from system save --- src/yuzu/configuration/configure_system.cpp | 179 ++++++++++++++++++++-------- 1 file changed, 132 insertions(+), 47 deletions(-) (limited to 'src/yuzu/configuration/configure_system.cpp') diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 9a41c1f6c..af2acdd45 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -2,10 +2,15 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include +#include #include -#include +#include +#include #include -#include +#include +#include +#include #include "common/common_paths.h" #include "common/logging/backend.h" #include "core/core.h" @@ -14,6 +19,11 @@ #include "yuzu/configuration/configure_system.h" #include "yuzu/main.h" +static std::string GetImagePath(Service::Account::UUID uuid) { + return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + + "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; +} + static const std::array days_in_month = {{ 31, 29, @@ -40,7 +50,9 @@ static constexpr std::array backup_jpeg{ 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, }; -ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) { +ConfigureSystem::ConfigureSystem(QWidget* parent) + : QWidget(parent), ui(new Ui::ConfigureSystem), + profile_manager(std::make_unique()) { ui->setupUi(this); connect(ui->combo_birthmonth, static_cast(&QComboBox::currentIndexChanged), this, @@ -82,6 +94,7 @@ ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui:: connect(ui->pm_add, &QPushButton::pressed, this, &ConfigureSystem::AddUser); connect(ui->pm_rename, &QPushButton::pressed, this, &ConfigureSystem::RenameUser); connect(ui->pm_remove, &QPushButton::pressed, this, &ConfigureSystem::DeleteUser); + connect(ui->pm_set_image, &QPushButton::pressed, this, &ConfigureSystem::SetUserImage); scene = new QGraphicsScene; ui->current_user_icon->setScene(scene); @@ -99,49 +112,69 @@ void ConfigureSystem::setConfiguration() { item_model->removeRows(0, item_model->rowCount()); list_items.clear(); - std::transform(Settings::values.users.begin(), Settings::values.users.end(), - std::back_inserter(list_items), - [](const std::pair& user) { - const auto icon_url = QString::fromStdString( - FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "users" + - DIR_SEP + user.first + ".jpg"); - QPixmap icon{icon_url}; - - if (!icon) { - icon.fill(QColor::fromRgb(0, 0, 0)); - icon.loadFromData(backup_jpeg.data(), backup_jpeg.size()); - } - - return QList{new QStandardItem{ - icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), - QString::fromStdString(user.first + "\n" + user.second.Format())}}; - }); - - for (const auto& item : list_items) - item_model->appendRow(item); + ui->pm_add->setEnabled(profile_manager->GetUserCount() < 8); + PopulateUserList(); UpdateCurrentUser(); } -void ConfigureSystem::UpdateCurrentUser() { - const auto& current_user = Settings::values.users[Settings::values.current_user]; - const auto icon_url = - QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "users" + - DIR_SEP + current_user.first + ".jpg"); +static QPixmap GetIcon(Service::Account::UUID uuid) { + const auto icon_url = QString::fromStdString(GetImagePath(uuid)); QPixmap icon{icon_url}; if (!icon) { - icon.fill(QColor::fromRgb(0, 0, 0)); + icon.fill(Qt::black); icon.loadFromData(backup_jpeg.data(), backup_jpeg.size()); } + return icon; +} + +void ConfigureSystem::PopulateUserList() { + const auto& profiles = profile_manager->GetAllUsers(); + std::transform( + profiles.begin(), profiles.end(), std::back_inserter(list_items), + [this](const Service::Account::UUID& user) { + Service::Account::ProfileBase profile; + if (!profile_manager->GetProfileBase(user, profile)) + return QList{}; + const auto username = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(profile.username.data()), profile.username.size()); + + return QList{new QStandardItem{ + GetIcon(user).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(username + '\n' + user.FormatSwitch())}}; + }); + + list_items.erase( + std::remove_if(list_items.begin(), list_items.end(), + [](const auto& list) { return list == QList{}; }), + list_items.end()); + + for (const auto& item : list_items) + item_model->appendRow(item); +} + +void ConfigureSystem::UpdateCurrentUser() { + const auto& current_user = profile_manager->GetAllUsers()[Settings::values.current_user]; + const auto username = GetAccountUsername(current_user); + scene->clear(); - scene->addPixmap(icon.scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - ui->current_user_username->setText(QString::fromStdString(current_user.first)); + scene->addPixmap( + GetIcon(current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + ui->current_user_username->setText(QString::fromStdString(username)); } void ConfigureSystem::ReadSystemSettings() {} +std::string ConfigureSystem::GetAccountUsername(Service::Account::UUID uuid) { + Service::Account::ProfileBase profile; + if (!profile_manager->GetProfileBase(uuid, profile)) + return ""; + return Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(profile.username.data()), profile.username.size()); +} + void ConfigureSystem::applyConfiguration() { if (!enabled) return; @@ -192,16 +225,16 @@ void ConfigureSystem::refreshConsoleID() { void ConfigureSystem::SelectUser(const QModelIndex& index) { Settings::values.current_user = - std::clamp(index.row(), 0, Settings::values.users.size() - 1); + std::clamp(index.row(), 0, profile_manager->GetUserCount() - 1); UpdateCurrentUser(); - if (Settings::values.users.size() >= 2) - ui->pm_remove->setEnabled(true); - else - ui->pm_remove->setEnabled(false); + ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2); + ui->pm_remove->setEnabled(false); ui->pm_rename->setEnabled(true); + + ui->pm_set_image->setEnabled(true); } void ConfigureSystem::AddUser() { @@ -212,33 +245,57 @@ void ConfigureSystem::AddUser() { const auto username = QInputDialog::getText(this, tr("Enter Username"), tr("Enter a username for the new user:"), QLineEdit::Normal, QString(), &ok); + if (!ok) + return; - Settings::values.users.emplace_back(username.toStdString(), uuid); + profile_manager->CreateNewUser(uuid, username.toStdString()); - setConfiguration(); + item_model->appendRow(new QStandardItem{ + GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(username.toStdString() + '\n' + uuid.FormatSwitch())}); } void ConfigureSystem::RenameUser() { const auto user = tree_view->currentIndex().row(); + ASSERT(user < 8); + + const auto uuid = profile_manager->GetAllUsers()[user]; + const auto username = GetAccountUsername(uuid); + + Service::Account::ProfileBase profile; + if (!profile_manager->GetProfileBase(uuid, profile)) + return; bool ok = false; - const auto new_username = QInputDialog::getText( - this, tr("Enter Username"), tr("Enter a new username:"), QLineEdit::Normal, - QString::fromStdString(Settings::values.users[user].first), &ok); + const auto new_username = + QInputDialog::getText(this, tr("Enter Username"), tr("Enter a new username:"), + QLineEdit::Normal, QString::fromStdString(username), &ok); if (!ok) return; - Settings::values.users[user].first = new_username.toStdString(); + const auto username_std = new_username.toStdString(); + if (username_std.size() > profile.username.size()) + std::copy_n(username_std.begin(), profile.username.size(), profile.username.begin()); + else + std::copy(username_std.begin(), username_std.end(), profile.username.begin()); - setConfiguration(); + profile_manager->SetProfileBase(uuid, profile); + + list_items[user][0] = new QStandardItem{ + GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(username_std + '\n' + uuid.FormatSwitch())}; } void ConfigureSystem::DeleteUser() { - const auto user = Settings::values.users.begin() + tree_view->currentIndex().row(); + const auto index = tree_view->currentIndex().row(); + ASSERT(index < 8); + const auto uuid = profile_manager->GetAllUsers()[index]; + const auto username = GetAccountUsername(uuid); + const auto confirm = QMessageBox::question( this, tr("Confirm Delete"), - tr("You are about to delete user with name %1. Are you sure?").arg(user->first.c_str())); + tr("You are about to delete user with name %1. Are you sure?").arg(username.c_str())); if (confirm == QMessageBox::No) return; @@ -246,10 +303,38 @@ void ConfigureSystem::DeleteUser() { if (Settings::values.current_user == tree_view->currentIndex().row()) Settings::values.current_user = 0; - Settings::values.users.erase(user); + if (!profile_manager->RemoveUser(uuid)) + return; - setConfiguration(); + item_model->removeRows(tree_view->currentIndex().row(), 1); ui->pm_remove->setEnabled(false); ui->pm_rename->setEnabled(false); } + +void ConfigureSystem::SetUserImage() { + const auto index = tree_view->currentIndex().row(); + ASSERT(index < 8); + const auto uuid = profile_manager->GetAllUsers()[index]; + const auto username = GetAccountUsername(uuid); + + const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), + "JPEG Images (*.jpg *.jpeg)"); + + if (file.isEmpty()) + return; + + FileUtil::Delete(GetImagePath(uuid)); + + const auto raw_path = + FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"; + if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path)) + FileUtil::Delete(raw_path); + + FileUtil::CreateFullPath(GetImagePath(uuid)); + FileUtil::Copy(file.toStdString(), GetImagePath(uuid)); + + list_items[index][0] = new QStandardItem{ + GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(username + '\n' + uuid.FormatSwitch())}; +} -- cgit v1.2.3 From e408bbceed90da8965480e23d05fb764fcbfbb84 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Thu, 11 Oct 2018 09:16:32 -0400 Subject: configure_system: Clear selection after user delete --- src/yuzu/configuration/configure_system.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/yuzu/configuration/configure_system.cpp') diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index af2acdd45..87301b5a2 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -13,6 +13,7 @@ #include #include "common/common_paths.h" #include "common/logging/backend.h" +#include "common/string_util.h" #include "core/core.h" #include "core/settings.h" #include "ui_configure_system.h" @@ -112,8 +113,6 @@ void ConfigureSystem::setConfiguration() { item_model->removeRows(0, item_model->rowCount()); list_items.clear(); - ui->pm_add->setEnabled(profile_manager->GetUserCount() < 8); - PopulateUserList(); UpdateCurrentUser(); } @@ -156,6 +155,8 @@ void ConfigureSystem::PopulateUserList() { } void ConfigureSystem::UpdateCurrentUser() { + ui->pm_add->setEnabled(profile_manager->GetUserCount() < 8); + const auto& current_user = profile_manager->GetAllUsers()[Settings::values.current_user]; const auto username = GetAccountUsername(current_user); @@ -230,10 +231,7 @@ void ConfigureSystem::SelectUser(const QModelIndex& index) { UpdateCurrentUser(); ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2); - ui->pm_remove->setEnabled(false); - ui->pm_rename->setEnabled(true); - ui->pm_set_image->setEnabled(true); } @@ -282,9 +280,12 @@ void ConfigureSystem::RenameUser() { profile_manager->SetProfileBase(uuid, profile); - list_items[user][0] = new QStandardItem{ - GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), - QString::fromStdString(username_std + '\n' + uuid.FormatSwitch())}; + item_model->setItem( + user, 0, + new QStandardItem{ + GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(username_std + '\n' + uuid.FormatSwitch())}); + UpdateCurrentUser(); } void ConfigureSystem::DeleteUser() { @@ -302,11 +303,13 @@ void ConfigureSystem::DeleteUser() { if (Settings::values.current_user == tree_view->currentIndex().row()) Settings::values.current_user = 0; + UpdateCurrentUser(); if (!profile_manager->RemoveUser(uuid)) return; item_model->removeRows(tree_view->currentIndex().row(), 1); + tree_view->clearSelection(); ui->pm_remove->setEnabled(false); ui->pm_rename->setEnabled(false); @@ -334,7 +337,10 @@ void ConfigureSystem::SetUserImage() { FileUtil::CreateFullPath(GetImagePath(uuid)); FileUtil::Copy(file.toStdString(), GetImagePath(uuid)); - list_items[index][0] = new QStandardItem{ - GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), - QString::fromStdString(username + '\n' + uuid.FormatSwitch())}; + item_model->setItem( + index, 0, + new QStandardItem{ + GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(username + '\n' + uuid.FormatSwitch())}); + UpdateCurrentUser(); } -- cgit v1.2.3 From 45f2a2fe29373f261144c097d169dad8b65fe012 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sat, 13 Oct 2018 13:02:33 -0400 Subject: acc: Fix account UUID duplication error --- src/yuzu/configuration/configure_system.cpp | 86 ++++++++++++++--------------- 1 file changed, 41 insertions(+), 45 deletions(-) (limited to 'src/yuzu/configuration/configure_system.cpp') diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 87301b5a2..02e061ebc 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -131,38 +131,33 @@ static QPixmap GetIcon(Service::Account::UUID uuid) { void ConfigureSystem::PopulateUserList() { const auto& profiles = profile_manager->GetAllUsers(); - std::transform( - profiles.begin(), profiles.end(), std::back_inserter(list_items), - [this](const Service::Account::UUID& user) { - Service::Account::ProfileBase profile; - if (!profile_manager->GetProfileBase(user, profile)) - return QList{}; - const auto username = Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast(profile.username.data()), profile.username.size()); - - return QList{new QStandardItem{ - GetIcon(user).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), - QString::fromStdString(username + '\n' + user.FormatSwitch())}}; - }); - - list_items.erase( - std::remove_if(list_items.begin(), list_items.end(), - [](const auto& list) { return list == QList{}; }), - list_items.end()); + for (const auto& user : profiles) { + Service::Account::ProfileBase profile; + if (!profile_manager->GetProfileBase(user, profile)) + continue; + + const auto username = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(profile.username.data()), profile.username.size()); + + list_items.push_back(QList{new QStandardItem{ + GetIcon(user).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(username + '\n' + user.FormatSwitch())}}); + } for (const auto& item : list_items) item_model->appendRow(item); } void ConfigureSystem::UpdateCurrentUser() { - ui->pm_add->setEnabled(profile_manager->GetUserCount() < 8); + ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS); - const auto& current_user = profile_manager->GetAllUsers()[Settings::values.current_user]; - const auto username = GetAccountUsername(current_user); + const auto& current_user = profile_manager->GetUser(Settings::values.current_user); + ASSERT(current_user != boost::none); + const auto username = GetAccountUsername(*current_user); scene->clear(); scene->addPixmap( - GetIcon(current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); ui->current_user_username->setText(QString::fromStdString(username)); } @@ -255,13 +250,12 @@ void ConfigureSystem::AddUser() { void ConfigureSystem::RenameUser() { const auto user = tree_view->currentIndex().row(); - ASSERT(user < 8); - - const auto uuid = profile_manager->GetAllUsers()[user]; - const auto username = GetAccountUsername(uuid); + const auto uuid = profile_manager->GetUser(user); + ASSERT(uuid != boost::none); + const auto username = GetAccountUsername(*uuid); Service::Account::ProfileBase profile; - if (!profile_manager->GetProfileBase(uuid, profile)) + if (!profile_manager->GetProfileBase(*uuid, profile)) return; bool ok = false; @@ -273,26 +267,28 @@ void ConfigureSystem::RenameUser() { return; const auto username_std = new_username.toStdString(); - if (username_std.size() > profile.username.size()) - std::copy_n(username_std.begin(), profile.username.size(), profile.username.begin()); - else + if (username_std.size() > profile.username.size()) { + std::copy_n(username_std.begin(), std::min(profile.username.size(), username_std.size()), + profile.username.begin()); + } else { std::copy(username_std.begin(), username_std.end(), profile.username.begin()); + } - profile_manager->SetProfileBase(uuid, profile); + profile_manager->SetProfileBase(*uuid, profile); item_model->setItem( user, 0, new QStandardItem{ - GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), - QString::fromStdString(username_std + '\n' + uuid.FormatSwitch())}); + GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(username_std + '\n' + uuid->FormatSwitch())}); UpdateCurrentUser(); } void ConfigureSystem::DeleteUser() { const auto index = tree_view->currentIndex().row(); - ASSERT(index < 8); - const auto uuid = profile_manager->GetAllUsers()[index]; - const auto username = GetAccountUsername(uuid); + const auto uuid = profile_manager->GetUser(index); + ASSERT(uuid != boost::none); + const auto username = GetAccountUsername(*uuid); const auto confirm = QMessageBox::question( this, tr("Confirm Delete"), @@ -305,7 +301,7 @@ void ConfigureSystem::DeleteUser() { Settings::values.current_user = 0; UpdateCurrentUser(); - if (!profile_manager->RemoveUser(uuid)) + if (!profile_manager->RemoveUser(*uuid)) return; item_model->removeRows(tree_view->currentIndex().row(), 1); @@ -317,9 +313,9 @@ void ConfigureSystem::DeleteUser() { void ConfigureSystem::SetUserImage() { const auto index = tree_view->currentIndex().row(); - ASSERT(index < 8); - const auto uuid = profile_manager->GetAllUsers()[index]; - const auto username = GetAccountUsername(uuid); + const auto uuid = profile_manager->GetUser(index); + ASSERT(uuid != boost::none); + const auto username = GetAccountUsername(*uuid); const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), "JPEG Images (*.jpg *.jpeg)"); @@ -327,20 +323,20 @@ void ConfigureSystem::SetUserImage() { if (file.isEmpty()) return; - FileUtil::Delete(GetImagePath(uuid)); + FileUtil::Delete(GetImagePath(*uuid)); const auto raw_path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"; if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path)) FileUtil::Delete(raw_path); - FileUtil::CreateFullPath(GetImagePath(uuid)); - FileUtil::Copy(file.toStdString(), GetImagePath(uuid)); + FileUtil::CreateFullPath(GetImagePath(*uuid)); + FileUtil::Copy(file.toStdString(), GetImagePath(*uuid)); item_model->setItem( index, 0, new QStandardItem{ - GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), - QString::fromStdString(username + '\n' + uuid.FormatSwitch())}); + GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + QString::fromStdString(username + '\n' + uuid->FormatSwitch())}); UpdateCurrentUser(); } -- cgit v1.2.3 From bfad41b0c12a308b0a5a10e3162d74140e3c121a Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 14 Oct 2018 14:49:32 -0400 Subject: profile_manager: Create save data if it doesn't exist on use --- src/yuzu/configuration/configure_system.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/yuzu/configuration/configure_system.cpp') diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 02e061ebc..a88fabc36 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -163,7 +163,7 @@ void ConfigureSystem::UpdateCurrentUser() { void ConfigureSystem::ReadSystemSettings() {} -std::string ConfigureSystem::GetAccountUsername(Service::Account::UUID uuid) { +std::string ConfigureSystem::GetAccountUsername(Service::Account::UUID uuid) const { Service::Account::ProfileBase profile; if (!profile_manager->GetProfileBase(uuid, profile)) return ""; -- cgit v1.2.3 From e7ac42677be6c13e5286fb42004aa94b0da45391 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Wed, 24 Oct 2018 09:25:13 -0400 Subject: configure_system: Clear current username before overwriting Prevents bug where old username would remain if the new username was shorter in length. --- src/yuzu/configuration/configure_system.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/yuzu/configuration/configure_system.cpp') diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index a88fabc36..83cc49dfc 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -15,6 +15,7 @@ #include "common/logging/backend.h" #include "common/string_util.h" #include "core/core.h" +#include "core/hle/service/acc/profile_manager.h" #include "core/settings.h" #include "ui_configure_system.h" #include "yuzu/configuration/configure_system.h" @@ -266,6 +267,7 @@ void ConfigureSystem::RenameUser() { if (!ok) return; + std::fill(profile.username.begin(), profile.username.end(), '\0'); const auto username_std = new_username.toStdString(); if (username_std.size() > profile.username.size()) { std::copy_n(username_std.begin(), std::min(profile.username.size(), username_std.size()), @@ -280,7 +282,10 @@ void ConfigureSystem::RenameUser() { user, 0, new QStandardItem{ GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), - QString::fromStdString(username_std + '\n' + uuid->FormatSwitch())}); + tr("%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. " + "00112233-4455-6677-8899-AABBCCDDEEFF))") + .arg(QString::fromStdString(username_std), + QString::fromStdString(uuid->FormatSwitch()))}); UpdateCurrentUser(); } @@ -290,9 +295,10 @@ void ConfigureSystem::DeleteUser() { ASSERT(uuid != boost::none); const auto username = GetAccountUsername(*uuid); - const auto confirm = QMessageBox::question( - this, tr("Confirm Delete"), - tr("You are about to delete user with name %1. Are you sure?").arg(username.c_str())); + const auto confirm = + QMessageBox::question(this, tr("Confirm Delete"), + tr("You are about to delete user with name %1. Are you sure?") + .arg(QString::fromStdString(username))); if (confirm == QMessageBox::No) return; -- cgit v1.2.3