[nautilus-actions] Call parent class methods from derived classes



commit ae51ee06a7f5c1170083bcf84ff3644f0a03a502
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Jan 23 10:38:50 2011 +0100

    Call parent class methods from derived classes

 ChangeLog                   |    8 ++++++++
 src/nact/base-window.c      |   20 +++++++++-----------
 src/nact/base-window.h      |   17 +++++++----------
 src/nact/nact-main-window.c |   10 ++++++++++
 4 files changed, 34 insertions(+), 21 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f5817c0..a14d17a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2011-01-22 Pierre Wieser <pwieser trychlos org>
 
+	* src/nact/base-window.c: Handles the recorded signals in a GList.
+
+	* src/nact/base-window.h (is_willing_to_quit): Fix the comment.
+
+	* src/nact/nact-main-window.c
+	(base_is_willing_to_quit, on_base_initialize_gtk_toplevel):
+	Calls the parent class method if willing to quit.
+
 	* src/nact/nact-window.c:
 	* src/nact/nact-window.h
 	(nact_window_is_item_writable): Remove unused function.
diff --git a/src/nact/base-window.c b/src/nact/base-window.c
index 57f6a45..7b46676 100644
--- a/src/nact/base-window.c
+++ b/src/nact/base-window.c
@@ -66,7 +66,7 @@ struct _BaseWindowPrivate {
 	GtkWindow       *gtk_toplevel;
 	gboolean         initialized;
 
-	GSList          *signals;
+	GList           *signals;
 	gboolean         save_window_position;
 	BaseBuilder     *builder;
 };
@@ -77,7 +77,7 @@ typedef struct {
 	gpointer instance;
 	gulong   handler_id;
 }
-	BaseWindowRecordedSignal;
+	RecordedSignal;
 
 /* instance properties
  */
