aboutsummaryrefslogtreecommitdiff
path: root/eventemitter.h
diff options
context:
space:
mode:
authorlink2xt <link2xt@testrun.org>2020-09-12 14:10:13 +0300
committerlink2xt <link2xt@testrun.org>2020-10-03 00:20:03 +0300
commitb8762ddb38dd975b0acb217b793594dfed83a824 (patch)
tree23ccefbba703fed6c07acce82ff72e32ba77c9ba /eventemitter.h
downloadkdeltachat-b8762ddb38dd975b0acb217b793594dfed83a824.tar.gz
kdeltachat-b8762ddb38dd975b0acb217b793594dfed83a824.zip
Initial commit
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();
+};