diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-01-01 15:08:40 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-01-01 15:10:35 +0100 |
commit | 396e63500ec189b003d36504bae91a2b6a78a69d (patch) | |
tree | b78022c1877536af1293a24d657a451085c55a4c /depends/settings/include | |
parent | 6648c7ad903f4c8120193fa6f276ce8dde3b0b77 (diff) | |
download | MultiMC-396e63500ec189b003d36504bae91a2b6a78a69d.tar MultiMC-396e63500ec189b003d36504bae91a2b6a78a69d.tar.gz MultiMC-396e63500ec189b003d36504bae91a2b6a78a69d.tar.lz MultiMC-396e63500ec189b003d36504bae91a2b6a78a69d.tar.xz MultiMC-396e63500ec189b003d36504bae91a2b6a78a69d.zip |
Allow the use of synonyms in settings. Refactor settings.
Remove a bunch of obsolete/unused code.
Diffstat (limited to 'depends/settings/include')
-rw-r--r-- | depends/settings/include/basicsettingsobject.h | 42 | ||||
-rw-r--r-- | depends/settings/include/inifile.h | 38 | ||||
-rw-r--r-- | depends/settings/include/inisettingsobject.h | 61 | ||||
-rw-r--r-- | depends/settings/include/keyring.h | 97 | ||||
-rw-r--r-- | depends/settings/include/libsettings_config.h | 28 | ||||
-rw-r--r-- | depends/settings/include/overridesetting.h | 40 | ||||
-rw-r--r-- | depends/settings/include/setting.h | 121 | ||||
-rw-r--r-- | depends/settings/include/settingsobject.h | 189 |
8 files changed, 0 insertions, 616 deletions
diff --git a/depends/settings/include/basicsettingsobject.h b/depends/settings/include/basicsettingsobject.h deleted file mode 100644 index 387a3646..00000000 --- a/depends/settings/include/basicsettingsobject.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * 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 - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <QObject> -#include <QSettings> - -#include "settingsobject.h" - -#include "libsettings_config.h" - -/*! - * \brief A settings object that stores its settings in a QSettings object. - */ -class LIBSETTINGS_EXPORT BasicSettingsObject : public SettingsObject -{ - Q_OBJECT -public: - explicit BasicSettingsObject(QObject *parent = 0); - -protected -slots: - virtual void changeSetting(const Setting &setting, QVariant value); - -protected: - virtual QVariant retrieveValue(const Setting &setting); - - QSettings config; -}; diff --git a/depends/settings/include/inifile.h b/depends/settings/include/inifile.h deleted file mode 100644 index 27da7bf0..00000000 --- a/depends/settings/include/inifile.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * 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 - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <QString> -#include <QVariant> -#include <QIODevice> - -#include "libsettings_config.h" - -// Sectionless INI parser (for instance config files) -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); - QString escape(QString orig); -}; diff --git a/depends/settings/include/inisettingsobject.h b/depends/settings/include/inisettingsobject.h deleted file mode 100644 index 8badc0c6..00000000 --- a/depends/settings/include/inisettingsobject.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * 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 - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <QObject> - -#include "inifile.h" - -#include "settingsobject.h" - -#include "libsettings_config.h" - -/*! - * \brief A settings object that stores its settings in an INIFile. - */ -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; - } - - /*! - * \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: - virtual void changeSetting(const Setting &setting, QVariant value); - virtual void resetSetting(const Setting &setting); - -protected: - virtual QVariant retrieveValue(const Setting &setting); - - INIFile m_ini; - - QString m_filePath; -}; diff --git a/depends/settings/include/keyring.h b/depends/settings/include/keyring.h deleted file mode 100644 index a4da23b1..00000000 --- a/depends/settings/include/keyring.h +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Authors: Orochimarufan <orochimarufan.x3@gmail.com> - * - * 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 - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <QString> - -#include "libsettings_config.h" - -/** - * @file libsettings/include/keyring.h - * Access to System Keyrings - */ - -/** - * @brief The Keyring class - * the System Keyring/Keychain/Wallet/Vault/etc - */ -class LIBSETTINGS_EXPORT Keyring -{ -public: - /** - * @brief virtual dtor - */ - virtual ~Keyring() {}; - - /** - * @brief the System Keyring instance - * @return the Keyring instance - */ - static Keyring *instance(); - - /** - * @brief store a password in the Keyring - * @param service the service name - * @param username the account name - * @param password the password to store - * @return success - */ - virtual bool storePassword(QString service, QString username, QString password) = 0; - - /** - * @brief get a password from the Keyring - * @param service the service name - * @param username the account name - * @return the password (success=!isNull()) - */ - virtual QString getPassword(QString service, QString username) = 0; - - /** - * @brief lookup a password - * @param service the service name - * @param username the account name - * @return wether the password is available - */ - virtual bool hasPassword(QString service, QString username) = 0; - - /** - * @brief get a list of all stored accounts. - * @param service the service name - * @return - */ - virtual QStringList getStoredAccounts(QString service) = 0; - - /** - * @brief Remove the specified account from storage - * @param service the service name - * @param username the account name - * @return - */ - virtual void removeStoredAccount(QString service, QString username) = 0; - -protected: - /// fall back to StubKeyring if false - virtual bool isValid() - { - return false; - } - -private: - static Keyring *m_instance; - static void destroy(); -}; diff --git a/depends/settings/include/libsettings_config.h b/depends/settings/include/libsettings_config.h deleted file mode 100644 index ba77f640..00000000 --- a/depends/settings/include/libsettings_config.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * 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 - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <QtCore/QtGlobal> - -#ifdef LIBSETTINGS_STATIC -#define LIBSETTINGS_EXPORT -#else -#ifdef LIBSETTINGS_LIBRARY -#define LIBSETTINGS_EXPORT Q_DECL_EXPORT -#else -#define LIBSETTINGS_EXPORT Q_DECL_IMPORT -#endif -#endif diff --git a/depends/settings/include/overridesetting.h b/depends/settings/include/overridesetting.h deleted file mode 100644 index 3e60dc7c..00000000 --- a/depends/settings/include/overridesetting.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * 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 - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <QObject> - -#include "setting.h" - -#include "libsettings_config.h" - -/*! - * \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 - * than this one. - */ -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; -}; diff --git a/depends/settings/include/setting.h b/depends/settings/include/setting.h deleted file mode 100644 index 39490207..00000000 --- a/depends/settings/include/setting.h +++ /dev/null @@ -1,121 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * 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 - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <QObject> -#include <QVariant> - -#include "libsettings_config.h" - -class SettingsObject; - -/*! - * - */ -class LIBSETTINGS_EXPORT Setting : public QObject -{ - Q_OBJECT -public: - /*! - * \brief Constructs a new Setting object with the given parent. - * \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. - * \return The ID of the setting. - */ - 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(); - } - - /*! - * \brief Gets this setting's value as a QVariant. - * This is done by calling the SettingsObject's retrieveValue() function. - * If this Setting doesn't have a SettingsObject, this returns an invalid QVariant. - * \return QVariant containing this setting's value. - * \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>(); - } - - /*! - * \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. - * \param setting A reference to the Setting that changed. - * \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: - /*! - * \brief Changes the setting's value. - * This is done by emitting the settingChanged() signal which will then be - * handled by the SettingsObject object and cause the setting to change. - * \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 - * handled by the SettingsObject object and cause the setting to change. - * \param value The new value. - */ - virtual void reset(); - -protected: - QString m_id; - QVariant m_defVal; -}; diff --git a/depends/settings/include/settingsobject.h b/depends/settings/include/settingsobject.h deleted file mode 100644 index 7a6b3cb6..00000000 --- a/depends/settings/include/settingsobject.h +++ /dev/null @@ -1,189 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * 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 - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <QObject> -#include <QMap> - -#include "libsettings_config.h" - -class Setting; - -/*! - * \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 - * a SettingsObject and can be managed similarly to the way a list works. - * - * \author Andrew Okin - * \date 2/22/2013 - * - * \sa Setting - */ -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. - * 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 - * of the object. This means that setting's parent will be set to the object - * it was registered with. Because the object it was registered with has taken - * ownership, it becomes responsible for managing that setting object's memory. - * \warning Do \b not delete the setting after registering it. - * \param setting A pointer to the setting that will be registered. - * \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 - * 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. - * 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. - * \sa getSetting() - */ - 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. - * \return The setting's value as a QVariant. - * 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 - * \param id The ID of the setting to change. - * \param value The new value of the setting. - * \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 - * 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 - * settingReset() signals. - * \param setting A reference to the Setting object that changed. - */ - void settingReset(const Setting &setting); - -protected -slots: - /*! - * \brief Changes a setting. - * 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 - * 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 - */ - virtual QVariant retrieveValue(const Setting &setting) = 0; - - friend class Setting; - -private: - QMap<QString, Setting *> m_settings; -}; |