Better attachments detection for text/calendar
[modest] / src / widgets / modest-attachment-view.c
1 /* Copyright (c) 2007, 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 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif /*HAVE_CONFIG_H*/
33
34 #include <glib/gi18n.h>
35
36 #include <string.h>
37 #include <modest-attachment-view.h>
38 #include <modest-platform.h>
39 #include <modest-text-utils.h>
40 #include <modest-tny-mime-part.h>
41 #include <tny-msg.h>
42 #include <modest-mail-operation.h>
43 #include <modest-mail-operation-queue.h>
44 #include <modest-runtime.h>
45 #include <modest-count-stream.h>
46 #include <modest-ui-constants.h>
47
48 #define GET_SIZE_BUFFER_SIZE 128
49
50 static GObjectClass *parent_class = NULL;
51
52 typedef struct _ModestAttachmentViewPrivate ModestAttachmentViewPrivate;
53
54 struct _ModestAttachmentViewPrivate
55 {
56         TnyMimePart *mime_part;
57
58         GtkWidget *icon;
59         GtkWidget *filename_view;
60         GtkWidget *size_view;
61
62         gboolean detect_size;
63         TnyStream *get_size_stream;
64         guint64 size;
65
66         PangoLayout *layout_full_filename;
67         gboolean is_purged;
68
69 };
70
71 #ifdef MODEST_TOOLKIT_HILDON2
72 #define UNKNOWN_FILE_ICON "filemanager_unknown_file"
73 #else
74 #define UNKNOWN_FILE_ICON "qgn_list_gene_unknown_file"
75 #endif
76
77 #define MODEST_ATTACHMENT_VIEW_GET_PRIVATE(o)   \
78         (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ATTACHMENT_VIEW, ModestAttachmentViewPrivate))
79
80 /* TnyMimePartView functions */
81 static TnyMimePart *modest_attachment_view_get_part (TnyMimePartView *self);
82 static TnyMimePart *modest_attachment_view_get_part_default (TnyMimePartView *self);
83 static void modest_attachment_view_set_part (TnyMimePartView *self, TnyMimePart *mime_part);
84 static void modest_attachment_view_set_part_default (TnyMimePartView *self, TnyMimePart *mime_part);
85 static void modest_attachment_view_clear (TnyMimePartView *self);
86 static void modest_attachment_view_clear_default (TnyMimePartView *self);
87
88 /* Gtk events */
89 static void size_allocate (GtkWidget *widget, GtkAllocation *allocation);
90
91 /* GObject and GInterface management */
92 static void modest_attachment_view_instance_init (GTypeInstance *instance, gpointer g_class);
93 static void modest_attachment_view_finalize (GObject *object);
94 static void modest_attachment_view_class_init (ModestAttachmentViewClass *klass);
95 static void tny_mime_part_view_init (gpointer g, gpointer iface_data);
96
97 static void on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata);
98 static void update_style (ModestAttachmentView *self);
99
100
101 static void update_filename_request (ModestAttachmentView *self);
102
103 static void 
104 on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata)
105 {
106         if (strcmp ("style", spec->name) == 0) {
107                 update_style (MODEST_ATTACHMENT_VIEW (obj));
108                 gtk_widget_queue_draw (GTK_WIDGET (obj));
109         } 
110 }
111
112 /* This method updates the color (and other style settings) of widgets using secondary text color,
113  * tracking the gtk style */
114 static void
115 update_style (ModestAttachmentView *self)
116 {
117 #ifdef MODEST_COMPACT_HEADER_BG
118         GdkColor bg_color;
119         GtkStyle *style;
120         GdkColor *current_bg;
121
122         g_return_if_fail (MODEST_IS_ATTACHMENT_VIEW (self));
123
124         gdk_color_parse (MODEST_COMPACT_HEADER_BG, &bg_color);
125         style = gtk_widget_get_style (GTK_WIDGET (self));
126         current_bg = &(style->bg[GTK_STATE_NORMAL]);
127         if (current_bg->red != bg_color.red || current_bg->blue != bg_color.blue || current_bg->green != bg_color.green)
128                 gtk_widget_modify_bg (GTK_WIDGET (self), GTK_STATE_NORMAL, &bg_color);
129 #endif
130 }
131
132
133
134 static void update_size_label (ModestAttachmentView *self)
135 {
136         ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
137         gchar *size_str;
138         gchar *label_text;
139
140         size_str = modest_text_utils_get_display_size (priv->size);
141         label_text = g_strdup_printf (" (%s)", size_str);
142         g_free (size_str);
143         gtk_label_set_text (GTK_LABEL (priv->size_view), label_text);
144         g_free (label_text);
145 }
146
147 static gboolean
148 idle_get_mime_part_size_cb (gpointer userdata)
149 {
150         ModestAttachmentView *view = (ModestAttachmentView *) userdata;
151         gdk_threads_enter ();
152
153         if (GTK_WIDGET_VISIBLE (view)) {
154                 update_size_label (view);
155         }
156
157         gdk_threads_leave ();
158
159         g_object_unref (view);
160
161         return FALSE;
162 }
163
164 static gpointer
165 get_mime_part_size_thread (gpointer thr_user_data)
166 {
167         ModestAttachmentView *view =  (ModestAttachmentView *) thr_user_data;
168         ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (view);
169         gsize total = 0;
170         gssize result = 0;
171
172         result = tny_mime_part_decode_to_stream (priv->mime_part, priv->get_size_stream, NULL);
173         total = modest_count_stream_get_count(MODEST_COUNT_STREAM (priv->get_size_stream));
174         if (total == 0) {
175                 modest_count_stream_reset_count(MODEST_COUNT_STREAM (priv->get_size_stream));
176                 result = tny_mime_part_write_to_stream (priv->mime_part, priv->get_size_stream, NULL);
177                 total = modest_count_stream_get_count(MODEST_COUNT_STREAM (priv->get_size_stream));
178         }
179         
180         /* if there was an error, don't set the size (this is pretty uncommon) */
181         if (result < 0) {
182                 g_warning ("%s: error while writing mime part to stream\n", __FUNCTION__);
183         } else {
184                 priv->size = (guint64)total;
185                 g_idle_add (idle_get_mime_part_size_cb, g_object_ref (view));
186         }
187         g_object_unref (view);
188
189         return NULL;
190 }
191
192 void
193 modest_attachment_view_set_detect_size (ModestAttachmentView *self, gboolean detect_size)
194 {
195         ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
196
197         priv->detect_size = detect_size;
198         
199 }
200
201 void
202 modest_attachment_view_set_size (ModestAttachmentView *self, guint64 size)
203 {
204         ModestAttachmentViewPrivate *priv;
205
206         g_return_if_fail (MODEST_IS_ATTACHMENT_VIEW (self));
207         priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
208
209         if (!priv->detect_size) {
210                 priv->size = size;
211                 update_size_label (self);
212         } else {
213                 g_assert ("Shouldn't set the size of the attachment view if detect size is enabled");
214         }
215 }
216
217 guint64
218 modest_attachment_view_get_size (ModestAttachmentView *self)
219 {
220         ModestAttachmentViewPrivate *priv;
221
222         g_return_val_if_fail (MODEST_IS_ATTACHMENT_VIEW (self), 0);
223         priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
224
225         return priv->size;
226 }
227
228 static TnyMimePart *
229 modest_attachment_view_get_part (TnyMimePartView *self)
230 {
231         return MODEST_ATTACHMENT_VIEW_GET_CLASS (self)->get_part_func (self);
232 }
233
234 static TnyMimePart *
235 modest_attachment_view_get_part_default (TnyMimePartView *self)
236 {
237         ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
238
239         if (priv->mime_part)
240                 return TNY_MIME_PART (g_object_ref (priv->mime_part));
241         else
242                 return NULL;
243 }
244
245 static void
246 update_filename_request (ModestAttachmentView *self)
247 {
248         ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
249         /* gint width, height; */
250         
251         pango_layout_set_text (PANGO_LAYOUT (priv->layout_full_filename), 
252                                gtk_label_get_text (GTK_LABEL (priv->filename_view)), -1);
253
254
255 }
256
257 static void
258 modest_attachment_view_set_part (TnyMimePartView *self, TnyMimePart *mime_part)
259 {
260         MODEST_ATTACHMENT_VIEW_GET_CLASS (self)->set_part_func (self, mime_part);
261         return;
262 }
263
264
265 static void
266 modest_attachment_view_set_part_default (TnyMimePartView *self, TnyMimePart *mime_part)
267 {
268         ModestAttachmentViewPrivate *priv = NULL;
269         gchar *filename = NULL;
270         gchar *file_icon_name = NULL;
271         gboolean show_size = FALSE;
272         
273         g_return_if_fail (TNY_IS_MIME_PART_VIEW (self));
274         g_return_if_fail (TNY_IS_MIME_PART (mime_part));
275         priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
276
277         if (priv->mime_part != NULL) {
278                 g_object_unref (priv->mime_part);
279         }
280
281         priv->mime_part = g_object_ref (mime_part);
282
283         priv->size = 0;
284         priv->is_purged = tny_mime_part_is_purged (mime_part);
285
286         if (TNY_IS_MSG (mime_part)) {
287                 TnyHeader *header = tny_msg_get_header (TNY_MSG (mime_part));
288                 if (TNY_IS_HEADER (header)) {
289                         filename = g_strdup (tny_mime_part_get_filename (mime_part));
290                         if (!filename)
291                                 filename = tny_header_dup_subject (header);
292                         if (filename == NULL || filename[0] == '\0') {
293                                 if (filename)
294                                         g_free (filename);
295                                 filename = g_strdup (_("mail_va_no_subject"));
296                         }
297                         if (priv->is_purged) {
298                                 file_icon_name = modest_platform_get_file_icon_name (NULL, NULL, NULL);
299                         } else {
300                                 gchar *header_content_type;
301                                 header_content_type = modest_tny_mime_part_get_content_type (mime_part);
302                                 if ((g_str_has_prefix (header_content_type, "message/rfc822") ||
303                                      g_str_has_prefix (header_content_type, "multipart/"))) {
304                                         file_icon_name = 
305                                                 modest_platform_get_file_icon_name (
306                                                         NULL, "message/rfc822", NULL);
307                                 } else if (g_str_has_prefix (header_content_type, "text/")) {
308                                         file_icon_name = 
309                                                 modest_platform_get_file_icon_name (
310                                                         NULL, tny_mime_part_get_content_type (mime_part), NULL);
311                                 } else {
312                                         file_icon_name = 
313                                                 modest_platform_get_file_icon_name (
314                                                         NULL, header_content_type, NULL);
315                                 }
316                                 g_free (header_content_type);
317                         }
318                         g_object_unref (header);
319                 }
320         } else {
321                 gboolean is_other_body = FALSE;
322                 filename = g_strdup (tny_mime_part_get_filename (mime_part));
323                 if (filename == NULL) {
324                         gchar *description;
325                         description = modest_tny_mime_part_get_header_value (mime_part, "Content-Description");
326                         if (description) {
327                                 g_strstrip (description);
328                                 filename = description;
329                         }
330                         if (!filename || filename[0] == '\0') {
331                                 g_free (filename);
332                                 filename = g_strdup (_("mail_va_no_subject"));
333                         }
334                         is_other_body = TRUE;
335                 }
336                 if (priv->is_purged) {
337                         file_icon_name = modest_platform_get_file_icon_name (NULL, NULL, NULL);
338                 } else {
339                         if (is_other_body) {
340                                 file_icon_name = modest_platform_get_file_icon_name (NULL, "message/rfc822", NULL);
341                         } else {
342                                 file_icon_name = modest_platform_get_file_icon_name (
343                                         filename, modest_tny_mime_part_get_content_type (mime_part), NULL);
344                                 show_size = TRUE;
345                         }
346                 }
347         }
348
349         if (file_icon_name) {
350                 gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), file_icon_name, GTK_ICON_SIZE_MENU);
351                 g_free (file_icon_name);
352         } else {
353                 gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), UNKNOWN_FILE_ICON, GTK_ICON_SIZE_MENU);
354         }
355
356         if (priv->is_purged) {
357                 gchar * label_str = g_markup_printf_escaped(
358                         "<span style='italic' foreground='grey'>%s</span>",
359                         filename);
360                 gtk_label_set_markup (GTK_LABEL (priv->filename_view), label_str);
361                 g_free (label_str);
362         } else {
363                 gtk_label_set_text (GTK_LABEL (priv->filename_view), filename);
364         }
365         g_free (filename);
366         update_filename_request (MODEST_ATTACHMENT_VIEW (self));
367
368         gtk_label_set_text (GTK_LABEL (priv->size_view), "");
369
370         if (show_size && priv->detect_size) {
371                 gchar *disposition;
372
373                 disposition = modest_tny_mime_part_get_header_value (mime_part, "Content-Disposition");
374                 if (disposition) {
375                         const gchar *size_tmp;
376                         size_tmp = strstr (disposition, "size=");
377                         if (size_tmp) size_tmp += strlen("size=");
378                         if (size_tmp) {
379                                 gchar *disposition_value;
380                                 const gchar *size_end;
381                                 size_end = strstr (size_tmp, ";");
382                                 if (size_end == NULL) {
383                                         disposition_value = g_strdup (size_tmp);
384                                 } else {
385                                         disposition_value = g_strndup (size_tmp, size_end - size_tmp);
386                                 }
387                                 if (disposition_value && disposition_value[0] != '\0') {
388                                         priv->size = atoll (disposition_value);
389                                         if (priv->size != 0) {
390                                                 show_size = FALSE;
391                                                 update_size_label (MODEST_ATTACHMENT_VIEW (self));
392                                         }
393                                 }
394                                 g_free (disposition_value);
395                         }
396                         
397                         g_free (disposition);
398                 }
399         }
400
401         if (show_size && priv->detect_size) {
402                 g_object_ref (self);
403                 if (!priv->get_size_stream)
404                         priv->get_size_stream = modest_count_stream_new ();
405                 g_thread_create (get_mime_part_size_thread, self, FALSE, NULL);
406         }
407
408         gtk_widget_queue_draw (GTK_WIDGET (self));
409 }
410
411 static void
412 modest_attachment_view_clear (TnyMimePartView *self)
413 {
414         MODEST_ATTACHMENT_VIEW_GET_CLASS (self)->clear_func (self);
415         return;
416 }
417
418 static void
419 modest_attachment_view_clear_default (TnyMimePartView *self)
420 {
421         ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
422
423         if (priv->mime_part != NULL) {
424                 g_object_unref (priv->mime_part);
425                 priv->mime_part = NULL;
426         }
427
428         if (priv->get_size_stream)
429                 modest_count_stream_reset_count(MODEST_COUNT_STREAM (priv->get_size_stream));
430
431         priv->size = 0;
432
433         gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), 
434                                       UNKNOWN_FILE_ICON,
435                                       GTK_ICON_SIZE_MENU);
436         gtk_label_set_text (GTK_LABEL (priv->filename_view), "");
437         update_filename_request (MODEST_ATTACHMENT_VIEW(self));
438         gtk_label_set_text (GTK_LABEL (priv->size_view), " ");
439
440         gtk_widget_queue_draw (GTK_WIDGET (self));
441 }
442
443
444 /**
445  * modest_attachment_view_new:
446  * @mime_part: a #TnyMimePart
447  *
448  * Constructor for attachment view widget.
449  *
450  * Return value: a new #ModestAttachmentView instance implemented for Gtk+
451  **/
452 GtkWidget*
453 modest_attachment_view_new (TnyMimePart *mime_part, gboolean detect_size)
454 {
455         ModestAttachmentView *self = g_object_new (MODEST_TYPE_ATTACHMENT_VIEW, 
456                                                    NULL);
457
458         modest_attachment_view_set_detect_size (self, detect_size);
459
460         modest_attachment_view_set_part (TNY_MIME_PART_VIEW (self), mime_part);
461
462         return GTK_WIDGET (self);
463 }
464
465 static void
466 modest_attachment_view_instance_init (GTypeInstance *instance, gpointer g_class)
467 {
468         ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (instance);
469         PangoContext *context;
470         GtkWidget *box = NULL;
471         GtkWidget *icon_alignment = NULL;
472
473 #ifdef MODEST_TOOLKIT_HILDON2
474         PangoAttrList *attr_list;
475         attr_list = pango_attr_list_new ();
476         pango_attr_list_insert (attr_list, pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
477 #endif
478
479         priv->mime_part = NULL;
480         icon_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
481         gtk_alignment_set_padding (GTK_ALIGNMENT (icon_alignment), 0, 0, 0, MODEST_MARGIN_DEFAULT);
482         priv->icon = gtk_image_new ();
483         priv->filename_view = gtk_label_new ("");
484         gtk_label_set_line_wrap (GTK_LABEL (priv->filename_view), FALSE);
485         gtk_label_set_ellipsize (GTK_LABEL (priv->filename_view), PANGO_ELLIPSIZE_END);
486         gtk_label_set_single_line_mode (GTK_LABEL (priv->filename_view), TRUE);
487         gtk_label_set_selectable (GTK_LABEL (priv->filename_view), FALSE);
488         priv->size_view = gtk_label_new (" ");
489         gtk_label_set_line_wrap (GTK_LABEL (priv->size_view), FALSE);
490         gtk_label_set_selectable (GTK_LABEL (priv->size_view), FALSE);
491         gtk_misc_set_alignment (GTK_MISC (priv->size_view), 0.0, 0.5);
492         gtk_misc_set_alignment (GTK_MISC (priv->filename_view), 0.0, 0.5);
493
494 #ifdef MODEST_TOOLKIT_HILDON2
495         gtk_label_set_attributes (GTK_LABEL (priv->filename_view), attr_list);
496         gtk_label_set_attributes (GTK_LABEL (priv->size_view), attr_list);
497 #endif
498
499         priv->get_size_stream = NULL;
500         priv->size = 0;
501         priv->detect_size = TRUE;
502
503         box = gtk_hbox_new (FALSE, 0);
504         gtk_container_add (GTK_CONTAINER (icon_alignment), priv->icon);
505         gtk_box_pack_start (GTK_BOX (box), icon_alignment, FALSE, FALSE, 0);
506         gtk_box_pack_start (GTK_BOX (box), priv->filename_view, TRUE, TRUE, 0);
507         gtk_box_pack_start (GTK_BOX (box), priv->size_view, FALSE, FALSE, 0);
508         gtk_container_add (GTK_CONTAINER (instance), box);
509
510 /*      gtk_widget_get_style */
511 /*      gtk_widget_modify_bg (instance, GTK_STATE_SELECTED, selection_color); */
512
513         context = gtk_widget_get_pango_context (priv->filename_view);
514         priv->layout_full_filename = pango_layout_new (context);
515         
516         pango_layout_set_ellipsize (priv->layout_full_filename, PANGO_ELLIPSIZE_NONE);
517
518         gtk_event_box_set_above_child (GTK_EVENT_BOX (instance), FALSE);
519         gtk_event_box_set_visible_window (GTK_EVENT_BOX (instance), TRUE);
520         gtk_widget_set_events (GTK_WIDGET (instance), 0);
521
522 #ifdef MODEST_TOOLKIT_HILDON2
523         pango_attr_list_unref (attr_list);
524 #endif
525
526         GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (instance), GTK_CAN_FOCUS);
527
528         g_signal_connect (G_OBJECT (instance), "notify::style", G_CALLBACK (on_notify_style), (gpointer) instance);
529
530         update_style (MODEST_ATTACHMENT_VIEW (instance));
531
532
533         return;
534 }
535
536 static void
537 modest_attachment_view_finalize (GObject *object)
538 {
539         ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (object);
540
541         if (priv->get_size_stream != NULL) {
542                 g_object_unref (priv->get_size_stream);
543                 priv->get_size_stream = NULL;
544         }
545
546         if (G_LIKELY (priv->mime_part)) {
547                 g_object_unref (G_OBJECT (priv->mime_part));
548                 priv->mime_part = NULL;
549         }
550
551         (*parent_class->finalize) (object);
552
553         return;
554 }
555
556 static void
557 size_allocate (GtkWidget *widget, GtkAllocation *allocation)
558 {
559         ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (widget);
560         gint width, width_diff;
561
562         GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
563         pango_layout_set_font_description (priv->layout_full_filename, pango_context_get_font_description(pango_layout_get_context (gtk_label_get_layout (GTK_LABEL (priv->filename_view)))));
564
565         pango_layout_get_pixel_size (priv->layout_full_filename, &width, NULL);
566         width_diff = priv->filename_view->allocation.width - width;
567         if (width_diff > 0) {
568                 GtkAllocation filename_alloc, filesize_alloc;
569                 filename_alloc = priv->filename_view->allocation;
570                 filesize_alloc = priv->size_view->allocation;
571                 filename_alloc.width -= width_diff;
572                 filesize_alloc.width += width_diff;
573                 filesize_alloc.x -= width_diff;
574                 gtk_widget_size_allocate (priv->filename_view, &filename_alloc);
575                 gtk_widget_size_allocate (priv->size_view, &filesize_alloc);
576         }
577         
578 }
579
580
581 static void 
582 modest_attachment_view_class_init (ModestAttachmentViewClass *klass)
583 {
584         GObjectClass *object_class;
585         GtkWidgetClass *widget_class;
586
587         parent_class = g_type_class_peek_parent (klass);
588         object_class = (GObjectClass*) klass;
589         widget_class = GTK_WIDGET_CLASS (klass);
590
591         object_class->finalize = modest_attachment_view_finalize;
592
593         klass->get_part_func = modest_attachment_view_get_part_default;
594         klass->set_part_func = modest_attachment_view_set_part_default;
595         klass->clear_func = modest_attachment_view_clear_default;
596
597         widget_class->size_allocate = size_allocate;
598
599         g_type_class_add_private (object_class, sizeof (ModestAttachmentViewPrivate));
600
601         return;
602 }
603
604 static void
605 tny_mime_part_view_init (gpointer g, gpointer iface_data)
606 {
607         TnyMimePartViewIface *klass = (TnyMimePartViewIface *)g;
608
609         klass->get_part = modest_attachment_view_get_part;
610         klass->set_part = modest_attachment_view_set_part;
611         klass->clear = modest_attachment_view_clear;
612
613         return;
614 }
615
616 GType 
617 modest_attachment_view_get_type (void)
618 {
619         static GType type = 0;
620
621         if (G_UNLIKELY(type == 0))
622         {
623                 static const GTypeInfo info = 
624                 {
625                   sizeof (ModestAttachmentViewClass),
626                   NULL,   /* base_init */
627                   NULL,   /* base_finalize */
628                   (GClassInitFunc) modest_attachment_view_class_init,   /* class_init */
629                   NULL,   /* class_finalize */
630                   NULL,   /* class_data */
631                   sizeof (ModestAttachmentView),
632                   0,      /* n_preallocs */
633                   modest_attachment_view_instance_init    /* instance_init */
634                 };
635
636                 static const GInterfaceInfo tny_mime_part_view_info =
637                 {
638                         (GInterfaceInitFunc) tny_mime_part_view_init, /* interface_init */
639                         NULL,        /* interface_finalize */
640                         NULL         /* interface_data */
641                 };
642
643                 type = g_type_register_static (GTK_TYPE_EVENT_BOX,
644                         "ModestAttachmentView",
645                         &info, 0);
646
647                 g_type_add_interface_static (type, TNY_TYPE_MIME_PART_VIEW,
648                                              &tny_mime_part_view_info);
649
650         }
651
652         return type;
653 }