Added confirmation dialog to automatic location update feature.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 8 Jun 2010 09:14:57 +0000 (12:14 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 8 Jun 2010 09:14:57 +0000 (12:14 +0300)
src/engine/engine.cpp
src/engine/engine.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/settingsdialog.cpp
src/ui/settingsdialog.h

index 534a4c9..486a917 100644 (file)
@@ -22,6 +22,7 @@
     USA.
  */
 
+#include <QMessageBox>
 
 #include "common.h"
 #include "facebookservice/facebookauthentication.h"
@@ -42,6 +43,7 @@ const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for
 SituareEngine::SituareEngine(QMainWindow *parent)
     : QObject(parent),
       m_autoCenteringEnabled(false),
+      m_automaticUpdateFirstStart(true),
       m_loggedIn(false),
       m_automaticUpdateIntervalTimer(0),
       m_lastUpdatedGPSPosition(QPointF()),
@@ -112,10 +114,11 @@ SituareEngine::~SituareEngine()
 
 void SituareEngine::automaticUpdateIntervalTimerTimeout()
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__;
 
     if (m_gps->isRunning() && m_userMoved) {
-        requestUpdateLocation();
+//        requestUpdateLocation();
+        qWarning() << __PRETTY_FUNCTION__ << "requestUpdateLocation()";
         m_userMoved = false;
     }
 }
@@ -167,16 +170,31 @@ void SituareEngine::enableGPS(bool enabled)
 
 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__ << enabled;
+
+    bool accepted = false;
+
+    if (m_automaticUpdateFirstStart && enabled) {
+        accepted = m_ui->showEnableAutomaticUpdateLocationDialog();
+        m_automaticUpdateFirstStart = false;
+        m_ui->automaticLocationUpdateEnabled(accepted);
+    }
+    else {
+        accepted = true;
+    }
+
+    qWarning() << __PRETTY_FUNCTION__ << accepted;
 
