[network-manager-applet/th/validation-error-bgo754832: 12/13] c-e: show tooltip with validation error
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/th/validation-error-bgo754832: 12/13] c-e: show tooltip with validation error
- Date: Fri, 11 Sep 2015 12:15:05 +0000 (UTC)
commit 803b9f0cbe704e5f99f8c0cc811a9a0e5b15b99e
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 | 25 ++++++++++----
src/connection-editor/ce-polkit-button.h | 2 +-
src/connection-editor/nm-connection-editor.c | 45 ++++++++++++++-----------
src/connection-editor/nm-connection-list.c | 4 +-
4 files changed, 46 insertions(+), 30 deletions(-)
---
diff --git a/src/connection-editor/ce-polkit-button.c b/src/connection-editor/ce-polkit-button.c
index 71eb614..1898d1e 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;
@@ -65,7 +65,9 @@ update_button (CEPolkitButton *self)
gtk_widget_set_sensitive (GTK_WIDGET (self), actionable);
- if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_AUTH)
+ if (priv->validation_error)
+ gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->validation_error);
+ else if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_AUTH)
gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->auth_tooltip);
else if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES)
gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->tooltip);
@@ -90,16 +92,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
@@ -112,7 +122,7 @@ ce_polkit_button_get_actionable (CEPolkitButton *self)
priv = CE_POLKIT_BUTTON_GET_PRIVATE (self);
- return priv->master_sensitive
+ return !priv->validation_error
&& ce_polkit_button_get_authorized (self);
}
@@ -216,6 +226,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 da2f3e3..a81963b 100644
--- a/src/connection-editor/ce-polkit-button.h
+++ b/src/connection-editor/ce-polkit-button.h
@@ -56,7 +56,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 b4b0711..6dca0e2 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -108,7 +108,7 @@ nm_connection_editor_update_title (NMConnectionEditor *editor)
}
static gboolean
-ui_to_setting (NMConnectionEditor *editor)
+ui_to_setting (NMConnectionEditor *editor, GError **error)
{
NMSettingConnection *s_con;
GtkWidget *widget;
@@ -123,8 +123,10 @@ ui_to_setting (NMConnectionEditor *editor)
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, name, NULL);
nm_connection_editor_update_title (editor);
- if (!name || !strlen (name))
+ if (!name || !strlen (name)) {
+ g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Missing connection name"));
return FALSE;
+ }
return TRUE;
}
@@ -180,43 +182,46 @@ static void
connection_editor_validate (NMConnectionEditor *editor)
{
NMSettingConnection *s_con;
- gboolean valid = FALSE, printed = FALSE;
GSList *iter;
+ char *validation_error = NULL;
+ GError *error = NULL;
- if (!editor_is_initialized (editor))
+ if (!editor_is_initialized (editor)) {
+ validation_error = g_strdup (_("Editor initializing..."));
goto done;
+ }
s_con = nm_connection_get_setting_connection (editor->connection);
g_assert (s_con);
- if (nm_setting_connection_get_read_only (s_con))
+ if (nm_setting_connection_get_read_only (s_con)) {
+ validation_error = g_strdup (_("Connection cannot be modified"));
goto done;
+ }
- if (!ui_to_setting (editor))
+ if (!ui_to_setting (editor, &error)) {
+ validation_error = g_strdup (error->message);
+ g_clear_error (&error);
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) {
+ validation_error = g_strdup_printf (_("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);
+ gtk_widget_set_sensitive (editor->export_button, !!validation_error);
+
update_sensitivity (editor);
+
+ g_free (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]