Settings: check if we are using a power kernel
authorDaniel Klaffenbach <danielklaffenbach@gmail.com>
Wed, 3 Nov 2010 22:47:29 +0000 (23:47 +0100)
committerDaniel Klaffenbach <danielklaffenbach@gmail.com>
Wed, 3 Nov 2010 22:47:29 +0000 (23:47 +0100)
src/settings.cpp
src/settings.h

index d660d0c..a0b78f7 100644 (file)
@@ -1,11 +1,15 @@
 #include "settings.h"
 #include "ui_settings.h"
 
+#include <QFile>
 #include <QMessageBox>
+#include <QStringList>
+#include <QTextStream>
 #if defined(Q_WS_MAEMO_5)
     #include <QMaemo5InformationBox>
 #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;
+}
index 921e237..b061e22 100644 (file)
@@ -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;
 };