Commit 13f4544d authored by Matthew Barnes's avatar Matthew Barnes
Browse files

EMailFormatter: Simplify context allocation.

Replace the create_context() and free_context() class methods with a
"context_size" class member defaulting to sizeof(EMailFormatterContext).

EMailFormatter will use "context_size" to allocate a zero-filled slab of
heap memory.  Since EMailFormatterQuote is currently the only thing that
overrides the "context_size" (to append a "qf_flags" member), let's keep
this simple.
parent aebf88cc
......@@ -41,19 +41,6 @@ struct _EMailFormatterQuotePrivate {
static gpointer e_mail_formatter_quote_parent_class = 0;
static EMailFormatterContext *
mail_formatter_quote_create_context (EMailFormatter *formatter)
{
return g_malloc0 (sizeof (EMailFormatterQuoteContext));
}
static void
mail_formatter_quote_free_context (EMailFormatter *formatter,
EMailFormatterContext *context)
{
g_free ((EMailFormatterQuoteContext *) context);
}
static void
mail_formatter_quote_run (EMailFormatter *formatter,
EMailFormatterContext *context,
......@@ -189,9 +176,8 @@ e_mail_formatter_quote_class_init (EMailFormatterQuoteClass *class)
g_type_class_add_private (class, sizeof (EMailFormatterQuotePrivate));
formatter_class = E_MAIL_FORMATTER_CLASS (class);
formatter_class->context_size = sizeof (EMailFormatterQuoteContext);
formatter_class->run = mail_formatter_quote_run;
formatter_class->create_context = mail_formatter_quote_create_context;
formatter_class->free_context = mail_formatter_quote_free_context;
object_class = G_OBJECT_CLASS (class);
object_class->finalize = e_mail_formatter_quote_finalize;
......
......@@ -82,37 +82,20 @@ static gint signals[LAST_SIGNAL];
static EMailFormatterContext *
mail_formatter_create_context (EMailFormatter *formatter)
{
EMailFormatterClass *formatter_class;
formatter_class = E_MAIL_FORMATTER_GET_CLASS (formatter);
EMailFormatterClass *class;
if (formatter_class->create_context) {
if (!formatter_class->free_context) {
g_warning (
"%s implements create_context() but "
"does not implement free_context()!",
G_OBJECT_TYPE_NAME (formatter));
}
class = E_MAIL_FORMATTER_GET_CLASS (formatter);
return formatter_class->create_context (formatter);
}
g_warn_if_fail (class->context_size >= sizeof (EMailFormatterContext));
return g_new0 (EMailFormatterContext, 1);
return g_malloc0 (class->context_size);
}
static void
mail_formatter_free_context (EMailFormatter *formatter,
EMailFormatterContext *context)
{
EMailFormatterClass *formatter_class;
formatter_class = E_MAIL_FORMATTER_GET_CLASS (formatter);
if (formatter_class->free_context) {
formatter_class->free_context (formatter, context);
} else {
g_free (context);
}
g_free (context);
}
static void
......@@ -540,11 +523,8 @@ e_mail_formatter_class_init (EMailFormatterClass *class)
object_class->finalize = e_mail_formatter_finalize;
object_class->constructed = e_mail_formatter_constructed;
class->context_size = sizeof (EMailFormatterContext);
class->run = mail_formatter_run;
/* EMailFormatter calls these directly */
class->create_context = NULL;
class->free_context = NULL;
class->set_style = mail_formatter_set_style;
color = &class->colors[E_MAIL_FORMATTER_COLOR_BODY];
......
......@@ -114,22 +114,20 @@ struct _EMailFormatterClass {
/* Colors should apply globally */
GdkColor colors[E_MAIL_FORMATTER_NUM_COLOR_TYPES];
void (*run) (EMailFormatter *formatter,
EMailFormatterContext *context,
CamelStream *stream,
GCancellable *cancellable);
/* sizeof(EMailFormatterContext) or some derivative struct */
gsize context_size;
EMailFormatterContext * (*create_context) (EMailFormatter *formatter);
void (*free_context) (EMailFormatter *formatter,
EMailFormatterContext *context);
void (*run) (EMailFormatter *formatter,
EMailFormatterContext *context,
CamelStream *stream,
GCancellable *cancellable);
void (*set_style) (EMailFormatter *formatter,
GtkStyle *style,
GtkStateType state);
void (*set_style) (EMailFormatter *formatter,
GtkStyle *style,
GtkStateType state);
/* Signals */
void (*need_redraw) (EMailFormatter *formatter);
void (*need_redraw) (EMailFormatter *formatter);
};
GType e_mail_formatter_get_type (void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment