1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/*
* main.cpp
*
* Copyright (c) 1999 Paul Campbell <paul@taniwha.com>
*
* Requires the TQt widget libraries, available at no cost at
* http://www.troll.no/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <klocale.h>
#include <kprocess.h>
#include <kconfig.h>
#include <kglobal.h>
#include <tqlayout.h>
#include <unistd.h>
#include <fcntl.h>
#include "main.h"
#include "version.h"
#include "warning.h"
#include "power.h"
#include "battery.h"
#include "buttons.h"
#include "pcmcia.h"
#include "acpi.h"
#include "apm.h"
#include "sony.h"
#include "profile.h"
#include "portable.h"
extern void wake_laptop_daemon();
extern "C"
{
KDE_EXPORT KCModule *create_pcmcia(TQWidget *parent, const char *)
{
return new PcmciaConfig(parent, "kcmlaptop");
}
KDE_EXPORT KCModule *create_bwarning(TQWidget *parent, const char *)
{
return new WarningConfig(0, parent, "kcmlaptop");
}
KDE_EXPORT KCModule *create_cwarning(TQWidget *parent, const char *)
{
return new WarningConfig(1, parent, "kcmlaptop");
}
KDE_EXPORT KCModule *create_battery(TQWidget *parent, const char *)
{
return new BatteryConfig(parent, "kcmlaptop");
}
KDE_EXPORT KCModule *create_power(TQWidget *parent, const char *)
{
return new PowerConfig(parent, "kcmlaptop");
}
KDE_EXPORT KCModule *create_acpi(TQWidget *parent, const char *)
{
return new AcpiConfig(parent, "kcmlaptop");
}
KDE_EXPORT KCModule *create_apm(TQWidget *parent, const char *)
{
return new ApmConfig(parent, "kcmlaptop");
}
KDE_EXPORT KCModule *create_Profile(TQWidget *parent, const char *)
{
return new ProfileConfig(parent, "kcmlaptop");
}
KDE_EXPORT KCModule *create_sony(TQWidget *parent, const char *)
{
return new SonyConfig(parent, "kcmlaptop");
}
KDE_EXPORT KCModule *create_buttons(TQWidget *parent, const char *)
{
return new ButtonsConfig(parent, "kcmlaptop");
}
KDE_EXPORT void init_battery()
{
KConfig config("kcmlaptoprc", true /*readonly*/, false /*no globals*/);
config.setGroup("BatteryDefault");
bool enable = false;
if (!config.hasKey("Enable")) { // if they have APM or PCMCIA, Enable=true
struct power_result pr = laptop_portable::poll_battery_state();
if ((laptop_portable::has_power_management() &&
!(pr.powered &&
(pr.percentage < 0 || pr.percentage == 0xff)))||
0 == access("/var/run/stab", R_OK|F_OK) ||
0 == access("/var/lib/pcmcia/stab", R_OK|F_OK))
enable = true;
} else {
enable = config.readBoolEntry("Enable", false);
}
if (!enable)
return;
wake_laptop_daemon();
}
KDE_EXPORT KCModule *create_laptop(TQWidget *parent, const char *)
{
return new LaptopModule(parent, "kcmlaptop");
}
KDE_EXPORT void init_laptop()
{
init_battery();
}
}
LaptopModule::LaptopModule(TQWidget *parent, const char *)
: KCModule(parent, "kcmlaptop")
{
{ // export ACPI options
KConfig config("kcmlaptoprc", true /*readonly*/, false /*no globals*/);
config.setGroup("AcpiDefault");
bool enablestandby = config.readBoolEntry("EnableStandby", false);
bool enablesuspend = config.readBoolEntry("EnableSuspend", false);
bool enablehibernate = config.readBoolEntry("EnableHibernate", false);
bool enableperformance = config.readBoolEntry("EnablePerformance", false);
bool enablethrottle = config.readBoolEntry("EnableThrottle", false);
laptop_portable::acpi_set_mask(enablestandby, enablesuspend, enablehibernate, enableperformance, enablethrottle);
config.setGroup("ApmDefault");
enablestandby = config.readBoolEntry("EnableStandby", false);
enablesuspend = config.readBoolEntry("EnableSuspend", false);
laptop_portable::apm_set_mask(enablestandby, enablesuspend);
config.setGroup("SoftwareSuspendDefault");
enablehibernate = config.readBoolEntry("EnableHibernate", false);
laptop_portable::software_suspend_set_mask(enablehibernate);
}
TQVBoxLayout *layout = new TQVBoxLayout(this);
tab = new TQTabWidget(this);
layout->addWidget(tab);
battery = new BatteryConfig(parent, "kcmlaptop");
tab->addTab(battery, i18n("&Battery"));
connect(battery, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(moduleChanged(bool)));
power = new PowerConfig(parent, "kcmlaptop");
tab->addTab(power, i18n("&Power Control"));
connect(power, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(moduleChanged(bool)));
warning = new WarningConfig(0, parent, "kcmlaptop");
tab->addTab(warning, i18n("Low Battery &Warning"));
connect(warning, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(moduleChanged(bool)));
critical = new WarningConfig(1, parent, "kcmlaptop");
tab->addTab(critical, i18n("Low Battery &Critical"));
connect(critical, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(moduleChanged(bool)));
TQStringList profile_list;
int current_profile;
bool *active_list;
bool has_profile = laptop_portable::get_system_performance(0, current_profile, profile_list, active_list);
TQStringList throttle_list;
int current_throttle;
bool has_throttling = laptop_portable::get_system_throttling(0, current_throttle, throttle_list, active_list);
if (laptop_portable::has_brightness() || has_profile || has_throttling) {
profile = new ProfileConfig(parent, "kcmlaptop");
tab->addTab(profile, i18n("Default Power Profiles"));
connect(profile, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(moduleChanged(bool)));
} else {
profile = 0;
}
if (laptop_portable::has_button(laptop_portable::LidButton) || laptop_portable::has_button(laptop_portable::PowerButton)) {
buttons = new ButtonsConfig(parent, "kcmlaptop");
tab->addTab(buttons, i18n("Button Actions"));
connect(buttons, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(moduleChanged(bool)));
} else {
buttons = 0;
}
if (laptop_portable::has_acpi()) {
acpi = new AcpiConfig(parent, "kcmlaptop");
tab->addTab(acpi, i18n("&ACPI Config"));
connect(acpi, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(moduleChanged(bool)));
} else {
acpi = 0;
}
if (laptop_portable::has_apm()) {
apm = new ApmConfig(parent, "kcmlaptop");
tab->addTab(apm, i18n("&APM Config"));
connect(apm, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(moduleChanged(bool)));
} else {
apm = 0;
}
if (::access("/dev/sonypi", F_OK) == 0) {
bool do_sony = 1;
if (::access("/dev/sonypi", R_OK) == 0) {
int fd = ::open("/dev/sonypi", O_RDONLY); // make sure the driver's there as well as the /dev inode
if (fd >= 0) {
::close(fd);
} else {
do_sony = 0;
}
}
if (do_sony) {
sony = new SonyConfig(parent, "kcmlaptop");
tab->addTab(sony, i18n("&Sony Laptop Config"));
connect(sony, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(moduleChanged(bool)));
} else {
sony = 0;
}
} else {
sony = 0;
}
TDEAboutData* about =
new TDEAboutData("kcmlaptop", I18N_NOOP("Laptop Battery Configuration"), LAPTOP_VERSION,
I18N_NOOP("Battery Control Panel Module"),
TDEAboutData::License_GPL,
I18N_NOOP("(c) 1999 Paul Campbell"), 0, 0);
//about->addAuthor("NAME", 0, "e-mail addy");
setAboutData( about );
}
void LaptopModule::load()
{
battery->load();
warning->load();
critical->load();
power->load();
if (apm)
apm->load();
if (acpi)
acpi->load();
if (profile)
profile->load();
if (sony)
sony->load();
if (buttons)
buttons->load();
}
void LaptopModule::save()
{
battery->save();
warning->save();
critical->save();
power->save();
if (profile)
profile->save();
if (acpi)
acpi->save();
if (apm)
apm->save();
if (sony)
sony->save();
if (buttons)
buttons->save();
}
void LaptopModule::defaults()
{
battery->defaults();
warning->defaults();
critical->defaults();
power->defaults();
if (acpi)
acpi->defaults();
if (apm)
apm->defaults();
if (profile)
profile->defaults();
if (sony)
sony->defaults();
if (buttons)
buttons->defaults();
}
TQString LaptopModule::quickHelp() const
{
return i18n("<h1>Laptop Battery</h1>This module allows you to monitor "
"your batteries. To make use of this module, you must have power management software "
"installed. (And, of course, you should have batteries in your "
"machine.)");
}
void LaptopModule::moduleChanged(bool state)
{
emit changed(state);
}
#include "main.moc"
|