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 overclocking = settings.value("main/overclocking", false).toBool();
42 advancedTemperature = settings.value("main/advanced_temperature", false).toBool();
44 /* The next few lines of code check if QCPUFreq is running on a power kernel and if
45 * the kernel-config script is installed.
47 * Basically we get the maximum available frequency - if it is greater than
48 * DEFAULT_FREQUENCY we can be sure that the current kernel is a power kernel.
50 QFile file( "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies" );
53 kernelConfigInstalled = false;
56 if ( !file.exists() || !file.open( QIODevice::ReadOnly ) ) {
57 QMessageBox::critical(this, tr("QCPUFreq"), tr("Could not get information from /sys!"));
60 QTextStream in( &file );
61 QStringList freqList = in.readLine().split(" ");
62 int maxFreq = freqList.at(0).toInt();
67 if (maxFreq > DEFAULT_FREQUENCY) {
71 //Check if kernel-config is installed
72 file.setFileName("/usr/sbin/kernel-config");
74 kernelConfigInstalled = true;
78 //on non-power-kernels we can disable the overclocking and temperature options
80 ui->checkBox_oc->setDisabled(true);
81 ui->checkBox_temperature->setDisabled(true);
87 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()));
88 connect(ui->checkBox_oc, SIGNAL(clicked()), this, SLOT(showOverclockingWarning()));
98 * Returns True if the kernel-config script is installed.
100 bool Settings::isKernelConfigInstalled()
102 return kernelConfigInstalled;
107 * Returns true if we are on a Maemo 5 OS.
109 bool Settings::platformMaemo()
111 #if defined(Q_WS_MAEMO_5)
120 * Resets the UI to the values stored by QSettings.
122 void Settings::reset()
124 ui->checkBox_rotate->setChecked(autoRotate);
125 ui->checkBox_oc->setChecked(overclocking);
126 ui->checkBox_temperature->setChecked(advancedTemperature);
131 * Saves the changes and hides the SettingsWidget.
133 * @emits: settingsChanged()
135 void Settings::save()
137 autoRotate = ui->checkBox_rotate->isChecked();
138 overclocking = ui->checkBox_oc->isChecked();
139 advancedTemperature = ui->checkBox_temperature->isChecked();
141 settings.setValue("main/autorotate", autoRotate);
142 settings.setValue("main/overclocking", overclocking);
143 settings.setValue("main/advanced_temperature", advancedTemperature);
145 //save settings to file
150 emit settingsChanged();
155 * Displays a warning when overclocking is being enabled.
157 void Settings::showOverclockingWarning()
159 if (ui->checkBox_oc->isChecked()) {
160 #if defined(Q_WS_MAEMO_5)
161 QMaemo5InformationBox::information(this, tr( "Please note that overclocking voids your warranty and may break your device! Be careful!"), 0);
163 QMessageBox::warning(this, tr("Warning"), tr("Please note that overclocking voids your warranty and may break your device! Be careful!"));
170 * Returns true if the user wants to display a more
171 * accurate temperature.
173 bool Settings::useAdvancedTemperature()
175 return advancedTemperature;
180 * Returns true if auto-Rotate is enabled.
182 bool Settings::useAutoRotate()
189 * Returns true if the user enabled overclocking.
191 bool Settings::useOverclocking()
198 * Returns true if QCPUFreq is running on a power kernel.
200 bool Settings::usePowerKernel()