aboutsummaryrefslogtreecommitdiffstats
path: root/modules/audio-inline
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-05-15 21:17:58 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-05-20 01:07:22 +0800
commitf9ffe647231a7ba2bd5347d92d560b6a57fee786 (patch)
tree6c1245d91a399647fc25521bc1f38cf564210979 /modules/audio-inline
parent0b4e7ec091c8bbe65dc2f2afd7da78b04da7c274 (diff)
downloadgsoc2013-evolution-f9ffe647231a7ba2bd5347d92d560b6a57fee786.tar.gz
gsoc2013-evolution-f9ffe647231a7ba2bd5347d92d560b6a57fee786.tar.zst
gsoc2013-evolution-f9ffe647231a7ba2bd5347d92d560b6a57fee786.zip
Convert EMailPart to a GObject.
EMailPart is reference-counted, subclassed, and allows a custom finalize function. There's no excuse for it not to use GObject.
Diffstat (limited to 'modules/audio-inline')
-rw-r--r--modules/audio-inline/Makefile.am1
-rw-r--r--modules/audio-inline/e-mail-formatter-audio.c3
-rw-r--r--modules/audio-inline/e-mail-parser-audio.c38
-rw-r--r--modules/audio-inline/e-mail-part-audio.c142
-rw-r--r--modules/audio-inline/e-mail-part-audio.h33
-rw-r--r--modules/audio-inline/evolution-module-audio-inline.c2
6 files changed, 181 insertions, 38 deletions
diff --git a/modules/audio-inline/Makefile.am b/modules/audio-inline/Makefile.am
index b53c2913fd..ad75a62ab7 100644
--- a/modules/audio-inline/Makefile.am
+++ b/modules/audio-inline/Makefile.am
@@ -15,6 +15,7 @@ module_audio_inline_la_SOURCES = \
e-mail-formatter-audio.h \
e-mail-parser-audio.c \
e-mail-parser-audio.h \
+ e-mail-part-audio.c \
e-mail-part-audio.h \
evolution-module-audio-inline.c
diff --git a/modules/audio-inline/e-mail-formatter-audio.c b/modules/audio-inline/e-mail-formatter-audio.c
index b700651221..fc27bb7091 100644
--- a/modules/audio-inline/e-mail-formatter-audio.c
+++ b/modules/audio-inline/e-mail-formatter-audio.c
@@ -287,7 +287,8 @@ mail_formatter_audio_get_widget (EMailFormatterExtension *extension,
GtkWidget *box;
EMailPartAudio *ai_part;
- g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartAudio), NULL);
+ g_return_val_if_fail (E_IS_MAIL_PART_AUDIO (part), NULL);
+
ai_part = (EMailPartAudio *) part;
/* it is OK to call UI functions here, since we are called from UI thread */
diff --git a/modules/audio-inline/e-mail-parser-audio.c b/modules/audio-inline/e-mail-parser-audio.c
index c81a94bcff..c9c41335ac 100644
--- a/modules/audio-inline/e-mail-parser-audio.c
+++ b/modules/audio-inline/e-mail-parser-audio.c
@@ -23,7 +23,6 @@
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gi18n.h>
-#include <glib/gstdio.h>
#include "e-mail-parser-audio.h"
#include "e-mail-part-audio.h"
@@ -75,33 +74,6 @@ static const gchar *parser_mime_types[] = {
NULL
};
-static void
-mail_part_audio_free (EMailPart *mail_part)
-{
- EMailPartAudio *ai_part = (EMailPartAudio *) mail_part;
-
- g_clear_object (&ai_part->play_button);
- g_clear_object (&ai_part->pause_button);
- g_clear_object (&ai_part->stop_button);
-
- if (ai_part->filename) {
- g_unlink (ai_part->filename);
- g_free (ai_part->filename);
- ai_part->filename = NULL;
- }
-
- if (ai_part->bus_id) {
- g_source_remove (ai_part->bus_id);
- ai_part->bus_id = 0;
- }
-
- if (ai_part->playbin) {
- gst_element_set_state (ai_part->playbin, GST_STATE_NULL);
- gst_object_unref (ai_part->playbin);
- ai_part->playbin = NULL;
- }
-}
-
static gint
mail_parser_audio_parse (EMailParserExtension *extension,
EMailParser *parser,
@@ -110,7 +82,7 @@ mail_parser_audio_parse (EMailParserExtension *extension,
GCancellable *cancellable,
GQueue *out_mail_queue)
{
- EMailPartAudio *mail_part;
+ EMailPart *mail_part;
GQueue work_queue = G_QUEUE_INIT;
gint len;
gint n_parts_added = 0;
@@ -120,12 +92,8 @@ mail_parser_audio_parse (EMailParserExtension *extension,
d (printf ("audio formatter: format classid %s\n", part_id->str));
- mail_part = (EMailPartAudio *) e_mail_part_subclass_new (
- part, part_id->str, sizeof (EMailPartAudio),
- (GFreeFunc) mail_part_audio_free);
- mail_part->parent.mime_type = camel_content_type_simple (
- camel_mime_part_get_content_type (part));
- mail_part->parent.is_attachment = TRUE;
+ mail_part = e_mail_part_audio_new (part, part_id->str);
+
g_string_truncate (part_id, len);
g_queue_push_tail (&work_queue, mail_part);
diff --git a/modules/audio-inline/e-mail-part-audio.c b/modules/audio-inline/e-mail-part-audio.c
new file mode 100644
index 0000000000..0c8ae7fa16
--- /dev/null
+++ b/modules/audio-inline/e-mail-part-audio.c
@@ -0,0 +1,142 @@
+/*
+ * e-mail-part-audio.c
+ *
+ * This program 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) version 3.
+ *
+ * This program 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 the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-mail-part-audio.h"
+
+#include <glib/gstdio.h>
+
+#define E_MAIL_PART_AUDIO_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_MAIL_PART_AUDIO, EMailPartAudioPrivate))
+
+struct _EMailPartAudioPrivate {
+ gint placeholder;
+};
+
+G_DEFINE_DYNAMIC_TYPE (
+ EMailPartAudio,
+ e_mail_part_audio,
+ E_TYPE_MAIL_PART)
+
+static void
+mail_part_audio_dispose (GObject *object)
+{
+ EMailPartAudio *part = E_MAIL_PART_AUDIO (object);
+
+ if (part->bus_id > 0) {
+ g_source_remove (part->bus_id);
+ part->bus_id = 0;
+ }
+
+ if (part->playbin != NULL) {
+ gst_element_set_state (part->playbin, GST_STATE_NULL);
+ gst_object_unref (part->playbin);
+ part->playbin = NULL;
+ }
+
+ g_clear_object (&part->play_button);
+ g_clear_object (&part->pause_button);
+ g_clear_object (&part->stop_button);
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_mail_part_audio_parent_class)->dispose (object);
+}
+
+static void
+mail_part_audio_finalize (GObject *object)
+{
+ EMailPartAudio *part = E_MAIL_PART_AUDIO (object);
+
+ if (part->filename != NULL) {
+ g_unlink (part->filename);
+ g_free (part->filename);
+ }
+
+ /* Chain up to parent's finalize() method. */
+ G_OBJECT_CLASS (e_mail_part_audio_parent_class)->finalize (object);
+}
+
+static void
+mail_part_audio_constructed (GObject *object)
+{
+ EMailPart *part;
+ CamelMimePart *mime_part;
+ CamelContentType *content_type;
+ gchar *mime_type;
+
+ part = E_MAIL_PART (object);
+
+ /* Chain up to parent's constructed() method. */
+ G_OBJECT_CLASS (e_mail_part_audio_parent_class)->constructed (object);
+
+ e_mail_part_set_is_attachment (part, TRUE);
+
+ mime_part = e_mail_part_ref_mime_part (part);
+
+ content_type = camel_mime_part_get_content_type (mime_part);
+ mime_type = camel_content_type_simple (content_type);
+ e_mail_part_set_mime_type (part, mime_type);
+ g_free (mime_type);
+
+ g_object_unref (mime_part);
+}
+
+static void
+e_mail_part_audio_class_init (EMailPartAudioClass *class)
+{
+ GObjectClass *object_class;
+
+ g_type_class_add_private (class, sizeof (EMailPartAudioPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->dispose = mail_part_audio_dispose;
+ object_class->finalize = mail_part_audio_finalize;
+ object_class->constructed = mail_part_audio_constructed;
+}
+
+static void
+e_mail_part_audio_class_finalize (EMailPartAudioClass *class)
+{
+}
+
+static void
+e_mail_part_audio_init (EMailPartAudio *part)
+{
+ part->priv = E_MAIL_PART_AUDIO_GET_PRIVATE (part);
+}
+
+void
+e_mail_part_audio_type_register (GTypeModule *type_module)
+{
+ /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
+ * function, so we have to wrap it with a public function in
+ * order to register types from a separate compilation unit. */
+ e_mail_part_audio_register_type (type_module);
+}
+
+EMailPart *
+e_mail_part_audio_new (CamelMimePart *mime_part,
+ const gchar *id)
+{
+ g_return_val_if_fail (id != NULL, NULL);
+
+ return g_object_new (
+ E_TYPE_MAIL_PART_AUDIO,
+ "id", id, "mime-part", mime_part, NULL);
+}
+
diff --git a/modules/audio-inline/e-mail-part-audio.h b/modules/audio-inline/e-mail-part-audio.h
index 628da0bc22..42459e01ff 100644
--- a/modules/audio-inline/e-mail-part-audio.h
+++ b/modules/audio-inline/e-mail-part-audio.h
@@ -19,17 +19,37 @@
#ifndef E_MAIL_PART_AUDIO_H
#define E_MAIL_PART_AUDIO_H
-#include <glib-object.h>
-
#include <em-format/e-mail-part.h>
#include <gst/gst.h>
+/* Standard GObject macros */
+#define E_TYPE_MAIL_PART_AUDIO \
+ (e_mail_part_audio_get_type ())
+#define E_MAIL_PART_AUDIO(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_MAIL_PART_AUDIO, EMailPartAudio))
+#define E_MAIL_PART_AUDIO_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_MAIL_PART_AUDIO, EMailPartAudioClass))
+#define E_IS_MAIL_PART_AUDIO(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_MAIL_PART_AUDIO))
+#define E_IS_MAIL_PART_AUDIO_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_MAIL_PART_AUDIO))
+#define E_MAIL_PART_AUDIO_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_MAIL_PART_AUDIO, EMailPartAudioClass))
+
G_BEGIN_DECLS
typedef struct _EMailPartAudio EMailPartAudio;
+typedef struct _EMailPartAudioClass EMailPartAudioClass;
+typedef struct _EMailPartAudioPrivate EMailPartAudioPrivate;
struct _EMailPartAudio {
EMailPart parent;
+ EMailPartAudioPrivate *priv;
gchar *filename;
GstElement *playbin;
@@ -40,6 +60,15 @@ struct _EMailPartAudio {
GtkWidget *stop_button;
};
+struct _EMailPartAudioClass {
+ EMailPartClass parent_class;
+};
+
+GType e_mail_part_audio_get_type (void) G_GNUC_CONST;
+void e_mail_part_audio_type_register (GTypeModule *type_module);
+EMailPart * e_mail_part_audio_new (CamelMimePart *mime_part,
+ const gchar *id);
+
G_END_DECLS
#endif /* E_MAIL_PART_AUDIO_H */
diff --git a/modules/audio-inline/evolution-module-audio-inline.c b/modules/audio-inline/evolution-module-audio-inline.c
index d58883ae1a..678bfe436c 100644
--- a/modules/audio-inline/evolution-module-audio-inline.c
+++ b/modules/audio-inline/evolution-module-audio-inline.c
@@ -18,6 +18,7 @@
#include "e-mail-formatter-audio.h"
#include "e-mail-parser-audio.h"
+#include "e-mail-part-audio.h"
#include <gmodule.h>
@@ -28,6 +29,7 @@ const gchar * g_module_check_init (GModule *module);
G_MODULE_EXPORT void
e_module_load (GTypeModule *type_module)
{
+ e_mail_part_audio_type_register (type_module);
e_mail_parser_audio_type_register (type_module);
e_mail_formatter_audio_type_register (type_module);
}