1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 Jolla Ltd. 4 ** Contact: Aaron McCarthy <aaron.mccarthy@jollamobile.com> 5 ** Copyright (C) 2016 The Qt Company Ltd. 6 ** Contact: https://www.qt.io/licensing/ 7 ** 8 ** This file is part of the QtPositioning module of the Qt Toolkit. 9 ** 10 ** $QT_BEGIN_LICENSE:LGPL$ 11 ** Commercial License Usage 12 ** Licensees holding valid commercial Qt licenses may use this file in 13 ** accordance with the commercial license agreement provided with the 14 ** Software or, alternatively, in accordance with the terms contained in 15 ** a written agreement between you and The Qt Company. For licensing terms 16 ** and conditions see https://www.qt.io/terms-conditions. For further 17 ** information use the contact form at https://www.qt.io/contact-us. 18 ** 19 ** GNU Lesser General Public License Usage 20 ** Alternatively, this file may be used under the terms of the GNU Lesser 21 ** General Public License version 3 as published by the Free Software 22 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 23 ** packaging of this file. Please review the following information to 24 ** ensure the GNU Lesser General Public License version 3 requirements 25 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 26 ** 27 ** GNU General Public License Usage 28 ** Alternatively, this file may be used under the terms of the GNU 29 ** General Public License version 2.0 or (at your option) the GNU General 30 ** Public license version 3 or any later version approved by the KDE Free 31 ** Qt Foundation. The licenses are as published by the Free Software 32 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 33 ** included in the packaging of this file. Please review the following 34 ** information to ensure the GNU General Public License requirements will 35 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 36 ** https://www.gnu.org/licenses/gpl-3.0.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 #ifndef QGEOPOSITIONINFOSOURCE_GEOCLUEMASTER_H 43 #define QGEOPOSITIONINFOSOURCE_GEOCLUEMASTER_H 44 45 #include "qgeocluemaster.h" 46 #include "geocluetypes.h" 47 48 #include <QtCore/QTimer> 49 #include <QtPositioning/QGeoPositionInfoSource> 50 51 class OrgFreedesktopGeoclueInterface; 52 class OrgFreedesktopGeocluePositionInterface; 53 class OrgFreedesktopGeoclueVelocityInterface; 54 55 QT_BEGIN_NAMESPACE 56 57 class QDBusPendingCallWatcher; 58 59 class QGeoPositionInfoSourceGeoclueMaster : public QGeoPositionInfoSource 60 { 61 Q_OBJECT 62 63 public: 64 explicit QGeoPositionInfoSourceGeoclueMaster(QObject *parent = 0); 65 ~QGeoPositionInfoSourceGeoclueMaster(); 66 67 // From QGeoPositionInfoSource 68 void setUpdateInterval(int msec) override; 69 QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const override; 70 PositioningMethods supportedPositioningMethods() const override; 71 void setPreferredPositioningMethods(PositioningMethods methods) override; 72 int minimumUpdateInterval() const override; 73 74 Error error() const override; 75 76 void startUpdates() override; 77 void stopUpdates() override; 78 void requestUpdate(int timeout = 5000) override; 79 80 private slots: 81 void positionProviderChanged(const QString &name, const QString &description, 82 const QString &service, const QString &path); 83 void requestUpdateTimeout(); 84 85 void getPositionFinished(QDBusPendingCallWatcher *watcher); 86 void positionChanged(qint32 fields, qint32 timestamp, double latitude, double longitude, 87 double altitude, const Accuracy &accuracy); 88 void velocityChanged(qint32 fields, qint32 timestamp, double speed, double direction, 89 double climb); 90 91 private: 92 void configurePositionSource(); 93 void cleanupPositionSource(); 94 void setOptions(); 95 96 enum PositionField 97 { 98 NoPositionFields = 0, 99 Latitude = 1 << 0, 100 Longitude = 1 << 1, 101 Altitude = 1 << 2 102 }; 103 Q_DECLARE_FLAGS(PositionFields, PositionField) 104 105 void updatePosition(PositionFields fields, int timestamp, double latitude, 106 double longitude, double altitude, Accuracy accuracy); 107 void positionUpdateFailed(); 108 109 enum VelocityField 110 { 111 NoVelocityFields = 0, 112 Speed = 1 << 0, 113 Direction = 1 << 1, 114 Climb = 1 << 2 115 }; 116 Q_DECLARE_FLAGS(VelocityFields, VelocityField) 117 118 void updateVelocity(VelocityFields fields, int timestamp, double speed, double direction, 119 double climb); 120 void velocityUpdateFailed(); 121 122 private: 123 QGeoclueMaster *m_master; 124 125 OrgFreedesktopGeoclueInterface *m_provider; 126 OrgFreedesktopGeocluePositionInterface *m_pos; 127 OrgFreedesktopGeoclueVelocityInterface *m_vel; 128 129 QTimer m_requestTimer; 130 bool m_lastVelocityIsFresh; 131 bool m_regularUpdateTimedOut; 132 double m_lastVelocity; 133 double m_lastDirection; 134 double m_lastClimb; 135 bool m_lastPositionFromSatellite; 136 QGeoPositionInfo m_lastPosition; 137 bool m_running; 138 QGeoPositionInfoSource::Error m_error; 139 }; 140 141 QT_END_NAMESPACE 142 143 #endif // QGEOPOSITIONINFOSOURCE_GEOCLUEMASTER_H 144