File indexing completed on 2024-03-03 05:09:20

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     aboutData.setBugAddress("https://bugs.kde.org/enter_bug.cgi?product=kdeconnect&component=common");
0040     KAboutData::setApplicationData(aboutData);
0041 
0042 #ifdef Q_OS_WIN
0043     KColorSchemeManager manager;
0044     QApplication::setStyle(QStringLiteral("breeze"));
0045 #endif
0046 
0047     // Default to org.kde.desktop style unless the user forces another style
0048     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0049         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0050     }
0051 
0052     QString urlToShare;
0053     {
0054         QCommandLineParser parser;
0055         parser.addPositionalArgument(QStringLiteral("url"), i18n("URL to share"));
0056         aboutData.setupCommandLine(&parser);
0057         parser.process(app);
0058         aboutData.processCommandLine(&parser);
0059         if (parser.positionalArguments().count() == 1) {
0060             urlToShare = parser.positionalArguments().constFirst();
0061             const QString kdeconnectHandlerExecutable =
0062                 QStandardPaths::findExecutable(QStringLiteral("kdeconnect-handler"), {QCoreApplication::applicationDirPath()});
0063             if (!kdeconnectHandlerExecutable.isEmpty()) {
0064                 QProcess::startDetached(kdeconnectHandlerExecutable, {urlToShare});
0065                 return 0; // exit the app once kdeconnect-handler is started
0066             }
0067         }
0068     }
0069 
0070     qmlRegisterSingletonType("org.kde.kdeconnect.app", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
0071         return engine->toScriptValue(KAboutData::applicationData());
0072     });
0073 
0074     QQmlApplicationEngine engine;
0075     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0076     engine.loadFromModule("org.kde.kdeconnect.app", "Main");
0077 
0078     return app.exec();
0079 }