cvsimport
[beagle.git] / libbeagle / beagle / beagle-queryable-status.c
blob57dc40568a848f9e27840e81beff2295263656ff
1 /*
2 * beagle-queryable-status.c
4 * Copyright (C) 2006 Debajyoti Bera <dbera.web@gmail.com>
6 */
8 /*
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #include "beagle-queryable-status.h"
29 #include "beagle-private.h"
31 BeagleQueryableStatus *
32 _beagle_queryable_status_new (void)
34 BeagleQueryableStatus *status;
36 status = g_new0 (BeagleQueryableStatus, 1);
38 status->ref_count = 1;
40 status->name = NULL;
41 status->item_count = -1;
42 status->state = BEAGLE_QUERYABLE_STATE_NA;
43 status->progress_percent = -1;
44 status->is_indexing = FALSE;
46 return status;
49 /**
50 * beagle_queryable_status_ref:
51 * @status: a #BeagleQueryableStatus
53 * Increases the reference count of the #BeagleQueryableStatus.
55 * Return value: the #BeagleQueryableStatus
56 **/
57 BeagleQueryableStatus *
58 beagle_queryable_status_ref (BeagleQueryableStatus *status)
60 g_return_val_if_fail (status != NULL, NULL);
62 status->ref_count ++;
64 return status;
67 /**
68 * beagle_queryable_status_unref:
69 * @status: a #BeagleQueryableStatus
71 * Decreases the reference count of the #BeagleQueryableStatus. When the reference count drops to 0, it is freed.
72 **/
73 void
74 beagle_queryable_status_unref (BeagleQueryableStatus *status)
76 g_return_if_fail (status != NULL);
77 g_return_if_fail (status->ref_count > 0);
79 status->ref_count --;
81 if (status->ref_count == 0) {
82 g_free (status->name);
83 g_free (status);
87 /**
88 * beagle_queryable_status_get_name:
89 * @status: a #BeagleQueryableStatus
91 * Fetches the name of the backend for the given #BeagleQueryableStatus.
93 * Return value: the name of the backend for the #BeagleQueryableStatus.
94 **/
95 G_CONST_RETURN char *
96 beagle_queryable_status_get_name (BeagleQueryableStatus *status)
98 g_return_val_if_fail (status != NULL, NULL);
100 return status->name;
104 * beagle_queryable_status_get_item_count:
105 * @status: a #BeagleQueryableStatus
107 * Fetches the number of items in the backend for the given #BeagleQueryableStatus.
109 * Return value: the number of items in the backend for the #BeagleQueryableStatus.
112 beagle_queryable_status_get_item_count (BeagleQueryableStatus *status)
114 g_return_val_if_fail (status != NULL, -1);
116 return status->item_count;
120 * beagle_queryable_status_get_state:
121 * @status: a #BeagleQueryableStatus
123 * DEPRECATED: This function will be removed in a future version. At
124 * present, this function will always reutrn BEAGLE_QUERYABLE_STATE_NA.
126 * Return value: BEAGLE_QUERYABLE_STATE_NA.
128 BeagleQueryableState
129 beagle_queryable_status_get_state (BeagleQueryableStatus *status)
131 g_return_val_if_fail (status != NULL, BEAGLE_QUERYABLE_STATE_NA);
133 return status->state;
137 * beagle_queryable_status_get_progress_percent:
138 * @status: a #BeagleQueryableStatus
140 * Fetches the progress in percent of the backend for the given #BeagleQueryableStatus.
142 * Return value: the progress of the backend for the #BeagleQueryableStatus.
145 beagle_queryable_status_get_progress_percent (BeagleQueryableStatus *status)
147 g_return_val_if_fail (status != NULL, -1);
149 return status->progress_percent;
153 * beagle_queryable_status_get_is_indexing:
154 * @status: a #BeagleQueryableStatus
156 * Fetches whether the backend for the given #BeagleQueryableStatus is currently indexing.
158 * Return value: whether the backend for the #BeagleQueryableStatus is currently indexing.
160 gboolean
161 beagle_queryable_status_get_is_indexing (BeagleQueryableStatus *status)
163 g_return_val_if_fail (status != NULL, FALSE);
165 return status->is_indexing;
168 void
169 _beagle_queryable_status_to_xml (BeagleQueryableStatus *status, GString *data)
171 char *tmp;
173 g_string_append_printf (data, "<IndexInformation");
175 if (status->name)
176 g_string_append_printf (data, " Name=\"%s\"", status->name);
178 g_string_append_printf (data, " ItemCount=\"%d\"", status->item_count);
180 g_string_append_printf (data, " ProgressPercent=\"%d\"", status->progress_percent);
182 g_string_append_printf (data, " IsIndexing=\"%s\"",
183 status->is_indexing ? "true" : "false");
185 g_string_append (data, ">");
187 g_string_append (data, "</IndexInformation>");