File indexing completed on 2022-11-29 20:26:08

0001 /**
0002  * SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include "androidutils.h"
0008 #include "controller.h"
0009 #include "formatter.h"
0010 #include "ktripsettings.h"
0011 #include "locationcachemodel.h"
0012 #include "version.h"
0013 
0014 #include <QCommandLineOption>
0015 #include <QCommandLineParser>
0016 #include <QIcon>
0017 #include <QImage>
0018 #include <QQmlApplicationEngine>
0019 #include <QQmlContext>
0020 #include <QQuickStyle>
0021 
0022 #ifdef Q_OS_ANDROID
0023 #include <QGuiApplication>
0024 #else
0025 #include <QApplication>
0026 #endif
0027 
0028 #include <KAboutData>
0029 #include <KLocalizedContext>
0030 #include <KLocalizedString>
0031 #include <KPublicTransport/LocationRequest>
0032 #include <KPublicTransport/Manager>
0033 
0034 #ifdef Q_OS_ANDROID
0035 Q_DECL_EXPORT
0036 #endif
0037 int main(int argc, char *argv[])
0038 {
0039     QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0040     QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0041 
0042     QCommandLineParser parser;
0043 #ifdef Q_OS_ANDROID
0044     QGuiApplication app(argc, argv);
0045     QQuickStyle::setStyle(QStringLiteral("org.kde.breeze"));
0046 #else
0047     QIcon::setFallbackThemeName(QStringLiteral("breeze"));
0048     QApplication app(argc, argv);
0049     // Default to org.kde.desktop style unless the user forces another style
0050     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0051         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0052     }
0053 #endif
0054 
0055 #ifdef Q_OS_WINDOWS
0056     QApplication::setStyle(QStringLiteral("breeze"));
0057 #endif
0058 
0059     QCoreApplication::setApplicationName(QStringLiteral("ktrip"));
0060     QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
0061     QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
0062     QCoreApplication::setApplicationVersion(QStringLiteral(KTRIP_VERSION_STRING));
0063 
0064     QGuiApplication::setApplicationDisplayName(QStringLiteral("KTrip"));
0065     QGuiApplication::setDesktopFileName(QStringLiteral("org.kde.ktrip"));
0066 
0067     KLocalizedString::setApplicationDomain("ktrip");
0068     parser.addVersionOption();
0069     parser.process(app);
0070 
0071     QQmlApplicationEngine engine;
0072     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0073 
0074     qRegisterMetaType<KPublicTransport::LocationRequest>();
0075 
0076     qmlRegisterType<LocationCacheModel>("org.kde.ktrip", 1, 0, "LocationCacheModel");
0077 
0078     KPublicTransport::Manager manager;
0079     manager.setAllowInsecureBackends(true);
0080     manager.setBackendsEnabledByDefault(false);
0081 
0082     qmlRegisterSingletonInstance<KPublicTransport::Manager>("org.kde.ktrip", 1, 0, "Manager", &manager);
0083 
0084     KTripSettings settings;
0085     manager.setEnabledBackends(settings.enabledBackends());
0086 
0087     QObject::connect(&manager, &KPublicTransport::Manager::configurationChanged, &settings, [&settings, &manager] {
0088         settings.setEnabledBackends(manager.enabledBackends());
0089         settings.save();
0090     });
0091 
0092     qmlRegisterSingletonInstance<KTripSettings>("org.kde.ktrip", 1, 0, "Settings", &settings);
0093 
0094     KAboutData about(QStringLiteral("ktrip"),
0095                      i18n("KTrip"),
0096                      QStringLiteral(KTRIP_VERSION_STRING),
0097                      i18n("Public transport assistant"),
0098                      KAboutLicense::GPL,
0099                      i18n("© 2019 KDE Community"));
0100     about.addAuthor(i18n("Nicolas Fella"), QString(), QStringLiteral("nicolas.fella@gmx.de"));
0101     about.setBugAddress("https://invent.kde.org/utilities/ktrip/-/issues");
0102     KAboutData::setApplicationData(about);
0103 
0104     engine.rootContext()->setContextProperty(QStringLiteral("_aboutData"), QVariant::fromValue(about));
0105 
0106     Formatter formatter;
0107     qmlRegisterSingletonInstance<Formatter>("org.kde.ktrip", 1, 0, "Formatter", &formatter);
0108 
0109 #ifdef Q_OS_ANDROID
0110     engine.rootContext()->setContextProperty(QStringLiteral("_isAndroid"), true);
0111     engine.rootContext()->setContextProperty(QStringLiteral("_androidUtils"), QVariant::fromValue(AndroidUtils::instance()));
0112 #else
0113     engine.rootContext()->setContextProperty(QStringLiteral("_isAndroid"), false);
0114 #endif
0115 
0116     Controller controller;
0117     qmlRegisterSingletonInstance<Controller>("org.kde.ktrip", 1, 0, "Controller", &controller);
0118 
0119     engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
0120 
0121     return app.exec();
0122 }