summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Jon McCann <jmccann@redhat.com>2008-05-01 23:02:01 +0000
committerWilliam Jon McCann <mccann@src.gnome.org>2008-05-01 23:02:01 +0000
commit08749a86aa5dad52648c456bcff66777570127ed (patch)
tree19991301cd2299ae5e405d0f29d728bc23997e04
parent59cf48eed931307e0a4617004a3eee4dfd7327c2 (diff)
downloadgdm-08749a86aa5dad52648c456bcff66777570127ed.tar.gz
Use new ConsoleKit error format. Patch from: Matthias Clasen
2008-05-01 William Jon McCann <jmccann@redhat.com> * gui/simple-greeter/gdm-greeter-login-window.c (get_action_from_error), (get_result_from_error), (do_system_restart), (do_system_stop): Use new ConsoleKit error format. Patch from: Matthias Clasen <mclasen@redhat.com> svn path=/trunk/; revision=6196
-rw-r--r--ChangeLog8
-rw-r--r--gui/simple-greeter/gdm-greeter-login-window.c82
2 files changed, 88 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 81c08e62..662b02db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-05-01 William Jon McCann <jmccann@redhat.com>
+
+ * gui/simple-greeter/gdm-greeter-login-window.c
+ (get_action_from_error), (get_result_from_error),
+ (do_system_restart), (do_system_stop):
+ Use new ConsoleKit error format.
+ Patch from: Matthias Clasen <mclasen@redhat.com>
+
2008-04-30 Ray Strode <rstrode@redhat.com>
* gui/simple-greeter/gdm-option-widget.c
diff --git a/gui/simple-greeter/gdm-greeter-login-window.c b/gui/simple-greeter/gdm-greeter-login-window.c
index 896a8711..862ed176 100644
--- a/gui/simple-greeter/gdm-greeter-login-window.c
+++ b/gui/simple-greeter/gdm-greeter-login-window.c
@@ -1141,20 +1141,42 @@ static PolKitAction *
get_action_from_error (GError *error)
{
PolKitAction *action;
- const char *paction;
+ char *paction;
+ char *p;
action = polkit_action_new ();
paction = NULL;
if (g_str_has_prefix (error->message, "Not privileged for action: ")) {
- paction = error->message + strlen ("Not privileged for action: ");
+ paction = g_strdup (error->message + strlen ("Not privileged for action: "));
+ p = strchr (paction, ' ');
+ if (p != NULL) {
+ *p = '\0';
+ }
}
g_debug ("GdmGreeterLoginWindow: Requesting priv for '%s'", paction);
polkit_action_set_action_id (action, paction);
+ g_free (paction);
+
return action;
}
+
+static PolKitResult
+get_result_from_error (GError *error)
+{
+ PolKitResult result = POLKIT_RESULT_UNKNOWN;
+ const char *p;
+
+ p = strrchr (error->message, ' ');
+ if (p != NULL) {
+ p++;
+ polkit_result_from_string_representation (p, &result);
+ }
+
+ return result;
+}
#endif
static void
@@ -1181,11 +1203,40 @@ do_system_restart (GdmGreeterLoginWindow *login_window)
if (dbus_g_error_has_name (error, "org.freedesktop.ConsoleKit.Manager.NotPrivileged")) {
PolKitAction *action;
+ PolKitAction *action2;
+ PolKitResult result;
+ GtkWidget *dialog;
guint xid;
pid_t pid;
+ result = get_result_from_error (error);
action = get_action_from_error (error);
+ if (result == POLKIT_RESULT_NO) {
+ action2 = polkit_action_new ();
+ polkit_action_set_action_id (action2,
+ "org.freedesktop.consolekit.system.restart-multiple-users");
+ dialog = gtk_message_dialog_new (GTK_WINDOW (login_window),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Failed to restart computer"));
+ if (polkit_action_equal (action, action2)) {
+ gtk_message_dialog_format_secondary_text (dialog,
+ _("You are not allowed to restart the computer "
+ "because multiple users are logged in"));
+ }
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ polkit_action_unref (action);
+ polkit_action_unref (action2);
+
+ g_error_free (error);
+
+ return;
+ }
+
xid = 0;
pid = getpid ();
@@ -1233,14 +1284,41 @@ do_system_stop (GdmGreeterLoginWindow *login_window)
if (dbus_g_error_has_name (error, "org.freedesktop.ConsoleKit.Manager.NotPrivileged")) {
PolKitAction *action;
+ PolKitAction *action2;
+ PolKitResult result;
+ GtkWidget *dialog;
guint xid;
pid_t pid;
xid = 0;
pid = getpid ();
+ result = get_result_from_error (error);
action = get_action_from_error (error);
+ if (result == POLKIT_RESULT_NO) {
+ action2 = polkit_action_new ();
+ polkit_action_set_action_id (action2,
+ "org.freedesktop.consolekit.system.stop-multiple-users");
+ dialog = gtk_message_dialog_new (GTK_WINDOW (login_window),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Failed to stop computer"));
+ if (polkit_action_equal (action, action2)) {
+ gtk_message_dialog_format_secondary_text (dialog,
+ _("You are not allowed to stop the computer "
+ "because multiple users are logged in"));
+ }
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ polkit_action_unref (action);
+ polkit_action_unref (action2);
+
+ return;
+ }
+
g_error_free (error);
error = NULL;
res = polkit_gnome_auth_obtain (action,