2007-06-08 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Fri, 8 Jun 2007 16:09:26 +0000 (16:09 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Fri, 8 Jun 2007 16:09:26 +0000 (16:09 +0000)
* src/maemo/easysetup/modest-easysetup-country-combo-box.h:
        * src/maemo/easysetup/modest-easysetup-country-combo-box.c:
        (on_model_foreach_release), (easysetup_country_combo_box_finalize),
        (load_from_file), (easysetup_country_combo_box_init),
        (easysetup_country_combo_box_get_active_country_ids),
        (on_model_foreach_select_id): Store a GSList* of IDs in the model row,
        instead of just one ID, to avoid duplicate country names in the UI.

        * src/maemo/easysetup/modest-easysetup-provider-combo-box.h:
        * src/maemo/easysetup/modest-easysetup-provider-combo-box.c:
        (easysetup_provider_combo_box_fill): Adapt to use a list rather than
        a single ID, avoiding duplicate providers.
        * src/maemo/easysetup/modest-easysetup-wizard.c:
        (on_combo_account_country): Adapt to use a list.

pmo-trunk-r2137

ChangeLog2
src/maemo/easysetup/modest-easysetup-country-combo-box.c
src/maemo/easysetup/modest-easysetup-country-combo-box.h
src/maemo/easysetup/modest-easysetup-provider-combo-box.c
src/maemo/easysetup/modest-easysetup-provider-combo-box.h
src/maemo/easysetup/modest-easysetup-wizard.c

index 970ef47..ea80e71 100644 (file)
@@ -1,5 +1,22 @@
 2007-06-08  Murray Cumming  <murrayc@murrayc.com>
 
+       * src/maemo/easysetup/modest-easysetup-country-combo-box.h:
+       * src/maemo/easysetup/modest-easysetup-country-combo-box.c:
+       (on_model_foreach_release), (easysetup_country_combo_box_finalize),
+       (load_from_file), (easysetup_country_combo_box_init),
+       (easysetup_country_combo_box_get_active_country_ids),
+       (on_model_foreach_select_id): Store a GSList* of IDs in the model row, 
+       instead of just one ID, to avoid duplicate country names in the UI.
+
+       * src/maemo/easysetup/modest-easysetup-provider-combo-box.h:
+       * src/maemo/easysetup/modest-easysetup-provider-combo-box.c:
+       (easysetup_provider_combo_box_fill): Adapt to use a list rather than 
+       a single ID, avoiding duplicate providers.
+       * src/maemo/easysetup/modest-easysetup-wizard.c:
+       (on_combo_account_country): Adapt to use a list.
+
+2007-06-08  Murray Cumming  <murrayc@murrayc.com>
+
        * src/modest-account-mgr-priv.h: Added a timeout id and a GSList of 
        keys changed in the last X seconds.
        
index c41a2c2..21c36d3 100644 (file)
@@ -87,11 +87,29 @@ easysetup_country_combo_box_dispose (GObject *object)
                G_OBJECT_CLASS (easysetup_country_combo_box_parent_class)->dispose (object);
 }
 
+enum MODEL_COLS {
+       MODEL_COL_NAME = 0, /* string */
+       MODEL_COL_IDS = 1 /* A GSList* of guints. */
+};
+
+static gboolean 
+on_model_foreach_release (GtkTreeModel *model, GtkTreePath *path, 
+       GtkTreeIter *iter, gpointer data)
+{
+       GSList *list = NULL;
+       gtk_tree_model_get (model, iter, MODEL_COL_IDS, &list, -1); 
+       if (list)
+               g_slist_free (list);
+               
+       return FALSE; /* keep walking. */
+}
+       
 static void
 easysetup_country_combo_box_finalize (GObject *object)
 {
        EasysetupCountryComboBoxPrivate *priv = COUNTRY_COMBO_BOX_GET_PRIVATE (object);
 
+       gtk_tree_model_foreach (priv->model, on_model_foreach_release, NULL);
        g_object_unref (G_OBJECT (priv->model));
 
        G_OBJECT_CLASS (easysetup_country_combo_box_parent_class)->finalize (object);
@@ -110,11 +128,6 @@ easysetup_country_combo_box_class_init (EasysetupCountryComboBoxClass *klass)
        object_class->finalize = easysetup_country_combo_box_finalize;
 }
 
