blob: 8f6c7095bb82eabf4957291ce2b5ef550112be5e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <QObject>
#include <QEvent>
#include <QCoreApplication>
#include "Swiften/EventLoop/EventLoop.h"
namespace Swift {
class QtEventLoop : public QObject, public EventLoop {
public:
QtEventLoop() {}
~QtEventLoop() {
QCoreApplication::removePostedEvents(this);
}
virtual void post(const Swift::Event& event) {
QCoreApplication::postEvent(this, new Event(event));
}
virtual bool event(QEvent* qevent) {
Event* event = dynamic_cast<Event*>(qevent);
if (event) {
handleEvent(event->event_);
//event->deleteLater(); FIXME: Leak?
return true;
}
return false;
}
private:
struct Event : public QEvent {
Event(const Swift::Event& event) :
QEvent(QEvent::User), event_(event) {
}
Swift::Event event_;
};
};
}
|