Added missing settingsdialog files
[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 "facebookservice/facebookcommon.h"
25 #include "settingsdialog.h"
26
27 const QString AUTOMATIC_LOCATION_UPDATE("Automatic_location_update");
28
29 SettingsDialog::SettingsDialog(QWidget *parent)
30     : QDialog(parent)
31 {
32     qDebug() << __PRETTY_FUNCTION__;
33     setWindowTitle(tr("Settings"));
34
35     QScrollArea *scrollArea = new QScrollArea(this);
36     QGridLayout *gridLayout = new QGridLayout(this);
37     QGroupBox *groupBox = new QGroupBox(scrollArea);
38     QSettings settings(DIRECTORY_NAME, FILE_NAME);
39
40     m_automaticLocationUpdate = new QCheckBox(tr("Use automatic location update"));
41     m_automaticLocationUpdate->setChecked(settings.value(AUTOMATIC_LOCATION_UPDATE).toBool());
42
43     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
44     QPushButton *saveButton = buttonBox->addButton(QDialogButtonBox::Save);
45     QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
46     connect(saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
47     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
48
49     connect(this, SIGNAL(finished(int)), this, SLOT(dialogFinished(int)));
50
51     QFormLayout *form = new QFormLayout();
52     form->addWidget(m_automaticLocationUpdate);
53
54     groupBox->setLayout(form);
55     scrollArea->setWidget(groupBox);
56     scrollArea->setWidgetResizable(true);
57     gridLayout->addWidget(scrollArea, 0, 0, 2, 1);
58     gridLayout->addWidget(buttonBox, 0, 1, 1, 1);
59     setLayout(gridLayout);
60
61     scrollArea->show();
62 }
63
64 SettingsDialog::~SettingsDialog()
65 {
66     qDebug() << __PRETTY_FUNCTION__;
67     delete m_automaticLocationUpdate;
68 }
69
70 void SettingsDialog::dialogFinished(int /* reason */)
71 {
72     qDebug() << __PRETTY_FUNCTION__;
73     deleteLater();
74 }
75
76 void SettingsDialog::saveValues()
77 {
78     qDebug() << __PRETTY_FUNCTION__;
79     QSettings settings(DIRECTORY_NAME, FILE_NAME);
80     settings.setValue(AUTOMATIC_LOCATION_UPDATE, m_automaticLocationUpdate->isChecked());
81     accept();
82
83 }