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