From 320d12281f3fe28cd8dcdf0ba41d97d8180ca408 Mon Sep 17 00:00:00 2001 From: Alexey Shilov Date: Thu, 17 Feb 2011 15:43:26 +0200 Subject: [PATCH] Changes: EventHandler works with both QApplication and MApplication event loop RevBy: Antti Kervinen --- src/common/eventhandler.cpp | 39 +++++++++++++------ src/common/eventhandler.h | 11 +++++- src/mbooster/mbooster.cpp | 2 +- .../qdeclarativebooster.cpp | 2 +- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/common/eventhandler.cpp b/src/common/eventhandler.cpp index 69c816f..ebc58b1 100644 --- a/src/common/eventhandler.cpp +++ b/src/common/eventhandler.cpp @@ -4,12 +4,13 @@ #include "booster.h" #include #include +#include #include int EventHandler::m_sighupFd[2]; struct sigaction EventHandler::m_oldSigAction; -EventHandler::EventHandler(Booster* parent) : m_item(0), m_parent(parent) +EventHandler::EventHandler(Booster* parent, EventHandlerType type) : m_item(0), m_parent(parent), m_type(type) { } @@ -17,13 +18,22 @@ void EventHandler::runEventLoop() { Logger::logError(" EventHandler::runEventLoop() "); - // Exit from event loop when invoker is ready to connect - connect(this, SIGNAL(connectionAccepted()), QApplication::instance() , SLOT(quit())); - connect(this, SIGNAL(connectionRejected()), QApplication::instance() , SLOT(quit())); + if (m_type == MEventHandler) + { + // Exit from event loop when invoker is ready to connect + connect(this, SIGNAL(connectionAccepted()), MApplication::instance(), SLOT(quit())); + connect(this, SIGNAL(connectionRejected()), MApplication::instance(), SLOT(quit())); - // Enable theme change handler - m_item = new MGConfItem(MEEGOTOUCH_THEME_GCONF_KEY, 0); - connect(m_item, SIGNAL(valueChanged()), this, SLOT(notifyThemeChange())); + // Enable theme change handler + m_item = new MGConfItem(MEEGOTOUCH_THEME_GCONF_KEY, 0); + connect(m_item, SIGNAL(valueChanged()), this, SLOT(notifyThemeChange())); + } + else if (m_type == QEventHandler) + { + // Exit from event loop when invoker is ready to connect + connect(this, SIGNAL(connectionAccepted()), QApplication::instance(), SLOT(quit())); + connect(this, SIGNAL(connectionRejected()), QApplication::instance(), SLOT(quit())); + } // Start another thread to listen connection from invoker QtConcurrent::run(this, &EventHandler::accept); @@ -47,8 +57,11 @@ void EventHandler::runEventLoop() handlerIsSet = true; } - // Run event loop so MApplication and MApplicationWindow objects can receive notifications - MApplication::exec(); + // Run event loop so application instance can receive notifications + if (m_type == MEventHandler) + MApplication::exec(); + else if (m_type == QEventHandler) + QApplication::exec(); // Disable theme change handler disconnect(m_item, 0, this, 0); @@ -72,11 +85,11 @@ void EventHandler::accept() { emit connectionRejected(); } - } void EventHandler::notifyThemeChange() { + // only MApplication is connected to this signal MApplication::quit(); ::_exit(EXIT_SUCCESS); } @@ -96,7 +109,11 @@ void EventHandler::hupSignalHandler(int) void EventHandler::handleSigHup() { - MApplication::quit(); + if (m_type == MEventHandler) + MApplication::quit(); + else if (m_type == QEventHandler) + QApplication::quit(); + ::_exit(EXIT_SUCCESS); } diff --git a/src/common/eventhandler.h b/src/common/eventhandler.h index 2be0abc..a7d9fc2 100644 --- a/src/common/eventhandler.h +++ b/src/common/eventhandler.h @@ -15,8 +15,14 @@ class EventHandler : public QObject public: + enum EventHandlerType + { + QEventHandler, + MEventHandler + }; + //! \brief Constructor - EventHandler(Booster* parent); + EventHandler(Booster* parent, EventHandlerType type); //! \brief Destructor virtual ~EventHandler() {} @@ -52,6 +58,9 @@ private: // Parent object Booster* m_parent; + // type of application's event loop + const EventHandlerType m_type; + private slots: //! Qt signal handler for SIGHUP. diff --git a/src/mbooster/mbooster.cpp b/src/mbooster/mbooster.cpp index e89c041..2c538b3 100644 --- a/src/mbooster/mbooster.cpp +++ b/src/mbooster/mbooster.cpp @@ -78,7 +78,7 @@ bool MBooster::receiveDataFromInvoker(int socketFd) // Setup the conversation channel with the invoker. setConnection(new Connection(socketFd)); - EventHandler handler(this); + EventHandler handler(this, EventHandler::MEventHandler); handler.runEventLoop(); if (!connection()->connected()) diff --git a/src/qdeclarativebooster/qdeclarativebooster.cpp b/src/qdeclarativebooster/qdeclarativebooster.cpp index 0a5f0ce..f3a6647 100644 --- a/src/qdeclarativebooster/qdeclarativebooster.cpp +++ b/src/qdeclarativebooster/qdeclarativebooster.cpp @@ -69,7 +69,7 @@ bool QDeclarativeBooster::receiveDataFromInvoker(int socketFd) // Setup the conversation channel with the invoker. setConnection(new Connection(socketFd)); - EventHandler handler(this); + EventHandler handler(this, EventHandler::QEventHandler); handler.runEventLoop(); if (!connection()->connected())