KWeatherCore

locationquery.cpp
1 /*
2  * SPDX-FileCopyrightText: 2020-2021 Han Young <[email protected]>
3  * SPDX-FileCopyrightText: 2020 Devin Lin <[email protected]>
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 
15 namespace KWeatherCore
16 {
17 class LocationQueryPrivate
18 {
19 public:
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 
29 LocationQueryPrivate::LocationQueryPrivate(LocationQuery *parent)
30  : q(parent)
31  , locationSource(QGeoPositionInfoSource::createDefaultSource(q))
32 {
33  if (locationSource) {
34  locationSource->stopUpdates();
35  }
36 }
37 
38 QNetworkAccessManager *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 
52  : QObject(parent)
53  , d(new LocationQueryPrivate(this))
54 {
55 }
56 
57 LocationQuery::~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"
QString writableLocation(QStandardPaths::StandardLocation type)
void setNetworkAccessManager(QNetworkAccessManager *nam)
Set the network access manager to use for network operations.
LocationQueryReply * query(const QString &name, int number=30)
query query locations by name
Asynchronous reply for a location query.
LocationQueryReply * locate()
locate current location
LocationQuery(QObject *parent=nullptr)
LocationQuery.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Dec 5 2023 03:56:02 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.