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)
32 * pwi 2009-12-09 - French comments are from
33 * http://www.unixgarden.com/index.php/programmation/decouvertes-et-experimentation-avec-d-bus
40 #include <dbus/dbus-glib.h>
42 #include <libnautilus-extension/nautilus-file-info.h>
44 #include "na-tracker-dbus.h"
45 #include "na-tracker-dbus-glue.h"
49 struct NATrackerDBusClassPrivate
{
50 void *empty
; /* so that gcc -pedantic is happy */
53 /* private instance data
55 struct NATrackerDBusPrivate
{
56 gboolean dispose_has_run
;
60 static GObjectClass
*st_parent_class
= NULL
;
62 static GType
register_type( void );
63 static void class_init( NATrackerDBusClass
*klass
);
64 static void instance_init( GTypeInstance
*instance
, gpointer klass
);
65 static void instance_dispose( GObject
*object
);
66 static void instance_finalize( GObject
*object
);
68 static GList
*free_selected( GList
*selected
);
71 na_tracker_dbus_get_type( void )
73 static GType tracker_type
= 0;
76 tracker_type
= register_type();
79 return( tracker_type
);
85 static const gchar
*thisfn
= "na_tracker_dbus_register_type";
88 static GTypeInfo info
= {
89 sizeof( NATrackerDBusClass
),
90 ( GBaseInitFunc
) NULL
,
91 ( GBaseFinalizeFunc
) NULL
,
92 ( GClassInitFunc
) class_init
,
95 sizeof( NATrackerDBus
),
97 ( GInstanceInitFunc
) instance_init
100 g_debug( "%s", thisfn
);
102 type
= g_type_register_static( G_TYPE_OBJECT
, "NATrackerDBus", &info
, 0 );
108 class_init( NATrackerDBusClass
*klass
)
110 static const gchar
*thisfn
= "na_tracker_dbus_class_init";
111 GObjectClass
*gobject_class
;
113 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
115 st_parent_class
= g_type_class_peek_parent( klass
);
117 gobject_class
= G_OBJECT_CLASS( klass
);
118 gobject_class
->dispose
= instance_dispose
;
119 gobject_class
->finalize
= instance_finalize
;
121 klass
->private = g_new0( NATrackerDBusClassPrivate
, 1 );
123 /* Installation du mécanisme d’introspection,
124 * permettant de faire l’appel de méthodes via un nom.
125 * - Le second paramètre de cette fonction (dbus_glib_na_tracker_dbus_object_info)
126 * est généré lors de l’appel à dbus-binding-tool, et sa définition
127 * peut être retrouvée dans le fichier na-tracker-dbus-glue.h
129 dbus_g_object_type_install_info( NA_TRACKER_DBUS_TYPE
, &dbus_glib_na_tracker_dbus_object_info
);
133 instance_init( GTypeInstance
*instance
, gpointer klass
)
135 static const gchar
*thisfn
= "na_tracker_dbus_instance_init";
138 g_debug( "%s: instance=%p, klass=%p", thisfn
, ( void * ) instance
, ( void * ) klass
);
139 g_return_if_fail( NA_IS_TRACKER_DBUS( instance
));
141 self
= NA_TRACKER_DBUS( instance
);
143 self
->private = g_new0( NATrackerDBusPrivate
, 1 );
144 self
->private->dispose_has_run
= FALSE
;
145 self
->private->selected
= NULL
;
149 instance_dispose( GObject
*object
)
151 static const gchar
*thisfn
= "na_tracker_dbus_instance_dispose";
154 g_debug( "%s: object=%p", thisfn
, ( void * ) object
);
155 g_return_if_fail( NA_IS_TRACKER_DBUS( object
));
156 self
= NA_TRACKER_DBUS( object
);
158 if( !self
->private->dispose_has_run
){
160 self
->private->dispose_has_run
= TRUE
;
162 self
->private->selected
= free_selected( self
->private->selected
);
164 /* chain up to the parent class */
165 if( G_OBJECT_CLASS( st_parent_class
)->dispose
){
166 G_OBJECT_CLASS( st_parent_class
)->dispose( object
);
172 instance_finalize( GObject
*object
)
174 static const gchar
*thisfn
= "na_tracker_dbus_instance_finalize";
177 g_debug( "%s: object=%p", thisfn
, ( void * ) object
);
178 g_return_if_fail( NA_IS_TRACKER_DBUS( object
));
179 self
= NA_TRACKER_DBUS( object
);
181 g_free( self
->private );
183 /* chain up to the parent class */
184 if( G_OBJECT_CLASS( st_parent_class
)->finalize
){
185 G_OBJECT_CLASS( st_parent_class
)->finalize( object
);
190 * na_tracker_dbus_set_uris:
191 * @tracker: this #NATrackerDBus instance.
192 * @files: the list of currently selected items.
194 * Maintains our own list of uris.
197 na_tracker_dbus_set_uris( NATrackerDBus
*tracker
, GList
*files
)
199 if( !tracker
->private->dispose_has_run
){
201 tracker
->private->selected
= free_selected( tracker
->private->selected
);
202 tracker
->private->selected
= nautilus_file_info_list_copy( files
);
207 * na_tracker_dbus_get_selected_paths:
208 * @tracker: this #NATrackerDBus object.
209 * @paths: the location in which copy the strings to be sent.
210 * @error: the location of a GError.
212 * Sends on session DBus the list of currently selected items, as two strings
215 * - the mimetype as returned by NautilusFileInfo.
217 * This is required as some particular items are only known by Nautilus
218 * (e.g. computer), and standard GLib functions are not able to retrieve
221 * Exported as GetSelectedPaths method on Tracker.Status interface.
224 na_tracker_dbus_get_selected_paths( NATrackerDBus
*tracker
, char ***paths
, GError
**error
)
226 static const gchar
*thisfn
= "na_tracker_dbus_get_selected_paths";
232 g_debug( "%s: object=%p, paths=%p, error=%p", thisfn
, ( void * ) tracker
, ( void * ) paths
, ( void * ) error
);
237 if( !tracker
->private->dispose_has_run
){
239 count
= 2 * g_list_length( tracker
->private->selected
);
240 *paths
= ( char ** ) g_new0( gchar
*, 1+count
);
243 for( it
= tracker
->private->selected
; it
; it
= it
->next
){
244 *iter
= nautilus_file_info_get_uri(( NautilusFileInfo
* ) it
->data
);
246 *iter
= nautilus_file_info_get_mime_type(( NautilusFileInfo
* ) it
->data
);
255 free_selected( GList
*selected
)
257 nautilus_file_info_list_free( selected
);