[nautilus-actions: 24/45] Fix new imported profiles check status



commit dadec65ab3c273c0ac5d2fe0f848270cdff56b18
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Jul 27 18:59:39 2009 +0200

    Fix new imported profiles check status

 ChangeLog                   |    7 +++
 TODO                        |   14 ++-----
 src/common/na-action.c      |   15 +++++++
 src/common/na-object.c      |   22 ++++++++++-
 src/common/na-object.h      |   19 +++++++--
 src/common/na-pivot.c       |   10 ++--
 src/nact/nact-imenubar.c    |   51 ++++++++++++++++++++++++
 src/nact/nact-imenubar.h    |    1 +
 src/nact/nact-main-window.c |   91 +++++++++++++++---------------------------
 9 files changed, 151 insertions(+), 79 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index aad09d7..f3d6ec5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-07-27 Pierre Wieser <pwieser trychlos org>
 
+	* src/common/na-object.c:
+	* src/common/na-object.h (na_object_check_edited_status):
+	New derivable function.
+
+	* src/common/na-action.c:
+	Implements check_edited_status for profiles.
+
 	* src/common/na-utils.c:
 	* src/common/na-utils.h (na_utils_path_to_key):
 	New function moved from na-gconf.c.
diff --git a/TODO b/TODO
index 9c06142..c7df89d 100644
--- a/TODO
+++ b/TODO
@@ -7,21 +7,15 @@
 - i18n doen't works in the command line tool and for some part of NACT 
 like the scheme list, it seems.
 
-- Add better error handling in import/export stuff of nact and some feedback to
-user throught error dialog when import/export failed.
-
 - na-action and na-action-profile are included in nact-window.h
   so are not needed in all other derived window files
 
 - try to import a schema for an action (without schema)
 
-- see if we could define signals in base classes, and if this signals
-  can be caught by interfaces - this would prevent us to define and
-  call specific api (initial_load, runtime_init, etc)
-
-- is it required to pass an action or a profile at initial_load ??
-  (would be better only at runtime_init)
-
 - gtk_window_set_transient_for (see nact-conditions-editor.c) should be
   called in base_window_do_initial_load, but requires a parent window
   which should be passed as a virtual or in the constructor
+
+- when importing multi-profile actions, profiles are not marked as modified
+
+- reload actions : doesn't work ?? nothing appears in the ui
diff --git a/src/common/na-action.c b/src/common/na-action.c
index 7be1555..91a485b 100644
--- a/src/common/na-action.c
+++ b/src/common/na-action.c
@@ -105,6 +105,7 @@ static void      instance_set_property( GObject *object, guint property_id, cons
 static void      instance_dispose( GObject *object );
 static void      instance_finalize( GObject *object );
 
+static void      object_check_edited_status( const NAObject *action );
 static void      object_dump( const NAObject *action );
 static NAObject *object_duplicate( const NAObject *action );
 static void      object_copy( NAObject *target, const NAObject *source );
@@ -213,6 +214,7 @@ class_init( NAActionClass *klass )
 	klass->private = g_new0( NAActionClassPrivate, 1 );
 
 	NA_OBJECT_CLASS( klass )->dump = object_dump;
+	NA_OBJECT_CLASS( klass )->check_edited_status = object_check_edited_status;
 	NA_OBJECT_CLASS( klass )->duplicate = object_duplicate;
 	NA_OBJECT_CLASS( klass )->copy = object_copy;
 	NA_OBJECT_CLASS( klass )->are_equal = object_are_equal;
@@ -931,6 +933,19 @@ na_action_get_profiles_count( const NAAction *action )
 }
 
 static void
