aboutsummaryrefslogtreecommitdiff
path: root/eventemitter.h
diff options
context:
space:
mode:
Diffstat (limited to 'eventemitter.h')
-rw-r--r--eventemitter.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/eventemitter.h b/eventemitter.h
new file mode 100644
index 0000000..0b18a8e
--- /dev/null
+++ b/eventemitter.h
@@ -0,0 +1,55 @@
+#pragma once
+
+#include <QThread>
+#include <QObject>
+
+#include <iostream>
+#include <deltachat.h>
+#include "dcevent.h"
+
+class EventLoopThread : public QThread
+{
+ Q_OBJECT
+
+ dc_accounts_event_emitter_t *m_eventEmitter;
+ void run() override {
+ dc_event_t *event;
+ while((event = dc_accounts_get_next_event(m_eventEmitter))) {
+ emit emitEvent(new DcEvent{event});
+ }
+ std::cout << "NO MORE EVENTS!" << std::endl;
+ }
+public:
+ explicit EventLoopThread(QObject *parent = nullptr)
+ : QThread{parent}
+ {
+ }
+ void setEventEmitter(dc_accounts_event_emitter_t *eventEmitter)
+ {
+ m_eventEmitter = eventEmitter;
+ }
+
+signals:
+ void emitEvent(DcEvent *event);
+};
+
+class DcAccountsEventEmitter : public QObject {
+ Q_OBJECT
+
+ dc_accounts_event_emitter_t *m_accounts_event_emitter{nullptr};
+ EventLoopThread *m_eventLoopThread{nullptr};
+public:
+ explicit DcAccountsEventEmitter(QObject *parent = nullptr);
+ explicit DcAccountsEventEmitter(dc_accounts_event_emitter_t *emitter);
+ ~DcAccountsEventEmitter();
+
+ Q_INVOKABLE void start();
+ Q_INVOKABLE void stop();
+ Q_INVOKABLE void processEvent(DcEvent *event);
+
+signals:
+ void chatModified(uint32_t accountId, int chatId);
+ void incomingMessage(uint32_t accountId, int chatId, int msgId);
+ void messagesChanged(uint32_t accountId, int chatId, int msgId);
+ void incomingEvent();
+};