Manage locked and mandatory preferences
[nautilus-actions.git] / src / core / na-export-format.c
blobbec2ffec4fc69373d7fe718beda0a5d50b9a4d5a
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 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 <libintl.h>
37 #include "na-export-format.h"
39 /* private class data
41 struct _NAExportFormatClassPrivate {
42 void *empty; /* so that gcc -pedantic is happy */
45 /* private instance data
47 struct _NAExportFormatPrivate {
48 gboolean dispose_has_run;
49 GQuark id;
50 NAIExporterFormat *str;
51 NAIExporter *exporter;
54 static GObjectClass *st_parent_class = NULL;
56 static GType register_type( void );
57 static void class_init( NAExportFormatClass *klass );
58 static void instance_init( GTypeInstance *instance, gpointer klass );
59 static void instance_dispose( GObject *object );
60 static void instance_finalize( GObject *object );
62 GType
63 na_export_format_get_type( void )
65 static GType object_type = 0;
67 if( !object_type ){
68 object_type = register_type();
71 return( object_type );
74 static GType
75 register_type( void )
77 static const gchar *thisfn = "na_export_format_register_type";
78 GType type;
80 static GTypeInfo info = {
81 sizeof( NAExportFormatClass ),
82 ( GBaseInitFunc ) NULL,
83 ( GBaseFinalizeFunc ) NULL,
84 ( GClassInitFunc ) class_init,
85 NULL,
86 NULL,
87 sizeof( NAExportFormat ),
89 ( GInstanceInitFunc ) instance_init
92 g_debug( "%s", thisfn );
94 type = g_type_register_static( G_TYPE_OBJECT, "NAExportFormat", &info, 0 );
96 return( type );
99 static void
100 class_init( NAExportFormatClass *klass )
102 static const gchar *thisfn = "na_export_format_class_init";
103 GObjectClass *object_class;
105 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
107 st_parent_class = g_type_class_peek_parent( klass );
109 object_class = G_OBJECT_CLASS( klass );
110 object_class->dispose = instance_dispose;
111 object_class->finalize = instance_finalize;
113 klass->private = g_new0( NAExportFormatClassPrivate, 1 );
116 static void
117 instance_init( GTypeInstance *instance, gpointer klass )
119 static const gchar *thisfn = "na_export_format_instance_init";
120 NAExportFormat *self;
122 g_return_if_fail( NA_IS_EXPORT_FORMAT( instance ));
124 g_debug( "%s: instance=%p (%s), klass=%p",
125 thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ), ( void * ) klass );
126 self = NA_EXPORT_FORMAT( instance );
128 self->private = g_new0( NAExportFormatPrivate, 1 );
130 self->private->dispose_has_run = FALSE;
133 static void
134 instance_dispose( GObject *object )
136 static const gchar *thisfn = "na_export_format_instance_dispose";
137 NAExportFormat *self;
139 g_return_if_fail( NA_IS_EXPORT_FORMAT( object ));
141 self = NA_EXPORT_FORMAT( object );
143 if( !self->private->dispose_has_run ){
145 g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
147 self->private->dispose_has_run = TRUE;
149 /* chain up to the parent class */
150 if( G_OBJECT_CLASS( st_parent_class )->dispose ){
151 G_OBJECT_CLASS( st_parent_class )->dispose( object );
156 static void
157 instance_finalize( GObject *object )
159 static const gchar *thisfn = "na_export_format_instance_finalize";
160 NAExportFormat *self;
162 g_return_if_fail( NA_IS_EXPORT_FORMAT( object ));
164 g_debug( "%s: object=%p", thisfn, ( void * ) object );
165 self = NA_EXPORT_FORMAT( object );
167 g_free( self->private );
169 /* chain call to parent class */
170 if( G_OBJECT_CLASS( st_parent_class )->finalize ){
171 G_OBJECT_CLASS( st_parent_class )->finalize( object );
176 * na_export_format_new:
177 * @exporter_format: a #NAIExporterFormat which describes an export format.
178 * @exporter: the #NAIExporter which provides this export format.
180 * Returns: a newly allocated #NAExportFormat object.
182 NAExportFormat *
183 na_export_format_new( const NAIExporterFormat *exporter_format, const NAIExporter *exporter )
185 NAExportFormat *format;
187 format = g_object_new( NA_EXPORT_FORMAT_TYPE, NULL );
189 format->private->id = g_quark_from_string( exporter_format->format );
190 format->private->str = ( NAIExporterFormat * ) exporter_format;
191 format->private->exporter = ( NAIExporter * ) exporter;
193 return( format );
197 * na_export_format_get_quark:
198 * @format: this #NAExportFormat object.
200 * Returns: the #GQuark associated with this format.
202 GQuark
203 na_export_format_get_quark( const NAExportFormat *format )
205 GQuark id;
207 g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), 0 );
209 id = 0;
211 if( !format->private->dispose_has_run ){
213 id = format->private->id;
216 return( id );
220 * na_export_format_get_id:
221 * @format: this #NAExportFormat object.
223 * Returns: the ASCII id of the format, as a newly allocated string which
224 * should be g_free() by the caller.
226 gchar *
227 na_export_format_get_id( const NAExportFormat *format )
229 gchar *id;
231 g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), NULL );
233 id = NULL;
235 if( !format->private->dispose_has_run ){
237 id = g_strdup( format->private->str->format );
240 return( id );
244 * na_export_format_get_label:
245 * @format: this #NAExportFormat object.
247 * Returns: the UTF-8 localizable label of the format, as a newly
248 * allocated string which should be g_free() by the caller.
250 gchar *
251 na_export_format_get_label( const NAExportFormat *format )
253 gchar *label;
255 g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), NULL );
257 label = NULL;
259 if( !format->private->dispose_has_run ){
261 label = g_strdup( gettext( format->private->str->label ));
264 return( label );
268 * na_export_format_get_description:
269 * @format: this #NAExportFormat object.
271 * Returns: the UTF-8 localizable description of the format, as a newly
272 * allocated string which should be g_free() by the caller.
274 gchar *
275 na_export_format_get_description( const NAExportFormat *format )
277 gchar *description;
279 g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), NULL );
281 description = NULL;
283 if( !format->private->dispose_has_run ){
285 description = g_strdup( gettext( format->private->str->description ));
288 return( description );
292 * na_export_format_get_exporter:
293 * @format: this #NAExportFormat object.
295 * Returns: a pointer to the #NAIExporter which provides this format.
297 * The pointer is owned by NAEportFormat class, and should not be released
298 * by the caller.
300 NAIExporter *
301 na_export_format_get_exporter( const NAExportFormat *format )
303 NAIExporter *exporter;
305 g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), NULL );
307 exporter = NULL;
309 if( !format->private->dispose_has_run ){
311 exporter = format->private->exporter;
314 return( exporter );