[nautilus-actions] base_application_run() now takes argc, argv as arguments



commit fdf33a5650a133459f881740eb8a144c92e843c1
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Jan 6 08:31:18 2012 +0100

    base_application_run() now takes argc,argv as arguments

 ChangeLog                   |   10 ++
 src/nact/base-application.c |  311 +++++++++++++++++++++++++++++++------------
 src/nact/base-application.h |   57 ++++++--
 src/nact/main.c             |    7 +-
 src/nact/nact-application.c |    8 +-
 5 files changed, 282 insertions(+), 111 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9788491..3c21dee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-01-06 Pierre Wieser <pwieser trychlos org>
+
+	* src/nact/base-application.c:
+	* src/nact/base-application.h (base_application_run):
+	Take argc, argv as function arguments.
+	Define 'code' as a property.
+
+	* src/nact/main.c b/src/nact/main.c (main):
+	* src/nact/nact-application.c (appli_manage_options): Updated accordingly.
+
 2012-01-05 Pierre Wieser <pwieser trychlos org>
 
 	* src/nact/nact-tree-ieditable.c:
diff --git a/src/nact/base-application.c b/src/nact/base-application.c
index 009a3ce..d5667ea 100644
--- a/src/nact/base-application.c
+++ b/src/nact/base-application.c
@@ -60,6 +60,7 @@ struct _BaseApplicationPrivate {
 	gchar        *description;
 	gchar        *icon_name;
 	gchar        *unique_app_name;
+	int           code;
 
 	/* internals
 	 */
@@ -83,6 +84,7 @@ enum {
 	BASE_PROP_DESCRIPTION_ID,
 	BASE_PROP_ICON_NAME_ID,
 	BASE_PROP_UNIQUE_NAME_ID,
+	BASE_PROP_CODE_ID,
 
 	BASE_PROP_N_PROPERTIES
 };
@@ -97,16 +99,19 @@ static void           instance_set_property( GObject *object, guint property_id,
 static void           instance_dispose( GObject *application );
 static void           instance_finalize( GObject *application );
 
-static gboolean       appli_initialize_gtk( BaseApplication *application, int *code );
-static gboolean       appli_initialize_manage_options( const BaseApplication *application, int *code );
-static gboolean       appli_initialize_unique_app( BaseApplication *application, int *code );
+static gboolean       init_i18n( BaseApplication *application );
+static gboolean       init_application_name( BaseApplication *application );
+static gboolean       init_gtk( BaseApplication *application );
+static gboolean       v_manage_options( const BaseApplication *application );
+static gboolean       init_unique_app( BaseApplication *application );
 #if 0
 static UniqueResponse on_unique_message_received( UniqueApp *app, UniqueCommand command, UniqueMessageData *message, guint time, gpointer user_data );
 #endif
-static gboolean       appli_initialize_session_manager( BaseApplication *application, int *code );
+static gboolean       init_session_manager( BaseApplication *application );
 static void           session_manager_client_quit_cb( EggSMClient *client, BaseApplication *application );
 static void           session_manager_client_quit_requested_cb( EggSMClient *client, BaseApplication *application );
-static gboolean       appli_initialize_base_application( BaseApplication *application, int *code );
+static gboolean       init_icon_name( BaseApplication *application );
+static gboolean       init_builder( BaseApplication *application );
 
 GType
 base_application_get_type( void )
@@ -218,6 +223,14 @@ class_init( BaseApplicationClass *klass )
 					"",
 					G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
 
+	g_object_class_install_property( object_class, BASE_PROP_CODE_ID,
+			g_param_spec_int(
+					BASE_PROP_CODE,
+					"Return code",
+					"The return code of the application",
+					0, 127, 0,
+					G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
+
 	klass->private = g_new0( BaseApplicationClassPrivate, 1 );
 
 	klass->manage_options = NULL;
@@ -281,6 +294,10 @@ instance_get_property( GObject *object, guint property_id, GValue *value, GParam
 				g_value_set_string( value, self->private->unique_app_name );
 				break;
 
+			case BASE_PROP_CODE_ID:
+				g_value_set_int( value, self->private->code );
+				break;
+
 			default:
 				G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
 				break;
@@ -334,6 +351,10 @@ instance_set_property( GObject *object, guint property_id, const GValue *value,
 				self->private->unique_app_name = g_value_dup_string( value );
 				break;
 
+			case BASE_PROP_CODE_ID:
+				self->private->code = g_value_get_int( value );
+				break;
+
 			default:
 				G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
 				break;
@@ -402,6 +423,7 @@ instance_finalize( GObject *application )
 	g_free( self->private->description );
 	g_free( self->private->icon_name );
 	g_free( self->private->unique_app_name );
+	g_strfreev( self->private->argv );
 
 	g_free( self->private );
 
@@ -427,81 +449,84 @@ instance_finalize( GObject *application )
  * seldomly needed to override this in a derived class.
  */
 int
-base_application_run( BaseApplication *application )
+base_application_run( BaseApplication *application, int argc, GStrv argv )
 {
 	static const gchar *thisfn = "base_application_run";
-	int code;
+	BaseApplicationPrivate *priv;
 	GtkWindow *gtk_toplevel;
 
 	g_return_val_if_fail( BASE_IS_APPLICATION( application ), BASE_EXIT_CODE_START_FAIL );
 
-	code = BASE_EXIT_CODE_START_FAIL;
+	priv = application->private;
 
-	if( !application->private->dispose_has_run ){
-		g_debug( "%s: application=%p", thisfn, ( void * ) application );
+	if( !priv->dispose_has_run ){
 
-		code = BASE_EXIT_CODE_OK;
-		application->private->main_window = NULL;
+		g_debug( "%s: application=%p (%s), argc=%d",
+				thisfn,
+				( void * ) application, G_OBJECT_TYPE_NAME( application ),
+				argc );
 
-		if( appli_initialize_gtk( application, &code ) &&
-			appli_initialize_manage_options( application, &code ) &&
-			appli_initialize_unique_app( application, &code ) &&
-			appli_initialize_session_manager( application, &code ) &&
-			appli_initialize_base_application( application, &code )){
+		priv->argc = argc;
+		priv->argv = g_strdupv( argv );
+		priv->main_window = NULL;
+		priv->code = BASE_EXIT_CODE_OK;
+
+		if( init_i18n( application ) &&
+			init_application_name( application ) &&
+			init_gtk( application ) &&
+			v_manage_options( application ) &&
+			init_unique_app( application ) &&
+			init_session_manager( application ) &&
+			init_icon_name( application ) &&
+			init_builder( application )){
 
 
 			if( BASE_APPLICATION_GET_CLASS( application )->main_window_new ){
-				application->private->main_window =
-						( BaseWindow * ) BASE_APPLICATION_GET_CLASS( application )->main_window_new( application, &code );
+				priv->main_window =
+						( BaseWindow * ) BASE_APPLICATION_GET_CLASS( application )->main_window_new( application, &priv->code );
 			} else {
-				code = BASE_EXIT_CODE_MAIN_WINDOW;
+				priv->code = BASE_EXIT_CODE_MAIN_WINDOW;
 			}
 
-			if( application->private->main_window ){
-				g_return_val_if_fail( BASE_IS_WINDOW( application->private->main_window ), BASE_EXIT_CODE_START_FAIL );
+			if( priv->main_window ){
+				g_return_val_if_fail( BASE_IS_WINDOW( priv->main_window ), BASE_EXIT_CODE_START_FAIL );
 
-				if( base_window_init( application->private->main_window )){
-					gtk_toplevel = base_window_get_gtk_toplevel( application->private->main_window );
+				if( base_window_init( priv->main_window )){
+					gtk_toplevel = base_window_get_gtk_toplevel( priv->main_window );
 					g_return_val_if_fail( gtk_toplevel, BASE_EXIT_CODE_START_FAIL );
 					g_return_val_if_fail( GTK_IS_WINDOW( gtk_toplevel ), BASE_EXIT_CODE_START_FAIL );
 
-					if( application->private->unique_app_handle ){
-						unique_app_watch_window( application->private->unique_app_handle, gtk_toplevel );
+					if( priv->unique_app_handle ){
+						unique_app_watch_window( priv->unique_app_handle, gtk_toplevel );
 					}
 
 					g_debug( "%s: invoking base_window_run", thisfn );
-					code = base_window_run( application->private->main_window );
+					priv->code = base_window_run( priv->main_window );
 
 				} else {
 					g_debug( "%s: base_window_init has returned FALSE", thisfn );
-					code = BASE_EXIT_CODE_INIT_FAIL;
+					priv->code = BASE_EXIT_CODE_INIT_FAIL;
 				}
 			}
 		}
 	}
 
-	return( code );
+	return( priv->code );
 }
 
 /*
- * pre-gtk initialization
+ * i18n initialization
  *
- * Returns: %TRUE to continue the execution, %FALSE to temrinate the program.
+ * Returns: %TRUE to continue the execution, %FALSE to terminate the program.
  * The program exit code will be taken from @code.
  */
 static gboolean
-appli_initialize_gtk( BaseApplication *application, int *code )
+init_i18n( BaseApplication *application )
 {
-	static const gchar *thisfn = "base_application_appli_initialize_gtk";
-	gchar *name;
-	gboolean ret;
-	char *parameter_string;
-	GError *error;
+	static const gchar *thisfn = "base_application_init_i18n";
 
-	g_debug( "%s: application=%p, code=%p (%d)", thisfn, ( void * ) application, ( void * ) code, *code );
+	g_debug( "%s: application=%p", thisfn, ( void * ) application );
 
-	/* initialize i18n
-	 */
 #ifdef ENABLE_NLS
 	bindtextdomain( GETTEXT_PACKAGE, GNOMELOCALEDIR );
 # ifdef HAVE_BIND_TEXTDOMAIN_CODESET
@@ -510,90 +535,153 @@ appli_initialize_gtk( BaseApplication *application, int *code )
 	textdomain( GETTEXT_PACKAGE );
 #endif
 
+	return( TRUE );
+}
+
+/*
+ * From GLib Reference Manual:
+ * Sets a human-readable name for the application.
+ * This name should be localized if possible, and is intended for display to the user.
+ *
+ * This application name is supposed to have been set as a property when
+ * the BaseApplication-derived has been instanciated.
+ */
+static gboolean
+init_application_name( BaseApplication *application )
+{
+	static const gchar *thisfn = "base_application_init_application_name";
+	gchar *name;
+	gboolean ret;
+
+	g_debug( "%s: application=%p", thisfn, ( void * ) application );
+
+	ret = TRUE;
+
 	/* setup default Gtk+ application name
 	 * must have been set at instanciation time by the derived class
 	 */
 	name = base_application_get_application_name( application );
 	if( name && g_utf8_strlen( name, -1 )){
 		g_set_application_name( name );
+
+	} else {
+		application->private->code = BASE_EXIT_CODE_NO_APPLICATION_NAME;
+		ret = FALSE;
 	}
 	g_free( name );
 
+	return( ret );
+}
+
+/*
+ * pre-gtk initialization
+ */
+static gboolean
+init_gtk( BaseApplication *application )
+{
+	static const gchar *thisfn = "base_application_init_gtk";
+	gboolean ret;
+	char *parameter_string;
+	GError *error;
+
+	g_debug( "%s: application=%p", thisfn, ( void * ) application );
+
 	/* manage command-line arguments
 	 */
 	if( application->private->options ){
 		parameter_string = g_strdup( g_get_application_name());
 		error = NULL;
 		ret = gtk_init_with_args(
-				&application->private->argc, ( char *** ) &application->private->argv,
-				parameter_string, application->private->options, GETTEXT_PACKAGE, &error );
+				&application->private->argc,
+				( char *** ) &application->private->argv,
+				parameter_string,
+				application->private->options,
+				GETTEXT_PACKAGE,
+				&error );
 		if( error ){
 			g_warning( "%s: %s", thisfn, error->message );
 			g_error_free( error );
 			ret = FALSE;
-			*code = BASE_EXIT_CODE_ARGS;
+			application->private->code = BASE_EXIT_CODE_ARGS;
 		}
 		g_free( parameter_string );
 
 	} else {
-		ret = gtk_init_check( &application->private->argc, ( char *** ) &application->private->argv );
+		ret = gtk_init_check(
+				&application->private->argc,
+				( char *** ) &application->private->argv );
+		if( !ret ){
+			g_warning( "%s", _( "Unable to interpret command-line arguments" ));
+			application->private->code = BASE_EXIT_CODE_ARGS;
+		}
 	}
 
 	return( ret );
 }
 
 static gboolean
-appli_initialize_manage_options( const BaseApplication *application, int *code )
+v_manage_options( const BaseApplication *application )
 {
-	static const gchar *thisfn = "base_application_appli_initialize_manage_options";
+	static const gchar *thisfn = "base_application_v_manage_options";
 	gboolean ret;
 
-	g_debug( "%s: application=%p, code=%p (%d)", thisfn, ( void * ) application, ( void * ) code, *code );
+	g_debug( "%s: application=%p", thisfn, ( void * ) application );
 
 	ret = TRUE;
 
 	if( BASE_APPLICATION_GET_CLASS( application )->manage_options ){
-		ret = BASE_APPLICATION_GET_CLASS( application )->manage_options( application, code );
+		ret = BASE_APPLICATION_GET_CLASS( application )->manage_options( application );
 	}
 
 	return( ret );
 }
 
+/*
+ * Relying on libunique to detect another instance already running.
+ *
+ * A replacement is available with GLib 2.28 in GApplication, but only
+ * GLib 2.30 (Fedora 16) provides a "non-unique" property.
+ */
 static gboolean
-appli_initialize_unique_app( BaseApplication *application, int *code )
+init_unique_app( BaseApplication *application )
 {
-	static const gchar *thisfn = "base_application_appli_initialize_unique_app";
+	static const gchar *thisfn = "base_application_init_unique_app";
 	gboolean ret;
+	BaseApplicationPrivate *priv;
 	gboolean is_first;
 	gchar *msg;
 
-	g_debug( "%s: application=%p, code=%p (%d)", thisfn, ( void * ) application, ( void * ) code, *code );
+	g_debug( "%s: application=%p", thisfn, ( void * ) application );
 
 	ret = TRUE;
+	priv = application->private;
 
-	if( application->private->unique_app_name &&
-		strlen( application->private->unique_app_name )){
+	if( priv->unique_app_name && strlen( priv->unique_app_name )){
 
-			application->private->unique_app_handle = unique_app_new( application->private->unique_app_name, NULL );
-			is_first = !unique_app_is_running( application->private->unique_app_handle );
+			priv->unique_app_handle = unique_app_new( priv->unique_app_name, NULL );
+			is_first = !unique_app_is_running( priv->unique_app_handle );
 
 			if( !is_first ){
-				unique_app_send_message( application->private->unique_app_handle, UNIQUE_ACTIVATE, NULL );
+				unique_app_send_message( priv->unique_app_handle, UNIQUE_ACTIVATE, NULL );
 				/* i18n: application name */
 				msg = g_strdup_printf(
 						_( "Another instance of %s is already running.\n"
-							"Please switch back to it." ), application->private->application_name );
+							"Please switch back to it." ),
+						priv->application_name );
 				base_window_display_error_dlg( NULL, _( "The application is not unique" ), msg );
 				g_free( msg );
 				ret = FALSE;
-				*code = BASE_EXIT_CODE_UNIQUE_APP;
+				priv->code = BASE_EXIT_CODE_UNIQUE_APP;
 #if 0
 			/* default from libunique is actually to activate the first window
 			 * so we rely on the default..
 			 */
 			} else {
-				g_signal_connect( application->private->unique_app_handle,
-						"message-received", G_CALLBACK( on_unique_message_received ), application );
+				g_signal_connect(
+						priv->unique_app_handle,
+						"message-received",
+						G_CALLBACK( on_unique_message_received ),
+						application );
 #endif
 			}
 	}
@@ -622,29 +710,45 @@ on_unique_message_received(
 }
 #endif
 
+/*
+ * Relying on session manager to have a chance to save the modifications
+ * before exiting a session
+ */
 static gboolean
-appli_initialize_session_manager( BaseApplication *application, int *code )
+init_session_manager( BaseApplication *application )
 {
-	static const gchar *thisfn = "base_application_do_initialize_session_manager";
+	static const gchar *thisfn = "base_application_init_session_manager";
+	BaseApplicationPrivate *priv;
+
+	g_debug( "%s: application=%p", thisfn, ( void * ) application );
 
-	g_debug( "%s: application=%p, code=%p (%d)", thisfn, ( void * ) application, ( void * ) code, *code );
+	priv = application->private;
 
 	egg_sm_client_set_mode( EGG_SM_CLIENT_MODE_NO_RESTART );
-	application->private->sm_client = egg_sm_client_get();
+	priv->sm_client = egg_sm_client_get();
 	egg_sm_client_startup();
-	g_debug( "%s: sm_client=%p", thisfn, ( void * ) application->private->sm_client );
-
-	application->private->sm_client_quit_handler_id =
-			g_signal_connect( application->private->sm_client,
-					"quit-requested", G_CALLBACK( session_manager_client_quit_requested_cb ), application );
-
-	application->private->sm_client_quit_requested_handler_id =
-			g_signal_connect( application->private->sm_client,
-					"quit", G_CALLBACK( session_manager_client_quit_cb ), application );
+	g_debug( "%s: sm_client=%p", thisfn, ( void * ) priv->sm_client );
+
+	priv->sm_client_quit_handler_id =
+			g_signal_connect(
+					priv->sm_client,
+					"quit-requested",
+					G_CALLBACK( session_manager_client_quit_requested_cb ),
+					application );
+
+	priv->sm_client_quit_requested_handler_id =
+			g_signal_connect(
+					priv->sm_client,
+					"quit",
+					G_CALLBACK( session_manager_client_quit_cb ),
+					application );
 
 	return( TRUE );
 }
 
+/*
+ * cleanly terminate the main window when exiting the session
+ */
 static void
 session_manager_client_quit_cb( EggSMClient *client, BaseApplication *application )
 {
@@ -652,16 +756,22 @@ session_manager_client_quit_cb( EggSMClient *client, BaseApplication *applicatio
 
 	g_return_if_fail( BASE_IS_APPLICATION( application ));
 
-	g_debug( "%s: client=%p, application=%p", thisfn, ( void * ) client, ( void * ) application );
+	if( !application->private->dispose_has_run ){
+
+		g_debug( "%s: client=%p, application=%p", thisfn, ( void * ) client, ( void * ) application );
 
-	if( application->private->main_window ){
+		if( application->private->main_window ){
 
-			g_return_if_fail( BASE_IS_WINDOW( application->private->main_window ));
-			g_object_unref( application->private->main_window );
-			application->private->main_window = NULL;
+				g_return_if_fail( BASE_IS_WINDOW( application->private->main_window ));
+				g_object_unref( application->private->main_window );
+				application->private->main_window = NULL;
+		}
 	}
 }
 
+/*
+ * the session manager advertises us that the session is about to exit
+ */
 static void
 session_manager_client_quit_requested_cb( EggSMClient *client, BaseApplication *application )
 {
@@ -670,32 +780,57 @@ session_manager_client_quit_requested_cb( EggSMClient *client, BaseApplication *
 
 	g_return_if_fail( BASE_IS_APPLICATION( application ));
 
-	g_debug( "%s: client=%p, application=%p", thisfn, ( void * ) client, ( void * ) application );
+	if( !application->private->dispose_has_run ){
+
+		g_debug( "%s: client=%p, application=%p", thisfn, ( void * ) client, ( void * ) application );
 
-	if( application->private->main_window ){
+		if( application->private->main_window ){
 
-			g_return_if_fail( BASE_IS_WINDOW( application->private->main_window ));
-			willing_to = base_window_is_willing_to_quit( application->private->main_window );
+				g_return_if_fail( BASE_IS_WINDOW( application->private->main_window ));
+				willing_to = base_window_is_willing_to_quit( application->private->main_window );
+		}
 	}
 
 	egg_sm_client_will_quit( client, willing_to );
 }
 
+/*
+ * From GTK+ Reference Manual:
+ * Sets an icon to be used as fallback for windows that haven't had
+ * gtk_window_set_icon_list() called on them from a named themed icon.
+ *
+ * This icon name is supposed to have been set as a property when
+ * the BaseApplication-derived has been instanciated.
+ */
 static gboolean
-appli_initialize_base_application( BaseApplication *application, int *code )
+init_icon_name( BaseApplication *application )
 {
-	static const gchar *thisfn = "base_application_appli_initialize_base_application";
+	static const gchar *thisfn = "base_application_init_icon_name";
 
-	g_debug( "%s: application=%p, code=%p (%d)", thisfn, ( void * ) application, ( void * ) code, *code );
+	g_debug( "%s: application=%p", thisfn, ( void * ) application );
 
 	/* setup default application icon
 	 */
-	if( application->private->icon_name &&
-		g_utf8_strlen( application->private->icon_name, -1 )){
-
+	if( application->private->icon_name && g_utf8_strlen( application->private->icon_name, -1 )){
 			gtk_window_set_default_icon_name( application->private->icon_name );
+
+	} else {
+		g_warning( "%s: no default icon name", thisfn );
 	}
 
+	return( TRUE );
+}
+
+/*
+ * allocate a default builder
+ */
+static gboolean
+init_builder( BaseApplication *application )
+{
+	static const gchar *thisfn = "base_application_init_builder";
+
+	g_debug( "%s: application=%p", thisfn, ( void * ) application );
+
 	/* allocate the common BaseBuilder instance
 	 */
 	application->private->builder = base_builder_new();
diff --git a/src/nact/base-application.h b/src/nact/base-application.h
index 535f155..1970d7e 100644
--- a/src/nact/base-application.h
+++ b/src/nact/base-application.h
@@ -56,17 +56,46 @@
  *         int code;
  *
  *         appli = my_application_new();
- *         g_object_set( G_OBJECT( appli ),
- *             BASE_PROP_ARGC, argc,
- *             BASE_PROP_ARGV, argv,
- *             NULL );
- *         code = base_appliction_run( BASE_APPLICATION( appli ));
+ *         code = base_appliction_run( BASE_APPLICATION( appli ), argc, argv );
  *         g_object_unref( appli );
  *
  *         return( code );
  *     }
  *   </programlisting>
  * </example>
+ *
+ * main                 BaseApplication      NactApplication
+ * ===================  ===================  ===================
+ * appli = nact_application_new()
+ *                                           appli = g_object_new()
+ *                                           set properties
+ *                                             application name
+ *                                             icon name
+ *                                             description
+ *                                             command-line definitions
+ *                                             unique name (if apply)
+ * ret = base_application_run( appli, argc, argv )
+ *                      init i18n
+ *                      init application name
+ *                      init gtk with command-line options
+ *                      manage command-line options
+ *                      init unique manager
+ *                      init session manager
+ *                      init icon name
+ *                      init common builder
+ *                      foreach window to display
+ *                        create window
+ *                        create gtk toplevel
+ *                        unique watch toplevel
+ *                        run the window
+ *                      ret = last window return code
+ * g_object_unref( appli )
+ * return( ret )
+ *
+ * At any time, a function may preset the exit code of the application just by
+ * setting the @BASE_PROP_CODE property. Unless it also asks to quit immediately
+ * by returning %FALSE, another function may always set another exit code after
+ * that.
  */
 
 #include "base-builder.h"
@@ -107,10 +136,6 @@ typedef struct {
 	/**
 	 * 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()
@@ -121,9 +146,12 @@ typedef struct {
 	 * the derived class should call the parent class method in order to
 	 * let it manage its own options.
 	 *
+	 * The derived class may set the exit code of the application by
+	 * setting the @BASE_PROP_CODE property of @appli.
+	 *
 	 * Returns: %TRUE to continue execution, %FALSE to stop it.
 	 */
-	gboolean  ( *manage_options ) ( const BaseApplication *appli, int *code );
+	gboolean  ( *manage_options ) ( const BaseApplication *appli );
 
 	/**
 	 * main_window_new:
@@ -155,6 +183,7 @@ typedef struct {
  * @BASE_PROP_DESCRIPTION:      short description.
  * @BASE_PROP_ICON_NAME:        icon name.
  * @BASE_PROP_UNIQUE_NAME:      unique name of the application (if not empty)
+ * @BASE_PROP_CODE:             return code of the application
  */
 #define BASE_PROP_ARGC						"base-application-argc"
 #define BASE_PROP_ARGV						"base-application-argv"
@@ -163,12 +192,14 @@ typedef struct {
 #define BASE_PROP_DESCRIPTION				"base-application-description"
 #define BASE_PROP_ICON_NAME					"base-application-icon-name"
 #define BASE_PROP_UNIQUE_NAME				"base-application-unique-name"
+#define BASE_PROP_CODE						"base-application-code"
 
 typedef enum {
 	BASE_EXIT_CODE_START_FAIL = -1,
 	BASE_EXIT_CODE_OK = 0,
-	BASE_EXIT_CODE_ARGS,
-	BASE_EXIT_CODE_UNIQUE_APP,
+	BASE_EXIT_CODE_NO_APPLICATION_NAME,		/* no application name has been set by the derived class */
+	BASE_EXIT_CODE_ARGS,					/* unable to interpret command-line options */
+	BASE_EXIT_CODE_UNIQUE_APP,				/* another instance is already running */
 	BASE_EXIT_CODE_MAIN_WINDOW,
 	BASE_EXIT_CODE_INIT_FAIL,
 	BASE_EXIT_CODE_PROGRAM,
@@ -182,7 +213,7 @@ typedef enum {
 
 GType        base_application_get_type( void );
 
-int          base_application_run( BaseApplication *application );
+int          base_application_run( BaseApplication *application, int argc, GStrv argv );
 
 gchar       *base_application_get_application_name( const BaseApplication *application );
 BaseBuilder *base_application_get_builder         ( const BaseApplication *application );
diff --git a/src/nact/main.c b/src/nact/main.c
index b06047b..075c307 100644
--- a/src/nact/main.c
+++ b/src/nact/main.c
@@ -69,12 +69,7 @@ main( int argc, char *argv[] )
 	 */
 	appli = nact_application_new();
 
-	g_object_set( G_OBJECT( appli ),
-			BASE_PROP_ARGC, argc,
-			BASE_PROP_ARGV, argv,
-			NULL );
-
-	ret = base_application_run( BASE_APPLICATION( appli ));
+	ret = base_application_run( BASE_APPLICATION( appli ), argc, argv );
 
 	g_object_unref( appli );
 
diff --git a/src/nact/nact-application.c b/src/nact/nact-application.c
index fffc6b3..89064ff 100644
--- a/src/nact/nact-application.c
+++ b/src/nact/nact-application.c
@@ -77,7 +77,7 @@ static void     class_init( NactApplicationClass *klass );
 static void     instance_init( GTypeInstance *instance, gpointer klass );
 static void     instance_dispose( GObject *application );
 static void     instance_finalize( GObject *application );
-static gboolean appli_manage_options( const BaseApplication *application, int *code );
+static gboolean appli_manage_options( const BaseApplication *application );
 static GObject *appli_main_window_new( const BaseApplication *application, int *code );
 
 GType
@@ -231,14 +231,14 @@ nact_application_new( void )
  * overriden to manage command-line options
  */
 static gboolean
-appli_manage_options( const BaseApplication *application, int *code )
+appli_manage_options( const BaseApplication *application )
 {
 	static const gchar *thisfn = "nact_application_appli_manage_options";
 	gboolean ret;
 
 	g_return_val_if_fail( NACT_IS_APPLICATION( application ), FALSE );
 
-	g_debug( "%s: application=%p, code=%p (%d)", thisfn, ( void * ) application, ( void * ) code, *code );
+	g_debug( "%s: application=%p", thisfn, ( void * ) application );
 
 	ret = TRUE;
 
@@ -258,7 +258,7 @@ appli_manage_options( const BaseApplication *application, int *code )
 
 	/* call parent class */
 	if( ret && BASE_APPLICATION_CLASS( st_parent_class )->manage_options ){
-		ret = BASE_APPLICATION_CLASS( st_parent_class )->manage_options( application, code );
+		ret = BASE_APPLICATION_CLASS( st_parent_class )->manage_options( application );
 	}
 
 	return( ret );



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