Re-factored the source to use the new coordinate classes
[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 MainWindow;
41 class MapEngine;
42 class NetworkAccessManager;
43 class SituareService;
44 class User;
45 class MCE;
46
47 class QTimer;
48
49 /**
50 * @brief Engine class for Situare Application
51 *
52 * This class handles all the underlaying login of the Situare
53 * application.
54 */
55 class SituareEngine : public QObject
56 {
57     Q_OBJECT
58 public:
59     /**
60     * @brief Constructor
61     *
62     * @param parent
63     */
64     SituareEngine();
65
66     /**
67     * @brief Destructor
68     */
69     ~SituareEngine();
70
71 /*******************************************************************************
72  * MEMBER FUNCTIONS AND SLOTS
73  ******************************************************************************/
74 public slots:
75     /**
76     * @brief Slot to intercept error signal from ImageFetcher and SituareService
77     *
78     * @param context Error context
79     * @param error Error message
80     */
81     void error(const int context, const int error);
82
83     /**
84     * @brief Slot to intercept signal when username is fetched from settings
85     *
86     */
87     void fetchUsernameFromSettings();
88
89     /**
90     * @brief Slot to intercept signal when Login/Logout action is pressed
91     *
92     */
93     void loginActionPressed();
94
95     /**
96     * @brief Slot to intercept signal from successful login
97     *
98     */
99     void loginOk();
100
101     /**
102     * @brief Slot to intercept signal when user has cancelled login process
103     */
104     void loginProcessCancelled();
105
106     /**
107     * @brief Changes application state when logged out
108     *
109     */
110     void logout();
111
112     /**
113     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
114     *
115     */
116     void requestAddress();
117
118     /**
119     * @brief Calls updateLocation from SituareService to send the location update to
120     *        Situare server.
121     *
122     * @param status Status message
123     * @param publish Publish on Facebook
124     */
125     void requestUpdateLocation(const QString &status = QString(), bool publish = false);
126
127     /**
128     * @brief Slot to refresh user data
129     */
130     void refreshUserData();
131
132     /**
133     * @brief Slot to intercept signal from successful location update
134     *
135     */
136     void updateWasSuccessful();
137
138     /**
139     * @brief Slot to intercept signal when new user data is available.
140     *        Splits User and friendsList data and emits them as two different signals.
141     *
142     * @param user instance of User
143     * @param friendsList list of User instances (friends)
144     */
145     void userDataChanged(User *user, QList<User *> &friendsList);
146
147 private:
148     /**
149     * @brief Read settings and determine whether to use GPS and autocentering.
150     * When values does not found on the settings, GPS and autocentering are enabled as a default.
151     */
152     void initializeGpsAndAutocentering();
153
154     /**
155       * @brief Connect signals coming from Facdebook authenticator
156       */
157     void signalsFromFacebookAuthenticator();
158
159     /**
160       * @brief Connect signals coming from GPS
161       */
162     void signalsFromGPS();
163
164     /**
165       * @brief Connect signals coming from MainWindow
166       */
167     void signalsFromMainWindow();
168
169     /**
170       * @brief Connect signals coming from MapEngine
171       */
172     void signalsFromMapEngine();
173
174     /**
175       * @brief Connect signals coming from MapView
176       */
177     void signalsFromMapView();
178
179     /**
180       * @brief Connect signals coming from Situare
181       */
182     void signalsFromSituareService();
183
184 private slots:
185     /**
186     * @brief Set auto centering feature enabled / disabled
187     *
188     * @param enabled true if enabled, false otherwise
189     */
190     void changeAutoCenteringSetting(bool enabled);
191
192     /**
193     * @brief Slot for disabling automatic centering when map is scrolled manually
194     */
195     void disableAutoCentering();
196
197     /**
198     * @brief Slot for auto centering enabling.
199     *
200     * Calls gps to send last known position
201     *
202     * @param enabled true if auto centering was enabled, false otherwise
203     */
204     void enableAutoCentering(bool enabled);
205
206     /**
207     * @brief Slot for gps enabling.
208     *
209     * @param enabled true if gps should be enabled, false otherwise
210     */
211     void enableGPS(bool enabled);
212
213     /**
214     * @brief Enables automatic location update.
215     *
216     * @param enabled true if enabled, false otherwise
217     * @param updateIntervalMsecs update interval in milliseconds
218     */
219     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
220
221     /**
222     * @brief Slot for enabling power saving.
223     *
224     * @param enabled true if enabled, false otherwise
225     */
226     void enablePowerSave(bool enabled);
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 Sets zoom level to default when first GPS location is received if autocentering
246      * is enabled.
247      */
248     void setFirstStartZoomLevel();
249
250     /**
251     * @brief Automatic update interval timer timeout.
252     *
253     * Requests update location if user has moved.
254     */
255     void startAutomaticUpdate();
256
257 /*******************************************************************************
258  * SIGNALS
259  ******************************************************************************/
260 signals:
261     /**
262     * @brief Signals when automatic location update was enabled.
263     *
264     * @param enabled true if enabled, false otherwise
265     */
266     void automaticLocationUpdateEnabled(bool enabled);
267
268     /**
269     * @brief Signal to clear locationUpdateDialog's data
270     *
271     */
272     void clearUpdateLocationDialogData();
273
274     /**
275     * @brief Signals when new friends data is ready
276     *
277     * @param friendList List of User instances (friends)
278     */
279     void friendsLocationsReady(QList<User *> &friendList);
280
281     /**
282     * @brief Signals when friend's image is ready
283     *
284     * @param user Instance of friend
285     */
286     void friendImageReady(User *user);
287
288     /**
289     * @brief Signals when new user data is ready
290     *
291     * @param user Instance of User
292     */
293     void userLocationReady(User *user);
294
295 /*******************************************************************************
296  * DATA MEMBERS
297  ******************************************************************************/
298 private:
299     bool m_autoCenteringEnabled;        ///< Auto centering flag
300     bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
301     bool m_automaticUpdateRequest;      ///< Flag for automatic update request
302     bool m_userMoved;                   ///< Flag for user move
303
304 #ifdef Q_WS_MAEMO_5
305     Application *m_app;                              ///< Pointer to Application
306 #endif
307     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
308     GPSPosition *m_gps;                              ///< Instance of the gps position
309     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
310     MapEngine *m_mapEngine;                          ///< MapEngine
311     NetworkAccessManager *m_networkAccessManager;    ///< NetworkAccessManager
312     SituareService *m_situareService;  ///< Instance of the situare server communication service
313     MCE *m_mce;                        ///< Instance of the MCE
314
315     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
316     GeoCoordinate m_lastUpdatedGPSPosition; ///< Last updated GPS position
317
318 };
319
320 #endif // ENGINE_H