* src/maemo/modest-connection-specific-smtp-edit-window.c:
[modest] / src / maemo / easysetup / modest-easysetup-country-combo-box.c
index 9c37ebf..ba1a908 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <stdio.h>
 
+#include "../modest-maemo-utils.h"
 #include "modest-easysetup-country-combo-box.h"
 #include <gtk/gtkliststore.h>
 #include <gtk/gtkcelllayout.h>
@@ -158,37 +159,32 @@ static int
 parse_mcc_mapping_line (const char* line,  char** country)
 {
        int i, j;
-       char mcc[4];  /* the mcc code, always 3 bytes*/
+       char mcc[3];  /* the mcc code, always 3 bytes*/
        static char my_country[128];
-       
-       /* Initialize output parameters: */
-       *country = NULL;
 
-       g_return_val_if_fail (line && strlen(line) > 20, 0);
+       if (!line) {
+               *country = NULL;
+               return 0;
+       }
        
        for (i = 3, j = 0; i < 128; ++i) {
                char kar = line[i];
-               if (kar < '_' ) { /* optimization */
-                       if (kar == '\n' || kar == '\r')
-                               break;
-                       else if (kar == ' ' || kar == '\t')
-                               continue;
-                       else  /* error */
-                               return 0;
-               } else {
-                       printf ("%c", kar);
+               if (kar == '\0')
+                       break;
+               else if (kar < '_')
+                       continue;
+               else 
                        my_country [j++] = kar;
-               }
        }
        my_country[j] = '\0';
 
        mcc[0] = line[0];
        mcc[1] = line[1];
        mcc[2] = line[2];
-       mcc[3] = '\0';
        
        *country = my_country;
-       return effective_mcc (atoi(mcc));
+
+       return effective_mcc ((int) strtol ((const char*)mcc, NULL, 10));
 }
 
 /** Note that the mcc_mapping file is installed 
@@ -202,22 +198,8 @@ load_from_file (EasysetupCountryComboBox *self)
        
        char line[MAX_LINE_LEN];
        guint previous_mcc = 0;
-               
-       /* Load the file one line at a time: */
-#ifdef MODEST_HILDON_VERSION_0
-       const gchar* filepath = PROVIDER_DATA_DIR "/mcc_mapping";
-#else
-       /* This is the official version, in the 'operator-wizard-settings' package */
-       const gchar* filepath = "/usr/share/operator-wizard/mcc_mapping";
-#endif /*MODEST_HILDON_VERSION_0*/
-       /* printf ("DEBUG: %s: filepath=%s\n", __FUNCTION__, filepath); */
-       FILE *file = fopen(filepath, "r");
-       if (!file) {
-               const gchar* filepath_hack = HACK_TOP_SRCDIR "src/maemo/easysetup/mcc_mapping";
-               g_warning ("Could not locate the official mcc_mapping countries list file from %s, "
-                       "so attempting to load it instead from %s", filepath, filepath_hack);
-               file = fopen(filepath_hack, "r");
-       }
+       
+       FILE *file = modest_maemo_open_mcc_mapping_file ();
        if (!file) {
                g_warning("Could not open mcc_mapping file");
                return;
@@ -274,7 +256,6 @@ easysetup_country_combo_box_init (EasysetupCountryComboBox *self)
        
        /* Setup the combo box: */
        GtkComboBox *combobox = GTK_COMBO_BOX (self);
-       gtk_combo_box_set_model (combobox, priv->model);
        
        /* Country column:
         * The ID model column in not shown in the view. */
@@ -290,6 +271,8 @@ easysetup_country_combo_box_init (EasysetupCountryComboBox *self)
        
        /* Fill the model with rows: */
        load_from_file (self);
+       /* Set this _after_ loading from file, it makes loading faster */
+       gtk_combo_box_set_model (combobox, priv->model);
 }
 
 EasysetupCountryComboBox*