kdeconnect-kde/app/main.cpp

81 lines
3 KiB
C++
Raw Permalink Normal View History

2018-10-11 21:52:42 +01:00
/**
* SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@kde.org>
2015-06-13 00:30:38 +01:00
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
2015-06-13 00:30:38 +01:00
*/
#include <QApplication>
#include <QCommandLineParser>
#include <QIcon>
#include <QProcess>
2015-06-13 00:30:38 +01:00
#include <QQmlApplicationEngine>
2019-02-03 00:44:22 +00:00
#include <QQmlContext>
#include <QQuickStyle>
#include <QStandardPaths>
2019-02-03 00:44:22 +00:00
2023-07-16 15:20:34 +01:00
#include "kdeconnect-version.h"
2015-06-13 00:30:38 +01:00
#include <KAboutData>
#include <KColorSchemeManager>
2024-07-31 21:44:55 +01:00
#include <KCrash>
#include <KLocalizedContext>
#include <KLocalizedString>
2015-06-13 00:30:38 +01:00
int main(int argc, char *argv[])
2015-06-13 00:30:38 +01:00
{
QIcon::setFallbackThemeName(QStringLiteral("breeze"));
2015-06-13 00:30:38 +01:00
QApplication app(argc, argv);
KLocalizedString::setApplicationDomain("kdeconnect-app");
app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect")));
KAboutData aboutData(QStringLiteral("kdeconnect.app"),
i18n("KDE Connect"),
QStringLiteral(KDE_CONNECT_VERSION_STRING),
i18n("KDE Connect"),
KAboutLicense::GPL,
i18n("(c) 2015, Aleix Pol Gonzalez"));
aboutData.addAuthor(i18n("Aleix Pol Gonzalez"), i18n("Maintainer"), QStringLiteral("aleixpol@kde.org"));
aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
aboutData.setBugAddress("https://bugs.kde.org/enter_bug.cgi?product=kdeconnect&component=common");
2015-06-13 00:30:38 +01:00
KAboutData::setApplicationData(aboutData);
2024-07-31 21:44:55 +01:00
KCrash::initialize();
#ifdef Q_OS_WIN
KColorSchemeManager::instance();
QApplication::setStyle(QStringLiteral("breeze"));
#endif
// Default to org.kde.desktop style unless the user forces another style
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
}
QString urlToShare;
2015-06-13 00:30:38 +01:00
{
QCommandLineParser parser;
parser.addPositionalArgument(QStringLiteral("url"), i18n("URL to share"));
2015-06-13 00:30:38 +01:00
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
if (parser.positionalArguments().count() == 1) {
urlToShare = parser.positionalArguments().constFirst();
const QString kdeconnectHandlerExecutable =
QStandardPaths::findExecutable(QStringLiteral("kdeconnect-handler"), {QCoreApplication::applicationDirPath()});
if (!kdeconnectHandlerExecutable.isEmpty()) {
QProcess::startDetached(kdeconnectHandlerExecutable, {urlToShare});
return 0; // exit the app once kdeconnect-handler is started
}
}
2015-06-13 00:30:38 +01:00
}
2018-10-11 21:52:42 +01:00
qmlRegisterSingletonType("org.kde.kdeconnect.app", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
return engine->toScriptValue(KAboutData::applicationData());
});
QQmlApplicationEngine engine;
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
2023-12-23 20:13:07 +00:00
engine.loadFromModule("org.kde.kdeconnect.app", "Main");
2015-06-13 00:30:38 +01:00
return app.exec();
}