[nautilus-actions] BaseApplication::manage_options has the exit code as an argument



commit 159c14fbfe9cf7faf6797068a844e7f531f285d7
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Jan 20 23:56:14 2011 +0100

    BaseApplication::manage_options has the exit code as an argument
    
    This will let us get ride of having the exit code as a BaseApplication object member.

 ChangeLog                         |    4 ++
 src/nact/base-application-class.h |   90 ++++++++++++++++++++++++++++++-------
 src/nact/base-application.c       |   13 +++---
 src/nact/nact-application.c       |    6 +-
 4 files changed, 88 insertions(+), 25 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1b0a9de..e73b505 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-01-20 Pierre Wieser <pwieser trychlos org>
 
+	* src/nact/base-application-class.h (manage_options):
+	* src/nact/base-application.c:
+	* src/nact/nact-application.c: Return exit code of the program.
+
 	* src/nact/nact-tree-model-dnd.c
 	(drop_inside, is_drop_possible, drop_uri_list):
 	* src/nact/base-window.c (is_main):
diff --git a/src/nact/base-application-class.h b/src/nact/base-application-class.h
index 165723d..e51775f 100644
--- a/src/nact/base-application-class.h
+++ b/src/nact/base-application-class.h
@@ -32,11 +32,35 @@
 #define __BASE_APPLICATION_CLASS_H__
 
 /**
- * SECTION: base_application
- * @short_description: #BaseApplication class definition.
- * @include: nact/base-application-class.h
+ * SECTION: base-application
+ * @title: BaseApplication
+ * @short_description: The Base Application application base class definition
+ * @include: base-application-class.h
  *
- * This is a pure virtual base class for Gtk+ programs.
+ * #BaseApplication is the base class for the application part of Gtk programs.
+ * It aims at providing all common services. It interacts with #BaseBuilder
+ * and #BaseWindow classes.
+ *
+ * #BaseApplication is a pure virtual class. A Gtk program should derive
+ * its own class from #BaseApplication, and instantiate it in its main()
+ * program entry point.
+ *
+ * <example>
+ *   <programlisting>
+ *     int
+ *     main( int argc, char **argv )
+ *     {
+ *         NactApplication *appli;
+ *         int code;
+ *
+ *         appli = nact_application_new_with_args( argc, argv );
+ *         code = base_appliction_run( BASE_APPLICATION( appli ));
+ *         g_object_unref( appli );
+ *
+ *         return( code );
+ *     }
+ *   </programlisting>
+ * </example>
  */
 
 #include <glib-object.h>
