Added power save method to GPS. power_save
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 21 Jun 2010 11:56:00 +0000 (14:56 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 21 Jun 2010 11:56:00 +0000 (14:56 +0300)
12 files changed:
src/engine/engine.cpp
src/engine/engine.h
src/gps/gpsposition.cpp
src/gps/gpsposition.h
src/gps/gpspositionprivate.cpp
src/gps/gpspositionprivate.h
src/gps/gpspositionprivateliblocation.cpp
src/gps/gpspositionprivateliblocation.h
src/gps/gpspositionprivatestub.cpp
src/gps/gpspositionprivatestub.h
src/mceprivate.cpp
src/src.pro

index 275dd11..fbb9887 100644 (file)
@@ -49,7 +49,6 @@ SituareEngine::SituareEngine(QMainWindow *parent)
       m_autoCenteringEnabled(false),
       m_automaticUpdateFirstStart(true),
       m_userMoved(false),
-      m_automaticUpdateScreenOff(false),
       m_automaticUpdateIntervalTimer(0),
       m_lastUpdatedGPSPosition(QPointF())
 {    
@@ -151,15 +150,12 @@ void SituareEngine::displayOn(bool on)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_displayOn = on;
-
-    if (m_autoCenteringEnabled)
-        enableAutoCentering(on);
+    m_gps->enablePowerSave(!on);
 }
 
 void SituareEngine::enableAutoCentering(bool enabled)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__ << enabled;
 
     m_ui->setAutoCenteringButtonEnabled(enabled);
     m_mapEngine->setAutoCentering(enabled);
@@ -439,8 +435,8 @@ void SituareEngine::saveGPSPosition(QPointF position)
         m_userMoved = true;
     }
 
-    if (m_automaticUpdateGPSRequest) {
-        m_
+    if (!m_mce->isDisplayOn()) {
+        m_gps->stop();
     }
 }
 
index 9007860..6bdacf3 100644 (file)
@@ -290,8 +290,6 @@ signals:
 private:
     bool m_autoCenteringEnabled;        ///< Auto centering flag
     bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
-    bool m_automaticUpdateScreenOff;    ///< Flag for automatic location update when screen is off
-    bool m_screenOn;                    ///< Flag for device screen on
     bool m_userMoved;                   ///< Flag for user moving
 
 
index 48dd60a..7185d32 100644 (file)
@@ -40,6 +40,13 @@ GPSPosition::GPSPosition(QObject *parent)
     m_gpsPositionPrivate = new GPSPositionPrivate(this);
 }
 
+void GPSPosition::enablePowerSave(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_gpsPositionPrivate->enablePowerSave(enabled);
+}
+
 bool GPSPosition::isInitialized()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -68,6 +75,13 @@ void GPSPosition::requestLastPosition()
     m_gpsPositionPrivate->requestLastPosition();
 }
 
