Qt: move some more settings to persistent_settings

This commit is contained in:
Megamouse 2020-08-02 16:03:30 +02:00
parent 70fb5712e5
commit 8799eebfe1
15 changed files with 176 additions and 88 deletions

View File

@ -571,10 +571,10 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
mutex_cat.lock();
const QString serial = qstr(game.serial);
const QString note = m_gui_settings->GetValue(gui::notes, serial, "").toString();
const QString title = m_gui_settings->GetValue(gui::titles, serial, "").toString().simplified();
// Read persistent_settings values
QString note = m_persistent_settings->GetValue(gui::persistent::notes, serial, "").toString();
QString title = m_persistent_settings->GetValue(gui::persistent::titles, serial, "").toString().simplified();
QString last_played = m_persistent_settings->GetValue(gui::persistent::last_played, serial, "").toString();
int playtime = m_persistent_settings->GetValue(gui::persistent::playtime, serial, 0).toInt();
@ -588,6 +588,27 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
{
playtime = m_gui_settings->GetValue(gui::persistent::playtime, serial, 0).toInt();
}
// Deprecated values older than August 2nd 2020
if (note.isEmpty())
{
note = m_gui_settings->GetValue(gui::persistent::notes, serial, "").toString();
// Move to persistent settings
if (!note.isEmpty())
{
m_persistent_settings->SetValue(gui::persistent::notes, serial, note);
}
}
if (title.isEmpty())
{
title = m_gui_settings->GetValue(gui::persistent::titles, serial, "").toString().simplified();
// Move to persistent settings
if (!title.isEmpty())
{
m_persistent_settings->SetValue(gui::persistent::titles, serial, title);
}
}
// Set persistent_settings values if values exist
if (!last_played.isEmpty())
@ -870,7 +891,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
? tr("&Reboot with custom configuration")
: tr("&Boot with custom configuration"));
boot_custom->setFont(font);
connect(boot_custom, &QAction::triggered, [=, this]
connect(boot_custom, &QAction::triggered, [this, gameinfo]
{
sys_log.notice("Booting from gamelist per context menu...");
Q_EMIT RequestBoot(gameinfo);
@ -902,7 +923,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
if (gameinfo->hasCustomConfig)
{
QAction* remove_custom_config = remove_menu->addAction(tr("&Remove Custom Configuration"));
connect(remove_custom_config, &QAction::triggered, [=, this]()
connect(remove_custom_config, &QAction::triggered, [this, current_game, gameinfo]()
{
if (RemoveCustomConfiguration(current_game.serial, gameinfo, true))
{
@ -913,7 +934,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
if (gameinfo->hasCustomPadConfig)
{
QAction* remove_custom_pad_config = remove_menu->addAction(tr("&Remove Custom Gamepad Configuration"));
connect(remove_custom_pad_config, &QAction::triggered, [=, this]()
connect(remove_custom_pad_config, &QAction::triggered, [this, current_game, gameinfo]()
{
if (RemoveCustomPadConfiguration(current_game.serial, gameinfo, true))
{
@ -925,22 +946,22 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
{
remove_menu->addSeparator();
QAction* remove_shaders_cache = remove_menu->addAction(tr("&Remove Shaders Cache"));
connect(remove_shaders_cache, &QAction::triggered, [=, this]()
connect(remove_shaders_cache, &QAction::triggered, [this, cache_base_dir]()
{
RemoveShadersCache(cache_base_dir, true);
});
QAction* remove_ppu_cache = remove_menu->addAction(tr("&Remove PPU Cache"));
connect(remove_ppu_cache, &QAction::triggered, [=, this]()
connect(remove_ppu_cache, &QAction::triggered, [this, cache_base_dir]()
{
RemovePPUCache(cache_base_dir, true);
});
QAction* remove_spu_cache = remove_menu->addAction(tr("&Remove SPU Cache"));
connect(remove_spu_cache, &QAction::triggered, [=, this]()
connect(remove_spu_cache, &QAction::triggered, [this, cache_base_dir]()
{
RemoveSPUCache(cache_base_dir, true);
});
QAction* remove_all_caches = remove_menu->addAction(tr("&Remove All Caches"));
connect(remove_all_caches, &QAction::triggered, [=, this]()
connect(remove_all_caches, &QAction::triggered, [this, cache_base_dir]()
{
if (QMessageBox::question(this, tr("Confirm Removal"), tr("Remove all caches?")) != QMessageBox::Yes)
return;
@ -955,7 +976,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
if (gameinfo->hasCustomConfig)
{
QAction* open_config_dir = menu.addAction(tr("&Open Custom Config Folder"));
connect(open_config_dir, &QAction::triggered, [=, this]()
connect(open_config_dir, &QAction::triggered, [current_game]()
{
const std::string new_config_path = Emulator::GetCustomConfigPath(current_game.serial);
@ -971,7 +992,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
if (fs::is_dir(data_base_dir))
{
QAction* open_data_dir = menu.addAction(tr("&Open Data Folder"));
connect(open_data_dir, &QAction::triggered, [=, this]()
connect(open_data_dir, &QAction::triggered, [data_base_dir]()
{
gui::utils::open_dir(data_base_dir);
});
@ -986,12 +1007,12 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
QAction* copy_name = info_menu->addAction(tr("&Copy Name"));
QAction* copy_serial = info_menu->addAction(tr("&Copy Serial"));
connect(boot, &QAction::triggered, [=, this]()
connect(boot, &QAction::triggered, [this, gameinfo]()
{
sys_log.notice("Booting from gamelist per context menu...");
Q_EMIT RequestBoot(gameinfo, gameinfo->hasCustomConfig);
});
connect(configure, &QAction::triggered, [=, this]()
connect(configure, &QAction::triggered, [this, current_game, gameinfo]()
{
settings_dialog dlg(m_gui_settings, m_emu_settings, 0, this, &current_game);
connect(&dlg, &settings_dialog::EmuSettingsApplied, [this, gameinfo]()
@ -1005,7 +1026,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
});
dlg.exec();
});
connect(pad_configure, &QAction::triggered, [=, this]()
connect(pad_configure, &QAction::triggered, [this, current_game, gameinfo]()
{
pad_settings_dialog dlg(m_gui_settings, this, &current_game);
@ -1032,7 +1053,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
CreatePPUCache(gameinfo);
}
});
connect(remove_game, &QAction::triggered, [=, this]
connect(remove_game, &QAction::triggered, [this, current_game, gameinfo, cache_base_dir, name]
{
if (current_game.path.empty())
{
@ -1069,22 +1090,22 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
}
}
});
connect(open_game_folder, &QAction::triggered, [=, this]()
connect(open_game_folder, &QAction::triggered, [current_game]()
{
gui::utils::open_dir(current_game.path);
});
connect(check_compat, &QAction::triggered, [=, this]
connect(check_compat, &QAction::triggered, [serial]
{
const QString link = "https://rpcs3.net/compatibility?g=" + serial;
QDesktopServices::openUrl(QUrl(link));
});
connect(download_compat, &QAction::triggered, [=, this]
connect(download_compat, &QAction::triggered, [this]
{
m_game_compat->RequestCompatibility(true);
});
connect(rename_title, &QAction::triggered, [=, this]
connect(rename_title, &QAction::triggered, [this, name, serial, global_pos]
{
const QString custom_title = m_gui_settings->GetValue(gui::titles, serial, "").toString();
const QString custom_title = m_persistent_settings->GetValue(gui::persistent::titles, serial, "").toString();
const QString old_title = custom_title.isEmpty() ? name : custom_title;
QString new_title;
@ -1100,20 +1121,20 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
if (new_title.isEmpty() || new_title == name)
{
m_titles.remove(serial);
m_gui_settings->RemoveValue(gui::titles, serial);
m_persistent_settings->RemoveValue(gui::persistent::titles, serial);
}
else
{
m_titles.insert(serial, new_title);
m_gui_settings->SetValue(gui::titles, serial, new_title);
m_persistent_settings->SetValue(gui::persistent::titles, serial, new_title);
}
Refresh(true); // full refresh in order to reliably sort the list
}
});
connect(edit_notes, &QAction::triggered, [=, this]
connect(edit_notes, &QAction::triggered, [this, name, serial]
{
bool accepted;
const QString old_notes = m_gui_settings->GetValue(gui::notes, serial, "").toString();
const QString old_notes = m_persistent_settings->GetValue(gui::persistent::notes, serial, "").toString();
const QString new_notes = QInputDialog::getMultiLineText(this, tr("Edit Tooltip Notes"), tr("%0\n%1").arg(name).arg(serial), old_notes, &accepted);
if (accepted)
@ -1121,25 +1142,25 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
if (new_notes.simplified().isEmpty())
{
m_notes.remove(serial);
m_gui_settings->RemoveValue(gui::notes, serial);
m_persistent_settings->RemoveValue(gui::persistent::notes, serial);
}
else
{
m_notes.insert(serial, new_notes);
m_gui_settings->SetValue(gui::notes, serial, new_notes);
m_persistent_settings->SetValue(gui::persistent::notes, serial, new_notes);
}
Refresh();
}
});
connect(copy_info, &QAction::triggered, [=, this]
connect(copy_info, &QAction::triggered, [name, serial]
{
QApplication::clipboard()->setText(name % QStringLiteral(" [") % serial % QStringLiteral("]"));
});
connect(copy_name, &QAction::triggered, [=, this]
connect(copy_name, &QAction::triggered, [name]
{
QApplication::clipboard()->setText(name);
});
connect(copy_serial, &QAction::triggered, [=, this]
connect(copy_serial, &QAction::triggered, [serial]
{
QApplication::clipboard()->setText(serial);
});

View File

@ -58,8 +58,14 @@ void gui_application::Init()
m_gui_settings.reset(new gui_settings());
m_persistent_settings.reset(new persistent_settings());
// Get deprecated active user (before August 2nd 2020)
QString active_user = m_gui_settings->GetValue(gui::um_active_user).toString();
// Get active user with deprecated active user as fallback
active_user = m_persistent_settings->GetCurrentUser(active_user.isEmpty() ? "00000001" : active_user);
// Force init the emulator
InitializeEmulator(m_gui_settings->GetCurrentUser().toStdString(), true, m_show_gui);
InitializeEmulator(active_user.toStdString(), true, m_show_gui);
// Create the main window
if (m_show_gui)

View File

@ -26,23 +26,6 @@ gui_settings::gui_settings(QObject* parent) : settings(parent)
}
}
QString gui_settings::GetCurrentUser()
{
// load user
bool is_valid_user;
const QString user = GetValue(gui::um_active_user).toString();
const u32 user_id = user.toInt(&is_valid_user);
// set user if valid
if (is_valid_user && user_id > 0)
{
return user;
}
cfg_log.fatal("Could not parse user setting: '%s' = '%d'.", user.toStdString(), user_id);
return QString();
}
bool gui_settings::ChangeToConfig(const QString& config_name)
{
if (m_current_name == config_name)

View File

@ -107,10 +107,6 @@ namespace gui
const QString gs_frame = "GSFrame";
const QString trophy = "Trophy";
const QString patches = "Patches";
const QString savedata = "SaveData";
const QString users = "Users";
const QString notes = "Notes";
const QString titles = "Titles";
const QString localization = "Localization";
const QString pad_settings = "PadSettings";
@ -186,7 +182,7 @@ namespace gui
const gui_save m_currentConfig = gui_save(meta, "currentConfig", Settings);
const gui_save m_currentStylesheet = gui_save(meta, "currentStylesheet", Default);
const gui_save m_saveNotes = gui_save(meta, "saveNotes", QVariantMap());
const gui_save m_saveNotes = gui_save(meta, "saveNotes", QVariantMap()); // Deprecated
const gui_save m_showDebugTab = gui_save(meta, "showDebugTab", false);
const gui_save m_enableUIColors = gui_save(meta, "enableUIColors", false);
const gui_save m_richPresence = gui_save(meta, "useRichPresence", true);
@ -224,7 +220,7 @@ namespace gui
const gui_save sd_icon_color = gui_save(savedata, "icon_color", gl_icon_color);
const gui_save um_geometry = gui_save(users, "geometry", QByteArray());
const gui_save um_active_user = gui_save(users, "active_user", "00000001");
const gui_save um_active_user = gui_save(users, "active_user", ""); // Deprecated
const gui_save loc_language = gui_save(localization, "language", "en");
@ -240,8 +236,6 @@ class gui_settings : public settings
public:
explicit gui_settings(QObject* parent = nullptr);
QString GetCurrentUser();
/** Changes the settings file to the destination preset*/
bool ChangeToConfig(const QString& config_name);

View File

@ -1551,7 +1551,7 @@ void main_window::CreateConnects()
connect(ui->confSavedataManagerAct, &QAction::triggered, [this]
{
save_manager_dialog* save_manager = new save_manager_dialog(m_gui_settings);
save_manager_dialog* save_manager = new save_manager_dialog(m_gui_settings, m_persistent_settings);
connect(this, &main_window::RequestTrophyManagerRepaint, save_manager, &save_manager_dialog::HandleRepaintUiRequest);
save_manager->show();
});
@ -1594,7 +1594,7 @@ void main_window::CreateConnects()
connect(ui->actionManage_Users, &QAction::triggered, [this]
{
user_manager_dialog user_manager(m_gui_settings, this);
user_manager_dialog user_manager(m_gui_settings, m_persistent_settings, this);
user_manager.exec();
m_game_list_frame->Refresh(true); // New user may have different games unlocked.
});

View File

@ -1,4 +1,7 @@
#include "persistent_settings.h"
#include "stdafx.h"
#include "persistent_settings.h"
LOG_CHANNEL(cfg_log, "CFG");
persistent_settings::persistent_settings(QObject* parent) : settings(parent)
{
@ -27,3 +30,25 @@ QString persistent_settings::GetLastPlayed(const QString& serial)
{
return m_last_played[serial];
}
QString persistent_settings::GetCurrentUser(const QString& fallback) const
{
// Load user
QString user = GetValue(gui::persistent::active_user).toString();
if (user.isEmpty())
{
user = fallback;
}
bool is_valid_user;
const u32 user_id = user.toInt(&is_valid_user);
// Set user if valid
if (is_valid_user && user_id > 0)
{
return user;
}
cfg_log.fatal("Could not parse user setting: '%s' = '%d'.", user.toStdString(), user_id);
return QString();
}

View File

@ -12,11 +12,17 @@ namespace gui
// Entry names
const QString playtime = "Playtime";
const QString last_played = "LastPlayed";
const QString notes = "Notes";
const QString titles = "Titles";
// Date format
const QString last_played_date_format_old = "MMMM d yyyy";
const QString last_played_date_format_new = "MMMM d, yyyy";
const Qt::DateFormat last_played_date_format = Qt::DateFormat::ISODate;
// GUI Saves
const gui_save save_notes = gui_save(savedata, "notes", QVariantMap());
const gui_save active_user = gui_save(users, "active_user", "");
}
}
@ -28,6 +34,8 @@ class persistent_settings : public settings
public:
explicit persistent_settings(QObject* parent = nullptr);
QString GetCurrentUser(const QString& fallback) const;
public Q_SLOTS:
void SetPlaytime(const QString& serial, const qint64& elapsed);
qint64 GetPlaytime(const QString& serial);

View File

@ -2,6 +2,7 @@
#include "save_data_list_dialog.h"
#include "save_data_info_dialog.h"
#include "gui_settings.h"
#include "persistent_settings.h"
#include <QPushButton>
#include <QHBoxLayout>
@ -33,6 +34,7 @@ save_data_list_dialog::save_data_list_dialog(const std::vector<SaveDataEntry>& e
setMinimumSize(QSize(400, 400));
m_gui_settings.reset(new gui_settings());
m_persistent_settings.reset(new persistent_settings());
// Table
m_list = new QTableWidget(this);
@ -103,12 +105,12 @@ save_data_list_dialog::save_data_list_dialog(const std::vector<SaveDataEntry>& e
connect(m_list, &QTableWidget::cellChanged, [&](int row, int col)
{
const int originalIndex = m_list->item(row, 0)->data(Qt::UserRole).toInt();
const SaveDataEntry originalEntry = m_save_entries[originalIndex];
const QString originalDirName = qstr(originalEntry.dirName);
QVariantMap currNotes = m_gui_settings->GetValue(gui::m_saveNotes).toMap();
currNotes[originalDirName] = m_list->item(row, col)->text();
m_gui_settings->SetValue(gui::m_saveNotes, currNotes);
const int original_index = m_list->item(row, 0)->data(Qt::UserRole).toInt();
const SaveDataEntry original_entry = m_save_entries[original_index];
const QString original_dir_name = qstr(original_entry.dirName);
QVariantMap notes = m_persistent_settings->GetValue(gui::persistent::save_notes).toMap();
notes[original_dir_name] = m_list->item(row, col)->text();
m_persistent_settings->SetValue(gui::persistent::save_notes, notes);
});
m_list->setCurrentCell(focusedEntry, 0);
@ -179,7 +181,19 @@ void save_data_list_dialog::UpdateList()
m_list->clearContents();
m_list->setRowCount(::narrow<int>(m_save_entries.size()));
const QVariantMap currNotes = m_gui_settings->GetValue(gui::m_saveNotes).toMap();
QVariantMap notes = m_persistent_settings->GetValue(gui::persistent::save_notes).toMap();
// Find deprecated values (older than August 2nd 2020)
if (notes.isEmpty())
{
notes = m_gui_settings->GetValue(gui::m_saveNotes).toMap();
// Move to persistent settings
if (!notes.isEmpty())
{
m_persistent_settings->SetValue(gui::persistent::save_notes, notes);
}
}
int row = 0;
for (const SaveDataEntry& entry: m_save_entries)
@ -204,9 +218,9 @@ void save_data_list_dialog::UpdateList()
QTableWidgetItem* noteItem = new QTableWidgetItem();
noteItem->setFlags(noteItem->flags() | Qt::ItemIsEditable);
if (currNotes.contains(dirName))
if (notes.contains(dirName))
{
noteItem->setText(currNotes[dirName].toString());
noteItem->setText(notes[dirName].toString());
}
m_list->setItem(row, 3, noteItem);

View File

@ -10,6 +10,7 @@
#include <QLabel>
class gui_settings;
class persistent_settings;
//Display a list of SaveData. Would need to be initialized.
//Can also be used as a Save Data Chooser.
@ -41,6 +42,7 @@ private:
std::vector<SaveDataEntry> m_save_entries;
std::shared_ptr<gui_settings> m_gui_settings;
std::shared_ptr<persistent_settings> m_persistent_settings;
int m_sort_column = 0;
bool m_sort_ascending = true;

View File

@ -3,6 +3,7 @@
#include "custom_table_widget_item.h"
#include "qt_utils.h"
#include "gui_settings.h"
#include "persistent_settings.h"
#include "Emu/System.h"
#include "Emu/Memory/vm.h"
@ -91,10 +92,11 @@ namespace
}
}
save_manager_dialog::save_manager_dialog(std::shared_ptr<gui_settings> gui_settings, std::string dir, QWidget* parent)
save_manager_dialog::save_manager_dialog(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<persistent_settings> persistent_settings, std::string dir, QWidget* parent)
: QDialog(parent)
, m_dir(dir)
, m_gui_settings(gui_settings)
, m_persistent_settings(persistent_settings)
{
setWindowTitle(tr("Save Manager"));
setMinimumSize(QSize(400, 400));
@ -214,12 +216,12 @@ void save_manager_dialog::Init(std::string dir)
{
return;
}
const int originalIndex = user_item->data(Qt::UserRole).toInt();
const SaveDataEntry originalEntry = m_save_entries[originalIndex];
const QString originalDirName = qstr(originalEntry.dirName);
QVariantMap currNotes = m_gui_settings->GetValue(gui::m_saveNotes).toMap();
currNotes[originalDirName] = text_item->text();
m_gui_settings->SetValue(gui::m_saveNotes, currNotes);
const int original_index = user_item->data(Qt::UserRole).toInt();
const SaveDataEntry originalEntry = m_save_entries[original_index];
const QString original_dir_name = qstr(originalEntry.dirName);
QVariantMap notes = m_persistent_settings->GetValue(gui::persistent::save_notes).toMap();
notes[original_dir_name] = text_item->text();
m_persistent_settings->SetValue(gui::persistent::save_notes, notes);
});
connect(m_list, &QTableWidget::itemSelectionChanged, this, &save_manager_dialog::UpdateDetails);
}
@ -236,7 +238,7 @@ void save_manager_dialog::UpdateList()
m_list->clearContents();
m_list->setRowCount(static_cast<int>(m_save_entries.size()));
QVariantMap currNotes = m_gui_settings->GetValue(gui::m_saveNotes).toMap();
QVariantMap notes = m_persistent_settings->GetValue(gui::persistent::save_notes).toMap();
if (m_gui_settings->GetValue(gui::m_enableUIColors).toBool())
{
@ -271,7 +273,7 @@ void save_manager_dialog::UpdateList()
const auto& entry = m_save_entries[i];
QString title = qstr(entry.title) + QStringLiteral("\n") + qstr(entry.subtitle);
QString dirName = qstr(entry.dirName);
QString dir_name = qstr(entry.dirName);
custom_table_widget_item* iconItem = new custom_table_widget_item;
iconItem->setData(Qt::UserRole, icons[i]);
@ -287,15 +289,15 @@ void save_manager_dialog::UpdateList()
timeItem->setFlags(timeItem->flags() & ~Qt::ItemIsEditable);
m_list->setItem(i, 2, timeItem);
QTableWidgetItem* dirNameItem = new QTableWidgetItem(dirName);
QTableWidgetItem* dirNameItem = new QTableWidgetItem(dir_name);
dirNameItem->setFlags(dirNameItem->flags() & ~Qt::ItemIsEditable);
m_list->setItem(i, 3, dirNameItem);
QTableWidgetItem* noteItem = new QTableWidgetItem();
noteItem->setFlags(noteItem->flags() | Qt::ItemIsEditable);
if (currNotes.contains(dirName))
if (notes.contains(dir_name))
{
noteItem->setText(currNotes[dirName].toString());
noteItem->setText(notes[dir_name].toString());
}
m_list->setItem(i, 4, noteItem);
}

View File

@ -8,6 +8,7 @@
#include <QTableWidget>
class gui_settings;
class persistent_settings;
class save_manager_dialog : public QDialog
{
@ -19,7 +20,7 @@ public:
* Plus, there's the added complexity of an additional way in which the dialog will spawn differently.
* There'll be some duplicated code. But, in the future, there'll be no duplicated code. So, I don't care.
*/
explicit save_manager_dialog(std::shared_ptr<gui_settings> gui_settings, std::string dir = "", QWidget* parent = nullptr);
explicit save_manager_dialog(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<persistent_settings> persistent_settings, std::string dir = "", QWidget* parent = nullptr);
public Q_SLOTS:
void HandleRepaintUiRequest();
private Q_SLOTS:
@ -42,6 +43,7 @@ private:
std::vector<SaveDataEntry> m_save_entries;
std::shared_ptr<gui_settings> m_gui_settings;
std::shared_ptr<persistent_settings> m_persistent_settings;
int m_sort_column = 1;
bool m_sort_ascending = true;

View File

@ -37,12 +37,12 @@ void settings::RemoveValue(const QString& key, const QString& name)
}
}
QVariant settings::GetValue(const gui_save& entry)
QVariant settings::GetValue(const gui_save& entry) const
{
return m_settings ? m_settings->value(entry.key + "/" + entry.name, entry.def) : entry.def;
}
QVariant settings::GetValue(const QString& key, const QString& name, const QString& def)
QVariant settings::GetValue(const QString& key, const QString& name, const QVariant& def) const
{
return m_settings ? m_settings->value(key + "/" + name, def) : def;
}
@ -74,6 +74,14 @@ void settings::SetValue(const gui_save& entry, const QVariant& value)
}
}
void settings::SetValue(const QString& key, const QVariant& value)
{
if (m_settings)
{
m_settings->setValue(key, value);
}
}
void settings::SetValue(const QString& key, const QString& name, const QVariant& value)
{
if (m_settings)

View File

@ -14,6 +14,12 @@ typedef QPair<QString, QSize> q_size_pair;
typedef QList<q_string_pair> q_pair_list;
typedef QList<q_size_pair> q_size_list;
namespace gui
{
const QString savedata = "SaveData";
const QString users = "Users";
}
// Parent Class for GUI settings
class settings : public QObject
{
@ -25,8 +31,8 @@ public:
QString GetSettingsDir() const;
QVariant GetValue(const gui_save& entry);
QVariant GetValue(const QString& key, const QString& name, const QString& def);
QVariant GetValue(const gui_save& entry) const;
QVariant GetValue(const QString& key, const QString& name, const QVariant& def) const;
static QVariant List2Var(const q_pair_list& list);
static q_pair_list Var2List(const QVariant& var);
@ -36,6 +42,7 @@ public Q_SLOTS:
/** Write value to entry */
void SetValue(const gui_save& entry, const QVariant& value);
void SetValue(const QString& key, const QVariant& value);
void SetValue(const QString& key, const QString& name, const QVariant& value);
protected:

View File

@ -16,6 +16,7 @@
#include "table_item_delegate.h"
#include "main_application.h"
#include "gui_settings.h"
#include "persistent_settings.h"
#include "Emu/System.h"
@ -64,9 +65,10 @@ namespace
}
}
user_manager_dialog::user_manager_dialog(std::shared_ptr<gui_settings> gui_settings, QWidget* parent)
user_manager_dialog::user_manager_dialog(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget* parent)
: QDialog(parent)
, m_gui_settings(gui_settings)
, m_persistent_settings(persistent_settings)
{
setWindowTitle(tr("User Manager"));
setMinimumSize(QSize(500, 400));
@ -123,7 +125,19 @@ void user_manager_dialog::Init()
vbox_main->addLayout(hbox_buttons);
setLayout(vbox_main);
m_active_user = m_gui_settings->GetValue(gui::um_active_user).toString().toStdString();
m_active_user = m_persistent_settings->GetValue(gui::persistent::active_user).toString().toStdString();
// Handle deprecated value (before August 2nd 2020)
if (m_active_user.empty())
{
m_active_user = m_gui_settings->GetValue(gui::um_active_user).toString().toStdString();
if (!m_active_user.empty())
{
m_persistent_settings->SetValue(gui::persistent::active_user, qstr(m_active_user));
}
}
UpdateTable();
restoreGeometry(m_gui_settings->GetValue(gui::um_geometry).toByteArray());
@ -389,7 +403,7 @@ void user_manager_dialog::OnUserLogin()
}
m_active_user = new_user;
m_gui_settings->SetValue(gui::um_active_user, qstr(m_active_user));
m_persistent_settings->SetValue(gui::persistent::active_user, qstr(m_active_user));
UpdateTable(true);
Q_EMIT OnUserLoginSuccess();
}

View File

@ -7,12 +7,13 @@
#include <QTableWidget>
class gui_settings;
class persistent_settings;
class user_manager_dialog : public QDialog
{
Q_OBJECT
public:
explicit user_manager_dialog(std::shared_ptr<gui_settings> gui_settings, QWidget* parent = nullptr);
explicit user_manager_dialog(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget* parent = nullptr);
Q_SIGNALS:
void OnUserLoginSuccess();
private Q_SLOTS:
@ -39,6 +40,7 @@ private:
std::map<u32, UserAccount> m_user_list;
std::shared_ptr<gui_settings> m_gui_settings;
std::shared_ptr<persistent_settings> m_persistent_settings;
int m_sort_column = 1;
bool m_sort_ascending = true;