main.cpp 3.34 KB
Newer Older
1
/**
2
3
 * SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@kde.org>
 * SPDX-FileCopyrightText: 2018 Simon Redman <simon@ergotech.com>
4
 *
5
 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
6
7
 */

8
9
#include "conversationmodel.h"
#include "conversationlistmodel.h"
10
#include "conversationssortfilterproxymodel.h"
11
#include "thumbnailsprovider.h"
12
13
#include "kdeconnect-version.h"

14
15
16
17
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QCommandLineParser>
#include <QQmlContext>
18
#include <QQuickStyle>
19
20
21
22
23
#include <KAboutData>
#include <KLocalizedString>
#include <KLocalizedContext>
#include <KDBusService>

24
25
#include "smshelper.h"

26
27
int main(int argc, char *argv[])
{
Nicolas Fella's avatar
Nicolas Fella committed
28
    QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
29
    QApplication app(argc, argv);
30
    app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect")));
Simon Redman's avatar
Simon Redman committed
31
32
    KAboutData aboutData(QStringLiteral("kdeconnect.sms"),
                         i18n("KDE Connect SMS"),
33
34
                         QStringLiteral(KDECONNECT_VERSION_STRING),
                         i18n("SMS Instant Messaging"),
Simon Redman's avatar
Simon Redman committed
35
                         KAboutLicense::GPL_V3,
Simon Redman's avatar
Simon Redman committed
36
                         i18n("(C) 2018-2019, KDE Connect Team"));
37
    aboutData.addAuthor(i18n("Simon Redman"), {}, QStringLiteral("simon@ergotech.com"));
38
39
    aboutData.addAuthor(i18n("Aleix Pol Gonzalez"), {}, QStringLiteral("aleixpol@kde.org"));
    aboutData.addAuthor(i18n("Nicolas Fella"), {}, QStringLiteral("nicolas.fella@gmx.de"));
40
41
    KAboutData::setApplicationData(aboutData);

42
43
44
45
#ifdef Q_OS_WIN
    QApplication::setStyle(QStringLiteral("breeze"));
#endif

46
47
48
49
50
    // Default to org.kde.desktop style unless the user forces another style
    if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
        QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
    }

51
    QString initialMessage, deviceid;
52

53
54
55
    {
        QCommandLineParser parser;
        aboutData.setupCommandLine(&parser);
56
        parser.addOption(QCommandLineOption(QStringLiteral("device"), i18n("Select a device"), i18n("id")));
57
        parser.addOption(QCommandLineOption(QStringLiteral("message"), i18n("Send a message"), i18n("message")));
58
59
        parser.process(app);
        aboutData.processCommandLine(&parser);
60

61
62
        initialMessage = parser.value(QStringLiteral("message"));
        deviceid = parser.value(QStringLiteral("device"));
63
64
65
    }

    KDBusService service(KDBusService::Unique);
66

67
    qmlRegisterType<ConversationsSortFilterProxyModel>("org.kde.kdeconnect.sms", 1, 0, "QSortFilterProxyModel");
68
    qmlRegisterType<ConversationModel>("org.kde.kdeconnect.sms", 1, 0, "ConversationModel");
69
    qmlRegisterType<ConversationListModel>("org.kde.kdeconnect.sms", 1, 0, "ConversationListModel");
70

71
72
    qmlRegisterSingletonType<SmsHelper>("org.kde.kdeconnect.sms", 1, 0, "SmsHelper", SmsHelper::singletonProvider);

73
74
    QQmlApplicationEngine engine;
    engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
75
    engine.addImageProvider(QStringLiteral("thumbnailsProvider"), new ThumbnailsProvider);
76
77
78
79
80
    engine.rootContext()->setContextProperties({
        { QStringLiteral("initialMessage"), initialMessage },
        { QStringLiteral("initialDevice"), deviceid },
        { QStringLiteral("aboutData"), QVariant::fromValue(KAboutData::applicationData()) }
    });
81
    engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
82
83
84

    return app.exec();
}