• Main Page
  • Classes
  • Files
  • File List

Swiften/EventLoop/Qt/QtEventLoop.h

00001 /*
00002  * Copyright (c) 2010 Remko Tronçon
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
00005  */
00006 
00007 #pragma once
00008 
00009 #include <QObject>
00010 #include <QEvent>
00011 #include <QCoreApplication>
00012 
00013 #include <Swiften/EventLoop/EventLoop.h>
00014 
00015 namespace Swift {
00016   class QtEventLoop : public QObject, public EventLoop {
00017     public:
00018       QtEventLoop() {}
00019       ~QtEventLoop() {
00020         QCoreApplication::removePostedEvents(this);
00021       }
00022 
00023       virtual void post(const Swift::Event& event) {
00024         QCoreApplication::postEvent(this, new Event(event));
00025       }
00026 
00027       virtual bool event(QEvent* qevent) {
00028         Event* event = dynamic_cast<Event*>(qevent);
00029         if (event) {
00030           handleEvent(event->event_);
00031           //event->deleteLater(); FIXME: Leak?
00032           return true;
00033         }
00034 
00035         return false;
00036       }
00037     
00038     private:
00039       struct Event : public QEvent {
00040           Event(const Swift::Event& event) :
00041               QEvent(QEvent::User), event_(event) {
00042           }
00043 
00044           Swift::Event event_;
00045       };
00046   };
00047 }

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1