r3495 - in trunk/src/target/OM-2007.2/applications/openmoko-dialer2: . src/phone-kit

chris at sita.openmoko.org chris at sita.openmoko.org
Fri Nov 23 19:14:33 CET 2007


Author: chris
Date: 2007-11-23 19:14:31 +0100 (Fri, 23 Nov 2007)
New Revision: 3495

Added:
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-mcc-dc.h
Modified:
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/Makefile.am
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-dbus.xml
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h
Log:
        * src/phone-kit/Makefile.am:
        * src/phone-kit/moko-dialer-mcc-dc.h:
        Add a header with mappings from MCC to dialing codes

        * src/phone-kit/moko-dialer-dbus.xml:
        * src/phone-kit/moko-dialer.c: (on_network_registered),
        (moko_dialer_finalize), (net_msghandler), (pb_msghandler),
        (dialer_init_gsmd), (moko_dialer_check_gsmd),
        (moko_dialer_check_registration), (moko_dialer_cc_from_mcc),
        (moko_dialer_send_sms), (moko_dialer_get_provider_name),
        (moko_dialer_get_subscriber_number),
        (moko_dialer_get_country_code),
        (moko_dialer_get_home_country_code):
        * src/phone-kit/moko-dialer.h:
        Add new methods to get current country code, home country code,
        provider name and subscriber number


Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog	2007-11-23 17:50:48 UTC (rev 3494)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog	2007-11-23 18:14:31 UTC (rev 3495)
@@ -1,3 +1,22 @@
+2007-11-23  Chris Lord  <chris at openedhand.com>
+
+	* src/phone-kit/Makefile.am:
+	* src/phone-kit/moko-dialer-mcc-dc.h:
+	Add a header with mappings from MCC to dialing codes
+
+	* src/phone-kit/moko-dialer-dbus.xml:
+	* src/phone-kit/moko-dialer.c: (on_network_registered),
+	(moko_dialer_finalize), (net_msghandler), (pb_msghandler),
+	(dialer_init_gsmd), (moko_dialer_check_gsmd),
+	(moko_dialer_check_registration), (moko_dialer_cc_from_mcc),
+	(moko_dialer_send_sms), (moko_dialer_get_provider_name),
+	(moko_dialer_get_subscriber_number),
+	(moko_dialer_get_country_code),
+	(moko_dialer_get_home_country_code):
+	* src/phone-kit/moko-dialer.h:
+	Add new methods to get current country code, home country code,
+	provider name and subscriber number
+
 2007-11-23  Thomas Wood  <thomas at openedhand.com>
 
 	* src/phone-kit/moko-dialer.c: (moko_dialer_dial),

Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/Makefile.am	2007-11-23 17:50:48 UTC (rev 3494)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/Makefile.am	2007-11-23 18:14:31 UTC (rev 3495)
@@ -12,7 +12,8 @@
 	moko-sound.c moko-sound.h \
 	moko-talking.c moko-talking.h \
 	moko-pin.c \
-	moko-pin.h
+	moko-pin.h \
+	moko-dialer-mcc-dc.h
 
 phone_kit_LDADD = @DIALER_LIBS@ @JANA_LIBS@ $(top_srcdir)/src/common/libdialer-common.a
 

Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-dbus.xml
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-dbus.xml	2007-11-23 17:50:48 UTC (rev 3494)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-dbus.xml	2007-11-23 18:14:31 UTC (rev 3495)
@@ -20,6 +20,22 @@
     <arg type="s" name="uid" direction="out" />
   </method>
 
+  <method name="GetProviderName">
+    <arg type="s" name="name" direction="out" />
+  </method>
+
+  <method name="GetSubscriberNumber">
+    <arg type="s" name="number" direction="out" />
+  </method>
+
+  <method name="GetCountryCode">
+    <arg type="s" name="dial_code" direction="out" />
+  </method>
+
+  <method name="GetHomeCountryCode">
+    <arg type="s" name="dial_code" direction="out" />
+  </method>
+
   <signal name="IncomingCall">
     <arg type="s" name="number"/>
   </signal>

