X-Git-Url: https://vaikene.ee/gitweb/pswgen09.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Fprop.cpp;h=b76c3c5417d54ae4942d16912d491602c76ea689;hb=13dedf19c628b9967e4c4106ab0fd967f1df0b90;hp=b3ccb6fa98b383d9ebc3ee034c1dee88e7c4b9e4;hpb=f01d61fb753b347bbff2ffb7f224650ac3f9d81e;p=evaf
diff --git a/src/libs/Common/prop.cpp b/src/libs/Common/prop.cpp
index b3ccb6f..b76c3c5 100644
--- a/src/libs/Common/prop.cpp
+++ b/src/libs/Common/prop.cpp
@@ -3,7 +3,7 @@
* @brief Implementation of the iProp interface
* @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.
*
@@ -31,10 +31,18 @@
using namespace eVaf::Common;
+namespace
+{
+ static Internal::Prop * singleton = nullptr;
+}
+
iProp * iProp::instance()
{
- static Internal::Prop singleton;
- return singleton.interface();
+ if (nullptr == singleton)
+ {
+ singleton = new Internal::Prop;
+ }
+ return singleton->_interface();
}
@@ -42,28 +50,39 @@ iProp * iProp::instance()
using namespace eVaf::Common::Internal;
+void Prop::destroyInstance()
+{
+ if (nullptr != singleton)
+ {
+ delete singleton;
+ singleton = nullptr;
+ }
+}
+
Prop::Prop()
: iProp()
- , mPersistentProps(0)
{
setObjectName(QString("%1.iProp").arg(VER_MODULE_NAME_STR));
+
+ // Register the iProp interface
+ iRegistry::instance()->registerInterface("iProp", this);
+
+ EVAF_INFO("%s-Prop created", VER_MODULE_NAME_STR);
}
Prop::~Prop()
{
done();
+ EVAF_INFO("%s-Prop destroyed", VER_MODULE_NAME_STR);
}
-iProp * Prop::interface() const
+iProp * Prop::_interface() const
{
return evafQueryInterface("iProp");
}
bool Prop::init()
{
- // Register the iProp interface
- iRegistry::instance()->registerInterface("iProp", this);
-
// Set application name and language properties
setValue("applicationName", iApp::instance()->name());
setValue("applicationLanguage", iApp::instance()->language());
@@ -80,7 +99,7 @@ bool Prop::init()
isProp = true;
}
else if (isProp && xml.name() == "property") {
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
if (isTrue(xml.attributes().value("windowsonly").toString()))
continue;
#endif
@@ -116,9 +135,10 @@ bool Prop::init()
}
// Initialize persistent properties
- if (mPersistentProps)
- delete mPersistentProps;
- mPersistentProps = new QSettings(QString("%1/.%2.dat").arg(iApp::instance()->dataRootDir()).arg(iApp::instance()->name()), QSettings::IniFormat);
+ mPersistentProps.reset(new QSettings(QString("%1/.%2.dat")
+ .arg(iApp::instance()->dataRootDir())
+ .arg(iApp::instance()->name()),
+ QSettings::IniFormat));
QStringList keys = mPersistentProps->allKeys();
for (int i = 0; i < keys.size(); ++i) {
QString key = keys.at(i);
@@ -130,10 +150,7 @@ bool Prop::init()
void Prop::done()
{
- if (mPersistentProps) {
- delete mPersistentProps;
- mPersistentProps = 0;
- }
+ mPersistentProps.reset();
}
QVariant Prop::getValue(QString const & name, QVariant const & defaultValue) const