README: add deprecation notice
[nautilus-actions.git] / src / core / fma-gconf-monitor.c
blobef62dcf87ef88db76aa8777d046d9884f3af43aa
1 /*
2 * FileManager-Actions
3 * A file-manager extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009-2015 Pierre Wieser and others (see AUTHORS)
9 * FileManager-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.
14 * FileManager-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.
19 * You should have received a copy of the GNU General Public License
20 * along with FileManager-Actions; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
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)
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
34 #include <api/fma-gconf-monitor.h>
36 #ifdef HAVE_GCONF
37 #ifdef FMA_ENABLE_DEPRECATED
39 /* private class data
41 struct _FMAGConfMonitorClassPrivate {
42 void *empty; /* so that gcc -pedantic is happy */
45 /* private instance data
47 struct _FMAGConfMonitorPrivate {
48 gboolean dispose_has_run;
49 GConfClient *gconf;
50 gchar *path;
51 gint preload;
52 GConfClientNotifyFunc handler;
53 gpointer user_data;
54 guint monitor_id;
57 static GObjectClass *st_parent_class = NULL;
59 static GType register_type( void );
60 static void class_init( FMAGConfMonitorClass *klass );
61 static void instance_init( GTypeInstance *instance, gpointer klass );
62 static void instance_dispose( GObject *object );
63 static void instance_finalize( GObject *object );
65 static guint install_monitor( FMAGConfMonitor *monitor );
66 static void release_monitor( FMAGConfMonitor *monitor );
68 GType
69 fma_gconf_monitor_get_type( void )
71 static GType object_type = 0;
73 if( !object_type ){
74 object_type = register_type();
77 return( object_type );
80 static GType
81 register_type( void )
83 static const gchar *thisfn = "fma_gconf_monitor_register_type";
84 GType type;
86 static GTypeInfo info = {
87 sizeof( FMAGConfMonitorClass ),
88 NULL,
89 NULL,
90 ( GClassInitFunc ) class_init,
91 NULL,
92 NULL,
93 sizeof( FMAGConfMonitor ),
95 ( GInstanceInitFunc ) instance_init
98 g_debug( "%s", thisfn );
100 type = g_type_register_static( G_TYPE_OBJECT, "FMAGConfMonitor", &info, 0 );
102 return( type );
105 static void
106 class_init( FMAGConfMonitorClass *klass )
108 static const gchar *thisfn = "fma_gconf_monitor_class_init";
109 GObjectClass *object_class;
111 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
113 st_parent_class = g_type_class_peek_parent( klass );
115 object_class = G_OBJECT_CLASS( klass );
116 object_class->dispose = instance_dispose;
117 object_class->finalize = instance_finalize;
119 klass->private = g_new0( FMAGConfMonitorClassPrivate, 1 );
122 static void
123 instance_init( GTypeInstance *instance, gpointer klass )
125 static const gchar *thisfn = "fma_gconf_monitor_instance_init";
126 FMAGConfMonitor *self;
128 g_return_if_fail( FMA_IS_GCONF_MONITOR( instance ));
130 g_debug( "%s: instance=%p (%s), klass=%p",
131 thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ), ( void * ) klass );
132 self = FMA_GCONF_MONITOR( instance );
134 self->private = g_new0( FMAGConfMonitorPrivate, 1 );
136 self->private->gconf = gconf_client_get_default();
138 self->private->dispose_has_run = FALSE;
141 static void
142 instance_dispose( GObject *object )
144 static const gchar *thisfn = "fma_gconf_monitor_instance_dispose";
145 FMAGConfMonitor *self;
147 g_return_if_fail( FMA_IS_GCONF_MONITOR( object ));
149 self = FMA_GCONF_MONITOR( object );
151 if( !self->private->dispose_has_run ){
153 g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
155 /* release the installed monitor before setting dispose_has_run */
156 release_monitor( self );
158 self->private->dispose_has_run = TRUE;
160 g_object_unref( self->private->gconf );
162 /* chain up to the parent class */
163 if( G_OBJECT_CLASS( st_parent_class )->dispose ){
164 G_OBJECT_CLASS( st_parent_class )->dispose( object );
169 static void
170 instance_finalize( GObject *object )
172 static const gchar *thisfn = "fma_gconf_monitor_instance_finalize";
173 FMAGConfMonitor *self;
175 g_return_if_fail( FMA_IS_GCONF_MONITOR( object ));
177 g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
179 self = FMA_GCONF_MONITOR( object );
181 g_free( self->private->path );
182 g_free( self->private );
184 /* chain call to parent class */
185 if( G_OBJECT_CLASS( st_parent_class )->finalize ){
186 G_OBJECT_CLASS( st_parent_class )->finalize( object );
191 * fma_gconf_monitor_new:
192 * @path: the absolute path to monitor.
193 * @handler: the function to be triggered by the monitor.
194 * @user_data: data to pass to the @handler.
196 * Initializes the monitoring of a GConf path.
198 * This monitoring will only be stopped when object is released, via
199 * g_object_unref().
201 * Returns: a new #FMAGConfMonitor object, which will monitor the given path,
202 * triggeering the @handler in case of modifications.
204 * Since: 2.30
205 * Deprecated: 3.1
207 FMAGConfMonitor *
208 fma_gconf_monitor_new( const gchar *path, GConfClientNotifyFunc handler, gpointer user_data )
210 static const gchar *thisfn = "fma_gconf_monitor_new";
211 FMAGConfMonitor *monitor;
213 g_debug( "%s: path=%s, user_data=%p", thisfn, path, ( void * ) user_data );
215 monitor = g_object_new( FMA_TYPE_GCONF_MONITOR, NULL );
217 monitor->private->path = g_strdup( path );
218 monitor->private->preload = GCONF_CLIENT_PRELOAD_RECURSIVE;
219 monitor->private->handler = handler;
220 monitor->private->user_data = user_data;
222 monitor->private->monitor_id = install_monitor( monitor );
224 return( monitor );
227 static guint
228 install_monitor( FMAGConfMonitor *monitor )
230 static const gchar *thisfn = "fma_gconf_monitor_install_monitor";
231 GError *error = NULL;
232 guint notify_id;
234 g_return_val_if_fail( FMA_IS_GCONF_MONITOR( monitor ), 0 );
235 g_return_val_if_fail( !monitor->private->dispose_has_run, 0 );
237 gconf_client_add_dir(
238 monitor->private->gconf,
239 monitor->private->path,
240 monitor->private->preload,
241 &error );
243 if( error ){
244 g_warning( "%s[gconf_client_add_dir] path=%s, error=%s", thisfn, monitor->private->path, error->message );
245 g_error_free( error );
246 return( 0 );
249 notify_id = gconf_client_notify_add(
250 monitor->private->gconf,
251 monitor->private->path,
252 monitor->private->handler,
253 monitor->private->user_data,
254 NULL,
255 &error );
257 if( error ){
258 g_warning( "%s[gconf_client_notify_add] path=%s, error=%s", thisfn, monitor->private->path, error->message );
259 g_error_free( error );
260 return( 0 );
263 return( notify_id );
267 * fma_gconf_monitor_release_monitors:
268 * @monitors: a list of #FMAGConfMonitors.
270 * Release allocated monitors.
272 * Since: 2.30
273 * Deprecated: 3.1
275 void
276 fma_gconf_monitor_release_monitors( GList *monitors )
278 g_list_foreach( monitors, ( GFunc ) g_object_unref, NULL );
279 g_list_free( monitors );
283 * this is called by instance_dispose, before setting dispose_has_run
285 static void
286 release_monitor( FMAGConfMonitor *monitor )
288 static const gchar *thisfn = "fma_gconf_monitor_release_monitor";
289 GError *error = NULL;
291 g_return_if_fail( FMA_IS_GCONF_MONITOR( monitor ));
293 if( !monitor->private->dispose_has_run ){
295 g_debug( "%s: monitor=%p", thisfn, ( void * ) monitor );
297 if( monitor->private->monitor_id ){
298 gconf_client_notify_remove( monitor->private->gconf, monitor->private->monitor_id );
301 gconf_client_remove_dir( monitor->private->gconf, monitor->private->path, &error );
303 if( error ){
304 g_warning( "%s: path=%s, error=%s", thisfn, monitor->private->path, error->message );
305 g_error_free( error );
310 #endif /* FMA_ENABLE_DEPRECATED */
311 #endif /* HAVE_GCONF */