Added power save method to GPS.
[situare] / src / gps / gpspositionprivate.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 GPSPOSITIONPRIVATE_H
23 #define GPSPOSITIONPRIVATE_H
24
25 #include <QPointF>
26
27 #include <QGeoPositionInfo>
28 #include <QGeoPositionInfoSource>
29 #include <QNmeaPositionInfoSource>
30
31 #include "gpsposition.h"
32
33 QTM_USE_NAMESPACE
34
35 /**
36 * @brief GPSPositionPrivate class use GPS to receive location information.
37 */
38 class GPSPositionPrivate : public QObject
39 {
40     Q_OBJECT
41
42 public:
43     /**
44     * @brief Constructor creates GPS source.
45     *
46     * @param parent QObject
47     */
48     GPSPositionPrivate(QObject *parent);
49
50 /******************************************************************************
51 * MEMBER FUNCTIONS AND SLOTS
52 ******************************************************************************/
53 public:
54     /**
55     * @brief Enables power save mode.
56     *
57     * Starts GPS for position update and then stops it.
58     */
59     void enablePowerSave(bool enabled);
60
61     /**
62     * @brief Returns is GPS initialized.
63     *
64     * @return true if initialized, false otherwise
65     */
66     bool isInitialized();
67
68     /**
69     * @brief Checks if GPS is running.
70     *
71     * @return true if GPS running, false otherwise
72     */
73     bool isRunning();
74
75     /**
76     * @brief Return last known position.
77     */
78     QPointF lastPosition();
79
80     /**
81     * @brief Informs gps to emit last known position.
82     */
83     void requestLastPosition();
84
85     /**
86     * @brief Requests update from GPS.
87     *
88     * Enables GPS if it is disabled
89     */
90     void requestUpdate();
91
92     /**
93     * @brief Set GPS mode.
94     *
95     * Modes: default and simulation.
96     * @param mode GPS mode
97     * @param filePath file path to NMEA file if simulation mode is used
98     */
99     void setMode(GPSPosition::Mode mode, const QString &filePath = 0);
100
101     /**
102     * @brief Set GPS update interval
103     *
104     * @return interval interval in milliseconds
105     */
106     void setUpdateInterval(int interval);
107
108     /**
109     * @brief Start GPS.
110     */
111     void start();
112
113     /**
114     * @brief Stop GPS.
115     */
116     void stop();
117
118 private:
119     /**
120     * @brief Return horizontal accuracy
121     *
122     * @param positionInfo geo position info
123     * @return accuracy value, -1 if undefined. Returns -1 also is timestamp is not valid
124     *         (when using network positioning)
125     */
126     qreal accuracy(const QGeoPositionInfo &positionInfo);
127
128 private slots:
129
130     /**
131     * @brief Slot for received position update.
132     *
133     * @param positionInfo Geo position info.
134     */
135     void positionUpdated(const QGeoPositionInfo &positionInfo);
136
137     /**
138     * @brief Slot for update timeout.
139     *
140     * Called when request timeout occurs.
141     */
142     void updateTimeout();
143
144 /*******************************************************************************
145  * DATA MEMBERS
146  ******************************************************************************/
147 private:
148     QGeoPositionInfoSource *m_gpsSource;        ///< GPS position info source
149     GPSPosition *m_parent;                      ///< Parent object
150     bool m_initialized;                         ///< GPS is initialized
151     bool m_running;                             ///< GPS is running
152     int m_updateInterval;                       ///< GPS update interval
153 };
154
155 const int DEFAULT_UPDATE_INTERVAL = 5000;       ///< Default update interval
156
157 #endif // GPSPOSITIONPRIVATE_H