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.
45 * Basically we get the maximum available frequency - if it is greater than
46 * DEFAULT_FREQUENCY we can be sure that the current kernel is a power kernel.
48 QFile file( "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies" );
51 if ( !file.exists() || !file.open( QIODevice::ReadOnly ) ) {
52 QMessageBox::critical(this, tr("QCPUFreq"), tr("Could not get information from /sys!"));
56 QTextStream in( &file );
57 QStringList freqList = in.readLine().split(" ");
58 int maxFreq = freqList.at(0).toInt();
63 if (maxFreq > DEFAULT_FREQUENCY) {
70 //on non-power-kernels we can disable the overclocking and temperature options
72 ui->checkBox_oc->setDisabled(true);
73 ui->checkBox_temperature->setDisabled(true);
79 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()));
80 connect(ui->checkBox_oc, SIGNAL(clicked()), this, SLOT(showOverclockingWarning()));
90 * Returns true if we are on a Maemo 5 OS.
92 bool Settings::platformMaemo()
94 #if defined(Q_WS_MAEMO_5)
103 * Resets the UI to the values stored by QSettings.
105 void Settings::reset()
107 ui->checkBox_rotate->setChecked(autoRotate);
108 ui->checkBox_oc->setChecked(overclocking);
109 ui->checkBox_temperature->setChecked(advancedTemperature);
114 * Saves the changes and hides the SettingsWidget.
116 void Settings::save()
118 autoRotate = ui->checkBox_rotate->isChecked();
119 overclocking = ui->checkBox_oc->isChecked();
120 advancedTemperature = ui->checkBox_temperature->isChecked();
122 settings.setValue("main/autorotate", autoRotate);
123 settings.setValue("main/overclocking", overclocking);
124 settings.setValue("main/advanced_temperature", advancedTemperature);
126 //save settings to file
134 * Displays a warning when overclocking is being enabled.
136 void Settings::showOverclockingWarning()
138 if (ui->checkBox_oc->isChecked()) {
139 #if defined(Q_WS_MAEMO_5)
140 QMaemo5InformationBox::information(this, tr( "Please note that overclocking voids your warranty and may break your device! Be careful!"), 0);
142 QMessageBox::warning(this, tr("Warning"), tr("Please note that overclocking voids your warranty and may break your device! Be careful!"));
149 * Returns true if the user wants to display a more
150 * accurate temperature.
152 bool Settings::useAdvancedTemperature()
154 return advancedTemperature;
159 * Returns true if auto-Rotate is enabled.
161 bool Settings::useAutoRotate()
168 * Returns true if the user enabled overclocking.
170 bool Settings::useOverclocking()
177 * Returns true if QCPUFreq is running on a power kernel.
179 bool Settings::usePowerKernel()