-enum MODEL_COLS {
-       MODEL_COL_NAME = 0,
-       MODEL_COL_ID = 1
-};
-
 /** id and country must be freed.
  */
 static void parse_mcc_mapping_line (const char* line, char** id, char** country)
@@ -184,6 +197,7 @@ static void load_from_file (EasysetupCountryComboBox *self)
        /* 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)
        {
@@ -203,37 +217,84 @@ static void load_from_file (EasysetupCountryComboBox *self)
        /* We use the getline() GNU extension,
         * because it reads per line, which simplifies our code,
         * and it doesn't require us to hard-code a buffer length.
+        * TODO: Could we make this faster?
         */
        int len = 0;
        char *line = NULL;
+       guint previous_id = 0;
+       gchar* previous_country = NULL;
+       GSList *list = NULL;
        while (getline (&line, &len, file) > 0) { /* getline will realloc line if necessary. */
                /* printf ("DBEUG: len=%d, line: %s\n", len, line); */
                
                char *id_str = NULL;
                char *country = NULL;
                parse_mcc_mapping_line (line, &id_str, &country);
-               //printf("DEBUG: parsed: id=%s, country=%s\n", id_str, country); 
+               /* printf("DEBUG: parsed: id=%s, country=%s\n", id_str, country); */
                
                if(id_str && country) {
-                       guint id = (guint)g_ascii_strtod(id_str, NULL); /* Note that this parses locale-independent text. */
                        
-                       /* Get the translation for the country name:
-                        * Note that the osso_countries_1.0 translation domain files are installed 
-                        * by the operator-wizard-settings package. */
-                       /* For post-Bora, there is a separate (meta)package osso-countries-l10n-mr0 */
-                       const gchar *name_translated = dgettext ("osso-countries", country);
-                       if(!name_translated)
-                         name_translated = country;
+                       if (previous_country) {
+                               /* printf ("  debug: storing id=%d for country=%s\n", previous_id, previous_country); */
+                               list = g_slist_append (list, GUINT_TO_POINTER (previous_id));
+                       }
+                       
+                       /* Group multiple MMC IDs for the same country together:
+                        * This assumes that they are in sequence.
+                        * We don't know why some countries, such as the USA, have several MMC IDs.
+                        * If they are regions in the country, and we need to show them separately, then 
+                        * we would need to have that information in the file to distinguish them.
+                        */
+                       if (!previous_country || 
+                          (previous_country && strcmp (previous_country, country) != 0)) {
+                               
+                               /* Get the translation for the country name:
+                                * Note that the osso_countries_1.0 translation domain files are installed 
+                                * by the operator-wizard-settings package. */
+                               /* For post-Bora, there is a separate (meta)package osso-countries-l10n-mr0 */
+                               
+                               /* Note: Even when the untranslated names are different, there may still be 
+                                * duplicate translated names. They would be translation bugs.
+                                */
+                               const gchar *name_translated = dgettext ("osso-countries", previous_country);
+                               if(!name_translated)
+                                 name_translated = previous_country;
+                               
+                               /* Add the row to the model: */
+                               GtkTreeIter iter;
+                               gtk_list_store_append (liststore, &iter);
+                               gtk_list_store_set(liststore, &iter, MODEL_COL_IDS, list, MODEL_COL_NAME, name_translated, -1);
+                               
+                               /* The list will be freed in our finalize(). */
+                               list = NULL;
+                       }
+                       
+                       g_free (previous_country);
+                       previous_country = g_strdup (country);
                        
-                       /* Add the row to the model: */
-                       GtkTreeIter iter;
-                       gtk_list_store_append (liststore, &iter);
-                       gtk_list_store_set(liststore, &iter, MODEL_COL_ID, id, MODEL_COL_NAME, name_translated, -1);
+                       const guint id = (guint)g_ascii_strtod(id_str, NULL); /* Note that this parses locale-independent text. */
+                       previous_id = id;
                }
                
                g_free (id_str);
                g_free (country);
        }
