Added automatic location update timer to Engine. Modified settings in
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 25 May 2010 12:58:24 +0000 (15:58 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 25 May 2010 12:58:24 +0000 (15:58 +0300)
settingsdialog.

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 759a3f0..3646aac 100644 (file)
@@ -97,6 +97,10 @@ SituareEngine::SituareEngine(QMainWindow *parent)
         m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
 
     m_facebookAuthenticator->start();
+
+    m_automaticUpdateIntervalTimer = new QTimer(this);
+    connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
+            this, SLOT(automaticUpdateIntervalTimerTimeout()));
 }
 
 SituareEngine::~SituareEngine()
@@ -111,6 +115,29 @@ SituareEngine::~SituareEngine()
     settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
 }
 
+void SituareEngine::automaticLocationUpdateIntervalSet(int updateIntervalMsecs)
+{
+    qDebug() << __PRETTY_FUNCTION__ <<;
+
+    if (m_automaticUpdateIntervalTimer) {
+
+        m_automaticUpdateIntervalTimer->stop();
+
+        if ((updateIntervalMsecs > 0) && m_gps->isRunning()) {
+            m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
+            m_automaticUpdateIntervalTimer->start();
+        }
+    }
+}
+
+void SituareEngine::automaticUpdateIntervalTimerTimeout()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_gps->isRunning());
+        //requestUpdateLocation();
+}
+
 void SituareEngine::changeAutoCenteringSetting(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -153,6 +180,7 @@ void SituareEngine::enableGPS(bool enabled)
     else {
         m_gps->stop();
         enableAutoCentering(false);
+        automaticLocationUpdateIntervalSet(-1);
     }
 }
 
@@ -331,6 +359,9 @@ 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)));
+
     // signals from user info tab
     connect(m_ui, SIGNAL(refreshUserData()),
             this, SLOT(refreshUserData()));
index d171810..e21f369 100644 (file)
@@ -27,6 +27,7 @@
 #define ENGINE_H
 
 #include <QObject>
+#include <QTime>
 
 class QMainWindow;
 
@@ -38,6 +39,8 @@ class MapEngine;
 class SituareService;
 class User;
 
+class QTimer;
+
 /**
 * @brief Engine class for Situare Application
 *
@@ -115,7 +118,7 @@ public slots:
     * @param status Status message
     * @param publish Publish on Facebook
     */
-    void requestUpdateLocation(const QString &status, bool publish);
+    void requestUpdateLocation(const QString &status = QString(), bool publish = false);
 
     /**
     * @brief Slot to refresh user data
@@ -169,6 +172,11 @@ private:
     void signalsFromSituareService();
 
 private slots:
+
+    void automaticLocationUpdateIntervalSet(int updateIntervalMsecs);
+
+    void automaticUpdateIntervalTimerTimeout();
+
     /**
       * @brief Set auto centering feature enabled / disabled
       */
@@ -232,6 +240,8 @@ private:
     MapEngine *m_mapEngine;                          ///< MapEngine
     SituareService *m_situareService;  ///< Instance of the situare server communication service
 
+    QTimer *m_automaticUpdateIntervalTimer;
+
 };
 
 #endif // ENGINE_H
index 565af75..3577953 100644 (file)
@@ -73,6 +73,11 @@ MainWindow::MainWindow(QWidget *parent)
     buildFriendListPanel();
     buildUserInfoPanel();
 
+    m_settingsDialog = new SettingsDialog(this);
+    m_settingsDialog->hide();
+    connect(m_settingsDialog, SIGNAL(automaticLocationUpdateIntervalSet(int)),
+            this, SIGNAL(automaticLocationUpdateIntervalSet(int)));
+
     createMenus();
     setWindowTitle(tr("Situare"));
 
@@ -461,11 +466,9 @@ void MainWindow::openSettingsDialog()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    SettingsDialog *dialog = new SettingsDialog(this);
-    if(!m_loggedIn) {
-        dialog->disableSituareSettings();
-    }
-    dialog->show();
+    m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
+
+    m_settingsDialog->show();
 }
 
 void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
index d34d0ad..d24646c 100644 (file)
@@ -42,6 +42,7 @@ class SituareService;
 class User;
 class UserInfoPanel;
 class ZoomButtonPanel;
+class SettingsDialog;
 
 /**
 * @brief Main Window Class
@@ -276,6 +277,8 @@ signals:
     */
     void autoCenteringTriggered(bool enabled);
 