+object_check_edited_status( const NAObject *action )
+{
+	if( st_parent_class->check_edited_status ){
+		st_parent_class->check_edited_status( action );
+	}
+
+	GSList *ip;
+	for( ip = NA_ACTION( action )->private->profiles ; ip ; ip = ip->next ){
+		na_object_check_edited_status( NA_OBJECT( ip->data ));
+	}
+}
+
+static void
 object_dump( const NAObject *action )
 {
 	static const gchar *thisfn = "na_action_object_dump";
diff --git a/src/common/na-object.c b/src/common/na-object.c
index 48426e5..507b4f0 100644
--- a/src/common/na-object.c
+++ b/src/common/na-object.c
@@ -67,12 +67,14 @@ static void      instance_set_property( GObject *object, guint property_id, cons
 static void      instance_dispose( GObject *object );
 static void      instance_finalize( GObject *object );
 
+static void      v_check_edited_status( const NAObject *object );
 static NAObject *v_duplicate( const NAObject *object );
 static void      v_copy( NAObject *target, const NAObject *source );
 static gboolean  v_are_equal( const NAObject *a, const NAObject *b );
 static gboolean  v_is_valid( const NAObject *object );
 
 static void      do_dump( const NAObject *object );
+static void      do_check_edited_status( const NAObject *object );
 static void      do_copy( NAObject *target, const NAObject *source );
 static gboolean  do_are_equal( const NAObject *a, const NAObject *b );
 static gboolean  do_is_valid( const NAObject *object );
@@ -159,6 +161,7 @@ class_init( NAObjectClass *klass )
 	klass->private = g_new0( NAObjectClassPrivate, 1 );
 
 	klass->dump = do_dump;
+	klass->check_edited_status = do_check_edited_status;
 	klass->duplicate = NULL;
 	klass->copy = do_copy;
 	klass->are_equal = do_are_equal;
@@ -339,7 +342,7 @@ na_object_check_edited_status( const NAObject *object )
 {
 	g_assert( NA_IS_OBJECT( object ));
 
-	na_iduplicable_check_edited_status( object );
+	v_check_edited_status( object );
 }
 
 /**
@@ -524,6 +527,17 @@ na_object_set_label( NAObject *object, const gchar *label )
 	g_object_set( G_OBJECT( object ), PROP_NAOBJECT_LABEL_STR, label, NULL );
 }
 
+static void
+v_check_edited_status( const NAObject *object )
+{
+	if( NA_OBJECT_GET_CLASS( object )->check_edited_status ){
+		NA_OBJECT_GET_CLASS( object )->check_edited_status( object );
+
+	} else {
+		do_check_edited_status( object );
+	}
+}
+
 static NAObject *
 v_duplicate( const NAObject *object )
 {
@@ -577,6 +591,12 @@ do_dump( const NAObject *object )
 }
 
 static void
+do_check_edited_status( const NAObject *object )
+{
+	na_iduplicable_check_edited_status( object );
+}
+
+static void
 do_copy( NAObject *target, const NAObject *source )
 {
 	gchar *id = na_object_get_id( source );
diff --git a/src/common/na-object.h b/src/common/na-object.h
index a863123..95bd1b6 100644
--- a/src/common/na-object.h
+++ b/src/common/na-object.h
@@ -83,7 +83,16 @@ typedef struct {
 	 * implementation should call its parent class before actually
 	 * dumping its own data and properties.
 	 */
-	void       ( *dump )     ( const NAObject *object );
+	void       ( *dump )               ( const NAObject *object );
+
+	/**
+	 * check_edited_status:
+	 * @object: the #NAObject-derived object to be checked.
+	 *
+	 * Checks a #NAObject-derived object for modification and validity
+	 * status.
+	 */
+	void       ( *check_edited_status )( const NAObject *object );
 
 	/**
 	 * duplicate:
@@ -100,7 +109,7 @@ typedef struct {
 	 * Returns: a newly allocated object, which is an exact copy of
 	 * @object.
 	 */
-	NAObject * ( *duplicate )( const NAObject *object );
+	NAObject * ( *duplicate )          ( const NAObject *object );
 
 	/**
 	 * copy:
@@ -112,7 +121,7 @@ typedef struct {
 	 * Each derived class should take care of calling its parent class
 	 * to complete the copy.
 	 */
-	void       ( *copy )     ( NAObject *target, const NAObject *source );
+	void       ( *copy )               ( NAObject *target, const NAObject *source );
 
 	/**
 	 * are_equal:
@@ -127,7 +136,7 @@ typedef struct {
 	 *
 	 * Returns: %TRUE if @a and @b are identical, %FALSE else.
 	 */
-	gboolean   ( *are_equal )( const NAObject *a, const NAObject *b );
+	gboolean   ( *are_equal )          ( const NAObject *a, const NAObject *b );
 
 	/**
 	 * is_valid:
@@ -143,7 +152,7 @@ typedef struct {
 	 *
 	 * Returns: %TRUE if @object is valid, %FALSE else.
 	 */
-	gboolean   ( *is_valid ) ( const NAObject *object );
+	gboolean   ( *is_valid )           ( const NAObject *object );
 }
 	NAObjectClass;
 
diff --git a/src/common/na-pivot.c b/src/common/na-pivot.c
index 593d1e7..0c60be7 100644
--- a/src/common/na-pivot.c
+++ b/src/common/na-pivot.c
@@ -67,7 +67,7 @@ struct NAPivotPrivate {
 	/* list of actions
 	 */
 	GSList  *actions;
-	gboolean reload;
+	gboolean automatic_reload;
 };
 
 enum {
@@ -171,7 +171,7 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self->private->notified = NULL;
 	self->private->providers = register_interface_providers( self );
 	self->private->actions = na_iio_provider_read_actions( self );
-	self->private->reload = TRUE;
+	self->private->automatic_reload = TRUE;
 }
 
 static GSList *
@@ -547,7 +547,7 @@ na_pivot_get_automatic_reload( const NAPivot *pivot )
 {
 	g_assert( NA_IS_PIVOT( pivot ));
 
-	return( pivot->private->reload );
+	return( pivot->private->automatic_reload );
 }
 
 /**
@@ -569,7 +569,7 @@ na_pivot_set_automatic_reload( NAPivot *pivot, gboolean reload )
 {
 	g_assert( NA_IS_PIVOT( pivot ));
 
-	pivot->private->reload = reload;
+	pivot->private->automatic_reload = reload;
 }
 
 static void
@@ -633,7 +633,7 @@ on_actions_changed_timeout( gpointer user_data )
 		return( TRUE );
 	}
 
-	if( pivot->private->reload ){
+	if( pivot->private->automatic_reload ){
 		na_pivot_free_actions( pivot->private->actions );
 		pivot->private->actions = na_iio_provider_read_actions( pivot );
 	}
diff --git a/src/nact/nact-imenubar.c b/src/nact/nact-imenubar.c
index 24a0246..605b0d5 100644
--- a/src/nact/nact-imenubar.c
+++ b/src/nact/nact-imenubar.c
@@ -81,6 +81,8 @@ static void       on_duplicate_activated( GtkMenuItem *item, NactWindow *window
 static void       on_duplicate_selected( GtkItem *item, NactWindow *window );
 static void       on_delete_activated( GtkMenuItem *item, NactWindow *window );
 static void       on_delete_selected( GtkItem *item, NactWindow *window );
+static void       on_reload_activated( GtkMenuItem *item, NactWindow *window );
+static void       on_reload_selected( GtkItem *item, NactWindow *window );
 
 static void       on_tools_selected( GtkMenuItem *item, NactWindow *window );
 static void       on_import_activated( GtkMenuItem *item, NactWindow *window );
@@ -111,6 +113,7 @@ static void       v_update_actions_list( NactWindow *window );
 static void       v_select_actions_list( NactWindow *window, GType type, const gchar *uuid, const gchar *label );
 static gint       v_count_actions( NactWindow *window );
 static gint       v_count_modified_actions( NactWindow *window );
+static void       v_reload_actions( NactWindow *window );
 static void       v_on_save( NactWindow *window );
 
 static guint      get_status_context( NactMainWindow *window );
@@ -321,6 +324,14 @@ create_edit_menu( NactMainWindow *window, GtkMenuBar *menubar )
 	gtk_menu_shell_append( GTK_MENU_SHELL( menu ), item );
 	set_delete_item( NACT_WINDOW( window ), item );
 	signal_connect( window, item, G_CALLBACK( on_delete_activated ), G_CALLBACK( on_delete_selected ));
+
+	item = gtk_separator_menu_item_new();
+	gtk_menu_shell_append( GTK_MENU_SHELL( menu ), item );
+
+	item = gtk_image_menu_item_new_with_label( _( "_Reload the list of actions" ));
+	gtk_menu_item_set_use_underline( GTK_MENU_ITEM( item ), TRUE );
+	gtk_menu_shell_append( GTK_MENU_SHELL( menu ), item );
+	signal_connect( window, item, G_CALLBACK( on_reload_activated ), G_CALLBACK( on_reload_selected ));
 }
 
 static void
@@ -696,6 +707,38 @@ on_delete_selected( GtkItem *item, NactWindow *window )
 }
 
 static void
+on_reload_activated( GtkMenuItem *item, NactWindow *window )
+{
+	static const gchar *thisfn = "nact_imenubar_on_reload_activated";
+	g_debug( "%s: item=%p, window=%p", thisfn, item, window );
+
+	gboolean ok = TRUE;
+
+	if( v_count_modified_actions( window )){
+
+		/* i18n: message before reloading the list of actions */
+		gchar *first = g_strdup( _( "This will cancel your current modifications." ));
+		gchar *second = g_strdup( _( "Are you sure this is what you want ?" ));
+
+		ok = base_window_yesno_dlg( BASE_WINDOW( window ), GTK_MESSAGE_QUESTION, first, second );
+
+		g_free( second );
+		g_free( first );
+	}
+
+	if( ok ){
+		v_reload_actions( window );
+	}
+}
+
+static void
+on_reload_selected( GtkItem *item, NactWindow *window )
+{
+	/* i18n: tooltip displayed in the status bar when selecting the 'Reload' item */
+	display_status( window, _( " Cancel your current modifications and reload the list of actions." ));
+}
+
+static void
 on_tools_selected( GtkMenuItem *item, NactWindow *window )
 {
 	gboolean export_enabled = v_count_actions( window );
@@ -973,6 +1016,14 @@ v_count_modified_actions( NactWindow *window )
 }
 
 static void