+       
+       /* Deal with the last country: */
+       const gchar *name_translated = dgettext ("osso-countries", previous_country);
+       if(!name_translated)
+         name_translated = previous_country;
+       
+       /* Add the row to the model: */
+       GtkTreeIter iter;
+       gtk_list_store_append (liststore, &iter);
+       gtk_list_store_set(liststore, &iter, MODEL_COL_IDS, list, MODEL_COL_NAME, name_translated, -1);
+       
+       if (list) {
+               g_slist_free (list);
+               list = NULL;
+       }
+                               
 
        if (line)
                free (line);
@@ -250,7 +311,9 @@ easysetup_country_combo_box_init (EasysetupCountryComboBox *self)
         * with a string for the name, and an int for the MCC ID.
         * This must match our MODEL_COLS enum constants.
         */
-       priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_UINT));
+       priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, 
+               G_TYPE_STRING, 
+               G_TYPE_POINTER));
 
        /* Setup the combo box: */
        GtkComboBox *combobox = GTK_COMBO_BOX (self);
@@ -275,21 +338,22 @@ easysetup_country_combo_box_new (void)
 
 /**
  * Returns the MCC number of the selected country, or 0 if no country was selected. 
+ * The list should not be freed.
  */
-guint
-easysetup_country_combo_box_get_active_country_id (EasysetupCountryComboBox *self)
+GSList *
+easysetup_country_combo_box_get_active_country_ids (EasysetupCountryComboBox *self)
 {
        GtkTreeIter active;
        const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &active);
        if (found) {
                EasysetupCountryComboBoxPrivate *priv = COUNTRY_COMBO_BOX_GET_PRIVATE (self);
 
-               guint id = 0;
-               gtk_tree_model_get (priv->model, &active, MODEL_COL_ID, &id, -1); 
-               return id;      
+               GSList *list = NULL;
+               gtk_tree_model_get (priv->model, &active, MODEL_COL_IDS, &list, -1); 
+               return list;    
        }
 
-       return 0; /* Failed. */
+       return NULL; /* Failed. */
 }
 
 
