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 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)
36 #include <api/na-gconf-utils.h>
38 #include <core/na-iprefs.h>
40 #include "nact-application.h"
41 #include "nact-iprefs.h"
43 /* private interface data
45 struct NactIPrefsInterfacePrivate
{
49 static gboolean st_initialized
= FALSE
;
50 static gboolean st_finalized
= FALSE
;
52 static GType
register_type( void );
53 static void interface_base_init( NactIPrefsInterface
*klass
);
54 static void interface_base_finalize( NactIPrefsInterface
*klass
);
56 static GConfValue
*get_value( GConfClient
*client
, const gchar
*path
, const gchar
*entry
);
57 static void set_value( GConfClient
*client
, const gchar
*path
, const gchar
*entry
, GConfValue
*value
);
60 nact_iprefs_get_type( void )
62 static GType iface_type
= 0;
65 iface_type
= register_type();
74 static const gchar
*thisfn
= "nact_iprefs_register_type";
77 static const GTypeInfo info
= {
78 sizeof( NactIPrefsInterface
),
79 ( GBaseInitFunc
) interface_base_init
,
80 ( GBaseFinalizeFunc
) interface_base_finalize
,
89 g_debug( "%s", thisfn
);
91 type
= g_type_register_static( G_TYPE_INTERFACE
, "NactIPrefs", &info
, 0 );
93 g_type_interface_add_prerequisite( type
, G_TYPE_OBJECT
);
99 interface_base_init( NactIPrefsInterface
*klass
)
101 static const gchar
*thisfn
= "nact_iprefs_interface_base_init";
103 if( !st_initialized
){
105 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
107 klass
->private = g_new0( NactIPrefsInterfacePrivate
, 1 );
109 klass
->private->client
= gconf_client_get_default();
111 st_initialized
= TRUE
;
116 interface_base_finalize( NactIPrefsInterface
*klass
)
118 static const gchar
*thisfn
= "nact_iprefs_interface_base_finalize";
120 if( st_initialized
&& !st_finalized
){
122 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
126 g_object_unref( klass
->private->client
);
128 g_free( klass
->private );
133 * nact_iprefs_get_export_format:
134 * @window: this #BaseWindow-derived window.
135 * @name: name of the export format key to be readen
137 * Returns: the export format currently set as a #GQuark.
139 * Defaults to exporting as a GConfEntry (see. #nact-iprefs.h)
141 * Note: please take care of keeping the default value synchronized with
142 * those defined in schemas.
145 nact_iprefs_get_export_format( const BaseWindow
*window
, const gchar
*name
)
147 GQuark export_format
;
148 NactApplication
*application
;
152 export_format
= g_quark_from_static_string( IPREFS_EXPORT_FORMAT_DEFAULT
);
154 g_return_val_if_fail( BASE_IS_WINDOW( window
), export_format
);
156 if( st_initialized
&& !st_finalized
){
158 application
= NACT_APPLICATION( base_window_get_application( window
));
159 updater
= nact_application_get_updater( application
);
161 format_str
= na_iprefs_read_string(
162 NA_IPREFS( updater
),
164 IPREFS_EXPORT_FORMAT_DEFAULT
);
166 export_format
= g_quark_from_string( format_str
);
168 g_free( format_str
);
171 return( export_format
);
175 * nact_iprefs_set_export_format:
176 * @window: this #BaseWindow-derived window.
177 * @format: the new value to be written.
179 * Writes the preferred export format' to the GConf preference system.
182 nact_iprefs_set_export_format( const BaseWindow
*window
, const gchar
*name
, GQuark format
)
184 g_return_if_fail( BASE_IS_WINDOW( window
));
186 if( st_initialized
&& !st_finalized
){
188 nact_iprefs_write_string(
191 g_quark_to_string( format
));
196 * nact_iprefs_migrate_key:
197 * @window: a #BaseWindow window.
198 * @old_key: the old preference entry.
199 * @new_key: the new preference entry.
201 * Migrates the content of an entry from an obsoleted key to a new one.
202 * Removes the old key, along with the schema associated to it,
203 * considering that the version which asks for this migration has
204 * installed a schema corresponding to the new key.
207 nact_iprefs_migrate_key( const BaseWindow
*window
, const gchar
*old_key
, const gchar
*new_key
)
209 static const gchar
*thisfn
= "nact_iprefs_migrate_key";
210 GConfClient
*gconf_client
;
213 g_debug( "%s: window=%p, old_key=%s, new_key=%s", thisfn
, ( void * ) window
, old_key
, new_key
);
214 g_return_if_fail( BASE_IS_WINDOW( window
));
216 if( st_initialized
&& !st_finalized
){
218 gconf_client
= NACT_IPREFS_GET_INTERFACE( window
)->private->client
;
220 value
= get_value( gconf_client
, IPREFS_GCONF_PREFS_PATH
, new_key
);
222 value
= get_value( gconf_client
, IPREFS_GCONF_PREFS_PATH
, old_key
);
224 set_value( gconf_client
, IPREFS_GCONF_PREFS_PATH
, new_key
, value
);
225 gconf_value_free( value
);
229 /* do not remove entries which may still be used by an older N-A version
235 * nact_iprefs_write_bool:
236 * @window: this #BaseWindow-derived window.
237 * @name: the preference entry.
238 * @value: the value to be written.
240 * Writes the given boolean value.
243 nact_iprefs_write_bool( const BaseWindow
*window
, const gchar
*name
, gboolean value
)
247 g_return_if_fail( BASE_IS_WINDOW( window
));
248 g_return_if_fail( NACT_IS_IPREFS( window
));
250 if( st_initialized
&& !st_finalized
){
252 path
= gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH
, name
);
253 na_gconf_utils_write_bool( NACT_IPREFS_GET_INTERFACE( window
)->private->client
, path
, value
, NULL
);
259 * nact_iprefs_write_string:
260 * @window: this #BaseWindow-derived window.
261 * @name: the preference key.
262 * @value: the value to be written.
264 * Writes the value as the given GConf preference.
267 nact_iprefs_write_string( const BaseWindow
*window
, const gchar
*name
, const gchar
*value
)
271 g_return_if_fail( BASE_IS_WINDOW( window
));
272 g_return_if_fail( NACT_IS_IPREFS( window
));
274 if( st_initialized
&& !st_finalized
){
276 path
= gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH
, name
);
278 na_gconf_utils_write_string( NACT_IPREFS_GET_INTERFACE( window
)->private->client
, path
, value
, NULL
);
285 get_value( GConfClient
*client
, const gchar
*path
, const gchar
*entry
)
287 static const gchar
*thisfn
= "na_iprefs_get_value";
288 GError
*error
= NULL
;
292 fullpath
= gconf_concat_dir_and_key( path
, entry
);
294 value
= gconf_client_get_without_default( client
, fullpath
, &error
);
297 g_warning( "%s: key=%s, %s", thisfn
, fullpath
, error
->message
);
298 g_error_free( error
);
300 gconf_value_free( value
);
311 set_value( GConfClient
*client
, const gchar
*path
, const gchar
*entry
, GConfValue
*value
)
313 static const gchar
*thisfn
= "na_iprefs_set_value";
314 GError
*error
= NULL
;
317 g_return_if_fail( value
);
319 fullpath
= gconf_concat_dir_and_key( path
, entry
);
321 gconf_client_set( client
, fullpath
, value
, &error
);
324 g_warning( "%s: key=%s, %s", thisfn
, fullpath
, error
->message
);
325 g_error_free( error
);