aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
blob: 57334a4ba87ae7db6378db5ddff46ddc3000eb4b (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
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QMetaType>
#include <QtWebEngine>

#include "accounts.h"
#include "message.h"
#include "chat.h"
#include "chatlist.h"
#include "context.h"
#include "contact.h"
#include "eventemitter.h"

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);

    QtWebEngine::initialize();
    QGuiApplication app(argc, argv);

    app.setApplicationName("KDeltaChat");
    app.setOrganizationName("KDeltaChat");
    app.setOrganizationDomain("delta.chat");

    // TODO: switch to using Qt 5.15 QML_ELEMENT macro
    if (qmlRegisterType<DcAccounts>("DeltaChat", 1, 0, "DcAccounts") == -1)
      {
        QCoreApplication::exit(-1);
      }
    if (qmlRegisterType<Context>("DeltaChat", 1, 0, "DcContext") == -1)
      {
        QCoreApplication::exit(-1);
      }
    if (qmlRegisterType<DcChatlist>("DeltaChat", 1, 0, "DcChatlist") == -1)
      {
        QCoreApplication::exit(-1);
      }
    if (qmlRegisterType<DcChat>("DeltaChat", 1, 0, "DcChat") == -1)
      {
        QCoreApplication::exit(-1);
      }
    if (qmlRegisterType<DcMessage>("DeltaChat", 1, 0, "DcMessage") == -1)
      {
        QCoreApplication::exit(-1);
      }
    if (qmlRegisterType<DcContact>("DeltaChat", 1, 0, "DcContact") == -1)
      {
        QCoreApplication::exit(-1);
      }
    if (qmlRegisterType<DcLot>("DeltaChat", 1, 0, "DcLot") == -1)
      {
        QCoreApplication::exit(-1);
      }
    if (qmlRegisterType<DcAccountsEventEmitter>("DeltaChat", 1, 0, "DcAccountsEventEmitter") == -1)
      {
        QCoreApplication::exit(-1);
      }
    qRegisterMetaType<size_t>("size_t");
    qRegisterMetaType<uint32_t>("uint32_t");
    qRegisterMetaType<QVector<uint32_t>>("QVector<uint32_t>");

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}