yuzu-emu
/
yuzu
Archived
1
0
Fork 0

Merge pull request #9247 from lat9nq/verbose-del-warn

configure_profile_manager: Use a custom dialog when deleting a profile
This commit is contained in:
Mai 2022-11-16 02:26:20 +00:00 committed by GitHub
commit 48b4eca28a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 11 deletions

View File

@ -2,6 +2,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm> #include <algorithm>
#include <functional>
#include <QDialog>
#include <QDialogButtonBox>
#include <QFileDialog> #include <QFileDialog>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QHeaderView> #include <QHeaderView>
@ -108,9 +111,12 @@ ConfigureProfileManager::ConfigureProfileManager(const Core::System& system_, QW
connect(ui->pm_add, &QPushButton::clicked, this, &ConfigureProfileManager::AddUser); connect(ui->pm_add, &QPushButton::clicked, this, &ConfigureProfileManager::AddUser);
connect(ui->pm_rename, &QPushButton::clicked, this, &ConfigureProfileManager::RenameUser); connect(ui->pm_rename, &QPushButton::clicked, this, &ConfigureProfileManager::RenameUser);
connect(ui->pm_remove, &QPushButton::clicked, this, &ConfigureProfileManager::DeleteUser); connect(ui->pm_remove, &QPushButton::clicked, this,
&ConfigureProfileManager::ConfirmDeleteUser);
connect(ui->pm_set_image, &QPushButton::clicked, this, &ConfigureProfileManager::SetUserImage); connect(ui->pm_set_image, &QPushButton::clicked, this, &ConfigureProfileManager::SetUserImage);
confirm_dialog = new ConfigureProfileManagerDeleteDialog(this);
scene = new QGraphicsScene; scene = new QGraphicsScene;
ui->current_user_icon->setScene(scene); ui->current_user_icon->setScene(scene);
@ -230,26 +236,23 @@ void ConfigureProfileManager::RenameUser() {
UpdateCurrentUser(); UpdateCurrentUser();
} }
void ConfigureProfileManager::DeleteUser() { void ConfigureProfileManager::ConfirmDeleteUser() {
const auto index = tree_view->currentIndex().row(); const auto index = tree_view->currentIndex().row();
const auto uuid = profile_manager->GetUser(index); const auto uuid = profile_manager->GetUser(index);
ASSERT(uuid); ASSERT(uuid);
const auto username = GetAccountUsername(*profile_manager, *uuid); const auto username = GetAccountUsername(*profile_manager, *uuid);
const auto confirm = QMessageBox::question( confirm_dialog->SetInfo(username, *uuid, [this, uuid]() { DeleteUser(*uuid); });
this, tr("Confirm Delete"), confirm_dialog->show();
tr("You are about to delete user with name \"%1\". Are you sure?").arg(username)); }
if (confirm == QMessageBox::No) {
return;
}
void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
if (Settings::values.current_user.GetValue() == tree_view->currentIndex().row()) { if (Settings::values.current_user.GetValue() == tree_view->currentIndex().row()) {
Settings::values.current_user = 0; Settings::values.current_user = 0;
} }
UpdateCurrentUser(); UpdateCurrentUser();
if (!profile_manager->RemoveUser(*uuid)) { if (!profile_manager->RemoveUser(uuid)) {
return; return;
} }
@ -319,3 +322,47 @@ void ConfigureProfileManager::SetUserImage() {
new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)}); new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)});
UpdateCurrentUser(); UpdateCurrentUser();
} }
ConfigureProfileManagerDeleteDialog::ConfigureProfileManagerDeleteDialog(QWidget* parent)
: QDialog{parent} {
auto dialog_vbox_layout = new QVBoxLayout(this);
dialog_button_box =
new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No, Qt::Horizontal, parent);
auto label_message =
new QLabel(tr("Delete this user? All of the user's save data will be deleted."), this);
label_info = new QLabel(this);
auto dialog_hbox_layout_widget = new QWidget(this);
auto dialog_hbox_layout = new QHBoxLayout(dialog_hbox_layout_widget);
icon_scene = new QGraphicsScene(0, 0, 64, 64, this);
auto icon_view = new QGraphicsView(icon_scene, this);
dialog_hbox_layout_widget->setLayout(dialog_hbox_layout);
icon_view->setMaximumSize(64, 64);
icon_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
icon_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setLayout(dialog_vbox_layout);
this->setWindowTitle(tr("Confirm Delete"));
this->setSizeGripEnabled(false);
dialog_vbox_layout->addWidget(label_message);
dialog_vbox_layout->addWidget(dialog_hbox_layout_widget);
dialog_vbox_layout->addWidget(dialog_button_box);
dialog_hbox_layout->addWidget(icon_view);
dialog_hbox_layout->addWidget(label_info);
connect(dialog_button_box, &QDialogButtonBox::rejected, this, [this]() { close(); });
}
ConfigureProfileManagerDeleteDialog::~ConfigureProfileManagerDeleteDialog() = default;
void ConfigureProfileManagerDeleteDialog::SetInfo(const QString& username, const Common::UUID& uuid,
std::function<void()> accept_callback) {
label_info->setText(
tr("Name: %1\nUUID: %2").arg(username, QString::fromStdString(uuid.FormattedString())));
icon_scene->clear();
icon_scene->addPixmap(GetIcon(uuid));
connect(dialog_button_box, &QDialogButtonBox::accepted, this, [this, accept_callback]() {
close();
accept_callback();
});
}

