summaryrefslogtreecommitdiffstats
path: root/klaptopdaemon/warning.cpp
blob: 21213371a8815217c084e1dcaee3c5b13c49636d (plain)
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
/*
 * warning.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 "warning.h"
#include "portable.h"
#include "version.h"

#include <klocale.h>
#include <kfiledialog.h>
#include <kmessagebox.h>
#include <kconfig.h>
#include <kurlrequester.h>
#include <kapplication.h>
#include <kcombobox.h>

#include <layout.h>
#include <tqcheckbox.h>
#include <tqspinbox.h>
#include <tqslider.h>
#include <tqhbox.h>
#include <tqvbuttongroup.h>
#include <tqradiobutton.h>
#include <tqtooltip.h>

extern void wake_laptop_daemon();

WarningConfig::WarningConfig (int t, TQWidget * parent, const char *name)
  : KCModule(parent, name),
    checkSuspend(0),
    checkStandby(0),
    checkHibernate(0)
{
  KGlobal::locale()->insertCatalogue("klaptopdaemon"); // For translation of klaptopdaemon messages

  type = t;
  apm = laptop_portable::has_power_management();
  config =  new KConfig("kcmlaptoprc");

  my_load(0);

  if (!apm) {
    TQVBoxLayout *top_layout = new TQVBoxLayout( this, KDialog::marginHint(),
					       KDialog::spacingHint() );
	
    KActiveLabel* explain = laptop_portable::no_power_management_explanation(this);
    top_layout->addWidget(explain, 0);

    top_layout->addStretch(1);
  } else {
    TQGridLayout *grid = new TQGridLayout( this, 11, 2, /* rows x cols */
					 KDialog::marginHint(),
					 KDialog::spacingHint() );
    grid->setColStretch( 1, 1 );

    int curRow = 0;
    // setup the trigger stuff:
    if (type) { 
        checkCriticalTime = new TQCheckBox( i18n("Critical &trigger:"), this );
        checkCriticalPercent = new TQCheckBox( i18n("Critical &trigger:"), this );
        editCriticalTime = new TQSpinBox(1, 60*24, 1, this);
        editCriticalTime->setSuffix(i18n("keep short, unit in spinbox", "min"));
        TQToolTip::add(editCriticalTime, i18n("When this amount of battery life is left the actions below will be triggered"));
        editCriticalPercent = new TQSpinBox(1, 100, 1, this);
        editCriticalPercent->setSuffix(i18n("keep short, unit in spinbox", "%"));
        TQToolTip::add(editCriticalPercent, i18n("When this amount of battery life is left the actions below will be triggered"));
        grid->addWidget(checkCriticalTime, curRow, 0);
        grid->addWidget(editCriticalTime, curRow++, TQt::AlignLeft);
        grid->addWidget(checkCriticalPercent, curRow, 0);
        grid->addWidget(editCriticalPercent, curRow++, TQt::AlignLeft);

        connect(editCriticalTime, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(configChanged()));
        connect(editCriticalPercent, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(configChanged()));
        connect(checkCriticalTime, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(configChanged()));
        connect(checkCriticalPercent, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(configChanged()));
        connect(checkCriticalTime, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(checkCriticalTimeChanged(bool)));
        connect(checkCriticalPercent, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(checkCriticalPercentChanged(bool)));
    } else {
        checkLowTime = new TQCheckBox( i18n("Low &trigger:"), this );
        checkLowPercent = new TQCheckBox( i18n("Low &trigger:"), this );        
        editLowTime = new TQSpinBox(1, 60*24, 1, this);
        editLowTime->setSuffix(i18n("keep short, unit in spinbox", "min"));
        TQToolTip::add(editLowTime, i18n("When this amount of battery life is left the actions below will be triggered"));
        editLowPercent = new TQSpinBox(1, 100, 1, this);
        editLowPercent->setSuffix(i18n("keep short, unit in spinbox", "%"));
        TQToolTip::add(editLowPercent, i18n("When this amount of battery life is left the actions below will be triggered"));
        grid->addWidget(checkLowTime, curRow, 0);
        grid->addWidget(editLowTime, curRow++, TQt::AlignLeft);
        grid->addWidget(checkLowPercent, curRow, 0);
        grid->addWidget(editLowPercent, curRow++, TQt::AlignLeft);
        
        connect(editLowTime, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(configChanged()));
        connect(editLowPercent, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(configChanged()));
        connect(checkLowTime, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(configChanged()));
        connect(checkLowPercent, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(configChanged()));
        connect(checkLowTime, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(checkLowTimeChanged(bool)));
        connect(checkLowPercent, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(checkLowPercentChanged(bool)));
    }

    
    // setup the Run Command stuff
    checkRunCommand = new TQCheckBox(i18n("Run &command:"), this);
    grid->addWidget(checkRunCommand, curRow, 0);

    editRunCommand = new KURLRequester( this );
    editRunCommand->setEnabled(false);
    connect( checkRunCommand, TQT_SIGNAL(toggled(bool)),
	     editRunCommand,  TQT_SLOT(setEnabled(bool)) );
    connect( checkRunCommand, TQT_SIGNAL(clicked()),
	     this, TQT_SLOT(configChanged()) );
    connect( editRunCommand, TQT_SIGNAL(textChanged(const TQString&)),
	     this, TQT_SLOT(configChanged()) );
    grid->addWidget(editRunCommand, curRow++, 1);
    TQToolTip::add( editRunCommand, i18n( "This command will be run when the battery gets low" ) );

    // setup the Play Sound stuff
    checkPlaySound = new TQCheckBox(i18n("&Play sound:"), this);
    grid->addWidget(checkPlaySound, curRow, 0);

    editPlaySound = new KURLRequester( this );
    editPlaySound->setEnabled(false);
    connect( checkPlaySound, TQT_SIGNAL(toggled(bool)),
	     editPlaySound,  TQT_SLOT(setEnabled(bool)) );
    connect( checkPlaySound, TQT_SIGNAL(clicked()),
	     this, TQT_SLOT(configChanged()) );
    connect( editPlaySound, TQT_SIGNAL(textChanged(const TQString&)),
	     this, TQT_SLOT(configChanged()) );
    grid->addWidget(editPlaySound, curRow++, 1);
    TQToolTip::add( editPlaySound, i18n( "This sound will play when the battery gets low" ) );

    // setup the System Sound stuff
    checkBeep = new TQCheckBox(i18n("System &beep"), this);
    grid->addWidget(checkBeep, curRow++, 0);
    connect(checkBeep, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()));
    TQToolTip::add( checkBeep, i18n( "The system will beep if this is enabled" ) );

    checkNotify = new TQCheckBox(i18n("&Notify"), this);
    grid->addWidget(checkNotify, curRow++, 0);
    connect(checkNotify, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()));

    int can_suspend = laptop_portable::has_suspend();
    int can_standby = laptop_portable::has_standby();
    int can_hibernate = laptop_portable::has_hibernation();
    int can_brightness = laptop_portable::has_brightness();

    if (can_brightness) {
      checkBrightness = new TQCheckBox(i18n("Panel b&rightness"), this);
      checkBrightness->setMinimumSize(checkBrightness->sizeHint());
      TQToolTip::add( checkBrightness, i18n( "If enabled the back panel brightness will change" ) );
      grid->addWidget(checkBrightness, curRow, 0);
      connect(checkBrightness, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(brightness_changed(bool)));
      TQHBoxLayout *v = new TQHBoxLayout();
      v->addWidget(new TQLabel("-", this));
      valueBrightness = new TQSlider(0, 255, 16, 160, Qt::Horizontal, this);
      TQToolTip::add( valueBrightness, i18n( "How bright or dim to make the back panel" ) );
      valueBrightness->setMaximumWidth(70);
      v->addWidget(valueBrightness);
      v->addWidget(new TQLabel("+", this));
      v->addStretch(1);
      grid->addLayout(v, curRow, 1);
      valueBrightness->setEnabled(0);
      connect(valueBrightness, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(configChanged()));
      ++curRow;
    } else {
      checkBrightness = 0;
      valueBrightness = 0;
    }
    TQStringList performance_list;
    int current_performance;
    bool *active_list;
    bool has_performance = laptop_portable::get_system_performance(0, current_performance, performance_list, active_list);
    if (has_performance) {
    	performance = new TQCheckBox(i18n("System performance"), this);
        TQToolTip::add( performance, i18n( "If enabled the laptop's power performance profile will change" ) );
        grid->addWidget(performance, curRow, 0);
    	connect (performance, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(performance_changed(bool)));

        TQHBoxLayout *v = new TQHBoxLayout();
    	performance_val = new KComboBox(0, this);
	performance_val->insertStringList(performance_list);
    	performance_val->setEnabled(0);
    	connect (performance_val, TQT_SIGNAL(activated(int)), this, TQT_SLOT(configChanged()));
        TQToolTip::add( performance_val, i18n( "The performance profile to change to" ) );
	v->addWidget(performance_val);
	v->addStretch(1);
        grid->addLayout(v, curRow, 1);
	++curRow;
    } else {
        performance = 0;
        performance_val = 0;
    }
    TQStringList throttle_list;
    int current_throttle;
    bool has_throttle = laptop_portable::get_system_throttling(0, current_throttle, throttle_list, active_list);
    if (has_throttle) {
    	throttle = new TQCheckBox(i18n("CPU throttling"), this);
        TQToolTip::add( throttle, i18n( "If enabled the CPU performance will be throttled" ) );
        grid->addWidget(throttle, curRow, 0);
    	connect (throttle, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(throttle_changed(bool)));

        TQHBoxLayout *v = new TQHBoxLayout();
    	throttle_val = new KComboBox(0, this);
	throttle_val->insertStringList(throttle_list);
    	throttle_val->setEnabled(0);
    	connect (throttle_val, TQT_SIGNAL(activated(int)), this, TQT_SLOT(configChanged()));
        TQToolTip::add( throttle_val, i18n( "How much to throttle the CPU performance by" ) );
	v->addWidget(throttle_val);
	v->addStretch(1);
        grid->addLayout(v, curRow, 1);
	++curRow;
    } else {
        throttle = 0;
        throttle_val = 0;
    }



    TQVButtonGroup *b = new TQVButtonGroup(i18n("System State Change"), this);
    TQToolTip::add( b, i18n( "You may choose one of the following to occur when the battery gets low" ) );
    b->layout()->setSpacing( KDialog::spacingHint() );
    if (can_standby) {
      checkStandby = new TQRadioButton(i18n("Standb&y"), b);
      TQToolTip::add( checkStandby, i18n( "Move the system into the standby state - a temporary lower power state" ) );
      checkStandby->setMinimumSize(checkStandby->sizeHint());
      connect(checkStandby, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()));
    }
    if (can_suspend) {
      checkSuspend = new TQRadioButton(i18n("&Suspend"), b);
      TQToolTip::add( checkSuspend, i18n( "Move the system into the suspend state - also known as 'save-to-ram'" ) );
      checkSuspend->setMinimumSize(checkSuspend->sizeHint());
      connect(checkSuspend, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()));
    }
    if (can_hibernate) {
      checkHibernate = new TQRadioButton(i18n("H&ibernate"), b);
      TQToolTip::add( checkHibernate, i18n( "Move the system into the hibernate state - also known as 'save-to-disk'" ) );
      checkHibernate->setMinimumSize(checkHibernate->sizeHint());
      connect(checkHibernate, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()));
    }
    // setup the logout option
    checkLogout = new TQRadioButton(i18n("&Logout"), b);
    connect(checkLogout, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()));
    // setup the shutdown option
    checkShutdown = new TQRadioButton(i18n("System power off"), b);
    TQToolTip::add( checkShutdown, i18n( "Power the laptop off" ) );
    connect(checkShutdown, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()));
    
    checkNone = new TQRadioButton(i18n("&None"), b);
    connect(checkNone, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()));

    grid->addMultiCellWidget(b, curRow, curRow, 0, 1, TQt::AlignLeft|TQt::AlignTop);
    curRow++;


    TQLabel* explain;
    if (type) {
      explain = new TQLabel(i18n("This panel controls how and when you receive warnings that your battery power is going to run out VERY VERY soon."), this);
    } else {
      explain = new TQLabel(i18n("This panel controls how and when you receive warnings that your battery power is about to run out"), this);
    }
    explain->setAlignment( TQt::WordBreak );
    grid->addMultiCellWidget(explain, curRow, curRow, 0, 1);
    ++curRow;

    if (!can_suspend && !can_standby && !can_hibernate) {
      // display help text:
      TQLabel* note = laptop_portable::how_to_do_suspend_resume(this);
      grid->addMultiCellWidget(note, curRow, curRow, 0, 1);
      ++curRow;
    }
    grid->setRowStretch(curRow++, 1);

    grid->addWidget(new TQLabel( i18n("Version: %1").arg(LAPTOP_VERSION), this),
		    curRow, 1, TQt::AlignRight);

  }
  my_load(1);
}

