[network-manager-applet/aleksander/mm1-applet: 5/10] applet: consolidate icon retrieval for 'gsm' and 'cdma' devices



commit e3f0176148326a09f87b9346d73cb39535de81d2
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Fri Dec 14 14:25:54 2012 +0100

    applet: consolidate icon retrieval for 'gsm' and 'cdma' devices
    
    Will also make it easier to handle the new 'broadband' devices.

 src/applet-device-cdma.c |   55 +++++++-----------------------------------
 src/applet-device-gsm.c  |   55 +++++++-----------------------------------
 src/mobile-helpers.c     |   60 ++++++++++++++++++++++++++++++++++++++++++++++
 src/mobile-helpers.h     |   12 +++++++++
 4 files changed, 90 insertions(+), 92 deletions(-)
---
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index 5519065..4dd35cf 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -365,57 +365,20 @@ cdma_get_icon (NMDevice *device,
                char **tip,
                NMApplet *applet)
 {
-	NMSettingConnection *s_con;
-	GdkPixbuf *pixbuf = NULL;
-	const char *id;
 	CdmaDeviceInfo *info;
-	gboolean mb_state;
 
 	info = g_object_get_data (G_OBJECT (device), "devinfo");
 	g_assert (info);
 
-	id = nm_device_get_iface (NM_DEVICE (device));
-	if (connection) {
-		s_con = nm_connection_get_setting_connection (connection);
-		id = nm_setting_connection_get_id (s_con);
-	}
-
-	switch (state) {
-	case NM_DEVICE_STATE_PREPARE:
-		*tip = g_strdup_printf (_("Preparing mobile broadband connection '%s'..."), id);
-		break;
-	case NM_DEVICE_STATE_CONFIG:
-		*tip = g_strdup_printf (_("Configuring mobile broadband connection '%s'..."), id);
-		break;
-	case NM_DEVICE_STATE_NEED_AUTH:
-		*tip = g_strdup_printf (_("User authentication required for mobile broadband connection '%s'..."), id);
-		break;
-	case NM_DEVICE_STATE_IP_CONFIG:
-		*tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
-		break;
-	case NM_DEVICE_STATE_ACTIVATED:
-		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 ((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,
-			                        roaming ? ", " : "",
-			                        roaming ? _("roaming") : "");
-		} else
-			*tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id);
-		break;
-	default:
-		break;
-	}
-
-	return pixbuf;
+	return mobile_helper_get_icon (device,
+	                               state,
+	                               connection,
+	                               tip,
+	                               applet,
+	                               cdma_state_to_mb_state (info),
+	                               cdma_act_to_mb_act (info),
+	                               info->quality,
+	                               info->quality_valid);
 }
 
 static gboolean
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index 593525d..22a8a68 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -419,57 +419,20 @@ gsm_get_icon (NMDevice *device,
               char **tip,
               NMApplet *applet)
 {
-	NMSettingConnection *s_con;
-	GdkPixbuf *pixbuf = NULL;
-	const char *id;
 	GsmDeviceInfo *info;
-	guint32 mb_state;
 
 	info = g_object_get_data (G_OBJECT (device), "devinfo");
 	g_assert (info);
 
-	id = nm_device_get_iface (NM_DEVICE (device));
-	if (connection) {
-		s_con = nm_connection_get_setting_connection (connection);
-		id = nm_setting_connection_get_id (s_con);
-	}
-
-	switch (state) {
-	case NM_DEVICE_STATE_PREPARE:
-		*tip = g_strdup_printf (_("Preparing mobile broadband connection '%s'..."), id);
-		break;
-	case NM_DEVICE_STATE_CONFIG:
-		*tip = g_strdup_printf (_("Configuring mobile broadband connection '%s'..."), id);
-		break;
-	case NM_DEVICE_STATE_NEED_AUTH:
-		*tip = g_strdup_printf (_("User authentication required for mobile broadband connection '%s'..."), id);
-		break;
-	case NM_DEVICE_STATE_IP_CONFIG:
-		*tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
-		break;
-	case NM_DEVICE_STATE_ACTIVATED:
-		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,
-			                        roaming ? ", " : "",
-			                        roaming ? _("roaming") : "");
-		} else
-			*tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id);
-		break;
-	default:
-		break;
-	}
-
-	return pixbuf;
+	return mobile_helper_get_icon (device,
+	                               state,
+	                               connection,
+	                               tip,
+	                               applet,
+	                               gsm_state_to_mb_state (info),
+	                               gsm_act_to_mb_act (info),
+	                               info->quality,
+	                               info->quality_valid);
 }
 
 static gboolean
diff --git a/src/mobile-helpers.c b/src/mobile-helpers.c
index d3a1273..b2c81e3 100644
--- a/src/mobile-helpers.c
+++ b/src/mobile-helpers.c
@@ -577,3 +577,63 @@ mobile_helper_get_secrets (NMDeviceModemCapabilities capabilities,
 
 	return TRUE;
 }
+
+/********************************************************************/
+
+GdkPixbuf *
+mobile_helper_get_icon (NMDevice *device,
+                        NMDeviceState state,
+                        NMConnection *connection,
+                        char **tip,
+                        NMApplet *applet,
+                        guint32 mb_state,
+                        guint32 mb_tech,
+                        guint32 quality,
+                        gboolean quality_valid)
+{
+	NMSettingConnection *s_con;
+	GdkPixbuf *pixbuf = NULL;
+	const char *id;
+
+	id = nm_device_get_iface (NM_DEVICE (device));
+	if (connection) {
+		s_con = nm_connection_get_setting_connection (connection);
+		id = nm_setting_connection_get_id (s_con);
+	}
+
+	switch (state) {
+	case NM_DEVICE_STATE_PREPARE:
+		*tip = g_strdup_printf (_("Preparing mobile broadband connection '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_CONFIG:
+		*tip = g_strdup_printf (_("Configuring mobile broadband connection '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_NEED_AUTH:
+		*tip = g_strdup_printf (_("User authentication required for mobile broadband connection '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_IP_CONFIG:
+		*tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_ACTIVATED:
+		pixbuf = mobile_helper_get_status_pixbuf (quality,
+		                                          quality_valid,
+		                                          mb_state,
+		                                          mb_tech,
+		                                          applet);
+
+		if ((mb_state != MB_STATE_UNKNOWN) && quality_valid) {
+			gboolean roaming = (mb_state == MB_STATE_ROAMING);
+
+			*tip = g_strdup_printf (_("Mobile broadband connection '%s' active: (%d%%%s%s)"),
+			                        id, quality,
+			                        roaming ? ", " : "",
+			                        roaming ? _("roaming") : "");
+		} else
+			*tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id);
+		break;
+	default:
+		break;
+	}
+
+	return pixbuf;
+}
diff --git a/src/mobile-helpers.h b/src/mobile-helpers.h
index 6eb66c7..1ffb7fa 100644
--- a/src/mobile-helpers.h
+++ b/src/mobile-helpers.h
@@ -90,4 +90,16 @@ gboolean mobile_helper_get_secrets (NMDeviceModemCapabilities capabilities,
                                     SecretsRequest *req,
                                     GError **error);
 
+/********************************************************************/
+
+GdkPixbuf *mobile_helper_get_icon (NMDevice *device,
+                                   NMDeviceState state,
+                                   NMConnection *connection,
+                                   char **tip,
+                                   NMApplet *applet,
+                                   guint32 mb_state,
+                                   guint32 mb_tech,
+                                   guint32 quality,
+                                   gboolean quality_valid);
+
 #endif  /* APPLET_MOBILE_HELPERS_H */



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