Do not enabled advanced temperature display by default
[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", false).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 /**
36   * Returns true if we are on a Maemo 5 OS.
37   */
38 bool Settings::platformMaemo()
39 {
40     #if defined(Q_WS_MAEMO_5)
41         return true;
42     #else
43         return false;
44     #endif
45 }
46
47
48 /**
49   * Resets the UI to the values stored by QSettings.
50   */
51 void Settings::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 Settings::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 }
77
78
79 /**
80   * Displays a warning when overclocking is being enabled.
81   */
82 void Settings::showOverclockingWarning()
83 {
84
85 #if defined(Q_WS_MAEMO_5)
86     QMaemo5InformationBox::information(this, tr( "Please note that overclocking voids your warranty and may break your device! Be careful!"), 0);
87 #else
88     QMessageBox::warning(this, tr("Warning"), tr("Please note that overclocking voids your warranty and may break your device! Be careful!"));
89 #endif
90
91 }
92
93
94 /**
95   * Returns true if the user wants to display a more
96   * accurate temperature.
97   */
98 bool Settings::useAdvancedTemperature()
99 {
100     return advancedTemperature;
101 }
102
103
104 /**
105   * Returns true if auto-Rotate is enabled.
106   */
107 bool Settings::useAutoRotate()
108 {
109     return autoRotate;
110 }
111
112
113 /**
114   * Returns true if the user enabled overclocking.
115   */
116 bool Settings::useOverclocking()
117 {
118     return overclocking;
119 }