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-gtk-attribute-store.h"
23 #include "libmmanager/mm-attribute-manager.h"
24 #include "libmmanager/mm-attribute.h"
28 #include <glib-object.h>
30 /* our parent's model iface */
31 static GtkTreeModelIface parent_iface
= { 0, };
32 static void mm_gtk_attribute_store_tree_model_iface_init (GtkTreeModelIface
*iface
);
34 G_DEFINE_TYPE_EXTENDED (MMGtkAttributeStore
, mm_gtk_attribute_store
,
35 GTK_TYPE_LIST_STORE
, 0,
36 G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL
,
37 mm_gtk_attribute_store_tree_model_iface_init
));
40 mm_gtk_attribute_store_class_init (MMGtkAttributeStoreClass
*klass
)
46 mm_gtk_attribute_store_init (MMGtkAttributeStore
*self
)
48 GType types
[] = { G_TYPE_POINTER
};
50 gtk_list_store_set_column_types (GTK_LIST_STORE (self
), 1,
54 /* interface methods implementations */
57 impl_get_column_type (GtkTreeModel
*self
,
68 g_return_val_if_fail (MM_GTK_IS_ATTRIBUTE_STORE (self
), G_TYPE_INVALID
);
69 g_return_val_if_fail (column
>= 0 && column
< MM_GTK_ATTR_STORE_N_COL
, G_TYPE_INVALID
);
75 get_attribute_from_store (GtkTreeModel
*self
, GtkTreeIter
*iter
)
80 /* validate our parameters */
81 g_return_val_if_fail (MM_GTK_IS_ATTRIBUTE_STORE (self
), NULL
);
82 g_return_val_if_fail (iter
!= NULL
, NULL
);
84 /* retreive the object using our parent's interface */
85 parent_iface
.get_value (self
, iter
, MM_GTK_ATTR_STORE_ATTR_COL
, &val
);
87 attr
= (MMAttribute
*) g_value_get_pointer (&val
);
94 impl_get_value (GtkTreeModel
*self
, GtkTreeIter
*iter
,
95 gint column
, GValue
*value
)
99 value
= g_value_init (value
, impl_get_column_type (self
, column
));
100 attr
= get_attribute_from_store (self
, iter
);
103 case MM_GTK_ATTR_STORE_ATTR_COL
:
104 /* return the attr itself */
105 g_value_set_pointer (value
, attr
);
107 case MM_GTK_ATTR_STORE_ID_COL
:
108 g_value_set_string (value
, mm_attribute_get_id (attr
));
110 case MM_GTK_ATTR_STORE_NAME_COL
:
111 g_value_set_string (value
, mm_attribute_get_name (attr
));
113 case MM_GTK_ATTR_STORE_DESC_COL
:
114 g_value_set_string (value
, mm_attribute_get_description (attr
));
116 case MM_GTK_ATTR_STORE_GTYPE_COL
:
117 g_value_set_gtype (value
, mm_attribute_get_value_type (attr
));
120 g_assert_not_reached ();
126 impl_get_n_columns (GtkTreeModel
*self
)
128 g_return_val_if_fail (MM_GTK_IS_ATTRIBUTE_STORE (self
), 0);
130 return MM_GTK_ATTR_STORE_N_COL
;
134 mm_gtk_attribute_store_tree_model_iface_init (GtkTreeModelIface
*iface
)
136 /* save a copy of our parent's iface */
137 parent_iface
= *iface
;
139 /* override the iface methods */
140 iface
->get_n_columns
= impl_get_n_columns
;
141 iface
->get_column_type
= impl_get_column_type
;
142 iface
->get_value
= impl_get_value
;
148 * mm_gtk_attribute_store_new:
150 * Builds an empty #GtkListStore, which will allow to store #MMAttributes
151 * in a #GtkTreeModel fashion.
153 * Return value: an empty #MMGtkAttributeStore.
157 mm_gtk_attribute_store_new (void)
159 return g_object_new (MM_GTK_TYPE_ATTRIBUTE_STORE
, NULL
);
163 * mm_gtk_attribute_store_add_attribute:
164 * @self: a #MMGtkAttributeStore.
165 * @attr: a #MMAttriubte.
167 * Adds @attr to the model pointed by @self. This isn't very useful for
168 * clients, you might want to use
169 * #mm_gtk_attribute_store_set_from_attribute_manager instead.
173 mm_gtk_attribute_store_add_attribute (MMGtkAttributeStore
*self
,
178 g_return_if_fail (MM_GTK_IS_ATTRIBUTE_STORE (self
));
180 gtk_list_store_append (GTK_LIST_STORE (self
), &iter
);
181 gtk_list_store_set (GTK_LIST_STORE (self
), &iter
,
182 MM_GTK_ATTR_STORE_ATTR_COL
, attr
, -1);
186 * mm_gtk_attribute_store_set_from_attribute_manager:
187 * @self: a #MMGtkAttributeStore.
188 * @attr_manager: a #MMAttributeManager.
190 * Encapsulates all the attributes supported by @attr_manager into the
191 * #GtkTreeModel implemented by @self.
195 mm_gtk_attribute_store_set_from_attribute_manager (MMGtkAttributeStore
*self
,
196 MMAttributeManager
*attr_manager
)
200 g_return_if_fail (MM_GTK_IS_ATTRIBUTE_STORE (self
));
201 g_return_if_fail (MM_IS_ATTRIBUTE_MANAGER (attr_manager
));
203 gtk_list_store_clear (GTK_LIST_STORE (self
));
205 attrs
= mm_attribute_manager_get_supported_attributes (attr_manager
);
206 for (l
= attrs
; l
; l
= l
->next
) {
207 mm_gtk_attribute_store_add_attribute (self
, l
->data
);