Modified automatic location update method.
[situare] / src / engine / engine.h
index d2e5838..19d8a7b 100644 (file)
 #define ENGINE_H
 
 #include <QObject>
+#include <QTime>
+#include <QPointF>
 
 class QMainWindow;
 
 class FacebookAuthentication;
+class FacebookCredentials;
 class GPSPosition;
 class MainWindow;
 class MapEngine;
 class SituareService;
 class User;
-class NetworkHandler;
+class MCE;
+
+class QTimer;
 
 /**
 * @brief Engine class for Situare Application
@@ -69,7 +74,7 @@ public slots:
     *
     * @param error Error message
     */
-    void error(const QString &error);
+    void error(const int error);
 
     /**
     * @brief Slot to intercept signal when username is fetched from settings
@@ -78,11 +83,16 @@ public slots:
     void fetchUsernameFromSettings();
 
     /**
+    * @brief Slot to intercept signal when Login/Logout action is pressed
+    *
+    */
+    void loginActionPressed();
+
+    /**
     * @brief Slot to intercept signal from successful login
     *
-    * @param freshLogin Was login done via login dialog
     */
-    void loginOk(bool freshLogin);
+    void loginOk();
 
     /**
     * @brief Slot to intercept signal when user has cancelled login process
@@ -90,6 +100,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
     *
     */
@@ -102,7 +118,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
@@ -126,6 +142,12 @@ public slots:
 
 private:
     /**
+    * @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 Facdebook authenticator
       */
     void signalsFromFacebookAuthenticator();
@@ -151,39 +173,29 @@ private:
     void signalsFromMapView();
 
     /**
-      * @brief Connect signals coming from NetworkHandler.
-      */
-    void signalsFromNetworkHandler();
-
-    /**
       * @brief Connect signals coming from Situare
       */
     void signalsFromSituareService();
 
 private slots:
     /**
-      * @brief Set auto centering feature enabled / disabled
-      */
-    void changeAutoCenteringSetting(bool enabled);
-
-    /**
-    * @brief Slot for connected to network.
+    * @brief Automatic update interval timer timeout.
     *
-    * Starts network requests.
+    * Requests update location if user has moved.
     */
-    void connectedToNetwork();
+    void automaticUpdateIntervalTimerTimeout();
 
     /**
-      * @brief Slot for disabling automatic centering when map is scrolled manually
-      */
-    void disableAutoCentering();
+    * @brief Set auto centering feature enabled / disabled
+    *
+    * @param enabled true if enabled, false otherwise
+    */
+    void changeAutoCenteringSetting(bool enabled);
 
     /**
-    * @brief Slot for disconnecting from network.
-    *
-    * Stops all network requests.
+    * @brief Slot for disabling automatic centering when map is scrolled manually
     */
-    void disconnectedFromNetwork();
+    void disableAutoCentering();
 
     /**
     * @brief Slot for auto centering enabling.
@@ -201,10 +213,55 @@ private slots:
     */
     void enableGPS(bool enabled);
 
+    /**
+    * @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 for display on.
+    *
+    * @param on true if on, false otherwise
+    */
+    void displayOn(bool on);
+
+    /**
+     * @brief Sets zoom level to default when first GPS location is received if autocentering
+     * is enabled.
+     *
+     * @param latLonCoordinate own location
+     * @param accuracy accuracy of GPS location
+     */
+    void setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy);
+
+    /**
+    * @brief Saves GPS position.
+    *
+    * Saves GPS position if it has changed enough and sets m_userMoved flag.
+    *
+    * @param position geo coordinates
+    */
+    void saveGPSPosition(QPointF position);
+
 /*******************************************************************************
  * 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 Signals when new friends data is ready
@@ -224,14 +281,21 @@ 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
+
 
     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
     GPSPosition *m_gps;                              ///< Instance of the gps position
     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
     MapEngine *m_mapEngine;                          ///< MapEngine
     SituareService *m_situareService;  ///< Instance of the situare server communication service
-    NetworkHandler *m_networkHandler;  ///< Instance of NetworkHandler
+    MCE *m_mce;                        ///< Instance of the MCE
+
+    QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
+    QPointF m_lastUpdatedGPSPosition;       ///< Last updated GPS position
 };
 
 #endif // ENGINE_H