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