Added: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-mcc-dc.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-mcc-dc.h	2007-11-23 17:50:48 UTC (rev 3494)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-mcc-dc.h	2007-11-23 18:14:31 UTC (rev 3495)
@@ -0,0 +1,244 @@
+
+/* The following is a mapping of GSM MCC codes to country dialing codes */
+
+/* This mapping generated by cross-referencing
+ * ITU E.212[1] ("Land Mobile Numbering Plan") with the wikipedia list of 
+ * country dialing codes[2]. FIXME: It may not be 100% correct.
+ *
+ * [1] http://www.itu.int/itudoc/itu-t/ob-lists/icc/e212_685.html
+ * [2] http://en.wikipedia.org/wiki/List_of_country_calling_codes
+ */
+
+static const gchar * mcc_to_dc[][3] = {
+{ "412", "+93", "Afghanistan" },
+{ "276", "+355", "Albania" },
+{ "603", "+213", "Algeria" },
+{ "544", "+1-684", "American Samoa (US)" },
+{ "213", "+376", "Andorra" },
+{ "631", "+244", "Angola" },
+{ "365", "+1-264", "Anguilla" },
+{ "344", "+1-268", "Antigua and Barbuda" },
+{ "722", "+54", "Argentine Republic" },
+{ "283", "+374", "Armenia" },
+{ "363", "+297", "Aruba (Netherlands)" },
+{ "505", "+61", "Australia" },
+{ "232", "+43", "Austria" },
+{ "400", "+994", "Azerbaijani Republic" },
+{ "364", "+1-242", "Bahamas" },
+{ "426", "+973", "Bahrain" },
+{ "470", "+880", "Bangladesh" },
+{ "342", "+1-246", "Barbados" },
+{ "257", "+375", "Belarus" },
+{ "206", "+32", "Belgium" },
+{ "702", "+501", "Belize" },
+{ "616", "+229", "Benin" },
+{ "350", "+1-441", "Bermuda (UK)" },
+{ "402", "+975", "Bhutan" },
+{ "736", "+591", "Bolivia" },
+{ "218", "+387", "Bosnia and Herzegovina" },
+{ "652", "+267", "Botswana" },
+{ "724", "+55", "Brazil" },
+{ "348", "+1-284", "British Virgin Islands (UK)" },
+{ "528", "+673", "Brunei Darussalam" },
+{ "284", "+359", "Bulgaria" },
+{ "613", "+226", "Burkina Faso" },
+{ "642", "+257", "Burundi" },
+{ "456", "+855", "Cambodia" },
+{ "624", "+237", "Cameroon" },
+{ "302", "+1", "Canada" },
+{ "625", "+238", "Cape Verde" },
+{ "346", "+1-345", "Cayman Islands (UK)" },
+{ "623", "+236", "Central African Republic" },
+{ "622", "+235", "Chad" },
+{ "730", "+56", "Chile" },
+{ "460", "+86", "China" },
+{ "732", "+57", "Colombia" },
+{ "654", "+269", "Comoros" },
+{ "629", "+242", "Republic of the Congo" },
+{ "548", "+682", "Cook Islands (NZ)" },
+{ "712", "+506", "Costa Rica" },
+{ "612", "+225", "Côte d'Ivoire" },
+{ "219", "+385", "Croatia" },
+{ "368", "+53", "Cuba" },
+{ "280", "+357", "Cyprus" },
+{ "230", "+420", "Czech Republic" },
+{ "630", "+243", "Democratic Republic of the Congo" },
+{ "238", "+45", "Denmark" },
+{ "638", "+253", "Djibouti" },
+{ "366", "+1-767", "Dominica" },
+{ "370", "+1-809", "Dominican Republic" },
+{ "514", "+670", "East Timor" },
+{ "740", "+593", "Ecuador" },
+{ "602", "+20", "Egypt" },
+{ "706", "+503", "El Salvador" },
+{ "627", "+240", "Equatorial Guinea" },
+{ "657", "+291", "Eritrea" },
+{ "248", "+372", "Estonia" },
+{ "636", "+251", "Ethiopia" },
+{ "288", "+298", "Faroe Islands (Denmark)" },
+{ "542", "+679", "Fiji" },
+{ "244", "+358", "Finland" },
+{ "208", "+33", "France" },
+{ "742", "+594", "French Guiana (France)" },
+{ "547", "+689", "French Polynesia (France)" },
+{ "628", "+241", "Gabonese Republic" },
+{ "607", "+220", "Gambia" },
+{ "282", "+995", "Georgia" },
+{ "262", "+49", "Germany" },
+{ "620", "+233", "Ghana" },
+{ "266", "+350", "Gibraltar (UK)" },
+{ "202", "+30", "Greece" },
+{ "290", "+299", "Greenland (Denmark)" },
+{ "352", "+1-473", "Grenada" },
+{ "340", "+590", "Guadeloupe (France)" },
+{ "535", "+1-671", "Guam (US)" },
+{ "704", "+502", "Guatemala" },
+{ "611", "+224", "Guinea" },
+{ "632", "+245", "Guinea-Bissau" },
+{ "738", "+592", "Guyana" },
+{ "372", "+509", "Haiti" },
+{ "708", "+504", "Honduras" },
+{ "454", "+852", "Hong Kong (PRC)" },
+{ "216", "+36", "Hungary" },
+{ "274", "+354", "Iceland" },
+{ "404", "+91", "India" },
+{ "405", "+91", "India" },
+{ "510", "+62", "Indonesia" },
+{ "432", "+98", "Iran" },
+{ "418", "+964", "Iraq" },
+{ "272", "+353", "Ireland" },
+{ "425", "+972", "Israel" },
+{ "222", "+39", "Italy" },
+{ "338", "+1-876", "Jamaica" },
+{ "441", "+81", "Japan" },
+{ "440", "+81", "Japan" },
+{ "416", "+962", "Jordan" },
+{ "401", "+7", "Kazakhstan" },
+{ "639", "+254", "Kenya" },
+{ "545", "+686", "Kiribati" },
+{ "467", "+850", "Korea North" },
+{ "450", "+82", "Korea South" },
+{ "419", "+965", "Kuwait" },
+{ "437", "+996", "Kyrgyz Republic" },
+{ "457", "+856", "Laos" },
+{ "247", "+371", "Latvia" },
+{ "415", "+961", "Lebanon" },
+{ "651", "+266", "Lesotho" },
+{ "618", "+231", "Liberia" },
+{ "606", "+218", "Libya" },
+{ "295", "+423", "Liechtenstein" },
+{ "246", "+370", "Lithuania" },
+{ "270", "+352", "Luxembourg" },
+{ "455", "+853", "Macao (PRC)" },
+{ "294", "+389", "Republic of Macedonia" },
+{ "646", "+261", "Madagascar" },
+{ "650", "+265", "Malawi" },
+{ "502", "+60", "Malaysia" },
+{ "472", "+960", "Maldives" },
+{ "610", "+223", "Mali" },
+{ "278", "+356", "Malta" },
+{ "551", "+692", "Marshall Islands" },
+{ "340", "+596", "Martinique (France)" },
+{ "609", "+222", "Mauritania" },
+{ "617", "+230", "Mauritius" },
+{ "334", "+52", "Mexico" },
+{ "550", "+691", "Federated States of Micronesia" },
+{ "259", "+373", "Moldova" },
+{ "212", "+377", "Monaco" },
+{ "428", "+976", "Mongolia" },
+{ "354", "+1-664", "Montserrat (UK)" },
+{ "604", "+212", "Morocco" },
+{ "643", "+258", "Mozambique" },
+{ "414", "+95", "Myanmar" },
+{ "649", "+264", "Namibia" },
+{ "536", "+674", "Nauru" },
+{ "429", "+977", "Nepal" },
+{ "204", "+31", "Netherlands" },
+{ "362", "+599", "Netherlands Antilles (Netherlands)" },
+{ "546", "+687", "New Caledonia (France)" },
+{ "530", "+64", "New Zealand" },
+{ "710", "+505", "Nicaragua" },
+{ "614", "+227", "Niger" },
+{ "621", "+234", "Nigeria" },
+{ "534", "+1-670", "Northern Mariana Islands (US)" },
+{ "242", "+47", "Norway" },
+{ "422", "+968", "Oman" },
+{ "410", "+92", "Pakistan" },
+{ "552", "+680", "Palau" },
+{ "714", "+507", "Panama" },
+{ "537", "+675", "Papua New Guinea" },
+{ "744", "+595", "Paraguay" },
+{ "716", "+51", "Peru" },
+{ "515", "+63", "Philippines" },
+{ "260", "+48", "Poland" },
+{ "351", "+351", "Portugal" },
+{ "330", "+1-787", "Puerto Rico (US)" },
+{ "427", "+974", "Qatar" },
+{ "647", "+262", "Réunion (France)" },
+{ "226", "+40", "Romania" },
+{ "250", "+7", "Russian Federation" },
+{ "635", "+250", "Rwandese Republic" },
+{ "356", "+1-869", "Saint Kitts and Nevis" },
+{ "358", "+1-758", "Saint Lucia" },
+{ "308", "+508", "Saint Pierre and Miquelon (France)" },
+{ "360", "+1-784", "Saint Vincent and the Grenadines" },
+{ "549", "+685", "Samoa" },
+{ "292", "+378", "San Marino" },
+{ "626", "+239", "São Tomé and Príncipe" },
+{ "420", "+966", "Saudi Arabia" },
+{ "608", "+221", "Senegal" },
+{ "220", "+382", "Montenegro" },
+{ "633", "+248", "Seychelles" },
+{ "619", "+232", "Sierra Leone" },
+{ "525", "+65", "Singapore" },
+{ "231", "+421", "Slovakia" },
+{ "293", "+386", "Slovenia" },
+{ "540", "+677", "Solomon Islands" },
+{ "637", "+252", "Somalia" },
+{ "655", "+27", "South Africa" },
+{ "214", "+34", "Spain" },
+{ "413", "+94", "Sri Lanka" },
+{ "634", "+249", "Sudan" },
+{ "746", "+597", "Suriname" },
+{ "653", "+268", "Swaziland" },
+{ "240", "+46", "Sweden" },
+{ "228", "+41", "Switzerland" },
+{ "417", "+963", "Syria" },
+{ "466", "+886", "Taiwan" },
+{ "436", "+992", "Tajikistan" },
+{ "640", "+255", "Tanzania" },
+{ "520", "+66", "Thailand" },
+{ "615", "+228", "Togolese Republic" },
+{ "539", "+676", "Tonga" },
+{ "374", "+1-868", "Trinidad and Tobago" },
+{ "605", "+216", "Tunisia" },
+{ "286", "+90", "Turkey" },
+{ "438", "+993", "Turkmenistan" },
+{ "376", "+1-649", "Turks and Caicos Islands (UK)" },
+{ "641", "+256", "Uganda" },
+{ "255", "+380", "Ukraine" },
+{ "424", "+971", "United Arab Emirates" },
+{ "430", "+971", "United Arab Emirates (Abu Dhabi)" },
+{ "431", "+971", "United Arab Emirates (Dubai)" },
+{ "235", "+44", "United Kingdom" },
+{ "234", "+44", "United Kingdom" },
+{ "310", "+1", "United States of America" },
+{ "311", "+1", "United States of America" },
+{ "312", "+1", "United States of America" },
+{ "313", "+1", "United States of America" },
+{ "314", "+1", "United States of America" },
+{ "315", "+1", "United States of America" },
+{ "316", "+1", "United States of America" },
+{ "332", "+1-340", "United States Virgin Islands (US)" },
+{ "748", "+598", "Uruguay" },
+{ "434", "+998", "Uzbekistan" },
+{ "541", "+678", "Vanuatu" },
+{ "225", "+39", "Vatican City State" },
+{ "734", "+58", "Venezuela" },
+{ "452", "+84", "Viet Nam" },
+{ "543", "+681", "Wallis and Futuna (France)" },
+{ "421", "+967", "Yemen" },
+{ "645", "+260", "Zambia" },
+{ "648", "+263", "Zimbabwe" },
+{NULL}
+};

Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c	2007-11-23 17:50:48 UTC (rev 3494)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c	2007-11-23 18:14:31 UTC (rev 3495)
@@ -33,6 +33,8 @@
 #include <libgsmd/misc.h>
 #include <libgsmd/sms.h>
 #include <libgsmd/voicecall.h>
