aboutsummaryrefslogtreecommitdiff
path: root/eventemitter.cpp
blob: 5d8c763a087f22f7402936c04f27a3d1b9089853 (plain) (blame)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#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) {
        m_eventLoopThread->wait();
    }
}

void
DcAccountsEventEmitter::start()
{
    m_eventLoopThread = new EventLoopThread(this);
    QObject::connect(m_eventLoopThread, &EventLoopThread::emitEvent,
                     this, &DcAccountsEventEmitter::processEvent);
    m_eventLoopThread->setEventEmitter(m_accounts_event_emitter);
    m_eventLoopThread->start();
}

void
DcAccountsEventEmitter::processEvent(DcEvent *event)
{
    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_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:
            emit incomingMessage(event->getAccountId(),
                                 event->getData1Int(),
                                 event->getData2Int());
            break;
        case DC_EVENT_MSGS_NOTICED:
            emit messagesNoticed(event->getAccountId(), event->getData1Int());
            break;
        case DC_EVENT_CONFIGURE_PROGRESS:
            emit configureProgress(event->getAccountId(),
                                   event->getData1Int(),
                                   event->getData2Str());
            break;
        default:
            std::cout << "Not processing " << event->getId() << std::endl;
    }
    delete event;
}