1 /*
2 * e-mail-formatter-extension.c
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 #include "e-mail-formatter-extension.h"
19
G_DEFINE_ABSTRACT_TYPE(EMailFormatterExtension,e_mail_formatter_extension,G_TYPE_OBJECT)20 G_DEFINE_ABSTRACT_TYPE (
21 EMailFormatterExtension,
22 e_mail_formatter_extension,
23 G_TYPE_OBJECT)
24
25 static void
26 e_mail_formatter_extension_class_init (EMailFormatterExtensionClass *class)
27 {
28 class->priority = G_PRIORITY_DEFAULT;
29 }
30
31 static void
e_mail_formatter_extension_init(EMailFormatterExtension * extension)32 e_mail_formatter_extension_init (EMailFormatterExtension *extension)
33 {
34 }
35
36 /**
37 * e_mail_formatter_extension_format
38 * @extension: an #EMailFormatterExtension
39 * @formatter: an #EMailFormatter
40 * @context: an #EMailFormatterContext
41 * @part: an #EMailPart to be formatter
42 * @stream: a #GOutputStream to which the output should be written
43 * @cancellable: (allow-none) a #GCancellable
44 *
45 * A virtual function reimplemented in all mail formatter extensions. The
46 * function formats @part, generated HTML (or other format that can be
47 * displayed to user) and writes it to the @stream.
48 *
49 * When the function is unable to format the @part (either because it's broken
50 * or because it is a different mimetype then the extension is specialized
51 * for), the function will return @FALSE indicating the #EMailFormatter, that
52 * it should pick another extension.
53 *
54 * Implementation of this function must be thread-safe.
55 *
56 * Returns: Returns @TRUE when the @part was successfully formatted and
57 * data were written to the @stream, @FALSE otherwise.
58 */
59 gboolean
e_mail_formatter_extension_format(EMailFormatterExtension * extension,EMailFormatter * formatter,EMailFormatterContext * context,EMailPart * part,GOutputStream * stream,GCancellable * cancellable)60 e_mail_formatter_extension_format (EMailFormatterExtension *extension,
61 EMailFormatter *formatter,
62 EMailFormatterContext *context,
63 EMailPart *part,
64 GOutputStream *stream,
65 GCancellable *cancellable)
66 {
67 EMailFormatterExtensionClass *class;
68
69 g_return_val_if_fail (E_IS_MAIL_FORMATTER_EXTENSION (extension), FALSE);
70 g_return_val_if_fail (E_IS_MAIL_FORMATTER (formatter), FALSE);
71 g_return_val_if_fail (context != NULL, FALSE);
72 g_return_val_if_fail (part != NULL, FALSE);
73 g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
74
75 class = E_MAIL_FORMATTER_EXTENSION_GET_CLASS (extension);
76 g_return_val_if_fail (class != NULL, FALSE);
77 g_return_val_if_fail (class->format != NULL, FALSE);
78
79 return class->format (extension, formatter, context, part, stream, cancellable);
80 }
81