+#include <libgsmd/phonebook.h>
+#include <gsmd/usock.h>
 
 #include <libjana/jana.h>
 #include <libjana-ecal/jana-ecal.h>
@@ -45,6 +47,8 @@
 #include "moko-sound.h"
 #include "moko-pin.h"
 
+#include "moko-dialer-mcc-dc.h"
+
 G_DEFINE_TYPE (MokoDialer, moko_dialer, G_TYPE_OBJECT)
 
 #define MOKO_DIALER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
@@ -61,6 +65,9 @@
   gint               status;
   gchar              *incoming_clip;
   gchar              *own_number;
+  gchar              *network_name;
+  gchar              *network_number;
+  gchar              *imsi;
 
   /* handles user interaction */
   GtkWidget          *talking;
@@ -421,6 +428,19 @@
       g_debug ("Network registered: LocationAreaCode: %x. CellID: %x.", lac, cell);
       priv->gsm_location.lac = lac;
       priv->gsm_location.cid = cell;
+      
+      if ((priv->registered != GSMD_NETREG_REG_HOME) &&
+          (priv->registered != GSMD_NETREG_REG_ROAMING)) {
+        /* Retrieve operator name */
+        lgsm_oper_get (priv->handle);
+        
+        /* Retrieve operator list to get current country code */
+        lgsm_opers_get (priv->handle);
+        
+        /* Retrieve IMSI to get home country code */
+        lgsm_get_imsi (priv->handle);
+      }
+      
       break;
     default:
       g_warning ("Unhandled register event type = %d\n", type);
