1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; -*- */
4 * beagle-query-part-property.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-property.h"
39 BeaglePropertyType prop_type
;
40 } BeagleQueryPartPropertyPrivate
;
42 #define BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_QUERY_PART_PROPERTY, BeagleQueryPartPropertyPrivate))
44 static GObjectClass
*parent_class
= NULL
;
46 G_DEFINE_TYPE (BeagleQueryPartProperty
, beagle_query_part_property
, BEAGLE_TYPE_QUERY_PART
)
49 beagle_query_part_property_to_xml (BeagleQueryPart
*part
)
51 BeagleQueryPartPropertyPrivate
*priv
= BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part
);
53 GString
*data
= g_string_new (NULL
);
55 _beagle_query_part_append_standard_header (data
, part
, "Property");
57 switch (priv
->prop_type
) {
58 case BEAGLE_PROPERTY_TYPE_TEXT
:
59 g_string_append (data
, "<Type>Text</Type>");
61 case BEAGLE_PROPERTY_TYPE_KEYWORD
:
62 g_string_append (data
, "<Type>Keyword</Type>");
64 case BEAGLE_PROPERTY_TYPE_DATE
:
65 g_string_append (data
, "<Type>Date</Type>");
68 g_assert_not_reached ();
71 g_string_append_printf (data
, "<Key>%s</Key>", priv
->key
);
72 g_string_append_printf (data
, "<Value>%s</Value>", priv
->value
);
74 _beagle_query_part_append_standard_footer (data
);
80 beagle_query_part_property_finalize (GObject
*obj
)
82 if (G_OBJECT_CLASS (parent_class
)->finalize
)
83 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
87 beagle_query_part_property_class_init (BeagleQueryPartPropertyClass
*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_property_finalize
;
95 query_part_class
->to_xml
= beagle_query_part_property_to_xml
;
97 g_type_class_add_private (klass
, sizeof (BeagleQueryPartPropertyPrivate
));
101 beagle_query_part_property_init (BeagleQueryPartProperty
*part
)
105 BeagleQueryPartProperty
*
106 beagle_query_part_property_new (void)
108 BeagleQueryPartProperty
*part
= g_object_new (BEAGLE_TYPE_QUERY_PART_PROPERTY
, 0);
113 * beagle_query_part_property_set_key:
114 * @part: a #BeagleQueryPartProperty
115 * @key: a #const char *
117 * Sets the key of the #BeagleQueryPartProperty to be queried against. For
118 * example, "beagle:Type".
121 beagle_query_part_property_set_key (BeagleQueryPartProperty
*part
,
124 BeagleQueryPartPropertyPrivate
*priv
;
126 g_return_if_fail (BEAGLE_IS_QUERY_PART_PROPERTY (part
));
128 priv
= BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part
);
133 * beagle_query_part_property_set_value:
134 * @part: a #BeagleQueryPartProperty
135 * @value: a #const char *
137 * Sets the value of the #BeagleQueryPartProperty to be queried for. For
138 * example, "MailMessage".
141 beagle_query_part_property_set_value (BeagleQueryPartProperty
*part
,
144 BeagleQueryPartPropertyPrivate
*priv
;
146 g_return_if_fail (BEAGLE_IS_QUERY_PART_PROPERTY (part
));
148 priv
= BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part
);
153 * beagle_query_part_property_set_property_type:
154 * @part: a #BeagleQueryPartProperty
155 * @value: a value of #BeaglePropertyType
157 * Sets the property type of the #BeagleQueryPartProperty to be queried for.
160 beagle_query_part_property_set_property_type (BeagleQueryPartProperty
*part
,
161 BeaglePropertyType prop_type
)
163 BeagleQueryPartPropertyPrivate
*priv
;
165 g_return_if_fail (BEAGLE_IS_QUERY_PART_PROPERTY (part
));
167 priv
= BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part
);
168 priv
->prop_type
= prop_type
;