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

Ali Abdallah aliov at xfce.org
Tue Mar 10 13:24:36 CET 2009


Author: aliov
Date: 2009-03-10 12:24:36 +0000 (Tue, 10 Mar 2009)
New Revision: 6878

Modified:
   xfce4-power-manager/trunk/ChangeLog
   xfce4-power-manager/trunk/src/xfpm-battery.c
   xfce4-power-manager/trunk/src/xfpm-battery.h
   xfce4-power-manager/trunk/src/xfpm-engine.c
   xfce4-power-manager/trunk/src/xfpm-enum-glib.h
   xfce4-power-manager/trunk/src/xfpm-notify.c
   xfce4-power-manager/trunk/src/xfpm-notify.h
   xfce4-power-manager/trunk/src/xfpm-supply.c
   xfce4-power-manager/trunk/src/xfpm-supply.h
Log:
Handle critical battery charge+ update on the notifications

Modified: xfce4-power-manager/trunk/ChangeLog
===================================================================
--- xfce4-power-manager/trunk/ChangeLog	2009-03-10 09:11:33 UTC (rev 6877)
+++ xfce4-power-manager/trunk/ChangeLog	2009-03-10 12:24:36 UTC (rev 6878)
@@ -1,4 +1,7 @@
 
+2009-03-10 13:24 Ali aliov at xfce.org 
+	 * : Handle critical battery charge+ update on the notifications
+
 2009-03-10 10:11 Ali aliov at xfce.org 
 	 * : Added Only show in XFCE in the autostart file and correct tooltip of a primary battery
 

Modified: xfce4-power-manager/trunk/src/xfpm-battery.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-battery.c	2009-03-10 09:11:33 UTC (rev 6877)
+++ xfce4-power-manager/trunk/src/xfpm-battery.c	2009-03-10 12:24:36 UTC (rev 6878)
@@ -288,14 +288,19 @@
     }
     else if ( !is_charging && is_discharging )
     {
-	if ( percentage >= 10 )
+	if ( percentage > 20 )
 	{
 	    *state = BATTERY_IS_DISCHARGING;
 	    return  _("is discharging");
 	}
-	else
+	else if ( percentage >= 10 && percentage < 20)
 	{
-	    *state = BATTERY_CRITICALLY_LOW;
+	    *state = BATTERY_CHARGE_LOW;
+	    return  _("charge is low");
+	}
+	else if ( percentage < 10 )
+	{
+	    *state = BATTERY_CHARGE_CRITICAL;
 	    return _("is almost empty");
     	}
     }
@@ -359,7 +364,7 @@
 		
 	if ( state == BATTERY_IS_DISCHARGING || 
 	     state == BATTERY_CHARGE_LOW         || 
-	     state == BATTERY_CRITICALLY_LOW )
+	     state == BATTERY_CHARGE_CRITICAL )
         {
             est_time = _("Estimated time left");
         }
@@ -371,7 +376,7 @@
                                    hours,hours > 1 ? _("hours") : _("hour") ,
                                    minutes_left, minutes_left > 1 ? _("minutes") : _("minute"));
 				   
-	tip = g_strdup_printf ("%i%% %s \n%s %s\n%s", 
+	tip = g_strdup_printf ("%i%% %s %s\n%s\n%s", 
 			       percentage, 
 			       _("Battery"),
 			       str,

Modified: xfce4-power-manager/trunk/src/xfpm-battery.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-battery.h	2009-03-10 09:11:33 UTC (rev 6877)
+++ xfce4-power-manager/trunk/src/xfpm-battery.h	2009-03-10 12:24:36 UTC (rev 6878)
@@ -51,7 +51,10 @@
     void	        (*battery_state_changed)	(XfpmBattery *battery,
     					            	 XfpmBatteryState state);
     void                (*popup_battery_menu)		(XfpmBattery *battery,
-						         GtkStatusIcon *icon);
+						         GtkStatusIcon *icon,
+							 guint button,
+							 guint activate_time,
+							 guint type);
        
 } XfpmBatteryClass;
 

Modified: xfce4-power-manager/trunk/src/xfpm-engine.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-engine.c	2009-03-10 09:11:33 UTC (rev 6877)
+++ xfce4-power-manager/trunk/src/xfpm-engine.c	2009-03-10 12:24:36 UTC (rev 6878)
@@ -52,6 +52,7 @@
 #include "xfpm-engine.h"
 #include "xfpm-supply.h"
 #include "xfpm-cpu.h"
