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