Merge branch 'master' into indicator
[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 #ifdef Q_WS_MAEMO_5
35 class Application;
36 #endif
37 class FacebookAuthentication;
38 class FacebookCredentials;
39 class GPSPosition;
40 class Location;
41 class MainWindow;
42 class MapEngine;
43 class NetworkAccessManager;
44 class RoutingService;
45 class SituareService;
46 class User;
47 class MCE;
48
49 class QTimer;
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 results are ready
92     *
93     * @param result list if location search results
94     */
95     void locationDataReady(QList<Location> &result);
96
97     /**
98     * @brief Slot to intercept signal when location search is issued
99     *
100     * @param location QString location
101     */
102     void locationSearch(QString location);
103
104     /**
105     * @brief Slot to intercept signal when Login/Logout action is pressed
106     *
107     */
108     void loginActionPressed();
109
110     /**
111     * @brief Slot to intercept signal from successful login
112     *
113     */
114     void loginOk();
115
116     /**
117     * @brief Slot to intercept signal when user has cancelled login process
118     */
119     void loginProcessCancelled();
120
121     /**
122     * @brief Changes application state when logged out
123     *
124     */
125     void logout();
126
127     /**
128     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
129     *
130     */
131     void requestAddress();
132
133     /**
134     * @brief Calls updateLocation from SituareService to send the location update to
135     *        Situare server.
136     *
137     * @param status Status message
138     * @param publish Publish on Facebook
139     */
140     void requestUpdateLocation(const QString &status = QString(), bool publish = false);
141
142     /**
143     * @brief Slot to refresh user data
144     */
145     void refreshUserData();
146
147     /**
148     * @brief Slot to intercept signal from successful location update
149     *
150     */
151     void updateWasSuccessful();
152
153     /**
154     * @brief Slot to intercept signal when new user data is available.
155     *        Splits User and friendsList data and emits them as two different signals.
156     *
157     * @param user instance of User
158     * @param friendsList list of User instances (friends)
159     */
160     void userDataChanged(User *user, QList<User *> &friendsList);
161
162 private:
163     /**
164     * @brief Read settings and determine whether to use GPS and autocentering.
165     * When values does not found on the settings, GPS and autocentering are enabled as a default.
166     */
167     void initializeGpsAndAutocentering();
168
169     /**
170       * @brief Connect signals coming from Facdebook authenticator
171       */
172     void signalsFromFacebookAuthenticator();
173
174     /**
175       * @brief Connect signals coming from GPS
176       */
177     void signalsFromGPS();
178
179     /**
180       * @brief Connect signals coming from MainWindow
181       */
182     void signalsFromMainWindow();
183
184     /**
185       * @brief Connect signals coming from MapEngine
186       */
187     void signalsFromMapEngine();
188
189     /**
190       * @brief Connect signals coming from MapView
191       */
192     void signalsFromMapView();
193
194     /**
195       * @brief Connect signals coming from RoutingService
196       */
197     void signalsFromRoutingService();
198
199     /**
200       * @brief Connect signals coming from Situare
201       */
202     void signalsFromSituareService();
203
204 private slots:
205     /**
206     * @brief Set auto centering feature enabled / disabled
207     *
208     * @param enabled true if enabled, false otherwise
209     */
210     void changeAutoCenteringSetting(bool enabled);
211
212     /**
213     * @brief Slot for disabling automatic centering when map is scrolled manually
214     */
215     void disableAutoCentering();
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 for enabling power saving.
227     *
228     * @param enabled true if enabled, false otherwise
229     */
230     void enablePowerSave(bool enabled);
231
232     /**
233     * @brief Slot to intercept signal when user's/friend's image is downloaded
234     *
235     * @param user Instance of user/friend
236     */
237     void imageReady(User *user);
238
239     /**
240     * @brief Requests automatic update.
241     *
242     * Makes automatic location update request if user has moved enough.
243     *
244     * @param position geo coordinates
245     */
246     void requestAutomaticUpdateIfMoved(GeoCoordinate position);
247
248     /**
249     * @brief Slot for setting auto centering state.
250     *
251     * Calls gps to send last known position
252     *
253     * @param enabled true if auto centering was enabled, false otherwise
254     */
255     void setAutoCentering(bool enabled);
256
257     /**
258      * @brief Sets zoom level to default when first GPS location is received if autocentering
259      * is enabled.
260      */
261     void setFirstStartZoomLevel();
262
263     /**
264     * @brief Slot for setting GPS state.
265     *
266     * @param enabled true if gps should be enabled, false otherwise
267     */
268     void setGPS(bool enabled);
269
270     /**
271     * @brief Automatic update interval timer timeout.
272     *
273     * Requests update location if user has moved.
274     */
275     void startAutomaticUpdate();
276
277 /*******************************************************************************
278  * SIGNALS
279  ******************************************************************************/
280 signals:
281     /**
282     * @brief Signals when automatic location update was enabled.
283     *
284     * @param enabled true if enabled, false otherwise
285     */
286     void automaticLocationUpdateEnabled(bool enabled);
287
288     /**
289     * @brief Signal to clear locationUpdateDialog's data
290     *
291     */
292     void clearUpdateLocationDialogData();
293
294     /**
295     * @brief Signal when direction and distance from current map center point to current GPS
296     *        location is changed
297     *
298     * @param direction Direction in degrees
299     * @param distance Distance in kilometers
300     * @param draw Should the indicator triangle be drawn or not
301     */
302     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
303
304     /**
305     * @brief Signals when new friends data is ready
306     *
307     * @param friendList List of User instances (friends)
308     */
309     void friendsLocationsReady(QList<User *> &friendList);
310
311     /**
312     * @brief Signals when friend's image is ready
313     *
314     * @param user Instance of friend
315     */
316     void friendImageReady(User *user);
317
318     /**
319     * @brief Signals when new user data is ready
320     *
321     * @param user Instance of User
322     */
323     void userLocationReady(User *user);
324
325 /*******************************************************************************
326  * DATA MEMBERS
327  ******************************************************************************/
328 private:
329     bool m_autoCenteringEnabled;        ///< Auto centering flag
330     bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
331     bool m_automaticUpdateRequest;      ///< Flag for automatic update request
332     bool m_userMoved;                   ///< Flag for user move
333
334 #ifdef Q_WS_MAEMO_5
335     Application *m_app;                              ///< Pointer to Application
336 #endif
337     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
338     GPSPosition *m_gps;                              ///< Instance of the gps position
339     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
340     MapEngine *m_mapEngine;                          ///< MapEngine
341     NetworkAccessManager *m_networkAccessManager;    ///< NetworkAccessManager
342     RoutingService *m_routingService;  ///< Instance of the routing service
343     SituareService *m_situareService;  ///< Instance of the situare server communication service
344     MCE *m_mce;                        ///< Instance of the MCE
345
346     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
347     GeoCoordinate m_lastUpdatedGPSPosition; ///< Last updated GPS position
348
349 };
350
351 #endif // ENGINE_H