Refactored code in modest_text_utils_get_display_addresses to get a list of display...
[modest] / src / widgets / modest-compact-mail-header-view.c
index bf6c7d4..d248f03 100644 (file)
@@ -50,14 +50,11 @@ typedef struct _ModestCompactMailHeaderViewPriv ModestCompactMailHeaderViewPriv;
 struct _ModestCompactMailHeaderViewPriv
 {
        GtkWidget    *headers_vbox;
-       GtkWidget    *subject_box;
 
        GtkWidget    *fromto_label;
        GtkWidget    *fromto_contents;
-       GtkWidget    *priority_icon;
-       GtkWidget    *details_label;
+       GtkWidget    *time_label;
        GtkWidget    *date_label;
-       GtkWidget    *subject_label;
 
        GSList       *custom_labels;
 
@@ -67,6 +64,8 @@ struct _ModestCompactMailHeaderViewPriv
        TnyHeader    *header;
        TnyHeaderFlags priority_flags;
 
+       gboolean     is_loading;
+
        time_t       date_to_show;
        ModestDatetimeFormatter *datetime_formatter;
 };
@@ -94,6 +93,10 @@ static TnyHeaderFlags modest_compact_mail_header_view_get_priority_default (Mode
 static void modest_compact_mail_header_view_set_priority (ModestMailHeaderView *self, TnyHeaderFlags flags);
 static void modest_compact_mail_header_view_set_priority_default (ModestMailHeaderView *headers_view,
                                                                   TnyHeaderFlags flags);
+static gboolean modest_compact_mail_header_view_get_loading (ModestMailHeaderView *headers_view);
+static gboolean modest_compact_mail_header_view_get_loading_default (ModestMailHeaderView *headers_view);
+static void modest_compact_mail_header_view_set_loading (ModestMailHeaderView *headers_view, gboolean is_loading);
+static void modest_compact_mail_header_view_set_loading_default (ModestMailHeaderView *headers_view, gboolean is_loading);
 static const GtkWidget *modest_compact_mail_header_view_add_custom_header (ModestMailHeaderView *self,
                                                                            const gchar *label,
                                                                            GtkWidget *custom_widget,
@@ -107,7 +110,6 @@ static const GtkWidget *modest_compact_mail_header_view_add_custom_header_defaul
 
 /* internal */
 static void on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata);
-static void on_details_button_clicked  (GtkButton *button, gpointer userdata);
 static void update_style (ModestCompactMailHeaderView *self);
 static void set_date_time (ModestCompactMailHeaderView *compact_mail_header);
 static void fill_address (ModestCompactMailHeaderView *self);
@@ -129,8 +131,10 @@ set_date_time (ModestCompactMailHeaderView *compact_mail_header)
        buffer = g_string_append_c (buffer, ' ');
        date_str = modest_datetime_formatter_format_time (priv->datetime_formatter, priv->date_to_show);
        buffer = g_string_append (buffer, date_str);
-       buffer = g_string_append (buffer, "\n");
-       modest_text_utils_strftime (date_buf, BUF_SIZE, _HL("wdgt_va_date_long"), priv->date_to_show);
+       gtk_label_set_text (GTK_LABEL (priv->time_label), buffer->str);
+       g_string_free  (buffer, TRUE);
+       buffer = g_string_new ("");
+       modest_text_utils_strftime (date_buf, BUF_SIZE, _HL("wdgt_va_date_medium"), priv->date_to_show);
        buffer = g_string_append (buffer, date_buf);
 
        gtk_label_set_text (GTK_LABEL (priv->date_label), buffer->str);
@@ -208,11 +212,6 @@ modest_compact_mail_header_view_set_header_default (TnyHeaderView *self, TnyHead
 
                subject = tny_header_dup_subject (header);
 
-               if (subject && (subject[0] != '\0'))
-                       gtk_label_set_text (GTK_LABEL (priv->subject_label), subject);
-               else
-                       gtk_label_set_text (GTK_LABEL (priv->subject_label), _("mail_va_no_subject"));
-
                if (priv->is_outgoing && priv->is_draft) {
                        priv->date_to_show = tny_header_get_date_sent (header);
                } else {
@@ -325,42 +324,22 @@ modest_compact_mail_header_view_instance_init (GTypeInstance *instance, gpointer
 {
        ModestCompactMailHeaderView *self = (ModestCompactMailHeaderView *)instance;
        ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
-       GtkWidget *first_hbox, *second_hbox, *vbox, *main_vbox;
-       GtkWidget *details_button;
-       PangoAttrList *attr_list;
+       GtkWidget *from_date_hbox, *vbox, *main_vbox;
+       GtkWidget *main_align;
+       GtkWidget *headers_date_hbox;
 
        priv->header = NULL;
        priv->custom_labels = NULL;
 
        main_vbox = gtk_vbox_new (FALSE, 0);
        vbox = gtk_vbox_new (FALSE, 0);
-       first_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_HALF);
-
-       priv->subject_box = gtk_hbox_new (FALSE, MODEST_MARGIN_HALF);
 
        /* We set here the style for widgets using standard text color. For
         * widgets with secondary text color, we set them in update_style,
         * as we want to track the style changes and update the color properly */
 
-       priv->subject_label = gtk_label_new (NULL);
-       gtk_misc_set_alignment (GTK_MISC (priv->subject_label), 0.0, 1.0);
-       gtk_label_set_ellipsize (GTK_LABEL (priv->subject_label), PANGO_ELLIPSIZE_END);
-       attr_list = pango_attr_list_new ();
-       pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_LARGE));
-       gtk_label_set_attributes (GTK_LABEL (priv->subject_label), attr_list);
-       pango_attr_list_unref (attr_list);
-
-       details_button = gtk_button_new ();
-       priv->details_label = gtk_label_new (_("mcen_ti_message_properties"));
-       gtk_misc_set_alignment (GTK_MISC (priv->details_label), 1.0, 0.5);
-       gtk_container_add (GTK_CONTAINER (details_button), priv->details_label);
-       gtk_button_set_relief (GTK_BUTTON (details_button), GTK_RELIEF_NONE);
-
-       gtk_box_pack_end (GTK_BOX (priv->subject_box), priv->subject_label, TRUE, TRUE, 0);
-       gtk_box_pack_start (GTK_BOX (first_hbox), priv->subject_box, TRUE, TRUE, 0);
-       gtk_box_pack_start (GTK_BOX (first_hbox), details_button, FALSE, FALSE, 0);
-
-       second_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_DOUBLE);
+       from_date_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_DOUBLE);
+       headers_date_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_DOUBLE);
 
        priv->fromto_label = gtk_label_new (NULL);
        gtk_misc_set_alignment (GTK_MISC (priv->fromto_label), 0.0, 1.0);