+#include "xfpm-network-manager.h"
 #include "xfpm-button-xf86.h"
 #include "xfpm-lid-hal.h"
 #include "xfpm-brightness-hal.h"
@@ -159,22 +160,6 @@
     G_OBJECT_CLASS(xfpm_engine_parent_class)->finalize(object);
 }
 
-static void
-xfpm_engine_block_shutdown_cb (XfpmSupply *supply, gboolean block, XfpmEngine *engine)
-{
-    engine->priv->block_shutdown = block;
-}
-
-static void
-xfpm_engine_on_battery_cb (XfpmSupply *supply, gboolean on_battery, XfpmEngine *engine)
-{
-    engine->priv->on_battery = on_battery;
-#ifdef HAVE_DPMS
-    xfpm_dpms_set_on_battery (engine->priv->dpms, on_battery);
-#endif
-    xfpm_cpu_set_on_battery (engine->priv->cpu, on_battery);
-}
-
 const gchar *
 _shutdown_string_from_enum (XfpmShutdownRequest shutdown)
 {
@@ -187,9 +172,38 @@
 	
     return "Nothing";
 }
+
+static void
+xfpm_engine_shutdown_request_battery_cb (XfpmSupply *supply, XfpmShutdownRequest action, XfpmEngine *engine)
+{
+    const gchar *shutdown =
+	_shutdown_string_from_enum (action);
 	
+    if ( xfpm_strequal (shutdown, "Nothing") )
+	return;
+	
+	
+    xfpm_send_message_to_network_manager ("sleep");
+    
+    if ( action != XFPM_DO_SHUTDOWN )
+	xfpm_lock_screen ();
+    
+    dbus_hal_shutdown (engine->priv->hbus, shutdown, NULL);
+    
+    xfpm_send_message_to_network_manager ("wake");
+}
 
 static void
+xfpm_engine_on_battery_cb (XfpmSupply *supply, gboolean on_battery, XfpmEngine *engine)
+{
+    engine->priv->on_battery = on_battery;
+#ifdef HAVE_DPMS
+    xfpm_dpms_set_on_battery (engine->priv->dpms, on_battery);
+#endif
+    xfpm_cpu_set_on_battery (engine->priv->cpu, on_battery);
+}
+
+static void
 xfpm_engine_shutdown_request (XfpmEngine *engine, XfpmShutdownRequest shutdown)
 {
     const gchar *action =
@@ -278,8 +292,8 @@
 
     engine->priv->supply = xfpm_supply_new (engine->priv->hbus, engine->priv->channel);
 
-    g_signal_connect (G_OBJECT(engine->priv->supply), "block-shutdown",
-		      G_CALLBACK (xfpm_engine_block_shutdown_cb), engine);
+    g_signal_connect (G_OBJECT(engine->priv->supply), "shutdown-request",
+		      G_CALLBACK (xfpm_engine_shutdown_request_battery_cb), engine);
 
     g_signal_connect (G_OBJECT(engine->priv->supply), "on-battery",
 		      G_CALLBACK (xfpm_engine_on_battery_cb), engine);

Modified: xfce4-power-manager/trunk/src/xfpm-enum-glib.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-enum-glib.h	2009-03-10 09:11:33 UTC (rev 6877)
+++ xfce4-power-manager/trunk/src/xfpm-enum-glib.h	2009-03-10 12:24:36 UTC (rev 6878)
@@ -51,7 +51,7 @@
     BATTERY_IS_CHARGING,
     BATTERY_IS_DISCHARGING,
     BATTERY_CHARGE_LOW,
-    BATTERY_CRITICALLY_LOW,
+    BATTERY_CHARGE_CRITICAL,
     BATTERY_NOT_PRESENT
     
 } XfpmBatteryState;

Modified: xfce4-power-manager/trunk/src/xfpm-notify.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-notify.c	2009-03-10 09:11:33 UTC (rev 6877)
+++ xfce4-power-manager/trunk/src/xfpm-notify.c	2009-03-10 12:24:36 UTC (rev 6878)
@@ -91,16 +91,6 @@
     G_OBJECT_CLASS(xfpm_notify_parent_class)->finalize(object);
 }
 
-static NotifyNotification *
-xfpm_notify_new_notification_internal (XfpmNotify *notify, const gchar *title, const gchar *message)
-{
-    NotifyNotification *n;
-    
-    n = notify_notification_new (title, message, NULL, NULL);
-    
-    return n;
-}
-
 static void
 xfpm_notify_set_icon (XfpmNotify *notify, NotifyNotification *n, const gchar *icon_name )
 {
@@ -114,6 +104,27 @@
     }
 }
 
