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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
/*
* * Copyright (C) 2009 Ali <aliov@xfce.org>
*
* Licensed under the GNU General Public License Version 2
*
* 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
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <libxfce4util/libxfce4util.h>
#include "libxfpm/xfpm-string.h"
#include "libxfpm/xfpm-common.h"
#include "xfpm-xfconf.h"
#include "xfpm-config.h"
#include "xfpm-enum-glib.h"
#include "xfpm-enum.h"
static void xfpm_xfconf_finalize (GObject *object);
#define XFPM_XFCONF_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_XFCONF, XfpmXfconfPrivate ))
static gpointer xfpm_xfconf_object = NULL;
struct XfpmXfconfPrivate
{
XfconfChannel *channel;
XfpmShutdownRequest power_button;
XfpmShutdownRequest hibernate_button;
XfpmShutdownRequest sleep_button;
XfpmShutdownRequest lid_button_ac;
XfpmShutdownRequest lid_button_battery;
XfpmShutdownRequest critical_action;
gboolean lock_screen;
#ifdef HAVE_DPMS
gboolean dpms_enabled;
guint16 dpms_sleep_on_battery;
guint16 dpms_off_on_battery;
guint16 dpms_sleep_on_ac;
guint16 dpms_off_on_ac;
gboolean sleep_dpms_mode; /*TRUE = standby FALSE = suspend*/
#endif
gboolean power_save_on_battery;
#ifdef SYSTEM_IS_LINUX
gboolean cpu_freq_control;
#endif
guint16 brightness_on_ac_timeout;
guint16 brightness_on_battery_timeout;
XfpmShowIcon show_icon;
guint critical_level;
gboolean general_notification;
guint inactivity_on_ac;
guint inactivity_on_battery;
gboolean sleep_inactivity; /* TRUE = suspend FALSE = hibernate*/
gboolean enable_brightness;
};
enum
{
DPMS_SETTINGS_CHANGED,
POWER_SAVE_SETTINGS_CHANGED,
BRIGHTNESS_SETTINGS_CHANGED,
TRAY_ICON_SETTINGS_CHANGED,
INACTIVITY_TIMEOUT_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE(XfpmXfconf, xfpm_xfconf, G_TYPE_OBJECT)
static void
xfpm_xfconf_property_changed_cb (XfconfChannel *channel, gchar *property,
GValue *value, XfpmXfconf *conf)
{
const gchar *str;
gint val;
if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
return;
TRACE("Property modified: %s\n", property);
if ( xfpm_strequal (property, SLEEP_SWITCH_CFG) )
{
str = g_value_get_string (value);
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == 3) )
{
g_warning ("Invalid value %s for property %s, using default\n", str, SLEEP_SWITCH_CFG);
conf->priv->sleep_button = XFPM_DO_NOTHING;
}
else
conf->priv->sleep_button = val;
}
else if ( xfpm_strequal (property, GENERAL_NOTIFICATION_CFG) )
{
conf->priv->general_notification = g_value_get_boolean (value);
}
else if ( xfpm_strequal (property, POWER_SWITCH_CFG ) )
{
str = g_value_get_string (value);
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1) )
{
g_warning ("Invalid value %s fpr property %s, using default\n", str, POWER_SWITCH_CFG);
conf->priv->power_button = XFPM_DO_NOTHING;
}
else
conf->priv->power_button = xfpm_shutdown_string_to_int (str);
}
else if ( xfpm_strequal (property, HIBERNATE_SWITCH_CFG ) )
{
str = g_value_get_string (value);
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1) )
{
g_warning ("Invalid value %s fpr property %s, using default\n", str, HIBERNATE_SWITCH_CFG);
conf->priv->hibernate_button = XFPM_DO_NOTHING;
}
else
conf->priv->hibernate_button = xfpm_shutdown_string_to_int (str);
}
else if ( xfpm_strequal (property, LID_SWITCH_ON_AC_CFG) )
{
str = g_value_get_string (value);
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1 || val == 3) )
{
g_warning ("Invalid value %s for property %s, using default\n", str, LID_SWITCH_ON_AC_CFG);
conf->priv->lid_button_ac = XFPM_DO_NOTHING;
}
else
conf->priv->lid_button_ac = val;
}
else if ( xfpm_strequal (property, LID_SWITCH_ON_BATTERY_CFG) )
{
str = g_value_get_string (value);
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1 || val == 3) )
{
g_warning ("Invalid value %s for property %s, using default\n", str, LID_SWITCH_ON_BATTERY_CFG);
conf->priv->lid_button_battery = XFPM_DO_NOTHING;
}
else
conf->priv->lid_button_battery = val;
}
else if ( xfpm_strequal (property, LOCK_SCREEN_ON_SLEEP ) )
{
conf->priv->lock_screen = g_value_get_boolean (value);
}
#ifdef HAVE_DPMS
else if ( xfpm_strequal (property, DPMS_ENABLED_CFG) )
{
conf->priv->dpms_enabled = g_value_get_boolean (value);
g_signal_emit (G_OBJECT(conf), signals[DPMS_SETTINGS_CHANGED], 0);
}
else if ( xfpm_strequal (property, ON_AC_DPMS_SLEEP) )
{
conf->priv->dpms_sleep_on_ac = MIN(3600, g_value_get_uint (value) * 60);
g_signal_emit (G_OBJECT(conf), signals[DPMS_SETTINGS_CHANGED], 0);
}
else if ( xfpm_strequal (property, ON_AC_DPMS_OFF) )
{
conf->priv->dpms_off_on_ac = MIN(3600, g_value_get_uint (value) * 60);
g_signal_emit (G_OBJECT(conf), signals[DPMS_SETTINGS_CHANGED], 0);
}
else if ( xfpm_strequal (property, ON_BATT_DPMS_SLEEP) )
{
conf->priv->dpms_sleep_on_battery = MIN(3600, g_value_get_uint (value) * 60);
g_signal_emit (G_OBJECT(conf), signals[DPMS_SETTINGS_CHANGED], 0);
}
else if ( xfpm_strequal (property, ON_BATT_DPMS_OFF) )
{
conf->priv->dpms_off_on_battery = MIN (3600, g_value_get_uint (value) * 60);
g_signal_emit (G_OBJECT(conf), signals[DPMS_SETTINGS_CHANGED], 0);
}
else if ( xfpm_strequal (property, DPMS_SLEEP_MODE) )
{
str = g_value_get_string (value);
if ( xfpm_strequal (str, "sleep" ) )
{
conf->priv->sleep_dpms_mode = TRUE;
}
else if ( xfpm_strequal (str, "suspend") )
{
conf->priv->sleep_dpms_mode = FALSE;
}
else
{
g_critical("Invalid value %s for property %s\n", str, DPMS_SLEEP_MODE);
conf->priv->sleep_dpms_mode = TRUE;
}
g_signal_emit (G_OBJECT(conf), signals[DPMS_SETTINGS_CHANGED], 0);
}
#endif /* HAVE_DPMS */
else if ( xfpm_strequal(property, POWER_SAVE_ON_BATTERY) )
{
conf->priv->power_save_on_battery = g_value_get_boolean (value);
g_signal_emit (G_OBJECT(conf), signals[POWER_SAVE_SETTINGS_CHANGED], 0);
}
#ifdef SYSTEM_IS_LINUX
else if ( xfpm_strequal(property, CPU_FREQ_CONTROL) )
{
conf->priv->cpu_freq_control = g_value_get_boolean (value);
g_signal_emit (G_OBJECT(conf), signals[POWER_SAVE_SETTINGS_CHANGED], 0);
}
#endif
else if ( xfpm_strequal (property, BRIGHTNESS_ON_AC ) )
{
conf->priv->brightness_on_ac_timeout = g_value_get_uint (value);
if ( G_UNLIKELY (conf->priv->brightness_on_ac_timeout > 120 || conf->priv->brightness_on_ac_timeout < 9 ))
{
g_warning ("Value %d for %s is out of range", conf->priv->brightness_on_ac_timeout, BRIGHTNESS_ON_AC );
conf->priv->brightness_on_ac_timeout = 9;
}
g_signal_emit (G_OBJECT(conf), signals[BRIGHTNESS_SETTINGS_CHANGED], 0);
}
else if ( xfpm_strequal (property, BRIGHTNESS_ON_BATTERY ) )
{
conf->priv->brightness_on_battery_timeout = g_value_get_uint (value);
if ( G_UNLIKELY (conf->priv->brightness_on_battery_timeout > 120 || conf->priv->brightness_on_battery_timeout < 9 ))
{
g_warning ("Value %d for %s is out of range", conf->priv->brightness_on_battery_timeout, BRIGHTNESS_ON_BATTERY );
conf->priv->brightness_on_battery_timeout = 9;
}
g_signal_emit (G_OBJECT(conf), signals[BRIGHTNESS_SETTINGS_CHANGED], 0);
}
else if ( xfpm_strequal (property, CRITICAL_BATT_ACTION_CFG) )
{
str = g_value_get_string (value);
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1 || val == 1 ))
{
g_warning ("Invalid value %s for property %s, using default\n", str, CRITICAL_BATT_ACTION_CFG);
conf->priv->critical_action = XFPM_DO_NOTHING;
}
else
conf->priv->critical_action = val;
}
else if ( xfpm_strequal (property, SHOW_TRAY_ICON_CFG) )
{
conf->priv->show_icon = g_value_get_uint (value);
g_signal_emit (G_OBJECT(conf), signals[TRAY_ICON_SETTINGS_CHANGED], 0 );
}
else if ( xfpm_strequal( property, CRITICAL_POWER_LEVEL) )
{
val = g_value_get_uint (value);
if ( G_UNLIKELY (val > 20) )
{
g_warning ("Value %d for property %s is out of range \n", val, CRITICAL_POWER_LEVEL);
conf->priv->critical_level = 10;
}
else
conf->priv->critical_level = val;
}
else if ( xfpm_strequal (property, ON_AC_INACTIVITY_TIMEOUT ) )
{
val = g_value_get_uint (value);
conf->priv->inactivity_on_ac = val;
if ( G_UNLIKELY (conf->priv->inactivity_on_ac < 30 ) )
{
g_print ("Invalid value for property %s", ON_AC_INACTIVITY_TIMEOUT);
conf->priv->inactivity_on_ac = 30;
}
g_signal_emit (G_OBJECT (conf), signals [INACTIVITY_TIMEOUT_CHANGED], 0);
}
else if ( xfpm_strequal (property, ON_BATTERY_INACTIVITY_TIMEOUT ) )
{
val = g_value_get_uint (value);
conf->priv->inactivity_on_battery = val;
if ( G_UNLIKELY (conf->priv->inactivity_on_battery < 30 ) )
{
g_print ("Invalid value for property %s", ON_BATTERY_INACTIVITY_TIMEOUT);
conf->priv->inactivity_on_battery = 30;
}
g_signal_emit (G_OBJECT (conf), signals [INACTIVITY_TIMEOUT_CHANGED], 0);
}
else if ( xfpm_strequal (property, INACTIVITY_SLEEP_MODE ) )
{
str = g_value_get_string (value);
if ( xfpm_strequal (str, "Suspend"))
{
conf->priv->sleep_inactivity = TRUE;
}
else if ( xfpm_strequal (str, "Hibernate") )
{
conf->priv->sleep_inactivity = FALSE;
}
else
{
g_critical("Invalid value %s for property %s\n", str, INACTIVITY_SLEEP_MODE);
conf->priv->sleep_inactivity = TRUE;
}
}
else if ( xfpm_strequal (property, ENABLE_BRIGHTNESS_CONTROL) )
conf->priv->enable_brightness = g_value_get_boolean (value);
else
g_warn_if_reached ();
}
static void
xfpm_xfconf_load_configuration (XfpmXfconf *conf)
{
gchar *str;
gint val;
str = xfconf_channel_get_string (conf->priv->channel, SLEEP_SWITCH_CFG, "Nothing");
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1 || val == 3) )
{
g_warning ("Invalid value %s for property %s, using default\n", str, SLEEP_SWITCH_CFG);
conf->priv->sleep_button = XFPM_DO_NOTHING;
xfconf_channel_set_string (conf->priv->channel, SLEEP_SWITCH_CFG, "Nothing");
}
else conf->priv->sleep_button = val;
g_free (str);
str = xfconf_channel_get_string (conf->priv->channel, POWER_SWITCH_CFG, "Nothing");
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1 ) )
{
g_warning ("Invalid value %s for property %s, using default\n", str, SLEEP_SWITCH_CFG);
conf->priv->power_button = XFPM_DO_NOTHING;
xfconf_channel_set_string (conf->priv->channel, POWER_SWITCH_CFG, "Nothing");
}
else conf->priv->power_button = val;
g_free (str);
str = xfconf_channel_get_string (conf->priv->channel, HIBERNATE_SWITCH_CFG, "Nothing");
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1 ) )
{
g_warning ("Invalid value %s for property %s, using default\n", str, HIBERNATE_SWITCH_CFG);
conf->priv->hibernate_button = XFPM_DO_NOTHING;
xfconf_channel_set_string (conf->priv->channel, HIBERNATE_SWITCH_CFG, "Nothing");
}
else conf->priv->hibernate_button = val;
g_free (str);
conf->priv->general_notification = xfconf_channel_get_bool (conf->priv->channel, GENERAL_NOTIFICATION_CFG, TRUE);
str = xfconf_channel_get_string (conf->priv->channel, LID_SWITCH_ON_AC_CFG, "Nothing");
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1 || val == 3) )
{
g_warning ("Invalid value %s for property %s, using default\n", str, LID_SWITCH_ON_AC_CFG);
conf->priv->lid_button_ac = XFPM_DO_NOTHING;
xfconf_channel_set_string (conf->priv->channel, LID_SWITCH_ON_AC_CFG, "Nothing");
}
else conf->priv->lid_button_ac = val;
g_free (str);
str = xfconf_channel_get_string (conf->priv->channel, LID_SWITCH_ON_BATTERY_CFG, "Nothing");
val = xfpm_shutdown_string_to_int (str);
if ( G_UNLIKELY (val == -1 || val == 3) )
{
g_warning ("Invalid value %s for property %s, using default\n", str, LID_SWITCH_ON_BATTERY_CFG);
conf->priv->lid_button_battery = XFPM_DO_NOTHING;
xfconf_channel_set_string (conf->priv->channel, LID_SWITCH_ON_BATTERY_CFG, "Nothing");
}
else conf->priv->lid_button_battery = val;
g_free (str);
conf->priv->lock_screen = xfconf_channel_get_bool (conf->priv->channel, LOCK_SCREEN_ON_SLEEP, TRUE);
#ifdef HAVE_DPMS
conf->priv->dpms_enabled =
xfconf_channel_get_bool (conf->priv->channel, DPMS_ENABLED_CFG, TRUE);
conf->priv->dpms_sleep_on_battery =
MIN( xfconf_channel_get_uint( conf->priv->channel, ON_BATT_DPMS_SLEEP, 3) * 60, 3600);
conf->priv->dpms_off_on_battery =
MIN(xfconf_channel_get_uint( conf->priv->channel, ON_BATT_DPMS_OFF, 5) * 60, 3600);
conf->priv->dpms_sleep_on_ac =
MIN(xfconf_channel_get_uint( conf->priv->channel, ON_AC_DPMS_SLEEP, 10) * 60, 3600);
conf->priv->dpms_off_on_ac =
MIN(xfconf_channel_get_uint( conf->priv->channel, ON_AC_DPMS_OFF, 15) * 60, 3600);
str = xfconf_channel_get_string (conf->priv->channel, DPMS_SLEEP_MODE, "sleep");
if ( xfpm_strequal (str, "sleep" ) )
{
conf->priv->sleep_dpms_mode = 0;
}
else if ( xfpm_strequal (str, "suspend") )
{
conf->priv->sleep_dpms_mode = 1;
}
else
{
g_critical("Invalid value %s for property %s\n", str, DPMS_SLEEP_MODE);
conf->priv->sleep_dpms_mode = 0;
}
g_free (str);
#endif /* HAVE_DPMS */
conf->priv->power_save_on_battery =
xfconf_channel_get_bool (conf->priv->channel, POWER_SAVE_ON_BATTERY, TRUE);
#ifdef SYSTEM_IS_LINUX
conf->priv->cpu_freq_control =
xfconf_channel_get_bool (conf->priv->channel, CPU_FREQ_CONTROL, TRUE);
#endif
conf->priv->brightness_on_ac_timeout =
xfconf_channel_get_uint (conf->priv->channel, BRIGHTNESS_ON_AC, 9);
if ( G_UNLIKELY (conf->priv->brightness_on_ac_timeout > 120 || conf->priv->brightness_on_ac_timeout < 9 ))
{
g_warning ("Value %d for %s is out of range", conf->priv->brightness_on_ac_timeout, BRIGHTNESS_ON_AC );
conf->priv->brightness_on_ac_timeout = 9;
}
conf->priv->brightness_on_battery_timeout =
xfconf_channel_get_uint (conf->priv->channel, BRIGHTNESS_ON_BATTERY, 10);
if ( G_UNLIKELY (conf->priv->brightness_on_battery_timeout > 120 || conf->priv->brightness_on_battery_timeout < 9) )
{
g_warning ("Value %d for %s is out of range", conf->priv->brightness_on_battery_timeout, BRIGHTNESS_ON_BATTERY );
conf->priv->brightness_on_battery_timeout = 10;
}
//FIXME: check if valid
str = xfconf_channel_get_string (conf->priv->channel, CRITICAL_BATT_ACTION_CFG, "Nothing");
conf->priv->critical_action = xfpm_shutdown_string_to_int (str);
g_free (str);
conf->priv->show_icon =
xfconf_channel_get_uint (conf->priv->channel, SHOW_TRAY_ICON_CFG, SHOW_ICON_WHEN_BATTERY_PRESENT);
if ( G_UNLIKELY ( conf->priv->show_icon > 3) )
{
g_warning ("Invalid value %d for property %s, using default\n", conf->priv->show_icon, SHOW_TRAY_ICON_CFG);
xfconf_channel_set_uint (conf->priv->channel, CRITICAL_BATT_ACTION_CFG, SHOW_ICON_WHEN_BATTERY_PRESENT);
}
conf->priv->critical_level =
xfconf_channel_get_uint (conf->priv->channel, CRITICAL_POWER_LEVEL, 0);
if ( G_UNLIKELY ( conf->priv->critical_level > 20) )
{
g_warning ("Value %d for property %s is out of range \n", conf->priv->critical_level, CRITICAL_POWER_LEVEL);
conf->priv->critical_level = 10;
}
conf->priv->inactivity_on_ac =
xfconf_channel_get_uint (conf->priv->channel, ON_AC_INACTIVITY_TIMEOUT, 30);
if ( G_UNLIKELY (conf->priv->inactivity_on_ac < 30 ) )
{
conf->priv->inactivity_on_ac = 30;
}
conf->priv->inactivity_on_battery =
xfconf_channel_get_uint (conf->priv->channel, ON_BATTERY_INACTIVITY_TIMEOUT, 30);
if ( G_UNLIKELY (conf->priv->inactivity_on_battery < 30) )
{
conf->priv->inactivity_on_battery = 30;
}
str = xfconf_channel_get_string (conf->priv->channel, INACTIVITY_SLEEP_MODE, "Suspend");
if ( xfpm_strequal (str, "Suspend"))
{
conf->priv->sleep_inactivity = TRUE;
}
else if ( xfpm_strequal (str, "Hibernate") )
{
conf->priv->sleep_inactivity = FALSE;
}
else
{
g_critical("Invalid value %s for property %s\n", str, INACTIVITY_SLEEP_MODE);
conf->priv->sleep_inactivity = TRUE;
}
conf->priv->enable_brightness =
xfconf_channel_get_bool (conf->priv->channel, ENABLE_BRIGHTNESS_CONTROL, TRUE);
}
static void
xfpm_xfconf_class_init (XfpmXfconfClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
signals[DPMS_SETTINGS_CHANGED] =
g_signal_new("dpms-settings-changed",
XFPM_TYPE_XFCONF,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(XfpmXfconfClass, dpms_settings_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
signals[POWER_SAVE_SETTINGS_CHANGED] =
g_signal_new("power-save-settings-changed",
XFPM_TYPE_XFCONF,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(XfpmXfconfClass, power_save_settings_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
signals[BRIGHTNESS_SETTINGS_CHANGED] =
g_signal_new("brightness-settings-changed",
XFPM_TYPE_XFCONF,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(XfpmXfconfClass, brightness_settings_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
signals[TRAY_ICON_SETTINGS_CHANGED] =
g_signal_new("tray-icon-settings-changed",
XFPM_TYPE_XFCONF,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(XfpmXfconfClass, tray_icon_settings_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
signals[INACTIVITY_TIMEOUT_CHANGED] =
g_signal_new("inactivity-timeout-changed",
XFPM_TYPE_XFCONF,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(XfpmXfconfClass, inactivity_timeout_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
object_class->finalize = xfpm_xfconf_finalize;
g_type_class_add_private (klass, sizeof(XfpmXfconfPrivate));
}
static void
xfpm_xfconf_init (XfpmXfconf *conf)
{
GError *error = NULL;
conf->priv = XFPM_XFCONF_GET_PRIVATE (conf);
if ( !xfconf_init(&error) )
{
g_critical ("xfconf_init failed: %s\n", error->message);
g_error_free (error);
}
else
{
conf->priv->channel = xfconf_channel_new ("xfce4-power-manager");
g_signal_connect (conf->priv->channel, "property-changed",
G_CALLBACK (xfpm_xfconf_property_changed_cb), conf);
xfpm_xfconf_load_configuration (conf);
}
conf->channel = xfconf_channel_new ("xfce4-power-manager");
}
static void
xfpm_xfconf_finalize(GObject *object)
{
XfpmXfconf *conf;
conf = XFPM_XFCONF(object);
if (conf->priv->channel )
g_object_unref (conf->priv->channel);
G_OBJECT_CLASS(xfpm_xfconf_parent_class)->finalize(object);
}
XfpmXfconf *
xfpm_xfconf_new(void)
{
if ( xfpm_xfconf_object != NULL )
{
g_object_ref (xfpm_xfconf_object);
}
else
{
xfpm_xfconf_object = g_object_new (XFPM_TYPE_XFCONF, NULL);
g_object_add_weak_pointer (xfpm_xfconf_object, &xfpm_xfconf_object);
}
return XFPM_XFCONF (xfpm_xfconf_object);
}
gboolean xfpm_xfconf_get_property_bool (XfpmXfconf *conf, const gchar *property)
{
g_return_val_if_fail (XFPM_IS_XFCONF(conf), FALSE);
if ( xfpm_strequal (property, LOCK_SCREEN_ON_SLEEP))
return conf->priv->lock_screen;
else if ( xfpm_strequal (property, POWER_SAVE_ON_BATTERY ) )
return conf->priv->power_save_on_battery;
#ifdef SYSTEM_IS_LINUX
else if ( xfpm_strequal (property, CPU_FREQ_CONTROL) )
return conf->priv->cpu_freq_control;
#endif
else if ( xfpm_strequal (property, GENERAL_NOTIFICATION_CFG ) )
return conf->priv->general_notification;
#ifdef HAVE_DPMS
else if ( xfpm_strequal (property, DPMS_SLEEP_MODE ))
return conf->priv->sleep_dpms_mode;
else if ( xfpm_strequal (property, DPMS_ENABLED_CFG) )
return conf->priv->dpms_enabled;
#endif /* HAVE_DPMS */
else if ( xfpm_strequal (property, INACTIVITY_SLEEP_MODE) )
return conf->priv->sleep_inactivity;
else if ( xfpm_strequal (property, ENABLE_BRIGHTNESS_CONTROL) )
return conf->priv->enable_brightness;
g_warn_if_reached ();
return FALSE;
}
guint8 xfpm_xfconf_get_property_enum (XfpmXfconf *conf, const gchar *property)
{
g_return_val_if_fail (XFPM_IS_XFCONF(conf), 0);
if ( xfpm_strequal (property, LID_SWITCH_ON_AC_CFG) )
return conf->priv->lid_button_ac;
else if ( xfpm_strequal (property, LID_SWITCH_ON_BATTERY_CFG) )
return conf->priv->lid_button_battery;
else if ( xfpm_strequal (property, SLEEP_SWITCH_CFG) )
return conf->priv->sleep_button;
else if ( xfpm_strequal (property, CRITICAL_BATT_ACTION_CFG) )
return conf->priv->critical_action;
else if ( xfpm_strequal (property, SHOW_TRAY_ICON_CFG ) )
return conf->priv->show_icon;
else if ( xfpm_strequal (property, POWER_SWITCH_CFG) )
return conf->priv->power_button;
else if ( xfpm_strequal (property, HIBERNATE_SWITCH_CFG ) )
return conf->priv->hibernate_button;
g_warn_if_reached ();
return 0;
}
gint xfpm_xfconf_get_property_int (XfpmXfconf *conf, const gchar *property)
{
g_return_val_if_fail (XFPM_IS_XFCONF(conf), 0);
if ( xfpm_strequal (property, BRIGHTNESS_ON_AC ) )
return conf->priv->brightness_on_ac_timeout;
#ifdef HAVE_DPMS
else if ( xfpm_strequal (property, ON_AC_DPMS_SLEEP))
return conf->priv->dpms_sleep_on_ac;
else if ( xfpm_strequal (property, ON_BATT_DPMS_SLEEP))
return conf->priv->dpms_sleep_on_battery;
else if ( xfpm_strequal (property, ON_AC_DPMS_OFF))
return conf->priv->dpms_off_on_ac;
else if ( xfpm_strequal (property, ON_BATT_DPMS_OFF))
return conf->priv->dpms_off_on_battery;
#endif /* HAVE_DPMS */
else if ( xfpm_strequal (property, BRIGHTNESS_ON_BATTERY ))
return conf->priv->brightness_on_battery_timeout;
else if ( xfpm_strequal (property, CRITICAL_POWER_LEVEL) )
return conf->priv->critical_level;
else if ( xfpm_strequal (property, ON_AC_INACTIVITY_TIMEOUT ) )
return conf->priv->inactivity_on_ac;
else if ( xfpm_strequal (property, ON_BATTERY_INACTIVITY_TIMEOUT ) )
return conf->priv->inactivity_on_battery;
g_warn_if_reached ();
return 0;
}
|