@@ -371,22 +350,24 @@ modest_compact_mail_header_view_instance_init (GTypeInstance *instance, gpointer
 
        priv->date_label = gtk_label_new (NULL);
        gtk_label_set_justify (GTK_LABEL (priv->date_label), GTK_JUSTIFY_RIGHT);
-       gtk_misc_set_alignment (GTK_MISC (priv->date_label), 1.0, 1.0);
-       gtk_misc_set_padding (GTK_MISC (priv->date_label), MODEST_MARGIN_DEFAULT, 0);
+       gtk_misc_set_alignment (GTK_MISC (priv->date_label), 1.0, 0.0);
+       gtk_misc_set_padding (GTK_MISC (priv->date_label), MODEST_MARGIN_DOUBLE, 0);
 
-       gtk_box_pack_start (GTK_BOX (second_hbox), priv->fromto_label, FALSE, FALSE, 0);
-       gtk_box_pack_start (GTK_BOX (second_hbox), priv->fromto_contents, TRUE, TRUE, 0);
-       gtk_box_pack_start (GTK_BOX (second_hbox), priv->date_label, FALSE, FALSE, 0);
+       priv->time_label = gtk_label_new (NULL);
+       gtk_label_set_justify (GTK_LABEL (priv->time_label), GTK_JUSTIFY_RIGHT);
+       gtk_misc_set_alignment (GTK_MISC (priv->time_label), 1.0, 1.0);
+       gtk_misc_set_padding (GTK_MISC (priv->time_label), MODEST_MARGIN_DOUBLE, 0);
 
-       gtk_box_pack_start (GTK_BOX (vbox), first_hbox, FALSE, FALSE, 0);
-       gtk_box_pack_start (GTK_BOX (vbox), second_hbox, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (from_date_hbox), priv->fromto_label, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (from_date_hbox), priv->fromto_contents, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (from_date_hbox), priv->time_label, FALSE, FALSE, 0);
+
+       gtk_box_pack_start (GTK_BOX (vbox), from_date_hbox, FALSE, FALSE, 0);
 
        update_style (self);
 
        g_signal_connect (G_OBJECT (self), "notify::style", G_CALLBACK (on_notify_style), (gpointer) self);
 
-       g_signal_connect (G_OBJECT (details_button), "clicked", G_CALLBACK (on_details_button_clicked), instance);
-
        priv->datetime_formatter = modest_datetime_formatter_new ();
        g_signal_connect (G_OBJECT (priv->datetime_formatter), "format-changed", 
                          G_CALLBACK (datetime_format_changed), (gpointer) self);
@@ -396,15 +377,20 @@ modest_compact_mail_header_view_instance_init (GTypeInstance *instance, gpointer
        g_object_ref (priv->headers_vbox);
 
        gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
-       gtk_box_pack_start (GTK_BOX (main_vbox), priv->headers_vbox, FALSE, FALSE, 0);
-       gtk_box_pack_start (GTK_BOX (self), main_vbox, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (headers_date_hbox), priv->headers_vbox, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (headers_date_hbox), priv->date_label, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (main_vbox), headers_date_hbox, FALSE, FALSE, 0);
 
-       gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_DOUBLE);
+       main_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+       gtk_alignment_set_padding (GTK_ALIGNMENT (main_align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
+       gtk_container_add (GTK_CONTAINER (main_align), main_vbox);
+       gtk_box_pack_start (GTK_BOX (self), main_align, TRUE, TRUE, 0);
 
-       gtk_widget_show_all (main_vbox);
+       gtk_widget_show_all (main_align);
 
        priv->is_outgoing = FALSE;
        priv->is_draft = FALSE;
+       priv->is_loading = FALSE;
 
        return;
 }
@@ -457,6 +443,8 @@ modest_mail_header_view_init (gpointer g, gpointer iface_data)
 
        klass->get_priority = modest_compact_mail_header_view_get_priority;
        klass->set_priority = modest_compact_mail_header_view_set_priority;
+       klass->get_loading = modest_compact_mail_header_view_get_loading;
+       klass->set_loading = modest_compact_mail_header_view_set_loading;
        klass->add_custom_header = modest_compact_mail_header_view_add_custom_header;
 
        return;
@@ -474,6 +462,8 @@ modest_compact_mail_header_view_class_init (ModestCompactMailHeaderViewClass *kl
        klass->clear_func = modest_compact_mail_header_view_clear_default;
        klass->set_priority_func = modest_compact_mail_header_view_set_priority_default;
        klass->get_priority_func = modest_compact_mail_header_view_get_priority_default;
+       klass->set_loading_func = modest_compact_mail_header_view_set_loading_default;
+       klass->get_loading_func = modest_compact_mail_header_view_get_loading_default;
        klass->add_custom_header_func = modest_compact_mail_header_view_add_custom_header_default;
        object_class->finalize = modest_compact_mail_header_view_finalize;
 
@@ -564,21 +554,40 @@ modest_compact_mail_header_view_set_priority_default (ModestMailHeaderView *head
        priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
 
        priv->priority_flags = flags & TNY_HEADER_FLAG_PRIORITY_MASK ;
+}
 
-       if (priv->priority_flags == TNY_HEADER_FLAG_NORMAL_PRIORITY) {
-               if (priv->priority_icon != NULL) {
-                       gtk_widget_destroy (priv->priority_icon);
-                       priv->priority_icon = NULL;
-               }
-       } else if (priv->priority_flags == TNY_HEADER_FLAG_HIGH_PRIORITY) {
-               priv->priority_icon = gtk_image_new_from_icon_name (MODEST_HEADER_ICON_HIGH, GTK_ICON_SIZE_MENU);
-               gtk_box_pack_start (GTK_BOX (priv->subject_box), priv->priority_icon, FALSE, FALSE, 0);
-               gtk_widget_show (priv->priority_icon);
-       } else if (priv->priority_flags == TNY_HEADER_FLAG_LOW_PRIORITY) {
-               priv->priority_icon = gtk_image_new_from_icon_name (MODEST_HEADER_ICON_LOW, GTK_ICON_SIZE_MENU);
-               gtk_box_pack_start (GTK_BOX (priv->subject_box), priv->priority_icon, FALSE, FALSE, 0);
-               gtk_widget_show (priv->priority_icon);
-       }
+static gboolean
+modest_compact_mail_header_view_get_loading (ModestMailHeaderView *headers_view)
+{
+       return MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (headers_view)->get_loading_func (headers_view);
+}
+
+static gboolean
+modest_compact_mail_header_view_get_loading_default (ModestMailHeaderView *headers_view)
+{
+       ModestCompactMailHeaderViewPriv *priv;
+
+       g_return_val_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (headers_view), FALSE);
+       priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
+
+       return priv->is_loading;
+}
+
+static void
+modest_compact_mail_header_view_set_loading (ModestMailHeaderView *headers_view, gboolean is_loading)
+{
+       MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (headers_view)->set_loading_func (headers_view, is_loading);
+}
+
+static void
+modest_compact_mail_header_view_set_loading_default (ModestMailHeaderView *headers_view, gboolean is_loading)
+{
+       ModestCompactMailHeaderViewPriv *priv;
+
+       g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (headers_view));
+       priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
+
+       priv->is_loading = is_loading;
 }
 
 static void 
@@ -609,7 +618,12 @@ update_style (ModestCompactMailHeaderView *self)
                color.green = style_color.green;
                color.blue = style_color.blue;
        } else {
-               pango_color_parse (&color, "grey");
+               if (!pango_color_parse (&color, "grey")) {
+                       g_warning ("Failed to parse color grey");
+                       color.red = 0xc0c0;
+                       color.green = 0xc0c0;
+                       color.blue = 0xc0c0;
+               }
        }
 
        /* style of from:/to: label */
