summaryrefslogtreecommitdiffstats
blob: 40e927e5d25b5db20bea105f699035090e7ff7a8 (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
#pragma once

#include <QObject>
#include <QEvent>
#include <QCoreApplication>

#include "Swiften/EventLoop/EventLoop.h"

class QtEventLoop : public QObject, public Swift::EventLoop {
	public:
		QtEventLoop() {}

		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_;
		};
};