#include <stdlib.h>
#include <string.h> /* For memcpy() */
-
+#include <langinfo.h>
+#include <locale.h>
#include <libintl.h> /* For dgettext(). */
/* Include config.h so that _() works: */
typedef struct
{
- GtkTreeModel *model;
+ gint locale_mcc;
+/* GtkTreeModel *model; */
} ModestEasysetupCountryComboBoxPrivate;
#define MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
static void
easysetup_country_combo_box_finalize (GObject *object)
{
- ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (object);
-
- g_object_unref (G_OBJECT (priv->model));
G_OBJECT_CLASS (easysetup_country_combo_box_parent_class)->finalize (object);
}
* by the operator-wizard-settings package.
*/
static void
-load_from_file (EasysetupCountryComboBox *self)
+load_from_file (EasysetupCountryComboBox *self, GtkListStore *liststore)
{
ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
- GtkListStore *liststore = GTK_LIST_STORE (priv->model);
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);
+
+ /* 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 ();
if (!file) {
g_warning("Could not open mcc_mapping file");
int mcc;
char *country = NULL;
+ const gchar *name_translated, *english_translation;
+
mcc = parse_mcc_mapping_line (line, &country);
if (!country || mcc == 0) {
g_warning ("%s: error parsing line: '%s'", __FUNCTION__, line);
continue;
}
previous_mcc = mcc;
-
- /* 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", country);
+
+ if (!priv->locale_mcc) {
+ english_translation = dgettext ("osso-countries", country);
+ if (!strcmp (english_translation, territory) ||
+ (fallback && !strcmp (english_translation, fallback)))
+ priv->locale_mcc = mcc;
+ }
+ name_translated = dgettext ("osso-countries", country);
/* Add the row to the model: */
GtkTreeIter iter;
gtk_list_store_set(liststore, &iter, MODEL_COL_MCC, mcc, MODEL_COL_NAME, name_translated, -1);
}
fclose (file);
-
+
/* 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
easysetup_country_combo_box_init (EasysetupCountryComboBox *self)
{
ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
- priv->model = NULL;
+ priv->locale_mcc = 0;
}
void
easysetup_country_combo_box_load_data(EasysetupCountryComboBox *self)
{
- ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
+ GtkListStore *model;
/* Create a tree model for the combo box,
* 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_INT));
+ model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
/* Setup the combo box: */
GtkComboBox *combobox = GTK_COMBO_BOX (self);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
"text", MODEL_COL_NAME, NULL);
-
- g_assert (GTK_IS_LIST_STORE(priv->model));
-
-
/* Fill the model with rows: */
- load_from_file (self);
+ load_from_file (self, model);
+
/* Set this _after_ loading from file, it makes loading faster */
- gtk_combo_box_set_model (combobox, priv->model);
+ gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (model));
}
EasysetupCountryComboBox*
GtkTreeIter active;
const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &active);
if (found) {
- ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
gint mcc = 0;
- gtk_tree_model_get (priv->model, &active, MODEL_COL_MCC, &mcc, -1);
+ gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (self)),
+ &active, MODEL_COL_MCC, &mcc, -1);
return mcc;
}
return 0; /* Failed. */
* Specify 0 to select no country.
*/
gboolean
-easysetup_country_combo_box_set_active_country_mcc (EasysetupCountryComboBox *self, guint mcc)
+easysetup_country_combo_box_set_active_country_locale (EasysetupCountryComboBox *self)
{
ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
GtkTreeIter iter;
+ gint current_mcc;
+ GtkTreeModel *model;
- if (!gtk_tree_model_get_iter_first (priv->model, &iter))
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
+ if (!gtk_tree_model_get_iter_first (model, &iter))
return FALSE;
do {
- gint current_mcc = 0;
- gtk_tree_model_get (priv->model, &iter, MODEL_COL_MCC, ¤t_mcc, -1);
- if (current_mcc == mcc) {
+ gtk_tree_model_get (model, &iter, MODEL_COL_MCC, ¤t_mcc, -1);
+ if (priv->locale_mcc == current_mcc) {
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter);
return TRUE;
}
- } while (gtk_tree_model_iter_next (priv->model, &iter));
+ } while (gtk_tree_model_iter_next (model, &iter));
return FALSE; /* not found */
}
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkseparator.h>
+#include <string.h> /* For strlen(). */
#include "maemo/easysetup/modest-easysetup-country-combo-box.h"
#include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
#include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
#include "widgets/modest-secureauth-combo-box.h"
#include "widgets/modest-validating-entry.h"
#include "modest-text-utils.h"
+#include "modest-conf.h"
#include "modest-account-mgr.h"
#include "modest-account-mgr-helpers.h"
#include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
#include "widgets/modest-account-settings-dialog.h"
#include "maemo/modest-maemo-utils.h"
#include "modest-utils.h"
-#include <gconf/gconf-client.h>
-#include <string.h> /* For strlen(). */
#include "maemo/modest-hildon-includes.h"
/* Include config.h so that _() works: */
show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
}
-static gint
-get_default_country_code(void)
-{
- /* TODO: Default to the current country somehow.
- * But I don't know how to get the information that is specified in the
- * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
- *
- * This is probably not the best choice of gconf key:
- * This is the "mcc used in the last pairing", ie. the last connection you made.
- * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
- *
- */
- GError *error = NULL;
- const gchar* key = "/apps/osso/operator-wizard/last_mcc";
- gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
-
- if(mcc_id < 0)
- mcc_id = 0;
-
- if (error) {
- g_warning ("Error getting gconf key %s:\n%s", key, error->message);
- g_error_free (error);
- error = NULL;
-
- mcc_id = 0;
- }
-
- /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
- * This might just be a Maemo bug.
- */
- if (mcc_id == 0)
- {
- /* For now, we default to Finland when there is nothing better: */
- mcc_id = 244;
- }
- return mcc_id;
-}
-
static GtkWidget*
create_page_account_details (ModestEasysetupWizardDialog *self)
{
priv->presets = idle_data->presets;
if (MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX (priv->combo_account_country)) {
- gint mcc = get_default_country_code();
+/* gint mcc = get_default_country_code(); */
+ gint mcc;
/* Fill the combo in an idle call, as it takes a lot of time */
easysetup_country_combo_box_load_data(
MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
- easysetup_country_combo_box_set_active_country_mcc (
- MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc);
+/* easysetup_country_combo_box_set_active_country_mcc ( */
+/* MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc); */
+ easysetup_country_combo_box_set_active_country_locale (
+ MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
+ mcc = easysetup_country_combo_box_get_active_country_mcc (
+ MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
easysetup_provider_combo_box_fill (
EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider),
priv->presets, mcc);