Added network connection slots to Engine.
[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 GPSPosition;
35 class MainWindow;
36 class MapEngine;
37 class SituareService;
38 class User;
39 class NetworkHandler;
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 Connect signals coming from Facdebook authenticator
130       */
131     void signalsFromFacebookAuthenticator();
132
133     /**
134       * @brief Connect signals coming from GPS
135       */
136     void signalsFromGPS();
137
138     /**
139       * @brief Connect signals coming from MainWindow
140       */
141     void signalsFromMainWindow();
142
143     /**
144       * @brief Connect signals coming from MapEngine
145       */
146     void signalsFromMapEngine();
147
148     /**
149       * @brief Connect signals coming from MapView
150       */
151     void signalsFromMapView();
152
153     /**
154       * @brief Connect signals coming from NetworkHandler.
155       */
156     void signalsFromNetworkHandler();
157
158     /**
159       * @brief Connect signals coming from Situare
160       */
161     void signalsFromSituareService();
162
163 private slots:
164     /**
165       * @brief Set auto centering feature enabled / disabled
166       */
167     void changeAutoCenteringSetting(bool enabled);
168
169     /**
170     * @brief Slot for connected to network.
171     *
172     * Starts network requests.
173     */
174     void connectedToNetwork();
175
176     /**
177       * @brief Slot for disabling automatic centering when map is scrolled manually
178       */
179     void disableAutoCentering();
180
181     /**
182     * @brief Slot for disconnecting from network.
183     *
184     * Stops all network requests.
185     */
186     void disconnectedFromNetwork();
187
188     /**
189     * @brief Slot for auto centering enabling.
190     *
191     * Calls gps to send last known position
192     *
193     * @param enabled true if auto centering was enabled, false otherwise
194     */
195     void enableAutoCentering(bool enabled);
196
197     /**
198     * @brief Slot for gps enabling.
199     *
200     * @param enabled true if gps should be enabled, false otherwise
201     */
202     void enableGPS(bool enabled);
203
204 /*******************************************************************************
205  * SIGNALS
206  ******************************************************************************/
207 signals:
208
209     /**
210     * @brief Signals when new friends data is ready
211     *
212     * @param friendList List of User instances (friends)
213     */
214     void friendsLocationsReady(QList<User *> &friendList);
215
216     /**
217     * @brief Signals when new user data is ready
218     *
219     * @param user Instance of User
220     */
221     void userLocationReady(User *user);
222
223 /*******************************************************************************
224  * DATA MEMBERS
225  ******************************************************************************/
226 private:
227     bool m_autoCenteringEnabled;  ///< Auto centering enabled
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     NetworkHandler *m_networkHandler;  ///< Instance of NetworkHandler
235 };
236
237 #endif // ENGINE_H