Commit 00b211b0 authored by Matthew Barnes's avatar Matthew Barnes
Browse files

Convert EMailFormatterExtension to an abstract class.

With the previous changes, all formatter extensions derive from
GObjectClass and implement the EMailFormatterExtensionInterface.

Simplify things further by making EMailFormatterExtension an abstract
base class so formatter extensions are now just direct subclasses and
need not bother with implementing GObject interfaces.
parent 54455ca1
......@@ -98,13 +98,9 @@ load (EMailExtensionRegistry *ereg,
extension_class = g_type_class_ref (extension_type);
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;
}
if (g_type_is_a (extension_type, interface_type))
mime_types = ((EMailFormatterExtensionClass *)
extension_class)->mime_types;
interface_type = E_TYPE_MAIL_PARSER_EXTENSION;
if (g_type_is_a (extension_type, interface_type)) {
......
......@@ -28,24 +28,13 @@
#include <em-format/e-mail-formatter-extension.h>
#include <em-format/e-mail-formatter.h>
typedef struct _EMailFormatterAttachmentBar {
GObject parent;
} EMailFormatterAttachmentBar;
typedef EMailFormatterExtension EMailFormatterAttachmentBar;
typedef EMailFormatterExtensionClass EMailFormatterAttachmentBarClass;
typedef struct _EMailFormatterAttachmentBarClass {
GObjectClass parent_class;
} EMailFormatterAttachmentBarClass;
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
G_DEFINE_TYPE (
EMailFormatterAttachmentBar,
e_mail_formatter_attachment_bar,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
E_TYPE_MAIL_FORMATTER_EXTENSION)
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.widget.attachment-bar",
......@@ -122,22 +111,16 @@ emfe_attachment_bar_get_description (EMailFormatterExtension *extension)
}
static void
e_mail_formatter_attachment_bar_class_init (EMailFormatterAttachmentBarClass *class)
e_mail_formatter_attachment_bar_class_init (EMailFormatterExtensionClass *class)
{
class->mime_types = formatter_mime_types;
class->format = emfe_attachment_bar_format;
class->get_widget = emfe_attachment_bar_get_widget;
class->get_display_name = emfe_attachment_bar_get_display_name;
class->get_description = emfe_attachment_bar_get_description;
}
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
e_mail_formatter_attachment_bar_init (EMailFormatterExtension *extension)
{
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_attachment_bar_init (EMailFormatterAttachmentBar *extension)
{
}
......@@ -40,25 +40,13 @@
#define d(x)
typedef struct _EMailFormatterAttachment {
GObject parent;
} EMailFormatterAttachment;
typedef EMailFormatterExtension EMailFormatterAttachment;
typedef EMailFormatterExtensionClass EMailFormatterAttachmentClass;
typedef struct _EMailFormatterAttachmentClass {
GObjectClass parent_class;
} EMailFormatterAttachmentClass;
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
G_DEFINE_TYPE (
EMailFormatterAttachment,
e_mail_formatter_attachment,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init)
)
E_TYPE_MAIL_FORMATTER_EXTENSION)
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.attachment",
......@@ -387,22 +375,16 @@ emfe_attachment_get_description (EMailFormatterExtension *extension)
}
static void
e_mail_formatter_attachment_class_init (EMailFormatterAttachmentClass *class)
e_mail_formatter_attachment_class_init (EMailFormatterExtensionClass *class)
{
class->mime_types = formatter_mime_types;
class->format = emfe_attachment_format;
class->get_widget = emfe_attachment_get_widget;
class->get_display_name = emfe_attachment_get_display_name;
class->get_description = emfe_attachment_get_description;
}
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
e_mail_formatter_attachment_init (EMailFormatterExtension *extension)
{
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_attachment_init (EMailFormatterAttachment *formatter)
{
}
......@@ -29,24 +29,13 @@
#include <camel/camel.h>
typedef struct _EMailFormatterError {
GObject parent;
} EMailFormatterError;
typedef EMailFormatterExtension EMailFormatterError;
typedef EMailFormatterExtensionClass EMailFormatterErrorClass;
typedef struct _EMailFormatterErrorClass {
GObjectClass parent_class;
} EMailFormatterErrorClass;
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
G_DEFINE_TYPE (
EMailFormatterError,
e_mail_formatter_error,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
E_TYPE_MAIL_FORMATTER_EXTENSION)
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.error",
......@@ -128,21 +117,15 @@ emfe_error_get_description (EMailFormatterExtension *extension)
}
static void
e_mail_formatter_error_class_init (EMailFormatterErrorClass *class)
e_mail_formatter_error_class_init (EMailFormatterExtensionClass *class)
{
class->mime_types = formatter_mime_types;
class->format = emfe_error_format;
class->get_display_name = emfe_error_get_display_name;
class->get_description = emfe_error_get_description;
}
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
e_mail_formatter_error_init (EMailFormatterExtension *extension)
{
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_error_init (EMailFormatterError *formatter)
{
}
......@@ -18,22 +18,19 @@
#include "e-mail-formatter-extension.h"
G_DEFINE_INTERFACE (
G_DEFINE_ABSTRACT_TYPE (
EMailFormatterExtension,
e_mail_formatter_extension,
G_TYPE_OBJECT)
/**
* EMailFormatterExtension:
*
* The #EMailFormatterExtension is an abstract interface for all extensions for
* #EmailFormatter.
*/
static void
e_mail_formatter_extension_default_init (EMailFormatterExtensionInterface *iface)
e_mail_formatter_extension_class_init (EMailFormatterExtensionClass *class)
{
}
static void
e_mail_formatter_extension_init (EMailFormatterExtension *extension)
{
}
/**
......@@ -45,18 +42,18 @@ e_mail_formatter_extension_default_init (EMailFormatterExtensionInterface *iface
* @stream: a #CamelStream to which the output should be written
* @cancellable: (allow-none) a #GCancellable
*
* A virtual function reimplemented in all mail formatter extensions. The function
* formats @part, generated HTML (or other format that can be displayed to user)
* and writes it to the @stream.
* A virtual function reimplemented in all mail formatter extensions. The
* function formats @part, generated HTML (or other format that can be
* displayed to user) and writes it to the @stream.
*
* When the function is unable to format the @part (either because it's broken
* or because it is a different mimetype then the extension is specialized for), the
* function will return @FALSE indicating the #EMailFormatter, that it should pick
* another extension.
* or because it is a different mimetype then the extension is specialized
* for), the function will return @FALSE indicating the #EMailFormatter, that
* it should pick another extension.
*
* Implementation of this function must be thread-safe.
*
* Return value: Returns @TRUE when the @part was successfully formatted and
* Returns: Returns @TRUE when the @part was successfully formatted and
* data were written to the @stream, @FALSE otherwise.
*/
gboolean
......@@ -67,7 +64,7 @@ e_mail_formatter_extension_format (EMailFormatterExtension *extension,
CamelStream *stream,
GCancellable *cancellable)
{
EMailFormatterExtensionInterface *interface;
EMailFormatterExtensionClass *class;
g_return_val_if_fail (E_IS_MAIL_FORMATTER_EXTENSION (extension), FALSE);
g_return_val_if_fail (E_IS_MAIL_FORMATTER (formatter), FALSE);
......@@ -75,10 +72,10 @@ e_mail_formatter_extension_format (EMailFormatterExtension *extension,
g_return_val_if_fail (part != NULL, FALSE);
g_return_val_if_fail (CAMEL_IS_STREAM (stream), FALSE);
interface = E_MAIL_FORMATTER_EXTENSION_GET_INTERFACE (extension);
g_return_val_if_fail (interface->format != NULL, FALSE);
class = E_MAIL_FORMATTER_EXTENSION_GET_CLASS (extension);
g_return_val_if_fail (class->format != NULL, FALSE);
return interface->format (extension, formatter, context, part, stream, cancellable);
return class->format (extension, formatter, context, part, stream, cancellable);
}
/**
......@@ -87,19 +84,19 @@ e_mail_formatter_extension_format (EMailFormatterExtension *extension,
*
* Returns whether the extension can provide a GtkWidget.
*
* Return value: Returns %TRUE when @extension reimplements get_widget(), %FALSE
* Returns: Returns %TRUE when @extension reimplements get_widget(), %FALSE
* otherwise.
*/
gboolean
e_mail_formatter_extension_has_widget (EMailFormatterExtension *extension)
{
EMailFormatterExtensionInterface *interface;
EMailFormatterExtensionClass *class;
g_return_val_if_fail (E_IS_MAIL_FORMATTER_EXTENSION (extension), FALSE);
interface = E_MAIL_FORMATTER_EXTENSION_GET_INTERFACE (extension);
class = E_MAIL_FORMATTER_EXTENSION_GET_CLASS (extension);
return (interface->get_widget != NULL);
return (class->get_widget != NULL);
}
/**
......@@ -108,17 +105,17 @@ e_mail_formatter_extension_has_widget (EMailFormatterExtension *extension)
* @part: an #EMailPart
* @params: a #GHashTable
*
* A virtual function reimplemented in some mail formatter extensions. The function
* should construct a #GtkWidget for given @part. The @params hash table can contain
* additional parameters listed in the &lt;object&gt; HTML element that has requested
* the widget.
* A virtual function reimplemented in some mail formatter extensions. The
* function should construct a #GtkWidget for given @part. The @params hash
* table can contain additional parameters listed in the &lt;object&gt; HTML
* element that has requested the widget.
*
* When @bind_dom_func is not %NULL, the callee will set a callback function
* which should be called when the webpage is completely rendered to setup
* bindings between DOM events and the widget.
*
* Return value: Returns a #GtkWidget or %NULL, when error occurs or given @extension
* does not reimplement this method.
* Returns: Returns a #GtkWidget or %NULL, when error occurs or given
* @extension does not reimplement this method.
*/
GtkWidget *
e_mail_formatter_extension_get_widget (EMailFormatterExtension *extension,
......@@ -126,20 +123,17 @@ e_mail_formatter_extension_get_widget (EMailFormatterExtension *extension,
EMailPart *part,
GHashTable *params)
{
EMailFormatterExtensionInterface *interface;
GtkWidget *widget;
EMailFormatterExtensionClass *class;
GtkWidget *widget = NULL;
g_return_val_if_fail (E_IS_MAIL_FORMATTER_EXTENSION (extension), NULL);
g_return_val_if_fail (part != NULL, NULL);
g_return_val_if_fail (params != NULL, NULL);
interface = E_MAIL_FORMATTER_EXTENSION_GET_INTERFACE (extension);
class = E_MAIL_FORMATTER_EXTENSION_GET_CLASS (extension);
widget = NULL;
if (interface->get_widget) {
widget = interface->get_widget (
extension, context, part, params);
}
if (class->get_widget != NULL)
widget = class->get_widget (extension, context, part, params);
return widget;
}
......@@ -149,21 +143,21 @@ e_mail_formatter_extension_get_widget (EMailFormatterExtension *extension,
* @extension: an #EMailFormatterExtension
*
* A virtual function reimplemented in all formatter extensions. It returns a
* short name of the extension that can be displayed in user interface.
* short name of the extension that can be displayed in user class.
*
* Return value: A (localized) string with name of the extension
* Returns: A (localized) string with name of the extension
*/
const gchar *
e_mail_formatter_extension_get_display_name (EMailFormatterExtension *extension)
{
EMailFormatterExtensionInterface *interface;
EMailFormatterExtensionClass *class;
g_return_val_if_fail (E_IS_MAIL_FORMATTER_EXTENSION (extension), NULL);
interface = E_MAIL_FORMATTER_EXTENSION_GET_INTERFACE (extension);
g_return_val_if_fail (interface->get_display_name != NULL, NULL);
class = E_MAIL_FORMATTER_EXTENSION_GET_CLASS (extension);
g_return_val_if_fail (class->get_display_name != NULL, NULL);
return interface->get_display_name (extension);
return class->get_display_name (extension);
}
/**
......@@ -173,17 +167,17 @@ e_mail_formatter_extension_get_display_name (EMailFormatterExtension *extension)
* A virtual function reimplemented in all formatter extensions. It returns a
* longer description of capabilities of the extension.
*
* Return value: A (localized) string with description of the extension.
* Returns: A (localized) string with description of the extension.
*/
const gchar *
e_mail_formatter_extension_get_description (EMailFormatterExtension *extension)
{
EMailFormatterExtensionInterface *interface;
EMailFormatterExtensionClass *class;
g_return_val_if_fail (E_IS_MAIL_FORMATTER_EXTENSION (extension), NULL);
interface = E_MAIL_FORMATTER_EXTENSION_GET_INTERFACE (extension);
g_return_val_if_fail (interface->get_description != NULL, NULL);
class = E_MAIL_FORMATTER_EXTENSION_GET_CLASS (extension);
g_return_val_if_fail (class->get_description != NULL, NULL);
return interface->get_description (extension);
return class->get_description (extension);
}
......@@ -30,29 +30,41 @@
#define E_MAIL_FORMATTER_EXTENSION(obj) \
(G_TYPE_CHECK_INSTANCE_CAST \
((obj), E_TYPE_MAIL_FORMATTER_EXTENSION, EMailFormatterExtension))
#define E_MAIL_FORMATTER_EXTENSION_INTERFACE(cls) \
#define E_MAIL_FORMATTER_EXTENSION_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST \
((cls), E_TYPE_MAIL_FORMATTER_EXTENSION, EMailFormatterExtensionInterface))
((cls), E_TYPE_MAIL_FORMATTER_EXTENSION, EMailFormatterExtensionClass))
#define E_IS_MAIL_FORMATTER_EXTENSION(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE \
((obj), E_TYPE_MAIL_FORMATTER_EXTENSION))
#define E_IS_MAIL_FORMATTER_EXTENSION_INTERFACE(cls) \
#define E_IS_MAIL_FORMATTER_EXTENSION_CLASS(cls) \
(G_TYPE_CHECK_CLASS_TYPE \
((cls), E_TYPE_MAIL_FORMATTER_EXTENSION))
#define E_MAIL_FORMATTER_EXTENSION_GET_INTERFACE(obj) \
(G_TYPE_INSTANCE_GET_INTERFACE \
((obj), E_TYPE_MAIL_FORMATTER_EXTENSION, EMailFormatterExtensionInterface))
#define E_MAIL_FORMATTER_EXTENSION_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS \
((obj), E_TYPE_MAIL_FORMATTER_EXTENSION, EMailFormatterExtensionClass))
#define EMF_EXTENSION_GET_FORMATTER(e) \
E_MAIL_FORMATTER (e_extension_get_extensible (E_EXTENSION (e)))
G_BEGIN_DECLS
/**
* EMailFormatterExtension:
*
* The #EMailFormatterExtension is an abstract class for all extensions for
* #EMailFormatter.
*/
typedef struct _EMailFormatterExtension EMailFormatterExtension;
typedef struct _EMailFormatterExtensionInterface EMailFormatterExtensionInterface;
typedef struct _EMailFormatterExtensionClass EMailFormatterExtensionClass;
typedef struct _EMailFormatterExtensionPrivate EMailFormatterExtensionPrivate;
struct _EMailFormatterExtension {
GObject parent;
EMailFormatterExtensionPrivate *priv;
};
struct _EMailFormatterExtensionInterface {
GTypeInterface parent_interface;
struct _EMailFormatterExtensionClass {
GObjectClass parent_class;
/* This is a NULL-terminated array of supported MIME types.
* The MIME types can be exact (e.g. "text/plain") or use a
......@@ -65,23 +77,19 @@ struct _EMailFormatterExtensionInterface {
EMailPart *part,
CamelStream *stream,
GCancellable *cancellable);
GtkWidget * (*get_widget) (EMailFormatterExtension *extension,
EMailPartList *context,
EMailPart *part,
GHashTable *params);
const gchar * (*get_display_name)
(EMailFormatterExtension *extension);
const gchar * (*get_description)
(EMailFormatterExtension *extension);
};
GType e_mail_formatter_extension_get_type
(void);
(void) G_GNUC_CONST;
gboolean e_mail_formatter_extension_format
(EMailFormatterExtension *extension,
EMailFormatter *formatter,
......@@ -89,19 +97,15 @@ gboolean e_mail_formatter_extension_format
EMailPart *part,
CamelStream *stream,
GCancellable *cancellable);
gboolean e_mail_formatter_extension_has_widget
(EMailFormatterExtension *extension);
GtkWidget * e_mail_formatter_extension_get_widget
(EMailFormatterExtension *extension,
EMailPartList *context,
EMailPart *part,
GHashTable *params);
const gchar * e_mail_formatter_extension_get_display_name
(EMailFormatterExtension *extension);
const gchar * e_mail_formatter_extension_get_description
(EMailFormatterExtension *extension);
......
......@@ -37,30 +37,19 @@
#include <string.h>
typedef struct _EMailFormatterHeaders {
GObject parent;
} EMailFormatterHeaders;
typedef EMailFormatterExtension EMailFormatterHeaders;
typedef EMailFormatterExtensionClass EMailFormatterHeadersClass;
typedef struct _EMailFormatterHeadersClass {
GObjectClass parent_class;
} EMailFormatterHeadersClass;
G_DEFINE_TYPE (
EMailFormatterHeaders,
e_mail_formatter_headers,
E_TYPE_MAIL_FORMATTER_EXTENSION)
static const gchar *formatter_mime_types[] = {
"application/vnd.evolution.headers",
NULL
};
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
EMailFormatterHeaders,
e_mail_formatter_headers,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init))
static void
format_short_headers (EMailFormatter *formatter,
GString *buffer,
......@@ -583,21 +572,15 @@ emfe_headers_get_description (EMailFormatterExtension *extension)
}
static void
e_mail_formatter_headers_class_init (EMailFormatterHeadersClass *class)
e_mail_formatter_headers_class_init (EMailFormatterExtensionClass *class)
{
class->mime_types = formatter_mime_types;
class->format = emfe_headers_format;
class->get_display_name = emfe_headers_get_display_name;
class->get_description = emfe_headers_get_description;
}
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
e_mail_formatter_headers_init (EMailFormatterExtension *extension)
{
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_headers_init (EMailFormatterHeaders *formatter)
{
}
......@@ -33,6 +33,14 @@
#include <glib/gi18n-lib.h>
#include <camel/camel.h>
typedef EMailFormatterExtension EMailFormatterImage;
typedef EMailFormatterExtensionClass EMailFormatterImageClass;
G_DEFINE_TYPE (
EMailFormatterImage,
e_mail_formatter_image,
E_TYPE_MAIL_FORMATTER_EXTENSION)
static const gchar *formatter_mime_types[] = {
"image/gif",
"image/jpeg",
......@@ -54,25 +62,6 @@ static const gchar *formatter_mime_types[] = {
NULL
};
typedef struct _EMailFormatterImage {
GObject parent;
} EMailFormatterImage;
typedef struct _EMailFormatterImageClass {
GObjectClass parent_class;
} EMailFormatterImageClass;
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
G_DEFINE_TYPE_EXTENDED (
EMailFormatterImage,
e_mail_formatter_image,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
static gboolean
emfe_image_format (EMailFormatterExtension *extension,
EMailFormatter *formatter,
......@@ -163,21 +152,15 @@ emfe_image_get_description (EMailFormatterExtension *extension)
}
static void
e_mail_formatter_image_class_init (EMailFormatterImageClass *class)
e_mail_formatter_image_class_init (EMailFormatterExtensionClass *class)
{
class->mime_types = formatter_mime_types;
class->format = emfe_image_format;
class->get_display_name = emfe_image_get_display_name;
class->get_description = emfe_image_get_description;
}
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
e_mail_formatter_image_init (EMailFormatterExtension *extension)
{
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_image_init (EMailFormatterImage *formatter)
{