Add doc files to dist and fix version number in NEWS.
[mmediamanager.git] / libmmanager / mm-filter-param.c
blob5d0721dd115f599282d73cf78f6c18741eaf9278
1 /* MManager - a Desktop wide manager for multimedia applications.
3 * Copyright (C) 2008 Cosimo Cecchi <cosimoc@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include "mm-filter-param.h"
22 #include "mm-types.h"
23 #include "mm-attribute.h"
25 #include <glib.h>
27 #define MM_FILTER_PARAM_GET_PRIVATE(o) \
28 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_FILTER_PARAM, MMFilterParamPrivate))
30 struct _MMFilterParamPrivate {
31 GValue *value;
32 MMAttribute *attribute;
33 MMComparisionOperator op;
36 G_DEFINE_TYPE (MMFilterParam, mm_filter_param, G_TYPE_OBJECT);
38 void
39 mm_filter_param_finalize (GObject *o)
41 mm_filter_param_clear (MM_FILTER_PARAM (o));
42 g_free (MM_FILTER_PARAM (o)->details->value);
44 G_OBJECT_CLASS (mm_filter_param_parent_class)->finalize (o);
47 static void
48 mm_filter_param_init (MMFilterParam *fp)
50 MMFilterParamPrivate *details = fp->details = MM_FILTER_PARAM_GET_PRIVATE (fp);
52 details->value = NULL;
53 details->attribute = NULL;
54 details->op = MM_COMP_NONE;
57 static void
58 mm_filter_param_class_init (MMFilterParamClass *klass)
60 G_OBJECT_CLASS (klass)->finalize = mm_filter_param_finalize;
62 g_type_class_add_private (klass, sizeof (MMFilterParamPrivate));
65 /* public methods */
67 /**
68 * mm_filter_param_get_attribute:
69 * @filter_param: a #MMFilterParam.
71 * Gets the attribute stored in @filter_param.
73 * Return value: a #MMAttribute. Do not modify it.
76 MMAttribute *
77 mm_filter_param_get_attribute (MMFilterParam *filter_param)
79 return filter_param->details->attribute;
82 /**
83 * mm_filter_param_get_operator:
84 * @filter_param: a #MMFilterParam.
86 * Gets the operator stored in @filter_param.
88 * Return value: a #MMComparisionOperator.
91 MMComparisionOperator
92 mm_filter_param_get_operator (MMFilterParam *filter_param)
94 return filter_param->details->op;
97 /**
98 * mm_filter_param_get_value:
99 * @filter_param: a #MMFilterParam.
101 * Gets the value stored in @filter_param.
103 * Return value: a #GValue. Do not modify it.
106 GValue *
107 mm_filter_param_get_value (MMFilterParam *filter_param)
109 return filter_param->details->value;
113 * mm_filter_param_set_attribute:
114 * @filter_param: a #MMFilterParam.
115 * @attribute: a #MMAttribute.
117 * Sets the attribute inside @filter_param to be @attribute. This will also
118 * reset the value of @filter_param if @attribute specifies a #GType different
119 * from the old one.
122 void
123 mm_filter_param_set_attribute (MMFilterParam *filter_param,
124 MMAttribute *attribute)
126 GType new_attr_type = mm_attribute_get_value_type (attribute);
127 GType old_attr_type = mm_attribute_get_value_type (attribute);
129 if (new_attr_type != old_attr_type) {
130 /* we're changing attribute to a new tipe, change value type */
131 g_value_unset (filter_param->details->value);
132 g_value_init (filter_param->details->value, new_attr_type);
135 filter_param->details->attribute = attribute;
139 * mm_filter_param_set_value:
140 * @filter_param: a #MMFilterParam.
141 * @value: a #GValue.
143 * Sets the value inside @filter_param to be @value. The #GType of @value must
144 * be the same of the #MMAttribute inside @filter_param.
147 void
148 mm_filter_param_set_value (MMFilterParam *filter_param,
149 GValue *value)
151 GType attribute_type = mm_attribute_get_value_type
152 (filter_param->details->attribute);
154 if (attribute_type != G_VALUE_TYPE (value)) {
155 g_warning ("Trying to set an invalid value for attribute %s",
156 mm_attribute_get_name (filter_param->details->attribute));
157 return;
160 g_value_reset (filter_param->details->value);
161 g_value_copy (value, filter_param->details->value);
165 * mm_filter_param_set_comparision:
166 * @filter_param: a #MMFilterParam.
167 * @op: a #MMComparisionOperator.
169 * Sets the comparision operator inside @filter_param to be @op.
172 void
173 mm_filter_param_set_comparision (MMFilterParam *filter_param,
174 MMComparisionOperator op)
176 filter_param->details->op = op;
180 * mm_filter_param_clear:
181 * @filter_param: a #MMFilterParam.
183 * Clears all the fields of @filter_param, leaving it empty.
186 void
187 mm_filter_param_clear (MMFilterParam *filter_param)
189 filter_param->details->op = MM_COMP_NONE;
190 filter_param->details->attribute = NULL;
191 g_value_unset (filter_param->details->value);
195 * mm_filter_param_new:
196 * @attribute: a #MMAttribute.
197 * @value: a #GValue.
198 * @op: a #MMComparisionOperator.
200 * Builds a new #MMFilterParam, which would filter for @attribute<!-- -->'s
201 * value being in the relation specified by @op with @value.
203 * Return value: a #MMFilterParam object.
206 MMFilterParam *
207 mm_filter_param_new (MMAttribute *attribute,
208 GValue *value,
209 MMComparisionOperator op)
211 MMFilterParam *fp;
212 GType attribute_type = mm_attribute_get_value_type (attribute);
214 if (attribute_type != G_VALUE_TYPE (value)) {
215 g_warning ("Trying to set an incompatible value to attribute %s",
216 mm_attribute_get_name (attribute));
217 return NULL;
220 fp = g_object_new (MM_TYPE_FILTER_PARAM, NULL);
222 fp->details->op = op;
223 fp->details->attribute = attribute;
224 fp->details->value = g_new0 (GValue, 1);
225 g_value_init (fp->details->value, attribute_type);
226 g_value_copy (value, fp->details->value);
228 return fp;