Add progress hint on loading external images (fixes NB#112376)
[modest] / src / widgets / modest-compact-mail-header-view.c
index 851377c..b7b6abd 100644 (file)
@@ -56,6 +56,7 @@ struct _ModestCompactMailHeaderViewPriv
        GtkWidget    *fromto_contents;
        GtkWidget    *priority_icon;
        GtkWidget    *details_label;
+       GtkWidget    *details_button;
        GtkWidget    *date_label;
        GtkWidget    *subject_label;
 
@@ -67,6 +68,8 @@ struct _ModestCompactMailHeaderViewPriv
        TnyHeader    *header;
        TnyHeaderFlags priority_flags;
 
+       gboolean     is_loading;
+
        time_t       date_to_show;
        ModestDatetimeFormatter *datetime_formatter;
 };
@@ -94,6 +97,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,
@@ -130,7 +137,7 @@ set_date_time (ModestCompactMailHeaderView *compact_mail_header)
        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);
+       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);
@@ -326,7 +333,6 @@ 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 *main_align;
 
@@ -345,21 +351,25 @@ modest_compact_mail_header_view_instance_init (GTypeInstance *instance, gpointer
 
        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);
+       gtk_label_set_ellipsize (GTK_LABEL (priv->subject_label), PANGO_ELLIPSIZE_NONE);
        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_button = gtk_button_new ();
+       gtk_widget_set_no_show_all (priv->details_button, TRUE);
+       gtk_widget_show (priv->details_button);
        priv->details_label = gtk_label_new (_("mcen_ti_message_properties"));
+       gtk_widget_show (priv->details_label);
        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_container_add (GTK_CONTAINER (priv->details_button), priv->details_label);
+       gtk_button_set_relief (GTK_BUTTON (priv->details_button), GTK_RELIEF_NONE);
+       gtk_widget_set_size_request (priv->details_button, 200, -1);
 
        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);
+       gtk_box_pack_start (GTK_BOX (first_hbox), priv->details_button, FALSE, FALSE, 0);
 
        second_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_DOUBLE);
 
@@ -386,7 +396,7 @@ modest_compact_mail_header_view_instance_init (GTypeInstance *instance, gpointer
 
        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);
+       g_signal_connect (G_OBJECT (priv->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", 
@@ -408,6 +418,7 @@ modest_compact_mail_header_view_instance_init (GTypeInstance *instance, gpointer
 
        priv->is_outgoing = FALSE;
        priv->is_draft = FALSE;
+       priv->is_loading = FALSE;
 
        return;
 }
@@ -460,6 +471,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;
@@ -477,6 +490,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;
 
@@ -584,6 +599,46 @@ modest_compact_mail_header_view_set_priority_default (ModestMailHeaderView *head
        }
 }
 
+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;
+       gtk_widget_set_sensitive (priv->details_button, !is_loading);
+       if (is_loading) {
+               gtk_widget_hide (priv->details_label);
+       } else {
+               gtk_widget_show (priv->details_label);
+       }
+}
+
 static void 
 on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata)
 {
@@ -612,7 +667,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 */