Modified automatic location update method.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 22 Jun 2010 10:44:41 +0000 (13:44 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 22 Jun 2010 10:44:41 +0000 (13:44 +0300)
src/engine/engine.cpp
src/engine/engine.h
src/gps/gpspositionprivateliblocation.cpp
src/gps/gpspositionprivateliblocation.h
src/gps/liblocationwrapper.cpp
src/mce.cpp [deleted file]
src/mce.h [deleted file]
src/mceprivate.cpp [deleted file]
src/mceprivate.h [deleted file]
src/src.pro

index fbb9887..65ed9a2 100644 (file)
@@ -48,6 +48,7 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     : QObject(parent),
       m_autoCenteringEnabled(false),
       m_automaticUpdateFirstStart(true),
+      m_automaticUpdateRequest(false),
       m_userMoved(false),
       m_automaticUpdateIntervalTimer(0),
       m_lastUpdatedGPSPosition(QPointF())
@@ -121,13 +122,8 @@ void SituareEngine::automaticUpdateIntervalTimerTimeout()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_gps->isRunning() && m_userMoved) {
-        requestUpdateLocation();
-        m_userMoved = false;
-    }
-
-    if (!m_mce->isDisplayOn())
-        m_gps->requestUpdate();
+    m_gps->requestUpdate();
+    m_automaticUpdateRequest = true;
 }
 
 void SituareEngine::changeAutoCenteringSetting(bool enabled)
@@ -151,11 +147,14 @@ void SituareEngine::displayOn(bool on)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_gps->enablePowerSave(!on);
+
+    if (m_autoCenteringEnabled)
+        enableAutoCentering(on);
 }
 
 void SituareEngine::enableAutoCentering(bool enabled)
 {
-    qWarning() << __PRETTY_FUNCTION__ << enabled;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_ui->setAutoCenteringButtonEnabled(enabled);
     m_mapEngine->setAutoCentering(enabled);
@@ -214,9 +213,15 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
             else
                 m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
 
+            connect(m_gps, SIGNAL(position(QPointF,qreal)),
+                    this, SLOT(saveGPSPosition(QPointF)));
+
             m_automaticUpdateIntervalTimer->start();
 
         } else {
+            disconnect(m_gps, SIGNAL(position(QPointF,qreal)),
+                    this, SLOT(saveGPSPosition(QPointF)));
+
             m_automaticUpdateIntervalTimer->stop();
         }
     }
@@ -336,13 +341,6 @@ void SituareEngine::initializeGpsAndAutocentering()
     }
 }
 
-bool SituareEngine::isUserMoved()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_userMoved;
-}
-
 void SituareEngine::loginActionPressed()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -435,8 +433,10 @@ void SituareEngine::saveGPSPosition(QPointF position)
         m_userMoved = true;
     }
 
-    if (!m_mce->isDisplayOn()) {
-        m_gps->stop();
+    if (m_automaticUpdateRequest && m_userMoved) {
+        requestUpdateLocation(tr("Automatic location update"));
+        m_automaticUpdateRequest = false;
+        m_userMoved = false;
     }
 }
 
@@ -489,9 +489,6 @@ void SituareEngine::signalsFromGPS()
 
     connect(m_gps, SIGNAL(error(int)),
             this, SLOT(error(int)));
-
-    connect(m_gps, SIGNAL(position(QPointF,qreal)),
-            this, SLOT(saveGPSPosition(QPointF)));
 }
 
 void SituareEngine::signalsFromMainWindow()
index 6bdacf3..19d8a7b 100644 (file)
@@ -142,13 +142,6 @@ public slots:
 
 private:
     /**
-    * @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.
     */
@@ -290,7 +283,8 @@ signals:
 private:
     bool m_autoCenteringEnabled;        ///< Auto centering flag
     bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
-    bool m_userMoved;                   ///< Flag for user moving
+    bool m_automaticUpdateRequest;      ///< Flag for automatic update request
+    bool m_userMoved;                   ///< Flag for user move
 
 
     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
index 2da121d..3345ee7 100644 (file)
@@ -31,6 +31,8 @@
 #include "gpspositionprivateliblocation.h"
 #include "liblocationwrapper.h"
 
+const int POWER_SAVE_START_DELAY_MS = 1000*10;
+
 GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     : QObject(parent),
       m_liblocationWrapper(0),
