From: Daniel Klaffenbach Date: Mon, 27 Dec 2010 11:50:33 +0000 (+0100) Subject: Remove old init() method, partially move code to calculateMinFreq() X-Git-Tag: v0.4.3~3 X-Git-Url: https://vcs.maemo.org/git/?p=qcpufreq;a=commitdiff_plain;h=33c5e252b2b68c87e27379050fc7fd5401b021c2 Remove old init() method, partially move code to calculateMinFreq() --- diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f89e370..cf21237 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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: diff --git a/src/mainwindow.h b/src/mainwindow.h index c895bf2..17edd40 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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 );