diff options
Diffstat (limited to 'depends/settings')
-rw-r--r-- | depends/settings/CMakeLists.txt | 43 | ||||
-rw-r--r-- | depends/settings/include/basicsettingsobject.h | 42 | ||||
-rw-r--r-- | depends/settings/include/keyring.h | 97 | ||||
-rw-r--r-- | depends/settings/inifile.cpp (renamed from depends/settings/src/inifile.cpp) | 2 | ||||
-rw-r--r-- | depends/settings/inifile.h (renamed from depends/settings/include/inifile.h) | 0 | ||||
-rw-r--r-- | depends/settings/inisettingsobject.cpp (renamed from depends/settings/src/inisettingsobject.cpp) | 34 | ||||
-rw-r--r-- | depends/settings/inisettingsobject.h (renamed from depends/settings/include/inisettingsobject.h) | 0 | ||||
-rw-r--r-- | depends/settings/libsettings_config.h (renamed from depends/settings/include/libsettings_config.h) | 1 | ||||
-rw-r--r-- | depends/settings/overridesetting.cpp (renamed from depends/settings/src/overridesetting.cpp) | 6 | ||||
-rw-r--r-- | depends/settings/overridesetting.h (renamed from depends/settings/include/overridesetting.h) | 5 | ||||
-rw-r--r-- | depends/settings/setting.cpp (renamed from depends/settings/src/setting.cpp) | 10 | ||||
-rw-r--r-- | depends/settings/setting.h (renamed from depends/settings/include/setting.h) | 36 | ||||
-rw-r--r-- | depends/settings/settingsobject.cpp (renamed from depends/settings/src/settingsobject.cpp) | 90 | ||||
-rw-r--r-- | depends/settings/settingsobject.h (renamed from depends/settings/include/settingsobject.h) | 82 | ||||
-rw-r--r-- | depends/settings/src/basicsettingsobject.cpp | 44 | ||||
-rw-r--r-- | depends/settings/src/keyring.cpp | 63 | ||||
-rw-r--r-- | depends/settings/src/stubkeyring.cpp | 105 | ||||
-rw-r--r-- | depends/settings/src/stubkeyring.h | 47 |
18 files changed, 146 insertions, 561 deletions
diff --git a/depends/settings/CMakeLists.txt b/depends/settings/CMakeLists.txt index 154697f6..da853a73 100644 --- a/depends/settings/CMakeLists.txt +++ b/depends/settings/CMakeLists.txt @@ -5,44 +5,27 @@ find_package(Qt5Core REQUIRED) # Include Qt headers. include_directories(${Qt5Base_INCLUDE_DIRS}) -include_directories(${Qt5Network_INCLUDE_DIRS}) -SET(LIBSETTINGS_HEADERS -include/libsettings_config.h - -include/inifile.h - -include/settingsobject.h -include/setting.h -include/overridesetting.h - -include/basicsettingsobject.h -include/inisettingsobject.h - -include/keyring.h -) - -SET(LIBSETTINGS_HEADERS_PRIVATE -src/stubkeyring.h -) SET(LIBSETTINGS_SOURCES -src/inifile.cpp +libsettings_config.h -src/settingsobject.cpp -src/setting.cpp -src/overridesetting.cpp +inifile.h +inifile.cpp -src/basicsettingsobject.cpp -src/inisettingsobject.cpp +settingsobject.h +settingsobject.cpp +inisettingsobject.h +inisettingsobject.cpp -src/keyring.cpp -src/stubkeyring.cpp +setting.h +setting.cpp +overridesetting.h +overridesetting.cpp ) # Set the include dir path. -SET(LIBSETTINGS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE) -include_directories(${LIBSETTINGS_INCLUDE_DIR}) +SET(LIBSETTINGS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) # Static link! ADD_DEFINITIONS(-DLIBSETTINGS_STATIC) @@ -59,6 +42,6 @@ IF(MultiMC_CODE_COVERAGE) SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0 --coverage") ENDIF(MultiMC_CODE_COVERAGE) -add_library(libSettings STATIC ${LIBSETTINGS_SOURCES} ${LIBSETTINGS_HEADERS} ${LIBSETTINGS_HEADERS_PRIVATE}) +add_library(libSettings STATIC ${LIBSETTINGS_SOURCES}) qt5_use_modules(libSettings Core) target_link_libraries(libSettings) 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/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/src/inifile.cpp b/depends/settings/inifile.cpp index 83aec15e..1170f0b1 100644 --- a/depends/settings/src/inifile.cpp +++ b/depends/settings/inifile.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "include/inifile.h" +#include "inifile.h" #include <QFile> #include <QTextStream> diff --git a/depends/settings/include/inifile.h b/depends/settings/inifile.h index 27da7bf0..27da7bf0 100644 --- a/depends/settings/include/inifile.h +++ b/depends/settings/inifile.h diff --git a/depends/settings/src/inisettingsobject.cpp b/depends/settings/inisettingsobject.cpp index 4a7a7428..5e52a56f 100644 --- a/depends/settings/src/inisettingsobject.cpp +++ b/depends/settings/inisettingsobject.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "include/inisettingsobject.h" -#include "include/setting.h" +#include "inisettingsobject.h" +#include "setting.h" INISettingsObject::INISettingsObject(const QString &path, QObject *parent) : SettingsObject(parent) @@ -32,31 +32,45 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value) { if (contains(setting.id())) { + // valid value -> set the main config, remove all the sysnonyms if (value.isValid()) - m_ini.set(setting.configKey(), value); + { + auto list = setting.configKeys(); + m_ini.set(list.takeFirst(), value); + for(auto iter: list) + m_ini.remove(iter); + } + // invalid -> remove all (just like resetSetting) else - m_ini.remove(setting.configKey()); + { + for(auto iter: setting.configKeys()) + m_ini.remove(iter); + } m_ini.saveFile(m_filePath); } } void INISettingsObject::resetSetting(const Setting &setting) { + // if we have the setting, remove all the synonyms. ALL OF THEM if (contains(setting.id())) { - m_ini.remove(setting.configKey()); + for(auto iter: setting.configKeys()) + m_ini.remove(iter); m_ini.saveFile(m_filePath); } } QVariant INISettingsObject::retrieveValue(const Setting &setting) { + // if we have the setting, return value of the first matching synonym if (contains(setting.id())) { - return m_ini.get(setting.configKey(), QVariant()); - } - else - { - return QVariant(); + for(auto iter: setting.configKeys()) + { + if(m_ini.contains(iter)) + return m_ini[iter]; + } } + return QVariant(); } diff --git a/depends/settings/include/inisettingsobject.h b/depends/settings/inisettingsobject.h index 8badc0c6..8badc0c6 100644 --- a/depends/settings/include/inisettingsobject.h +++ b/depends/settings/inisettingsobject.h diff --git a/depends/settings/include/libsettings_config.h b/depends/settings/libsettings_config.h index ba77f640..e5beed28 100644 --- a/depends/settings/include/libsettings_config.h +++ b/depends/settings/libsettings_config.h @@ -26,3 +26,4 @@ #define LIBSETTINGS_EXPORT Q_DECL_IMPORT #endif #endif + diff --git a/depends/settings/src/overridesetting.cpp b/depends/settings/overridesetting.cpp index 5b10920d..7b5f5418 100644 --- a/depends/settings/src/overridesetting.cpp +++ b/depends/settings/overridesetting.cpp @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "include/overridesetting.h" +#include "overridesetting.h" -OverrideSetting::OverrideSetting(const QString &name, Setting *other, QObject *parent) - : Setting(name, QVariant(), parent) +OverrideSetting::OverrideSetting(std::shared_ptr<Setting> other) + : Setting(other->configKeys(), QVariant()) { m_other = other; } diff --git a/depends/settings/include/overridesetting.h b/depends/settings/overridesetting.h index 3e60dc7c..5ef901d0 100644 --- a/depends/settings/include/overridesetting.h +++ b/depends/settings/overridesetting.h @@ -16,6 +16,7 @@ #pragma once #include <QObject> +#include <memory> #include "setting.h" @@ -31,10 +32,10 @@ class LIBSETTINGS_EXPORT OverrideSetting : public Setting { Q_OBJECT public: - explicit OverrideSetting(const QString &name, Setting *other, QObject *parent = 0); + explicit OverrideSetting(std::shared_ptr<Setting> other); virtual QVariant defValue() const; protected: - Setting *m_other; + std::shared_ptr<Setting> m_other; }; diff --git a/depends/settings/src/setting.cpp b/depends/settings/setting.cpp index 899463dc..0d685771 100644 --- a/depends/settings/src/setting.cpp +++ b/depends/settings/setting.cpp @@ -13,17 +13,17 @@ * limitations under the License. */ -#include "include/setting.h" -#include "include/settingsobject.h" +#include "setting.h" +#include "settingsobject.h" -Setting::Setting(QString id, QVariant defVal, QObject *parent) - : QObject(parent), m_id(id), m_defVal(defVal) +Setting::Setting(QStringList synonyms, QVariant defVal) + : QObject(), m_synonyms(synonyms), m_defVal(defVal) { } QVariant Setting::get() const { - SettingsObject *sbase = qobject_cast<SettingsObject *>(parent()); + SettingsObject *sbase = m_storage; if (!sbase) { return defValue(); diff --git a/depends/settings/include/setting.h b/depends/settings/setting.h index 39490207..a73474d2 100644 --- a/depends/settings/include/setting.h +++ b/depends/settings/setting.h @@ -17,6 +17,8 @@ #include <QObject> #include <QVariant> +#include <QStringList> +#include <memory> #include "libsettings_config.h" @@ -29,11 +31,16 @@ 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. + /** + * Construct a Setting + * + * Synonyms are all the possible names used in the settings object, in order of preference. + * First synonym is the ID, which identifies the setting in MultiMC. + * + * defVal is the default value that will be returned when the settings object + * doesn't have any value for this setting. */ - explicit Setting(QString id, QVariant defVal = QVariant(), QObject *parent = 0); + explicit Setting(QStringList synonyms, QVariant defVal = QVariant()); /*! * \brief Gets this setting's ID. @@ -44,7 +51,7 @@ public: */ virtual QString id() const { - return m_id; + return m_synonyms.first(); } /*! @@ -53,9 +60,9 @@ public: * the same as the setting's ID, but it can be different. * \return The setting's config file key. */ - virtual QString configKey() const + virtual QStringList configKeys() const { - return id(); + return m_synonyms; } /*! @@ -68,16 +75,6 @@ public: 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. */ @@ -111,11 +108,12 @@ slots: * \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; + friend class SettingsObject; + SettingsObject * m_storage; + QStringList m_synonyms; QVariant m_defVal; }; diff --git a/depends/settings/src/settingsobject.cpp b/depends/settings/settingsobject.cpp index 32a63b8d..43fc989a 100644 --- a/depends/settings/src/settingsobject.cpp +++ b/depends/settings/settingsobject.cpp @@ -13,8 +13,9 @@ * limitations under the License. */ -#include "include/settingsobject.h" -#include "include/setting.h" +#include "settingsobject.h" +#include "setting.h" +#include "overridesetting.h" #include <QVariant> @@ -22,17 +23,49 @@ SettingsObject::SettingsObject(QObject *parent) : QObject(parent) { } -bool SettingsObject::registerSetting(Setting *setting) +SettingsObject::~SettingsObject() { - // Check if setting is null or we already have a setting with the same ID. - if (!setting) + m_settings.clear(); +} + +std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Setting> original) +{ + if (contains(original->id())) { - qDebug(QString("Failed to register setting. Setting is null.") - .arg(setting->id()) + qDebug(QString("Failed to register setting %1. ID already exists.") + .arg(original->id()) .toUtf8()); - return false; // Fail + return nullptr; // Fail } + auto override = std::make_shared<OverrideSetting>(original); + override->m_storage = this; + connectSignals(*override); + m_settings.insert(override->id(), override); + return override; +} + +std::shared_ptr<Setting> SettingsObject::registerSetting(QStringList synonyms, QVariant defVal) +{ + if (synonyms.empty()) + return nullptr; + if (contains(synonyms.first())) + { + qDebug(QString("Failed to register setting %1. ID already exists.") + .arg(synonyms.first()) + .toUtf8()); + return nullptr; // Fail + } + auto setting = std::make_shared<Setting>(synonyms, defVal); + setting->m_storage = this; + connectSignals(*setting); + m_settings.insert(setting->id(), setting); + return setting; +} + +/* +bool SettingsObject::registerSetting(Setting *setting) +{ if (contains(setting->id())) { qDebug(QString("Failed to register setting %1. ID already exists.") @@ -50,21 +83,8 @@ bool SettingsObject::registerSetting(Setting *setting) // qDebug(QString("Registered setting %1.").arg(setting->id()).toUtf8()); return true; } - -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 +*/ +std::shared_ptr<Setting> SettingsObject::getSetting(const QString &id) const { // Make sure there is a setting with the given ID. if (!m_settings.contains(id)) @@ -75,13 +95,13 @@ Setting *SettingsObject::getSetting(const QString &id) const QVariant SettingsObject::get(const QString &id) const { - Setting *setting = getSetting(id); + auto setting = getSetting(id); return (setting ? setting->get() : QVariant()); } bool SettingsObject::set(const QString &id, QVariant value) { - Setting *setting = getSetting(id); + auto setting = getSetting(id); if (!setting) { qDebug(QString("Error changing setting %1. Setting doesn't exist.").arg(id).toUtf8()); @@ -96,16 +116,11 @@ bool SettingsObject::set(const QString &id, QVariant value) void SettingsObject::reset(const QString &id) const { - Setting *setting = getSetting(id); + auto setting = getSetting(id); if (setting) setting->reset(); } -QList<Setting *> SettingsObject::getSettings() -{ - return m_settings.values(); -} - bool SettingsObject::contains(const QString &id) { return m_settings.contains(id); @@ -121,16 +136,3 @@ void SettingsObject::connectSignals(const Setting &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))); -} diff --git a/depends/settings/include/settingsobject.h b/depends/settings/settingsobject.h index 7a6b3cb6..27746f2d 100644 --- a/depends/settings/include/settingsobject.h +++ b/depends/settings/settingsobject.h @@ -17,6 +17,9 @@ #include <QObject> #include <QMap> +#include <QStringList> +#include <QVariant> +#include <memory> #include "libsettings_config.h" @@ -39,32 +42,37 @@ class LIBSETTINGS_EXPORT SettingsObject : public QObject Q_OBJECT public: explicit SettingsObject(QObject *parent = 0); + virtual ~SettingsObject(); + /*! + * Registers an override setting for the given original setting in this settings object + * + * This will fail if there is already a setting with the same ID as + * the one that is being registered. + * \return A valid Setting shared pointer if successful. + */ + std::shared_ptr<Setting> registerOverride(std::shared_ptr<Setting> original); /*! - * \brief Registers the given setting with this SettingsObject and connects the necessary - * signals. + * 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. + * \return A valid Setting shared pointer if successful. */ - virtual bool registerSetting(Setting *setting); + std::shared_ptr<Setting> registerSetting(QStringList synonyms, + QVariant defVal = QVariant()); /*! - * \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. + * 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. + * \return A valid Setting shared pointer if successful. */ - virtual void unregisterSetting(Setting *setting); + std::shared_ptr<Setting> registerSetting(QString id, QVariant defVal = QVariant()) + { + return registerSetting(QStringList(id), defVal); + } /*! * \brief Gets the setting with the given ID. @@ -73,18 +81,7 @@ public: * 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); - } + std::shared_ptr<Setting> getSetting(const QString &id) const; /*! * \brief Gets the value of the setting with the given ID. @@ -92,7 +89,7 @@ public: * \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; + QVariant get(const QString &id) const; /*! * \brief Sets the value of the setting with the given ID. @@ -101,27 +98,20 @@ public: * \param value The new value of the setting. * \return True if successful, false if it failed. */ - virtual bool set(const QString &id, QVariant value); + 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(); + void reset(const QString &id) const; /*! * \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); + bool contains(const QString &id); signals: /*! @@ -167,13 +157,7 @@ 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); + void connectSignals(const Setting &setting); /*! * \brief Function used by Setting objects to get their values from the SettingsObject. @@ -185,5 +169,5 @@ protected: friend class Setting; private: - QMap<QString, Setting *> m_settings; + QMap<QString, std::shared_ptr<Setting>> m_settings; }; diff --git a/depends/settings/src/basicsettingsobject.cpp b/depends/settings/src/basicsettingsobject.cpp deleted file mode 100644 index 96b38851..00000000 --- a/depends/settings/src/basicsettingsobject.cpp +++ /dev/null @@ -1,44 +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. - */ - -#include "include/basicsettingsobject.h" -#include "include/setting.h" - -BasicSettingsObject::BasicSettingsObject(QObject *parent) : SettingsObject(parent) -{ -} - -void BasicSettingsObject::changeSetting(const Setting &setting, QVariant value) -{ - if (contains(setting.id())) - { - if (value.isValid()) - config.setValue(setting.configKey(), value); - else - config.remove(setting.configKey()); - } -} - -QVariant BasicSettingsObject::retrieveValue(const Setting &setting) -{ - if (contains(setting.id())) - { - return config.value(setting.configKey()); - } - else - { - return QVariant(); - } -} diff --git a/depends/settings/src/keyring.cpp b/depends/settings/src/keyring.cpp deleted file mode 100644 index 9eaba684..00000000 --- a/depends/settings/src/keyring.cpp +++ /dev/null @@ -1,63 +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. - */ - -#include "include/keyring.h" - -#include "osutils.h" - -#include "stubkeyring.h" - -// system specific keyrings -/*#if defined(OSX) -class OSXKeychain; -#define KEYRING OSXKeychain -#elif defined(LINUX) -class XDGKeyring; -#define KEYRING XDGKeyring -#elif defined(WINDOWS) -class Win32Keystore; -#define KEYRING Win32Keystore -#else -#pragma message Keyrings are not supported on your os. Falling back to the insecure StubKeyring -#endif*/ - -Keyring *Keyring::instance() -{ - if (m_instance == nullptr) - { -#ifdef KEYRING - m_instance = new KEYRING(); - if (!m_instance->isValid()) - { - qWarning("Could not create SystemKeyring! falling back to StubKeyring."); - m_instance = new StubKeyring(); - } -#else - qWarning("Keyrings are not supported on your OS. Fallback StubKeyring is insecure!"); - m_instance = new StubKeyring(); -#endif - atexit(Keyring::destroy); - } - return m_instance; -} - -void Keyring::destroy() -{ - delete m_instance; -} - -Keyring *Keyring::m_instance; diff --git a/depends/settings/src/stubkeyring.cpp b/depends/settings/src/stubkeyring.cpp deleted file mode 100644 index 53fca025..00000000 --- a/depends/settings/src/stubkeyring.cpp +++ /dev/null @@ -1,105 +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. - */ - -#include "stubkeyring.h" - -#include <QStringList> - -// Scrambling -// this is NOT SAFE, but it's not plain either. -int scrambler = 0x9586309; - -QString scramble(QString in_) -{ - QByteArray in = in_.toUtf8(); - QByteArray out; - for (int i = 0; i < in.length(); i++) - out.append(in.at(i) ^ scrambler); - return QString::fromUtf8(out); -} - -inline QString base64(QString in) -{ - return QString(in.toUtf8().toBase64()); -} -inline QString unbase64(QString in) -{ - return QString::fromUtf8(QByteArray::fromBase64(in.toLatin1())); -} - -inline QString scramble64(QString in) -{ - return base64(scramble(in)); -} -inline QString unscramble64(QString in) -{ - return scramble(unbase64(in)); -} - -// StubKeyring implementation -inline QString generateKey(QString service, QString username) -{ - return QString("%1/%2").arg(base64(service)).arg(scramble64(username)); -} - -bool StubKeyring::storePassword(QString service, QString username, QString password) -{ - m_settings.setValue(generateKey(service, username), scramble64(password)); - return true; -} - -QString StubKeyring::getPassword(QString service, QString username) -{ - QString key = generateKey(service, username); - if (!m_settings.contains(key)) - return QString(); - return unscramble64(m_settings.value(key).toString()); -} - -bool StubKeyring::hasPassword(QString service, QString username) -{ - return m_settings.contains(generateKey(service, username)); -} - -QStringList StubKeyring::getStoredAccounts(QString service) -{ - service = base64(service).append('/'); - QStringList out; - QStringList in(m_settings.allKeys()); - QStringListIterator it(in); - while (it.hasNext()) - { - QString c = it.next(); - if (c.startsWith(service)) - out << unscramble64(c.mid(service.length())); - } - return out; -} - -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) -{ -} diff --git a/depends/settings/src/stubkeyring.h b/depends/settings/src/stubkeyring.h deleted file mode 100644 index 1f4b1be0..00000000 --- a/depends/settings/src/stubkeyring.h +++ /dev/null @@ -1,47 +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 "include/keyring.h" - -#include <QSettings> - -class StubKeyring : public Keyring -{ -public: - /** - * @brief virtual dtor - */ - virtual ~StubKeyring() {}; - - virtual bool storePassword(QString service, QString username, QString password); - virtual QString getPassword(QString service, QString username); - 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; - } - - QSettings m_settings; -}; |