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);
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)
/* 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)
{
/* 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);
* 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);
/**
* 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. */
}
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;
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);
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: */
/* 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);
}
/**