summaryrefslogtreecommitdiff
path: root/libnm-util/nm-connection.c
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2013-12-18 15:15:21 -0500
committerDan Winship <danw@gnome.org>2014-01-27 15:39:51 -0500
commitf7b1b2820245aff26da0c2c946b55752e91112e5 (patch)
tree61406813aec66b02005f698a2cb18895c3964b4b /libnm-util/nm-connection.c
parent078d177874736bdc9ee06ef7406a31702b63a69a (diff)
downloadNetworkManager-f7b1b2820245aff26da0c2c946b55752e91112e5.tar.gz
libnm-util, libnm-glib: add device/connection describing functions
Add functions to describe and disambiguate devices and connections for display to the user. Originally from libnm-gtk.
Diffstat (limited to 'libnm-util/nm-connection.c')
-rw-r--r--libnm-util/nm-connection.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index f7d643193c..52b541120b 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -24,6 +24,7 @@
*/
#include <glib-object.h>
+#include <glib/gi18n.h>
#include <dbus/dbus-glib.h>
#include <string.h>
#include "nm-connection.h"
@@ -1242,6 +1243,47 @@ nm_connection_get_id (NMConnection *connection)
return nm_setting_connection_get_id (s_con);
}
+/**
+ * nm_connection_get_virtual_device_description:
+ * @connection: an #NMConnection for a virtual device type
+ *
+ * Returns the name that nm_device_disambiguate_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,
+ * or %NULL if @connection is not a virtual connection type
+ */
+char *
+nm_connection_get_virtual_device_description (NMConnection *connection)
+{
+ const char *iface, *type, *display_type;
+ NMSettingConnection *s_con;
+
+ iface = nm_connection_get_virtual_iface_name (connection);
+ if (!iface)
+ return 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_TEAM_SETTING_NAME))
+ display_type = _("Team");
+ 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);
+}
+
/*************************************************************/
/**