FilterHtml.cs: Add ExtractText(string) command to extract text out of large html...
[beagle.git] / libbeagle / beagle / beagle-query-part-or.c
blobd246fbb2b8cc59b1b0340e9063fc54c9f0f89b1e
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; -*- */
3 /*
4 * beagle-query-part-or.c
6 * Copyright (C) 2005 Novell, Inc.
8 */
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
30 #include <string.h>
32 #include "beagle-private.h"
33 #include "beagle-query-part.h"
34 #include "beagle-query-part-or.h"
36 typedef struct {
37 GSList *subparts;
38 } BeagleQueryPartOrPrivate;
40 #define BEAGLE_QUERY_PART_OR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_QUERY_PART_OR, BeagleQueryPartOrPrivate))
42 static GObjectClass *parent_class = NULL;
44 G_DEFINE_TYPE (BeagleQueryPartOr, beagle_query_part_or, BEAGLE_TYPE_QUERY_PART)
46 static GString *
47 beagle_query_part_or_to_xml (BeagleQueryPart *part)
49 BeagleQueryPartOrPrivate *priv = BEAGLE_QUERY_PART_OR_GET_PRIVATE (part);
50 GString *data = g_string_new (NULL);
51 GSList *iter;
53 _beagle_query_part_append_standard_header (data, part, "Or");
55 g_string_append (data, "<SubParts>");
57 for (iter = priv->subparts; iter != NULL; iter = iter->next) {
58 BeagleQueryPart *subpart = BEAGLE_QUERY_PART (iter->data);
59 GString *sub_data;
61 sub_data = _beagle_query_part_to_xml (subpart);
62 g_string_append_len (data, sub_data->str, sub_data->len);
63 g_string_free (sub_data, TRUE);
66 g_string_append (data, "</SubParts>");
68 _beagle_query_part_append_standard_footer (data);
70 return data;
73 static void
74 beagle_query_part_or_finalize (GObject *obj)
76 BeagleQueryPartOr *or = BEAGLE_QUERY_PART_OR (obj);
77 BeagleQueryPartOrPrivate *priv = BEAGLE_QUERY_PART_OR_GET_PRIVATE (or);
79 g_slist_foreach (priv->subparts, (GFunc) g_object_unref, NULL);
80 g_slist_free (priv->subparts);
82 if (G_OBJECT_CLASS (parent_class)->finalize)
83 G_OBJECT_CLASS (parent_class)->finalize (obj);
86 static void
87 beagle_query_part_or_class_init (BeagleQueryPartOrClass *klass)
89 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
90 BeagleQueryPartClass *query_part_class = BEAGLE_QUERY_PART_CLASS (klass);
92 parent_class = g_type_class_peek_parent (klass);
94 obj_class->finalize = beagle_query_part_or_finalize;
95 query_part_class->to_xml = beagle_query_part_or_to_xml;
97 g_type_class_add_private (klass, sizeof (BeagleQueryPartOrPrivate));
100 static void
101 beagle_query_part_or_init (BeagleQueryPartOr *part)
107 * beagle_query_part_or_new:
109 * Creates a new #BeagleQueryPartOr.
111 * Return value: the newly created #BeagleQueryPartOr.
113 BeagleQueryPartOr *
114 beagle_query_part_or_new (void)
116 BeagleQueryPartOr *part = g_object_new (BEAGLE_TYPE_QUERY_PART_OR, 0);
117 return part;
121 * beagle_query_part_or_add_subpart:
122 * @part: a #BeagleQueryPartOr
123 * @subpart: a #BeagleQueryPart
125 * Adds a #BeagleQueryPart as a subpart to the #BeagleQueryPartOr. It takes ownership
126 * of the subpart, so you should not unref it afterward.
128 void
129 beagle_query_part_or_add_subpart (BeagleQueryPartOr *part,
130 BeagleQueryPart *subpart)
132 BeagleQueryPartOrPrivate *priv;
134 g_return_if_fail (BEAGLE_IS_QUERY_PART_OR (part));
135 g_return_if_fail (BEAGLE_IS_QUERY_PART (subpart));
137 priv = BEAGLE_QUERY_PART_OR_GET_PRIVATE (part);
138 priv->subparts = g_slist_append (priv->subparts, subpart);