[Xfce4-commits] <xfce4-panel:nick/poweractions> Adjust to new power-related dbus methods.

Nick Schermer noreply at xfce.org
Sun Dec 4 11:44:02 CET 2011


Updating branch refs/heads/nick/poweractions
         to b0f45ac5e328c1a966300b22e26c0ea60f716cbe (commit)
       from 8017f4b5f1f0b55cf86487a9e26a7e6704c0f7ee (commit)

commit b0f45ac5e328c1a966300b22e26c0ea60f716cbe
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Dec 3 11:49:58 2011 +0100

    Adjust to new power-related dbus methods.

 plugins/actions/actions.c |  138 +++++++++++++++++++++++++++++++++------------
 1 files changed, 102 insertions(+), 36 deletions(-)

diff --git a/plugins/actions/actions.c b/plugins/actions/actions.c
index 6b50486..7fb44fe 100644
--- a/plugins/actions/actions.c
+++ b/plugins/actions/actions.c
@@ -120,19 +120,6 @@ typedef enum
 }
 ActionType;
 
-/* copied from xfce4-session/shutdown.h -- ORDER MATTERS.
- * The numbers correspond to the 'type' parameter of
- * org.xfce.Session.Manager.Shutdown */
-typedef enum
-{
-  ACTION_SHUTDOWN_ASK = 0,
-  ACTION_SHUTDOWN_LOGOUT,
-  ACTION_SHUTDOWN_HALT,
-  ACTION_SHUTDOWN_REBOOT,
-  ACTION_SHUTDOWN_SUSPEND,
-  ACTION_SHUTDOWN_HIBERNATE,
-} ActionShutdownType;
-
 typedef struct
 {
   ActionType   type;
@@ -769,9 +756,10 @@ actions_plugin_action_confirmation (ActionsPlugin *plugin,
 
 
 static gboolean
-actions_plugin_action_activate_dbus (ActionShutdownType   type,
-                                     gboolean             allow_save,
-                                     GError             **error)
+actions_plugin_action_dbus_xfsm (const gchar  *method,
+                                 gboolean      show_dialog,
+                                 gboolean      allow_save,
+                                 GError      **error)
 {
   DBusGConnection *connection;
   DBusGProxy      *proxy;
@@ -787,9 +775,89 @@ actions_plugin_action_activate_dbus (ActionShutdownType   type,
                                      "org.xfce.Session.Manager");
   if (G_LIKELY (proxy != NULL))
     {
+      if (g_strcmp0 (method, "Logout") == 0)
+        {
+          retval = dbus_g_proxy_call (proxy, method, error,
+                                      G_TYPE_BOOLEAN, show_dialog,
+                                      G_TYPE_BOOLEAN, allow_save,
+                                      G_TYPE_INVALID, G_TYPE_INVALID);
+        }
+      else
+        {
+          retval = dbus_g_proxy_call (proxy, method, error,
+                                      G_TYPE_BOOLEAN, allow_save,
+                                      G_TYPE_INVALID, G_TYPE_INVALID);
+        }
+
+      g_object_unref (G_OBJECT (proxy));
+    }
+
+  return retval;
+}
+
+
+
+static void
+actions_plugin_action_dbus_query_xfsm (gboolean *can_restart,
+                                       gboolean *can_shutdown)
+{
+  GError *error =NULL;
+
+  *can_restart = FALSE;
+  *can_shutdown = FALSE;
+
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
+  if (connection == NULL)
+    return;
+
+  proxy = dbus_g_proxy_new_for_name (connection,
+                                     "org.xfce.SessionManager",
+                                     "/org/xfce/SessionManager",
+                                     "org.xfce.Session.Manager");
+  if (G_LIKELY (proxy != NULL))
+    {
+      if (dbus_g_proxy_call (proxy, "CanShutdown", &error,
+                             G_TYPE_INVALID,
+                             G_TYPE_BOOLEAN, can_shutdown,
+                             G_TYPE_INVALID))
+        {
+          dbus_g_proxy_call (proxy, "CanRestart", &error,
+                             G_TYPE_INVALID,
+                             G_TYPE_BOOLEAN, can_restart,
+                             G_TYPE_INVALID);
+        }
+      
+      if (error != NULL)
+        {
+          g_warning ("Failed to query session manager: %s", error->message);
+          g_error_free (error);
+        }
+      
+      g_object_unref (G_OBJECT (proxy));
+    }
+}
+
+
+
+static gboolean
+actions_plugin_action_dbus_xfpm (const gchar  *mothod,
+                                 GError      **error)
+{
+  DBusGConnection *connection;
+  DBusGProxy      *proxy;
+  gboolean         retval;
+
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
+  if (connection == NULL)
+    return FALSE;
+
+  proxy = dbus_g_proxy_new_for_name (connection,
+                                     "org.xfce.Power.Manager",
+                                     "/org/xfce/PowerManager",
+                                     "org.xfce.Power.Manager");
+  if (G_LIKELY (proxy != NULL))
+    {
       retval = dbus_g_proxy_call (proxy, "Shutdown", error,
-                                  G_TYPE_UINT, type,
-                                  G_TYPE_BOOLEAN, allow_save,
                                   G_TYPE_INVALID, G_TYPE_INVALID);
 
       g_object_unref (G_OBJECT (proxy));
@@ -821,13 +889,23 @@ actions_plugin_action_activate (GtkWidget      *widget,
   switch (entry->type)
     {
     case ACTION_TYPE_LOGOUT:
-      succeed = actions_plugin_action_activate_dbus (ACTION_SHUTDOWN_LOGOUT,
-                                                     unattended, &error);
+      succeed = actions_plugin_action_dbus_xfsm ("Logout", FALSE,
+                                                 unattended, &error);
       break;
 
     case ACTION_TYPE_LOGOUT_DIALOG:
-      succeed = actions_plugin_action_activate_dbus (ACTION_SHUTDOWN_ASK,
-                                                     unattended, &error);
+      succeed = actions_plugin_action_dbus_xfsm ("Logout", TRUE,
+                                                 unattended, &error);
+      break;
+
+    case ACTION_TYPE_RESTART:
+      succeed = actions_plugin_action_dbus_xfsm ("Restart", FALSE,
+                                                 unattended, &error);
+      break;
+
+    case ACTION_TYPE_SHUTDOWN:
+      succeed = actions_plugin_action_dbus_xfsm ("Shutdown", FALSE,
+                                                 unattended, &error);
       break;
 
     case ACTION_TYPE_SWITCH_USER:
@@ -839,23 +917,11 @@ actions_plugin_action_activate (GtkWidget      *widget,
       break;
 
     case ACTION_TYPE_HIBERNATE:
-      succeed = actions_plugin_action_activate_dbus (ACTION_SHUTDOWN_HIBERNATE,
-                                                     unattended, &error);
+      succeed = actions_plugin_action_dbus_xfpm ("Hibernate", &error);
       break;
 
     case ACTION_TYPE_SUSPEND:
-      succeed = actions_plugin_action_activate_dbus (ACTION_SHUTDOWN_SUSPEND,
-                                                     unattended, &error);
-      break;
-
-    case ACTION_TYPE_RESTART:
-      succeed = actions_plugin_action_activate_dbus (ACTION_SHUTDOWN_REBOOT,
-                                                     unattended, &error);
-      break;
-
-    case ACTION_TYPE_SHUTDOWN:
-      succeed = actions_plugin_action_activate_dbus (ACTION_SHUTDOWN_HALT,
-                                                     unattended, &error);
+      succeed = actions_plugin_action_dbus_xfpm ("Suspend", &error);
       break;
 
     default:


More information about the Xfce4-commits mailing list