KOSMIndoorMap

main.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include <kosmindoormap_version.h>
8
9#include <KLocalizedContext>
10#include <KLocalizedString>
11
12#include <QNetworkAccessManager>
13#include <QNetworkDiskCache>
14#include <QQmlApplicationEngine>
15#include <QQmlContext>
16#include <QQmlNetworkAccessManagerFactory>
17#include <QStandardPaths>
18
19#ifdef Q_OS_ANDROID
20#include <QGuiApplication>
21#include <QQuickStyle>
22#else
23#include <QApplication>
24#endif
25
26#include <QCommandLineParser>
27#include <QIcon>
28#include <QTimer>
29#include <QtPlugin>
30
31#if HAVE_OSM_PBF_SUPPORT
32Q_IMPORT_PLUGIN(OSM_PbfIOPlugin)
33#endif
34
35class NetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory
36{
37public:
38 QNetworkAccessManager* create(QObject *parent) override
39 {
40 auto nam = new QNetworkAccessManager(parent);
41 nam->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
42
43 nam->enableStrictTransportSecurityStore(true, QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/hsts/"));
44 nam->setStrictTransportSecurityEnabled(true);
45
46 auto namDiskCache = new QNetworkDiskCache(nam);
47 namDiskCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/nam/"));
48 nam->setCache(namDiskCache);
49
50 return nam;
51 }
52};
53
54#ifdef Q_OS_ANDROID
55Q_DECL_EXPORT
56#endif
57int main(int argc, char **argv)
58{
59 QCoreApplication::setApplicationName(QStringLiteral("kosmindoormap"));
60 QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
61 QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
62 QCoreApplication::setApplicationVersion(QStringLiteral(KOSMINDOORMAP_VERSION_STRING));
63
64#ifdef Q_OS_ANDROID
65 QGuiApplication app(argc, argv);
66 QQuickStyle::setStyle(QStringLiteral("org.kde.breeze"));
67#else
68 QApplication app(argc, argv); // for native file dialogs
69#endif
71 QGuiApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("go-home")));
72
73 QCommandLineParser parser;
74 QCommandLineOption selfTestOpt(QStringLiteral("self-test"), QStringLiteral("internal, for automated testing"));
75 parser.addOption(selfTestOpt);
76 parser.process(app);
77
79 engine.setNetworkAccessManagerFactory(new NetworkAccessManagerFactory());
80 auto l10nContext = new KLocalizedContext(&engine);
81 l10nContext->setTranslationDomain(QStringLiteral(TRANSLATION_DOMAIN));
82 engine.rootContext()->setContextObject(l10nContext);
83
84 engine.loadFromModule("org.kde.kosmindoormap.app", "Main");
85
86 if (parser.isSet(selfTestOpt)) {
87 QTimer::singleShot(std::chrono::milliseconds(250), &app, &QCoreApplication::quit);
88 }
89
90 return app.exec();
91}
QString i18n(const char *text, const TYPE &arg...)
bool addOption(const QCommandLineOption &option)
bool isSet(const QCommandLineOption &option) const const
void process(const QCoreApplication &app)
void setApplicationName(const QString &application)
void setApplicationVersion(const QString &version)
void setOrganizationDomain(const QString &orgDomain)
void setOrganizationName(const QString &orgName)
void setApplicationDisplayName(const QString &name)
void setWindowIcon(const QIcon &icon)
QIcon fromTheme(const QString &name)
void loadFromModule(QAnyStringView uri, QAnyStringView typeName)
void setContextObject(QObject *object)
QQmlContext * rootContext() const const
void setNetworkAccessManagerFactory(QQmlNetworkAccessManagerFactory *factory)
void setStyle(const QString &style)
QString writableLocation(StandardLocation type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:16:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.