[network-manager-applet] core: show signal strength, roaming, and access technology in panel



commit 296e00ad2906f8a1b14f9499ad296bbd4a95b685
Author: Dan Williams <dcbw redhat com>
Date:   Fri Apr 2 09:16:00 2010 -0700

    core: show signal strength, roaming, and access technology in panel
    
    We'll get better icons and signal bars eventually, but this will
    have to do for now.

 icons/22/Makefile.am         |   11 ++++-
 icons/22/nm-mb-roam.png      |  Bin 0 -> 267 bytes
 icons/22/nm-tech-3g.png      |  Bin 0 -> 209 bytes
 icons/22/nm-tech-cdma-1x.png |  Bin 0 -> 212 bytes
 icons/22/nm-tech-edge.png    |  Bin 0 -> 205 bytes
 icons/22/nm-tech-evdo.png    |  Bin 0 -> 215 bytes
 icons/22/nm-tech-gprs.png    |  Bin 0 -> 207 bytes
 icons/22/nm-tech-hspa.png    |  Bin 0 -> 213 bytes
 icons/22/nm-tech-umts.png    |  Bin 0 -> 196 bytes
 icons/22/nm-wwan-tower.png   |  Bin 0 -> 227 bytes
 src/Makefile.am              |    2 +
 src/applet-device-cdma.c     |   79 +++++++++++++++------------
 src/applet-device-gsm.c      |   45 +++++++++-------
 src/applet.c                 |   13 ++++-
 src/applet.h                 |   11 ++++
 src/mb-menu-item.c           |   31 +----------
 src/mb-menu-item.h           |   24 +--------
 src/mobile-helpers.c         |  122 ++++++++++++++++++++++++++++++++++++++++++
 src/mobile-helpers.h         |   63 ++++++++++++++++++++++
 19 files changed, 292 insertions(+), 109 deletions(-)
---
diff --git a/icons/22/Makefile.am b/icons/22/Makefile.am
index a7f4df6..3dd7143 100644
--- a/icons/22/Makefile.am
+++ b/icons/22/Makefile.am
@@ -3,6 +3,7 @@ icon_DATA = \
 	nm-no-connection.png \
 	nm-device-wired.png \
 	nm-device-wwan.png \
+	nm-wwan-tower.png \
 	nm-adhoc.png \
 	nm-stage01-connecting01.png \
 	nm-stage01-connecting02.png \
@@ -57,7 +58,15 @@ icon_DATA = \
 	nm-vpn-connecting13.png \
 	nm-vpn-connecting14.png \
 	nm-vpn-active-lock.png \
-	nm-secure-lock.png
+	nm-secure-lock.png \
+	nm-tech-cdma-1x.png \
+	nm-tech-evdo.png \
+	nm-tech-gprs.png \
+	nm-tech-edge.png \
+	nm-tech-umts.png \
+	nm-tech-hspa.png \
+	nm-mb-roam.png \
+	nm-tech-3g.png
 
 EXTRA_DIST = $(icon_DATA)
 
