Fixes NB#131102, fixes a small memory leak
[modest] / src / widgets / modest-details-dialog.c
index 5bb6dae..8242c34 100644 (file)
 #include <string.h> /* for strlen */
 
 static void    modest_details_dialog_set_header_default          (ModestDetailsDialog *self,
-                                                                 TnyHeader *header);
+                                                                 TnyHeader *header,
+                                                                 gboolean get_size);
 
 static void    modest_details_dialog_set_folder_default          (ModestDetailsDialog *self,
                                                                  TnyFolder *foler);
 
+static void    modest_details_dialog_set_message_size_default    (ModestDetailsDialog *self, 
+                                                                 guint message_size);
+
 static void    modest_details_dialog_create_container_default    (ModestDetailsDialog *self);
 
 static void    modest_details_dialog_add_data_default            (ModestDetailsDialog *self,
@@ -90,6 +94,7 @@ modest_details_dialog_class_init (ModestDetailsDialogClass *klass)
        klass->create_container_func = modest_details_dialog_create_container_default;
        klass->add_data_func = modest_details_dialog_add_data_default;
        klass->set_header_func = modest_details_dialog_set_header_default;
+       klass->set_message_size_func = modest_details_dialog_set_message_size_default;
        klass->set_folder_func = modest_details_dialog_set_folder_default;
 }
 
@@ -100,7 +105,8 @@ modest_details_dialog_init (ModestDetailsDialog *self)
 
 GtkWidget*
 modest_details_dialog_new_with_header (GtkWindow *parent, 
-                                      TnyHeader *header)
+                                      TnyHeader *header,
+                                      gboolean get_size)
 {
        ModestDetailsDialog *dialog;
 
@@ -112,7 +118,7 @@ modest_details_dialog_new_with_header (GtkWindow *parent,
                                                        NULL));
 
        MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->create_container_func (dialog);
-       MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->set_header_func (dialog, header);
+       MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->set_header_func (dialog, header, get_size);
 
        /* Add close button */
        gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_close"), GTK_RESPONSE_CLOSE);
@@ -150,6 +156,13 @@ modest_details_dialog_add_data (ModestDetailsDialog *self,
        MODEST_DETAILS_DIALOG_GET_CLASS (self)->add_data_func (self, label, value);
 }
 
+void
+modest_details_dialog_set_message_size (ModestDetailsDialog *self,
+                                       guint size)
+{
+       MODEST_DETAILS_DIALOG_GET_CLASS (self)->set_message_size_func (self, size);
+}
+
 static void
 modest_details_dialog_add_data_default (ModestDetailsDialog *self,
                                        const gchar *label,
@@ -190,12 +203,24 @@ modest_details_dialog_add_data_default (ModestDetailsDialog *self,
                          0, 0);
 }
 
+static void 
+replace_recipients (gchar **recipients)
+{
+
+       gchar *result;
+
+       result = modest_text_utils_simplify_recipients (*recipients);
+
+       g_free (*recipients);
+       *recipients = result;
+}
 
 static void
 modest_details_dialog_set_header_default (ModestDetailsDialog *self,
-                                         TnyHeader *header)
+                                         TnyHeader *header,
+                                         gboolean get_size)
 {
-       gchar *from, *subject, *to, *cc;
+       gchar *from = NULL, *subject = NULL, *to = NULL, *cc = NULL, *bcc = NULL;
        time_t received, sent;
        guint size;
        gchar *size_s;
@@ -205,7 +230,7 @@ modest_details_dialog_set_header_default (ModestDetailsDialog *self,
        const gchar *date_time_str;
 
        datetime_formatter = modest_datetime_formatter_new ();
-       
+
        /* Set window title */
        gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_message_properties"));
 
@@ -218,24 +243,31 @@ modest_details_dialog_set_header_default (ModestDetailsDialog *self,
        }
 
        g_return_if_fail (folder_type != TNY_FOLDER_TYPE_INVALID);
-       
+
        /* Get header data */
        from = tny_header_dup_from (header);
        to = tny_header_dup_to (header);
        subject = tny_header_dup_subject (header);
        cc = tny_header_dup_cc (header);
+       bcc = tny_header_dup_bcc (header);
        received = tny_header_get_date_received (header);
        sent = tny_header_get_date_sent (header);
-       size = tny_header_get_message_size (header);
+       if (get_size) {
+               size = tny_header_get_message_size (header);
+       } else {
+               size = -1;
+       }
 
-       if (from == NULL)
-               from = g_strdup ("");
-       if (to == NULL)
-               to = g_strdup ("");
+       replace_recipients (&from);
+       replace_recipients (&to);
+       replace_recipients (&cc);
        if (subject == NULL)
                subject = g_strdup ("");
-       if (cc == NULL)
-               cc = g_strdup ("");
+
+       if (!strcmp (subject, "")) {
+               g_free (subject);
+               subject = g_strdup (_("mail_va_no_subject"));
+       }
 
        /* Add from and subject for all folders */
        modest_details_dialog_add_data (self, _("mcen_fi_message_properties_from"), from);
@@ -248,7 +280,7 @@ modest_details_dialog_set_header_default (ModestDetailsDialog *self,
            (folder_type != TNY_FOLDER_TYPE_OUTBOX)) {
                date_time_str = modest_datetime_formatter_display_long_datetime (datetime_formatter, 
                                                                            received);
-               
+
                modest_details_dialog_add_data (self, _("mcen_fi_message_properties_received"),
                                                date_time_str);
        }
@@ -278,10 +310,18 @@ modest_details_dialog_set_header_default (ModestDetailsDialog *self,
        if (cc && strlen(cc) > 0)
                modest_details_dialog_add_data (self, _("mcen_fi_message_properties_cc"), cc);
 
+       /* only show cc when it's there */
+       if (bcc && strlen(bcc) > 0) {
+               replace_recipients (&bcc);
+               modest_details_dialog_add_data (self, _("mcen_fi_message_properties_bcc"), bcc);
+       }
+
        /* Set size */
-       size_s = modest_text_utils_get_display_size (size);
-       modest_details_dialog_add_data (self, _("mcen_fi_message_properties_size"), size_s);
-       g_free (size_s);
+       if (get_size) {
+               size_s = modest_text_utils_get_display_size (size);
+               modest_details_dialog_add_data (self, _("mcen_fi_message_properties_size"), size_s);
+               g_free (size_s);
+       }
 
        /* Frees */
        g_object_unref (datetime_formatter);
@@ -289,6 +329,18 @@ modest_details_dialog_set_header_default (ModestDetailsDialog *self,
        g_free (from);
        g_free (subject);
        g_free (cc);
+       g_free (bcc);
+}
+
+static void
+modest_details_dialog_set_message_size_default (ModestDetailsDialog *self,
+                                               guint size)
+{
+       gchar *size_s;
+       size_s = modest_text_utils_get_display_size (size);
+       modest_details_dialog_add_data (self, _("mcen_fi_message_properties_size"), size_s);
+       g_free (size_s);
+       gtk_widget_show_all (GTK_WIDGET (self));
 }
 
 static void