1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "kgeourihandler_p.h"
7#include <kguiaddons_version.h>
8
9#include <QCommandLineParser>
10#include <QDesktopServices>
11#include <QGuiApplication>
12#include <QUrl>
13
14int main(int argc, char **argv)
15{
16 QCoreApplication::setApplicationName(QStringLiteral("kde-geo-uri-handler"));
17 QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
18 QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
19 QCoreApplication::setApplicationVersion(QStringLiteral(KGUIADDONS_VERSION_STRING));
20
21 QGuiApplication app(argc, argv);
22
23 QCommandLineParser parser;
24 QCommandLineOption coordTmplOpt(QStringLiteral("coordinate-template"),
25 QStringLiteral("URL template for coordinate-based access."),
26 QStringLiteral("coordinate-template"));
27 parser.addOption(commandLineOption: coordTmplOpt);
28 QCommandLineOption queryTmplOpt(QStringLiteral("query-template"), QStringLiteral("URL template for query-based access."), QStringLiteral("query-template"));
29 parser.addOption(commandLineOption: queryTmplOpt);
30 QCommandLineOption fallbackOpt(QStringLiteral("fallback"), QStringLiteral("URL to use in case of errors."), QStringLiteral("fallback-url"));
31 parser.addOption(commandLineOption: fallbackOpt);
32 parser.addPositionalArgument(QStringLiteral("uri"), QStringLiteral("geo: URI to handle"));
33 parser.addHelpOption();
34 parser.addVersionOption();
35 parser.process(app);
36
37 KGeoUriHandler handler;
38 handler.setCoordinateTemplate(parser.value(option: coordTmplOpt));
39 handler.setQueryTemplate(parser.value(option: queryTmplOpt));
40 handler.setFallbackUrl(parser.value(option: fallbackOpt));
41
42 const auto args = parser.positionalArguments();
43 for (const auto &arg : args) {
44 const auto url = handler.handleUri(geoUri: QUrl(arg));
45 QDesktopServices::openUrl(url: QUrl(url));
46 }
47
48 return 0;
49}
50

source code of kguiaddons/src/geo-scheme-handler/main.cpp