WarningConfig::~WarningConfig()
{
  delete config;
}

void WarningConfig::brightness_changed(bool v)
{
  valueBrightness->setEnabled(v);
  configChanged();
}

void WarningConfig::throttle_changed(bool v)
{
  throttle_val->setEnabled(v);
  configChanged();
}

void WarningConfig::performance_changed(bool v)
{
  performance_val->setEnabled(v);
  configChanged();
}

void WarningConfig::checkLowTimeChanged(bool state)
{
  checkLowPercent->setChecked(state ? false : true);
  editLowPercent->setEnabled(state ? false : true);
}

void WarningConfig::checkLowPercentChanged(bool state)
{
  checkLowTime->setChecked(state ? false : true);
  editLowTime->setEnabled(state ? false : true);
}

void WarningConfig::checkCriticalTimeChanged(bool state)
{
  checkCriticalPercent->setChecked(state ? false : true);
  editCriticalPercent->setEnabled(state ? false : true);
}

void WarningConfig::checkCriticalPercentChanged(bool state)
{
  checkCriticalTime->setChecked(state ? false: true);
  editCriticalTime->setEnabled(state ? false : true);
}


void WarningConfig::save()
{
    if (apm) {
    	runcommand = checkRunCommand->isChecked();
    	playsound = checkPlaySound->isChecked();
    	logout = checkLogout->isChecked();
    	shutdown = checkShutdown->isChecked();
    	beep = checkBeep->isChecked();
    	notify = checkNotify->isChecked();
    	do_suspend = (checkSuspend? checkSuspend->isChecked() : false);
    	do_standby = (checkStandby? checkStandby->isChecked() : false);
    	do_hibernate = (checkHibernate? checkHibernate->isChecked() : false);
    	do_brightness = (checkBrightness? checkBrightness->isChecked() : false);
    	val_brightness = (valueBrightness? valueBrightness->value() : 255);
    	do_performance = (performance? performance->isChecked() : false);
    	val_performance = (performance_val? performance_val->currentText() : "");
    	do_throttle = (throttle? throttle->isChecked() : false);
    	val_throttle = (throttle_val? throttle_val->currentText() : "");
    	runcommand_val = editRunCommand->url();
        if (type) {
          time_based_action_critical = checkCriticalTime->isChecked();
          critical_val_time = editCriticalTime->value();
          critical_val_percent = editCriticalPercent->value();
        } else {
          time_based_action_low = checkLowTime->isChecked();
          low_val_time = editLowTime->value();
          low_val_percent = editLowPercent->value();
        }
        
    	sound_val = editPlaySound->url();
    }
    config->setGroup((type?"BatteryCritical":"BatteryLow"));

    if (config->group() == "BatteryLow") {
        config->writeEntry("TimeBasedAction", time_based_action_low);
        config->writeEntry("LowValTime", low_val_time);
        config->writeEntry("LowValPercent", low_val_percent);
    } else {
        config->writeEntry("TimeBasedAction", time_based_action_critical);
        config->writeEntry("CriticalValTime", critical_val_time);
        config->writeEntry("CriticalValPercent", critical_val_percent);
    }
    config->writeEntry("RunCommand", runcommand);
    config->writeEntry("PlaySound", playsound);
    config->writeEntry("Logout", logout);
    config->writeEntry("Shutdown", shutdown);
    config->writeEntry("SystemBeep", beep);
    config->writeEntry("Notify", notify);
    config->writeEntry("Suspend", do_suspend);
    config->writeEntry("Standby", do_standby);
    config->writeEntry("Hibernate", do_hibernate);
    config->writeEntry("Brightness", do_brightness);
    config->writeEntry("BrightnessValue", val_brightness);
    config->writeEntry("Performance", do_performance);
    config->writeEntry("PerformanceValue", val_performance);
    config->writeEntry("Throttle", do_throttle);
    config->writeEntry("ThrottleValue", val_throttle);
    config->writeEntry("RunCommandPath", runcommand_val);
    config->writeEntry("PlaySoundPath", sound_val);
    config->sync();
    wake_laptop_daemon();
}

