[nautilus-actions] Review NactApplication startup



commit b8bacc61993342e9764ed809f71929c627248ec2
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Dec 28 23:45:19 2011 +0100

    Review NactApplication startup

 ChangeLog                   |   13 ++++++
 src/nact/base-application.c |   38 ++++++++--------
 src/nact/base-application.h |   30 ++++++++-----
 src/nact/main.c             |   11 ++++-
 src/nact/nact-application.c |  100 +++++++-----------------------------------
 src/nact/nact-application.h |   27 +++++++----
 6 files changed, 94 insertions(+), 125 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5bd1f32..368ce9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-12-28 Pierre Wieser <pwieser trychlos org>
+
+	* src/nact/base-application.c (class_init): Property labels are not translatable.
+
+	* src/nact/base-application.h: Review comments.
+
+	* src/nact/main.c (main): Set command-line arguments here.
+
+	* src/nact/nact-application.c (class_init): Remove "updater" property.
+
+	* src/nact/nact-application.c:
+	* src/nact/nact-application.h (nact_application_new): Have an empty constructor.
+
 2011-12-22 Pierre Wieser <pwieser trychlos org>
 
 	* src/core/na-export-format.c: Remove superfluous gdk-pixbuf.h include.
diff --git a/src/nact/base-application.c b/src/nact/base-application.c
index 2824d4b..6a033b8 100644
--- a/src/nact/base-application.c
+++ b/src/nact/base-application.c
@@ -82,7 +82,7 @@ enum {
 	BASE_PROP_APPLICATION_NAME_ID,
 	BASE_PROP_DESCRIPTION_ID,
 	BASE_PROP_ICON_NAME_ID,
-	BASE_PROP_UNIQUE_APP_NAME_ID,
+	BASE_PROP_UNIQUE_NAME_ID,
 
 	BASE_PROP_N_PROPERTIES
 };
