diff options
Diffstat (limited to 'src/settings.cpp')
| -rw-r--r-- | src/settings.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..f221854 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,97 @@ +/** + * Copyright (c) 2012 Nokia Corporation. + * All rights reserved. + * + * For the applicable distribution terms see the license text file included in + * the distribution. + */ + +#include "settings.h" +#include <QtCore/QSettings> +#include <QDebug> +#include <QGuiApplication> + +/*! + \class Settings + \brief This class loads and stores settings used by client application. +*/ + + +/*! + Constructor. +*/ +Settings::Settings(QObject *parent) + : QObject(parent) +{ +} + + +/*! + Copy constructor. + Not used. +*/ +Settings::Settings(const Settings &settings) + : QObject(0) +{ + Q_UNUSED(settings) +} + + +/*! + Stores the setting as a key value pair. +*/ +void Settings::setSetting(const QString &setting, const QVariant &value) +{ + QSettings settings; + settings.setValue(setting, value); + //qDebug() << "changed setting: " << setting << "to value: " << value; + emit settingChanged(setting, value); +} + + +/*! + Loads the setting by key. Returns value or the default value if no setting is found. +*/ +QVariant Settings::setting(const QString &setting, const QVariant &defaultValue) +{ + QSettings settings; + //qDebug() << "returning settings value: " << settings.value(setting); + return settings.value(setting, defaultValue); +} + +/*! + Loads the setting by key. Returns value. +*/ +QVariant Settings::setting(const QString &setting) +{ + QSettings settings; + //qDebug() << "returning settings value: " << settings.value(setting); + return settings.value(setting); +} + + +/*! + Removes the setting by key. Returns true, if setting removed + successfully. Otherwise false. +*/ +bool Settings::removeSetting(const QString &setting) +{ + QSettings settings; + if (!settings.contains(setting)) { + return false; + } + + settings.remove(setting); + return true; +} + + +/*! + Removes all settings. +*/ +void Settings::clear() +{ + QSettings settings; + settings.clear(); +} + |
