KGuiAddons

main.cpp
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(coordTmplOpt);
28 QCommandLineOption queryTmplOpt(QStringLiteral("query-template"), QStringLiteral("URL template for query-based access."), QStringLiteral("query-template"));
29 parser.addOption(queryTmplOpt);
30 QCommandLineOption fallbackOpt(QStringLiteral("fallback"), QStringLiteral("URL to use in case of errors."), QStringLiteral("fallback-url"));
31 parser.addOption(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(coordTmplOpt));
39 handler.setQueryTemplate(parser.value(queryTmplOpt));
40 handler.setFallbackUrl(parser.value(fallbackOpt));
41
42 const auto args = parser.positionalArguments();
43 for (const auto &arg : args) {
44 const auto url = handler.handleUri(QUrl(arg));
46 }
47
48 return 0;
49}
QCommandLineOption addHelpOption()
bool addOption(const QCommandLineOption &option)
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
QCommandLineOption addVersionOption()
QStringList positionalArguments() const const
void process(const QCoreApplication &app)
QString value(const QCommandLineOption &option) const const
void setApplicationName(const QString &application)
void setApplicationVersion(const QString &version)
void setOrganizationDomain(const QString &orgDomain)
void setOrganizationName(const QString &orgName)
bool openUrl(const QUrl &url)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.