NoiseFilter: Dont drop last word of apparent hostnames. Too many non-hostnames can...
[beagle.git] / libbeagle / beagle / beagle-query-part-date.c
blobdef0cad9e8a48ce37d672f7fc6e66c50cf1eb58a
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; -*- */
3 /*
4 * beagle-query-part-date.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-date.h"
36 typedef struct {
37 char *key;
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;
46 static GString *
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);
51 char *tmp;
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);
60 g_free (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);
66 g_free (tmp);
69 _beagle_query_part_append_standard_footer (data);
71 return data;
74 G_DEFINE_TYPE (BeagleQueryPartDate, beagle_query_part_date, BEAGLE_TYPE_QUERY_PART)
76 static void
77 beagle_query_part_date_finalize (GObject *obj)
79 if (G_OBJECT_CLASS (parent_class)->finalize)
80 G_OBJECT_CLASS (parent_class)->finalize (obj);
83 static void
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));
97 static void
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);
107 return part;
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.
117 void
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.
136 void
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;