+static NotifyNotification *
+xfpm_notify_new_notification_internal (XfpmNotify *notify, const gchar *title, const gchar *message,
+				       const gchar *icon_name, guint timeout,
+				       XfpmNotifyUrgency urgency, GtkStatusIcon *icon)
+{
+    NotifyNotification *n;
+    
+    n = notify_notification_new (title, message, NULL, NULL);
+    
+    if ( icon_name )
+    	xfpm_notify_set_icon (notify, n, icon_name);
+	
+    if ( icon )
+    	notify_notification_attach_to_status_icon (n, icon);
+	
+    notify_notification_set_urgency (n, urgency);
+    notify_notification_set_timeout (n, timeout);
+    
+    return n;
+}
+
 static void
 xfpm_notify_closed_cb (NotifyNotification *n, XfpmNotify *notify)
 {
@@ -150,14 +161,44 @@
     if ( !simple )
         xfpm_notify_close_notification (notify);
     
-    NotifyNotification *n = xfpm_notify_new_notification_internal (notify, title, text);
+    NotifyNotification *n = xfpm_notify_new_notification_internal (notify, title, 
+							           text, icon_name, 
+								   timeout, urgency, 
+								   icon);
+    xfpm_notify_present_notification (notify, n, simple);
+}
+
+NotifyNotification *xfpm_notify_new_notification (XfpmNotify *notify,
+						  const gchar *title,
+						  const gchar *text,
+						  const gchar *icon_name,
+						  guint timeout,
+						  XfpmNotifyUrgency urgency,
+						  GtkStatusIcon *icon)
+{
+    NotifyNotification *n = xfpm_notify_new_notification_internal (notify, title, 
+							           text, icon_name, 
+								   timeout, urgency, 
+								   icon);
+    return n;
+}
+
+void xfpm_notify_add_action_to_notification (XfpmNotify *notify, NotifyNotification *n,
+					    const gchar *id, const gchar *action_label,
+					    NotifyActionCallback callback, gpointer data)
+{
+    g_return_if_fail (XFPM_IS_NOTIFY(notify));
     
-    if ( icon_name )
-    	xfpm_notify_set_icon (notify, n, icon_name);
-	
-    if ( icon )
-    	notify_notification_attach_to_status_icon (n, icon);
+    notify_notification_add_action (n, id, action_label,
+				   (NotifyActionCallback)callback,
+				    data, NULL);
+    
+}
 
