summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-09-10 17:59:38 +0200
committerThomas Haller <thaller@redhat.com>2015-09-11 23:03:13 +0200
commit05a1b8e9b47842978313a259c0ae161f0a1da4f1 (patch)
tree1da88c54462fc2a5eeac9a51ea3e78f510c01f9d
parent8a77b227ad7cde7d9eed622a83e0d560b38ed19b (diff)
downloadnetwork-manager-applet-05a1b8e9b47842978313a259c0ae161f0a1da4f1.tar.gz
c-e: fix icon and tooltip of "Save" button regarding authorization
CEPolkitButton has two different icons/tooltips, depending on whether you can perform the action right away or are asked for further polkit authorization. We need three states regarding the icon/tooltip: - NO authorization: Button is disabled - NM_CLIENT_PERMISSION_RESULT_AUTH: user can get authorization after authenticating with polkit. - NM_CLIENT_PERMISSION_RESULT_YES: user has permission right away. Regardless of that, the check in update_button() was very wrong. It would set priv->auth_tooltip when priv->authorized while it should set priv->tooltip (if it doesn't consider the three states above).
-rw-r--r--src/connection-editor/ce-polkit-button.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/connection-editor/ce-polkit-button.c b/src/connection-editor/ce-polkit-button.c
index 690ed928..71eb6141 100644
--- a/src/connection-editor/ce-polkit-button.c
+++ b/src/connection-editor/ce-polkit-button.c
@@ -41,11 +41,8 @@ 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;
+
+ NMClientPermissionResult permission_result;
guint perm_id;
} CEPolkitButtonPrivate;
@@ -68,13 +65,17 @@ update_button (CEPolkitButton *self)
gtk_widget_set_sensitive (GTK_WIDGET (self), actionable);
- if (priv->authorized) {
+ 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
@@ -111,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
@@ -130,16 +137,16 @@ permission_changed_cb (NMClient *client,
CEPolkitButton *self)
{
CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
- gboolean old_actionable, old_authorized;
+ gboolean old_actionable;
- old_actionable = ce_polkit_button_get_actionable (self);
- old_authorized = priv->authorized;
+ if (priv->permission_result == result)
+ return;
- priv->authorized = (result == NM_CLIENT_PERMISSION_RESULT_YES || result == NM_CLIENT_PERMISSION_RESULT_AUTH);
+ old_actionable = ce_polkit_button_get_actionable (self);
+ priv->permission_result = result;
update_and_emit (self, old_actionable);
- if (priv->authorized != old_authorized)
- g_signal_emit (self, signals[AUTHORIZED], 0, priv->authorized);
+ g_signal_emit (self, signals[AUTHORIZED], 0, ce_polkit_button_get_authorized (self));
}
GtkWidget *