[gnome-power-manager] Split notify-low-power into -system and -device keys, so that users can disable device notifications



commit 8668c62a0f09f5c485dfd6e18d8ba2471c46f929
Author: Richard Hughes <richard hughsie com>
Date:   Thu Oct 14 15:57:28 2010 +0100

    Split notify-low-power into -system and -device keys, so that users can disable device notifications for faulty devices attached to the computer and still get system events. Fixes #632029

 data/org.gnome.power-manager.gschema.migrate |    2 +-
 data/org.gnome.power-manager.gschema.xml     |    9 ++++++-
 src/gpm-common.h                             |    3 +-
 src/gpm-manager.c                            |   28 ++++++++++++++++++++++++++
 4 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/data/org.gnome.power-manager.gschema.migrate b/data/org.gnome.power-manager.gschema.migrate
index 7300083..56db7cd 100644
--- a/data/org.gnome.power-manager.gschema.migrate
+++ b/data/org.gnome.power-manager.gschema.migrate
@@ -40,7 +40,7 @@ notify-discharging = /apps/gnome-power-manager/notify/discharging
 notify-fully-charged = /apps/gnome-power-manager/notify/fully_charged
 notify-sleep-failed = /apps/gnome-power-manager/notify/sleep_failed
 notify-sleep-failed-uri = /apps/gnome-power-manager/notify/sleep_failed_uri
-notify-low-power = /apps/gnome-power-manager/notify/low_power
+notify-low-power-system = /apps/gnome-power-manager/notify/low_power
 info-history-graph-points = /apps/gnome-power-manager/statistics/show_events
 info-history-graph-smooth = /apps/gnome-power-manager/statistics/smooth_data
 info-history-type = /apps/gnome-power-manager/statistics/graph_type
diff --git a/data/org.gnome.power-manager.gschema.xml b/data/org.gnome.power-manager.gschema.xml
index 9506312..e71f6ba 100644
--- a/data/org.gnome.power-manager.gschema.xml
+++ b/data/org.gnome.power-manager.gschema.xml
@@ -225,10 +225,15 @@
       <summary>The URI to show to the user on sleep failure</summary>
       <description>When sleep fails we can show the user a button to help fix the situation. Leave this blank if the button should not be shown.</description>
     </key>
-    <key name="notify-low-power" type="b">
+    <key name="notify-low-power-system" type="b">
       <default>true</default>
       <summary>Notify on a low power</summary>
-      <description>If a notification message should be displayed when the battery is getting low.</description>
+      <description>If a notification message should be displayed when the system battery or UPS is getting low.</description>
+    </key>
+    <key name="notify-low-power-device" type="b">
+      <default>true</default>
+      <summary>Notify on a low power</summary>
+      <description>If a notification message should be displayed when devices attached to the computer are getting low.</description>
     </key>
     <key name="info-history-graph-points" type="b">
       <default>true</default>
diff --git a/src/gpm-common.h b/src/gpm-common.h
index fafc532..5797b18 100644
--- a/src/gpm-common.h
+++ b/src/gpm-common.h
@@ -100,7 +100,8 @@ G_BEGIN_DECLS
 #define GPM_SETTINGS_NOTIFY_FULLY_CHARGED		"notify-fully-charged"
 #define GPM_SETTINGS_NOTIFY_SLEEP_FAILED		"notify-sleep-failed"
 #define GPM_SETTINGS_NOTIFY_SLEEP_FAILED_URI		"notify-sleep-failed-uri"
-#define GPM_SETTINGS_NOTIFY_LOW_POWER			"notify-low-power"
+#define GPM_SETTINGS_NOTIFY_LOW_POWER_SYSTEM		"notify-low-power-system"
+#define GPM_SETTINGS_NOTIFY_LOW_POWER_DEVICE		"notify-low-power-device"
 
 /* thresholds */
 #define GPM_SETTINGS_PERCENTAGE_LOW			"percentage-low"
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index fc5e3f9..87a1bfe 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -1491,6 +1491,20 @@ gpm_manager_engine_charge_low_cb (GpmEngine *engine, UpDevice *device, GpmManage
 		      "time-to-empty", &time_to_empty,
 		      NULL);
 
+	/* do we do the notification */
+	if (kind == UP_DEVICE_KIND_BATTERY ||
+	    kind == UP_DEVICE_KIND_UPS) {
+		ret = g_settings_get_boolean (manager->priv->settings,
+					      GPM_SETTINGS_NOTIFY_LOW_POWER_SYSTEM);
+	} else {
+		ret = g_settings_get_boolean (manager->priv->settings,
+					      GPM_SETTINGS_NOTIFY_LOW_POWER_DEVICE);
+	}
+	if (!ret) {
+		egg_debug ("ignoring notication for type %s", up_device_kind_to_string (kind));
+		goto out;
+	}
+
 	/* check to see if the batteries have not noticed we are on AC */
 	if (kind == UP_DEVICE_KIND_BATTERY) {
 		if (!manager->priv->on_battery) {
@@ -1617,6 +1631,20 @@ gpm_manager_engine_charge_critical_cb (GpmEngine *engine, UpDevice *device, GpmM
 		}
 	}
 
+	/* do we do the notification */
+	if (kind == UP_DEVICE_KIND_BATTERY ||
+	    kind == UP_DEVICE_KIND_UPS) {
+		/* this is not configurable */
+		ret = TRUE;
+	} else {
+		ret = g_settings_get_boolean (manager->priv->settings,
+					      GPM_SETTINGS_NOTIFY_LOW_POWER_DEVICE);
+	}
+	if (!ret) {
+		egg_debug ("ignoring notication for type %s", up_device_kind_to_string (kind));
+		goto out;
+	}
+
 	if (kind == UP_DEVICE_KIND_BATTERY) {
 
 		/* if the user has no other batteries, drop the "Laptop" wording */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]