Implemented entry into power saving state when application is in background,
[situare] / src / engine / engine.cpp
index 289a578..1fe7989 100644 (file)
@@ -25,6 +25,9 @@
 #include <QMessageBox>
 #include <QNetworkReply>
 
+#ifdef Q_WS_MAEMO_5
+#include "application.h"
+#endif
 #include "common.h"
 #include "facebookservice/facebookauthentication.h"
 #include "gps/gpsposition.h"
@@ -44,9 +47,8 @@ const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value fo
 const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
 const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
 
-SituareEngine::SituareEngine(QMainWindow *parent)
-    : QObject(parent),
-      m_autoCenteringEnabled(false),
+SituareEngine::SituareEngine()
+    : m_autoCenteringEnabled(false),
       m_automaticUpdateFirstStart(true),
       m_automaticUpdateRequest(false),
       m_userMoved(false),
@@ -54,9 +56,18 @@ SituareEngine::SituareEngine(QMainWindow *parent)
       m_lastUpdatedGPSPosition(QPointF())
 {
     qDebug() << __PRETTY_FUNCTION__;
+
     m_ui = new MainWindow;
     m_ui->updateItemVisibility();
 
+#ifdef Q_WS_MAEMO_5
+    m_app = static_cast<Application *>(qApp);
+    m_app->registerWindow(m_ui->winId());
+
+    connect(m_app, SIGNAL(topmostChanged(bool)),
+            this, SLOT(enablePowerSave(bool)));
+#endif
+
     m_networkAccessManager = NetworkAccessManager::instance();
 
     // build MapEngine
@@ -112,7 +123,7 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     initializeGpsAndAutocentering();
 
     m_mce = new MCE(this);
-    connect(m_mce, SIGNAL(displayStateChanged(bool)), this, SLOT(displayStateChanged(bool)));
+    connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(enablePowerSave(bool)));
 }
 
 SituareEngine::~SituareEngine()
@@ -142,16 +153,6 @@ void SituareEngine::disableAutoCentering()
     m_ui->buildInformationBox(tr("Auto centering disabled"));
 }
 
-void SituareEngine::displayStateChanged(bool enabled)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_gps->enablePowerSave(!enabled);
-
-    if (m_autoCenteringEnabled)
-        enableAutoCentering(enabled);
-}
-
 void SituareEngine::enableAutoCentering(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -227,6 +228,16 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
     }
 }
 
+void SituareEngine::enablePowerSave(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_gps->enablePowerSave(enabled);
+
+    if(m_autoCenteringEnabled)
+        m_mapEngine->setAutoCentering(!enabled);
+}
+
 void SituareEngine::error(const int context, const int error)
 {
     qDebug() << __PRETTY_FUNCTION__;