Add doc files to dist and fix version number in NEWS.
[mmediamanager.git] / libmmanager / mm-category.c
blob95399d0c86e808536e1e1ab6207bbf597500005e
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-object.h>
22 #include <glib.h>
24 #include "mm-category.h"
25 #include "mm-hit-collection-provider.h"
26 #include "mm-manager.h"
27 #include "mm-filter.h"
30 #define MM_CATEGORY_GET_PRIVATE(o) \
31 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_CATEGORY, MMCategoryPrivate))
33 G_DEFINE_TYPE (MMCategory, mm_category, G_TYPE_OBJECT);
35 struct _MMCategoryPrivate {
36 char *name;
37 GIcon *icon;
38 MMApplication *application;
41 static void
42 mm_category_finalize (GObject *o)
44 MMCategoryPrivate *details = MM_CATEGORY (o)->details;
46 g_free (details->name);
48 if (details->icon) {
49 g_object_unref (details->icon);
51 if (details->application) {
52 g_object_unref (details->application);
55 G_OBJECT_CLASS (mm_category_parent_class)->finalize (o);
58 static void
59 mm_category_class_init (MMCategoryClass *klass)
61 G_OBJECT_CLASS (klass)->finalize = mm_category_finalize;
63 g_type_class_add_private (klass, sizeof (MMCategoryPrivate));
66 static void
67 mm_category_init (MMCategory *c)
69 MMCategoryPrivate *details = c->details = MM_CATEGORY_GET_PRIVATE (c);
71 details->name = NULL;
72 details->icon = NULL;
73 details->application = NULL;
76 /* public methods */
78 /**
79 * mm_category_set_attributes:
80 * @category: a #MMCategory.
81 * @app: a #MMApplication.
82 * @name: a string containing the name for the category.
83 * @icon: a #GIcon containing the icon for the category.
85 * Sets all the specified properties and attributes to @category. This is useful
86 * only for #MMCategory implementations.
89 void
90 mm_category_set_attributes (MMCategory *category,
91 MMApplication *app,
92 const char *name,
93 GIcon *icon)
95 MMCategoryPrivate *details = category->details;
97 details->name = g_strdup (name);
98 details->application = g_object_ref (app);
99 if (icon) {
100 details->icon = g_object_ref (icon);
105 * mm_category_get_icon:
106 * @category: a #MMCategory.
108 * Gets the category's icon.
110 * Return value: a #GIcon containing the icon of the category or %NULL. Unref it
111 * when done.
114 GIcon *
115 mm_category_get_icon (MMCategory *category)
117 g_return_val_if_fail (category != NULL, NULL);
118 g_return_val_if_fail (MM_IS_CATEGORY (category), NULL);
120 return category->details->icon ? g_object_ref (category->details->icon) : NULL;
124 * mm_category_get_name:
125 * @category: a #MMCategory.
127 * Gets the name of the category.
129 * Return value: a string containing the name of the category.
132 const char *
133 mm_category_get_name (MMCategory *category)
135 g_return_val_if_fail (category != NULL, NULL);
136 g_return_val_if_fail (MM_IS_CATEGORY (category), NULL);
138 return category->details->name;
142 * mm_category_get_hits:
143 * @category: a #MMCategory.
144 * @filter: a #MMFilter.
145 * @error: a #GError.
147 * Gets a #MMHitCollection of all the hits contained in @category and satisfying the
148 * requirements of @filter.
150 * Return value: a #MMHitCollection or %NULL (in this case, the #GError is set).
153 MMHitCollection *
154 mm_category_get_hits (MMCategory *category,
155 MMFilter *filter,
156 GError **error)
158 g_return_val_if_fail (category != NULL, NULL);
159 g_return_val_if_fail (filter != NULL, NULL);
160 g_return_val_if_fail (MM_IS_CATEGORY (category), NULL);
161 g_return_val_if_fail (MM_IS_FILTER (filter), NULL);
163 /* return NULL if we can't find the method in the subclass */
164 return (MM_CATEGORY_CLASS (G_OBJECT_GET_CLASS (category))->get_hits == NULL) ?
165 NULL : ((* MM_CATEGORY_CLASS (G_OBJECT_GET_CLASS (category))->get_hits)
166 (category, filter, error));
170 * mm_category_get_application:
171 * @category: a #MMCategory.
173 * Gets the #MMApplication to which @category belong.
175 * Return value: a #MMApplication. Unref it when done.
178 MMApplication *
179 mm_category_get_application (MMCategory *category)
181 g_return_val_if_fail (category != NULL, NULL);
182 g_return_val_if_fail (MM_IS_CATEGORY (category), NULL);
184 return g_object_ref (category->details->application);