USA.
*/
+#ifdef Q_WS_MAEMO_5
+#include <QMaemo5TimePickSelector>
+#include <QMaemo5ValueButton>
+#endif
+
#include <QtGui>
#include <QDebug>
#include <QTime>
#include "settingsdialog.h"
const QString SETTINGS_AUTOMATIC_UPDATE_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
-const int MINIMUM_UPDATE_INTERVAL_SECS = 30;
-const int MAXIMUM_UPDATE_INTERVAL_HOURS = 1;
+const int LIST_MINUTES_STEP = 5;
+const int LIST_MINUTES_MAX = 60;
+const int MAXIMUM_HOURS = 1;
SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent),
m_automaticLocationUpdateOldValue(false),
- m_automaticLocationUpdateIntervalOldValue(QTime(0, 0, MINIMUM_UPDATE_INTERVAL_SECS))
+ m_automaticLocationUpdateIntervalOldValue(QTime(0, LIST_MINUTES_STEP))
{
qDebug() << __PRETTY_FUNCTION__;
setWindowTitle(tr("Settings"));
m_automaticLocationUpdate = new QCheckBox(tr("Use automatic location update"));
- m_automaticLocationUpdateInterval = new QTimeEdit();
- m_automaticLocationUpdateInterval->setTimeRange(QTime(0, 0, MINIMUM_UPDATE_INTERVAL_SECS),
- QTime(MAXIMUM_UPDATE_INTERVAL_HOURS, 0));
- m_automaticLocationUpdateInterval->setDisplayFormat("hh:mm:ss");
- m_automaticLocationUpdateInterval->setDisabled(true);
-
QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
QPushButton *saveButton = buttonBox->addButton(QDialogButtonBox::Save);
QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
+#ifdef Q_WS_MAEMO_5
+ m_automaticLocationUpdateIntervalButton = new QMaemo5ValueButton(tr("Update interval"), this);
+ m_automaticLocationUpdateIntervalButton->setDisabled(true);
+ m_timePick = new QMaemo5ListPickSelector;
+ m_automaticLocationUpdateIntervalButton->setPickSelector(m_timePick);
+ m_automaticLocationUpdateIntervalButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
+ QStandardItemModel *updateIntervalListModel = new QStandardItemModel(0, 1, this);
+ populateUpdateIntervalList(updateIntervalListModel);
+ m_timePick->setModel(updateIntervalListModel);
+
+ Q_UNUSED(cancelButton);
+#else
+ m_automaticLocationUpdateInterval = new QTimeEdit();
+ m_automaticLocationUpdateInterval->setTimeRange(QTime(0, LIST_INDEX_STEP),
+ QTime(MAXIMUM_HOURS, 0));
+ m_automaticLocationUpdateInterval->setDisplayFormat("hh:mm");
+ m_automaticLocationUpdateInterval->setDisabled(true);
+
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+#endif
+
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(rejected()), this, SLOT(rejectValues()));
QFormLayout *form = new QFormLayout();
form->setRowWrapPolicy(QFormLayout::WrapAllRows);
form->addWidget(m_automaticLocationUpdate);
+
+#ifdef Q_WS_MAEMO_5
+ form->addWidget(m_automaticLocationUpdateIntervalButton);
+#else
form->addRow(tr("Update interval"), m_automaticLocationUpdateInterval);
+#endif
groupBox->setLayout(form);
scrollArea->setWidget(groupBox);
scrollArea->show();
+ readSettings();
+}
+
+SettingsDialog::~SettingsDialog()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, time());
+}
+
+void SettingsDialog::enableSituareSettings(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_automaticLocationUpdate->setEnabled(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()) {
- m_automaticLocationUpdateInterval->setTime(QTime::fromString(automaticUpdateInterval));
- m_automaticLocationUpdateIntervalOldValue = m_automaticLocationUpdateInterval->time();
+ setTime(QTime::fromString(automaticUpdateInterval));
+ m_automaticLocationUpdateIntervalOldValue = time();
}
}
-SettingsDialog::~SettingsDialog()
+void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
{
qDebug() << __PRETTY_FUNCTION__;
- QSettings settings(DIRECTORY_NAME, FILE_NAME);
- settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL,
- m_automaticLocationUpdateInterval->time());
+ for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
+ QStandardItem *item = new QStandardItem(QString("%1 min").arg(i));
+ item->setTextAlignment(Qt::AlignCenter);
+ item->setEditable(false);
+ model->appendRow(item);
+ }
}
void SettingsDialog::rejectValues()
qDebug() << __PRETTY_FUNCTION__;
m_automaticLocationUpdate->setChecked(m_automaticLocationUpdateOldValue);
- m_automaticLocationUpdateInterval->setTime(m_automaticLocationUpdateIntervalOldValue);
+ setTime(m_automaticLocationUpdateIntervalOldValue);
}
void SettingsDialog::saveValues()
qDebug() << __PRETTY_FUNCTION__;
m_automaticLocationUpdateOldValue = m_automaticLocationUpdate->isChecked();
- m_automaticLocationUpdateIntervalOldValue = m_automaticLocationUpdateInterval->time();
+ m_automaticLocationUpdateIntervalOldValue = time();
if (m_automaticLocationUpdate->isChecked()) {
- QTime time = QTime();
- emit enableAutomaticLocationUpdate(true, time.msecsTo(
- m_automaticLocationUpdateInterval->time()));
+ QTime emptyTime = QTime();
+ emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
}
else {
emit enableAutomaticLocationUpdate(false);
accept();
}
-void SettingsDialog::enableSituareSettings(bool enabled)
+void SettingsDialog::setTime(const QTime &time)
{
qDebug() << __PRETTY_FUNCTION__;
- m_automaticLocationUpdate->setEnabled(enabled);
+#ifdef Q_WS_MAEMO_5
+ int index = time.minute()/LIST_MINUTES_STEP - 1;
+ m_timePick->setCurrentIndex(index);
+#else
+ m_automaticLocationUpdateInterval->setTime(time);
+#endif
+}
+
+QTime SettingsDialog::time()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QTime time = QTime();
+
+#ifdef Q_WS_MAEMO_5
+ time = time.addSecs((m_timePick->currentIndex()+1)*LIST_MINUTES_STEP*60);
+#else
+ time = m_automaticLocationUpdateInterval->time();
+#endif
+
+ if ((time.hour() == 0) && (time.second() == 0))
+ time.addSecs(60);
+
+ return time;
}
-void SettingsDialog::toggleAutomaticLocationUpdate(bool value)
+void SettingsDialog::toggleAutomaticLocationUpdate(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
- m_automaticLocationUpdateInterval->setEnabled(value);
+#ifdef Q_WS_MAEMO_5
+ m_automaticLocationUpdateIntervalButton->setEnabled(enabled);
+#else
+ m_automaticLocationUpdateInterval->setEnabled(enabled);
+#endif
}