diff --git a/icons/22/nm-mb-roam.png b/icons/22/nm-mb-roam.png
new file mode 100644
index 0000000..9d96555
Binary files /dev/null and b/icons/22/nm-mb-roam.png differ
diff --git a/icons/22/nm-tech-3g.png b/icons/22/nm-tech-3g.png
new file mode 100644
index 0000000..b998256
Binary files /dev/null and b/icons/22/nm-tech-3g.png differ
diff --git a/icons/22/nm-tech-cdma-1x.png b/icons/22/nm-tech-cdma-1x.png
new file mode 100644
index 0000000..f70f77d
Binary files /dev/null and b/icons/22/nm-tech-cdma-1x.png differ
diff --git a/icons/22/nm-tech-edge.png b/icons/22/nm-tech-edge.png
new file mode 100644
index 0000000..f1055a0
Binary files /dev/null and b/icons/22/nm-tech-edge.png differ
diff --git a/icons/22/nm-tech-evdo.png b/icons/22/nm-tech-evdo.png
new file mode 100644
index 0000000..ec556ec
Binary files /dev/null and b/icons/22/nm-tech-evdo.png differ
diff --git a/icons/22/nm-tech-gprs.png b/icons/22/nm-tech-gprs.png
new file mode 100644
index 0000000..b7dbac0
Binary files /dev/null and b/icons/22/nm-tech-gprs.png differ
diff --git a/icons/22/nm-tech-hspa.png b/icons/22/nm-tech-hspa.png
new file mode 100644
index 0000000..056a982
Binary files /dev/null and b/icons/22/nm-tech-hspa.png differ
diff --git a/icons/22/nm-tech-umts.png b/icons/22/nm-tech-umts.png
new file mode 100644
index 0000000..7bea37f
Binary files /dev/null and b/icons/22/nm-tech-umts.png differ
diff --git a/icons/22/nm-wwan-tower.png b/icons/22/nm-wwan-tower.png
new file mode 100644
index 0000000..5e974bf
Binary files /dev/null and b/icons/22/nm-wwan-tower.png differ
diff --git a/src/Makefile.am b/src/Makefile.am
index 48fdb0a..2082296 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,6 +47,8 @@ nm_applet_SOURCES =			\
 	applet-device-gsm.c \
 	applet-device-cdma.h \
 	applet-device-cdma.c \
