[network-manager-applet/th/validation-error-bgo754832: 4/13] fixup! c-e: fix icon and tooltip of "Save" button regarding authorization



commit e7ead248b598f339633cb6c09f29d0726893997f
Author: Thomas Haller <thaller redhat com>
Date:   Fri Sep 11 08:53:11 2015 +0200

    fixup! c-e: fix icon and tooltip of "Save" button regarding authorization
    
    Restore the AUTHORIZED signal. It might be needed... (well, somewhat).
    
    Also, merge priv->authorized and priv->authorized_asks to
    priv->permission_result.

 src/connection-editor/ce-polkit-button.c     |   50 ++++++++++++++++---------
 src/connection-editor/ce-polkit-button.h     |    2 +
 src/connection-editor/nm-connection-editor.c |    2 +
 3 files changed, 36 insertions(+), 18 deletions(-)
---
diff --git a/src/connection-editor/ce-polkit-button.c b/src/connection-editor/ce-polkit-button.c
index 50a1e9b..71eb614 100644
--- a/src/connection-editor/ce-polkit-button.c
+++ b/src/connection-editor/ce-polkit-button.c
@@ -41,18 +41,15 @@ typedef struct {
 
        NMClient *client;
        NMClientPermission permission;
-       /* authorized = TRUE if either explicitly authorized or if the action
-        * could be performed if the user successfully authenticated to gain the
-        * authorization.
-        */
-       gboolean authorized;
-       gboolean authorized_asks;
+
+       NMClientPermissionResult permission_result;
 
        guint perm_id;
 } CEPolkitButtonPrivate;
 
 enum {
        ACTIONABLE,
+       AUTHORIZED,
        LAST_SIGNAL
 };
 
@@ -68,16 +65,17 @@ update_button (CEPolkitButton *self)
 
        gtk_widget_set_sensitive (GTK_WIDGET (self), actionable);
 
-       if (!priv->authorized) {
-               gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("No polkit authorization to perform the 
action"));
-               gtk_button_set_image (GTK_BUTTON (self), priv->auth);
-       } else if (priv->authorized_asks) {
+       if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_AUTH)
                gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->auth_tooltip);
-               gtk_button_set_image (GTK_BUTTON (self), priv->auth);
-       } else {
+       else if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES)
                gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->tooltip);
+       else
+               gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("No polkit authorization to perform the 
action"));
+
+       if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES)
                gtk_button_set_image (GTK_BUTTON (self), priv->stock);
-       }
+       else
+               gtk_button_set_image (GTK_BUTTON (self), priv->auth);
 }
 
 static void
@@ -114,16 +112,22 @@ ce_polkit_button_get_actionable (CEPolkitButton *self)
 
        priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
 
-       return priv->master_sensitive && priv->authorized;
+       return    priv->master_sensitive
+              && ce_polkit_button_get_authorized (self);
 }
 
 gboolean
 ce_polkit_button_get_authorized (CEPolkitButton *self)
 {
+       CEPolkitButtonPrivate *priv;
+
        g_return_val_if_fail (self != NULL, FALSE);
        g_return_val_if_fail (CE_IS_POLKIT_BUTTON (self), FALSE);
 
-       return CE_POLKIT_BUTTON_GET_PRIVATE (self)->authorized;
+       priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
+
+       return    priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES
+              || priv->permission_result == NM_CLIENT_PERMISSION_RESULT_AUTH;
 }
 
 static void
@@ -135,11 +139,14 @@ permission_changed_cb (NMClient *client,
        CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
        gboolean old_actionable;
 
-       old_actionable = ce_polkit_button_get_actionable (self);
+       if (priv->permission_result == result)
+               return;
 
-       priv->authorized = (result == NM_CLIENT_PERMISSION_RESULT_YES || result == 
NM_CLIENT_PERMISSION_RESULT_AUTH);
-       priv->authorized_asks = priv->authorized_asks && (result == NM_CLIENT_PERMISSION_RESULT_AUTH);
+       old_actionable = ce_polkit_button_get_actionable (self);
+       priv->permission_result = result;
        update_and_emit (self, old_actionable);
+
+       g_signal_emit (self, signals[AUTHORIZED], 0, ce_polkit_button_get_authorized (self));
 }
 
 GtkWidget *
@@ -234,5 +241,12 @@ ce_polkit_button_class_init (CEPolkitButtonClass *pb_class)
                                            G_STRUCT_OFFSET (CEPolkitButtonClass, actionable),
                                            NULL, NULL, NULL,
                                            G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+       signals[AUTHORIZED] = g_signal_new ("authorized",
+                                           G_OBJECT_CLASS_TYPE (object_class),
+                                           G_SIGNAL_RUN_FIRST,
+                                           G_STRUCT_OFFSET (CEPolkitButtonClass, authorized),
+                                           NULL, NULL, NULL,
+                                           G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 }
 
diff --git a/src/connection-editor/ce-polkit-button.h b/src/connection-editor/ce-polkit-button.h
index 802aab4..da2f3e3 100644
--- a/src/connection-editor/ce-polkit-button.h
+++ b/src/connection-editor/ce-polkit-button.h
@@ -43,6 +43,8 @@ typedef struct {
 
        /* Signals */
        void (*actionable) (CEPolkitButton *self, gboolean actionable);
+       
+       void (*authorized) (CEPolkitButton *self, gboolean authorized);
 } CEPolkitButtonClass;
 
 GType ce_polkit_button_get_type (void);
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index 7b42ae4..b4b0711 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -403,6 +403,8 @@ nm_connection_editor_new (GtkWindow *parent_window,
 
        g_signal_connect (editor->ok_button, "actionable",
                          G_CALLBACK (ok_button_actionable_cb), editor);
+       g_signal_connect (editor->ok_button, "authorized",
+                         G_CALLBACK (ok_button_actionable_cb), editor);
        hbox = GTK_WIDGET (gtk_builder_get_object (editor->builder, "action_area_hbox"));
        gtk_box_pack_end (GTK_BOX (hbox), editor->ok_button, TRUE, TRUE, 0);
        gtk_widget_show_all (editor->ok_button);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]