void WarningConfig::load()
{
	load( false );
}

void WarningConfig::load(bool useDefaults)
{
	if (config == NULL)
		return;
	my_load(0, useDefaults);
	my_load(1, useDefaults);
}

void WarningConfig::my_load(int x, bool useDefaults )
{
	config->setReadDefaults( useDefaults );

	// open the config file
	if (!x) {
		config->setGroup((type?"BatteryCritical":"BatteryLow"));

                if (config->group() == "BatteryLow") {
                    time_based_action_low = config->readBoolEntry("TimeBasedAction", true);
                    low_val_time = config->readNumEntry("LowValTime", 15);
                    low_val_percent = config->readNumEntry("LowValPercent", 7);
                } else {
                    time_based_action_critical = config->readBoolEntry("TimeBasedAction", true);
                    critical_val_time = config->readNumEntry("CriticalValTime", 5);
                    critical_val_percent = config->readNumEntry("CriticalValPercent", 3);
                }
		runcommand = config->readBoolEntry("RunCommand", false);
		playsound = config->readBoolEntry("PlaySound", false);
		logout = config->readBoolEntry("Logout", false);
		shutdown = config->readBoolEntry("Shutdown", false);
		beep = config->readBoolEntry("SystemBeep", true);
		notify = config->readBoolEntry("Notify", (type && checkSuspend ? false : true));
		do_suspend = config->readBoolEntry("Suspend", (type && checkSuspend ? true :false));
		do_standby = config->readBoolEntry("Standby", false);
		do_hibernate = config->readBoolEntry("Hibernate", false);
		do_brightness = config->readBoolEntry("Brightness", false);
		val_brightness = config->readNumEntry("BrightnessValue", 255);
		do_performance = config->readBoolEntry("Performance", false);
		val_performance = config->readEntry("PerformanceValue", "");
		do_throttle = config->readBoolEntry("Throttle", false);
		val_throttle = config->readEntry("ThrottleValue", "");
		runcommand_val = config->readEntry("RunCommandPath");
		sound_val = config->readEntry("PlaySoundPath");
		have_time = config->readNumEntry("HaveTime", 2);
		if (laptop_portable::has_power_management())
			have_time = laptop_portable::has_battery_time();
	
	} else
	if (apm) {
		checkRunCommand->setChecked(runcommand);
		checkPlaySound->setChecked(playsound);
		checkBeep->setChecked(beep);
		if (checkBrightness)
			checkBrightness->setChecked(do_brightness);
		if (valueBrightness) {
			valueBrightness->setValue(val_brightness);
  			valueBrightness->setEnabled(do_brightness);
		}
		if (performance)
			performance->setChecked(do_performance);
		if (performance_val) {
			int ind = 0;
			for (int i = 0; i < performance_val->count(); i++)
			if (performance_val->text(i) == val_performance) {
				ind = i;
				break;
			}
			performance_val->setCurrentItem(ind);
  			performance_val->setEnabled(do_performance);
		}
		if (throttle)
			throttle->setChecked(do_throttle);
		if (throttle_val) {
			int ind = 0;
			for (int i = 0; i < throttle_val->count(); i++)
			if (throttle_val->text(i) == val_throttle) {
				ind = i;
				break;
			}
			throttle_val->setCurrentItem(ind);
  			throttle_val->setEnabled(do_throttle);
		}
		
		checkLogout->setChecked(logout);
		checkNotify->setChecked(notify);
		checkShutdown->setChecked(shutdown);
		if (checkHibernate) {
			checkHibernate->setChecked(do_hibernate);
		} else {
			do_hibernate = 0;
		}
		if (checkStandby) {
			checkStandby->setChecked(do_standby);
		} else {
			do_standby = 0;
		}
		if (checkSuspend) {
			checkSuspend->setChecked(do_suspend);
		} else {
			do_suspend = 0;
		}
		checkNone->setChecked(!do_suspend&!do_standby&!do_hibernate&!logout&!shutdown);
		editRunCommand->setURL(runcommand_val);

                if(type) {
                checkCriticalTime->setChecked(time_based_action_critical ? true : false);
                editCriticalTime->setValue(critical_val_time);
                checkCriticalPercent->setChecked(time_based_action_critical ? false : true);
                editCriticalPercent->setValue(critical_val_percent);
                } else {
                  checkLowTime->setChecked(time_based_action_low ? true : false);
                  editLowTime->setValue(low_val_time);
                  checkLowPercent->setChecked(time_based_action_low ? false : true);
                  editLowPercent->setValue(low_val_percent);
                }
                
                editPlaySound->setURL(sound_val);
	}
	emit changed(useDefaults);
}

