root/trunk/libtinymailui-gtk/tny-gtk-attachment-mime-part-view.c

Revision 3666 (checked in by jdapena, 7 months ago)

* Use GOnce registering all types in tinymail to make

registering thread-safe.

Line 
1 /* libtinymailui-gtk - The Tiny Mail UI library for Gtk+
2  * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with self library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /**
21  * TnyGtkAttachmentMimePartView:
22  *
23  * A #TnyMimePartView for showing a #TnyMimePart that is also an attachment
24  *
25  * free-function: g_object_unref
26  **/
27
28 #include <config.h>
29
30 #include <glib/gi18n-lib.h>
31
32 #include <unistd.h>
33 #include <fcntl.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <sys/stat.h>
37 #include <sys/types.h>
38
39 #include <string.h>
40 #include <gtk/gtk.h>
41 #include <tny-list.h>
42
43 #ifdef GNOME
44 #include <tny-vfs-stream.h>
45 #include <libgnomevfs/gnome-vfs.h>
46 #include <libgnomevfs/gnome-vfs-utils.h>
47 #else
48 #include <tny-fs-stream.h>
49 #endif
50
51 #include <tny-gtk-attachment-mime-part-view.h>
52
53
54 static GObjectClass *parent_class = NULL;
55
56 typedef struct _TnyGtkAttachmentMimePartViewPriv TnyGtkAttachmentMimePartViewPriv;
57
58 struct _TnyGtkAttachmentMimePartViewPriv
59 {
60         TnyMimePart *part;
61         TnyGtkAttachListModel *imodel;
62 };
63
64 #define TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_PRIVATE(o) \
65         (G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_TYPE_GTK_ATTACHMENT_MIME_PART_VIEW, TnyGtkAttachmentMimePartViewPriv))
66
67
68 static TnyMimePart*
69 tny_gtk_attachment_mime_part_view_get_part (TnyMimePartView *self)
70 {
71         return TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_CLASS (self)->get_part(self);
72 }
73
74 static TnyMimePart*
75 tny_gtk_attachment_mime_part_view_get_part_default (TnyMimePartView *self)
76 {
77         TnyGtkAttachmentMimePartViewPriv *priv = TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_PRIVATE (self);
78         return (priv->part)?TNY_MIME_PART (g_object_ref (priv->part)):NULL;
79 }
80
81 static void
82 tny_gtk_attachment_mime_part_view_set_part (TnyMimePartView *self, TnyMimePart *part)
83 {
84         TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_CLASS (self)->set_part(self, part);
85         return;
86 }
87
88 static void
89 tny_gtk_attachment_mime_part_view_set_part_default (TnyMimePartView *self, TnyMimePart *part)
90 {
91         TnyGtkAttachmentMimePartViewPriv *priv = TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_PRIVATE (self);
92
93         if (G_LIKELY (priv->part))
94                 g_object_unref (G_OBJECT (priv->part));
95
96         if (part)
97         {
98                 g_assert (TNY_IS_LIST (priv->imodel));
99                 tny_list_prepend (TNY_LIST (priv->imodel), G_OBJECT (part));
100                 priv->part = g_object_ref (G_OBJECT (part));
101         }
102
103         return;
104 }
105
106 static void
107 tny_gtk_attachment_mime_part_view_clear (TnyMimePartView *self)
108 {
109         TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_CLASS (self)->clear(self);
110         return;
111 }
112
113 static void
114 tny_gtk_attachment_mime_part_view_clear_default (TnyMimePartView *self)
115 {
116         TnyGtkAttachmentMimePartViewPriv *priv = TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_PRIVATE (self);
117
118         if (priv->part)
119         {
120                 tny_list_remove (TNY_LIST (priv->imodel), G_OBJECT (priv->part));
121                 g_object_unref (G_OBJECT (priv->part));
122                 priv->part = NULL;
123         }
124
125         return;
126 }
127
128 /**
129  * tny_gtk_attachment_mime_part_view_new:
130  * @iview: A #TnyGtkAttachListModel
131  *
132  * Create a new #TnyMimePartView for showing MIME parts that are attachments.
133  * The @iview parameter that you must pass is the #GtkTreeModel containing the
134  * #TnyMimePart instances that are attachments.
135  *
136  * returns: (caller-owns): a new #TnyMimePartView for showing MIME parts that are attachments
137  * since: 1.0
138  * audience: application-developer
139  **/
140 TnyMimePartView*
141 tny_gtk_attachment_mime_part_view_new (TnyGtkAttachListModel *iview)
142 {
143         TnyGtkAttachmentMimePartView *self = g_object_new (TNY_TYPE_GTK_ATTACHMENT_MIME_PART_VIEW, NULL);
144
145         g_object_ref (G_OBJECT (iview));
146         TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_PRIVATE (self)->imodel = iview;
147
148         return TNY_MIME_PART_VIEW (self);
149 }
150
151 static void
152 tny_gtk_attachment_mime_part_view_instance_init (GTypeInstance *instance, gpointer g_class)
153 {
154         TnyGtkAttachmentMimePartView *self = (TnyGtkAttachmentMimePartView *)instance;
155         TnyGtkAttachmentMimePartViewPriv *priv = TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_PRIVATE (self);
156
157         priv->part = NULL;
158         priv->imodel = NULL;
159
160         return;
161 }
162
163 static void
164 tny_gtk_attachment_mime_part_view_finalize (GObject *object)
165 {
166         TnyGtkAttachmentMimePartView *self = (TnyGtkAttachmentMimePartView *)object;   
167         TnyGtkAttachmentMimePartViewPriv *priv = TNY_GTK_ATTACHMENT_MIME_PART_VIEW_GET_PRIVATE (self);
168
169         if (priv->imodel)
170                 g_object_unref (G_OBJECT (priv->imodel));
171         priv->imodel = NULL;
172
173         if (G_LIKELY (priv->part))
174                 g_object_unref (G_OBJECT (priv->part));
175         priv->part = NULL;
176
177         (*parent_class->finalize) (object);
178
179         return;
180 }
181
182 static void
183 tny_mime_part_view_init (gpointer g, gpointer iface_data)
184 {
185         TnyMimePartViewIface *klass = (TnyMimePartViewIface *)g;
186
187         klass->get_part= tny_gtk_attachment_mime_part_view_get_part;
188         klass->set_part= tny_gtk_attachment_mime_part_view_set_part;
189         klass->clear= tny_gtk_attachment_mime_part_view_clear;
190
191         return;
192 }
193
194 static void
195 tny_gtk_attachment_mime_part_view_class_init (TnyGtkAttachmentMimePartViewClass *class)
196 {
197         GObjectClass *object_class;
198
199         parent_class = g_type_class_peek_parent (class);
200         object_class = (GObjectClass*) class;
201
202         class->get_part= tny_gtk_attachment_mime_part_view_get_part_default;
203         class->set_part= tny_gtk_attachment_mime_part_view_set_part_default;
204         class->clear= tny_gtk_attachment_mime_part_view_clear_default;
205
206         object_class->finalize = tny_gtk_attachment_mime_part_view_finalize;
207         g_type_class_add_private (object_class, sizeof (TnyGtkAttachmentMimePartViewPriv));
208
209         return;
210 }
211
212 static gpointer
213 tny_gtk_attachment_mime_part_view_register_type (gpointer notused)
214 {
215         GType type = 0;
216
217         static const GTypeInfo info =
218                 {
219                   sizeof (TnyGtkAttachmentMimePartViewClass),
220                   NULL,   /* base_init */
221                   NULL,   /* base_finalize */
222                   (GClassInitFunc) tny_gtk_attachment_mime_part_view_class_init,   /* class_init */
223                   NULL,   /* class_finalize */
224                   NULL,   /* class_data */
225                   sizeof (TnyGtkAttachmentMimePartView),
226                   0,      /* n_preallocs */
227                   tny_gtk_attachment_mime_part_view_instance_init,    /* instance_init */
228                   NULL
229                 };
230
231         static const GInterfaceInfo tny_mime_part_view_info =
232                 {
233                   (GInterfaceInitFunc) tny_mime_part_view_init, /* interface_init */
234                   NULL,         /* interface_finalize */
235                   NULL          /* interface_data */
236                 };
237
238         type = g_type_register_static (G_TYPE_OBJECT,
239                                        "TnyGtkAttachmentMimePartView",
240                                        &info, 0);
241
242         g_type_add_interface_static (type, TNY_TYPE_MIME_PART_VIEW,
243                                      &tny_mime_part_view_info);
244
245         return GUINT_TO_POINTER (type);
246 }
247
248 /**
249  * tny_gtk_attachment_mime_part_view_get_type:
250  *
251  * GType system helper function
252  *
253  * returns: a #GType
254  **/
255 GType
256 tny_gtk_attachment_mime_part_view_get_type (void)
257 {
258         static GOnce once = G_ONCE_INIT;
259         g_once (&once, tny_gtk_attachment_mime_part_view_register_type, NULL);
260         return GPOINTER_TO_UINT (once.retval);
261 }
Note: See TracBrowser for help on using the browser.