Merge branch 'master' into settings_auto_update
[situare] / src / engine / engine.h
index d7781a5..2a4f9d0 100644 (file)
@@ -27,6 +27,7 @@
 #define ENGINE_H
 
 #include <QObject>
+#include <QTime>
 #include <QPointF>
 
 class QMainWindow;
@@ -39,6 +40,8 @@ class MapEngine;
 class SituareService;
 class User;
 
+class QTimer;
+
 /**
 * @brief Engine class for Situare Application
 *
@@ -114,7 +117,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
@@ -138,9 +141,16 @@ 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.
-      */
+    * @brief Checks if user is moved enough for position auto update.
+    *
+    * @return true if moved engouh, false otherwise
+    */
+    bool isUserMoved();
+
+    /**
+    * @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();
 
     /**
@@ -175,13 +185,22 @@ private:
 
 private slots:
     /**
-      * @brief Set auto centering feature enabled / disabled
-      */
+    * @brief Automatic update interval timer timeout.
+    *
+    * Requests update location if user has moved.
+    */
+    void automaticUpdateIntervalTimerTimeout();
+
+    /**
+    * @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();
 
     /**
@@ -201,6 +220,13 @@ private slots:
     void enableGPS(bool enabled);
 
     /**
+    * @brief Enables automatic location update.
+    *
+    * @param enabled true if
+    */
+    void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
+
+    /**
      * @brief Sets zoom level to default when first GPS location is received if autocentering
      * is enabled.
      *
@@ -215,6 +241,15 @@ private slots:
     */
     void invalidCredentials();
 
+    /**
+    * @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
  ******************************************************************************/
@@ -245,6 +280,10 @@ private:
     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
     MapEngine *m_mapEngine;                          ///< MapEngine
     SituareService *m_situareService;  ///< Instance of the situare server communication service
+
+    QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
+    QPointF m_lastUpdatedGPSPosition;       ///< Last updated GPS position
+    bool m_userMoved;                       ///< Flag for user moving
 };
 
 #endif // ENGINE_H