[Goodies-commits] r7030 - in xfce4-power-manager/trunk: . libxfpm panel-plugins/inhibit

Ali Abdallah aliov at xfce.org
Sun Mar 29 18:09:48 CEST 2009


Author: aliov
Date: 2009-03-29 16:09:48 +0000 (Sun, 29 Mar 2009)
New Revision: 7030

Modified:
   xfce4-power-manager/trunk/ChangeLog
   xfce4-power-manager/trunk/libxfpm/xfpm-notify.c
   xfce4-power-manager/trunk/panel-plugins/inhibit/inhibit-plugin.c
Log:
Inhibit plugin: automatically reconnect when the power manager restarts

Modified: xfce4-power-manager/trunk/ChangeLog
===================================================================
--- xfce4-power-manager/trunk/ChangeLog	2009-03-29 15:28:13 UTC (rev 7029)
+++ xfce4-power-manager/trunk/ChangeLog	2009-03-29 16:09:48 UTC (rev 7030)
@@ -1,4 +1,7 @@
 
+2009-03-29 18:09 Ali aliov at xfce.org 
+	 * : Inhibit plugin: automatically reconnect when the power manager restarts
+
 2009-03-29 17:28 Ali aliov at xfce.org 
 	 * : Disabling lid and sleep buttons if the power manager is in inhibit state
 

Modified: xfce4-power-manager/trunk/libxfpm/xfpm-notify.c
===================================================================
--- xfce4-power-manager/trunk/libxfpm/xfpm-notify.c	2009-03-29 15:28:13 UTC (rev 7029)
+++ xfce4-power-manager/trunk/libxfpm/xfpm-notify.c	2009-03-29 16:09:48 UTC (rev 7030)
@@ -139,6 +139,13 @@
     g_object_unref (G_OBJECT(n));
 }
 
+static gboolean
+xfpm_notify_show (NotifyNotification *n)
+{
+    notify_notification_show (n, NULL);
+    return FALSE;
+}
+
 static void
 xfpm_notify_close_notification (XfpmNotify *notify )
 {
@@ -216,5 +223,5 @@
 	notify->priv->notification = n;
     }
     
-    notify_notification_show (n, NULL);
+    g_idle_add ((GSourceFunc) xfpm_notify_show, n);
 }

Modified: xfce4-power-manager/trunk/panel-plugins/inhibit/inhibit-plugin.c
===================================================================
--- xfce4-power-manager/trunk/panel-plugins/inhibit/inhibit-plugin.c	2009-03-29 15:28:13 UTC (rev 7029)
+++ xfce4-power-manager/trunk/panel-plugins/inhibit/inhibit-plugin.c	2009-03-29 16:09:48 UTC (rev 7030)
@@ -49,6 +49,7 @@
     
     DBusGConnection  *bus;
     DBusGProxy       *proxy;
+    DBusGProxy       *monitor_proxy;
     
     XfpmNotify       *notify;
     
@@ -260,6 +261,10 @@
     {
 	inhibit_plugin_save_bool_entry ("power-manager-disconnected-notification", FALSE);
     }
+    else if ( xfpm_strequal (id, "power-manager-connected-notification") )
+    {
+	inhibit_plugin_save_bool_entry ("power-manager-connected-notification", FALSE);
+    }
 }
 
 /*
@@ -353,6 +358,7 @@
     g_signal_handlers_block_by_func (inhibit->proxy, proxy_destroy_cb, inhibit);
     g_object_unref (inhibit->proxy);
     inhibit->proxy = NULL;
+    inhibit->connected = FALSE;
 }
 
 /*
@@ -369,6 +375,9 @@
 	
     g_object_unref (inhibit->notify);
     
+    if ( inhibit->monitor_proxy )
+	g_object_unref (inhibit->monitor_proxy);
+    
     g_free (inhibit);
 }
 
@@ -414,9 +423,6 @@
 static void
 inhibit_plugin_connect (inhibit_t *inhibit)
 {
-    if (!inhibit->bus )
-	inhibit->bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
-    
     if ( !xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(inhibit->bus),
 				    "org.freedesktop.PowerManagement") )
     {
@@ -481,6 +487,53 @@
 }
 
 /*
+ * Monitor if a power manager won the org.freedesktop.PowerManagement.Inhibit name
+ */
+static void
+inhibit_plugin_name_owner_changed_cb (DBusGProxy *proxy, const gchar *name,
+				      const gchar *prev, const gchar *new,
+				      inhibit_t *inhibit)
+{
+    gboolean show_notification;
+    NotifyNotification *n;
+	
+    if ( g_strcmp0 (name, "org.freedesktop.PowerManagement.Inhibit") != 0)
+	return;
+	
+    if ( strlen (new) != 0 )
+    {
+	if ( inhibit->connected == TRUE )
+	{
+	    TRACE("Plugin is already connected!");
+	    return;
+	}
+	show_notification = inhibit_plugin_read_bool_entry ("power-manager-connected-notification");
+    
+	if ( show_notification )
+	{
+	    n = xfpm_notify_new_notification (inhibit->notify,
+					  (_("Inhibit plugin")),
+					  (_("Power manager is connected")),
+					  "gnome-inhibit-applet",
+					  5000,
+					  XFPM_NOTIFY_NORMAL,
+					  NULL);
+					  
+	    xfpm_notify_add_action_to_notification (inhibit->notify,
+						    n,
+						    "power-manager-connected-notification",
+						    (_("Don't show again")),
+						    (NotifyActionCallback) inhibit_plugin_notify_callback,
+						    inhibit);
+					  
+	    notify_notification_attach_to_widget (n, inhibit->button);
+	    xfpm_notify_present_notification (inhibit->notify, n, FALSE);
+	}
+	reload_activated (NULL, inhibit);
+    }
+}
+
+/*
  * Constructor of the plugin
  */
 static void
@@ -509,7 +562,27 @@
 		      G_CALLBACK(reload_activated), inhibit);
 		      
     xfce_panel_plugin_menu_insert_item (inhibit->plugin, GTK_MENU_ITEM(mi));
+    
+    /*
+     * Create the monitor proxy
+     */
 
+    inhibit->monitor_proxy 
+	= dbus_g_proxy_new_for_name_owner (inhibit->bus,
+					   "org.freedesktop.DBus",
+					   "/org/freedesktop/DBus",
+					   "org.freedesktop.DBus",
+					   NULL);
+    if ( !inhibit->monitor_proxy )
+	goto out;
+
+    dbus_g_proxy_add_signal (inhibit->monitor_proxy, "NameOwnerChanged",
+			     G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+			     
+    dbus_g_proxy_connect_signal (inhibit->monitor_proxy, "NameOwnerChanged",
+				 G_CALLBACK (inhibit_plugin_name_owner_changed_cb), inhibit, NULL);
+
+out:
     gtk_widget_show_all (inhibit->button);
 }
 
@@ -525,6 +598,7 @@
     
     inhibit->plugin = plugin;
     
+    inhibit->bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
     inhibit_plugin_construct (inhibit);
     
     inhibit_plugin_connect (inhibit);




More information about the Goodies-commits mailing list