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