Documenting
[situare] / src / engine / engine.h
index 5ced8e2..71bfc7a 100644 (file)
 #ifndef ENGINE_H
 #define ENGINE_H
 
-#include <QWidget>
-#include <QtDebug>
-#include "facebookservice/facebookauthentication.h"
-#include "situareservice/situareservice.h"
-#include "ui/mainwindow.h"
+#include <QObject>
+#include <QTime>
 
-class GPSPositionInterface;
+#include "coordinates/geocoordinate.h"
+
+class QTimer;
+
+class Application;
+class FacebookAuthentication;
+class FacebookCredentials;
+class GeocodingService;
+class GPSPosition;
+class Location;
+class MainWindow;
 class MapEngine;
+class MCE;
+class NetworkAccessManager;
+class Route;
+class RoutingService;
+class SituareService;
+class User;
 
 /**
 * @brief Engine class for Situare Application
@@ -48,9 +61,8 @@ public:
     /**
     * @brief Constructor
     *
-    * @param parent
     */
-    SituareEngine(QMainWindow *parent = 0);
+    SituareEngine();
 
     /**
     * @brief Destructor
@@ -64,12 +76,33 @@ public slots:
     /**
     * @brief Slot to intercept error signal from ImageFetcher and SituareService
     *
+    * @param context Error context
     * @param error Error message
     */
-    void error(const QString &error);
+    void error(const int context, const int error);
+
+    /**
+    * @brief Slot to intercept signal when username is fetched from settings
+    *
+    */
+    void fetchUsernameFromSettings();
+
+    /**
+    * @brief Slot to intercept signal when location search is issued
+    *
+    * @param location QString location
+    */
+    void locationSearch(QString location);
+
+    /**
+    * @brief Slot to intercept signal when Login/Logout action is pressed
+    *
+    */
+    void loginActionPressed();
 
     /**
     * @brief Slot to intercept signal from successful login
+    *
     */
     void loginOk();
 
@@ -79,6 +112,12 @@ public slots:
     void loginProcessCancelled();
 
     /**
+    * @brief Changes application state when logged out
+    *
+    */
+    void logout();
+
+    /**
     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
     *
     */
@@ -91,7 +130,7 @@ public slots:
     * @param status Status message
     * @param publish Publish on Facebook
     */
-    void requestUpdateLocation(const QString &status, bool publish);
+    void requestUpdateLocation(const QString &status = QString(), bool publish = false);
 
     /**
     * @brief Slot to refresh user data
@@ -115,11 +154,22 @@ public slots:
 
 private:
     /**
-      * @brief Connect signals coming from Facdebook authenticator
+    * @brief Read settings and determine whether to use GPS and autocentering.
+    * When values does not found on the settings, GPS and autocentering are enabled as a default.
+    */
+    void initializeGpsAndAutocentering();
+
+    /**
+      * @brief Connect signals coming from Facebook authenticator
       */
     void signalsFromFacebookAuthenticator();
 
     /**
+      * @brief Connect signals coming from GeocodingService
+      */
+    void signalsFromGeocodingService();
+
+    /**
       * @brief Connect signals coming from GPS
       */
     void signalsFromGPS();
@@ -140,41 +190,143 @@ private:
     void signalsFromMapView();
 
     /**
+      * @brief Connect signals coming from RoutingService
+      */
+    void signalsFromRoutingService();
+
+    /**
       * @brief Connect signals coming from Situare
       */
     void signalsFromSituareService();
 
 private slots:
     /**
-      * @brief Set auto centering feature enabled / disabled
-      */
+    * @brief Set auto centering feature enabled / disabled
+    *
+    * @param enabled true if enabled, false otherwise
+    */
     void changeAutoCenteringSetting(bool enabled);
 
     /**
-      * @brief Slot for disabling automatic centering when map is scrolled manually
-      */
+    * @brief Slot for disabling automatic centering when map is scrolled manually
+    */
     void disableAutoCentering();
 
     /**
-    * @brief Slot for auto centering enabling.
+    * @brief Calls vibration feedback.
+    */
+    void draggingModeTriggered();
+
+    /**
+    * @brief Enables automatic location update.
+    *
+    * @param enabled true if enabled, false otherwise
+    * @param updateIntervalMsecs update interval in milliseconds
+    */
+    void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
+
+    /**
+    * @brief Slot to intercept signal when user's/friend's image is downloaded
+    *
+    * @param user Instance of user/friend
+    */
+    void imageReady(User *user);
+
+    /**
+    * @brief Requests automatic update.
+    *
+    * Makes automatic location update request if user has moved enough.
+    *
+    * @param position geo coordinates
+    */
+    void requestAutomaticUpdateIfMoved(GeoCoordinate position);
+
+    /**
+    * @brief Route is parsed and is ready for further processing.
+    *
+    * @param route Route item containing parsed route details
+    */
+    void routeParsed(Route &route);
+
+    /**
+    * @brief Routes to geo coordinates.
+    *
+    * Uses map center coordinates as start point.
+    * @param endPointCoordinates end point geo coordinates
+    */
+    void routeTo(const GeoCoordinate &endPointCoordinates);
+
+    /**
+    * @brief Slot for setting auto centering state.
     *
     * Calls gps to send last known position
     *
     * @param enabled true if auto centering was enabled, false otherwise
     */
