Re: [gpm] A couple of GPM patches



On Mon, 2008-09-08 at 18:08 -0500, Ted Gould wrote:
> >       * Patch 11 is a little more invasive than I'd like but it seems to
> >         be complete.  It was originally for 2.22.6 but I've ported it to
> >         2.23.91.  The bug is that it seems that critical battery actions
> >         are blocked while GPM doesn't have a good profile for the
> >         battery.  Basically this means that the first time you try on a
> >         new system, it fails.

cc'ing the list, hope this is okay.

I've reviewed your patch and re-written it a little. Can you review it
and see if you think it does the same thing?

Thanks,

Richard.

Index: src/gpm-warnings.c
===================================================================
--- src/gpm-warnings.c	(revision 2940)
+++ src/gpm-warnings.c	(working copy)
@@ -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);
Index: src/gpm-cell-array.c
===================================================================
--- src/gpm-cell-array.c	(revision 2942)
+++ src/gpm-cell-array.c	(working copy)
@@ -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);
Index: src/gpm-warnings.h
===================================================================
--- src/gpm-warnings.h	(revision 2940)
+++ src/gpm-warnings.h	(working copy)
@@ -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]