[nautilus-actions] Initialization stuff goes to nact-application.c:startup_appli()
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Subject: [nautilus-actions] Initialization stuff goes to nact-application.c:startup_appli()
- Date: Thu, 11 Jun 2009 17:30:32 -0400 (EDT)
commit d0fc09d54caa056ae520e781242ed337b099b1d8
Author: Pierre Wieser <pwieser trychlos org>
Date: Thu Jun 11 23:31:01 2009 +0200
Initialization stuff goes to nact-application.c:startup_appli()
ChangeLog | 1 +
src/nact/nact-application.c | 190 +++++++++++++++++++++++++++++++++++++++++--
src/nact/nact-application.h | 17 +++--
src/nact/nact-main.c | 28 +-----
src/nact/nact.c | 26 ------
5 files changed, 198 insertions(+), 64 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8789d6e..b0cc3c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
* src/nact/nact-application.c:
* src/nact/nact-application.h: New NactApplication class.
+ Initialization stuff goes to nact-application.c:startup_appli().
* src/nact/nact-main.c: New file.
diff --git a/src/nact/nact-application.c b/src/nact/nact-application.c
index 1bb926f..a4aee3f 100644
--- a/src/nact/nact-application.c
+++ b/src/nact/nact-application.c
@@ -32,6 +32,10 @@
#include <config.h>
#endif
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "nact.h"
#include "nact-application.h"
/* private class data
@@ -43,15 +47,34 @@ struct NactApplicationClassPrivate {
*/
struct NactApplicationPrivate {
gboolean dispose_has_run;
+ int argc;
+ gpointer argv;
};
+/* private instance properties
+ */
+enum {
+ PROP_ARGC = 1,
+ PROP_ARGV
+};
+
+#define PROP_ARGC_STR "argc"
+#define PROP_ARGV_STR "argv"
+
static GObjectClass *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_dispose( GObject *application );
-static void instance_finalize( GObject *application );
+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 void initialize_i18n( NactApplication *application );
+static gboolean startup_appli( NactApplication *application );
+static int run_appli( NactApplication *application );
+static void finish_appli( NactApplication *application );
GType
nact_application_get_type( void )
@@ -68,6 +91,11 @@ nact_application_get_type( void )
static GType
register_type( void )
{
+ static const gchar *thisfn = "nact_application_register_type";
+ g_debug( "%s", thisfn );
+
+ g_type_init();
+
static GTypeInfo info = {
sizeof( NactApplicationClass ),
( GBaseInitFunc ) NULL,
@@ -91,9 +119,26 @@ class_init( NactApplicationClass *klass )
st_parent_class = g_type_class_peek_parent( klass );
- GObjectClass *application_class = G_OBJECT_CLASS( klass );
- application_class->dispose = instance_dispose;
- application_class->finalize = instance_finalize;
+ GObjectClass *object_class = G_OBJECT_CLASS( klass );
+ object_class->dispose = instance_dispose;
+ object_class->finalize = instance_finalize;
+ object_class->set_property = instance_set_property;
+ object_class->get_property = instance_get_property;
+
+ GParamSpec *spec;
+ spec = g_param_spec_int(
+ PROP_ARGC_STR,
+ PROP_ARGC_STR,
+ "Command-line arguments count", 0, 65535, 0,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
+ g_object_class_install_property( object_class, PROP_ARGC, spec );
+
+ spec = g_param_spec_pointer(
+ PROP_ARGV_STR,
+ PROP_ARGV_STR,
+ "Command-line arguments",
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
+ g_object_class_install_property( object_class, PROP_ARGV, spec );
klass->private = g_new0( NactApplicationClassPrivate, 1 );
}
@@ -113,6 +158,48 @@ instance_init( GTypeInstance *instance, gpointer klass )
}
static void
+instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec )
+{
+ g_assert( NACT_IS_APPLICATION( object ));
+ NactApplication *self = NACT_APPLICATION( object );
+
+ switch( property_id ){
+ case PROP_ARGC:
+ g_value_set_int( value, self->private->argc );
+ break;
+
+ case PROP_ARGV:
+ g_value_set_pointer( value, self->private->argv );
+ 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 )
+{
+ g_assert( NACT_IS_APPLICATION( object ));
+ NactApplication *self = NACT_APPLICATION( object );
+
+ switch( property_id ){
+ case PROP_ARGC:
+ self->private->argc = g_value_get_int( value );
+ break;
+
+ case PROP_ARGV:
+ self->private->argv = 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";
@@ -153,3 +240,90 @@ nact_application_new( void )
{
return( g_object_new( NACT_APPLICATION_TYPE, NULL ));
}
+
+/**
+ * Returns a newly allocated NactApplication object.
+ *
+ * @argc: count of command-line arguments.
+ *
+ * @argv: command-line arguments.
+ */
+NactApplication *
+nact_application_new_with_args( int argc, char *argv[] )
+{
+ return( g_object_new( NACT_APPLICATION_TYPE, PROP_ARGC_STR, argc, PROP_ARGV_STR, argv, NULL ));
+}
+
+static void
+initialize_i18n( NactApplication *application )
+{
+#ifdef ENABLE_NLS
+ bindtextdomain( GETTEXT_PACKAGE, GNOMELOCALEDIR );
+# ifdef HAVE_BIND_TEXTDOMAIN_CODESET
+ bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" );
+# endif
+ textdomain( GETTEXT_PACKAGE );
+#endif
+}
+
+static gboolean
+startup_appli( NactApplication *application )
+{
+ int argc;
+ char **argv;
+ int ret = TRUE;
+
+ initialize_i18n( application );
+
+ argc = application->private->argc;
+ argv = ( char ** ) application->private->argv;
+ gtk_init( &argc, &argv );
+
+ g_set_application_name( PACKAGE );
+ gtk_window_set_default_icon_name( PACKAGE );
+
+ /* create main dialog */
+ nact_init_dialog ();
+
+ return( ret );
+}
+
+static int
+run_appli( NactApplication *application )
+{
+ int code = 0;
+
+ gtk_main();
+
+ return( code );
+}
+
+static void
+finish_appli( NactApplication *application )
+{
+}
+
+/**
+ * This a the whole run management for the NactApplication Object.
+ *
+ * @app: the considered NactApplication object.
+ *
+ * The returned integer should be returned to the OS.
+ */
+int
+nact_application_run( NactApplication *application )
+{
+ static const gchar *thisfn = "nact_application_run";
+ g_debug( "%s: application=%p", thisfn, application );
+
+ g_assert( NACT_IS_APPLICATION( application ));
+
+ int code = 0;
+
+ if( startup_appli( application )){
+ code = run_appli( application );
+ finish_appli( application );
+ }
+
+ return( code );
+}
diff --git a/src/nact/nact-application.h b/src/nact/nact-application.h
index b22355b..7a8ad00 100644
--- a/src/nact/nact-application.h
+++ b/src/nact/nact-application.h
@@ -41,12 +41,12 @@
G_BEGIN_DECLS
-#define NACT_APPLICATION_TYPE ( nact_application_get_type())
-#define NACT_APPLICATION( application ) ( G_TYPE_CHECK_INSTANCE_CAST( application, NACT_APPLICATION_TYPE, NactApplication ))
-#define NACT_APPLICATION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( klass, NACT_APPLICATION_TYPE, NactApplicationClass ))
-#define NACT_IS_APPLICATION( application ) ( G_TYPE_CHECK_INSTANCE_TYPE( application, NACT_APPLICATION_TYPE ))
-#define NACT_IS_APPLICATION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE(( klass ), NACT_APPLICATION_TYPE ))
-#define NACT_APPLICATION_GET_CLASS( application ) ( G_TYPE_INSTANCE_GET_CLASS(( application ), NACT_APPLICATION_TYPE, NactApplicationClass ))
+#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 ))
typedef struct NactApplicationPrivate NactApplicationPrivate;
@@ -66,7 +66,10 @@ typedef struct {
GType nact_application_get_type( void );
-NactApplication *nact_application_new( void);
+NactApplication *nact_application_new( void );
+NactApplication *nact_application_new_with_args( int argc, char *argv[] );
+
+int nact_application_run( NactApplication *application );
G_END_DECLS
diff --git a/src/nact/nact-main.c b/src/nact/nact-main.c
index cb71fd8..3d0d63c 100644
--- a/src/nact/nact-main.c
+++ b/src/nact/nact-main.c
@@ -32,34 +32,16 @@
#include <config.h>
#endif
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-
-#include <common/nautilus-actions-config-gconf-writer.h>
-
-#include "nact.h"
+#include "nact-application.h"
int
main( int argc, char *argv[] )
{
- /* initialize application */
-#ifdef ENABLE_NLS
- bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
-# ifdef HAVE_BIND_TEXTDOMAIN_CODESET
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-# endif
- textdomain (GETTEXT_PACKAGE);
-#endif
-
- gtk_init (&argc, &argv);
+ NactApplication *app = nact_application_new_with_args( argc, argv );
- g_set_application_name (PACKAGE);
- gtk_window_set_default_icon_name (PACKAGE);
+ int ret = nact_application_run( app );
- /* create main dialog */
- nact_init_dialog ();
+ g_object_unref( app );
- /* run the application */
- gtk_main ();
- return 0;
+ return( ret );
}
diff --git a/src/nact/nact.c b/src/nact/nact.c
index 09bbb68..8f4ea4e 100644
--- a/src/nact/nact.c
+++ b/src/nact/nact.c
@@ -413,29 +413,3 @@ nact_init_dialog (void)
gtk_widget_show (nact_dialog);
g_object_unref (gui);
}
-
-/*int
-main (int argc, char *argv[])
-{*/
- /* initialize application */
-/*#ifdef ENABLE_NLS
- bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
-# ifdef HAVE_BIND_TEXTDOMAIN_CODESET
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-# endif
- textdomain (GETTEXT_PACKAGE);
-#endif
-
- gtk_init (&argc, &argv);
-
- config = nautilus_actions_config_gconf_writer_get ();
- g_set_application_name (PACKAGE);
- gtk_window_set_default_icon_name (PACKAGE);*/
-
- /* create main dialog */
- /*init_dialog ();*/
-
- /* run the application */
- /*gtk_main ();
- return 0;
-}*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]