X-Git-Url: https://vaikene.ee/gitweb/highlight.css?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Fconfig.cpp;h=7ddc61ea9829b4270203fabfba61d143b0505abb;hb=de270ece1b764b19968e14420f538321f1c06b15;hp=610dd74d98b445ba766efad28cc0badf0df0e557;hpb=ec272061c2af46e4cd8730c18682e18ac5b369ff;p=evaf diff --git a/src/libs/Common/config.cpp b/src/libs/Common/config.cpp index 610dd74..7ddc61e 100644 --- a/src/libs/Common/config.cpp +++ b/src/libs/Common/config.cpp @@ -3,7 +3,7 @@ * @brief eVaf configuration interface implementation * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -30,10 +30,18 @@ using namespace eVaf::Common; +namespace +{ + static Internal::Config * singleton = nullptr; +} + iConfig * iConfig::instance() { - static Internal::Config singleton; - return singleton.interface(); + if (nullptr == singleton) + { + singleton = new Internal::Config; + } + return singleton->_interface(); } @@ -41,6 +49,15 @@ iConfig * iConfig::instance() using namespace eVaf::Common::Internal; +void Config::destroyInstance() +{ + if (nullptr != singleton) + { + delete singleton; + singleton = nullptr; + } +} + Config::Config() : iConfig() { @@ -48,14 +65,17 @@ Config::Config() // Register the iConfig interface iRegistry::instance()->registerInterface("iConfig", this); + + EVAF_INFO("%s-Config created", VER_MODULE_NAME_STR); } Config::~Config() { done(); + EVAF_INFO("%s-Config destroyed", VER_MODULE_NAME_STR); } -iConfig * Config::interface() const +iConfig * Config::_interface() const { return evafQueryInterface("iConfig"); } @@ -101,7 +121,7 @@ QVariant Config::getValue(QString const & paramName, QVariant const & defaultVal if (file.isEmpty() || file == "*") file = iApp::instance()->name(); - IniFile * ini = 0; + IniFile * ini = nullptr; // Is this INI file already opened? QHash::const_iterator it = mIniFiles.constFind(file); @@ -123,7 +143,7 @@ QVariant Config::getValue(QString const & paramName, QVariant const & defaultVal } // Read the value - return ini->getValue(name, defaultValue); + return ini->getValue(name.toLocal8Bit(), defaultValue); } bool Config::setValue(QString const & paramName, QVariant const & value, bool commit) @@ -176,7 +196,7 @@ bool Config::writeValue(QString const & paramName, QVariant const & value) if (file.isEmpty() || file == "*") file = iApp::instance()->name(); - IniFile * ini = 0; + IniFile * ini = nullptr; // Is this INI file already opened? QHash::const_iterator it = mIniFiles.constFind(file); @@ -198,7 +218,7 @@ bool Config::writeValue(QString const & paramName, QVariant const & value) } // Write the value - if (!ini->setValue(name, value)) + if (!ini->setValue(name.toLocal8Bit(), value)) return false; return true;