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