Commit 9d34f72e authored by Matthew Barnes's avatar Matthew Barnes
Browse files

EMailExtension: Replace mime_types() method with a string array.

In all implementations for EMailExtension, the MIME type list is a
static string array -- with the single exception of the text-highlight
module, where the MIME type list is dynamically assembled once.

Replace the mime_types() method with a "mime_types" string array in the
EMailExtensionInterface struct.  Then the list of MIME types supported
by the class implementing the EMailExtensionInterface can be obtained
without requiring an instance of the class.
parent 3924dc75
......@@ -106,8 +106,8 @@ void
e_mail_extension_registry_add_extension (EMailExtensionRegistry *reg,
EMailExtension *extension)
{
gint i;
const gchar **types;
EMailExtensionInterface *interface;
gint ii;
g_return_if_fail (E_IS_MAIL_EXTENSION_REGISTRY (reg));
g_return_if_fail (E_IS_MAIL_EXTENSION (extension));
......@@ -115,15 +115,26 @@ e_mail_extension_registry_add_extension (EMailExtensionRegistry *reg,
/* One reference per extension is enough */
g_object_ref (extension);
types = e_mail_extension_get_mime_types (extension);
for (i = 0; types && types[i]; i++) {
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;
}
for (ii = 0; interface->mime_types[ii] != NULL; ii++) {
GQueue *queue;
queue = g_hash_table_lookup (reg->priv->table, types[i]);
if (!queue) {
queue = g_hash_table_lookup (
reg->priv->table, interface->mime_types[ii]);
if (queue == NULL) {
queue = g_queue_new ();
g_queue_push_head (queue, extension);
g_hash_table_insert (reg->priv->table, (gchar *) types[i], queue);
g_hash_table_insert (
reg->priv->table,
(gpointer) interface->mime_types[ii],
queue);
} else {
g_queue_push_head (queue, extension);
}
......@@ -131,7 +142,8 @@ e_mail_extension_registry_add_extension (EMailExtensionRegistry *reg,
if (camel_debug ("emformat:registry")) {
printf (
"Added extension '%s' for type '%s'\n",
G_OBJECT_TYPE_NAME (extension), types[i]);
G_OBJECT_TYPE_NAME (extension),
interface->mime_types[ii]);
}
}
}
......@@ -147,28 +159,32 @@ void
e_mail_extension_registry_remove_extension (EMailExtensionRegistry *reg,
EMailExtension *extension)
{
gint i;
const gchar **types;
EMailExtensionInterface *interface;
gint ii;
g_return_if_fail (E_IS_MAIL_EXTENSION_REGISTRY (reg));
g_return_if_fail (E_IS_MAIL_EXTENSION (extension));
types = e_mail_extension_get_mime_types (extension);
for (i = 0; types && types[i]; i++) {
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, types[i]);
if (!queue) {
i++;
queue = g_hash_table_lookup (
reg->priv->table,
interface->mime_types[ii]);
if (queue == NULL)
continue;
}
g_queue_remove (queue, extension);
if (camel_debug ("emformat:registry")) {
printf (
"Removed extension '%s' from type '%s'\n",
G_OBJECT_TYPE_NAME (extension), types[i]);
G_OBJECT_TYPE_NAME (extension),
interface->mime_types[ii]);
}
}
......
......@@ -39,29 +39,3 @@ e_mail_extension_default_init (EMailExtensionInterface *iface)
* of extensions.
*/
/**
* e_mail_extension_get_mime_types:
* @extension: an #EMailExtension
*
* A virtual function reimplemented in all mail extensions that returns a
* @NULL-terminated array of mime types that the particular extension is able
* to process.
*
* The mime-types can be either full (like text/plain), or with common subtype,
* e.g. text/ *. User should try to find the best mathing mime-type handler and
* use the latter type only as a fallback.
*
* Return value: a @NULL-terminated array or @NULL
*/
const gchar **
e_mail_extension_get_mime_types (EMailExtension *extension)
{
EMailExtensionInterface *interface;
g_return_val_if_fail (E_IS_MAIL_EXTENSION (extension), NULL);
interface = E_MAIL_EXTENSION_GET_INTERFACE (extension);
g_return_val_if_fail (interface->mime_types != NULL, NULL);
return interface->mime_types (extension);
}
......@@ -48,12 +48,13 @@ typedef struct _EMailExtensionInterface EMailExtensionInterface;
struct _EMailExtensionInterface {
GTypeInterface parent_interface;
const gchar ** (*mime_types) (EMailExtension *extension);
/* 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);
const gchar ** e_mail_extension_get_mime_types (EMailExtension *extension);
GType e_mail_extension_get_type (void) G_GNUC_CONST;
G_END_DECLS
......
......@@ -51,7 +51,10 @@ G_DEFINE_TYPE_EXTENDED (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
static const gchar *formatter_mime_types[] = { "application/vnd.evolution.widget.attachment-bar", NULL };
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.widget.attachment-bar",
NULL
};
static gboolean
emfe_attachment_bar_format (EMailFormatterExtension *extension,
......@@ -122,12 +125,6 @@ emfe_attachment_bar_get_description (EMailFormatterExtension *extension)
return NULL;
}
static const gchar **
emfe_attachment_bar_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_attachment_bar_class_init (EMailFormatterAttachmentBarClass *class)
{
......@@ -145,7 +142,7 @@ e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInte
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emfe_attachment_bar_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -64,9 +64,11 @@ G_DEFINE_TYPE_EXTENDED (
e_mail_formatter_formatter_extension_interface_init)
)
static const gchar *formatter_mime_types[] = { "application/vnd.evolution.attachment",
"application/vnd.evolution.widget.attachment-button",
NULL };
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.attachment",
"application/vnd.evolution.widget.attachment-button",
NULL
};
static EAttachmentStore *
find_attachment_store (EMailPartList *part_list,
......@@ -388,12 +390,6 @@ emfe_attachment_get_description (EMailFormatterExtension *extension)
return _("Display as attachment");
}
static const gchar **
emfe_attachment_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_attachment_class_init (EMailFormatterAttachmentClass *class)
{
......@@ -411,7 +407,7 @@ e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInte
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emfe_attachment_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -52,7 +52,10 @@ G_DEFINE_TYPE_EXTENDED (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
static const gchar *formatter_mime_types[] = { "application/vnd.evolution.error", NULL };
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.error",
NULL
};
static gboolean
emfe_error_format (EMailFormatterExtension *extension,
......@@ -128,12 +131,6 @@ emfe_error_get_description (EMailFormatterExtension *extension)
return NULL;
}
static const gchar **
emfe_error_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_error_class_init (EMailFormatterErrorClass *class)
{
......@@ -150,7 +147,7 @@ e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInte
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emfe_error_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -45,7 +45,10 @@ typedef struct _EMailFormatterHeadersClass {
GObjectClass parent_class;
} EMailFormatterHeadersClass;
static const gchar *formatter_mime_types[] = { "application/vnd.evolution.headers", NULL };
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.headers",
NULL
};
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
......@@ -583,12 +586,6 @@ emfe_headers_get_description (EMailFormatterExtension *extension)
return NULL;
}
static const gchar **
emfe_headers_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_headers_class_init (EMailFormatterHeadersClass *class)
{
......@@ -605,7 +602,7 @@ e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInte
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emfe_headers_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -33,18 +33,26 @@
#include <glib/gi18n-lib.h>
#include <camel/camel.h>
static const gchar *formatter_mime_types[] = { "image/gif", "image/jpeg",
"image/png", "image/x-png",
"image/x-bmp", "image/bmp",
"image/svg", "image/x-cmu-raster",
"image/x-ico",
"image/x-portable-anymap",
"image/x-portable-bitmap",
"image/x-portable-graymap",
"image/x-portable-pixmap",
"image/x-xpixmap",
"image/jpg", "image/pjpeg",
"image/*", NULL };
static const gchar *formatter_mime_types[] = {
"image/gif",
"image/jpeg",
"image/png",
"image/x-png",
"image/x-bmp",
"image/bmp",
"image/svg",
"image/x-cmu-raster",
"image/x-ico",
"image/x-portable-anymap",
"image/x-portable-bitmap",
"image/x-portable-graymap",
"image/x-portable-pixmap",
"image/x-xpixmap",
"image/jpg",
"image/pjpeg",
"image/*",
NULL
};
typedef struct _EMailFormatterImage {
GObject parent;
......@@ -158,12 +166,6 @@ emfe_image_get_description (EMailFormatterExtension *extension)
return _("Display part as an image");
}
static const gchar **
emfe_image_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_image_class_init (EMailFormatterImageClass *class)
{
......@@ -180,7 +182,7 @@ e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInte
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emfe_image_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -35,9 +35,11 @@
#include <string.h>
static const gchar * formatter_mime_types[] = { "message/rfc822",
"application/vnd.evolution.rfc822.end",
NULL };
static const gchar *formatter_mime_types[] = {
"message/rfc822",
"application/vnd.evolution.rfc822.end",
NULL
};
typedef struct _EMailFormatterMessageRFC822 {
GObject parent;
......@@ -255,12 +257,6 @@ emfe_message_rfc822_get_description (EMailFormatterExtension *extension)
return _("Format part as an RFC822 message");
}
static const gchar **
emfe_message_rfc822_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_message_rfc822_class_init (EMailFormatterMessageRFC822Class *class)
{
......@@ -277,7 +273,7 @@ e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInte
static void
e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emfe_message_rfc822_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -43,7 +43,10 @@ typedef struct _EMailFormatterPrintHeadersClass {
GObjectClass parent_class;
} EMailFormatterPrintHeadersClass;
static const gchar *formatter_mime_types[] = { "application/vnd.evolution.headers", NULL };
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.headers",
NULL
};
static void e_mail_formatter_print_formatter_extension_interface_init
(EMailFormatterExtensionInterface *iface);
......@@ -232,12 +235,6 @@ emfpe_headers_get_description (EMailFormatterExtension *extension)
return NULL;
}
static const gchar **
emfpe_headers_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_print_headers_class_init (EMailFormatterPrintHeadersClass *class)
{
......@@ -254,7 +251,7 @@ e_mail_formatter_print_formatter_extension_interface_init (EMailFormatterExtensi
static void
e_mail_formatter_print_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emfpe_headers_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -57,8 +57,10 @@ G_DEFINE_TYPE_EXTENDED (
e_mail_formatter_quote_formatter_extension_interface_init)
)
static const gchar *formatter_mime_types[] = { "application/vnd.evolution.attachment",
NULL };
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.attachment",
NULL
};
static gboolean
emfqe_attachment_format (EMailFormatterExtension *extension,
......@@ -133,12 +135,6 @@ emfqe_attachment_get_description (EMailFormatterExtension *extension)
return NULL;
}
static const gchar **
emfqe_attachment_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_quote_attachment_class_init (EMailFormatterQuoteAttachmentClass *class)
{
......@@ -155,7 +151,7 @@ e_mail_formatter_quote_formatter_extension_interface_init (EMailFormatterExtensi
static void
e_mail_formatter_quote_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emfqe_attachment_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -43,8 +43,6 @@ typedef struct _EMailFormatterQuoteHeadersClass {
GObjectClass parent_class;
} EMailFormatterQuoteHeadersClass;
static const gchar *formatter_mime_types[] = { "application/vnd.evolution.headers", NULL };
static void e_mail_formatter_quote_formatter_extension_interface_init
(EMailFormatterExtensionInterface *iface);
static void e_mail_formatter_quote_mail_extension_interface_init
......@@ -62,6 +60,11 @@ G_DEFINE_TYPE_EXTENDED (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_quote_formatter_extension_interface_init))
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.headers",
NULL
};
static void
emfqe_format_text_header (EMailFormatter *emf,
GString *buffer,
......@@ -258,12 +261,6 @@ emqfe_headers_get_description (EMailFormatterExtension *extension)
return NULL;
}
static const gchar **
emqfe_headers_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_quote_headers_class_init (EMailFormatterQuoteHeadersClass *class)
{
......@@ -280,7 +277,7 @@ e_mail_formatter_quote_formatter_extension_interface_init (EMailFormatterExtensi
static void
e_mail_formatter_quote_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emqfe_headers_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -35,10 +35,6 @@
#include <string.h>
static const gchar * formatter_mime_types[] = { "message/rfc822",
"application/vnd.evolution.rfc822.end",
NULL };
typedef struct _EMailFormatterQuoteMessageRFC822 {
GObject parent;
} EMailFormatterQuoteMessageRFC822;
......@@ -62,6 +58,12 @@ G_DEFINE_TYPE_EXTENDED (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_quote_formatter_extension_interface_init));
static const gchar *formatter_mime_types[] = {
"message/rfc822",
"application/vnd.evolution.rfc822.end",
NULL
};
static gboolean
emfqe_message_rfc822_format (EMailFormatterExtension *extension,
EMailFormatter *formatter,
......@@ -161,12 +163,6 @@ emfqe_message_rfc822_get_description (EMailFormatterExtension *extension)
return NULL;
}
static const gchar **
emfqe_message_rfc822_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_quote_message_rfc822_class_init (EMailFormatterQuoteMessageRFC822Class *class)
{
......@@ -183,7 +179,7 @@ e_mail_formatter_quote_formatter_extension_interface_init (EMailFormatterExtensi
static void
e_mail_formatter_quote_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emfqe_message_rfc822_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -30,10 +30,6 @@
#include <glib/gi18n-lib.h>
#include <camel/camel.h>
static const gchar *formatter_mime_types[] = { "text/enriched",
"text/richtext",
NULL };
typedef struct _EMailFormatterQuoteTextEnriched {
GObject parent;
} EMailFormatterQuoteTextEnriched;
......@@ -59,6 +55,12 @@ G_DEFINE_TYPE_EXTENDED (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_quote_formatter_extension_interace_init));
static const gchar *formatter_mime_types[] = {
"text/enriched",
"text/richtext",
NULL
};
static gboolean
emqfe_text_enriched_format (EMailFormatterExtension *extension,
EMailFormatter *formatter,
......@@ -108,12 +110,6 @@ emqfe_text_enriched_get_description (EMailFormatterExtension *extension)
return _("Display part as enriched text");
}
static const gchar **
emqfe_text_enriched_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_quote_text_enriched_class_init (EMailFormatterQuoteTextEnrichedClass *class)
{
......@@ -130,7 +126,7 @@ e_mail_formatter_quote_formatter_extension_interace_init (EMailFormatterExtensio
static void
e_mail_formatter_quote_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emqfe_text_enriched_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -33,8 +33,6 @@
#include <string.h>
static const gchar *formatter_mime_types[] = { "text/html", NULL };
typedef struct _EMailFormatterQuoteTextHTML {
GObject parent;
} EMailFormatterQuoteTextHTML;
......@@ -60,6 +58,11 @@ G_DEFINE_TYPE_EXTENDED (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_quote_formatter_extension_interface_init));
static const gchar *formatter_mime_types[] = {
"text/html",
NULL
};
static gboolean
emqfe_text_html_format (EMailFormatterExtension *extension,
EMailFormatter *formatter,
......@@ -110,12 +113,6 @@ emqfe_text_html_get_description (EMailFormatterExtension *extension)
return _("Format part as HTML");
}
static const gchar **
emqfe_text_html_mime_types (EMailExtension *extension)
{
return formatter_mime_types;
}
static void
e_mail_formatter_quote_text_html_class_init (EMailFormatterQuoteTextHTMLClass *class)
{
......@@ -132,7 +129,7 @@ e_mail_formatter_quote_formatter_extension_interface_init (EMailFormatterExtensi
static void
e_mail_formatter_quote_mail_extension_interface_init (EMailExtensionInterface *iface)
{
iface->mime_types = emqfe_text_html_mime_types;
iface->mime_types = formatter_mime_types;
}
static void
......
......@@ -31,8 +31,6 @@
#include <glib/gi18n-lib.h>