1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; -*- */
4 * beagle-query-part-text.c
6 * Copyright (C) 2005 Novell, Inc.
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.
32 #include "beagle-private.h"
33 #include "beagle-query-part.h"
34 #include "beagle-query-part-text.h"
38 gboolean search_full_text
: 1;
39 gboolean search_properties
: 1;
40 } BeagleQueryPartTextPrivate
;
42 #define BEAGLE_QUERY_PART_TEXT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_QUERY_PART_TEXT, BeagleQueryPartTextPrivate))
44 static GObjectClass
*parent_class
= NULL
;
46 G_DEFINE_TYPE (BeagleQueryPartText
, beagle_query_part_text
, BEAGLE_TYPE_QUERY_PART
)
49 beagle_query_part_text_to_xml (BeagleQueryPart
*part
)
51 BeagleQueryPartTextPrivate
*priv
= BEAGLE_QUERY_PART_TEXT_GET_PRIVATE (part
);
52 GString
*data
= g_string_new (NULL
);
54 _beagle_query_part_append_standard_header (data
, part
, "Text");
56 g_string_append (data
, "<Text>");
57 g_string_append (data
, priv
->text
);
58 g_string_append (data
, "</Text>");
60 if (priv
->search_full_text
)
61 g_string_append (data
, "<SearchFullText>true</SearchFullText>");
63 g_string_append (data
, "<SearchFullText>false</SearchFullText>");
65 if (priv
->search_properties
)
66 g_string_append (data
, "<SearchTextProperties>true</SearchTextProperties>");
68 g_string_append (data
, "<SearchTextProperties>false</SearchTextProperties>");
70 _beagle_query_part_append_standard_footer (data
);
76 beagle_query_part_text_finalize (GObject
*obj
)
78 if (G_OBJECT_CLASS (parent_class
)->finalize
)
79 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
83 beagle_query_part_text_class_init (BeagleQueryPartTextClass
*klass
)
85 GObjectClass
*obj_class
= G_OBJECT_CLASS (klass
);
86 BeagleQueryPartClass
*query_part_class
= BEAGLE_QUERY_PART_CLASS (klass
);
88 parent_class
= g_type_class_peek_parent (klass
);
90 obj_class
->finalize
= beagle_query_part_text_finalize
;
91 query_part_class
->to_xml
= beagle_query_part_text_to_xml
;
93 g_type_class_add_private (klass
, sizeof (BeagleQueryPartTextPrivate
));
97 beagle_query_part_text_init (BeagleQueryPartText
*part
)
102 BeagleQueryPartText
*
103 beagle_query_part_text_new (void)
105 BeagleQueryPartText
*part
= g_object_new (BEAGLE_TYPE_QUERY_PART_TEXT
, 0);
110 * beagle_query_part_text_set_text:
111 * @part: a #BeagleQueryPartText
112 * @text: a #const char *
114 * Sets the text to search for in a #BeagleQueryPartText. This should only
115 * be used for programmatically built queries, because it does not use the
116 * query language and doesn't handle things like "OR". If you are getting
117 * input from a user, you should use #BeagleQueryPartHuman instead.
120 beagle_query_part_text_set_text (BeagleQueryPartText
*part
,
123 BeagleQueryPartTextPrivate
*priv
;
125 g_return_if_fail (BEAGLE_IS_QUERY_PART_TEXT (part
));
126 g_return_if_fail (text
!= NULL
);
128 priv
= BEAGLE_QUERY_PART_TEXT_GET_PRIVATE (part
);
133 * beagle_query_part_text_set_search_full_text:
134 * @part: a #BeagleQueryPartText
135 * @search_full_text: a #gboolean
137 * Sets whether to search the full text of documents to find the text part
138 * of this #BeagleQueryPartText.
141 beagle_query_part_text_set_search_full_text (BeagleQueryPartText
*part
,
142 gboolean search_full_text
)
144 BeagleQueryPartTextPrivate
*priv
;
146 g_return_if_fail (BEAGLE_IS_QUERY_PART_TEXT (part
));
148 priv
= BEAGLE_QUERY_PART_TEXT_GET_PRIVATE (part
);
149 priv
->search_full_text
= search_full_text
;
153 * beagle_query_part_text_set_search_properties:
154 * @part: a #BeagleQueryPartText
155 * @search_properties: a #gboolean
157 * Sets whether to search the properties of documents to find the text part
158 * of this #BeagleQueryPartText.
161 beagle_query_part_text_set_search_properties (BeagleQueryPartText
*part
,
162 gboolean search_properties
)
164 BeagleQueryPartTextPrivate
*priv
;
166 g_return_if_fail (BEAGLE_IS_QUERY_PART_TEXT (part
));
168 priv
= BEAGLE_QUERY_PART_TEXT_GET_PRIVATE (part
);
169 priv
->search_properties
= search_properties
;