2016-06-01 07:43:33 +00:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-10-11 01:49:20 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <QFileDialog>
|
2018-10-10 01:53:04 +00:00
|
|
|
#include <QGraphicsItem>
|
2018-10-11 01:49:20 +00:00
|
|
|
#include <QGraphicsScene>
|
2018-10-28 22:11:17 +00:00
|
|
|
#include <QHeaderView>
|
2017-05-06 00:55:51 +00:00
|
|
|
#include <QMessageBox>
|
2018-10-11 01:49:20 +00:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QTreeView>
|
|
|
|
#include <QVBoxLayout>
|
2018-10-28 22:11:17 +00:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/file_util.h"
|
2018-10-11 13:16:32 +00:00
|
|
|
#include "common/string_util.h"
|
2017-02-20 02:37:14 +00:00
|
|
|
#include "core/core.h"
|
2018-10-24 13:25:13 +00:00
|
|
|
#include "core/hle/service/acc/profile_manager.h"
|
2018-08-03 15:02:55 +00:00
|
|
|
#include "core/settings.h"
|
2016-09-20 15:21:23 +00:00
|
|
|
#include "ui_configure_system.h"
|
2018-01-12 03:33:56 +00:00
|
|
|
#include "yuzu/configuration/configure_system.h"
|
2018-10-28 22:11:17 +00:00
|
|
|
#include "yuzu/util/limitable_input_dialog.h"
|
2018-01-12 03:33:56 +00:00
|
|
|
|
2018-10-25 20:58:37 +00:00
|
|
|
namespace {
|
|
|
|
constexpr std::array<int, 12> days_in_month = {{
|
2018-01-20 07:48:02 +00:00
|
|
|
31,
|
|
|
|
29,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
|
|
|
30,
|
|
|
|
31,
|
2016-09-19 01:01:46 +00:00
|
|
|
}};
|
2016-06-01 07:43:33 +00:00
|
|
|
|
2018-10-10 01:53:04 +00:00
|
|
|
// Same backup JPEG used by acc IProfile::GetImage if no jpeg found
|
2018-10-25 20:58:37 +00:00
|
|
|
constexpr std::array<u8, 107> backup_jpeg{
|
2018-10-10 01:53:04 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2018-10-26 23:28:47 +00:00
|
|
|
QString GetImagePath(Service::Account::UUID uuid) {
|
|
|
|
const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
|
|
|
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
|
|
|
|
return QString::fromStdString(path);
|
2018-10-25 20:58:37 +00:00
|
|
|
}
|
|
|
|
|
2018-10-26 23:36:41 +00:00
|
|
|
QString GetAccountUsername(const Service::Account::ProfileManager& manager,
|
|
|
|
Service::Account::UUID uuid) {
|
2018-10-25 20:58:37 +00:00
|
|
|
Service::Account::ProfileBase profile;
|
|
|
|
if (!manager.GetProfileBase(uuid, profile)) {
|
2018-10-26 23:36:41 +00:00
|
|
|
return {};
|
2018-10-25 20:58:37 +00:00
|
|
|
}
|
|
|
|
|
2018-10-26 23:36:41 +00:00
|
|
|
const auto text = Common::StringFromFixedZeroTerminatedBuffer(
|
2018-10-25 20:58:37 +00:00
|
|
|
reinterpret_cast<const char*>(profile.username.data()), profile.username.size());
|
2018-10-26 23:36:41 +00:00
|
|
|
return QString::fromStdString(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FormatUserEntryText(const QString& username, Service::Account::UUID uuid) {
|
|
|
|
return ConfigureSystem::tr("%1\n%2",
|
|
|
|
"%1 is the profile username, %2 is the formatted UUID (e.g. "
|
|
|
|
"00112233-4455-6677-8899-AABBCCDDEEFF))")
|
|
|
|
.arg(username, QString::fromStdString(uuid.FormatSwitch()));
|
2018-10-25 20:58:37 +00:00
|
|
|
}
|
2018-10-26 23:28:47 +00:00
|
|
|
|
|
|
|
QPixmap GetIcon(Service::Account::UUID uuid) {
|
|
|
|
QPixmap icon{GetImagePath(uuid)};
|
|
|
|
|
|
|
|
if (!icon) {
|
|
|
|
icon.fill(Qt::black);
|
2018-10-28 20:13:09 +00:00
|
|
|
icon.loadFromData(backup_jpeg.data(), static_cast<u32>(backup_jpeg.size()));
|
2018-10-26 23:28:47 +00:00
|
|
|
}
|
|
|
|
|
2018-10-26 23:46:38 +00:00
|
|
|
return icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
2018-10-26 23:28:47 +00:00
|
|
|
}
|
2018-10-28 22:11:17 +00:00
|
|
|
|
|
|
|
QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_text) {
|
|
|
|
return LimitableInputDialog::GetText(parent, ConfigureSystem::tr("Enter Username"),
|
|
|
|
description_text, 1,
|
|
|
|
static_cast<int>(Service::Account::profile_username_size));
|
|
|
|
}
|
2018-10-25 20:58:37 +00:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
2018-10-11 01:49:20 +00:00
|
|
|
ConfigureSystem::ConfigureSystem(QWidget* parent)
|
|
|
|
: QWidget(parent), ui(new Ui::ConfigureSystem),
|
|
|
|
profile_manager(std::make_unique<Service::Account::ProfileManager>()) {
|
2016-06-01 07:43:33 +00:00
|
|
|
ui->setupUi(this);
|
2017-05-06 00:55:51 +00:00
|
|
|
connect(ui->combo_birthmonth,
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
2018-10-25 20:47:09 +00:00
|
|
|
&ConfigureSystem::UpdateBirthdayComboBox);
|
2017-05-06 00:55:51 +00:00
|
|
|
connect(ui->button_regenerate_console_id, &QPushButton::clicked, this,
|
2018-10-25 20:47:09 +00:00
|
|
|
&ConfigureSystem::RefreshConsoleID);
|
2016-09-13 05:04:17 +00:00
|
|
|
|
2018-10-10 01:53:04 +00:00
|
|
|
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<QStandardItem*>>("QList<QStandardItem*>");
|
|
|
|
|
|
|
|
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);
|
2018-10-11 01:49:20 +00:00
|
|
|
connect(ui->pm_set_image, &QPushButton::pressed, this, &ConfigureSystem::SetUserImage);
|
2018-10-10 01:53:04 +00:00
|
|
|
|
|
|
|
scene = new QGraphicsScene;
|
|
|
|
ui->current_user_icon->setScene(scene);
|
|
|
|
|
2016-09-13 05:04:17 +00:00
|
|
|
this->setConfiguration();
|
2016-06-01 07:43:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 16:58:46 +00:00
|
|
|
ConfigureSystem::~ConfigureSystem() = default;
|
2016-06-01 07:43:33 +00:00
|
|
|
|
2016-09-02 12:18:45 +00:00
|
|
|
void ConfigureSystem::setConfiguration() {
|
2016-11-05 03:14:38 +00:00
|
|
|
enabled = !Core::System::GetInstance().IsPoweredOn();
|
2018-10-10 01:53:04 +00:00
|
|
|
|
2018-08-03 15:02:55 +00:00
|
|
|
ui->combo_language->setCurrentIndex(Settings::values.language_index);
|
2018-10-10 01:53:04 +00:00
|
|
|
|
|
|
|
item_model->removeRows(0, item_model->rowCount());
|
|
|
|
list_items.clear();
|
|
|
|
|
2018-10-11 01:49:20 +00:00
|
|
|
PopulateUserList();
|
2018-10-10 01:53:04 +00:00
|
|
|
UpdateCurrentUser();
|
|
|
|
}
|
|
|
|
|
2018-10-11 01:49:20 +00:00
|
|
|
void ConfigureSystem::PopulateUserList() {
|
|
|
|
const auto& profiles = profile_manager->GetAllUsers();
|
2018-10-13 17:02:33 +00:00
|
|
|
for (const auto& user : profiles) {
|
|
|
|
Service::Account::ProfileBase profile;
|
|
|
|
if (!profile_manager->GetProfileBase(user, profile))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto username = Common::StringFromFixedZeroTerminatedBuffer(
|
|
|
|
reinterpret_cast<const char*>(profile.username.data()), profile.username.size());
|
|
|
|
|
|
|
|
list_items.push_back(QList<QStandardItem*>{new QStandardItem{
|
2018-10-26 23:46:38 +00:00
|
|
|
GetIcon(user), FormatUserEntryText(QString::fromStdString(username), user)}});
|
2018-10-13 17:02:33 +00:00
|
|
|
}
|
2018-10-11 01:49:20 +00:00
|
|
|
|
|
|
|
for (const auto& item : list_items)
|
|
|
|
item_model->appendRow(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureSystem::UpdateCurrentUser() {
|
2018-10-13 17:02:33 +00:00
|
|
|
ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS);
|
2018-10-11 13:16:32 +00:00
|
|
|
|
2018-10-13 17:02:33 +00:00
|
|
|
const auto& current_user = profile_manager->GetUser(Settings::values.current_user);
|
2018-10-30 04:03:25 +00:00
|
|
|
ASSERT(current_user);
|
2018-10-25 20:58:37 +00:00
|
|
|
const auto username = GetAccountUsername(*profile_manager, *current_user);
|
2018-10-11 01:49:20 +00:00
|
|
|
|
2018-10-10 01:53:04 +00:00
|
|
|
scene->clear();
|
2018-10-11 01:49:20 +00:00
|
|
|
scene->addPixmap(
|
2018-10-13 17:02:33 +00:00
|
|
|
GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
2018-10-26 23:36:41 +00:00
|
|
|
ui->current_user_username->setText(username);
|
2016-06-01 07:43:33 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 03:33:56 +00:00
|
|
|
void ConfigureSystem::ReadSystemSettings() {}
|
2016-06-01 07:43:33 +00:00
|
|
|
|
|
|
|
void ConfigureSystem::applyConfiguration() {
|
|
|
|
if (!enabled)
|
|
|
|
return;
|
2018-10-10 01:53:04 +00:00
|
|
|
|
2018-08-03 15:02:55 +00:00
|
|
|
Settings::values.language_index = ui->combo_language->currentIndex();
|
|
|
|
Settings::Apply();
|
2016-06-01 07:43:33 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 20:47:09 +00:00
|
|
|
void ConfigureSystem::UpdateBirthdayComboBox(int birthmonth_index) {
|
2016-06-01 07:43:33 +00:00
|
|
|
if (birthmonth_index < 0 || birthmonth_index >= 12)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// store current day selection
|
|
|
|
int birthday_index = ui->combo_birthday->currentIndex();
|
|
|
|
|
|
|
|
// get number of days in the new selected month
|
|
|
|
int days = days_in_month[birthmonth_index];
|
|
|
|
|
|
|
|
// if the selected day is out of range,
|
|
|
|
// reset it to 1st
|
|
|
|
if (birthday_index < 0 || birthday_index >= days)
|
|
|
|
birthday_index = 0;
|
|
|
|
|
|
|
|
// update the day combo box
|
|
|
|
ui->combo_birthday->clear();
|
|
|
|
for (int i = 1; i <= days; ++i) {
|
|
|
|
ui->combo_birthday->addItem(QString::number(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore the day selection
|
|
|
|
ui->combo_birthday->setCurrentIndex(birthday_index);
|
|
|
|
}
|
2017-05-06 00:55:51 +00:00
|
|
|
|
2018-10-25 20:47:09 +00:00
|
|
|
void ConfigureSystem::RefreshConsoleID() {
|
2017-05-06 00:55:51 +00:00
|
|
|
QMessageBox::StandardButton reply;
|
2018-01-13 23:49:16 +00:00
|
|
|
QString warning_text = tr("This will replace your current virtual Switch with a new one. "
|
|
|
|
"Your current virtual Switch will not be recoverable. "
|
2017-05-06 00:55:51 +00:00
|
|
|
"This might have unexpected effects in games. This might fail, "
|
|
|
|
"if you use an outdated config savegame. Continue?");
|
|
|
|
reply = QMessageBox::critical(this, tr("Warning"), warning_text,
|
|
|
|
QMessageBox::No | QMessageBox::Yes);
|
|
|
|
if (reply == QMessageBox::No)
|
|
|
|
return;
|
2017-10-13 01:21:49 +00:00
|
|
|
u64 console_id{};
|
2018-01-17 16:20:46 +00:00
|
|
|
ui->label_console_id->setText(
|
|
|
|
tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper()));
|
2017-05-06 00:55:51 +00:00
|
|
|
}
|
2018-10-10 01:53:04 +00:00
|
|
|
|
|
|
|
void ConfigureSystem::SelectUser(const QModelIndex& index) {
|
|
|
|
Settings::values.current_user =
|
2018-11-06 15:38:10 +00:00
|
|
|
std::clamp<s32>(index.row(), 0, static_cast<s32>(profile_manager->GetUserCount() - 1));
|
2018-10-10 01:53:04 +00:00
|
|
|
|
|
|
|
UpdateCurrentUser();
|
|
|
|
|
2018-10-11 01:49:20 +00:00
|
|
|
ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2);
|
2018-10-10 01:53:04 +00:00
|
|
|
ui->pm_rename->setEnabled(true);
|
2018-10-11 01:49:20 +00:00
|
|
|
ui->pm_set_image->setEnabled(true);
|
2018-10-10 01:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureSystem::AddUser() {
|
|
|
|
const auto username =
|
2018-10-28 22:11:17 +00:00
|
|
|
GetProfileUsernameFromUser(this, tr("Enter a username for the new user:"));
|
|
|
|
if (username.isEmpty()) {
|
2018-10-11 01:49:20 +00:00
|
|
|
return;
|
2018-10-28 22:11:17 +00:00
|
|
|
}
|
2018-10-10 01:53:04 +00:00
|
|
|
|
2018-10-28 22:11:17 +00:00
|
|
|
const auto uuid = Service::Account::UUID::Generate();
|
2018-10-11 01:49:20 +00:00
|
|
|
profile_manager->CreateNewUser(uuid, username.toStdString());
|
2018-10-10 01:53:04 +00:00
|
|
|
|
2018-10-26 23:46:38 +00:00
|
|
|
item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)});
|
2018-10-10 01:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureSystem::RenameUser() {
|
|
|
|
const auto user = tree_view->currentIndex().row();
|
2018-10-13 17:02:33 +00:00
|
|
|
const auto uuid = profile_manager->GetUser(user);
|
2018-10-30 04:03:25 +00:00
|
|
|
ASSERT(uuid);
|
2018-10-11 01:49:20 +00:00
|
|
|
|
|
|
|
Service::Account::ProfileBase profile;
|
2018-10-13 17:02:33 +00:00
|
|
|
if (!profile_manager->GetProfileBase(*uuid, profile))
|
2018-10-11 01:49:20 +00:00
|
|
|
return;
|
2018-10-10 01:53:04 +00:00
|
|
|
|
2018-10-28 22:11:17 +00:00
|
|
|
const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:"));
|
|
|
|
if (new_username.isEmpty()) {
|
2018-10-10 01:53:04 +00:00
|
|
|
return;
|
2018-10-28 22:11:17 +00:00
|
|
|
}
|
2018-10-10 01:53:04 +00:00
|
|
|
|
2018-10-11 01:49:20 +00:00
|
|
|
const auto username_std = new_username.toStdString();
|
2018-10-28 22:11:17 +00:00
|
|
|
std::fill(profile.username.begin(), profile.username.end(), '\0');
|
|
|
|
std::copy(username_std.begin(), username_std.end(), profile.username.begin());
|
2018-10-10 01:53:04 +00:00
|
|
|
|
2018-10-13 17:02:33 +00:00
|
|
|
profile_manager->SetProfileBase(*uuid, profile);
|
2018-10-11 01:49:20 +00:00
|
|
|
|
2018-10-11 13:16:32 +00:00
|
|
|
item_model->setItem(
|
|
|
|
user, 0,
|
2018-10-26 23:46:38 +00:00
|
|
|
new QStandardItem{GetIcon(*uuid),
|
|
|
|
FormatUserEntryText(QString::fromStdString(username_std), *uuid)});
|
2018-10-11 13:16:32 +00:00
|
|
|
UpdateCurrentUser();
|
2018-10-10 01:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureSystem::DeleteUser() {
|
2018-10-11 01:49:20 +00:00
|
|
|
const auto index = tree_view->currentIndex().row();
|
2018-10-13 17:02:33 +00:00
|
|
|
const auto uuid = profile_manager->GetUser(index);
|
2018-10-30 04:03:25 +00:00
|
|
|
ASSERT(uuid);
|
2018-10-25 20:58:37 +00:00
|
|
|
const auto username = GetAccountUsername(*profile_manager, *uuid);
|
2018-10-11 01:49:20 +00:00
|
|
|
|
2018-10-26 23:36:41 +00:00
|
|
|
const auto confirm = QMessageBox::question(
|
|
|
|
this, tr("Confirm Delete"),
|
|
|
|
tr("You are about to delete user with name \"%1\". Are you sure?").arg(username));
|
2018-10-10 01:53:04 +00:00
|
|
|
|
|
|
|
if (confirm == QMessageBox::No)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Settings::values.current_user == tree_view->currentIndex().row())
|
|
|
|
Settings::values.current_user = 0;
|
2018-10-11 13:16:32 +00:00
|
|
|
UpdateCurrentUser();
|
2018-10-10 01:53:04 +00:00
|
|
|
|
2018-10-13 17:02:33 +00:00
|
|
|
if (!profile_manager->RemoveUser(*uuid))
|
2018-10-11 01:49:20 +00:00
|
|
|
return;
|
2018-10-10 01:53:04 +00:00
|
|
|
|
2018-10-11 01:49:20 +00:00
|
|
|
item_model->removeRows(tree_view->currentIndex().row(), 1);
|
2018-10-11 13:16:32 +00:00
|
|
|
tree_view->clearSelection();
|
2018-10-10 01:53:04 +00:00
|
|
|
|
|
|
|
ui->pm_remove->setEnabled(false);
|
|
|
|
ui->pm_rename->setEnabled(false);
|
|
|
|
}
|
2018-10-11 01:49:20 +00:00
|
|
|
|
|
|
|
void ConfigureSystem::SetUserImage() {
|
|
|
|
const auto index = tree_view->currentIndex().row();
|
2018-10-13 17:02:33 +00:00
|
|
|
const auto uuid = profile_manager->GetUser(index);
|
2018-10-30 04:03:25 +00:00
|
|
|
ASSERT(uuid);
|
2018-10-11 01:49:20 +00:00
|
|
|
|
|
|
|
const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(),
|
2018-10-25 21:03:31 +00:00
|
|
|
tr("JPEG Images (*.jpg *.jpeg)"));
|
2018-10-11 01:49:20 +00:00
|
|
|
|
2018-10-26 23:28:47 +00:00
|
|
|
if (file.isEmpty()) {
|
2018-10-11 01:49:20 +00:00
|
|
|
return;
|
2018-10-26 23:28:47 +00:00
|
|
|
}
|
2018-10-11 01:49:20 +00:00
|
|
|
|
2018-10-26 23:28:47 +00:00
|
|
|
const auto image_path = GetImagePath(*uuid);
|
|
|
|
if (QFile::exists(image_path) && !QFile::remove(image_path)) {
|
|
|
|
QMessageBox::warning(
|
|
|
|
this, tr("Error deleting image"),
|
|
|
|
tr("Error occurred attempting to overwrite previous image at: %1.").arg(image_path));
|
|
|
|
return;
|
|
|
|
}
|
2018-10-11 01:49:20 +00:00
|
|
|
|
2018-10-26 23:28:47 +00:00
|
|
|
const auto raw_path = QString::fromStdString(
|
|
|
|
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010");
|
|
|
|
const QFileInfo raw_info{raw_path};
|
|
|
|
if (raw_info.exists() && !raw_info.isDir() && !QFile::remove(raw_path)) {
|
|
|
|
QMessageBox::warning(this, tr("Error deleting file"),
|
|
|
|
tr("Unable to delete existing file: %1.").arg(raw_path));
|
|
|
|
return;
|
|
|
|
}
|
2018-10-11 01:49:20 +00:00
|
|
|
|
2018-10-26 23:28:47 +00:00
|
|
|
const QString absolute_dst_path = QFileInfo{image_path}.absolutePath();
|
|
|
|
if (!QDir{raw_path}.mkpath(absolute_dst_path)) {
|
|
|
|
QMessageBox::warning(
|
|
|
|
this, tr("Error creating user image directory"),
|
|
|
|
tr("Unable to create directory %1 for storing user images.").arg(absolute_dst_path));
|
|
|
|
return;
|
|
|
|
}
|
2018-10-11 01:49:20 +00:00
|
|
|
|
2018-10-26 23:28:47 +00:00
|
|
|
if (!QFile::copy(file, image_path)) {
|
|
|
|
QMessageBox::warning(this, tr("Error copying user image"),
|
|
|
|
tr("Unable to copy image from %1 to %2").arg(file, image_path));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto username = GetAccountUsername(*profile_manager, *uuid);
|
2018-10-26 23:46:38 +00:00
|
|
|
item_model->setItem(index, 0,
|
|
|
|
new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)});
|
2018-10-11 13:16:32 +00:00
|
|
|
UpdateCurrentUser();
|
2018-10-11 01:49:20 +00:00
|
|
|
}
|