+void GPSPosition::requestUpdate()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_gpsPositionPrivate->requestUpdate();
+}
+
 void GPSPosition::setMode(Mode mode, const QString &filePath)
 {
     qDebug() << __PRETTY_FUNCTION__;
index be69bf1..8b4126b 100644 (file)
@@ -57,6 +57,13 @@ public:
 ******************************************************************************/
 public:
     /**
+    * @brief Enables power save mode.
+    *
+    * Starts GPS for position update and then stops it.
+    */
+    void enablePowerSave(bool enabled);
+
+    /**
     * @brief Returns is GPS initialized.
     *
     * @return true if initialized, false otherwise
@@ -81,6 +88,13 @@ public:
     void requestLastPosition();
 
     /**
+    * @brief Requests update from GPS.
+    *
+    * Enables GPS if it is disabled
+    */
+    void requestUpdate();
+
+    /**
     * @brief Set GPS mode.
     *
     * Modes: default and simulation.
index 8184ea2..66a7bef 100644 (file)
@@ -42,6 +42,11 @@ GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     m_parent = static_cast<GPSPosition*>(parent);
 }
 
+void GPSPositionPrivate::enablePowerSave(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
 bool GPSPositionPrivate::isInitialized()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -131,6 +136,16 @@ void GPSPositionPrivate::requestLastPosition()
     }
 }
 
+void GPSPositionPrivate::requestUpdate()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (!isRunning())
+        start();
+
+    m_gpsSource->requestUpdate();
+}
+
 void GPSPositionPrivate::positionUpdated(const QGeoPositionInfo &positionInfo)
 {
     qDebug() << __PRETTY_FUNCTION__ << positionInfo;
index 63f6e73..3e578c1 100644 (file)
@@ -52,6 +52,13 @@ public:
 ******************************************************************************/
 public:
     /**
+    * @brief Enables power save mode.
+    *
+    * Starts GPS for position update and then stops it.
+    */
+    void enablePowerSave(bool enabled);
+
+    /**
     * @brief Returns is GPS initialized.
     *
     * @return true if initialized, false otherwise
@@ -76,6 +83,13 @@ public:
     void requestLastPosition();
 
     /**
+    * @brief Requests update from GPS.
+    *
+    * Enables GPS if it is disabled
+    */
+    void requestUpdate();
+
+    /**
     * @brief Set GPS mode.
     *
     * Modes: default and simulation.
index 4ce2acd..2da121d 100644 (file)
@@ -35,6 +35,7 @@ GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     : QObject(parent),
       m_liblocationWrapper(0),
       m_initialized(false),
+      m_powerSave(false),
       m_running(false),
       m_updateInterval(DEFAULT_UPDATE_INTERVAL)
 {
@@ -43,6 +44,22 @@ GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     m_parent = static_cast<GPSPosition*>(parent);
 }
 
+void GPSPositionPrivate::enablePowerSave(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (isRunning()) {
+        m_powerSave = enabled;
+        if (enabled)
+            m_liblocationWrapper->stopUpdates();
+        else
+            m_liblocationWrapper->startUpdates();
+    }
+    else {
+        m_powerSave = false;
+    }
+}
+
 bool GPSPositionPrivate::isInitialized()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -131,6 +148,14 @@ void GPSPositionPrivate::requestLastPosition()
     }
 }
 
+void GPSPositionPrivate::requestUpdate()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_powerSave)
+        m_liblocationWrapper->startUpdates();
+}
+
 void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -140,6 +165,9 @@ void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
         emit m_parent->position(QPointF(coordinate.longitude(), coordinate.latitude()),
                       accuracy(positionInfo));
     }
+
+    if (m_powerSave)
+        m_liblocationWrapper->stopUpdates();
 }
 
 void GPSPositionPrivate::locationError(const QString &errorMessage)
index 3192ff5..e67fc35 100644 (file)
@@ -49,6 +49,13 @@ public:
 ******************************************************************************/
 public:
     /**
+    * @brief Enables power save mode.
+    *
+    * Starts GPS for position update and then stops it.
+    */
+    void enablePowerSave(bool enabled);
+
+    /**
     * @brief Returns is GPS initialized.
     *
     * @return true if initialized, false otherwise
@@ -73,6 +80,13 @@ public:
     void requestLastPosition();
 
     /**
+    * @brief Requests update from GPS.
+    *
+    * Enables GPS if it is disabled
+    */
+    void requestUpdate();
+
+    /**
     * @brief Set GPS mode.
     *
     * Modes: default and simulation.
@@ -131,6 +145,7 @@ private:
     LiblocationWrapper *m_liblocationWrapper;    ///< Liblocation wrapper object
     GPSPosition *m_parent;                      ///< Parent object
     bool m_initialized;                         ///< GPS is initialized
+    bool m_powerSave;                           ///< Power save flag
     bool m_running;                             ///< GPS is running
     int m_updateInterval;                       ///< GPS update interval
 };
index 8f23493..18e2030 100644 (file)
@@ -33,6 +33,11 @@ GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     m_parent = static_cast<GPSPosition*>(parent);
 }
 
+void GPSPositionPrivate::enablePowerSave(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
 bool GPSPositionPrivate::isInitialized()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -85,3 +90,8 @@ void GPSPositionPrivate::requestLastPosition()
 {
     qDebug() << __PRETTY_FUNCTION__;
 }
+
+void GPSPositionPrivate::requestUpdate()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
index e697266..2a73fcc 100644 (file)
@@ -51,6 +51,13 @@ public:
 ******************************************************************************/
 public:
     /**
+    * @brief Enables power save mode.
+    *
+    * Starts GPS for position update and then stops it.
+    */
+    void enablePowerSave(bool enabled);
+
+    /**
     * @brief Returns is GPS initialized.
     *
     * RETURNS FALSE
@@ -77,6 +84,13 @@ public:
     void requestLastPosition();
 
     /**
+    * @brief Requests update from GPS.
+    *
+    * Enables GPS if it is disabled
+    */
+    void requestUpdate();
+
+    /**
     * @brief Set GPS update interval.
     *
     * DOES NOTHING.
index 3797878..4aba790 100644 (file)
@@ -63,9 +63,13 @@ void MCEPrivate::displayStateChanged(const QDBusMessage &message)
     QString content = message.arguments().at(DISPLAY_STATE_INDEX).toString();
 
     if (!content.isEmpty()) {
-        if (content == MCE_DISPLAY_ON_STRING)
+        if (content == MCE_DISPLAY_ON_STRING) {
+            m_displayOn = true;
             emit m_parent->displayOn(true);
-        else if (content == MCE_DISPLAY_OFF_STRING)
+        }
+        else if (content == MCE_DISPLAY_OFF_STRING) {
+            m_displayOn = false;
             emit m_parent->displayOn(false);
+        }
     }
 }
index aa90192..95fa479 100644 (file)
@@ -108,7 +108,7 @@ HEADERS += common.h \
 QT += network \
     webkit
 
-#DEFINES += QT_NO_DEBUG_OUTPUT
+DEFINES += QT_NO_DEBUG_OUTPUT
 
 simulator {
     SOURCES += network/networkhandlerprivatestub.cpp \