From 3b9f4fa01f5cc312e6fe810b7297e3b2920f16b8 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Tue, 30 Sep 2008 20:31:34 +0000 Subject: [PATCH] * Now ModestEasysetupCountryComboBox becomes ModestCountryPicker. We also eliminate ifdefs when they're not required for using this. * Cleaned more "legacy" maemo platform elements and replaced with the new MODEST_TOOLKIT_GTK. pmo-trunk-r5824 --- src/hildon2/Makefile.am | 2 +- src/hildon2/modest-country-picker.c | 355 ++++++++++++++++++ src/hildon2/modest-country-picker.h | 80 ++++ .../modest-default-account-settings-dialog.c | 8 +- src/hildon2/modest-easysetup-country-combo-box.c | 394 -------------------- src/hildon2/modest-easysetup-country-combo-box.h | 93 ----- src/hildon2/modest-easysetup-wizard-dialog.c | 58 ++- src/hildon2/modest-maemo-global-settings-dialog.c | 2 +- src/hildon2/modest-maemo-security-options-view.c | 2 +- src/hildon2/modest-main-window.c | 2 +- src/hildon2/modest-osso-autosave-callbacks.c | 2 +- src/hildon2/modest-osso-state-saving.c | 2 +- src/hildon2/modest-platform.c | 4 +- 13 files changed, 470 insertions(+), 534 deletions(-) create mode 100644 src/hildon2/modest-country-picker.c create mode 100644 src/hildon2/modest-country-picker.h delete mode 100644 src/hildon2/modest-easysetup-country-combo-box.c delete mode 100644 src/hildon2/modest-easysetup-country-combo-box.h diff --git a/src/hildon2/Makefile.am b/src/hildon2/Makefile.am index d35d0c4..a412ae7 100644 --- a/src/hildon2/Makefile.am +++ b/src/hildon2/Makefile.am @@ -52,7 +52,7 @@ libmodest_ui_la_SOURCES= \ modest-account-view-window.c \ modest-default-account-settings-dialog.c \ modest-easysetup-wizard-dialog.h modest-easysetup-wizard-dialog.c \ - modest-easysetup-country-combo-box.h modest-easysetup-country-combo-box.c \ + modest-country-picker.h modest-country-picker.c \ modest-easysetup-provider-combo-box.h modest-easysetup-provider-combo-box.c \ modest-easysetup-servertype-combo-box.h modest-easysetup-servertype-combo-box.c \ modest-icon-names.h \ diff --git a/src/hildon2/modest-country-picker.c b/src/hildon2/modest-country-picker.c new file mode 100644 index 0000000..f7ea929 --- /dev/null +++ b/src/hildon2/modest-country-picker.c @@ -0,0 +1,355 @@ +/* Copyright (c) 2008, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE /* So we can use the getline() function, which is a convenient GNU extension. */ +#endif + +#include + +#include "modest-maemo-utils.h" +#include "modest-country-picker.h" +#include +#include +#include + +#include +#include /* For memcpy() */ +#include +#include +#include /* For dgettext(). */ + +/* Include config.h so that _() works: */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#define MAX_LINE_LEN 128 /* max length of a line in MCC file */ + +G_DEFINE_TYPE (ModestCountryPicker, modest_country_picker, HILDON_TYPE_PICKER_BUTTON); + +typedef struct +{ + gint locale_mcc; +/* GtkTreeModel *model; */ +} ModestCountryPickerPrivate; + +#define MODEST_COUNTRY_PICKER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + MODEST_TYPE_COUNTRY_PICKER, \ + ModestCountryPickerPrivate)) + +static void +modest_country_picker_get_property (GObject *object, guint property_id, + GValue *value, GParamSpec *pspec) +{ + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +modest_country_picker_set_property (GObject *object, guint property_id, + const GValue *value, GParamSpec *pspec) +{ + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +modest_country_picker_dispose (GObject *object) +{ + if (G_OBJECT_CLASS (modest_country_picker_parent_class)->dispose) + G_OBJECT_CLASS (modest_country_picker_parent_class)->dispose (object); +} + +enum MODEL_COLS { + MODEL_COL_NAME = 0, /* string */ + MODEL_COL_MCC = 1 /* the 'effective mcc' for this country */ +}; + + +static void +modest_country_picker_finalize (GObject *object) +{ + G_OBJECT_CLASS (modest_country_picker_parent_class)->finalize (object); +} + +static void +modest_country_picker_class_init (ModestCountryPickerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (ModestCountryPickerPrivate)); + + object_class->get_property = modest_country_picker_get_property; + object_class->set_property = modest_country_picker_set_property; + object_class->dispose = modest_country_picker_dispose; + object_class->finalize = modest_country_picker_finalize; +} + + + + +/* cluster mcc's, based on the list + * http://en.wikipedia.org/wiki/Mobile_country_code + */ +static int +effective_mcc (gint mcc) +{ + switch (mcc) { + case 405: return 404; /* india */ + case 441: return 440; /* japan */ + case 235: return 234; /* united kingdom */ + case 311: + case 312: + case 313: + case 314: + case 315: + case 316: return 310; /* united states */ + default: return 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 + + also note, this function will return the "effective mcc", which + is the normalized mcc for a country - ie. even if the there + are multiple entries for the United States with various mccs, + this function will always return 310, even if the real mcc parsed + would be 314. see the 'effective_mcc' function above. +*/ +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]; + + 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]; + mcc[3] = '\0'; + + *country = my_country; + + return effective_mcc ((int) strtol ((const char*)mcc, NULL, 10)); +} + +/** Note that the mcc_mapping file is installed + * by the operator-wizard-settings package. + */ +static void +load_from_file (ModestCountryPicker *self, GtkListStore *liststore) +{ + ModestCountryPickerPrivate *priv = MODEST_COUNTRY_PICKER_GET_PRIVATE (self); + + 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"); + return; + } + + while (fgets (line, MAX_LINE_LEN, file) != NULL) { + + 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; + } + + if (mcc == previous_mcc) { + /* g_warning ("already seen: %s", line); */ + continue; + } + 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; + } + 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); + + /* 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 +modest_country_picker_init (ModestCountryPicker *self) +{ + ModestCountryPickerPrivate *priv = MODEST_COUNTRY_PICKER_GET_PRIVATE (self); + priv->locale_mcc = 0; +} + +void +modest_country_picker_load_data(ModestCountryPicker *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. + */ + model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT); + + /* Country column: + * The ID model column in not shown in the view. */ + GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); + + GtkWidget *selector = hildon_touch_selector_new (); + hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (self), HILDON_TOUCH_SELECTOR (selector)); + hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector), GTK_TREE_MODEL (model), + renderer, "text", MODEL_COL_NAME, NULL); + + /* Fill the model with rows: */ + load_from_file (self, model); + + /* Set this _after_ loading from file, it makes loading faster */ + hildon_touch_selector_set_model (HILDON_TOUCH_SELECTOR (selector), + 0, GTK_TREE_MODEL (model)); +} + +ModestCountryPicker* +modest_country_picker_new (void) +{ + return g_object_new (MODEST_TYPE_COUNTRY_PICKER, + "arrangement", HILDON_BUTTON_ARRANGEMENT_VERTICAL, + "size", HILDON_SIZE_AUTO, + NULL); +} + +/** + * Returns the MCC number of the selected country, or 0 if no country was selected. + */ +gint +modest_country_picker_get_active_country_mcc (ModestCountryPicker *self) +{ + GtkTreeIter active; + gboolean found; + + found = hildon_touch_selector_get_selected (hildon_picker_button_get_selector + (HILDON_PICKER_BUTTON (self)), 0, &active); + if (found) { + gint mcc = 0; + gtk_tree_model_get (hildon_touch_selector_get_model (hildon_picker_button_get_selector + (HILDON_PICKER_BUTTON (self)), + 0), + &active, MODEL_COL_MCC, &mcc, -1); + return mcc; + } + return 0; /* Failed. */ +} + + +/** + * Selects the MCC number of the selected country. + * Specify 0 to select no country. + */ +gboolean +modest_country_picker_set_active_country_locale (ModestCountryPicker *self) +{ + ModestCountryPickerPrivate *priv = MODEST_COUNTRY_PICKER_GET_PRIVATE (self); + GtkTreeIter iter; + gint current_mcc; + GtkTreeModel *model; + + model = hildon_touch_selector_get_model (hildon_picker_button_get_selector + (HILDON_PICKER_BUTTON (self)), 0); + if (!gtk_tree_model_get_iter_first (model, &iter)) + return FALSE; + do { + gtk_tree_model_get (model, &iter, MODEL_COL_MCC, ¤t_mcc, -1); + if (priv->locale_mcc == current_mcc) { + hildon_touch_selector_select_iter (hildon_picker_button_get_selector + (HILDON_PICKER_BUTTON (self)), 0, + &iter, TRUE); + return TRUE; + } + } while (gtk_tree_model_iter_next (model, &iter)); + + return FALSE; /* not found */ +} + diff --git a/src/hildon2/modest-country-picker.h b/src/hildon2/modest-country-picker.h new file mode 100644 index 0000000..a091d7e --- /dev/null +++ b/src/hildon2/modest-country-picker.h @@ -0,0 +1,80 @@ +/* Copyright (c) 2008, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MODEST_COUNTRY_PICKER +#define _MODEST_COUNTRY_PICKER + +#include + +G_BEGIN_DECLS + +#define MODEST_TYPE_COUNTRY_PICKER modest_country_picker_get_type() + +#define MODEST_COUNTRY_PICKER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + MODEST_TYPE_COUNTRY_PICKER, ModestCountryPicker)) + +#define MODEST_COUNTRY_PICKER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + MODEST_TYPE_COUNTRY_PICKER, ModestCountryPickerClass)) + +#define MODEST_IS_COUNTRY_PICKER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + MODEST_TYPE_COUNTRY_PICKER)) + +#define MODEST_IS_COUNTRY_PICKER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + MODEST_TYPE_COUNTRY_PICKER)) + +#define MODEST_COUNTRY_PICKER_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + MODEST_TYPE_COUNTRY_PICKER, ModestCountryPickerClass)) + +typedef struct { + HildonPickerButton parent; +} ModestCountryPicker; + +typedef struct { + HildonPickerButtonClass parent_class; +} ModestCountryPickerClass; + +GType modest_country_picker_get_type (void); + +ModestCountryPicker* modest_country_picker_new (void); + +void modest_country_picker_load_data(ModestCountryPicker *self); + +gint modest_country_picker_get_active_country_mcc (ModestCountryPicker *self); + + +gboolean modest_country_picker_set_active_country_locale (ModestCountryPicker *self); + +G_END_DECLS + +#endif /* _MODEST_COUNTRY_PICKER */ diff --git a/src/hildon2/modest-default-account-settings-dialog.c b/src/hildon2/modest-default-account-settings-dialog.c index bdfb231..54a6a3c 100644 --- a/src/hildon2/modest-default-account-settings-dialog.c +++ b/src/hildon2/modest-default-account-settings-dialog.c @@ -51,12 +51,12 @@ #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */ #include #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */ -#include "maemo/modest-connection-specific-smtp-window.h" -#include "maemo/modest-signature-editor-dialog.h" +#include "modest-connection-specific-smtp-window.h" +#include "modest-signature-editor-dialog.h" #include #include -#include "maemo/modest-maemo-utils.h" -#include "maemo/modest-maemo-security-options-view.h" +#include "modest-maemo-utils.h" +#include "modest-maemo-security-options-view.h" #include "widgets/modest-ui-constants.h" #include #include diff --git a/src/hildon2/modest-easysetup-country-combo-box.c b/src/hildon2/modest-easysetup-country-combo-box.c deleted file mode 100644 index 683c365..0000000 --- a/src/hildon2/modest-easysetup-country-combo-box.c +++ /dev/null @@ -1,394 +0,0 @@ -/* Copyright (c) 2006, Nokia Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Nokia Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE /* So we can use the getline() function, which is a convenient GNU extension. */ -#endif - -#include - -#include "modest-maemo-utils.h" -#include "modest-easysetup-country-combo-box.h" -#include -#include -#include - -#include -#include /* For memcpy() */ -#include -#include -#include /* For dgettext(). */ - -/* Include config.h so that _() works: */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#define MAX_LINE_LEN 128 /* max length of a line in MCC file */ - -#if MODEST_HILDON_API < 2 -G_DEFINE_TYPE (EasysetupCountryComboBox, easysetup_country_combo_box, GTK_TYPE_COMBO_BOX); -#else -G_DEFINE_TYPE (EasysetupCountryComboBox, easysetup_country_combo_box, HILDON_TYPE_PICKER_BUTTON); -#endif - -typedef struct -{ - gint locale_mcc; -/* GtkTreeModel *model; */ -} ModestEasysetupCountryComboBoxPrivate; - -#define MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX, \ - ModestEasysetupCountryComboBoxPrivate)) - -static void -easysetup_country_combo_box_get_property (GObject *object, guint property_id, - GValue *value, GParamSpec *pspec) -{ - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -easysetup_country_combo_box_set_property (GObject *object, guint property_id, - const GValue *value, GParamSpec *pspec) -{ - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -easysetup_country_combo_box_dispose (GObject *object) -{ - if (G_OBJECT_CLASS (easysetup_country_combo_box_parent_class)->dispose) - G_OBJECT_CLASS (easysetup_country_combo_box_parent_class)->dispose (object); -} - -enum MODEL_COLS { - MODEL_COL_NAME = 0, /* string */ - MODEL_COL_MCC = 1 /* the 'effective mcc' for this country */ -}; - - -static void -easysetup_country_combo_box_finalize (GObject *object) -{ - G_OBJECT_CLASS (easysetup_country_combo_box_parent_class)->finalize (object); -} - -static void -easysetup_country_combo_box_class_init (EasysetupCountryComboBoxClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (ModestEasysetupCountryComboBoxPrivate)); - - object_class->get_property = easysetup_country_combo_box_get_property; - object_class->set_property = easysetup_country_combo_box_set_property; - object_class->dispose = easysetup_country_combo_box_dispose; - object_class->finalize = easysetup_country_combo_box_finalize; -} - - - - -/* cluster mcc's, based on the list - * http://en.wikipedia.org/wiki/Mobile_country_code - */ -static int -effective_mcc (gint mcc) -{ - switch (mcc) { - case 405: return 404; /* india */ - case 441: return 440; /* japan */ - case 235: return 234; /* united kingdom */ - case 311: - case 312: - case 313: - case 314: - case 315: - case 316: return 310; /* united states */ - default: return 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 - - also note, this function will return the "effective mcc", which - is the normalized mcc for a country - ie. even if the there - are multiple entries for the United States with various mccs, - this function will always return 310, even if the real mcc parsed - would be 314. see the 'effective_mcc' function above. -*/ -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]; - - 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]; - mcc[3] = '\0'; - - *country = my_country; - - return effective_mcc ((int) strtol ((const char*)mcc, NULL, 10)); -} - -/** Note that the mcc_mapping file is installed - * by the operator-wizard-settings package. - */ -static void -load_from_file (EasysetupCountryComboBox *self, GtkListStore *liststore) -{ - ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self); - - 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"); - return; - } - - while (fgets (line, MAX_LINE_LEN, file) != NULL) { - - 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; - } - - if (mcc == previous_mcc) { - /* g_warning ("already seen: %s", line); */ - continue; - } - 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; - } - 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); - - /* 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->locale_mcc = 0; -} - -void -easysetup_country_combo_box_load_data(EasysetupCountryComboBox *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. - */ - model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT); - - /* Country column: - * The ID model column in not shown in the view. */ - GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); - -#if MODEST_HILDON_API < 2 - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (self), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self), renderer, - "text", MODEL_COL_NAME, NULL); -#else - GtkWidget *selector = hildon_touch_selector_new (); - hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (self), HILDON_TOUCH_SELECTOR (selector)); - hildon_touch_selector_append_column (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (self)), - GTK_TREE_MODEL (model), - renderer, "text", MODEL_COL_NAME, NULL); -#endif - - /* Fill the model with rows: */ - load_from_file (self, model); - - /* Set this _after_ loading from file, it makes loading faster */ -#if MODEST_HILDON_API < 2 - gtk_combo_box_set_model (GTK_COMBO_BOX (self), GTK_TREE_MODEL (model)); -#else - hildon_touch_selector_set_model (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (self)), - 0, GTK_TREE_MODEL (model)); -#endif -} - -EasysetupCountryComboBox* -easysetup_country_combo_box_new (void) -{ -#if MODEST_HILDON_API >= 2 - return g_object_new (MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX, - "arrangement", HILDON_BUTTON_ARRANGEMENT_VERTICAL, - "size", HILDON_SIZE_AUTO, - NULL); -#else - return g_object_new (MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX, - NULL); -#endif -} - -/** - * Returns the MCC number of the selected country, or 0 if no country was selected. - */ -gint -easysetup_country_combo_box_get_active_country_mcc (EasysetupCountryComboBox *self) -{ - GtkTreeIter active; - gboolean found; - -#if MODEST_HILDON_API < 2 - found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &active); -#else - found = hildon_touch_selector_get_selected (hildon_picker_button_get_selector - (HILDON_PICKER_BUTTON (self)), 0, &active); -#endif - if (found) { - gint mcc = 0; -#if MODEST_HILDON_API < 2 - gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (self)), - &active, MODEL_COL_MCC, &mcc, -1); -#else - gtk_tree_model_get (hildon_touch_selector_get_model (hildon_picker_button_get_selector - (HILDON_PICKER_BUTTON (self)), - 0), - &active, MODEL_COL_MCC, &mcc, -1); -#endif - return mcc; - } - return 0; /* Failed. */ -} - - -/** - * Selects the MCC number of the selected country. - * Specify 0 to select no country. - */ -gboolean -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 MODEST_HILDON_API < 2 - model = gtk_combo_box_get_model (GTK_COMBO_BOX (self)); - g_message ("HILDON < 2"); -#else - model = hildon_touch_selector_get_model (hildon_picker_button_get_selector - (HILDON_PICKER_BUTTON (self)), 0); - g_message ("HILDON >= 2"); -#endif - if (!gtk_tree_model_get_iter_first (model, &iter)) - return FALSE; - do { - gtk_tree_model_get (model, &iter, MODEL_COL_MCC, ¤t_mcc, -1); - if (priv->locale_mcc == current_mcc) { -#if MODEST_HILDON_API < 2 - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter); -#else - hildon_touch_selector_select_iter (hildon_picker_button_get_selector - (HILDON_PICKER_BUTTON (self)), 0, - &iter, TRUE); -#endif - return TRUE; - } - } while (gtk_tree_model_iter_next (model, &iter)); - - return FALSE; /* not found */ -} - diff --git a/src/hildon2/modest-easysetup-country-combo-box.h b/src/hildon2/modest-easysetup-country-combo-box.h deleted file mode 100644 index 56f1741..0000000 --- a/src/hildon2/modest-easysetup-country-combo-box.h +++ /dev/null @@ -1,93 +0,0 @@ -/* Copyright (c) 2006, Nokia Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Nokia Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _MODEST_EASYSETUP_COUNTRY_COMBO_BOX -#define _MODEST_EASYSETUP_COUNTRY_COMBO_BOX - -#if MODEST_HILDON_API < 2 -#include -#else -#include -#endif - -G_BEGIN_DECLS - -#define MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX easysetup_country_combo_box_get_type() - -#define MODEST_EASYSETUP_COUNTRY_COMBO_BOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX, EasysetupCountryComboBox)) - -#define MODEST_EASYSETUP_COUNTRY_COMBO_BOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX, EasysetupCountryComboBoxClass)) - -#define MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX)) - -#define MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX)) - -#define MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX, EasysetupCountryComboBoxClass)) - -#if MODEST_HILDON_API < 2 -typedef struct { - GtkComboBox parent; -} EasysetupCountryComboBox; - -typedef struct { - GtkComboBoxClass parent_class; -} EasysetupCountryComboBoxClass; -#else -typedef struct { - HildonPickerButton parent; -} EasysetupCountryComboBox; - -typedef struct { - HildonPickerButtonClass parent_class; -} EasysetupCountryComboBoxClass; -#endif -GType easysetup_country_combo_box_get_type (void); - -EasysetupCountryComboBox* easysetup_country_combo_box_new (void); - -void easysetup_country_combo_box_load_data(EasysetupCountryComboBox *self); - -gint easysetup_country_combo_box_get_active_country_mcc (EasysetupCountryComboBox *self); - - -gboolean easysetup_country_combo_box_set_active_country_locale (EasysetupCountryComboBox *self); - -G_END_DECLS - -#endif /* _MODEST_EASYSETUP_COUNTRY_COMBO_BOX */ diff --git a/src/hildon2/modest-easysetup-wizard-dialog.c b/src/hildon2/modest-easysetup-wizard-dialog.c index 9e61d43..a4ae4b7 100644 --- a/src/hildon2/modest-easysetup-wizard-dialog.c +++ b/src/hildon2/modest-easysetup-wizard-dialog.c @@ -40,9 +40,9 @@ #include #include #include -#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 "modest-country-picker.h" +#include "modest-easysetup-provider-combo-box.h" +#include "modest-easysetup-servertype-combo-box.h" #include "widgets/modest-validating-entry.h" #include "modest-text-utils.h" #include "modest-conf.h" @@ -51,14 +51,14 @@ #include "modest-signal-mgr.h" #include "modest-account-mgr-helpers.h" #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */ -#include "maemo/modest-connection-specific-smtp-window.h" +#include "modest-connection-specific-smtp-window.h" #include "widgets/modest-ui-constants.h" #include "widgets/modest-default-account-settings-dialog.h" #include "widgets/modest-easysetup-wizard-page.h" -#include "maemo/modest-maemo-utils.h" +#include "modest-maemo-utils.h" #include "modest-utils.h" -#include "maemo/modest-hildon-includes.h" -#include "maemo/modest-maemo-security-options-view.h" +#include "modest-hildon-includes.h" +#include "modest-maemo-security-options-view.h" #include /* Include config.h so that _() works: */ @@ -103,7 +103,7 @@ struct _ModestEasysetupWizardDialogPrivate GtkWidget *page_welcome; GtkWidget *page_account_details; - GtkWidget *combo_account_country; + GtkWidget *account_country_picker; GtkWidget *combo_account_serviceprovider; GtkWidget *entry_account_title; @@ -390,13 +390,8 @@ create_page_welcome (ModestEasysetupWizardDialog *self) return GTK_WIDGET (box); } -#if MODEST_HILDON_API < 2 static void -on_combo_account_country (GtkComboBox *widget, gpointer user_data) -#else -static void -on_combo_account_country (HildonTouchSelector *widget, gint column, gpointer user_data) -#endif +on_account_country_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data) { ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); g_assert(self); @@ -406,8 +401,8 @@ on_combo_account_country (HildonTouchSelector *widget, gint column, gpointer use /* Fill the providers combo, based on the selected country: */ if (priv->presets != NULL) { - gint mcc = easysetup_country_combo_box_get_active_country_mcc ( - MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country)); + gint mcc = modest_country_picker_get_active_country_mcc ( + MODEST_COUNTRY_PICKER (priv->account_country_picker)); easysetup_provider_combo_box_fill ( EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider), priv->presets, mcc); } @@ -466,23 +461,18 @@ create_page_account_details (ModestEasysetupWizardDialog *self) GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); /* The country widgets: */ - priv->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ()); + priv->account_country_picker = GTK_WIDGET (modest_country_picker_new ()); GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"), - priv->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL); - gtk_widget_show (priv->combo_account_country); + priv->account_country_picker, NULL, HILDON_CAPTION_OPTIONAL); + gtk_widget_show (priv->account_country_picker); gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF); gtk_widget_show (caption); /* connect to country combo's changed signal, so we can fill the provider combo: */ -#if MODEST_HILDON_API < 2 - g_signal_connect (G_OBJECT (priv->combo_account_country), "changed", - G_CALLBACK (on_combo_account_country), self); -#else g_signal_connect (G_OBJECT (hildon_picker_button_get_selector - (HILDON_PICKER_BUTTON (priv->combo_account_country))), + (HILDON_PICKER_BUTTON (priv->account_country_picker))), "changed", - G_CALLBACK (on_combo_account_country), self); -#endif + G_CALLBACK (on_account_country_selector_changed), self); GtkWidget *separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF); @@ -1119,18 +1109,16 @@ presets_idle (gpointer userdata) priv->presets = idle_data->presets; - if (MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX (priv->combo_account_country)) { + if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) { /* 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_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)); + modest_country_picker_load_data( + MODEST_COUNTRY_PICKER (priv->account_country_picker)); + modest_country_picker_set_active_country_locale ( + MODEST_COUNTRY_PICKER (priv->account_country_picker)); + mcc = modest_country_picker_get_active_country_mcc ( + MODEST_COUNTRY_PICKER (priv->account_country_picker)); easysetup_provider_combo_box_fill ( EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider), priv->presets, mcc); diff --git a/src/hildon2/modest-maemo-global-settings-dialog.c b/src/hildon2/modest-maemo-global-settings-dialog.c index 3d192ea..6d96477 100644 --- a/src/hildon2/modest-maemo-global-settings-dialog.c +++ b/src/hildon2/modest-maemo-global-settings-dialog.c @@ -45,7 +45,7 @@ #include "modest-runtime.h" #include "widgets/modest-global-settings-dialog-priv.h" #include "widgets/modest-combo-box.h" -#include "maemo/modest-maemo-global-settings-dialog.h" +#include "modest-maemo-global-settings-dialog.h" #include "widgets/modest-ui-constants.h" #include diff --git a/src/hildon2/modest-maemo-security-options-view.c b/src/hildon2/modest-maemo-security-options-view.c index 8593897..5d7dbde 100644 --- a/src/hildon2/modest-maemo-security-options-view.c +++ b/src/hildon2/modest-maemo-security-options-view.c @@ -37,7 +37,7 @@ #include "widgets/modest-validating-entry.h" #include "widgets/modest-serversecurity-combo-box.h" #include "widgets/modest-secureauth-combo-box.h" -#include "maemo/easysetup/modest-easysetup-servertype-combo-box.h" +#include "modest-easysetup-servertype-combo-box.h" #ifdef MODEST_HAVE_HILDON0_WIDGETS #include #include diff --git a/src/hildon2/modest-main-window.c b/src/hildon2/modest-main-window.c index e252f7f..07071b5 100644 --- a/src/hildon2/modest-main-window.c +++ b/src/hildon2/modest-main-window.c @@ -61,7 +61,7 @@ #include "modest-progress-bar.h" #include "modest-text-utils.h" #include "modest-ui-dimming-manager.h" -#include "maemo/modest-osso-state-saving.h" +#include "modest-osso-state-saving.h" #include "modest-text-utils.h" #include "modest-signal-mgr.h" diff --git a/src/hildon2/modest-osso-autosave-callbacks.c b/src/hildon2/modest-osso-autosave-callbacks.c index e58ef7e..e51e4db 100644 --- a/src/hildon2/modest-osso-autosave-callbacks.c +++ b/src/hildon2/modest-osso-autosave-callbacks.c @@ -28,7 +28,7 @@ */ -#include +#include void modest_on_osso_application_autosave(gpointer data) { diff --git a/src/hildon2/modest-osso-state-saving.c b/src/hildon2/modest-osso-state-saving.c index 03a8f15..13e420b 100644 --- a/src/hildon2/modest-osso-state-saving.c +++ b/src/hildon2/modest-osso-state-saving.c @@ -28,7 +28,7 @@ */ -#include +#include #include "modest-runtime.h" #include diff --git a/src/hildon2/modest-platform.c b/src/hildon2/modest-platform.c index 06ece71..be10a10 100644 --- a/src/hildon2/modest-platform.c +++ b/src/hildon2/modest-platform.c @@ -33,12 +33,12 @@ #include #include #include -#include "maemo/modest-maemo-global-settings-dialog.h" +#include "modest-maemo-global-settings-dialog.h" #include "modest-widget-memory.h" #include #include #include -#include +#include #include #include #include -- 1.7.9.5