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.
22 #include <glib-object.h>
23 #include <glib/gi18n.h>
25 #include "mm-attribute-manager.h"
26 #include "mm-attribute-base-manager.h"
27 #include "mm-base-attributes.h"
29 static MMAttributeManager
*base_manager
= NULL
;
30 static GHashTable
*cached_attrs
= NULL
;
32 static void mm_attribute_manager_iface_init (MMAttributeManagerIface
*iface
);
34 G_DEFINE_TYPE_WITH_CODE (MMAttributeBaseManager
, mm_attribute_base_manager
,
36 G_IMPLEMENT_INTERFACE (MM_TYPE_ATTRIBUTE_MANAGER
,
37 mm_attribute_manager_iface_init
));
40 static const char * attribute_ids
[] = {
41 MM_ATTRIBUTE_BASE_URI
,
42 MM_ATTRIBUTE_BASE_NAME
45 static const GType attribute_types
[] = {
50 static const char * attribute_names
[] = {
55 static const char * attribute_descriptions
[] = {
56 N_("URI of the resource"),
57 N_("Name of the resource")
60 /* MMAttributeManager interface implementation */
63 impl_lookup_attribute (MMAttributeManager
*m
,
67 gboolean found
= FALSE
;
70 for (idx
= 0; idx
< G_N_ELEMENTS (attribute_ids
); idx
++) {
71 if (g_strcmp0 (attribute_ids
[idx
], id
) == 0) {
78 attr
= g_hash_table_lookup (cached_attrs
,
81 attr
= mm_attribute_new (attribute_types
[idx
],
84 attribute_descriptions
[idx
]);
85 g_hash_table_insert (cached_attrs
, (char *) attribute_ids
[idx
],
95 impl_get_supported_attributes (MMAttributeManager
*m
)
97 GList
*attributes
= NULL
;
101 for (idx
= 0; idx
< G_N_ELEMENTS (attribute_ids
); idx
++) {
102 attr
= g_hash_table_lookup (cached_attrs
,
105 attr
= mm_attribute_new (attribute_types
[idx
],
107 attribute_names
[idx
],
108 attribute_descriptions
[idx
]);
109 g_hash_table_insert (cached_attrs
, (char *) attribute_ids
[idx
],
112 attributes
= g_list_prepend (attributes
, attr
);
115 return g_list_reverse (attributes
);
119 mm_attribute_manager_iface_init (MMAttributeManagerIface
*iface
)
121 iface
->lookup_attribute
= impl_lookup_attribute
;
122 iface
->get_supported_attributes
= impl_get_supported_attributes
;
126 mm_attribute_base_manager_finalize (GObject
*o
)
128 g_hash_table_destroy (cached_attrs
);
130 G_OBJECT_CLASS (mm_attribute_base_manager_parent_class
)->finalize (o
);
134 mm_attribute_base_manager_init (MMAttributeBaseManager
*abm
)
137 cached_attrs
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
138 NULL
, (GDestroyNotify
) mm_attribute_free
);
143 mm_attribute_base_manager_class_init (MMAttributeBaseManagerClass
*klass
)
145 G_OBJECT_CLASS (klass
)->finalize
= mm_attribute_base_manager_finalize
;
151 * mm_attribute_base_manager_get:
153 * Gets the #MMAttributeManager in charge of managing all the basic attributes,
154 * like "name" or "URI". The attributes managed by this manager belong to the
155 * "base" namespace and will have a "base::foo" id.
157 * Return value: a #MMAttributeManager. This is owned by the library and you
158 * should not modify or unref it.
162 mm_attribute_base_manager_get (void)
165 base_manager
= MM_ATTRIBUTE_MANAGER (g_object_new (MM_TYPE_ATTRIBUTE_BASE_MANAGER
, NULL
));