2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-11-23 03:03:33 +01:00
|
|
|
|
|
|
|
#include <mutex>
|
2021-11-28 06:26:51 +01:00
|
|
|
#include <QApplication>
|
2018-11-23 03:03:33 +01:00
|
|
|
#include <QDialogButtonBox>
|
2019-02-16 16:19:29 +01:00
|
|
|
#include <QHeaderView>
|
2018-11-23 03:03:33 +01:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QStandardItemModel>
|
2022-03-19 06:16:04 +01:00
|
|
|
#include <QTreeView>
|
2018-11-23 03:03:33 +01:00
|
|
|
#include <QVBoxLayout>
|
2021-05-26 01:32:56 +02:00
|
|
|
#include "common/fs/path_util.h"
|
2018-11-23 03:03:33 +01:00
|
|
|
#include "common/string_util.h"
|
2019-06-07 23:46:52 +02:00
|
|
|
#include "core/constants.h"
|
2021-07-14 06:29:12 +02:00
|
|
|
#include "yuzu/applets/qt_profile_select.h"
|
2018-11-23 03:03:33 +01:00
|
|
|
#include "yuzu/main.h"
|
2021-11-28 06:26:51 +01:00
|
|
|
#include "yuzu/util/controller_navigation.h"
|
2018-11-23 03:03:33 +01:00
|
|
|
|
2020-04-17 04:43:33 +02:00
|
|
|
namespace {
|
2022-02-05 18:35:39 +01:00
|
|
|
QString FormatUserEntryText(const QString& username, Common::UUID uuid) {
|
2018-11-23 03:03:33 +01:00
|
|
|
return QtProfileSelectionDialog::tr(
|
|
|
|
"%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. "
|
|
|
|
"00112233-4455-6677-8899-AABBCCDDEEFF))")
|
2022-02-05 18:29:09 +01:00
|
|
|
.arg(username, QString::fromStdString(uuid.FormattedString()));
|
2018-11-23 03:03:33 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 18:35:39 +01:00
|
|
|
QString GetImagePath(Common::UUID uuid) {
|
2021-05-26 01:32:56 +02:00
|
|
|
const auto path =
|
|
|
|
Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) /
|
2022-02-05 18:29:09 +01:00
|
|
|
fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormattedString());
|
2021-05-26 01:32:56 +02:00
|
|
|
return QString::fromStdString(Common::FS::PathToUTF8String(path));
|
2018-11-23 03:03:33 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 18:35:39 +01:00
|
|
|
QPixmap GetIcon(Common::UUID uuid) {
|
2018-11-23 03:03:33 +01:00
|
|
|
QPixmap icon{GetImagePath(uuid)};
|
|
|
|
|
|
|
|
if (!icon) {
|
|
|
|
icon.fill(Qt::black);
|
2019-06-07 23:46:52 +02:00
|
|
|
icon.loadFromData(Core::Constants::ACCOUNT_BACKUP_JPEG.data(),
|
|
|
|
static_cast<u32>(Core::Constants::ACCOUNT_BACKUP_JPEG.size()));
|
2018-11-23 03:03:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
|
|
}
|
2020-04-17 04:43:33 +02:00
|
|
|
} // Anonymous namespace
|
2018-11-23 03:03:33 +01:00
|
|
|
|
2023-03-29 04:55:06 +02:00
|
|
|
QtProfileSelectionDialog::QtProfileSelectionDialog(
|
|
|
|
Core::HID::HIDCore& hid_core, QWidget* parent,
|
|
|
|
const Core::Frontend::ProfileSelectParameters& parameters)
|
2018-11-23 03:03:33 +01:00
|
|
|
: QDialog(parent), profile_manager(std::make_unique<Service::Account::ProfileManager>()) {
|
|
|
|
outer_layout = new QVBoxLayout;
|
|
|
|
|
2023-03-29 04:55:06 +02:00
|
|
|
instruction_label = new QLabel();
|
2018-11-23 03:03:33 +01:00
|
|
|
|
|
|
|
scroll_area = new QScrollArea;
|
|
|
|
|
2019-04-03 17:06:15 +02:00
|
|
|
buttons = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
2018-11-23 03:03:33 +01:00
|
|
|
connect(buttons, &QDialogButtonBox::accepted, this, &QtProfileSelectionDialog::accept);
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, this, &QtProfileSelectionDialog::reject);
|
|
|
|
|
|
|
|
outer_layout->addWidget(instruction_label);
|
|
|
|
outer_layout->addWidget(scroll_area);
|
|
|
|
outer_layout->addWidget(buttons);
|
|
|
|
|
|
|
|
layout = new QVBoxLayout;
|
|
|
|
tree_view = new QTreeView;
|
|
|
|
item_model = new QStandardItemModel(tree_view);
|
|
|
|
tree_view->setModel(item_model);
|
2021-11-28 06:26:51 +01:00
|
|
|
controller_navigation = new ControllerNavigation(hid_core, this);
|
2018-11-23 03:03:33 +01:00
|
|
|
|
|
|
|
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);
|
2019-05-19 07:17:53 +02:00
|
|
|
item_model->setHeaderData(0, Qt::Horizontal, tr("Users"));
|
2018-11-23 03:03:33 +01:00
|
|
|
|
|
|
|
// We must register all custom types with the Qt Automoc system so that we are able to use it
|
2019-05-19 07:17:53 +02:00
|
|
|
// with signals/slots. In this case, QList falls under the umbrella of custom types.
|
2018-11-23 03:03:33 +01:00
|
|
|
qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>");
|
|
|
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
layout->addWidget(tree_view);
|
|
|
|
|
|
|
|
scroll_area->setLayout(layout);
|
|
|
|
|
|
|
|
connect(tree_view, &QTreeView::clicked, this, &QtProfileSelectionDialog::SelectUser);
|
2023-05-07 18:05:42 +02:00
|
|
|
connect(tree_view, &QTreeView::doubleClicked, this, &QtProfileSelectionDialog::accept);
|
2021-11-28 06:26:51 +01:00
|
|
|
connect(controller_navigation, &ControllerNavigation::TriggerKeyboardEvent,
|
|
|
|
[this](Qt::Key key) {
|
|
|
|
if (!this->isActiveWindow()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier);
|
|
|
|
QCoreApplication::postEvent(tree_view, event);
|
2022-08-05 17:02:04 +02:00
|
|
|
SelectUser(tree_view->currentIndex());
|
2021-11-28 06:26:51 +01:00
|
|
|
});
|
2018-11-23 03:03:33 +01:00
|
|
|
|
|
|
|
const auto& profiles = profile_manager->GetAllUsers();
|
|
|
|
for (const auto& user : profiles) {
|
2021-01-15 09:33:33 +01:00
|
|
|
Service::Account::ProfileBase profile{};
|
2018-11-23 03:03:33 +01:00
|
|
|
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{
|
|
|
|
GetIcon(user), FormatUserEntryText(QString::fromStdString(username), user)}});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& item : list_items)
|
|
|
|
item_model->appendRow(item);
|
|
|
|
|
|
|
|
setLayout(outer_layout);
|
2023-03-29 04:55:06 +02:00
|
|
|
SetWindowTitle(parameters);
|
|
|
|
SetDialogPurpose(parameters);
|
2018-11-23 03:03:33 +01:00
|
|
|
resize(550, 400);
|
|
|
|
}
|
|
|
|
|
2021-11-28 06:26:51 +01:00
|
|
|
QtProfileSelectionDialog::~QtProfileSelectionDialog() {
|
|
|
|
controller_navigation->UnloadController();
|
|
|
|
};
|
2018-11-23 03:03:33 +01:00
|
|
|
|
2020-10-21 20:36:57 +02:00
|
|
|
int QtProfileSelectionDialog::exec() {
|
|
|
|
// Skip profile selection when there's only one.
|
|
|
|
if (profile_manager->GetUserCount() == 1) {
|
|
|
|
user_index = 0;
|
|
|
|
return QDialog::Accepted;
|
|
|
|
}
|
2020-10-25 14:16:43 +01:00
|
|
|
return QDialog::exec();
|
2020-10-21 20:36:57 +02:00
|
|
|
}
|
|
|
|
|
2018-11-23 03:03:33 +01:00
|
|
|
void QtProfileSelectionDialog::accept() {
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProfileSelectionDialog::reject() {
|
|
|
|
user_index = 0;
|
|
|
|
QDialog::reject();
|
|
|
|
}
|
|
|
|
|
2019-05-29 06:23:46 +02:00
|
|
|
int QtProfileSelectionDialog::GetIndex() const {
|
2018-11-23 03:03:33 +01:00
|
|
|
return user_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProfileSelectionDialog::SelectUser(const QModelIndex& index) {
|
|
|
|
user_index = index.row();
|
|
|
|
}
|
|
|
|
|
2023-03-29 04:55:06 +02:00
|
|
|
void QtProfileSelectionDialog::SetWindowTitle(
|
|
|
|
const Core::Frontend::ProfileSelectParameters& parameters) {
|
|
|
|
using Service::AM::Applets::UiMode;
|
|
|
|
switch (parameters.mode) {
|
|
|
|
case UiMode::UserCreator:
|
|
|
|
case UiMode::UserCreatorForStarter:
|
|
|
|
setWindowTitle(tr("Profile Creator"));
|
|
|
|
return;
|
|
|
|
case UiMode::EnsureNetworkServiceAccountAvailable:
|
|
|
|
setWindowTitle(tr("Profile Selector"));
|
|
|
|
return;
|
|
|
|
case UiMode::UserIconEditor:
|
|
|
|
setWindowTitle(tr("Profile Icon Editor"));
|
|
|
|
return;
|
|
|
|
case UiMode::UserNicknameEditor:
|
|
|
|
setWindowTitle(tr("Profile Nickname Editor"));
|
|
|
|
return;
|
|
|
|
case UiMode::NintendoAccountAuthorizationRequestContext:
|
|
|
|
case UiMode::IntroduceExternalNetworkServiceAccount:
|
|
|
|
case UiMode::IntroduceExternalNetworkServiceAccountForRegistration:
|
|
|
|
case UiMode::NintendoAccountNnidLinker:
|
|
|
|
case UiMode::LicenseRequirementsForNetworkService:
|
|
|
|
case UiMode::LicenseRequirementsForNetworkServiceWithUserContextImpl:
|
|
|
|
case UiMode::UserCreatorForImmediateNaLoginTest:
|
|
|
|
case UiMode::UserQualificationPromoter:
|
|
|
|
case UiMode::UserSelector:
|
|
|
|
default:
|
|
|
|
setWindowTitle(tr("Profile Selector"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProfileSelectionDialog::SetDialogPurpose(
|
|
|
|
const Core::Frontend::ProfileSelectParameters& parameters) {
|
|
|
|
using Service::AM::Applets::UserSelectionPurpose;
|
|
|
|
|
|
|
|
switch (parameters.purpose) {
|
|
|
|
case UserSelectionPurpose::GameCardRegistration:
|
|
|
|
instruction_label->setText(tr("Who will receive the points?"));
|
|
|
|
return;
|
|
|
|
case UserSelectionPurpose::EShopLaunch:
|
|
|
|
instruction_label->setText(tr("Who is using Nintendo eShop?"));
|
|
|
|
return;
|
|
|
|
case UserSelectionPurpose::EShopItemShow:
|
|
|
|
instruction_label->setText(tr("Who is making this purchase?"));
|
|
|
|
return;
|
|
|
|
case UserSelectionPurpose::PicturePost:
|
|
|
|
instruction_label->setText(tr("Who is posting?"));
|
|
|
|
return;
|
|
|
|
case UserSelectionPurpose::NintendoAccountLinkage:
|
|
|
|
instruction_label->setText(tr("Select a user to link to a Nintendo Account."));
|
|
|
|
return;
|
|
|
|
case UserSelectionPurpose::SettingsUpdate:
|
|
|
|
instruction_label->setText(tr("Change settings for which user?"));
|
|
|
|
return;
|
|
|
|
case UserSelectionPurpose::SaveDataDeletion:
|
|
|
|
instruction_label->setText(tr("Format data for which user?"));
|
|
|
|
return;
|
|
|
|
case UserSelectionPurpose::UserMigration:
|
|
|
|
instruction_label->setText(tr("Which user will be transferred to another console?"));
|
|
|
|
return;
|
|
|
|
case UserSelectionPurpose::SaveDataTransfer:
|
|
|
|
instruction_label->setText(tr("Send save data for which user?"));
|
|
|
|
return;
|
|
|
|
case UserSelectionPurpose::General:
|
|
|
|
default:
|
|
|
|
instruction_label->setText(tr("Select a user:"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-23 03:03:33 +01:00
|
|
|
QtProfileSelector::QtProfileSelector(GMainWindow& parent) {
|
|
|
|
connect(this, &QtProfileSelector::MainWindowSelectProfile, &parent,
|
|
|
|
&GMainWindow::ProfileSelectorSelectProfile, Qt::QueuedConnection);
|
2023-03-25 18:29:08 +01:00
|
|
|
connect(this, &QtProfileSelector::MainWindowRequestExit, &parent,
|
|
|
|
&GMainWindow::ProfileSelectorRequestExit, Qt::QueuedConnection);
|
2018-11-23 03:03:33 +01:00
|
|
|
connect(&parent, &GMainWindow::ProfileSelectorFinishedSelection, this,
|
|
|
|
&QtProfileSelector::MainWindowFinishedSelection, Qt::DirectConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
QtProfileSelector::~QtProfileSelector() = default;
|
|
|
|
|
2023-03-25 18:29:08 +01:00
|
|
|
void QtProfileSelector::Close() const {
|
|
|
|
callback = {};
|
|
|
|
emit MainWindowRequestExit();
|
|
|
|
}
|
|
|
|
|
2023-03-29 04:55:06 +02:00
|
|
|
void QtProfileSelector::SelectProfile(
|
|
|
|
SelectProfileCallback callback_,
|
|
|
|
const Core::Frontend::ProfileSelectParameters& parameters) const {
|
2020-12-05 14:37:13 +01:00
|
|
|
callback = std::move(callback_);
|
2023-03-29 04:55:06 +02:00
|
|
|
emit MainWindowSelectProfile(parameters);
|
2018-11-23 03:03:33 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 18:35:39 +01:00
|
|
|
void QtProfileSelector::MainWindowFinishedSelection(std::optional<Common::UUID> uuid) {
|
2023-03-25 18:29:08 +01:00
|
|
|
if (callback) {
|
|
|
|
callback(uuid);
|
|
|
|
}
|
2018-11-23 03:03:33 +01:00
|
|
|
}
|