* Embedded messages without a filename shows their subject in save/remove attachments...
[modest] / src / hildon2 / modest-maemo-utils.c
index 0dcdf0b..0ef4d77 100644 (file)
@@ -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;
 }
 
@@ -252,6 +260,7 @@ modest_maemo_utils_create_captioned_with_size_type    (GtkSizeGroup *title_size_
                                                       HildonSizeType size_type)
 {
        GtkWidget *label;
+       GtkWidget *align;
        GtkWidget *box;
   
        if (use_markup) {
@@ -260,14 +269,18 @@ modest_maemo_utils_create_captioned_with_size_type    (GtkSizeGroup *title_size_
        } else {
                label = gtk_label_new (title);
        }
+       align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+       gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_TRIPLE);
 
        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
        hildon_gtk_widget_set_theme_size (label, HILDON_SIZE_FINGER_HEIGHT);
        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
        gtk_widget_show (label);
-       box = gtk_hbox_new (FALSE, MODEST_MARGIN_HALF);
-       gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_box_pack_start (GTK_BOX (box), control, TRUE, TRUE, MODEST_MARGIN_HALF);
+       gtk_widget_show (align);
+       box = gtk_hbox_new (FALSE, 0);
+       gtk_container_add (GTK_CONTAINER (align), label);
+       gtk_box_pack_start (GTK_BOX (box), align, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (box), control, TRUE, TRUE, 0);
        if (title_size_group)
                gtk_size_group_add_widget (title_size_group, label);
        if (value_size_group)
@@ -375,7 +388,7 @@ static gboolean match_all (TnyList *list, GObject *item, gpointer match_data)
 }
 
 gboolean
-modest_maemo_utils_select_attachments (GtkWindow *window, TnyList *att_list)
+modest_maemo_utils_select_attachments (GtkWindow *window, TnyList *att_list, gboolean include_msgs)
 {
        GtkTreeModel *model;
        TnyIterator *iterator;
@@ -391,15 +404,23 @@ modest_maemo_utils_select_attachments (GtkWindow *window, TnyList *att_list)
             tny_iterator_next (iterator)) {
                GtkTreeIter iter;
                TnyMimePart *part;
+               gchar *label;
+               gchar *filename = NULL;
 
                part = (TnyMimePart *) tny_iterator_get_current (iterator);
 
-               /* Embbeded messages are not offered to be saved */
-               if (!TNY_IS_MSG (part)) {
-                       gchar *label;
-                       gchar *filename = NULL;
-
-                       filename = g_strdup (tny_mime_part_get_filename (part));
+               /* Ignore purged attachments and messages if ignore is
+                  set to TRUE */
+               if (!(tny_mime_part_is_purged (part) ||
+                     (TNY_IS_MSG (part) && !include_msgs))) {
+
+                       if (TNY_IS_MSG (part)) {
+                               TnyHeader *header = tny_msg_get_header (TNY_MSG (part));
+                               filename = tny_header_dup_subject (header);
+                               g_object_unref (header);
+                       } else {
+                               filename = g_strdup (tny_mime_part_get_filename (part));
+                       }
                        label = g_strconcat (filename, NULL);
                        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
                        gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, label, 1, part, -1);