/** * @file Common/config.h * @brief eVaf configuration interface implementation * @author Enar Vaikene * * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * * This file can be used under the terms of the GNU General Public License * version 3.0 as published by the Free Software Foundation and appearing in * the file LICENSE included in the packaging of this file. Please review the * the following information to ensure the GNU General Public License version * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. * * Alternatively, this file may be used in accordance with the Commercial License * Agreement provided with the Software. */ #ifndef __COMMON_CONFIG_H # define __COMMON_CONFIG_H #include "iconfig.h" #include #include #include #include #include namespace eVaf { namespace Common { class IniFile; namespace Internal { /** * Structure for queued write operations */ struct NameValuePair { NameValuePair(QString const & n, QVariant const & v) : name(n) , value(v) {} QString name; QVariant value; }; /** * Default implementation of the iConfig interface. * * This class implements the iConfig interface using INI files in the eVaf::Common::iApp::instance()->etcDir() directory. */ class Config : public iConfig { Q_OBJECT public: /** * Destroys the iConfig interface instance. */ static void destroyInstance(); Config(); virtual ~Config(); /** * Returns the current implementation of the iConfig interface */ iConfig * _interface() const; /** * Initializes the iConfig interface implementation. * @return True if succeeded; false if not */ bool init(); /** * Finalizes the iConfig interface implementation. */ void done(); /* iConfig interface */ virtual QVariant getValue(QString const & paramName, QVariant const & defaultValue) const; virtual bool setValue(QString const & paramName, QVariant const & value, bool commit); private: // Members /// List of already opened INI files mutable QHash mIniFiles; /// Commit queue QQueue mCommitQueue; private: // Methods /// Commits queued parameters bool commitValues(); /// Writes a parameter value to the INI file bool writeValue(QString const & paramName, QVariant const & value); /// Writes a name/value pair to the INI file inline bool writeValue(NameValuePair const & param) { return writeValue(param.name, param.value); } }; } // namespace eVaf::Common::Internal } // namespace eVaf::Common } // namespace eVaf #endif // config.h