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



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

    applet: consolidate icon retrieval for 'gsm' and 'cdma' devices
    
    The new mobile_helper_get_icon() allows specifying all the items the icon is
    required to expose.

 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 c72a68f..263039e 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 45e2b4f..f951629 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -420,57 +420,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 4bfe980..80e70ca 100644
--- a/src/mobile-helpers.c
+++ b/src/mobile-helpers.c
@@ -576,3 +576,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 014226b..9626eec 100644
--- a/src/mobile-helpers.h
+++ b/src/mobile-helpers.h
@@ -89,4 +89,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]