X-Git-Url: https://vaikene.ee/gitweb/pswgen09.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Fapp.cpp;h=f6668d956e997aa656bfbb29eba75a51f0df6ab8;hb=af2feaab777210b8fbd9190904df3dd187acf0cd;hp=21818f9ebe7d1e67e1e6eff9c911ac17bd22efdf;hpb=60aebc188674bbfb67be51958ec33171c72986b9;p=evaf
diff --git a/src/libs/Common/app.cpp b/src/libs/Common/app.cpp
index 21818f9..f6668d9 100644
--- a/src/libs/Common/app.cpp
+++ b/src/libs/Common/app.cpp
@@ -3,7 +3,7 @@
* @brief Application 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.
*
@@ -31,10 +31,18 @@
using namespace eVaf::Common;
+namespace
+{
+ static Internal::App * singleton = nullptr;
+}
+
iApp * iApp::instance()
{
- static Internal::App singleton;
- return &singleton;
+ if (nullptr == singleton)
+ {
+ singleton = new Internal::App;
+ }
+ return singleton;
}
char const * const iApp::EV_QUIT = "iApp::quit";
@@ -47,6 +55,15 @@ char const * const iApp::EV_TERMINATING = "iApp::terminating";
using namespace eVaf::Common::Internal;
+void App::destroyInstance()
+{
+ if (nullptr != singleton)
+ {
+ delete singleton;
+ singleton = nullptr;
+ }
+}
+
App::App()
: iApp()
, mReady(false)
@@ -57,11 +74,12 @@ App::App()
, mEvTerminating(0)
{
setObjectName(QString("%1.iApp").arg(VER_MODULE_NAME_STR));
-
+ EVAF_INFO("%s-App created", VER_MODULE_NAME_STR);
}
App::~App()
{
+ EVAF_INFO("%s-App destroyed", VER_MODULE_NAME_STR);
}
bool App::init()
@@ -206,7 +224,7 @@ bool App::event(QEvent * e)
QString const App::dataRootDir() const
{
if (mDataRootDir.isEmpty()) {
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
QString dataLoc = QDir::homePath();
if (!dataLoc.endsWith('/'))
dataLoc.append('/');
@@ -274,6 +292,14 @@ QString const App::xmlFileName() const
return mXmlFile;
}
+int App::exec()
+{
+ setReady(true);
+ int rval = QCoreApplication::exec();
+ setReady(false);
+ return rval;
+}
+
void App::restart()
{
QCoreApplication::exit(RC_Restart);
@@ -283,3 +309,15 @@ void App::quit(bool err)
{
QCoreApplication::exit(err ? RC_Error : RC_Quit);
}
+
+void App::setReady(bool value)
+{
+ if (mReady != value) {
+ mReady = value;
+ iEventQueue::instance()->broadcastEvent(new Event(mReady ? mEvReady : mEvTerminating));
+ if (mReady)
+ emit ready();
+ else
+ emit terminating();
+ }
+}