Change help menu item from Gtk default to Gnome (apparent) standard
[nautilus-actions.git] / src / nact / nact-iprefs.c
blob92a69e804af6f2d1a0fd28ab3f7ee8c097776108
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 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)
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
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 {
46 GConfClient *client;
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 );
59 GType
60 nact_iprefs_get_type( void )
62 static GType iface_type = 0;
64 if( !iface_type ){
65 iface_type = register_type();
68 return( iface_type );
71 static GType
72 register_type( void )
74 static const gchar *thisfn = "nact_iprefs_register_type";
75 GType type;
77 static const GTypeInfo info = {
78 sizeof( NactIPrefsInterface ),
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, "NactIPrefs", &info, 0 );
93 g_type_interface_add_prerequisite( type, G_TYPE_OBJECT );
95 return( type );
98 static void
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;
115 static void
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 );
124 st_finalized = TRUE;
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.
144 GQuark
145 nact_iprefs_get_export_format( const BaseWindow *window, const gchar *name )
147 GQuark export_format;
148 NactApplication *application;
149 NAUpdater *updater;
150 gchar *format_str;
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 ),
163 name,
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.
181 void
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(
189 window,
190 name,
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.
206 void
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;
211 GConfValue *value;
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 );
221 if( !value ){
222 value = get_value( gconf_client, IPREFS_GCONF_PREFS_PATH, old_key );
223 if( value ){
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.
242 void
243 nact_iprefs_write_bool( const BaseWindow *window, const gchar *name, gboolean value )
245 gchar *path;
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 );
254 g_free( path );
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.
266 void
267 nact_iprefs_write_string( const BaseWindow *window, const gchar *name, const gchar *value )
269 gchar *path;
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 );
280 g_free( path );
284 static GConfValue *
285 get_value( GConfClient *client, const gchar *path, const gchar *entry )
287 static const gchar *thisfn = "na_iprefs_get_value";
288 GError *error = NULL;
289 gchar *fullpath;
290 GConfValue *value;
292 fullpath = gconf_concat_dir_and_key( path, entry );
294 value = gconf_client_get_without_default( client, fullpath, &error );
296 if( error ){
297 g_warning( "%s: key=%s, %s", thisfn, fullpath, error->message );
298 g_error_free( error );
299 if( value ){
300 gconf_value_free( value );
301 value = NULL;
305 g_free( fullpath );
307 return( value );
310 static void
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;
315 gchar *fullpath;
317 g_return_if_fail( value );
319 fullpath = gconf_concat_dir_and_key( path, entry );
321 gconf_client_set( client, fullpath, value, &error );
323 if( error ){
324 g_warning( "%s: key=%s, %s", thisfn, fullpath, error->message );
325 g_error_free( error );
328 g_free( fullpath );