+    void automaticLocationUpdateIntervalSet(int updateIntervalMsecs);
+
     /**
     * @brief Signal that indicates when user has cancelled login process
     *
@@ -450,6 +453,8 @@ private:
     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
+
+    SettingsDialog *m_settingsDialog;       ///< Settings dialog
 };
 
 #endif // MAINWINDOW_H
index 3590523..4e8befe 100644 (file)
 
 #include <QtGui>
 #include <QDebug>
+#include <QTime>
 #include "common.h"
 #include "settingsdialog.h"
 
-const QString AUTOMATIC_LOCATION_UPDATE("Automatic_location_update");
-
 SettingsDialog::SettingsDialog(QWidget *parent)
     : QDialog(parent)
 {
@@ -35,21 +34,26 @@ SettingsDialog::SettingsDialog(QWidget *parent)
     QScrollArea *scrollArea = new QScrollArea(this);
     QGridLayout *gridLayout = new QGridLayout(this);
     QGroupBox *groupBox = new QGroupBox(scrollArea);
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
 
     m_automaticLocationUpdate = new QCheckBox(tr("Use automatic location update"));
-    m_automaticLocationUpdate->setChecked(settings.value(AUTOMATIC_LOCATION_UPDATE).toBool());
+
+    m_automaticLocationUpdateInterval = new QTimeEdit();
+    m_automaticLocationUpdateInterval->setTimeRange(QTime(0, 0, 5), QTime(1, 0));
+    m_automaticLocationUpdateInterval->setDisplayFormat("mm:ss");
+    m_automaticLocationUpdateInterval->setDisabled(true);
 
     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
     QPushButton *saveButton = buttonBox->addButton(QDialogButtonBox::Save);
     QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
+
+    connect(m_automaticLocationUpdate, SIGNAL(toggled(bool)),
+            this, SLOT(toggleAutomaticLocationUpdate(bool)));
     connect(saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
 
-    connect(this, SIGNAL(finished(int)), this, SLOT(dialogFinished(int)));
-
     QFormLayout *form = new QFormLayout();
     form->addWidget(m_automaticLocationUpdate);
+    form->addRow("Update interval", m_automaticLocationUpdateInterval);
 
     groupBox->setLayout(form);
     scrollArea->setWidget(groupBox);
@@ -61,30 +65,30 @@ SettingsDialog::SettingsDialog(QWidget *parent)
     scrollArea->show();
 }
 
-SettingsDialog::~SettingsDialog()
+void SettingsDialog::saveValues()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    delete m_automaticLocationUpdate;
-}
 
-void SettingsDialog::dialogFinished(int /* reason */)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-    deleteLater();
+    if (m_automaticLocationUpdate->isChecked()) {
+        QTime time = QTime();
+        emit automaticLocationUpdateIntervalSet(time.msecsTo(
+                m_automaticLocationUpdateInterval->time()));
+    }
+    else {
+        emit automaticLocationUpdateIntervalSet(-1);
+    }
+    accept();
 }
 
-void SettingsDialog::saveValues()
+void SettingsDialog::enableSituareSettings(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    settings.setValue(AUTOMATIC_LOCATION_UPDATE, m_automaticLocationUpdate->isChecked());
-    accept();
+    m_automaticLocationUpdate->setEnabled(enabled);
 }
 
-void SettingsDialog::disableSituareSettings()
+void SettingsDialog::toggleAutomaticLocationUpdate(bool value)
 {
     qDebug() << __PRETTY_FUNCTION__;
-
-    m_automaticLocationUpdate->setDisabled(true);
+    m_automaticLocationUpdateInterval->setEnabled(value);
 }
index 1224129..60745bb 100644 (file)
@@ -25,6 +25,7 @@
 #include <QDialog>
 
 class QCheckBox;
+class QTimeEdit;
 
 /**
 * @brief Settings Dialog NOTE: dialog deletes itself after saving or closing settings
@@ -44,37 +45,31 @@ public:
     SettingsDialog(QWidget *parent = 0);
 
     /**
-    * @brief Destructor
-    */
-    ~SettingsDialog();
-
-    /**
     * @brief Disables Situare related settings from settings dialog
     *
     */
-    void disableSituareSettings();
+    void enableSituareSettings(bool enabled);
 
 /*******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
 private slots:
     /**
-    * @brief is called when dialog is closed
-    *
-    * @param reason why dialog was closed
-    */
-    void dialogFinished(int reason);
-
-    /**
     * @brief Saves settings to file
     */
     void saveValues();
 
+    void toggleAutomaticLocationUpdate(bool value);
+
+signals:
+    void automaticLocationUpdateIntervalSet(int updateIntervalMsecs);
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 private:
     QCheckBox *m_automaticLocationUpdate; ///< Pointer to CheckBox
+    QTimeEdit *m_automaticLocationUpdateInterval;   ///< Pointer to QTimeEdit
 };
 
 #endif // SETTINGSDIALOG_H