Remove old init() method, partially move code to calculateMinFreq()
authorDaniel Klaffenbach <danielklaffenbach@gmail.com>
Mon, 27 Dec 2010 11:50:33 +0000 (12:50 +0100)
committerDaniel Klaffenbach <danielklaffenbach@gmail.com>
Mon, 27 Dec 2010 11:50:33 +0000 (12:50 +0100)
src/mainwindow.cpp
src/mainwindow.h

index f89e370..cf21237 100644 (file)
@@ -58,7 +58,17 @@ MainWindow::MainWindow(QWidget *parent) :
     loadPresetDialog = new LoadPreset;
     loadPresetDialog->hide();
 
-    init();
+    //enable save and load option on power kernels
+    if (settings->usePowerKernel() && settings->isKernelConfigInstalled()) {
+        ui->actionSave->setEnabled(true);
+        //loading presets may cause overclocking - only enable it if overclokcing is enabled
+        if (settings->useOverclocking()) {
+            ui->actionLoad->setEnabled(true);
+        }
+    }
+
+    //display the correct minimum frequency
+    calculateMinFreq();
 
     //applies the settings from the settings dialog
     applySettings();
@@ -191,6 +201,47 @@ void MainWindow::applySettings()
 
 
 /**
+  * Calculates the minimum frequency according to scaling_min_freq and avoid_frequencies.
+  *
+  * Since this is a somewhat complex calculation it sould only be performed when it is
+  * really necessary (on startup, after loading presets, etc.).
+  */
+void MainWindow::calculateMinFreq()
+{
+    this->minFreq = 0;
+    QString freqs = readSysFile( "devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies" );
+    QStringList freqList = freqs.split( " " );
+    //change the order of the QStringList - last element becomes first
+    for (int i=freqList.size() - 1; i>=0; --i) {
+        if (freqList.at(i) != "")
+            this->scalingFrequencies << freqList.at(i);
+    }
+    this->scalingSteps = (this->scalingFrequencies.size());
+
+    //set minFreq and check avoid_frequencies
+    QString min = readSysFile( "devices/system/cpu/cpu0/cpufreq/scaling_min_freq" );
+    //check if avoid file exists (only on power kernel)
+    QFile file( "/sys/devices/system/cpu/cpu0/cpufreq/ondemand/avoid_frequencies" );
+    if (file.exists()) {
+        QString avoid = readSysFile( "devices/system/cpu/cpu0/cpufreq/ondemand/avoid_frequencies" );
+        QStringList avoidList = avoid.split( " " );
+
+        //check if min is in avoid_frequencies
+        for (int i = getScalingStep( min.toInt() ); i <= this->scalingSteps; ++i) {
+            min.setNum( getScalingFreq(i) );
+            if (!avoidList.contains(min)) {
+                this->minFreq = min.toInt();
+                break;
+            }
+        }
+    } else {
+        this->minFreq = min.toInt();
+    }
+    file.close();
+}
+
+
+/**
   * Calls the QCPUFreq helper script with "sudo action param"
   *
   * @param  action : the action of the helper script
@@ -352,56 +403,6 @@ int MainWindow::getSmartReflexState()
 
 
 /**
-  * Initializes internal variables, such as:
-  *  - scalingSteps
-  *  - scalingFrequencies
-  *  - minFreq
-  */
-void MainWindow::init()
-{
-    this->minFreq = 0;
-    QString freqs = readSysFile( "devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies" );
-    QStringList freqList = freqs.split( " " );
-    //change the order of the QStringList - last element becomes first
-    for (int i=freqList.size() - 1; i>=0; --i) {
-        if (freqList.at(i) != "")
-            this->scalingFrequencies << freqList.at(i);
-    }
-    this->scalingSteps = (this->scalingFrequencies.size());
-
-    //set minFreq and check avoid_frequencies
-    QString min = readSysFile( "devices/system/cpu/cpu0/cpufreq/scaling_min_freq" );
-    //check if avoid file exists (only on power kernel)
-    QFile file( "/sys/devices/system/cpu/cpu0/cpufreq/ondemand/avoid_frequencies" );
-    if (file.exists()) {
-        QString avoid = readSysFile( "devices/system/cpu/cpu0/cpufreq/ondemand/avoid_frequencies" );
-        QStringList avoidList = avoid.split( " " );
-
-        //check if min is in avoid_frequencies
-        for (int i = getScalingStep( min.toInt() ); i <= this->scalingSteps; ++i) {
-            min.setNum( getScalingFreq(i) );
-            if (!avoidList.contains(min)) {
-                this->minFreq = min.toInt();
-                break;
-            }
-        }
-    } else {
-        this->minFreq = min.toInt();
-    }
-    file.close();
-
-    //enable save and load option on power kernels
-    if (settings->usePowerKernel() && settings->isKernelConfigInstalled()) {
-        ui->actionSave->setEnabled(true);
-        //loading presets may cause overclocking - only enable it if overclokcing is enabled
-        if (settings->useOverclocking()) {
-            ui->actionLoad->setEnabled(true);
-        }
-    }
-}
-
-
-/**
   * Loads a voltage preset by calling kernel-config.
   *
   * Available presets are:
index c895bf2..17edd40 100644 (file)
@@ -59,6 +59,7 @@ public slots:
 
 private:
     Ui::MainWindow *ui;
+    void calculateMinFreq();
     int callHelper( QString action, QString param );
     QString getCPUTemp();
     int getMaxFreq();
@@ -72,8 +73,6 @@ private:
     QProcess helperProcess;
     //! The help window
     HelpWindow helpWindow;
-    //! Initializes the application
-    void init();
     LoadPreset *loadPresetDialog;
     int minFreq;
     QString readSysFile( QString sys_file );