[nm-applet][PATCH 1/2] add GSM registration status notification



The current UI requires the user to mouse-over and reveal a tool
tip (or click an indicator) to discover the registration state
(aka polling). If the user inadvertently re-registers on a
roaming network, the operation is silent until the user decides
to check the applet for network status, possibly incurring
expensive roaming tariffs in the mean time.

So, alert the user with a notification when the GSM registration
status changes, either from home to roaming or vice versa, to
prevent silent registration changes.

Refactor internal function gsm_state_to_mb_state so it calls
helper function reg_state_to_mb_state, which simply takes a
guint32 instead of a GsmDeviceInfo *. The new helper function can
be re-used to convert the registration state to an internal
mb_state in reg_info_changed_cb(), as a simple "add +1 to
registration state" is insufficient in the case where we are
roaming.

---
 applet-device-gsm.c |   33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index 5d0d584..fb4f090 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -313,12 +313,9 @@ add_connection_item (NMDevice *device,
 }
 
 static guint32
-gsm_state_to_mb_state (GsmDeviceInfo *info)
+reg_state_to_mb_state (guint32 reg_state)
 {
-	if (!info->modem_enabled)
-		return MB_STATE_UNKNOWN;
-
-	switch (info->reg_state) {
+	switch (reg_state) {
 	case 1:  /* IDLE */
 		return MB_STATE_IDLE;
 	case 2:  /* HOME */
@@ -338,6 +335,15 @@ gsm_state_to_mb_state (GsmDeviceInfo *info)
 }
 
 static guint32
+gsm_state_to_mb_state (GsmDeviceInfo *info)
+{
+	if (!info->modem_enabled)
+		return MB_STATE_UNKNOWN;
+
+	return reg_state_to_mb_state(info->reg_state);
+}
+
+static guint32
 gsm_act_to_mb_act (GsmDeviceInfo *info)
 {
 	switch (info->act) {
@@ -1280,9 +1286,24 @@ reg_info_changed_cb (DBusGProxy *proxy,
                      const char *op_name,
                      gpointer user_data)
 {
+	guint32 mb_state = reg_state_to_mb_state(reg_state);
 	GsmDeviceInfo *info = user_data;
 
-	info->reg_state = reg_state + 1;
+	if (info->reg_state != mb_state) {
+                if (mb_state == MB_STATE_HOME)
+                        applet_do_notify_with_pref (info->applet,
+                                            _("GSM network."),
+                                            _("You are now registered on the home network."),
+                                            "notification-gsm-high",
+                                            PREF_DISABLE_CONNECTED_NOTIFICATIONS);
+                else if (mb_state == MB_STATE_ROAMING)
+                        applet_do_notify_with_pref (info->applet,
+                                            _("GSM network."),
+                                            _("You are now registered on a roaming network."),
+                                            "notification-gsm-high",
+                                            PREF_DISABLE_CONNECTED_NOTIFICATIONS);
+        }
+	info->reg_state = mb_state;
 	g_free (info->op_code);
 	info->op_code = strlen (op_code) ? g_strdup (op_code) : NULL;
 	g_free (info->op_name);


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