aboutsummaryrefslogtreecommitdiffstats
path: root/em-format
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-12-05 03:56:41 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-12-08 03:01:04 +0800
commit13f4544dafe211a748b064b86a8af4085d042b2b (patch)
tree2d7d421306bd37aefc7edbd10b5a0599e961d690 /em-format
parentaebf88cc8e3f45f8603a4706877dc59706be4963 (diff)
downloadgsoc2013-evolution-13f4544dafe211a748b064b86a8af4085d042b2b.tar.gz
gsoc2013-evolution-13f4544dafe211a748b064b86a8af4085d042b2b.tar.zst
gsoc2013-evolution-13f4544dafe211a748b064b86a8af4085d042b2b.zip
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.
Diffstat (limited to 'em-format')
-rw-r--r--em-format/e-mail-formatter-quote.c16
-rw-r--r--em-format/e-mail-formatter.c32
-rw-r--r--em-format/e-mail-formatter.h22
3 files changed, 17 insertions, 53 deletions
diff --git a/em-format/e-mail-formatter-quote.c b/em-format/e-mail-formatter-quote.c
index 2468a3110b..a86dad06af 100644
--- a/em-format/e-mail-formatter-quote.c
+++ b/em-format/e-mail-formatter-quote.c
@@ -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;
diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c
index 656e08d5d7..ad69c4b1dd 100644
--- a/em-format/e-mail-formatter.c
+++ b/em-format/e-mail-formatter.c
@@ -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];
diff --git a/em-format/e-mail-formatter.h b/em-format/e-mail-formatter.h
index 9b4e84d262..d7e578f794 100644
--- a/em-format/e-mail-formatter.h
+++ b/em-format/e-mail-formatter.h
@@ -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);