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
));
42 g_free (MM_FILTER_PARAM (o
)->details
->value
);
44 G_OBJECT_CLASS (mm_filter_param_parent_class
)->finalize (o
);
48 mm_filter_param_init (MMFilterParam
*fp
)
50 MMFilterParamDetails
*details
= fp
->details
= MM_FILTER_PARAM_GET_PRIVATE (fp
);
52 details
->value
= NULL
;
53 details
->attribute
= NULL
;
54 details
->op
= MM_COMP_NONE
;
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 (MMFilterParamDetails
));
68 mm_filter_param_get_attribute (MMFilterParam
*fp
)
70 return fp
->details
->attribute
;
74 mm_filter_param_get_operator (MMFilterParam
*fp
)
76 return fp
->details
->op
;
80 mm_filter_param_get_value (MMFilterParam
*fp
)
82 return fp
->details
->value
;
86 mm_filter_param_set_attribute (MMFilterParam
*fp
,
87 MMAttribute
*attribute
)
89 GType new_attr_type
= mm_attribute_get_value_type (attribute
);
90 GType old_attr_type
= mm_attribute_get_value_type (attribute
);
92 if (new_attr_type
!= old_attr_type
) {
93 /* we're changing attribute to a new tipe, change value type */
94 g_value_unset (fp
->details
->value
);
95 g_value_init (fp
->details
->value
, new_attr_type
);
98 fp
->details
->attribute
= attribute
;
102 mm_filter_param_set_value (MMFilterParam
*fp
,
105 GType attribute_type
= mm_attribute_get_value_type (fp
->details
->attribute
);
107 if (attribute_type
!= G_VALUE_TYPE (value
)) {
108 g_warning ("Trying to set an invalid value for attribute %s",
109 mm_attribute_get_name (fp
->details
->attribute
));
113 g_value_reset (fp
->details
->value
);
114 g_value_copy (value
, fp
->details
->value
);
118 mm_filter_param_set_comparision (MMFilterParam
*fp
,
119 MMComparisionOperator op
)
121 fp
->details
->op
= op
;
125 mm_filter_param_clear (MMFilterParam
*fp
)
127 fp
->details
->op
= MM_COMP_NONE
;
128 fp
->details
->attribute
= NULL
;
129 g_value_unset (fp
->details
->value
);
133 mm_filter_param_new (MMAttribute
*attribute
,
135 MMComparisionOperator op
)
138 GType attribute_type
= mm_attribute_get_value_type (attribute
);
140 if (attribute_type
!= G_VALUE_TYPE (value
)) {
141 g_warning ("Trying to set an incompatible value to attribute %s",
142 mm_attribute_get_name (attribute
));
146 fp
= g_object_new (MM_TYPE_FILTER_PARAM
, NULL
);
148 fp
->details
->op
= op
;
149 fp
->details
->attribute
= attribute
;
150 fp
->details
->value
= g_new0 (GValue
, 1);
151 g_value_init (fp
->details
->value
, attribute_type
);
152 g_value_copy (value
, fp
->details
->value
);