[network-manager-applet] libnm-gtk: add nma_utils_get_connection_device_name()



commit 38b30df12eb5271639ada4d977154dd1f48c79c8
Author: Dan Winship <danw gnome org>
Date:   Tue Dec 4 08:45:55 2012 -0500

    libnm-gtk: add nma_utils_get_connection_device_name()
    
    nma_utils_disambiguate_device_names() can only work for devices that
    actually exist. Add nma_utils_get_connection_device_name() to get the
    user-friendly device name for a virtual device that doesn't yet exist.

 src/libnm-gtk/nm-ui-utils.c |   37 +++++++++++++++++++++++++++++++++++++
 src/libnm-gtk/nm-ui-utils.h |    1 +
 2 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/libnm-gtk/nm-ui-utils.c b/src/libnm-gtk/nm-ui-utils.c
index 0e68257..68971bb 100644
--- a/src/libnm-gtk/nm-ui-utils.c
+++ b/src/libnm-gtk/nm-ui-utils.c
@@ -531,3 +531,40 @@ nma_utils_disambiguate_device_names (NMDevice **devices,
 	names[num_devices] = NULL;
 	return names;
 }
+
+/**
+ * nma_utils_get_connection_device_name:
+ * @connection: an #NMConnection for a virtual device type
+ *
+ * Returns the name that nma_utils_disambiguate_device_names() would
+ * return for the virtual device that would be created for @connection.
+ * Eg, "VLAN (eth1.1)".
+ *
+ * Returns: (transfer full): the name of @connection's device
+ */
+char *
+nma_utils_get_connection_device_name (NMConnection *connection)
+{
+	const char *iface, *type, *display_type;
+	NMSettingConnection *s_con;
+
+	iface = nm_connection_get_virtual_iface_name (connection);
+	g_return_val_if_fail (iface != NULL, NULL);
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_return_val_if_fail (s_con != NULL, NULL);
+	type = nm_setting_connection_get_connection_type (s_con);
+
+	if (!strcmp (type, NM_SETTING_BOND_SETTING_NAME))
+		display_type = _("Bond");
+	else if (!strcmp (type, NM_SETTING_BRIDGE_SETTING_NAME))
+		display_type = _("Bridge");
+	else if (!strcmp (type, NM_SETTING_VLAN_SETTING_NAME))
+		display_type = _("VLAN");
+	else {
+		g_warning ("Unrecognized virtual device type '%s'", type);
+		display_type = type;
+	}
+
+	return g_strdup_printf ("%s (%s)", display_type, iface);
+}
diff --git a/src/libnm-gtk/nm-ui-utils.h b/src/libnm-gtk/nm-ui-utils.h
index 3c09e17..693df44 100644
--- a/src/libnm-gtk/nm-ui-utils.h
+++ b/src/libnm-gtk/nm-ui-utils.h
@@ -35,6 +35,7 @@ const char *nma_utils_get_device_type_name (NMDevice *device);
 
 char **nma_utils_disambiguate_device_names (NMDevice **devices,
                                             int        num_devices);
+char *nma_utils_get_connection_device_name (NMConnection *connection);
 
 #endif	/* NMA_UI_UTILS_H */
 



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