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 BeagleQueryPartLogic logic
;
41 } BeagleQueryPartPropertyPrivate
;
43 #define BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_QUERY_PART_PROPERTY, BeagleQueryPartPropertyPrivate))
45 static GObjectClass
*parent_class
= NULL
;
47 G_DEFINE_TYPE (BeagleQueryPartProperty
, beagle_query_part_property
, BEAGLE_TYPE_QUERY_PART
)
50 beagle_query_part_property_to_xml (BeagleQueryPart
*part
, GError
**err
)
52 BeagleQueryPartPropertyPrivate
*priv
;
53 priv
= BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part
);
55 GString
*data
= g_string_new (NULL
);
57 _beagle_query_part_append_standard_header (data
, "Property", priv
->logic
);
60 switch (priv
->prop_type
) {
61 case BEAGLE_PROPERTY_TYPE_TEXT
:
62 g_string_append (data
, "<Type>Text</Type>");
64 case BEAGLE_PROPERTY_TYPE_KEYWORD
:
65 g_string_append (data
, "<Type>Keyword</Type>");
67 case BEAGLE_PROPERTY_TYPE_DATE
:
68 g_string_append (data
, "<Type>Date</Type>");
72 g_string_append_printf (data
, "<Key>%s</Key>", priv
->key
);
73 g_string_append_printf (data
, "<Value>%s</Value>", priv
->value
);
75 _beagle_query_part_append_standard_footer (data
);
81 beagle_query_part_property_finalize (GObject
*obj
)
83 if (G_OBJECT_CLASS (parent_class
)->finalize
)
84 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
88 beagle_query_part_property_class_init (BeagleQueryPartPropertyClass
*klass
)
90 GObjectClass
*obj_class
= G_OBJECT_CLASS (klass
);
91 BeagleQueryPartClass
*query_part_class
= BEAGLE_QUERY_PART_CLASS (klass
);
93 parent_class
= g_type_class_peek_parent (klass
);
95 obj_class
->finalize
= beagle_query_part_property_finalize
;
96 query_part_class
->to_xml
= beagle_query_part_property_to_xml
;
98 g_type_class_add_private (klass
, sizeof (BeagleQueryPartPropertyPrivate
));
102 beagle_query_part_property_init (BeagleQueryPartProperty
*part
)
106 BeagleQueryPartProperty
*
107 beagle_query_part_property_new (void)
109 BeagleQueryPartProperty
*part
= g_object_new (BEAGLE_TYPE_QUERY_PART_PROPERTY
, 0);
114 beagle_query_part_property_set_key (BeagleQueryPartProperty
*part
,
117 BeagleQueryPartPropertyPrivate
*priv
= BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part
);
122 beagle_query_part_property_set_value (BeagleQueryPartProperty
*part
,
125 BeagleQueryPartPropertyPrivate
*priv
= BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part
);
130 beagle_query_part_property_set_property_type (BeagleQueryPartProperty
*part
,
131 BeaglePropertyType prop_type
)
133 BeagleQueryPartPropertyPrivate
*priv
= BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part
);
134 priv
->prop_type
= prop_type
;
139 beagle_query_part_property_set_logic (BeagleQueryPartProperty
*part
,
140 BeagleQueryPartLogic logic
)
142 BeagleQueryPartPropertyPrivate
*priv
= BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part
);