1 /*
2 * Nautilus-Actions
3 * A Nautilus extension which offers configurable context menu actions.
4 *
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009-2014 Pierre Wieser and others (see AUTHORS)
8 *
9 * Nautilus-Actions 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.
13 *
14 * Nautilus-Actions 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 GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Nautilus-Actions; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
22 *
23 * Authors:
24 * Frederic Ruaudel <grumz@grumz.net>
25 * Rodrigo Moya <rodrigo@gnome-db.org>
26 * Pierre Wieser <pwieser@trychlos.org>
27 * ... and many others (see AUTHORS)
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33
34 #include <string.h>
35
36 #include <api/na-ifactory-object.h>
37
38 #include "na-factory-object.h"
39
40 /* private interface data
41 */
42 struct _NAIFactoryObjectInterfacePrivate {
43 void *empty; /* so that gcc -pedantic is happy */
44 };
45
46 static guint st_initializations = 0; /* interface initialization count */
47
48 static GType register_type( void );
49 static void interface_base_init( NAIFactoryObjectInterface *klass );
50 static void interface_base_finalize( NAIFactoryObjectInterface *klass );
51
52 static guint ifactory_object_get_version( const NAIFactoryObject *instance );
53
54 /*
55 * Registers the GType of this interface.
56 */
57 GType
na_ifactory_object_get_type(void)58 na_ifactory_object_get_type( void )
59 {
60 static GType object_type = 0;
61
62 if( !object_type ){
63 object_type = register_type();
64 }
65
66 return( object_type );
67 }
68
69 static GType
register_type(void)70 register_type( void )
71 {
72 static const gchar *thisfn = "na_ifactory_object_register_type";
73 GType type;
74
75 static const GTypeInfo info = {
76 sizeof( NAIFactoryObjectInterface ),
77 ( GBaseInitFunc ) interface_base_init,
78 ( GBaseFinalizeFunc ) interface_base_finalize,
79 NULL,
80 NULL,
81 NULL,
82 0,
83 0,
84 NULL
85 };
86
87 g_debug( "%s", thisfn );
88
89 type = g_type_register_static( G_TYPE_INTERFACE, "NAIFactoryObject", &info, 0 );
90
91 g_type_interface_add_prerequisite( type, G_TYPE_OBJECT );
92
93 return( type );
94 }
95
96 static void
interface_base_init(NAIFactoryObjectInterface * klass)97 interface_base_init( NAIFactoryObjectInterface *klass )
98 {
99 static const gchar *thisfn = "na_ifactory_object_interface_base_init";
100
101 if( !st_initializations ){
102
103 g_debug( "%s: klass=%p (%s)", thisfn, ( void * ) klass, G_OBJECT_CLASS_NAME( klass ));
104
105 klass->private = g_new0( NAIFactoryObjectInterfacePrivate, 1 );
106
107 klass->get_version = ifactory_object_get_version;
108 klass->get_groups = NULL;
109 klass->copy = NULL;
110 klass->are_equal = NULL;
111 klass->is_valid = NULL;
112 klass->read_start = NULL;
113 klass->read_done = NULL;
114 klass->write_start = NULL;
115 klass->write_done = NULL;
116 }
117
118 st_initializations += 1;
119 }
120
121 static void
interface_base_finalize(NAIFactoryObjectInterface * klass)122 interface_base_finalize( NAIFactoryObjectInterface *klass )
123 {
124 static const gchar *thisfn = "na_ifactory_object_interface_base_finalize";
125
126 st_initializations -= 1;
127
128 if( !st_initializations ){
129
130 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
131
132 g_free( klass->private );
133 }
134 }
135
136 static guint
ifactory_object_get_version(const NAIFactoryObject * instance)137 ifactory_object_get_version( const NAIFactoryObject *instance )
138 {
139 return( 1 );
140 }
141
142 /**
143 * na_ifactory_object_get_data_boxed:
144 * @object: a #NAIFactoryObject object.
145 * @name: the name of the elementary data we are searching for.
146 *
147 * The returned #NADataBoxed is owned by #NAIFactoryObject @object, and
148 * should not be released by the caller.
149 *
150 * Returns: The #NADataBoxed object which contains the specified data,
151 * or %NULL.
152 *
153 * Since: 2.30
154 */
155 NADataBoxed *
na_ifactory_object_get_data_boxed(const NAIFactoryObject * object,const gchar * name)156 na_ifactory_object_get_data_boxed( const NAIFactoryObject *object, const gchar *name )
157 {
158 GList *list, *ip;
159
160 g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
161
162 list = g_object_get_data( G_OBJECT( object ), NA_IFACTORY_OBJECT_PROP_DATA );
163 /*g_debug( "list=%p (count=%u)", ( void * ) list, g_list_length( list ));*/
164
165 for( ip = list ; ip ; ip = ip->next ){
166 NADataBoxed *boxed = NA_DATA_BOXED( ip->data );
167 const NADataDef *def = na_data_boxed_get_data_def( boxed );
168
169 if( !strcmp( def->name, name )){
170 return( boxed );
171 }
172 }
173
174 return( NULL );
175 }
176
177 /**
178 * na_ifactory_object_get_data_groups:
179 * @object: a #NAIFactoryObject object.
180 *
181 * The returned #NADataGroup is owned by the #NAIFactoryObject @object,
182 * and should not be released by the caller.
183 *
184 * Returns: The #NADataGroup groups definition, or %NULL.
185 *
186 * Since: 2.30
187 */
188 NADataGroup *
na_ifactory_object_get_data_groups(const NAIFactoryObject * object)189 na_ifactory_object_get_data_groups( const NAIFactoryObject *object )
190 {
191 NADataGroup *groups;
192
193 g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
194
195 groups = NULL;
196
197 if( NA_IFACTORY_OBJECT_GET_INTERFACE( object )->get_groups ){
198 groups = NA_IFACTORY_OBJECT_GET_INTERFACE( object )->get_groups( object );
199 }
200
201 return( groups );
202 }
203
204 /**
205 * na_ifactory_object_get_as_void:
206 * @object: this #NAIFactoryObject instance.
207 * @name: the elementary data whose value is to be got.
208 *
209 * If the type of the value is %NA_DATA_TYPE_STRING, %NA_DATA_TYPE_LOCALE_STRING,
210 * or %NA_DATA_TYPE_STRING_LIST, then the returned value is a newly allocated
211 * one and should be g_free() (resp. na_core_utils_slist_free()) by the
212 * caller.
213 *
214 * Returns: the searched value.
215 *
216 * Since: 2.30
217 */
218 void *
na_ifactory_object_get_as_void(const NAIFactoryObject * object,const gchar * name)219 na_ifactory_object_get_as_void( const NAIFactoryObject *object, const gchar *name )
220 {
221 g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
222
223 return( na_factory_object_get_as_void( object, name ));
224 }
225
226 /**
227 * na_ifactory_object_set_from_void:
228 * @object: this #NAIFactoryObject instance.
229 * @name: the name of the elementary data whose value is to be set.
230 * @data: the value to set.
231 *
232 * Set the elementary data with the given value.
233 *
234 * Since: 2.30
235 */
236 void
na_ifactory_object_set_from_void(NAIFactoryObject * object,const gchar * name,const void * data)237 na_ifactory_object_set_from_void( NAIFactoryObject *object, const gchar *name, const void *data )
238 {
239 g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));
240
241 na_factory_object_set_from_void( object, name, data );
242 }
243