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