Fixed typo in string
[nautilus-actions.git] / src / core / na-ioption.c
blob924326dd9af1a869c65c9476496bafee94877bc0
1 /*
2 * Nautilus-Actions
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.
24 * Authors:
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)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
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.
47 typedef struct {
48 gboolean initialized;
50 IOptionData;
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 );
64 /**
65 * na_ioption_get_type:
67 * Returns: the #GType type of this interface.
69 GType
70 na_ioption_get_type( void )
72 static GType type = 0;
74 if( !type ){
75 type = register_type();
78 return( type );
82 * na_ioption_register_type:
84 * Registers this interface.
86 static GType
87 register_type( void )
89 static const gchar *thisfn = "na_ioption_register_type";
90 GType type;
92 static const GTypeInfo info = {
93 sizeof( NAIOptionInterface ),
94 ( GBaseInitFunc ) interface_base_init,
95 ( GBaseFinalizeFunc ) interface_base_finalize,
96 NULL,
97 NULL,
98 NULL,
101 NULL
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 );
110 return( type );
113 static void
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;
130 static void
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 );
145 static guint
146 ioption_get_version( const NAIOption *instance )
148 return( 1 );
151 static IOptionData *
152 get_ioption_data( NAIOption *instance )
154 IOptionData *data;
156 data = ( IOptionData * ) g_object_get_data( G_OBJECT( instance ), IOPTION_PROP_DATA );
158 if( !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;
167 return( data );
170 static void
171 on_instance_finalized( gpointer user_data, NAIOption *instance )
173 static const gchar *thisfn = "na_ioption_on_instance_finalized";
174 IOptionData *data;
176 g_debug( "%s: user_data=%p, instance=%p", thisfn, ( void * ) user_data, ( void * ) instance );
178 data = get_ioption_data( instance );
180 g_free( data );
184 * na_ioption_get_id:
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.
190 gchar *
191 na_ioption_get_id( const NAIOption *option )
193 gchar *id;
195 g_return_val_if_fail( NA_IS_IOPTION( option ), NULL );
197 get_ioption_data( NA_IOPTION( option ));
198 id = NULL;
200 if( NA_IOPTION_GET_INTERFACE( option )->get_id ){
201 id = NA_IOPTION_GET_INTERFACE( option )->get_id( option );
204 return( id );
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.
214 gchar *
215 na_ioption_get_label( const NAIOption *option )
217 gchar *label;
219 g_return_val_if_fail( NA_IS_IOPTION( option ), NULL );
221 get_ioption_data( NA_IOPTION( option ));
222 label = NULL;
224 if( NA_IOPTION_GET_INTERFACE( option )->get_label ){
225 label = NA_IOPTION_GET_INTERFACE( option )->get_label( option );
228 return( label );
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.
238 gchar *
239 na_ioption_get_description( const NAIOption *option )
241 gchar *description;
243 g_return_val_if_fail( NA_IS_IOPTION( option ), NULL );
245 get_ioption_data( NA_IOPTION( option ));
246 description = NULL;
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,
260 * or %NULL.
262 GdkPixbuf *
263 na_ioption_get_pixbuf( const NAIOption *option )
265 GdkPixbuf *pixbuf;
267 g_return_val_if_fail( NA_IS_IOPTION( option ), NULL );
269 get_ioption_data( NA_IOPTION( option ));
270 pixbuf = NULL;
272 if( NA_IOPTION_GET_INTERFACE( option )->get_pixbuf ){
273 pixbuf = NA_IOPTION_GET_INTERFACE( option )->get_pixbuf( option );
276 return( pixbuf );