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_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
34 const int LIST_MINUTES_STEP = 5;
35 const int LIST_MINUTES_MAX = 60;
36 const int LIST_HOURS_MAX = 1;
38 SettingsDialog::SettingsDialog(QWidget *parent)
40 m_automaticLocationUpdateOldValue(false),
41 m_automaticLocationUpdateIntervalOldValue(QTime(0, LIST_MINUTES_STEP))
43 qDebug() << __PRETTY_FUNCTION__;
44 setWindowTitle(tr("Settings"));
46 QScrollArea *scrollArea = new QScrollArea(this);
47 QGridLayout *gridLayout = new QGridLayout(this);
48 QGroupBox *groupBox = new QGroupBox(scrollArea);
50 m_automaticLocationUpdate = new QCheckBox(tr("Use automatic location update"));
52 QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
53 QPushButton *saveButton = buttonBox->addButton(QDialogButtonBox::Save);
54 QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
57 m_automaticLocationUpdateIntervalButton = new QMaemo5ValueButton(tr("Update interval"), this);
58 m_automaticLocationUpdateIntervalButton->setDisabled(true);
59 m_timePick = new QMaemo5ListPickSelector;
60 m_automaticLocationUpdateIntervalButton->setPickSelector(m_timePick);
61 m_automaticLocationUpdateIntervalButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
62 QStandardItemModel *updateIntervalListModel = new QStandardItemModel(0, 1, this);
63 populateUpdateIntervalList(updateIntervalListModel);
64 m_timePick->setModel(updateIntervalListModel);
66 Q_UNUSED(cancelButton);
68 m_automaticLocationUpdateInterval = new QTimeEdit();
69 m_automaticLocationUpdateInterval->setTimeRange(QTime(0, LIST_MINUTES_STEP),
70 QTime(LIST_HOURS_MAX, 0));
71 m_automaticLocationUpdateInterval->setDisplayFormat("hh:mm");
72 m_automaticLocationUpdateInterval->setDisabled(true);
74 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
77 connect(m_automaticLocationUpdate, SIGNAL(toggled(bool)),
78 this, SLOT(toggleAutomaticLocationUpdate(bool)));
79 connect(saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
80 connect(this, SIGNAL(rejected()), this, SLOT(rejectValues()));
82 QFormLayout *form = new QFormLayout();
83 form->setRowWrapPolicy(QFormLayout::WrapAllRows);
84 form->addWidget(m_automaticLocationUpdate);
87 form->addWidget(m_automaticLocationUpdateIntervalButton);
89 form->addRow(tr("Update interval"), m_automaticLocationUpdateInterval);
92 groupBox->setLayout(form);
93 scrollArea->setWidget(groupBox);
94 scrollArea->setWidgetResizable(true);
95 gridLayout->addWidget(scrollArea, 0, 0, 2, 1);
96 gridLayout->addWidget(buttonBox, 0, 1, 1, 1);
97 setLayout(gridLayout);
104 SettingsDialog::~SettingsDialog()
106 qDebug() << __PRETTY_FUNCTION__;
108 QSettings settings(DIRECTORY_NAME, FILE_NAME);
109 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, time());
112 void SettingsDialog::enableSituareSettings(bool enabled)
114 qDebug() << __PRETTY_FUNCTION__;
116 m_automaticLocationUpdate->setEnabled(enabled);
117 toggleAutomaticLocationUpdate(enabled);
120 void SettingsDialog::readSettings()
122 qDebug() << __PRETTY_FUNCTION__;
124 QSettings settings(DIRECTORY_NAME, FILE_NAME);
125 QString automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, "")
127 if (!automaticUpdateInterval.isEmpty()) {
128 setTime(QTime::fromString(automaticUpdateInterval));
129 m_automaticLocationUpdateIntervalOldValue = time();
133 void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
135 qDebug() << __PRETTY_FUNCTION__;
137 for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
138 QStandardItem *item = new QStandardItem(QString(tr("%1 min")).arg(i));
139 item->setTextAlignment(Qt::AlignCenter);
140 item->setEditable(false);
141 model->appendRow(item);
145 void SettingsDialog::rejectValues()
147 qDebug() << __PRETTY_FUNCTION__;
149 m_automaticLocationUpdate->setChecked(m_automaticLocationUpdateOldValue);
150 setTime(m_automaticLocationUpdateIntervalOldValue);
153 void SettingsDialog::saveValues()
155 qDebug() << __PRETTY_FUNCTION__;
157 m_automaticLocationUpdateOldValue = m_automaticLocationUpdate->isChecked();
158 m_automaticLocationUpdateIntervalOldValue = time();
160 if (m_automaticLocationUpdate->isChecked()) {
161 QTime emptyTime = QTime();
162 emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
165 emit enableAutomaticLocationUpdate(false);
170 void SettingsDialog::setTime(const QTime &time)
172 qDebug() << __PRETTY_FUNCTION__;
175 int index = time.minute()/LIST_MINUTES_STEP - 1;
176 m_timePick->setCurrentIndex(index);
178 m_automaticLocationUpdateInterval->setTime(time);
182 QTime SettingsDialog::time()
184 qDebug() << __PRETTY_FUNCTION__;
186 QTime time = QTime();
189 time = time.addSecs((m_timePick->currentIndex()+1)*LIST_MINUTES_STEP*60);
191 time = m_automaticLocationUpdateInterval->time();
197 void SettingsDialog::toggleAutomaticLocationUpdate(bool enabled)
199 qDebug() << __PRETTY_FUNCTION__;
202 m_automaticLocationUpdateIntervalButton->setEnabled(enabled);
204 m_automaticLocationUpdateInterval->setEnabled(enabled);