32
32
#include <xfconf/xfconf.h>
34
34
#include <libxfce4util/libxfce4util.h>
35
#include <libxfcegui4/libxfcegui4.h>
35
#include <libxfce4ui/libxfce4ui.h>
37
#include "libxfpm/xfpm-common.h"
38
#include "libxfpm/xfpm-string.h"
39
#include "libxfpm/xfpm-icons.h"
37
#include "xfpm-common.h"
38
#include "xfpm-icons.h"
39
#include "xfpm-debug.h"
41
41
#include "interfaces/xfpm-settings_ui.h"
149
149
void lock_screen_toggled_cb (GtkWidget *w,
150
150
XfconfChannel *channel);
152
void cpu_freq_control_changed_cb (GtkWidget *w,
152
void on_battery_spin_changed (GtkWidget *w,
153
XfconfChannel *channel);
155
void on_ac_spin_changed (GtkWidget *w,
153
156
XfconfChannel *channel);
155
158
void _cursor_changed_cb (GtkTreeView *view,
706
cpu_freq_control_changed_cb (GtkWidget *w, XfconfChannel *channel)
708
void on_battery_spin_changed (GtkWidget *w, XfconfChannel *channel)
708
#ifdef SYSTEM_IS_LINUX
709
gboolean val = (gint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
710
gboolean val = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
711
if ( !xfconf_channel_set_bool (channel, PROPERTIES_PREFIX CPU_FREQ_CONTROL, val) )
712
if ( !xfconf_channel_set_bool (channel, PROPERTIES_PREFIX SPIN_DOWN_ON_BATTERY, val) )
713
g_critical ("Unable to set value for property %s\n", CPU_FREQ_CONTROL);
714
g_critical ("Unable to set value for property %s", SPIN_DOWN_ON_BATTERY);
719
void on_ac_spin_changed (GtkWidget *w, XfconfChannel *channel)
721
gboolean val = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
723
if ( !xfconf_channel_set_bool (channel, PROPERTIES_PREFIX SPIN_DOWN_ON_AC, val) )
725
g_critical ("Unable to set value for property %s", SPIN_DOWN_ON_AC);
720
xfpm_settings_on_battery (XfconfChannel *channel, gboolean user_privilege, gboolean can_suspend,
721
gboolean can_hibernate, gboolean has_lcd_brightness, gboolean has_lid)
730
xfpm_settings_on_battery (XfconfChannel *channel, gboolean auth_hibernate,
731
gboolean auth_suspend, gboolean can_shutdown,
732
gboolean can_suspend, gboolean can_hibernate,
733
gboolean has_lcd_brightness, gboolean has_lid,
734
gboolean devkit_disk, gboolean can_spin_down)
744
758
if ( !can_suspend && !can_hibernate )
746
760
gtk_widget_set_sensitive (inact, FALSE);
761
gtk_widget_set_tooltip_text (inact, _("Hibernate and suspend operations not supported"));
763
else if ( !auth_suspend && !auth_hibernate )
765
gtk_widget_set_sensitive (inact, FALSE);
747
766
gtk_widget_set_tooltip_text (inact, _("Hibernate and suspend operations not permitted"));
751
770
gtk_range_set_value (GTK_RANGE (inact), val);
754
if (!user_privilege )
756
gtk_widget_set_sensitive (battery_critical, FALSE);
757
gtk_widget_set_tooltip_text (battery_critical, _("Shutdown and hibernate operations not permitted"));
760
773
list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
762
775
gtk_combo_box_set_model (GTK_COMBO_BOX(battery_critical), GTK_TREE_MODEL(list_store));
764
777
gtk_list_store_append(list_store, &iter);
765
778
gtk_list_store_set (list_store, &iter, 0, _("Nothing"), 1, XFPM_DO_NOTHING, -1);
780
if ( can_suspend && auth_suspend )
769
782
gtk_list_store_append(list_store, &iter);
770
783
gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
786
if ( can_hibernate && auth_hibernate )
775
788
gtk_list_store_append(list_store, &iter);
776
789
gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
779
gtk_list_store_append(list_store, &iter);
780
gtk_list_store_set (list_store, &iter, 0, _("Shutdown"), 1, XFPM_DO_SHUTDOWN, -1);
794
gtk_list_store_append(list_store, &iter);
795
gtk_list_store_set (list_store, &iter, 0, _("Shutdown"), 1, XFPM_DO_SHUTDOWN, -1);
782
798
gtk_list_store_append(list_store, &iter);
783
799
gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
822
838
lid = GTK_WIDGET (gtk_builder_get_object (xml, "on-battery-lid"));
825
if (!user_privilege )
827
gtk_widget_set_sensitive (lid, FALSE);
828
gtk_widget_set_tooltip_text (lid, _("Shutdown and hibernate operations not permitted"));
831
841
list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
833
843
gtk_combo_box_set_model (GTK_COMBO_BOX(lid), GTK_TREE_MODEL(list_store));
835
845
gtk_list_store_append(list_store, &iter);
836
846
gtk_list_store_set (list_store, &iter, 0, _("Nothing"), 1, LID_TRIGGER_NOTHING, -1);
848
if ( can_suspend && auth_suspend )
840
850
gtk_list_store_append(list_store, &iter);
841
851
gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, LID_TRIGGER_SUSPEND, -1);
854
if ( can_hibernate && auth_hibernate)
846
856
gtk_list_store_append(list_store, &iter);
847
857
gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, LID_TRIGGER_HIBERNATE, -1);
895
905
gtk_notebook_remove_page (GTK_NOTEBOOK (nt), 1);
909
spin_down = GTK_WIDGET (gtk_builder_get_object (xml, "spin-down-on-battery"));
910
gtk_widget_set_sensitive (spin_down, can_spin_down);
914
gtk_widget_hide (spin_down);
916
else if ( !can_spin_down )
918
gtk_widget_set_tooltip_text (spin_down, _("Spinning down hard disks permission denied"));
901
xfpm_settings_on_ac (XfconfChannel *channel, gboolean user_privilege, gboolean can_suspend,
902
gboolean can_hibernate, gboolean has_lcd_brightness, gboolean has_lid)
923
xfpm_settings_on_ac (XfconfChannel *channel, gboolean auth_suspend,
924
gboolean auth_hibernate, gboolean can_suspend,
925
gboolean can_hibernate, gboolean has_lcd_brightness,
926
gboolean has_lid, gboolean devkit_disk, gboolean can_spin_down)
904
928
GtkWidget *inact;
906
930
GtkWidget *frame;
932
GtkWidget *spin_down;
908
933
GtkListStore *list_store;
909
934
GtkTreeIter iter;
920
945
if ( !can_suspend && !can_hibernate )
922
947
gtk_widget_set_sensitive (inact, FALSE);
948
gtk_widget_set_tooltip_text (inact, _("Hibernate and suspend operations not supported"));
950
else if ( !auth_suspend && !auth_hibernate )
952
gtk_widget_set_sensitive (inact, FALSE);
923
953
gtk_widget_set_tooltip_text (inact, _("Hibernate and suspend operations not permitted"));
949
979
list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
951
if ( !user_privilege )
953
gtk_widget_set_sensitive (lid, FALSE);
954
gtk_widget_set_tooltip_text (lid, _("Hibernate and suspend operations not permitted"));
957
981
gtk_combo_box_set_model (GTK_COMBO_BOX(lid), GTK_TREE_MODEL(list_store));
959
983
gtk_list_store_append(list_store, &iter);
1019
1043
gtk_notebook_remove_page (GTK_NOTEBOOK (GTK_WIDGET (gtk_builder_get_object (xml, "on-ac-notebook"))), 1);
1047
spin_down = GTK_WIDGET (gtk_builder_get_object (xml, "spin-down-on-ac"));
1048
gtk_widget_set_sensitive (spin_down, can_spin_down);
1052
gtk_widget_hide (spin_down);
1054
else if ( !can_spin_down )
1056
gtk_widget_set_tooltip_text (spin_down, _("Spinning down hard disks permission denied"));
1025
xfpm_settings_general (XfconfChannel *channel, gboolean user_privilege,
1062
xfpm_settings_general (XfconfChannel *channel, gboolean auth_hibernate,
1063
gboolean auth_suspend, gboolean can_shutdown,
1026
1064
gboolean can_suspend, gboolean can_hibernate,
1027
1065
gboolean has_sleep_button, gboolean has_hibernate_button,
1028
1066
gboolean has_power_button)
1106
1144
if ( has_power_button )
1108
if (!user_privilege )
1110
gtk_widget_set_sensitive (power, FALSE);
1111
gtk_widget_set_tooltip_text (power, _("Hibernate and suspend operations not permitted"));
1114
1146
gtk_combo_box_set_model (GTK_COMBO_BOX(power), GTK_TREE_MODEL(list_store));
1116
1148
gtk_list_store_append (list_store, &iter);
1117
1149
gtk_list_store_set (list_store, &iter, 0, _("Nothing"), 1, XFPM_DO_NOTHING, -1);
1151
if ( can_suspend && auth_suspend)
1121
1153
gtk_list_store_append (list_store, &iter);
1122
1154
gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
1125
if ( can_hibernate )
1157
if ( can_hibernate && auth_hibernate )
1127
1159
gtk_list_store_append (list_store, &iter);
1128
1160
gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
1131
gtk_list_store_append (list_store, &iter);
1132
gtk_list_store_set (list_store, &iter, 0, _("Shutdown"), 1, XFPM_DO_SHUTDOWN, -1);
1165
gtk_list_store_append (list_store, &iter);
1166
gtk_list_store_set (list_store, &iter, 0, _("Shutdown"), 1, XFPM_DO_SHUTDOWN, -1);
1134
1169
gtk_list_store_append (list_store, &iter);
1135
1170
gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
1164
1199
if (has_hibernate_button )
1166
if (!user_privilege )
1168
gtk_widget_set_sensitive (hibernate, FALSE);
1169
gtk_widget_set_tooltip_text (hibernate, _("Hibernate and suspend operations not permitted"));
1172
1201
gtk_combo_box_set_model (GTK_COMBO_BOX(hibernate), GTK_TREE_MODEL(list_store));
1174
1203
gtk_list_store_append (list_store, &iter);
1175
1204
gtk_list_store_set (list_store, &iter, 0, _("Nothing"), 1, XFPM_DO_NOTHING, -1);
1206
if ( can_suspend && auth_suspend)
1179
1208
gtk_list_store_append (list_store, &iter);
1180
1209
gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
1183
if ( can_hibernate )
1212
if ( can_hibernate && auth_hibernate )
1185
1214
gtk_list_store_append (list_store, &iter);
1186
1215
gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
1190
1219
gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
1192
1221
value = xfconf_channel_get_uint (channel, PROPERTIES_PREFIX HIBERNATE_SWITCH_CFG, XFPM_DO_NOTHING);
1193
1223
for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
1195
1225
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
1219
1249
if ( has_sleep_button )
1221
if (!user_privilege )
1223
gtk_widget_set_sensitive (sleep_w, FALSE);
1224
gtk_widget_set_tooltip_text (sleep_w, _("Hibernate and suspend operations not permitted"));
1227
1251
gtk_combo_box_set_model (GTK_COMBO_BOX(sleep_w), GTK_TREE_MODEL(list_store));
1229
1253
gtk_list_store_append (list_store, &iter);
1230
1254
gtk_list_store_set (list_store, &iter, 0, _("Nothing"), 1, XFPM_DO_NOTHING, -1);
1256
if ( can_suspend && auth_suspend )
1234
1258
gtk_list_store_append (list_store, &iter);
1235
1259
gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
1238
if ( can_hibernate )
1262
if ( can_hibernate && auth_hibernate)
1240
1264
gtk_list_store_append (list_store, &iter);
1241
1265
gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
1271
1295
val = xfconf_channel_get_bool (channel, PROPERTIES_PREFIX GENERAL_NOTIFICATION_CFG, TRUE);
1273
1297
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(notify), val);
1278
xfpm_settings_advanced (XfconfChannel *channel, gboolean system_laptop, gboolean user_privilege,
1301
xfpm_settings_advanced (XfconfChannel *channel, gboolean system_laptop,
1302
gboolean auth_hibernate, gboolean auth_suspend,
1279
1303
gboolean can_suspend, gboolean can_hibernate)
1283
1307
GtkWidget *critical_level;
1284
1308
GtkWidget *lock;
1286
1309
GtkWidget *label;
1287
1310
GtkWidget *sleep_dpms_mode;
1288
1311
GtkWidget *suspend_dpms_mode;
1293
1316
if ( !can_suspend )
1318
gtk_widget_set_sensitive (inact_suspend, FALSE);
1319
gtk_widget_set_tooltip_text (inact_suspend, _("Suspend operation not supported"));
1321
else if ( !auth_suspend )
1295
1323
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (inact_hibernate), TRUE);
1296
1324
gtk_widget_set_sensitive (inact_suspend, FALSE);
1297
1325
gtk_widget_set_tooltip_text (inact_suspend, _("Suspend operation not permitted"));
1300
1328
if ( !can_hibernate )
1302
1330
gtk_widget_set_sensitive (inact_hibernate, FALSE);
1331
gtk_widget_set_tooltip_text (inact_hibernate, _("Hibernate operation not supported"));
1333
else if ( !auth_hibernate)
1335
gtk_widget_set_sensitive (inact_hibernate, FALSE);
1303
1336
gtk_widget_set_tooltip_text (inact_hibernate, _("Hibernate operation not permitted"));
1306
1339
str = xfconf_channel_get_string (channel, PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE, "Suspend");
1307
if ( xfpm_strequal (str, "Suspend") )
1340
if ( !g_strcmp0 (str, "Suspend") )
1308
1341
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (inact_suspend), TRUE);
1309
else if ( xfpm_strequal (str, "Hibernate"))
1342
else if ( !g_strcmp0 (str, "Hibernate"))
1310
1343
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (inact_hibernate), TRUE);
1322
1355
#ifdef HAVE_DPMS
1323
1356
str = xfconf_channel_get_string (channel, PROPERTIES_PREFIX DPMS_SLEEP_MODE, "standby");
1325
if ( xfpm_strequal (str, "standby" ) )
1358
if ( !g_strcmp0 (str, "standby" ) )
1326
1359
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sleep_dpms_mode), TRUE);
1327
else if ( xfpm_strequal (str, "suspend") )
1360
else if ( !g_strcmp0 (str, "suspend") )
1328
1361
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (suspend_dpms_mode), TRUE);
1352
1385
val = xfconf_channel_get_uint (channel, PROPERTIES_PREFIX CRITICAL_POWER_LEVEL, 10);
1354
if ( G_UNLIKELY (val > 20) )
1387
if ( val > 20 || val < 5)
1356
1389
g_critical ("Value %d if out of range for property %s\n", val, CRITICAL_POWER_LEVEL);
1357
1390
gtk_spin_button_set_value (GTK_SPIN_BUTTON(critical_level), 10);
1372
1405
lock = GTK_WIDGET (gtk_builder_get_object (xml, "lock-screen"));
1374
if ( !user_privilege )
1407
if ( !can_suspend && !can_hibernate )
1409
gtk_widget_set_sensitive (lock, FALSE);
1410
gtk_widget_set_tooltip_text (lock, _("Hibernate and suspend operations not supported"));
1412
else if ( !auth_hibernate && !auth_suspend)
1376
1414
gtk_widget_set_sensitive (lock, FALSE);
1377
1415
gtk_widget_set_tooltip_text (lock, _("Hibernate and suspend operations not permitted"));
1380
1418
val = xfconf_channel_get_bool (channel, PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
1381
1419
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(lock), val);
1383
cpu = GTK_WIDGET (gtk_builder_get_object (xml, "cpu-freq"));
1385
#ifdef SYSTEM_IS_LINUX
1386
if ( system_laptop )
1388
val = xfconf_channel_get_bool (channel, PROPERTIES_PREFIX CPU_FREQ_CONTROL, TRUE);
1389
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(cpu), val);
1392
gtk_widget_hide (cpu);
1394
gtk_widget_hide (cpu);
1454
1477
gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
1456
1479
/*General settings */
1457
pix = xfce_themed_icon_load ("preferences-system", 48);
1480
pix = xfpm_icon_load ("preferences-system", 48);
1459
1482
gtk_list_store_append(list_store, &iter);
1472
1495
/* ON ac power */
1473
pix = xfce_themed_icon_load (XFPM_AC_ADAPTER_ICON, 48);
1496
pix = xfpm_icon_load (XFPM_AC_ADAPTER_ICON, 48);
1474
1497
gtk_list_store_append(list_store, &iter);
1486
1509
if ( system_laptop )
1488
pix = xfce_themed_icon_load (XFPM_BATTERY_ICON, 48);
1511
pix = xfpm_icon_load (XFPM_BATTERY_ICON, 48);
1489
1512
gtk_list_store_append(list_store, &iter);
1502
pix = xfce_themed_icon_load ("applications-other", 48);
1525
pix = xfpm_icon_load ("applications-other", 48);
1503
1526
gtk_list_store_append(list_store, &iter);
1548
1571
settings_quit (plug, channel);
1552
1575
xfpm_settings_dialog_new (XfconfChannel *channel, gboolean system_laptop,
1553
gboolean user_privilege, gboolean can_suspend,
1576
gboolean auth_hibernate, gboolean auth_suspend,
1577
gboolean can_shutdown, gboolean can_suspend,
1554
1578
gboolean can_hibernate, gboolean has_lcd_brightness,
1555
1579
gboolean has_lid, gboolean has_sleep_button,
1556
1580
gboolean has_hibernate_button, gboolean has_power_button,
1581
gboolean devkit_disk, gboolean can_spin_down,
1557
1582
GdkNativeWindow id)
1559
1584
GtkWidget *plug;
1561
1586
GtkWidget *allbox;
1562
1587
GError *error = NULL;
1564
TRACE("system_laptop=%s user_privilege=%s can_suspend=%s can_hibernate=%s has_lcd_brightness=%s has_lid=%s "\
1565
"has_sleep_button=%s has_hibernate_button=%s has_power_button=%s",
1566
xfpm_bool_to_string (system_laptop), xfpm_bool_to_string (user_privilege),
1589
XFPM_DEBUG ("system_laptop=%s auth_hibernate=%s auth_suspend=%s can_shutdown=%s can_suspend=%s can_hibernate=%s has_lcd_brightness=%s has_lid=%s "\
1590
"has_sleep_button=%s has_hibernate_button=%s has_power_button=%s can_spin_down=%s",
1591
xfpm_bool_to_string (system_laptop), xfpm_bool_to_string (auth_hibernate),
1592
xfpm_bool_to_string (can_shutdown), xfpm_bool_to_string (auth_suspend),
1567
1593
xfpm_bool_to_string (can_suspend), xfpm_bool_to_string (can_hibernate),
1568
1594
xfpm_bool_to_string (has_lcd_brightness), xfpm_bool_to_string (has_lid),
1569
1595
xfpm_bool_to_string (has_sleep_button), xfpm_bool_to_string (has_hibernate_button),
1570
xfpm_bool_to_string (has_power_button) );
1596
xfpm_bool_to_string (has_power_button), xfpm_bool_to_string (can_spin_down) );
1572
1598
xml = xfpm_builder_new_from_string (xfpm_settings_ui, &error);
1574
1600
if ( G_UNLIKELY (error) )
1576
xfce_err ("%s : %s", error->message, _("Check your power manager installation"));
1602
xfce_dialog_show_error (NULL, error, "%s", _("Check your power manager installation"));
1577
1603
g_error ("%s", error->message);
1589
1615
dialog = GTK_WIDGET (gtk_builder_get_object (xml, "xfpm-settings-dialog"));
1590
1616
nt = GTK_WIDGET (gtk_builder_get_object (xml, "main-notebook"));
1592
xfpm_settings_on_ac (channel, user_privilege, can_suspend, can_hibernate, has_lcd_brightness, has_lid );
1618
xfpm_settings_on_ac (channel,
1594
1628
if ( system_laptop )
1595
xfpm_settings_on_battery (channel, user_privilege, can_suspend, can_hibernate, has_lcd_brightness, has_lid);
1629
xfpm_settings_on_battery (channel,
1597
1640
xfpm_settings_tree_view (channel, system_laptop);
1599
xfpm_settings_general (channel, user_privilege, can_suspend, can_hibernate,
1642
xfpm_settings_general (channel, auth_hibernate, auth_suspend, can_shutdown, can_suspend, can_hibernate,
1600
1643
has_sleep_button, has_hibernate_button, has_power_button );
1602
xfpm_settings_advanced (channel, system_laptop, user_privilege, can_suspend, can_hibernate);
1645
xfpm_settings_advanced (channel, system_laptop, auth_hibernate, auth_suspend, can_suspend, can_hibernate);