- sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_priority"),
- SORT_ID_NUM);
- sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN;
- sort_ids[sort_key] = TNY_HEADER_FLAG_PRIORITY_MASK;
- priority_sort_id = sort_key;
-
- sortable = GTK_TREE_SORTABLE (gtk_tree_model_filter_get_model
- (GTK_TREE_MODEL_FILTER (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)))));
- /* Launch dialogs */
- if (!gtk_tree_sortable_get_sort_column_id (sortable,
- ¤t_sort_colid, ¤t_sort_type)) {
- modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), default_key);
- modest_sort_criterium_view_set_sort_order (MODEST_SORT_CRITERIUM_VIEW (dialog), GTK_SORT_DESCENDING);
- } else {
- modest_sort_criterium_view_set_sort_order (MODEST_SORT_CRITERIUM_VIEW (dialog), current_sort_type);
- if (current_sort_colid == TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN) {
- gpointer flags_sort_type_pointer;
- flags_sort_type_pointer = g_object_get_data (G_OBJECT (cols->data), MODEST_HEADER_VIEW_FLAG_SORT);
- if (GPOINTER_TO_INT (flags_sort_type_pointer) == TNY_HEADER_FLAG_PRIORITY_MASK)
- modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), priority_sort_id);
- else
- modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), attachments_sort_id);
- } else {
- gint current_sort_keyid = 0;
- while (current_sort_keyid < 6) {
- if (sort_model_ids[current_sort_keyid] == current_sort_colid)
- break;
- else
- current_sort_keyid++;
+#define MCC_FILE_MAX_LINE_LEN 128 /* max length of a line in MCC file */
+
+/** Note that the mcc_mapping file is installed
+ * by the operator-wizard-settings package.
+ */
+GtkTreeModel *
+modest_utils_create_country_model (void)
+{
+ GtkTreeModel *model;
+
+ model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT));
+
+ return model;
+}
+
+void
+modest_utils_fill_country_model (GtkTreeModel *model, gint *locale_mcc)
+{
+ gboolean translated;
+ char line[MCC_FILE_MAX_LINE_LEN];
+ guint previous_mcc = 0;
+ gchar *territory;
+ GHashTable *country_hash;
+ FILE *file;
+
+ /* First we need to know our current region */
+ file = modest_utils_open_mcc_mapping_file (FALSE, &translated);
+ if (!file) {
+ g_warning ("Could not open mcc_mapping file");
+ return;
+ }
+
+ /* Get the territory specified for the current locale */
+ territory = nl_langinfo (_NL_ADDRESS_COUNTRY_NAME);
+
+ while (fgets (line, MCC_FILE_MAX_LINE_LEN, file) != NULL) {
+ int mcc;
+ char *country = NULL;
+
+ 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 (!(*locale_mcc)) {
+ if (translated) {
+ if (!g_utf8_collate (country, territory))
+ *locale_mcc = mcc;
+ } else {
+ gchar *translation = dgettext ("osso-countries", country);
+ if (!g_utf8_collate (translation, territory))
+ *locale_mcc = mcc;