From: Daniel Klaffenbach Date: Wed, 3 Nov 2010 22:47:29 +0000 (+0100) Subject: Settings: check if we are using a power kernel X-Git-Tag: v0.4.0~17 X-Git-Url: http://vcs.maemo.org/git/?p=qcpufreq;a=commitdiff_plain;h=442ead7773c701f72453afff9e27365d843f4b85 Settings: check if we are using a power kernel --- diff --git a/src/settings.cpp b/src/settings.cpp index d660d0c..a0b78f7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,11 +1,15 @@ #include "settings.h" #include "ui_settings.h" +#include #include +#include +#include #if defined(Q_WS_MAEMO_5) #include #endif +#define DEFAULT_FREQUENCY 600000 Settings::Settings(QWidget *parent) : QDialog(parent), @@ -19,6 +23,38 @@ Settings::Settings(QWidget *parent) : overclocking = settings.value("main/overclocking", false).toBool(); advancedTemperature = settings.value("main/advanced_temperature", false).toBool(); + /* The next few lines of code check if QCPUFreq is running on a power kernel. + * Basically we get the maximum available frequency - if it is greater than + * DEFAULT_FREQUENCY we can be sure that the current kernel is a power kernel. + */ + QFile file( "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies" ); + + //open the file + if ( !file.exists() || !file.open( QIODevice::ReadOnly ) ) { + QMessageBox::critical(this, tr("QCPUFreq"), tr("Could not get information from /sys!")); + powerKernel = false; + } else { + //read the file + QTextStream in( &file ); + QStringList freqList = in.readLine().split(" "); + int maxFreq = freqList.at(0).toInt(); + + //close the file + file.close(); + + if (maxFreq > DEFAULT_FREQUENCY) { + powerKernel = true; + } else { + powerKernel = false; + } + } + + //on non-power-kernels we can disable the overclocking and temperature options + if (!powerKernel) { + ui->checkBox_oc->setDisabled(true); + ui->checkBox_temperature->setDisabled(true); + } + //reset GUI reset(); @@ -117,3 +153,12 @@ bool Settings::useOverclocking() { return overclocking; } + + +/** + * Returns true if QCPUFreq is running on a power kernel. + */ +bool Settings::usePowerKernel() +{ + return powerKernel; +} diff --git a/src/settings.h b/src/settings.h index 921e237..b061e22 100644 --- a/src/settings.h +++ b/src/settings.h @@ -19,6 +19,7 @@ public: bool useAdvancedTemperature(); bool useAutoRotate(); bool useOverclocking(); + bool usePowerKernel(); public slots: void reset(); @@ -29,6 +30,7 @@ private: bool advancedTemperature; bool autoRotate; bool overclocking; + bool powerKernel; QSettings settings; Ui::Settings *ui; };