network: display "device state reason", and remove duplicate code
For disconnected/unavailable devices, show the localized NMDeviceStateReason next to the localized NMDeviceState (and not in the tooltip). Also, move the code to do this into panel-common rather to save some duplication. https://bugzilla.gnome.org/show_bug.cgi?id=676117
This commit is contained in:
parent
e3c9f53a09
commit
15baea4720
7 changed files with 90 additions and 85 deletions
|
@ -208,7 +208,6 @@ device_ethernet_refresh_ui (NetDeviceEthernet *device)
|
||||||
NMDevice *nm_device;
|
NMDevice *nm_device;
|
||||||
NMDeviceState state;
|
NMDeviceState state;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GString *status;
|
|
||||||
gchar *speed = NULL;
|
gchar *speed = NULL;
|
||||||
|
|
||||||
nm_device = net_device_get_nm_device (NET_DEVICE (device));
|
nm_device = net_device_get_nm_device (NET_DEVICE (device));
|
||||||
|
@ -230,17 +229,9 @@ device_ethernet_refresh_ui (NetDeviceEthernet *device)
|
||||||
gtk_switch_set_active (GTK_SWITCH (widget), device_state_to_off_switch (state));
|
gtk_switch_set_active (GTK_SWITCH (widget), device_state_to_off_switch (state));
|
||||||
device->updating_device = FALSE;
|
device->updating_device = FALSE;
|
||||||
|
|
||||||
widget = GTK_WIDGET (gtk_builder_get_object (device->builder, "label_status"));
|
|
||||||
status = g_string_new (panel_device_state_to_localized_string (nm_device));
|
|
||||||
if (state != NM_DEVICE_STATE_UNAVAILABLE)
|
if (state != NM_DEVICE_STATE_UNAVAILABLE)
|
||||||
speed = net_device_simple_get_speed (NET_DEVICE_SIMPLE (device));
|
speed = net_device_simple_get_speed (NET_DEVICE_SIMPLE (device));
|
||||||
if (speed) {
|
panel_set_device_status (device->builder, "label_status", nm_device, speed);
|
||||||
if (status->len)
|
|
||||||
g_string_append (status, " - ");
|
|
||||||
g_string_append (status, speed);
|
|
||||||
}
|
|
||||||
gtk_label_set_label (GTK_LABEL (widget), status->str);
|
|
||||||
g_string_free (status, TRUE);
|
|
||||||
|
|
||||||
populate_ui (device);
|
populate_ui (device);
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,10 +247,8 @@ static void
|
||||||
nm_device_mobile_refresh_ui (NetDeviceMobile *device_mobile)
|
nm_device_mobile_refresh_ui (NetDeviceMobile *device_mobile)
|
||||||
{
|
{
|
||||||
gboolean is_connected;
|
gboolean is_connected;
|
||||||
GString *status;
|
|
||||||
GtkListStore *liststore;
|
GtkListStore *liststore;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
guint speed = 0;
|
|
||||||
NetDeviceMobilePrivate *priv = device_mobile->priv;
|
NetDeviceMobilePrivate *priv = device_mobile->priv;
|
||||||
NMClient *client;
|
NMClient *client;
|
||||||
NMDeviceModemCapabilities caps;
|
NMDeviceModemCapabilities caps;
|
||||||
|
@ -268,18 +266,8 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *device_mobile)
|
||||||
client = net_object_get_client (NET_OBJECT (device_mobile));
|
client = net_object_get_client (NET_OBJECT (device_mobile));
|
||||||
mobilebb_enabled_toggled (client, NULL, device_mobile);
|
mobilebb_enabled_toggled (client, NULL, device_mobile);
|
||||||
|
|
||||||
/* set device state, with status and optionally speed */
|
/* set device state, with status */
|
||||||
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder, "label_status"));
|
panel_set_device_status (device_mobile->priv->builder, "label_status", nm_device, NULL);
|
||||||
status = g_string_new (panel_device_state_to_localized_string (nm_device));
|
|
||||||
if (speed > 0) {
|
|
||||||
if (status->len)
|
|
||||||
g_string_append (status, " - ");
|
|
||||||
/* Translators: network device speed */
|
|
||||||
g_string_append_printf (status, _("%d Mb/s"), speed);
|
|
||||||
}
|
|
||||||
gtk_label_set_label (GTK_LABEL (widget), status->str);
|
|
||||||
g_string_free (status, TRUE);
|
|
||||||
gtk_widget_set_tooltip_text (widget, panel_device_state_reason_to_localized_string (nm_device));
|
|
||||||
|
|
||||||
/* sensitive for other connection types if the device is currently connected */
|
/* sensitive for other connection types if the device is currently connected */
|
||||||
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
|
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
|
||||||
|
|
|
@ -93,13 +93,12 @@ update_off_switch_from_device_state (GtkSwitch *sw,
|
||||||
static void
|
static void
|
||||||
nm_device_simple_refresh_ui (NetDeviceSimple *device_simple)
|
nm_device_simple_refresh_ui (NetDeviceSimple *device_simple)
|
||||||
{
|
{
|
||||||
|
NetDeviceSimplePrivate *priv = device_simple->priv;
|
||||||
char *hwaddr;
|
char *hwaddr;
|
||||||
GString *status;
|
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
char *speed = NULL;
|
char *speed = NULL;
|
||||||
NMDevice *nm_device;
|
NMDevice *nm_device;
|
||||||
NMDeviceState state;
|
NMDeviceState state;
|
||||||
NetDeviceSimplePrivate *priv = device_simple->priv;
|
|
||||||
|
|
||||||
nm_device = net_device_get_nm_device (NET_DEVICE (device_simple));
|
nm_device = net_device_get_nm_device (NET_DEVICE (device_simple));
|
||||||
|
|
||||||
|
@ -124,20 +123,9 @@ nm_device_simple_refresh_ui (NetDeviceSimple *device_simple)
|
||||||
gtk_widget_set_visible (widget, state != NM_DEVICE_STATE_UNMANAGED);
|
gtk_widget_set_visible (widget, state != NM_DEVICE_STATE_UNMANAGED);
|
||||||
|
|
||||||
/* set device state, with status and optionally speed */
|
/* set device state, with status and optionally speed */
|
||||||
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_status"));
|
|
||||||
status = g_string_new (panel_device_state_to_localized_string (nm_device));
|
|
||||||
if (state != NM_DEVICE_STATE_UNAVAILABLE)
|
if (state != NM_DEVICE_STATE_UNAVAILABLE)
|
||||||
speed = net_device_simple_get_speed (device_simple);
|
speed = net_device_simple_get_speed (device_simple);
|
||||||
if (speed) {
|
panel_set_device_status (priv->builder, "label_status", nm_device, speed);
|
||||||
if (status->len)
|
|
||||||
g_string_append (status, " - ");
|
|
||||||
g_string_append (status, speed);
|
|
||||||
g_free (speed);
|
|
||||||
}
|
|
||||||
gtk_label_set_label (GTK_LABEL (widget), status->str);
|
|
||||||
g_string_free (status, TRUE);
|
|
||||||
gtk_widget_set_tooltip_text (widget,
|
|
||||||
panel_device_state_reason_to_localized_string (nm_device));
|
|
||||||
|
|
||||||
/* device MAC */
|
/* device MAC */
|
||||||
g_object_get (G_OBJECT (nm_device),
|
g_object_get (G_OBJECT (nm_device),
|
||||||
|
|
|
@ -494,7 +494,6 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi)
|
||||||
const gchar *str;
|
const gchar *str;
|
||||||
gboolean is_hotspot;
|
gboolean is_hotspot;
|
||||||
gchar *str_tmp = NULL;
|
gchar *str_tmp = NULL;
|
||||||
GtkWidget *widget;
|
|
||||||
gint strength = 0;
|
gint strength = 0;
|
||||||
guint speed = 0;
|
guint speed = 0;
|
||||||
NMAccessPoint *active_ap;
|
NMAccessPoint *active_ap;
|
||||||
|
@ -595,9 +594,7 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi)
|
||||||
else
|
else
|
||||||
panel_set_device_widget_details (priv->builder, "last_used", NULL);
|
panel_set_device_widget_details (priv->builder, "last_used", NULL);
|
||||||
|
|
||||||
widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder, "heading_status"));
|
panel_set_device_status (priv->builder, "heading_status", nm_device, NULL);
|
||||||
gtk_label_set_label (GTK_LABEL (widget),
|
|
||||||
panel_device_state_to_localized_string (nm_device));
|
|
||||||
|
|
||||||
/* update list of APs */
|
/* update list of APs */
|
||||||
populate_ap_list (device_wifi);
|
populate_ap_list (device_wifi);
|
||||||
|
|
|
@ -153,7 +153,6 @@ net_virtual_device_refresh (NetObject *object)
|
||||||
NetVirtualDevice *virtual_device = NET_VIRTUAL_DEVICE (object);
|
NetVirtualDevice *virtual_device = NET_VIRTUAL_DEVICE (object);
|
||||||
NetVirtualDevicePrivate *priv = virtual_device->priv;
|
NetVirtualDevicePrivate *priv = virtual_device->priv;
|
||||||
char *hwaddr;
|
char *hwaddr;
|
||||||
const char *status, *tooltip;
|
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
NMDevice *nm_device;
|
NMDevice *nm_device;
|
||||||
NMDeviceState state;
|
NMDeviceState state;
|
||||||
|
@ -174,16 +173,12 @@ net_virtual_device_refresh (NetObject *object)
|
||||||
update_off_switch_from_device_state (GTK_SWITCH (widget), state, virtual_device);
|
update_off_switch_from_device_state (GTK_SWITCH (widget), state, virtual_device);
|
||||||
|
|
||||||
/* set device state, with status and optionally speed */
|
/* set device state, with status and optionally speed */
|
||||||
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_status"));
|
|
||||||
if (nm_device) {
|
if (nm_device) {
|
||||||
status = panel_device_state_to_localized_string (nm_device);
|
panel_set_device_status (priv->builder, "label_status", nm_device, NULL);
|
||||||
tooltip = panel_device_state_reason_to_localized_string (nm_device);
|
|
||||||
} else {
|
} else {
|
||||||
status = "";
|
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_status"));
|
||||||
tooltip = NULL;
|
gtk_label_set_label (GTK_LABEL (widget), "");
|
||||||
}
|
}
|
||||||
gtk_label_set_label (GTK_LABEL (widget), status);
|
|
||||||
gtk_widget_set_tooltip_text (widget, tooltip);
|
|
||||||
|
|
||||||
/* device MAC */
|
/* device MAC */
|
||||||
if (nm_device) {
|
if (nm_device) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include <nm-device-ethernet.h>
|
#include <nm-device-ethernet.h>
|
||||||
|
#include <nm-device-infiniband.h>
|
||||||
#include <nm-device-modem.h>
|
#include <nm-device-modem.h>
|
||||||
#include <nm-utils.h>
|
#include <nm-utils.h>
|
||||||
|
|
||||||
|
@ -180,19 +181,11 @@ panel_ap_mode_to_localized_string (NM80211Mode mode)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static const gchar *
|
||||||
* panel_device_state_to_localized_string:
|
device_state_to_localized_string (NMDeviceState state)
|
||||||
**/
|
|
||||||
const gchar *
|
|
||||||
panel_device_state_to_localized_string (NMDevice *device)
|
|
||||||
{
|
{
|
||||||
NMDeviceType type;
|
|
||||||
NMDeviceState state;
|
|
||||||
|
|
||||||
type = nm_device_get_device_type (device);
|
|
||||||
state = nm_device_get_state (device);
|
|
||||||
|
|
||||||
const gchar *value = NULL;
|
const gchar *value = NULL;
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case NM_DEVICE_STATE_UNKNOWN:
|
case NM_DEVICE_STATE_UNKNOWN:
|
||||||
/* TRANSLATORS: device status */
|
/* TRANSLATORS: device status */
|
||||||
|
@ -203,20 +196,11 @@ panel_device_state_to_localized_string (NMDevice *device)
|
||||||
value = _("Unmanaged");
|
value = _("Unmanaged");
|
||||||
break;
|
break;
|
||||||
case NM_DEVICE_STATE_UNAVAILABLE:
|
case NM_DEVICE_STATE_UNAVAILABLE:
|
||||||
if (nm_device_get_firmware_missing (device)) {
|
/* TRANSLATORS: device status */
|
||||||
/* TRANSLATORS: device status */
|
value = _("Unavailable");
|
||||||
value = _("Firmware missing");
|
|
||||||
} else if (type == NM_DEVICE_TYPE_ETHERNET &&
|
|
||||||
!nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (device))) {
|
|
||||||
/* TRANSLATORS: device status */
|
|
||||||
value = _("Cable unplugged");
|
|
||||||
} else {
|
|
||||||
/* TRANSLATORS: device status */
|
|
||||||
value = _("Unavailable");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case NM_DEVICE_STATE_DISCONNECTED:
|
case NM_DEVICE_STATE_DISCONNECTED:
|
||||||
value = "";
|
value = NULL;
|
||||||
break;
|
break;
|
||||||
case NM_DEVICE_STATE_PREPARE:
|
case NM_DEVICE_STATE_PREPARE:
|
||||||
case NM_DEVICE_STATE_CONFIG:
|
case NM_DEVICE_STATE_CONFIG:
|
||||||
|
@ -291,16 +275,17 @@ panel_vpn_state_to_localized_string (NMVPNConnectionState type)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static const gchar *
|
||||||
* panel_device_state_reason_to_localized_string:
|
device_state_reason_to_localized_string (NMDevice *device)
|
||||||
**/
|
|
||||||
const gchar *
|
|
||||||
panel_device_state_reason_to_localized_string (NMDevice *device)
|
|
||||||
{
|
{
|
||||||
const gchar *value = NULL;
|
const gchar *value = NULL;
|
||||||
NMDeviceStateReason state_reason;
|
NMDeviceStateReason state_reason;
|
||||||
|
|
||||||
/* we only want the StateReason's we care about */
|
/* This only covers NMDeviceStateReasons that explain why a connection
|
||||||
|
* failed / can't be attempted, and aren't redundant with the state
|
||||||
|
* (eg, NM_DEVICE_STATE_REASON_CARRIER).
|
||||||
|
*/
|
||||||
|
|
||||||
nm_device_get_state_reason (device, &state_reason);
|
nm_device_get_state_reason (device, &state_reason);
|
||||||
switch (state_reason) {
|
switch (state_reason) {
|
||||||
case NM_DEVICE_STATE_REASON_CONFIG_FAILED:
|
case NM_DEVICE_STATE_REASON_CONFIG_FAILED:
|
||||||
|
@ -435,10 +420,6 @@ panel_device_state_reason_to_localized_string (NMDevice *device)
|
||||||
/* TRANSLATORS: device status reason */
|
/* TRANSLATORS: device status reason */
|
||||||
value = _("Connection disappeared");
|
value = _("Connection disappeared");
|
||||||
break;
|
break;
|
||||||
case NM_DEVICE_STATE_REASON_CARRIER:
|
|
||||||
/* TRANSLATORS: device status reason */
|
|
||||||
value = _("Carrier/link changed");
|
|
||||||
break;
|
|
||||||
case NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED:
|
case NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED:
|
||||||
/* TRANSLATORS: device status reason */
|
/* TRANSLATORS: device status reason */
|
||||||
value = _("Existing connection was assumed");
|
value = _("Existing connection was assumed");
|
||||||
|
@ -483,6 +464,69 @@ panel_device_state_reason_to_localized_string (NMDevice *device)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
device_status_to_localized_string (NMDevice *nm_device,
|
||||||
|
const gchar *speed)
|
||||||
|
{
|
||||||
|
NMDeviceState state;
|
||||||
|
GString *string;
|
||||||
|
const gchar *state_str = NULL, *reason_str = NULL;
|
||||||
|
|
||||||
|
string = g_string_new (NULL);
|
||||||
|
|
||||||
|
state = nm_device_get_state (nm_device);
|
||||||
|
if (state == NM_DEVICE_STATE_UNAVAILABLE) {
|
||||||
|
if (nm_device_get_firmware_missing (nm_device)) {
|
||||||
|
/* TRANSLATORS: device status */
|
||||||
|
state_str = _("Firmware missing");
|
||||||
|
} else if (NM_IS_DEVICE_ETHERNET (nm_device) &&
|
||||||
|
!nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (nm_device))) {
|
||||||
|
/* TRANSLATORS: device status */
|
||||||
|
state_str = _("Cable unplugged");
|
||||||
|
} else if (NM_IS_DEVICE_INFINIBAND (nm_device) &&
|
||||||
|
!nm_device_infiniband_get_carrier (NM_DEVICE_INFINIBAND (nm_device))) {
|
||||||
|
state_str = _("Cable unplugged");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!state_str)
|
||||||
|
state_str = device_state_to_localized_string (state);
|
||||||
|
if (state_str)
|
||||||
|
g_string_append (string, state_str);
|
||||||
|
|
||||||
|
if (state > NM_DEVICE_STATE_UNAVAILABLE && speed) {
|
||||||
|
if (string->len)
|
||||||
|
g_string_append (string, " - ");
|
||||||
|
g_string_append (string, speed);
|
||||||
|
} else if (state == NM_DEVICE_STATE_UNAVAILABLE ||
|
||||||
|
state == NM_DEVICE_STATE_DISCONNECTED ||
|
||||||
|
state == NM_DEVICE_STATE_DEACTIVATING ||
|
||||||
|
state == NM_DEVICE_STATE_FAILED) {
|
||||||
|
reason_str = device_state_reason_to_localized_string (nm_device);
|
||||||
|
if (*reason_str) {
|
||||||
|
if (string->len)
|
||||||
|
g_string_append (string, " - ");
|
||||||
|
g_string_append (string, reason_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_string_free (string, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
panel_set_device_status (GtkBuilder *builder,
|
||||||
|
const gchar *label_name,
|
||||||
|
NMDevice *nm_device,
|
||||||
|
const gchar *speed)
|
||||||
|
{
|
||||||
|
GtkLabel *label;
|
||||||
|
gchar *status;
|
||||||
|
|
||||||
|
label = GTK_LABEL (gtk_builder_get_object (builder, label_name));
|
||||||
|
status = device_status_to_localized_string (nm_device, speed);
|
||||||
|
gtk_label_set_label (label, status);
|
||||||
|
g_free (status);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
panel_set_device_widget_details (GtkBuilder *builder,
|
panel_set_device_widget_details (GtkBuilder *builder,
|
||||||
const gchar *widget_suffix,
|
const gchar *widget_suffix,
|
||||||
|
|
|
@ -35,9 +35,11 @@ const gchar *panel_device_to_icon_name (NMDevice *device
|
||||||
const gchar *panel_device_to_localized_string (NMDevice *device);
|
const gchar *panel_device_to_localized_string (NMDevice *device);
|
||||||
const gchar *panel_device_to_sortable_string (NMDevice *device);
|
const gchar *panel_device_to_sortable_string (NMDevice *device);
|
||||||
const gchar *panel_ap_mode_to_localized_string (NM80211Mode mode);
|
const gchar *panel_ap_mode_to_localized_string (NM80211Mode mode);
|
||||||
const gchar *panel_device_state_to_localized_string (NMDevice *device);
|
|
||||||
const gchar *panel_vpn_state_to_localized_string (NMVPNConnectionState type);
|
const gchar *panel_vpn_state_to_localized_string (NMVPNConnectionState type);
|
||||||
const gchar *panel_device_state_reason_to_localized_string (NMDevice *device);
|
void panel_set_device_status (GtkBuilder *builder,
|
||||||
|
const gchar *label_name,
|
||||||
|
NMDevice *nm_device,
|
||||||
|
const gchar *speed);
|
||||||
gboolean panel_set_device_widget_details (GtkBuilder *builder,
|
gboolean panel_set_device_widget_details (GtkBuilder *builder,
|
||||||
const gchar *widget_suffix,
|
const gchar *widget_suffix,
|
||||||
const gchar *value);
|
const gchar *value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue