Fixing defects found in the review
[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
32 #include "coordinates/geocoordinate.h"
33
34 class QTimer;
35
36 #ifdef Q_WS_MAEMO_5
37 class Application;
38 #endif
39 class FacebookAuthentication;
40 class FacebookCredentials;
41 class GeocodingService;
42 class GPSPosition;
43 class Location;
44 class MainWindow;
45 class MapEngine;
46 class MCE;
47 class NetworkAccessManager;
48 class RoutingService;
49 class SituareService;
50 class User;
51
52 /**
53 * @brief Engine class for Situare Application
54 *
55 * This class handles all the underlaying login of the Situare
56 * application.
57 */
58 class SituareEngine : public QObject
59 {
60     Q_OBJECT
61 public:
62     /**
63     * @brief Constructor
64     *
65     */
66     SituareEngine();
67
68     /**
69     * @brief Destructor
70     */
71     ~SituareEngine();
72
73 /*******************************************************************************
74  * MEMBER FUNCTIONS AND SLOTS
75  ******************************************************************************/
76 public slots:
77     /**
78     * @brief Slot to intercept error signal from ImageFetcher and SituareService
79     *
80     * @param context Error context
81     * @param error Error message
82     */
83     void error(const int context, const int error);
84
85     /**
86     * @brief Slot to intercept signal when username is fetched from settings
87     *
88     */
89     void fetchUsernameFromSettings();
90
91     /**
92     * @brief Slot to intercept signal when location search results are ready
93     *
94     * @param result list if location search results
95     */
96     void locationDataReady(QList<Location> &result);
97
98     /**
99     * @brief Slot to intercept signal when location search is issued
100     *
101     * @param location QString location
102     */
103     void locationSearch(QString location);
104
105     /**
106     * @brief Slot to intercept signal when Login/Logout action is pressed
107     *
108     */
109     void loginActionPressed();
110
111     /**
112     * @brief Slot to intercept signal from successful login
113     *
114     */
115     void loginOk();
116
117     /**
118     * @brief Slot to intercept signal when user has cancelled login process
119     */
120     void loginProcessCancelled();
121
122     /**
123     * @brief Changes application state when logged out
124     *
125     */
126     void logout();
127
128     /**
129     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
130     *
131     */
132     void requestAddress();
133
134     /**
135     * @brief Calls updateLocation from SituareService to send the location update to
136     *        Situare server.
137     *
138     * @param status Status message
139     * @param publish Publish on Facebook
140     */
141     void requestUpdateLocation(const QString &status = QString(), bool publish = false);
142
143     /**
144     * @brief Slot to refresh user data
145     */
146     void refreshUserData();
147
148     /**
149     * @brief Slot to intercept signal from successful location update
150     *
151     */
152     void updateWasSuccessful();
153
154     /**
155     * @brief Slot to intercept signal when new user data is available.
156     *        Splits User and friendsList data and emits them as two different signals.
157     *
158     * @param user instance of User
159     * @param friendsList list of User instances (friends)
160     */
161     void userDataChanged(User *user, QList<User *> &friendsList);
162
163 private:
164     /**
165     * @brief Read settings and determine whether to use GPS and autocentering.
166     * When values does not found on the settings, GPS and autocentering are enabled as a default.
167     */
168     void initializeGpsAndAutocentering();
169
170     /**
171       * @brief Connect signals coming from Facebook authenticator
172       */
173     void signalsFromFacebookAuthenticator();
174
175     /**
176       * @brief Connect signals coming from GeocodingService
177       */
178     void signalsFromGeocodingService();
179
180     /**
181       * @brief Connect signals coming from GPS
182       */
183     void signalsFromGPS();
184
185     /**
186       * @brief Connect signals coming from MainWindow
187       */
188     void signalsFromMainWindow();
189
190     /**
191       * @brief Connect signals coming from MapEngine
192       */
193     void signalsFromMapEngine();
194
195     /**
196       * @brief Connect signals coming from MapView
197       */
198     void signalsFromMapView();
199
200     /**
201       * @brief Connect signals coming from RoutingService
202       */
203     void signalsFromRoutingService();
204
205     /**
206       * @brief Connect signals coming from Situare
207       */
208     void signalsFromSituareService();
209
210 private slots:
211     /**
212     * @brief Set auto centering feature enabled / disabled
213     *
214     * @param enabled true if enabled, false otherwise
215     */
216     void changeAutoCenteringSetting(bool enabled);
217
218     /**
219     * @brief Slot for disabling automatic centering when map is scrolled manually
220     */
221     void disableAutoCentering();
222
223     /**
224     * @brief Calls vibration feedback.
225     */
226     void draggingModeTriggered();
227
228     /**
229     * @brief Enables automatic location update.
230     *
231     * @param enabled true if enabled, false otherwise
232     * @param updateIntervalMsecs update interval in milliseconds
233     */
234     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
235
236     /**
237     * @brief Slot for enabling power saving.
238     *
239     * @param enabled true if enabled, false otherwise
240     */
241     void enablePowerSave(bool enabled);
242
243     /**
244     * @brief Slot to intercept signal when user's/friend's image is downloaded
245     *
246     * @param user Instance of user/friend
247     */
248     void imageReady(User *user);
249
250     /**
251     * @brief Requests automatic update.
252     *
253     * Makes automatic location update request if user has moved enough.
254     *
255     * @param position geo coordinates
256     */
257     void requestAutomaticUpdateIfMoved(GeoCoordinate position);
258
259     /**
260     * @brief Slot for setting auto centering state.
261     *
262     * Calls gps to send last known position
263     *
264     * @param enabled true if auto centering was enabled, false otherwise
265     */
266     void setAutoCentering(bool enabled);
267
268     /**
269      * @brief Sets zoom level to default when first GPS location is received if autocentering
270      * is enabled.
271      */
272     void setFirstStartZoomLevel();
273
274     /**
275     * @brief Slot for setting GPS state.
276     *
277     * @param enabled true if gps should be enabled, false otherwise
278     */
279     void setGPS(bool enabled);
280
281     /**
282     * @brief Automatic update interval timer timeout.
283     *
284     * Requests update location if user has moved.
285     */
286     void startAutomaticUpdate();
287
288 /*******************************************************************************
289  * SIGNALS
290  ******************************************************************************/
291 signals:
292     /**
293     * @brief Signals when automatic location update was enabled.
294     *
295     * @param enabled true if enabled, false otherwise
296     */
297     void automaticLocationUpdateEnabled(bool enabled);
298
299     /**
300     * @brief Signal to clear locationUpdateDialog's data
301     *
302     */
303     void clearUpdateLocationDialogData();
304
305     /**
306     * @brief Signal when direction and distance from current map center point to current GPS
307     *        location is changed
308     *
309     * @param direction Direction in degrees
310     * @param distance Distance in meters
311     * @param draw Should the indicator triangle be drawn or not
312     */
313     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
314
315     /**
316     * @brief Signals when new friends data is ready
317     *
318     * @param friendList List of User instances (friends)
319     */
320     void friendsLocationsReady(QList<User *> &friendList);
321
322     /**
323     * @brief Signals when friend's image is ready
324     *
325     * @param user Instance of friend
326     */
327     void friendImageReady(User *user);
328
329     /**
330     * @brief Signals when new user data is ready
331     *
332     * @param user Instance of User
333     */
334     void userLocationReady(User *user);
335
336 /*******************************************************************************
337  * DATA MEMBERS
338  ******************************************************************************/
339 private:
340     bool m_autoCenteringEnabled;        ///< Auto centering flag
341     bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
342     bool m_automaticUpdateRequest;      ///< Flag for automatic update request
343     bool m_userMoved;                   ///< Flag for user move
344
345 #ifdef Q_WS_MAEMO_5
346     Application *m_app;                              ///< Pointer to Application
347 #endif
348     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
349     GeocodingService *m_geocodingService;            ///< Instance of the geocoding service
350     GPSPosition *m_gps;                              ///< Instance of the gps position
351     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
352     MapEngine *m_mapEngine;                          ///< MapEngine
353     NetworkAccessManager *m_networkAccessManager;    ///< NetworkAccessManager
354     RoutingService *m_routingService;  ///< Instance of the routing service
355     SituareService *m_situareService;  ///< Instance of the situare server communication service
356     MCE *m_mce;                        ///< Instance of the MCE
357
358     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
359     GeoCoordinate m_lastUpdatedGPSPosition; ///< Last updated GPS position
360
361 };
362
363 #endif // ENGINE_H