[nautilus-actions] na_xml_writer_output_xml() returns error messages
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions] na_xml_writer_output_xml() returns error messages
- Date: Wed, 28 Oct 2009 23:59:37 +0000 (UTC)
commit 03c3c58bb8891be2f57cfa5c4f61142ea8ac4557
Author: Pierre Wieser <pwieser trychlos org>
Date: Wed Oct 28 20:25:49 2009 +0100
na_xml_writer_output_xml() returns error messages
ChangeLog | 8 ++++++++
src/common/na-xml-writer.c | 37 +++++++++++++++++++++++++++----------
src/common/na-xml-writer.h | 2 +-
src/nact/nact-clipboard.c | 4 +++-
4 files changed, 39 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bbb9b9d..802caff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2009-10-28 Pierre Wieser <pwieser trychlos org>
+ * src/common/na-xml-writer.c:
+ * src/common/na-xml-writer.h:
+ (na_xml_writer_export): Returns a NULL filename if errors.
+ (na_xml_writer_output_xml): Returns error messages.
+
+ * src/nact/nact-clipboard.c
+ (export_row_object): Updated accordingly.
+
* src/utils/nautilus-actions-new.c:
Specify that the output directory must be specified as an URI.
diff --git a/src/common/na-xml-writer.c b/src/common/na-xml-writer.c
index 7da33b3..f3f09d9 100644
--- a/src/common/na-xml-writer.c
+++ b/src/common/na-xml-writer.c
@@ -286,13 +286,16 @@ xml_writer_new( const gchar *uuid )
* Can be NULL when exporting schemas ; in this case, format must be
* FORMAT_GCONF_SCHEMA.
* @folder: the directoy where to write the output XML file.
- * If NULL, the output will be directed to stdout.
+ * If NULL, the output will be directed to stdout.
+ * If not NULL, must be specified as an URI (e.g. file:///tmp)
* @format: the export format.
- * @msg: pointer to a buffer which will receive error messages.
+ * @msg: pointer to a #GSList which will receive error messages.
+ * The #GSList should be initialized to an empty list (NULL) before
+ * calling the function.
*
* Export the specified action as an XML file.
*
- * Returns: the written filename, or NULL if written to stdout.
+ * Returns: the written filename, or NULL if written to stdout or errors.
*/
gchar *
na_xml_writer_export( const NAObjectAction *action, const gchar *folder, gint format, GSList **msg )
@@ -338,11 +341,16 @@ na_xml_writer_export( const NAObjectAction *action, const gchar *folder, gint fo
xml_buffer = na_xml_writer_get_xml_buffer( action, format );
if( folder ){
- na_xml_writer_output_xml( xml_buffer, filename );
+ na_xml_writer_output_xml( xml_buffer, filename, msg );
} else {
g_print( "%s", xml_buffer );
}
+ if( *msg ){
+ g_free( filename );
+ filename = NULL;
+ }
+
g_free( xml_buffer );
return( filename );
@@ -483,30 +491,37 @@ na_xml_writer_get_xml_buffer( const NAObjectAction *action, gint format )
* Exports an action to the given filename.
*/
void
-na_xml_writer_output_xml( const gchar *xml, const gchar *filename )
+na_xml_writer_output_xml( const gchar *xml, const gchar *filename, GSList **msg )
{
static const gchar *thisfn = "na_xml_writer_output_xml";
GFile *file;
GFileOutputStream *stream;
GError *error = NULL;
+ gchar *errmsg;
g_return_if_fail( xml );
g_return_if_fail( filename && g_utf8_strlen( filename, -1 ));
file = g_file_new_for_uri( filename );
- stream = g_file_create( file, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error );
+ stream = g_file_replace( file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error );
if( error ){
- g_warning( "%s: %s", thisfn, error->message );
+ errmsg = g_strdup_printf( "%s: g_file_replace: %s", thisfn, error->message );
+ g_warning( errmsg );
+ *msg = g_slist_append( *msg, errmsg );
g_error_free( error );
- g_object_unref( stream );
+ if( stream ){
+ g_object_unref( stream );
+ }
g_object_unref( file );
return;
}
g_output_stream_write( G_OUTPUT_STREAM( stream ), xml, g_utf8_strlen( xml, -1 ), NULL, &error );
if( error ){
- g_warning( "%s: %s", thisfn, error->message );
+ errmsg = g_strdup_printf( "%s: g_output_stream_write: %s", thisfn, error->message );
+ g_warning( errmsg );
+ *msg = g_slist_append( *msg, errmsg );
g_error_free( error );
g_object_unref( stream );
g_object_unref( file );
@@ -515,7 +530,9 @@ na_xml_writer_output_xml( const gchar *xml, const gchar *filename )
g_output_stream_close( G_OUTPUT_STREAM( stream ), NULL, &error );
if( error ){
- g_warning( "%s: %s", thisfn, error->message );
+ errmsg = g_strdup_printf( "%s: g_output_stream_close: %s", thisfn, error->message );
+ g_warning( errmsg );
+ *msg = g_slist_append( *msg, errmsg );
g_error_free( error );
g_object_unref( stream );
g_object_unref( file );
diff --git a/src/common/na-xml-writer.h b/src/common/na-xml-writer.h
index dc4b680..d392f94 100644
--- a/src/common/na-xml-writer.h
+++ b/src/common/na-xml-writer.h
@@ -74,7 +74,7 @@ GType na_xml_writer_get_type( void );
gchar *na_xml_writer_export( const NAObjectAction *action, const gchar *folder, gint format, GSList **msg );
gchar *na_xml_writer_get_output_fname( const NAObjectAction *action, const gchar *folder, gint format );
gchar *na_xml_writer_get_xml_buffer( const NAObjectAction *action, gint format );
-void na_xml_writer_output_xml( const gchar *xml, const gchar *filename );
+void na_xml_writer_output_xml( const gchar *xml, const gchar *filename, GSList **msg );
G_END_DECLS
diff --git a/src/nact/nact-clipboard.c b/src/nact/nact-clipboard.c
index 869c825..cfaae31 100644
--- a/src/nact/nact-clipboard.c
+++ b/src/nact/nact-clipboard.c
@@ -528,6 +528,7 @@ export_row_object( NactClipboard *clipboard, NAObject *object, const gchar *dest
NAPivot *pivot;
gint format;
gchar *fname;
+ GSList *msg;
if( NA_IS_OBJECT_MENU( object )){
subitems = na_object_get_items_list( object );
@@ -544,6 +545,7 @@ export_row_object( NactClipboard *clipboard, NAObject *object, const gchar *dest
return( g_string_free( data, FALSE ));
}
+ msg = NULL;
buffer = NULL;
action = ( NAObjectAction * ) object;
if( NA_IS_OBJECT_PROFILE( object )){
@@ -567,7 +569,7 @@ export_row_object( NactClipboard *clipboard, NAObject *object, const gchar *dest
if( buffer && dest_folder ){
fname = na_xml_writer_get_output_fname( action, dest_folder, format );
- na_xml_writer_output_xml( buffer, fname );
+ na_xml_writer_output_xml( buffer, fname, &msg );
g_free( fname );
g_free( buffer );
buffer = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]