[network-manager-applet/aleksander/mm1-applet: 13/13] fixup! applet: new support for the 'ModemManager1' interface



commit 018af7aae420e2dad89c5680765f8c7265ab1766
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Wed Dec 19 11:01:44 2012 +0100

    fixup! applet: new support for the 'ModemManager1' interface
    
    3GPP and CDMA interfaces only available once unlocked.

 src/applet-device-broadband.c |  165 +++++++++++++++++++++++++++-------------
 1 files changed, 111 insertions(+), 54 deletions(-)
---
diff --git a/src/applet-device-broadband.c b/src/applet-device-broadband.c
index 7732d81..34c59db 100644
--- a/src/applet-device-broadband.c
+++ b/src/applet-device-broadband.c
@@ -51,6 +51,9 @@ typedef struct {
 
 	/* Operator info */
 	gchar *operator_name;
+	guint operator_name_update_id;
+	guint operator_code_update_id;
+	guint sid_update_id;
 	NMAMobileProvidersDatabase *mpd;
 
 	/* Unlock dialog stuff */
@@ -819,38 +822,6 @@ device_state_changed (NMDevice *device,
 /********************************************************************/
 
 static void
-modem_state_changed (MMModem             *object,
-                     gint                 old,
-                     gint                 new,
-                     guint                reason,
-                     BroadbandDeviceInfo *info)
-{
-	/* Modem just got registered */
-	if ((old < MM_MODEM_STATE_REGISTERED &&
-	     new >= MM_MODEM_STATE_REGISTERED)) {
-		guint32 mb_state;
-
-		/* Notify about new registration info */
-		mb_state = broadband_state_to_mb_state (info);
-		if (mb_state == MB_STATE_HOME) {
-			applet_do_notify_with_pref (info->applet,
-			                            _("Mobile Broadband network."),
-			                            _("You are now registered on the home network."),
-			                            "nm-signal-100",
-			                            PREF_DISABLE_CONNECTED_NOTIFICATIONS);
-		} else if (mb_state == MB_STATE_ROAMING) {
-			applet_do_notify_with_pref (info->applet,
-			                            _("Mobile Broadband network."),
-			                            _("You are now registered on a roaming network."),
-			                            "nm-signal-100",
-			                            PREF_DISABLE_CONNECTED_NOTIFICATIONS);
-		}
-	}
-}
-
-/********************************************************************/
-
-static void
 signal_quality_updated (GObject *object,
                         GParamSpec *pspec,
                         BroadbandDeviceInfo *info)
@@ -891,21 +862,120 @@ operator_info_updated (GObject *object,
 			                       mm_modem_cdma_get_sid (info->mm_modem_cdma)));
 }
 
