File: tny-msg-view.c

package info (click to toggle)
libtinymail 0.0.9-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,148 kB
  • ctags: 19,175
  • sloc: ansic: 151,565; xml: 20,145; sh: 9,245; makefile: 2,394; cs: 243; cpp: 141; python: 93; perl: 71
file content (282 lines) | stat: -rw-r--r-- 8,221 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/* libtinymailui - The Tiny Mail UI library
 * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with self library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

/**
 * TnyMsgView:
 * 
 * A type that can view a #TnyMsg and usually inherits from #TnyMimePartView
 *
 * free-function: g_object_unref
 **/

#include <config.h>

#include <tny-msg-view.h>

/**
 * tny_msg_view_create_new_inline_viewer:
 * @self: a #TnyMsgView
 *
 * Create a new #TnyMsgView that can be used to display an inline message, 
 * like a message/rfc822 MIME part. Usually it will return a new instance of
 * the same type as @self. The returned instance must be unreferenced after
 * use.
 *
 * Example:
 * <informalexample><programlisting>
 * static TnyMsgView*
 * tny_my_html_msg_view_create_new_inline_viewer (TnyMsgView *self)
 * {
 *    return tny_my_html_msg_view_new ();
 * }
 * </programlisting></informalexample>
 *
 * returns: (caller-owns): a #TnyMsgView instance
 * since: 1.0
 * audience: application-developer, type-implementer
 **/
TnyMsgView* 
tny_msg_view_create_new_inline_viewer (TnyMsgView *self)
{
#ifdef DEBUG
	if (!TNY_MSG_VIEW_GET_IFACE (self)->create_new_inline_viewer)
		g_critical ("You must implement tny_msg_view_create_new_inline_viewer\n");
#endif

	return TNY_MSG_VIEW_GET_IFACE (self)->create_new_inline_viewer(self);
}

/**
 * tny_msg_view_create_mime_part_view_for:
 * @self: a #TnyMsgView
 * @part: a #TnyMimePart
 *
 * Create a #TnyMimePartView instance for viewing @part. The returned instance
 * must be unreferenced after use. It's recommended to return the result of
 * calling the function on the super of @self (like in the example below) in
 * case your type's implementation can't display @part.
 *
 * Example:
 * <informalexample><programlisting>
 * static TnyMimePartView*
 * tny_my_html_msg_view_create_mime_part_view_for (TnyMsgView *self, TnyMimePart *part)
 * {
 *    TnyMimePartView *retval = NULL;
 *    if (tny_mime_part_content_type_is (part, "text/html")) {
 *        GtkWidget *widget = (GtkWidget *) self;
 *        retval = tny_my_html_mime_part_view_new ();
 *    } else
 *        retval = TNY_GTK_MSG_VIEW_CLASS (parent_class)->create_mime_part_view_for(self, part);
 *    return retval;
 * }
 * </programlisting></informalexample>
 *
 * ps. For a real and complete working example take a look at the implementation of 
 * #TnyMozEmbedMsgView in libtinymailui-mozembed.
 *
 * returns: (caller-owns): a #TnyMimePartView instance
 * since: 1.0
 * audience: application-developer, type-implementer
 **/
TnyMimePartView*
tny_msg_view_create_mime_part_view_for (TnyMsgView *self, TnyMimePart *part)
{
#ifdef DEBUG
	if (!TNY_MSG_VIEW_GET_IFACE (self)->create_mime_part_view_for)
		g_critical ("You must implement tny_msg_view_create_mime_part_view_for\n");
#endif

	return TNY_MSG_VIEW_GET_IFACE (self)->create_mime_part_view_for(self, part);
}

/**
 * tny_msg_view_clear:
 * @self: A #TnyMsgView
 *
 * Clear @self, show nothing
 * 
 * since: 1.0
 * audience: application-developer, type-implementer
 **/
void
tny_msg_view_clear (TnyMsgView *self)
{
#ifdef DEBUG
	if (!TNY_MSG_VIEW_GET_IFACE (self)->clear)
		g_critical ("You must implement tny_msg_view_clear\n");
#endif

	TNY_MSG_VIEW_GET_IFACE (self)->clear(self);
	return;
}


/**
 * tny_msg_view_set_unavailable:
 * @self: a #TnyMsgView
 *
 * Set @self to display that a message was unavailable. You can for example
 * implement this method by simply calling tny_msg_view_clear().
 * 
 * since: 1.0
 * audience: application-developer, type-implementer
 **/
void
tny_msg_view_set_unavailable (TnyMsgView *self)
{
#ifdef DEBUG
	if (!TNY_MSG_VIEW_GET_IFACE (self)->set_unavailable)
		g_critical ("You must implement tny_msg_view_set_unavailable\n");
#endif

	TNY_MSG_VIEW_GET_IFACE (self)->set_unavailable(self);
	return;
}


