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 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)
35
#include "na-gconf-monitor.h"
39
struct NAGConfMonitorClassPrivate {
40
void *empty; /* so that gcc -pedantic is happy */
43
/* private instance data
45
struct NAGConfMonitorPrivate {
46
gboolean dispose_has_run;
50
GConfClientNotifyFunc handler;
55
static GObjectClass *st_parent_class = NULL;
57
static GType register_type( void );
58
static void class_init( NAGConfMonitorClass *klass );
59
static void instance_init( GTypeInstance *instance, gpointer klass );
60
static void instance_dispose( GObject *object );
61
static void instance_finalize( GObject *object );
63
static guint install_monitor( NAGConfMonitor *monitor );
64
static void release_monitor( NAGConfMonitor *monitor );
67
na_gconf_monitor_get_type( void )
69
static GType object_type = 0;
72
object_type = register_type();
75
return( object_type );
81
static const gchar *thisfn = "na_gconf_monitor_register_type";
84
static GTypeInfo info = {
85
sizeof( NAGConfMonitorClass ),
88
( GClassInitFunc ) class_init,
91
sizeof( NAGConfMonitor ),
93
( GInstanceInitFunc ) instance_init
96
g_debug( "%s", thisfn );
98
type = g_type_register_static( G_TYPE_OBJECT, "NAGConfMonitor", &info, 0 );
104
class_init( NAGConfMonitorClass *klass )
106
static const gchar *thisfn = "na_gconf_monitor_class_init";
107
GObjectClass *object_class;
109
g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
111
st_parent_class = g_type_class_peek_parent( klass );
113
object_class = G_OBJECT_CLASS( klass );
114
object_class->dispose = instance_dispose;
115
object_class->finalize = instance_finalize;
117
klass->private = g_new0( NAGConfMonitorClassPrivate, 1 );
121
instance_init( GTypeInstance *instance, gpointer klass )
123
static const gchar *thisfn = "na_gconf_monitor_instance_init";
124
NAGConfMonitor *self;
126
g_debug( "%s: instance=%p, klass=%p", thisfn, ( void * ) instance, ( void * ) klass );
127
g_return_if_fail( NA_IS_GCONF_MONITOR( instance ));
128
self = NA_GCONF_MONITOR( instance );
130
self->private = g_new0( NAGConfMonitorPrivate, 1 );
134
instance_dispose( GObject *object )
136
static const gchar *thisfn = "na_gconf_monitor_instance_dispose";
137
NAGConfMonitor *self;
139
g_debug( "%s: object=%p", thisfn, ( void * ) object );
140
g_return_if_fail( NA_IS_GCONF_MONITOR( object ));
141
self = NA_GCONF_MONITOR( object );
143
if( !self->private->dispose_has_run ){
145
/* release the installed monitor before setting dispose_has_run */
146
release_monitor( self );
148
self->private->dispose_has_run = TRUE;
150
/* chain up to the parent class */
151
if( G_OBJECT_CLASS( st_parent_class )->dispose ){
152
G_OBJECT_CLASS( st_parent_class )->dispose( object );
158
instance_finalize( GObject *object )
160
NAGConfMonitor *self;
162
g_return_if_fail( NA_IS_GCONF_MONITOR( object ));
163
self = NA_GCONF_MONITOR( object );
165
g_free( self->private->path );
166
g_free( self->private );
168
/* chain call to parent class */
169
if( G_OBJECT_CLASS( st_parent_class )->finalize ){
170
G_OBJECT_CLASS( st_parent_class )->finalize( object );
175
* na_gconf_monitor_new:
176
* @client: a #GConfClient object already initialized by the caller.
177
* @path: the absolute path to monitor.
178
* @preload: a #GConfClientPreloadType for this monitoring.
179
* @handler: the function to be triggered by the monitor.
180
* @user_data: data to pass to the @handler.
182
* Initializes the monitoring of a GConf path.
185
na_gconf_monitor_new( const gchar *path, GConfClientNotifyFunc handler, gpointer user_data )
187
static const gchar *thisfn = "na_gconf_monitor_new";
188
NAGConfMonitor *monitor;
190
g_debug( "%s: path=%s, user_data=%p", thisfn, path, ( void * ) user_data );
192
monitor = g_object_new( NA_GCONF_MONITOR_TYPE, NULL );
194
monitor->private->gconf = gconf_client_get_default();
195
monitor->private->path = g_strdup( path );
196
monitor->private->preload = GCONF_CLIENT_PRELOAD_RECURSIVE;
197
monitor->private->handler = handler;
198
monitor->private->user_data = user_data;
200
monitor->private->monitor_id = install_monitor( monitor );
206
install_monitor( NAGConfMonitor *monitor )
208
static const gchar *thisfn = "na_gconf_monitor_install_monitor";
209
GError *error = NULL;
212
g_return_val_if_fail( NA_IS_GCONF_MONITOR( monitor ), 0 );
213
g_return_val_if_fail( !monitor->private->dispose_has_run, 0 );
215
gconf_client_add_dir(
216
monitor->private->gconf,
217
monitor->private->path,
218
monitor->private->preload,
222
g_warning( "%s[gconf_client_add_dir] path=%s, error=%s", thisfn, monitor->private->path, error->message );
223
g_error_free( error );
227
notify_id = gconf_client_notify_add(
228
monitor->private->gconf,
229
monitor->private->path,
230
monitor->private->handler,
231
monitor->private->user_data,
236
g_warning( "%s[gconf_client_notify_add] path=%s, error=%s", thisfn, monitor->private->path, error->message );
237
g_error_free( error );
245
* na_gconf_monitor_release_monitors:
246
* @monitors: a list of #NAGConfMonitors.
248
* Release allocated monitors.
251
na_gconf_monitor_release_monitors( GList *monitors )
253
g_list_foreach( monitors, ( GFunc ) g_object_unref, NULL );
254
g_list_free( monitors );
258
* this is called by instance_dispose, before setting dispose_has_run
261
release_monitor( NAGConfMonitor *monitor )
263
static const gchar *thisfn = "na_gconf_monitor_release_monitor";
264
GError *error = NULL;
266
g_debug( "%s: monitor=%p", thisfn, ( void * ) monitor );
267
g_return_if_fail( NA_IS_GCONF_MONITOR( monitor ));
268
g_return_if_fail( !monitor->private->dispose_has_run );
270
if( monitor->private->monitor_id ){
271
gconf_client_notify_remove( monitor->private->gconf, monitor->private->monitor_id );
274
gconf_client_remove_dir( monitor->private->gconf, monitor->private->path, &error );
277
g_warning( "%s: path=%s, error=%s", thisfn, monitor->private->path, error->message );
278
g_error_free( error );
281
g_object_unref( monitor->private->gconf );