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

chris at sita.openmoko.org chris at sita.openmoko.org
Mon Nov 26 16:21:41 CET 2007


Author: chris
Date: 2007-11-26 16:21:39 +0100 (Mon, 26 Nov 2007)
New Revision: 3512

Modified:
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog
   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.c
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h
Log:
	* src/phone-kit/moko-dialer-mcc-dc.h:
        Replace "+1-" with "+1"

        * src/phone-kit/moko-dialer.c: (on_network_registered),
        (start_handling_sms), (net_msghandler), (pb_msghandler),
        (sms_store_opened_cb), (dialer_init_gsmd),
        (moko_dialer_check_gsmd), (moko_dialer_send_sms):
        Try to resolve local numbers (numbers beginning in '0'), make gsmd
        requests in more reliable places, be a bit better with failures (all to
        do with SMS code)

        * src/phone-kit/moko-dialer.h:
        Remove error code PK_DIALER_ERROR_NO_TOOLONG, add error code
        PK_DIALER_ERROR_INVALID_NUMBER


Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog	2007-11-26 14:17:02 UTC (rev 3511)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog	2007-11-26 15:21:39 UTC (rev 3512)
@@ -1,3 +1,20 @@
+2007-11-26  Chris Lord  <chris at openedhand.com>
+
+	* src/phone-kit/moko-dialer-mcc-dc.h:
+	Replace "+1-" with "+1"
+
+	* src/phone-kit/moko-dialer.c: (on_network_registered),
+	(start_handling_sms), (net_msghandler), (pb_msghandler),
+	(sms_store_opened_cb), (dialer_init_gsmd),
+	(moko_dialer_check_gsmd), (moko_dialer_send_sms):
+	Try to resolve local numbers (numbers beginning in '0'), make gsmd
+	requests in more reliable places, be a bit better with failures (all to
+	do with SMS code)
+
+	* src/phone-kit/moko-dialer.h:
+	Remove error code PK_DIALER_ERROR_NO_TOOLONG, add error code
+	PK_DIALER_ERROR_INVALID_NUMBER
+
 2007-11-23  Chris Lord  <chris at openedhand.com>
 
 	* src/phone-kit/Makefile.am:

Modified: 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-26 14:17:02 UTC (rev 3511)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-mcc-dc.h	2007-11-26 15:21:39 UTC (rev 3512)
@@ -13,32 +13,32 @@
 { "412", "+93", "Afghanistan" },
 { "276", "+355", "Albania" },
 { "603", "+213", "Algeria" },
-{ "544", "+1-684", "American Samoa (US)" },
+{ "544", "+1684", "American Samoa (US)" },
 { "213", "+376", "Andorra" },
 { "631", "+244", "Angola" },
-{ "365", "+1-264", "Anguilla" },
-{ "344", "+1-268", "Antigua and Barbuda" },
+{ "365", "+1264", "Anguilla" },
+{ "344", "+1268", "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" },
+{ "364", "+1242", "Bahamas" },
 { "426", "+973", "Bahrain" },
 { "470", "+880", "Bangladesh" },
-{ "342", "+1-246", "Barbados" },
+{ "342", "+1246", "Barbados" },
 { "257", "+375", "Belarus" },
 { "206", "+32", "Belgium" },
 { "702", "+501", "Belize" },
 { "616", "+229", "Benin" },
-{ "350", "+1-441", "Bermuda (UK)" },
+{ "350", "+1441", "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)" },
+{ "348", "+1284", "British Virgin Islands (UK)" },
 { "528", "+673", "Brunei Darussalam" },
 { "284", "+359", "Bulgaria" },
 { "613", "+226", "Burkina Faso" },
@@ -47,7 +47,7 @@
 { "624", "+237", "Cameroon" },
 { "302", "+1", "Canada" },
 { "625", "+238", "Cape Verde" },
-{ "346", "+1-345", "Cayman Islands (UK)" },
+{ "346", "+1345", "Cayman Islands (UK)" },
 { "623", "+236", "Central African Republic" },
 { "622", "+235", "Chad" },
 { "730", "+56", "Chile" },
@@ -65,8 +65,8 @@
 { "630", "+243", "Democratic Republic of the Congo" },
 { "238", "+45", "Denmark" },
 { "638", "+253", "Djibouti" },
-{ "366", "+1-767", "Dominica" },
-{ "370", "+1-809", "Dominican Republic" },
+{ "366", "+1767", "Dominica" },
+{ "370", "+1809", "Dominican Republic" },
 { "514", "+670", "East Timor" },
 { "740", "+593", "Ecuador" },
 { "602", "+20", "Egypt" },
@@ -89,9 +89,9 @@
 { "266", "+350", "Gibraltar (UK)" },
 { "202", "+30", "Greece" },
 { "290", "+299", "Greenland (Denmark)" },
-{ "352", "+1-473", "Grenada" },
+{ "352", "+1473", "Grenada" },
 { "340", "+590", "Guadeloupe (France)" },
