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/>.
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)
34 #include "fma-ioption.h"
36 /* private interface data
38 struct _FMAIOptionInterfacePrivate
{
39 void *empty
; /* so that gcc -pedantic is happy */
42 /* data set against the instance
44 * Initialization here mainly means setting the weak ref against the instance.
51 #define IOPTION_PROP_DATA "prop-ioption-data"
53 static guint st_initializations
= 0; /* interface initialization count */
55 static GType
register_type( void );
56 static void interface_base_init( FMAIOptionInterface
*iface
);
57 static void interface_base_finalize( FMAIOptionInterface
*iface
);
59 static guint
ioption_get_version( const FMAIOption
*instance
);
60 static IOptionData
*get_ioption_data( FMAIOption
*instance
);
61 static void on_instance_finalized( gpointer user_data
, FMAIOption
*instance
);
64 * fma_ioption_get_type:
66 * Returns: the #GType type of this interface.
69 fma_ioption_get_type( void )
71 static GType type
= 0;
74 type
= register_type();
81 * fma_ioption_register_type:
83 * Registers this interface.
88 static const gchar
*thisfn
= "fma_ioption_register_type";
91 static const GTypeInfo info
= {
92 sizeof( FMAIOptionInterface
),
93 ( GBaseInitFunc
) interface_base_init
,
94 ( GBaseFinalizeFunc
) interface_base_finalize
,
103 g_debug( "%s", thisfn
);
105 type
= g_type_register_static( G_TYPE_INTERFACE
, "FMAIOption", &info
, 0 );
107 g_type_interface_add_prerequisite( type
, G_TYPE_OBJECT
);
113 interface_base_init( FMAIOptionInterface
*iface
)
115 static const gchar
*thisfn
= "fma_ioption_interface_base_init";
117 if( !st_initializations
){
119 g_debug( "%s: iface=%p (%s)", thisfn
, ( void * ) iface
, G_OBJECT_CLASS_NAME( iface
));
121 iface
->private = g_new0( FMAIOptionInterfacePrivate
, 1 );
123 iface
->get_version
= ioption_get_version
;
126 st_initializations
+= 1;
130 interface_base_finalize( FMAIOptionInterface
*iface
)
132 static const gchar
*thisfn
= "fma_ioption_interface_base_finalize";
134 st_initializations
-= 1;
136 if( !st_initializations
){
138 g_debug( "%s: iface=%p", thisfn
, ( void * ) iface
);
140 g_free( iface
->private );
145 ioption_get_version( const FMAIOption
*instance
)
151 get_ioption_data( FMAIOption
*instance
)
155 data
= ( IOptionData
* ) g_object_get_data( G_OBJECT( instance
), IOPTION_PROP_DATA
);
158 data
= g_new0( IOptionData
, 1 );
159 g_object_set_data( G_OBJECT( instance
), IOPTION_PROP_DATA
, data
);
160 g_object_weak_ref( G_OBJECT( instance
), ( GWeakNotify
) on_instance_finalized
, NULL
);
162 data
->initialized
= TRUE
;
169 on_instance_finalized( gpointer user_data
, FMAIOption
*instance
)
171 static const gchar
*thisfn
= "fma_ioption_on_instance_finalized";
174 g_debug( "%s: user_data=%p, instance=%p", thisfn
, ( void * ) user_data
, ( void * ) instance
);
176 data
= get_ioption_data( instance
);
182 * fma_ioption_get_id:
183 * @option: this #FMAIOption instance.
185 * Returns: the string identifier of the format, as a newly
186 * allocated string which should be g_free() by the caller.
189 fma_ioption_get_id( const FMAIOption
*option
)
193 g_return_val_if_fail( FMA_IS_IOPTION( option
), NULL
);
195 get_ioption_data( FMA_IOPTION( option
));
198 if( FMA_IOPTION_GET_INTERFACE( option
)->get_id
){
199 id
= FMA_IOPTION_GET_INTERFACE( option
)->get_id( option
);
206 * fma_ioption_get_label:
207 * @option: this #FMAIOption instance.
209 * Returns: the UTF-8 localizable label of the format, as a newly
210 * allocated string which should be g_free() by the caller.
213 fma_ioption_get_label( const FMAIOption
*option
)
217 g_return_val_if_fail( FMA_IS_IOPTION( option
), NULL
);
219 get_ioption_data( FMA_IOPTION( option
));
222 if( FMA_IOPTION_GET_INTERFACE( option
)->get_label
){
223 label
= FMA_IOPTION_GET_INTERFACE( option
)->get_label( option
);
230 * fma_ioption_get_description:
231 * @format: this #FMAExportFormat object.
233 * Returns: the UTF-8 localizable description of the format, as a newly
234 * allocated string which should be g_free() by the caller.
237 fma_ioption_get_description( const FMAIOption
*option
)
241 g_return_val_if_fail( FMA_IS_IOPTION( option
), NULL
);
243 get_ioption_data( FMA_IOPTION( option
));
246 if( FMA_IOPTION_GET_INTERFACE( option
)->get_description
){
247 description
= FMA_IOPTION_GET_INTERFACE( option
)->get_description( option
);
250 return( description
);
254 * fma_ioption_get_pixbuf:
255 * @option: this #FMAIOption instance.
257 * Returns: a new reference to the #GdkPixbuf image associated with this format,
261 fma_ioption_get_pixbuf( const FMAIOption
*option
)
265 g_return_val_if_fail( FMA_IS_IOPTION( option
), NULL
);
267 get_ioption_data( FMA_IOPTION( option
));
270 if( FMA_IOPTION_GET_INTERFACE( option
)->get_pixbuf
){
271 pixbuf
= FMA_IOPTION_GET_INTERFACE( option
)->get_pixbuf( option
);