@@ -166,55 +166,55 @@ class_init( BaseApplicationClass *klass )
 	g_object_class_install_property( object_class, BASE_PROP_ARGC_ID,
 			g_param_spec_int(
 					BASE_PROP_ARGC,
-					_( "Arguments count" ),
-					_( "The count of command-line arguments" ),
+					"Arguments count",
+					"The count of command-line arguments",
 					0, 65535, 0,
 					G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
 
 	g_object_class_install_property( object_class, BASE_PROP_ARGV_ID,
 			g_param_spec_boxed(
 					BASE_PROP_ARGV,
-					_( "Arguments" ),
-					_( "The array of command-line arguments" ),
+					"Arguments",
+					"The array of command-line arguments",
 					G_TYPE_STRV,
 					G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
 
 	g_object_class_install_property( object_class, BASE_PROP_OPTIONS_ID,
 			g_param_spec_pointer(
 					BASE_PROP_OPTIONS,
-					_( "Option entries" ),
-					_( "The array of command-line option definitions" ),
+					"Option entries",
+					"The array of command-line option definitions",
 					G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
 
 	g_object_class_install_property( object_class, BASE_PROP_APPLICATION_NAME_ID,
 			g_param_spec_string(
 					BASE_PROP_APPLICATION_NAME,
-					_( "Application name" ),
-					_( "The name of the application" ),
+					"Application name",
+					"The name of the application",
 					"",
 					G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
 
 	g_object_class_install_property( object_class, BASE_PROP_DESCRIPTION_ID,
 			g_param_spec_string(
 					BASE_PROP_DESCRIPTION,
-					_( "Description" ),
-					_( "A short description to be displayed in the first line of --help output" ),
+					"Description",
+					"A short description to be displayed in the first line of --help output",
 					"",
 					G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
 
 	g_object_class_install_property( object_class, BASE_PROP_ICON_NAME_ID,
 			g_param_spec_string(
 					BASE_PROP_ICON_NAME,
-					_( "Icon name" ),
-					_( "The name of the icon of the application" ),
+					"Icon name",
+					"The name of the icon of the application",
 					"",
 					G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
 
-	g_object_class_install_property( object_class, BASE_PROP_UNIQUE_APP_NAME_ID,
+	g_object_class_install_property( object_class, BASE_PROP_UNIQUE_NAME_ID,
 			g_param_spec_string(
-					BASE_PROP_UNIQUE_APP_NAME,
-					_( "UniqueApp name" ),
-					_( "The Unique name of the application" ),
+					BASE_PROP_UNIQUE_NAME,
+					"UniqueApp name",
+					"The Unique name of the application",
 					"",
 					G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
 
@@ -277,7 +277,7 @@ instance_get_property( GObject *object, guint property_id, GValue *value, GParam
 				g_value_set_string( value, self->private->icon_name );
 				break;
 
-			case BASE_PROP_UNIQUE_APP_NAME_ID:
+			case BASE_PROP_UNIQUE_NAME_ID:
 				g_value_set_string( value, self->private->unique_app_name );
 				break;
 
@@ -329,7 +329,7 @@ instance_set_property( GObject *object, guint property_id, const GValue *value,
 				self->private->icon_name = g_value_dup_string( value );
 				break;
 
-			case BASE_PROP_UNIQUE_APP_NAME_ID:
+			case BASE_PROP_UNIQUE_NAME_ID:
 				g_free( self->private->unique_app_name );
 				self->private->unique_app_name = g_value_dup_string( value );
 				break;
diff --git a/src/nact/base-application.h b/src/nact/base-application.h
index f4a9c2d..5763022 100644
--- a/src/nact/base-application.h
+++ b/src/nact/base-application.h
@@ -55,7 +55,11 @@
  *         MyApplication *appli;
  *         int code;
  *
- *         appli = my_application_new_with_args( argc, argv );
+ *         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 ));
  *         g_object_unref( appli );
  *
@@ -69,14 +73,14 @@
 
 G_BEGIN_DECLS
 
-#define BASE_APPLICATION_TYPE                ( base_application_get_type())
-#define BASE_APPLICATION( object )           ( G_TYPE_CHECK_INSTANCE_CAST( object, BASE_APPLICATION_TYPE, BaseApplication ))
-#define BASE_APPLICATION_CLASS( klass )      ( G_TYPE_CHECK_CLASS_CAST( klass, BASE_APPLICATION_TYPE, BaseApplicationClass ))
-#define BASE_IS_APPLICATION( object )        ( G_TYPE_CHECK_INSTANCE_TYPE( object, BASE_APPLICATION_TYPE ))
-#define BASE_IS_APPLICATION_CLASS( klass )   ( G_TYPE_CHECK_CLASS_TYPE(( klass ), BASE_APPLICATION_TYPE ))
-#define BASE_APPLICATION_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), BASE_APPLICATION_TYPE, BaseApplicationClass ))
+#define BASE_APPLICATION_TYPE           ( base_application_get_type())
+#define BASE_APPLICATION( o )           ( G_TYPE_CHECK_INSTANCE_CAST( o, BASE_APPLICATION_TYPE, BaseApplication ))
+#define BASE_APPLICATION_CLASS( k )     ( G_TYPE_CHECK_CLASS_CAST( k, BASE_APPLICATION_TYPE, BaseApplicationClass ))
+#define BASE_IS_APPLICATION( o )        ( G_TYPE_CHECK_INSTANCE_TYPE( o, BASE_APPLICATION_TYPE ))
+#define BASE_IS_APPLICATION_CLASS( k )  ( G_TYPE_CHECK_CLASS_TYPE(( k ), BASE_APPLICATION_TYPE ))
+#define BASE_APPLICATION_GET_CLASS( o ) ( G_TYPE_INSTANCE_GET_CLASS(( o ), BASE_APPLICATION_TYPE, BaseApplicationClass ))
 
-typedef struct _BaseApplicationPrivate       BaseApplicationPrivate;
+typedef struct _BaseApplicationPrivate      BaseApplicationPrivate;
 
 typedef struct {
 	/*< private >*/
@@ -85,7 +89,7 @@ typedef struct {
 }
 	BaseApplication;
 
-typedef struct _BaseApplicationClassPrivate  BaseApplicationClassPrivate;
+typedef struct _BaseApplicationClassPrivate BaseApplicationClassPrivate;
 
 /**
  * BaseApplicationClass:
@@ -140,7 +144,9 @@ typedef struct {
 
 /**
  * Properties defined by the BaseApplication class.
- * They should be provided at object instantiation time.
+ * They may be provided at object instantiation time, either in the derived-
+ * application constructor, or in the main() function, but in all cases
+ * before calling base_application_run().
  *
  * @BASE_PROP_ARGC:             count of arguments in command-line.
  * @BASE_PROP_ARGV:             array of command-line arguments.
@@ -148,7 +154,7 @@ typedef struct {
  * @BASE_PROP_APPLICATION_NAME: application name.
  * @BASE_PROP_DESCRIPTION:      short description.
  * @BASE_PROP_ICON_NAME:        icon name.
- * @BASE_PROP_UNIQUE_APP_NAME:  unique name of the application (if apply)
+ * @BASE_PROP_UNIQUE_NAME:      unique name of the application (if not empty)
  */
 #define BASE_PROP_ARGC						"base-application-argc"
 #define BASE_PROP_ARGV						"base-application-argv"
@@ -156,7 +162,7 @@ typedef struct {
 #define BASE_PROP_APPLICATION_NAME			"base-application-name"
 #define BASE_PROP_DESCRIPTION				"base-application-description"
 #define BASE_PROP_ICON_NAME					"base-application-icon-name"
-#define BASE_PROP_UNIQUE_APP_NAME			"base-application-unique-app-name"
+#define BASE_PROP_UNIQUE_NAME				"base-application-unique-name"
 
 typedef enum {
 	BASE_EXIT_CODE_START_FAIL = -1,
diff --git a/src/nact/main.c b/src/nact/main.c
index 4362197..199b490 100644
--- a/src/nact/main.c
+++ b/src/nact/main.c
@@ -65,8 +65,17 @@ main( int argc, char *argv[] )
 	 */
 	na_gconf_migration_run();
 
-	appli = nact_application_new_with_args( argc, argv );
+	/* create and run the application
+	 */
+	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 ));
+
 	g_object_unref( appli );
 
 	return( ret );
diff --git a/src/nact/nact-application.c b/src/nact/nact-application.c
index c53996d..7b3746e 100644
--- a/src/nact/nact-application.c
+++ b/src/nact/nact-application.c
@@ -55,21 +55,13 @@ struct _NactApplicationPrivate {
 	NAUpdater *updater;
 };
 
-/* private instance properties
- */
-enum {
-	NACT_APPLICATION_PROP_UPDATER_ID = 1
-};
-
-#define NACT_APPLICATION_PROP_UPDATER	"nact-application-prop-updater"
+static const gchar *st_application_name	= N_( "Nautilus-Actions Configuration Tool" );
+static const gchar *st_description		= N_( "A user interface to edit your own contextual actions" );
+static const gchar *st_unique_name		= "org.gnome.nautilus-actions.ConfigurationTool";
 
 static gboolean     st_non_unique_opt = FALSE;
 static gboolean     st_version_opt    = FALSE;
 
-static const gchar *st_application_name = N_( "Nautilus-Actions Configuration Tool" );
-static const gchar *st_description      = N_( "A user interface to edit your own contextual actions" );
-static const gchar *st_unique_app_name  = "org.nautilus-actions.ConfigurationTool";
-
 static GOptionEntry st_option_entries[] = {
 	{ "non-unique", 'n', 0, G_OPTION_ARG_NONE, &st_non_unique_opt,
 			N_( "Set it to run multiple instances of the program [unique]" ), NULL },
@@ -83,11 +75,8 @@ static BaseApplicationClass *st_parent_class = NULL;
 static GType    register_type( void );
 static void     class_init( NactApplicationClass *klass );
 static void     instance_init( GTypeInstance *instance, gpointer klass );
-static void     instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
-static void     instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
 static void     instance_dispose( GObject *application );
 static void     instance_finalize( GObject *application );
-
 static gboolean appli_manage_options( const BaseApplication *application, int *code );
 static GObject *appli_main_window_new( const BaseApplication *application, int *code );
 
@@ -133,7 +122,6 @@ class_init( NactApplicationClass *klass )
 {
 	static const gchar *thisfn = "nact_application_class_init";
 	GObjectClass *object_class;
-	GParamSpec *spec;
 	BaseApplicationClass *appli_class;
 
 	g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
@@ -143,15 +131,6 @@ class_init( NactApplicationClass *klass )
 	object_class = G_OBJECT_CLASS( klass );
 	object_class->dispose = instance_dispose;
 	object_class->finalize = instance_finalize;
-	object_class->get_property = instance_get_property;
-	object_class->set_property = instance_set_property;
-
-	spec = g_param_spec_pointer(
-			NACT_APPLICATION_PROP_UPDATER,
-			NACT_APPLICATION_PROP_UPDATER,
-			"NAUpdater object pointer",
-			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
-	g_object_class_install_property( object_class, NACT_APPLICATION_PROP_UPDATER_ID, spec );
 
 	klass->private = g_new0( NactApplicationClassPrivate, 1 );
 
@@ -179,50 +158,6 @@ instance_init( GTypeInstance *application, gpointer klass )
 }
 
 static void
-instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec )
-{
-	NactApplication *self;
-
-	g_assert( NACT_IS_APPLICATION( object ));
-	self = NACT_APPLICATION( object );
-
-	if( !self->private->dispose_has_run ){
-
-		switch( property_id ){
-			case NACT_APPLICATION_PROP_UPDATER_ID:
-				g_value_set_pointer( value, self->private->updater );
-				break;
-
-			default:
-				G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
-				break;
-		}
-	}
-}
-
-static void
-instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec )
-{
-	NactApplication *self;
-
-	g_assert( NACT_IS_APPLICATION( object ));
-	self = NACT_APPLICATION( object );
-
-	if( !self->private->dispose_has_run ){
-
-		switch( property_id ){
-			case NACT_APPLICATION_PROP_UPDATER_ID:
-				self->private->updater = g_value_get_pointer( value );
-				break;
-
-			default:
-				G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
-				break;
-		}
-	}
-}
-
-static void
 instance_dispose( GObject *application )
 {
 	static const gchar *thisfn = "nact_application_instance_dispose";
@@ -270,32 +205,25 @@ instance_finalize( GObject *application )
 }
 
 /**
- * Returns a newly allocated NactApplication object.
- *
- * @argc: count of command-line arguments.
+ * nact_application_new:
  *
- * @argv: command-line arguments.
+ * Returns: a newly allocated NactApplication object.
  */
 NactApplication *
-nact_application_new_with_args( int argc, char **argv )
+nact_application_new( void )
 {
 	NactApplication *application;
-	gchar *icon_name;
 
-	icon_name = na_about_get_icon_name();
+	application = g_object_new( NACT_APPLICATION_TYPE, NULL );
 
-	application = g_object_new( NACT_APPLICATION_TYPE,
-			BASE_PROP_ARGC,             argc,
-			BASE_PROP_ARGV,             argv,
+	g_object_set( G_OBJECT( application ),
 			BASE_PROP_OPTIONS,          st_option_entries,
 			BASE_PROP_APPLICATION_NAME, gettext( st_application_name ),
 			BASE_PROP_DESCRIPTION,      gettext( st_description ),
-			BASE_PROP_ICON_NAME,        icon_name,
-			BASE_PROP_UNIQUE_APP_NAME,  st_unique_app_name,
+			BASE_PROP_ICON_NAME,        na_about_get_icon_name(),
+			BASE_PROP_UNIQUE_NAME,      st_unique_name,
 			NULL );
 
-	g_free( icon_name );
-
 	return( application );
 }
 
@@ -314,12 +242,18 @@ appli_manage_options( const BaseApplication *application, int *code )
 
 	ret = TRUE;
 
+	/* display the program version ?
+	 * if yes, then stops here
+	 */
 	if( st_version_opt ){
 		na_core_utils_print_version();
 		ret = FALSE;
 	}
+
+	/* run the application as non-unique ?
+	 */
 	if( ret && st_non_unique_opt ){
-		g_object_set( G_OBJECT( application ), BASE_PROP_UNIQUE_APP_NAME, "", NULL );
+		g_object_set( G_OBJECT( application ), BASE_PROP_UNIQUE_NAME, "", NULL );
 	}
 
 	/* call parent class */
diff --git a/src/nact/nact-application.h b/src/nact/nact-application.h
index a7e1c18..613a0eb 100644
--- a/src/nact/nact-application.h
+++ b/src/nact/nact-application.h
@@ -37,6 +37,13 @@
  * @include: nact/nact-application.h
  *
  * This is the main class for nautilus-actions-config-tool program.
+ *
+ * The #NactApplication object is instanciated in main() function.
+ *
+ * Properties are explicitely set in main() before calling base_application_run().
+ *
+ * The #NactApplication object is later g_object_unref() in main() after
+ * base_application_run() has returned.
  */
 
 #include <core/na-updater.h>
@@ -45,14 +52,14 @@
 
 G_BEGIN_DECLS
 
-#define NACT_APPLICATION_TYPE                ( nact_application_get_type())
-#define NACT_APPLICATION( object )           ( G_TYPE_CHECK_INSTANCE_CAST( object, NACT_APPLICATION_TYPE, NactApplication ))
-#define NACT_APPLICATION_CLASS( klass )      ( G_TYPE_CHECK_CLASS_CAST( klass, NACT_APPLICATION_TYPE, NactApplicationClass ))
-#define NACT_IS_APPLICATION( object )        ( G_TYPE_CHECK_INSTANCE_TYPE( object, NACT_APPLICATION_TYPE ))
-#define NACT_IS_APPLICATION_CLASS( klass )   ( G_TYPE_CHECK_CLASS_TYPE(( klass ), NACT_APPLICATION_TYPE ))
-#define NACT_APPLICATION_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), NACT_APPLICATION_TYPE, NactApplicationClass ))
+#define NACT_APPLICATION_TYPE           ( nact_application_get_type())
+#define NACT_APPLICATION( o )           ( G_TYPE_CHECK_INSTANCE_CAST( o, NACT_APPLICATION_TYPE, NactApplication ))
+#define NACT_APPLICATION_CLASS( k )     ( G_TYPE_CHECK_CLASS_CAST( k, NACT_APPLICATION_TYPE, NactApplicationClass ))
+#define NACT_IS_APPLICATION( o )        ( G_TYPE_CHECK_INSTANCE_TYPE( o, NACT_APPLICATION_TYPE ))
+#define NACT_IS_APPLICATION_CLASS( k )  ( G_TYPE_CHECK_CLASS_TYPE(( k ), NACT_APPLICATION_TYPE ))
+#define NACT_APPLICATION_GET_CLASS( o ) ( G_TYPE_INSTANCE_GET_CLASS(( o ), NACT_APPLICATION_TYPE, NactApplicationClass ))
 
-typedef struct _NactApplicationPrivate       NactApplicationPrivate;
+typedef struct _NactApplicationPrivate      NactApplicationPrivate;
 
 typedef struct {
 	/*< private >*/
@@ -61,7 +68,7 @@ typedef struct {
 }
 	NactApplication;
 
-typedef struct _NactApplicationClassPrivate  NactApplicationClassPrivate;
+typedef struct _NactApplicationClassPrivate NactApplicationClassPrivate;
 
 typedef struct {
 	/*< private >*/
@@ -70,9 +77,9 @@ typedef struct {
 }
 	NactApplicationClass;
 
-GType            nact_application_get_type( void );
+GType            nact_application_get_type   ( void );
 
-NactApplication *nact_application_new_with_args( int argc, char **argv );
+NactApplication *nact_application_new        ( void );
 
 NAUpdater       *nact_application_get_updater( const NactApplication *application );
 



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