README: add deprecation notice
[nautilus-actions.git] / src / core / fma-ioption.c
blob1f8b5fdc9e5475308ad7efd428dde46eb18715ae
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 "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.
46 typedef struct {
47 gboolean initialized;
49 IOptionData;
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 );
63 /**
64 * fma_ioption_get_type:
66 * Returns: the #GType type of this interface.
68 GType
69 fma_ioption_get_type( void )
71 static GType type = 0;
73 if( !type ){
74 type = register_type();
77 return( type );
81 * fma_ioption_register_type:
83 * Registers this interface.
85 static GType
86 register_type( void )
88 static const gchar *thisfn = "fma_ioption_register_type";
89 GType type;
91 static const GTypeInfo info = {
92 sizeof( FMAIOptionInterface ),
93 ( GBaseInitFunc ) interface_base_init,
94 ( GBaseFinalizeFunc ) interface_base_finalize,
95 NULL,
96 NULL,
97 NULL,
100 NULL
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 );
109 return( type );
112 static void
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;
129 static void
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 );
144 static guint
145 ioption_get_version( const FMAIOption *instance )
147 return( 1 );
150 static IOptionData *
151 get_ioption_data( FMAIOption *instance )
153 IOptionData *data;
155 data = ( IOptionData * ) g_object_get_data( G_OBJECT( instance ), IOPTION_PROP_DATA );
157 if( !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;
165 return( data );
168 static void
169 on_instance_finalized( gpointer user_data, FMAIOption *instance )
171 static const gchar *thisfn = "fma_ioption_on_instance_finalized";
172 IOptionData *data;
174 g_debug( "%s: user_data=%p, instance=%p", thisfn, ( void * ) user_data, ( void * ) instance );
176 data = get_ioption_data( instance );
178 g_free( data );
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.
188 gchar *
189 fma_ioption_get_id( const FMAIOption *option )
191 gchar *id;
193 g_return_val_if_fail( FMA_IS_IOPTION( option ), NULL );
195 get_ioption_data( FMA_IOPTION( option ));
196 id = NULL;
198 if( FMA_IOPTION_GET_INTERFACE( option )->get_id ){
199 id = FMA_IOPTION_GET_INTERFACE( option )->get_id( option );
202 return( id );
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.
212 gchar *
213 fma_ioption_get_label( const FMAIOption *option )
215 gchar *label;
217 g_return_val_if_fail( FMA_IS_IOPTION( option ), NULL );
219 get_ioption_data( FMA_IOPTION( option ));
220 label = NULL;
222 if( FMA_IOPTION_GET_INTERFACE( option )->get_label ){
223 label = FMA_IOPTION_GET_INTERFACE( option )->get_label( option );
226 return( label );
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.
236 gchar *
237 fma_ioption_get_description( const FMAIOption *option )
239 gchar *description;
241 g_return_val_if_fail( FMA_IS_IOPTION( option ), NULL );
243 get_ioption_data( FMA_IOPTION( option ));
244 description = NULL;
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,
258 * or %NULL.
260 GdkPixbuf *
261 fma_ioption_get_pixbuf( const FMAIOption *option )
263 GdkPixbuf *pixbuf;
265 g_return_val_if_fail( FMA_IS_IOPTION( option ), NULL );
267 get_ioption_data( FMA_IOPTION( option ));
268 pixbuf = NULL;
270 if( FMA_IOPTION_GET_INTERFACE( option )->get_pixbuf ){
271 pixbuf = FMA_IOPTION_GET_INTERFACE( option )->get_pixbuf( option );
274 return( pixbuf );