1 /* Copyright (c) 2007, 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.
32 //#include <glib/gi18n-lib.h>
38 #include <tny-simple-list.h>
40 #include <modest-platform.h>
41 #include <modest-runtime.h>
42 #include <modest-attachment-view.h>
43 #include <modest-attachments-view.h>
45 static GObjectClass *parent_class = NULL;
53 typedef struct _ModestAttachmentsViewPriv ModestAttachmentsViewPriv;
55 struct _ModestAttachmentsViewPriv
60 #define MODEST_ATTACHMENTS_VIEW_GET_PRIVATE(o) \
61 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ATTACHMENTS_VIEW, ModestAttachmentsViewPriv))
63 static guint signals[LAST_SIGNAL] = {0};
66 activate_attachment (ModestAttachmentView *attachment_view,
69 TnyMimePart *mime_part;
71 mime_part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (attachment_view));
72 g_signal_emit (G_OBJECT (userdata), signals[ACTIVATE_SIGNAL], 0, mime_part);
73 g_object_unref (mime_part);
77 * modest_attachments_view_new:
80 * Constructor for attachments view widget.
82 * Return value: a new #ModestAttachmentsView instance implemented for Gtk+
85 modest_attachments_view_new (TnyMsg *msg)
87 ModestAttachmentsView *self = g_object_new (MODEST_TYPE_ATTACHMENTS_VIEW,
90 "resize-mode", GTK_RESIZE_PARENT,
93 modest_attachments_view_set_message (self, msg);
95 return GTK_WIDGET (self);
99 modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, TnyMsg *msg)
101 ModestAttachmentsViewPriv *priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (attachments_view);
106 g_object_unref (priv->msg);
108 g_object_ref (G_OBJECT(msg));
112 gtk_container_foreach (GTK_CONTAINER (attachments_view), (GtkCallback) gtk_widget_destroy, NULL);
114 if (priv->msg == NULL) {
118 parts = TNY_LIST (tny_simple_list_new ());
119 tny_mime_part_get_parts (TNY_MIME_PART (priv->msg), parts);
120 iter = tny_list_create_iterator (parts);
122 while (!tny_iterator_is_done (iter)) {
125 part = TNY_MIME_PART (tny_iterator_get_current (iter));
126 if (tny_mime_part_is_attachment (part)) {
127 modest_attachments_view_add_attachment (attachments_view, part);
129 g_object_unref (part);
130 tny_iterator_next (iter);
133 gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
138 modest_attachments_view_add_attachment (ModestAttachmentsView *attachments_view, TnyMimePart *part)
140 GtkWidget *att_view = NULL;
142 g_return_if_fail (MODEST_IS_ATTACHMENTS_VIEW (attachments_view));
143 g_return_if_fail (TNY_IS_MIME_PART (part));
144 g_return_if_fail (tny_mime_part_is_attachment (part));
146 att_view = modest_attachment_view_new (part);
147 gtk_box_pack_end (GTK_BOX (attachments_view), att_view, FALSE, FALSE, 0);
148 gtk_widget_show_all (att_view);
149 g_signal_connect (G_OBJECT (att_view), "activate", G_CALLBACK (activate_attachment), (gpointer) attachments_view);
153 modest_attachments_view_instance_init (GTypeInstance *instance, gpointer g_class)
155 ModestAttachmentsViewPriv *priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (instance);
163 modest_attachments_view_finalize (GObject *object)
165 ModestAttachmentsViewPriv *priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (object);
168 g_object_unref (priv->msg);
172 (*parent_class->finalize) (object);
178 modest_attachments_view_class_init (ModestAttachmentsViewClass *klass)
180 GObjectClass *object_class;
181 GtkWidgetClass *widget_class;
183 parent_class = g_type_class_peek_parent (klass);
184 object_class = (GObjectClass*) klass;
185 widget_class = GTK_WIDGET_CLASS (klass);
187 object_class->finalize = modest_attachments_view_finalize;
189 klass->activate = NULL;
191 g_type_class_add_private (object_class, sizeof (ModestAttachmentsViewPriv));
193 signals[ACTIVATE_SIGNAL] =
194 g_signal_new ("activate",
195 G_TYPE_FROM_CLASS (object_class),
196 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
197 G_STRUCT_OFFSET(ModestAttachmentsViewClass, activate),
199 g_cclosure_marshal_VOID__OBJECT,
200 G_TYPE_NONE, 1, G_TYPE_OBJECT);
206 modest_attachments_view_get_type (void)
208 static GType type = 0;
210 if (G_UNLIKELY(type == 0))
212 static const GTypeInfo info =
214 sizeof (ModestAttachmentsViewClass),
215 NULL, /* base_init */
216 NULL, /* base_finalize */
217 (GClassInitFunc) modest_attachments_view_class_init, /* class_init */
218 NULL, /* class_finalize */
219 NULL, /* class_data */
220 sizeof (ModestAttachmentsView),
222 modest_attachments_view_instance_init /* instance_init */
225 type = g_type_register_static (GTK_TYPE_VBOX,
226 "ModestAttachmentsView",