Added comments to settingsdialog, engine and mainwindow.
[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 QString &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     * @param freshLogin Was login done via login dialog
94     * @param credentials Facebook credentials
95     */
96     void loginOk(bool freshLogin, const FacebookCredentials &credentials);
97
98     /**
99     * @brief Slot to intercept signal when user has cancelled login process
100     */
101     void loginProcessCancelled();
102
103     /**
104     * @brief Changes application state when logged out
105     *
106     */
107     void logout();
108
109     /**
110     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
111     *
112     */
113     void requestAddress();
114
115     /**
116     * @brief Calls updateLocation from SituareService to send the location update to
117     *        Situare server.
118     *
119     * @param status Status message
120     * @param publish Publish on Facebook
121     */
122     void requestUpdateLocation(const QString &status = QString(), bool publish = false);
123
124     /**
125     * @brief Slot to refresh user data
126     */
127     void refreshUserData();
128
129     /**
130     * @brief Slot to intercept signal from successful location update
131     *
132     */
133     void updateWasSuccessful();
134
135     /**
136     * @brief Slot to intercept signal when new user data is available.
137     *        Splits User and friendsList data and emits them as two different signals.
138     *
139     * @param user instance of User
140     * @param friendsList list of User instances (friends)
141     */
142     void userDataChanged(User *user, QList<User *> &friendsList);
143
144 private:
145     /**
146     * @brief Checks if user is moved enough for position auto update.
147     *
148     * @return true if moved engouh, false otherwise
149     */
150     bool isUserMoved();
151
152     /**
153     * @brief Read settings and determine whether to use GPS and autocentering.
154     * When values does not found on the settings, GPS and autocentering are enabled as a default.
155     */
156     void initializeGpsAndAutocentering();
157
158     /**
159       * @brief Connect signals coming from Facdebook authenticator
160       */
161     void signalsFromFacebookAuthenticator();
162
163     /**
164       * @brief Connect signals coming from GPS
165       */
166     void signalsFromGPS();
167
168     /**
169       * @brief Connect signals coming from MainWindow
170       */
171     void signalsFromMainWindow();
172
173     /**
174       * @brief Connect signals coming from MapEngine
175       */
176     void signalsFromMapEngine();
177
178     /**
179       * @brief Connect signals coming from MapView
180       */
181     void signalsFromMapView();
182
183     /**
184       * @brief Connect signals coming from Situare
185       */
186     void signalsFromSituareService();
187
188 private slots:
189     /**
190     * @brief Automatic update interval timer timeout.
191     *
192     * Requests update location if user has moved.
193     */
194     void automaticUpdateIntervalTimerTimeout();
195
196     /**
197     * @brief Set auto centering feature enabled / disabled
198     *
199     * @param enabled true if enabled, false otherwise
200     */
201     void changeAutoCenteringSetting(bool enabled);
202
203     /**
204     * @brief Slot for disabling automatic centering when map is scrolled manually
205     */
206     void disableAutoCentering();
207
208     /**
209     * @brief Slot for auto centering enabling.
210     *
211     * Calls gps to send last known position
212     *
213     * @param enabled true if auto centering was enabled, false otherwise
214     */
215     void enableAutoCentering(bool enabled);
216
217     /**
218     * @brief Slot for gps enabling.
219     *
220     * @param enabled true if gps should be enabled, false otherwise
221     */
222     void enableGPS(bool enabled);
223
224     /**
225     * @brief Enables automatic location update.
226     *
227     * @param enabled true if
228     */
229     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
230
231     /**
232      * @brief Sets zoom level to default when first GPS location is received if autocentering
233      * is enabled.
234      *
235      * @param latLonCoordinate own location
236      * @param accuracy accuracy of GPS location
237      */
238     void setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy);
239     
240     /**
241     * @brief Slot for intercepting signal when credentials are invalid
242     *
243     */
244     void invalidCredentials();
245
246     /**
247     * @brief Saves GPS position.
248     *
249     * Saves GPS position if it has changed enough and sets m_userMoved flag.
250     *
251     * @param position geo coordinates
252     */
253     void saveGPSPosition(QPointF position);
254
255 /*******************************************************************************
256  * SIGNALS
257  ******************************************************************************/
258 signals:
259     /**
260     * @brief Signals when new friends data is ready
261     *
262     * @param friendList List of User instances (friends)
263     */
264     void friendsLocationsReady(QList<User *> &friendList);
265
266     /**
267     * @brief Signals when new user data is ready
268     *
269     * @param user Instance of User
270     */
271     void userLocationReady(User *user);
272
273 /*******************************************************************************
274  * DATA MEMBERS
275  ******************************************************************************/
276 private:
277     bool m_autoCenteringEnabled;  ///< Auto centering enabled
278     bool m_loggedIn;              ///< Login state
279
280     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
281     GPSPosition *m_gps;                              ///< Instance of the gps position
282     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
283     MapEngine *m_mapEngine;                          ///< MapEngine
284     SituareService *m_situareService;  ///< Instance of the situare server communication service
285
286     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
287     QPointF m_lastUpdatedGPSPosition;       ///< Last updated GPS position
288     bool m_userMoved;                       ///< Flag for user moving
289 };
290
291 #endif // ENGINE_H