@@ -654,6 +674,9 @@
   priv = dialer->priv;
 
   g_free (priv->own_number);
+  g_free (priv->network_name);
+  g_free (priv->network_number);
+  g_free (priv->imsi);
   
   G_OBJECT_CLASS (moko_dialer_parent_class)->finalize (object);
 }
@@ -938,17 +961,53 @@
   MokoDialer *dialer = moko_dialer_get_default ();
   MokoDialerPrivate *priv = dialer->priv;
 
+	const char *oper = (char *) gmh + sizeof(*gmh);
   const struct gsmd_own_number *num = (struct gsmd_own_number *)
                                       ((void *) gmh + sizeof(*gmh));
+	const struct gsmd_msg_oper *opers = (struct gsmd_msg_oper *)
+		((void *) gmh + sizeof(*gmh));
 
-  if (gmh->msg_subtype != GSMD_NETWORK_GET_NUMBER) return -EINVAL;
+  switch (gmh->msg_subtype) {
+    case GSMD_NETWORK_GET_NUMBER :
+      g_free (priv->own_number);
+      priv->own_number = g_strdup (num->addr.number);
+      break;
+    case GSMD_NETWORK_OPER_GET :
+      g_free (priv->network_name);
+      if (oper[0]) priv->network_name = g_strdup (oper);
+      else priv->network_name = NULL;
+      break;
+    case GSMD_NETWORK_OPER_LIST :
+      for (; !opers->is_last; opers++) {
+        if (opers->stat == GSMD_OPER_CURRENT) {
+          g_free (priv->network_number);
+          priv->network_number = g_strndup (opers->opname_num,
+                                            sizeof(opers->opname_num));
+          break;
+        }
+      }
+      break;
+    default :
+      return -EINVAL;
+  }
   