+void xfpm_notify_present_notification (XfpmNotify *notify, NotifyNotification *n, gboolean simple)
+{
+    g_return_if_fail (XFPM_IS_NOTIFY(notify));
+    
     if ( !simple )
     {
 	g_signal_connect (G_OBJECT(n),"closed",

Modified: xfce4-power-manager/trunk/src/xfpm-notify.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-notify.h	2009-03-10 09:11:33 UTC (rev 6877)
+++ xfce4-power-manager/trunk/src/xfpm-notify.h	2009-03-10 12:24:36 UTC (rev 6878)
@@ -24,6 +24,8 @@
 #include <glib-object.h>
 #include <gtk/gtk.h>
 
+#include <libnotify/notify.h>
+
 G_BEGIN_DECLS
 
 #define XFPM_TYPE_NOTIFY        (xfpm_notify_get_type () )
@@ -32,9 +34,9 @@
 
 typedef enum 
 {
+    XFPM_NOTIFY_LOW,
     XFPM_NOTIFY_CRITICAL,
-    XFPM_NOTIFY_NORMAL,
-    XFPM_NOTIFY_LOW
+    XFPM_NOTIFY_NORMAL
     
 } XfpmNotifyUrgency;
 
@@ -53,19 +55,35 @@
     
 } XfpmNotifyClass;
 
-GType        	 xfpm_notify_get_type          (void) G_GNUC_CONST;
-XfpmNotify      *xfpm_notify_new               (void);
+GType        	 	  xfpm_notify_get_type          	    (void) G_GNUC_CONST;
+XfpmNotify      	 *xfpm_notify_new                           (void);
 
-void             xfpm_notify_show_notification (XfpmNotify *notify,
-						const gchar *title,
-						const gchar *text,
-						const gchar *icon_name,
-						gint timeout,
-						gboolean simple,
-						XfpmNotifyUrgency urgency,
-						GtkStatusIcon *icon);
+void             	  xfpm_notify_show_notification 	    (XfpmNotify *notify,
+								     const gchar *title,
+								     const gchar *text,
+								     const gchar *icon_name,
+								     gint timeout,
+								     gboolean simple,
+								     XfpmNotifyUrgency urgency,
+								     GtkStatusIcon *icon);
 
+NotifyNotification       *xfpm_notify_new_notification  	    (XfpmNotify *notify,
+								     const gchar *title,
+								     const gchar *text,
+								     const gchar *icon_name,
+								     guint timeout,
+								     XfpmNotifyUrgency urgency,
+								     GtkStatusIcon *icon);
 
+void 			  xfpm_notify_add_action_to_notification    (XfpmNotify *notify, 
+								     NotifyNotification *n,
+								     const gchar *id, 
+								     const gchar *action_label,
+								     NotifyActionCallback callback, 
+								     gpointer data);
+void 			  xfpm_notify_present_notification 	    (XfpmNotify *notify, 
+								     NotifyNotification *n,
+								     gboolean simple);
 G_END_DECLS
 
 #endif /* __XFPM_NOTIFY_H */

Modified: xfce4-power-manager/trunk/src/xfpm-supply.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-supply.c	2009-03-10 09:11:33 UTC (rev 6877)
+++ xfce4-power-manager/trunk/src/xfpm-supply.c	2009-03-10 12:24:36 UTC (rev 6878)
@@ -38,7 +38,6 @@
 #include "xfpm-battery.h"
 #include "xfpm-adapter.h"
 #include "xfpm-notify.h"
-#include "xfpm-network-manager.h"
 #include "xfpm-enum.h"
 #include "xfpm-enum-types.h"
 #include "xfpm-config.h"
@@ -72,6 +71,7 @@
 
 enum
 {
+    SHUTDOWN_REQUEST,
     BLOCK_SHUTDOWN,
     ON_BATTERY,
     ON_LOW_BATTERY,
@@ -87,6 +87,15 @@
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
 
+    signals[SHUTDOWN_REQUEST] = 
+    	g_signal_new("shutdown-request",
+                      XFPM_TYPE_SUPPLY,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET(XfpmSupplyClass, shutdown_request),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__ENUM,
+                      G_TYPE_NONE, 1, XFPM_TYPE_SHUTDOWN_REQUEST);
+
     signals[BLOCK_SHUTDOWN] = 
     	g_signal_new("block-shutdown",
                       XFPM_TYPE_SUPPLY,
@@ -144,13 +153,13 @@
 	
     if ( supply->priv->hash )
     	g_hash_table_destroy (supply->priv->hash);
+	
     if ( supply->priv->notify )
     	g_object_unref (supply->priv->notify);
     
     G_OBJECT_CLASS(xfpm_supply_parent_class)->finalize(object);
 }
 
-
 static void
 xfpm_supply_hibernate_cb (GtkWidget *w, XfpmSupply *supply)
 {
@@ -161,14 +170,7 @@
     
     if ( ret ) 
     {
-	g_signal_emit (G_OBJECT(supply ), signals[BLOCK_SHUTDOWN], 0, TRUE);
-	
-	xfpm_send_message_to_network_manager ("sleep");
-	xfpm_lock_screen ();
-	dbus_hal_shutdown (supply->priv->hbus, "Hibernate", NULL);
-	xfpm_send_message_to_network_manager ("wake");
-	
-	g_signal_emit (G_OBJECT(supply ), signals[BLOCK_SHUTDOWN], 0, FALSE);
+	g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, XFPM_DO_HIBERNATE);
     }
 }
 
@@ -182,14 +184,7 @@
     
     if ( ret ) 
     {
-	g_signal_emit (G_OBJECT(supply ), signals[BLOCK_SHUTDOWN], 0, TRUE);
-	
-	xfpm_send_message_to_network_manager ("sleep");
-	xfpm_lock_screen ();
-	dbus_hal_shutdown (supply->priv->hbus, "Suspend", NULL);
-	xfpm_send_message_to_network_manager ("wake");
-	
-	g_signal_emit (G_OBJECT(supply ), signals[BLOCK_SHUTDOWN], 0, FALSE);
+	g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, XFPM_DO_SUSPEND);
     }
 }
 
@@ -220,10 +215,44 @@
     }
 }
 
