Modified automatic location update method.
[situare] / src / gps / gpspositionprivateliblocation.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #ifndef GPSPOSITIONPRIVATELIBLOCATION_H
23 #define GPSPOSITIONPRIVATELIBLOCATION_H
24
25 #include <QPointF>
26
27 #include "gpsposition.h"
28 #include "geopositioninfo.h"
29
30 class QTimer;
31 class LiblocationWrapper;
32
33 /**
34 * @brief GPSPositionPrivate class use GPS to receive location information.
35 */
36 class GPSPositionPrivate : public QObject
37 {
38     Q_OBJECT
39
40 public:
41     /**
42     * @brief Constructor creates GPS source.
43     *
44     * @param parent QObject
45     */
46     GPSPositionPrivate(QObject *parent);
47
48 /******************************************************************************
49 * MEMBER FUNCTIONS AND SLOTS
50 ******************************************************************************/
51 public:
52     /**
53     * @brief Enables power save mode.
54     *
55     * Starts GPS for position update and then stops it.
56     */
57     void enablePowerSave(bool enabled);
58
59     /**
60     * @brief Returns is GPS initialized.
61     *
62     * @return true if initialized, false otherwise
63     */
64     bool isInitialized();
65
66     /**
67     * @brief Checks if GPS is running.
68     *
69     * @return true if GPS running, false otherwise
70     */
71     bool isRunning();
72
73     /**
74     * @brief Return last known position.
75     */
76     QPointF lastPosition();
77
78     /**
79     * @brief Informs gps to emit last known position.
80     */
81     void requestLastPosition();
82
83     /**
84     * @brief Requests update from GPS.
85     *
86     * Enables GPS if it is disabled
87     */
88     void requestUpdate();
89
90     /**
91     * @brief Set GPS mode.
92     *
93     * Modes: default and simulation.
94     * @param mode GPS mode
95     * @param filePath file path to NMEA file if simulation mode is used
96     */
97     void setMode(GPSPosition::Mode mode, const QString &filePath = 0);
98
99     /**
100     * @brief Set GPS update interval
101     *
102     * @return interval interval in milliseconds
103     */
104     void setUpdateInterval(int interval);
105
106     /**
107     * @brief Start GPS.
108     */
109     void start();
110
111     /**
112     * @brief Stop GPS.
113     */
114     void stop();
115
116 private:
117     /**
118     * @brief Returns horizontal accuracy.
119     *
120     * @param positionInfo geo position info
121     * @return accuracy value, -1 if undefined. Returns -1 also is timestamp is not valid
122     *         (when using network positioning)
123     */
124     qreal accuracy(const GeoPositionInfo &positionInfo);
125
126 private slots:
127     void delayedPowerSaveStart();
128
129     /**
130     * @brief Slot for received position update.
131     *
132     * @param positionInfo Geo position info.
133     */
134     void positionUpdated(const GeoPositionInfo &positionInfo);
135
136     /**
137     * @brief Slot for location error.
138     *
139     * Called when there is error in GPS.
140     */
141     void locationError(const QString &errorMessage);
142
143 /*******************************************************************************
144  * DATA MEMBERS
145  ******************************************************************************/
146 private:
147     LiblocationWrapper *m_liblocationWrapper;    ///< Liblocation wrapper object
148     GPSPosition *m_parent;                      ///< Parent object
149     bool m_initialized;                         ///< GPS is initialized
150     bool m_powerSave;                           ///< Power save flag
151     bool m_running;                             ///< GPS is running
152     int m_updateInterval;                       ///< GPS update interval
153     QTimer *m_delayedPowerSaveTimer;            ///< Delayed power save timer
154 };
155
156 const int DEFAULT_UPDATE_INTERVAL = 5000;       ///< Default update interval
157
158 #endif // GPSPOSITIONPRIVATELIBLOCATION_H