@@ -618,19 +632,12 @@ update_style (ModestCompactMailHeaderView *self)
        gtk_label_set_attributes (GTK_LABEL (priv->fromto_label), attr_list);
        pango_attr_list_unref (attr_list);
 
-       /* style of details label in details button */
-       attr_list = pango_attr_list_new ();
-       pango_attr_list_insert (attr_list, pango_attr_foreground_new (color.red, color.green, color.blue));
-       pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_SMALL));
-       pango_attr_list_insert (attr_list, pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
-       gtk_label_set_attributes (GTK_LABEL (priv->details_label), attr_list);
-       pango_attr_list_unref (attr_list);
-
        /* style of date time label */
        attr_list = pango_attr_list_new ();
        pango_attr_list_insert (attr_list, pango_attr_foreground_new (color.red, color.green, color.blue));
        pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_SMALL));
        gtk_label_set_attributes (GTK_LABEL (priv->date_label), attr_list);
+       gtk_label_set_attributes (GTK_LABEL (priv->time_label), attr_list);
        pango_attr_list_unref (attr_list);
 
        /* set style of custom headers */
@@ -649,9 +656,7 @@ fill_address (ModestCompactMailHeaderView *self)
        ModestCompactMailHeaderViewPriv *priv;
        gchar *recipients;
        const gchar *label;
