root/trunk/libtinymailui-webkit/tny-webkit-msg-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-webkit - The Tiny Mail UI library for Webkit
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 #include <config.h>
21 #include <glib/gi18n-lib.h>
22 #include <gtk/gtk.h>
23
24 #include <tny-webkit-msg-view.h>
25 #include <tny-webkit-html-mime-part-view.h>
26
27 static GObjectClass *parent_class = NULL;
28
29 /**
30  * tny_webkit_msg_view_new:
31  *
32  * Create a new #TnyMsgView that can display HTML messages.
33  *
34  * Return value: a new #TnyMsgView instance implemented for Gtk+
35  **/
36 TnyMsgView*
37 tny_webkit_msg_view_new (void)
38 {
39         TnyWebkitMsgView *self = g_object_new (TNY_TYPE_WEBKIT_MSG_VIEW, NULL);
40        
41         return TNY_MSG_VIEW (self);
42 }
43
44 static void
45 tny_webkit_msg_view_instance_init (GTypeInstance *instance, gpointer g_class)
46 {
47         return;
48 }
49
50 static void
51 tny_webkit_msg_view_finalize (GObject *object)
52 {
53         (*parent_class->finalize) (object);
54
55         return;
56 }
57
58
59 /**
60  * tny_webkit_msg_view_create_mime_part_view_for_default:
61  * @self: a #TnyWebkitMsgView instance
62  * @part: a #TnyMimePart instance
63  *
64  * This is non-public API documentation
65  *
66  * This implementation will return a #TnyWebkitHtmlMimePartView in case part
67  * is of content type text/html. Else it will call its super implementation.
68  **/
69 static TnyMimePartView*
70 tny_webkit_msg_view_create_mime_part_view_for_default (TnyMsgView *self, TnyMimePart *part)
71 {
72         TnyMimePartView *retval = NULL;
73
74         g_assert (TNY_IS_MIME_PART (part));
75
76         /* HTML mime part (shows HTML using GtkWebkit) */
77         if (tny_mime_part_content_type_is (part, "text/html"))
78         {
79                 GtkWidget *widget = (GtkWidget *) self;
80
81                 retval = tny_webkit_html_mime_part_view_new ();
82
83                 gtk_widget_set_usize (GTK_WIDGET (retval),
84                         widget->allocation.width>11?widget->allocation.width-10:1, 2500);
85
86         } else
87                 retval = TNY_GTK_MSG_VIEW_CLASS (parent_class)->create_mime_part_view_for(self, part);
88
89         return retval;
90 }
91
92 static TnyMimePartView*
93 tny_webkit_msg_view_create_mime_part_view_for (TnyMsgView *self, TnyMimePart *part)
94 {
95         return TNY_WEBKIT_MSG_VIEW_GET_CLASS (self)->create_mime_part_view_for(self, part);
96 }
97
98
99
100 static TnyMsgView*
101 tny_webkit_msg_view_create_new_inline_viewer (TnyMsgView *self)
102 {
103         return TNY_WEBKIT_MSG_VIEW_GET_CLASS (self)->create_new_inline_viewer(self);
104 }
105
106 /**
107  * tny_webkit_msg_view_create_new_inline_viewer_default:
108  * @self: a #TnyWebkitMsgView instance
109  *
110  * This is non-public API documentation
111  *
112  * This implementation returns a new #TnyWebkitMsgView instance suitable for
113  * displaying HTML messages.
114  **/
115 static TnyMsgView*
116 tny_webkit_msg_view_create_new_inline_viewer_default (TnyMsgView *self)
117 {
118         return tny_webkit_msg_view_new ();
119 }
120
121
122 static void
123 tny_webkit_msg_view_class_init (TnyWebkitMsgViewClass *class)
124 {
125         GObjectClass *object_class;
126
127         parent_class = g_type_class_peek_parent (class);
128         object_class = (GObjectClass*) class;
129
130         class->create_mime_part_view_for= tny_webkit_msg_view_create_mime_part_view_for_default;
131         class->create_new_inline_viewer= tny_webkit_msg_view_create_new_inline_viewer_default;
132
133         object_class->finalize = tny_webkit_msg_view_finalize;
134
135         TNY_GTK_MSG_VIEW_CLASS (class)->create_mime_part_view_for= tny_webkit_msg_view_create_mime_part_view_for;
136         TNY_GTK_MSG_VIEW_CLASS (class)->create_new_inline_viewer= tny_webkit_msg_view_create_new_inline_viewer;
137
138         return;
139 }
140
141 static gpointer
142 tny_webkit_msg_view_register_type (gpointer notused)
143 {
144         GType type = 0;
145
146         static const GTypeInfo info =
147                 {
148                   sizeof (TnyWebkitMsgViewClass),
149                   NULL,   /* base_init */
150                   NULL,   /* base_finalize */
151                   (GClassInitFunc) tny_webkit_msg_view_class_init,   /* class_init */
152                   NULL,   /* class_finalize */
153                   NULL,   /* class_data */
154                   sizeof (TnyWebkitMsgView),
155                   0,      /* n_preallocs */
156                   tny_webkit_msg_view_instance_init    /* instance_init */
157                 };
158
159         type = g_type_register_static (TNY_TYPE_GTK_MSG_VIEW,
160                                        "TnyWebkitMsgView",
161                                        &info, 0);
162
163         return GUINT_TO_POINTER (type);
164 }
165
166 GType
167 tny_webkit_msg_view_get_type (void)
168 {
169         static GOnce once = G_ONCE_INIT;
170         g_once (&once, tny_webkit_msg_view_register_type, NULL);
171         return GPOINTER_TO_UINT (once.retval);
172 }
Note: See TracBrowser for help on using the browser.