void WarningConfig::defaults()
{
	load( true );
}


void WarningConfig::configChanged()
{
  emit changed(true);
}


#if 0
void WarningConfig::enableRunCommand(bool enable)
{
	editRunCommand->setEnabled(enable);
	buttonBrowseRunCommand->setEnabled(enable);
	configChanged();
}

void WarningConfig::enablePlaySound(bool enable)
{
	editPlaySound->setEnabled(enable);
	buttonBrowsePlaySound->setEnabled(enable);
	configChanged();
}

void WarningConfig::browseRunCommand()
{
  KURL url = KFileDialog::getOpenURL(TQString(), TQString(), this  );
  
  if( url.isEmpty() )
    return;
  
  if( !url.isLocalFile() )
  {
    KMessageBox::sorry( 0L, i18n( "Only local files are currently supported." ) );
    return;
  }
  
  editRunCommand->setText( url.path() );
  configChanged();
}

void WarningConfig::browsePlaySound()
{
  KURL url = KFileDialog::getOpenURL(TQString(), TQString(), this  );
  
  if( url.isEmpty() )
    return;
  
  if( !url.isLocalFile() )
  {
    KMessageBox::sorry( 0L, i18n( "Only local files are currently supported." ) );
    return;
  }
  
  editPlaySound->setText( url.path() );
  configChanged();
}
#endif

TQString WarningConfig::quickHelp() const
{
  return i18n("<h1>Low battery Warning</h1>This module allows you to "
	"set an alarm in case your battery's charge is about to run out.");
}

#include "warning.moc"