From: Jussi Laitinen Date: Fri, 28 May 2010 10:49:56 +0000 (+0300) Subject: Added auto updating methods to Engine. X-Git-Tag: v0.5^2~10 X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=370d147ee580ef19737050786dbc5d4466189f94;p=situare Added auto updating methods to Engine. --- diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index e87768a..0606c9c 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -29,6 +29,7 @@ #include "map/mapengine.h" #include "situareservice/situareservice.h" #include "ui/mainwindow.h" +#include #include "engine.h" @@ -38,7 +39,10 @@ const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED"; SituareEngine::SituareEngine(QMainWindow *parent) : QObject(parent), m_autoCenteringEnabled(false), - m_loggedIn(false) + m_loggedIn(false), + m_automaticUpdateIntervalTimer(0), + m_lastUpdatedGPSPosition(QPointF()), + m_userMoved(false) { qDebug() << __PRETTY_FUNCTION__; m_ui = new MainWindow; @@ -115,18 +119,18 @@ SituareEngine::~SituareEngine() settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled); } -void SituareEngine::automaticLocationUpdateIntervalSet(int updateIntervalMsecs) +void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs) { qDebug() << __PRETTY_FUNCTION__; if (m_automaticUpdateIntervalTimer) { - m_automaticUpdateIntervalTimer->stop(); - - if ((updateIntervalMsecs > 0) && m_gps->isRunning()) { + if (enabled && m_gps->isRunning()) { m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs); m_automaticUpdateIntervalTimer->start(); } + else + m_automaticUpdateIntervalTimer->stop(); } } @@ -134,8 +138,11 @@ void SituareEngine::automaticUpdateIntervalTimerTimeout() { qDebug() << __PRETTY_FUNCTION__; - if (m_gps->isRunning()); + if (m_gps->isRunning() && m_userMoved) { + qDebug() << __PRETTY_FUNCTION__ << "requestUpdateLocation()"; //requestUpdateLocation(); + m_userMoved = false; + } } void SituareEngine::changeAutoCenteringSetting(bool enabled) @@ -180,7 +187,7 @@ void SituareEngine::enableGPS(bool enabled) else { m_gps->stop(); enableAutoCentering(false); - automaticLocationUpdateIntervalSet(-1); + enableAutomaticLocationUpdate(false); } } @@ -205,6 +212,13 @@ void SituareEngine::invalidCredentials() m_facebookAuthenticator->start(); } +bool SituareEngine::isUserMoved() +{ + qDebug() << __PRETTY_FUNCTION__; + + return m_userMoved; +} + void SituareEngine::loginActionPressed() { qDebug() << __PRETTY_FUNCTION__; @@ -281,6 +295,23 @@ void SituareEngine::requestUpdateLocation(const QString &status, bool publish) m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish); } +void SituareEngine::saveGPSPosition(QPointF position) +{ + qDebug() << __PRETTY_FUNCTION__; + + qDebug() << __PRETTY_FUNCTION__ << m_lastUpdatedGPSPosition.x() << m_lastUpdatedGPSPosition.y(); + qDebug() << __PRETTY_FUNCTION__ << position.x() << position.y(); + qDebug() << __PRETTY_FUNCTION__ << "=" << fabs(m_lastUpdatedGPSPosition.x() - position.x()) << + fabs(m_lastUpdatedGPSPosition.y() - position.y()); + + if ((fabs(m_lastUpdatedGPSPosition.x() - position.x()) > 0.003) || + (fabs(m_lastUpdatedGPSPosition.y() - position.y()) > 0.001)) { + qDebug() << __PRETTY_FUNCTION__ << "m_userMoved = true"; + m_lastUpdatedGPSPosition = position; + m_userMoved = true; + } +} + void SituareEngine::signalsFromFacebookAuthenticator() { qDebug() << __PRETTY_FUNCTION__; @@ -310,6 +341,9 @@ void SituareEngine::signalsFromGPS() connect(m_gps, SIGNAL(error(QString)), m_ui, SLOT(gpsError(QString))); + + connect(m_gps, SIGNAL(position(QPointF,qreal)), + this, SLOT(saveGPSPosition(QPointF))); } void SituareEngine::signalsFromMainWindow() @@ -359,8 +393,8 @@ void SituareEngine::signalsFromMainWindow() connect(m_ui, SIGNAL(statusUpdate(QString,bool)), this, SLOT(requestUpdateLocation(QString,bool))); - connect(m_ui, SIGNAL(automaticLocationUpdateIntervalSet(int)), - this, SLOT(automaticLocationUpdateIntervalSet(int))); + connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)), + this, SLOT(enableAutomaticLocationUpdate(bool, int))); // signals from user info tab connect(m_ui, SIGNAL(refreshUserData()), diff --git a/src/engine/engine.h b/src/engine/engine.h index e21f369..cf087ca 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -28,6 +28,7 @@ #include #include +#include class QMainWindow; @@ -142,6 +143,13 @@ public slots: private: /** + * @brief Checks if user is moved enough for position auto update. + * + * @return true if moved engouh, false otherwise + */ + bool isUserMoved(); + + /** * @brief Connect signals coming from Facdebook authenticator */ void signalsFromFacebookAuthenticator(); @@ -173,8 +181,6 @@ private: private slots: - void automaticLocationUpdateIntervalSet(int updateIntervalMsecs); - void automaticUpdateIntervalTimerTimeout(); /** @@ -209,6 +215,22 @@ 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); + + /** + * @brief Enables automatic location update. + * + * @param enabled true if + */ + void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = -1); + /******************************************************************************* * SIGNALS ******************************************************************************/ @@ -240,8 +262,9 @@ private: MapEngine *m_mapEngine; ///< MapEngine SituareService *m_situareService; ///< Instance of the situare server communication service - QTimer *m_automaticUpdateIntervalTimer; - + QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer + QPointF m_lastUpdatedGPSPosition; ///< Last updated GPS position + bool m_userMoved; ///< Flag for user moving }; #endif // ENGINE_H diff --git a/src/gps/gpspositionprivate.cpp b/src/gps/gpspositionprivate.cpp index 4c43779..cbe87cd 100644 --- a/src/gps/gpspositionprivate.cpp +++ b/src/gps/gpspositionprivate.cpp @@ -146,11 +146,11 @@ qreal GPSPositionPrivate::accuracy(const QGeoPositionInfo &positionInfo) QDateTime timestamp; -#ifdef Q_WS_MAEMO_5 - timestamp = positionInfo.dateTime(); -#else +//#ifdef Q_WS_MAEMO_5 +// timestamp = positionInfo.dateTime(); +//#else timestamp = positionInfo.timestamp(); -#endif +//#endif if (!timestamp.isValid()) return GPS_ACCURACY_UNDEFINED; diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index d24646c..2657415 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -277,8 +277,6 @@ signals: */ void autoCenteringTriggered(bool enabled); - void automaticLocationUpdateIntervalSet(int updateIntervalMsecs); - /** * @brief Signal that indicates when user has cancelled login process * @@ -293,6 +291,14 @@ signals: void centerToSceneCoordinates(QPoint sceneCoordinate); /** + * @brief Signal for enabling automatic location update. + * + * @param enabled true if enabled, false otherwise + * @param updateIntervalMsecs update interval in milliseconds + */ + void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs); + + /** * @brief Signal for requesting username from settings * */ diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index 4e8befe..5cfa180 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -52,6 +52,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); QFormLayout *form = new QFormLayout(); + form->setRowWrapPolicy(QFormLayout::WrapAllRows); form->addWidget(m_automaticLocationUpdate); form->addRow("Update interval", m_automaticLocationUpdateInterval);