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