diff options
author | Sky <git@bunnies.cc> | 2013-11-06 17:02:23 +0000 |
---|---|---|
committer | Sky <git@bunnies.cc> | 2013-11-06 17:02:23 +0000 |
commit | 7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a (patch) | |
tree | 2753d1ee11dad2cf1c4ce1e8a28ead92214f2f1c /depends/settings | |
parent | dc3b0fcb2b74aeede37b08216b203cab284f7fce (diff) | |
parent | bba4ed5ab2c98c3d60a141d6a089a49716753615 (diff) | |
download | MultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.tar MultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.tar.gz MultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.tar.lz MultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.tar.xz MultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.zip |
Merge branch 'develop'
Diffstat (limited to 'depends/settings')
-rw-r--r-- | depends/settings/include/basicsettingsobject.h | 16 | ||||
-rw-r--r-- | depends/settings/include/inifile.h | 7 | ||||
-rw-r--r-- | depends/settings/include/inisettingsobject.h | 31 | ||||
-rw-r--r-- | depends/settings/include/keyring.h | 12 | ||||
-rw-r--r-- | depends/settings/include/libsettings_config.h | 14 | ||||
-rw-r--r-- | depends/settings/include/overridesetting.h | 13 | ||||
-rw-r--r-- | depends/settings/include/setting.h | 51 | ||||
-rw-r--r-- | depends/settings/include/settingsobject.h | 77 | ||||
-rw-r--r-- | depends/settings/src/basicsettingsobject.cpp | 8 | ||||
-rw-r--r-- | depends/settings/src/inifile.cpp | 32 | ||||
-rw-r--r-- | depends/settings/src/inisettingsobject.cpp | 10 | ||||
-rw-r--r-- | depends/settings/src/overridesetting.cpp | 6 | ||||
-rw-r--r-- | depends/settings/src/setting.cpp | 9 | ||||
-rw-r--r-- | depends/settings/src/settingsobject.cpp | 66 | ||||
-rw-r--r-- | depends/settings/src/stubkeyring.cpp | 15 | ||||
-rw-r--r-- | depends/settings/src/stubkeyring.h | 11 |
16 files changed, 189 insertions, 189 deletions
diff --git a/depends/settings/include/basicsettingsobject.h b/depends/settings/include/basicsettingsobject.h index b7e5851d..387a3646 100644 --- a/depends/settings/include/basicsettingsobject.h +++ b/depends/settings/include/basicsettingsobject.h @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -13,8 +13,7 @@ * limitations under the License. */ -#ifndef BASICSETTINGSOBJECT_H -#define BASICSETTINGSOBJECT_H +#pragma once #include <QObject> #include <QSettings> @@ -31,14 +30,13 @@ class LIBSETTINGS_EXPORT BasicSettingsObject : public SettingsObject Q_OBJECT public: explicit BasicSettingsObject(QObject *parent = 0); - -protected slots: + +protected +slots: virtual void changeSetting(const Setting &setting, QVariant value); - + protected: virtual QVariant retrieveValue(const Setting &setting); - + QSettings config; }; - -#endif // BASICSETTINGSOBJECT_H diff --git a/depends/settings/include/inifile.h b/depends/settings/include/inifile.h index 8d30a258..27da7bf0 100644 --- a/depends/settings/include/inifile.h +++ b/depends/settings/include/inifile.h @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -14,6 +14,7 @@ */ #pragma once + #include <QString> #include <QVariant> #include <QIODevice> @@ -25,11 +26,11 @@ class LIBSETTINGS_EXPORT INIFile : public QMap<QString, QVariant> { public: explicit INIFile(); - + bool loadFile(QByteArray file); bool loadFile(QString fileName); bool saveFile(QString fileName); - + QVariant get(QString key, QVariant def) const; void set(QString key, QVariant val); QString unescape(QString orig); diff --git a/depends/settings/include/inisettingsobject.h b/depends/settings/include/inisettingsobject.h index 03d6fe05..8badc0c6 100644 --- a/depends/settings/include/inisettingsobject.h +++ b/depends/settings/include/inisettingsobject.h @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -13,8 +13,7 @@ * limitations under the License. */ -#ifndef INISETTINGSOBJECT_H -#define INISETTINGSOBJECT_H +#pragma once #include <QObject> @@ -22,7 +21,7 @@ #include "settingsobject.h" -#include "libutil_config.h" +#include "libsettings_config.h" /*! * \brief A settings object that stores its settings in an INIFile. @@ -32,29 +31,31 @@ class LIBSETTINGS_EXPORT INISettingsObject : public SettingsObject Q_OBJECT public: explicit INISettingsObject(const QString &path, QObject *parent = 0); - + /*! * \brief Gets the path to the INI file. * \return The path to the INI file. */ - virtual QString filePath() const { return m_filePath; } - + virtual QString filePath() const + { + return m_filePath; + } + /*! * \brief Sets the path to the INI file and reloads it. * \param filePath The INI file's new path. */ virtual void setFilePath(const QString &filePath); - -protected slots: + +protected +slots: virtual void changeSetting(const Setting &setting, QVariant value); - virtual void resetSetting ( const Setting& setting ); - + virtual void resetSetting(const Setting &setting); + protected: virtual QVariant retrieveValue(const Setting &setting); - + INIFile m_ini; - + QString m_filePath; }; - -#endif // INISETTINGSOBJECT_H diff --git a/depends/settings/include/keyring.h b/depends/settings/include/keyring.h index 299b14b0..747211de 100644 --- a/depends/settings/include/keyring.h +++ b/depends/settings/include/keyring.h @@ -15,8 +15,7 @@ * limitations under the License. */ -#ifndef KEYRING_H -#define KEYRING_H +#pragma once #include <QString> @@ -79,14 +78,15 @@ public: * @return */ virtual void removeStoredAccount(QString service, QString username) = 0; - + protected: /// fall back to StubKeyring if false - virtual bool isValid() { return false; } + virtual bool isValid() + { + return false; + } private: static Keyring *m_instance; static void destroy(); }; - -#endif // KEYRING_H diff --git a/depends/settings/include/libsettings_config.h b/depends/settings/include/libsettings_config.h index 2ecfe1c1..ba77f640 100644 --- a/depends/settings/include/libsettings_config.h +++ b/depends/settings/include/libsettings_config.h @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -18,11 +18,11 @@ #include <QtCore/QtGlobal> #ifdef LIBSETTINGS_STATIC - #define LIBSETTINGS_EXPORT +#define LIBSETTINGS_EXPORT +#else +#ifdef LIBSETTINGS_LIBRARY +#define LIBSETTINGS_EXPORT Q_DECL_EXPORT #else - #ifdef LIBSETTINGS_LIBRARY - #define LIBSETTINGS_EXPORT Q_DECL_EXPORT - #else - #define LIBSETTINGS_EXPORT Q_DECL_IMPORT - #endif +#define LIBSETTINGS_EXPORT Q_DECL_IMPORT +#endif #endif diff --git a/depends/settings/include/overridesetting.h b/depends/settings/include/overridesetting.h index 58bb6d40..3e60dc7c 100644 --- a/depends/settings/include/overridesetting.h +++ b/depends/settings/include/overridesetting.h @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -13,8 +13,7 @@ * limitations under the License. */ -#ifndef OVERRIDESETTING_H -#define OVERRIDESETTING_H +#pragma once #include <QObject> @@ -25,7 +24,7 @@ /*! * \brief A setting that 'overrides another.' * This means that the setting's default value will be the value of another setting. - * The other setting can be (and usually is) a part of a different SettingsObject + * The other setting can be (and usually is) a part of a different SettingsObject * than this one. */ class LIBSETTINGS_EXPORT OverrideSetting : public Setting @@ -33,11 +32,9 @@ class LIBSETTINGS_EXPORT OverrideSetting : public Setting Q_OBJECT public: explicit OverrideSetting(const QString &name, Setting *other, QObject *parent = 0); - + virtual QVariant defValue() const; - + protected: Setting *m_other; }; - -#endif // OVERRIDESETTING_H diff --git a/depends/settings/include/setting.h b/depends/settings/include/setting.h index a161ab50..39490207 100644 --- a/depends/settings/include/setting.h +++ b/depends/settings/include/setting.h @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -13,8 +13,7 @@ * limitations under the License. */ -#ifndef SETTING_H -#define SETTING_H +#pragma once #include <QObject> #include <QVariant> @@ -24,7 +23,7 @@ class SettingsObject; /*! - * + * */ class LIBSETTINGS_EXPORT Setting : public QObject { @@ -35,23 +34,30 @@ public: * \param parent The Setting's parent object. */ explicit Setting(QString id, QVariant defVal = QVariant(), QObject *parent = 0); - + /*! * \brief Gets this setting's ID. * This is used to refer to the setting within the application. - * \warning Changing the ID while the setting is registered with a SettingsObject results in undefined behavior. + * \warning Changing the ID while the setting is registered with a SettingsObject results in + * undefined behavior. * \return The ID of the setting. */ - virtual QString id() const { return m_id; } - + virtual QString id() const + { + return m_id; + } + /*! * \brief Gets this setting's config file key. * This is used to store the setting's value in the config file. It is usually * the same as the setting's ID, but it can be different. * \return The setting's config file key. */ - virtual QString configKey() const { return id(); } - + virtual QString configKey() const + { + return id(); + } + /*! * \brief Gets this setting's value as a QVariant. * This is done by calling the SettingsObject's retrieveValue() function. @@ -60,22 +66,23 @@ public: * \sa value() */ virtual QVariant get() const; - + /*! * \brief Gets this setting's actual value (I.E. not as a QVariant). * This function is just shorthand for get().value<T>() * \return The setting's actual value. */ - template<typename T> - inline T value() const { return get().value<T>(); } - - + template <typename T> inline T value() const + { + return get().value<T>(); + } + /*! * \brief Gets this setting's default value. * \return The default value of this setting. */ virtual QVariant defValue() const; - + signals: /*! * \brief Signal emitted when this Setting object's value changes. @@ -83,14 +90,15 @@ signals: * \param value This Setting object's new value. */ void settingChanged(const Setting &setting, QVariant value); - + /*! * \brief Signal emitted when this Setting object's value resets to default. * \param setting A reference to the Setting that changed. */ void settingReset(const Setting &setting); - -public slots: + +public +slots: /*! * \brief Changes the setting's value. * This is done by emitting the settingChanged() signal which will then be @@ -98,7 +106,7 @@ public slots: * \param value The new value. */ virtual void set(QVariant value); - + /*! * \brief Reset the setting to default * This is done by emitting the settingReset() signal which will then be @@ -106,9 +114,8 @@ public slots: * \param value The new value. */ virtual void reset(); + protected: QString m_id; QVariant m_defVal; }; - -#endif // SETTING_H diff --git a/depends/settings/include/settingsobject.h b/depends/settings/include/settingsobject.h index e8bf5c83..7a6b3cb6 100644 --- a/depends/settings/include/settingsobject.h +++ b/depends/settings/include/settingsobject.h @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -23,9 +23,10 @@ class Setting; /*! - * \brief The SettingsObject handles communicating settings between the application and a settings file. + * \brief The SettingsObject handles communicating settings between the application and a + *settings file. * The class keeps a list of Setting objects. Each Setting object represents one - * of the application's settings. These Setting objects are registered with + * of the application's settings. These Setting objects are registered with * a SettingsObject and can be managed similarly to the way a list works. * * \author Andrew Okin @@ -38,9 +39,10 @@ class LIBSETTINGS_EXPORT SettingsObject : public QObject Q_OBJECT public: explicit SettingsObject(QObject *parent = 0); - + /*! - * \brief Registers the given setting with this SettingsObject and connects the necessary signals. + * \brief Registers the given setting with this SettingsObject and connects the necessary + * signals. * This will fail if there is already a setting with the same ID as * the one that is being registered. * \note Registering a setting object causes the SettingsObject to take ownership @@ -52,36 +54,38 @@ public: * \return True if successful. False if registry failed. */ virtual bool registerSetting(Setting *setting); - + /*! - * \brief Unregisters the given setting from this SettingsObject and disconnects its signals. - * \note This does not delete the setting. Furthermore, when the setting is + * \brief Unregisters the given setting from this SettingsObject and disconnects its + * signals. + * \note This does not delete the setting. Furthermore, when the setting is * unregistered, the SettingsObject drops ownership of the setting. This means * that if you unregister a setting, its parent is set to null and you become * responsible for freeing its memory. * \param setting The setting to unregister. */ virtual void unregisterSetting(Setting *setting); - - + /*! * \brief Gets the setting with the given ID. * \param id The ID of the setting to get. - * \return A pointer to the setting with the given ID. + * \return A pointer to the setting with the given ID. * Returns null if there is no setting with the given ID. * \sa operator []() */ virtual Setting *getSetting(const QString &id) const; - + /*! * \brief Same as getSetting() * \param id The ID of the setting to get. - * \return A pointer to the setting with the given ID. + * \return A pointer to the setting with the given ID. * \sa getSetting() */ - inline Setting *operator [](const QString &id) { return getSetting(id); } - - + inline Setting *operator[](const QString &id) + { + return getSetting(id); + } + /*! * \brief Gets the value of the setting with the given ID. * \param id The ID of the setting to get. @@ -89,7 +93,7 @@ public: * If no setting with the given ID exists, returns an invalid QVariant. */ virtual QVariant get(const QString &id) const; - + /*! * \brief Sets the value of the setting with the given ID. * If no setting with the given ID exists, returns false and logs to qDebug @@ -98,87 +102,88 @@ public: * \return True if successful, false if it failed. */ virtual bool set(const QString &id, QVariant value); - + /*! * \brief Reverts the setting with the given ID to default. * \param id The ID of the setting to reset. */ virtual void reset(const QString &id) const; - + /*! * \brief Gets a QList with pointers to all of the registered settings. * The order of the entries in the list is undefined. * \return A QList with pointers to all registered settings. */ virtual QList<Setting *> getSettings(); - + /*! * \brief Checks if this SettingsObject contains a setting with the given ID. * \param id The ID to check for. * \return True if the SettingsObject has a setting with the given ID. */ virtual bool contains(const QString &id); - + signals: /*! * \brief Signal emitted when one of this SettingsObject object's settings changes. - * This is usually just connected directly to each Setting object's + * This is usually just connected directly to each Setting object's * settingChanged() signals. * \param setting A reference to the Setting object that changed. * \param value The Setting object's new value. */ void settingChanged(const Setting &setting, QVariant value); - + /*! * \brief Signal emitted when one of this SettingsObject object's settings resets. - * This is usually just connected directly to each Setting object's + * This is usually just connected directly to each Setting object's * settingReset() signals. * \param setting A reference to the Setting object that changed. */ void settingReset(const Setting &setting); - -protected slots: + +protected +slots: /*! * \brief Changes a setting. - * This slot is usually connected to each Setting object's + * This slot is usually connected to each Setting object's * settingChanged() signal. The signal is emitted, causing this slot * to update the setting's value in the config file. * \param setting A reference to the Setting object that changed. * \param value The setting's new value. */ virtual void changeSetting(const Setting &setting, QVariant value) = 0; - + /*! * \brief Resets a setting. - * This slot is usually connected to each Setting object's + * This slot is usually connected to each Setting object's * settingReset() signal. The signal is emitted, causing this slot * to update the setting's value in the config file. * \param setting A reference to the Setting object that changed. */ virtual void resetSetting(const Setting &setting) = 0; - + protected: /*! * \brief Connects the necessary signals to the given Setting. * \param setting The setting to connect. */ virtual void connectSignals(const Setting &setting); - + /*! * \brief Disconnects signals from the given Setting. * \param setting The setting to disconnect. */ virtual void disconnectSignals(const Setting &setting); - + /*! * \brief Function used by Setting objects to get their values from the SettingsObject. - * \param setting The - * \return + * \param setting The + * \return */ virtual QVariant retrieveValue(const Setting &setting) = 0; - + friend class Setting; - + private: QMap<QString, Setting *> m_settings; }; diff --git a/depends/settings/src/basicsettingsobject.cpp b/depends/settings/src/basicsettingsobject.cpp index 484928c8..96b38851 100644 --- a/depends/settings/src/basicsettingsobject.cpp +++ b/depends/settings/src/basicsettingsobject.cpp @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -16,17 +16,15 @@ #include "include/basicsettingsobject.h" #include "include/setting.h" -BasicSettingsObject::BasicSettingsObject(QObject *parent) : - SettingsObject(parent) +BasicSettingsObject::BasicSettingsObject(QObject *parent) : SettingsObject(parent) { - } void BasicSettingsObject::changeSetting(const Setting &setting, QVariant value) { if (contains(setting.id())) { - if(value.isValid()) + if (value.isValid()) config.setValue(setting.configKey(), value); else config.remove(setting.configKey()); diff --git a/depends/settings/src/inifile.cpp b/depends/settings/src/inifile.cpp index 1eae5609..83aec15e 100644 --- a/depends/settings/src/inifile.cpp +++ b/depends/settings/src/inifile.cpp @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -19,10 +19,8 @@ #include <QTextStream> #include <QStringList> - INIFile::INIFile() { - } QString INIFile::unescape(QString orig) @@ -47,50 +45,50 @@ bool INIFile::saveFile(QString fileName) file.open(QIODevice::WriteOnly); QTextStream out(&file); out.setCodec("UTF-8"); - + for (Iterator iter = begin(); iter != end(); iter++) { QString value = iter.value().toString(); value = escape(value); out << iter.key() << "=" << value << "\n"; } - + return true; } bool INIFile::loadFile(QString fileName) { QFile file(fileName); - if(!file.open(QIODevice::ReadOnly)) + if (!file.open(QIODevice::ReadOnly)) return false; bool success = loadFile(file.readAll()); file.close(); return success; } -bool INIFile::loadFile( QByteArray file ) +bool INIFile::loadFile(QByteArray file) { QTextStream in(file); in.setCodec("UTF-8"); - + QStringList lines = in.readAll().split('\n'); for (int i = 0; i < lines.count(); i++) { - QString & lineRaw = lines[i]; + QString &lineRaw = lines[i]; // Ignore comments. QString line = lineRaw.left(lineRaw.indexOf('#')).trimmed(); - + int eqPos = line.indexOf('='); - if(eqPos == -1) + if (eqPos == -1) continue; QString key = line.left(eqPos).trimmed(); QString valueStr = line.right(line.length() - eqPos - 1).trimmed(); - + valueStr = unescape(valueStr); - + QVariant value(valueStr); - this->operator [](key) = value; + this->operator[](key) = value; } - + return true; } @@ -99,10 +97,10 @@ QVariant INIFile::get(QString key, QVariant def) const if (!this->contains(key)) return def; else - return this->operator [](key); + return this->operator[](key); } void INIFile::set(QString key, QVariant val) { - this->operator [](key) = val; + this->operator[](key) = val; } diff --git a/depends/settings/src/inisettingsobject.cpp b/depends/settings/src/inisettingsobject.cpp index 854421b6..4a7a7428 100644 --- a/depends/settings/src/inisettingsobject.cpp +++ b/depends/settings/src/inisettingsobject.cpp @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -16,8 +16,8 @@ #include "include/inisettingsobject.h" #include "include/setting.h" -INISettingsObject::INISettingsObject(const QString &path, QObject *parent) : - SettingsObject(parent) +INISettingsObject::INISettingsObject(const QString &path, QObject *parent) + : SettingsObject(parent) { m_filePath = path; m_ini.loadFile(path); @@ -32,7 +32,7 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value) { if (contains(setting.id())) { - if(value.isValid()) + if (value.isValid()) m_ini.set(setting.configKey(), value); else m_ini.remove(setting.configKey()); @@ -40,7 +40,7 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value) } } -void INISettingsObject::resetSetting ( const Setting& setting ) +void INISettingsObject::resetSetting(const Setting &setting) { if (contains(setting.id())) { diff --git a/depends/settings/src/overridesetting.cpp b/depends/settings/src/overridesetting.cpp index eafb298f..5b10920d 100644 --- a/depends/settings/src/overridesetting.cpp +++ b/depends/settings/src/overridesetting.cpp @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -15,8 +15,8 @@ #include "include/overridesetting.h" -OverrideSetting::OverrideSetting(const QString &name, Setting *other, QObject *parent) : - Setting(name, QVariant(), parent) +OverrideSetting::OverrideSetting(const QString &name, Setting *other, QObject *parent) + : Setting(name, QVariant(), parent) { m_other = other; } diff --git a/depends/settings/src/setting.cpp b/depends/settings/src/setting.cpp index 8e60af06..899463dc 100644 --- a/depends/settings/src/setting.cpp +++ b/depends/settings/src/setting.cpp @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -16,10 +16,9 @@ #include "include/setting.h" #include "include/settingsobject.h" -Setting::Setting(QString id, QVariant defVal, QObject *parent) : - QObject(parent), m_id(id), m_defVal(defVal) +Setting::Setting(QString id, QVariant defVal, QObject *parent) + : QObject(parent), m_id(id), m_defVal(defVal) { - } QVariant Setting::get() const @@ -32,7 +31,7 @@ QVariant Setting::get() const else { QVariant test = sbase->retrieveValue(*this); - if(!test.isValid()) + if (!test.isValid()) return defValue(); return test; } diff --git a/depends/settings/src/settingsobject.cpp b/depends/settings/src/settingsobject.cpp index 2ca544ad..32a63b8d 100644 --- a/depends/settings/src/settingsobject.cpp +++ b/depends/settings/src/settingsobject.cpp @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -18,10 +18,8 @@ #include <QVariant> -SettingsObject::SettingsObject(QObject *parent) : - QObject(parent) +SettingsObject::SettingsObject(QObject *parent) : QObject(parent) { - } bool SettingsObject::registerSetting(Setting *setting) @@ -29,24 +27,26 @@ bool SettingsObject::registerSetting(Setting *setting) // Check if setting is null or we already have a setting with the same ID. if (!setting) { - qDebug(QString("Failed to register setting. Setting is null."). - arg(setting->id()).toUtf8()); + qDebug(QString("Failed to register setting. Setting is null.") + .arg(setting->id()) + .toUtf8()); return false; // Fail } - + if (contains(setting->id())) { - qDebug(QString("Failed to register setting %1. ID already exists."). - arg(setting->id()).toUtf8()); + qDebug(QString("Failed to register setting %1. ID already exists.") + .arg(setting->id()) + .toUtf8()); return false; // Fail } - + m_settings.insert(setting->id(), setting); setting->setParent(this); // Take ownership. - + // Connect signals. connectSignals(*setting); - + // qDebug(QString("Registered setting %1.").arg(setting->id()).toUtf8()); return true; } @@ -55,22 +55,21 @@ void SettingsObject::unregisterSetting(Setting *setting) { if (!setting || !m_settings.contains(setting->id())) return; // We can't unregister something that's not registered. - + m_settings.remove(setting->id()); - + // Disconnect signals. disconnectSignals(*setting); - + setting->setParent(NULL); // Drop ownership. } - Setting *SettingsObject::getSetting(const QString &id) const { // Make sure there is a setting with the given ID. if (!m_settings.contains(id)) return NULL; - + return m_settings[id]; } @@ -85,8 +84,7 @@ bool SettingsObject::set(const QString &id, QVariant value) Setting *setting = getSetting(id); if (!setting) { - qDebug(QString("Error changing setting %1. Setting doesn't exist."). - arg(id).toUtf8()); + qDebug(QString("Error changing setting %1. Setting doesn't exist.").arg(id).toUtf8()); return false; } else @@ -99,11 +97,10 @@ bool SettingsObject::set(const QString &id, QVariant value) void SettingsObject::reset(const QString &id) const { Setting *setting = getSetting(id); - if(setting) + if (setting) setting->reset(); } - QList<Setting *> SettingsObject::getSettings() { return m_settings.values(); @@ -114,29 +111,26 @@ bool SettingsObject::contains(const QString &id) return m_settings.contains(id); } - void SettingsObject::connectSignals(const Setting &setting) { connect(&setting, SIGNAL(settingChanged(const Setting &, QVariant)), SLOT(changeSetting(const Setting &, QVariant))); connect(&setting, SIGNAL(settingChanged(const Setting &, QVariant)), SIGNAL(settingChanged(const Setting &, QVariant))); - - connect(&setting, SIGNAL(settingReset(Setting)), - SLOT(resetSetting(const Setting &))); - connect(&setting, SIGNAL(settingReset(Setting)), - SIGNAL(settingReset(const Setting &))); + + connect(&setting, SIGNAL(settingReset(Setting)), SLOT(resetSetting(const Setting &))); + connect(&setting, SIGNAL(settingReset(Setting)), SIGNAL(settingReset(const Setting &))); } void SettingsObject::disconnectSignals(const Setting &setting) { - setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)), - this, SLOT(changeSetting(const Setting &, QVariant))); - setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)), - this, SIGNAL(settingChanged(const Setting &, QVariant))); - - setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), - this, SLOT(resetSetting(const Setting &, QVariant))); - setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), - this, SIGNAL(settingReset(const Setting &, QVariant))); + setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)), this, + SLOT(changeSetting(const Setting &, QVariant))); + setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)), this, + SIGNAL(settingChanged(const Setting &, QVariant))); + + setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), this, + SLOT(resetSetting(const Setting &, QVariant))); + setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), this, + SIGNAL(settingReset(const Setting &, QVariant))); } diff --git a/depends/settings/src/stubkeyring.cpp b/depends/settings/src/stubkeyring.cpp index cf814d2f..53fca025 100644 --- a/depends/settings/src/stubkeyring.cpp +++ b/depends/settings/src/stubkeyring.cpp @@ -27,7 +27,7 @@ QString scramble(QString in_) { QByteArray in = in_.toUtf8(); QByteArray out; - for (int i = 0; i<in.length(); i++) + for (int i = 0; i < in.length(); i++) out.append(in.at(i) ^ scrambler); return QString::fromUtf8(out); } @@ -81,7 +81,7 @@ QStringList StubKeyring::getStoredAccounts(QString service) QStringList out; QStringList in(m_settings.allKeys()); QStringListIterator it(in); - while(it.hasNext()) + while (it.hasNext()) { QString c = it.next(); if (c.startsWith(service)) @@ -90,15 +90,16 @@ QStringList StubKeyring::getStoredAccounts(QString service) return out; } -void StubKeyring::removeStoredAccount ( QString service, QString username ) +void StubKeyring::removeStoredAccount(QString service, QString username) { QString key = generateKey(service, username); m_settings.remove(key); } -//FIXME: this needs tweaking/changes for user account level storage -StubKeyring::StubKeyring() : -// m_settings(QSettings::UserScope, "Orochimarufan", "Keyring") - m_settings("keyring.cfg", QSettings::IniFormat) +// FIXME: this needs tweaking/changes for user account level storage +StubKeyring::StubKeyring() + : + // m_settings(QSettings::UserScope, "Orochimarufan", "Keyring") + m_settings("keyring.cfg", QSettings::IniFormat) { } diff --git a/depends/settings/src/stubkeyring.h b/depends/settings/src/stubkeyring.h index 45791c85..f25cefde 100644 --- a/depends/settings/src/stubkeyring.h +++ b/depends/settings/src/stubkeyring.h @@ -15,8 +15,7 @@ * limitations under the License. */ -#ifndef STUBKEYRING_H -#define STUBKEYRING_H +#pragma once #include "include/keyring.h" @@ -30,12 +29,14 @@ public: virtual bool hasPassword(QString service, QString username); virtual QStringList getStoredAccounts(QString service); virtual void removeStoredAccount(QString service, QString username); + private: friend class Keyring; explicit StubKeyring(); - virtual bool isValid() { return true; } + virtual bool isValid() + { + return true; + } QSettings m_settings; }; - -#endif // STUBKEYRING_H |