+gboolean xfpm_supply_on_low_power ( XfpmSupply *supply)
+{
+    GList *list = NULL;
+    int i;
+    gboolean low_power = FALSE;
+    list = g_hash_table_get_values (supply->priv->hash);
+    
+    if ( !list)
+	return FALSE;
+	
+    for ( i=0; i< g_list_length(list); i++)
+    {
+	XfpmBattery *battery = NULL;
+	HalDeviceType type;
+	guint percentage;
+	battery = g_list_nth_data(list, i);
+	
+	if ( !battery )
+	    continue;
+	    
+	const HalDevice *device = xfpm_battery_get_device (battery);
+	g_object_get (G_OBJECT(device), "type", &type, "percentage", &percentage, NULL);
+	if ( type != HAL_DEVICE_TYPE_PRIMARY )
+	    continue;
+	    
+	if ( percentage < 10 ) //FIXME: make this configurable
+	    low_power = TRUE;
+	else 
+	    low_power = FALSE;
+    }
+    
+    return low_power;
+}
+
 static const gchar *
-xfpm_supply_get_message_from_battery_state ( XfpmBatteryState state, HalDeviceType type, gboolean adapter_present)
+xfpm_supply_get_message_from_battery_state (XfpmBatteryState state, gboolean adapter_present)
 {
-    switch ( state )
+    switch (state)
     {
 	case BATTERY_FULLY_CHARGED:
 	    return _("Your battery is fully charged");
@@ -232,40 +261,118 @@
 	    return  _("Battery is charging");
 	    break;
 	case BATTERY_IS_DISCHARGING:
-	    if ( type == HAL_DEVICE_TYPE_PRIMARY )
-	    	return adapter_present ? _("Your battery is discharging") : _("System is running on battery");
-	    else
-	    	return _("Your battery is discharging");
+	    return  adapter_present ? _("Your battery is discharging"): _("System is running on battery power");
 	    break;
 	case BATTERY_CHARGE_LOW:
-	    return _("Your battery charge is low");
+	    return adapter_present ? _("Your battery charge is low") : _("System is running on low power"); 
 	    break;
 	default:
-	    return  NULL;
-	    break;
+	    return NULL;
     }
 }
 
 static void
