00001
00002
00003
00004
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
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 }