1 /* Copyright (c) 2008, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 //#include <glib/gi18n-lib.h>
35 #include <modest-defs.h>
36 #include <modest-text-utils.h>
37 #include <modest-compact-mail-header-view.h>
38 #include <modest-tny-folder.h>
39 #include <modest-ui-constants.h>
40 #include <modest-icon-names.h>
41 #include <modest-datetime-formatter.h>
42 #ifdef MODEST_TOOLKIT_HILDON2
43 #include <hildon/hildon-gtk.h>
46 static GObjectClass *parent_class = NULL;
48 typedef struct _ModestCompactMailHeaderViewPriv ModestCompactMailHeaderViewPriv;
50 struct _ModestCompactMailHeaderViewPriv
52 GtkWidget *headers_vbox;
54 GtkWidget *fromto_label;
55 GtkWidget *fromto_contents;
56 GtkWidget *time_label;
57 GtkWidget *date_label;
59 GSList *custom_labels;
65 TnyHeaderFlags priority_flags;
70 ModestDatetimeFormatter *datetime_formatter;
73 #define MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE(o) \
74 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_COMPACT_MAIL_HEADER_VIEW, ModestCompactMailHeaderViewPriv))
77 static void modest_compact_mail_header_view_class_init (ModestCompactMailHeaderViewClass *klass);
78 static void modest_compact_mail_header_view_instance_init (GTypeInstance *instance, gpointer g_class);
79 static void modest_compact_mail_header_view_finalize (GObject *object);
81 /* TnyHeaderView interface */
82 static void tny_header_view_init (gpointer g, gpointer iface_data);
83 static void modest_compact_mail_header_view_set_header (TnyHeaderView *self, TnyHeader *header);
84 static void modest_compact_mail_header_view_update_is_outgoing (TnyHeaderView *self);
85 static void modest_compact_mail_header_view_set_header_default (TnyHeaderView *self, TnyHeader *header);
86 static void modest_compact_mail_header_view_clear (TnyHeaderView *self);
87 static void modest_compact_mail_header_view_clear_default (TnyHeaderView *self);
89 /* ModestMailHeaderView interface */
90 static void modest_mail_header_view_init (gpointer g, gpointer iface_data);
91 static TnyHeaderFlags modest_compact_mail_header_view_get_priority (ModestMailHeaderView *self);
92 static TnyHeaderFlags modest_compact_mail_header_view_get_priority_default (ModestMailHeaderView *headers_view);
93 static void modest_compact_mail_header_view_set_priority (ModestMailHeaderView *self, TnyHeaderFlags flags);
94 static void modest_compact_mail_header_view_set_priority_default (ModestMailHeaderView *headers_view,
95 TnyHeaderFlags flags);
96 static gboolean modest_compact_mail_header_view_get_loading (ModestMailHeaderView *headers_view);
97 static gboolean modest_compact_mail_header_view_get_loading_default (ModestMailHeaderView *headers_view);
98 static void modest_compact_mail_header_view_set_loading (ModestMailHeaderView *headers_view, gboolean is_loading);
99 static void modest_compact_mail_header_view_set_loading_default (ModestMailHeaderView *headers_view, gboolean is_loading);
100 static const GtkWidget *modest_compact_mail_header_view_add_custom_header (ModestMailHeaderView *self,
102 GtkWidget *custom_widget,
103 gboolean with_expander,
105 static const GtkWidget *modest_compact_mail_header_view_add_custom_header_default (ModestMailHeaderView *self,
107 GtkWidget *custom_widget,
108 gboolean with_expander,
112 static void on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata);
113 static void update_style (ModestCompactMailHeaderView *self);
114 static void set_date_time (ModestCompactMailHeaderView *compact_mail_header);
115 static void fill_address (ModestCompactMailHeaderView *self);
118 set_date_time (ModestCompactMailHeaderView *compact_mail_header)
120 const guint BUF_SIZE = 64;
121 const gchar *date_str;
122 gchar date_buf[BUF_SIZE];
123 GString *buffer = g_string_new ("");
125 ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (compact_mail_header);
127 modest_text_utils_strftime (date_buf, BUF_SIZE, _HL("wdgt_va_week"), priv->date_to_show);
128 buffer = g_string_append (buffer, date_buf);
129 buffer = g_string_append_c (buffer, ' ');
130 buffer = g_string_append_unichar (buffer, 0x2015);
131 buffer = g_string_append_c (buffer, ' ');
132 date_str = modest_datetime_formatter_format_time (priv->datetime_formatter, priv->date_to_show);
133 buffer = g_string_append (buffer, date_str);
134 gtk_label_set_text (GTK_LABEL (priv->time_label), buffer->str);
135 g_string_free (buffer, TRUE);
136 buffer = g_string_new ("");
137 modest_text_utils_strftime (date_buf, BUF_SIZE, _HL("wdgt_va_date_medium"), priv->date_to_show);
138 buffer = g_string_append (buffer, date_buf);
140 gtk_label_set_text (GTK_LABEL (priv->date_label), buffer->str);
141 g_string_free (buffer, TRUE);
146 /* activate_recpt (GtkWidget *recpt_view, const gchar *address, gpointer user_data) */
148 /* ModestCompactMailHeaderView * view = MODEST_COMPACT_MAIL_HEADER_VIEW (user_data); */
150 /* g_signal_emit (G_OBJECT (view), signals[RECPT_ACTIVATED_SIGNAL], 0, address); */
155 modest_compact_mail_header_view_set_header (TnyHeaderView *self, TnyHeader *header)
157 MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->set_header_func (self, header);
162 modest_compact_mail_header_view_update_is_outgoing (TnyHeaderView *self)
164 ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
165 TnyFolder *folder = NULL;
167 priv->is_outgoing = FALSE;
169 if (priv->header == NULL)
172 folder = tny_header_get_folder (priv->header);
175 TnyFolderType folder_type = tny_folder_get_folder_type (folder);
177 switch (folder_type) {
178 case TNY_FOLDER_TYPE_DRAFTS:
179 case TNY_FOLDER_TYPE_OUTBOX:
180 case TNY_FOLDER_TYPE_SENT:
181 priv->is_outgoing = TRUE;
184 priv->is_outgoing = FALSE;
186 priv->is_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
188 g_object_unref (folder);
193 modest_compact_mail_header_view_set_header_default (TnyHeaderView *self, TnyHeader *header)
195 ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
198 g_assert (TNY_IS_HEADER (header));
200 if (G_LIKELY (priv->header))
201 g_object_unref (G_OBJECT (priv->header));
204 if (header && G_IS_OBJECT (header))
208 g_object_ref (G_OBJECT (header));
209 priv->header = header;
211 modest_compact_mail_header_view_update_is_outgoing (self);
213 subject = tny_header_dup_subject (header);
215 if (priv->is_outgoing && priv->is_draft) {
216 priv->date_to_show = tny_header_get_date_sent (header);
218 priv->date_to_show = tny_header_get_date_received (header);
220 set_date_time (MODEST_COMPACT_MAIL_HEADER_VIEW (self));
222 fill_address (MODEST_COMPACT_MAIL_HEADER_VIEW (self));
227 modest_mail_header_view_set_priority (MODEST_MAIL_HEADER_VIEW (self), 0);
228 update_style (MODEST_COMPACT_MAIL_HEADER_VIEW (self));
229 gtk_widget_show_all (GTK_WIDGET (self));
235 modest_compact_mail_header_view_clear (TnyHeaderView *self)
237 MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->clear_func (self);
242 modest_compact_mail_header_view_clear_default (TnyHeaderView *self)
244 ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
246 if (G_LIKELY (priv->header))
247 g_object_unref (G_OBJECT (priv->header));
250 gtk_label_set_text (GTK_LABEL (priv->fromto_label), "");
251 gtk_label_set_text (GTK_LABEL (priv->fromto_contents), "");
253 gtk_widget_hide (GTK_WIDGET(self));
258 static const GtkWidget *
259 modest_compact_mail_header_view_add_custom_header (ModestMailHeaderView *self,
261 GtkWidget *custom_widget,
262 gboolean with_expander,
265 return MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->add_custom_header_func (self, label,
266 custom_widget, with_expander,
270 static const GtkWidget *
271 modest_compact_mail_header_view_add_custom_header_default (ModestMailHeaderView *header_view,
273 GtkWidget *custom_widget,
274 gboolean with_expander,
277 ModestCompactMailHeaderViewPriv *priv;
278 g_return_val_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (header_view), NULL);
280 GtkWidget *label_field;
282 priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (header_view);
283 hbox = gtk_hbox_new (FALSE, 12);
284 label_field = gtk_label_new (NULL);
285 gtk_label_set_text (GTK_LABEL (label_field), label);
286 priv->custom_labels = g_slist_prepend (priv->custom_labels, (gpointer) label_field);
287 gtk_misc_set_alignment (GTK_MISC (label_field), 1.0, 0.0);
288 gtk_box_pack_start (GTK_BOX (hbox), label_field, FALSE, FALSE, 0);
289 gtk_box_pack_start (GTK_BOX (hbox), custom_widget, TRUE, TRUE, 0);
292 gtk_box_pack_start (GTK_BOX (priv->headers_vbox), hbox, FALSE, FALSE, 0);
294 gtk_box_pack_end (GTK_BOX (priv->headers_vbox), hbox, FALSE, FALSE, 0);
296 update_style (MODEST_COMPACT_MAIL_HEADER_VIEW (header_view));
301 * modest_compact_mail_header_view_new:
303 * Return value: a new #ModestHeaderView instance implemented for Gtk+
306 modest_compact_mail_header_view_new ()
308 ModestCompactMailHeaderViewPriv *priv;
309 ModestCompactMailHeaderView *self = g_object_new (MODEST_TYPE_COMPACT_MAIL_HEADER_VIEW, NULL);
311 priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
312 return TNY_HEADER_VIEW (self);
316 datetime_format_changed (ModestDatetimeFormatter *formatter,
317 ModestCompactMailHeaderView *self)
319 set_date_time (self);
323 modest_compact_mail_header_view_instance_init (GTypeInstance *instance, gpointer g_class)
325 ModestCompactMailHeaderView *self = (ModestCompactMailHeaderView *)instance;
326 ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
327 GtkWidget *from_date_hbox, *vbox, *main_vbox;
328 GtkWidget *main_align;
329 GtkWidget *headers_date_hbox;
332 priv->custom_labels = NULL;
334 main_vbox = gtk_vbox_new (FALSE, 0);
335 vbox = gtk_vbox_new (FALSE, 0);
337 /* We set here the style for widgets using standard text color. For
338 * widgets with secondary text color, we set them in update_style,
339 * as we want to track the style changes and update the color properly */
341 from_date_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_DOUBLE);
342 headers_date_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_DOUBLE);
344 priv->fromto_label = gtk_label_new (NULL);
345 gtk_misc_set_alignment (GTK_MISC (priv->fromto_label), 0.0, 1.0);
347 priv->fromto_contents = gtk_label_new (NULL);
348 gtk_misc_set_alignment (GTK_MISC (priv->fromto_contents), 0.0, 1.0);
349 gtk_label_set_ellipsize (GTK_LABEL (priv->fromto_contents), PANGO_ELLIPSIZE_END);
351 priv->date_label = gtk_label_new (NULL);
352 gtk_label_set_justify (GTK_LABEL (priv->date_label), GTK_JUSTIFY_RIGHT);
353 gtk_misc_set_alignment (GTK_MISC (priv->date_label), 1.0, 0.0);
354 gtk_misc_set_padding (GTK_MISC (priv->date_label), MODEST_MARGIN_DOUBLE, 0);
356 priv->time_label = gtk_label_new (NULL);
357 gtk_label_set_justify (GTK_LABEL (priv->time_label), GTK_JUSTIFY_RIGHT);
358 gtk_misc_set_alignment (GTK_MISC (priv->time_label), 1.0, 1.0);
359 gtk_misc_set_padding (GTK_MISC (priv->time_label), MODEST_MARGIN_DOUBLE, 0);
361 gtk_box_pack_start (GTK_BOX (from_date_hbox), priv->fromto_label, FALSE, FALSE, 0);
362 gtk_box_pack_start (GTK_BOX (from_date_hbox), priv->fromto_contents, TRUE, TRUE, 0);
363 gtk_box_pack_start (GTK_BOX (from_date_hbox), priv->time_label, FALSE, FALSE, 0);
365 gtk_box_pack_start (GTK_BOX (vbox), from_date_hbox, FALSE, FALSE, 0);
369 g_signal_connect (G_OBJECT (self), "notify::style", G_CALLBACK (on_notify_style), (gpointer) self);
371 priv->datetime_formatter = modest_datetime_formatter_new ();
372 g_signal_connect (G_OBJECT (priv->datetime_formatter), "format-changed",
373 G_CALLBACK (datetime_format_changed), (gpointer) self);
375 priv->headers_vbox = gtk_vbox_new (FALSE, 0);
376 gtk_container_set_focus_chain (GTK_CONTAINER (priv->headers_vbox), NULL);
377 g_object_ref (priv->headers_vbox);
379 gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
380 gtk_box_pack_start (GTK_BOX (headers_date_hbox), priv->headers_vbox, TRUE, TRUE, 0);
381 gtk_box_pack_start (GTK_BOX (headers_date_hbox), priv->date_label, FALSE, FALSE, 0);
382 gtk_box_pack_start (GTK_BOX (main_vbox), headers_date_hbox, FALSE, FALSE, 0);
384 main_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
385 gtk_alignment_set_padding (GTK_ALIGNMENT (main_align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
386 gtk_container_add (GTK_CONTAINER (main_align), main_vbox);
387 gtk_box_pack_start (GTK_BOX (self), main_align, TRUE, TRUE, 0);
389 gtk_widget_show_all (main_align);
391 priv->is_outgoing = FALSE;
392 priv->is_draft = FALSE;
393 priv->is_loading = FALSE;
399 modest_compact_mail_header_view_finalize (GObject *object)
401 ModestCompactMailHeaderView *self = (ModestCompactMailHeaderView *)object;
402 ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
404 if (priv->datetime_formatter) {
405 g_object_unref (priv->datetime_formatter);
406 priv->datetime_formatter = NULL;
409 if (priv->custom_labels) {
410 g_slist_free (priv->custom_labels);
411 priv->custom_labels = NULL;
414 if (G_LIKELY (priv->header))
415 g_object_unref (G_OBJECT (priv->header));
418 if (G_LIKELY (priv->headers_vbox))
419 g_object_unref (G_OBJECT (priv->headers_vbox));
421 priv->headers_vbox = NULL;
423 (*parent_class->finalize) (object);
429 tny_header_view_init (gpointer g, gpointer iface_data)
431 TnyHeaderViewIface *klass = (TnyHeaderViewIface *)g;
433 klass->set_header = modest_compact_mail_header_view_set_header;
434 klass->clear = modest_compact_mail_header_view_clear;
440 modest_mail_header_view_init (gpointer g, gpointer iface_data)
442 ModestMailHeaderViewIface *klass = (ModestMailHeaderViewIface *)g;
444 klass->get_priority = modest_compact_mail_header_view_get_priority;
445 klass->set_priority = modest_compact_mail_header_view_set_priority;
446 klass->get_loading = modest_compact_mail_header_view_get_loading;
447 klass->set_loading = modest_compact_mail_header_view_set_loading;
448 klass->add_custom_header = modest_compact_mail_header_view_add_custom_header;
454 modest_compact_mail_header_view_class_init (ModestCompactMailHeaderViewClass *klass)
456 GObjectClass *object_class;
458 parent_class = g_type_class_peek_parent (klass);
459 object_class = (GObjectClass*) klass;
461 klass->set_header_func = modest_compact_mail_header_view_set_header_default;
462 klass->clear_func = modest_compact_mail_header_view_clear_default;
463 klass->set_priority_func = modest_compact_mail_header_view_set_priority_default;
464 klass->get_priority_func = modest_compact_mail_header_view_get_priority_default;
465 klass->set_loading_func = modest_compact_mail_header_view_set_loading_default;
466 klass->get_loading_func = modest_compact_mail_header_view_get_loading_default;
467 klass->add_custom_header_func = modest_compact_mail_header_view_add_custom_header_default;
468 object_class->finalize = modest_compact_mail_header_view_finalize;
470 g_type_class_add_private (object_class, sizeof (ModestCompactMailHeaderViewPriv));
476 modest_compact_mail_header_view_get_type (void)
478 static GType type = 0;
480 if (G_UNLIKELY(type == 0))
482 static const GTypeInfo info =
484 sizeof (ModestCompactMailHeaderViewClass),
485 NULL, /* base_init */
486 NULL, /* base_finalize */
487 (GClassInitFunc) modest_compact_mail_header_view_class_init, /* class_init */
488 NULL, /* class_finalize */
489 NULL, /* class_data */
490 sizeof (ModestCompactMailHeaderView),
492 modest_compact_mail_header_view_instance_init /* instance_init */
495 static const GInterfaceInfo tny_header_view_info =
497 (GInterfaceInitFunc) tny_header_view_init, /* interface_init */
498 NULL, /* interface_finalize */
499 NULL /* interface_data */
502 static const GInterfaceInfo modest_mail_header_view_info =
504 (GInterfaceInitFunc) modest_mail_header_view_init, /* interface_init */
505 NULL, /* interface_finalize */
506 NULL /* interface_data */
509 type = g_type_register_static (GTK_TYPE_HBOX,
510 "ModestCompactMailHeaderView",
513 g_type_add_interface_static (type, TNY_TYPE_HEADER_VIEW,
514 &tny_header_view_info);
515 g_type_add_interface_static (type, MODEST_TYPE_MAIL_HEADER_VIEW,
516 &modest_mail_header_view_info);
523 static TnyHeaderFlags
524 modest_compact_mail_header_view_get_priority (ModestMailHeaderView *self)
526 return MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->get_priority_func (self);
529 static TnyHeaderFlags
530 modest_compact_mail_header_view_get_priority_default (ModestMailHeaderView *headers_view)
532 ModestCompactMailHeaderViewPriv *priv;
534 g_return_val_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (headers_view), 0);
535 priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
537 return priv->priority_flags;
541 modest_compact_mail_header_view_set_priority (ModestMailHeaderView *self, TnyHeaderFlags flags)
543 MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->set_priority_func (self, flags);
548 modest_compact_mail_header_view_set_priority_default (ModestMailHeaderView *headers_view,
549 TnyHeaderFlags flags)
551 ModestCompactMailHeaderViewPriv *priv;
553 g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (headers_view));
554 priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
556 priv->priority_flags = flags & TNY_HEADER_FLAG_PRIORITY_MASK ;
560 modest_compact_mail_header_view_get_loading (ModestMailHeaderView *headers_view)
562 return MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (headers_view)->get_loading_func (headers_view);
566 modest_compact_mail_header_view_get_loading_default (ModestMailHeaderView *headers_view)
568 ModestCompactMailHeaderViewPriv *priv;
570 g_return_val_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (headers_view), FALSE);
571 priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
573 return priv->is_loading;
577 modest_compact_mail_header_view_set_loading (ModestMailHeaderView *headers_view, gboolean is_loading)
579 MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (headers_view)->set_loading_func (headers_view, is_loading);
583 modest_compact_mail_header_view_set_loading_default (ModestMailHeaderView *headers_view, gboolean is_loading)
585 ModestCompactMailHeaderViewPriv *priv;
587 g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (headers_view));
588 priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
590 priv->is_loading = is_loading;
594 on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata)
596 if (strcmp ("style", spec->name) == 0) {
597 update_style (MODEST_COMPACT_MAIL_HEADER_VIEW (obj));
598 gtk_widget_queue_draw (GTK_WIDGET (obj));
602 /* This method updates the color (and other style settings) of widgets using secondary text color,
603 * tracking the gtk style */
605 update_style (ModestCompactMailHeaderView *self)
607 ModestCompactMailHeaderViewPriv *priv;
608 GdkColor style_color;
610 PangoAttrList *attr_list;
613 g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (self));
614 priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
616 if (gtk_style_lookup_color (GTK_WIDGET (self)->style, "SecondaryTextColor", &style_color)) {
617 color.red = style_color.red;
618 color.green = style_color.green;
619 color.blue = style_color.blue;
621 if (!pango_color_parse (&color, "grey")) {
622 g_warning ("Failed to parse color grey");
624 color.green = 0xc0c0;
629 /* style of from:/to: label */
630 attr_list = pango_attr_list_new ();
631 pango_attr_list_insert (attr_list, pango_attr_foreground_new (color.red, color.green, color.blue));
632 gtk_label_set_attributes (GTK_LABEL (priv->fromto_label), attr_list);
633 pango_attr_list_unref (attr_list);
635 /* style of date time label */
636 attr_list = pango_attr_list_new ();
637 pango_attr_list_insert (attr_list, pango_attr_foreground_new (color.red, color.green, color.blue));
638 pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_SMALL));
639 gtk_label_set_attributes (GTK_LABEL (priv->date_label), attr_list);
640 gtk_label_set_attributes (GTK_LABEL (priv->time_label), attr_list);
641 pango_attr_list_unref (attr_list);
643 /* set style of custom headers */
644 attr_list = pango_attr_list_new ();
645 pango_attr_list_insert (attr_list, pango_attr_foreground_new (color.red, color.green, color.blue));
646 for (node = priv->custom_labels; node != NULL; node = g_slist_next (node)) {
647 gtk_label_set_attributes (GTK_LABEL (node->data), attr_list);
649 pango_attr_list_unref (attr_list);
654 fill_address (ModestCompactMailHeaderView *self)
656 ModestCompactMailHeaderViewPriv *priv;
659 GSList *recipient_list;
660 gchar *first_address;
662 g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (self));
663 priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
665 if (priv->is_outgoing) {
666 label = _("mail_va_to");
667 recipients = tny_header_dup_to (TNY_HEADER (priv->header));
669 label = _("mail_va_from");
670 recipients = tny_header_dup_from (TNY_HEADER (priv->header));
673 recipient_list = modest_text_utils_split_addresses_list (recipients);
674 if (recipient_list == NULL) {
675 first_address = NULL;
677 gchar *first_recipient;
679 first_recipient = (gchar *) recipient_list->data;
680 first_address = first_recipient?g_strdup (first_recipient):NULL;
682 g_slist_foreach (recipient_list, (GFunc) g_free, NULL);
683 g_slist_free (recipient_list);
685 gtk_label_set_text (GTK_LABEL (priv->fromto_label), label);
687 modest_text_utils_get_display_address (first_address);
688 gtk_label_set_text (GTK_LABEL (priv->fromto_contents), first_address);
690 g_free (first_address);