Merge branch 'master' of https://vcs.maemo.org/git/situare
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 9 Jun 2010 12:20:24 +0000 (15:20 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 9 Jun 2010 12:20:24 +0000 (15:20 +0300)
Conflicts:
doc/testing/functionality-tests.doc

1  2 
src/common.h
src/engine/engine.cpp
src/facebookservice/facebookauthentication.cpp
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/settingsdialog.cpp
src/ui/settingsdialog.h

diff --cc src/common.h
@@@ -33,6 -33,6 +33,8 @@@ const QString FILE_NAME = "Situare"
  // QSettings common values
  const QString COOKIES = "cookies";
  const QString EMPTY = "";
++const QString SETTINGS_AUTOMATIC_UPDATE_ENABLED = "SETTINGS_AUTOMATIC_UPDATE_ENABLED";
++const QString SETTINGS_AUTOMATIC_UPDATE_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
  
  const QColor COLOR_GRAY = QColor(152, 152, 152);                           ///< Gray color
  const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal);    ///< Normal font
@@@ -176,36 -169,14 +176,32 @@@ void SituareEngine::enableAutomaticLoca
  {
      qDebug() << __PRETTY_FUNCTION__;
  
 -    if (m_automaticUpdateIntervalTimer) {
 +    bool accepted = true;
 +
 +    m_automaticUpdateEnabled = enabled;
 +
++    //Show automatic update confirmation dialog
 +    if (m_automaticUpdateFirstStart && m_gps->isRunning() && m_automaticUpdateEnabled) {
-         accepted = m_ui->showEnableAutomaticUpdateLocationDialog(
++        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);
-         if (accepted && !m_gps->isRunning()) {
-             enableGPS(true);
-             m_ui->buildInformationBox(tr("GPS enabled"));
-         }
 +    }
++    else {
++        if (!m_automaticUpdateFirstStart && m_automaticUpdateEnabled && accepted)
++            m_ui->buildInformationBox(tr("Automatic location update enabled"));
 +
-     if (!m_automaticUpdateFirstStart && m_automaticUpdateEnabled && accepted)
-         m_ui->buildInformationBox(tr("Automatic location update enabled"));
-     if (accepted && m_gps->isRunning() && m_automaticUpdateEnabled) {
-         if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
-             m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
-         else
-             m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
++        if (accepted && m_gps->isRunning() && m_automaticUpdateEnabled) {
++            if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
++                m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
++            else
++                m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
  
-         m_automaticUpdateIntervalTimer->start();
 -        if (enabled && m_gps->isRunning()) {
 -            m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
+             m_automaticUpdateIntervalTimer->start();
 -        }
 -        else
 +
-     } else {
-         m_automaticUpdateIntervalTimer->stop();
++        } else {
+             m_automaticUpdateIntervalTimer->stop();
++        }
      }
  }
  
@@@ -283,7 -254,7 +279,7 @@@ void SituareEngine::loginActionPressed(
  
  void SituareEngine::loginOk()
  {
--    qDebug() << __PRETTY_FUNCTION__;
++    qWarning() << __PRETTY_FUNCTION__;
  
      m_loggedIn = true;
      m_ui->loggedIn(m_loggedIn);
@@@ -51,8 -51,8 +51,11 @@@ void FacebookAuthentication::clearAccou
      m_loginCredentials.clearCredentials();
      QSettings settings(DIRECTORY_NAME, FILE_NAME);
  
--    if(!keepUsername)
++    if(!keepUsername) {
          settings.remove(USERNAME);
++        settings.remove(SETTINGS_AUTOMATIC_UPDATE_ENABLED);
++        settings.remove(SETTINGS_AUTOMATIC_UPDATE_INTERVAL);
++    }
  
      settings.remove(COOKIES);
  }
@@@ -119,11 -123,6 +123,20 @@@ MainWindow::~MainWindow(
      m_error_queue.clear();
  }
  
- void MainWindow::automaticLocationUpdateEnabled(bool enabled)
++void MainWindow::automaticUpdateDialogFinished(int result)
 +{
-     m_settingsDialog->setAutomaticLocationUpdateSettings(enabled);
++    qDebug() << __PRETTY_FUNCTION__;
++
++    if (result == QMessageBox::Yes) {
++        m_settingsDialog->setAutomaticLocationUpdateSettings(true);
++        m_settingsDialog->emitAutomaticLocationUpdateSettings();
++    }
++    else {
++        m_settingsDialog->setAutomaticLocationUpdateSettings(false);
++        m_settingsDialog->emitAutomaticLocationUpdateSettings();
++    }
 +}
 +
  void MainWindow::buildFullScreenButton()
  {
      qDebug() << __PRETTY_FUNCTION__;
@@@ -652,6 -672,6 +686,7 @@@ void MainWindow::openSettingsDialog(
      qDebug() << __PRETTY_FUNCTION__;
  
      m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
++    m_settingsDialog->readSettings();
      m_settingsDialog->show();
  }
  
@@@ -752,22 -765,10 +787,21 @@@ void MainWindow::setViewPortSize(const 
  {
      qDebug() << __PRETTY_FUNCTION__;
  
-     m_viewPortWidth = width;
-     m_viewPortHeight = height;
+     m_viewPortWidth = size.width();
+     m_viewPortHeight = size.height();
  }
  
 +bool MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
 +{
-     QMessageBox msgBox(QMessageBox::Question, tr("Automatic location update"), text,
-                        QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, 0);
-     int returnValue = msgBox.exec();
-     qWarning() << __PRETTY_FUNCTION__ << returnValue;
-     if (returnValue == QMessageBox::Yes)
-         return true;
-     else
-         return false;
++    m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
++                                                      tr("Automatic location update"), text,
++                                                      QMessageBox::Yes | QMessageBox::No |
++                                                      QMessageBox::Cancel, this);
++    connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
++            this, SLOT(automaticUpdateDialogFinished(int)));
++    m_automaticUpdateLocationDialog->show();
 +}
 +
  void MainWindow::toggleFullScreen()
  {
      qDebug() << __PRETTY_FUNCTION__;
@@@ -45,6 -46,6 +46,7 @@@ class UserInfoPanel
  class ZoomButtonPanel;
  class SettingsDialog;
  class QToolButton;
++class QMessageBox;
  
  /**
  * @brief Main Window Class
@@@ -281,6 -266,6 +281,13 @@@ private
  
  private slots:
      /**
++    * @brief Slot for automatic update dialog finished.
++    *
++    * @result result code
++    */
++    void automaticUpdateDialogFinished(int result);
++
++    /**
      * @brief Slot to intercept signal when dialog/information note is processed
      *
      * @param status Status of the dialog
@@@ -594,7 -590,6 +612,8 @@@ private
      ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
  
      SettingsDialog *m_settingsDialog;       ///< Settings dialog
 +
++    QMessageBox *m_automaticUpdateLocationDialog;
  };
  
  #endif // MAINWINDOW_H
  #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;
  const int LIST_HOURS_MAX = 1;
  
  SettingsDialog::SettingsDialog(QWidget *parent)
--    : QDialog(parent),
--      m_automaticLocationUpdateOldValue(false),
--      m_automaticLocationUpdateIntervalOldValue(QTime(0, LIST_MINUTES_STEP))
++    : QDialog(parent)
  {
      qDebug() << __PRETTY_FUNCTION__;
      setWindowTitle(tr("Settings"));
@@@ -79,7 -77,7 +75,6 @@@
      connect(m_automaticLocationUpdate, SIGNAL(toggled(bool)),
              this, SLOT(toggleAutomaticLocationUpdate(bool)));
      connect(saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
--    connect(this, SIGNAL(rejected()), this, SLOT(rejectValues()));
  
      QFormLayout *form = new QFormLayout();
      form->setRowWrapPolicy(QFormLayout::WrapAllRows);
      readSettings();
  }
  
--SettingsDialog::~SettingsDialog()
- {
-     qDebug() << __PRETTY_FUNCTION__;
-     QSettings settings(DIRECTORY_NAME, FILE_NAME);
-     settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdateOldValue);
-     settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL,
-                       m_automaticLocationUpdateIntervalOldValue);
- }
- void SettingsDialog::setAutomaticLocationUpdateSettings(bool checked)
++void SettingsDialog::emitAutomaticLocationUpdateSettings()
  {
      qDebug() << __PRETTY_FUNCTION__;
  
-     m_automaticLocationUpdate->setChecked(checked);
-     m_automaticLocationUpdateOldValue = checked;
 -    QSettings settings(DIRECTORY_NAME, FILE_NAME);
 -    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, time());
++    if (m_automaticLocationUpdate->isChecked()) {
++        QTime emptyTime = QTime();
++        emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
++    }
++    else {
++        emit enableAutomaticLocationUpdate(false);
++    }
  }
  
  void SettingsDialog::enableSituareSettings(bool enabled)
      qDebug() << __PRETTY_FUNCTION__;
  
      m_automaticLocationUpdate->setEnabled(enabled);
 -    toggleAutomaticLocationUpdate(enabled);
 -}
  
 -void SettingsDialog::readSettings()
 -{
 -    qDebug() << __PRETTY_FUNCTION__;
 -
 -    QSettings settings(DIRECTORY_NAME, FILE_NAME);
 -    QString automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, "")
 -                                      .toString();
 -    if (!automaticUpdateInterval.isEmpty()) {
 -        setTime(QTime::fromString(automaticUpdateInterval));
 -        m_automaticLocationUpdateIntervalOldValue = time();
 -    }
 +    if (enabled)
 +        toggleAutomaticLocationUpdate(m_automaticLocationUpdate->isChecked());
 +    else
 +        toggleAutomaticLocationUpdate(false);
  }
  
+ void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
+ {
+     qDebug() << __PRETTY_FUNCTION__;
+     for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
+         QStandardItem *item = new QStandardItem(QString(tr("%1 min")).arg(i));
+         item->setTextAlignment(Qt::AlignCenter);
+         item->setEditable(false);
+         model->appendRow(item);
+     }
+ }
 -void SettingsDialog::rejectValues()
 +void SettingsDialog::readSettings()
  {
      qDebug() << __PRETTY_FUNCTION__;
  
 -    m_automaticLocationUpdate->setChecked(m_automaticLocationUpdateOldValue);
 -    setTime(m_automaticLocationUpdateIntervalOldValue);
 +    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, "hh:mm:ss"));
 +    else
 +        setTime(QTime(0, LIST_MINUTES_STEP));
-     m_automaticLocationUpdateOldValue = automaticUpdateEnabled;
-     m_automaticLocationUpdateIntervalOldValue = time();
  }
  
- void SettingsDialog::emitAutomaticLocationUpdateSettings()
- {
-     qDebug() << __PRETTY_FUNCTION__;
-     if (m_automaticLocationUpdate->isChecked()) {
-         QTime emptyTime = QTime();
-         emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
-     }
-     else {
-         emit enableAutomaticLocationUpdate(false);
-     }
- }
- void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
+ void SettingsDialog::saveValues()
  {
      qDebug() << __PRETTY_FUNCTION__;
  
-     for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
-         QStandardItem *item = new QStandardItem(QString(tr("%1 min")).arg(i));
-         item->setTextAlignment(Qt::AlignCenter);
-         item->setEditable(false);
-         model->appendRow(item);
-     }
- }
 -    m_automaticLocationUpdateOldValue = m_automaticLocationUpdate->isChecked();
 -    m_automaticLocationUpdateIntervalOldValue = time();
++    QSettings settings(DIRECTORY_NAME, FILE_NAME);
++    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdate->isChecked());
++    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, time());
 +
- void SettingsDialog::rejectValues()
- {
-     qDebug() << __PRETTY_FUNCTION__;
++    emitAutomaticLocationUpdateSettings();
  
-     m_automaticLocationUpdate->setChecked(m_automaticLocationUpdateOldValue);
-     setTime(m_automaticLocationUpdateIntervalOldValue);
 -    if (m_automaticLocationUpdate->isChecked()) {
 -        QTime emptyTime = QTime();
 -        emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
 -    }
 -    else {
 -        emit enableAutomaticLocationUpdate(false);
 -    }
+     accept();
  }
  
- void SettingsDialog::saveValues()
++void SettingsDialog::setAutomaticLocationUpdateSettings(bool checked)
 +{
 +    qDebug() << __PRETTY_FUNCTION__;
 +
-     m_automaticLocationUpdateOldValue = m_automaticLocationUpdate->isChecked();
-     m_automaticLocationUpdateIntervalOldValue = time();
-     emitAutomaticLocationUpdateSettings();
++    m_automaticLocationUpdate->setChecked(checked);
 +
-     accept();
++    QSettings settings(DIRECTORY_NAME, FILE_NAME);
++    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdate->isChecked());
 +}
 +
  void SettingsDialog::setTime(const QTime &time)
  {
      qDebug() << __PRETTY_FUNCTION__;
@@@ -54,13 -54,13 +54,6 @@@ public
      */
      SettingsDialog(QWidget *parent = 0);
  
--    /**
--    * @brief Destructor.
--    *
--    * Saves automatic update interval in settings.
--    */
--    ~SettingsDialog();
--
  /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
      */
      void enableSituareSettings(bool enabled);
  
 +    /**
 +    * @brief Emits automatic location update settings.
 +    */
 +    void emitAutomaticLocationUpdateSettings();
  
--private slots:
      /**
--    * @brief Saves settings to file.
++    * @brief Read settings.
      */
--    void saveValues();
++    void readSettings();
  
++private slots:
      /**
--    * @brief Rejects changes made to settings.
++    * @brief Saves settings to file.
      */
--    void rejectValues();
++    void saveValues();
  
      /**
      * @brief Toggles automatic location update state.
      void toggleAutomaticLocationUpdate(bool enabled);
  
   private:
 -    void populateUpdateIntervalList(QStandardItemModel *model);
 -
      /**
 -    * @brief Read settings.
 +    * @brief Populates update interval list.
 +    *
 +    * @param model QStandardItemModel
      */
 -    void readSettings();
 +    void populateUpdateIntervalList(QStandardItemModel *model);
  
      /**
-     * @brief Read settings.
-     */
-     void readSettings();
-     /**
      * @brief Sets time.
      *
      * @param time time to set
@@@ -144,13 -127,13 +132,11 @@@ signals
   * DATA MEMBERS
   ******************************************************************************/
  private:
 -    QCheckBox *m_automaticLocationUpdate; ///< Pointer to CheckBox
 -    bool m_automaticLocationUpdateOldValue;         ///< Automatic location update state
 -    QTime m_automaticLocationUpdateIntervalOldValue;///< Automatic location update interval value
 +    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