diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-07-29 18:10:32 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-07-30 10:33:37 +0200 |
commit | 9a6f7a2d31829b541b688b68cff85ffaa1ee2d1c (patch) | |
tree | c83e15b00e4cb40a591ce481cb802c3802e41555 /src/plugins/position | |
parent | 0ab2fe51bb68ef7c1503fc5aa9880421421bd6dc (diff) | |
download | qtlocation-9a6f7a2d31829b541b688b68cff85ffaa1ee2d1c.tar.gz |
GeoClue v2: do not use env variables and update docs
There is no need in using the environment variable to set the desktop id
parameter.
This patch introduces parsing of the desktop id parameter from the
provided plugin parameters.
It also introduces a separate page with the plugin documentation.
Task-number: QTBUG-74995
Pick-to: 6.2
Change-Id: Ie59e2410709dc9517b305f0b490d35c6718ce9ba
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/plugins/position')
3 files changed, 24 insertions, 12 deletions
diff --git a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp index 34a1a035..3c78a075 100644 --- a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp +++ b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp @@ -68,6 +68,7 @@ enum GClueAccuracyLevel { const char GEOCLUE2_SERVICE_NAME[] = "org.freedesktop.GeoClue2"; const int MINIMUM_UPDATE_INTERVAL = 1000; const int UPDATE_TIMEOUT_COLD_START = 120000; +static const auto desktopIdParameter = "desktopId"; static QString lastPositionFilePath() { @@ -77,7 +78,8 @@ static QString lastPositionFilePath() } // namespace -QGeoPositionInfoSourceGeoclue2::QGeoPositionInfoSourceGeoclue2(QObject *parent) +QGeoPositionInfoSourceGeoclue2::QGeoPositionInfoSourceGeoclue2(const QVariantMap ¶meters, + QObject *parent) : QGeoPositionInfoSource(parent) , m_requestTimer(new QTimer(this)) , m_manager(QLatin1String(GEOCLUE2_SERVICE_NAME), @@ -85,6 +87,8 @@ QGeoPositionInfoSourceGeoclue2::QGeoPositionInfoSourceGeoclue2(QObject *parent) QDBusConnection::systemBus(), this) { + parseParameters(parameters); + qDBusRegisterMetaType<Timestamp>(); restoreLastPosition(); @@ -347,19 +351,15 @@ bool QGeoPositionInfoSourceGeoclue2::configureClient() if (!m_client) return false; - auto desktopId = QString::fromUtf8(qgetenv("QT_GEOCLUE_APP_DESKTOP_ID")); - if (desktopId.isEmpty()) - desktopId = QCoreApplication::applicationName(); - if (desktopId.isEmpty()) { - qCCritical(lcPositioningGeoclue2) << "Unable to configure the client " - "due to the application desktop id " - "is not set via QT_GEOCLUE_APP_DESKTOP_ID " - "envirorment variable or QCoreApplication::applicationName"; + if (m_desktopId.isEmpty()) { + qCCritical(lcPositioningGeoclue2) + << "Unable to configure the client due to the desktop id is not set via" + << desktopIdParameter << "plugin parameter or QCoreApplication::applicationName"; setError(AccessError); return false; } - m_client->setDesktopId(desktopId); + m_client->setDesktopId(m_desktopId); const auto msecs = updateInterval(); const uint secs = qMax(uint(msecs), 0u) / 1000u; @@ -446,4 +446,13 @@ void QGeoPositionInfoSourceGeoclue2::handleNewLocation(const QDBusObjectPath &ol stopClient(); } +void QGeoPositionInfoSourceGeoclue2::parseParameters(const QVariantMap ¶meters) +{ + if (parameters.contains(desktopIdParameter)) + m_desktopId = parameters.value(desktopIdParameter).toString(); + + if (m_desktopId.isEmpty()) + m_desktopId = QCoreApplication::applicationName(); +} + QT_END_NAMESPACE diff --git a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2_p.h b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2_p.h index 16f5b9a1..f5ec2b06 100644 --- a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2_p.h +++ b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2_p.h @@ -55,7 +55,8 @@ class QGeoPositionInfoSourceGeoclue2 : public QGeoPositionInfoSource Q_OBJECT public: - explicit QGeoPositionInfoSourceGeoclue2(QObject *parent = nullptr); + explicit QGeoPositionInfoSourceGeoclue2(const QVariantMap ¶meters, + QObject *parent = nullptr); ~QGeoPositionInfoSourceGeoclue2(); // From QGeoPositionInfoSource @@ -82,6 +83,7 @@ private: void requestUpdateTimeout(); void handleNewLocation(const QDBusObjectPath &oldLocation, const QDBusObjectPath &newLocation); + void parseParameters(const QVariantMap ¶meters); QTimer *m_requestTimer = nullptr; OrgFreedesktopGeoClue2ManagerInterface m_manager; @@ -90,6 +92,7 @@ private: bool m_lastPositionFromSatellite = false; QGeoPositionInfoSource::Error m_error = NoError; QGeoPositionInfo m_lastPosition; + QString m_desktopId; }; QT_END_NAMESPACE diff --git a/src/plugins/position/geoclue2/qgeopositioninfosourcefactory_geoclue2.cpp b/src/plugins/position/geoclue2/qgeopositioninfosourcefactory_geoclue2.cpp index 68caba3a..68161f41 100644 --- a/src/plugins/position/geoclue2/qgeopositioninfosourcefactory_geoclue2.cpp +++ b/src/plugins/position/geoclue2/qgeopositioninfosourcefactory_geoclue2.cpp @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE QGeoPositionInfoSource *QGeoPositionInfoSourceFactoryGeoclue2::positionInfoSource(QObject *parent, const QVariantMap ¶meters) { Q_UNUSED(parameters) - return new QGeoPositionInfoSourceGeoclue2(parent); + return new QGeoPositionInfoSourceGeoclue2(parameters, parent); } QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactoryGeoclue2::satelliteInfoSource(QObject *parent, const QVariantMap ¶meters) |