From d8b83aa8f5a267278e06d5a113063663c8eed138 Mon Sep 17 00:00:00 2001 From: Godkratos Date: Mon, 18 May 2020 00:08:41 +1200 Subject: [PATCH] Add button to show and update current user profile on status bar --- src/yuzu/main.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++ src/yuzu/main.h | 1 + 2 files changed, 59 insertions(+) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 0b291c7d0c..92f2d2e70e 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -441,6 +441,20 @@ void GMainWindow::WebBrowserOpenPage(std::string_view filename, std::string_view #endif +QString GetAccountUsername() { + Service::Account::ProfileManager manager; + const auto current_user = manager.GetUser(Settings::values.current_user); + ASSERT(current_user); + Service::Account::ProfileBase profile; + if (!manager.GetProfileBase(*current_user, profile)) { + return {}; + } + + const auto text = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(profile.username.data()), profile.username.size()); + return QString::fromStdString(text); +} + void GMainWindow::InitializeWidgets() { #ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING ui.action_Report_Compatibility->setVisible(true); @@ -493,6 +507,48 @@ void GMainWindow::InitializeWidgets() { statusBar()->addPermanentWidget(label); } + // Setup Profile button + profile_status_button = new QPushButton(); + profile_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); + profile_status_button->setCheckable(true); + profile_status_button->setChecked(true); + profile_status_button->setFocusPolicy(Qt::NoFocus); + const auto username = GetAccountUsername(); + profile_status_button->setText(username); + connect(profile_status_button, &QPushButton::clicked, [=] { + profile_status_button->setChecked(true); + + if (emulation_running) { + return; + } + + // User save data + const auto select_profile = [this] { + QtProfileSelectionDialog dialog(this); + dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | + Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); + dialog.setWindowModality(Qt::WindowModal); + + if (dialog.exec() == QDialog::Rejected) { + return -1; + } + + return dialog.GetIndex(); + }; + + const auto index = select_profile(); + if (index == -1) { + return; + } + + Settings::values.current_user = index; + Settings::Apply(); + + const auto username = GetAccountUsername(); + profile_status_button->setText(username); + }); + statusBar()->insertPermanentWidget(0, profile_status_button); + // Setup Dock button dock_status_button = new QPushButton(); dock_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); @@ -1902,6 +1958,8 @@ void GMainWindow::OnConfigure() { ui.centralwidget->setMouseTracking(false); } + const auto username = GetAccountUsername(); + profile_status_button->setText(username); dock_status_button->setChecked(Settings::values.use_docked_mode); async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); #ifdef HAS_VULKAN diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 4f4c8ddbee..589081fa2e 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -233,6 +233,7 @@ private: QLabel* emu_speed_label = nullptr; QLabel* game_fps_label = nullptr; QLabel* emu_frametime_label = nullptr; + QPushButton* profile_status_button = nullptr; QPushButton* async_status_button = nullptr; QPushButton* renderer_status_button = nullptr; QPushButton* dock_status_button = nullptr;