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"
26 #define MM_FILTER_PARAM_GET_PRIVATE(o) \
27 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_FILTER_PARAM, MMFilterParamDetails))
29 struct _MMFilterParamDetails
{
31 MMAttribute
*attribute
;
32 MMComparisionOperator op
;
35 G_DEFINE_TYPE (MMFilterParam
, mm_filter_param
, G_TYPE_OBJECT
);
38 mm_filter_param_finalize (GObject
*o
)
40 mm_filter_param_clear (MM_FILTER_PARAM (fp
));
42 G_OBJECT_CLASS (mm_filter_param_parent_class
)->finalize (o
);
46 mm_filter_param_init (MMFilterParam
*fp
)
48 MMFilterParamDetails
*details
= fp
->details
= MM_FILTER_PARAM_GET_PRIVATE (fp
);
52 mm_filter_param_class_init (MMFilterParamClass
*klass
)
54 G_OBJECT_CLASS (klass
)->finalize
= mm_filter_param_finalize
;
56 g_type_class_add_private (klass
, sizeof (MMFilterParamDetails
));
62 mm_filter_param_get_attribute (MMFilterParam
*fp
)
68 mm_filter_param_get_operator (MMFilterParam
*fp
)
74 mm_filter_param_get_value (MMFilterParam
*fp
)
80 mm_filter_param_set_attribute (MMFilterParam
*fp
,
81 MMAttribute
*attribute
)
83 GType new_attr_type
= mm_attribute_get_type (attribute
);
84 GType old_attr_type
= mm_attribute_get_type (attribute
);
86 if (new_attr_type
!= old_attr_type
) {
87 /* we're changing attribute to a new tipe, change value type */
88 g_value_unset (fp
->value
);
89 g_value_init (fp
->value
, new_attr_type
);
92 fp
->attribute
= attribute
;
96 mm_filter_param_set_value (MMFilterParam
*fp
,
99 GType attribute_type
= mm_attribute_get_type (fp
->attribute
);
101 if (attribute_type
!= G_VALUE_TYPE (value
)) {
102 g_warning ("Trying to set an invalid value for attribute %s",
103 mm_attribute_get_name (fp
->attribute
));
107 g_value_reset (fp
->value
);
108 g_value_copy (value
, fp
->value
);
112 mm_filter_param_set_comparision (MMFilterParam
*fp
,
113 MMComparisionOperator op
)
119 mm_filter_param_clear (MMFilterParam
*fp
)
121 fp
->op
= MM_COMP_NONE
;
122 fp
->attribute
= NULL
;
123 g_value_unset (fp
->value
);
127 mm_filter_param_new (MMAttribute
*attribute
,
129 MMComparisionOperator op
)
132 GType attribute_type
= mm_attribute_get_type (attribute
);
134 if (attribute_type
!= G_VALUE_TYPE (value
)) {
135 g_warning ("Trying to set an incompatible value to attribute %s",
136 mm_attribute_get_name (attribute
));
140 fp
= g_object_new (MM_TYPE_FILTER_PARAM
, NULL
);
142 fp
->details
->op
= op
;
143 fp
->details
->attribute
= attribute
;
144 fp
->details
->value
= g_value_init (fp
->value
, attribute_type
);
145 g_value_copy (value
, fp
->details
->value
);