From b8762ddb38dd975b0acb217b793594dfed83a824 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 12 Sep 2020 14:10:13 +0300 Subject: Initial commit --- eventemitter.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 eventemitter.h (limited to 'eventemitter.h') 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 +#include + +#include +#include +#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(); +}; -- cgit v1.2.3-70-g09d2