X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmainwindow.cpp;fp=src%2Fmainwindow.cpp;h=cf212370768673f815bde224a79e29851d955a8d;hb=33c5e252b2b68c87e27379050fc7fd5401b021c2;hp=f89e370cc8e5a46b089626959a1d0aea1800fda8;hpb=66671cd3a408d0bb97a85680ae776abb474c2934;p=qcpufreq 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: