d5652e1a0c4468d26f79e0131716ba334b930e77
[modest] / src / widgets / modest-compact-mail-header-view.c
1 /* Copyright (c) 2008, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 #include <config.h>
31 //#include <glib/gi18n-lib.h>
32
33 #include <string.h>
34 #include <gtk/gtk.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>
44 #endif
45
46 static GObjectClass *parent_class = NULL;
47
48 typedef struct _ModestCompactMailHeaderViewPriv ModestCompactMailHeaderViewPriv;
49
50 struct _ModestCompactMailHeaderViewPriv
51 {
52         GtkWidget    *headers_vbox;
53
54         GtkWidget    *fromto_label;
55         GtkWidget    *fromto_contents;
56         GtkWidget    *time_label;
57         GtkWidget    *date_label;
58
59         GSList       *custom_labels;
60
61         gboolean     is_outgoing;
62         gboolean     is_draft;
63         
64         TnyHeader    *header;
65         TnyHeaderFlags priority_flags;
66
67         gboolean     is_loading;
68
69         time_t       date_to_show;
70         ModestDatetimeFormatter *datetime_formatter;
71 };
72
73 #define MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE(o)  \
74         (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_COMPACT_MAIL_HEADER_VIEW, ModestCompactMailHeaderViewPriv))
75
76 /* GObject */
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);
80
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);
88
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,
101                                                                             const gchar *label,
102                                                                             GtkWidget *custom_widget,
103                                                                             gboolean with_expander,
104                                                                             gboolean start);
105 static const GtkWidget *modest_compact_mail_header_view_add_custom_header_default (ModestMailHeaderView *self,
106                                                                                     const gchar *label,
107                                                                                     GtkWidget *custom_widget,
108                                                                                     gboolean with_expander,
109                                                                                     gboolean start);
110
111 /* internal */
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);
116
117 static void
118 set_date_time (ModestCompactMailHeaderView *compact_mail_header)
119 {
120         const guint BUF_SIZE = 64; 
121         const gchar *date_str;
122         gchar date_buf[BUF_SIZE];
123         GString *buffer = g_string_new ("");
124
125         ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (compact_mail_header);
126
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);
139
140         gtk_label_set_text (GTK_LABEL (priv->date_label), buffer->str);
141         g_string_free (buffer, TRUE);
142
143 }
144
145 /* static void */
146 /* activate_recpt (GtkWidget *recpt_view, const gchar *address, gpointer user_data) */
147 /* { */
148 /*      ModestCompactMailHeaderView * view = MODEST_COMPACT_MAIL_HEADER_VIEW (user_data); */
149
150 /*      g_signal_emit (G_OBJECT (view), signals[RECPT_ACTIVATED_SIGNAL], 0, address); */
151 /* } */
152
153
154 static void 
155 modest_compact_mail_header_view_set_header (TnyHeaderView *self, TnyHeader *header)
156 {
157         MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->set_header_func (self, header);
158         return;
159 }
160
161 static void
162 modest_compact_mail_header_view_update_is_outgoing (TnyHeaderView *self)
163 {
164         ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
165         TnyFolder *folder = NULL;
166      
167         priv->is_outgoing = FALSE;
168
169         if (priv->header == NULL)
170                 return;
171         
172         folder = tny_header_get_folder (priv->header);
173
174         if (folder) {
175                 TnyFolderType folder_type = tny_folder_get_folder_type (folder);
176
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;
182                         break;
183                 default:
184                         priv->is_outgoing = FALSE;
185                 }
186                 priv->is_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
187
188                 g_object_unref (folder);
189         }
190 }
191
192 static void 
193 modest_compact_mail_header_view_set_header_default (TnyHeaderView *self, TnyHeader *header)
194 {
195         ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
196
197         if (header)
198                 g_assert (TNY_IS_HEADER (header));
199
200         if (G_LIKELY (priv->header))
201                 g_object_unref (G_OBJECT (priv->header));
202         priv->header = NULL;
203
204         if (header && G_IS_OBJECT (header))
205         {
206                 gchar *subject;
207
208                 g_object_ref (G_OBJECT (header)); 
209                 priv->header = header;
210
211                 modest_compact_mail_header_view_update_is_outgoing (self);
212
213                 subject = tny_header_dup_subject (header);
214
215                 if (priv->is_outgoing && priv->is_draft) {
216                         priv->date_to_show = tny_header_get_date_sent (header);
217                 } else {
218                         priv->date_to_show = tny_header_get_date_received (header);
219                 }
220                 set_date_time (MODEST_COMPACT_MAIL_HEADER_VIEW (self));
221
222                 fill_address (MODEST_COMPACT_MAIL_HEADER_VIEW (self));
223
224                 g_free (subject);
225         }
226
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));
230
231         return;
232 }
233
234 static void 
235 modest_compact_mail_header_view_clear (TnyHeaderView *self)
236 {
237         MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->clear_func (self);
238         return;
239 }
240
241 static void 
242 modest_compact_mail_header_view_clear_default (TnyHeaderView *self)
243 {
244         ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
245
246         if (G_LIKELY (priv->header))
247                 g_object_unref (G_OBJECT (priv->header));
248         priv->header = NULL;
249
250         gtk_label_set_text (GTK_LABEL (priv->fromto_label), "");
251         gtk_label_set_text (GTK_LABEL (priv->fromto_contents), "");
252
253         gtk_widget_hide (GTK_WIDGET(self));
254
255         return;
256 }
257
258 static const GtkWidget *
259 modest_compact_mail_header_view_add_custom_header (ModestMailHeaderView *self,
260                                                     const gchar *label,
261                                                     GtkWidget *custom_widget,
262                                                     gboolean with_expander,
263                                                     gboolean start)
264 {
265         return MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->add_custom_header_func (self, label,
266                                                                                          custom_widget, with_expander,
267                                                                                          start);
268 }
269
270 static const GtkWidget *
271 modest_compact_mail_header_view_add_custom_header_default (ModestMailHeaderView *header_view,
272                                                            const gchar *label,
273                                                            GtkWidget *custom_widget,
274                                                            gboolean with_expander,
275                                                            gboolean start)
276 {
277         ModestCompactMailHeaderViewPriv *priv;
278         g_return_val_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (header_view), NULL);
279         GtkWidget *hbox;
280         GtkWidget *label_field;
281
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);
290
291         if (start)
292                 gtk_box_pack_start (GTK_BOX (priv->headers_vbox), hbox, FALSE, FALSE, 0);
293         else
294                 gtk_box_pack_end (GTK_BOX (priv->headers_vbox), hbox, FALSE, FALSE, 0);
295
296         update_style (MODEST_COMPACT_MAIL_HEADER_VIEW (header_view));
297         return hbox;
298 }
299
300 /**
301  * modest_compact_mail_header_view_new:
302  *
303  * Return value: a new #ModestHeaderView instance implemented for Gtk+
304  **/
305 TnyHeaderView*
306 modest_compact_mail_header_view_new ()
307 {
308         ModestCompactMailHeaderViewPriv *priv;
309         ModestCompactMailHeaderView *self = g_object_new (MODEST_TYPE_COMPACT_MAIL_HEADER_VIEW, NULL);
310
311         priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
312         return TNY_HEADER_VIEW (self);
313 }
314
315 static void
316 datetime_format_changed (ModestDatetimeFormatter *formatter,
317                          ModestCompactMailHeaderView *self)
318 {
319         set_date_time (self);
320 }
321
322 static void
323 modest_compact_mail_header_view_instance_init (GTypeInstance *instance, gpointer g_class)
324 {
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;
330
331         priv->header = NULL;
332         priv->custom_labels = NULL;
333
334         main_vbox = gtk_vbox_new (FALSE, 0);
335         vbox = gtk_vbox_new (FALSE, 0);
336
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 */
340
341         from_date_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_DOUBLE);
342         headers_date_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_DOUBLE);
343
344         priv->fromto_label = gtk_label_new (NULL);
345         gtk_misc_set_alignment (GTK_MISC (priv->fromto_label), 0.0, 1.0);
346
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);
350
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);
355
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);
360
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);
364
365         gtk_box_pack_start (GTK_BOX (vbox), from_date_hbox, FALSE, FALSE, 0);
366
367         update_style (self);
368
369         g_signal_connect (G_OBJECT (self), "notify::style", G_CALLBACK (on_notify_style), (gpointer) self);
370
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);
374
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);
378
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);
383
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);
388
389         gtk_widget_show_all (main_align);
390
391         priv->is_outgoing = FALSE;
392         priv->is_draft = FALSE;
393         priv->is_loading = FALSE;
394
395         return;
396 }
397
398 static void
399 modest_compact_mail_header_view_finalize (GObject *object)
400 {
401         ModestCompactMailHeaderView *self = (ModestCompactMailHeaderView *)object;      
402         ModestCompactMailHeaderViewPriv *priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
403
404         if (priv->datetime_formatter) {
405                 g_object_unref (priv->datetime_formatter);
406                 priv->datetime_formatter = NULL;
407         }
408
409         if (priv->custom_labels) {
410                 g_slist_free (priv->custom_labels);
411                 priv->custom_labels = NULL;
412         }
413
414         if (G_LIKELY (priv->header))
415                 g_object_unref (G_OBJECT (priv->header));
416         priv->header = NULL;
417
418         if (G_LIKELY (priv->headers_vbox))
419                 g_object_unref (G_OBJECT (priv->headers_vbox));
420
421         priv->headers_vbox = NULL;
422
423         (*parent_class->finalize) (object);
424
425         return;
426 }
427
428 static void
429 tny_header_view_init (gpointer g, gpointer iface_data)
430 {
431         TnyHeaderViewIface *klass = (TnyHeaderViewIface *)g;
432
433         klass->set_header = modest_compact_mail_header_view_set_header;
434         klass->clear = modest_compact_mail_header_view_clear;
435
436         return;
437 }
438
439 static void
440 modest_mail_header_view_init (gpointer g, gpointer iface_data)
441 {
442         ModestMailHeaderViewIface *klass = (ModestMailHeaderViewIface *)g;
443
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;
449
450         return;
451 }
452
453 static void 
454 modest_compact_mail_header_view_class_init (ModestCompactMailHeaderViewClass *klass)
455 {
456         GObjectClass *object_class;
457
458         parent_class = g_type_class_peek_parent (klass);
459         object_class = (GObjectClass*) klass;
460
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;
469
470         g_type_class_add_private (object_class, sizeof (ModestCompactMailHeaderViewPriv));
471
472         return;
473 }
474
475 GType 
476 modest_compact_mail_header_view_get_type (void)
477 {
478         static GType type = 0;
479
480         if (G_UNLIKELY(type == 0))
481         {
482                 static const GTypeInfo info = 
483                 {
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),
491                   0,      /* n_preallocs */
492                   modest_compact_mail_header_view_instance_init    /* instance_init */
493                 };
494
495                 static const GInterfaceInfo tny_header_view_info = 
496                 {
497                   (GInterfaceInitFunc) tny_header_view_init, /* interface_init */
498                   NULL,         /* interface_finalize */
499                   NULL          /* interface_data */
500                 };
501
502                 static const GInterfaceInfo modest_mail_header_view_info = 
503                 {
504                   (GInterfaceInitFunc) modest_mail_header_view_init, /* interface_init */
505                   NULL,         /* interface_finalize */
506                   NULL          /* interface_data */
507                 };
508
509                 type = g_type_register_static (GTK_TYPE_HBOX,
510                         "ModestCompactMailHeaderView",
511                         &info, 0);
512
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);
517
518         }
519
520         return type;
521 }
522
523 static TnyHeaderFlags
524 modest_compact_mail_header_view_get_priority (ModestMailHeaderView *self)
525 {
526         return MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->get_priority_func (self);
527 }
528
529 static TnyHeaderFlags
530 modest_compact_mail_header_view_get_priority_default (ModestMailHeaderView *headers_view)
531 {
532         ModestCompactMailHeaderViewPriv *priv;
533
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);
536
537         return priv->priority_flags;
538 }
539
540 static void 
541 modest_compact_mail_header_view_set_priority (ModestMailHeaderView *self, TnyHeaderFlags flags)
542 {
543         MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (self)->set_priority_func (self, flags);
544         return;
545 }
546
547 static void
548 modest_compact_mail_header_view_set_priority_default (ModestMailHeaderView *headers_view,
549                                                       TnyHeaderFlags flags)
550 {
551         ModestCompactMailHeaderViewPriv *priv;
552
553         g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (headers_view));
554         priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
555
556         priv->priority_flags = flags & TNY_HEADER_FLAG_PRIORITY_MASK ;
557 }
558
559 static gboolean
560 modest_compact_mail_header_view_get_loading (ModestMailHeaderView *headers_view)
561 {
562         return MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (headers_view)->get_loading_func (headers_view);
563 }
564
565 static gboolean
566 modest_compact_mail_header_view_get_loading_default (ModestMailHeaderView *headers_view)
567 {
568         ModestCompactMailHeaderViewPriv *priv;
569
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);
572
573         return priv->is_loading;
574 }
575
576 static void
577 modest_compact_mail_header_view_set_loading (ModestMailHeaderView *headers_view, gboolean is_loading)
578 {
579         MODEST_COMPACT_MAIL_HEADER_VIEW_GET_CLASS (headers_view)->set_loading_func (headers_view, is_loading);
580 }
581
582 static void
583 modest_compact_mail_header_view_set_loading_default (ModestMailHeaderView *headers_view, gboolean is_loading)
584 {
585         ModestCompactMailHeaderViewPriv *priv;
586
587         g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (headers_view));
588         priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (headers_view);
589
590         priv->is_loading = is_loading;
591 }
592
593 static void 
594 on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata)
595 {
596         if (strcmp ("style", spec->name) == 0) {
597                 update_style (MODEST_COMPACT_MAIL_HEADER_VIEW (obj));
598                 gtk_widget_queue_draw (GTK_WIDGET (obj));
599         } 
600 }
601
602 /* This method updates the color (and other style settings) of widgets using secondary text color,
603  * tracking the gtk style */
604 static void
605 update_style (ModestCompactMailHeaderView *self)
606 {
607         ModestCompactMailHeaderViewPriv *priv;
608         GdkColor style_color;
609         PangoColor color;
610         PangoAttrList *attr_list;
611         GSList *node;
612
613         g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (self));
614         priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
615
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;
620         } else {
621                 if (!pango_color_parse (&color, "grey")) {
622                         g_warning ("Failed to parse color grey");
623                         color.red = 0xc0c0;
624                         color.green = 0xc0c0;
625                         color.blue = 0xc0c0;
626                 }
627         }
628
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);
634
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);
642
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);
648         }
649         pango_attr_list_unref (attr_list);
650
651 }
652
653 static void
654 fill_address (ModestCompactMailHeaderView *self)
655 {
656         ModestCompactMailHeaderViewPriv *priv;
657         gchar *recipients;
658         const gchar *label;
659         GSList *recipient_list;
660         gchar *first_address;
661         
662         g_return_if_fail (MODEST_IS_COMPACT_MAIL_HEADER_VIEW (self));
663         priv = MODEST_COMPACT_MAIL_HEADER_VIEW_GET_PRIVATE (self);
664
665         if (priv->is_outgoing) {
666                 label = _("mail_va_to");
667                 recipients = tny_header_dup_to (TNY_HEADER (priv->header));
668         } else {
669                 label = _("mail_va_from");
670                 recipients = tny_header_dup_from (TNY_HEADER (priv->header));
671         }
672
673         recipient_list = modest_text_utils_split_addresses_list (recipients);
674         if (recipient_list == NULL) {
675                 first_address = NULL;
676         } else {
677                 gchar *first_recipient;
678
679                 first_recipient = (gchar *) recipient_list->data;
680                 first_address = first_recipient?g_strdup (first_recipient):NULL;
681         }
682         g_slist_foreach (recipient_list, (GFunc) g_free, NULL);
683         g_slist_free (recipient_list);
684
685         gtk_label_set_text (GTK_LABEL (priv->fromto_label), label);
686         if (recipients) {
687                 modest_text_utils_get_display_address (first_address);
688                 gtk_label_set_text (GTK_LABEL (priv->fromto_contents), first_address);
689                 g_free (recipients);
690                 g_free (first_address);
691         }
692
693 }
694