Merge branch 'master' into network_handler
[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 #include <QPointF>
32
33 class QMainWindow;
34
35 class FacebookAuthentication;
36 class FacebookCredentials;
37 class GPSPosition;
38 class MainWindow;
39 class MapEngine;
40 class NetworkAccessManager;
41 class SituareService;
42 class User;
43 class MCE;
44
45 class QTimer;
46
47 /**
48 * @brief Engine class for Situare Application
49 *
50 * This class handles all the underlaying login of the Situare
51 * application.
52 */
53 class SituareEngine : public QObject
54 {
55     Q_OBJECT
56 public:
57     /**
58     * @brief Constructor
59     *
60     * @param parent
61     */
62     SituareEngine(QMainWindow *parent = 0);
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 display state changed.
197     *
198     * @param enabled true if enabled, false otherwise
199     */
200     void displayStateChanged(bool enabled);
201
202     /**
203     * @brief Slot for auto centering enabling.
204     *
205     * Calls gps to send last known position
206     *
207     * @param enabled true if auto centering was enabled, false otherwise
208     */
209     void enableAutoCentering(bool enabled);
210
211     /**
212     * @brief Slot for gps enabling.
213     *
214     * @param enabled true if gps should be enabled, false otherwise
215     */
216     void enableGPS(bool enabled);
217
218     /**
219     * @brief Enables automatic location update.
220     *
221     * @param enabled true if enabled, false otherwise
222     * @param updateIntervalMsecs update interval in milliseconds
223     */
224     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
225
226     /**
227     * @brief Requests automatic update.
228     *
229     * Makes automatic location update request if user has moved enough.
230     *
231     * @param position geo coordinates
232     */
233     void requestAutomaticUpdateIfMoved(QPointF position);
234
235     /**
236      * @brief Sets zoom level to default when first GPS location is received if autocentering
237      * is enabled.
238      *
239      * @param latLonCoordinate own location
240      * @param accuracy accuracy of GPS location
241      */
242     void setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy);
243
244     /**
245     * @brief Automatic update interval timer timeout.
246     *
247     * Requests update location if user has moved.
248     */
249     void startAutomaticUpdate();
250
251 /*******************************************************************************
252  * SIGNALS
253  ******************************************************************************/
254 signals:
255     /**
256     * @brief Signals when automatic location update was enabled.
257     *
258     * @param enabled true if enabled, false otherwise
259     */
260     void automaticLocationUpdateEnabled(bool enabled);
261
262     /**
263     * @brief Signal to clear locationUpdateDialog's data
264     *
265     */
266     void clearUpdateLocationDialogData();
267
268     /**
269     * @brief Signals when new friends data is ready
270     *
271     * @param friendList List of User instances (friends)
272     */
273     void friendsLocationsReady(QList<User *> &friendList);
274
275     /**
276     * @brief Signals when new user data is ready
277     *
278     * @param user Instance of User
279     */
280     void userLocationReady(User *user);
281
282 /*******************************************************************************
283  * DATA MEMBERS
284  ******************************************************************************/
285 private:
286     bool m_autoCenteringEnabled;        ///< Auto centering flag
287     bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
288     bool m_automaticUpdateRequest;      ///< Flag for automatic update request
289     bool m_userMoved;                   ///< Flag for user move
290
291
292     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
293     GPSPosition *m_gps;                              ///< Instance of the gps position
294     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
295     MapEngine *m_mapEngine;                          ///< MapEngine
296     NetworkAccessManager *m_networkAccessManager;    ///< NetworkAccessManager
297     SituareService *m_situareService;  ///< Instance of the situare server communication service
298     MCE *m_mce;                        ///< Instance of the MCE
299
300     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
301     QPointF m_lastUpdatedGPSPosition;       ///< Last updated GPS position
302 };
303
304 #endif // ENGINE_H