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 <klocale.h>
00026 #include <k3process.h>
00027 #include <kconfig.h>
00028 #include <kglobal.h>
00029 #include <QLayout>
00030
00031 #include <QVBoxLayout>
00032 #include <unistd.h>
00033 #include <fcntl.h>
00034
00035 #include "main.h"
00036 #include "version.h"
00037 #include "warning.h"
00038 #include "power.h"
00039 #include "battery.h"
00040 #include "buttons.h"
00041 #include "pcmcia.h"
00042 #include "acpi.h"
00043 #include "apm.h"
00044 #include "sony.h"
00045 #include "profile.h"
00046 #include "portable.h"
00047 extern void wake_laptop_daemon();
00048
00049
00050 extern "C"
00051 {
00052
00053 KDE_EXPORT KCModule *create_pcmcia(QWidget *parent, const char *)
00054 {
00055 KLocale::setMainCatalog("klaptopdaemon");
00056 KComponentData inst("kcmlaptop");
00057 return new PcmciaConfig(inst,parent);
00058 }
00059
00060 KDE_EXPORT KCModule *create_bwarning(QWidget *parent, const char *)
00061 {
00062 KLocale::setMainCatalog("klaptopdaemon");
00063 KComponentData inst("kcmlaptop");
00064 return new WarningConfig(0, inst,parent);
00065 }
00066 KDE_EXPORT KCModule *create_cwarning(QWidget *parent, const char *)
00067 {
00068 KLocale::setMainCatalog("klaptopdaemon");
00069 KComponentData inst("kcmlaptop");
00070 return new WarningConfig(1, inst, parent);
00071 }
00072 KDE_EXPORT KCModule *create_battery(QWidget *parent, const char *)
00073 {
00074 KLocale::setMainCatalog("klaptopdaemon");
00075 KComponentData inst("kcmlaptop");
00076 return new BatteryConfig(inst,parent);
00077 }
00078 KDE_EXPORT KCModule *create_power(QWidget *parent, const char *)
00079 {
00080 KLocale::setMainCatalog("klaptopdaemon");
00081 KComponentData inst("kcmlaptop");
00082 return new PowerConfig(inst,parent);
00083 }
00084 KDE_EXPORT KCModule *create_acpi(QWidget *parent, const char *)
00085 {
00086 KLocale::setMainCatalog("klaptopdaemon");
00087 KComponentData inst("kcmlaptop");
00088 return new AcpiConfig(inst,parent);
00089 }
00090 KDE_EXPORT KCModule *create_apm(QWidget *parent, const char *)
00091 {
00092 KLocale::setMainCatalog("klaptopdaemon");
00093 KComponentData inst("kcmlaptop");
00094 return new ApmConfig(inst, parent);
00095 }
00096 KDE_EXPORT KCModule *create_Profile(QWidget *parent, const char *)
00097 {
00098 KLocale::setMainCatalog("klaptopdaemon");
00099 KComponentData inst("kcmlaptop");
00100 return new ProfileConfig(inst,parent);
00101 }
00102 KDE_EXPORT KCModule *create_sony(QWidget *parent, const char *)
00103 {
00104 KLocale::setMainCatalog("klaptopdaemon");
00105 KComponentData inst("kcmlaptop");
00106 return new SonyConfig(inst,parent);
00107 }
00108 KDE_EXPORT KCModule *create_buttons(QWidget *parent, const char *)
00109 {
00110 KLocale::setMainCatalog("klaptopdaemon");
00111 KComponentData inst("kcmlaptop");
00112 return new ButtonsConfig(inst,parent);
00113 }
00114
00115 KDE_EXPORT void init_battery()
00116 {
00117 KConfig config("kcmlaptoprc", true , false );
00118 config.setGroup("BatteryDefault");
00119 bool enable = false;
00120 if (!config.hasKey("Enable")) {
00121 struct power_result pr = laptop_portable::poll_battery_state();
00122 if ((laptop_portable::has_power_management() &&
00123 !(pr.powered &&
00124 (pr.percentage < 0 || pr.percentage == 0xff)))||
00125 0 == access("/var/run/stab", R_OK|F_OK) ||
00126 0 == access("/var/lib/pcmcia/stab", R_OK|F_OK))
00127 enable = true;
00128 } else {
00129 enable = config.readEntry("Enable", false);
00130 }
00131 if (!enable)
00132 return;
00133 wake_laptop_daemon();
00134 }
00135
00136 KDE_EXPORT KCModule *create_laptop(QWidget *parent, const char *)
00137 {
00138 KLocale::setMainCatalog("klaptopdaemon");
00139 KComponentData inst("kcmlaptop");
00140 return new LaptopModule(inst,parent);
00141 }
00142
00143 KDE_EXPORT void init_laptop()
00144 {
00145 init_battery();
00146 }
00147 }
00148
00149
00150
00151 LaptopModule::LaptopModule(const KComponentData &inst,QWidget *parent)
00152 : KCModule(inst, parent)
00153 {
00154 {
00155 KConfig config("kcmlaptoprc", true , false );
00156 config.setGroup("AcpiDefault");
00157
00158 bool enablestandby = config.readEntry("EnableStandby", false);
00159 bool enablesuspend = config.readEntry("EnableSuspend", false);
00160 bool enablehibernate = config.readEntry("EnableHibernate", false);
00161 bool enableperformance = config.readEntry("EnablePerformance", false);
00162 bool enablethrottle = config.readEntry("EnableThrottle", false);
00163 laptop_portable::acpi_set_mask(enablestandby, enablesuspend, enablehibernate, enableperformance, enablethrottle);
00164
00165 config.setGroup("ApmDefault");
00166
00167 enablestandby = config.readEntry("EnableStandby", false);
00168 enablesuspend = config.readEntry("EnableSuspend", false);
00169 laptop_portable::apm_set_mask(enablestandby, enablesuspend);
00170 config.setGroup("SoftwareSuspendDefault");
00171 enablehibernate = config.readEntry("EnableHibernate", false);
00172 laptop_portable::software_suspend_set_mask(enablehibernate);
00173 }
00174 QVBoxLayout *layout = new QVBoxLayout(this);
00175 tab = new QTabWidget(this);
00176 layout->addWidget(tab);
00177
00178 battery = new BatteryConfig(inst,parent);
00179 tab->addTab(battery, i18n("&Battery"));
00180 connect(battery, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool)));
00181
00182 power = new PowerConfig(inst,parent);
00183 tab->addTab(power, i18n("&Power Control"));
00184 connect(power, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool)));
00185
00186 warning = new WarningConfig(0, inst,parent);
00187 tab->addTab(warning, i18n("Low Battery &Warning"));
00188 connect(warning, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool)));
00189
00190 critical = new WarningConfig(1, inst,parent);
00191 tab->addTab(critical, i18n("Low Battery &Critical"));
00192 connect(critical, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool)));
00193
00194 QStringList profile_list;
00195 int current_profile;
00196 bool *active_list;
00197 bool has_profile = laptop_portable::get_system_performance(0, current_profile, profile_list, active_list);
00198 QStringList throttle_list;
00199 int current_throttle;
00200 bool has_throttling = laptop_portable::get_system_throttling(0, current_throttle, throttle_list, active_list);
00201 if (laptop_portable::has_brightness() || has_profile || has_throttling) {
00202 profile = new ProfileConfig(inst,parent);
00203 tab->addTab(profile, i18n("Default Power Profiles"));
00204 connect(profile, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool)));
00205 } else {
00206 profile = 0;
00207 }
00208 if (laptop_portable::has_button(laptop_portable::LidButton) || laptop_portable::has_button(laptop_portable::PowerButton)) {
00209 buttons = new ButtonsConfig(inst,parent);
00210 tab->addTab(buttons, i18n("Button Actions"));
00211 connect(buttons, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool)));
00212 } else {
00213 buttons = 0;
00214 }
00215 if (laptop_portable::has_acpi()) {
00216 acpi = new AcpiConfig(inst,parent);
00217 tab->addTab(acpi, i18n("&ACPI Config"));
00218 connect(acpi, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool)));
00219 } else {
00220 acpi = 0;
00221 }
00222 if (laptop_portable::has_apm()) {
00223 apm = new ApmConfig(inst,parent);
00224 tab->addTab(apm, i18n("&APM Config"));
00225 connect(apm, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool)));
00226 } else {
00227 apm = 0;
00228 }
00229 if (::access("/dev/sonypi", F_OK) == 0) {
00230 bool do_sony = 1;
00231 if (::access("/dev/sonypi", R_OK) == 0) {
00232 int fd = ::open("/dev/sonypi", O_RDONLY);
00233 if (fd >= 0) {
00234 ::close(fd);
00235 } else {
00236 do_sony = 0;
00237 }
00238 }
00239 if (do_sony) {
00240 sony = new SonyConfig(inst,parent);
00241 tab->addTab(sony, i18n("&Sony Laptop Config"));
00242 connect(sony, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool)));
00243 } else {
00244 sony = 0;
00245 }
00246 } else {
00247 sony = 0;
00248 }
00249
00250 KAboutData* about =
00251 new KAboutData("kcmlaptop", 0, ki18n("Laptop Battery Configuration"), LAPTOP_VERSION,
00252 ki18n("Battery Control Panel Module"),
00253 KAboutData::License_GPL,
00254 ki18n("(c) 1999 Paul Campbell"));
00255
00256 setAboutData( about );
00257 }
00258
00259 void LaptopModule::load()
00260 {
00261 battery->load();
00262 warning->load();
00263 critical->load();
00264 power->load();
00265 if (apm)
00266 apm->load();
00267 if (acpi)
00268 acpi->load();
00269 if (profile)
00270 profile->load();
00271 if (sony)
00272 sony->load();
00273 if (buttons)
00274 buttons->load();
00275 }
00276
00277 void LaptopModule::save()
00278 {
00279 battery->save();
00280 warning->save();
00281 critical->save();
00282 power->save();
00283 if (profile)
00284 profile->save();
00285 if (acpi)
00286 acpi->save();
00287 if (apm)
00288 apm->save();
00289 if (sony)
00290 sony->save();
00291 if (buttons)
00292 buttons->save();
00293 }
00294
00295
00296 void LaptopModule::defaults()
00297 {
00298 battery->defaults();
00299 warning->defaults();
00300 critical->defaults();
00301 power->defaults();
00302 if (acpi)
00303 acpi->defaults();
00304 if (apm)
00305 apm->defaults();
00306 if (profile)
00307 profile->defaults();
00308 if (sony)
00309 sony->defaults();
00310 if (buttons)
00311 buttons->defaults();
00312 }
00313
00314 QString LaptopModule::quickHelp() const
00315 {
00316 return i18n("<h1>Laptop Battery</h1>This module allows you to monitor "
00317 "your batteries. To make use of this module, you must have power management software "
00318 "installed. (And, of course, you should have batteries in your "
00319 "machine.)");
00320 }
00321
00322
00323 void LaptopModule::moduleChanged(bool state)
00324 {
00325 emit changed(state);
00326 }
00327
00328
00329 #include "main.moc"