KWeatherCore

locationquery.cpp
1/*
2 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com>
3 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7#include "locationquery.h"
8#include "kweathercore_p.h"
9#include "locationqueryreply.h"
10
11#include <QGeoPositionInfoSource>
12#include <QNetworkAccessManager>
13#include <QStandardPaths>
14
15namespace KWeatherCore
16{
17class LocationQueryPrivate
18{
19public:
20 LocationQueryPrivate(LocationQuery *parent);
21 void positionUpdated(const QGeoPositionInfo &update);
22 QNetworkAccessManager *networkAccessManager();
23
24 LocationQuery *q = nullptr;
25 QNetworkAccessManager *manager = nullptr;
26 QGeoPositionInfoSource *locationSource = nullptr;
27};
28
29LocationQueryPrivate::LocationQueryPrivate(LocationQuery *parent)
30 : q(parent)
31 , locationSource(QGeoPositionInfoSource::createDefaultSource(q))
32{
33 if (locationSource) {
34 locationSource->stopUpdates();
35 }
36}
37
38QNetworkAccessManager *LocationQueryPrivate::networkAccessManager()
39{
40 if (!manager) {
41 manager = new QNetworkAccessManager(q);
42 manager->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
43 manager->setStrictTransportSecurityEnabled(true);
44 manager->enableStrictTransportSecurityStore(true,
46 + QLatin1String("/org.kde.kweathercore/hsts/"));
47 }
48 return manager;
49}
50
51LocationQuery::LocationQuery(QObject *parent)
52 : QObject(parent)
53 , d(new LocationQueryPrivate(this))
54{
55}
56
57LocationQuery::~LocationQuery() = default;
58
60{
61 return new LocationQueryReply(name, number, d->networkAccessManager(), this);
62}
63
65{
66 return new LocationQueryReply(d->locationSource, d->networkAccessManager(), this);
67}
68
70{
71 if (d->manager == nam) {
72 return;
73 }
74
75 if (d->manager->parent() == this) {
76 delete d->manager;
77 }
78 d->manager = nam;
79}
80}
81
82#include "moc_locationquery.cpp"
Asynchronous reply for a location query.
LocationQueryReply * query(const QString &name, int number=30)
query query locations by name
void setNetworkAccessManager(QNetworkAccessManager *nam)
Set the network access manager to use for network operations.
LocationQueryReply * locate()
locate current location
QString writableLocation(StandardLocation type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:30:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.