Add doc files to dist and fix version number in NEWS.
[mmediamanager.git] / libmmanager / mm-filter.c
blob41ceef0dd9aa0866092a81e1c172feddd2234b56
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 <glib.h>
22 #include <glib-object.h>
24 #include "mm-filter.h"
26 #define MM_FILTER_GET_PRIVATE(o) \
27 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_FILTER, MMFilterPrivate))
29 struct _MMFilterPrivate {
30 GList *filter_params;
33 G_DEFINE_TYPE (MMFilter, mm_filter, G_TYPE_OBJECT);
35 static void
36 unref_obj (gpointer data,
37 gpointer _unused)
39 g_object_unref (data);
42 static void
43 unref_all_fps (MMFilter *f)
45 MMFilterPrivate *details = f->details;
46 g_list_foreach (details->filter_params, unref_obj, NULL);
49 static void
50 add_to_filter_params (gpointer _fp,
51 gpointer _filter)
53 MMFilter *filter = _filter;
54 MMFilterParam *fp = _fp;
56 mm_filter_add_filtering_param (filter, fp);
59 static void
60 mm_filter_finalize (GObject *o)
62 unref_all_fps (MM_FILTER (o));
63 g_list_free (MM_FILTER (o)->details->filter_params);
65 G_OBJECT_CLASS (mm_filter_parent_class)->finalize (o);
68 static void
69 mm_filter_init (MMFilter *f)
71 MMFilterPrivate *details = f->details = MM_FILTER_GET_PRIVATE (f);
72 details->filter_params = NULL;
75 static void
76 mm_filter_class_init (MMFilterClass *klass)
78 G_OBJECT_CLASS (klass)->finalize = mm_filter_finalize;
80 g_type_class_add_private (klass, sizeof (MMFilterPrivate));
83 /* public methods */
85 /**
86 * mm_filter_new:
88 * Builds an empty #MMFilter object.
90 * Return value: an empty #MMFilter.
93 MMFilter *
94 mm_filter_new (void)
96 return g_object_new (MM_TYPE_FILTER, NULL);
99 /**
100 * mm_filter_add_filtering_param:
101 * @filter: a #MMFilter
102 * @fp: a #MMFilterParam
104 * Adds @fp to @filter. @filter will keep a reference to @fp.
107 void
108 mm_filter_add_filtering_param (MMFilter *filter,
109 MMFilterParam *fp)
111 MMFilterPrivate *details = filter->details;
113 g_return_if_fail (MM_IS_FILTER_PARAM (fp));
115 details->filter_params = g_list_prepend (details->filter_params,
116 g_object_ref (fp));
120 * mm_filter_add_filtering_params:
121 * @filter: a #MMFilter.
122 * @fps: a #GList of #MMFilterParam objects.
124 * Adds the #MMFilterParam objects inside the list to @filter. @filter
125 * will keep a reference to all the #MMFilterParam objects.
128 void
129 mm_filter_add_filtering_params (MMFilter *filter,
130 GList *fps)
132 g_list_foreach (fps, add_to_filter_params, filter);
136 * mm_filter_clear:
137 * @filter: a #MMFilter.
139 * Clears all the #MMFilterParam<!-- -->s from @filter.
142 void
143 mm_filter_clear (MMFilter *filter)
145 unref_all_fps (filter);
146 g_list_free (filter->details->filter_params);
147 filter->details->filter_params = NULL;
151 * mm_filter_get_filtering_params:
152 * @filter: a #MMFilter.
154 * Gets a #GList of all the #MMFilterParam<!-- -->s added to @filter.
156 * Return value: a #GList of #MMFilterParam objects. Use #g_list_free when done
157 * with the list.
160 GList *
161 mm_filter_get_filtering_params (MMFilter *filter)
163 return g_list_reverse (filter->details->filter_params);