[network-manager-applet] connection-editor: redo ce_page_get_mac_list()
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet] connection-editor: redo ce_page_get_mac_list()
- Date: Thu, 4 Oct 2012 12:43:33 +0000 (UTC)
commit 2bc965794192baef11299014ad6e0c42c3870f9c
Author: Dan Winship <danw gnome org>
Date: Wed Aug 8 14:53:30 2012 -0400
connection-editor: redo ce_page_get_mac_list()
ce_page_get_mac_list() was a virtual method that had nearly identical
implementations in every class. Make it non-virtual and add a few
parameters instead.
src/connection-editor/ce-page.c | 30 ++++++++++++++++++++++---
src/connection-editor/ce-page.h | 3 +-
src/connection-editor/page-ethernet.c | 36 +-----------------------------
src/connection-editor/page-infiniband.c | 36 +-----------------------------
src/connection-editor/page-wifi.c | 36 +-----------------------------
src/connection-editor/page-wimax.c | 36 +-----------------------------
6 files changed, 35 insertions(+), 142 deletions(-)
---
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index c2c44ae..e0cae96 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -125,14 +125,36 @@ ce_page_validate (CEPage *self, NMConnection *connection, GError **error)
}
char **
-ce_page_get_mac_list (CEPage *self)
+ce_page_get_mac_list (CEPage *self, GType device_type, const char *mac_property)
{
+ const GPtrArray *devices;
+ GPtrArray *macs;
+ int i;
+
g_return_val_if_fail (CE_IS_PAGE (self), NULL);
- if (CE_PAGE_GET_CLASS (self)->get_mac_list)
- return CE_PAGE_GET_CLASS (self)->get_mac_list (self);
+ if (!self->client)
+ return NULL;
- return NULL;
+ macs = g_ptr_array_new ();
+ devices = nm_client_get_devices (self->client);
+ for (i = 0; devices && (i < devices->len); i++) {
+ NMDevice *dev = g_ptr_array_index (devices, i);
+ const char *iface;
+ char *mac, *item;
+
+ if (!G_TYPE_CHECK_INSTANCE_TYPE (dev, device_type))
+ continue;
+
+ g_object_get (G_OBJECT (dev), mac_property, &mac, NULL);
+ iface = nm_device_get_iface (NM_DEVICE (dev));
+ item = g_strdup_printf ("%s (%s)", mac, iface);
+ g_free (mac);
+ g_ptr_array_add (macs, item);
+ }
+
+ g_ptr_array_add (macs, NULL);
+ return (char **)g_ptr_array_free (macs, FALSE);
}
void
diff --git a/src/connection-editor/ce-page.h b/src/connection-editor/ce-page.h
index 0ff5ebc..b6a0d28 100644
--- a/src/connection-editor/ce-page.h
+++ b/src/connection-editor/ce-page.h
@@ -84,7 +84,6 @@ typedef struct {
/* Virtual functions */
gboolean (*validate) (CEPage *self, NMConnection *connection, GError **error);
- char ** (*get_mac_list) (CEPage *self);
/* Let the page warn the user if some property needs review */
GtkWidget * (*nag_user) (CEPage *self);
@@ -110,7 +109,7 @@ const char * ce_page_get_title (CEPage *self);
gboolean ce_page_validate (CEPage *self, NMConnection *connection, GError **error);
-char **ce_page_get_mac_list (CEPage *self);
+char **ce_page_get_mac_list (CEPage *self, GType device_type, const char *mac_property);
void ce_page_changed (CEPage *self);
diff --git a/src/connection-editor/page-ethernet.c b/src/connection-editor/page-ethernet.c
index 46c5875..c6ac1a8 100644
--- a/src/connection-editor/page-ethernet.c
+++ b/src/connection-editor/page-ethernet.c
@@ -173,7 +173,8 @@ populate_ui (CEPageEthernet *self)
nm_setting_wired_get_auto_negotiate (setting));
/* Device MAC address */
- mac_list = ce_page_get_mac_list (CE_PAGE (self));
+ mac_list = ce_page_get_mac_list (CE_PAGE (self), NM_TYPE_DEVICE_ETHERNET,
+ NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
s_mac = nm_setting_wired_get_mac_address (setting);
s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL;
for (iter = mac_list; iter && *iter; iter++) {
@@ -387,38 +388,6 @@ validate (CEPage *page, NMConnection *connection, GError **error)
return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
}
-static char **
-get_mac_list (CEPage *page)
-{
- const GPtrArray *devices;
- GString *mac_str;
- char **mac_list;
- int i;
-
- if (!page->client)
- return NULL;
-
- mac_str = g_string_new (NULL);
- devices = nm_client_get_devices (page->client);
- for (i = 0; devices && (i < devices->len); i++) {
- const char *mac, *iface;
- NMDevice *dev = g_ptr_array_index (devices, i);
-
- if (!NM_IS_DEVICE_ETHERNET (dev))
- continue;
-
- mac = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (dev));
- iface = nm_device_get_iface (NM_DEVICE (dev));
- g_string_append_printf (mac_str, "%s (%s),", mac, iface);
- }
- g_string_truncate (mac_str, mac_str->len-1);
-
- mac_list = g_strsplit (mac_str->str, ",", 0);
- g_string_free (mac_str, TRUE);
-
- return mac_list;
-}
-
static void
ce_page_ethernet_init (CEPageEthernet *self)
{
@@ -434,7 +403,6 @@ ce_page_ethernet_class_init (CEPageEthernetClass *ethernet_class)
/* virtual methods */
parent_class->validate = validate;
- parent_class->get_mac_list = get_mac_list;
}
diff --git a/src/connection-editor/page-infiniband.c b/src/connection-editor/page-infiniband.c
index d10af7b..190a12c 100644
--- a/src/connection-editor/page-infiniband.c
+++ b/src/connection-editor/page-infiniband.c
@@ -116,7 +116,8 @@ populate_ui (CEPageInfiniband *self)
gtk_combo_box_set_active (priv->transport_mode, mode_idx);
/* Device MAC address */
- mac_list = ce_page_get_mac_list (CE_PAGE (self));
+ mac_list = ce_page_get_mac_list (CE_PAGE (self), NM_TYPE_DEVICE_INFINIBAND,
+ NM_DEVICE_INFINIBAND_HW_ADDRESS);
s_mac = nm_setting_infiniband_get_mac_address (setting);
s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_INFINIBAND):
NULL;
@@ -256,38 +257,6 @@ validate (CEPage *page, NMConnection *connection, GError **error)
return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
}
-static char **
-get_mac_list (CEPage *page)
-{
- const GPtrArray *devices;
- GString *mac_str;
- char **mac_list;
- int i;
-
- if (!page->client)
- return NULL;
-
- mac_str = g_string_new (NULL);
- devices = nm_client_get_devices (page->client);
- for (i = 0; devices && (i < devices->len); i++) {
- const char *mac, *iface;
- NMDevice *dev = g_ptr_array_index (devices, i);
-
- if (!NM_IS_DEVICE_INFINIBAND (dev))
- continue;
-
- mac = nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (dev));
- iface = nm_device_get_iface (NM_DEVICE (dev));
- g_string_append_printf (mac_str, "%s (%s),", mac, iface);
- }
- g_string_truncate (mac_str, mac_str->len-1);
-
- mac_list = g_strsplit (mac_str->str, ",", 0);
- g_string_free (mac_str, TRUE);
-
- return mac_list;
-}
-
static void
ce_page_infiniband_init (CEPageInfiniband *self)
{
@@ -303,7 +272,6 @@ ce_page_infiniband_class_init (CEPageInfinibandClass *infiniband_class)
/* virtual methods */
parent_class->validate = validate;
- parent_class->get_mac_list = get_mac_list;
}
diff --git a/src/connection-editor/page-wifi.c b/src/connection-editor/page-wifi.c
index 470c454..0c11feb 100644
--- a/src/connection-editor/page-wifi.c
+++ b/src/connection-editor/page-wifi.c
@@ -376,7 +376,8 @@ populate_ui (CEPageWifi *self)
g_signal_connect_swapped (priv->bssid, "changed", G_CALLBACK (ce_page_changed), self);
/* Device MAC address */
- mac_list = ce_page_get_mac_list (CE_PAGE (self));
+ mac_list = ce_page_get_mac_list (CE_PAGE (self), NM_TYPE_DEVICE_WIFI,
+ NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS);
s_mac = nm_setting_wireless_get_mac_address (setting);
s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL;
for (iter = mac_list; iter && *iter; iter++) {
@@ -603,38 +604,6 @@ validate (CEPage *page, NMConnection *connection, GError **error)
return success;
}
-static char **
-get_mac_list (CEPage *page)
-{
- const GPtrArray *devices;
- GString *mac_str;
- char **mac_list;
- int i;
-
- if (!page->client)
- return NULL;
-
- mac_str = g_string_new (NULL);
- devices = nm_client_get_devices (page->client);
- for (i = 0; devices && (i < devices->len); i++) {
- const char *mac, *iface;
- NMDevice *dev = g_ptr_array_index (devices, i);
-
- if (!NM_IS_DEVICE_WIFI (dev))
- continue;
-
- mac = nm_device_wifi_get_permanent_hw_address (NM_DEVICE_WIFI (dev));
- iface = nm_device_get_iface (NM_DEVICE (dev));
- g_string_append_printf (mac_str, "%s (%s),", mac, iface);
- }
- g_string_truncate (mac_str, mac_str->len-1);
-
- mac_list = g_strsplit (mac_str->str, ",", 0);
- g_string_free (mac_str, TRUE);
-
- return mac_list;
-}
-
static void
ce_page_wifi_init (CEPageWifi *self)
{
@@ -650,7 +619,6 @@ ce_page_wifi_class_init (CEPageWifiClass *wifi_class)
/* virtual methods */
parent_class->validate = validate;
- parent_class->get_mac_list = get_mac_list;
}
diff --git a/src/connection-editor/page-wimax.c b/src/connection-editor/page-wimax.c
index 449a621..e3308bf 100644
--- a/src/connection-editor/page-wimax.c
+++ b/src/connection-editor/page-wimax.c
@@ -93,7 +93,8 @@ populate_ui (CEPageWimax *self)
g_signal_connect_swapped (priv->name, "changed", G_CALLBACK (ce_page_changed), self);
/* Device MAC address */
- mac_list = ce_page_get_mac_list (CE_PAGE (self));
+ mac_list = ce_page_get_mac_list (CE_PAGE (self), NM_TYPE_DEVICE_WIMAX,
+ NM_DEVICE_WIMAX_HW_ADDRESS);
s_mac = nm_setting_wimax_get_mac_address (setting);
s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL;
for (iter = mac_list; iter && *iter; iter++) {
@@ -223,38 +224,6 @@ validate (CEPage *page, NMConnection *connection, GError **error)
return TRUE;
}
-static char **
-get_mac_list (CEPage *page)
-{
- const GPtrArray *devices;
- GString *mac_str;
- char **mac_list;
- int i;
-
- if (!page->client)
- return NULL;
-
- mac_str = g_string_new (NULL);
- devices = nm_client_get_devices (page->client);
- for (i = 0; devices && (i < devices->len); i++) {
- const char *mac, *iface;
- NMDevice *dev = g_ptr_array_index (devices, i);
-
- if (!NM_IS_DEVICE_WIMAX (dev))
- continue;
-
- mac = nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (dev));
- iface = nm_device_get_iface (NM_DEVICE (dev));
- g_string_append_printf (mac_str, "%s (%s),", mac, iface);
- }
- g_string_truncate (mac_str, mac_str->len-1);
-
- mac_list = g_strsplit (mac_str->str, ",", 0);
- g_string_free (mac_str, TRUE);
-
- return mac_list;
-}
-
static void
ce_page_wimax_init (CEPageWimax *self)
{
@@ -270,7 +239,6 @@ ce_page_wimax_class_init (CEPageWimaxClass *wimax_class)
/* virtual methods */
parent_class->validate = validate;
- parent_class->get_mac_list = get_mac_list;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]