[nautilus-actions] Emit an error message if we are unable to save the level zero items list



commit 7e3bd054841e310f92214c1c4bb829965f0f2645
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Dec 13 06:58:20 2010 +0100

    Emit an error message if we are unable to save the level zero items list

 ChangeLog                         |    8 ++++++++
 src/core/na-io-provider.c         |    4 ++--
 src/core/na-iprefs.c              |    2 +-
 src/core/na-pivot.c               |   11 +++++++----
 src/core/na-pivot.h               |    2 +-
 src/nact/nact-main-menubar-file.c |   36 ++++++++++++++++++++++++++++--------
 6 files changed, 47 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ad1ade2..387562a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2010-12-13 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-pivot.c:
+	* src/core/na-pivot.h (na_pivot_write_level_zero):
+	Let the function returns error messages.
+
+	* src/core/na-io-provider.c (na_io_provider_get_writable_provider):
+	* src/nact/nact-main-menubar-file.c (nact_main_menubar_file_save_items):
+	Updated accordingly.
+
 	* src/core/na-iprefs.c:
 	* src/core/na-iprefs.h (na_iprefs_write_string_list):
 	Returns a writing status.
diff --git a/src/core/na-io-provider.c b/src/core/na-io-provider.c
index fc02a5c..dbf9f38 100644
--- a/src/core/na-io-provider.c
+++ b/src/core/na-io-provider.c
@@ -627,7 +627,7 @@ na_io_provider_get_writable_provider( const NAPivot *pivot )
 /*
  * na_io_provider_read_items:
  * @pivot: the #NAPivot object which owns the list of registered I/O
- * storage providers.
+ *  storage providers.
  * @messages: error messages.
  *
  * Loads the tree from I/O storage subsystems.
@@ -665,7 +665,7 @@ na_io_provider_read_items( const NAPivot *pivot, GSList **messages )
 
 	if( merged || !level_zero || !g_slist_length( level_zero )){
 		g_debug( "%s: rewriting level-zero", thisfn );
-		if( !na_pivot_write_level_zero( pivot, hierarchy )){
+		if( !na_pivot_write_level_zero( pivot, hierarchy, messages )){
 			g_warning( "%s: unable to update level-zero", thisfn );
 		}
 	}
diff --git a/src/core/na-iprefs.c b/src/core/na-iprefs.c
index 799b213..9685df2 100644
--- a/src/core/na-iprefs.c
+++ b/src/core/na-iprefs.c
@@ -462,7 +462,7 @@ na_iprefs_write_string_list( const NAIPrefs *instance, const gchar *key, GSList
 	gboolean ret = FALSE;
 	gchar *path;
 
-	g_return_if_fail( NA_IS_IPREFS( instance ), FALSE );
+	g_return_val_if_fail( NA_IS_IPREFS( instance ), FALSE );
 
 	if( st_initialized && !st_finalized ){
 
diff --git a/src/core/na-pivot.c b/src/core/na-pivot.c
index 10eec38..fb1cef2 100644
--- a/src/core/na-pivot.c
+++ b/src/core/na-pivot.c
@@ -683,6 +683,11 @@ time_val_diff( const GTimeVal *recent, const GTimeVal *old )
  * na_pivot_write_level_zero:
  * @pivot: this #NAPivot instance.
  * @items: the #GList of items whose first level is to be written.
+ * @messages: a pointer to a #GSList in which we will add happening
+ *  error messages;
+ *  the pointer may be %NULL;
+ *  if not %NULL, the #GSList must have been initialized by the
+ *  caller.
  *
  * Rewrite the level-zero items in GConf preferences.
  *
@@ -690,7 +695,7 @@ time_val_diff( const GTimeVal *recent, const GTimeVal *old )
  * and so on), %FALSE else.
  */
 gboolean
-na_pivot_write_level_zero( const NAPivot *pivot, GList *items )
+na_pivot_write_level_zero( const NAPivot *pivot, GList *items, GSList **messages )
 {
 	static const gchar *thisfn = "na_pivot_write_level_zero";
 	gboolean written;
@@ -716,11 +721,9 @@ na_pivot_write_level_zero( const NAPivot *pivot, GList *items )
 			}
 			content = g_slist_reverse( content );
 