/**
 * tny_msg_view_get_msg:
 * @self: a #TnyMsgView
 *
 * Get the current message of @self. If @self is not displaying any message,
 * NULL will be returned. Else the return value must be unreferenced after use.
 *
 * When inheriting from a #TnyMimePartView, this method is most likely going to
 * be an alias for tny_mime_part_view_get_part(), with the returned #TnyMimePart
 * casted to a #TnyMsg (in this case, the method in the #TnyMimePartView should
 * return a #TnyMsg, indeed).
 *
 * returns: (null-ok) (caller-owns): A #TnyMsg instance or NULL
 * since: 1.0
 * audience: application-developer, type-implementer
 **/
TnyMsg* 
tny_msg_view_get_msg (TnyMsgView *self)
{
#ifdef DEBUG
	if (!TNY_MSG_VIEW_GET_IFACE (self)->get_msg)
		g_critical ("You must implement tny_msg_view_get_msg\n");
#endif

	return TNY_MSG_VIEW_GET_IFACE (self)->get_msg(self);
}

/**
 * tny_msg_view_set_msg:
 * @self: a #TnyMsgView
 * @msg: a #TnyMsg
 *
 * Set the message which view @self must display.
 * 
 * Note that you can get a list of mime parts using the tny_mime_part_get_parts()
 * API of the #TnyMimePart type. You can use the tny_msg_view_create_mime_part_view_for()
 * API to get a #TnyMimePartView that can view the mime part.
 * 
 * When inheriting from a #TnyMimePartView this method is most likely going to
 * decorate or alias tny_mime_part_view_set_part(), with the passed #TnyMsg
 * casted to a #TnyMimePart.
 *
 * Example:
 * <informalexample><programlisting>
 * static void 
 * tny_my_msg_view_set_msg (TnyMsgView *self, TnyMsg *msg)
 * {
 *     TnyIterator *iterator;
 *     TnyList *list = tny_simple_list_new ();
 *     tny_msg_view_clear (self);
 *     header = tny_msg_get_header (msg);
 *     tny_header_view_set_header (priv->headerview, header);
 *     g_object_unref (header);
 *     tny_mime_part_view_set_part (TNY_MIME_PART_VIEW (self),
 *                TNY_MIME_PART (msg));
 *     tny_mime_part_get_parts (TNY_MIME_PART (msg), list);
 *     iterator = tny_list_create_iterator (list);
 *     while (!tny_iterator_is_done (iterator)) {
 *         TnyMimePart *part = tny_iterator_get_current (iterator);
 *         TnyMimePartView *mpview;
 *         mpview = tny_msg_view_create_mime_part_view_for (self, part);
 *         if (mpview)
 *             tny_mime_part_view_set_part (mpview, part);
 *         g_object_unref (part);
 *         tny_iterator_next (iterator);
 *     }
 *     g_object_unref (iterator);
 *     g_object_unref (list);
 * }
 * </programlisting></informalexample>
 *
 * ps. For a real and complete working example take a look at the implementation of 
 * #TnyGtkMsgView in libtinymailui-gtk.
 *
 * since: 1.0
 * audience: application-developer, type-implementer
 **/
void
tny_msg_view_set_msg (TnyMsgView *self, TnyMsg *msg)
{
#ifdef DEBUG
	if (!TNY_MSG_VIEW_GET_IFACE (self)->set_msg)
		g_critical ("You must implement tny_msg_view_set_msg\n");
#endif

	TNY_MSG_VIEW_GET_IFACE (self)->set_msg(self, msg);
	return;
}

static void
tny_msg_view_base_init (gpointer g_class)
{
	static gboolean initialized = FALSE;

	if (!initialized) {
		/* create interface signals here. */
		initialized = TRUE;
	}
}

GType
tny_msg_view_get_type (void)
{
	static GType type = 0;

	if (G_UNLIKELY(type == 0))
	{
		static const GTypeInfo info = 
		{
		  sizeof (TnyMsgViewIface),
		  tny_msg_view_base_init,   /* base_init */
		  NULL,   /* base_finalize */
		  NULL,   /* class_init */
		  NULL,   /* class_finalize */
		  NULL,   /* class_data */
		  0,
		  0,      /* n_preallocs */
		  NULL    /* instance_init */
		};
		type = g_type_register_static (G_TYPE_INTERFACE, 
			"TnyMsgView", &info, 0);

		g_type_interface_add_prerequisite (type, TNY_TYPE_MIME_PART_VIEW);

	}

	return type;
}