@@ -436,7 +436,7 @@ instance_dispose( GObject *window )
 {
 	static const gchar *thisfn = "base_window_instance_dispose";
 	BaseWindow *self;
-	GSList *is;
+	GList *is;
 
 	g_return_if_fail( BASE_IS_WINDOW( window ));
 
@@ -453,7 +453,7 @@ instance_dispose( GObject *window )
 		/* signals must be deconnected before quitting main loop
 		 */
 		for( is = self->private->signals ; is ; is = is->next ){
-			BaseWindowRecordedSignal *str = ( BaseWindowRecordedSignal * ) is->data;
+			RecordedSignal *str = ( RecordedSignal * ) is->data;
 			if( g_signal_handler_is_connected( str->instance, str->handler_id )){
 				g_signal_handler_disconnect( str->instance, str->handler_id );
 				if( st_debug_signal_connect ){
@@ -462,7 +462,7 @@ instance_dispose( GObject *window )
 			}
 			g_free( str );
 		}
-		g_slist_free( self->private->signals );
+		g_list_free( self->private->signals );
 
 		if( is_main_window( BASE_WINDOW( window ))){
 			g_debug( "%s: quitting main window", thisfn );
@@ -1005,10 +1005,8 @@ base_window_is_willing_to_quit( const BaseWindow *window )
 
 	if( !window->private->dispose_has_run ){
 
-		for( class = G_OBJECT_GET_CLASS( window ) ; willing_to && BASE_IS_WINDOW_CLASS( class ) ; class = g_type_class_peek_parent( class )){
-			if( BASE_WINDOW_CLASS( class )->is_willing_to_quit ){
-				willing_to = BASE_WINDOW_CLASS( class )->is_willing_to_quit( window );
-			}
+		if( BASE_WINDOW_GET_CLASS( window )->is_willing_to_quit ){
+			BASE_WINDOW_GET_CLASS( window )->is_willing_to_quit( window );
 		}
 	}
 
@@ -1279,10 +1277,10 @@ record_connected_signal( BaseWindow *window, GObject *instance, gulong handler_i
 {
 	static const gchar *thisfn = "base_window_record_connected_signal";
 
-	BaseWindowRecordedSignal *str = g_new0( BaseWindowRecordedSignal, 1 );
+	RecordedSignal *str = g_new0( RecordedSignal, 1 );
 	str->instance = instance;
 	str->handler_id = handler_id;
-	window->private->signals = g_slist_prepend( window->private->signals, str );
+	window->private->signals = g_list_prepend( window->private->signals, str );
 
 	if( st_debug_signal_connect ){
 		g_debug( "%s: connecting signal handler %p:%lu", thisfn, ( void * ) instance, handler_id );
diff --git a/src/nact/base-window.h b/src/nact/base-window.h
index ea5a6ac..9e97549 100644
--- a/src/nact/base-window.h
+++ b/src/nact/base-window.h
@@ -159,7 +159,7 @@ typedef struct {
 	 * dialog_response:
 	 * @window: this #BaseWindow instance.
 	 */
-	gboolean ( *dialog_response )      ( GtkDialog *dialog, gint code, BaseWindow *window );
+	gboolean ( *dialog_response )        ( GtkDialog *dialog, gint code, BaseWindow *window );
 
 	/**
 	 * delete_event:
@@ -170,7 +170,7 @@ typedef struct {
 	 * can so implement the virtual function, without having to take
 	 * care of the signal itself.
 	 */
-	gboolean ( *delete_event )         ( BaseWindow *window, GtkWindow *toplevel, GdkEvent *event );
+	gboolean ( *delete_event )           ( BaseWindow *window, GtkWindow *toplevel, GdkEvent *event );
 
 	/**
 	 * get_iprefs_window_id:
@@ -182,7 +182,7 @@ typedef struct {
 	 * This delegates to #BaseWindow-derived classes the NactIPrefs
 	 * interface virtual function.
 	 */
-	gchar *  ( *get_iprefs_window_id ) ( const BaseWindow *window );
+	gchar *  ( *get_iprefs_window_id )   ( const BaseWindow *window );
 
 	/**
 	 * is_willing_to_quit:
@@ -191,17 +191,14 @@ typedef struct {
 	 * Invoked (e.g. by the session manager) when the application
 	 * has been asked for to terminate itself.
 	 *
-	 * The BaseWindow class takes care of successively invoking the
-	 * is_willing_to_quit() method of each derived class, starting from
-	 * the topmost derived class, up to the BaseWindow itself.
-	 *
-	 * As soon as one of these method returns %FALSE, the loop is
-	 * stopped.
+	 * Unless the derived class is not willing to quit, it should call
+	 * its parent class method, in order to give it a chance to also
+	 * refuse the termination of the application.
 	 *
 	 * The derived method should return %TRUE if it is willing to quit,
 	 * %FALSE else.
 	 */
-	gboolean ( *is_willing_to_quit )   ( const BaseWindow *window );
+	gboolean ( *is_willing_to_quit )     ( const BaseWindow *window );
 }
 	BaseWindowClass;
 
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index cb9f689..c069473 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -1112,6 +1112,11 @@ base_is_willing_to_quit( const BaseWindow *window )
 		willing_to = nact_confirm_logout_run( NACT_MAIN_WINDOW( window ));
 	}
 
+	/* call parent class */
+	if( willing_to && BASE_APPLICATION_CLASS( st_parent_class )->is_willing_to_quit ){
+		willing_to = BASE_APPLICATION_CLASS( st_parent_class )->is_willing_to_quit( window );
+	}
+
 	return( willing_to );
 }
 
@@ -1165,6 +1170,11 @@ on_base_initialize_gtk_toplevel( BaseWindow *window, GtkWindow *toplevel )
 		nact_iproperties_tab_initial_load_toplevel( NACT_IPROPERTIES_TAB( window ));
 
 		nact_main_statusbar_initial_load_toplevel( main_window );
+
+		/* call parent class */
+		if( ret && BASE_APPLICATION_CLASS( st_parent_class )->initialize_gtk_toplevel ){
+			ret = BASE_APPLICATION_CLASS( st_parent_class )->initialize_gtk_toplevel( window, toplevel );
+		}
 	}
 }
 



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