gnome-power-manager r2947 - in trunk: . src



Author: rhughes
Date: Tue Sep  9 15:35:03 2008
New Revision: 2947
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=2947&view=rev

Log:
2008-09-09  Richard Hughes  <richard hughsie com>

* src/gpm-cell-array.c: (gpm_cell_array_emit_system_action),
(gpm_cell_array_percent_changed):
* src/gpm-warnings.c: (gpm_warnings_time_is_accurate),
(gpm_warnings_get_state), (gpm_warnings_init):
* src/gpm-warnings.h:
Only use the time for policy decisions when it is accurate, and GConf
is not disabled.
The bug is that critical battery actions are blocked while GPM doesn't
have a good profile for the battery.
This means that the first time you try on a new system, it fails.
Based on a patch from Joakim Andersson, many thanks.


Modified:
   trunk/ChangeLog
   trunk/src/gpm-cell-array.c
   trunk/src/gpm-warnings.c
   trunk/src/gpm-warnings.h

Modified: trunk/src/gpm-cell-array.c
==============================================================================
--- trunk/src/gpm-cell-array.c	(original)
+++ trunk/src/gpm-cell-array.c	Tue Sep  9 15:35:03 2008
@@ -491,21 +491,12 @@
 gpm_cell_array_emit_system_action (GpmCellArray	   *cell_array,
 				   GpmWarningsState warnings_state)
 {
-	gfloat accuracy;
 	GpmCellUnit *unit;
 
 	g_return_val_if_fail (GPM_IS_CELL_ARRAY (cell_array), FALSE);
 
-	/* do we trust the profile enough to make a decision? */
+	/* array */
 	unit = &(cell_array->priv->unit);
-	if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY) {
-		accuracy = gpm_profile_get_accuracy_average (cell_array->priv->profile,
-							     unit->is_discharging);
-		if (accuracy < GPM_PROFILE_GOOD_TRUST) {
-			egg_debug ("profile is not accurate. Not doing policy action");
-			return FALSE;
-		}
-	}
 
 	/* we are not primary, or we are primary with a trusted profile */
 	if (warnings_state == GPM_WARNINGS_ACTION) {
@@ -532,6 +523,7 @@
 {
 	GpmWarningsState warnings_state;
 	GpmCellUnit *unit;
+	gfloat accuracy;
 
 	g_return_if_fail (GPM_IS_CELL_ARRAY (cell_array));
 
@@ -558,6 +550,12 @@
 		cell_array->priv->done_fully_charged = FALSE;
 	}
 
+	/* do we trust the profile enough to make a decision based on time? */
+	if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY) {
+		accuracy = gpm_profile_get_accuracy_average (cell_array->priv->profile, unit->is_discharging);
+		gpm_warnings_time_is_accurate (warning, (accuracy > GPM_PROFILE_GOOD_TRUST));
+	}
+
 	/* only get a warning state if we are discharging */
 	if (unit->is_discharging) {
 		warnings_state = gpm_warnings_get_state (cell_array->priv->warnings, unit);

Modified: trunk/src/gpm-warnings.c
==============================================================================
--- trunk/src/gpm-warnings.c	(original)
+++ trunk/src/gpm-warnings.c	Tue Sep  9 15:35:03 2008
@@ -50,6 +50,7 @@
 {
 	GpmConf			*conf;
 	gboolean		 use_time_primary;
+	gboolean		 time_is_accurate;
 
 	guint			 low_percentage;
 	guint			 critical_percentage;
@@ -64,6 +65,21 @@
 
 static gpointer gpm_warnings_object = NULL;
 
+/**
+ * gpm_warnings_time_is_accurate:
+ * @warnings: This class instance
+ * @time_accurate: If the time remaining is accurate, and should be used for a policy action
+ *
+ * Return value: %TRUE if set
+ **/
+void
+gpm_warnings_time_is_accurate (GpmWarnings *warnings, gboolean time_accurate)
+{
+	g_return_if_fail (GPM_IS_WARNINGS (warnings));
+	egg_debug ("time accurate is %i", time_accurate);
+	warnings->priv->time_is_accurate = time_accurate;
+}
+
 static GpmWarningsState
 gpm_warnings_get_state_csr (GpmWarnings  *warnings,
 		           GpmCellUnit *unit)
@@ -150,15 +166,13 @@
 
 		type = gpm_warnings_get_state_percentage (warnings, unit);
 
-	} else if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY &&
-		   warnings->priv->use_time_primary) {
-
-		type = gpm_warnings_get_state_time (warnings, unit);
-
-	} else if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY &&
-		   warnings->priv->use_time_primary == FALSE) {
-
-		type = gpm_warnings_get_state_percentage (warnings, unit);
+	} else if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY) {
+		/* only use the time when it is accurate, and GConf is not disabled */
+		if (warnings->priv->time_is_accurate &&
+		    warnings->priv->use_time_primary)
+			type = gpm_warnings_get_state_time (warnings, unit);
+		else
+			type = gpm_warnings_get_state_percentage (warnings, unit);
 	}
 
 	/* If we have no important warningss, we should test for discharging */
@@ -228,6 +242,7 @@
 {
 	warnings->priv = GPM_WARNINGS_GET_PRIVATE (warnings);
 
+	warnings->priv->time_is_accurate = TRUE;
 	warnings->priv->conf = gpm_conf_new ();
 	g_signal_connect (warnings->priv->conf, "value-changed",
 			  G_CALLBACK (gconf_key_changed_cb), warnings);

Modified: trunk/src/gpm-warnings.h
==============================================================================
--- trunk/src/gpm-warnings.h	(original)
+++ trunk/src/gpm-warnings.h	Tue Sep  9 15:35:03 2008
@@ -56,11 +56,13 @@
 	GObjectClass	parent_class;
 } GpmWarningsClass;
 
-GType		 gpm_warnings_get_type	(void);
-GpmWarnings	*gpm_warnings_new	(void);
+GType		 gpm_warnings_get_type		(void);
+GpmWarnings	*gpm_warnings_new		(void);
 
-GpmWarningsState	 gpm_warnings_get_state	(GpmWarnings		*warnings,
-					 GpmCellUnit		*unit);
+GpmWarningsState gpm_warnings_get_state		(GpmWarnings		*warnings,
+						 GpmCellUnit		*unit);
+void		 gpm_warnings_time_is_accurate	(GpmWarnings		*warnings,
+						 gboolean		 time_accurate);
 
 G_END_DECLS
 



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