@@ -61,6 +85,13 @@ typedef struct {
 
 typedef struct _BaseApplicationClassPrivate  BaseApplicationClassPrivate;
 
+/**
+ * BaseApplicationClass:
+ * @manage_options: manage the command-line arguments
+ * @run_window:     open and run the first (main) window of the application.
+ *
+ * This defines the virtual method a derived class may, should or must implement.
+ */
 typedef struct {
 	/*< private >*/
 	GObjectClass                 parent;
@@ -68,6 +99,45 @@ typedef struct {
 
 	/*< public >*/
 	/**
+	 * manage_options:
+	 * @appli: this #BaseApplication -derived instance.
+	 * @code:  a pointer to an integer that the derived application may
+	 *         set as the exit code of the program if it chooses to stop
+	 *         the execution; the code set here will be ignored if execution
+	 *         is allowed to continue.
+	 *
+	 * This is invoked by the BaseApplication base class, after arguments
+	 * in the command-line have been processed by gtk_init_with_args()
+	 * function.
+	 *
+	 * This let the derived class an opportunity to manage command-line
+	 * arguments.
+	 *
+	 * The derived class should return %TRUE to continue execution,
+	 * %FALSE to stop it. In this later case only, the exit code set
+	 * in @code will be considered.
+	 *
+	 * This is a pure virtual method.
+	 */
+	gboolean ( *manage_options )( const BaseApplication *appli, int *code );
+
+	/**
+	 * run_window:
+	 * @appli: this #BaseApplication -derived instance.
+	 *
+	 * This is invoked by the BaseApplication base class to let the derived
+	 * class create, run and then release its first (maybe main) window.
+	 *
+	 * When the derived class returns, then the application is supposed
+	 * willing to terminate.
+	 *
+	 * This is a pure virtual method.
+	 *
+	 * Returns: the exit code of the program.
+	 */
+	int      ( *run_window )    ( const BaseApplication *appli );
+
+	/**
 	 * run:
 	 * @appli: this #BaseApplication instance.
 	 *
@@ -155,18 +225,6 @@ typedef struct {
 	gboolean  ( *initialize_gtk )             ( BaseApplication *appli );
 
 	/**
-	 * manage_options:
-	 * @appli: this #BaseApplication instance.
-	 *
-	 * Lets the application an opportunity to manage options entered
-	 * in command-line.
-	 *
-	 * Returns: %TRUE to continue initialization process,
-	 * %FALSE to stop it.
-	 */
-	gboolean  ( *manage_options )             ( BaseApplication *appli );
-
-	/**
 	 * initialize_application_name:
 	 * @appli: this #BaseApplication instance.
 	 *
diff --git a/src/nact/base-application.c b/src/nact/base-application.c
index 00f2f33..2804919 100644
--- a/src/nact/base-application.c
+++ b/src/nact/base-application.c
@@ -92,7 +92,7 @@ static void           instance_finalize( GObject *application );
 static gboolean       v_initialize( BaseApplication *application );
 static gboolean       v_initialize_i18n( BaseApplication *application );
 static gboolean       v_initialize_gtk( BaseApplication *application );
-static gboolean       v_manage_options( BaseApplication *application );
+static gboolean       v_manage_options( const BaseApplication *application, int *code );
 static gboolean       v_initialize_application_name( BaseApplication *application );
 static gboolean       v_initialize_session_manager( BaseApplication *application );
 static gboolean       v_initialize_unique_app( BaseApplication *application );
@@ -104,7 +104,7 @@ static int            application_do_run( BaseApplication *application );
 static gboolean       application_do_initialize( BaseApplication *application );
 static gboolean       application_do_initialize_i18n( BaseApplication *application );
 static gboolean       application_do_initialize_gtk( BaseApplication *application );
-static gboolean       application_do_manage_options( BaseApplication *application );
+static gboolean       application_do_manage_options( const BaseApplication *application, int *code );
 static gboolean       application_do_initialize_application_name( BaseApplication *application );
 static gboolean       application_do_initialize_session_manager( BaseApplication *application );
 static gboolean       application_do_initialize_unique_app( BaseApplication *application );
@@ -804,14 +804,14 @@ v_initialize_gtk( BaseApplication *application )
 }
 
 static gboolean
-v_manage_options( BaseApplication *application )
+v_manage_options( const BaseApplication *application, int *code )
 {
 	static const gchar *thisfn = "base_application_v_manage_options";
 	gboolean ok;
 
 	g_debug( "%s: application=%p", thisfn, ( void * ) application );
 
-	ok = BASE_APPLICATION_GET_CLASS( application )->manage_options( application );
+	ok = BASE_APPLICATION_GET_CLASS( application )->manage_options( application, code );
 
 	return( ok );
 }
@@ -939,6 +939,7 @@ static gboolean
 application_do_initialize( BaseApplication *application )
 {
 	static const gchar *thisfn = "base_application_do_initialize";
+	int code;
 
 	g_debug( "%s: application=%p", thisfn, ( void * ) application );
 
@@ -946,7 +947,7 @@ application_do_initialize( BaseApplication *application )
 			v_initialize_i18n( application ) &&
 			v_initialize_application_name( application ) &&
 			v_initialize_gtk( application ) &&
-			v_manage_options( application ) &&
+			v_manage_options( application, &code ) &&
 			v_initialize_session_manager( application ) &&
 			v_initialize_unique_app( application ) &&
 			v_initialize_ui( application ) &&
@@ -1004,7 +1005,7 @@ application_do_initialize_gtk( BaseApplication *application )
 }
 
 static gboolean
-application_do_manage_options( BaseApplication *application )
+application_do_manage_options( const BaseApplication *application, int *code )
 {
 	static const gchar *thisfn = "base_application_do_manage_options";
 
diff --git a/src/nact/nact-application.c b/src/nact/nact-application.c
index 6af122d..3fc67b1 100644
--- a/src/nact/nact-application.c
+++ b/src/nact/nact-application.c
@@ -85,7 +85,7 @@ static void     instance_set_property( GObject *object, guint property_id, const
 static void     instance_dispose( GObject *application );
 static void     instance_finalize( GObject *application );
 
-static gboolean appli_manage_options( BaseApplication *application );
+static gboolean appli_manage_options( const BaseApplication *application, int *code );
 static gboolean appli_initialize_unique_app( BaseApplication *application );
 static gboolean appli_initialize_application( BaseApplication *application );
 static gchar   *appli_get_application_name( BaseApplication *application );
@@ -326,12 +326,12 @@ nact_application_get_updater( NactApplication *application )
  * overriden to manage command-line options
  */
 static gboolean
-appli_manage_options( BaseApplication *application )
+appli_manage_options( const BaseApplication *application, int *code )
 {
 	gboolean ok;
 
 	/* call parent class */
-	ok = BASE_APPLICATION_CLASS( st_parent_class )->manage_options( application );
+	ok = BASE_APPLICATION_CLASS( st_parent_class )->manage_options( application, code );
 
 	if( ok ){
 		if( st_version_opt ){



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