Send along the type data in a QueryPart from libbeagle. Fix from D Bera
[beagle.git] / libbeagle / beagle / beagle-query-part-property.c
blob17ad90f1a4e7f18c5687104b3c0f082172785a47
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; -*- */
3 /*
4 * beagle-query-part-property.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-property.h"
36 typedef struct {
37 const char *key;
38 const char *value;
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)
49 static GString *
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>");
63 break;
64 case BEAGLE_PROPERTY_TYPE_KEYWORD:
65 g_string_append (data, "<Type>Keyword</Type>");
66 break;
67 case BEAGLE_PROPERTY_TYPE_DATE:
68 g_string_append (data, "<Type>Date</Type>");
69 break;
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);
77 return data;
80 static void
81 beagle_query_part_property_finalize (GObject *obj)
83 if (G_OBJECT_CLASS (parent_class)->finalize)
84 G_OBJECT_CLASS (parent_class)->finalize (obj);
87 static void
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));
101 static void
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);
110 return part;
113 void
114 beagle_query_part_property_set_key (BeagleQueryPartProperty *part,
115 const char *key)
117 BeagleQueryPartPropertyPrivate *priv = BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part);
118 priv->key = key;
121 void
122 beagle_query_part_property_set_value (BeagleQueryPartProperty *part,
123 const char *value)
125 BeagleQueryPartPropertyPrivate *priv = BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part);
126 priv->value = value;
129 void
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;
138 void
139 beagle_query_part_property_set_logic (BeagleQueryPartProperty *part,
140 BeagleQueryPartLogic logic)
142 BeagleQueryPartPropertyPrivate *priv = BEAGLE_QUERY_PART_PROPERTY_GET_PRIVATE (part);
143 priv->logic = logic;