[Goodies-commits] r7029 - in xfce4-power-manager/trunk: . src

Ali Abdallah aliov at xfce.org
Sun Mar 29 17:28:13 CEST 2009


Author: aliov
Date: 2009-03-29 15:28:13 +0000 (Sun, 29 Mar 2009)
New Revision: 7029

Modified:
   xfce4-power-manager/trunk/ChangeLog
   xfce4-power-manager/trunk/src/xfpm-engine.c
   xfce4-power-manager/trunk/src/xfpm-inhibit.c
   xfce4-power-manager/trunk/src/xfpm-screen-saver.c
   xfce4-power-manager/trunk/src/xfpm-supply.c
   xfce4-power-manager/trunk/src/xfpm-tray-icon.c
Log:
Disabling lid and sleep buttons if the power manager is in inhibit state

Modified: xfce4-power-manager/trunk/ChangeLog
===================================================================
--- xfce4-power-manager/trunk/ChangeLog	2009-03-29 14:24:12 UTC (rev 7028)
+++ xfce4-power-manager/trunk/ChangeLog	2009-03-29 15:28:13 UTC (rev 7029)
@@ -1,4 +1,7 @@
 
+2009-03-29 17:28 Ali aliov at xfce.org 
+	 * : Disabling lid and sleep buttons if the power manager is in inhibit state
+
 2009-03-29 16:24 Ali aliov at xfce.org 
 	 * : Added option to reload panel brightness plugin
 

Modified: xfce4-power-manager/trunk/src/xfpm-engine.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-engine.c	2009-03-29 14:24:12 UTC (rev 7028)
+++ xfce4-power-manager/trunk/src/xfpm-engine.c	2009-03-29 15:28:13 UTC (rev 7029)
@@ -164,12 +164,12 @@
 	}
 	else if (shutdown == XFPM_DO_HIBERNATE)
 	{
-	    g_timeout_add_seconds (4, (GSourceFunc) xfpm_engine_do_hibernate,
+	    g_timeout_add_seconds (2, (GSourceFunc) xfpm_engine_do_hibernate,
 				   engine);
 	}
 	else if (shutdown == XFPM_DO_SUSPEND)
 	{
-	    g_timeout_add_seconds (4, (GSourceFunc) xfpm_engine_do_suspend,
+	    g_timeout_add_seconds (2, (GSourceFunc) xfpm_engine_do_suspend,
 				   engine);
 	}
 
@@ -184,6 +184,9 @@
 					 XfpmShutdownRequest action,
 					 XfpmEngine * engine)
 {
+    if ( engine->priv->inhibited && critical == FALSE ) /* We can ignore the request here */
+	return;
+	
     xfpm_engine_shutdown_request (engine, action, critical);
 }
 
@@ -194,6 +197,12 @@
     TRACE ("Received button press event type %d", type);
     XfpmShutdownRequest shutdown;
   
+    if ( engine->priv->inhibited )
+    {
+	TRACE("Power manager automatic sleep is currently disabled");
+	return;
+    }
+  
     if ( type != BUTTON_POWER_OFF && type != BUTTON_SLEEP )
 	return;
 
@@ -215,6 +224,11 @@
 					      LID_SWITCH_ON_BATTERY_CFG :
 					      LID_SWITCH_ON_AC_CFG);
 
+    if ( engine->priv->inhibited )
+    {
+	TRACE("Power manager automatic sleep is currently disabled");
+	return;
+    }
     xfpm_engine_shutdown_request (engine, shutdown, FALSE);
 }
 

Modified: xfce4-power-manager/trunk/src/xfpm-inhibit.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-inhibit.c	2009-03-29 14:24:12 UTC (rev 7028)
+++ xfce4-power-manager/trunk/src/xfpm-inhibit.c	2009-03-29 15:28:13 UTC (rev 7029)
@@ -77,7 +77,7 @@
 static void
 xfpm_inhibit_screen_saver_inhibited_cb (XfpmScreenSaver *srv, gboolean is_inhibited, XfpmInhibit *inhibit)
 {
-   // inhibit->priv->inhibited = is_inhibited;
+    //inhibit->priv->inhibited = is_inhibited;
     //g_signal_emit (G_OBJECT(inhibit), signals[HAS_INHIBIT_CHANGED], 0, is_inhibited);
 }
 

