Use QDialog instead of QWidget for Settings
[qcpufreq] / src / settings.cpp
1 #include "settings.h"
2 #include "ui_settings.h"
3
4 #include <QMessageBox>
5 #if defined(Q_WS_MAEMO_5)
6     #include <QMaemo5InformationBox>
7 #endif
8
9
10 Settings::Settings(QWidget *parent) :
11     QDialog(parent),
12     settings("qcpufreq"),
13     ui(new Ui::Settings)
14 {
15     ui->setupUi(this);
16
17     //read values from config file
18     autoRotate = settings.value("main/autorotate", true).toBool();
19     overclocking = settings.value("main/overclocking", false).toBool();
20     advancedTemperature = settings.value("main/advanced_temperature", true).toBool();
21
22     //reset GUI
23     reset();
24
25     connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()));
26     connect(ui->checkBox_oc, SIGNAL(clicked()), this, SLOT(showOverclockingWarning()));
27 }
28
29 Settings::~Settings()
30 {
31     delete ui;
32 }
33
34 /**
35   * Returns true if we are on a Maemo 5 OS.
36   */
37 bool Settings::platformMaemo()
38 {
39     #if defined(Q_WS_MAEMO_5)
40         return true;
41     #else
42         return false;
43     #endif
44 }
45
46
47 /**
48   * Resets the UI to the values stored by QSettings.
49   */
50 void Settings::reset()
51 {
52     ui->checkBox_rotate->setChecked(autoRotate);
53     ui->checkBox_oc->setChecked(overclocking);
54     ui->checkBox_temperature->setChecked(advancedTemperature);
55 }
56
57
58 /**
59   * Saves the changes and hides the SettingsWidget.
60   */
61 void Settings::save()
62 {
63     autoRotate = ui->checkBox_rotate->isChecked();
64     overclocking = ui->checkBox_oc->isChecked();
65     advancedTemperature = ui->checkBox_temperature->isChecked();
66
67     settings.setValue("main/autorotate", autoRotate);
68     settings.setValue("main/overclocking", overclocking);
69     settings.setValue("main/advanced_temperature", advancedTemperature);
70
71     //save settings to file
72     settings.sync();
73
74     hide();
75 }
76
77
78 /**
79   * Displays a warning when overclocking is being enabled.
80   */
81 void Settings::showOverclockingWarning()
82 {
83
84 #if defined(Q_WS_MAEMO_5)
85     QMaemo5InformationBox::information(this, tr( "Please note that overclocking voids your warranty and may break your device! Be careful!"), 0);
86 #else
87     QMessageBox::warning(this, tr("Warning"), tr("Please note that overclocking voids your warranty and may break your device! Be careful!"));
88 #endif
89
90 }