-{ "535", "+1-671", "Guam (US)" },
+{ "535", "+1671", "Guam (US)" },
 { "704", "+502", "Guatemala" },
 { "611", "+224", "Guinea" },
 { "632", "+245", "Guinea-Bissau" },
@@ -109,7 +109,7 @@
 { "272", "+353", "Ireland" },
 { "425", "+972", "Israel" },
 { "222", "+39", "Italy" },
-{ "338", "+1-876", "Jamaica" },
+{ "338", "+1876", "Jamaica" },
 { "441", "+81", "Japan" },
 { "440", "+81", "Japan" },
 { "416", "+962", "Jordan" },
@@ -146,7 +146,7 @@
 { "259", "+373", "Moldova" },
 { "212", "+377", "Monaco" },
 { "428", "+976", "Mongolia" },
-{ "354", "+1-664", "Montserrat (UK)" },
+{ "354", "+1664", "Montserrat (UK)" },
 { "604", "+212", "Morocco" },
 { "643", "+258", "Mozambique" },
 { "414", "+95", "Myanmar" },
@@ -160,7 +160,7 @@
 { "710", "+505", "Nicaragua" },
 { "614", "+227", "Niger" },
 { "621", "+234", "Nigeria" },
-{ "534", "+1-670", "Northern Mariana Islands (US)" },
+{ "534", "+1670", "Northern Mariana Islands (US)" },
 { "242", "+47", "Norway" },
 { "422", "+968", "Oman" },
 { "410", "+92", "Pakistan" },
@@ -172,16 +172,16 @@
 { "515", "+63", "Philippines" },
 { "260", "+48", "Poland" },
 { "351", "+351", "Portugal" },
-{ "330", "+1-787", "Puerto Rico (US)" },
+{ "330", "+1787", "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" },
+{ "356", "+1869", "Saint Kitts and Nevis" },
+{ "358", "+1758", "Saint Lucia" },
 { "308", "+508", "Saint Pierre and Miquelon (France)" },
-{ "360", "+1-784", "Saint Vincent and the Grenadines" },
+{ "360", "+1784", "Saint Vincent and the Grenadines" },
 { "549", "+685", "Samoa" },
 { "292", "+378", "San Marino" },
 { "626", "+239", "São Tomé and Príncipe" },
@@ -210,11 +210,11 @@
 { "520", "+66", "Thailand" },
 { "615", "+228", "Togolese Republic" },
 { "539", "+676", "Tonga" },
-{ "374", "+1-868", "Trinidad and Tobago" },
+{ "374", "+1868", "Trinidad and Tobago" },
 { "605", "+216", "Tunisia" },
 { "286", "+90", "Turkey" },
 { "438", "+993", "Turkmenistan" },
-{ "376", "+1-649", "Turks and Caicos Islands (UK)" },
+{ "376", "+1649", "Turks and Caicos Islands (UK)" },
 { "641", "+256", "Uganda" },
 { "255", "+380", "Ukraine" },
 { "424", "+971", "United Arab Emirates" },
@@ -229,7 +229,7 @@
 { "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)" },
+{ "332", "+1340", "United States Virgin Islands (US)" },
 { "748", "+598", "Uruguay" },
 { "434", "+998", "Uzbekistan" },
 { "541", "+678", "Vanuatu" },

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-26 14:17:02 UTC (rev 3511)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c	2007-11-26 15:21:39 UTC (rev 3512)
@@ -75,11 +75,12 @@
   /* gsmd connection variables */
   struct lgsm_handle *handle;
   MokoDialerSource   *source;
+  gboolean           handling_sms;
   
   /* Storage objects */
   JanaStore          *sms_store;
   gboolean           sms_store_open;
-	JanaNote           *last_msg;
+  JanaNote           *last_msg;
   MokoJournal        *journal;
   MokoContacts       *contacts;
   
@@ -110,6 +111,8 @@
 
 static void dialer_init_gsmd (MokoDialer *dialer);
 
+static const gchar *moko_dialer_cc_from_mcc (gchar *mcc);
+
 /* DBus functions */
 
 static gboolean
@@ -426,11 +429,9 @@
     case GSMD_NETREG_REG_HOME:
     case GSMD_NETREG_REG_ROAMING:
       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 details when we switch location/type */
+      if ((priv->registered != type) || (priv->gsm_location.lac != lac)) {
         /* Retrieve operator name */
         lgsm_oper_get (priv->handle);
         
@@ -441,6 +442,9 @@
         lgsm_get_imsi (priv->handle);
       }
       
+      priv->gsm_location.lac = lac;
+      priv->gsm_location.cid = cell;
+      
       break;
     default:
       g_warning ("Unhandled register event type = %d\n", type);
@@ -955,6 +959,20 @@
   return 0;
 }
 
