File indexing completed on 2024-05-19 03:56:50

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #include "kgeourihandler_p.h"
0007 #include <kguiaddons_version.h>
0008 
0009 #include <QCommandLineParser>
0010 #include <QDesktopServices>
0011 #include <QGuiApplication>
0012 #include <QUrl>
0013 
0014 int main(int argc, char **argv)
0015 {
0016     QCoreApplication::setApplicationName(QStringLiteral("kde-geo-uri-handler"));
0017     QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
0018     QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
0019     QCoreApplication::setApplicationVersion(QStringLiteral(KGUIADDONS_VERSION_STRING));
0020 
0021     QGuiApplication app(argc, argv);
0022 
0023     QCommandLineParser parser;
0024     QCommandLineOption coordTmplOpt(QStringLiteral("coordinate-template"),
0025                                     QStringLiteral("URL template for coordinate-based access."),
0026                                     QStringLiteral("coordinate-template"));
0027     parser.addOption(coordTmplOpt);
0028     QCommandLineOption queryTmplOpt(QStringLiteral("query-template"), QStringLiteral("URL template for query-based access."), QStringLiteral("query-template"));
0029     parser.addOption(queryTmplOpt);
0030     QCommandLineOption fallbackOpt(QStringLiteral("fallback"), QStringLiteral("URL to use in case of errors."), QStringLiteral("fallback-url"));
0031     parser.addOption(fallbackOpt);
0032     parser.addPositionalArgument(QStringLiteral("uri"), QStringLiteral("geo: URI to handle"));
0033     parser.addHelpOption();
0034     parser.addVersionOption();
0035     parser.process(app);
0036 
0037     KGeoUriHandler handler;
0038     handler.setCoordinateTemplate(parser.value(coordTmplOpt));
0039     handler.setQueryTemplate(parser.value(queryTmplOpt));
0040     handler.setFallbackUrl(parser.value(fallbackOpt));
0041 
0042     const auto args = parser.positionalArguments();
0043     for (const auto &arg : args) {
0044         const auto url = handler.handleUri(QUrl(arg));
0045         QDesktopServices::openUrl(QUrl(url));
0046     }
0047 
0048     return 0;
0049 }