Modified: xfce4-power-manager/trunk/src/xfpm-screen-saver.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-screen-saver.c	2009-03-29 14:24:12 UTC (rev 7028)
+++ xfce4-power-manager/trunk/src/xfpm-screen-saver.c	2009-03-29 15:28:13 UTC (rev 7029)
@@ -81,25 +81,21 @@
     if ( dbus_message_is_method_call (message, "org.gnome.ScreenSaver", "Inhibit") )
     {
 	g_signal_emit (G_OBJECT(srv), signals[SCREEN_SAVER_INHIBITED], 0, TRUE);
-	return DBUS_HANDLER_RESULT_HANDLED;
     }
     else if ( dbus_message_is_method_call (message, "org.gnome.ScreenSaver", "UnInhibit") )
     {
 	g_signal_emit (G_OBJECT(srv), signals[SCREEN_SAVER_INHIBITED], 0, FALSE);
-	return DBUS_HANDLER_RESULT_HANDLED;
     }
     else if ( dbus_message_is_method_call (message, "org.freedesktop.ScreenSaver", "Inhibit") )
     {
 	g_signal_emit (G_OBJECT(srv), signals[SCREEN_SAVER_INHIBITED], 0, TRUE);
-	return DBUS_HANDLER_RESULT_HANDLED;
     }
     else if ( dbus_message_is_method_call (message, "org.freedesktop.ScreenSaver", "UnInhibit") )
     {
 	g_signal_emit (G_OBJECT(srv), signals[SCREEN_SAVER_INHIBITED], 0, FALSE);
-	return DBUS_HANDLER_RESULT_HANDLED;
     }
     
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; /* Keep on as we just want to spy */
 }
 
 static void

Modified: xfce4-power-manager/trunk/src/xfpm-supply.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-supply.c	2009-03-29 14:24:12 UTC (rev 7028)
+++ xfce4-power-manager/trunk/src/xfpm-supply.c	2009-03-29 15:28:13 UTC (rev 7029)
@@ -44,6 +44,7 @@
 #include "xfpm-tray-icon.h"
 #include "xfpm-config.h"
 #include "xfpm-shutdown.h"
+#include "xfpm-inhibit.h"
 #include "xfpm-marshal.h"
 
 /* Init */
@@ -60,11 +61,13 @@
     XfpmAdapter   *adapter;
     XfpmXfconf    *conf;
     XfpmTrayIcon  *tray;
+    XfpmInhibit   *inhibit;
     
     HalPower      *power;
     GHashTable    *hash;
     
     gboolean       adapter_present;
+    gboolean       inhibited;
     guint8         power_management;
 };
 
@@ -79,6 +82,12 @@
 G_DEFINE_TYPE(XfpmSupply, xfpm_supply, G_TYPE_OBJECT)
 
 static void
+xfpm_supply_has_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean inhibited, XfpmSupply *supply)
+{
+    supply->priv->inhibited = inhibited;
+}
+
+static void
 xfpm_supply_class_init(XfpmSupplyClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
@@ -110,9 +119,15 @@
     supply->priv->notify  = xfpm_notify_new    ();
     supply->priv->conf    = xfpm_xfconf_new    ();
     supply->priv->tray    = xfpm_tray_icon_new ();
+    supply->priv->inhibit = xfpm_inhibit_new   ();
+    supply->priv->inhibited = FALSE;
+    
     xfpm_tray_icon_set_visible (supply->priv->tray, FALSE);
     xfpm_tray_icon_set_icon (supply->priv->tray, "gpm-ac-adapter");
     xfpm_tray_icon_set_show_info_menu (supply->priv->tray, FALSE);
+    
+    g_signal_connect (supply->priv->inhibit, "has-inhibit-changed",
+		      G_CALLBACK (xfpm_supply_has_inhibit_changed_cb), supply);
 }
 
 static void
