[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [picmi] src: Ensure we access the correct settings
From:       Jakob Gruber <jakob.gruber () gmail ! com>
Date:       2015-07-15 13:42:41
Message-ID: E1ZFMxN-0006mw-RU () scm ! kde ! org
[Download RAW message or body]

Git commit f381f0061ae6c68032c03fad9b6662e3431ba7d0 by Jakob Gruber.
Committed on 15/07/2015 at 13:34.
Pushed by gruber into branch 'master'.

Ensure we access the correct settings

Previously, we set 'picmi' as the organization name. This commit ensures
that we still access the correct settings even though the organization
name has now been removed.

M  +7    -5    src/gui/mainwindow.cpp
M  +7    -7    src/logic/levelloader.cpp
M  +7    -1    src/settings.cpp
M  +4    -0    src/settings.h

http://commits.kde.org/picmi/f381f0061ae6c68032c03fad9b6662e3431ba7d0

diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp
index c18f58a..0b85843 100644
--- a/src/gui/mainwindow.cpp
+++ b/src/gui/mainwindow.cpp
@@ -34,6 +34,7 @@
 #include "src/constants.h"
 #include "src/logic/levelloader.h"
 #include "src/logic/picmi.h"
+#include "src/settings.h"
 #include "selectboardwindow.h"
 #include "settingswindow.h"
 #include "scene.h"
@@ -43,6 +44,7 @@ MainWindow::MainWindow(QWidget *parent) :
     m_key_pos("window/position"), m_in_progress(false), m_mode(Random)
 {
     QCoreApplication::setApplicationName("picmi");
+    QCoreApplication::setOrganizationDomain("kde.org");
 
     m_timer.setInterval(500);
 
@@ -152,14 +154,14 @@ void MainWindow::closeEvent(QCloseEvent *event) {
 }
 
 void MainWindow::saveWindowState() {
-    QSettings settings;
-    settings.setValue(m_key_pos, pos());
-    settings.sync();
+    QSharedPointer<QSettings> settings = Settings::instance()->qSettings();
+    settings->setValue(m_key_pos, pos());
+    settings->sync();
 }
 
 void MainWindow::restoreWindowState() {
-    QSettings settings;
-    QPoint p = settings.value(m_key_pos, pos()).toPoint();
+    QSharedPointer<QSettings> settings = Settings::instance()->qSettings();
+    QPoint p = settings->value(m_key_pos, pos()).toPoint();
 
     move(p);
 }
diff --git a/src/logic/levelloader.cpp b/src/logic/levelloader.cpp
index 7090a91..eef2e31 100644
--- a/src/logic/levelloader.cpp
+++ b/src/logic/levelloader.cpp
@@ -24,9 +24,9 @@
 #include <QDir>
 #include <QDomDocument>
 #include <QFile>
-#include <QSettings>
 #include <QStandardPaths>
 
+#include "src/settings.h"
 #include "src/systemexception.h"
 
 class LevelList : public QList<QSharedPointer<Level> >
@@ -82,11 +82,11 @@ QString Level::key() const {
 }
 
 void Level::writeSettings(int seconds) {
-    QSettings settings;
+    QSharedPointer<QSettings> settings = Settings::instance()->qSettings();
     QString k = key();
 
-    settings.setValue(k, seconds);
-    settings.sync();
+    settings->setValue(k, seconds);
+    settings->sync();
 }
 
 void Level::finalize() {
@@ -95,12 +95,12 @@ void Level::finalize() {
 }
 
 void Level::readSettings() {
-    QSettings settings;
+    QSharedPointer<QSettings> settings = Settings::instance()->qSettings();
     QString k = key();
 
-    if (settings.contains(k)) {
+    if (settings->contains(k)) {
         m_solved = true;
-        m_solved_time = settings.value(k).toInt();
+        m_solved_time = settings->value(k).toInt();
     }
 }
 
diff --git a/src/settings.cpp b/src/settings.cpp
index 0e9f0cd..daa11ce 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -30,7 +30,13 @@ Settings::Settings() {
            << "game/font_color_solved"
            << "game/font_color_unsolved";
 
-    m_qsettings = QSharedPointer<QSettings>(new QSettings);
+    /* We explicitly pass "picmi" as the organization name in order to
+     * access the correct settings.
+     * This has historical reason in that we used to set the organization
+     * name globally, which however caused problems in
+     * QStandardPaths::locate().
+     */
+    m_qsettings = QSharedPointer<QSettings>(new QSettings("picmi", "picmi"));
     restore();
 }
 
diff --git a/src/settings.h b/src/settings.h
index 946e43c..3b9edfa 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -64,6 +64,10 @@ public:
 
     void sync();
 
+    /** Raw access to the underlying QSettings object.
+     *  TODO: Wrap all accesses in custom functions and remove this. */
+    QSharedPointer<QSettings> qSettings() const { return m_qsettings; }
+
     static Settings *instance();
 
 signals:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic