From 92f877e6a7dad0ee7561aa220db539ff694219da Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 4 Jan 2015 23:23:08 -0800 Subject: [PATCH] Qt: Move MRU to QSettings --- src/platform/qt/ConfigController.cpp | 23 +++++++++++++++-------- src/platform/qt/ConfigController.h | 3 ++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/platform/qt/ConfigController.cpp b/src/platform/qt/ConfigController.cpp index 938002487..23bf6c570 100644 --- a/src/platform/qt/ConfigController.cpp +++ b/src/platform/qt/ConfigController.cpp @@ -8,6 +8,7 @@ #include "GameController.h" #include +#include #include extern "C" { @@ -81,6 +82,13 @@ ConfigController::ConfigController(QObject* parent) : QObject(parent) , m_opts() { + char path[PATH_MAX]; + GBAConfigDirectory(path, sizeof(path)); + QString fileName(path); + fileName.append(QDir::separator()); + fileName.append("qt.ini"); + m_settings = new QSettings(fileName, QSettings::IniFormat, this); + GBAConfigInit(&m_config, PORT); m_opts.audioSync = GameController::AUDIO_SYNC; @@ -178,33 +186,32 @@ void ConfigController::setOption(const char* key, const QVariant& value) { QList ConfigController::getMRU() const { QList mru; + m_settings->beginGroup("mru"); for (int i = 0; i < MRU_LIST_SIZE; ++i) { - char mruName[7]; - snprintf(mruName, sizeof(mruName) - 1, "mru.%i", i); - mruName[sizeof(mruName) - 1] = '\0'; - QString item = getOption(mruName); + QString item = m_settings->value(QString::number(i)).toString(); if (item.isNull()) { continue; } mru.append(item); } + m_settings->endGroup(); return mru; } void ConfigController::setMRU(const QList& mru) { int i = 0; + m_settings->beginGroup("mru"); for (const QString& item : mru) { - char mruName[7]; - snprintf(mruName, sizeof(mruName) - 1, "mru.%i", i); - mruName[sizeof(mruName) - 1] = '\0'; - setOption(mruName, item); + m_settings->setValue(QString::number(i), item); ++i; if (i >= MRU_LIST_SIZE) { break; } } + m_settings->endGroup(); } void ConfigController::write() { GBAConfigSave(&m_config); + m_settings->sync(); } diff --git a/src/platform/qt/ConfigController.h b/src/platform/qt/ConfigController.h index f2e329765..393e93bfc 100644 --- a/src/platform/qt/ConfigController.h +++ b/src/platform/qt/ConfigController.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -92,6 +92,7 @@ private: GBAOptions m_opts; QMap m_optionSet; + QSettings* m_settings; }; }