Fix export format ids documentation
[nautilus-actions.git] / src / test / test-reader.c
blob7f3d7ec9f283bb87cc1985e0f0ea5752e61936b4
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 <glib/gi18n.h>
36 #include <stdlib.h>
38 #include <api/na-core-utils.h>
40 #include <core/na-pivot.h>
41 #include <core/na-importer.h>
43 static gchar *uri = "";
44 static gboolean version = FALSE;
46 static GOptionEntry entries[] = {
48 { "uri" , 'u', 0, G_OPTION_ARG_STRING , &uri,
49 N_( "The URI of the file to be imported" ), N_( "<URI>" ) },
50 { NULL }
53 static GOptionEntry misc_entries[] = {
55 { "version" , 'v', 0, G_OPTION_ARG_NONE , &version,
56 N_( "Output the version number" ), NULL },
57 { NULL }
60 static GOptionContext *init_options( void );
61 static void check_options( int argc, char **argv, GOptionContext *context );
62 static void exit_with_usage( void );
64 int
65 main( int argc, char **argv )
67 NAImporterParms parms;
68 NAImporterResult *result;
70 g_type_init();
72 GOptionContext *context = init_options();
73 check_options( argc, argv, context );
75 NAPivot *pivot = na_pivot_new();
76 /* for test */
77 /*na_pivot_register_consumer( pivot, NA_IPIVOT_CONSUMER( self ));*/
78 na_pivot_set_automatic_reload( pivot, TRUE );
79 na_pivot_set_loadable( pivot, !PIVOT_LOAD_DISABLED & !PIVOT_LOAD_INVALID );
80 na_pivot_load_items( pivot );
81 /* for test - end */
83 parms.parent = NULL;
84 parms.uris = g_slist_prepend( NULL, uri );
85 parms.mode = IMPORTER_MODE_ASK;
86 parms.check_fn = NULL;
87 parms.check_fn_data = NULL;
89 guint code = na_importer_import_from_list( pivot, &parms );
91 g_print( "%s: return code from import is %u.\n", g_get_prgname(), code );
93 result = parms.results->data;
94 if( result->imported ){
95 na_object_dump( result->imported );
96 g_object_unref( result->imported );
99 na_core_utils_slist_dump( NULL, result->messages );
100 na_core_utils_slist_free( result->messages );
102 return( 0 );
105 static GOptionContext *
106 init_options( void )
108 GOptionContext *context;
109 gchar* description;
110 GOptionGroup *misc_group;
112 context = g_option_context_new( _( "Import a file." ));
114 #ifdef ENABLE_NLS
115 bindtextdomain( GETTEXT_PACKAGE, GNOMELOCALEDIR );
116 # ifdef HAVE_BIND_TEXTDOMAIN_CODESET
117 bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" );
118 # endif
119 textdomain( GETTEXT_PACKAGE );
120 g_option_context_add_main_entries( context, entries, GETTEXT_PACKAGE );
121 #else
122 g_option_context_add_main_entries( context, entries, NULL );
123 #endif
125 description = g_strdup_printf( "%s.\n%s", PACKAGE_STRING,
126 _( "Bug reports are welcomed at http://bugzilla.gnome.org,"
127 " or you may prefer to mail to <maintainer@nautilus-actions.org>.\n" ));
129 g_option_context_set_description( context, description );
131 g_free( description );
133 misc_group = g_option_group_new(
134 "misc", _( "Miscellaneous options" ), _( "Miscellaneous options" ), NULL, NULL );
135 g_option_group_add_entries( misc_group, misc_entries );
136 g_option_context_add_group( context, misc_group );
138 return( context );
141 static void
142 check_options( int argc, char **argv, GOptionContext *context )
144 GError *error = NULL;
146 if( argc == 1 ){
147 g_set_prgname( argv[0] );
148 gchar *help = g_option_context_get_help( context, FALSE, NULL );
149 g_print( "\n%s", help );
150 g_free( help );
151 exit( EXIT_SUCCESS );
154 if( !g_option_context_parse( context, &argc, &argv, &error )){
155 g_printerr( _( "Syntax error: %s\n" ), error->message );
156 g_error_free (error);
157 exit_with_usage();
160 g_option_context_free( context );
162 if( version ){
163 na_core_utils_print_version();
164 exit( EXIT_SUCCESS );
167 gint errors = 0;
169 if( !uri || !strlen( uri )){
170 g_printerr( _( "Error: uri is mandatory.\n" ));
171 errors += 1;
174 if( errors ){
175 exit_with_usage();
179 static void
180 exit_with_usage( void )
182 g_printerr( _( "Try %s --help for usage.\n" ), g_get_prgname());
183 exit( EXIT_FAILURE );