2 * QCPUFreq - a simple cpufreq GUI
3 * Copyright (C) 2010 Daniel Klaffenbach <danielklaffenbach@gmail.com>
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.
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.
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/>.
20 #include "ui_settings.h"
23 #include <QMessageBox>
24 #include <QStringList>
25 #include <QTextStream>
26 #if defined(Q_WS_MAEMO_5)
27 #include <QMaemo5InformationBox>
30 #define DEFAULT_FREQUENCY 600000
32 Settings::Settings(QWidget *parent) :
39 //read values from config file
40 autoRotate = settings.value("main/autorotate", true).toBool();
41 confirmApply = settings.value("main/confirm_apply", true).toBool();
42 overclocking = settings.value("main/overclocking", false).toBool();
43 advancedTemperature = settings.value("main/advanced_temperature", false).toBool();
45 /* The next few lines of code check if QCPUFreq is running on a power kernel and if
46 * the kernel-config script is installed.
48 * Basically we get the maximum available frequency - if it is greater than
49 * DEFAULT_FREQUENCY we can be sure that the current kernel is a power kernel.
51 QFile file( "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies" );
54 kernelConfigInstalled = false;
57 if ( !file.exists() || !file.open( QIODevice::ReadOnly ) ) {
58 QMessageBox::critical(this, tr("QCPUFreq"), tr("Could not get information from /sys!"));
61 QTextStream in( &file );
62 QStringList freqList = in.readLine().split(" ");
63 int maxFreq = freqList.at(0).toInt();
68 if (maxFreq > DEFAULT_FREQUENCY) {
72 //Check if kernel-config is installed
73 file.setFileName("/usr/sbin/kernel-config");
75 kernelConfigInstalled = true;
79 //on non-power-kernels we can disable the overclocking and temperature options
81 ui->checkBox_oc->setDisabled(true);
82 ui->checkBox_temperature->setDisabled(true);
88 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()));
89 connect(ui->checkBox_oc, SIGNAL(clicked()), this, SLOT(showOverclockingWarning()));
99 * Returns True if the kernel-config script is installed.
101 bool Settings::isKernelConfigInstalled()
103 return kernelConfigInstalled;
108 * Returns true if we are on a Maemo 5 OS.
110 bool Settings::platformMaemo()
112 #if defined(Q_WS_MAEMO_5)
121 * Resets the UI to the values stored by QSettings.
123 void Settings::reset()
125 ui->checkBox_rotate->setChecked(autoRotate);
126 ui->checkBox_confirmapply->setChecked(confirmApply);
127 ui->checkBox_oc->setChecked(overclocking);
128 ui->checkBox_temperature->setChecked(advancedTemperature);
133 * Saves the changes and hides the SettingsWidget.
135 * @emits: settingsChanged()
137 void Settings::save()
139 autoRotate = ui->checkBox_rotate->isChecked();
140 confirmApply = ui->checkBox_confirmapply->isChecked();
141 overclocking = ui->checkBox_oc->isChecked();
142 advancedTemperature = ui->checkBox_temperature->isChecked();
144 settings.setValue("main/autorotate", autoRotate);
145 settings.setValue("main/confirm_apply", confirmApply);
146 settings.setValue("main/overclocking", overclocking);
147 settings.setValue("main/advanced_temperature", advancedTemperature);
149 //save settings to file
154 emit settingsChanged();
159 * Displays a warning when overclocking is being enabled.
161 void Settings::showOverclockingWarning()
163 if (ui->checkBox_oc->isChecked()) {
164 #if defined(Q_WS_MAEMO_5)
165 QMaemo5InformationBox::information(this, tr( "Please note that overclocking voids your warranty and may break your device! Be careful!"), 0);
167 QMessageBox::warning(this, tr("Warning"), tr("Please note that overclocking voids your warranty and may break your device! Be careful!"));
174 * Returns true if the user wants to display a more
175 * accurate temperature.
177 bool Settings::useAdvancedTemperature()
179 return advancedTemperature;
184 * Do we need to display a confirmation dialog before applying new
187 bool Settings::useConfirmation()
194 * Returns true if auto-Rotate is enabled.
196 bool Settings::useAutoRotate()
203 * Returns true if the user enabled overclocking.
205 bool Settings::useOverclocking()
212 * Returns true if QCPUFreq is running on a power kernel.
214 bool Settings::usePowerKernel()