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