[desktop] Fix double profile deletion (#3422)
Classic case of double-emission of signals. Epic Also fixed a bug that caused profile manager to not immediately update when a profile was deleted from Qlaunch. Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3422 Reviewed-by: Lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
a692986bd7
commit
8b55a15808
|
|
@ -88,11 +88,14 @@ bool ProfileManager::RemoveProfileAtIndex(std::size_t index) {
|
||||||
if (index >= MAX_USERS || index >= user_count) {
|
if (index >= MAX_USERS || index >= user_count) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (index < user_count - 1) {
|
|
||||||
std::rotate(profiles.begin() + index, profiles.begin() + index + 1, profiles.end());
|
profiles[index] = ProfileInfo{};
|
||||||
}
|
std::stable_partition(profiles.begin(), profiles.end(),
|
||||||
profiles.back() = {};
|
[](const ProfileInfo& profile) { return profile.user_uuid.IsValid(); });
|
||||||
user_count--;
|
|
||||||
|
is_save_needed = true;
|
||||||
|
WriteUserSaveFile();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -355,14 +358,7 @@ bool ProfileManager::RemoveUser(UUID uuid) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
profiles[*index] = ProfileInfo{};
|
return RemoveProfileAtIndex(*index);
|
||||||
std::stable_partition(profiles.begin(), profiles.end(),
|
|
||||||
[](const ProfileInfo& profile) { return profile.user_uuid.IsValid(); });
|
|
||||||
|
|
||||||
is_save_needed = true;
|
|
||||||
WriteUserSaveFile();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) {
|
bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
|
|
@ -97,6 +97,8 @@ public:
|
||||||
bool CanSystemRegisterUser() const;
|
bool CanSystemRegisterUser() const;
|
||||||
|
|
||||||
bool RemoveUser(Common::UUID uuid);
|
bool RemoveUser(Common::UUID uuid);
|
||||||
|
bool RemoveProfileAtIndex(std::size_t index);
|
||||||
|
|
||||||
bool SetProfileBase(Common::UUID uuid, const ProfileBase& profile_new);
|
bool SetProfileBase(Common::UUID uuid, const ProfileBase& profile_new);
|
||||||
bool SetProfileBaseAndData(Common::UUID uuid, const ProfileBase& profile_new,
|
bool SetProfileBaseAndData(Common::UUID uuid, const ProfileBase& profile_new,
|
||||||
const UserData& data_new);
|
const UserData& data_new);
|
||||||
|
|
@ -113,7 +115,6 @@ public:
|
||||||
private:
|
private:
|
||||||
void ParseUserSaveFile();
|
void ParseUserSaveFile();
|
||||||
std::optional<std::size_t> AddToProfiles(const ProfileInfo& profile);
|
std::optional<std::size_t> AddToProfiles(const ProfileInfo& profile);
|
||||||
bool RemoveProfileAtIndex(std::size_t index);
|
|
||||||
void RemoveAllProfiles();
|
void RemoveAllProfiles();
|
||||||
|
|
||||||
bool is_save_needed{};
|
bool is_save_needed{};
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,8 @@ ConfigureProfileManager::ConfigureProfileManager(Core::System& system_, QWidget*
|
||||||
connect(ui->pm_add, &QPushButton::clicked, this, &ConfigureProfileManager::AddUser);
|
connect(ui->pm_add, &QPushButton::clicked, this, &ConfigureProfileManager::AddUser);
|
||||||
|
|
||||||
confirm_dialog = new ConfigureProfileManagerDeleteDialog(this);
|
confirm_dialog = new ConfigureProfileManagerDeleteDialog(this);
|
||||||
|
connect(confirm_dialog, &ConfigureProfileManagerDeleteDialog::deleteUser, this,
|
||||||
|
&ConfigureProfileManager::DeleteUser);
|
||||||
|
|
||||||
scene = new QGraphicsScene;
|
scene = new QGraphicsScene;
|
||||||
ui->current_user_icon->setScene(scene);
|
ui->current_user_icon->setScene(scene);
|
||||||
|
|
@ -146,6 +148,7 @@ void ConfigureProfileManager::SetConfiguration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureProfileManager::PopulateUserList() {
|
void ConfigureProfileManager::PopulateUserList() {
|
||||||
|
profile_manager.ResetUserSaveFile();
|
||||||
const auto& profiles = profile_manager.GetAllUsers();
|
const auto& profiles = profile_manager.GetAllUsers();
|
||||||
for (const auto& user : profiles) {
|
for (const auto& user : profiles) {
|
||||||
Service::Account::ProfileBase profile{};
|
Service::Account::ProfileBase profile{};
|
||||||
|
|
@ -323,16 +326,16 @@ void ConfigureProfileManager::ConfirmDeleteUser() {
|
||||||
ASSERT(uuid);
|
ASSERT(uuid);
|
||||||
const auto username = GetAccountUsername(profile_manager, *uuid);
|
const auto username = GetAccountUsername(profile_manager, *uuid);
|
||||||
|
|
||||||
confirm_dialog->SetInfo(username, *uuid, [this, uuid]() { DeleteUser(*uuid); });
|
confirm_dialog->SetInfo(username, *uuid, index);
|
||||||
confirm_dialog->show();
|
confirm_dialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
|
void ConfigureProfileManager::DeleteUser(const int index) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!profile_manager.RemoveUser(uuid)) {
|
if (!profile_manager.RemoveProfileAtIndex(index)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -378,19 +381,20 @@ ConfigureProfileManagerDeleteDialog::ConfigureProfileManagerDeleteDialog(QWidget
|
||||||
setMinimumSize(380, 160);
|
setMinimumSize(380, 160);
|
||||||
|
|
||||||
connect(dialog_button_box, &QDialogButtonBox::rejected, this, [this]() { close(); });
|
connect(dialog_button_box, &QDialogButtonBox::rejected, this, [this]() { close(); });
|
||||||
|
connect(dialog_button_box, &QDialogButtonBox::accepted, this, [this]() {
|
||||||
|
close();
|
||||||
|
emit deleteUser(m_index);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigureProfileManagerDeleteDialog::~ConfigureProfileManagerDeleteDialog() = default;
|
ConfigureProfileManagerDeleteDialog::~ConfigureProfileManagerDeleteDialog() = default;
|
||||||
|
|
||||||
void ConfigureProfileManagerDeleteDialog::SetInfo(const QString& username, const Common::UUID& uuid,
|
void ConfigureProfileManagerDeleteDialog::SetInfo(const QString& username, const Common::UUID& uuid,
|
||||||
std::function<void()> accept_callback) {
|
int index) {
|
||||||
label_info->setText(
|
label_info->setText(
|
||||||
tr("Name: %1\nUUID: %2").arg(username, QString::fromStdString(uuid.FormattedString())));
|
tr("Name: %1\nUUID: %2").arg(username, QString::fromStdString(uuid.FormattedString())));
|
||||||
icon_scene->clear();
|
icon_scene->clear();
|
||||||
icon_scene->addPixmap(GetIcon(uuid));
|
icon_scene->addPixmap(GetIcon(uuid));
|
||||||
|
|
||||||
connect(dialog_button_box, &QDialogButtonBox::accepted, this, [this, accept_callback]() {
|
m_index = index;
|
||||||
close();
|
|
||||||
accept_callback();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,18 +40,24 @@ namespace Ui {
|
||||||
class ConfigureProfileManager;
|
class ConfigureProfileManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(crueter): Move this to a .ui def
|
||||||
class ConfigureProfileManagerDeleteDialog : public QDialog {
|
class ConfigureProfileManagerDeleteDialog : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ConfigureProfileManagerDeleteDialog(QWidget* parent);
|
explicit ConfigureProfileManagerDeleteDialog(QWidget* parent);
|
||||||
~ConfigureProfileManagerDeleteDialog();
|
~ConfigureProfileManagerDeleteDialog();
|
||||||
|
|
||||||
void SetInfo(const QString& username, const Common::UUID& uuid,
|
void SetInfo(const QString& username, const Common::UUID& uuid,
|
||||||
std::function<void()> accept_callback);
|
int index);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void deleteUser(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDialogButtonBox* dialog_button_box;
|
QDialogButtonBox* dialog_button_box;
|
||||||
QGraphicsScene* icon_scene;
|
QGraphicsScene* icon_scene;
|
||||||
QLabel* label_info;
|
QLabel* label_info;
|
||||||
|
int m_index = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigureProfileManager : public QWidget {
|
class ConfigureProfileManager : public QWidget {
|
||||||
|
|
@ -66,6 +72,7 @@ public:
|
||||||
private slots:
|
private slots:
|
||||||
void saveImage(QPixmap pixmap, Common::UUID uuid);
|
void saveImage(QPixmap pixmap, Common::UUID uuid);
|
||||||
void showContextMenu(const QPoint &pos);
|
void showContextMenu(const QPoint &pos);
|
||||||
|
void DeleteUser(const int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void changeEvent(QEvent* event) override;
|
void changeEvent(QEvent* event) override;
|
||||||
|
|
@ -80,7 +87,6 @@ private:
|
||||||
void AddUser();
|
void AddUser();
|
||||||
void EditUser();
|
void EditUser();
|
||||||
void ConfirmDeleteUser();
|
void ConfirmDeleteUser();
|
||||||
void DeleteUser(const Common::UUID& uuid);
|
|
||||||
bool LoadAvatarData();
|
bool LoadAvatarData();
|
||||||
std::vector<uint8_t> DecompressYaz0(const FileSys::VirtualFile& file);
|
std::vector<uint8_t> DecompressYaz0(const FileSys::VirtualFile& file);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue