Added auto updating methods to Engine.
[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->setRowWrapPolicy(QFormLayout::WrapAllRows);
56     form->addWidget(m_automaticLocationUpdate);
57     form->addRow("Update interval", m_automaticLocationUpdateInterval);
58
59     groupBox->setLayout(form);
60     scrollArea->setWidget(groupBox);
61     scrollArea->setWidgetResizable(true);
62     gridLayout->addWidget(scrollArea, 0, 0, 2, 1);
63     gridLayout->addWidget(buttonBox, 0, 1, 1, 1);
64     setLayout(gridLayout);
65
66     scrollArea->show();
67 }
68
69 void SettingsDialog::saveValues()
70 {
71     qDebug() << __PRETTY_FUNCTION__;
72
73     if (m_automaticLocationUpdate->isChecked()) {
74         QTime time = QTime();
75         emit automaticLocationUpdateIntervalSet(time.msecsTo(
76                 m_automaticLocationUpdateInterval->time()));
77     }
78     else {
79         emit automaticLocationUpdateIntervalSet(-1);
80     }
81     accept();
82 }
83
84 void SettingsDialog::enableSituareSettings(bool enabled)
85 {
86     qDebug() << __PRETTY_FUNCTION__;
87
88     m_automaticLocationUpdate->setEnabled(enabled);
89 }
90
91 void SettingsDialog::toggleAutomaticLocationUpdate(bool value)
92 {
93     qDebug() << __PRETTY_FUNCTION__;
94     m_automaticLocationUpdateInterval->setEnabled(value);
95 }