-  g_free (priv->own_number);
+  return 0;
+}
+
+static int
+pb_msghandler (struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
+{
+  MokoDialer *dialer = moko_dialer_get_default ();
+  MokoDialerPrivate *priv = dialer->priv;
+
+  switch (gmh->msg_subtype) {
+    case GSMD_PHONEBOOK_GET_IMSI :
+      priv->imsi = g_strdup ((char *)gmh + sizeof (*gmh));
+      break;
+    default :
+      return -EINVAL;
+  }
   
-  /* TODO: Normalise number necessary? */
-  priv->own_number = g_strdup (num->addr.number);
-  g_debug ("Got phone number: %s", priv->own_number);
-  
   return 0;
 }
 
@@ -1039,6 +1098,7 @@
   lgsm_evt_handler_register (priv->handle, GSMD_EVT_NETREG, gsmd_eventhandler);
   lgsm_evt_handler_register (priv->handle, GSMD_EVT_OUT_STATUS, gsmd_eventhandler);
   lgsm_register_handler (priv->handle, GSMD_MSG_NETWORK, &net_msghandler);
+  lgsm_register_handler (priv->handle, GSMD_MSG_PHONEBOOK, &pb_msghandler);
 
   /* Register with network */
   priv->registered = GSMD_NETREG_UNREG;
@@ -1129,6 +1189,48 @@
   return dialer;
 }
 
