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, 2011, 2012 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-ioption.h"
37 /* private interface data
39 struct _NAIOptionInterfacePrivate
{
40 void *empty
; /* so that gcc -pedantic is happy */
43 /* data set against the instance
45 * Initialization here mainly means setting the weak ref against the instance.
52 #define IOPTION_PROP_DATA "na-prop-ioption-data"
54 static guint st_initializations
= 0; /* interface initialization count */
56 static GType
register_type( void );
57 static void interface_base_init( NAIOptionInterface
*iface
);
58 static void interface_base_finalize( NAIOptionInterface
*iface
);
60 static guint
ioption_get_version( const NAIOption
*instance
);
61 static IOptionData
*get_ioption_data( NAIOption
*instance
);
62 static void on_instance_finalized( gpointer user_data
, NAIOption
*instance
);
65 * na_ioption_get_type:
67 * Returns: the #GType type of this interface.
70 na_ioption_get_type( void )
72 static GType type
= 0;
75 type
= register_type();
82 * na_ioption_register_type:
84 * Registers this interface.
89 static const gchar
*thisfn
= "na_ioption_register_type";
92 static const GTypeInfo info
= {
93 sizeof( NAIOptionInterface
),
94 ( GBaseInitFunc
) interface_base_init
,
95 ( GBaseFinalizeFunc
) interface_base_finalize
,
104 g_debug( "%s", thisfn
);
106 type
= g_type_register_static( G_TYPE_INTERFACE
, "NAIOption", &info
, 0 );
108 g_type_interface_add_prerequisite( type
, G_TYPE_OBJECT
);
114 interface_base_init( NAIOptionInterface
*iface
)
116 static const gchar
*thisfn
= "na_ioption_interface_base_init";
118 if( !st_initializations
){
120 g_debug( "%s: iface=%p (%s)", thisfn
, ( void * ) iface
, G_OBJECT_CLASS_NAME( iface
));
122 iface
->private = g_new0( NAIOptionInterfacePrivate
, 1 );
124 iface
->get_version
= ioption_get_version
;
127 st_initializations
+= 1;
131 interface_base_finalize( NAIOptionInterface
*iface
)
133 static const gchar
*thisfn
= "na_ioption_interface_base_finalize";
135 st_initializations
-= 1;
137 if( !st_initializations
){
139 g_debug( "%s: iface=%p", thisfn
, ( void * ) iface
);
141 g_free( iface
->private );
146 ioption_get_version( const NAIOption
*instance
)
152 get_ioption_data( NAIOption
*instance
)
156 data
= ( IOptionData
* ) g_object_get_data( G_OBJECT( instance
), IOPTION_PROP_DATA
);
159 data
= g_new0( IOptionData
, 1 );
160 g_object_set_data( G_OBJECT( instance
), IOPTION_PROP_DATA
, data
);
162 g_object_weak_ref( G_OBJECT( instance
), ( GWeakNotify
) on_instance_finalized
, NULL
);
164 data
->initialized
= TRUE
;
171 on_instance_finalized( gpointer user_data
, NAIOption
*instance
)
173 static const gchar
*thisfn
= "na_ioption_on_instance_finalized";
176 g_debug( "%s: user_data=%p, instance=%p", thisfn
, ( void * ) user_data
, ( void * ) instance
);
178 data
= get_ioption_data( instance
);
185 * @option: this #NAIOption instance.
187 * Returns: the string identifier of the format, as a newly
188 * allocated string which should be g_free() by the caller.
191 na_ioption_get_id( const NAIOption
*option
)
195 g_return_val_if_fail( NA_IS_IOPTION( option
), NULL
);
197 get_ioption_data( NA_IOPTION( option
));
200 if( NA_IOPTION_GET_INTERFACE( option
)->get_id
){
201 id
= NA_IOPTION_GET_INTERFACE( option
)->get_id( option
);
208 * na_ioption_get_label:
209 * @option: this #NAIOption instance.
211 * Returns: the UTF-8 localizable label of the format, as a newly
212 * allocated string which should be g_free() by the caller.
215 na_ioption_get_label( const NAIOption
*option
)
219 g_return_val_if_fail( NA_IS_IOPTION( option
), NULL
);
221 get_ioption_data( NA_IOPTION( option
));
224 if( NA_IOPTION_GET_INTERFACE( option
)->get_label
){
225 label
= NA_IOPTION_GET_INTERFACE( option
)->get_label( option
);
232 * na_ioption_get_description:
233 * @format: this #NAExportFormat object.
235 * Returns: the UTF-8 localizable description of the format, as a newly
236 * allocated string which should be g_free() by the caller.
239 na_ioption_get_description( const NAIOption
*option
)
243 g_return_val_if_fail( NA_IS_IOPTION( option
), NULL
);
245 get_ioption_data( NA_IOPTION( option
));
248 if( NA_IOPTION_GET_INTERFACE( option
)->get_description
){
249 description
= NA_IOPTION_GET_INTERFACE( option
)->get_description( option
);
252 return( description
);
256 * na_ioption_get_pixbuf:
257 * @option: this #NAIOption instance.
259 * Returns: a new reference to the #GdkPixbuf image associated with this format,
263 na_ioption_get_pixbuf( const NAIOption
*option
)
267 g_return_val_if_fail( NA_IS_IOPTION( option
), NULL
);
269 get_ioption_data( NA_IOPTION( option
));
272 if( NA_IOPTION_GET_INTERFACE( option
)->get_pixbuf
){
273 pixbuf
= NA_IOPTION_GET_INTERFACE( option
)->get_pixbuf( option
);