Bugs with master
[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
31 class QMainWindow;
32
33 class FacebookAuthentication;
34 class FacebookCredentials;
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 when Login/Logout action is pressed
82     *
83     */
84     void loginActionPressed();
85
86     /**
87     * @brief Slot to intercept signal from successful login
88     *
89     * @param freshLogin Was login done via login dialog
90     * @param credentials Facebook credentials
91     */
92     void loginOk(bool freshLogin, const FacebookCredentials &credentials);
93
94     /**
95     * @brief Slot to intercept signal when user has cancelled login process
96     */
97     void loginProcessCancelled();
98
99     /**
100     * @brief Changes application state when logged out
101     *
102     */
103     void logout();
104
105     /**
106     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
107     *
108     */
109     void requestAddress();
110
111     /**
112     * @brief Calls updateLocation from SituareService to send the location update to
113     *        Situare server.
114     *
115     * @param status Status message
116     * @param publish Publish on Facebook
117     */
118     void requestUpdateLocation(const QString &status, bool publish);
119
120     /**
121     * @brief Slot to refresh user data
122     */
123     void refreshUserData();
124
125     /**
126     * @brief Slot to intercept signal from successful location update
127     *
128     */
129     void updateWasSuccessful();
130
131     /**
132     * @brief Slot to intercept signal when new user data is available.
133     *        Splits User and friendsList data and emits them as two different signals.
134     *
135     * @param user instance of User
136     * @param friendsList list of User instances (friends)
137     */
138     void userDataChanged(User *user, QList<User *> &friendsList);
139
140 private:
141     /**
142       * @brief Connect signals coming from Facdebook authenticator
143       */
144     void signalsFromFacebookAuthenticator();
145
146     /**
147       * @brief Connect signals coming from GPS
148       */
149     void signalsFromGPS();
150
151     /**
152       * @brief Connect signals coming from MainWindow
153       */
154     void signalsFromMainWindow();
155
156     /**
157       * @brief Connect signals coming from MapEngine
158       */
159     void signalsFromMapEngine();
160
161     /**
162       * @brief Connect signals coming from MapView
163       */
164     void signalsFromMapView();
165
166     /**
167       * @brief Connect signals coming from Situare
168       */
169     void signalsFromSituareService();
170
171 private slots:
172     /**
173       * @brief Set auto centering feature enabled / disabled
174       */
175     void changeAutoCenteringSetting(bool enabled);
176
177     /**
178       * @brief Slot for disabling automatic centering when map is scrolled manually
179       */
180     void disableAutoCentering();
181
182     /**
183     * @brief Slot for auto centering enabling.
184     *
185     * Calls gps to send last known position
186     *
187     * @param enabled true if auto centering was enabled, false otherwise
188     */
189     void enableAutoCentering(bool enabled);
190
191     /**
192     * @brief Slot for gps enabling.
193     *
194     * @param enabled true if gps should be enabled, false otherwise
195     */
196     void enableGPS(bool enabled);
197
198     /**
199     * @brief Slot for intercepting signal when credentials are invalid
200     *
201     */
202     void invalidCredentials();
203
204 /*******************************************************************************
205  * SIGNALS
206  ******************************************************************************/
207 signals:
208     /**
209     * @brief Signals when new friends data is ready
210     *
211     * @param friendList List of User instances (friends)
212     */
213     void friendsLocationsReady(QList<User *> &friendList);
214
215     /**
216     * @brief Signals when new user data is ready
217     *
218     * @param user Instance of User
219     */
220     void userLocationReady(User *user);
221
222 /*******************************************************************************
223  * DATA MEMBERS
224  ******************************************************************************/
225 private:
226     bool m_autoCenteringEnabled;  ///< Auto centering enabled
227     bool m_loggedIn;              ///< Login state
228
229     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
230     GPSPosition *m_gps;                              ///< Instance of the gps position
231     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
232     MapEngine *m_mapEngine;                          ///< MapEngine
233     SituareService *m_situareService;  ///< Instance of the situare server communication service
234
235 };
236
237 #endif // ENGINE_H