View File

@ -3,16 +3,24 @@
#pragma once #pragma once
#include <functional>
#include <memory> #include <memory>
#include <QDialog>
#include <QList> #include <QList>
#include <QWidget> #include <QWidget>
namespace Common {
struct UUID;
}
namespace Core { namespace Core {
class System; class System;
} }
class QGraphicsScene; class QGraphicsScene;
class QDialogButtonBox;
class QLabel;
class QStandardItem; class QStandardItem;
class QStandardItemModel; class QStandardItemModel;
class QTreeView; class QTreeView;
@ -26,6 +34,20 @@ namespace Ui {
class ConfigureProfileManager; class ConfigureProfileManager;
} }
class ConfigureProfileManagerDeleteDialog : public QDialog {
public:
explicit ConfigureProfileManagerDeleteDialog(QWidget* parent);
~ConfigureProfileManagerDeleteDialog();
void SetInfo(const QString& username, const Common::UUID& uuid,
std::function<void()> accept_callback);
private:
QDialogButtonBox* dialog_button_box;
QGraphicsScene* icon_scene;
QLabel* label_info;
};
class ConfigureProfileManager : public QWidget { class ConfigureProfileManager : public QWidget {
Q_OBJECT Q_OBJECT
@ -47,7 +69,8 @@ private:
void SelectUser(const QModelIndex& index); void SelectUser(const QModelIndex& index);
void AddUser(); void AddUser();
void RenameUser(); void RenameUser();
void DeleteUser(); void ConfirmDeleteUser();
void DeleteUser(const Common::UUID& uuid);
void SetUserImage(); void SetUserImage();
QVBoxLayout* layout; QVBoxLayout* layout;
@ -55,6 +78,8 @@ private:
QStandardItemModel* item_model; QStandardItemModel* item_model;
QGraphicsScene* scene; QGraphicsScene* scene;
ConfigureProfileManagerDeleteDialog* confirm_dialog;
std::vector<QList<QStandardItem*>> list_items; std::vector<QList<QStandardItem*>> list_items;
std::unique_ptr<Ui::ConfigureProfileManager> ui; std::unique_ptr<Ui::ConfigureProfileManager> ui;

View File

@ -57,6 +57,12 @@
<height>48</height> <height>48</height>
</size> </size>
</property> </property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="verticalScrollBarPolicy"> <property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum> <enum>Qt::ScrollBarAlwaysOff</enum>
</property> </property>