commit 9324b9eeed65370451e6adbf261fd624fb331222
Author: Norbert <nf2.email@gmail.com>
Date:   Wed Jan 13 11:29:29 2010 +0100

    New UnlockRequired property for the Modem interface

diff --git a/introspection/mm-modem.xml b/introspection/mm-modem.xml
index 7896fff..da7635b 100644
--- a/introspection/mm-modem.xml
+++ b/introspection/mm-modem.xml
@@ -113,6 +113,18 @@
       </tp:docstring>
     </property>
 
+    <property name="UnlockRequired" type="s" access="read">
+      <tp:docstring>
+        Empty if the device is usable without an unlock code or has already
+        been unlocked. If the device needs to be unlocked before becoming usable this
+        property contains the specific unlock code required.  Valid unlock code values
+        are "" (blank), "sim-pin", "sim-puk", "ph-sim-pin", "ph-fsim-pin",
+        "ph-fsim-puk", "sim-pin2", "sim-puk2", "ph-net-pin", "ph-net-puk",
+        "ph-netsub-pin", "ph-netsub-puk", "ph-sp-pin", "ph-sp-puk", "ph-corp-pin", and
+        "ph-corp-puk".
+      </tp:docstring>
+    </property>
+
     <property name="IpMethod" type="u" access="read" tp:type="MM_MODEM_IP_METHOD">
       <tp:docstring>
         The IP configuration method.
diff --git a/src/mm-modem-base.c b/src/mm-modem-base.c
index 3d82f8e..af4f832 100644
--- a/src/mm-modem-base.c
+++ b/src/mm-modem-base.c
@@ -39,6 +39,7 @@ typedef struct {
     char *driver;
     char *plugin;
     char *device;
+    char *unlock_required;
     guint32 ip_method;
     gboolean valid;
     MMModemState state;
@@ -169,6 +170,26 @@ mm_modem_base_get_valid (MMModemBase *self)
     return MM_MODEM_BASE_GET_PRIVATE (self)->valid;
 }
 
+void mm_modem_base_set_unlock_required (MMModemBase *self, const char *unlock_required)
+{
+   MMModemBasePrivate *priv;
+
+   g_return_if_fail (self != NULL);
+   g_return_if_fail (MM_IS_MODEM_BASE (self));
+
+   priv = MM_MODEM_BASE_GET_PRIVATE (self);
+
+   /* Only do something if the value changes */
+   if (priv->unlock_required == unlock_required
+      || (priv->unlock_required && unlock_required
+      && !strcmp(priv->unlock_required, unlock_required)))
+      return;
+
+   g_free (priv->unlock_required);
+   priv->unlock_required = g_strdup (unlock_required);
+   g_object_notify (G_OBJECT (self), MM_MODEM_UNLOCK_REQUIRED);
+}
+
 /*****************************************************************************/
 
 static void
@@ -227,6 +248,7 @@ set_property (GObject *object, guint prop_id,
     case MM_MODEM_PROP_VALID:
     case MM_MODEM_PROP_TYPE:
     case MM_MODEM_PROP_ENABLED:
+    case MM_MODEM_PROP_UNLOCK_REQUIRED:
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -268,6 +290,9 @@ get_property (GObject *object, guint prop_id,
     case MM_MODEM_PROP_ENABLED:
         g_value_set_boolean (value, is_enabled (priv->state));
         break;
+    case MM_MODEM_PROP_UNLOCK_REQUIRED:
+        g_value_set_string (value, priv->unlock_required);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -284,6 +309,7 @@ finalize (GObject *object)
     g_free (priv->driver);
     g_free (priv->plugin);
     g_free (priv->device);
+    g_free (priv->unlock_required);
 
     G_OBJECT_CLASS (mm_modem_base_parent_class)->finalize (object);
 }
@@ -336,6 +362,10 @@ mm_modem_base_class_init (MMModemBaseClass *klass)
                                       MM_MODEM_PROP_ENABLED,
                                       MM_MODEM_ENABLED);
 
+    g_object_class_override_property (object_class,
+                                      MM_MODEM_PROP_UNLOCK_REQUIRED,
+                                      MM_MODEM_UNLOCK_REQUIRED);
+
     mm_properties_changed_signal_new (object_class);
 }
 
diff --git a/src/mm-modem-base.h b/src/mm-modem-base.h
index 9eb64ce..9078f3f 100644
--- a/src/mm-modem-base.h
+++ b/src/mm-modem-base.h
@@ -60,5 +60,8 @@ void mm_modem_base_set_valid (MMModemBase *self,
 
 gboolean mm_modem_base_get_valid (MMModemBase *self);
 
+void mm_modem_base_set_unlock_required (MMModemBase *self,
+                                        const char *unlock_required);
+
 #endif /* MM_MODEM_BASE_H */
 
diff --git a/src/mm-modem.c b/src/mm-modem.c
index 5f0f5fa..e97ee60 100644
--- a/src/mm-modem.c
+++ b/src/mm-modem.c
@@ -659,6 +659,15 @@ mm_modem_init (gpointer g_iface)
                                FALSE,
                                G_PARAM_READABLE));
 
+    g_object_interface_install_property
+        (g_iface,
+         g_param_spec_string (MM_MODEM_UNLOCK_REQUIRED,
+                               "UnlockRequired",
+                               "Whether or not the modem requires an unlock "
+                               "code to become usable, and if so, which unlock code is required",
+                               NULL,
+                               G_PARAM_READABLE));
+
     /* Signals */
     g_signal_new ("state-changed",
                   iface_type,
diff --git a/src/mm-modem.h b/src/mm-modem.h
index b59525e..17cf834 100644
--- a/src/mm-modem.h
+++ b/src/mm-modem.h
@@ -55,6 +55,7 @@ typedef enum {
 #define MM_MODEM_TYPE          "type"
 #define MM_MODEM_IP_METHOD     "ip-method"
 #define MM_MODEM_ENABLED       "enabled"
+#define MM_MODEM_UNLOCK_REQUIRED  "unlock-required"
 #define MM_MODEM_VALID         "valid"      /* not exported */
 #define MM_MODEM_PLUGIN        "plugin"     /* not exported */
 #define MM_MODEM_STATE         "state"      /* not exported */
@@ -78,7 +79,8 @@ typedef enum {
     MM_MODEM_PROP_VALID,       /* Not exported */
     MM_MODEM_PROP_PLUGIN,      /* Not exported */
     MM_MODEM_PROP_STATE,       /* Not exported */
-    MM_MODEM_PROP_ENABLED
+    MM_MODEM_PROP_ENABLED,
+    MM_MODEM_PROP_UNLOCK_REQUIRED
 } MMModemProp;
 
 typedef struct _MMModem MMModem;
