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.
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.
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/>
18 * Not Zed <notzed@lostzed.mmc.com.au>
19 * Jeffrey Stedfast <fejj@ximian.com>
21 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
32 #include <glib/gi18n.h>
34 #include "em-filter-folder-element.h"
35 #include "filter/e-filter-part.h"
36 #include "libevolution-utils/e-alert.h"
38 #define EM_FILTER_FOLDER_ELEMENT_GET_PRIVATE(obj) \
39 (G_TYPE_INSTANCE_GET_PRIVATE \
40 ((obj), EM_TYPE_FILTER_FOLDER_ELEMENT, EMFilterFolderElementPrivate))
42 struct _EMFilterFolderElementPrivate
{
47 EMFilterFolderElement
,
48 em_filter_folder_element
,
49 E_TYPE_FILTER_ELEMENT
)
52 filter_folder_element_finalize (GObject
*object
)
54 EMFilterFolderElementPrivate
*priv
;
56 priv
= EM_FILTER_FOLDER_ELEMENT_GET_PRIVATE (object
);
60 /* Chain up to parent's finalize() method. */
61 G_OBJECT_CLASS (em_filter_folder_element_parent_class
)->finalize (object
);
65 filter_folder_element_validate (EFilterElement
*fe
,
68 EMFilterFolderElement
*ff
= (EMFilterFolderElement
*) fe
;
70 g_warn_if_fail (alert
== NULL
|| *alert
== NULL
);
72 if (ff
->priv
->uri
!= NULL
&& *ff
->priv
->uri
!= '\0')
76 *alert
= e_alert_new ("mail:no-folder", NULL
);
82 filter_folder_element_eq (EFilterElement
*fe
,
85 return E_FILTER_ELEMENT_CLASS (
86 em_filter_folder_element_parent_class
)->eq (fe
, cm
) &&
87 strcmp (((EMFilterFolderElement
*) fe
)->priv
->uri
,
88 ((EMFilterFolderElement
*) cm
)->priv
->uri
)== 0;
92 filter_folder_element_xml_encode (EFilterElement
*fe
)
94 xmlNodePtr value
, work
;
95 EMFilterFolderElement
*ff
= (EMFilterFolderElement
*) fe
;
97 value
= xmlNewNode (NULL
, (xmlChar
*) "value");
98 xmlSetProp (value
, (xmlChar
*) "name", (xmlChar
*) fe
->name
);
99 xmlSetProp (value
, (xmlChar
*) "type", (xmlChar
*) "folder");
101 work
= xmlNewChild (value
, NULL
, (xmlChar
*) "folder", NULL
);
102 xmlSetProp (work
, (xmlChar
*) "uri", (xmlChar
*) ff
->priv
->uri
);
108 filter_folder_element_xml_decode (EFilterElement
*fe
,
111 EMFilterFolderElement
*ff
= (EMFilterFolderElement
*) fe
;
115 fe
->name
= (gchar
*) xmlGetProp(node
, (xmlChar
*) "name");
119 if (!strcmp((gchar
*) n
->name
, "folder")) {
122 uri
= (gchar
*) xmlGetProp(n
, (xmlChar
*) "uri");
123 g_free (ff
->priv
->uri
);
124 ff
->priv
->uri
= g_strdup (uri
);
135 filter_folder_element_get_widget (EFilterElement
*fe
)
139 widget
= E_FILTER_ELEMENT_CLASS (em_filter_folder_element_parent_class
)->
146 filter_folder_element_build_code (EFilterElement
*fe
,
150 /* We are doing nothing on purpose. */
154 filter_folder_element_format_sexp (EFilterElement
*fe
,
157 EMFilterFolderElement
*ff
= (EMFilterFolderElement
*) fe
;
159 camel_sexp_encode_string (out
, ff
->priv
->uri
);
163 filter_folder_element_copy_value (EFilterElement
*de
,
166 if (EM_IS_FILTER_FOLDER_ELEMENT (se
)) {
167 em_filter_folder_element_set_uri (
168 EM_FILTER_FOLDER_ELEMENT (de
),
169 EM_FILTER_FOLDER_ELEMENT (se
)->priv
->uri
);
171 E_FILTER_ELEMENT_CLASS (
172 em_filter_folder_element_parent_class
)->copy_value (de
, se
);
176 em_filter_folder_element_class_init (EMFilterFolderElementClass
*class)
178 GObjectClass
*object_class
;
179 EFilterElementClass
*filter_element_class
;
181 g_type_class_add_private (class, sizeof (EMFilterFolderElementPrivate
));
183 object_class
= G_OBJECT_CLASS (class);
184 object_class
->finalize
= filter_folder_element_finalize
;
186 filter_element_class
= E_FILTER_ELEMENT_CLASS (class);
187 filter_element_class
->validate
= filter_folder_element_validate
;
188 filter_element_class
->eq
= filter_folder_element_eq
;
189 filter_element_class
->xml_encode
= filter_folder_element_xml_encode
;
190 filter_element_class
->xml_decode
= filter_folder_element_xml_decode
;
191 filter_element_class
->get_widget
= filter_folder_element_get_widget
;
192 filter_element_class
->build_code
= filter_folder_element_build_code
;
193 filter_element_class
->format_sexp
= filter_folder_element_format_sexp
;
194 filter_element_class
->copy_value
= filter_folder_element_copy_value
;
198 em_filter_folder_element_init (EMFilterFolderElement
*element
)
200 element
->priv
= EM_FILTER_FOLDER_ELEMENT_GET_PRIVATE (element
);
204 em_filter_folder_element_new ()
206 return g_object_new (
207 EM_TYPE_FILTER_FOLDER_ELEMENT
,
212 em_filter_folder_element_get_uri (EMFilterFolderElement
*element
)
214 g_return_val_if_fail (EM_IS_FILTER_FOLDER_ELEMENT (element
), NULL
);
216 return element
->priv
->uri
;
220 em_filter_folder_element_set_uri (EMFilterFolderElement
*element
,
223 g_return_if_fail (EM_IS_FILTER_FOLDER_ELEMENT (element
));
225 g_free (element
->priv
->uri
);
226 element
->priv
->uri
= g_strdup (uri
);