[network-manager-applet/th/validation-error-bgo754832: 8/13] fixup! c-e: forward the validation error to print more sensible error message to stdout



commit 95dd583549dc5a888aab719a18c0e073b4421c92
Author: Thomas Haller <thaller redhat com>
Date:   Fri Sep 11 09:19:55 2015 +0200

    fixup! c-e: forward the validation error to print more sensible error message to stdout

 src/connection-editor/ce-page.c        |   24 +++++++++++++++++++-----
 src/connection-editor/ce-page.h        |    2 +-
 src/connection-editor/page-bluetooth.c |    4 +---
 src/connection-editor/page-ethernet.c  |    4 +---
 src/connection-editor/page-vlan.c      |    4 +---
 src/connection-editor/page-wifi.c      |    8 ++------
 6 files changed, 25 insertions(+), 21 deletions(-)
---
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index e5bdee8..05ae043 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -215,7 +215,7 @@ ce_page_setup_mac_combo (CEPage *self, GtkComboBox *combo,
 }
 
 gboolean
-ce_page_mac_entry_valid (GtkEntry *entry, int type)
+ce_page_mac_entry_valid (GtkEntry *entry, int type, const char *property_name, GError **error)
 {
        const char *mac;
 
@@ -223,10 +223,24 @@ ce_page_mac_entry_valid (GtkEntry *entry, int type)
        g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
 
        mac = gtk_entry_get_text (entry);
-       if (!mac || !*mac)
-               return TRUE;
-
-       return nm_utils_hwaddr_valid (mac, nm_utils_hwaddr_len (type));
+       if (mac && *mac) {
+               if (!nm_utils_hwaddr_valid (mac, nm_utils_hwaddr_len (type))) {
+                       const char *addr_type;
+
+                       addr_type = type == ARPHRD_ETHER ? _("MAC address") : _("HW addreess");
+                       if (property_name) {
+                               g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC,
+                                            _("invalid %s for %s (%s)"),
+                                            addr_type, property_name, mac);
+                       } else {
+                               g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC,
+                                            _("invalid %s (%s)"),
+                                            addr_type, mac);
+                       }
+                       return FALSE;
+               }
+       }
+       return TRUE;
 }
 
 static char **
diff --git a/src/connection-editor/ce-page.h b/src/connection-editor/ce-page.h
index 758e342..f927e1c 100644
--- a/src/connection-editor/ce-page.h
+++ b/src/connection-editor/ce-page.h
@@ -114,7 +114,7 @@ void ce_page_setup_device_combo (CEPage *self,
                                  const char *mac,
                                  const char *mac_property,
                                  gboolean ifname_first);
-gboolean ce_page_mac_entry_valid (GtkEntry *entry, int type);
+gboolean ce_page_mac_entry_valid (GtkEntry *entry, int type, const char *property_name, GError **error);
 gboolean ce_page_device_entry_get (GtkEntry *entry, int type,
                                    char **ifname, char **mac);
 
diff --git a/src/connection-editor/page-bluetooth.c b/src/connection-editor/page-bluetooth.c
index eda3a70..23ec596 100644
--- a/src/connection-editor/page-bluetooth.c
+++ b/src/connection-editor/page-bluetooth.c
@@ -145,10 +145,8 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
        CEPageBluetooth *self = CE_PAGE_BLUETOOTH (page);
        CEPageBluetoothPrivate *priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self);
 
-       if (!ce_page_mac_entry_valid (priv->bdaddr, ARPHRD_ETHER)) {
-               g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid bdaddr MAC address"));
+       if (!ce_page_mac_entry_valid (priv->bdaddr, ARPHRD_ETHER, _("bdaddr"), error))
                return FALSE;
-       }
 
        ui_to_setting (self);
        return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
diff --git a/src/connection-editor/page-ethernet.c b/src/connection-editor/page-ethernet.c
index 461beae..750f4f3 100644
--- a/src/connection-editor/page-ethernet.c
+++ b/src/connection-editor/page-ethernet.c
@@ -339,10 +339,8 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
                }
        }
 
-       if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER)) {
-               g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("input: invalid MAC address"));
+       if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER, _("cloned MAC"), error))
                return FALSE;
-       }
 
        ui_to_setting (self);
        return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
diff --git a/src/connection-editor/page-vlan.c b/src/connection-editor/page-vlan.c
index 2e2b9e7..d051b15 100644
--- a/src/connection-editor/page-vlan.c
+++ b/src/connection-editor/page-vlan.c
@@ -734,10 +734,8 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
                }
        }
 
-       if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER)) {
-               g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid MAC address"));
+       if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER, _("cloned MAC"), error))
                return FALSE;
-       }
 
        ui_to_setting (self);
 
diff --git a/src/connection-editor/page-wifi.c b/src/connection-editor/page-wifi.c
index 3b5ce4b..faa2f15 100644
--- a/src/connection-editor/page-wifi.c
+++ b/src/connection-editor/page-wifi.c
@@ -563,10 +563,8 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
 
        entry = gtk_bin_get_child (GTK_BIN (priv->bssid));
        if (entry) {
-               if (!ce_page_mac_entry_valid (GTK_ENTRY (entry), ARPHRD_ETHER)) {
-                       g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid BSSID"));
+               if (!ce_page_mac_entry_valid (GTK_ENTRY (entry), ARPHRD_ETHER, _("bssid"), error))
                        return FALSE;
-               }
        }
 
        entry = gtk_bin_get_child (GTK_BIN (priv->device_combo));
@@ -577,10 +575,8 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
                }
        }
 
-       if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER)) {
-               g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid MAC address"));
+       if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER, _("cloned MAC"), error))
                return FALSE;
-       }
 
        ui_to_setting (self);
 


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