diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-02-01 22:15:23 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-02-01 22:36:45 +0800 |
commit | ce3d24ef62437762e2e0b930cadb5c00580a4596 (patch) | |
tree | f026863a5fc7adf640ed49e2c45e4b8e0e24b4fe /em-format/e-mail-extension-registry.c | |
parent | 9a0b1266b5686d4985fec8a0dae7fdf00b1b8dd9 (diff) | |
download | gsoc2013-evolution-ce3d24ef62437762e2e0b930cadb5c00580a4596.tar.gz gsoc2013-evolution-ce3d24ef62437762e2e0b930cadb5c00580a4596.tar.zst gsoc2013-evolution-ce3d24ef62437762e2e0b930cadb5c00580a4596.zip |
Add a priority field for mail formatter and parser extensions.
Add a priority field to EMailFormatterExtension and EMailParserExtension
class structs. Extension classes can then explicitly specify a priority
with respect to other extension classes with the same MIME type, so that
the order of extension registration doesn't matter.
Priority field defaults to G_PRIORITY_DEFAULT. Built-in formatters and
extensions will use G_PRIORITY_LOW. We can get more sophisticated with
priority values if we need to, but this should suffice for now.
Diffstat (limited to 'em-format/e-mail-extension-registry.c')
-rw-r--r-- | em-format/e-mail-extension-registry.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/em-format/e-mail-extension-registry.c b/em-format/e-mail-extension-registry.c index 7e5f3a9b0b..3d5e7baa7c 100644 --- a/em-format/e-mail-extension-registry.c +++ b/em-format/e-mail-extension-registry.c @@ -59,7 +59,8 @@ destroy_queue (GQueue *queue) static void mail_extension_registry_add_extension (EMailExtensionRegistry *registry, const gchar **mime_types, - GType extension_type) + GType extension_type, + GCompareDataFunc compare_func) { GObject *extension; gint ii; @@ -86,7 +87,9 @@ mail_extension_registry_add_extension (EMailExtensionRegistry *registry, queue); } - g_queue_push_head (queue, g_object_ref (extension)); + g_queue_insert_sorted ( + queue, g_object_ref (extension), + compare_func, NULL); if (camel_debug ("emformat:registry")) { printf ( @@ -217,6 +220,23 @@ e_mail_parser_extension_registry_init (EMailParserExtensionRegistry *registry) { } +static gint +mail_parser_extension_registry_compare (gconstpointer extension1, + gconstpointer extension2, + gpointer user_data) +{ + EMailParserExtensionClass *class1; + EMailParserExtensionClass *class2; + + class1 = E_MAIL_PARSER_EXTENSION_GET_CLASS (extension1); + class2 = E_MAIL_PARSER_EXTENSION_GET_CLASS (extension2); + + if (class1->priority == class2->priority) + return 0; + + return (class1->priority < class2->priority) ? -1 : 1; +} + void e_mail_parser_extension_registry_load (EMailParserExtensionRegistry *registry) { @@ -239,7 +259,8 @@ e_mail_parser_extension_registry_load (EMailParserExtensionRegistry *registry) mail_extension_registry_add_extension ( E_MAIL_EXTENSION_REGISTRY (registry), - class->mime_types, children[ii]); + class->mime_types, children[ii], + mail_parser_extension_registry_compare); g_type_class_unref (class); } @@ -265,6 +286,23 @@ e_mail_formatter_extension_registry_init (EMailFormatterExtensionRegistry *regis { } +static gint +mail_formatter_extension_registry_compare (gconstpointer extension1, + gconstpointer extension2, + gpointer user_data) +{ + EMailFormatterExtensionClass *class1; + EMailFormatterExtensionClass *class2; + + class1 = E_MAIL_FORMATTER_EXTENSION_GET_CLASS (extension1); + class2 = E_MAIL_FORMATTER_EXTENSION_GET_CLASS (extension2); + + if (class1->priority == class2->priority) + return 0; + + return (class1->priority < class2->priority) ? -1 : 1; +} + void e_mail_formatter_extension_registry_load (EMailFormatterExtensionRegistry *registry, GType base_extension_type) @@ -286,7 +324,8 @@ e_mail_formatter_extension_registry_load (EMailFormatterExtensionRegistry *regis mail_extension_registry_add_extension ( E_MAIL_EXTENSION_REGISTRY (registry), - class->mime_types, children[ii]); + class->mime_types, children[ii], + mail_formatter_extension_registry_compare); g_type_class_unref (class); } |