Commit 54455ca1 authored by Matthew Barnes's avatar Matthew Barnes
Browse files

Remove EMailExtension.

EMailExtension is now too trivial to keep as a standalone interface.
Add a 'mime_types' string array to the EMailFormatterExtension and
EMailFormatterParser interface structs.

Alter e_mail_extension_registry_add_extension() to take a 'mime_types'
string array and the GType of an extension to instantiate, rather than
the extension instance directly.

e_mail_extension_registry_remove_extension() is no longer needed.
parent 9d34f72e
......@@ -4,7 +4,6 @@ privsolib_LTLIBRARIES = libemformat.la
emformatinclude_HEADERS = \
e-mail-extension-registry.h \
e-mail-extension.h \
e-mail-formatter-extension.h \
e-mail-formatter.h \
e-mail-formatter-print.h \
......@@ -40,7 +39,6 @@ endif
libemformat_la_SOURCES = \
$(emformatinclude_HEADERS) \
e-mail-extension-registry.c \
e-mail-extension.c \
e-mail-inline-filter.c \
e-mail-format-extensions.c \
e-mail-format-extensions.h \
......
......@@ -19,7 +19,6 @@
#include <glib-object.h>
#include "e-mail-extension-registry.h"
#include "e-mail-extension.h"
#include "e-mail-format-extensions.h"
#include <libebackend/libebackend.h>
#include <camel/camel.h>
......@@ -96,95 +95,47 @@ e_mail_extension_registry_init (EMailExtensionRegistry *reg)
/**
* e_mail_extension_registry_add_extension:
* @reg: An #EMailExtensionRegistry
* @extension: An #EMailExtension
* @reg: an #EMailExtensionRegistry
* @mime_types: a %NULL-terminated array of MIME types
* @extension_type: the #GType of the extension being added
*
* Registrys the @extension as a handler for all mime-types that it is able
* to handle.
* Creates an instance of @extension_type and registers the instance for
* all provided MIME types.
*/
void
e_mail_extension_registry_add_extension (EMailExtensionRegistry *reg,
EMailExtension *extension)
const gchar **mime_types,
GType extension_type)
{
EMailExtensionInterface *interface;
GObject *extension;
gint ii;
g_return_if_fail (E_IS_MAIL_EXTENSION_REGISTRY (reg));
g_return_if_fail (E_IS_MAIL_EXTENSION (extension));
/* One reference per extension is enough */
g_object_ref (extension);
g_return_if_fail (mime_types != NULL);
g_return_if_fail (extension_type != G_TYPE_INVALID);
interface = E_MAIL_EXTENSION_GET_INTERFACE (extension);
if (interface->mime_types == NULL) {
g_critical (
"%s does not define any MIME types",
G_OBJECT_TYPE_NAME (extension));
return;
}
extension = g_object_new (extension_type, NULL);
for (ii = 0; interface->mime_types[ii] != NULL; ii++) {
for (ii = 0; mime_types[ii] != NULL; ii++) {
GQueue *queue;
queue = g_hash_table_lookup (
reg->priv->table, interface->mime_types[ii]);
reg->priv->table, mime_types[ii]);
if (queue == NULL) {
queue = g_queue_new ();
g_queue_push_head (queue, extension);
g_hash_table_insert (
reg->priv->table,
(gpointer) interface->mime_types[ii],
(gpointer) mime_types[ii],
queue);
} else {
g_queue_push_head (queue, extension);
}
if (camel_debug ("emformat:registry")) {
printf (
"Added extension '%s' for type '%s'\n",
G_OBJECT_TYPE_NAME (extension),
interface->mime_types[ii]);
}
}
}
/**
* e_mail_extension_registry_remove_extension:
* @reg: An #EMailExtensionRegistry
* @extension: An #EMailExtension
*
* Removes @extension from the registry.
*/
void
e_mail_extension_registry_remove_extension (EMailExtensionRegistry *reg,
EMailExtension *extension)
{
EMailExtensionInterface *interface;
gint ii;
g_return_if_fail (E_IS_MAIL_EXTENSION_REGISTRY (reg));
g_return_if_fail (E_IS_MAIL_EXTENSION (extension));
interface = E_MAIL_EXTENSION_GET_INTERFACE (extension);
if (interface->mime_types == NULL)
return;
for (ii = 0; interface->mime_types[ii] != NULL; ii++) {
GQueue *queue;
queue = g_hash_table_lookup (
reg->priv->table,
interface->mime_types[ii]);
if (queue == NULL)
continue;
g_queue_remove (queue, extension);
g_queue_push_head (queue, g_object_ref (extension));
if (camel_debug ("emformat:registry")) {
printf (
"Removed extension '%s' from type '%s'\n",
G_OBJECT_TYPE_NAME (extension),
interface->mime_types[ii]);
"Added extension '%s' for type '%s'\n",
g_type_name (extension_type),
mime_types[ii]);
}
}
......
......@@ -19,7 +19,7 @@
#ifndef E_MAIL_EXTENSION_REGISTRY_H_
#define E_MAIL_EXTENSION_REGISTRY_H_
#include <em-format/e-mail-extension.h>
#include <glib-object.h>
/* Standard GObject macros */
#define E_TYPE_MAIL_EXTENSION_REGISTRY \
......@@ -55,21 +55,18 @@ struct _EMailExtensionRegistry {
EMailExtensionRegistryPrivate *priv;
};
GType e_mail_extension_registry_get_type (void);
void e_mail_extension_registry_add_extension (EMailExtensionRegistry *reg,
EMailExtension *extension);
void e_mail_extension_registry_remove_extension
(EMailExtensionRegistry *reg,
EMailExtension *extension);
GType e_mail_extension_registry_get_type
(void) G_GNUC_CONST;
void e_mail_extension_registry_add_extension
(EMailExtensionRegistry *reg,
const gchar **mime_types,
GType extension_type);
GQueue * e_mail_extension_registry_get_for_mime_type
(EMailExtensionRegistry *reg,
const gchar *mime_type);
GQueue * e_mail_extension_registry_get_fallback (EMailExtensionRegistry *reg,
const gchar *mime_type);
(EMailExtensionRegistry *reg,
const gchar *mime_type);
GQueue * e_mail_extension_registry_get_fallback
(EMailExtensionRegistry *reg,
const gchar *mime_type);
G_END_DECLS
......@@ -109,7 +106,8 @@ struct _EMailParserExtensionRegistry {
EMailParserExtensionRegistryPrivate *priv;
};
GType e_mail_parser_extension_registry_get_type (void);
GType e_mail_parser_extension_registry_get_type
(void) G_GNUC_CONST;
G_END_DECLS
......@@ -149,7 +147,8 @@ struct _EMailFormatterExtensionRegistry {
EMailFormatterExtensionRegistryPrivate *priv;
};
GType e_mail_formatter_extension_registry_get_type (void);
GType e_mail_formatter_extension_registry_get_type
(void) G_GNUC_CONST;
G_END_DECLS
......
/*
* e-mail-extension.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-extension.h"
#include <glib-object.h>
G_DEFINE_INTERFACE (EMailExtension, e_mail_extension, G_TYPE_OBJECT)
static void
e_mail_extension_default_init (EMailExtensionInterface *iface)
{
}
/**
* EMailExtension:
*
* The #EMailExtension is an abstract interface for all extensions for
* #EMailParser and #EmailFormatter.
*
* The interface is further extended by #EMailParserExtension and
* #EMailFormatterExtension interfaces which define final API for both types
* of extensions.
*/
/*
* e-mail-extension.h
*
* 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/>
*
*/
#ifndef E_MAIL_EXTENSION_H
#define E_MAIL_EXTENSION_H
#include <glib-object.h>
/* Standard GObject macros */
#define E_TYPE_MAIL_EXTENSION \
(e_mail_extension_get_type ())
#define E_MAIL_EXTENSION(obj) \
(G_TYPE_CHECK_INSTANCE_CAST \
((obj), E_TYPE_MAIL_EXTENSION, EMailExtension))
#define E_MAIL_EXTENSION_INTERFACE(cls) \
(G_TYPE_CHECK_CLASS_CAST \
((cls), E_TYPE_MAIL_EXTENSION, EMailExtensionInterface))
#define E_IS_MAIL_EXTENSION(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE \
((obj), E_TYPE_MAIL_EXTENSION))
#define E_IS_MAIL_EXTENSION_INTERFACE(cls) \
(G_TYPE_CHECK_CLASS_TYPE \
((cls), E_TYPE_MAIL_EXTENSION))
#define E_MAIL_EXTENSION_GET_INTERFACE(obj) \
(G_TYPE_INSTANCE_GET_INTERFACE \
((obj), E_TYPE_MAIL_EXTENSION, EMailExtensionInterface))
G_BEGIN_DECLS
typedef struct _EMailExtension EMailExtension;
typedef struct _EMailExtensionInterface EMailExtensionInterface;
struct _EMailExtensionInterface {
GTypeInterface parent_interface;
/* This is a NULL-terminated array of supported MIME types.
* The MIME types can be exact (e.g. "text/plain") or use a
* wildcard (e.g. "text/ *"). */
const gchar **mime_types;
};
GType e_mail_extension_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif /* E_MAIL_EXTENSION_H */
......@@ -86,16 +86,44 @@ static void
load (EMailExtensionRegistry *ereg,
TypeFunc *func_array)
{
gint i = 0;
gint ii;
for (i = 0; func_array[i] != NULL; i++) {
GType type;
EMailExtension *extension;
for (ii = 0; func_array[ii] != NULL; ii++) {
GType extension_type;
GType interface_type;
gpointer extension_class;
const gchar **mime_types = NULL;
type = func_array[i]();
extension = g_object_new (type, NULL);
extension_type = func_array[ii]();
extension_class = g_type_class_ref (extension_type);
e_mail_extension_registry_add_extension (ereg, extension);
interface_type = E_TYPE_MAIL_FORMATTER_EXTENSION;
if (g_type_is_a (extension_type, interface_type)) {
EMailFormatterExtensionInterface *interface;
interface = g_type_interface_peek (
extension_class, interface_type);
mime_types = interface->mime_types;
}
interface_type = E_TYPE_MAIL_PARSER_EXTENSION;
if (g_type_is_a (extension_type, interface_type)) {
EMailParserExtensionInterface *interface;
interface = g_type_interface_peek (
extension_class, interface_type);
mime_types = interface->mime_types;
}
if (mime_types != NULL)
e_mail_extension_registry_add_extension (
ereg, mime_types, extension_type);
else
g_critical (
"%s does not define any MIME types",
g_type_name (extension_type));
g_type_class_unref (extension_class);
}
}
......
......@@ -37,16 +37,12 @@ typedef struct _EMailFormatterAttachmentBarClass {
} EMailFormatterAttachmentBarClass;
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
EMailFormatterAttachmentBar,
e_mail_formatter_attachment_bar,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_EXTENSION,
e_mail_formatter_mail_extension_interface_init)
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
......@@ -133,18 +129,13 @@ e_mail_formatter_attachment_bar_class_init (EMailFormatterAttachmentBarClass *cl
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
iface->format = emfe_attachment_bar_format;
iface->get_widget = emfe_attachment_bar_get_widget;
iface->get_display_name = emfe_attachment_bar_get_display_name;
iface->get_description = emfe_attachment_bar_get_description;
}
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
}
static void
e_mail_formatter_attachment_bar_init (EMailFormatterAttachmentBar *extension)
{
......
......@@ -49,16 +49,12 @@ typedef struct _EMailFormatterAttachmentClass {
} EMailFormatterAttachmentClass;
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
EMailFormatterAttachment,
e_mail_formatter_attachment,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_EXTENSION,
e_mail_formatter_mail_extension_interface_init)
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init)
......@@ -398,18 +394,13 @@ e_mail_formatter_attachment_class_init (EMailFormatterAttachmentClass *class)
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
iface->format = emfe_attachment_format;
iface->get_widget = emfe_attachment_get_widget;
iface->get_display_name = emfe_attachment_get_display_name;
iface->get_description = emfe_attachment_get_description;
}
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
}
static void
e_mail_formatter_attachment_init (EMailFormatterAttachment *formatter)
{
......
......@@ -38,16 +38,12 @@ typedef struct _EMailFormatterErrorClass {
} EMailFormatterErrorClass;
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
EMailFormatterError,
e_mail_formatter_error,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_EXTENSION,
e_mail_formatter_mail_extension_interface_init)
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
......@@ -139,17 +135,12 @@ e_mail_formatter_error_class_init (EMailFormatterErrorClass *class)
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
iface->format = emfe_error_format;
iface->get_display_name = emfe_error_get_display_name;
iface->get_description = emfe_error_get_description;
}
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
}
static void
e_mail_formatter_error_init (EMailFormatterError *formatter)
{
......
......@@ -21,7 +21,7 @@
G_DEFINE_INTERFACE (
EMailFormatterExtension,
e_mail_formatter_extension,
E_TYPE_MAIL_EXTENSION)
G_TYPE_OBJECT)
/**
* EMailFormatterExtension:
......
......@@ -19,7 +19,6 @@
#ifndef E_MAIL_FORMATTER_EXTENSION_H
#define E_MAIL_FORMATTER_EXTENSION_H
#include <em-format/e-mail-extension.h>
#include <em-format/e-mail-part.h>
#include <em-format/e-mail-formatter.h>
#include <camel/camel.h>
......@@ -53,7 +52,12 @@ typedef struct _EMailFormatterExtension EMailFormatterExtension;
typedef struct _EMailFormatterExtensionInterface EMailFormatterExtensionInterface;
struct _EMailFormatterExtensionInterface {
EMailExtensionInterface parent_interface;
GTypeInterface parent_interface;
/* This is a NULL-terminated array of supported MIME types.
* The MIME types can be exact (e.g. "text/plain") or use a
* wildcard (e.g. "text/ *"). */
const gchar **mime_types;
gboolean (*format) (EMailFormatterExtension *extension,
EMailFormatter *formatter,
......
......@@ -51,16 +51,12 @@ static const gchar *formatter_mime_types[] = {
};
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
EMailFormatterHeaders,
e_mail_formatter_headers,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_EXTENSION,
e_mail_formatter_mail_extension_interface_init)
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init))
......@@ -594,17 +590,12 @@ e_mail_formatter_headers_class_init (EMailFormatterHeadersClass *class)
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
iface->format = emfe_headers_format;
iface->get_display_name = emfe_headers_get_display_name;
iface->get_description = emfe_headers_get_description;
}
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
}
static void
e_mail_formatter_headers_init (EMailFormatterHeaders *formatter)
{
......
......@@ -63,16 +63,12 @@ typedef struct _EMailFormatterImageClass {
} EMailFormatterImageClass;
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
EMailFormatterImage,
e_mail_formatter_image,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_EXTENSION,
e_mail_formatter_mail_extension_interface_init)
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
......@@ -174,17 +170,12 @@ e_mail_formatter_image_class_init (EMailFormatterImageClass *class)
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
iface->format = emfe_image_format;
iface->get_display_name = emfe_image_get_display_name;
iface->get_description = emfe_image_get_description;
}
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
}
static void
e_mail_formatter_image_init (EMailFormatterImage *formatter)
{
......
......@@ -50,16 +50,12 @@ typedef struct _EMailFormatterMessageRFC822Class {
} EMailFormatterMessageRFC822Class;
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
EMailFormatterMessageRFC822,
e_mail_formatter_message_rfc822,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_EXTENSION,
e_mail_formatter_mail_extension_interface_init)
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
......@@ -265,17 +261,12 @@ e_mail_formatter_message_rfc822_class_init (EMailFormatterMessageRFC822Class *cl
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
iface->format = emfe_message_rfc822_format;
iface->get_display_name = emfe_message_rfc822_get_display_name;
iface->get_description = emfe_message_rfc822_get_description;
}
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
}
static void
e_mail_formatter_message_rfc822_init (EMailFormatterMessageRFC822 *formatter)
{
......
......@@ -50,17 +50,12 @@ static const gchar *formatter_mime_types[] = {
static void e_mail_formatter_print_formatter_extension_interface_init
(EMailFormatterExtensionInterface *iface);
static void e_mail_formatter_print_mail_extension_interface_init
(EMailExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
EMailFormatterPrintHeaders,
e_mail_formatter_print_headers,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_EXTENSION,
e_mail_formatter_print_mail_extension_interface_init)