Add support for reading/saving config file
[qcpufreq] / src / settingswidget.cpp
1 /*
2  * QCPUFreq - a simple cpufreq GUI
3  * Copyright (C) 2010 Daniel Klaffenbach <danielklaffenbach@gmail.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "settingswidget.h"
21 #include "ui_settingswidget.h"
22
23
24 SettingsWidget::SettingsWidget(QWidget *parent) :
25     QWidget(parent),
26     settings("qcpufreq"),
27     ui(new Ui::SettingsWidget)
28 {
29     ui->setupUi(this);
30
31     //read values from config file
32     autoRotate = settings.value("main/autorotate", true).toBool();
33     overclocking = settings.value("main/overclocking", false).toBool();
34     advancedTemperature = settings.value("main/advanced_temperature", true).toBool();
35
36     //reset GUI
37     reset();
38
39     connect(ui->btn_save, SIGNAL(clicked()), this, SLOT(save()));
40 }
41
42 SettingsWidget::~SettingsWidget()
43 {
44     delete ui;
45 }
46
47
48 /**
49   * Resets the UI to the values stored by QSettings.
50   */
51 void SettingsWidget::reset()
52 {
53     ui->checkBox_rotate->setChecked(autoRotate);
54     ui->checkBox_oc->setChecked(overclocking);
55     ui->checkBox_temperature->setChecked(advancedTemperature);
56 }
57
58
59 /**
60   * Saves the changes and hides the SettingsWidget.
61   */
62 void SettingsWidget::save()
63 {
64     autoRotate = ui->checkBox_rotate->isChecked();
65     overclocking = ui->checkBox_oc->isChecked();
66     advancedTemperature = ui->checkBox_temperature->isChecked();
67
68     settings.setValue("main/autorotate", autoRotate);
69     settings.setValue("main/overclocking", overclocking);
70     settings.setValue("main/advanced_temperature", advancedTemperature);
71
72     //save settings to file
73     settings.sync();
74
75     hide();
76 }