No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-formatter-audio-inline.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-formatter-audio-inline.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-formatter-audio-inline.c
3 *
4 * This program 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) version 3.
8 *
9 * This program 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 the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 */
18
19 #include "e-mail-formatter-audio-inline.h"
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <glib/gi18n-lib.h>
26
27 #include <libebackend/libebackend.h>
28
29 #include <em-format/e-mail-formatter-extension.h>
30 #include <em-format/e-mail-formatter.h>
31
32 #include "e-util/e-mktemp.h"
33
34 #include <camel/camel.h>
35 #include <gst/gst.h>
36
37 #include "e-mail-part-audio-inline.h"
38
39 #define d(x)
40
41 typedef struct _EMailFormatterAudioInline {
42 EExtension parent;
43 } EMailFormatterAudioInline;
44
45 typedef struct _EMailFormatterAudioInlineClass {
46 EExtensionClass parent_class;
47 } EMailFormatterAudioInlineClass;
48
49 GType e_mail_formatter_audio_inline_get_type (void);
50 static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
51 static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
52
53 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
54 EMailFormatterAudioInline,
55 e_mail_formatter_audio_inline,
56 E_TYPE_EXTENSION,
57 0,
58 G_IMPLEMENT_INTERFACE_DYNAMIC (
59 E_TYPE_MAIL_EXTENSION,
60 e_mail_formatter_mail_extension_interface_init)
61 G_IMPLEMENT_INTERFACE_DYNAMIC (
62 E_TYPE_MAIL_FORMATTER_EXTENSION,
63 e_mail_formatter_formatter_extension_interface_init));
64
65 static const gchar * formatter_mime_types[] = { "application/vnd.evolution.widget.audio-inline",
66 "audio/ac3", "audio/x-ac3",
67 "audio/basic", "audio/mpeg",
68 "audio/x-mpeg", "audio/mpeg3",
69 "audio/x-mpeg3", "audio/mp3",
70 "audio/x-mp3", "audio/mp4",
71 "audio/flac", "audio/x-flac",
72 "audio/mod", "audio/x-mod",
73 "audio/x-wav", "audio/microsoft-wav",
74 "audio/x-wma", "audio/x-ms-wma",
75 "application/ogg", "application/x-ogg",
76 NULL };
77
78 static void
79 pause_clicked (GtkWidget *button,
80 EMailPartAudioInline *part)
81 {
82 if (part->playbin) {
83 /* pause playing */
84 gst_element_set_state (part->playbin, GST_STATE_PAUSED);
85 }
86 }
87
88 static void
89 stop_clicked (GtkWidget *button,
90 EMailPartAudioInline *part)
91 {
92 if (part->playbin) {
93 /* ready to play */
94 gst_element_set_state (part->playbin, GST_STATE_READY);
95 part->target_state = GST_STATE_READY;
96 }
97 }
98
99 static void
100 set_audiosink (GstElement *playbin)
101 {
102 GstElement *audiosink;
103
104 /* now it's time to get the audio sink */
105 audiosink = gst_element_factory_make ("gconfaudiosink", "play_audio");
106 if (audiosink == NULL) {
107 audiosink = gst_element_factory_make ("autoaudiosink", "play_audio");
108 }
109
110 if (audiosink) {
111 g_object_set (playbin, "audio-sink", audiosink, NULL);
112 }
113 }
114
115 static gboolean
116 gst_callback (GstBus *bus,
117 GstMessage *message,
118 gpointer data)
119 {
120 EMailPartAudioInline *part = data;
121 GstMessageType msg_type;
122
123 g_return_val_if_fail (part != NULL, TRUE);
124 g_return_val_if_fail (part->playbin != NULL, TRUE);
125
126 msg_type = GST_MESSAGE_TYPE (message);
127
128 switch (msg_type) {
129 case GST_MESSAGE_ERROR:
130 gst_element_set_state (part->playbin, GST_STATE_NULL);
131 break;
132 case GST_MESSAGE_EOS:
133 gst_element_set_state (part->playbin, GST_STATE_READY);
134 break;
135 case GST_MESSAGE_STATE_CHANGED:
136 {
137 GstState old_state, new_state;
138
139 if (GST_MESSAGE_SRC (message) != GST_OBJECT (part->playbin))
140 break;
141
142 gst_message_parse_state_changed (message, &old_state, &new_state, NULL);
143
144 if (old_state == new_state)
145 break;
146
147 if (part->play_button)
148 gtk_widget_set_sensitive (
149 part->play_button,
150 new_state <= GST_STATE_PAUSED);
151 if (part->pause_button)
152 gtk_widget_set_sensitive (
153 part->pause_button,
154 new_state > GST_STATE_PAUSED);
155 if (part->stop_button)
156 gtk_widget_set_sensitive (
157 part->stop_button,
158 new_state >= GST_STATE_PAUSED);
159 }
160
161 break;
162 default:
163 break;
164 }
165
166 return TRUE;
167 }
168
169 static void
170 play_clicked (GtkWidget *button,
171 EMailPartAudioInline *part)
172 {
173 GstState cur_state;
174
175 d (printf ("audio inline formatter: play\n"));
176
177 if (!part->filename) {
178 CamelStream *stream;
179 CamelDataWrapper *data;
180 GError *error = NULL;
181 gint argc = 1;
182 const gchar *argv[] = { "org_gnome_audio_inline", NULL };
183
184 /* FIXME this is ugly, we should stream this directly to gstreamer */
185 part->filename = e_mktemp ("org-gnome-audio-inline-file-XXXXXX");
186
187 d (printf ("audio inline formatter: write to temp file %s\n", po->filename));
188
189 stream = camel_stream_fs_new_with_name (
190 part->filename, O_RDWR | O_CREAT | O_TRUNC, 0600, NULL);
191 data = camel_medium_get_content (CAMEL_MEDIUM (part->parent.part));
192 camel_data_wrapper_decode_to_stream_sync (data, stream, NULL, NULL);
193 camel_stream_flush (stream, NULL, NULL);
194 g_object_unref (stream);
195
196 d (printf ("audio inline formatter: init gst playbin\n"));
197
198 if (gst_init_check (&argc, (gchar ***) &argv, &error)) {
199 gchar *uri;
200 GstBus *bus;
201
202 /* create a disk reader */
203 part->playbin = gst_element_factory_make ("playbin", "playbin");
204 if (part->playbin == NULL) {
205 g_printerr ("Failed to create gst_element_factory playbin; check your installation\n");
206 return;
207
208 }
209
210 uri = g_filename_to_uri (part->filename, NULL, NULL);
211 g_object_set (part->playbin, "uri", uri, NULL);
212 g_free (uri);
213 set_audiosink (part->playbin);
214
215 bus = gst_element_get_bus (part->playbin);
216 part->bus_id = gst_bus_add_watch (bus, gst_callback, part);
217 gst_object_unref (bus);
218
219 } else {
220 g_printerr ("GStreamer failed to initialize: %s",error ? error->message : "");
221 g_error_free (error);
222 }
223 }
224
225 gst_element_get_state (part->playbin, &cur_state, NULL, 0);
226
227 if (cur_state >= GST_STATE_PAUSED) {
228 gst_element_set_state (part->playbin, GST_STATE_READY);
229 }
230
231 if (part->playbin) {
232 /* start playing */
233 gst_element_set_state (part->playbin, GST_STATE_PLAYING);
234 }
235 }
236
237 static GtkWidget *
238 add_button (GtkWidget *box,
239 const gchar *stock_icon,
240 GCallback cb,
241 gpointer data,
242 gboolean sensitive)
243 {
244 GtkWidget *button;
245
246 button = gtk_button_new_from_stock (stock_icon);
247 gtk_widget_set_sensitive (button, sensitive);
248 g_signal_connect (button, "clicked", cb, data);
249
250 gtk_widget_show (button);
251 gtk_box_pack_end (GTK_BOX (box), button, TRUE, TRUE, 0);
252
253 return button;
254 }
255
256 static gboolean
257 emfe_audio_inline_format (EMailFormatterExtension *extension,
258 EMailFormatter *formatter,
259 EMailFormatterContext *context,
260 EMailPart *part,
261 CamelStream *stream,
262 GCancellable *cancellable)
263 {
264 gchar *str;
265
266 str = g_strdup_printf (
267 "<object type=\"application/vnd.evolution.widget.audio-inline\" "
268 "width=\"100%%\" height=\"auto\" data=\"%s\" id=\"%s\"></object>",
269 part->id, part->id);
270
271 camel_stream_write_string (stream, str, cancellable, NULL);
272
273 g_free (str);
274
275 return TRUE;
276 }
277
278 static GtkWidget *
279 emfe_audio_inline_get_widget (EMailFormatterExtension *extension,
280 EMailPartList *context,
281 EMailPart *part,
282 GHashTable *params)
283 {
284 GtkWidget *box;
285 EMailPartAudioInline *ai_part;
286
287 g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartAudioInline), NULL);
288 ai_part = (EMailPartAudioInline *) part;
289
290 /* it is OK to call UI functions here, since we are called from UI thread */
291 box = gtk_hbutton_box_new ();
292 ai_part->play_button = g_object_ref (
293 add_button (box, GTK_STOCK_MEDIA_PLAY,
294 G_CALLBACK (play_clicked), part, TRUE));
295 ai_part->pause_button = g_object_ref (
296 add_button (box, GTK_STOCK_MEDIA_PAUSE,
297 G_CALLBACK (pause_clicked), part, FALSE));
298 ai_part->stop_button = g_object_ref (
299 add_button (box, GTK_STOCK_MEDIA_STOP,
300 G_CALLBACK (stop_clicked), part, FALSE));
301
302 gtk_widget_show (box);
303
304 return box;
305 }
306
307 static const gchar *
308 emfe_audio_inline_get_display_name (EMailFormatterExtension *extension)
309 {
310 return _("Audio Player");
311 }
312
313 static const gchar *
314 emfe_audio_inline_get_description (EMailFormatterExtension *extension)
315 {
316 return _("Play the attachment in embedded audio player");
317 }
318
319 static const gchar **
320 emfe_audio_inline_mime_types (EMailExtension *extension)
321 {
322 return formatter_mime_types;
323 }
324
325 static void
326 e_mail_formatter_audio_inline_constructed (GObject *object)
327 {
328 EExtensible *extensible;
329 EMailExtensionRegistry *reg;
330
331 extensible = e_extension_get_extensible (E_EXTENSION (object));
332 reg = E_MAIL_EXTENSION_REGISTRY (extensible);
333
334 e_mail_extension_registry_add_extension (reg, E_MAIL_EXTENSION (object));
335 }
336
337 static void
338 e_mail_formatter_audio_inline_class_init (EMailFormatterAudioInlineClass *class)
339 {
340 GObjectClass *object_class;
341 EExtensionClass *extension_class;
342
343 object_class = G_OBJECT_CLASS (class);
344 object_class->constructed = e_mail_formatter_audio_inline_constructed;
345
346 extension_class = E_EXTENSION_CLASS (class);
347 extension_class->extensible_type = E_TYPE_MAIL_FORMATTER_EXTENSION_REGISTRY;
348 }
349
350 static void
351 e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
352 {
353 iface->format = emfe_audio_inline_format;
354 iface->get_widget = emfe_audio_inline_get_widget;
355 iface->get_display_name = emfe_audio_inline_get_display_name;
356 iface->get_description = emfe_audio_inline_get_description;
357 }
358
359 static void
360 e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
361 {
362 iface->mime_types = emfe_audio_inline_mime_types;
363 }
364
365 static void
366 e_mail_formatter_audio_inline_init (EMailFormatterAudioInline *formatter)
367 {
368
369 }
370
371 void
372 e_mail_formatter_audio_inline_type_register (GTypeModule *type_module)
373 {
374 e_mail_formatter_audio_inline_register_type (type_module);
375 }
376
377 static void
378 e_mail_formatter_audio_inline_class_finalize (EMailFormatterAudioInlineClass *class)
379 {
380
381 }