Modified SettingsDialog. Added running flag in gpspositionprivatestub.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 9 Jun 2010 07:35:55 +0000 (10:35 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 9 Jun 2010 07:35:55 +0000 (10:35 +0300)
src/engine/engine.cpp
src/gps/gpspositionprivatestub.cpp
src/gps/gpspositionprivatestub.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/settingsdialog.cpp

index 338a721..36fdeb1 100644 (file)
@@ -115,7 +115,7 @@ SituareEngine::~SituareEngine()
 
 void SituareEngine::automaticUpdateIntervalTimerTimeout()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (m_gps->isRunning() && m_userMoved) {
 //        requestUpdateLocation();
@@ -171,12 +171,14 @@ void SituareEngine::enableGPS(bool enabled)
 
 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
 {
-    qWarning() << __PRETTY_FUNCTION__ << enabled;
+    qDebug() << __PRETTY_FUNCTION__;
 
     bool accepted = false;
 
     if (m_automaticUpdateFirstStart && enabled) {
-        accepted = m_ui->showEnableAutomaticUpdateLocationDialog();
+        accepted = m_ui->showEnableAutomaticUpdateLocationDialog(
+                tr("Do you want to enable automatic location update with %1 min update interval?")
+                .arg(updateIntervalMsecs/1000/60));
         m_automaticUpdateFirstStart = false;
         m_ui->automaticLocationUpdateEnabled(accepted);
     }
@@ -184,20 +186,20 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
         accepted = true;
     }
 
-    qWarning() << __PRETTY_FUNCTION__ << accepted;
-
     if (accepted) {
-        if (m_automaticUpdateIntervalTimer) {
 
+        if (m_automaticUpdateIntervalTimer) {
             if (enabled && m_gps->isRunning()) {
-//                if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
-//                    m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
-//                else
+                if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
+                    m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS / 60);
+                else
                     m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs / 60);
+
                 m_automaticUpdateIntervalTimer->start();
             }
-            else
+            else {
                 m_automaticUpdateIntervalTimer->stop();
+            }
         }
     }
 }
index 1e55c4a..3933868 100644 (file)
@@ -25,7 +25,8 @@
 #include "gpspositionprivatestub.h"
 
 GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
-    : QObject(parent)
+    : QObject(parent),
+    m_isRunning(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 }
@@ -34,7 +35,7 @@ bool GPSPositionPrivate::isRunning()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return false;
+    return m_isRunning;
 }
 
 void GPSPositionPrivate::setUpdateInterval(int interval)
@@ -55,11 +56,15 @@ void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath
 void GPSPositionPrivate::start()
 {
     qDebug() << __PRETTY_FUNCTION__;
+
+    m_isRunning = true;
 }
 
 void GPSPositionPrivate::stop()
 {
     qDebug() << __PRETTY_FUNCTION__;
+
+    m_isRunning = false;
 }
 
 QPointF GPSPositionPrivate::lastPosition()
index 97aff93..43c7f6f 100644 (file)
@@ -98,6 +98,9 @@ public:
     * DOES NOTHING.
     */
     void stop();
+
+private:
+    bool m_isRunning;   ///< GPS running flag
 };
 
 #endif // GPSPOSITIONMOCKUP_H
index c45dd0c..05173d7 100644 (file)
@@ -756,10 +756,9 @@ void MainWindow::setViewPortSize(int width, int height)
     m_viewPortHeight = height;
 }
 
-bool MainWindow::showEnableAutomaticUpdateLocationDialog()
+bool MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
 {
-    QMessageBox msgBox(QMessageBox::Question, tr("Automatic location update"),
-                       tr("Are you sure you want to enable automatic location update?"),
+    QMessageBox msgBox(QMessageBox::Question, tr("Automatic location update"), text,
                        QMessageBox::Ok | QMessageBox::Cancel, 0);
     msgBox.button(QMessageBox::Ok)->setText(tr("Ok"));
     qWarning() << __PRETTY_FUNCTION__;
index ba7a8bd..dde8be0 100644 (file)
@@ -140,9 +140,10 @@ public:
     /**
     * Shows dialog with enable automatic location update question.
     *
+    * @param text text to show in dialog
     * @return true if accepted, false otherwise
     */
-    bool showEnableAutomaticUpdateLocationDialog();
+    bool showEnableAutomaticUpdateLocationDialog(const QString &text);
 
     /**
     * @brief Gets the username from member variable for saving purposes
index 9b83eda..46152dd 100644 (file)
@@ -100,7 +100,6 @@ SettingsDialog::SettingsDialog(QWidget *parent)
 
     scrollArea->show();
 
-    setTime(QTime(0, LIST_MINUTES_STEP));
     readSettings();
 }
 
@@ -109,13 +108,14 @@ SettingsDialog::~SettingsDialog()
     qDebug() << __PRETTY_FUNCTION__;
 
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdate->isChecked());
-    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, time());
+    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdateOldValue);
+    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL,
+                      m_automaticLocationUpdateIntervalOldValue);
 }
 
 void SettingsDialog::setAutomaticLocationUpdateSettings(bool checked)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_automaticLocationUpdate->setChecked(checked);
     m_automaticLocationUpdateOldValue = checked;
@@ -126,11 +126,16 @@ void SettingsDialog::enableSituareSettings(bool enabled)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_automaticLocationUpdate->setEnabled(enabled);
+
+    if (enabled)
+        toggleAutomaticLocationUpdate(m_automaticLocationUpdate->isChecked());
+    else
+        toggleAutomaticLocationUpdate(false);
 }
 
 void SettingsDialog::readSettings()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
     bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
@@ -141,15 +146,19 @@ void SettingsDialog::readSettings()
 
     if (!automaticUpdateInterval.isEmpty())
         setTime(QTime::fromString(automaticUpdateInterval, "hh:mm:ss"));
+    else
+        setTime(QTime(0, LIST_MINUTES_STEP));
+
+    m_automaticLocationUpdateOldValue = automaticUpdateEnabled;
+    m_automaticLocationUpdateIntervalOldValue = time();
 }
 
 void SettingsDialog::emitAutomaticLocationUpdateSettings()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (m_automaticLocationUpdate->isChecked()) {
         QTime emptyTime = QTime();
-        qDebug() << emptyTime.msecsTo(time());
         emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
     }
     else {
@@ -195,6 +204,12 @@ void SettingsDialog::setTime(const QTime &time)
 
 #ifdef Q_WS_MAEMO_5
         int index = time.minute()/LIST_MINUTES_STEP - 1;
+
+        if (index < 0)
+            index = 0;
+        if (index >= m_timePick->model()->rowCount())
+            index = m_timePick->model()->rowCount() - 1;
+
         m_timePick->setCurrentIndex(index);
 #else
         m_automaticLocationUpdateInterval->setTime(time);
@@ -213,6 +228,11 @@ QTime SettingsDialog::time()
     time = m_automaticLocationUpdateInterval->time();
 #endif
 
+    if (time < QTime(0, LIST_MINUTES_STEP))
+        time = QTime(0, LIST_MINUTES_STEP);
+    if (time > QTime(LIST_HOURS_MAX, 0))
+        time = QTime(LIST_HOURS_MAX, 0);
+
     return time;
 }