+	mobile-helpers.c \
+	mobile-helpers.h \
 	applet-device-bt.h \
 	applet-device-bt.c
 
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index faabc00..6f4da1e 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2009 Red Hat, Inc.
+ * (C) Copyright 2008 - 2010 Red Hat, Inc.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -199,6 +199,8 @@ add_connection_item (NMDevice *device,
 }
 
 typedef struct {
+	NMApplet *applet;
+
 	DBusGProxy *props_proxy;
 	DBusGProxy *cdma_proxy;
 	gboolean quality_valid;
@@ -216,26 +218,30 @@ typedef struct {
 } CdmaDeviceInfo;
 
 static guint32
-state_for_info (CdmaDeviceInfo *info, guint32 *out_tech)
+cdma_state_to_mb_state (CdmaDeviceInfo *info)
 {
-	guint32 state = MB_STATE_UNKNOWN;
-
+	/* EVDO state overrides 1X state for now */
 	if (info->evdo_state) {
-		*out_tech = MB_TECH_EVDO_REVA;
-		if (info->evdo_state == 1 || info->evdo_state == 2)
-			state = MB_STATE_HOME;
-		else if (info->evdo_state == 3)
-			state = MB_STATE_ROAMING;
+		if (info->evdo_state == 3)
+			return MB_STATE_ROAMING;
+		return MB_STATE_HOME;
 	} else if (info->cdma1x_state) {
-		*out_tech = MB_TECH_1XRTT;
-		if (info->cdma1x_state == 1 || info->cdma1x_state == 2)
-			state = MB_STATE_HOME;
-		else if (info->cdma1x_state == 3)
-			state = MB_STATE_ROAMING;
-	} else {
-		*out_tech = MB_TECH_1XRTT;
+		if (info->cdma1x_state == 3)
+			return MB_STATE_ROAMING;
+		return MB_STATE_HOME;
 	}
-	return state;
+
+	return MB_STATE_UNKNOWN;
+}
+
+static guint32
+cdma_act_to_mb_act (CdmaDeviceInfo *info)
+{
+	if (info->evdo_state)
+		return MB_TECH_EVDO_REVA; /* Always rA until we get CDMA AcT from MM */
+	else if (info->cdma1x_state)
+		return MB_TECH_1XRTT;
+	return MB_TECH_UNKNOWN;
 }
 
 static void
@@ -278,19 +284,15 @@ cdma_add_menu_item (NMDevice *device,
 	/* Add the active connection */
 	if (active) {
 		NMSettingConnection *s_con;
-		guint32 tech = MB_TECH_1XRTT;
-		guint32 mb_state;
 
 		s_con = (NMSettingConnection *) nm_connection_get_setting (active, NM_TYPE_SETTING_CONNECTION);
 		g_assert (s_con);
 
-		mb_state = state_for_info (info, &tech);
-
 		item = nm_mb_menu_item_new (nm_setting_connection_get_id (s_con),
 		                            info->quality_valid ? info->quality : 0,
 		                            info->provider_name,
-		                            tech,
-		                            mb_state,
+		                            cdma_act_to_mb_act (info),
+		                            cdma_state_to_mb_state (info),
 		                            applet);
 
 		add_connection_item (device, active, item, menu, applet);
@@ -304,15 +306,11 @@ cdma_add_menu_item (NMDevice *device,
 			gtk_widget_show (item);
 		}
 	} else {
-		guint32 tech = MB_TECH_1XRTT;
-		guint32 mb_state;
-
-		mb_state = state_for_info (info, &tech);
 		item = nm_mb_menu_item_new (NULL,
 		                            info->quality_valid ? info->quality : 0,
 		                            info->provider_name,
-		                            tech,
-		                            mb_state,
+		                            cdma_act_to_mb_act (info),
+		                            cdma_state_to_mb_state (info),
 		                            applet);
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	}
@@ -390,6 +388,7 @@ cdma_get_icon (NMDevice *device,
 	GdkPixbuf *pixbuf = NULL;
 	const char *id;
 	CdmaDeviceInfo *info;
+	gboolean mb_state;
 
 	info = g_object_get_data (G_OBJECT (device), "devinfo");
 	g_assert (info);
@@ -414,14 +413,15 @@ cdma_get_icon (NMDevice *device,
 		*tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_ACTIVATED:
-		pixbuf = nma_icon_check_and_load ("nm-device-wwan", &applet->wwan_icon, applet);
-		if ((info->cdma1x_state || info->evdo_state) && info->quality_valid) {
-			gboolean roaming = FALSE;
+		mb_state = cdma_state_to_mb_state (info);
+		pixbuf = mobile_helper_get_status_pixbuf (info->quality,
+		                                          info->quality_valid,
+		                                          mb_state,
+		                                          cdma_act_to_mb_act (info),
+		                                          applet);
 
-			if (info->evdo_state == 3)
-				roaming = TRUE;
-			else if (info->cdma1x_state == 3)
-				roaming = TRUE;
+		if ((mb_state != MB_STATE_UNKNOWN) && info->quality_valid) {
+			gboolean roaming = (mb_state == MB_STATE_ROAMING);
 
 			*tip = g_strdup_printf (_("Mobile broadband connection '%s' active: (%d%%%s%s)"),
 			                        id, info->quality,
@@ -642,6 +642,7 @@ reg_state_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
 	                           G_TYPE_INVALID)) {
 		info->cdma1x_state = cdma1x_state;
 		info->evdo_state = evdo_state;
+		applet_schedule_update_icon (info->applet);
 	}
 
 	g_clear_error (&error);
@@ -659,6 +660,7 @@ signal_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
 	                           G_TYPE_INVALID)) {
 		info->quality = quality;
 		info->quality_valid = TRUE;
+		applet_schedule_update_icon (info->applet);
 	}
 
 	g_clear_error (&error);
@@ -775,6 +777,8 @@ reg_state_changed_cb (DBusGProxy *proxy,
 
 	info->cdma1x_state = cdma1x_state;
 	info->evdo_state = evdo_state;
+
+	applet_schedule_update_icon (info->applet);
 }
 
 static void
@@ -786,6 +790,8 @@ signal_quality_changed_cb (DBusGProxy *proxy,
 
 	info->quality = quality;
 	info->quality_valid = TRUE;
+
+	applet_schedule_update_icon (info->applet);
 }
 
 static void
@@ -803,6 +809,7 @@ cdma_device_added (NMDevice *device, NMApplet *applet)
 		return;
 
 	info = g_malloc0 (sizeof (CdmaDeviceInfo));
+	info->applet = applet;
 	info->quality_valid = FALSE;
 
 	info->providers = nmn_mobile_providers_parse (NULL);
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index 9644876..f53f4ad 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2009 Red Hat, Inc.
+ * (C) Copyright 2008 - 2010 Red Hat, Inc.
  * (C) Copyright 2008 Novell, Inc.
  */
 
@@ -61,6 +61,7 @@ typedef enum {
 } MMModemGsmAccessTech;
 
 typedef struct {
+	NMApplet *applet;
 	NMDevice *device;
 
 	DBusGProxy *props_proxy;
@@ -248,7 +249,7 @@ add_connection_item (NMDevice *device,
 }
 
 static guint32
-state_for_info (GsmDeviceInfo *info)
+gsm_state_to_mb_state (GsmDeviceInfo *info)
 {
 	switch (info->reg_state) {
 	case 1:  /* IDLE */
@@ -270,7 +271,7 @@ state_for_info (GsmDeviceInfo *info)
 }
 
 static guint32
-tech_for_info (GsmDeviceInfo *info)
+gsm_act_to_mb_act (GsmDeviceInfo *info)
 {
 	switch (info->act) {
 	case MM_MODEM_GSM_ACCESS_TECH_GPRS:
@@ -332,18 +333,15 @@ gsm_add_menu_item (NMDevice *device,
 	/* Add the active connection */
 	if (active) {
 		NMSettingConnection *s_con;
-		guint32 mb_state, mb_tech;
 
 		s_con = (NMSettingConnection *) nm_connection_get_setting (active, NM_TYPE_SETTING_CONNECTION);
 		g_assert (s_con);
 
-		mb_state = state_for_info (info);
-		mb_tech = tech_for_info (info);
 		item = nm_mb_menu_item_new (nm_setting_connection_get_id (s_con),
 		                            info->quality_valid ? info->quality : 0,
 		                            info->op_name,
-		                            mb_tech,
-		                            mb_state,
+		                            gsm_act_to_mb_act (info),
+		                            gsm_state_to_mb_state (info),
 		                            applet);
 
 		add_connection_item (device, active, item, menu, applet);
@@ -357,15 +355,11 @@ gsm_add_menu_item (NMDevice *device,
 			gtk_widget_show (item);
 		}
 	} else {
-		guint32 mb_state, mb_tech;
-
-		mb_state = state_for_info (info);
-		mb_tech = tech_for_info (info);
 		item = nm_mb_menu_item_new (NULL,
 		                            info->quality_valid ? info->quality : 0,
 		                            info->op_name,
-		                            mb_tech,
-		                            mb_state,
+		                            gsm_act_to_mb_act (info),
+		                            gsm_state_to_mb_state (info),
 		                            applet);
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	}
@@ -442,6 +436,7 @@ gsm_get_icon (NMDevice *device,
 	GdkPixbuf *pixbuf = NULL;
 	const char *id;
 	GsmDeviceInfo *info;
+	guint32 mb_state;
 
 	info = g_object_get_data (G_OBJECT (device), "devinfo");
 	g_assert (info);
@@ -466,9 +461,15 @@ gsm_get_icon (NMDevice *device,
 		*tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_ACTIVATED:
-		pixbuf = nma_icon_check_and_load ("nm-device-wwan", &applet->wwan_icon, applet);
-		if (info->reg_state && info->quality_valid) {
-			gboolean roaming = (info->reg_state == 6);
+		mb_state = gsm_state_to_mb_state (info);
+		pixbuf = mobile_helper_get_status_pixbuf (info->quality,
+		                                          info->quality_valid,
+		                                          mb_state,
+		                                          gsm_act_to_mb_act (info),
+		                                          applet);
+
+		if ((mb_state != MB_STATE_UNKNOWN) && info->quality_valid) {
+			gboolean roaming = (mb_state == MB_STATE_ROAMING);
 
 			*tip = g_strdup_printf (_("Mobile broadband connection '%s' active: (%d%%%s%s)"),
 			                        id, info->quality,
@@ -1042,6 +1043,7 @@ signal_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
 	                           G_TYPE_INVALID)) {
 		info->quality = quality;
 		info->quality_valid = TRUE;
+		applet_schedule_update_icon (info->applet);
 	}
 
 	g_clear_error (&error);
@@ -1263,8 +1265,10 @@ access_tech_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
 	if (dbus_g_proxy_end_call (proxy, call, &error,
 	                           G_TYPE_VALUE, &value,
 	                           G_TYPE_INVALID)) {
-		if (G_VALUE_HOLDS_UINT (&value))
+		if (G_VALUE_HOLDS_UINT (&value)) {
 			info->act = g_value_get_uint (&value);
+			applet_schedule_update_icon (info->applet);
+		}
 		g_value_unset (&value);
 	}
 	g_clear_error (&error);
@@ -1363,6 +1367,8 @@ signal_quality_changed_cb (DBusGProxy *proxy,
 	info->quality = quality;
 	info->quality_valid = TRUE;
 	info->skip_signal_poll = TRUE;
+
+	applet_schedule_update_icon (info->applet);
 }
 
 #define MM_DBUS_INTERFACE_MODEM "org.freedesktop.ModemManager.Modem"
@@ -1394,7 +1400,7 @@ modem_properties_changed (DBusGProxy *proxy,
 		value = g_hash_table_lookup (props, "AccessTechnology");
 		if (value && G_VALUE_HOLDS_UINT (value)) {
 			info->act = g_value_get_uint (value);
-			/* FIXME: update main icon if needed */
+			applet_schedule_update_icon (info->applet);
 		}
 	}
 }
@@ -1413,6 +1419,7 @@ gsm_device_added (NMDevice *device, NMApplet *applet)
 		return;
 
 	info = g_malloc0 (sizeof (GsmDeviceInfo));
+	info->applet = applet;
 	info->device = device;
 
 	info->props_proxy = dbus_g_proxy_new_for_name (bus,
diff --git a/src/applet.c b/src/applet.c
index 16a8153..a1b6e24 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -15,7 +15,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * Copyright (C) 2004 - 2008 Red Hat, Inc.
+ * Copyright (C) 2004 - 2010 Red Hat, Inc.
  * Copyright (C) 2005 - 2008 Novell, Inc.
  *
  * This applet used the GNOME Wireless Applet as a skeleton to build from.
@@ -2673,6 +2673,7 @@ static void nma_icons_free (NMApplet *applet)
 	nma_clear_icon (&applet->wired_icon, applet);
 	nma_clear_icon (&applet->adhoc_icon, applet);
 	nma_clear_icon (&applet->wwan_icon, applet);
+	nma_clear_icon (&applet->wwan_tower_icon, applet);
 	nma_clear_icon (&applet->vpn_lock_icon, applet);
 	nma_clear_icon (&applet->wireless_00_icon, applet);
 	nma_clear_icon (&applet->wireless_25_icon, applet);
@@ -2681,6 +2682,15 @@ static void nma_icons_free (NMApplet *applet)
 	nma_clear_icon (&applet->wireless_100_icon, applet);
 	nma_clear_icon (&applet->secure_lock_icon, applet);
 
+	nma_clear_icon (&applet->mb_tech_1x_icon, applet);
+	nma_clear_icon (&applet->mb_tech_evdo_icon, applet);
+	nma_clear_icon (&applet->mb_tech_gprs_icon, applet);
+	nma_clear_icon (&applet->mb_tech_edge_icon, applet);
+	nma_clear_icon (&applet->mb_tech_umts_icon, applet);
+	nma_clear_icon (&applet->mb_tech_hspa_icon, applet);
+	nma_clear_icon (&applet->mb_roaming_icon, applet);
+	nma_clear_icon (&applet->mb_tech_3g_icon, applet);
+
 	for (i = 0; i < NUM_CONNECTING_STAGES; i++) {
 		for (j = 0; j < NUM_CONNECTING_FRAMES; j++)
 			nma_clear_icon (&applet->network_connecting_icons[i][j], applet);
@@ -2733,7 +2743,6 @@ nma_icons_reload (NMApplet *applet)
 
 	nma_icons_free (applet);
 
-
 	applet->fallback_icon = gtk_icon_theme_load_icon (applet->icon_theme,
 	                                                  FALLBACK_ICON_NAME,
 	                                                  applet->icon_size, 0,
diff --git a/src/applet.h b/src/applet.h
index 6cf1fe7..82f494b 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -122,6 +122,17 @@ typedef struct
 	GdkPixbuf *		vpn_lock_icon;
 	GdkPixbuf *		fallback_icon;
 
+	/* Mobiel Broadband icons */
+	GdkPixbuf *		wwan_tower_icon;
+	GdkPixbuf *		mb_tech_1x_icon;
+	GdkPixbuf *		mb_tech_evdo_icon;
+	GdkPixbuf *		mb_tech_gprs_icon;
+	GdkPixbuf *		mb_tech_edge_icon;
+	GdkPixbuf *		mb_tech_umts_icon;
+	GdkPixbuf *		mb_tech_hspa_icon;
+	GdkPixbuf *		mb_roaming_icon;
+	GdkPixbuf *		mb_tech_3g_icon;
+
 	/* Active status icon pixbufs */
 	GdkPixbuf *		icon_layers[ICON_LAYER_MAX + 1];
 
diff --git a/src/mb-menu-item.c b/src/mb-menu-item.c
index 00463d7..e2bea5f 100644
--- a/src/mb-menu-item.c
+++ b/src/mb-menu-item.c
@@ -96,7 +96,6 @@ nm_mb_menu_item_new (const char *connection_name,
 	NMMbMenuItem *item;
 	NMMbMenuItemPrivate *priv;
 	const char *tech_name;
-	GdkPixbuf *icon = NULL, *pixbuf;
 
 	g_return_val_if_fail (technology != MB_TECH_UNKNOWN, NULL);
 
@@ -166,34 +165,10 @@ nm_mb_menu_item_new (const char *connection_name,
 		gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
 	}
 
-	/* And the strength icon, if applicable */
+	/* And the strength icon, if we have strength information at all */
 	if (strength) {
-		if (strength > 80)
-			icon = nma_icon_check_and_load ("nm-signal-100", &applet->wireless_100_icon, applet);
-		else if (strength > 55)
-			icon = nma_icon_check_and_load ("nm-signal-75", &applet->wireless_75_icon, applet);
-		else if (strength > 30)
-			icon = nma_icon_check_and_load ("nm-signal-50", &applet->wireless_50_icon, applet);
-		else if (strength > 5)
-			icon = nma_icon_check_and_load ("nm-signal-25", &applet->wireless_25_icon, applet);
-		else
-			icon = nma_icon_check_and_load ("nm-signal-00", &applet->wireless_00_icon, applet);
-
-		pixbuf = gdk_pixbuf_copy (icon);
-
-#if 0
-		/* Composite technology icon here */
-		if (item->is_encrypted) {
-			top = nma_icon_check_and_load ("nm-secure-lock", &applet->secure_lock_icon, applet);
-			gdk_pixbuf_composite (top, pixbuf, 0, 0, gdk_pixbuf_get_width (top),
-								  gdk_pixbuf_get_height (top),
-								  0, 0, 1.0, 1.0,
-								  GDK_INTERP_NEAREST, 255);
-		}
-#endif
-
-		gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), pixbuf);
-		g_object_unref (pixbuf);
+		gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength),
+		                           mobile_helper_get_quality_icon (strength, applet));
 	}
 
 	return GTK_WIDGET (item);
diff --git a/src/mb-menu-item.h b/src/mb-menu-item.h
index e320954..e479f5e 100644
--- a/src/mb-menu-item.h
+++ b/src/mb-menu-item.h
@@ -26,6 +26,7 @@
 
 #include <gtk/gtk.h>
 #include "applet.h"
+#include "mobile-helpers.h"
 
 #define NM_TYPE_MB_MENU_ITEM            (nm_mb_menu_item_get_type ())
 #define NM_MB_MENU_ITEM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MB_MENU_ITEM, NMMbMenuItem))
@@ -34,29 +35,6 @@
 #define NM_IS_MB_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MB_MENU_ITEM))
 #define NM_MB_MENU_ITEM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MB_MENU_ITEM, NMMbMenuItemClass))
 
-enum {
-	MB_STATE_UNKNOWN = 0,
-	MB_STATE_IDLE,
-	MB_STATE_HOME,
-	MB_STATE_SEARCHING,
-	MB_STATE_DENIED,
-	MB_STATE_ROAMING
-};
-
-enum {
-	MB_TECH_UNKNOWN = 0,
-	MB_TECH_1XRTT,
-	MB_TECH_EVDO_REV0,
-	MB_TECH_EVDO_REVA,
-	MB_TECH_GSM,
-	MB_TECH_GPRS,
-	MB_TECH_EDGE,
-	MB_TECH_UMTS,
-	MB_TECH_HSDPA,
-	MB_TECH_HSUPA,
-	MB_TECH_HSPA,
-};
-
 typedef struct {
 	GtkImageMenuItem image_item;
 } NMMbMenuItem;
diff --git a/src/mobile-helpers.c b/src/mobile-helpers.c
new file mode 100644
index 0000000..5901c48
--- /dev/null
+++ b/src/mobile-helpers.c
@@ -0,0 +1,122 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2010 Red Hat, Inc.
+ */
+
+#include "mobile-helpers.h"
+
+GdkPixbuf *
+mobile_helper_get_status_pixbuf (guint32 quality,
+                                 gboolean quality_valid,
+                                 guint32 state,
+                                 guint32 access_tech,
+                                 NMApplet *applet)
+{
+	GdkPixbuf *pixbuf, *qual_pixbuf, *wwan_pixbuf, *tmp;
+
+	wwan_pixbuf = nma_icon_check_and_load ("nm-wwan-tower", &applet->wwan_tower_icon, applet);
+
+	if (!quality_valid)
+		quality = 0;
+	qual_pixbuf = mobile_helper_get_quality_icon (quality, applet);
+
+	pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+	                         TRUE,
+	                         gdk_pixbuf_get_bits_per_sample (qual_pixbuf),
+	                         gdk_pixbuf_get_width (qual_pixbuf),
+	                         gdk_pixbuf_get_height (qual_pixbuf));
+	gdk_pixbuf_fill (pixbuf, 0xFFFFFF00);
+
+	/* Composite the tower icon into the final icon at the bottom layer */
+	gdk_pixbuf_composite (wwan_pixbuf, pixbuf,
+	                      0, 0,
+	                      gdk_pixbuf_get_width (wwan_pixbuf),
+						  gdk_pixbuf_get_height (wwan_pixbuf),
+						  0, 0, 1.0, 1.0,
+						  GDK_INTERP_BILINEAR, 255);
+
+	/* Composite the signal quality onto the icon on top of the WWAN tower */
+	gdk_pixbuf_composite (qual_pixbuf, pixbuf,
+	                      0, 0,
+	                      gdk_pixbuf_get_width (qual_pixbuf),
+						  gdk_pixbuf_get_height (qual_pixbuf),
+						  0, 0, 1.0, 1.0,
+						  GDK_INTERP_BILINEAR, 255);
+
+	/* And finally the roaming or technology icon */
+	if (state == MB_STATE_ROAMING) {
+		tmp = nma_icon_check_and_load ("nm-mb-roam", &applet->mb_roaming_icon, applet);
+		gdk_pixbuf_composite (tmp, pixbuf, 0, 0,
+		                      gdk_pixbuf_get_width (tmp),
+							  gdk_pixbuf_get_height (tmp),
+							  0, 0, 1.0, 1.0,
+							  GDK_INTERP_BILINEAR, 255);
+	} else {
+		tmp = mobile_helper_get_tech_icon (access_tech, applet);
+		gdk_pixbuf_composite (tmp, pixbuf, 0, 0,
+		                      gdk_pixbuf_get_width (tmp),
+							  gdk_pixbuf_get_height (tmp),
+							  0, 0, 1.0, 1.0,
+							  GDK_INTERP_BILINEAR, 255);
+	}
+
+	return pixbuf;
+}
+
+GdkPixbuf *
+mobile_helper_get_quality_icon (guint32 quality, NMApplet *applet)
+{
+	if (quality > 80)
+		return nma_icon_check_and_load ("nm-signal-100", &applet->wireless_100_icon, applet);
+	else if (quality > 55)
+		return nma_icon_check_and_load ("nm-signal-75", &applet->wireless_75_icon, applet);
+	else if (quality > 30)
+		return nma_icon_check_and_load ("nm-signal-50", &applet->wireless_50_icon, applet);
+	else if (quality > 5)
+		return nma_icon_check_and_load ("nm-signal-25", &applet->wireless_25_icon, applet);
+
+	return nma_icon_check_and_load ("nm-signal-00", &applet->wireless_00_icon, applet);
+}
+
+GdkPixbuf *
+mobile_helper_get_tech_icon (guint32 tech, NMApplet *applet)
+{
+	switch (tech) {
+	case MB_TECH_1XRTT:
+		return nma_icon_check_and_load ("nm-tech-cdma-1x", &applet->mb_tech_1x_icon, applet);
+	case MB_TECH_EVDO_REV0:
+	case MB_TECH_EVDO_REVA:
+		return nma_icon_check_and_load ("nm-tech-evdo", &applet->mb_tech_evdo_icon, applet);
+	case MB_TECH_GSM:
+	case MB_TECH_GPRS:
+		return nma_icon_check_and_load ("nm-tech-gprs", &applet->mb_tech_gprs_icon, applet);
+	case MB_TECH_EDGE:
+		return nma_icon_check_and_load ("nm-tech-edge", &applet->mb_tech_edge_icon, applet);
+	case MB_TECH_UMTS:
+		return nma_icon_check_and_load ("nm-tech-umts", &applet->mb_tech_umts_icon, applet);
+	case MB_TECH_HSDPA:
+	case MB_TECH_HSUPA:
+	case MB_TECH_HSPA:
+		return nma_icon_check_and_load ("nm-tech-hspa", &applet->mb_tech_hspa_icon, applet);
+	default:
+		return NULL;
+	}
+}
+
diff --git a/src/mobile-helpers.h b/src/mobile-helpers.h
new file mode 100644
index 0000000..fc21328
--- /dev/null
+++ b/src/mobile-helpers.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2010 Red Hat, Inc.
+ */
+
+#ifndef APPLET_MOBILE_HELPERS_H
+#define APPLET_MOBILE_HELPERS_H
+
+#include <gtk/gtk.h>
+#include "applet.h"
+
+enum {
+	MB_STATE_UNKNOWN = 0,
+	MB_STATE_IDLE,
+	MB_STATE_HOME,
+	MB_STATE_SEARCHING,
+	MB_STATE_DENIED,
+	MB_STATE_ROAMING
+};
+
+enum {
+	MB_TECH_UNKNOWN = 0,
+	MB_TECH_1XRTT,
+	MB_TECH_EVDO_REV0,
+	MB_TECH_EVDO_REVA,
+	MB_TECH_GSM,
+	MB_TECH_GPRS,
+	MB_TECH_EDGE,
+	MB_TECH_UMTS,
+	MB_TECH_HSDPA,
+	MB_TECH_HSUPA,
+	MB_TECH_HSPA,
+};
+
+GdkPixbuf *mobile_helper_get_status_pixbuf (guint32 quality,
+                                            gboolean quality_valid,
+                                            guint32 state,
+                                            guint32 access_tech,
+                                            NMApplet *applet);
+
+GdkPixbuf *mobile_helper_get_quality_icon (guint32 quality, NMApplet *applet);
+
+GdkPixbuf *mobile_helper_get_tech_icon (guint32 tech, NMApplet *applet);
+
+#endif  /* APPLET_MOBILE_HELPERS_H */
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]