diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-10-07 11:38:52 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-10-13 01:58:59 +0800 |
commit | a06e4484b8df804124b5bcf88d94dec5acfba270 (patch) | |
tree | 4fa42793d7dc461f2b3767296d76592182c48222 /mail/em-vfolder-context.c | |
parent | 5e0758bb6934a7859b1d8a247c8fb21c156772cf (diff) | |
download | gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.tar gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.tar.gz gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.tar.bz2 gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.tar.lz gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.tar.xz gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.tar.zst gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.zip |
Give MailSession a permanent home.
Global variables in shared libraries are a bad idea. EMailBackend now
owns the MailSession instance, which is actually now EMailSession.
Move the blocking utility functions in mail-tools.c to e-mail-session.c
and add asynchronous variants. Same approach as Camel.
Replace EMailReader.get_shell_backend() with EMailReader.get_backend(),
which returns an EMailBackend. Easier access to the EMailSession.
Diffstat (limited to 'mail/em-vfolder-context.c')
-rw-r--r-- | mail/em-vfolder-context.c | 208 |
1 files changed, 147 insertions, 61 deletions
diff --git a/mail/em-vfolder-context.c b/mail/em-vfolder-context.c index 6d5604afe4..4e7d4018d4 100644 --- a/mail/em-vfolder-context.c +++ b/mail/em-vfolder-context.c @@ -35,89 +35,175 @@ #include "em-filter-folder-element.h" -static EFilterElement *vfolder_new_element (ERuleContext *rc, const gchar *type); +#define EM_VFOLDER_CONTEXT_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), EM_TYPE_VFOLDER_CONTEXT, EMVFolderContextPrivate)) -static ERuleContextClass *parent_class = NULL; +struct _EMVFolderContextPrivate { + EMailSession *session; +}; + +enum { + PROP_0, + PROP_SESSION +}; + +G_DEFINE_TYPE ( + EMVFolderContext, + em_vfolder_context, + E_TYPE_RULE_CONTEXT) static void -em_vfolder_context_class_init (EMVFolderContextClass *klass) +vfolder_context_set_session (EMVFolderContext *context, + EMailSession *session) { - parent_class = g_type_class_ref (E_TYPE_RULE_CONTEXT); + g_return_if_fail (E_IS_MAIL_SESSION (session)); + g_return_if_fail (context->priv->session == NULL); - ((ERuleContextClass *)klass)->new_element = vfolder_new_element; + context->priv->session = g_object_ref (session); } static void -em_vfolder_context_init (EMVFolderContext *vc) +vfolder_context_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) { - e_rule_context_add_part_set ( - (ERuleContext *) vc, "partset", E_TYPE_FILTER_PART, - e_rule_context_add_part, e_rule_context_next_part); - - e_rule_context_add_rule_set ( - (ERuleContext *) vc, "ruleset", em_vfolder_rule_get_type(), - e_rule_context_add_rule, e_rule_context_next_rule); + switch (property_id) { + case PROP_SESSION: + vfolder_context_set_session ( + EM_VFOLDER_CONTEXT (object), + g_value_get_object (value)); + return; + } - ((ERuleContext *)vc)->flags = - E_RULE_CONTEXT_THREADING | E_RULE_CONTEXT_GROUPING; + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } -GType -em_vfolder_context_get_type (void) +static void +vfolder_context_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - static GType type = 0; - - if (G_UNLIKELY (type == 0)) { - static const GTypeInfo type_info = { - sizeof (EMVFolderContextClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) em_vfolder_context_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (EMVFolderContext), - 0, /* n_preallocs */ - (GInstanceInitFunc) em_vfolder_context_init, - NULL /* value_table */ - }; - - type = g_type_register_static ( - E_TYPE_RULE_CONTEXT, "EMVFolderContext", - &type_info, 0); + switch (property_id) { + case PROP_SESSION: + g_value_set_object ( + value, + em_vfolder_context_get_session ( + EM_VFOLDER_CONTEXT (object))); + return; } - return type; + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } -/** - * em_vfolder_context_new: - * - * Create a new EMVFolderContext object. - * - * Return value: A new #EMVFolderContext object. - **/ -EMVFolderContext * -em_vfolder_context_new (void) +static void +vfolder_context_dispose (GObject *object) { - return g_object_new (em_vfolder_context_get_type (), NULL, NULL); + EMVFolderContextPrivate *priv; + + priv = EM_VFOLDER_CONTEXT_GET_PRIVATE (object); + + if (priv->session != NULL) { + g_object_unref (priv->session); + priv->session = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (em_vfolder_context_parent_class)->dispose (object); } static EFilterElement * -vfolder_new_element (ERuleContext *rc, const gchar *type) +vfolder_context_new_element (ERuleContext *context, + const gchar *type) { - if (!strcmp(type, "system-flag")) { - return (EFilterElement *) e_filter_option_new (); - } else if (!strcmp(type, "score")) { - return (EFilterElement *) e_filter_int_new_type("score", -3, 3); - } else if (!strcmp(type, "folder-curi")) { - EMFilterFolderElement *ff = em_filter_folder_element_new (); - if (ff) - ff->store_camel_uri = TRUE; - return (EFilterElement *) ff; - } else if (!strcmp(type, "folder")) { - return (EFilterElement *) em_filter_folder_element_new (); - } else { - return parent_class->new_element (rc, type); + EMVFolderContextPrivate *priv; + + priv = EM_VFOLDER_CONTEXT_GET_PRIVATE (context); + + if (strcmp (type, "system-flag") == 0) + return e_filter_option_new (); + + if (strcmp (type, "score") == 0) + return e_filter_int_new_type("score", -3, 3); + + if (strcmp (type, "folder-curi") == 0) { + EFilterElement *element; + + element = em_filter_folder_element_new (priv->session); + ((EMFilterFolderElement *) element)->store_camel_uri = TRUE; + + return element; } + + if (strcmp (type, "folder") == 0) + return em_filter_folder_element_new (priv->session); + + return E_RULE_CONTEXT_CLASS (em_vfolder_context_parent_class)-> + new_element (context, type); +} + +static void +em_vfolder_context_class_init (EMVFolderContextClass *class) +{ + GObjectClass *object_class; + ERuleContextClass *rule_context_class; + + g_type_class_add_private (class, sizeof (EMVFolderContextPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = vfolder_context_set_property; + object_class->get_property = vfolder_context_get_property; + object_class->dispose = vfolder_context_dispose; + + rule_context_class = E_RULE_CONTEXT_CLASS (class); + rule_context_class->new_element = vfolder_context_new_element; + + g_object_class_install_property ( + object_class, + PROP_SESSION, + g_param_spec_object ( + "session", + NULL, + NULL, + E_TYPE_MAIL_SESSION, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); } +static void +em_vfolder_context_init (EMVFolderContext *context) +{ + context->priv = EM_VFOLDER_CONTEXT_GET_PRIVATE (context); + + e_rule_context_add_part_set ( + E_RULE_CONTEXT (context), "partset", E_TYPE_FILTER_PART, + (ERuleContextPartFunc) e_rule_context_add_part, + (ERuleContextNextPartFunc) e_rule_context_next_part); + + e_rule_context_add_rule_set ( + E_RULE_CONTEXT (context), "ruleset", EM_TYPE_VFOLDER_RULE, + (ERuleContextRuleFunc) e_rule_context_add_rule, + (ERuleContextNextRuleFunc) e_rule_context_next_rule); + + E_RULE_CONTEXT (context)->flags = + E_RULE_CONTEXT_THREADING | E_RULE_CONTEXT_GROUPING; +} + +EMVFolderContext * +em_vfolder_context_new (EMailSession *session) +{ + g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL); + + return g_object_new ( + EM_TYPE_VFOLDER_CONTEXT, "session", session, NULL); +} + +EMailSession * +em_vfolder_context_get_session (EMVFolderContext *context) +{ + g_return_val_if_fail (EM_IS_VFOLDER_CONTEXT (context), NULL); + + return context->priv->session; +} |