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