+static void
+start_handling_sms (MokoDialer *dialer)
+{
+  MokoDialerPrivate *priv = dialer->priv;
+  
+  /* Register SMS handling callback */
+  lgsm_register_handler (priv->handle, GSMD_MSG_SMS, &sms_msghandler);
+
+  /* List all messages to move to journal */
+  lgsm_sms_list (priv->handle, GSMD_SMS_ALL);
+  
+  priv->handling_sms = TRUE;
+}
+
 static int
 net_msghandler (struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
 {
@@ -970,7 +988,17 @@
   switch (gmh->msg_subtype) {
     case GSMD_NETWORK_GET_NUMBER :
       g_free (priv->own_number);
-      priv->own_number = g_strdup (num->addr.number);
+      
+      if ((num->addr.number) && (num->addr.number[0] == '0') && (priv->imsi))
+        priv->own_number = g_strconcat (moko_dialer_cc_from_mcc (priv->imsi),
+                                        num->addr.number + 1, NULL);
+      else
+        priv->own_number = g_strdup (num->addr.number);
+      
+      if ((priv->sms_store_open) && (!priv->handling_sms)) {
+        start_handling_sms (dialer);
+      }
+      
       break;
     case GSMD_NETWORK_OPER_GET :
       g_free (priv->network_name);
@@ -1003,6 +1031,9 @@
   switch (gmh->msg_subtype) {
     case GSMD_PHONEBOOK_GET_IMSI :
       priv->imsi = g_strdup ((char *)gmh + sizeof (*gmh));
+      
+      /* Get phone number */
+      lgsm_get_subscriber_num (priv->handle);
       break;
     default :
       return -EINVAL;
@@ -1054,13 +1085,9 @@
 
   g_debug ("SMS store opened");
   
-  if (!priv->handle) return;
-  
-  /* Register SMS handling callback */
-  lgsm_register_handler (priv->handle, GSMD_MSG_SMS, &sms_msghandler);
-
-  /* List all messages to move to journal */
-  lgsm_sms_list (priv->handle, GSMD_SMS_ALL);
+  if (priv->handle && priv->own_number) {
+    start_handling_sms (self);
+  }
 }
 
 static void
@@ -1103,10 +1130,10 @@
   /* Register with network */
   priv->registered = GSMD_NETREG_UNREG;
   lgsm_netreg_register (priv->handle, "");
-
+  
   /* Get phone number */
   lgsm_get_subscriber_num (priv->handle);
-  
+
   /* Start polling for events */
   priv->source = (MokoDialerSource *)
     g_source_new (&funcs, sizeof (MokoDialerSource));
@@ -1194,6 +1221,8 @@
 {
   MokoDialerPrivate *priv = self->priv;
   
+  if (!priv->handle) dialer_init_gsmd (self);
+  
   if (!priv->handle) {
     *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD,
                           "Failed to connect to gsmd");
@@ -1240,6 +1269,7 @@
   gint msg_length, c;
   gboolean ascii;
   JanaNote *note;
+  const gchar *dialcode;
   
   g_assert (self && number && message);
 
@@ -1258,8 +1288,9 @@
   
   /* Set destination number */
   if (strlen (number) > GSMD_ADDR_MAXLEN + 1) {
-    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_NO_TOOLONG,
-                          "Number too long");
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR,
+                          PK_DIALER_ERROR_INVALID_NUMBER,
+                          "Invalid number");
     return FALSE;
   } else {
     strcpy (sms.addr, number);
@@ -1286,16 +1317,22 @@
     packing_7bit_character (message, &sms);
   } else {
     sms.alpha = ALPHABET_8BIT;
-    sms.length = strlen (message);
     strcpy ((gchar *)sms.data, message);
   }
+  sms.length = msg_length;
   
   /* Send message */
   lgsm_sms_send (priv->handle, &sms);
   
   /* Store sent message in journal */
   note = jana_ecal_note_new ();
-  jana_note_set_recipient (note, number);
+  if ((number[0] == '0') && (priv->network_number) &&
+      (dialcode = moko_dialer_cc_from_mcc (priv->network_number))) {
+    gchar *full_number = g_strconcat (dialcode, number + 1, NULL);
+    jana_note_set_recipient (note, full_number);
+    g_free (full_number);
+  } else
+    jana_note_set_recipient (note, number);
   jana_note_set_author (note, priv->own_number);
   
   jana_note_set_body (note, message);

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-26 14:17:02 UTC (rev 3511)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h	2007-11-26 15:21:39 UTC (rev 3512)
@@ -51,11 +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_PROVIDER,
   PK_DIALER_ERROR_NO_PROVIDER_NUM,
   PK_DIALER_ERROR_NO_IMSI,
   PK_DIALER_ERROR_NO_NUMBER,
+  PK_DIALER_ERROR_INVALID_NUMBER,
 } PhoneKitDialerError;
 
 typedef struct _MokoDialer MokoDialer;





More information about the commitlog mailing list