From: Sergio Villar Senin Date: Wed, 4 Mar 2009 10:34:35 +0000 (+0000) Subject: * Fixes NB#103682 improved the region selection in the easysetup wizard X-Git-Tag: git_migration_finished~441 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=296f6db2d35c09fa6267e967399c1bc529fc61e6 * Fixes NB#103682 improved the region selection in the easysetup wizard pmo-trunk-r7779 --- diff --git a/src/hildon2/modest-country-picker.c b/src/hildon2/modest-country-picker.c index 91b2088..20b3e70 100644 --- a/src/hildon2/modest-country-picker.c +++ b/src/hildon2/modest-country-picker.c @@ -142,7 +142,7 @@ effective_mcc (gint mcc) /* each line is of the form: xxx logical_id - + NOTE: this function is NOT re-entrant, the out-param country are static strings that should NOT be freed. and will change when calling this function again @@ -156,32 +156,29 @@ effective_mcc (gint mcc) static int parse_mcc_mapping_line (const char* line, char** country) { - int i, j; char mcc[4]; /* the mcc code, always 3 bytes*/ - static char my_country[128]; + gchar *iter, *tab, *final; if (!line) { *country = NULL; return 0; } - - for (i = 3, j = 0; i < 128; ++i) { - char kar = line[i]; - 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]; + /* Go to the first tab (Country separator) */ + tab = g_utf8_strrchr (line, -1, '\t'); + *country = g_utf8_find_next_char (tab, NULL); + + /* Replace by end of string */ + final = g_utf8_strrchr (tab, g_utf8_strlen (tab, 100) + 1, '\n'); + *final = '\0'; + + /* Get MCC code */ + mcc[0] = g_utf8_get_char (line); + iter = g_utf8_find_next_char (line, NULL); + mcc[1] = g_utf8_get_char (iter); + iter = g_utf8_find_next_char (iter, NULL); + mcc[2] = g_utf8_get_char (iter); mcc[3] = '\0'; - - *country = my_country; return effective_mcc ((int) strtol ((const char*)mcc, NULL, 10)); } @@ -193,34 +190,25 @@ static void load_from_file (ModestCountryPicker *self, GtkListStore *liststore) { ModestCountryPickerPrivate *priv = MODEST_COUNTRY_PICKER_GET_PRIVATE (self); - + gboolean translated; char line[MAX_LINE_LEN]; guint previous_mcc = 0; - gchar *territory, *fallback = NULL; - gchar *current_locale; - - /* Get the territory specified for the current locale */ - territory = nl_langinfo (_NL_ADDRESS_COUNTRY_NAME); + gchar *territory; - /* Tricky stuff, the translations of the OSSO countries does - not always correspond to the country names in locale - databases. Add all these cases here. sergio */ - if (!strcmp (territory, "United Kingdom")) - fallback = g_strdup ("UK"); - - current_locale = setlocale (LC_ALL ,NULL); - - FILE *file = modest_maemo_open_mcc_mapping_file (); + FILE *file = modest_maemo_open_mcc_mapping_file (&translated); if (!file) { g_warning("Could not open mcc_mapping file"); return; } - while (fgets (line, MAX_LINE_LEN, file) != NULL) { + /* Get the territory specified for the current locale */ + territory = nl_langinfo (_NL_ADDRESS_COUNTRY_NAME); + + while (fgets (line, MAX_LINE_LEN, file) != NULL) { int mcc; char *country = NULL; - const gchar *name_translated, *english_translation; + const gchar *name_translated; mcc = parse_mcc_mapping_line (line, &country); if (!country || mcc == 0) { @@ -235,25 +223,33 @@ load_from_file (ModestCountryPicker *self, GtkListStore *liststore) previous_mcc = mcc; if (!priv->locale_mcc) { - english_translation = dgettext ("osso-countries", country); - if (!strcmp (english_translation, territory) || - (fallback && !strcmp (english_translation, fallback))) - priv->locale_mcc = mcc; + if (translated) { + if (!g_utf8_collate (country, territory)) + priv->locale_mcc = mcc; + g_debug ("'%s' || '%s' || %d", territory, country, mcc); + } else { + gchar *translation = dgettext ("osso-countries", country); + if (!g_utf8_collate (translation, territory)) + priv->locale_mcc = mcc; + g_debug ("'%s' || '%s' || %d", territory, translation, mcc); + } } name_translated = dgettext ("osso-countries", country); - + /* Add the row to the model: */ GtkTreeIter iter; gtk_list_store_append (liststore, &iter); gtk_list_store_set(liststore, &iter, MODEL_COL_MCC, mcc, MODEL_COL_NAME, name_translated, -1); - } + } fclose (file); + /* Fallback to Finland */ + if (!priv->locale_mcc) + priv->locale_mcc = 244; + /* Sort the items: */ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (liststore), MODEL_COL_NAME, GTK_SORT_ASCENDING); - - g_free (fallback); } static void @@ -276,7 +272,7 @@ modest_country_picker_load_data(ModestCountryPicker *self) * This must match our MODEL_COLS enum constants. */ model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT); - + /* Country column: * The ID model column in not shown in the view. */ renderer = gtk_cell_renderer_text_new (); diff --git a/src/hildon2/modest-maemo-utils.c b/src/hildon2/modest-maemo-utils.c index 0dcdf0b..c2248af 100644 --- a/src/hildon2/modest-maemo-utils.c +++ b/src/hildon2/modest-maemo-utils.c @@ -150,30 +150,38 @@ modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win, } FILE* -modest_maemo_open_mcc_mapping_file (void) +modest_maemo_open_mcc_mapping_file (gboolean *translated) { - FILE* result; - + FILE* result = NULL; const gchar* path; - const gchar* path1 = MODEST_OPERATOR_WIZARD_MCC_MAPPING; + gchar *path1 = g_strdup_printf ("%s.%s", MODEST_OPERATOR_WIZARD_MCC_MAPPING, getenv("LANG")); const gchar* path2 = MODEST_MCC_MAPPING; - - if (access(path1, R_OK) == 0) + + if (translated) + *translated = TRUE; + + if (access (path1, R_OK) == 0) { path = path1; - else if (access(path2, R_OK) == 0) + } else if (access (MODEST_OPERATOR_WIZARD_MCC_MAPPING, R_OK) == 0) { + path = MODEST_OPERATOR_WIZARD_MCC_MAPPING; + if (translated) + *translated = FALSE; + } else if (access (path2, R_OK) == 0) { path = path2; - else { + } else { g_warning ("%s: neither '%s' nor '%s' is a readable mapping file", __FUNCTION__, path1, path2); - return NULL; + goto end; } - + result = fopen (path, "r"); if (!result) { g_warning ("%s: error opening mapping file '%s': %s", __FUNCTION__, path, strerror(errno)); - return NULL; + goto end; } + end: + g_free (path1); return result; } diff --git a/src/hildon2/modest-maemo-utils.h b/src/hildon2/modest-maemo-utils.h index 4f54dce..36f3658 100644 --- a/src/hildon2/modest-maemo-utils.h +++ b/src/hildon2/modest-maemo-utils.h @@ -81,7 +81,7 @@ osso_context_t *modest_maemo_utils_get_osso_context (void); * * Returns: file ptr or NULL in case of error */ -FILE* modest_maemo_open_mcc_mapping_file (void); +FILE* modest_maemo_open_mcc_mapping_file (gboolean *translated); /** * modest_maemo_set_thumbable_scrollbar: diff --git a/src/hildon2/modest-platform.c b/src/hildon2/modest-platform.c index 7263690..cf29aca 100644 --- a/src/hildon2/modest-platform.c +++ b/src/hildon2/modest-platform.c @@ -125,7 +125,7 @@ on_modest_conf_update_interval_changed (ModestConf* self, static gboolean check_required_files (void) { - FILE *mcc_file = modest_maemo_open_mcc_mapping_file (); + FILE *mcc_file = modest_maemo_open_mcc_mapping_file (NULL); if (!mcc_file) { g_printerr ("modest: check for mcc file failed\n"); return FALSE; diff --git a/src/modest-init.c b/src/modest-init.c index 983cd3d..a0361a4 100644 --- a/src/modest-init.c +++ b/src/modest-init.c @@ -600,8 +600,8 @@ init_i18n (void) setenv ("LC_MESSAGES", "en_GB", 1); } else { gchar *language = g_strdup_printf ("%s:en_GB", lc_messages); - setenv ("LANGUAGE", language, 1); - g_free (language); + setenv ("LC_MESSAGES", language, 1); + g_free (language); } /* end of little trick */