No issues found
1 /*
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with the program; if not, see <http://www.gnu.org/licenses/>
15 *
16 *
17 * Authors:
18 * Not Zed <notzed@lostzed.mmc.com.au>
19 * Jeffrey Stedfast <fejj@ximian.com>
20 *
21 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22 *
23 */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <string.h>
30
31 #include "em-vfolder-context.h"
32 #include "em-vfolder-rule.h"
33 #include "filter/e-filter-option.h"
34 #include "filter/e-filter-int.h"
35
36 #include "em-filter-folder-element.h"
37
38 #define EM_VFOLDER_CONTEXT_GET_PRIVATE(obj) \
39 (G_TYPE_INSTANCE_GET_PRIVATE \
40 ((obj), EM_TYPE_VFOLDER_CONTEXT, EMVFolderContextPrivate))
41
42 struct _EMVFolderContextPrivate {
43 gint placeholder;
44 };
45
46 enum {
47 PROP_0,
48 PROP_SESSION
49 };
50
51 G_DEFINE_TYPE (
52 EMVFolderContext,
53 em_vfolder_context,
54 E_TYPE_RULE_CONTEXT)
55
56 static EFilterElement *
57 vfolder_context_new_element (ERuleContext *context,
58 const gchar *type)
59 {
60 if (strcmp (type, "system-flag") == 0)
61 return e_filter_option_new ();
62
63 if (strcmp (type, "score") == 0)
64 return e_filter_int_new_type ("score", -3, 3);
65
66 if (strcmp (type, "folder") == 0)
67 return em_filter_folder_element_new ();
68
69 /* XXX Legacy type name. Same as "folder" now. */
70 if (strcmp (type, "folder-curi") == 0)
71 return em_filter_folder_element_new ();
72
73 return E_RULE_CONTEXT_CLASS (em_vfolder_context_parent_class)->
74 new_element (context, type);
75 }
76
77 static void
78 em_vfolder_context_class_init (EMVFolderContextClass *class)
79 {
80 ERuleContextClass *rule_context_class;
81
82 g_type_class_add_private (class, sizeof (EMVFolderContextPrivate));
83
84 rule_context_class = E_RULE_CONTEXT_CLASS (class);
85 rule_context_class->new_element = vfolder_context_new_element;
86 }
87
88 static void
89 em_vfolder_context_init (EMVFolderContext *context)
90 {
91 context->priv = EM_VFOLDER_CONTEXT_GET_PRIVATE (context);
92
93 e_rule_context_add_part_set (
94 E_RULE_CONTEXT (context), "partset", E_TYPE_FILTER_PART,
95 (ERuleContextPartFunc) e_rule_context_add_part,
96 (ERuleContextNextPartFunc) e_rule_context_next_part);
97
98 e_rule_context_add_rule_set (
99 E_RULE_CONTEXT (context), "ruleset", EM_TYPE_VFOLDER_RULE,
100 (ERuleContextRuleFunc) e_rule_context_add_rule,
101 (ERuleContextNextRuleFunc) e_rule_context_next_rule);
102
103 E_RULE_CONTEXT (context)->flags =
104 E_RULE_CONTEXT_THREADING | E_RULE_CONTEXT_GROUPING;
105 }
106
107 EMVFolderContext *
108 em_vfolder_context_new ()
109 {
110 return g_object_new (
111 EM_TYPE_VFOLDER_CONTEXT, NULL);
112 }