root/trunk/libtinymailui-gtkhtml/tny-gtk-html-msg-view.c

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

* Use GOnce registering all types in tinymail to make

registering thread-safe.

Line 
1 /* libtinymailui-gtk_html - The Tiny Mail UI library for GtkHtml
2  * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
3  *
4  * This component was developed based on Modest's ModestGtkHtmlMsgView
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with self library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include <config.h>
23 #include <glib/gi18n-lib.h>
24 #include <gtk/gtk.h>
25
26 #include <tny-gtk-html-msg-view.h>
27 #include <tny-gtk-html-mime-part-view.h>
28
29 static GObjectClass *parent_class = NULL;
30
31 /**
32  * tny_gtk_html_msg_view_new:
33  *
34  * Create a new #TnyMsgView that can display HTML messages.
35  *
36  * Return value: a new #TnyMsgView instance implemented for Gtk+
37  **/
38 TnyMsgView*
39 tny_gtk_html_msg_view_new (void)
40 {
41         TnyGtkHtmlMsgView *self = g_object_new (TNY_TYPE_GTK_HTML_MSG_VIEW, NULL);
42         return TNY_MSG_VIEW (self);
43 }
44
45
46
47 static void
48 tny_gtk_html_msg_view_instance_init (GTypeInstance *instance, gpointer g_class)
49 {
50         return;
51 }
52
53 static void
54 tny_gtk_html_msg_view_finalize (GObject *object)
55 {
56         (*parent_class->finalize) (object);
57
58         return;
59 }
60
61
62 /**
63  * tny_gtk_html_msg_view_create_mime_part_view_for_default:
64  * @self: a #TnyGtkHtmlMsgView instance
65  * @part: a #TnyMimePart instance
66  *
67  * This is non-public API documentation
68  *
69  * This implementation will return a #TnyGtkHtmlHtmlMimePartView in case part
70  * is of content type text/html. Else it will call its super implementation.
71  **/
72 static TnyMimePartView*
73 tny_gtk_html_msg_view_create_mime_part_view_for_default (TnyMsgView *self, TnyMimePart *part)
74 {
75         TnyMimePartView *retval = NULL;
76
77         g_assert (TNY_IS_MIME_PART (part));
78
79         /* HTML mime part (shows HTML using GtkGtkHtml) */
80         if (tny_mime_part_content_type_is (part, "text/html"))
81         {
82                 TnyStatusCallback status_callback;
83                 gpointer status_user_data;
84
85                 tny_gtk_msg_view_get_status_callback (TNY_GTK_MSG_VIEW (self), &status_callback, &status_user_data);
86
87                 retval = tny_gtk_html_mime_part_view_new (status_callback, status_user_data);
88         } else
89                 retval = TNY_GTK_MSG_VIEW_CLASS (parent_class)->create_mime_part_view_for(self, part);
90
91         return retval;
92 }
93
94 static TnyMimePartView*
95 tny_gtk_html_msg_view_create_mime_part_view_for (TnyMsgView *self, TnyMimePart *part)
96 {
97         return TNY_GTK_HTML_MSG_VIEW_GET_CLASS (self)->create_mime_part_view_for(self, part);
98 }
99
100
101
102 static TnyMsgView*
103 tny_gtk_html_msg_view_create_new_inline_viewer (TnyMsgView *self)
104 {
105         return TNY_GTK_HTML_MSG_VIEW_GET_CLASS (self)->create_new_inline_viewer(self);
106 }
107
108 /**
109  * tny_gtk_html_msg_view_create_new_inline_viewer_default:
110  * @self: a #TnyGtkHtmlMsgView instance
111  *
112  * This is non-public API documentation
113  *
114  * This implementation returns a new #TnyGtkHtmlMsgView instance suitable for
115  * displaying HTML messages.
116  **/
117 static TnyMsgView*
118 tny_gtk_html_msg_view_create_new_inline_viewer_default (TnyMsgView *self)
119 {
120         return tny_gtk_html_msg_view_new ();
121 }
122
123
124 static void
125 tny_gtk_html_msg_view_class_init (TnyGtkHtmlMsgViewClass *class)
126 {
127         GObjectClass *object_class;
128
129         parent_class = g_type_class_peek_parent (class);
130         object_class = (GObjectClass*) class;
131
132         class->create_mime_part_view_for= tny_gtk_html_msg_view_create_mime_part_view_for_default;
133         class->create_new_inline_viewer= tny_gtk_html_msg_view_create_new_inline_viewer_default;
134
135         object_class->finalize = tny_gtk_html_msg_view_finalize;
136
137         TNY_GTK_MSG_VIEW_CLASS (class)->create_mime_part_view_for= tny_gtk_html_msg_view_create_mime_part_view_for;
138         TNY_GTK_MSG_VIEW_CLASS (class)->create_new_inline_viewer= tny_gtk_html_msg_view_create_new_inline_viewer;
139
140         return;
141 }
142
143 static gpointer
144 tny_gtk_html_msg_view_register_type (gpointer notused)
145 {
146         GType type = 0;
147
148         static const GTypeInfo info =
149                 {
150                   sizeof (TnyGtkHtmlMsgViewClass),
151                   NULL,   /* base_init */
152                   NULL,   /* base_finalize */
153                   (GClassInitFunc) tny_gtk_html_msg_view_class_init,   /* class_init */
154                   NULL,   /* class_finalize */
155                   NULL,   /* class_data */
156                   sizeof (TnyGtkHtmlMsgView),
157                   0,      /* n_preallocs */
158                   tny_gtk_html_msg_view_instance_init    /* instance_init */
159                 };
160
161         type = g_type_register_static (TNY_TYPE_GTK_MSG_VIEW,
162                                        "TnyGtkHtmlMsgView",
163                                        &info, 0);
164
165         return GUINT_TO_POINTER (type);
166 }
167
168 GType
169 tny_gtk_html_msg_view_get_type (void)
170 {
171         static GOnce once = G_ONCE_INIT;
172         g_once (&once, tny_gtk_html_msg_view_register_type, NULL);
173         return GPOINTER_TO_UINT (once.retval);
174 }
Note: See TracBrowser for help on using the browser.