1 /*
2  * e-mail-formatter.h
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 #ifndef E_MAIL_FORMATTER_H_
19 #define E_MAIL_FORMATTER_H_
20 
21 #include <gdk/gdk.h>
22 
23 #include <em-format/e-mail-extension-registry.h>
24 #include <em-format/e-mail-formatter-enums.h>
25 #include <em-format/e-mail-part-list.h>
26 
27 /* Standard GObject macros */
28 #define E_TYPE_MAIL_FORMATTER \
29 	(e_mail_formatter_get_type ())
30 #define E_MAIL_FORMATTER(obj) \
31 	(G_TYPE_CHECK_INSTANCE_CAST \
32 	((obj), E_TYPE_MAIL_FORMATTER, EMailFormatter))
33 #define E_MAIL_FORMATTER_CLASS(cls) \
34 	(G_TYPE_CHECK_CLASS_CAST \
35 	((cls), E_TYPE_MAIL_FORMATTER, EMailFormatterClass))
36 #define E_IS_MAIL_FORMATTER(obj) \
37 	(G_TYPE_CHECK_INSTANCE_TYPE \
38 	((obj), E_TYPE_MAIL_FORMATTER))
39 #define E_IS_MAIL_FORMATTER_CLASS(cls) \
40 	(G_TYPE_CHECK_CLASS_TYPE \
41 	((cls), E_TYPE_MAIL_FORMATTER))
42 #define E_MAIL_FORMATTER_GET_CLASS(obj) \
43 	(G_TYPE_INSTANCE_GET_CLASS \
44 	((obj), E_TYPE_MAIL_FORMATTER, EMailFormatterClass))
45 
46 G_BEGIN_DECLS;
47 
48 typedef struct _EMailFormatter EMailFormatter;
49 typedef struct _EMailFormatterClass EMailFormatterClass;
50 typedef struct _EMailFormatterPrivate EMailFormatterPrivate;
51 typedef struct _EMailFormatterContext EMailFormatterContext;
52 
53 struct _EMailFormatterContext {
54 	EMailPartList *part_list;
55 	EMailFormatterMode mode;
56 	EMailFormatterHeaderFlags flags;
57 
58 	gchar *uri;
59 };
60 
61 struct _EMailFormatter {
62 	GObject parent;
63 	EMailFormatterPrivate *priv;
64 };
65 
66 struct _EMailFormatterClass {
67 	GObjectClass parent_class;
68 
69 	EMailFormatterExtensionRegistry *extension_registry;
70 	CamelMimeFilterToHTMLFlags text_html_flags;
71 
72 	/* Colors should apply globally */
73 	GdkRGBA colors[E_MAIL_FORMATTER_NUM_COLOR_TYPES];
74 
75 	/* sizeof(EMailFormatterContext) or some derivative struct */
76 	gsize context_size;
77 
78 	void		(*run)			(EMailFormatter *formatter,
79 						 EMailFormatterContext *context,
80 						 GOutputStream *stream,
81 						 GCancellable *cancellable);
82 
83 	void		(*update_style)		(EMailFormatter *formatter,
84 						 GtkStateFlags state);
85 
86 	/* Signals */
87 	void		(*need_redraw)		(EMailFormatter *formatter);
88 	void		(*claim_attachment)	(EMailFormatter *formatter,
89 						 EAttachment *attachment);
90 };
91 
92 GType		e_mail_formatter_get_type	(void);
93 
94 EMailFormatter *
95 		e_mail_formatter_new		(void);
96 void		e_mail_formatter_claim_attachment
97 						(EMailFormatter *formatter,
98 						 EAttachment *attachment);
99 void		e_mail_formatter_format_sync	(EMailFormatter *formatter,
100 						 EMailPartList *part_list,
101 						 GOutputStream *stream,
102 						 EMailFormatterHeaderFlags flags,
103 						 EMailFormatterMode mode,
104 						 GCancellable *cancellable);
105 
106 void		e_mail_formatter_format		(EMailFormatter *formatter,
107 						 EMailPartList *part_list,
108 						 GOutputStream *stream,
109 						 EMailFormatterHeaderFlags flags,
110 						 EMailFormatterMode mode,
111 						 GAsyncReadyCallback callback,
112 						 GCancellable *cancellable,
113 						 gpointer user_data);
114 
115 gboolean	e_mail_formatter_format_finish	(EMailFormatter *formatter,
116 						 GAsyncResult *result,
117 						 GError **error);
118 
119 gboolean	e_mail_formatter_format_as	(EMailFormatter *formatter,
120 						 EMailFormatterContext *context,
121 						 EMailPart *part,
122 						 GOutputStream *stream,
123 						 const gchar *as_mime_type,
124 						 GCancellable *cancellable);
125 
126 void		e_mail_formatter_format_text	(EMailFormatter *formatter,
127 						 EMailPart *part,
128 						 GOutputStream *stream,
129 						 GCancellable *cancellable);
130 const gchar *	e_mail_formatter_get_sub_html_header
131 						(EMailFormatter *formatter);
132 gchar *		e_mail_formatter_get_html_header
133 						(EMailFormatter *formatter);
134 EMailExtensionRegistry *
135 		e_mail_formatter_get_extension_registry
136 						(EMailFormatter *formatter);
137 
138 CamelMimeFilterToHTMLFlags
139 		e_mail_formatter_get_text_format_flags
140 						(EMailFormatter *formatter);
141 
142 const GdkRGBA *	e_mail_formatter_get_color	(EMailFormatter *formatter,
143 						 EMailFormatterColor type);
144 void		e_mail_formatter_set_color	(EMailFormatter *formatter,
145 						 EMailFormatterColor type,
146 						 const GdkRGBA *color);
147 void		e_mail_formatter_update_style	(EMailFormatter *formatter,
148 						 GtkStateFlags state);
149 
150 EImageLoadingPolicy
151 		e_mail_formatter_get_image_loading_policy
152 						(EMailFormatter *formatter);
153 void		e_mail_formatter_set_image_loading_policy
154 						(EMailFormatter *formatter,
155 						 EImageLoadingPolicy policy);
156 
157 gboolean	e_mail_formatter_get_mark_citations
158 						(EMailFormatter *formatter);
159 void		e_mail_formatter_set_mark_citations
160 						(EMailFormatter *formatter,
161 						 gboolean mark_citations);
162 
163 gboolean	e_mail_formatter_get_show_sender_photo
164 						(EMailFormatter *formatter);
165 void		e_mail_formatter_set_show_sender_photo
166 						(EMailFormatter *formatter,
167 						 gboolean show_sender_photo);
168 
169 gboolean	e_mail_formatter_get_animate_images
170 						(EMailFormatter *formatter);
171 void		e_mail_formatter_set_animate_images
172 						(EMailFormatter *formatter,
173 						 gboolean animate_images);
174 
175 gboolean	e_mail_formatter_get_show_real_date
176 						(EMailFormatter *formatter);
177 void		e_mail_formatter_set_show_real_date
178 						(EMailFormatter *formatter,
179 						 gboolean show_real_date);
180 
181 const gchar *	e_mail_formatter_get_charset	(EMailFormatter *formatter);
182 gchar *		e_mail_formatter_dup_charset	(EMailFormatter *formatter);
183 void		e_mail_formatter_set_charset	(EMailFormatter *formatter,
184 						 const gchar *charset);
185 
186 const gchar *	e_mail_formatter_get_default_charset
187 						(EMailFormatter *formatter);
188 gchar *		e_mail_formatter_dup_default_charset
189 						(EMailFormatter *formatter);
190 void		e_mail_formatter_set_default_charset
191 						(EMailFormatter *formatter,
192 						 const gchar *charset);
193 
194 G_END_DECLS
195 
196 #endif /* E_MAIL_FORMATTER_H_ */
197