2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Katri Kaikkonen - katri.kaikkonen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 #include <QMaemo5TimePickSelector>
24 #include <QMaemo5ValueButton>
31 #include "settingsdialog.h"
33 const QString SETTINGS_AUTOMATIC_UPDATE_ENABLED = "SETTINGS_AUTOMATIC_UPDATE_ENABLED";
34 const QString SETTINGS_AUTOMATIC_UPDATE_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
35 const int LIST_MINUTES_STEP = 5;
36 const int LIST_MINUTES_MAX = 60;
37 const int LIST_HOURS_MAX = 1;
39 SettingsDialog::SettingsDialog(QWidget *parent)
41 m_automaticLocationUpdateOldValue(false),
42 m_automaticLocationUpdateIntervalOldValue(QTime(0, LIST_MINUTES_STEP))
44 qDebug() << __PRETTY_FUNCTION__;
45 setWindowTitle(tr("Settings"));
47 QScrollArea *scrollArea = new QScrollArea(this);
48 QGridLayout *gridLayout = new QGridLayout(this);
49 QGroupBox *groupBox = new QGroupBox(scrollArea);
51 m_automaticLocationUpdate = new QCheckBox(tr("Use automatic location update"));
53 QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
54 QPushButton *saveButton = buttonBox->addButton(QDialogButtonBox::Save);
55 QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
58 m_automaticLocationUpdateIntervalButton = new QMaemo5ValueButton(tr("Update interval"), this);
59 m_automaticLocationUpdateIntervalButton->setDisabled(true);
60 m_timePick = new QMaemo5ListPickSelector;
61 m_automaticLocationUpdateIntervalButton->setPickSelector(m_timePick);
62 m_automaticLocationUpdateIntervalButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
63 QStandardItemModel *updateIntervalListModel = new QStandardItemModel(0, 1, this);
64 populateUpdateIntervalList(updateIntervalListModel);
65 m_timePick->setModel(updateIntervalListModel);
66 m_automaticLocationUpdateIntervalButton->setValueText(
67 updateIntervalListModel->item(0, 0)->text());
68 Q_UNUSED(cancelButton);
70 m_automaticLocationUpdateInterval = new QTimeEdit();
71 m_automaticLocationUpdateInterval->setTimeRange(QTime(0, LIST_MINUTES_STEP),
72 QTime(LIST_HOURS_MAX, 0));
73 m_automaticLocationUpdateInterval->setDisplayFormat("hh:mm");
74 m_automaticLocationUpdateInterval->setDisabled(true);
76 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
79 connect(m_automaticLocationUpdate, SIGNAL(toggled(bool)),
80 this, SLOT(toggleAutomaticLocationUpdate(bool)));
81 connect(saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
82 connect(this, SIGNAL(rejected()), this, SLOT(rejectValues()));
84 QFormLayout *form = new QFormLayout();
85 form->setRowWrapPolicy(QFormLayout::WrapAllRows);
86 form->addWidget(m_automaticLocationUpdate);
89 form->addWidget(m_automaticLocationUpdateIntervalButton);
91 form->addRow(tr("Update interval"), m_automaticLocationUpdateInterval);
94 groupBox->setLayout(form);
95 scrollArea->setWidget(groupBox);
96 scrollArea->setWidgetResizable(true);
97 gridLayout->addWidget(scrollArea, 0, 0, 2, 1);
98 gridLayout->addWidget(buttonBox, 0, 1, 1, 1);
99 setLayout(gridLayout);
106 SettingsDialog::~SettingsDialog()
108 qDebug() << __PRETTY_FUNCTION__;
110 QSettings settings(DIRECTORY_NAME, FILE_NAME);
111 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdate->isChecked());
112 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, time());
115 void SettingsDialog::setAutomaticLocationUpdateSettings(bool checked)
117 qDebug() << __PRETTY_FUNCTION__;
119 m_automaticLocationUpdate->setChecked(checked);
122 void SettingsDialog::enableSituareSettings(bool enabled)
124 qDebug() << __PRETTY_FUNCTION__;
126 m_automaticLocationUpdate->setEnabled(enabled);
129 void SettingsDialog::readSettings()
131 qWarning() << __PRETTY_FUNCTION__;
133 QSettings settings(DIRECTORY_NAME, FILE_NAME);
134 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
135 QString automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, "")
138 m_automaticLocationUpdate->setChecked(automaticUpdateEnabled);
140 if (!automaticUpdateInterval.isEmpty()) {
141 qWarning() << automaticUpdateInterval;
142 setTime(QTime::fromString(automaticUpdateInterval, "hh:mm:ss"));
143 qWarning() << time().toString("hh:mm:ss");
146 if (automaticUpdateEnabled)
147 QTimer::singleShot(0, this, SLOT(saveValues()));
150 void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
152 qDebug() << __PRETTY_FUNCTION__;
154 for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
155 QStandardItem *item = new QStandardItem(QString(tr("%1 min")).arg(i));
156 item->setTextAlignment(Qt::AlignCenter);
157 item->setEditable(false);
158 model->appendRow(item);
162 void SettingsDialog::rejectValues()
164 qDebug() << __PRETTY_FUNCTION__;
166 m_automaticLocationUpdate->setChecked(m_automaticLocationUpdateOldValue);
167 setTime(m_automaticLocationUpdateIntervalOldValue);
170 void SettingsDialog::saveValues()
172 qDebug() << __PRETTY_FUNCTION__;
174 m_automaticLocationUpdateOldValue = m_automaticLocationUpdate->isChecked();
175 m_automaticLocationUpdateIntervalOldValue = time();
177 if (m_automaticLocationUpdate->isChecked()) {
178 QTime emptyTime = QTime();
179 emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
182 emit enableAutomaticLocationUpdate(false);
187 void SettingsDialog::setTime(const QTime &time)
189 qDebug() << __PRETTY_FUNCTION__;
192 int index = time.minute()/LIST_MINUTES_STEP - 1;
193 m_timePick->setCurrentIndex(index);
195 m_automaticLocationUpdateInterval->setTime(time);
199 QTime SettingsDialog::time()
201 qDebug() << __PRETTY_FUNCTION__;
203 QTime time = QTime();
206 time = time.addSecs((m_timePick->currentIndex()+1)*LIST_MINUTES_STEP*60);
208 time = m_automaticLocationUpdateInterval->time();
214 void SettingsDialog::toggleAutomaticLocationUpdate(bool enabled)
216 qDebug() << __PRETTY_FUNCTION__;
219 m_automaticLocationUpdateIntervalButton->setEnabled(enabled);
221 m_automaticLocationUpdateInterval->setEnabled(enabled);