+v_reload_actions( NactWindow *window )
+{
+	if( NACT_IMENUBAR_GET_INTERFACE( window )->reload_actions ){
+		NACT_IMENUBAR_GET_INTERFACE( window )->reload_actions( window );
+	}
+}
+
+static void
 v_on_save( NactWindow *window )
 {
 	if( NACT_IMENUBAR_GET_INTERFACE( window )->on_save ){
diff --git a/src/nact/nact-imenubar.h b/src/nact/nact-imenubar.h
index 9bcbc31..024255d 100644
--- a/src/nact/nact-imenubar.h
+++ b/src/nact/nact-imenubar.h
@@ -69,6 +69,7 @@ typedef struct {
 	void        ( *select_actions_list )   ( NactWindow *window, GType type, const gchar *uuid, const gchar *label );
 	gint        ( *count_actions )         ( NactWindow *window );
 	gint        ( *count_modified_actions )( NactWindow *window );
+	void        ( *reload_actions )        ( NactWindow *window );
 	void        ( *on_save )               ( NactWindow *window );
 }
 	NactIMenubarInterface;
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 32661c8..3797505 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -108,7 +108,6 @@ static void             set_current_profile( NactMainWindow *window, gboolean se
 static NAAction        *get_edited_action( NactWindow *window );
 static NAActionProfile *get_edited_profile( NactWindow *window );
 static void             on_modified_field( NactWindow *window );
-static void             check_edited_status( NactWindow *window, const NAAction *action );
 static gboolean         is_modified_action( NactWindow *window, const NAAction *action );
 static gboolean         is_valid_action( NactWindow *window, const NAAction *action );
 static gboolean         is_modified_profile( NactWindow *window, const NAActionProfile *profile );
@@ -135,6 +134,8 @@ static void             update_actions_list( NactWindow *window );
 static gboolean         on_delete_event( BaseWindow *window, GtkWindow *toplevel, GdkEvent *event );
 static gint             count_actions( NactWindow *window );
 static gint             count_modified_actions( NactWindow *window );
+static void             reload_actions( NactWindow *window );
+static GSList          *free_actions( GSList *actions );
 static void             on_save( NactWindow *window );
 static void             on_actions_changed( NAIPivotConsumer *instance, gpointer user_data );
 
@@ -342,6 +343,7 @@ imenubar_iface_init( NactIMenubarInterface *iface )
 	iface->select_actions_list = nact_iactions_list_set_selection;
 	iface->count_actions = count_actions;
 	iface->count_modified_actions = count_modified_actions;
+	iface->reload_actions = reload_actions;
 	iface->on_save = on_save;
 }
 
@@ -385,13 +387,8 @@ instance_dispose( GObject *window )
 		gint pos = gtk_paned_get_position( GTK_PANED( pane ));
 		nact_iprefs_set_int( NACT_WINDOW( window ), "main-paned", pos );
 
-		GSList *ia;
-		for( ia = self->private->actions ; ia ; ia = ia->next ){
-			g_object_unref( NA_ACTION( ia->data ));
-		}
-		g_slist_free( self->private->actions );
-
-		free_deleted_actions( NACT_WINDOW( self ));
+		self->private->actions = free_actions( self->private->actions );
+		self->private->deleted = free_actions( self->private->deleted );
 
 		nact_iaction_tab_dispose( NACT_WINDOW( window ));
 		nact_icommand_tab_dispose( NACT_WINDOW( window ));
@@ -751,56 +748,13 @@ on_modified_field( NactWindow *window )
 {
 	g_assert( NACT_IS_MAIN_WINDOW( window ));
 
-	check_edited_status( window, NACT_MAIN_WINDOW( window )->private->edited_action );
+	na_object_check_edited_status( NA_OBJECT( NACT_MAIN_WINDOW( window )->private->edited_action ));
 
 	setup_dialog_title( window );
 
 	nact_iactions_list_update_selected( window, NACT_MAIN_WINDOW( window )->private->edited_action );
 }
 
-/*
- * is it modified ?
- * and, if it has been modified, is it valid ?
- */
-static void
-check_edited_status( NactWindow *window, const NAAction *edited )
-{
-	g_assert( edited );
-
-	na_object_check_edited_status( NA_OBJECT( edited ));
-	/*NactApplication *application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
-	NAPivot *pivot = NA_PIVOT( nact_application_get_pivot( application ));
-	gchar *uuid = na_action_get_uuid( edited );
-	NAAction *original = NA_ACTION( na_pivot_get_action( pivot, uuid ));
-	g_free( uuid );
-	gboolean is_modified = !na_object_are_equal( NA_OBJECT( edited ), NA_OBJECT( original ));
-	g_object_set_data( G_OBJECT( edited ), "nact-main-window-action-modified", GINT_TO_POINTER( is_modified ));*/
-
-	/*gboolean check = is_action_modified( edited );
-	g_debug( "check_edited_status: edited=%p, is_modified=%s, check=%s", edited, is_modified ? "True":"False", check ? "True":"False" );*/
-
-	/*gboolean a_valid = TRUE;
-	if( is_modified ){
-		gchar *label = na_action_get_label( edited );
-		if( label && g_utf8_strlen( label, -1 )){
-			GSList *ip;
-			gboolean p_valid = FALSE;
-			GSList *profiles = na_action_get_profiles( edited );
-			for( ip = profiles ; ip ; ip = ip->next ){
-				NAActionProfile *prof = NA_ACTION_PROFILE( ip->data );
-				gchar *prof_label = na_action_profile_get_label( prof );
-				if( prof_label && g_utf8_strlen( prof_label, -1 )){
-					p_valid = TRUE;
-				}
-				g_object_set_data( G_OBJECT( prof ), "nact-main-window-profile-is-valid", GINT_TO_POINTER( p_valid ));
-				g_free( prof_label );
-			}
-			g_free( label );
-		}
-	}
-	g_object_set_data( G_OBJECT( edited ), "nact-main-window-action-is-valid", GINT_TO_POINTER( a_valid ));*/
-}
-
 static gboolean
 is_modified_action( NactWindow *window, const NAAction *action )
 {
@@ -877,12 +831,8 @@ static void
 free_deleted_actions( NactWindow *window )
 {
 	NactMainWindow *self = NACT_MAIN_WINDOW( window );
-	GSList *ia;
-	for( ia = self->private->deleted ; ia ; ia = ia->next ){
-		g_object_unref( NA_ACTION( ia->data ));
-	}
-	g_slist_free( self->private->deleted );
-	self->private->deleted = NULL;
+
+	self->private->deleted = free_actions( self->private->deleted );
 }
 
 static void
@@ -1106,6 +1056,31 @@ count_modified_actions( NactWindow *window )
 	return( count );
 }
 
+static void
+reload_actions( NactWindow *window )
+{
+	NactMainWindow *self = NACT_MAIN_WINDOW( window );
+	self->private->actions = free_actions( self->private->actions );
+	self->private->deleted = free_actions( self->private->deleted );
+
+	NactApplication *application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+	NAPivot *pivot = nact_application_get_pivot( application );
+	na_pivot_reload_actions( pivot );
+	self->private->actions = na_pivot_get_duplicate_actions( pivot );
+	self->private->initial_count = g_slist_length( self->private->actions );
+}
+
+static GSList *
+free_actions( GSList *actions )
+{
+	GSList *ia;
+	for( ia = actions ; ia ; ia = ia->next ){
+		g_object_unref( NA_ACTION( ia->data ));
+	}
+	g_slist_free( actions );
+	return( NULL );
+}
+
 /*
  * in initial_load_toplevel(), we have forbidden the automatic reload
  * of the list of actions in NAPivot, as we take care of updating it of



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