[nautilus-actions] Display a better message on write_item error



commit ccb0ad27da58f185a35a87d81f2ab530962a562b
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Mar 5 22:38:01 2010 +0100

    Display a better message on write_item error

 ChangeLog                 |    9 +++++++
 src/api/na-iio-provider.h |    2 +
 src/core/na-io-provider.c |   53 ++++++++++++++++++++++++++++++++++++++++++++-
 src/core/na-io-provider.h |    1 +
 src/nact/nact-window.c    |   16 +++++++++++--
 5 files changed, 77 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 928ef77..70c9c78 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-03-05 Pierre Wieser <pwieser trychlos org>
 
+	* src/api/na-iio-provider.h: Add a comment.
+
+	* src/core/na-io-provider.c:
+	* src/core/na-io-provider.h (na_io_provider_get_return_code_label):
+	New function.
+
+	* src/nact/nact-window.c (nact_window_save_item):
+	Better error message.
+
 	* src/nact/nact-export-ask.c (on_base_runtime_init_dialog):
 	Set more clear label, whether the item be a label or an action.
 
diff --git a/src/api/na-iio-provider.h b/src/api/na-iio-provider.h
index eaf4a7e..da313ec 100644
--- a/src/api/na-iio-provider.h
+++ b/src/api/na-iio-provider.h
@@ -224,6 +224,8 @@ enum {
 };
 
 /* return code of operations
+ * adding a new code here should imply also adding a new label
+ * in #na_io_provider_get_return_code_label().
  */
 enum {
 	NA_IIO_PROVIDER_CODE_OK = 0,
diff --git a/src/core/na-io-provider.c b/src/core/na-io-provider.c
index d12a2ea..487891f 100644
--- a/src/core/na-io-provider.c
+++ b/src/core/na-io-provider.c
@@ -1275,14 +1275,65 @@ na_io_provider_get_readonly_tooltip( guint reason )
 			tooltip = g_strdup( _( "The whole configuration has been locked down by an administrator." ));
 			break;
 
+		/* item is writable, so tooltip is empty */
 		case 0:
 			tooltip = g_strdup( "" );
 			break;
 
 		default:
-			tooltip = g_strdup_printf( _( "Item is not writable for an unknown reason (%d)" ), reason );
+			tooltip = g_strdup_printf( _( "Item is not writable for an unknown reason (%d).\n" \
+					"Please, be kind enough to fill out a bug report on http://bugzilla.gnome.org."; ), reason );
 			break;
 	}
 
 	return( tooltip );
 }
+
+/**
+ * na_io_provider_get_return_code_label:
+ * @code: the return code of an operation.
+ *
+ * Returns: the associated label, as a newly allocated string which
+ * should be g_free() by the caller.
+ */
+gchar *
+na_io_provider_get_return_code_label( guint code )
+{
+	gchar *label;
+
+	label = NULL;
+
+	switch( code ){
+		case NA_IIO_PROVIDER_CODE_OK:
+			label = g_strdup( _( "OK." ));
+			break;
+
+		case NA_IIO_PROVIDER_CODE_PROGRAM_ERROR:
+			label = g_strdup( _( "Program flow error.\n" \
+					"Please, be kind enough to fill out a bug report on http://bugzilla.gnome.org."; ));
+			break;
+
+		case NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN:
+			label = g_strdup( _( "The I/O provider is not willing to do that." ));
+			break;
+
+		case NA_IIO_PROVIDER_CODE_WRITE_ERROR:
+			label = g_strdup( _( "Write error in I/O provider." ));
+			break;
+
+		case NA_IIO_PROVIDER_CODE_DELETE_SCHEMAS_ERROR:
+			label = g_strdup( _( "Unable to delete GConf schemas." ));
+			break;
+
+		case NA_IIO_PROVIDER_CODE_DELETE_CONFIG_ERROR:
+			label = g_strdup( _( "Unable to delete configuration." ));
+			break;
+
+		default:
+			label = g_strdup_printf( _( "Unknow return code (%d).\n" \
+					"Please, be kind enough to fill out a bug report on http://bugzilla.gnome.org."; ), code );
+			break;
+	}
+
+	return( label );
+}
diff --git a/src/core/na-io-provider.h b/src/core/na-io-provider.h
index 636dddd..8f3f50c 100644
--- a/src/core/na-io-provider.h
+++ b/src/core/na-io-provider.h
@@ -102,6 +102,7 @@ guint          na_io_provider_write_item ( const NAIOProvider *provider, const N
 guint          na_io_provider_delete_item( const NAIOProvider *provider, const NAObjectItem *item, GSList **messages );
 
 gchar         *na_io_provider_get_readonly_tooltip( guint reason );
+gchar         *na_io_provider_get_return_code_label( guint code );
 
 G_END_DECLS
 
diff --git a/src/nact/nact-window.c b/src/nact/nact-window.c
index e231860..d40690f 100644
--- a/src/nact/nact-window.c
+++ b/src/nact/nact-window.c
@@ -326,6 +326,7 @@ nact_window_save_item( NactWindow *window, NAObjectItem *item )
 	NAUpdater *updater;
 	GSList *messages = NULL;
 	guint ret;
+	gchar *msgerr;
 
 	g_debug( "%s: window=%p, item=%p (%s)", thisfn,
 			( void * ) window, ( void * ) item, G_OBJECT_TYPE_NAME( item ));
@@ -338,16 +339,25 @@ nact_window_save_item( NactWindow *window, NAObjectItem *item )
 		updater = nact_application_get_updater( application );
 
 		ret = na_updater_write_item( updater, item, &messages );
-
 		g_debug( "nact_window_save_item: ret=%d", ret );
 
+		msgerr = NULL;
+
 		if( messages ){
+			msgerr = na_core_utils_slist_join_at_end( messages, "\n" );
+			na_core_utils_slist_free( messages );
+
+		} else if( ret != NA_IIO_PROVIDER_CODE_OK ){
+			msgerr = na_io_provider_get_return_code_label( ret );
+		}
+
+		if( msgerr ){
 			base_window_error_dlg(
 					BASE_WINDOW( window ),
 					GTK_MESSAGE_WARNING,
 					_( "An error has occured when trying to save the item" ),
-					( const gchar * ) messages->data );
-			na_core_utils_slist_free( messages );
+					msgerr );
+			g_free( msgerr );
 		}
 
 		save_ok = ( ret == NA_IIO_PROVIDER_CODE_OK );



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]