From 68733ac6c1edb90b93d12906ba2b1d41c2a4bbf2 Mon Sep 17 00:00:00 2001 From: spycrab Date: Fri, 23 Mar 2018 12:10:53 +0100 Subject: [PATCH] Qt: Make QSettings use the user config directory --- .../DolphinQt2/Config/LogConfigWidget.cpp | 5 +-- Source/Core/DolphinQt2/Config/LogWidget.cpp | 5 +-- .../DolphinQt2/Debugger/BreakpointWidget.cpp | 5 +-- .../Core/DolphinQt2/Debugger/CodeWidget.cpp | 5 +-- .../DolphinQt2/Debugger/RegisterWidget.cpp | 5 +-- .../Core/DolphinQt2/Debugger/WatchWidget.cpp | 5 +-- Source/Core/DolphinQt2/GameList/GameList.cpp | 8 ++-- .../DolphinQt2/NetPlay/NetPlaySetupDialog.cpp | 7 +-- Source/Core/DolphinQt2/Settings.cpp | 44 +++++++++++-------- Source/Core/DolphinQt2/Settings.h | 2 + 10 files changed, 48 insertions(+), 43 deletions(-) diff --git a/Source/Core/DolphinQt2/Config/LogConfigWidget.cpp b/Source/Core/DolphinQt2/Config/LogConfigWidget.cpp index e8a28140d4..e2ad410824 100644 --- a/Source/Core/DolphinQt2/Config/LogConfigWidget.cpp +++ b/Source/Core/DolphinQt2/Config/LogConfigWidget.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "Common/FileUtil.h" @@ -122,7 +121,7 @@ void LogConfigWidget::ConnectWidgets() void LogConfigWidget::LoadSettings() { auto* logmanager = LogManager::GetInstance(); - QSettings settings; + auto& settings = Settings::GetQSettings(); restoreGeometry(settings.value(QStringLiteral("logconfigwidget/geometry")).toByteArray()); setFloating(settings.value(QStringLiteral("logconfigwidget/floating")).toBool()); @@ -156,7 +155,7 @@ void LogConfigWidget::SaveSettings() if (m_block_save) return; - QSettings settings; + auto& settings = Settings::GetQSettings(); settings.setValue(QStringLiteral("logconfigwidget/geometry"), saveGeometry()); settings.setValue(QStringLiteral("logconfigwidget/floating"), isFloating()); diff --git a/Source/Core/DolphinQt2/Config/LogWidget.cpp b/Source/Core/DolphinQt2/Config/LogWidget.cpp index e9293c22db..ced9c76fb0 100644 --- a/Source/Core/DolphinQt2/Config/LogWidget.cpp +++ b/Source/Core/DolphinQt2/Config/LogWidget.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -146,7 +145,7 @@ void LogWidget::ConnectWidgets() void LogWidget::LoadSettings() { - QSettings settings; + auto& settings = Settings::GetQSettings(); restoreGeometry(settings.value(QStringLiteral("logwidget/geometry")).toByteArray()); setFloating(settings.value(QStringLiteral("logwidget/floating")).toBool()); @@ -163,7 +162,7 @@ void LogWidget::LoadSettings() void LogWidget::SaveSettings() { - QSettings settings; + auto& settings = Settings::GetQSettings(); settings.setValue(QStringLiteral("logwidget/geometry"), saveGeometry()); settings.setValue(QStringLiteral("logwidget/floating"), isFloating()); diff --git a/Source/Core/DolphinQt2/Debugger/BreakpointWidget.cpp b/Source/Core/DolphinQt2/Debugger/BreakpointWidget.cpp index a5f6278904..b67c0b83fe 100644 --- a/Source/Core/DolphinQt2/Debugger/BreakpointWidget.cpp +++ b/Source/Core/DolphinQt2/Debugger/BreakpointWidget.cpp @@ -5,7 +5,6 @@ #include "DolphinQt2/Debugger/BreakpointWidget.h" #include -#include #include #include #include @@ -26,7 +25,7 @@ BreakpointWidget::BreakpointWidget(QWidget* parent) : QDockWidget(parent) setWindowTitle(tr("Breakpoints")); setAllowedAreas(Qt::AllDockWidgetAreas); - QSettings settings; + auto& settings = Settings::GetQSettings(); restoreGeometry(settings.value(QStringLiteral("breakpointwidget/geometry")).toByteArray()); setFloating(settings.value(QStringLiteral("breakpointwidget/floating")).toBool()); @@ -56,7 +55,7 @@ BreakpointWidget::BreakpointWidget(QWidget* parent) : QDockWidget(parent) BreakpointWidget::~BreakpointWidget() { - QSettings settings; + auto& settings = Settings::GetQSettings(); settings.setValue(QStringLiteral("breakpointwidget/geometry"), saveGeometry()); settings.setValue(QStringLiteral("breakpointwidget/floating"), isFloating()); diff --git a/Source/Core/DolphinQt2/Debugger/CodeWidget.cpp b/Source/Core/DolphinQt2/Debugger/CodeWidget.cpp index 8c78d507cd..b449d1c889 100644 --- a/Source/Core/DolphinQt2/Debugger/CodeWidget.cpp +++ b/Source/Core/DolphinQt2/Debugger/CodeWidget.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -30,7 +29,7 @@ CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent) setWindowTitle(tr("Code")); setAllowedAreas(Qt::AllDockWidgetAreas); - QSettings settings; + auto& settings = Settings::GetQSettings(); restoreGeometry(settings.value(QStringLiteral("codewidget/geometry")).toByteArray()); setFloating(settings.value(QStringLiteral("codewidget/floating")).toBool()); @@ -58,7 +57,7 @@ CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent) CodeWidget::~CodeWidget() { - QSettings settings; + auto& settings = Settings::GetQSettings(); settings.setValue(QStringLiteral("codewidget/geometry"), saveGeometry()); settings.setValue(QStringLiteral("codewidget/floating"), isFloating()); diff --git a/Source/Core/DolphinQt2/Debugger/RegisterWidget.cpp b/Source/Core/DolphinQt2/Debugger/RegisterWidget.cpp index 0da6d34c30..9f63afe3b3 100644 --- a/Source/Core/DolphinQt2/Debugger/RegisterWidget.cpp +++ b/Source/Core/DolphinQt2/Debugger/RegisterWidget.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -21,7 +20,7 @@ RegisterWidget::RegisterWidget(QWidget* parent) : QDockWidget(parent) setWindowTitle(tr("Registers")); setAllowedAreas(Qt::AllDockWidgetAreas); - QSettings settings; + auto& settings = Settings::GetQSettings(); restoreGeometry(settings.value(QStringLiteral("registerwidget/geometry")).toByteArray()); setFloating(settings.value(QStringLiteral("registerwidget/floating")).toBool()); @@ -54,7 +53,7 @@ RegisterWidget::RegisterWidget(QWidget* parent) : QDockWidget(parent) RegisterWidget::~RegisterWidget() { - QSettings settings; + auto& settings = Settings::GetQSettings(); settings.setValue(QStringLiteral("registerwidget/geometry"), saveGeometry()); settings.setValue(QStringLiteral("registerwidget/floating"), isFloating()); diff --git a/Source/Core/DolphinQt2/Debugger/WatchWidget.cpp b/Source/Core/DolphinQt2/Debugger/WatchWidget.cpp index 96b0132292..01caf96deb 100644 --- a/Source/Core/DolphinQt2/Debugger/WatchWidget.cpp +++ b/Source/Core/DolphinQt2/Debugger/WatchWidget.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -27,7 +26,7 @@ WatchWidget::WatchWidget(QWidget* parent) : QDockWidget(parent) setWindowTitle(tr("Watch")); setAllowedAreas(Qt::AllDockWidgetAreas); - QSettings settings; + auto& settings = Settings::GetQSettings(); restoreGeometry(settings.value(QStringLiteral("watchwidget/geometry")).toByteArray()); setFloating(settings.value(QStringLiteral("watchwidget/floating")).toBool()); @@ -59,7 +58,7 @@ WatchWidget::WatchWidget(QWidget* parent) : QDockWidget(parent) WatchWidget::~WatchWidget() { - QSettings settings; + auto& settings = Settings::GetQSettings(); settings.setValue(QStringLiteral("watchwidget/geometry"), saveGeometry()); settings.setValue(QStringLiteral("watchwidget/floating"), isFloating()); diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index f486a67510..e6de408dff 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include "Common/FileUtil.h" @@ -106,7 +105,8 @@ void GameList::MakeListView() connect(hor_header, &QHeaderView::sectionMoved, this, &GameList::OnHeaderViewChanged); hor_header->setSectionsMovable(true); - hor_header->restoreState(QSettings().value(QStringLiteral("tableheader/state")).toByteArray()); + hor_header->restoreState( + Settings::GetQSettings().value(QStringLiteral("tableheader/state")).toByteArray()); hor_header->setSectionResizeMode(GameListModel::COL_PLATFORM, QHeaderView::ResizeToContents); hor_header->setSectionResizeMode(GameListModel::COL_BANNER, QHeaderView::ResizeToContents); @@ -518,8 +518,8 @@ static bool CompressCB(const std::string& text, float percent, void* ptr) void GameList::OnHeaderViewChanged() { - QSettings().setValue(QStringLiteral("tableheader/state"), - m_list->horizontalHeader()->saveState()); + Settings::GetQSettings().setValue(QStringLiteral("tableheader/state"), + m_list->horizontalHeader()->saveState()); } void GameList::SetSearchTerm(const QString& term) diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlaySetupDialog.cpp b/Source/Core/DolphinQt2/NetPlay/NetPlaySetupDialog.cpp index 89fe579d5f..f4cc46becb 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlaySetupDialog.cpp +++ b/Source/Core/DolphinQt2/NetPlay/NetPlaySetupDialog.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -50,7 +49,7 @@ NetPlaySetupDialog::NetPlaySetupDialog(QWidget* parent) OnConnectionTypeChanged(m_connection_type->currentIndex()); - int selected_game = QSettings().value(QStringLiteral("netplay/hostgame"), 0).toInt(); + int selected_game = Settings::GetQSettings().value(QStringLiteral("netplay/hostgame"), 0).toInt(); if (selected_game >= m_host_games->count()) selected_game = 0; @@ -160,7 +159,9 @@ void NetPlaySetupDialog::ConnectWidgets() connect(m_host_port_box, static_cast(&QSpinBox::valueChanged), this, &NetPlaySetupDialog::SaveSettings); connect(m_host_games, static_cast(&QListWidget::currentRowChanged), - [](int index) { QSettings().setValue(QStringLiteral("netplay/hostgame"), index); }); + [](int index) { + Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"), index); + }); connect(m_host_force_port_check, &QCheckBox::toggled, [this](int value) { m_host_force_port_box->setEnabled(value); }); #ifdef USE_UPNP diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index 155af29f63..ed2746888d 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -33,6 +33,14 @@ Settings& Settings::Instance() return settings; } +QSettings& Settings::GetQSettings() +{ + static QSettings settings( + QStringLiteral("%1/Qt.ini").arg(QString::fromStdString(File::GetUserPath(D_CONFIG_IDX))), + QSettings::IniFormat); + return settings; +} + void Settings::SetThemeName(const QString& theme_name) { SConfig::GetInstance().theme_name = theme_name.toStdString(); @@ -88,22 +96,22 @@ void Settings::SetDefaultGame(QString path) bool Settings::GetPreferredView() const { - return QSettings().value(QStringLiteral("PreferredView"), true).toBool(); + return GetQSettings().value(QStringLiteral("PreferredView"), true).toBool(); } void Settings::SetPreferredView(bool list) { - QSettings().setValue(QStringLiteral("PreferredView"), list); + GetQSettings().setValue(QStringLiteral("PreferredView"), list); } int Settings::GetStateSlot() const { - return QSettings().value(QStringLiteral("Emulation/StateSlot"), 1).toInt(); + return GetQSettings().value(QStringLiteral("Emulation/StateSlot"), 1).toInt(); } void Settings::SetStateSlot(int slot) { - QSettings().setValue(QStringLiteral("Emulation/StateSlot"), slot); + GetQSettings().setValue(QStringLiteral("Emulation/StateSlot"), slot); } void Settings::SetHideCursor(bool hide_cursor) @@ -145,28 +153,28 @@ void Settings::DecreaseVolume(int volume) bool Settings::IsLogVisible() const { - return QSettings().value(QStringLiteral("logging/logvisible")).toBool(); + return GetQSettings().value(QStringLiteral("logging/logvisible")).toBool(); } void Settings::SetLogVisible(bool visible) { if (IsLogVisible() != visible) { - QSettings().setValue(QStringLiteral("logging/logvisible"), visible); + GetQSettings().setValue(QStringLiteral("logging/logvisible"), visible); emit LogVisibilityChanged(visible); } } bool Settings::IsLogConfigVisible() const { - return QSettings().value(QStringLiteral("logging/logconfigvisible")).toBool(); + return GetQSettings().value(QStringLiteral("logging/logconfigvisible")).toBool(); } void Settings::SetLogConfigVisible(bool visible) { if (IsLogConfigVisible() != visible) { - QSettings().setValue(QStringLiteral("logging/logconfigvisible"), visible); + GetQSettings().setValue(QStringLiteral("logging/logconfigvisible"), visible); emit LogConfigVisibilityChanged(visible); } } @@ -229,7 +237,7 @@ void Settings::SetRegistersVisible(bool enabled) { if (IsRegistersVisible() != enabled) { - QSettings().setValue(QStringLiteral("debugger/showregisters"), enabled); + GetQSettings().setValue(QStringLiteral("debugger/showregisters"), enabled); emit RegistersVisibilityChanged(enabled); } @@ -237,14 +245,14 @@ void Settings::SetRegistersVisible(bool enabled) bool Settings::IsRegistersVisible() const { - return QSettings().value(QStringLiteral("debugger/showregisters")).toBool(); + return GetQSettings().value(QStringLiteral("debugger/showregisters")).toBool(); } void Settings::SetWatchVisible(bool enabled) { if (IsWatchVisible() != enabled) { - QSettings().setValue(QStringLiteral("debugger/showwatch"), enabled); + GetQSettings().setValue(QStringLiteral("debugger/showwatch"), enabled); emit WatchVisibilityChanged(enabled); } @@ -252,14 +260,14 @@ void Settings::SetWatchVisible(bool enabled) bool Settings::IsWatchVisible() const { - return QSettings().value(QStringLiteral("debugger/showwatch")).toBool(); + return GetQSettings().value(QStringLiteral("debugger/showwatch")).toBool(); } void Settings::SetBreakpointsVisible(bool enabled) { if (IsBreakpointsVisible() != enabled) { - QSettings().setValue(QStringLiteral("debugger/showbreakpoints"), enabled); + GetQSettings().setValue(QStringLiteral("debugger/showbreakpoints"), enabled); emit BreakpointsVisibilityChanged(enabled); } @@ -267,7 +275,7 @@ void Settings::SetBreakpointsVisible(bool enabled) bool Settings::IsBreakpointsVisible() const { - return QSettings().value(QStringLiteral("debugger/showbreakpoints")).toBool(); + return GetQSettings().value(QStringLiteral("debugger/showbreakpoints")).toBool(); } bool Settings::IsControllerStateNeeded() const @@ -284,7 +292,7 @@ void Settings::SetCodeVisible(bool enabled) { if (IsCodeVisible() != enabled) { - QSettings().setValue(QStringLiteral("debugger/showcode"), enabled); + GetQSettings().setValue(QStringLiteral("debugger/showcode"), enabled); emit CodeVisibilityChanged(enabled); } @@ -292,14 +300,14 @@ void Settings::SetCodeVisible(bool enabled) bool Settings::IsCodeVisible() const { - return QSettings().value(QStringLiteral("debugger/showcode")).toBool(); + return GetQSettings().value(QStringLiteral("debugger/showcode")).toBool(); } void Settings::SetDebugFont(QFont font) { if (GetDebugFont() != font) { - QSettings().setValue(QStringLiteral("debugger/font"), font); + GetQSettings().setValue(QStringLiteral("debugger/font"), font); emit DebugFontChanged(font); } @@ -310,7 +318,7 @@ QFont Settings::GetDebugFont() const QFont default_font = QFont(QStringLiteral("Monospace")); default_font.setStyleHint(QFont::TypeWriter); - return QSettings().value(QStringLiteral("debugger/font"), default_font).value(); + return GetQSettings().value(QStringLiteral("debugger/font"), default_font).value(); } void Settings::SetAutoUpdateTrack(const QString& mode) diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index 5e37eadd25..f96d8d67b5 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -8,6 +8,7 @@ #include #include +#include #include #include "Core/NetPlayClient.h" @@ -39,6 +40,7 @@ public: Settings& operator=(Settings&&) = delete; static Settings& Instance(); + static QSettings& GetQSettings(); // UI void SetThemeName(const QString& theme_name);