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



Author: rhughes
Date: Sun Jul 27 09:44:29 2008
New Revision: 2846
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=2846&view=rev

Log:
2008-07-23  Richard Hughes  <richard hughsie com>

* src/gpm-control.c: (gpm_control_check_foreground_console),
(gpm_control_allowed_suspend), (gpm_control_allowed_hibernate),
(gpm_control_allowed_shutdown), (gpm_control_allowed_reboot),
(gpm_control_suspend), (gpm_control_hibernate),
(gpm_control_class_init), (gpm_control_init):
* src/gpm-control.h:
* src/gpm-manager.c: (manager_policy_do), (idle_changed_cb):
Completely remove all traces of the skipping suppressed action --
we might introduce regressions, but people are complaining about
the bad error message.


Modified:
   trunk/ChangeLog
   trunk/src/gpm-control.c
   trunk/src/gpm-control.h
   trunk/src/gpm-manager.c

Modified: trunk/src/gpm-control.c
==============================================================================
--- trunk/src/gpm-control.c	(original)
+++ trunk/src/gpm-control.c	Sun Jul 27 09:44:29 2008
@@ -59,8 +59,6 @@
 	GpmConf			*conf;
 	HalGPower		*hal_power;
 	GpmPolkit		*polkit;
-	time_t			 last_resume_event;
-	guint			 suppress_policy_timeout;
 };
 
 enum {
@@ -91,7 +89,7 @@
 }
 
 /**
- * gpm_control_is_policy_timout_valid:
+ * gpm_control_check_foreground_console:
  * @manager: This class instance
  * @action: The action we want to do, e.g. "suspend"
  *
@@ -103,21 +101,13 @@
  *
  * Return value: TRUE if we can perform the action.
  **/
-gboolean
-gpm_control_is_policy_timout_valid (GpmControl *control)
+static gboolean
+gpm_control_check_foreground_console (GpmControl *control)
 {
 #ifdef HAVE_CHECK_FG
 	gchar *argv[] = { "check-foreground-console", NULL };
 	int retcode;
-#endif
-
-	if ((time (NULL) - control->priv->last_resume_event) <=
-	    control->priv->suppress_policy_timeout) {
-		gpm_debug ("Skipping suppressed action");
-		return FALSE;
-	}
 
-#ifdef HAVE_CHECK_FG
 	if (!g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
 				 NULL, NULL, &retcode, NULL)  || ! WIFEXITED (retcode) ) {
 		/* if check-foreground-console could not be executed,
@@ -133,19 +123,6 @@
 }
 
 /**
- * gpm_control_reset_event_time:
- * @manager: This class instance
- *
- * Resets the time so we do not do any more actions until the
- * timeout has passed.
- **/
-void
-gpm_control_reset_event_time (GpmControl *control)
-{
-	control->priv->last_resume_event = time (NULL);
-}
-
-/**
  * gpm_control_allowed_suspend:
  * @control: This class instance
  * @can: If we can suspend
@@ -161,6 +138,7 @@
 	gboolean conf_ok;
 	gboolean polkit_ok = TRUE;
 	gboolean hal_ok = FALSE;
+	gboolean fg;
 	g_return_val_if_fail (can, FALSE);
 
 	*can = FALSE;
@@ -169,7 +147,8 @@
 	if (control->priv->polkit) {
 		polkit_ok = gpm_polkit_is_user_privileged (control->priv->polkit, "hal-power-suspend");
 	}
-	if ( conf_ok && hal_ok && polkit_ok ) {
+	fg = gpm_control_check_foreground_console (control);
+	if ( conf_ok && hal_ok && polkit_ok && fg ) {
 		*can = TRUE;
 	}
 
@@ -192,15 +171,17 @@
 	gboolean conf_ok;
 	gboolean polkit_ok = TRUE;
 	gboolean hal_ok = FALSE;
+	gboolean fg;
 	g_return_val_if_fail (can, FALSE);
 
 	*can = FALSE;
 	gpm_conf_get_bool (control->priv->conf, GPM_CONF_CAN_HIBERNATE, &conf_ok);
 	hal_ok = hal_gpower_can_hibernate (control->priv->hal_power);
+	fg = gpm_control_check_foreground_console (control);
 	if (control->priv->polkit) {
 		polkit_ok = gpm_polkit_is_user_privileged (control->priv->polkit, "hal-power-hibernate");
 	}
-	if ( conf_ok && hal_ok && polkit_ok ) {
+	if ( conf_ok && hal_ok && polkit_ok && fg ) {
 		*can = TRUE;
 	}
 	return TRUE;
@@ -218,12 +199,14 @@
 			      GError    **error)
 {
 	gboolean polkit_ok = TRUE;
+	gboolean fg;
 	g_return_val_if_fail (can, FALSE);
 	*can = FALSE;
+	fg = gpm_control_check_foreground_console (control);
 	if (control->priv->polkit) {
 		polkit_ok = gpm_polkit_is_user_privileged (control->priv->polkit, "hal-power-shutdown");
 	}
-	if (polkit_ok == TRUE) {
+	if (polkit_ok && fg) {
 		*can = TRUE;
 	}
 	return TRUE;
@@ -242,12 +225,14 @@
 			    GError    **error)
 {
 	gboolean polkit_ok = TRUE;
+	gboolean fg;
 	g_return_val_if_fail (can, FALSE);
 	*can = FALSE;
+	fg = gpm_control_check_foreground_console (control);
 	if (control->priv->polkit) {
 		polkit_ok = gpm_polkit_is_user_privileged (control->priv->polkit, "hal-power-reboot");
 	}
-	if (polkit_ok == TRUE) {
+	if (polkit_ok && fg) {
 		*can = TRUE;
 	}
 	return TRUE;
@@ -461,8 +446,6 @@
 		gpm_networkmanager_wake ();
 	}
 
-	/* save the time that we resumed */
-	gpm_control_reset_event_time (control);
 	g_object_unref (screensaver);
 
 	return ret;
@@ -538,30 +521,12 @@
 		gpm_networkmanager_wake ();
 	}
 