@@ -42,6 +44,20 @@ GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_parent = static_cast<GPSPosition*>(parent);
+
+    m_delayedPowerSaveTimer = new QTimer(this);
+    m_delayedPowerSaveTimer->setInterval(POWER_SAVE_START_DELAY_MS);
+    connect(m_delayedPowerSaveTimer, SIGNAL(timeout()),
+            this, SLOT(delayedPowerSaveStart()));
+}
+
+void GPSPositionPrivate::delayedPowerSaveStart()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_powerSave = true;
+    m_delayedPowerSaveTimer->stop();
+    m_liblocationWrapper->stopUpdates();
 }
 
 void GPSPositionPrivate::enablePowerSave(bool enabled)
@@ -49,11 +65,13 @@ void GPSPositionPrivate::enablePowerSave(bool enabled)
     qDebug() << __PRETTY_FUNCTION__;
 
     if (isRunning()) {
-        m_powerSave = enabled;
-        if (enabled)
-            m_liblocationWrapper->stopUpdates();
-        else
+        if (enabled) {
+            m_delayedPowerSaveTimer->start();
+        } else {
+            m_powerSave = false;
+            m_delayedPowerSaveTimer->stop();
             m_liblocationWrapper->startUpdates();
+        }
     }
     else {
         m_powerSave = false;
@@ -152,8 +170,13 @@ void GPSPositionPrivate::requestUpdate()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_powerSave)
+    if (m_powerSave) {
         m_liblocationWrapper->startUpdates();
+        qWarning() << __PRETTY_FUNCTION__ << "liblocation:start()";
+    }
+    else {
+        requestLastPosition();
+    }
 }
 
 void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
@@ -166,8 +189,10 @@ void GPSPositionPrivate::positionUpdated(const GeoPositionInfo &positionInfo)
                       accuracy(positionInfo));
     }
 
-    if (m_powerSave)
+    if (m_powerSave) {
         m_liblocationWrapper->stopUpdates();
+        qWarning() << __PRETTY_FUNCTION__ << "liblocation:stop()";
+    }
 }
 
 void GPSPositionPrivate::locationError(const QString &errorMessage)
index e67fc35..6560370 100644 (file)
@@ -27,6 +27,7 @@
 #include "gpsposition.h"
 #include "geopositioninfo.h"
 
