Author: carlosg
Date: Mon Jan  7 19:22:42 2008
New Revision: 4087
URL: http://svn.gnome.org/viewvc/gnome-system-tools?rev=4087&view=rev

Log:
2008-01-07  Carlos Garnacho  <[EMAIL PROTECTED]>

        * gst-polkit-action.c, gst-polkit-button.c: Display an error dialog if
        the call to org.gnome.PolicyKit returns some error.


Modified:
   trunk/src/common/ChangeLog
   trunk/src/common/gst-polkit-action.c
   trunk/src/common/gst-polkit-button.c

Modified: trunk/src/common/gst-polkit-action.c
==============================================================================
--- trunk/src/common/gst-polkit-action.c        (original)
+++ trunk/src/common/gst-polkit-action.c        Mon Jan  7 19:22:42 2008
@@ -330,24 +330,33 @@
        GstPolKitActionPriv *priv;
        DBusMessage *reply;
        DBusMessageIter iter;
+       DBusError error;
        gboolean authenticated = FALSE;
        gboolean was_authenticated;
 
        action = GST_POLKIT_ACTION (data);
        priv = GST_POLKIT_ACTION_GET_PRIVATE (action);
+       dbus_error_init (&error);
 
        reply = dbus_pending_call_steal_reply (pending_call);
-       dbus_message_iter_init (reply, &iter);
-       dbus_message_iter_get_basic (&iter, &authenticated);
-
-       was_authenticated = (priv->result == POLKIT_RESULT_YES);
-
-       if (was_authenticated != authenticated) {
-               priv->result = (authenticated) ?
-                       POLKIT_RESULT_YES : can_caller_do_action (action);
 
-               g_object_notify (G_OBJECT (action), "authenticated");
-               g_signal_emit (action, signals [CHANGED], 0);
+       if (dbus_set_error_from_message (&error, reply)) {
+               g_critical (error.message);
+               dbus_error_free (&error);
+               priv->result = POLKIT_RESULT_UNKNOWN;
+       } else {
+               dbus_message_iter_init (reply, &iter);
+               dbus_message_iter_get_basic (&iter, &authenticated);
+
+               was_authenticated = (priv->result == POLKIT_RESULT_YES);
+
+               if (was_authenticated != authenticated) {
+                       priv->result = (authenticated) ?
+                               POLKIT_RESULT_YES : can_caller_do_action 
(action);
+
+                       g_object_notify (G_OBJECT (action), "authenticated");
+                       g_signal_emit (action, signals [CHANGED], 0);
+               }
        }
 
        gtk_grab_remove (priv->invisible);

Modified: trunk/src/common/gst-polkit-button.c
==============================================================================
--- trunk/src/common/gst-polkit-button.c        (original)
+++ trunk/src/common/gst-polkit-button.c        Mon Jan  7 19:22:42 2008
@@ -131,11 +131,11 @@
        case POLKIT_RESULT_ONLY_VIA_SELF_AUTH:
        case POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_SESSION:
        case POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_ALWAYS:
+       case POLKIT_RESULT_UNKNOWN:
                image = gtk_image_new_from_stock 
(GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_BUTTON);
                sensitive = TRUE;
                break;
        case POLKIT_RESULT_NO:
-       case POLKIT_RESULT_UNKNOWN:
                image = gtk_image_new_from_stock (GTK_STOCK_NO, 
GTK_ICON_SIZE_BUTTON);
                tooltip = N_("This action is not allowed");
                break;
@@ -230,9 +230,28 @@
 gst_polkit_button_clicked (GtkButton *button)
 {
        GstPolKitButtonPriv *priv;
+       PolKitResult result;
 
        priv = GST_POLKIT_BUTTON_GET_PRIVATE (button);
        gst_polkit_action_authenticate (priv->action);
+       result = gst_polkit_action_get_result (priv->action);
+
+       if (result == POLKIT_RESULT_UNKNOWN) {
+               GtkWidget *dialog, *toplevel;
+
+               toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
+               dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
+                                                GTK_DIALOG_MODAL,
+                                                GTK_MESSAGE_ERROR,
+                                                GTK_BUTTONS_CLOSE,
+                                                _("Could not authenticate"));
+               gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG 
(dialog),
+                                                         _("An unexpected 
error has occurred."));
+
+               gtk_dialog_run (GTK_DIALOG (dialog));
+               gtk_widget_destroy (dialog);
+       }
+
        update_button_state (GST_POLKIT_BUTTON (button));
 }
 
_______________________________________________
SVN-commits-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/svn-commits-list

Reply via email to