File indexing completed on 2023-09-24 08:52:33

0001 /**
0002  * SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include <QApplication>
0008 #include <QCommandLineParser>
0009 #include <QIcon>
0010 #include <QProcess>
0011 #include <QQmlApplicationEngine>
0012 #include <QQmlContext>
0013 #include <QQuickStyle>
0014 #include <QStandardPaths>
0015 
0016 #include "kdeconnect-version.h"
0017 #include <KAboutData>
0018 #include <KColorSchemeManager>
0019 #include <KLocalizedContext>
0020 #include <KLocalizedString>
0021 
0022 int main(int argc, char *argv[])
0023 {
0024     QIcon::setFallbackThemeName(QStringLiteral("breeze"));
0025     QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0026     QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0027 
0028     QApplication app(argc, argv);
0029     KLocalizedString::setApplicationDomain("kdeconnect-app");
0030     app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect")));
0031     KAboutData aboutData(QStringLiteral("kdeconnect.app"),
0032                          i18n("KDE Connect"),
0033                          QStringLiteral(KDE_CONNECT_VERSION_STRING),
0034                          i18n("KDE Connect"),
0035                          KAboutLicense::GPL,
0036                          i18n("(c) 2015, Aleix Pol Gonzalez"));
0037     aboutData.addAuthor(i18n("Aleix Pol Gonzalez"), i18n("Maintainer"), QStringLiteral("aleixpol@kde.org"));
0038     aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
0039     KAboutData::setApplicationData(aboutData);
0040 
0041 #ifdef Q_OS_WIN
0042     KColorSchemeManager manager;
0043     QApplication::setStyle(QStringLiteral("breeze"));
0044 #endif
0045 
0046     // Default to org.kde.desktop style unless the user forces another style
0047     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0048         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0049     }
0050 
0051     QString urlToShare;
0052     {
0053         QCommandLineParser parser;
0054         parser.addPositionalArgument(QStringLiteral("url"), i18n("URL to share"));
0055         aboutData.setupCommandLine(&parser);
0056         parser.process(app);
0057         aboutData.processCommandLine(&parser);
0058         if (parser.positionalArguments().count() == 1) {
0059             urlToShare = parser.positionalArguments().constFirst();
0060             const QString kdeconnectHandlerExecutable =
0061                 QStandardPaths::findExecutable(QStringLiteral("kdeconnect-handler"), {QCoreApplication::applicationDirPath()});
0062             if (!kdeconnectHandlerExecutable.isEmpty()) {
0063                 QProcess::startDetached(kdeconnectHandlerExecutable, {urlToShare});
0064                 return 0; // exit the app once kdeconnect-handler is started
0065             }
0066         }
0067     }
0068 
0069     qmlRegisterSingletonType("org.kde.kdeconnect.app", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
0070         return engine->toScriptValue(KAboutData::applicationData());
0071     });
0072 
0073     QQmlApplicationEngine engine;
0074     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0075     engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
0076 
0077     return app.exec();
0078 }