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