1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; -*- */
4 * beagle-query-part-date.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-date.h"
38 BeagleTimestamp
*start_date
;
39 BeagleTimestamp
*end_date
;
40 } BeagleQueryPartDatePrivate
;
42 #define BEAGLE_QUERY_PART_DATE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_QUERY_PART_DATE, BeagleQueryPartDatePrivate))
44 static GObjectClass
*parent_class
= NULL
;
47 beagle_query_part_date_to_xml (BeagleQueryPart
*part
)
49 BeagleQueryPartDatePrivate
*priv
= BEAGLE_QUERY_PART_DATE_GET_PRIVATE (part
);
50 GString
*data
= g_string_new (NULL
);
53 _beagle_query_part_append_standard_header (data
, part
, "DateRange");
55 g_string_append (data
, "<Key>" BEAGLE_QUERY_PART_TARGET_ALL
"</Key>");
57 if (priv
->start_date
!= NULL
) {
58 tmp
= _beagle_timestamp_to_string (priv
->start_date
);
59 g_string_append_printf (data
, "<StartDate>%s</StartDate>", tmp
);
63 if (priv
->end_date
!= NULL
) {
64 tmp
= _beagle_timestamp_to_string (priv
->end_date
);
65 g_string_append_printf (data
, "<EndDate>%s</EndDate>", tmp
);
69 _beagle_query_part_append_standard_footer (data
);
74 G_DEFINE_TYPE (BeagleQueryPartDate
, beagle_query_part_date
, BEAGLE_TYPE_QUERY_PART
)
77 beagle_query_part_date_finalize (GObject
*obj
)
79 if (G_OBJECT_CLASS (parent_class
)->finalize
)
80 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
84 beagle_query_part_date_class_init (BeagleQueryPartDateClass
*klass
)
86 GObjectClass
*obj_class
= G_OBJECT_CLASS (klass
);
87 BeagleQueryPartClass
*query_part_class
= BEAGLE_QUERY_PART_CLASS (klass
);
89 parent_class
= g_type_class_peek_parent (klass
);
91 obj_class
->finalize
= beagle_query_part_date_finalize
;
92 query_part_class
->to_xml
= beagle_query_part_date_to_xml
;
94 g_type_class_add_private (klass
, sizeof (BeagleQueryPartDatePrivate
));
98 beagle_query_part_date_init (BeagleQueryPartDate
*part
)
103 BeagleQueryPartDate
*
104 beagle_query_part_date_new (void)
106 BeagleQueryPartDate
*part
= g_object_new (BEAGLE_TYPE_QUERY_PART_DATE
, 0);
111 * beagle_query_part_date_set_start_date:
112 * @part: a #BeagleQueryPartDate
113 * @start_date: a #BeagleTimestamp
115 * Sets the start date for the date range in a #BeagleQueryPartDate.
118 beagle_query_part_date_set_start_date (BeagleQueryPartDate
*part
,
119 BeagleTimestamp
*start_date
)
121 BeagleQueryPartDatePrivate
*priv
;
123 g_return_if_fail (BEAGLE_IS_QUERY_PART_DATE (part
));
125 priv
= BEAGLE_QUERY_PART_DATE_GET_PRIVATE (part
);
126 priv
->start_date
= start_date
;
130 * beagle_query_part_date_set_end_date:
131 * @part: a #BeagleQueryPartDate
132 * @start_date: a #BeagleTimestamp
134 * Sets the end date for the date range in a #BeagleQueryPartDate.
137 beagle_query_part_date_set_end_date (BeagleQueryPartDate
*part
,
138 BeagleTimestamp
*end_date
)
140 BeagleQueryPartDatePrivate
*priv
;
142 g_return_if_fail (BEAGLE_IS_QUERY_PART_DATE (part
));
144 priv
= BEAGLE_QUERY_PART_DATE_GET_PRIVATE (part
);
145 priv
->end_date
= end_date
;