File: journeyquerytest.cpp

package info (click to toggle)
itinerary 25.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,640 kB
  • sloc: cpp: 31,610; xml: 5,578; java: 622; python: 334; sh: 34; makefile: 10
file content (74 lines) | stat: -rw-r--r-- 2,683 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
    SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "journeysectionmodel.h"
#include "localizer.h"
#include "publictransport.h"
#include "util.h"

#include <KPublicTransport/JourneyRequest>
#include <KPublicTransport/Location>

#include <KLocalizedQmlContext>

#include <QQmlApplicationEngine>
#include <QQmlContext>

#include <QCommandLineParser>
#include <QDebug>
#include <QFile>
#include <QGuiApplication>
#include <QUrl>

int main(int argc, char **argv)
{
    QCoreApplication::setApplicationName(QStringLiteral("journeyquerytest"));
    QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
    QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
    QGuiApplication app(argc, argv);

    QCommandLineParser parser;
    parser.addHelpOption();
    QCommandLineOption backendOpt(QStringLiteral("b"), QStringLiteral("KPT backend"), QStringLiteral("backend id"));
    parser.addOption(backendOpt);
    QCommandLineOption fromOpt(QStringLiteral("f"), QStringLiteral("Origin station name"), QStringLiteral("from"));
    parser.addOption(fromOpt);
    QCommandLineOption toOpt(QStringLiteral("t"), QStringLiteral("Destination station name"), QStringLiteral("to"));
    parser.addOption(toOpt);
    parser.process(app);

    if (!parser.isSet(fromOpt) || !parser.isSet(backendOpt) || !parser.isSet(backendOpt)) {
        parser.showHelp(1);
    }

    KPublicTransport::JourneyRequest req;
    req.setBackendIds({parser.value(backendOpt)});
    KPublicTransport::Location from;
    from.setName(parser.value(fromOpt));
    req.setFrom(from);
    KPublicTransport::Location to;
    to.setName(parser.value(toOpt));
    req.setTo(to);
    req.setIncludeIntermediateStops(true);

    qmlRegisterType<JourneySectionModel>("org.kde.itinerary", 1, 0, "JourneySectionModel");
    qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "Localizer", [](QQmlEngine *, QJSEngine *engine) -> QJSValue {
        return engine->toScriptValue(Localizer());
    });
    qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "PublicTransport", [](QQmlEngine *, QJSEngine *engine) -> QJSValue {
        return engine->toScriptValue(PublicTransport());
    });
    qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "Util", [](QQmlEngine *, QJSEngine *engine) -> QJSValue {
        return engine->toScriptValue(Util());
    });

    QQmlApplicationEngine engine;
    KLocalization::setupLocalizedContext(&engine);
    engine.rootContext()->setContextProperty(QStringLiteral("_request"), req);
    engine.load(QStringLiteral("qrc:/qt/qml/org/kde/itinerary/journeyquerytest.qml"));

    return app.exec();
}