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
|
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "localizer.h"
#include "publictransport.h"
#include <KPublicTransport/Stopover>
#include <KLocalizedQmlContext>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QCommandLineParser>
#include <QDebug>
#include <QFile>
#include <QGuiApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QUrl>
int main(int argc, char **argv)
{
QCoreApplication::setApplicationName(QStringLiteral("vehiclelayoutviewer"));
QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
QGuiApplication app(argc, argv);
QCommandLineParser parser;
parser.addHelpOption();
QCommandLineOption coachOpt(QStringLiteral("c"), QStringLiteral("Reserved coach number"), QStringLiteral("coach number"));
parser.addOption(coachOpt);
QCommandLineOption seatOpt(QStringLiteral("s"), QStringLiteral("Reserved seat number"), QStringLiteral("seat"));
parser.addOption(seatOpt);
parser.addPositionalArgument(QStringLiteral("stopover file"), QStringLiteral("KPT stopver JSON file"), QStringLiteral("file"));
parser.process(app);
if (parser.positionalArguments().empty()) {
parser.showHelp(1);
}
QFile file(parser.positionalArguments().at(0));
if (!file.open(QFile::ReadOnly)) {
qCritical("Failed to open file!");
exit(1);
}
const auto stopover = KPublicTransport::Stopover::fromJson(QJsonDocument::fromJson(file.readAll()).object());
qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "PublicTransport", [](QQmlEngine *, QJSEngine *engine) -> QJSValue {
return engine->toScriptValue(PublicTransport());
});
qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "Localizer", [](QQmlEngine *, QJSEngine *engine) -> QJSValue {
return engine->toScriptValue(Localizer());
});
QQmlApplicationEngine engine;
KLocalization::setupLocalizedContext(&engine);
engine.rootContext()->setContextProperty(QStringLiteral("_stopover"), stopover);
engine.rootContext()->setContextProperty(QStringLiteral("_coach"), parser.value(coachOpt));
engine.rootContext()->setContextProperty(QStringLiteral("_seat"), parser.value(seatOpt));
engine.load(QStringLiteral("qrc:/vehiclelayoutviewer.qml"));
return app.exec();
}
|