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>
29 #include <QDialogButtonBox>
30 #include <QFormLayout>
31 #include <QGridLayout>
33 #include <QPushButton>
34 #include <QScrollArea>
40 #include "settingsdialog.h"
42 const int LIST_MINUTES_STEP = 5;
43 const int LIST_MINUTES_MAX = 60;
44 const int LIST_HOURS_MAX = 1;
46 SettingsDialog::SettingsDialog(QWidget *parent)
49 qDebug() << __PRETTY_FUNCTION__;
50 setWindowTitle(tr("Settings"));
51 setAttribute(Qt::WA_DeleteOnClose, true);
53 QScrollArea *scrollArea = new QScrollArea(this);
54 QGridLayout *gridLayout = new QGridLayout(this);
55 QGroupBox *groupBox = new QGroupBox(scrollArea);
57 m_automaticLocationUpdate = new QCheckBox(tr("Use automatic location update"));
59 QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
60 m_saveButton = buttonBox->addButton(QDialogButtonBox::Save);
61 QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
64 m_automaticLocationUpdateIntervalButton = new QMaemo5ValueButton(tr("Update interval"), this);
65 m_automaticLocationUpdateIntervalButton->setDisabled(true);
66 m_timePick = new QMaemo5ListPickSelector;
67 m_automaticLocationUpdateIntervalButton->setPickSelector(m_timePick);
68 m_automaticLocationUpdateIntervalButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
69 QStandardItemModel *updateIntervalListModel = new QStandardItemModel(0, 1, this);
70 populateUpdateIntervalList(updateIntervalListModel);
71 m_timePick->setModel(updateIntervalListModel);
72 m_automaticLocationUpdateIntervalButton->setValueText(
73 updateIntervalListModel->item(0, 0)->text());
74 Q_UNUSED(cancelButton);
76 m_automaticLocationUpdateInterval = new QTimeEdit();
77 m_automaticLocationUpdateInterval->setTimeRange(QTime(0, LIST_MINUTES_STEP),
78 QTime(LIST_HOURS_MAX, 0));
79 m_automaticLocationUpdateInterval->setDisplayFormat("hh:mm");
80 m_automaticLocationUpdateInterval->setDisabled(true);
82 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
85 connect(m_automaticLocationUpdate, SIGNAL(toggled(bool)),
86 this, SLOT(toggleAutomaticLocationUpdate(bool)));
87 connect(m_saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
89 QFormLayout *form = new QFormLayout();
90 form->setRowWrapPolicy(QFormLayout::WrapAllRows);
91 form->addWidget(m_automaticLocationUpdate);
94 form->addWidget(m_automaticLocationUpdateIntervalButton);
96 form->addRow(tr("Update interval"), m_automaticLocationUpdateInterval);
99 groupBox->setLayout(form);
100 scrollArea->setWidget(groupBox);
101 scrollArea->setWidgetResizable(true);
102 gridLayout->addWidget(scrollArea, 0, 0, 2, 1);
103 gridLayout->addWidget(buttonBox, 0, 1, 1, 1);
104 setLayout(gridLayout);
111 void SettingsDialog::enableSituareSettings(bool enabled)
113 qDebug() << __PRETTY_FUNCTION__;
115 m_saveButton->setEnabled(enabled);
116 m_automaticLocationUpdate->setEnabled(enabled);
119 toggleAutomaticLocationUpdate(m_automaticLocationUpdate->isChecked());
121 toggleAutomaticLocationUpdate(false);
124 void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
126 qDebug() << __PRETTY_FUNCTION__;
128 for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
129 QStandardItem *item = new QStandardItem(QString(tr("%1 min")).arg(i));
130 item->setTextAlignment(Qt::AlignCenter);
131 item->setEditable(false);
132 model->appendRow(item);
136 void SettingsDialog::readSettings()
138 qDebug() << __PRETTY_FUNCTION__;
140 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
141 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
142 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
145 m_automaticLocationUpdate->setChecked(automaticUpdateEnabled);
147 if (automaticUpdateInterval.isValid())
148 setTime(automaticUpdateInterval);
150 setTime(QTime(0, LIST_MINUTES_STEP));
153 void SettingsDialog::saveValues()
155 qDebug() << __PRETTY_FUNCTION__;
157 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
158 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdate->isChecked());
159 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, time());
164 void SettingsDialog::setTime(const QTime &time)
166 qDebug() << __PRETTY_FUNCTION__;
169 // Convert time to index in list
170 int index = time.minute()/LIST_MINUTES_STEP - 1;
174 if (index >= m_timePick->model()->rowCount())
175 index = m_timePick->model()->rowCount() - 1;
177 m_timePick->setCurrentIndex(index);
179 m_automaticLocationUpdateInterval->setTime(time);
183 QTime SettingsDialog::time()
185 qDebug() << __PRETTY_FUNCTION__;
190 time = time.addSecs((m_timePick->currentIndex()+1)*LIST_MINUTES_STEP*60);
192 time = m_automaticLocationUpdateInterval->time();
195 if (time < QTime(0, LIST_MINUTES_STEP))
196 time = QTime(0, LIST_MINUTES_STEP);
197 if (time > QTime(LIST_HOURS_MAX, 0))
198 time = QTime(LIST_HOURS_MAX, 0);
203 void SettingsDialog::toggleAutomaticLocationUpdate(bool enabled)
205 qDebug() << __PRETTY_FUNCTION__;
208 m_automaticLocationUpdateIntervalButton->setEnabled(enabled);
210 m_automaticLocationUpdateInterval->setEnabled(enabled);