Changes: EventHandler works with both QApplication and MApplication event loop

RevBy: Antti Kervinen
pull/1/head
Alexey Shilov 15 years ago
parent 8e2c76731e
commit 320d12281f

@ -4,12 +4,13 @@
#include "booster.h"
#include <sys/socket.h>
#include <QtConcurrentRun>
#include <QApplication>
#include <MApplication>
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);
}

@ -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.

@ -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())

@ -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())

Loading…
Cancel
Save