+static void
+setup_signals (BroadbandDeviceInfo *info,
+               gboolean enable)
+{
+	if (enable) {
+		g_assert (info->mm_modem_3gpp == NULL);
+		g_assert (info->mm_modem_cdma == NULL);
+		g_assert (info->operator_name_update_id == 0);
+		g_assert (info->operator_code_update_id == 0);
+		g_assert (info->sid_update_id == 0);
+
+		info->mm_modem_3gpp = mm_object_get_modem_3gpp (info->mm_object);
+		info->mm_modem_cdma = mm_object_get_modem_cdma (info->mm_object);
+
+		if (info->mm_modem_3gpp) {
+			info->operator_name_update_id = g_signal_connect (info->mm_modem_3gpp,
+			                                                  "notify::operator-name",
+			                                                  G_CALLBACK (operator_info_updated),
+			                                                  info);
+			info->operator_code_update_id = g_signal_connect (info->mm_modem_3gpp,
+			                                                  "notify::operator-code",
+			                                                  G_CALLBACK (operator_info_updated),
+			                                                  info);
+		}
+
+		if (info->mm_modem_cdma) {
+			info->sid_update_id = g_signal_connect (info->mm_modem_cdma,
+			                                        "notify::sid",
+			                                        G_CALLBACK (operator_info_updated),
+			                                        info);
+		}
+
+		/* Load initial values */
+		operator_info_updated (NULL, NULL, info);
+	} else {
+		if (info->mm_modem_3gpp) {
+			if (info->operator_name_update_id) {
+				if (g_signal_handler_is_connected (info->mm_modem_3gpp, info->operator_name_update_id))
+					g_signal_handler_disconnect (info->mm_modem_3gpp, info->operator_name_update_id);
+				info->operator_name_update_id = 0;
+			}
+			if (info->operator_code_update_id) {
+				if (g_signal_handler_is_connected (info->mm_modem_3gpp, info->operator_code_update_id))
+					g_signal_handler_disconnect (info->mm_modem_3gpp, info->operator_code_update_id);
+				info->operator_code_update_id = 0;
+			}
+			g_clear_object (&info->mm_modem_3gpp);
+		}
+
+		if (info->mm_modem_cdma) {
+			if (info->sid_update_id) {
+				if (g_signal_handler_is_connected (info->mm_modem_cdma, info->sid_update_id))
+					g_signal_handler_disconnect (info->mm_modem_cdma, info->sid_update_id);
+				info->sid_update_id = 0;
+			}
+			g_clear_object (&info->mm_modem_cdma);
+		}
+	}
+}
+
+static void
+modem_state_changed (MMModem             *object,
+                     gint                 old,
+                     gint                 new,
+                     guint                reason,
+                     BroadbandDeviceInfo *info)
+{
+	/* Modem just got enabled */
+	if (old < MM_MODEM_STATE_ENABLED &&
+	    new >= MM_MODEM_STATE_ENABLED) {
+		setup_signals (info, TRUE);
+	}
+	/* Modem just got disabled */
+	else if (old >= MM_MODEM_STATE_ENABLED &&
+	    new < MM_MODEM_STATE_ENABLED) {
+		setup_signals (info, FALSE);
+	}
+
+	/* Modem just got registered */
+	if ((old < MM_MODEM_STATE_REGISTERED &&
+	     new >= MM_MODEM_STATE_REGISTERED)) {
+		guint32 mb_state;
+
+		/* Notify about new registration info */
+		mb_state = broadband_state_to_mb_state (info);
+		if (mb_state == MB_STATE_HOME) {
+			applet_do_notify_with_pref (info->applet,
+			                            _("Mobile Broadband network."),
+			                            _("You are now registered on the home network."),
+			                            "nm-signal-100",
+			                            PREF_DISABLE_CONNECTED_NOTIFICATIONS);
+		} else if (mb_state == MB_STATE_ROAMING) {
+			applet_do_notify_with_pref (info->applet,
+			                            _("Mobile Broadband network."),
+			                            _("You are now registered on a roaming network."),
+			                            "nm-signal-100",
+			                            PREF_DISABLE_CONNECTED_NOTIFICATIONS);
+		}
+	}
+}
+
 /********************************************************************/
 
 static void
 broadband_device_info_free (BroadbandDeviceInfo *info)
 {
+	setup_signals (info, FALSE);
+
 	g_free (info->operator_name);
 	if (info->mpd)
 		g_object_unref (info->mpd);
 
 	if (info->mm_sim)
 		g_object_unref (info->mm_sim);
-	if (info->mm_modem_3gpp)
-		g_object_unref (info->mm_modem_3gpp);
-	if (info->mm_modem_cdma)
-		g_object_unref (info->mm_modem_cdma);
 	if (info->mm_modem)
 		g_object_unref (info->mm_modem);
 	if (info->mm_object)
@@ -951,8 +1021,6 @@ device_added (NMDevice *device,
 	info->device = device;
 	info->mm_object = MM_OBJECT (modem_object);
 	info->mm_modem = mm_object_get_modem (info->mm_object);
-	info->mm_modem_3gpp = mm_object_get_modem_3gpp (info->mm_object);
-	info->mm_modem_cdma = mm_object_get_modem_cdma (info->mm_object);
 
 	/* Setup signals */
 
@@ -969,22 +1037,11 @@ device_added (NMDevice *device,
 	                  G_CALLBACK (access_technologies_updated),
 	                  info);
 
-	if (info->mm_modem_3gpp) {
-		g_signal_connect (info->mm_modem_3gpp,
-		                  "notify::operator-name",
-		                  G_CALLBACK (operator_info_updated),
-		                  info);
-		g_signal_connect (info->mm_modem_3gpp,
-		                  "notify::operator-code",
-		                  G_CALLBACK (operator_info_updated),
-		                  info);
-	}
-
-	if (info->mm_modem_cdma)
-		g_signal_connect (info->mm_modem_cdma,
-		                  "notify::sid",
-		                  G_CALLBACK (operator_info_updated),
-		                  info);
+	/* Load initial values */
+	signal_quality_updated (NULL, NULL, info);
+	access_technologies_updated (NULL, NULL, info);
+	if (mm_modem_get_state (info->mm_modem) >= MM_MODEM_STATE_ENABLED)
+		setup_signals (info, TRUE);
 
 	/* Asynchronously get SIM */
 	mm_modem_get_sim (info->mm_modem,



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