+class QTimer;
 class LiblocationWrapper;
 
 /**
@@ -123,6 +124,7 @@ private:
     qreal accuracy(const GeoPositionInfo &positionInfo);
 
 private slots:
+    void delayedPowerSaveStart();
 
     /**
     * @brief Slot for received position update.
@@ -148,6 +150,7 @@ private:
     bool m_powerSave;                           ///< Power save flag
     bool m_running;                             ///< GPS is running
     int m_updateInterval;                       ///< GPS update interval
+    QTimer *m_delayedPowerSaveTimer;            ///< Delayed power save timer
 };
 
 const int DEFAULT_UPDATE_INTERVAL = 5000;       ///< Default update interval
index 2a80e08..d73b928 100644 (file)
@@ -69,7 +69,7 @@ void LiblocationWrapper::changed(LocationGPSDevice *device, gpointer data)
     LiblocationWrapper *wrapper;
     wrapper = (LiblocationWrapper*)data;
 
-    if (device) {
+    if (device && wrapper->isRunning()) {
         if (device->fix) {
 
             if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
diff --git a/src/mce.cpp b/src/mce.cpp
deleted file mode 100644 (file)
index 54b39eb..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Jussi Laitinen - jussi.laitinen@ixonos.com
-
-   Situare is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as published by the Free Software Foundation.
-
-   Situare is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with Situare; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
-   USA.
-*/
-
-#include <QDebug>
-
-#include "mce.h"
-
-#if defined(Q_WS_MAEMO_5) & defined(ARMEL)
-#include "mceprivate.h"
-#else
-#include "mceprivatestub.h"
-#endif
-
-MCE::MCE(QObject *parent)
-    : QObject(parent)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_mcePrivate = new MCEPrivate(this);
-}
-
-bool MCE::isDisplayOn()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_mcePrivate->isDisplayOn();
-}
diff --git a/src/mce.h b/src/mce.h
deleted file mode 100644 (file)
index 218fe53..0000000
--- a/src/mce.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Jussi Laitinen - jussi.laitinen@ixonos.com
-
-   Situare is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as published by the Free Software Foundation.
-
-   Situare is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with Situare; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
-   USA.
-*/
-
-#ifndef MCE_H
-#define MCE_H
-
-#include <QObject>
-
-class MCEPrivate;
-
-class MCE : public QObject
-{
-    Q_OBJECT
-
-public:
-    friend class MCEPrivate;
-
-    MCE(QObject *parent = 0);
-
-public:
-    bool isDisplayOn();
-
-signals:
-    void displayOn(bool on);
-
-private:
-    MCEPrivate *m_mcePrivate;
-};
-
-#endif // MCE_H
diff --git a/src/mceprivate.cpp b/src/mceprivate.cpp
deleted file mode 100644 (file)
index 4aba790..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Jussi Laitinen - jussi.laitinen@ixonos.com
-
-   Situare is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as published by the Free Software Foundation.
-
-   Situare is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with Situare; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
-   USA.
-*/
-
-#include <QString>
-#include <QDebug>
-
-#include <mce/dbus-names.h>
-#include <mce/mode-names.h>
-
-#include "mce.h"
-#include "mceprivate.h"
-
-const int DISPLAY_STATE_INDEX = 0;
-
-static QDBusConnection dBusConnection = QDBusConnection::systemBus();
-
-MCEPrivate::MCEPrivate(QObject *parent)
-    : QObject(parent),
-      m_displayOn(true)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_parent = static_cast<MCE*>(parent);
-
-    m_dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH,
-                                       MCE_REQUEST_IF, dBusConnection, this);
-
-    dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
-                           MCE_DISPLAY_SIG, this, SLOT(displayStateChanged(const QDBusMessage &)));
-
-    m_dBusInterface->call(MCE_DISPLAY_STATUS_GET);
-}
-
-bool MCEPrivate::isDisplayOn()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_displayOn;
-}
-
-void MCEPrivate::displayStateChanged(const QDBusMessage &message)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QString content = message.arguments().at(DISPLAY_STATE_INDEX).toString();
-
-    if (!content.isEmpty()) {
-        if (content == MCE_DISPLAY_ON_STRING) {
-            m_displayOn = true;
-            emit m_parent->displayOn(true);
-        }
-        else if (content == MCE_DISPLAY_OFF_STRING) {
-            m_displayOn = false;
-            emit m_parent->displayOn(false);
-        }
-    }
-}
diff --git a/src/mceprivate.h b/src/mceprivate.h
deleted file mode 100644 (file)
index c4a3abb..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Jussi Laitinen - jussi.laitinen@ixonos.com
-
-   Situare is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as published by the Free Software Foundation.
-
-   Situare is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with Situare; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
-   USA.
-*/
-
-#ifndef MCEPRIVATE_H
-#define MCEPRIVATE_H
-
-#include <QtDBus/QDBusInterface>
-#include <QtDBus/QDBusMessage>
-
-class MCE;
-
-class MCEPrivate : public QObject
-{
-    Q_OBJECT
-
-public:
-    MCEPrivate(QObject *parent);
-
-public:
-    bool isDisplayOn();
-
-private slots:
-    void displayStateChanged(const QDBusMessage &message);
-
-private:
-    QDBusInterface *m_dBusInterface;  ///< D-Bus interface
-    MCE *m_parent;                    ///< Parent object
-    bool m_displayOn;                 ///< Flag for display on/off
-};
-
-#endif // MCEPRIVATE_H
index 95fa479..2af0307 100644 (file)
@@ -53,7 +53,7 @@ SOURCES += main.cpp \
     ui/zoombuttonpanel.cpp \
     user/user.cpp \
     ui/fullscreenbutton.cpp \
-    mce.cpp
+    engine/mce.cpp
 HEADERS += common.h \
     engine/engine.h \
     facebookservice/facebookauthentication.h \
@@ -104,7 +104,7 @@ HEADERS += common.h \
     ui/zoombuttonpanel.h \
     user/user.h \
     ui/fullscreenbutton.h \
-    mce.h
+    engine/mce.h
 QT += network \
     webkit
 
@@ -123,9 +123,9 @@ simulator {
         DEFINES += ARMEL
         INCLUDEPATH += /usr/include/glib-2.0 /usr/lib/glib-2.0/include
         SOURCES += network/networkhandlerprivate.cpp \
-                   mceprivate.cpp
+                   engine/mceprivate.cpp
         HEADERS += network/networkhandlerprivate.h \
-                   mceprivate.h
+                   engine/mceprivate.h
         QT += dbus
         CONFIG += icd2 qdbus
         SOURCES += gps/gpspositionprivateliblocation.cpp \
@@ -142,10 +142,10 @@ simulator {
     } else {
         SOURCES += gps/gpspositionprivatestub.cpp \
                    network/networkhandlerprivatestub.cpp \
-                   mceprivatestub.cpp
+                   engine/mceprivatestub.cpp
         HEADERS += gps/gpspositionprivatestub.h \
                    network/networkhandlerprivatestub.h \
-                   mceprivatestub.h
+                   engine/mceprivatestub.h
     }
 
     QT += maemo5