-	/* save the time that we resumed */
-	gpm_control_reset_event_time (control);
 	g_object_unref (screensaver);
 
 	return ret;
 }
 
 /**
- * gpm_control_constructor:
- **/
-static GObject *
-gpm_control_constructor (GType		  type,
-			 guint		  n_construct_properties,
-			 GObjectConstructParam *construct_properties)
-{
-	GpmControl      *control;
-	GpmControlClass *klass;
-	klass = GPM_CONTROL_CLASS (g_type_class_peek (GPM_TYPE_CONTROL));
-	control = GPM_CONTROL (G_OBJECT_CLASS (gpm_control_parent_class)->constructor
-			      		     (type, n_construct_properties, construct_properties));
-	return G_OBJECT (control);
-}
-
-/**
  * gpm_control_finalize:
  **/
 static void
@@ -590,8 +555,7 @@
 gpm_control_class_init (GpmControlClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
-	object_class->finalize	   = gpm_control_finalize;
-	object_class->constructor  = gpm_control_constructor;
+	object_class->finalize = gpm_control_finalize;
 
 	signals [RESUME] =
 		g_signal_new ("resume",
@@ -651,13 +615,6 @@
 	control->priv->hal_power = hal_gpower_new ();
 
 	control->priv->conf = gpm_conf_new ();
-	gpm_conf_get_uint (control->priv->conf, GPM_CONF_POLICY_TIMEOUT,
-			   &control->priv->suppress_policy_timeout);
-	gpm_debug ("Using a supressed policy timeout of %i seconds",
-		   control->priv->suppress_policy_timeout);
-
-	/* Pretend we just resumed when we start to let actions settle */
-	gpm_control_reset_event_time (control);
 }
 
 /**

Modified: trunk/src/gpm-control.h
==============================================================================
--- trunk/src/gpm-control.h	(original)
+++ trunk/src/gpm-control.h	Sun Jul 27 09:44:29 2008
@@ -108,8 +108,6 @@
 							 GError		**error);
 gboolean	 gpm_control_get_lock_policy		(GpmControl	*control,
 							 const gchar	*policy);
-gboolean	 gpm_control_is_policy_timout_valid	(GpmControl	*control);
-void		 gpm_control_reset_event_time		(GpmControl	*control);
 
 G_END_DECLS
 

Modified: trunk/src/gpm-manager.c
==============================================================================
--- trunk/src/gpm-manager.c	(original)
+++ trunk/src/gpm-manager.c	Sun Jul 27 09:44:29 2008
@@ -427,17 +427,6 @@
 {
 	gchar *action = NULL;
 
-	/* error msg timeout not valid */
-	if (gpm_control_is_policy_timout_valid (manager->priv->control) == FALSE) {
-		gpm_notify_display (manager->priv->notify,
-				    _("Action forbidden"),
-				    _("Policy timeout is not valid. Please wait a few seconds and try again."),
-				    GPM_NOTIFY_TIMEOUT_SHORT,
-				    GPM_STOCK_APP_ICON,
-				    GPM_NOTIFY_URGENCY_NORMAL);
-		return FALSE;
-	}
-
 	/* are we inhibited? */
 	if (gpm_manager_is_inhibit_valid (manager, FALSE, "policy action") == FALSE) {
 		return FALSE;
@@ -831,9 +820,6 @@
 	} else if (mode == GPM_IDLE_MODE_SYSTEM) {
 		gpm_debug ("Idle state changed: SYSTEM");
 
-		if (gpm_control_is_policy_timout_valid (manager->priv->control) == FALSE) {
-			return;
-		}
 		if (gpm_manager_is_inhibit_valid (manager, FALSE, "timeout action") == FALSE) {
 			return;
 		}



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