mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-02-06 09:39:55 +00:00
Qt: Backup current gui config before applying another one
Also fixes some strange issues caused by the pointer
This commit is contained in:
parent
53676067fc
commit
5f247cbedc
@ -14,7 +14,7 @@ inline std::string sstr(const QString& _in) { return _in.toStdString(); }
|
||||
gui_settings::gui_settings(QObject* parent) : settings(parent)
|
||||
{
|
||||
m_current_name = gui::Settings;
|
||||
m_settings = new QSettings(ComputeSettingsDir() + gui::Settings + ".ini", QSettings::Format::IniFormat, parent);
|
||||
m_settings.reset(new QSettings(ComputeSettingsDir() + gui::Settings + ".ini", QSettings::Format::IniFormat, parent));
|
||||
|
||||
const QString settings_name = GetValue(gui::m_currentConfig).toString();
|
||||
|
||||
@ -48,34 +48,20 @@ bool gui_settings::ChangeToConfig(const QString& config_name)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config_name != gui::Settings)
|
||||
{
|
||||
if (m_current_name == gui::Settings)
|
||||
{
|
||||
SetValue(gui::m_currentConfig, config_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
QSettings tmp(m_settings_dir.absoluteFilePath(gui::Settings + ".ini"), QSettings::Format::IniFormat, parent());
|
||||
tmp.beginGroup(gui::m_currentConfig.key);
|
||||
tmp.setValue(gui::m_currentConfig.name, config_name);
|
||||
tmp.endGroup();
|
||||
}
|
||||
}
|
||||
// Backup current config
|
||||
SaveCurrentConfig(m_current_name);
|
||||
|
||||
// Save new config name to the default config
|
||||
SaveConfigNameToDefault(config_name);
|
||||
|
||||
// Sync file just in case
|
||||
m_settings->sync();
|
||||
|
||||
Reset(true);
|
||||
|
||||
const QSettings other(m_settings_dir.absoluteFilePath(config_name + ".ini"), QSettings::IniFormat);
|
||||
|
||||
for (const QString& key : other.allKeys())
|
||||
{
|
||||
m_settings->setValue(key, other.value(key));
|
||||
}
|
||||
// Load new config
|
||||
m_settings.reset(new QSettings(m_settings_dir.absoluteFilePath(config_name + ".ini"), QSettings::IniFormat));
|
||||
|
||||
// Save own name to new config
|
||||
SetValue(gui::m_currentConfig, config_name);
|
||||
|
||||
m_settings->sync();
|
||||
|
||||
m_current_name = config_name;
|
||||
@ -238,26 +224,11 @@ void gui_settings::SetCustomColor(int col, const QColor& val)
|
||||
SetValue(gui_save(gui::meta, "CustomColor" + QString::number(col), gui::gl_icon_color), val);
|
||||
}
|
||||
|
||||
void gui_settings::SaveCurrentConfig(const QString& friendly_name)
|
||||
void gui_settings::SaveCurrentConfig(const QString& config_name)
|
||||
{
|
||||
if (friendly_name != gui::Settings)
|
||||
{
|
||||
if (m_current_name == gui::Settings)
|
||||
{
|
||||
SetValue(gui::m_currentConfig, friendly_name);
|
||||
m_settings->sync();
|
||||
}
|
||||
else
|
||||
{
|
||||
QSettings tmp(m_settings_dir.absoluteFilePath(gui::Settings + ".ini"), QSettings::Format::IniFormat, parent());
|
||||
tmp.beginGroup(gui::m_currentConfig.key);
|
||||
tmp.setValue(gui::m_currentConfig.name, friendly_name);
|
||||
tmp.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
BackupSettingsToTarget(friendly_name);
|
||||
ChangeToConfig(friendly_name);
|
||||
SaveConfigNameToDefault(config_name);
|
||||
BackupSettingsToTarget(config_name);
|
||||
ChangeToConfig(config_name);
|
||||
}
|
||||
|
||||
logs::level gui_settings::GetLogLevel()
|
||||
@ -290,9 +261,26 @@ QStringList gui_settings::GetConfigEntries()
|
||||
return res;
|
||||
}
|
||||
|
||||
void gui_settings::BackupSettingsToTarget(const QString& friendly_name)
|
||||
// Save the name of the used config to the default settings file
|
||||
void gui_settings::SaveConfigNameToDefault(const QString& config_name)
|
||||
{
|
||||
QSettings target(ComputeSettingsDir() + friendly_name + ".ini", QSettings::Format::IniFormat);
|
||||
if (m_current_name == gui::Settings)
|
||||
{
|
||||
SetValue(gui::m_currentConfig, config_name);
|
||||
m_settings->sync();
|
||||
}
|
||||
else
|
||||
{
|
||||
QSettings tmp(m_settings_dir.absoluteFilePath(gui::Settings + ".ini"), QSettings::Format::IniFormat, parent());
|
||||
tmp.beginGroup(gui::m_currentConfig.key);
|
||||
tmp.setValue(gui::m_currentConfig.name, config_name);
|
||||
tmp.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void gui_settings::BackupSettingsToTarget(const QString& config_name)
|
||||
{
|
||||
QSettings target(ComputeSettingsDir() + config_name + ".ini", QSettings::Format::IniFormat);
|
||||
|
||||
for (const QString& key : m_settings->allKeys())
|
||||
{
|
||||
|
@ -258,13 +258,14 @@ public Q_SLOTS:
|
||||
|
||||
void SetCustomColor(int col, const QColor& val);
|
||||
|
||||
void SaveCurrentConfig(const QString& friendly_name);
|
||||
void SaveCurrentConfig(const QString& config_name);
|
||||
|
||||
static QSize SizeFromSlider(int pos);
|
||||
static gui_save GetGuiSaveForColumn(int col);
|
||||
|
||||
private:
|
||||
void BackupSettingsToTarget(const QString& friendly_name);
|
||||
void SaveConfigNameToDefault(const QString& config_name);
|
||||
void BackupSettingsToTarget(const QString& config_name);
|
||||
void ShowBox(bool confirm, const QString& title, const QString& text, const gui_save& entry, int* result, QWidget* parent, bool always_on_top);
|
||||
|
||||
QString m_current_name;
|
||||
|
@ -3,7 +3,7 @@
|
||||
persistent_settings::persistent_settings(QObject* parent) : settings(parent)
|
||||
{
|
||||
// Don't use the .ini file ending for now, as it will be confused for a regular gui_settings file.
|
||||
m_settings = new QSettings(ComputeSettingsDir() + gui::persistent::persistent_file_name + ".dat", QSettings::Format::IniFormat, parent);
|
||||
m_settings.reset(new QSettings(ComputeSettingsDir() + gui::persistent::persistent_file_name + ".dat", QSettings::Format::IniFormat, parent));
|
||||
}
|
||||
|
||||
void persistent_settings::SetPlaytime(const QString& serial, const qint64& elapsed)
|
||||
|
@ -17,12 +17,12 @@ settings::~settings()
|
||||
}
|
||||
}
|
||||
|
||||
QString settings::GetSettingsDir()
|
||||
QString settings::GetSettingsDir() const
|
||||
{
|
||||
return m_settings_dir.absolutePath();
|
||||
}
|
||||
|
||||
QString settings::ComputeSettingsDir()
|
||||
QString settings::ComputeSettingsDir() const
|
||||
{
|
||||
return QString::fromStdString(fs::get_config_dir()) + "/GuiConfigs/";
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ public:
|
||||
explicit settings(QObject* parent = nullptr);
|
||||
~settings();
|
||||
|
||||
QString GetSettingsDir();
|
||||
QString GetSettingsDir() const;
|
||||
|
||||
QVariant GetValue(const gui_save& entry);
|
||||
QVariant GetValue(const QString& key, const QString& name, const QString& def);
|
||||
QVariant List2Var(const q_pair_list& list);
|
||||
q_pair_list Var2List(const QVariant& var);
|
||||
static QVariant List2Var(const q_pair_list& list);
|
||||
static q_pair_list Var2List(const QVariant& var);
|
||||
|
||||
public Q_SLOTS:
|
||||
/** Remove entry */
|
||||
@ -56,9 +56,9 @@ public Q_SLOTS:
|
||||
void SetValue(const QString& key, const QString& name, const QVariant& value);
|
||||
|
||||
protected:
|
||||
QString ComputeSettingsDir();
|
||||
QString ComputeSettingsDir() const;
|
||||
|
||||
QSettings* m_settings = nullptr;
|
||||
std::unique_ptr<QSettings> m_settings;
|
||||
QDir m_settings_dir;
|
||||
QString m_current_name;
|
||||
};
|
||||
|
@ -51,9 +51,9 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
|
||||
ui->tab_widget_settings->setUsesScrollButtons(false);
|
||||
ui->tab_widget_settings->tabBar()->setObjectName("tab_bar_settings");
|
||||
|
||||
bool showDebugTab = m_gui_settings->GetValue(gui::m_showDebugTab).toBool();
|
||||
m_gui_settings->SetValue(gui::m_showDebugTab, showDebugTab);
|
||||
if (!showDebugTab)
|
||||
const bool show_debug_tab = m_gui_settings->GetValue(gui::m_showDebugTab).toBool();
|
||||
m_gui_settings->SetValue(gui::m_showDebugTab, show_debug_tab);
|
||||
if (!show_debug_tab)
|
||||
{
|
||||
ui->tab_widget_settings->removeTab(9);
|
||||
}
|
||||
@ -1903,6 +1903,9 @@ void settings_dialog::OnApplyConfig()
|
||||
return;
|
||||
}
|
||||
|
||||
// Backup current window states
|
||||
Q_EMIT GuiSettingsSaveRequest();
|
||||
|
||||
if (!m_gui_settings->ChangeToConfig(new_config))
|
||||
{
|
||||
const int new_config_idx = ui->combo_configs->currentIndex();
|
||||
|
Loading…
x
Reference in New Issue
Block a user