-xfpm_supply_show_battery_notification (XfpmSupply *supply, XfpmBatteryState state, XfpmBattery *battery)
+xfpm_supply_process_critical_action (XfpmSupply *supply)
 {
-    HalDeviceType type;
-    const HalDevice *device = xfpm_battery_get_device (battery);
+    //FIXME: shouldn't happen
+    g_return_if_fail (supply->priv->critical_action != XFPM_DO_SUSPEND );
     
-    if ( device )
-	g_object_get (G_OBJECT(device), "type", &type, NULL);
-    else
+    g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, supply->priv->critical_action);
+}
+
+static void
+_notify_action_callback (NotifyNotification *n, gchar *action, XfpmSupply *supply)
+{
+    if ( xfpm_strequal(action, "shutdow") )
+	g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, XFPM_DO_SHUTDOWN);
+    else if ( xfpm_strequal(action, "hibernate") )
+	g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, XFPM_DO_SHUTDOWN);
+}
+
+static void
+xfpm_supply_show_critical_action (XfpmSupply *supply, XfpmBattery *battery)
+{
+    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 )
     {
-	g_critical ("Unable to get device type\n");
+        xfpm_notify_add_action_to_notification(
+			       supply->priv->notify,
+			       n,
+                               "shutdown",
+                               _("Shutdown the system"),
+                               (NotifyActionCallback)_notify_action_callback,
+                               supply);   
+    }
+    
+    if ( supply->priv->power_management & SYSTEM_CAN_HIBERNATE )
+    {
+        xfpm_notify_add_action_to_notification(
+			       supply->priv->notify,
+			       n,
+                               "hibernate",
+                               _("Hibernate the system"),
+                               (NotifyActionCallback)_notify_action_callback,
+                               supply);      
+    }
+    
+    xfpm_notify_present_notification (supply->priv->notify, n, FALSE);
+    
+}
+
+static void
+xfpm_supply_handle_primary_critical (XfpmSupply *supply, XfpmBattery *battery)
+{
+    if ( xfpm_supply_on_low_power (supply) )
+    {
+	TRACE ("System is running on low power");
+	if ( supply->priv->critical_action == XFPM_DO_NOTHING )
+	{
+	    xfpm_supply_show_critical_action (supply, battery);
+	}
+	else
+	{
+	    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
+xfpm_supply_primary_battery_changed (XfpmSupply *supply, XfpmBattery *battery, XfpmBatteryState state)
+{
+    if ( state == BATTERY_CHARGE_CRITICAL )
+    {
+	xfpm_supply_handle_primary_critical (supply, battery);
 	return;
     }
     
     const gchar *message 
-    	= xfpm_supply_get_message_from_battery_state (state,
-						      type,
-						      supply->priv->adapter_found   ? 
-						      supply->priv->adapter_present : 
-						      TRUE);
+    	= xfpm_supply_get_message_from_battery_state (state, supply->priv->adapter_found ? 
+							     supply->priv->adapter_present : TRUE); // FIXME, TRUE makes sense here ?
+
     if ( !message )
     	return;
     
@@ -274,12 +381,55 @@
 				   message, 
 				   xfpm_battery_get_icon_name (battery),
 				   10000,
-				   FALSE, 
+				   FALSE,
 				   XFPM_NOTIFY_NORMAL,
 				   xfpm_battery_get_status_icon (battery));
 }
 
 static void
+xfpm_supply_misc_battery_changed (XfpmSupply *supply, XfpmBattery *battery, XfpmBatteryState state)
+{
+    const gchar *message 
+    	= xfpm_supply_get_message_from_battery_state (state, TRUE);
+	
+    if ( !message )
+    	return;
+    
+    xfpm_notify_show_notification (supply->priv->notify, 
+				   _("Xfce power manager"), 
+				   message, 
+				   xfpm_battery_get_icon_name (battery),
+				   10000,
+				   TRUE, 
+				   XFPM_NOTIFY_NORMAL,
+				   xfpm_battery_get_status_icon (battery));
+}
+
+static void
+xfpm_supply_show_battery_notification (XfpmSupply *supply, XfpmBatteryState state, XfpmBattery *battery)
+{
+    HalDeviceType type;
+    const HalDevice *device = xfpm_battery_get_device (battery);
+    
+    if ( device )
+	g_object_get (G_OBJECT(device), "type", &type, NULL);
+    else
+    {
+	g_critical ("Unable to get device type\n");
+	return;
+    }
+    
+    if ( type == HAL_DEVICE_TYPE_PRIMARY )
+    {
+	xfpm_supply_primary_battery_changed (supply, battery, state);
+    }
+    else 
+    {
+	xfpm_supply_misc_battery_changed (supply, battery, state);
+    }
+}
+
+static void
 xfpm_supply_battery_state_changed_cb (XfpmBattery *battery, XfpmBatteryState state, XfpmSupply *supply)
 {
     xfpm_supply_show_battery_notification (supply, state, battery);
@@ -337,7 +487,7 @@
     gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
     
     // Battery informations
-    mi = gtk_image_menu_item_new_with_label (_("Battery information"));
+    mi = gtk_image_menu_item_new_with_label (_("Information"));
     img = gtk_image_new_from_icon_name (_get_icon_name_from_battery_type(battery_type), GTK_ICON_SIZE_MENU);
     gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(mi), img);
     
@@ -560,7 +710,6 @@
 	    xfpm_battery_set_show_icon (battery, supply->priv->show_icon);
 	}
     }
-    
     g_list_free (list);
 }
 
@@ -581,7 +730,6 @@
 	supply->priv->show_icon = val;
 	xfpm_supply_set_battery_show_tray_icon (supply);
     }
-    
 }
 
 static void

Modified: xfce4-power-manager/trunk/src/xfpm-supply.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-supply.h	2009-03-10 09:11:33 UTC (rev 6877)
+++ xfce4-power-manager/trunk/src/xfpm-supply.h	2009-03-10 12:24:36 UTC (rev 6878)
@@ -26,6 +26,7 @@
 #include <xfconf/xfconf.h>
 
 #include "xfpm-enum.h"
+#include "xfpm-enum-glib.h"
 #include "dbus-hal.h"
 
 G_BEGIN_DECLS
@@ -47,6 +48,8 @@
 {
     GObjectClass         parent_class;
     
+    void                (*shutdown_request)	    (XfpmSupply *supply,
+						     XfpmShutdownRequest action);
     void	        (*block_shutdown)	    (XfpmSupply *supply,
     						     gboolean block);
     void                (*on_battery    )	    (XfpmSupply *supply,




More information about the Goodies-commits mailing list