• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

klaptopdaemon

power.cpp

Go to the documentation of this file.
00001 /*
00002  * power.cpp
00003  *
00004  * Copyright (c) 1999 Paul Campbell <paul@taniwha.com>
00005  * Copyright (c) 2002 Marc Mutz <mutz@kde.org>
00006  *
00007  * Requires the Qt widget libraries, available at no cost at
00008  * http://www.troll.no/
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023  */
00024 
00025 #include "power.h"
00026 #include "portable.h"
00027 #include "version.h"
00028 
00029 #include <kglobal.h>
00030 #include <klocale.h>
00031 #include <kconfig.h>
00032 #include <knumvalidator.h>
00033 #include <kdialog.h>
00034 #include <kapplication.h>
00035 #include <kcombobox.h>
00036 #include <knuminput.h>
00037 
00038 #include <QLayout>
00039 #include <QSpinBox>
00040 #include <qradiobutton.h>
00041 #include <QCheckBox>
00042 #include <q3hbox.h>
00043 #include <qslider.h>
00044 
00045 //Added by qt3to4:
00046 #include <QLabel>
00047 #include <QVBoxLayout>
00048 #include <QHBoxLayout>
00049 #include <Q3VButtonGroup>
00050 extern void wake_laptop_daemon();
00051 
00052 PowerConfig::PowerConfig (const KComponentData &inst,QWidget * parent)
00053   : KCModule(inst,parent),
00054     nopowerBox(0),
00055     nopowerStandby(0),
00056     nopowerSuspend(0),
00057     nopowerOff(0),
00058     nopowerHibernate(0),
00059     nopowerBrightness(0),
00060     nopowerValBrightness(0),
00061     nopowerThrottle(0),
00062     nopowerValThrottle(0),
00063     nopowerPerformance(0),
00064     nopowerValPerformance(0),
00065 
00066     powerBox(0),
00067     powerStandby(0),
00068     powerSuspend(0),
00069     powerOff(0),
00070     powerHibernate(0),
00071     powerBrightness(0),
00072     powerValBrightness(0),
00073     powerThrottle(0),
00074     powerValThrottle(0),
00075     powerPerformance(0),
00076     powerValPerformance(0),
00077 
00078 
00079     noeditwait(0),
00080     editwait(0),
00081     enablelav(0),
00082     noenablelav(0),
00083     noeditlav(0),
00084     editlav(0)
00085 {
00086   KGlobal::locale()->insertCatalog("klaptopdaemon"); // For translation of klaptopdaemon messages
00087 
00088   apm = laptop_portable::has_power_management();
00089   config =  new KConfig("kcmlaptoprc");
00090   int can_brightness = laptop_portable::has_brightness();
00091     QStringList throttle_list;
00092     int current_throttle;
00093     bool *active_list;
00094     bool has_throttle = laptop_portable::get_system_throttling(0, current_throttle, throttle_list, active_list);
00095     QStringList performance_list;
00096     int current_performance;
00097     bool has_performance = laptop_portable::get_system_performance(0, current_performance, performance_list, active_list);
00098 
00099   if (!apm && !can_brightness && !has_throttle && !has_performance) {
00100       QVBoxLayout *top_layout = new QVBoxLayout(this );
00101       top_layout->setMargin( KDialog::marginHint() );
00102       top_layout->setSpacing( KDialog::spacingHint() );
00103 
00104     K3ActiveLabel* explain = laptop_portable::no_power_management_explanation(this);
00105     top_layout->addWidget(explain);
00106 
00107     top_layout->addStretch(1);
00108   } else {
00109     int can_standby = laptop_portable::has_standby();
00110     int can_suspend = laptop_portable::has_suspend();
00111     int can_hibernate = laptop_portable::has_hibernation();
00112 
00113     if (!can_standby && !can_suspend && !can_hibernate && !can_brightness && !has_throttle && !has_performance)
00114       apm = 0;
00115     if (!apm) {
00116       QVBoxLayout *top_layout = new QVBoxLayout(this );
00117       top_layout->setMargin( KDialog::marginHint() );
00118       top_layout->setSpacing( KDialog::spacingHint() );
00119 
00120       QLabel* explain = laptop_portable::how_to_do_suspend_resume(this);
00121       top_layout->addWidget(explain);
00122 
00123       top_layout->addStretch(1);
00124     } else {
00125       QVBoxLayout *top_layout = new QVBoxLayout( this );
00126       top_layout->setMargin( KDialog::marginHint() );
00127       top_layout->setSpacing( KDialog::spacingHint() );
00128 
00129       QHBoxLayout *hlay = new QHBoxLayout( );
00130       top_layout->addItem( hlay );
00131 
00132       nopowerBox = new Q3VButtonGroup(i18n("Not Powered"), this);
00133       nopowerBox->setToolTip( i18n( "Options in this box apply when the laptop is unplugged from the wall and has been idle for a while" ) );
00134       nopowerBox->layout()->setSpacing( KDialog::spacingHint() );
00135       hlay->addWidget( nopowerBox );
00136 
00137       if (can_standby) {
00138     nopowerStandby = new QRadioButton(i18n("Standb&y"), nopowerBox);
00139         nopowerStandby->setToolTip( i18n( "Causes the laptop to change to a standby temporary-low power state" ) );
00140       }
00141       if (can_suspend) {
00142     nopowerSuspend = new QRadioButton(i18n("&Suspend"), nopowerBox);
00143         nopowerSuspend->setToolTip( i18n( "Causes the laptop to change to a suspend 'save-to-ram' state" ) );
00144       }
00145       if (can_hibernate) {
00146     nopowerHibernate = new QRadioButton(i18n("H&ibernate"), nopowerBox);
00147         nopowerHibernate->setToolTip( i18n( "Causes the laptop to change to a hibernate 'save-to-disk' state" ) );
00148       }
00149       if (can_suspend||can_standby||can_hibernate)
00150         nopowerOff = new QRadioButton(i18n("None"), nopowerBox);
00151       if (can_brightness) {
00152         nopowerBrightness = new QCheckBox(i18n("Brightness"), nopowerBox);
00153             nopowerBrightness->setToolTip( i18n( "Enables changing the laptop's back panel brightness" ) );
00154         QWidget *wp = new QWidget(nopowerBox);
00155             QHBoxLayout *xl = new QHBoxLayout( wp);
00156         xl->addWidget(new QLabel("-", wp));
00157         nopowerValBrightness = new QSlider(0, 255, 16, 255, Qt::Horizontal, wp);
00158             nopowerValBrightness->setToolTip( i18n( "How bright to change the back panel" ) );
00159         nopowerValBrightness->setEnabled(0);
00160         connect(nopowerValBrightness, SIGNAL(valueChanged(int)), this, SLOT(changed()));
00161         connect(nopowerBrightness, SIGNAL(toggled(bool)), nopowerValBrightness, SLOT(setEnabled(bool)));
00162         xl->addWidget(nopowerValBrightness);
00163         xl->addWidget(new QLabel("+", wp));
00164         xl->addStretch(1);
00165       }
00166       if (has_performance) {
00167         nopowerPerformance = new QCheckBox(i18n("System performance"), nopowerBox);
00168             nopowerPerformance->setToolTip( i18n( "Enables changing the laptop's performance profile" ) );
00169 
00170         QWidget *wp = new QWidget(nopowerBox);
00171             QHBoxLayout *xl = new QHBoxLayout( wp);
00172             nopowerValPerformance = new KComboBox(0, wp);
00173             nopowerValPerformance->setToolTip( i18n( "Which profile to change it to" ) );
00174         nopowerValPerformance->insertStringList(performance_list);
00175             nopowerValPerformance->setEnabled(0);
00176         connect(nopowerValPerformance, SIGNAL(activated(int)), this, SLOT(changed()));
00177         connect(nopowerPerformance, SIGNAL(toggled(bool)), nopowerValPerformance, SLOT(setEnabled(bool)));
00178         xl->addWidget(nopowerValPerformance);
00179         xl->addStretch(1);
00180       }
00181       if (has_throttle) {
00182         nopowerThrottle = new QCheckBox(i18n("CPU throttle"), nopowerBox);
00183             nopowerThrottle->setToolTip( i18n( "Enables throttling the laptop's CPU" ) );
00184 
00185         QWidget *wp = new QWidget(nopowerBox);
00186             QHBoxLayout *xl = new QHBoxLayout( wp);
00187             nopowerValThrottle = new KComboBox(0, wp);
00188             nopowerValThrottle->setToolTip( i18n( "How much to throttle the laptop's CPU" ) );
00189         nopowerValThrottle->insertStringList(throttle_list);
00190             nopowerValThrottle->setEnabled(0);
00191         connect(nopowerValThrottle, SIGNAL(activated(int)), this, SLOT(changed()));
00192         connect(nopowerThrottle, SIGNAL(toggled(bool)), nopowerValThrottle, SLOT(setEnabled(bool)));
00193         xl->addWidget(nopowerValThrottle);
00194         xl->addStretch(1);
00195       }
00196 
00197 
00198       connect(nopowerBox, SIGNAL(clicked(int)), this, SLOT(changed()));
00199 
00200       bool can_lav = laptop_portable::has_lav();
00201       Q3HBox *hbox;
00202       if (can_lav) {
00203           hbox = new Q3HBox( nopowerBox );
00204           noenablelav = new QCheckBox(i18n("Don't act if LAV is >"), hbox);
00205           connect(noenablelav, SIGNAL(clicked()), this, SLOT(changed()));
00206           noeditlav = new KDoubleSpinBox(0.0, 10.0, 0.0, 0.1, hbox, 1);
00207           noeditlav->setToolTip( i18n( "If enabled and the system load average is greater than this value none of the above options will be applied" ) );
00208           connect(noeditlav, SIGNAL(valueChanged(double)), this, SLOT(changed()));
00209           connect(noenablelav, SIGNAL(toggled(bool)), noeditlav, SLOT(setEnabled(bool)));
00210       }
00211 
00212       hbox = new Q3HBox( nopowerBox );
00213       QLabel* noedlabel = new QLabel(i18n("&Wait for:"), hbox);
00214       noeditwait = new QSpinBox( 1, 60*24 /*1 day*/, 1, hbox );
00215       noeditwait->setToolTip( i18n( "How long the computer has to be idle before these values take effect" ) );
00216       noeditwait->setSuffix( i18nc("keep short, unit in spinbox", "min") );
00217       noedlabel->setBuddy( noeditwait );
00218       hbox->setStretchFactor( noeditwait, 1 );
00219       connect( noeditwait, SIGNAL(valueChanged(int)), this, SLOT(changed()));
00220 
00221 
00223 
00224 
00225       powerBox = new Q3VButtonGroup(i18n("Powered"), this);
00226       powerBox->layout()->setSpacing( KDialog::spacingHint() );
00227       powerBox->setToolTip( i18n( "Options in this box apply when the laptop is plugged into the wall and has been idle for a while" ) );
00228       hlay->addWidget( powerBox );
00229 
00230       if (can_standby) {
00231     powerStandby = new QRadioButton(i18n("Sta&ndby"), powerBox);
00232         powerStandby->setToolTip( i18n( "Causes the laptop to change to a standby temporary-low power state" ) );
00233       }
00234       if (can_suspend) {
00235     powerSuspend = new QRadioButton(i18n("S&uspend"), powerBox);
00236         powerSuspend->setToolTip( i18n( "Causes the laptop to change to a suspend 'save-to-ram' state" ) );
00237       }
00238       if (can_hibernate) {
00239     powerHibernate = new QRadioButton(i18n("Hi&bernate"), powerBox);
00240         powerHibernate->setToolTip( i18n( "Causes the laptop to change to a hibernate 'save-to-disk' state" ) );
00241       }
00242       if (can_suspend||can_standby||can_hibernate)
00243         powerOff = new QRadioButton(i18n("None"), powerBox);
00244       if (can_brightness) {
00245         powerBrightness = new QCheckBox(i18n("Brightness"), powerBox);
00246             powerBrightness->setToolTip( i18n( "Enables changing the laptop's back panel brightness" ) );
00247         QWidget *wp = new QWidget(powerBox);
00248             QHBoxLayout *xl = new QHBoxLayout( wp);
00249         xl->addWidget(new QLabel("-", wp));
00250         powerValBrightness = new QSlider(0, 255, 16, 255, Qt::Horizontal, wp);
00251             powerValBrightness->setToolTip( i18n( "How bright to change the back panel" ) );
00252         powerValBrightness->setEnabled(0);
00253         connect(powerValBrightness, SIGNAL(valueChanged(int)), this, SLOT(changed()));
00254         connect(powerBrightness, SIGNAL(toggled(bool)), powerValBrightness, SLOT(setEnabled(bool)));
00255         xl->addWidget(powerValBrightness);
00256         xl->addWidget(new QLabel("+", wp));
00257         xl->addStretch(1);
00258       }
00259       if (has_performance) {
00260         powerPerformance = new QCheckBox(i18n("System performance"), powerBox);
00261             powerPerformance->setToolTip( i18n( "Enables changing the laptop's performance profile" ) );
00262 
00263         QWidget *wp = new QWidget(powerBox);
00264             QHBoxLayout *xl = new QHBoxLayout( wp);
00265             powerValPerformance = new KComboBox(0, wp);
00266             powerValPerformance->setToolTip( i18n( "Which profile to change it to" ) );
00267         powerValPerformance->insertStringList(performance_list);
00268             powerValPerformance->setEnabled(0);
00269         connect(powerValPerformance, SIGNAL(activated(int)), this, SLOT(changed()));
00270         connect(powerPerformance, SIGNAL(toggled(bool)), powerValPerformance, SLOT(setEnabled(bool)));
00271         xl->addWidget(powerValPerformance);
00272         xl->addStretch(1);
00273       }
00274       if (has_throttle) {
00275         powerThrottle = new QCheckBox(i18n("CPU throttle"), powerBox);
00276             powerThrottle->setToolTip( i18n( "Enables throttling the laptop's CPU" ) );
00277 
00278         QWidget *wp = new QWidget(powerBox);
00279             QHBoxLayout *xl = new QHBoxLayout( wp);
00280             powerValThrottle = new KComboBox(0, wp);
00281             powerValThrottle->setToolTip( i18n( "How much to throttle the laptop's CPU" ) );
00282         powerValThrottle->insertStringList(throttle_list);
00283             powerValThrottle->setEnabled(0);
00284         connect(powerValThrottle, SIGNAL(activated(int)), this, SLOT(changed()));
00285         connect(powerThrottle, SIGNAL(toggled(bool)), powerValThrottle, SLOT(setEnabled(bool)));
00286         xl->addWidget(powerValThrottle);
00287         xl->addStretch(1);
00288       }
00289 
00290       connect(powerBox, SIGNAL(clicked(int)), this, SLOT(changed()));
00291 
00292       if (can_lav) {
00293           hbox = new Q3HBox( powerBox );
00294           enablelav = new QCheckBox(i18n("Don't act if LAV is >"), hbox);
00295           connect( enablelav, SIGNAL(clicked()), this, SLOT(changed()));
00296           editlav = new KDoubleSpinBox(0.0, 10.0, 0.0, 0.1, hbox,1);
00297           editlav->setToolTip( i18n( "If enabled and the system load average is greater than this value none of the above options will be applied" ) );
00298           connect( editlav, SIGNAL(valueChanged(double)), this, SLOT(changed()));
00299           connect( enablelav, SIGNAL(toggled(bool)), editlav, SLOT(setEnabled(bool)) );
00300       }
00301 
00302       hbox = new Q3HBox( powerBox );
00303       QLabel* edlabel = new QLabel(i18n("Wai&t for:"), hbox);
00304       editwait = new QSpinBox( 1, 60*24 /*1 day*/, 1, hbox );
00305       editwait->setToolTip( i18n( "How long the computer has to be idle before these values take effect" ) );
00306       editwait->setSuffix( i18nc("keep short, unit in spinbox", "min") );
00307       edlabel->setBuddy( editwait );
00308       hbox->setStretchFactor( editwait, 1 );
00309       connect( editwait, SIGNAL(valueChanged(int)), this, SLOT(changed()));
00310 
00311       hlay->addStretch(1);
00312 
00313       QLabel* explain = new QLabel(i18n("This panel configures the behavior of the automatic power-down feature - "
00314                     "it works as a sort of extreme screen saver. You can configure different "
00315                     "timeouts and types of behavior depending on whether or not your laptop is "
00316                     "plugged in to the mains supply."), this );
00317       explain->setWordWrap( true );
00318       top_layout->addWidget(explain);
00319 
00320       if (can_standby) {
00321     QLabel* explain3 = new QLabel(i18n("Different laptops may respond to 'standby' in different ways - in many "
00322                     "it is only a temporary state and may not be useful for you."), this);
00323     explain3->setWordWrap( true );
00324     top_layout->addWidget(explain3, 0, Qt::AlignLeft);
00325       }
00326 
00327       top_layout->addStretch(1);
00328 
00329       top_layout->addWidget( new QLabel( i18n("Version: %1", QString(LAPTOP_VERSION)), this ), 0, Qt::AlignRight );
00330     }
00331   }
00332 
00333   load();
00334 }
00335 
00336 PowerConfig::~PowerConfig()
00337 {
00338   delete config;
00339 }
00340 
00341 void PowerConfig::save()
00342 {
00343   if (editwait) {
00344         power = getPower();
00345         nopower = getNoPower();
00346     edit_wait = editwait->value();
00347     noedit_wait = noeditwait->value();
00348     nopower_bright_enabled = (nopowerBrightness?nopowerBrightness->isChecked():0);
00349     power_bright_enabled = (powerBrightness?powerBrightness->isChecked():0);
00350     nopower_bright_val = (nopowerValBrightness?nopowerValBrightness->value():0);
00351     power_bright_val = (powerValBrightness?powerValBrightness->value():255);
00352     nopower_performance_enabled = (nopowerPerformance?nopowerPerformance->isChecked():0);
00353     power_performance_enabled = (powerPerformance?powerPerformance->isChecked():0);
00354     nopower_performance_val = (nopowerValPerformance?nopowerValPerformance->currentText():"");
00355     power_performance_val = (powerValPerformance?powerValPerformance->currentText():"");
00356     nopower_throttle_enabled = (nopowerThrottle?nopowerThrottle->isChecked():0);
00357     power_throttle_enabled = (powerThrottle?powerThrottle->isChecked():0);
00358     nopower_throttle_val = (nopowerValThrottle?nopowerValThrottle->currentText():"");
00359     power_throttle_val = (powerValThrottle?powerValThrottle->currentText():"");
00360     edit_lav = (editlav?editlav->value():-1);
00361     noedit_lav = (noeditlav?noeditlav->value():-1);
00362     lav_enabled = (enablelav?enablelav->isChecked():0);
00363     nolav_enabled = (noenablelav?noenablelav->isChecked():0);
00364   }
00365 
00366   config->setGroup("LaptopPower");
00367   config->writeEntry("NoPowerSuspend", nopower);
00368   config->writeEntry("PowerSuspend", power);
00369   config->writeEntry("PowerWait", edit_wait);
00370   config->writeEntry("NoPowerWait", noedit_wait);
00371   config->writeEntry("PowerLav", double(edit_lav));
00372   config->writeEntry("NoPowerLav", double(noedit_lav));
00373   config->writeEntry("LavEnabled", lav_enabled);
00374   config->writeEntry("NoLavEnabled", nolav_enabled);
00375   config->writeEntry("PowerBrightnessEnabled", power_bright_enabled);
00376   config->writeEntry("NoPowerBrightnessEnabled", nopower_bright_enabled);
00377   config->writeEntry("PowerBrightness", power_bright_val);
00378   config->writeEntry("NoPowerBrightness", nopower_bright_val);
00379   config->writeEntry("PowerPerformanceEnabled", power_performance_enabled);
00380   config->writeEntry("NoPowerPerformanceEnabled", nopower_performance_enabled);
00381   config->writeEntry("PowerPerformance", power_performance_val);
00382   config->writeEntry("NoPowerPerformance", nopower_performance_val);
00383   config->writeEntry("PowerThrottleEnabled", power_throttle_enabled);
00384   config->writeEntry("NoPowerThrottleEnabled", nopower_throttle_enabled);
00385   config->writeEntry("PowerThrottle", power_throttle_val);
00386   config->writeEntry("NoPowerThrottle", nopower_throttle_val);
00387   config->sync();
00388   changed(false);
00389   wake_laptop_daemon();
00390 }
00391 
00392 void PowerConfig::load()
00393 {
00394   config->setGroup("LaptopPower");
00395   nopower = config->readEntry("NoPowerSuspend", (nopowerStandby?1:nopowerSuspend?2:0));
00396   power = config->readEntry("PowerSuspend", 0);
00397   edit_wait = config->readEntry("PowerWait", 20);
00398   noedit_wait = config->readEntry("NoPowerWait", 5);
00399   edit_lav = config->readEntry("PowerLav", -1.0);
00400   noedit_lav = config->readEntry("NoPowerLav", -1.0);
00401   lav_enabled = config->readEntry("LavEnabled", 0);
00402   nolav_enabled = config->readEntry("NoLavEnabled", 0);
00403   nopower_bright_enabled = config->readEntry("NoPowerBrightnessEnabled", 0);
00404   power_bright_enabled = config->readEntry("PowerBrightnessEnabled", 0);
00405   nopower_bright_val = config->readEntry("NoPowerBrightness", 0);
00406   power_bright_val = config->readEntry("PowerBrightness", 255);
00407   nopower_performance_enabled = config->readEntry("NoPowerPerformanceEnabled", 0);
00408   power_performance_enabled = config->readEntry("PowerPerformanceEnabled", 0);
00409   nopower_performance_val = config->readEntry("NoPowerPerformance", "");
00410   power_performance_val = config->readEntry("PowerPerformance", "");
00411   nopower_throttle_enabled = config->readEntry("NoPowerThrottleEnabled", 0);
00412   power_throttle_enabled = config->readEntry("PowerThrottleEnabled", 0);
00413   nopower_throttle_val = config->readEntry("NoPowerThrottle", "");
00414   power_throttle_val = config->readEntry("PowerThrottle", "");
00415 
00416   // the GUI should reflect the real values
00417   if (editwait) {
00418     editwait->setValue(edit_wait);
00419     noeditwait->setValue(noedit_wait);
00420     if (editlav) {
00421         editlav->setValue(edit_lav);
00422         editlav->setEnabled(lav_enabled);
00423     }
00424     if (noeditlav) {
00425         noeditlav->setValue(noedit_lav);
00426         noeditlav->setEnabled(nolav_enabled);
00427     }
00428     if (enablelav)
00429         enablelav->setChecked(lav_enabled);
00430     if (noenablelav)
00431         noenablelav->setChecked(nolav_enabled);
00432     setPower(power, nopower);
00433     if (nopowerBrightness)
00434         nopowerBrightness->setChecked(nopower_bright_enabled);
00435     if (powerBrightness)
00436         powerBrightness->setChecked(power_bright_enabled);
00437     if (nopowerValBrightness) {
00438         nopowerValBrightness->setValue(nopower_bright_val);
00439         nopowerValBrightness->setEnabled(nopower_bright_enabled);
00440     }
00441     if (powerValBrightness) {
00442         powerValBrightness->setValue(power_bright_val);
00443         powerValBrightness->setEnabled(power_bright_enabled);
00444     }
00445     if (nopowerPerformance)
00446         nopowerPerformance->setChecked(nopower_performance_enabled);
00447     if (powerPerformance)
00448         powerPerformance->setChecked(power_performance_enabled);
00449     if (nopowerValPerformance) {
00450         int ind = 0;
00451         for (int i = 0; i < nopowerValPerformance->count(); i++)
00452         if (nopowerValPerformance->text(i) == nopower_performance_val) {
00453             ind = i;
00454             break;
00455         }
00456         nopowerValPerformance->setCurrentItem(ind);
00457         nopowerValPerformance->setEnabled(nopower_performance_enabled);
00458     }
00459     if (powerValPerformance) {
00460         int ind = 0;
00461         for (int i = 0; i < powerValPerformance->count(); i++)
00462         if (powerValPerformance->text(i) == power_performance_val) {
00463             ind = i;
00464             break;
00465         }
00466         powerValPerformance->setCurrentItem(ind);
00467         powerValPerformance->setEnabled(power_performance_enabled);
00468     }
00469     if (nopowerThrottle)
00470         nopowerThrottle->setChecked(nopower_throttle_enabled);
00471     if (powerThrottle)
00472         powerThrottle->setChecked(power_throttle_enabled);
00473     if (nopowerValThrottle) {
00474         int ind = 0;
00475         for (int i = 0; i < nopowerValThrottle->count(); i++)
00476         if (nopowerValThrottle->text(i) == nopower_throttle_val) {
00477             ind = i;
00478             break;
00479         }
00480         nopowerValThrottle->setCurrentItem(ind);
00481         nopowerValThrottle->setEnabled(nopower_throttle_enabled);
00482     }
00483     if (powerValThrottle) {
00484         int ind = 0;
00485         for (int i = 0; i < powerValThrottle->count(); i++)
00486         if (powerValThrottle->text(i) == power_throttle_val) {
00487             ind = i;
00488             break;
00489         }
00490         powerValThrottle->setCurrentItem(ind);
00491         powerValThrottle->setEnabled(power_throttle_enabled);
00492     }
00493   }
00494   changed(false);
00495 }
00496 
00497 void PowerConfig::defaults()
00498 {
00499   setPower(1, 0);
00500   edit_wait = 20;
00501   noedit_wait = 5;
00502   nopower_bright_enabled = 0;
00503   power_bright_enabled = 0;
00504   nopower_bright_val = 0;
00505   power_bright_val = 0;
00506   nopower_performance_enabled = 0;
00507   power_performance_enabled = 0;
00508   nopower_performance_val = "";
00509   power_performance_val = "";
00510   nopower_throttle_enabled = 0;
00511   power_throttle_enabled = 0;
00512   nopower_throttle_val = "";
00513   power_throttle_val = "";
00514   lav_enabled = 0;
00515   nolav_enabled = 0;
00516   edit_lav = -1;
00517   noedit_lav = -1;
00518   if (editwait) {
00519     editwait->setValue(edit_wait);
00520         noeditwait->setValue(noedit_wait);
00521     if (editlav) {
00522         editlav->setValue(edit_lav);
00523         editlav->setEnabled(lav_enabled);
00524     }
00525     if (noeditlav) {
00526         noeditlav->setValue(noedit_lav);
00527         noeditlav->setEnabled(nolav_enabled);
00528     }
00529     if (enablelav)
00530         enablelav->setChecked(lav_enabled);
00531     if (noenablelav)
00532         noenablelav->setChecked(nolav_enabled);
00533     if (nopowerBrightness)
00534         nopowerBrightness->setChecked(nopower_bright_enabled);
00535     if (powerBrightness)
00536         powerBrightness->setChecked(power_bright_enabled);
00537     if (nopowerValBrightness) {
00538         nopowerValBrightness->setValue(nopower_bright_val);
00539         nopowerValBrightness->setEnabled(nopower_bright_enabled);
00540     }
00541     if (powerValBrightness) {
00542         powerValBrightness->setValue(power_bright_val);
00543         powerValBrightness->setEnabled(power_bright_enabled);
00544     }
00545 
00546 
00547     if (nopowerPerformance)
00548         nopowerPerformance->setChecked(nopower_performance_enabled);
00549     if (powerPerformance)
00550         powerPerformance->setChecked(power_performance_enabled);
00551     if (nopowerValPerformance) {
00552         nopowerValPerformance->setCurrentItem(0);
00553         nopowerValPerformance->setEnabled(nopower_performance_enabled);
00554     }
00555     if (powerValPerformance) {
00556         powerValPerformance->setCurrentItem(0);
00557         powerValPerformance->setEnabled(power_performance_enabled);
00558     }
00559     if (nopowerThrottle)
00560         nopowerThrottle->setChecked(nopower_throttle_enabled);
00561     if (powerThrottle)
00562         powerThrottle->setChecked(power_throttle_enabled);
00563     if (nopowerValThrottle) {
00564         nopowerValThrottle->setCurrentItem(0);
00565         nopowerValThrottle->setEnabled(nopower_throttle_enabled);
00566     }
00567     if (powerValThrottle) {
00568         powerValThrottle->setCurrentItem(0);
00569         powerValThrottle->setEnabled(power_throttle_enabled);
00570     }
00571   }
00572   changed(true);
00573 }
00574 
00575 int  PowerConfig::getNoPower()
00576 {
00577   if (!apm)
00578     return(nopower);
00579   if (nopowerHibernate && nopowerHibernate->isChecked())
00580     return 3;
00581   if (nopowerStandby && nopowerStandby->isChecked())
00582     return 1;
00583   if (nopowerSuspend && nopowerSuspend->isChecked())
00584     return 2;
00585   return(0);
00586 }
00587 
00588 int  PowerConfig::getPower()
00589 {
00590   if (!apm || !powerOff)
00591     return(power);
00592   if (powerHibernate && powerHibernate->isChecked())
00593     return 3;
00594   if (powerStandby && powerStandby->isChecked())
00595     return 1;
00596   if (powerSuspend && powerSuspend->isChecked())
00597     return 2;
00598   return(0);
00599 }
00600 
00601 void PowerConfig::setPower(int p, int np)
00602 {
00603   if (!apm || nopowerOff == 0)
00604     return;
00605   if (nopowerSuspend) {
00606     nopowerSuspend->setChecked(false);
00607   } else {
00608     if (np == 2) np = 0;
00609   }
00610   if (nopowerStandby) {
00611     nopowerStandby->setChecked(false);
00612   } else {
00613     if (np == 1) np = 0;
00614   }
00615   if (nopowerHibernate) {
00616     nopowerHibernate->setChecked(false);
00617   } else {
00618     if (np == 3) np = 0;
00619   }
00620   if (nopowerOff)
00621       nopowerOff->setChecked(false);
00622   switch (np) {
00623   case 0: nopowerOff->setChecked(true);break;
00624   case 1: nopowerStandby->setChecked(true);break;
00625   case 2: nopowerSuspend->setChecked(true);break;
00626   case 3: nopowerHibernate->setChecked(true);break;
00627   }
00628   if (powerSuspend) {
00629     powerSuspend->setChecked(false);
00630   } else {
00631     if (p == 2) p = 0;
00632   }
00633   if (powerStandby) {
00634     powerStandby->setChecked(false);
00635   } else {
00636     if (p == 1) p = 0;
00637   }
00638   if (powerHibernate) {
00639     powerHibernate->setChecked(false);
00640   } else {
00641     if (p == 3) p = 0;
00642   }
00643   if (powerOff)
00644     powerOff->setChecked(false);
00645   switch (p) {
00646   case 0: powerOff->setChecked(true);break;
00647   case 1: powerStandby->setChecked(true);break;
00648   case 2: powerSuspend->setChecked(true);break;
00649   case 3: powerHibernate->setChecked(true);break;
00650   }
00651 }
00652 
00653 
00654 QString PowerConfig::quickHelp() const
00655 {
00656   return i18n("<h1>Laptop Power Control</h1>This module allows you to "
00657     "control the power settings of your laptop and set timouts that will trigger "
00658     "state changes you can use to save power");
00659 
00660 }
00661 
00662 #include "power.moc"

klaptopdaemon

Skip menu "klaptopdaemon"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal