* @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.
*
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";
using namespace eVaf::Common::Internal;
+void App::destroyInstance()
+{
+ if (nullptr != singleton)
+ {
+ delete singleton;
+ singleton = nullptr;
+ }
+}
+
App::App()
: iApp()
, mReady(false)
, 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()
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('/');
return mXmlFile;
}
+int App::exec()
+{
+ setReady(true);
+ int const rval = QCoreApplication::exec();
+ setReady(false);
+ return rval;
+}
+
void App::restart()
{
QCoreApplication::exit(RC_Restart);
{
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();
+ }
+}