File indexing completed on 2024-05-12 05:14:03
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "localizer.h" 0008 #include "journeysectionmodel.h" 0009 #include "publictransport.h" 0010 #include "util.h" 0011 0012 #include <KPublicTransport/JourneyRequest> 0013 #include <KPublicTransport/Location> 0014 0015 #include <KLocalizedContext> 0016 0017 #include <QQmlApplicationEngine> 0018 #include <QQmlContext> 0019 0020 #include <QCommandLineParser> 0021 #include <QDebug> 0022 #include <QFile> 0023 #include <QGuiApplication> 0024 #include <QUrl> 0025 0026 int main(int argc, char **argv) 0027 { 0028 QCoreApplication::setApplicationName(QStringLiteral("journeyquerytest")); 0029 QCoreApplication::setOrganizationName(QStringLiteral("KDE")); 0030 QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); 0031 QGuiApplication app(argc, argv); 0032 0033 QCommandLineParser parser; 0034 parser.addHelpOption(); 0035 QCommandLineOption backendOpt(QStringLiteral("b"), QStringLiteral("KPT backend"), QStringLiteral("backend id")); 0036 parser.addOption(backendOpt); 0037 QCommandLineOption fromOpt(QStringLiteral("f"), QStringLiteral("Origin station name"), QStringLiteral("from")); 0038 parser.addOption(fromOpt); 0039 QCommandLineOption toOpt(QStringLiteral("t"), QStringLiteral("Desitination station name"), QStringLiteral("to")); 0040 parser.addOption(toOpt); 0041 parser.process(app); 0042 0043 if (!parser.isSet(fromOpt) || !parser.isSet(backendOpt) || !parser.isSet(backendOpt)) { 0044 parser.showHelp(1); 0045 } 0046 0047 KPublicTransport::JourneyRequest req; 0048 req.setBackendIds({parser.value(backendOpt)}); 0049 KPublicTransport::Location from; 0050 from.setName(parser.value(fromOpt)); 0051 req.setFrom(from); 0052 KPublicTransport::Location to; 0053 to.setName(parser.value(toOpt)); 0054 req.setTo(to); 0055 req.setIncludeIntermediateStops(true); 0056 0057 qmlRegisterType<JourneySectionModel>("org.kde.itinerary", 1, 0, "JourneySectionModel"); 0058 qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "Localizer", [](QQmlEngine*, QJSEngine *engine) -> QJSValue { 0059 return engine->toScriptValue(Localizer()); 0060 }); 0061 qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "PublicTransport", [](QQmlEngine*, QJSEngine *engine) -> QJSValue { 0062 return engine->toScriptValue(PublicTransport()); 0063 }); 0064 qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "Util", [](QQmlEngine*, QJSEngine *engine) -> QJSValue { 0065 return engine->toScriptValue(Util()); 0066 }); 0067 0068 QQmlApplicationEngine engine; 0069 engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); 0070 engine.rootContext()->setContextProperty(QStringLiteral("_request"), req); 0071 engine.load(QStringLiteral("qrc:/qt/qml/org/kde/itinerary/journeyquerytest.qml")); 0072 0073 return app.exec(); 0074 }