2008-10-10 00:38:15 +00:00
|
|
|
diff -up gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-api gnome-session-2.24.0/gnome-session/gsm-consolekit.c
|
|
|
|
--- gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400
|
2008-10-10 21:50:58 +00:00
|
|
|
+++ gnome-session-2.24.0/gnome-session/gsm-consolekit.c 2008-10-10 17:43:35.000000000 -0400
|
|
|
|
@@ -825,20 +826,78 @@ gsm_consolekit_can_switch_user (GsmConso
|
2008-10-09 19:37:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-10 20:43:46 +00:00
|
|
|
+#ifdef HAVE_POLKIT_GNOME
|
2008-10-09 19:37:52 +00:00
|
|
|
+static gboolean
|
|
|
|
+gsm_consolekit_can_do_action (GsmConsolekit *manager,
|
2008-10-10 20:43:46 +00:00
|
|
|
+ const char *action_id)
|
2008-10-09 19:37:52 +00:00
|
|
|
+{
|
|
|
|
+ PolKitGnomeContext *gnome_context;
|
|
|
|
+ PolKitAction *action;
|
2008-10-10 21:50:58 +00:00
|
|
|
+ PolKitCaller *caller;
|
|
|
|
+ DBusError dbus_error;
|
|
|
|
+ PolKitError *error;
|
2008-10-09 19:37:52 +00:00
|
|
|
+ PolKitResult result;
|
|
|
|
+
|
|
|
|
+ gnome_context = polkit_gnome_context_get (NULL);
|
|
|
|
+
|
|
|
|
+ if (gnome_context == NULL) {
|
|
|
|
+ return FALSE;
|
|
|
|
+ }
|
|
|
|
+
|
2008-10-10 21:50:58 +00:00
|
|
|
+ if (gnome_context->pk_tracker == NULL) {
|
|
|
|
+ return FALSE;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dbus_error_init (&dbus_error);
|
|
|
|
+ caller = polkit_tracker_get_caller_from_pid (gnome_context->pk_tracker,
|
|
|
|
+ getpid (),
|
|
|
|
+ &dbus_error);
|
|
|
|
+ dbus_error_free (&dbus_error);
|
|
|
|
+
|
|
|
|
+ if (caller == NULL) {
|
|
|
|
+ return FALSE;
|
|
|
|
+ }
|
|
|
|
+
|
2008-10-09 19:37:52 +00:00
|
|
|
+ action = polkit_action_new ();
|
2008-10-10 20:43:46 +00:00
|
|
|
+ if (!polkit_action_set_action_id (action, action_id)) {
|
2008-10-09 19:37:52 +00:00
|
|
|
+ polkit_action_unref (action);
|
2008-10-10 21:50:58 +00:00
|
|
|
+ polkit_caller_unref (caller);
|
2008-10-09 19:37:52 +00:00
|
|
|
+ return FALSE;
|
|
|
|
+ }
|
|
|
|
+
|
2008-10-10 20:43:46 +00:00
|
|
|
+ result = POLKIT_RESULT_UNKNOWN;
|
2008-10-10 21:50:58 +00:00
|
|
|
+ error = NULL;
|
|
|
|
+ result = polkit_context_is_caller_authorized (gnome_context->pk_context,
|
|
|
|
+ action, caller, FALSE,
|
|
|
|
+ &error);
|
|
|
|
+ if (polkit_error_is_set (error)) {
|
|
|
|
+ polkit_error_free (error);
|
2008-10-10 00:38:15 +00:00
|
|
|
+ }
|
2008-10-10 21:50:58 +00:00
|
|
|
+ polkit_action_unref (action);
|
2008-10-15 15:35:41 +00:00
|
|
|
+ polkit_caller_unref (caller);
|
2008-10-09 19:37:52 +00:00
|
|
|
+
|
|
|
|
+ return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN;
|
|
|
|
+}
|
2008-10-10 20:43:46 +00:00
|
|
|
+#endif
|
2008-10-09 19:37:52 +00:00
|
|
|
+
|
|
|
|
gboolean
|
|
|
|
gsm_consolekit_can_restart (GsmConsolekit *manager)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_POLKIT_GNOME
|
|
|
|
gboolean res;
|
|
|
|
GError *error;
|
2008-10-15 15:35:41 +00:00
|
|
|
+
|
2008-10-09 19:37:52 +00:00
|
|
|
error = NULL;
|
|
|
|
res = gsm_consolekit_ensure_ck_connection (manager, &error);
|
|
|
|
if (!res) {
|
|
|
|
g_warning ("Could not connect to ConsoleKit: %s",
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
+ return FALSE;
|
|
|
|
}
|
|
|
|
- return res;
|
|
|
|
+
|
|
|
|
+ return gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.restart") ||
|
|
|
|
+ gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.restart-multiple-users");
|
|
|
|
#else
|
|
|
|
g_debug ("GsmConsolekit: built without PolicyKit-gnome support - cannot restart system");
|
|
|
|
return FALSE;
|
2008-10-10 21:50:58 +00:00
|
|
|
@@ -857,8 +916,11 @@ gsm_consolekit_can_stop (GsmConsolekit *
|
2008-10-09 19:37:52 +00:00
|
|
|
g_warning ("Could not connect to ConsoleKit: %s",
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
+ return FALSE;
|
|
|
|
}
|
|
|
|
- return res;
|
|
|
|
+
|
|
|
|
+ return gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.stop") ||
|
|
|
|
+ gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.stop-multiple-users");
|
|
|
|
#else
|
|
|
|
g_debug ("GsmConsolekit: built without PolicyKit-gnome support - cannot stop system");
|
|
|
|
return FALSE;
|
2008-10-10 00:38:15 +00:00
|
|
|
diff -up gnome-session-2.24.0/gnome-session/gsm-manager.c.add-can-shutdown-api gnome-session-2.24.0/gnome-session/gsm-manager.c
|
|
|
|
--- gnome-session-2.24.0/gnome-session/gsm-manager.c.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400
|
2008-10-15 15:35:41 +00:00
|
|
|
+++ gnome-session-2.24.0/gnome-session/gsm-manager.c 2008-10-15 11:33:18.000000000 -0400
|
|
|
|
@@ -2313,6 +2313,30 @@ gsm_manager_shutdown (GsmManager *manage
|
2008-10-09 19:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
+gsm_manager_can_shutdown (GsmManager *manager,
|
|
|
|
+ gboolean *shutdown_available,
|
|
|
|
+ GError **error)
|
|
|
|
+{
|
|
|
|
+ GsmConsolekit *consolekit;
|
|
|
|
+ GsmPowerManager *power_manager;
|
|
|
|
+
|
|
|
|
+ g_debug ("GsmManager: CanShutdown called");
|
|
|
|
+
|
|
|
|
+ g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE);
|
|
|
|
+
|
|
|
|
+ consolekit = gsm_get_consolekit ();
|
|
|
|
+ power_manager = gsm_get_power_manager ();
|
|
|
|
+ *shutdown_available = gsm_consolekit_can_stop (consolekit)
|
|
|
|
+ || gsm_consolekit_can_restart (consolekit)
|
|
|
|
+ || gsm_power_manager_can_suspend (power_manager)
|
|
|
|
+ || gsm_power_manager_can_hibernate (power_manager);
|
|
|
|
+ g_object_unref (consolekit);
|
|
|
|
+ g_object_unref (power_manager);
|
|
|
|
+
|
|
|
|
+ return TRUE;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+gboolean
|
|
|
|
gsm_manager_logout (GsmManager *manager,
|
|
|
|
guint logout_mode,
|
|
|
|
GError **error)
|
2008-10-10 00:38:15 +00:00
|
|
|
diff -up gnome-session-2.24.0/gnome-session/gsm-manager.h.add-can-shutdown-api gnome-session-2.24.0/gnome-session/gsm-manager.h
|
|
|
|
--- gnome-session-2.24.0/gnome-session/gsm-manager.h.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400
|
2008-10-10 21:50:58 +00:00
|
|
|
+++ gnome-session-2.24.0/gnome-session/gsm-manager.h 2008-10-10 16:41:14.000000000 -0400
|
2008-10-10 00:38:15 +00:00
|
|
|
@@ -151,6 +151,10 @@ gboolean gsm_manager_is_inhib
|
2008-10-09 19:37:52 +00:00
|
|
|
|
|
|
|
gboolean gsm_manager_shutdown (GsmManager *manager,
|
|
|
|
GError **error);
|
|
|
|
+
|
|
|
|
+gboolean gsm_manager_can_shutdown (GsmManager *manager,
|
|
|
|
+ gboolean *shutdown_available,
|
|
|
|
+ GError **error);
|
|
|
|
gboolean gsm_manager_logout (GsmManager *manager,
|
|
|
|
guint logout_mode,
|
|
|
|
GError **error);
|
2008-10-10 00:38:15 +00:00
|
|
|
diff -up gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml.add-can-shutdown-api gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml
|
|
|
|
--- gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400
|
2008-10-10 21:50:58 +00:00
|
|
|
+++ gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml 2008-10-10 16:41:14.000000000 -0400
|
2008-10-09 19:37:52 +00:00
|
|
|
@@ -252,6 +252,20 @@
|
|
|
|
</doc:doc>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
+ <method name="CanShutdown">
|
|
|
|
+ <arg name="is_available" direction="out" type="b">
|
|
|
|
+ <doc:doc>
|
|
|
|
+ <doc:summary>True if shutdown is available to the user, false otherwise</doc:summary>
|
|
|
|
+ </doc:doc>
|
|
|
|
+ </arg>
|
|
|
|
+ <doc:doc>
|
|
|
|
+ <doc:description>
|
|
|
|
+ <doc:para>Allows the caller to determine whether or not it's okay to show
|
|
|
|
+ a shutdown option in the UI</doc:para>
|
|
|
|
+ </doc:description>
|
|
|
|
+ </doc:doc>
|
|
|
|
+ </method>
|
|
|
|
+
|
|
|
|
<method name="Logout">
|
|
|
|
<arg name="mode" type="u" direction="in">
|
|
|
|
<doc:doc>
|