[network-manager-applet/th/validation-error-bgo754832: 6/6] c-e: show tooltip with validation error



commit 07c547ce2085f87bf2b44b0821c216ea1319487e
Author: Thomas Haller <thaller redhat com>
Date:   Thu Sep 10 16:38:13 2015 +0200

    c-e: show tooltip with validation error

 src/connection-editor/ce-polkit-button.c     |   36 +++++++++++++++++--------
 src/connection-editor/ce-polkit-button.h     |    2 +-
 src/connection-editor/nm-connection-editor.c |   25 ++++++++---------
 src/connection-editor/nm-connection-list.c   |    4 +-
 4 files changed, 39 insertions(+), 28 deletions(-)
---
diff --git a/src/connection-editor/ce-polkit-button.c b/src/connection-editor/ce-polkit-button.c
index 50a1e9b..fedda09 100644
--- a/src/connection-editor/ce-polkit-button.c
+++ b/src/connection-editor/ce-polkit-button.c
@@ -34,7 +34,7 @@ G_DEFINE_TYPE (CEPolkitButton, ce_polkit_button, GTK_TYPE_BUTTON)
 typedef struct {
        char *tooltip;
        char *auth_tooltip;
-       gboolean master_sensitive;
+       char *validation_error;
 
        GtkWidget *stock;
        GtkWidget *auth;
@@ -68,16 +68,19 @@ update_button (CEPolkitButton *self)
 
        gtk_widget_set_sensitive (GTK_WIDGET (self), actionable);
 
-       if (!priv->authorized) {
+       if (priv->validation_error)
+               gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->validation_error);
+       else 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) {
+       else if (priv->authorized_asks)
                gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->auth_tooltip);
-               gtk_button_set_image (GTK_BUTTON (self), priv->auth);
-       } else {
+       else
                gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->tooltip);
+
+       if (priv->authorized)
                gtk_button_set_image (GTK_BUTTON (self), priv->stock);
-       }
+       else
+               gtk_button_set_image (GTK_BUTTON (self), priv->auth);
 }
 
 static void
@@ -92,16 +95,24 @@ update_and_emit (CEPolkitButton *self, gboolean old_actionable)
 }
 
 void
-ce_polkit_button_set_master_sensitive (CEPolkitButton *self, gboolean sensitive)
+ce_polkit_button_set_validation_error (CEPolkitButton *self, const char *validation_error)
 {
+       CEPolkitButtonPrivate *priv;
        gboolean old_actionable;
 
        g_return_if_fail (self != NULL);
        g_return_if_fail (CE_IS_POLKIT_BUTTON (self));
 
-       old_actionable = ce_polkit_button_get_actionable (self);
-       CE_POLKIT_BUTTON_GET_PRIVATE (self)->master_sensitive = sensitive;
-       update_and_emit (self, old_actionable);
+       priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
+
+       if (g_strcmp0 (validation_error, priv->validation_error) != 0) {
+               old_actionable = ce_polkit_button_get_actionable (self);
+
+               g_clear_pointer (&priv->validation_error, g_free);
+               priv->validation_error = g_strdup (validation_error);
+
+               update_and_emit (self, old_actionable);
+       }
 }
 
 gboolean
@@ -114,7 +125,7 @@ ce_polkit_button_get_actionable (CEPolkitButton *self)
 
        priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
 
-       return priv->master_sensitive && priv->authorized;
+       return priv->authorized && !priv->validation_error;
 }
 
 gboolean
@@ -209,6 +220,7 @@ finalize (GObject *object)
 
        g_free (priv->tooltip);
        g_free (priv->auth_tooltip);
+       g_free (priv->validation_error);
 
        G_OBJECT_CLASS (ce_polkit_button_parent_class)->finalize (object);
 }
diff --git a/src/connection-editor/ce-polkit-button.h b/src/connection-editor/ce-polkit-button.h
index 802aab4..7e284e9 100644
--- a/src/connection-editor/ce-polkit-button.h
+++ b/src/connection-editor/ce-polkit-button.h
@@ -54,7 +54,7 @@ GtkWidget *ce_polkit_button_new (const char *label,
                                  NMClient *client,
                                  NMClientPermission permission);
 
-void ce_polkit_button_set_master_sensitive (CEPolkitButton *button, gboolean sensitive);
+void ce_polkit_button_set_validation_error (CEPolkitButton *self, const char *validation_error);
 
 gboolean ce_polkit_button_get_actionable (CEPolkitButton *button);
 
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index 7b42ae4..c3db7a4 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -180,8 +180,8 @@ static void
 connection_editor_validate (NMConnectionEditor *editor)
 {
        NMSettingConnection *s_con;
-       gboolean valid = FALSE, printed = FALSE;
        GSList *iter;
+       GError *validation_error = NULL;
 
        if (!editor_is_initialized (editor))
                goto done;
@@ -194,29 +194,28 @@ connection_editor_validate (NMConnectionEditor *editor)
        if (!ui_to_setting (editor))
                goto done;
 
-       valid = TRUE;
        for (iter = editor->pages; iter; iter = g_slist_next (iter)) {
                GError *error = NULL;
 
                if (!ce_page_validate (CE_PAGE (iter->data), editor->connection, &error)) {
-                       valid = FALSE;
-
-                       /* FIXME: use the error to indicate which UI widgets are invalid */
-                       if (!printed) {
-                               printed = TRUE;
-                               if (error) {
-                                       g_warning ("Invalid setting %s: %s", CE_PAGE (iter->data)->title, 
error->message);
-                               } else
-                                       g_warning ("Invalid setting %s", CE_PAGE (iter->data)->title);
+                       if (!validation_error) {
+                               g_set_error (&validation_error, NMA_ERROR, NMA_ERROR_GENERIC,
+                                            _("Invalid setting %s: %s"),
+                                            CE_PAGE (iter->data)->title,
+                                            error->message);
+                               g_warning ("Invalid setting %s: %s", CE_PAGE (iter->data)->title, 
error->message);
                        }
                        g_clear_error (&error);
                }
        }
 
 done:
-       ce_polkit_button_set_master_sensitive (CE_POLKIT_BUTTON (editor->ok_button), valid);
-       gtk_widget_set_sensitive (editor->export_button, valid);
+       ce_polkit_button_set_validation_error (CE_POLKIT_BUTTON (editor->ok_button), validation_error ? 
validation_error->message : NULL);
+       gtk_widget_set_sensitive (editor->export_button, !!validation_error);
+
        update_sensitivity (editor);
+
+       g_clear_error (&validation_error);
 }
 
 static void
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 1149433..d961b1f 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -389,12 +389,12 @@ pk_button_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
                if (connection) {
                        s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
                        g_assert (s_con);
-       
+
                        sensitive = !nm_setting_connection_get_read_only (s_con);
                }
        }
 
-       ce_polkit_button_set_master_sensitive (button, sensitive);
+       ce_polkit_button_set_validation_error (button, sensitive ? NULL : _("Connection cannot be modified"));
 }
 
 static void


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