@@ -309,9 +373,9 @@ on_model_foreach_select_id(GtkTreeModel *model,
        ForEachData *state = (ForEachData*)(user_data);
        
        /* Select the item if it has the matching ID: */
-       guint id = 0;
-       gtk_tree_model_get (model, iter, MODEL_COL_ID, &id, -1); 
-       if(id == state->mcc_id) {
+       GSList *list = NULL;
+       gtk_tree_model_get (model, iter, MODEL_COL_IDS, &list, -1);
+       if(list && g_slist_find (list, GUINT_TO_POINTER (state->mcc_id))) {
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (state->self), iter);
                
                state->found = TRUE;
index 880d29a..7f667aa 100644 (file)
@@ -68,7 +68,7 @@ GType easysetup_country_combo_box_get_type (void);
 
 EasysetupCountryComboBox* easysetup_country_combo_box_new (void);
 
-guint easysetup_country_combo_box_get_active_country_id (EasysetupCountryComboBox *self);
+GSList* easysetup_country_combo_box_get_active_country_ids (EasysetupCountryComboBox *self);
 gboolean easysetup_country_combo_box_set_active_country_id (EasysetupCountryComboBox *self, guint mcc_id);
 
 G_END_DECLS
index 220c324..cd2ed83 100644 (file)
@@ -142,7 +142,7 @@ easysetup_provider_combo_box_new (void)
        return g_object_new (EASYSETUP_TYPE_PROVIDER_COMBO_BOX, NULL);
 }
 
-void easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, ModestPresets *presets, gint country_id)
+void easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, ModestPresets *presets, GSList * list_country_id)
 {      
        EasysetupProviderComboBoxPrivate *priv = PROVIDER_COMBO_BOX_GET_PRIVATE (combobox);
        
@@ -150,38 +150,60 @@ void easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, Mod
        GtkListStore *liststore = GTK_LIST_STORE (priv->model);
        gtk_list_store_clear (liststore);
        
-       /* Add the appropriate rows for this country, from the presets file: */
-       gchar ** provider_ids = NULL;
-       gchar ** provider_names = modest_presets_get_providers (presets, country_id, 
-               TRUE /* include_globals */, &provider_ids);
+       GSList *provider_ids_used_already = NULL;
        
-       gchar ** iter_provider_names = provider_names;
-       gchar ** iter_provider_ids = provider_ids;
-       while(iter_provider_names && *iter_provider_names && iter_provider_ids && *iter_provider_ids)
-       {
-               const gchar* provider_name = *iter_provider_names;
-               if(!provider_name)
-                       continue;
+       GSList *iter_ids = list_country_id;
+       while (iter_ids) {
+               const guint country_id = GPOINTER_TO_UINT (iter_ids->data);
+               
+               /* Add the appropriate rows for this country, from the presets file: */
+               gchar ** provider_ids = NULL;
+               gchar ** provider_names = modest_presets_get_providers (presets, country_id, 
+                       TRUE /* include_globals */, &provider_ids);
+               
+               gchar ** iter_provider_names = provider_names;
+               gchar ** iter_provider_ids = provider_ids;
+               while(iter_provider_names && *iter_provider_names && iter_provider_ids && *iter_provider_ids)
+               {
+                       const gchar* provider_name = *iter_provider_names;
+                       if(!provider_name)
+                               continue;
+                               
+                       const gchar* provider_id = *iter_provider_ids;
+                       if(!provider_id)
+                               continue;
+                       
+                       /* Prevent duplicate providers: */
+                       if (g_slist_find_custom (provider_ids_used_already, 
+                               provider_id, (GCompareFunc)strcmp) == NULL) {
+                               /* printf("debug: provider_name=%s\n", provider_name); */
                        
-               const gchar* provider_id = *iter_provider_ids;
-               if(!provider_id)
-                       continue;
+                               /* Add the row: */
+                               GtkTreeIter iter;
+                               gtk_list_store_append (liststore, &iter);
+                               
+                               gchar *debug = g_strdup_printf ("%s: %s", provider_id, provider_name);
+                               gtk_list_store_set(liststore, &iter, 
+                                       MODEL_COL_ID, provider_id, 
+                                       MODEL_COL_NAME, debug, -1);
+                               g_free (debug);
+                               
+                               provider_ids_used_already = g_slist_append (
+                                       provider_ids_used_already, (gpointer)g_strdup (provider_id));
+                       }
+                               
+                       ++iter_provider_names;
+                       ++iter_provider_ids;    
+               }
                
-               /* printf("debug: provider_name=%s\n", provider_name); */
-       
-               /* Add the row: */
-               GtkTreeIter iter;
-               gtk_list_store_append (liststore, &iter);
-               gtk_list_store_set(liststore, &iter, MODEL_COL_ID, provider_id, MODEL_COL_NAME, provider_name, -1);
+               /* Free the result of modest_presets_get_providers()
+                * as specified by its documentation: */
+               g_strfreev (provider_names);
+               g_strfreev (provider_ids);
                
-               ++iter_provider_names;
-               ++iter_provider_ids;    
+               iter_ids = g_slist_next (iter_ids);
        }
        
-       /* Free the result of modest_presets_get_providers()
-        * as specified by its documentation: */
-       g_strfreev (provider_names);
-       g_strfreev (provider_ids);
        
        /* Add the "Other" item: */
        /* Note that ID 0 means "Other" for us: */
@@ -192,6 +214,9 @@ void easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, Mod
        
        /* Select the "Other" item: */
        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+       
+       g_slist_foreach (provider_ids_used_already, (GFunc)g_free, NULL);
+       g_slist_free (provider_ids_used_already);
 }
 
 /**
index 02bcf7a..d8b66aa 100644 (file)
@@ -69,7 +69,7 @@ GType easysetup_provider_combo_box_get_type (void);
 
 EasysetupProviderComboBox* easysetup_provider_combo_box_new (void);
 
-void easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, ModestPresets *presets, gint country_id);
+void easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, ModestPresets *presets, GSList * list_country_id);
 
 gchar* easysetup_provider_combo_box_get_active_provider_id (EasysetupProviderComboBox *combobox);
 
index 036620f..5495a43 100644 (file)
@@ -258,10 +258,10 @@ on_combo_account_country (GtkComboBox *widget, gpointer user_data)
        ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
        
        /* Fill the providers combo, based on the selected country: */
-       gint mcc_id = easysetup_country_combo_box_get_active_country_id (
+       GSList *list_mcc_ids = easysetup_country_combo_box_get_active_country_ids (
                EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
        easysetup_provider_combo_box_fill (
-               EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
+               EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, list_mcc_ids);
 }
 
 static void