[network-manager-applet/pavlix/appindicator-bgo740574: 3/7] indicator: add device specific icon code
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/pavlix/appindicator-bgo740574: 3/7] indicator: add device specific icon code
- Date: Wed, 17 Dec 2014 12:41:51 +0000 (UTC)
commit 3d5084e5fe8c52973c882b9ee70cdcc33d56dc96
Author: Pavel Šimerda <psimerda redhat com>
Date: Sun Nov 23 22:27:19 2014 +0100
indicator: add device specific icon code
Add device specific code for appindicator.
src/applet-device-cdma.c | 32 +++++++++++++++
src/applet-device-gsm.c | 36 +++++++++++++++++
src/applet-device-wifi.c | 96 +++++++++++++++++++++++++++++++++++++++++++++
src/applet-device-wimax.c | 48 ++++++++++++++++++-----
4 files changed, 202 insertions(+), 10 deletions(-)
---
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index 5abd75d..b179cb4 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -237,6 +237,9 @@ cdma_add_menu_item (NMDevice *device,
char *text;
GtkWidget *item;
GSList *iter;
+#ifdef ENABLE_INDICATOR
+ GtkWidget *signal_icon;
+#endif
info = g_object_get_data (G_OBJECT (device), "devinfo");
@@ -262,6 +265,7 @@ cdma_add_menu_item (NMDevice *device,
s_con = nm_connection_get_setting_connection (active);
g_assert (s_con);
+#ifndef ENABLE_INDICATOR
item = nm_mb_menu_item_new (nm_setting_connection_get_id (s_con),
info->quality_valid ? info->quality : 0,
info->provider_name,
@@ -270,6 +274,19 @@ cdma_add_menu_item (NMDevice *device,
cdma_state_to_mb_state (info),
info->modem_enabled,
applet);
+#else
+ text = mobile_helper_get_connection_label (nm_setting_connection_get_id (s_con),
+ info->provider_name,
+ cdma_act_to_mb_act (info),
+ cdma_state_to_mb_state (info));
+ item = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+ text = g_strdup (mobile_helper_get_quality_icon_name (info->quality_valid ? info->quality :
0));
+ signal_icon = gtk_image_new_from_icon_name (text, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (text);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), signal_icon);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
+#endif
gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
add_connection_item (device, active, item, menu, applet);
}
@@ -283,6 +300,7 @@ cdma_add_menu_item (NMDevice *device,
}
} else {
/* Otherwise show idle registration state or disabled */
+#ifndef ENABLE_INDICATOR
item = nm_mb_menu_item_new (NULL,
info->quality_valid ? info->quality : 0,
info->provider_name,
@@ -291,6 +309,19 @@ cdma_add_menu_item (NMDevice *device,
cdma_state_to_mb_state (info),
info->modem_enabled,
applet);
+#else
+ text = mobile_helper_get_connection_label (NULL,
+ info->provider_name,
+ cdma_act_to_mb_act (info),
+ cdma_state_to_mb_state (info));
+ item = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+ text = g_strdup (mobile_helper_get_quality_icon_name (info->quality_valid ? info->quality :
0));
+ signal_icon = gtk_image_new_from_icon_name (text, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (text);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), signal_icon);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
+#endif
gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
@@ -596,6 +627,7 @@ reg_state_changed_cb (DBusGProxy *proxy,
update_registration_state (info, cdma1x_state, evdo_state);
info->skip_reg_poll = TRUE;
applet_schedule_update_icon (info->applet);
+ applet_schedule_update_menu (info->applet);
}
static void
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index b398224..2140673 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -44,6 +44,7 @@
#include "applet.h"
#include "applet-device-gsm.h"
#include "utils.h"
+#include "mobile-helpers.h"
#include "applet-dialogs.h"
#include "mb-menu-item.h"
#include "nma-marshal.h"
@@ -293,6 +294,9 @@ gsm_add_menu_item (NMDevice *device,
char *text;
GtkWidget *item;
GSList *iter;
+#ifdef ENABLE_INDICATOR
+ GtkWidget *signal_icon;
+#endif
info = g_object_get_data (G_OBJECT (device), "devinfo");
@@ -318,6 +322,7 @@ gsm_add_menu_item (NMDevice *device,
s_con = nm_connection_get_setting_connection (active);
g_assert (s_con);
+#ifndef ENABLE_INDICATOR
item = nm_mb_menu_item_new (nm_setting_connection_get_id (s_con),
info->quality_valid ? info->quality : 0,
info->op_name,
@@ -326,6 +331,19 @@ gsm_add_menu_item (NMDevice *device,
gsm_state_to_mb_state (info),
info->modem_enabled,
applet);
+#else
+ text = mobile_helper_get_connection_label (nm_setting_connection_get_id (s_con),
+ info->op_name,
+ gsm_act_to_mb_act (info),
+ gsm_state_to_mb_state (info));
+ item = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+ text = g_strdup (mobile_helper_get_quality_icon_name (info->quality_valid ? info->quality :
0));
+ signal_icon = gtk_image_new_from_icon_name (text, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (text);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), signal_icon);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
+#endif
gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
add_connection_item (device, active, item, menu, applet);
}
@@ -339,6 +357,7 @@ gsm_add_menu_item (NMDevice *device,
}
} else {
/* Otherwise show idle registration state or disabled */
+#ifndef ENABLE_INDICATOR
item = nm_mb_menu_item_new (NULL,
info->quality_valid ? info->quality : 0,
info->op_name,
@@ -347,6 +366,21 @@ gsm_add_menu_item (NMDevice *device,
gsm_state_to_mb_state (info),
info->modem_enabled,
applet);
+#else
+ text = mobile_helper_get_connection_label (NULL,
+ info->op_name,
+ gsm_act_to_mb_act (info),
+ gsm_state_to_mb_state (info));
+ item = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+ text = g_strdup (mobile_helper_get_quality_icon_name (info->quality_valid ? info->quality :
0));
+ signal_icon = gtk_image_new_from_icon_name (text, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (text);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), signal_icon);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
+ gtk_widget_set_sensitive (item, FALSE);
+#endif
+
gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
@@ -1035,6 +1069,8 @@ reg_info_changed_cb (DBusGProxy *proxy,
op_name,
info->op_code);
info->skip_reg_poll = TRUE;
+
+ applet_schedule_update_menu (info->applet);
}
static void
diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index c67f8b6..7331cef 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -306,6 +306,87 @@ is_blacklisted_ssid (const GByteArray *ssid)
return is_ssid_in_list (ssid, blacklisted_ssids);
}
+#ifdef ENABLE_INDICATOR
+static gchar *
+get_best_icon_name_for_ap (NMAccessPoint *ap, gboolean need_sec, gboolean encrypted)
+{
+ GString *icon_name = NULL;
+ gchar *tmp = NULL;
+ guint32 strength;
+
+ g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
+
+ strength = nm_access_point_get_strength (ap);
+ strength = CLAMP (strength, 0, 100);
+
+ icon_name = g_string_new ("");
+ if (strength > 80)
+ icon_name = g_string_assign (icon_name, "nm-signal-100");
+ else if (strength > 55)
+ icon_name = g_string_assign (icon_name, "nm-signal-75");
+ else if (strength > 30)
+ icon_name = g_string_assign (icon_name, "nm-signal-50");
+ else if (strength > 5)
+ icon_name = g_string_assign (icon_name, "nm-signal-25");
+ else
+ icon_name = g_string_assign (icon_name, "nm-signal-00");
+
+ if (nm_access_point_get_mode (ap) == NM_802_11_MODE_ADHOC) {
+ icon_name = g_string_assign (icon_name, "nm-adhoc");
+ goto out;
+ }
+
+ if (need_sec && encrypted)
+ icon_name = g_string_append (icon_name, "-secure");
+
+out:
+ tmp = icon_name->str;
+ g_string_free (icon_name, FALSE);
+
+ return tmp;
+}
+
+static void
+set_menu_item_accessible_desc (NMAccessPoint *ap,
+ GtkMenuItem *item,
+ gboolean is_encrypted)
+{
+ guint32 strength;
+ gchar *ssid = NULL;
+ GString *icon_desc = NULL;
+
+ g_return_if_fail (NM_IS_ACCESS_POINT (ap));
+
+ strength = nm_access_point_get_strength (ap);
+ strength = CLAMP (strength, 0, 100);
+
+ ssid = g_strdup (gtk_menu_item_get_label (item));
+
+ if (ssid == NULL)
+ return;
+
+ icon_desc = g_string_new ("");
+ g_string_append_printf (icon_desc, "%s: ", ssid);
+
+ if (nm_access_point_get_mode (ap) == NM_802_11_MODE_ADHOC) {
+ icon_desc = g_string_append (icon_desc, _("ad-hoc"));
+ goto out;
+ }
+
+ g_string_append_printf (icon_desc, "%d%%", strength);
+
+ if (is_encrypted) {
+ icon_desc = g_string_append (icon_desc, ", ");
+ icon_desc = g_string_append (icon_desc, _("secure."));
+ }
+
+out:
+ atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (item)), icon_desc->str);
+ g_free (ssid);
+ g_string_free (icon_desc, TRUE);
+}
+#endif
+
static void
clamp_ap_to_bssid (NMAccessPoint *ap, NMSettingWireless *s_wifi)
{
@@ -535,6 +616,10 @@ create_new_ap_item (NMDeviceWifi *device,
WifiMenuItemInfo *info;
GSList *iter;
NMNetworkMenuItem *item = NULL;
+#ifdef ENABLE_INDICATOR
+ char *best_icon_name;
+ GtkWidget *icon_image;
+#endif
GSList *dev_connections = NULL;
GSList *ap_connections = NULL;
const GByteArray *ssid;
@@ -556,6 +641,15 @@ create_new_ap_item (NMDeviceWifi *device,
nm_network_menu_item_set_detail (item, ap, nma_icon_check_and_load ("nm-adhoc", applet), dev_caps);
nm_network_menu_item_best_strength (item, nm_access_point_get_strength (ap), applet);
nm_network_menu_item_add_dupe (item, ap);
+#ifdef ENABLE_INDICATOR
+ best_icon_name = get_best_icon_name_for_ap (ap, TRUE, item->is_encrypted);
+ icon_image = gtk_image_new_from_icon_name (best_icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (best_icon_name);
+
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), icon_image);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
+ set_menu_item_accessible_desc (ap, GTK_MENU_ITEM (item), item->is_encrypted);
+#endif
g_object_set_data (G_OBJECT (item), "device", NM_DEVICE (device));
@@ -1078,6 +1172,7 @@ access_point_added_cb (NMDeviceWifi *device,
applet);
queue_avail_access_point_notification (NM_DEVICE (device));
+ applet_schedule_update_menu (applet);
}
static void
@@ -1095,6 +1190,7 @@ access_point_removed_cb (NMDeviceWifi *device,
if (old == ap) {
g_object_set_data (G_OBJECT (device), ACTIVE_AP_TAG, NULL);
applet_schedule_update_icon (applet);
+ applet_schedule_update_menu (applet);
}
}
diff --git a/src/applet-device-wimax.c b/src/applet-device-wimax.c
index 1741b2f..d492b3b 100644
--- a/src/applet-device-wimax.c
+++ b/src/applet-device-wimax.c
@@ -36,6 +36,7 @@
#include "applet.h"
#include "applet-device-wimax.h"
#include "applet-dialogs.h"
+#include "mobile-helpers.h"
#include "nma-marshal.h"
#include "mb-menu-item.h"
#include "nm-ui-utils.h"
@@ -116,6 +117,7 @@ wimax_menu_item_activate (GtkMenuItem *item, gpointer user_data)
user_data);
}
+#ifndef ENABLE_INDICATOR
static guint32
nsp_type_to_mb_state (NMWimaxNspNetworkType nsp_type)
{
@@ -131,6 +133,7 @@ nsp_type_to_mb_state (NMWimaxNspNetworkType nsp_type)
return MB_STATE_UNKNOWN;
}
+#endif
static GtkWidget *
new_nsp_menu_item (NMDeviceWimax *device,
@@ -141,9 +144,14 @@ new_nsp_menu_item (NMDeviceWimax *device,
{
GtkWidget *item;
WimaxMenuItemInfo *info;
+#ifdef ENABLE_INDICATOR
+ char *text = NULL;
+ GtkWidget *signal_icon = NULL;
+#endif
g_return_val_if_fail (nsp != NULL, NULL);
+#ifndef ENABLE_INDICATOR
item = nm_mb_menu_item_new (nm_wimax_nsp_get_name (nsp),
nm_wimax_nsp_get_signal_quality (nsp),
NULL,
@@ -152,6 +160,16 @@ new_nsp_menu_item (NMDeviceWimax *device,
nsp_type_to_mb_state (nm_wimax_nsp_get_network_type (nsp)),
TRUE,
applet);
+#else
+ text = g_strdup (nm_wimax_nsp_get_name (nsp));
+ item = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+ text = g_strdup (mobile_helper_get_quality_icon_name (nm_wimax_nsp_get_signal_quality (nsp)));
+ signal_icon = gtk_image_new_from_icon_name (text, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (text);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), signal_icon);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
+#endif
gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
info = g_slice_new0 (WimaxMenuItemInfo);
@@ -296,7 +314,10 @@ wimax_add_menu_item (NMDevice *device,
static void
nsp_quality_changed (NMWimaxNsp *nsp, GParamSpec *pspec, gpointer user_data)
{
- applet_schedule_update_icon (NM_APPLET (user_data));
+ NMApplet *applet = NM_APPLET (user_data);
+
+ applet_schedule_update_icon (applet);
+ applet_schedule_update_menu (applet);
}
static NMWimaxNsp *
@@ -358,8 +379,11 @@ active_nsp_changed_cb (NMDeviceWimax *device,
if (!s_wimax)
return;
- if (g_strcmp0 (nm_wimax_nsp_get_name (new), nm_setting_wimax_get_network_name (s_wimax)) != 0)
- applet_schedule_update_icon (applet);
+ if (g_strcmp0 (nm_wimax_nsp_get_name (new), nm_setting_wimax_get_network_name (s_wimax)) == 0)
+ return;
+
+ applet_schedule_update_icon (applet);
+ applet_schedule_update_menu (applet);
}
static void
@@ -367,15 +391,15 @@ nsp_removed_cb (NMDeviceWimax *device,
NMWimaxNsp *nsp,
gpointer user_data)
{
- NMApplet *applet = NM_APPLET (user_data);
- NMWimaxNsp *old;
+ NMApplet *applet = NM_APPLET (user_data);
+
+ if (g_object_get_data (G_OBJECT (device), ACTIVE_NSP_TAG) != nsp)
+ return;
/* Clear the ACTIVE_NSP_TAG if the active NSP just got removed */
- old = g_object_get_data (G_OBJECT (device), ACTIVE_NSP_TAG);
- if (old == nsp) {
- g_object_set_data (G_OBJECT (device), ACTIVE_NSP_TAG, NULL);
- applet_schedule_update_icon (applet);
- }
+ g_object_set_data (G_OBJECT (device), ACTIVE_NSP_TAG, NULL);
+ applet_schedule_update_icon (applet);
+ applet_schedule_update_menu (applet);
}
static void
@@ -447,11 +471,15 @@ wimax_get_icon (NMDevice *device,
break;
case NM_DEVICE_STATE_ACTIVATED:
roaming = (nsp_type == NM_WIMAX_NSP_NETWORK_TYPE_ROAMING_PARTNER);
+#ifdef ENABLE_INDICATOR
+ *out_icon_name = mobile_helper_get_quality_icon_name (quality);
+#else
*out_pixbuf = mobile_helper_get_status_pixbuf (quality,
TRUE,
nsp_type_to_mb_state (nsp_type),
MB_TECH_WIMAX,
applet);
+#endif
*tip = g_strdup_printf (_("Mobile broadband connection '%s' active: (%d%%%s%s)"),
id, quality,
roaming ? ", " : "",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]