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>
25 #include "mm-attribute.h"
27 #define MM_HIT_GET_PRIVATE(o) \
28 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_HIT, MMHitDetails))
30 G_DEFINE_TYPE (MMHit
, mm_hit
, G_TYPE_OBJECT
);
32 struct _MMHitDetails
{
33 GHashTable
*attributes
;
42 mm_hit_finalize (GObject
*o
)
44 MMHitDetails
*details
= MM_HIT (o
)->details
;
46 g_hash_table_destroy (details
->attributes
);
48 G_OBJECT_CLASS (mm_hit_parent_class
)->finalize (o
);
52 pair_free (gpointer data
)
54 g_slice_free (AttributeValuePair
, data
);
58 mm_hit_init (MMHit
*h
)
60 MMHitDetails
*details
= h
->details
= MM_HIT_GET_PRIVATE (h
);
62 details
->attributes
= g_hash_table_new_full (g_str_hash
, g_str_equal
, NULL
, pair_free
);
66 mm_hit_class_init (MMHitClass
*klass
)
68 GObjectClass
*oclass
= G_OBJECT_CLASS (klass
);
70 oclass
->finalize
= mm_hit_finalize
;
72 g_type_class_add_private (klass
, sizeof (MMHitDetails
));
78 mm_hit_set_value (MMHit
*h
,
79 MMAttribute
*attribute
,
82 const char *attribute_id
;
83 AttributeValuePair
*pair
;
85 g_return_if_fail (MM_IS_HIT (h
));
87 if (G_VALUE_TYPE (value
) != mm_attribute_get_value_type (attribute
)) {
88 g_warning ("Setting the wrong value type for attribute %s",
89 mm_attribute_get_name (attribute
));
93 pair
= g_slice_new0 (AttributeValuePair
);
94 pair
->attr
= attribute
;
97 attribute_id
= mm_attribute_get_id (attribute
);
98 g_hash_table_insert (h
->details
->attributes
,
99 (char *) attribute_id
,
104 mm_hit_set_values (MMHit
*hit
,
110 g_return_if_fail (MM_IS_HIT (hit
));
111 g_return_if_fail (g_list_length (attributes
) == g_list_length (values
));
113 for (l
= attributes
, m
= values
; l
&& m
; l
= l
->next
, m
= m
->next
) {
114 mm_hit_set_value (hit
, l
->data
, m
->data
);
119 mm_hit_get_values (MMHit
*hit
,
123 gchar
**splitted_ids
;
125 AttributeValuePair
*pair
;
127 g_return_val_if_fail (MM_IS_HIT (hit
), NULL
);
128 table
= g_hash_table_new (g_direct_hash
, g_direct_equal
);
130 splitted_ids
= g_strsplit (ids
, " ", 0);
131 for (idx
= 0; idx
< G_N_ELEMENTS (splitted_ids
); idx
++) {
132 pair
= g_hash_table_lookup (hit
->details
->attributes
,
134 g_hash_table_insert (table
, pair
->attr
, pair
->val
);
141 build_all_table_foreach (gpointer k
,
145 GHashTable
*table
= ud
;
146 AttributeValuePair
*pair
= v
;
148 g_hash_table_insert (table
, pair
->attr
, pair
->val
);
152 mm_hit_get_all_values (MMHit
*hit
)
156 g_return_val_if_fail (MM_IS_HIT (hit
), NULL
);
158 table
= g_hash_table_new (g_direct_hash
, g_direct_equal
);
160 g_hash_table_foreach (hit
->details
->attributes
,
161 build_all_table_foreach
,