From 2a7e60d7244b20771933db61ee5a1c76bcb768a9 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 9 Nov 2018 14:56:24 +0100 Subject: [PATCH] cli/devices: sort hotspots above in nmcli output In general we want to keep the connections that the user is most likely to want to see topmost. Default connections should be close to the top, but the connections that are likely to have been brought up manually shall be above them. It applies to VPN connections and should apply to Hotspots too. --- clients/cli/devices.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/clients/cli/devices.c b/clients/cli/devices.c index 8e26a14450..f1211071e8 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -905,6 +905,8 @@ compare_devices (const void *a, const void *b) NMDevice *db = *(NMDevice **)b; NMActiveConnection *da_ac; NMActiveConnection *db_ac; + NMSettingIPConfig *s_ip; + NMRemoteConnection *conn; NMIPConfig *da_ip; NMIPConfig *db_ip; int da_num_addrs; @@ -927,7 +929,30 @@ compare_devices (const void *a, const void *b) if (cmp != 0) return cmp; - /* VPNs go on the top if possible */ + /* Shared connections (likely hotspots) go on the top if possible */ + conn = da_ac ? nm_active_connection_get_connection (da_ac) : NULL; + s_ip = conn ? nm_connection_get_setting_ip6_config (NM_CONNECTION (conn)) : NULL; + if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) + cmp--; + conn = db_ac ? nm_active_connection_get_connection (db_ac) : NULL; + s_ip = conn ? nm_connection_get_setting_ip6_config (NM_CONNECTION (conn)) : NULL; + if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) + cmp++; + if (cmp != 0) + return cmp; + + conn = da_ac ? nm_active_connection_get_connection (da_ac) : NULL; + s_ip = conn ? nm_connection_get_setting_ip4_config (NM_CONNECTION (conn)) : NULL; + if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) + cmp--; + conn = db_ac ? nm_active_connection_get_connection (db_ac) : NULL; + s_ip = conn ? nm_connection_get_setting_ip4_config (NM_CONNECTION (conn)) : NULL; + if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) + cmp++; + if (cmp != 0) + return cmp; + + /* VPNs go next */ if (da_ac && !nm_active_connection_get_vpn (da_ac)) cmp++; if (db_ac && !nm_active_connection_get_vpn (db_ac))