finalising this feature branch
[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 <QPointF>
31
32 class QMainWindow;
33
34 class FacebookAuthentication;
35 class GPSPosition;
36 class MainWindow;
37 class MapEngine;
38 class SituareService;
39 class User;
40
41 /**
42 * @brief Engine class for Situare Application
43 *
44 * This class handles all the underlaying login of the Situare
45 * application.
46 */
47 class SituareEngine : public QObject
48 {
49     Q_OBJECT
50 public:
51     /**
52     * @brief Constructor
53     *
54     * @param parent
55     */
56     SituareEngine(QMainWindow *parent = 0);
57
58     /**
59     * @brief Destructor
60     */
61     ~SituareEngine();
62
63 /*******************************************************************************
64  * MEMBER FUNCTIONS AND SLOTS
65  ******************************************************************************/
66 public slots:
67     /**
68     * @brief Slot to intercept error signal from ImageFetcher and SituareService
69     *
70     * @param error Error message
71     */
72     void error(const QString &error);
73
74     /**
75     * @brief Slot to intercept signal when username is fetched from settings
76     *
77     */
78     void fetchUsernameFromSettings();
79
80     /**
81     * @brief Slot to intercept signal from successful login
82     *
83     * @param freshLogin Was login done via login dialog
84     */
85     void loginOk(bool freshLogin);
86
87     /**
88     * @brief Slot to intercept signal when user has cancelled login process
89     */
90     void loginProcessCancelled();
91
92     /**
93     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
94     *
95     */
96     void requestAddress();
97
98     /**
99     * @brief Calls updateLocation from SituareService to send the location update to
100     *        Situare server.
101     *
102     * @param status Status message
103     * @param publish Publish on Facebook
104     */
105     void requestUpdateLocation(const QString &status, bool publish);
106
107     /**
108     * @brief Slot to refresh user data
109     */
110     void refreshUserData();
111
112     /**
113     * @brief Slot to intercept signal from successful location update
114     *
115     */
116     void updateWasSuccessful();
117
118     /**
119     * @brief Slot to intercept signal when new user data is available.
120     *        Splits User and friendsList data and emits them as two different signals.
121     *
122     * @param user instance of User
123     * @param friendsList list of User instances (friends)
124     */
125     void userDataChanged(User *user, QList<User *> &friendsList);
126
127 private:
128     /**
129       * @brief Read settings and determine whether to use GPS and autocentering.
130       * When values does not found on the settings, GPS and autocentering are enabled as a default.
131       */
132     void initializeGpsAndAutocentering();
133
134     /**
135       * @brief Connect signals coming from Facdebook authenticator
136       */
137     void signalsFromFacebookAuthenticator();
138
139     /**
140       * @brief Connect signals coming from GPS
141       */
142     void signalsFromGPS();
143
144     /**
145       * @brief Connect signals coming from MainWindow
146       */
147     void signalsFromMainWindow();
148
149     /**
150       * @brief Connect signals coming from MapEngine
151       */
152     void signalsFromMapEngine();
153
154     /**
155       * @brief Connect signals coming from MapView
156       */
157     void signalsFromMapView();
158
159     /**
160       * @brief Connect signals coming from Situare
161       */
162     void signalsFromSituareService();
163
164 private slots:    
165     /**
166       * @brief Set auto centering feature enabled / disabled
167       */
168     void changeAutoCenteringSetting(bool enabled);
169
170     /**
171       * @brief Slot for disabling automatic centering when map is scrolled manually
172       */
173     void disableAutoCentering();
174
175     /**
176     * @brief Slot for auto centering enabling.
177     *
178     * Calls gps to send last known position
179     *
180     * @param enabled true if auto centering was enabled, false otherwise
181     */
182     void enableAutoCentering(bool enabled);
183
184     /**
185     * @brief Slot for gps enabling.
186     *
187     * @param enabled true if gps should be enabled, false otherwise
188     */
189     void enableGPS(bool enabled);
190
191     /**
192      * @brief Sets zoom level to default when first GPS location is received if autocentering
193      * is enabled.
194      *
195      * @param latLonCoordinate own location
196      * @param accuracy accuracy of GPS location
197      */
198     void setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy);
199
200 /*******************************************************************************
201  * SIGNALS
202  ******************************************************************************/
203 signals:
204     /**
205     * @brief Signals when new friends data is ready
206     *
207     * @param friendList List of User instances (friends)
208     */
209     void friendsLocationsReady(QList<User *> &friendList);
210
211     /**
212     * @brief Signals when new user data is ready
213     *
214     * @param user Instance of User
215     */
216     void userLocationReady(User *user);
217
218 /*******************************************************************************
219  * DATA MEMBERS
220  ******************************************************************************/
221 private:
222     bool m_autoCenteringEnabled;  ///< Auto centering enabled
223
224     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
225     GPSPosition *m_gps;                              ///< Instance of the gps position
226     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
227     MapEngine *m_mapEngine;                          ///< MapEngine
228     SituareService *m_situareService;  ///< Instance of the situare server communication service
229 };
230
231 #endif // ENGINE_H