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