X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Fapp.cpp;h=60ee5bf698d00b809e6050bd2b6f17c9b4f8d76c;hb=602faa7b96d4467f127ccd581228ca7245283c32;hp=53efce95d319ad6cc12eea546d5b9f1189202275;hpb=be0e791df48f5a8c9bb4c16f65b62e41e1149552;p=evaf
diff --git a/src/libs/Common/app.cpp b/src/libs/Common/app.cpp
index 53efce9..60ee5bf 100644
--- a/src/libs/Common/app.cpp
+++ b/src/libs/Common/app.cpp
@@ -19,7 +19,9 @@
#include "app.h"
#include "globals.h"
-#include "registry.h"
+#include "iregistry.h"
+#include "ieventqueue.h"
+#include "event.h"
#include "version.h"
#include
@@ -49,6 +51,10 @@ App::App()
: iApp()
, mReady(false)
, mName(VER_PRODUCT_NAME_STR)
+ , mEvQuit(0)
+ , mEvRestart(0)
+ , mEvReady(0)
+ , mEvTerminating(0)
{
setObjectName(QString("%1.iApp").arg(VER_MODULE_NAME_STR));
@@ -63,6 +69,12 @@ bool App::init()
// Register our interface
iRegistry::instance()->registerInterface("iApp", this);
+ // Register events
+ mEvQuit = iEventQueue::instance()->subscribeEvent(iEventQueue::instance()->registerEvent(EV_QUIT), this);
+ mEvRestart = iEventQueue::instance()->subscribeEvent(iEventQueue::instance()->registerEvent(EV_RESTART), this);
+ mEvReady = iEventQueue::instance()->registerEvent(EV_READY);
+ mEvTerminating = iEventQueue::instance()->registerEvent(EV_TERMINATING);
+
// Set the default application name and language
mName = VER_PRODUCT_NAME_STR;
mLanguage = QLocale::system().name();
@@ -176,6 +188,21 @@ bool App::init()
return true;
}
+bool App::event(QEvent * e)
+{
+ if (e->type() == Event::eVafEvent) {
+ Event * event = static_cast(e);
+ if (event->id() == mEvQuit)
+ quit();
+ else if (event->id() == mEvRestart)
+ restart();
+
+ return false;
+ }
+ else
+ return iApp::event(e);
+}
+
QString const App::dataRootDir() const
{
if (mDataRootDir.isEmpty()) {
@@ -247,6 +274,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);
@@ -256,3 +291,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();
+ }
+}