00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "acpi.h"
00026 #include "version.h"
00027 #include "portable.h"
00028 #include <stdlib.h>
00029 #include <unistd.h>
00030
00031
00032 #include <klocale.h>
00033 #include <kconfig.h>
00034 #include <knuminput.h>
00035 #include <kiconloader.h>
00036 #include <kicondialog.h>
00037 #include <kapplication.h>
00038 #include <kmessagebox.h>
00039 #include <kstandarddirs.h>
00040 #include <kprocess.h>
00041
00042
00043 #include <QLayout>
00044 #include <QLabel>
00045 #include <QCheckBox>
00046 #include <q3hbox.h>
00047 #include <q3grid.h>
00048 #include <QPushButton>
00049
00050
00051 #include <QVBoxLayout>
00052 #include <QHBoxLayout>
00053 extern void wake_laptop_daemon();
00054
00055 AcpiConfig::AcpiConfig (const KComponentData &inst,QWidget * parent)
00056 : KCModule(inst,parent)
00057 {
00058 KGlobal::locale()->insertCatalog("klaptopdaemon");
00059
00060 config = new KConfig("kcmlaptoprc");
00061
00062 QVBoxLayout *top_layout = new QVBoxLayout( this );
00063 top_layout->setMargin( KDialog::marginHint() );
00064 top_layout->setSpacing( KDialog::spacingHint() );
00065
00066 QLabel *tmp_label = new QLabel( i18n("This panel provides information about your system's ACPI implementation "
00067 "and lets you have access to some of the extra features provided by ACPI"), this );
00068 tmp_label->setWordWrap(true);
00069 top_layout->addWidget( tmp_label );
00070
00071 tmp_label = new QLabel( i18n("NOTE: the Linux ACPI implementation is still a 'work in progress'. "
00072 "Some features, in particular suspend and hibernate are not yet available "
00073 "under 2.4 - and under 2.5 some particular ACPI implementations are still "
00074 "unstable, these check boxes let you only enable the things that work reliably. "
00075 "You should test these features very gingerly - save all your work, check them "
00076 "on and try a suspend/standby/hibernate from the popup menu on the battery icon "
00077 "in the panel if it fails to come back successfully uncheck the box again."), this );
00078 tmp_label->setWordWrap(true);
00079 top_layout->addWidget( tmp_label );
00080
00081 tmp_label = new QLabel( i18n("Some changes made on this page may require you to quit the laptop panel "
00082 "and start it again to take effect"), this );
00083 tmp_label->setWordWrap(true);
00084 top_layout->addWidget( tmp_label );
00085
00086 bool can_enable = laptop_portable::has_acpi(1);
00087 enableStandby = new QCheckBox( i18n("Enable standby"), this );
00088 top_layout->addWidget( enableStandby );
00089 enableStandby->setToolTip( i18n( "If checked this box enables transitions to the 'standby' state - a temporary powered down state" ) );
00090 enableStandby->setEnabled(can_enable);
00091 connect( enableStandby, SIGNAL(clicked()), this, SLOT(configChanged()) );
00092
00093 enableSuspend = new QCheckBox( i18n("Enable &suspend"), this );
00094 top_layout->addWidget( enableSuspend );
00095 enableSuspend->setToolTip( i18n( "If checked this box enables transitions to the 'suspend' state - a semi-powered down state, sometimes called 'suspend-to-ram'" ) );
00096 enableSuspend->setEnabled(can_enable);
00097 connect( enableSuspend, SIGNAL(clicked()), this, SLOT(configChanged()) );
00098
00099 QHBoxLayout *ll = new QHBoxLayout();
00100 enableHibernate = new QCheckBox( i18n("Enable &hibernate"), this );
00101 ll->addWidget( enableHibernate );
00102 enableHibernate->setToolTip( i18n( "If checked this box enables transitions to the 'hibernate' state - a powered down state, sometimes called 'suspend-to-disk'" ) );
00103 enableHibernate->setEnabled(can_enable);
00104 connect( enableHibernate, SIGNAL(clicked()), this, SLOT(configChanged()) );
00105 if (laptop_portable::has_software_suspend()) {
00106 ll->addStretch(1);
00107 enableSoftwareSuspendHibernate = new QCheckBox( i18n("Use software suspend for hibernate"), this );
00108 ll->addWidget( enableSoftwareSuspendHibernate );
00109 enableSoftwareSuspendHibernate->setToolTip( i18n( "If checked this box enables transitions to the 'hibernate' state - a powered down state, sometimes called 'suspend-to-disk' - the kernel 'Software Suspend' mechanism will be used instead of using ACPI directly" ) );
00110 enableSoftwareSuspendHibernate->setEnabled(laptop_portable::has_software_suspend(2));
00111 connect( enableSoftwareSuspendHibernate, SIGNAL(clicked()), this, SLOT(configChanged()) );
00112 } else {
00113 enableSoftwareSuspendHibernate = 0;
00114 }
00115 ll->addStretch(10);
00116
00117 top_layout->addLayout(ll);
00118
00119 enablePerformance = new QCheckBox( i18n("Enable &performance profiles"), this );
00120 top_layout->addWidget( enablePerformance );
00121 enablePerformance->setToolTip( i18n( "If checked this box enables access to ACPI performance profiles - usually OK in 2.4 and later" ) );
00122 enablePerformance->setEnabled(can_enable);
00123 connect( enablePerformance, SIGNAL(clicked()), this, SLOT(configChanged()) );
00124
00125 enableThrottle = new QCheckBox( i18n("Enable &CPU throttling"), this );
00126 top_layout->addWidget( enableThrottle );
00127 enableThrottle->setToolTip( i18n( "If checked this box enables access to ACPI throttle speed changes - usually OK in 2.4 and later" ) );
00128 enableThrottle->setEnabled(can_enable);
00129 connect( enableThrottle, SIGNAL(clicked()), this, SLOT(configChanged()) );
00130
00131 tmp_label = new QLabel(i18n("If the above boxes are disabled then there is no 'helper' "
00132 "application set up to help change ACPI states, there are two "
00133 "ways you can enable this application, either make the file "
00134 "/proc/acpi/sleep writeable by anyone every time your system boots "
00135 "or use the button below to make the KDE ACPI helper application "
00136 "set-uid root"), this );
00137 tmp_label->setWordWrap(true);
00138 top_layout->addWidget( tmp_label );
00139 ll = new QHBoxLayout();
00140 QPushButton *setupButton = new QPushButton(i18n("Setup Helper Application"), this);
00141 connect( setupButton, SIGNAL(clicked()), this, SLOT(setupHelper()) );
00142 setupButton->setToolTip( i18n( "This button can be used to enable the ACPI helper application" ) );
00143 ll->addStretch(2);
00144 ll->addWidget(setupButton);
00145 ll->addStretch(8);
00146 top_layout->addLayout(ll);
00147
00148
00149 top_layout->addStretch(1);
00150 top_layout->addWidget( new QLabel( i18n("Version: %1", QString(LAPTOP_VERSION)), this), 0, Qt::AlignRight );
00151
00152
00153 load();
00154 }
00155
00156 AcpiConfig::~AcpiConfig()
00157 {
00158 delete config;
00159 }
00160
00161 #include "checkcrc.h"
00162 #include "crcresult.h"
00163 #include <QFile>
00164
00165 void AcpiConfig::setupHelper()
00166 {
00167 unsigned long len, crc;
00168 QString helper = KStandardDirs::findExe("klaptop_acpi_helper");
00169 checkcrc(QFile::encodeName(helper), len, crc);
00170 if (len != file_len || crc != file_crc) {
00171 QString str(i18n("The %1 application does not seem to have "
00172 "the same size or checksum as when it was compiled we do NOT recommend "
00173 "you proceed with making it setuid-root without further investigation", helper));
00174 int rc = KMessageBox::warningContinueCancel(0, str, i18n("KLaptopDaemon"), i18n("Run Nevertheless"));
00175 if (rc != KMessageBox::Continue)
00176 return;
00177 }
00178
00179 QString kdesu = KStandardDirs::findExe("kdesu");
00180 if (!kdesu.isEmpty()) {
00181 int rc = KMessageBox::warningContinueCancel(0,
00182 i18n("You will need to supply a root password "
00183 "to allow the privileges of the klaptop_acpi_helper to change."),
00184 i18n("KLaptopDaemon"), KStandardGuiItem::cont(),
00185 "");
00186 if (rc == KMessageBox::Continue) {
00187 KProcess proc;
00188 proc << kdesu;
00189 proc << "-u";
00190 proc << "root";
00191 proc << "chown root "+helper+"; chmod +s "+helper;
00192 proc.execute();
00193 }
00194 } else {
00195 KMessageBox::sorry(0, i18n("The ACPI helper cannot be enabled because kdesu cannot be found. Please make sure that it is installed correctly."),
00196 i18n("KLaptopDaemon"));
00197 }
00198 laptop_portable::acpi_set_mask(enablestandby, enablesuspend, enablehibernate, enableperformance, enablethrottle);
00199 bool can_enable = laptop_portable::has_acpi(1);
00200 enableStandby->setEnabled(can_enable);
00201 enableSuspend->setEnabled(can_enable);
00202 enableHibernate->setEnabled(can_enable);
00203 enablePerformance->setEnabled(can_enable);
00204 enableThrottle->setEnabled(can_enable);
00205 if (enableSoftwareSuspendHibernate)
00206 enableSoftwareSuspendHibernate->setEnabled(laptop_portable::has_software_suspend(2));
00207 wake_laptop_daemon();
00208 }
00209
00210
00211 void AcpiConfig::save()
00212 {
00213 enablestandby = enableStandby->isChecked();
00214 enablesuspend = enableSuspend->isChecked();
00215 enablehibernate = enableHibernate->isChecked();
00216 enablesoftwaresuspend = (enableSoftwareSuspendHibernate?enableSoftwareSuspendHibernate->isChecked():0);
00217 enableperformance = enablePerformance->isChecked();
00218 enablethrottle = enableThrottle->isChecked();
00219 laptop_portable::acpi_set_mask(enablestandby, enablesuspend, enablehibernate, enableperformance, enablethrottle);
00220
00221 config->setGroup("AcpiDefault");
00222
00223 config->writeEntry("EnableStandby", enablestandby);
00224 config->writeEntry("EnableSuspend", enablesuspend);
00225 config->writeEntry("EnableHibernate", enablehibernate);
00226 config->writeEntry("EnableThrottle", enablethrottle);
00227 config->writeEntry("EnablePerformance", enableperformance);
00228 config->setGroup("SoftwareSuspendDefault");
00229 config->writeEntry("EnableHibernate", enablesoftwaresuspend);
00230 config->sync();
00231 changed(false);
00232 wake_laptop_daemon();
00233 }
00234
00235 void AcpiConfig::load()
00236 {
00237 config->setGroup("AcpiDefault");
00238
00239 enablestandby = config->readEntry("EnableStandby", false);
00240 enableStandby->setChecked(enablestandby);
00241 enablesuspend = config->readEntry("EnableSuspend", false);
00242 enableSuspend->setChecked(enablesuspend);
00243 enablehibernate = config->readEntry("EnableHibernate", false);
00244 enableHibernate->setChecked(enablehibernate);
00245 enableperformance = config->readEntry("EnablePerformance", false);
00246 enablePerformance->setChecked(enableperformance);
00247 enablethrottle = config->readEntry("EnableThrottle", false);
00248 enableThrottle->setChecked(enablethrottle);
00249 config->setGroup("SoftwareSuspendDefault");
00250 enablesoftwaresuspend = config->readEntry("EnableHibernate", false);
00251 if (enableSoftwareSuspendHibernate)
00252 enableSoftwareSuspendHibernate->setChecked(enablesoftwaresuspend);
00253 changed(false);
00254 }
00255
00256 void AcpiConfig::defaults()
00257 {
00258 enablestandby = false;
00259 enableStandby->setChecked(enablestandby);
00260 enablesuspend = false;
00261 enableSuspend->setChecked(enablesuspend);
00262 enablehibernate = false;
00263 enableHibernate->setChecked(enablehibernate);
00264 enableperformance = false;
00265 enablePerformance->setChecked(enableperformance);
00266 enablethrottle = false;
00267 enableThrottle->setChecked(enablethrottle);
00268 enablesoftwaresuspend = false;
00269 if (enableSoftwareSuspendHibernate)
00270 enableSoftwareSuspendHibernate->setChecked(enablesoftwaresuspend);
00271
00272 changed(true);
00273 }
00274
00275
00276 void AcpiConfig::configChanged()
00277 {
00278 emit changed(true);
00279 }
00280
00281
00282 QString AcpiConfig::quickHelp() const
00283 {
00284 return i18n("<h1>ACPI Setup</h1>This module allows you to configure ACPI for your system");
00285 }
00286
00287 #include "acpi.moc"
00288
00289