-			na_iprefs_write_string_list( NA_IPREFS( pivot ), IPREFS_LEVEL_ZERO_ITEMS, content );
+			written = na_iprefs_write_string_list( NA_IPREFS( pivot ), IPREFS_LEVEL_ZERO_ITEMS, content );
 
 			na_core_utils_slist_free( content );
-
-			written = TRUE;
 		}
 	}
 
diff --git a/src/core/na-pivot.h b/src/core/na-pivot.h
index 84eb377..f6a91b5 100644
--- a/src/core/na-pivot.h
+++ b/src/core/na-pivot.h
@@ -141,7 +141,7 @@ void          na_pivot_set_new_items( NAPivot *pivot, GList *tree );
 
 void          na_pivot_item_changed_handler( NAIIOProvider *provider, const gchar *id, NAPivot *pivot  );
 
-gboolean      na_pivot_write_level_zero( const NAPivot *pivot, GList *items );
+gboolean      na_pivot_write_level_zero( const NAPivot *pivot, GList *items, GSList **messages );
 
 /* NAIPivotConsumer interface management
  */
diff --git a/src/nact/nact-main-menubar-file.c b/src/nact/nact-main-menubar-file.c
index 280eb77..1a19283 100644
--- a/src/nact/nact-main-menubar-file.c
+++ b/src/nact/nact-main-menubar-file.c
@@ -34,6 +34,8 @@
 
 #include <glib/gi18n.h>
 
+#include <api/na-core-utils.h>
+
 #include <core/na-io-provider.h>
 
 #include "nact-application.h"
@@ -42,7 +44,10 @@
 #include "nact-main-tab.h"
 #include "nact-main-menubar-file.h"
 
-static guint st_event_autosave = 0;
+static guint  st_event_autosave   = 0;
+
+static gchar *st_save_error       = N_( "Save error" );
+static gchar *st_level_zero_write = N_( "Unable to rewrite the level-zero items list" );
 
 static void     save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item );
 static gboolean autosave_callback( NactMainWindow *window );
@@ -262,6 +267,8 @@ nact_main_menubar_file_save_items( NactMainWindow *window )
 	gchar *label;
 	GList *new_pivot;
 	NAObjectItem *duplicate;
+	GSList *messages;
+	gchar *msg;
 
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
 
@@ -271,22 +278,35 @@ nact_main_menubar_file_save_items( NactMainWindow *window )
 	 */
 	na_ipivot_consumer_allow_notify( NA_IPIVOT_CONSUMER( window ), FALSE, 0 );
 
-	/* remove deleted items
-	 * so that new actions with same id do not risk to be deleted later
-	 */
-	nact_main_window_remove_deleted( window );
-
-	/* always write the level zero list of items
+	/* always write the level zero list of items as the first save phase
 	 * and reset the corresponding modification flag
 	 */
 	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
 	updater = nact_application_get_updater( application );
 	items = nact_iactions_list_bis_get_items( NACT_IACTIONS_LIST( window ));
+	messages = NULL;
+
+	if( !na_pivot_write_level_zero( NA_PIVOT( updater ), items, &messages )){
+
+		if( g_slist_length( messages )){
+			msg = na_core_utils_slist_join_at_end( messages, "\n" );
+		} else {
+			msg = g_strdup( st_level_zero_write );
+		}
+		base_window_error_dlg( BASE_WINDOW( window ), GTK_MESSAGE_ERROR, st_save_error, msg );
+		g_free( msg );
+		na_core_utils_slist_free( messages );
+		return;
+	}
 
-	na_pivot_write_level_zero( NA_PIVOT( updater ), items );
 	mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
 	mis->level_zero_order_changed = FALSE;
 
+	/* remove deleted items
+	 * so that new actions with same id do not risk to be deleted later
+	 */
+	nact_main_window_remove_deleted( window );
+
 	/* recursively save the modified items
 	 * check is useless here if item was not modified, but not very costly
 	 * above all, it is less costly to check the status here, than to check



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