+static gboolean
+moko_dialer_check_gsmd (MokoDialer *self, GError **error)
+{
+  MokoDialerPrivate *priv = self->priv;
+  
+  if (!priv->handle) {
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD,
+                          "Failed to connect to gsmd");
+    return FALSE;
+  }
+  
+  return TRUE;
+}
+
+static gboolean
+moko_dialer_check_registration (MokoDialer *self, GError **error)
+{
+  MokoDialerPrivate *priv = self->priv;
+  
+  if ((priv->registered != GSMD_NETREG_REG_HOME) &&
+      (priv->registered != GSMD_NETREG_REG_ROAMING)) {
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_NOT_CONNECTED,
+                          "Not registered to a network");
+    return FALSE;
+  }
+  
+  return TRUE;
+}
+
+static const gchar *
+moko_dialer_cc_from_mcc (gchar *mcc)
+{
+  gint i;
+  for (i = 0; mcc_to_dc[i][0]; i++) {
+    if (strncmp (mcc, mcc_to_dc[i][0], 3) == 0) {
+      return mcc_to_dc[i][1];
+    }
+  }
+  
+  return NULL;
+}
+
 gboolean
 moko_dialer_send_sms (MokoDialer *self, const gchar *number,
                       const gchar *message, gchar **uid, GError **error)
@@ -1141,15 +1243,10 @@
   
   g_assert (self && number && message);
 
+  if (!moko_dialer_check_gsmd (self, error)) return FALSE;
+  if (!moko_dialer_check_registration (self, error)) return FALSE;
   priv = self->priv;
   
-  if (!priv->handle) {
-    /* Failed to connect to gsmd earlier */
-    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD,
-                          "Failed to connect to gsmd");
-    return FALSE;
-  }
-  
   if (!priv->sms_store_open) {
     *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_SMS_STORE,
                           "SMS store not opened");
@@ -1220,3 +1317,87 @@
   return TRUE;
 }
 
