Modified Engine automatic update location feature.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 9 Jun 2010 10:43:50 +0000 (13:43 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 9 Jun 2010 10:43:50 +0000 (13:43 +0300)
src/engine/engine.cpp
src/engine/engine.h
src/facebookservice/facebookauthentication.cpp
src/gps/gpsposition.cpp

index df56719..20e38c4 100644 (file)
@@ -48,7 +48,8 @@ SituareEngine::SituareEngine(QMainWindow *parent)
       m_loggedIn(false),
       m_automaticUpdateIntervalTimer(0),
       m_lastUpdatedGPSPosition(QPointF()),
-      m_userMoved(false)
+      m_userMoved(false),
+      m_automaticUpdateEnabled(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
     m_ui = new MainWindow;
@@ -87,6 +88,10 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
+    m_automaticUpdateIntervalTimer = new QTimer(this);
+    connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
+            this, SLOT(automaticUpdateIntervalTimerTimeout()));
+
     // signals connected, now it's time to show the main window
     // but init the MapEngine before so starting location is set
     m_mapEngine->init();
@@ -95,10 +100,6 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     m_facebookAuthenticator->start();
 
     initializeGpsAndAutocentering();
-
-    m_automaticUpdateIntervalTimer = new QTimer(this);
-    connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
-            this, SLOT(automaticUpdateIntervalTimerTimeout()));
 }
 
 SituareEngine::~SituareEngine()
@@ -117,8 +118,7 @@ void SituareEngine::automaticUpdateIntervalTimerTimeout()
     qWarning() << __PRETTY_FUNCTION__;
 
     if (m_gps->isRunning() && m_userMoved) {
-//        requestUpdateLocation();
-        qWarning() << __PRETTY_FUNCTION__ << "requestUpdateLocation()";
+        requestUpdateLocation();
         m_userMoved = false;
     }
 }
@@ -161,24 +161,29 @@ void SituareEngine::enableGPS(bool enabled)
         m_gps->start();
         enableAutoCentering(m_autoCenteringEnabled);
         m_gps->requestLastPosition();
+
+        if (!m_automaticUpdateEnabled && m_loggedIn)
+            m_ui->requestAutomaticLocationUpdateSettings();
     }
     else if (!enabled && m_gps->isRunning()) {
         m_gps->stop();
         enableAutoCentering(false);
+        enableAutomaticLocationUpdate(false);
     }
 }
 
 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
 {
-    qWarning() << __PRETTY_FUNCTION__ << enabled;
+    qDebug() << __PRETTY_FUNCTION__;
 
     bool accepted = true;
 
-    if (m_automaticUpdateFirstStart && enabled) {
+    m_automaticUpdateEnabled = enabled;
+
+    if (m_automaticUpdateFirstStart && m_gps->isRunning() && m_automaticUpdateEnabled) {
         accepted = m_ui->showEnableAutomaticUpdateLocationDialog(
                 tr("Do you want to enable automatic location update with %1 min update interval?")
                 .arg(updateIntervalMsecs/1000/60));
-        qWarning() << __PRETTY_FUNCTION__ << "Accepted" << accepted;
         m_automaticUpdateFirstStart = false;
         m_ui->automaticLocationUpdateEnabled(accepted);
 
@@ -188,11 +193,14 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
         }
     }
 
-    if (accepted && m_gps->isRunning() && enabled) {
+    if (!m_automaticUpdateFirstStart && m_automaticUpdateEnabled && accepted)
+        m_ui->buildInformationBox(tr("Automatic location update enabled"));
+
+    if (accepted && m_gps->isRunning() && m_automaticUpdateEnabled) {
         if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
-            m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS / 60);
+            m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
         else
-            m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs / 60);
+            m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
 
         m_automaticUpdateIntervalTimer->start();
 
@@ -282,7 +290,9 @@ void SituareEngine::loginOk()
 
     m_ui->show();
     m_situareService->fetchLocations(); // request user locations
-    m_ui->requestAutomaticLocationUpdateSettings();
+
+    if (m_gps->isRunning())
+        m_ui->requestAutomaticLocationUpdateSettings();
 }
 
 void SituareEngine::loginProcessCancelled()
index b4a4d86..ba8b83d 100644 (file)
@@ -285,6 +285,7 @@ private:
     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
     QPointF m_lastUpdatedGPSPosition;       ///< Last updated GPS position
     bool m_userMoved;                       ///< Flag for user moving
+    bool m_automaticUpdateEnabled;
 };
 
 #endif // ENGINE_H
index 80819b6..9501944 100644 (file)
@@ -97,7 +97,7 @@ void FacebookAuthentication::start()
 
 bool FacebookAuthentication::updateCredentials(const QUrl &url)
 {
-    qWarning() << __PRETTY_FUNCTION__ << url.toString();
+    qDebug() << __PRETTY_FUNCTION__ << url.toString();
 
     bool found = false;
 
index 7177705..5762ca3 100644 (file)
@@ -77,14 +77,14 @@ void GPSPosition::setUpdateInterval(int interval)
 
 void GPSPosition::start()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_gpsPositionPrivate->start();
 }
 
 void GPSPosition::stop()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_gpsPositionPrivate->stop();
 }