@@ -132,6 +147,8 @@
     g_object_unref (supply->priv->adapter);
     
     g_object_unref (supply->priv->tray);
+    
+    g_object_unref (supply->priv->inhibit);
 	
     G_OBJECT_CLASS(xfpm_supply_parent_class)->finalize(object);
 }
@@ -218,21 +235,8 @@
 }
 
 static void
-xfpm_supply_show_critical_action (XfpmSupply *supply, XfpmBattery *battery)
+xfpm_supply_add_actions_to_notification (XfpmSupply *supply, XfpmBattery *battery, NotifyNotification *n)
 {
-    const gchar *message;
-    message = _("Your battery is almost empty. "\
-              "Save your work to avoid losing data");
-	      
-    NotifyNotification *n = 
-	xfpm_notify_new_notification (supply->priv->notify, 
-				      _("Xfce power manager"), 
-				      message, 
-				      xfpm_battery_get_icon_name (battery),
-				      10000,
-				      XFPM_NOTIFY_CRITICAL,
-				      xfpm_battery_get_status_icon (battery));
-				   
     if (supply->priv->power_management != 0 )
     {
         xfpm_notify_add_action_to_notification(
@@ -254,11 +258,58 @@
                                (NotifyActionCallback)_notify_action_callback,
                                supply);      
     }
+}
+
+static void
+xfpm_supply_show_critical_action_inhibited (XfpmSupply *supply, XfpmBattery *battery)
+{
+    NotifyNotification *n;
+    const gchar *message;
     
+    message = _("System is running on low power, "\
+               "but an application is currently disabling the automatic sleep, "\
+	       "this means that doing a sleep now may damage the data of this application. "\
+	       "Close this application before putting the computer on sleep mode or plug "\
+	       "in your AC adapter");
+    
+     n = 
+	xfpm_notify_new_notification (supply->priv->notify, 
+				      _("Xfce power manager"), 
+				      message, 
+				      xfpm_battery_get_icon_name (battery),
+				      30000,
+				      XFPM_NOTIFY_CRITICAL,
+				      xfpm_battery_get_status_icon (battery));
+				      
+    xfpm_supply_add_actions_to_notification (supply, battery, n);
+    
     xfpm_notify_present_notification (supply->priv->notify, n, FALSE);
 }
 
 static void
+xfpm_supply_show_critical_action (XfpmSupply *supply, XfpmBattery *battery)
+{
+    const gchar *message;
+    NotifyNotification *n;
+    
+    message = _("System is running on low power. "\
+              "Save your work to avoid losing data");
+	      
+    n = 
+	xfpm_notify_new_notification (supply->priv->notify, 
+				      _("Xfce power manager"), 
+				      message, 
+				      xfpm_battery_get_icon_name (battery),
+				      15000,
+				      XFPM_NOTIFY_CRITICAL,
+				      xfpm_battery_get_status_icon (battery));
+    
+    xfpm_supply_add_actions_to_notification (supply, battery, n);
+    
+    xfpm_notify_present_notification (supply->priv->notify, n, FALSE);
+}
+
+static void
 xfpm_supply_handle_primary_critical (XfpmSupply *supply, XfpmBattery *battery)
 {
     XfpmShutdownRequest critical_action = 
@@ -267,8 +318,12 @@
     if ( xfpm_supply_on_low_power (supply) )
     {
 	TRACE ("System is running on low power");
-	if ( critical_action == XFPM_DO_NOTHING )
+	if ( supply->priv->inhibited )
 	{
+	    xfpm_supply_show_critical_action_inhibited (supply, battery);
+	}
+	else if ( critical_action == XFPM_DO_NOTHING )
+	{
 	    xfpm_supply_show_critical_action (supply, battery);
 	}
 	else
@@ -276,18 +331,6 @@
 	    xfpm_supply_process_critical_action (supply);
 	}
     }
-    else 
-    {
-	const gchar *message = _("Your battery is almost empty");
-	xfpm_notify_show_notification (supply->priv->notify, 
-				   _("Xfce power manager"), 
-				   message, 
-				   xfpm_battery_get_icon_name (battery),
-				   10000,
-				   FALSE,
-				   XFPM_NOTIFY_NORMAL,
-				   xfpm_battery_get_status_icon (battery));
-    }
 }
 
 static void

