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"
23 #include "mm-attribute.h"
27 #define MM_FILTER_PARAM_GET_PRIVATE(o) \
28 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_FILTER_PARAM, MMFilterParamDetails))
30 struct _MMFilterParamDetails
{
32 MMAttribute
*attribute
;
33 MMComparisionOperator op
;
36 G_DEFINE_TYPE (MMFilterParam
, mm_filter_param
, G_TYPE_OBJECT
);
39 mm_filter_param_finalize (GObject
*o
)
41 mm_filter_param_clear (MM_FILTER_PARAM (o
));
43 G_OBJECT_CLASS (mm_filter_param_parent_class
)->finalize (o
);
47 mm_filter_param_init (MMFilterParam
*fp
)
49 MMFilterParamDetails
*details
= fp
->details
= MM_FILTER_PARAM_GET_PRIVATE (fp
);
51 details
->value
= NULL
;
52 details
->attribute
= NULL
;
53 details
->op
= MM_COMP_NONE
;
57 mm_filter_param_class_init (MMFilterParamClass
*klass
)
59 G_OBJECT_CLASS (klass
)->finalize
= mm_filter_param_finalize
;
61 g_type_class_add_private (klass
, sizeof (MMFilterParamDetails
));
67 mm_filter_param_get_attribute (MMFilterParam
*fp
)
69 return fp
->details
->attribute
;
73 mm_filter_param_get_operator (MMFilterParam
*fp
)
75 return fp
->details
->op
;
79 mm_filter_param_get_value (MMFilterParam
*fp
)
81 return fp
->details
->value
;
85 mm_filter_param_set_attribute (MMFilterParam
*fp
,
86 MMAttribute
*attribute
)
88 GType new_attr_type
= mm_attribute_get_value_type (attribute
);
89 GType old_attr_type
= mm_attribute_get_value_type (attribute
);
91 if (new_attr_type
!= old_attr_type
) {
92 /* we're changing attribute to a new tipe, change value type */
93 g_value_unset (fp
->details
->value
);
94 g_value_init (fp
->details
->value
, new_attr_type
);
97 fp
->details
->attribute
= attribute
;
101 mm_filter_param_set_value (MMFilterParam
*fp
,
104 GType attribute_type
= mm_attribute_get_value_type (fp
->details
->attribute
);
106 if (attribute_type
!= G_VALUE_TYPE (value
)) {
107 g_warning ("Trying to set an invalid value for attribute %s",
108 mm_attribute_get_name (fp
->details
->attribute
));
112 g_value_reset (fp
->details
->value
);
113 g_value_copy (value
, fp
->details
->value
);
117 mm_filter_param_set_comparision (MMFilterParam
*fp
,
118 MMComparisionOperator op
)
120 fp
->details
->op
= op
;
124 mm_filter_param_clear (MMFilterParam
*fp
)
126 fp
->details
->op
= MM_COMP_NONE
;
127 fp
->details
->attribute
= NULL
;
128 g_value_unset (fp
->details
->value
);
132 mm_filter_param_new (MMAttribute
*attribute
,
134 MMComparisionOperator op
)
137 GType attribute_type
= mm_attribute_get_value_type (attribute
);
139 if (attribute_type
!= G_VALUE_TYPE (value
)) {
140 g_warning ("Trying to set an incompatible value to attribute %s",
141 mm_attribute_get_name (attribute
));
145 fp
= g_object_new (MM_TYPE_FILTER_PARAM
, NULL
);
147 fp
->details
->op
= op
;
148 fp
->details
->attribute
= attribute
;
149 fp
->details
->value
= g_value_init (fp
->details
->value
, attribute_type
);
150 g_value_copy (value
, fp
->details
->value
);