4e8befecfc086de61f0b471c36dc7f6c90338ea8
[situare] / src / ui / settingsdialog.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Katri Kaikkonen - katri.kaikkonen@ixonos.com
6
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.
10
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.
15
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,
19    USA.
20 */
21
22 #include <QtGui>
23 #include <QDebug>
24 #include <QTime>
25 #include "common.h"
26 #include "settingsdialog.h"
27
28 SettingsDialog::SettingsDialog(QWidget *parent)
29     : QDialog(parent)
30 {
31     qDebug() << __PRETTY_FUNCTION__;
32     setWindowTitle(tr("Settings"));
33
34     QScrollArea *scrollArea = new QScrollArea(this);
35     QGridLayout *gridLayout = new QGridLayout(this);
36     QGroupBox *groupBox = new QGroupBox(scrollArea);
37
38     m_automaticLocationUpdate = new QCheckBox(tr("Use automatic location update"));
39
40     m_automaticLocationUpdateInterval = new QTimeEdit();
41     m_automaticLocationUpdateInterval->setTimeRange(QTime(0, 0, 5), QTime(1, 0));
42     m_automaticLocationUpdateInterval->setDisplayFormat("mm:ss");
43     m_automaticLocationUpdateInterval->setDisabled(true);
44
45     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
46     QPushButton *saveButton = buttonBox->addButton(QDialogButtonBox::Save);
47     QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
48
49     connect(m_automaticLocationUpdate, SIGNAL(toggled(bool)),
50             this, SLOT(toggleAutomaticLocationUpdate(bool)));
51     connect(saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
52     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
53
54     QFormLayout *form = new QFormLayout();
55     form->addWidget(m_automaticLocationUpdate);
56     form->addRow("Update interval", m_automaticLocationUpdateInterval);
57
58     groupBox->setLayout(form);
59     scrollArea->setWidget(groupBox);
60     scrollArea->setWidgetResizable(true);
61     gridLayout->addWidget(scrollArea, 0, 0, 2, 1);
62     gridLayout->addWidget(buttonBox, 0, 1, 1, 1);
63     setLayout(gridLayout);
64
65     scrollArea->show();
66 }
67
68 void SettingsDialog::saveValues()
69 {
70     qDebug() << __PRETTY_FUNCTION__;
71
72     if (m_automaticLocationUpdate->isChecked()) {
73         QTime time = QTime();
74         emit automaticLocationUpdateIntervalSet(time.msecsTo(
75                 m_automaticLocationUpdateInterval->time()));
76     }
77     else {
78         emit automaticLocationUpdateIntervalSet(-1);
79     }
80     accept();
81 }
82
83 void SettingsDialog::enableSituareSettings(bool enabled)
84 {
85     qDebug() << __PRETTY_FUNCTION__;
86
87     m_automaticLocationUpdate->setEnabled(enabled);
88 }
89
90 void SettingsDialog::toggleAutomaticLocationUpdate(bool value)
91 {
92     qDebug() << __PRETTY_FUNCTION__;
93     m_automaticLocationUpdateInterval->setEnabled(value);
94 }