Modified: xfce4-power-manager/trunk/src/xfpm-tray-icon.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-tray-icon.c	2009-03-29 14:24:12 UTC (rev 7028)
+++ xfce4-power-manager/trunk/src/xfpm-tray-icon.c	2009-03-29 15:28:13 UTC (rev 7029)
@@ -39,6 +39,7 @@
 #include "xfpm-tray-icon.h"
 #include "xfpm-network-manager.h"
 #include "xfpm-shutdown.h"
+#include "xfpm-inhibit.h"
 #include "xfpm-xfconf.h"
 #include "xfpm-config.h"
 
@@ -55,10 +56,12 @@
     XfpmShutdown  *shutdown;
     XfpmXfconf    *conf;
     XfpmNotify    *notify;
+    XfpmInhibit   *inhibit;
     
     GtkStatusIcon *icon;
     GQuark         icon_quark;
     gboolean       info_menu;
+    gboolean       inhibited;
 };
 
 enum
@@ -149,9 +152,17 @@
 static void
 xfpm_tray_icon_hibernate_cb (GtkWidget *w, XfpmTrayIcon *tray)
 {
+    const gchar *message;
     gboolean lock_screen;
+    
+    message = tray->priv->inhibited ? 
+	     _("An application is currently disabling the automatic sleep,"
+	      " doing this action now may damage the working state of this application,"
+	      " are you sure you want to hibernate the system?") :
+	      _("Are you sure you want to procced?") ;
+    
     gboolean ret = 
-    xfce_confirm (_("Are you sure you want to hibernate the system?"),
+    xfce_confirm (message,
                   GTK_STOCK_YES,
                   _("Hibernate"));
     
@@ -168,10 +179,18 @@
 static void
 xfpm_tray_icon_suspend_cb (GtkWidget *w, XfpmTrayIcon *tray)
 {
+    const gchar *message;
     gboolean lock_screen;
+    
+    message = tray->priv->inhibited ? 
+	     _("An application is currently disabling the automatic sleep,"
+	      " doing this action now may damage the working state of this application,"
+	      " are you sure you want to suspend the system?") :
+	      _("Are you sure you want to procced?") ;
+    
     gboolean ret = 
-    xfce_confirm (_("Are you sure you want to suspend the system?"),
-                  GTK_STOCK_YES,
+    xfce_confirm  (message,
+                   GTK_STOCK_YES,
                   _("Suspend"));
     
     if ( ret ) 
@@ -286,6 +305,12 @@
 }
 
 static void
+xfpm_tray_icon_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean inhibited, XfpmTrayIcon *tray)
+{
+    tray->priv->inhibited = inhibited;
+}
+
+static void
 xfpm_tray_icon_class_init(XfpmTrayIconClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
@@ -313,6 +338,8 @@
     tray->priv->shutdown = xfpm_shutdown_new ();
     tray->priv->conf  = xfpm_xfconf_new ();
     tray->priv->notify = xfpm_notify_new ();
+    tray->priv->inhibited = FALSE;
+    tray->priv->inhibit = xfpm_inhibit_new ();
     
     tray->priv->info_menu = TRUE;
     tray->priv->icon_quark = 0;
@@ -322,6 +349,9 @@
 		      
     g_signal_connect (tray->priv->icon, "popup-menu",
 		      G_CALLBACK (xfpm_tray_icon_popup_menu_cb), tray);
+		      
+    g_signal_connect (tray->priv->inhibit, "has-inhibit-changed",
+		      G_CALLBACK (xfpm_tray_icon_inhibit_changed_cb), tray);
 }
 
 static void
@@ -338,6 +368,8 @@
     g_object_unref (tray->priv->conf);
     
     g_object_unref (tray->priv->notify);
+    
+    g_object_unref (tray->priv->inhibit);
 
     G_OBJECT_CLASS(xfpm_tray_icon_parent_class)->finalize(object);
 }




More information about the Goodies-commits mailing list