-       GSList *recipient_list;
-       gchar *first_address;
-       
+
        g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (self));
        priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
 
@@ -663,35 +668,18 @@ fill_address (ModestCompactMailHeaderView *self)
                recipients = tny_header_dup_from (TNY_HEADER (priv->header));
        }
 
-       recipient_list = modest_text_utils_split_addresses_list (recipients);
-       if (recipient_list == NULL) {
-               first_address = NULL;
-       } else {
-               gchar *first_recipient;
-
-               first_recipient = (gchar *) recipient_list->data;
-               first_address = first_recipient?g_strdup (first_recipient):NULL;
-       }
-       g_slist_foreach (recipient_list, (GFunc) g_free, NULL);
-       g_slist_free (recipient_list);
-
+       /* Set label */
        gtk_label_set_text (GTK_LABEL (priv->fromto_label), label);
+
+       /* Set recipients */
        if (recipients) {
-               modest_text_utils_get_display_address (first_address);
-               gtk_label_set_text (GTK_LABEL (priv->fromto_contents), first_address);
+               gchar *addresses;
+
+               addresses = modest_text_utils_get_display_addresses ((const gchar *) recipients);
+               gtk_label_set_text (GTK_LABEL (priv->fromto_contents), 
+                                   (addresses) ? addresses : _("mail_va_no_to"));
+               g_free (addresses);
                g_free (recipients);
-               g_free (first_address);
        }
-
 }
 
-static void 
-on_details_button_clicked (GtkButton *button,
-                          gpointer userdata)
-{
-       ModestCompactMailHeaderView *self = (ModestCompactMailHeaderView *) userdata;
-
-       g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (self));
-
-       g_signal_emit_by_name (G_OBJECT (self), "show-details");
-}