Qt: Make QSettings use the user config directory

This commit is contained in:
spycrab 2018-03-23 12:10:53 +01:00
parent 773ec975f3
commit 68733ac6c1
10 changed files with 48 additions and 43 deletions

View File

@ -9,7 +9,6 @@
#include <QListWidget>
#include <QPushButton>
#include <QRadioButton>
#include <QSettings>
#include <QVBoxLayout>
#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());

View File

@ -11,7 +11,6 @@
#include <QGroupBox>
#include <QPushButton>
#include <QScrollBar>
#include <QSettings>
#include <QTextEdit>
#include <QTimer>
#include <QVBoxLayout>
@ -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());

View File

@ -5,7 +5,6 @@
#include "DolphinQt2/Debugger/BreakpointWidget.h"
#include <QHeaderView>
#include <QSettings>
#include <QTableWidget>
#include <QToolBar>
#include <QVBoxLayout>
@ -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());

View File

@ -10,7 +10,6 @@
#include <QGroupBox>
#include <QLineEdit>
#include <QListWidget>
#include <QSettings>
#include <QSplitter>
#include <QTableWidget>
#include <QWidget>
@ -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());

View File

@ -12,7 +12,6 @@
#include <QHeaderView>
#include <QMenu>
#include <QSettings>
#include <QTableWidget>
#include <QVBoxLayout>
@ -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());

View File

@ -15,7 +15,6 @@
#include <QHeaderView>
#include <QMenu>
#include <QMessageBox>
#include <QSettings>
#include <QTableWidget>
#include <QToolBar>
#include <QVBoxLayout>
@ -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());

View File

@ -14,7 +14,6 @@
#include <QMenu>
#include <QMessageBox>
#include <QProgressDialog>
#include <QSettings>
#include <QUrl>
#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,7 +518,7 @@ static bool CompressCB(const std::string& text, float percent, void* ptr)
void GameList::OnHeaderViewChanged()
{
QSettings().setValue(QStringLiteral("tableheader/state"),
Settings::GetQSettings().setValue(QStringLiteral("tableheader/state"),
m_list->horizontalHeader()->saveState());
}

View File

@ -17,7 +17,6 @@
#include <QListWidget>
#include <QMessageBox>
#include <QPushButton>
#include <QSettings>
#include <QSpinBox>
#include <QTabWidget>
@ -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<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&NetPlaySetupDialog::SaveSettings);
connect(m_host_games, static_cast<void (QListWidget::*)(int)>(&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

View File

@ -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<QFont>();
return GetQSettings().value(QStringLiteral("debugger/font"), default_font).value<QFont>();
}
void Settings::SetAutoUpdateTrack(const QString& mode)

View File

@ -8,6 +8,7 @@
#include <QFont>
#include <QObject>
#include <QSettings>
#include <QVector>
#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);