aboutsummaryrefslogtreecommitdiff
path: root/eventemitter.cpp
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.cpp
downloadkdeltachat-b8762ddb38dd975b0acb217b793594dfed83a824.tar.gz
kdeltachat-b8762ddb38dd975b0acb217b793594dfed83a824.zip
Initial commit
Diffstat (limited to 'eventemitter.cpp')
-rw-r--r--eventemitter.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/eventemitter.cpp b/eventemitter.cpp
new file mode 100644
index 0000000..7c4d928
--- /dev/null
+++ b/eventemitter.cpp
@@ -0,0 +1,100 @@
+#include "eventemitter.h"
+
+DcAccountsEventEmitter::DcAccountsEventEmitter(QObject *parent)
+ : QObject{parent}
+{
+}
+
+DcAccountsEventEmitter::DcAccountsEventEmitter(dc_accounts_event_emitter_t *emitter)
+ : QObject{nullptr}
+ , m_accounts_event_emitter{emitter}
+{
+}
+
+DcAccountsEventEmitter::~DcAccountsEventEmitter()
+{
+ if (m_eventLoopThread) {
+ qInfo("Waiting");
+ m_eventLoopThread->wait();
+ qInfo("Waiting finished");
+ }
+}
+
+void
+DcAccountsEventEmitter::start()
+{
+ std::cerr << "Starting loop thread" << std::endl;
+ m_eventLoopThread = new EventLoopThread(this);
+ std::cerr << "Started loop thread" << std::endl;
+ QObject::connect(m_eventLoopThread, &EventLoopThread::emitEvent,
+ this, &DcAccountsEventEmitter::processEvent);
+ m_eventLoopThread->setEventEmitter(m_accounts_event_emitter);
+ m_eventLoopThread->start();
+}
+
+void
+DcAccountsEventEmitter::stop()
+{
+ qInfo("Stopping event emitter");
+ dc_accounts_event_emitter_unref(m_accounts_event_emitter);
+}
+
+void
+DcAccountsEventEmitter::processEvent(DcEvent *event)
+{
+ emit incomingEvent();
+ switch (event->getId()) {
+ case DC_EVENT_INFO:
+ qInfo("%s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_SMTP_CONNECTED:
+ qInfo("SMTP connected: %s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_IMAP_CONNECTED:
+ qInfo("IMAP connected: %s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_SMTP_MESSAGE_SENT:
+ qInfo("SMTP message sent: %s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_IMAP_MESSAGE_DELETED:
+ qInfo("IMAP message deleted: %s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_IMAP_MESSAGE_MOVED:
+ qInfo("IMAP message moved: %s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_NEW_BLOB_FILE:
+ qInfo("New blob file: %s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_DELETED_BLOB_FILE:
+ qInfo("Deleted blob file: %s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_WARNING:
+ qWarning("%s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_ERROR:
+ qCritical("%s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_ERROR_NETWORK:
+ qCritical("Network error: %s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_ERROR_SELF_NOT_IN_GROUP:
+ qCritical("Self not in group error: %s", qUtf8Printable(event->getData2Str()));
+ break;
+ case DC_EVENT_CHAT_MODIFIED:
+ emit chatModified(event->getAccountId(), event->getData1Int());
+ break;
+ case DC_EVENT_MSGS_CHANGED:
+ emit messagesChanged(event->getAccountId(), event->getData1Int(), event->getData2Int());
+ break;
+ case DC_EVENT_INCOMING_MSG:
+ std::cout << "Emitting incoming message!" << std::endl;
+ emit incomingMessage(event->getAccountId(),
+ event->getData1Int(),
+ event->getData2Int());
+ std::cout << "Emitted incoming message!" << std::endl;
+ break;
+ default:
+ std::cout << "Not processing " << event->getId() << std::endl;
+ }
+ delete event;
+}