Modified automatic location update method.
[situare] / src / engine / engine.h
1  /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6         Henri Lampela - henri.lampela@ixonos.com
7         Jussi Laitinen - jussi.laitinen@ixonos.com
8         Sami Rämö - sami.ramo@ixonos.com
9
10     Situare is free software; you can redistribute it and/or
11     modify it under the terms of the GNU General Public License
12     version 2 as published by the Free Software Foundation.
13
14     Situare is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with Situare; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
22     USA.
23  */
24
25
26 #ifndef ENGINE_H
27 #define ENGINE_H
28
29 #include <QObject>
30 #include <QTime>
31 #include <QPointF>
32
33 class QMainWindow;
34
35 class FacebookAuthentication;
36 class FacebookCredentials;
37 class GPSPosition;
38 class MainWindow;
39 class MapEngine;
40 class SituareService;
41 class User;
42 class MCE;
43
44 class QTimer;
45
46 /**
47 * @brief Engine class for Situare Application
48 *
49 * This class handles all the underlaying login of the Situare
50 * application.
51 */
52 class SituareEngine : public QObject
53 {
54     Q_OBJECT
55 public:
56     /**
57     * @brief Constructor
58     *
59     * @param parent
60     */
61     SituareEngine(QMainWindow *parent = 0);
62
63     /**
64     * @brief Destructor
65     */
66     ~SituareEngine();
67
68 /*******************************************************************************
69  * MEMBER FUNCTIONS AND SLOTS
70  ******************************************************************************/
71 public slots:
72     /**
73     * @brief Slot to intercept error signal from ImageFetcher and SituareService
74     *
75     * @param error Error message
76     */
77     void error(const int error);
78
79     /**
80     * @brief Slot to intercept signal when username is fetched from settings
81     *
82     */
83     void fetchUsernameFromSettings();
84
85     /**
86     * @brief Slot to intercept signal when Login/Logout action is pressed
87     *
88     */
89     void loginActionPressed();
90
91     /**
92     * @brief Slot to intercept signal from successful login
93     *
94     */
95     void loginOk();
96
97     /**
98     * @brief Slot to intercept signal when user has cancelled login process
99     */
100     void loginProcessCancelled();
101
102     /**
103     * @brief Changes application state when logged out
104     *
105     */
106     void logout();
107
108     /**
109     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
110     *
111     */
112     void requestAddress();
113
114     /**
115     * @brief Calls updateLocation from SituareService to send the location update to
116     *        Situare server.
117     *
118     * @param status Status message
119     * @param publish Publish on Facebook
120     */
121     void requestUpdateLocation(const QString &status = QString(), bool publish = false);
122
123     /**
124     * @brief Slot to refresh user data
125     */
126     void refreshUserData();
127
128     /**
129     * @brief Slot to intercept signal from successful location update
130     *
131     */
132     void updateWasSuccessful();
133
134     /**
135     * @brief Slot to intercept signal when new user data is available.
136     *        Splits User and friendsList data and emits them as two different signals.
137     *
138     * @param user instance of User
139     * @param friendsList list of User instances (friends)
140     */
141     void userDataChanged(User *user, QList<User *> &friendsList);
142
143 private:
144     /**
145     * @brief Read settings and determine whether to use GPS and autocentering.
146     * When values does not found on the settings, GPS and autocentering are enabled as a default.
147     */
148     void initializeGpsAndAutocentering();
149
150     /**
151       * @brief Connect signals coming from Facdebook authenticator
152       */
153     void signalsFromFacebookAuthenticator();
154
155     /**
156       * @brief Connect signals coming from GPS
157       */
158     void signalsFromGPS();
159
160     /**
161       * @brief Connect signals coming from MainWindow
162       */
163     void signalsFromMainWindow();
164
165     /**
166       * @brief Connect signals coming from MapEngine
167       */
168     void signalsFromMapEngine();
169
170     /**
171       * @brief Connect signals coming from MapView
172       */
173     void signalsFromMapView();
174
175     /**
176       * @brief Connect signals coming from Situare
177       */
178     void signalsFromSituareService();
179
180 private slots:
181     /**
182     * @brief Automatic update interval timer timeout.
183     *
184     * Requests update location if user has moved.
185     */
186     void automaticUpdateIntervalTimerTimeout();
187
188     /**
189     * @brief Set auto centering feature enabled / disabled
190     *
191     * @param enabled true if enabled, false otherwise
192     */
193     void changeAutoCenteringSetting(bool enabled);
194
195     /**
196     * @brief Slot for disabling automatic centering when map is scrolled manually
197     */
198     void disableAutoCentering();
199
200     /**
201     * @brief Slot for auto centering enabling.
202     *
203     * Calls gps to send last known position
204     *
205     * @param enabled true if auto centering was enabled, false otherwise
206     */
207     void enableAutoCentering(bool enabled);
208
209     /**
210     * @brief Slot for gps enabling.
211     *
212     * @param enabled true if gps should be enabled, false otherwise
213     */
214     void enableGPS(bool enabled);
215
216     /**
217     * @brief Enables automatic location update.
218     *
219     * @param enabled true if enabled, false otherwise
220     * @param updateIntervalMsecs update interval in milliseconds
221     */
222     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
223
224     /**
225     * @brief Slot for display on.
226     *
227     * @param on true if on, false otherwise
228     */
229     void displayOn(bool on);
230
231     /**
232      * @brief Sets zoom level to default when first GPS location is received if autocentering
233      * is enabled.
234      *
235      * @param latLonCoordinate own location
236      * @param accuracy accuracy of GPS location
237      */
238     void setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy);
239
240     /**
241     * @brief Saves GPS position.
242     *
243     * Saves GPS position if it has changed enough and sets m_userMoved flag.
244     *
245     * @param position geo coordinates
246     */
247     void saveGPSPosition(QPointF position);
248
249 /*******************************************************************************
250  * SIGNALS
251  ******************************************************************************/
252 signals:
253     /**
254     * @brief Signals when automatic location update was enabled.
255     *
256     * @param enabled true if enabled, false otherwise
257     */
258     void automaticLocationUpdateEnabled(bool enabled);
259
260     /**
261     * @brief Signal to clear locationUpdateDialog's data
262     *
263     */
264     void clearUpdateLocationDialogData();
265
266     /**
267     * @brief Signals when new friends data is ready
268     *
269     * @param friendList List of User instances (friends)
270     */
271     void friendsLocationsReady(QList<User *> &friendList);
272
273     /**
274     * @brief Signals when new user data is ready
275     *
276     * @param user Instance of User
277     */
278     void userLocationReady(User *user);
279
280 /*******************************************************************************
281  * DATA MEMBERS
282  ******************************************************************************/
283 private:
284     bool m_autoCenteringEnabled;        ///< Auto centering flag
285     bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
286     bool m_automaticUpdateRequest;      ///< Flag for automatic update request
287     bool m_userMoved;                   ///< Flag for user move
288
289
290     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
291     GPSPosition *m_gps;                              ///< Instance of the gps position
292     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
293     MapEngine *m_mapEngine;                          ///< MapEngine
294     SituareService *m_situareService;  ///< Instance of the situare server communication service
295     MCE *m_mce;                        ///< Instance of the MCE
296
297     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
298     QPointF m_lastUpdatedGPSPosition;       ///< Last updated GPS position
299 };
300
301 #endif // ENGINE_H