File indexing completed on 2024-04-14 04:51:52

0001 /**
0002  * SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@kde.org>
0003  * SPDX-FileCopyrightText: 2018 Simon Redman <simon@ergotech.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006  */
0007 
0008 #include "conversationlistmodel.h"
0009 #include "conversationmodel.h"
0010 #include "conversationssortfilterproxymodel.h"
0011 #include "kdeconnect-version.h"
0012 #include "thumbnailsprovider.h"
0013 
0014 #include <KAboutData>
0015 #include <KColorSchemeManager>
0016 #include <KDBusService>
0017 #include <KLocalizedContext>
0018 #include <KLocalizedString>
0019 #include <QApplication>
0020 #include <QCommandLineParser>
0021 #include <QQmlApplicationEngine>
0022 #include <QQmlContext>
0023 #include <QQuickStyle>
0024 
0025 #include "smshelper.h"
0026 
0027 class AppData : public QObject
0028 {
0029     Q_OBJECT
0030     Q_PROPERTY(QString initialMessage MEMBER m_initialMessage NOTIFY initialMessageChanged)
0031     Q_PROPERTY(QString deviceId MEMBER m_deviceId NOTIFY deviceIdChanged)
0032 
0033 public:
0034     Q_SIGNAL void initialMessageChanged();
0035     Q_SIGNAL void deviceIdChanged();
0036 
0037     QString m_initialMessage;
0038     QString m_deviceId;
0039 };
0040 
0041 int main(int argc, char *argv[])
0042 {
0043     QIcon::setFallbackThemeName(QStringLiteral("breeze"));
0044 
0045     QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0046     QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0047     QApplication app(argc, argv);
0048     KLocalizedString::setApplicationDomain("kdeconnect-sms");
0049     app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect")));
0050     KAboutData aboutData(QStringLiteral("kdeconnect.sms"),
0051                          i18n("KDE Connect SMS"),
0052                          QStringLiteral(KDECONNECT_VERSION_STRING),
0053                          i18n("SMS Instant Messaging"),
0054                          KAboutLicense::GPL_V3,
0055                          i18n("(C) 2018-2022, KDE Connect Team"));
0056     aboutData.addAuthor(i18n("Simon Redman"), {}, QStringLiteral("simon@ergotech.com"));
0057     aboutData.addAuthor(i18n("Aleix Pol Gonzalez"), {}, QStringLiteral("aleixpol@kde.org"));
0058     aboutData.addAuthor(i18n("Nicolas Fella"), {}, QStringLiteral("nicolas.fella@gmx.de"));
0059     aboutData.setBugAddress(QStringLiteral("https://bugs.kde.org/enter_bug.cgi?product=kdeconnect&component=messaging-application").toUtf8());
0060     KAboutData::setApplicationData(aboutData);
0061 
0062 #ifdef Q_OS_WIN
0063     KColorSchemeManager manager;
0064     QApplication::setStyle(QStringLiteral("breeze"));
0065 #endif
0066 
0067     // Default to org.kde.desktop style unless the user forces another style
0068     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0069         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0070     }
0071 
0072     AppData data;
0073 
0074     QCommandLineParser parser;
0075     aboutData.setupCommandLine(&parser);
0076     parser.addOption(QCommandLineOption(QStringLiteral("device"), i18n("Select a device"), i18n("id")));
0077     parser.addOption(QCommandLineOption(QStringLiteral("message"), i18n("Send a message"), i18n("message")));
0078     parser.process(app);
0079     aboutData.processCommandLine(&parser);
0080 
0081     data.m_initialMessage = parser.value(QStringLiteral("message"));
0082     data.m_deviceId = parser.value(QStringLiteral("device"));
0083 
0084     KDBusService service(KDBusService::Unique);
0085 
0086     QObject::connect(&service, &KDBusService::activateRequested, &service, [&parser, &data](const QStringList &args, const QString & /*workDir*/) {
0087         parser.parse(args);
0088 
0089         data.m_initialMessage = parser.value(QStringLiteral("message"));
0090         data.m_deviceId = parser.value(QStringLiteral("device"));
0091 
0092         Q_EMIT data.deviceIdChanged();
0093         Q_EMIT data.initialMessageChanged();
0094     });
0095 
0096     qmlRegisterType<ConversationsSortFilterProxyModel>("org.kde.kdeconnect.sms", 1, 0, "QSortFilterProxyModel");
0097     qmlRegisterType<ConversationModel>("org.kde.kdeconnect.sms", 1, 0, "ConversationModel");
0098     qmlRegisterType<ConversationListModel>("org.kde.kdeconnect.sms", 1, 0, "ConversationListModel");
0099 
0100     qmlRegisterSingletonType<SmsHelper>("org.kde.kdeconnect.sms", 1, 0, "SmsHelper", SmsHelper::singletonProvider);
0101 
0102     qmlRegisterSingletonInstance<AppData>("org.kde.kdeconnect.sms", 1, 0, "AppData", &data);
0103 
0104     qmlRegisterSingletonType("org.kde.kdeconnect.sms", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
0105         return engine->toScriptValue(KAboutData::applicationData());
0106     });
0107 
0108     QQmlApplicationEngine engine;
0109     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0110     engine.addImageProvider(QStringLiteral("thumbnailsProvider"), new ThumbnailsProvider);
0111     engine.loadFromModule("org.kde.kdeconnect.sms", "Main");
0112 
0113     return app.exec();
0114 }
0115 
0116 #include "main.moc"