+gboolean
+moko_dialer_get_provider_name (MokoDialer *self, gchar **name, GError **error)
+{
+  MokoDialerPrivate *priv;
+  
+  if (!moko_dialer_check_gsmd (self, error)) return FALSE;
+  if (!moko_dialer_check_registration (self, error)) return FALSE;
+  priv = self->priv;
+  
+  if (!priv->network_name) {
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_NO_PROVIDER,
+                          "No current provider");
+    return FALSE;
+  }
+
+  if (name) *name = g_strdup (priv->network_name);
+  return TRUE;
+}
+
+gboolean
+moko_dialer_get_subscriber_number (MokoDialer *self, gchar **number,
+                                   GError **error)
+{
+  MokoDialerPrivate *priv;
+  
+  if (!moko_dialer_check_gsmd (self, error)) return FALSE;
+  priv = self->priv;
+  
+  if (!priv->own_number) {
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_NO_NUMBER,
+                          "Unable to retrieve subscriber number");
+    return FALSE;
+  }
+  
+  if (number) *number = g_strdup (priv->own_number);
+  return TRUE;
+}
+
+gboolean
+moko_dialer_get_country_code (MokoDialer *self, gchar **dial_code,
+                              GError **error)
+{
+  MokoDialerPrivate *priv;
+  
+  if (!moko_dialer_check_gsmd (self, error)) return FALSE;
+  if (!moko_dialer_check_registration (self, error)) return FALSE;
+  priv = self->priv;
+  
+  if (!priv->network_number) {
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR,
+                          PK_DIALER_ERROR_NO_PROVIDER_NUM,
+                          "Unable to retrieve provider number");
+    return FALSE;
+  }
+  
+  if (dial_code)
+    *dial_code = g_strdup (moko_dialer_cc_from_mcc (priv->network_number));
+  
+  return TRUE;
+}
+
+gboolean
+moko_dialer_get_home_country_code (MokoDialer *self, gchar **dial_code,
+                                   GError **error)
+{
+  MokoDialerPrivate *priv;
+  
+  if (!moko_dialer_check_gsmd (self, error)) return FALSE;
+  if (!moko_dialer_check_registration (self, error)) return FALSE;
+  priv = self->priv;
+  
+  if (!priv->network_number) {
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR,
+                          PK_DIALER_ERROR_NO_IMSI,
+                          "Unable to retrieve IMSI");
+    return FALSE;
+  }
+  
+  if (dial_code)
+    *dial_code = g_strdup (moko_dialer_cc_from_mcc (priv->imsi));
+  
+  return TRUE;
+}
+

Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h	2007-11-23 17:50:48 UTC (rev 3494)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h	2007-11-23 18:14:31 UTC (rev 3495)
@@ -51,7 +51,11 @@
   PK_DIALER_ERROR_NOT_CONNECTED,
   PK_DIALER_ERROR_SMS_STORE,
   PK_DIALER_ERROR_SMS_TOOLONG,
-  PK_DIALER_ERROR_NO_TOOLONG
+  PK_DIALER_ERROR_NO_TOOLONG,
+  PK_DIALER_ERROR_NO_PROVIDER,
+  PK_DIALER_ERROR_NO_PROVIDER_NUM,
+  PK_DIALER_ERROR_NO_IMSI,
+  PK_DIALER_ERROR_NO_NUMBER,
 } PhoneKitDialerError;
 
 typedef struct _MokoDialer MokoDialer;
@@ -131,6 +135,21 @@
 moko_dialer_send_sms (MokoDialer *self, const gchar *number,
                       const gchar *message, gchar **uid, GError **error);
 
+gboolean
+moko_dialer_get_provider_name (MokoDialer *self, gchar **name, GError **error);
+
+gboolean
+moko_dialer_get_subscriber_number (MokoDialer *self, gchar **number,
+                                   GError **error);
+
+gboolean
+moko_dialer_get_country_code (MokoDialer *self, gchar **dial_code,
+                              GError **error);
+
+gboolean
+moko_dialer_get_home_country_code (MokoDialer *self, gchar **dial_code,
+                                   GError **error);
+
 G_END_DECLS
 
 #endif /* _HAVE_MOKO_DIALER_H */





More information about the commitlog mailing list