-    void enableAutoCentering(bool enabled);
+    void setAutoCentering(bool enabled);
 
     /**
-    * @brief Slot for gps enabling.
+     * @brief Sets zoom level to default when first GPS location is received if autocentering
+     * is enabled.
+     */
+    void setFirstStartZoomLevel();
+
+    /**
+    * @brief Slot for setting GPS state.
     *
     * @param enabled true if gps should be enabled, false otherwise
     */
-    void enableGPS(bool enabled);
+    void setGPS(bool enabled);
+
+    /**
+    * @brief Slot for setting power saving state.
+    *
+    * @param enabled true if enabled, false otherwise
+    */
+    void setPowerSaving(bool enabled);
+
+    /**
+    * @brief Automatic update interval timer timeout.
+    *
+    * Requests update location if user has moved.
+    */
+    void startAutomaticUpdate();
+
+    /**
+    * @brief Called when topmost window is changed
+    *
+    * Does set power saving state.
+    *
+    * @param isMainWindow True if MainWindow is the topmost one
+    */
+    void topmostWindowChanged(bool isMainWindow);
 
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
 signals:
+    /**
+    * @brief Signals when automatic location update was enabled.
+    *
+    * @param enabled true if enabled, false otherwise
+    */
+    void automaticLocationUpdateEnabled(bool enabled);
+
+    /**
+    * @brief Signal to clear locationUpdateDialog's data
+    *
+    */
+    void clearUpdateLocationDialogData();
+
+    /**
+    * @brief Signal when direction and distance from current map center point to current GPS
+    *        location is changed
+    *
+    * @param direction Direction in degrees
+    * @param distance Distance in meters
+    * @param draw Should the indicator triangle be drawn or not
+    */
+    void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
 
     /**
     * @brief Signals when new friends data is ready
@@ -184,6 +336,20 @@ signals:
     void friendsLocationsReady(QList<User *> &friendList);
 
     /**
+    * @brief Signals when friend's image is ready
+    *
+    * @param user Instance of friend
+    */
+    void friendImageReady(User *user);
+
+    /**
+    * @brief Emited when location request is parsed and is ready for further processing
+    *
+    * @param result List of Location items
+    */
+    void locationDataParsed(QList<Location> &result);
+
+    /**
     * @brief Signals when new user data is ready
     *
     * @param user Instance of User
@@ -194,15 +360,23 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    bool m_autoCenteringEnabled;  ///< Auto centering enabled
+    bool m_autoCenteringEnabled;        ///< Auto centering flag
+    bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
+    bool m_automaticUpdateRequest;      ///< Flag for automatic update request
+    bool m_userMoved;                   ///< Flag for user move
 
-    QPointF m_latestLocation;     ///< Placeholder for user's latest asked location
+    QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
 
     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
-    GPSPositionInterface *m_gps;                     ///< Instance of the gps position
+    GeocodingService *m_geocodingService;            ///< Instance of the geocoding service
+    GeoCoordinate m_lastUpdatedGPSPosition;          ///< Last updated GPS position
+    GPSPosition *m_gps;                              ///< Instance of the gps position
     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
     MapEngine *m_mapEngine;                          ///< MapEngine
+    NetworkAccessManager *m_networkAccessManager;    ///< NetworkAccessManager
+    RoutingService *m_routingService;  ///< Instance of the routing service
     SituareService *m_situareService;  ///< Instance of the situare server communication service
+    MCE *m_mce;                        ///< Instance of the MCE
 };
 
 #endif // ENGINE_H