Define new 'pivot-prop-loadable' property
[nautilus-actions.git] / src / core / na-ifactory-object.c
blob791091f590dfc24e85bc945eb966be17e882ca23
1 /*
2 * Nautilus-Actions
3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
24 * Authors:
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
35 #include <string.h>
37 #include <api/na-ifactory-object.h>
39 #include "na-factory-object.h"
41 /* private interface data
43 struct _NAIFactoryObjectInterfacePrivate {
44 void *empty; /* so that gcc -pedantic is happy */
47 gboolean ifactory_object_initialized = FALSE;
48 gboolean ifactory_object_finalized = FALSE;
50 static GType register_type( void );
51 static void interface_base_init( NAIFactoryObjectInterface *klass );
52 static void interface_base_finalize( NAIFactoryObjectInterface *klass );
54 static guint ifactory_object_get_version( const NAIFactoryObject *instance );
57 * Registers the GType of this interface.
59 GType
60 na_ifactory_object_get_type( void )
62 static GType object_type = 0;
64 if( !object_type ){
65 object_type = register_type();
68 return( object_type );
71 static GType
72 register_type( void )
74 static const gchar *thisfn = "na_ifactory_object_register_type";
75 GType type;
77 static const GTypeInfo info = {
78 sizeof( NAIFactoryObjectInterface ),
79 ( GBaseInitFunc ) interface_base_init,
80 ( GBaseFinalizeFunc ) interface_base_finalize,
81 NULL,
82 NULL,
83 NULL,
86 NULL
89 g_debug( "%s", thisfn );
91 type = g_type_register_static( G_TYPE_INTERFACE, "NAIFactoryObject", &info, 0 );
93 g_type_interface_add_prerequisite( type, G_TYPE_OBJECT );
95 return( type );
98 static void
99 interface_base_init( NAIFactoryObjectInterface *klass )
101 static const gchar *thisfn = "na_ifactory_object_interface_base_init";
103 if( !ifactory_object_initialized ){
105 g_debug( "%s: klass=%p (%s)", thisfn, ( void * ) klass, G_OBJECT_CLASS_NAME( klass ));
107 klass->private = g_new0( NAIFactoryObjectInterfacePrivate, 1 );
109 klass->get_version = ifactory_object_get_version;
110 klass->get_groups = NULL;
111 klass->copy = NULL;
112 klass->are_equal = NULL;
113 klass->is_valid = NULL;
114 klass->read_start = NULL;
115 klass->read_done = NULL;
116 klass->write_start = NULL;
117 klass->write_done = NULL;
119 ifactory_object_initialized = TRUE;
123 static void
124 interface_base_finalize( NAIFactoryObjectInterface *klass )
126 static const gchar *thisfn = "na_ifactory_object_interface_base_finalize";
128 if( ifactory_object_initialized && !ifactory_object_finalized ){
130 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
132 ifactory_object_finalized = TRUE;
134 g_free( klass->private );
138 static guint
139 ifactory_object_get_version( const NAIFactoryObject *instance )
141 return( 1 );
145 * na_ifactory_object_get_data_boxed:
146 * @object: a #NAIFactoryObject object.
147 * @name: the name of the elementary data we are searching for.
149 * The returned #NADataBoxed is owned by #NAIFactoryObject @object, and
150 * should not be released by the caller.
152 * Returns: The #NADataBoxed object which contains the specified data,
153 * or %NULL.
155 * Since: 2.30
157 NADataBoxed *
158 na_ifactory_object_get_data_boxed( const NAIFactoryObject *object, const gchar *name )
160 GList *list, *ip;
162 g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
164 if( ifactory_object_initialized && !ifactory_object_finalized ){
166 list = g_object_get_data( G_OBJECT( object ), NA_IFACTORY_OBJECT_PROP_DATA );
167 /*g_debug( "list=%p (count=%u)", ( void * ) list, g_list_length( list ));*/
169 for( ip = list ; ip ; ip = ip->next ){
170 NADataBoxed *boxed = NA_DATA_BOXED( ip->data );
171 const NADataDef *def = na_data_boxed_get_data_def( boxed );
173 if( !strcmp( def->name, name )){
174 return( boxed );
179 return( NULL );
183 * na_ifactory_object_get_data_groups:
184 * @object: a #NAIFactoryObject object.
186 * The returned #NADataGroup is owned by the #NAIFactoryObject @object,
187 * and should not be released by the caller.
189 * Returns: The #NADataGroup groups definition, or %NULL.
191 * Since: 2.30
193 NADataGroup *
194 na_ifactory_object_get_data_groups( const NAIFactoryObject *object )
196 NADataGroup *groups;
198 g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
200 groups = NULL;
202 if( ifactory_object_initialized && !ifactory_object_finalized ){
204 if( NA_IFACTORY_OBJECT_GET_INTERFACE( object )->get_groups ){
205 groups = NA_IFACTORY_OBJECT_GET_INTERFACE( object )->get_groups( object );
209 return( groups );
213 * na_ifactory_object_get_as_void:
214 * @object: this #NAIFactoryObject instance.
215 * @name: the elementary data whose value is to be got.
217 * If the type of the value is %NA_DATA_TYPE_STRING, %NA_DATA_TYPE_LOCALE_STRING,
218 * or %NA_DATA_TYPE_STRING_LIST, then the returned value is a newly allocated
219 * one and should be g_free() (resp. na_core_utils_slist_free()) by the
220 * caller.
222 * Returns: the searched value.
224 * Since: 2.30
226 void *
227 na_ifactory_object_get_as_void( const NAIFactoryObject *object, const gchar *name )
229 g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
231 return( na_factory_object_get_as_void( object, name ));
235 * na_ifactory_object_set_from_void:
236 * @object: this #NAIFactoryObject instance.
237 * @name: the name of the elementary data whose value is to be set.
238 * @data: the value to set.
240 * Set the elementary data with the given value.
242 * Since: 2.30
244 void
245 na_ifactory_object_set_from_void( NAIFactoryObject *object, const gchar *name, const void *data )
247 g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));
249 na_factory_object_set_from_void( object, name, data );