-    if (m_automaticUpdateIntervalTimer) {
+    if (accepted) {
+        if (m_automaticUpdateIntervalTimer) {
 
-        if (enabled && m_gps->isRunning()) {
-            m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
-            m_automaticUpdateIntervalTimer->start();
+            if (enabled && m_gps->isRunning()) {
+                m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
+                m_automaticUpdateIntervalTimer->start();
+            }
+            else
+                m_automaticUpdateIntervalTimer->stop();
         }
-        else
-            m_automaticUpdateIntervalTimer->stop();
     }
 }
 
index c568bc9..b4a4d86 100644 (file)
@@ -249,6 +249,13 @@ private slots:
  ******************************************************************************/
 signals:
     /**
+    * @brief Signals when automatic location update was enabled.
+    *
+    * @param enabled true if enabled, false otherwise
+    */
+    void automaticLocationUpdateEnabled(bool enabled);
+
+    /**
     * @brief Signals when new friends data is ready
     *
     * @param friendList List of User instances (friends)
@@ -266,9 +273,9 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    bool m_autoCenteringEnabled;  ///< Auto centering enabled
-    bool m_loggedIn;              ///< Login state
-
+    bool m_autoCenteringEnabled;        ///< Auto centering flag
+    bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
+    bool m_loggedIn;                    ///< Login state
     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
     GPSPosition *m_gps;                              ///< Instance of the gps position
     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
index 2ec3199..80dd084 100644 (file)
@@ -111,6 +111,11 @@ MainWindow::~MainWindow()
         delete m_webView;
 }
 
+void MainWindow::automaticLocationUpdateEnabled(bool enabled)
+{
+    m_settingsDialog->setAutomaticLocationUpdateSettings(enabled);
+}
+
 void MainWindow::buildFullScreenButton()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -631,6 +636,20 @@ void MainWindow::setViewPortSize(int width, int height)
     m_viewPortHeight = height;
 }
 
+bool MainWindow::showEnableAutomaticUpdateLocationDialog()
+{
+    QMessageBox msgBox(QMessageBox::Warning, tr("Automatic location update"),
+                       tr("Are you sure you want to enable automatic location update?"),
+                       QMessageBox::Ok | QMessageBox::Cancel, 0);
+    msgBox.button(QMessageBox::Ok)->setText(tr("Ok"));
+    int ret = msgBox.exec();
+
+    if (ret == QMessageBox::Ok)
+        return true;
+    else
+        return false;
+}
+
 void MainWindow::showMaemoInformationBox(const QString &message, bool modal)
 {
     qDebug() << __PRETTY_FUNCTION__;
index e4b78fe..2177b3e 100644 (file)
@@ -80,6 +80,13 @@ private:
  ******************************************************************************/
 public:
     /**
+    * @brief Sets automatic location update enabled from settings dialog.
+    *
+    * @param enabled true if enabled, false otherwise
+    */
+    void automaticLocationUpdateEnabled(bool enabled);
+
+    /**
     * @brief Clears cookie jar
     *
     */
@@ -116,6 +123,13 @@ public:
     void setMapViewScene(QGraphicsScene *scene);
 
     /**
+    * Shows dialog with enable automatic location update question.
+    *
+    * @return true if accepted, false otherwise
+    */
+    bool showEnableAutomaticUpdateLocationDialog();
+
+    /**
     * @brief Show Maemo information box with message.
     *
     * @param message Information message
index 4044814..9157e23 100644 (file)
@@ -30,6 +30,7 @@
 #include "common.h"
 #include "settingsdialog.h"
 
+const QString SETTINGS_AUTOMATIC_UPDATE_ENABLED = "SETTINGS_AUTOMATIC_UPDATE_ENABLED";
 const QString SETTINGS_AUTOMATIC_UPDATE_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
 const int LIST_MINUTES_STEP = 5;
 const int LIST_MINUTES_MAX = 60;
@@ -62,7 +63,8 @@ SettingsDialog::SettingsDialog(QWidget *parent)
     QStandardItemModel *updateIntervalListModel = new QStandardItemModel(0, 1, this);
     populateUpdateIntervalList(updateIntervalListModel);
     m_timePick->setModel(updateIntervalListModel);
-
+    m_automaticLocationUpdateIntervalButton->setValueText(
+            updateIntervalListModel->item(0, 0)->text());
     Q_UNUSED(cancelButton);
 #else
     m_automaticLocationUpdateInterval = new QTimeEdit();
@@ -106,28 +108,43 @@ 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());
 }
 
+void SettingsDialog::setAutomaticLocationUpdateSettings(bool checked)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_automaticLocationUpdate->setChecked(checked);
+}
+
 void SettingsDialog::enableSituareSettings(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     m_automaticLocationUpdate->setEnabled(enabled);
-    toggleAutomaticLocationUpdate(enabled);
 }
 
 void SettingsDialog::readSettings()
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__;
 
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
     QString automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, "")
                                       .toString();
+
+    m_automaticLocationUpdate->setChecked(automaticUpdateEnabled);
+
     if (!automaticUpdateInterval.isEmpty()) {
-        setTime(QTime::fromString(automaticUpdateInterval));
-        m_automaticLocationUpdateIntervalOldValue = time();
+        qWarning() << automaticUpdateInterval;
+        setTime(QTime::fromString(automaticUpdateInterval, "hh:mm:ss"));
+        qWarning() << time().toString("hh:mm:ss");
     }
+
+    if (automaticUpdateEnabled)
+        QTimer::singleShot(0, this, SLOT(saveValues()));
 }
 
 void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
index 5b853bb..d27eda1 100644 (file)
@@ -66,12 +66,16 @@ public:
 ******************************************************************************/
  public:
     /**
+    * @brief Sets automatic location update settings from settings dialog.
+    */
+    void setAutomaticLocationUpdateSettings(bool enabled);
+
+    /**
     * @brief Enables Situare related settings from settings dialog.
     *
     */
     void enableSituareSettings(bool enabled);
 
-
 private slots:
     /**
     * @brief Saves settings to file.
@@ -127,13 +131,13 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    QCheckBox *m_automaticLocationUpdate; ///< Pointer to CheckBox
+    QCheckBox *m_automaticLocationUpdate;           ///< Pointer to CheckBox
     bool m_automaticLocationUpdateOldValue;         ///< Automatic location update state
     QTime m_automaticLocationUpdateIntervalOldValue;///< Automatic location update interval value
 
 #ifdef Q_WS_MAEMO_5
-    QMaemo5ValueButton *m_automaticLocationUpdateIntervalButton;
-    QMaemo5ListPickSelector *m_timePick;
+    QMaemo5ValueButton *m_automaticLocationUpdateIntervalButton;    ///< Maemo 5 value button
+    QMaemo5ListPickSelector *m_timePick;                            ///< Maemo 5 time pick selector
 #else
     QTimeEdit *m_automaticLocationUpdateInterval;   ///< Pointer to QTimeEdit
 #endif