summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-09-19 16:51:07 -0400
committerDan Winship <danw@gnome.org>2014-09-27 11:49:15 -0400
commite684f363654892754a12ec172a14689c425dad88 (patch)
tree31baa9431e1db412f48c8fce20f035beed6e9eaf /clients
parent1b74e77f9f5062d7542c367baa75185c27093d95 (diff)
downloadNetworkManager-e684f363654892754a12ec172a14689c425dad88.tar.gz
libnm-core: add nm_utils_wifi_strength_bars(), use it in nmcli and nmtui
Add nm_utils_wifi_strength_bars(), which figures out whether the terminal can display graphical wifi strength bars, and converts a numerical value to the appropriate Unicode or ASCII characters. This also now takes into consideration the fact that the console font doesn't contain all of the necessary characters, so we can't display the graphical bars there. (rh #1131491)
Diffstat (limited to 'clients')
-rw-r--r--clients/cli/devices.c11
-rw-r--r--clients/tui/nmt-connect-connection-list.c31
2 files changed, 2 insertions, 40 deletions
diff --git a/clients/cli/devices.c b/clients/cli/devices.c
index 2d512ee212..fc88309212 100644
--- a/clients/cli/devices.c
+++ b/clients/cli/devices.c
@@ -501,11 +501,6 @@ fill_output_access_point (gpointer data, gpointer user_data)
*bitrate_str, *strength_str, *wpa_flags_str, *rsn_flags_str;
GString *security_str;
char *ap_name;
- const char *sig_level_0 = "____";
- const char *sig_level_1 = "▂___";
- const char *sig_level_2 = "▂▄__";
- const char *sig_level_3 = "▂▄▆_";
- const char *sig_level_4 = "▂▄▆█";
const char *sig_bars;
if (info->active_bssid) {
@@ -540,11 +535,7 @@ fill_output_access_point (gpointer data, gpointer user_data)
strength_str = g_strdup_printf ("%u", strength);
wpa_flags_str = ap_wpa_rsn_flags_to_string (wpa_flags);
rsn_flags_str = ap_wpa_rsn_flags_to_string (rsn_flags);
- sig_bars = strength > 80 ? sig_level_4 :
- strength > 55 ? sig_level_3 :
- strength > 30 ? sig_level_2 :
- strength > 5 ? sig_level_1 :
- sig_level_0;
+ sig_bars = nm_utils_wifi_strength_bars (strength);
security_str = g_string_new (NULL);
diff --git a/clients/tui/nmt-connect-connection-list.c b/clients/tui/nmt-connect-connection-list.c
index 98e46ba14f..a596364533 100644
--- a/clients/tui/nmt-connect-connection-list.c
+++ b/clients/tui/nmt-connect-connection-list.c
@@ -61,8 +61,6 @@ typedef struct {
GSList *nmt_devices;
} NmtConnectConnectionListPrivate;
-static const char *strength_full, *strength_high, *strength_med, *strength_low, *strength_none;
-
/**
* nmt_connect_connection_list_new:
*
@@ -527,16 +525,7 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
if (nmtconn->ap) {
guint8 strength = nm_access_point_get_strength (nmtconn->ap);
- if (strength > 80)
- strength_col = strength_full;
- else if (strength > 55)
- strength_col = strength_high;
- else if (strength > 30)
- strength_col = strength_med;
- else if (strength > 5)
- strength_col = strength_low;
- else
- strength_col = strength_none;
+ strength_col = nm_utils_wifi_strength_bars (strength);
} else
strength_col = NULL;
@@ -608,30 +597,12 @@ static void
nmt_connect_connection_list_class_init (NmtConnectConnectionListClass *list_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (list_class);
- char *tmp;
g_type_class_add_private (list_class, sizeof (NmtConnectConnectionListPrivate));
/* virtual methods */
object_class->constructed = nmt_connect_connection_list_constructed;
object_class->finalize = nmt_connect_connection_list_finalize;
-
- /* globals */
- tmp = nmt_newt_locale_from_utf8 ("\342\226\202\342\226\204\342\226\206\342\226\210");
- if (*tmp) {
- strength_full = /* ▂▄▆█ */ "\342\226\202\342\226\204\342\226\206\342\226\210";
- strength_high = /* ▂▄▆_ */ "\342\226\202\342\226\204\342\226\206_";
- strength_med = /* ▂▄__ */ "\342\226\202\342\226\204__";
- strength_low = /* ▂___ */ "\342\226\202___";
- strength_none = /* ____ */ "____";
- } else {
- strength_full = "****";
- strength_high = "*** ";
- strength_med = "** ";
- strength_low = "* ";
- strength_none = " ";
- }
- g_free (tmp);
}
/**