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.
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)
37 #include <api/na-data-def.h>
38 #include <api/na-data-types.h>
39 #include <api/na-iio-provider.h>
40 #include <api/na-ifactory-provider.h>
41 #include <api/na-object-api.h>
42 #include <api/na-core-utils.h>
43 #include <api/na-gconf-utils.h>
45 #include "nagp-gconf-provider.h"
46 #include "nagp-writer.h"
47 #include "nagp-keys.h"
49 #ifndef NA_DISABLE_DEPRECATED
50 static void write_start_write_type( NagpGConfProvider
*provider
, NAObjectItem
*item
);
51 static void write_start_write_version( NagpGConfProvider
*provider
, NAObjectItem
*item
);
55 * API function: should only be called through NAIIOProvider interface
58 nagp_iio_provider_is_willing_to_write( const NAIIOProvider
*provider
)
60 #ifndef NA_DISABLE_DEPRECATED
68 * Rationale: gconf reads its storage path from /etc/gconf/2/path ;
69 * there is there a 'xml:readwrite:$(HOME)/.gconf' line, but I do not
70 * known any way to get it programatically, so an admin may have set a
71 * readwrite space elsewhere..
73 * So, we try to write a 'foo' key somewhere: if it is ok, then the
74 * provider is supposed able to write...
76 * API function: should only be called through NAIIOProvider interface
79 nagp_iio_provider_is_able_to_write( const NAIIOProvider
*provider
)
81 #ifndef NA_DISABLE_DEPRECATED
82 static const gchar
*thisfn
= "nagp_iio_provider_is_able_to_write";
83 static const gchar
*path
= "/apps/nautilus-actions/foo";
84 NagpGConfProvider
*self
;
85 gboolean able_to
= FALSE
;
87 /*g_debug( "%s: provider=%p", thisfn, ( void * ) provider );*/
88 g_return_val_if_fail( NAGP_IS_GCONF_PROVIDER( provider
), FALSE
);
89 g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider
), FALSE
);
91 self
= NAGP_GCONF_PROVIDER( provider
);
93 if( !self
->private->dispose_has_run
){
95 if( !na_gconf_utils_write_string( self
->private->gconf
, path
, "foo", NULL
)){
99 gchar
*str
= na_gconf_utils_read_string( self
->private->gconf
, path
, FALSE
, NULL
);
100 if( strcmp( str
, "foo" )){
103 } else if( !gconf_client_recursive_unset( self
->private->gconf
, path
, 0, NULL
)){
114 gconf_client_suggest_sync( self
->private->gconf
, NULL
);
116 g_debug( "%s: provider=%p, able_to=%s", thisfn
, ( void * ) provider
, able_to
? "True":"False" );
123 #ifndef NA_DISABLE_DEPRECATED
125 * update an existing item or write a new one
126 * in all cases, it is much more easy to delete the existing entries
127 * before trying to write the new ones
130 nagp_iio_provider_write_item( const NAIIOProvider
*provider
, const NAObjectItem
*item
, GSList
**messages
)
132 static const gchar
*thisfn
= "nagp_gconf_provider_iio_provider_write_item";
133 NagpGConfProvider
*self
;
136 g_debug( "%s: provider=%p (%s), item=%p (%s), messages=%p",
138 ( void * ) provider
, G_OBJECT_TYPE_NAME( provider
),
139 ( void * ) item
, G_OBJECT_TYPE_NAME( item
),
140 ( void * ) messages
);
142 ret
= NA_IIO_PROVIDER_CODE_PROGRAM_ERROR
;
144 g_return_val_if_fail( NAGP_IS_GCONF_PROVIDER( provider
), ret
);
145 g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider
), ret
);
146 g_return_val_if_fail( NA_IS_OBJECT_ITEM( item
), ret
);
148 self
= NAGP_GCONF_PROVIDER( provider
);
150 if( self
->private->dispose_has_run
){
151 return( NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN
);
154 ret
= nagp_iio_provider_delete_item( provider
, item
, messages
);
156 if( ret
== NA_IIO_PROVIDER_CODE_OK
){
157 na_ifactory_provider_write_item( NA_IFACTORY_PROVIDER( provider
), NULL
, NA_IFACTORY_OBJECT( item
), messages
);
160 gconf_client_suggest_sync( self
->private->gconf
, NULL
);
166 * also delete the schema which may be directly attached to this action
167 * cf. http://bugzilla.gnome.org/show_bug.cgi?id=325585
170 nagp_iio_provider_delete_item( const NAIIOProvider
*provider
, const NAObjectItem
*item
, GSList
**messages
)
172 static const gchar
*thisfn
= "nagp_gconf_provider_iio_provider_delete_item";
173 NagpGConfProvider
*self
;
176 GError
*error
= NULL
;
178 g_debug( "%s: provider=%p (%s), item=%p (%s), messages=%p",
180 ( void * ) provider
, G_OBJECT_TYPE_NAME( provider
),
181 ( void * ) item
, G_OBJECT_TYPE_NAME( item
),
182 ( void * ) messages
);
184 ret
= NA_IIO_PROVIDER_CODE_PROGRAM_ERROR
;
186 g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider
), ret
);
187 g_return_val_if_fail( NAGP_IS_GCONF_PROVIDER( provider
), ret
);
188 g_return_val_if_fail( NA_IS_OBJECT_ITEM( item
), ret
);
190 self
= NAGP_GCONF_PROVIDER( provider
);
192 if( self
->private->dispose_has_run
){
193 return( NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN
);
196 ret
= NA_IIO_PROVIDER_CODE_OK
;
197 uuid
= na_object_get_id( NA_OBJECT( item
));
199 /* GCONF_UNSET_INCLUDING_SCHEMA_NAMES seems mean: including the name
200 * of the schemas which is embedded in the GConfEntry - this doesn't
201 * mean including the schemas themselves
203 if( ret
== NA_IIO_PROVIDER_CODE_OK
){
204 path
= gconf_concat_dir_and_key( NAGP_CONFIGURATIONS_PATH
, uuid
);
205 gconf_client_recursive_unset( self
->private->gconf
, path
, GCONF_UNSET_INCLUDING_SCHEMA_NAMES
, &error
);
207 g_warning( "%s: path=%s, error=%s", thisfn
, path
, error
->message
);
208 *messages
= g_slist_append( *messages
, g_strdup( error
->message
));
209 g_error_free( error
);
211 ret
= NA_IIO_PROVIDER_CODE_DELETE_CONFIG_ERROR
;
213 gconf_client_suggest_sync( self
->private->gconf
, NULL
);
217 if( ret
== NA_IIO_PROVIDER_CODE_OK
){
218 path
= gconf_concat_dir_and_key( NAGP_SCHEMAS_PATH
, uuid
);
219 gconf_client_recursive_unset( self
->private->gconf
, path
, 0, &error
);
221 g_warning( "%s: path=%s, error=%s", thisfn
, path
, error
->message
);
222 *messages
= g_slist_append( *messages
, g_strdup( error
->message
));
223 g_error_free( error
);
225 ret
= NA_IIO_PROVIDER_CODE_DELETE_SCHEMAS_ERROR
;
228 gconf_client_suggest_sync( self
->private->gconf
, NULL
);
237 nagp_writer_write_start( const NAIFactoryProvider
*writer
, void *writer_data
,
238 const NAIFactoryObject
*object
, GSList
**messages
)
240 if( NA_IS_OBJECT_ITEM( object
)){
241 write_start_write_type( NAGP_GCONF_PROVIDER( writer
), NA_OBJECT_ITEM( object
));
242 write_start_write_version( NAGP_GCONF_PROVIDER( writer
), NA_OBJECT_ITEM( object
));
245 return( NA_IIO_PROVIDER_CODE_OK
);
249 write_start_write_type( NagpGConfProvider
*provider
, NAObjectItem
*item
)
253 id
= na_object_get_id( item
);
254 path
= g_strdup_printf( "%s/%s/%s", NAGP_CONFIGURATIONS_PATH
, id
, NAGP_ENTRY_TYPE
);
256 na_gconf_utils_write_string(
257 provider
->private->gconf
,
259 NA_IS_OBJECT_ACTION( item
) ? NAGP_VALUE_TYPE_ACTION
: NAGP_VALUE_TYPE_MENU
,
267 write_start_write_version( NagpGConfProvider
*provider
, NAObjectItem
*item
)
272 id
= na_object_get_id( item
);
273 path
= g_strdup_printf( "%s/%s/%s", NAGP_CONFIGURATIONS_PATH
, id
, NAGP_ENTRY_IVERSION
);
275 iversion
= na_object_get_iversion( item
);
276 na_gconf_utils_write_int( provider
->private->gconf
, path
, iversion
, NULL
);
283 nagp_writer_write_data( const NAIFactoryProvider
*provider
, void *writer_data
,
284 const NAIFactoryObject
*object
, const NADataBoxed
*boxed
,
287 static const gchar
*thisfn
= "nagp_writer_write_data";
289 const NADataDef
*def
;
291 gchar
*this_path
, *path
;
299 /*g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));*/
302 code
= NA_IIO_PROVIDER_CODE_OK
;
303 def
= na_data_boxed_get_data_def( boxed
);
305 if( !na_data_boxed_is_default( boxed
) || def
->write_if_default
){
307 if( NA_IS_OBJECT_PROFILE( object
)){
308 NAObjectItem
*parent
= NA_OBJECT_ITEM( na_object_get_parent( object
));
309 gchar
*parent_id
= na_object_get_id( parent
);
310 gchar
*id
= na_object_get_id( object
);
311 this_id
= g_strdup_printf( "%s/%s", parent_id
, id
);
316 this_id
= na_object_get_id( object
);
319 this_path
= gconf_concat_dir_and_key( NAGP_CONFIGURATIONS_PATH
, this_id
);
320 path
= gconf_concat_dir_and_key( this_path
, def
->gconf_entry
);
322 gconf
= NAGP_GCONF_PROVIDER( provider
)->private->gconf
;
326 case NA_DATA_TYPE_STRING
:
327 str_value
= na_boxed_get_string( NA_BOXED( boxed
));
328 na_gconf_utils_write_string( gconf
, path
, str_value
, &msg
);
330 *messages
= g_slist_append( *messages
, msg
);
331 code
= NA_IIO_PROVIDER_CODE_WRITE_ERROR
;
336 case NA_DATA_TYPE_LOCALE_STRING
:
337 str_value
= na_boxed_get_string( NA_BOXED( boxed
));
338 na_gconf_utils_write_string( gconf
, path
, str_value
, &msg
);
340 *messages
= g_slist_append( *messages
, msg
);
341 code
= NA_IIO_PROVIDER_CODE_WRITE_ERROR
;
346 case NA_DATA_TYPE_BOOLEAN
:
347 bool_value
= GPOINTER_TO_UINT( na_boxed_get_as_void( NA_BOXED( boxed
)));
348 na_gconf_utils_write_bool( gconf
, path
, bool_value
, &msg
);
350 *messages
= g_slist_append( *messages
, msg
);
351 code
= NA_IIO_PROVIDER_CODE_WRITE_ERROR
;
355 case NA_DATA_TYPE_STRING_LIST
:
356 slist_value
= ( GSList
* ) na_boxed_get_as_void( NA_BOXED( boxed
));
357 na_gconf_utils_write_string_list( gconf
, path
, slist_value
, &msg
);
359 *messages
= g_slist_append( *messages
, msg
);
360 code
= NA_IIO_PROVIDER_CODE_WRITE_ERROR
;
362 na_core_utils_slist_free( slist_value
);
365 case NA_DATA_TYPE_UINT
:
366 uint_value
= GPOINTER_TO_UINT( na_boxed_get_as_void( NA_BOXED( boxed
)));
367 na_gconf_utils_write_int( gconf
, path
, uint_value
, &msg
);
369 *messages
= g_slist_append( *messages
, msg
);
370 code
= NA_IIO_PROVIDER_CODE_WRITE_ERROR
;
375 g_warning( "%s: unknown type=%u for %s", thisfn
, def
->type
, def
->name
);
376 code
= NA_IIO_PROVIDER_CODE_PROGRAM_ERROR
;
379 /*g_debug( "%s: gconf=%p, code=%u, path=%s", thisfn, ( void * ) gconf, code, path );*/
391 nagp_writer_write_done( const NAIFactoryProvider
*writer
, void *writer_data
,
392 const NAIFactoryObject
*object
,
395 return( NA_IIO_PROVIDER_CODE_OK
);
397 #endif /* NA_DISABLE_DEPRECATED */