Added show friend button to MeetPeoplePanel.
[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 #include <QPair>
32
33 #include "coordinates/geocoordinate.h"
34 #include "situareservice/situareservice.h"
35
36 class QTimer;
37
38 class Application;
39 class ContactManager;
40 class FacebookAuthentication;
41 class FacebookCredentials;
42 class GeocodingService;
43 class GPSPosition;
44 class Location;
45 class MainWindow;
46 class MapEngine;
47 class MCE;
48 class NetworkAccessManager;
49 class Route;
50 class RoutingService;
51 class SituareService;
52 class User;
53
54 /**
55 * @brief Engine class for Situare Application
56 *
57 * This class handles all the underlaying login of the Situare
58 * application.
59 */
60 class SituareEngine : public QObject
61 {
62     Q_OBJECT
63 public:
64     /**
65     * @brief Constructor
66     *
67     */
68     SituareEngine();
69
70     /**
71     * @brief Destructor
72     */
73     ~SituareEngine();
74
75 /*******************************************************************************
76  * MEMBER FUNCTIONS AND SLOTS
77  ******************************************************************************/
78 public slots:
79     /**
80     * @brief Slot to intercept error signal from ImageFetcher and SituareService
81     *
82     * @param context Error context
83     * @param error Error message
84     */
85     void error(const int context, const int error);
86
87     /**
88     * @brief Slot to intercept signal when username is fetched from settings
89     *
90     */
91     void fetchUsernameFromSettings();
92
93     /**
94     * @brief Slot to intercept signal when location search is issued
95     *
96     * @param location QString location
97     */
98     void locationSearch(QString location);
99
100     /**
101     * @brief Slot to intercept signal when Login/Logout action is pressed
102     *
103     */
104     void loginActionPressed();
105
106     /**
107     * @brief Slot to intercept signal from successful login
108     *
109     */
110     void loginOk();
111
112     /**
113     * @brief Slot to intercept signal when user has cancelled login process
114     */
115     void loginProcessCancelled();
116
117     /**
118     * @brief Changes application state when logged out
119     *
120     */
121     void logout();
122
123     /**
124     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
125     *
126     */
127     void requestAddress();
128
129     /**
130     * @brief Calls updateLocation from SituareService to send the location update to
131     *        Situare server.
132     *
133     * @param status Status message
134     * @param publish Publish on Facebook
135     */
136     void requestUpdateLocation(const QString &status = QString(), bool publish = false);
137
138     /**
139     * @brief Slot to refresh user data
140     */
141     void refreshUserData();
142
143     /**
144     * @brief Slot to intercept signal from successful location update
145     *
146     * @param successfulMethod which method was successful
147     */
148     void updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod);
149
150     /**
151     * @brief Slot to intercept signal when new user data is available.
152     *        Splits User and friendsList data and emits them as two different signals.
153     *
154     * @param user instance of User
155     * @param friendsList list of User instances (friends)
156     */
157     void userDataChanged(User *user, QList<User *> &friendsList);
158
159 private:
160     /**
161     * @brief Read settings and determine whether to use GPS and autocentering.
162     * When values does not found on the settings, GPS and autocentering are enabled as a default.
163     */
164     void initializeGpsAndAutocentering();
165
166     /**
167       * @brief Connect signals coming from Facebook authenticator
168       */
169     void signalsFromFacebookAuthenticator();
170
171     /**
172       * @brief Connect signals coming from GeocodingService
173       */
174     void signalsFromGeocodingService();
175
176     /**
177       * @brief Connect signals coming from GPS
178       */
179     void signalsFromGPS();
180
181     /**
182       * @brief Connect signals coming from MainWindow
183       */
184     void signalsFromMainWindow();
185
186     /**
187       * @brief Connect signals coming from MapEngine
188       */
189     void signalsFromMapEngine();
190
191     /**
192       * @brief Connect signals coming from MapView
193       */
194     void signalsFromMapView();
195
196     /**
197       * @brief Connect signals coming from RoutingService
198       */
199     void signalsFromRoutingService();
200
201     /**
202       * @brief Connect signals coming from Situare
203       */
204     void signalsFromSituareService();
205
206 private slots:
207     /**
208     * @brief Set auto centering feature enabled / disabled
209     *
210     * @param enabled true if enabled, false otherwise
211     */
212     void changeAutoCenteringSetting(bool enabled);
213
214     /**
215     * @brief Slot for disabling automatic centering when map is scrolled manually
216     */
217     void disableAutoCentering();
218
219     /**
220     * @brief Calls vibration feedback.
221     */
222     void draggingModeTriggered();
223
224     /**
225     * @brief Enables automatic location update.
226     *
227     * @param enabled true if enabled, false otherwise
228     * @param updateIntervalMsecs update interval in milliseconds
229     */
230     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
231
232     /**
233     * @brief Slot for image ready
234     *
235     * @param id image ID
236     * @param image image pixmap
237     */
238     void imageReady(const QString &id, const QPixmap &image);
239
240     /**
241     * @brief Requests automatic update.
242     *
243     * Makes automatic location update request if user has moved enough.
244     *
245     * @param position geo coordinates
246     */
247     void requestAutomaticUpdateIfMoved(GeoCoordinate position);
248
249     /**
250     * @brief Requests interesting people from current map viewport.
251     *
252     * Interesting people is defined by people with same tags as user has.
253     */
254     void requestInterestingPeople();
255
256     /**
257     * @brief Route is parsed and is ready for further processing.
258     *
259     * @param route Route item containing parsed route details
260     */
261     void routeParsed(Route &route);
262
263     /**
264     * @brief Routes to geo coordinates.
265     *
266     * Uses map center coordinates as start point.
267     * @param endPointCoordinates end point geo coordinates
268     */
269     void routeTo(const GeoCoordinate &endPointCoordinates);
270
271     /**
272     * @brief Route to current cursor position
273     */
274     void routeToCursor();
275
276     /**
277     * @brief Slot for setting auto centering state.
278     *
279     * Calls gps to send last known position
280     *
281     * @param enabled true if auto centering was enabled, false otherwise
282     */
283     void setAutoCentering(bool enabled);
284
285     /**
286      * @brief Sets zoom level to default when first GPS location is received if autocentering
287      * is enabled.
288      */
289     void setFirstStartZoomLevel();
290
291     /**
292     * @brief Slot for setting GPS state.
293     *
294     * @param enabled true if gps should be enabled, false otherwise
295     */
296     void setGPS(bool enabled);
297
298     /**
299     * @brief Slot for setting power saving state.
300     *
301     * @param enabled true if enabled, false otherwise
302     */
303     void setPowerSaving(bool enabled);
304
305     /**
306     * @brief Shows contact dialog.
307     *
308     * Calls MainWindow showContactDialog with contact guid defined by contact's Facebook ID.
309     * @param facebookId contact's facebookId
310     */
311     void showContactDialog(const QString &facebookId);
312
313     /**
314     * @brief Shows message dialog.
315     *
316     * If contact is a friend, show contact dialog instead.
317     * @param receiver receiver facebook ID and name
318     */
319     void showMessageDialog(const QPair<QString, QString> &receiver);
320
321     /**
322     * @brief Automatic update interval timer timeout.
323     *
324     * Requests update location if user has moved.
325     */
326     void startAutomaticUpdate();
327
328     /**
329     * @brief Called when topmost window is changed
330     *
331     * Does set power saving state.
332     *
333     * @param isMainWindow True if MainWindow is the topmost one
334     */
335     void topmostWindowChanged(bool isMainWindow);
336
337 /*******************************************************************************
338  * SIGNALS
339  ******************************************************************************/
340 signals:
341     /**
342     * @brief Signals when automatic location update was enabled.
343     *
344     * @param enabled true if enabled, false otherwise
345     */
346     void automaticLocationUpdateEnabled(bool enabled);
347
348     /**
349     * @brief Signal to clear locationUpdateDialog's data
350     *
351     */
352     void clearUpdateLocationDialogData();
353
354     /**
355     * @brief Signal when direction and distance from current map center point to current GPS
356     *        location is changed
357     *
358     * @param direction Direction in degrees
359     * @param distance Distance in meters
360     * @param draw Should the indicator triangle be drawn or not
361     */
362     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
363
364     /**
365     * @brief Signals when new friends data is ready
366     *
367     * @param friendList List of User instances (friends)
368     */
369     void friendsLocationsReady(QList<User *> &friendList);
370
371     /**
372     * @brief Signals when friend's image is ready
373     *
374     * @param user Instance of friend
375     */
376     void friendImageReady(const QString &id, const QPixmap &image);
377
378     /**
379     * @brief Emited when location request is parsed and is ready for further processing
380     *
381     * @param result List of Location items
382     */
383     void locationDataParsed(QList<Location> &result);
384
385     /**
386     * @brief Signals when users's image is ready
387     *
388     * @param user Instance of friend
389     */
390     void userImageReady(const QString &id, const QPixmap &image);
391
392     /**
393     * @brief Signals when new user data is ready
394     *
395     * @param user Instance of User
396     */
397     void userLocationReady(User *user);
398
399 /*******************************************************************************
400  * DATA MEMBERS
401  ******************************************************************************/
402 private:
403     bool m_autoCenteringEnabled;        ///< Auto centering flag
404     bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
405     bool m_automaticUpdateRequest;      ///< Flag for automatic update request
406     bool m_userMoved;                   ///< Flag for user move
407
408     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
409
410     ContactManager *m_contactManager;                ///< Instance of contact manager
411     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
412     GeocodingService *m_geocodingService;            ///< Instance of the geocoding service
413     GeoCoordinate m_lastUpdatedGPSPosition;          ///< Last updated GPS position
414     GPSPosition *m_gps;                              ///< Instance of the gps position
415     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
416     MapEngine *m_mapEngine;                          ///< MapEngine
417     NetworkAccessManager *m_networkAccessManager;    ///< NetworkAccessManager
418     RoutingService *m_routingService;  ///< Instance of the routing service
419     SituareService *m_situareService;  ///< Instance of the situare server communication service
420     MCE *m_mce;                        ///< Instance of the MCE
421 };
422
423 #endif // ENGINE_H