Bug 307312: gnome_program_init () should support GOption



Here is a patch set, which enables the use of goption to libgnome. This
should help move away from libgnome and popt for gnome apps. I used
expansion1 in GnomeModuleInfo to get GOptionGroup from all the modules.

There are 4 new GNOME PARMS
- PARM_GOPTION_CONTEXT (readonly) - GOption Context
- PARM_GOPTION_TABLE - The Applications GOptionEntry
- PARM_GOPTION_NAME - The name to add to help
- PARM_GOPTION_ENABLE - tell libgnome to use goption (default is FALSE)

I needed to patch libgnome,libgnomeui,libbonobo and libbonobui.

I also added a test case for people that want to try it out.

The help output look like this with goption enable:

Usage:
  test [OPTION...] - Test

Help Options:
  -?, --help                       Show help options
  --help-all                       Show all help options
  --help-gtk                       Show GTK+ Options
  --help-bonbo_activation          Show Bonobo Activation Options
  --help-libgnome                  Show Gnome Library Options
  --help-gnome-client              Show Session management Options
  --help-libgnomeui                Show GNOME GUI Library Options

Application Options:
  --encoding                       Set the character encoding to be used to open  the files listed on the command line
  --quit                           Quit an existing instance of gedit
  --new-window                     Create a new toplevel window in an existing i nstance of gedit
  --new-document                   Create a new document in an existing instance  of gedit
  --display=DISPLAY                X display to use



#include <libgnome/libgnome.h>
#include <glib/goption.h>
#include <libgnomeui/libgnomeui.h>
#include <popt.h>

static gchar *encoding_charset = NULL;
static gboolean quit_option = FALSE;
static gboolean new_window_option = FALSE;
static gboolean new_document_option = FALSE;

static const struct poptOption options [] =
{
	{ "encoding", '\0', POPT_ARG_STRING, &encoding_charset,	0,
	  N_("Set the character encoding to be used to open the files listed on the command line"), NULL },

	{ "quit", '\0', POPT_ARG_NONE, &quit_option, 0,
	  N_("Quit an existing instance of gedit"), NULL },

	{ "new-window", '\0', POPT_ARG_NONE, &new_window_option, 0,
	  N_("Create a new toplevel window in an existing instance of gedit"), NULL },

	{ "new-document", '\0', POPT_ARG_NONE, &new_document_option, 0,
	  N_("Create a new document in an existing instance of gedit"), NULL },

	{NULL, '\0', 0, NULL, 0}
};

static GOptionEntry goptions [] =
{
	{ "encoding", '\0',0, G_OPTION_ARG_STRING, &encoding_charset,
	  N_("Set the character encoding to be used to open the files listed on the command line"), NULL },

	{ "quit", '\0',0, G_OPTION_ARG_NONE, &quit_option, 
	  N_("Quit an existing instance of gedit"), NULL },

	{ "new-window", '\0',0, G_OPTION_ARG_NONE, &new_window_option, 
	  N_("Create a new toplevel window in an existing instance of gedit"), NULL },

	{ "new-document", '\0',0, G_OPTION_ARG_NONE, &new_document_option, 
	  N_("Create a new document in an existing instance of gedit"), NULL },

	{ NULL }
};

int
main (int argc, char **argv)
{
    	GnomeProgram *program;
	gboolean restored = FALSE;

	/* Initialize gnome program */
	program = gnome_program_init ("gedit", "1.2.3",
			    LIBGNOMEUI_MODULE, argc, argv,
			    //Don't need popt, but making sure it does screw things up
			    GNOME_PARAM_POPT_TABLE, options,
			    GNOME_PARAM_GOPTION_NAME, _("- Test"),
			    GNOME_PARAM_GOPTION_TABLE, goptions,
			    GNOME_PARAM_GOPTION_ENABLE, TRUE,
			    GNOME_PARAM_HUMAN_READABLE_NAME,
		            _("Text Editor"),
			    NULL);
	g_print("Test: %s\n",encoding_charset);
	g_object_unref (program);
	return 0;
}

? libbonobo-zip
Index: bonobo-activation/bonobo-activation-init.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo-activation/bonobo-activation-init.c,v
retrieving revision 1.62
diff -u -r1.62 bonobo-activation-init.c
--- bonobo-activation/bonobo-activation-init.c	25 Feb 2005 02:40:14 -0000	1.62
+++ bonobo-activation/bonobo-activation-init.c	19 Jun 2005 18:16:41 -0000
@@ -262,6 +262,26 @@
         { NULL }
 };
 
+GOptionEntry bonobo_activation_goption_options[] = {
+        { "oaf-ior-fd", '\0', 0,  G_OPTION_ARG_INT, &bonobo_activation_ior_fd, 
+          N_("File descriptor to print IOR on"), N_("FD") },
+        { "oaf-activate-iid", '\0', 0, G_OPTION_ARG_STRING, &bonobo_activation_activate_iid, 
+          N_("IID to activate"), "IID" },
+        { "oaf-private", '\0', 0, G_OPTION_ARG_NONE, &bonobo_activation_private, 
+          N_("Prevent registering of server with OAF"), NULL },
+        { NULL }
+};
+
+GOptionGroup * bonobo_activation_get_goption_group ()
+{
+	GOptionGroup * bonobo_activation_group;
+	bonobo_activation_group = g_option_group_new("bonbo_activation",_("Bonobo Activation"), _("Show Bonobo Activation Options"), NULL, NULL);
+	g_option_group_add_entries(bonobo_activation_group, bonobo_activation_goption_options);
+	g_option_group_set_translation_domain (bonobo_activation_group, GETTEXT_PACKAGE);
+
+	return bonobo_activation_group;
+}
+
 /**
  * bonobo_activation_activation_iid_get:
  *
Index: bonobo-activation/bonobo-activation-init.h
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo-activation/bonobo-activation-init.h,v
retrieving revision 1.9
diff -u -r1.9 bonobo-activation-init.h
--- bonobo-activation/bonobo-activation-init.h	25 Feb 2005 02:40:14 -0000	1.9
+++ bonobo-activation/bonobo-activation-init.h	19 Jun 2005 18:16:41 -0000
@@ -26,6 +26,7 @@
 
 #include <orbit/orbit.h>
 #include <popt.h>
+#include <glib/goption.h>
 
 G_BEGIN_DECLS
 
@@ -55,6 +56,8 @@
 
 extern struct poptOption bonobo_activation_popt_options[];
 
+GOptionGroup * bonobo_activation_get_goption_group();
+
 G_END_DECLS
 
 #endif /* BONOBO_ACTIVATION_INIT_H */
? depcomp
? gtk-doc.make
? libbonoboui-zip
Index: bonobo/bonobo-ui-init-gtk.c
===================================================================
RCS file: /cvs/gnome/libbonoboui/bonobo/bonobo-ui-init-gtk.c,v
retrieving revision 1.6
diff -u -r1.6 bonobo-ui-init-gtk.c
--- bonobo/bonobo-ui-init-gtk.c	22 Jan 2004 00:10:50 -0000	1.6
+++ bonobo/bonobo-ui-init-gtk.c	19 Jun 2005 19:15:50 -0000
@@ -12,49 +12,63 @@
 bonobo_ui_gtk_pre_args_parse (GnomeProgram    *program,
 			      GnomeModuleInfo *mod_info)
 {
-	bonobo_ui_gtk_init_info_t *init_info = g_new0 (bonobo_ui_gtk_init_info_t, 1);
-
-	init_info->gtk_args = g_ptr_array_new ();
-
-	g_object_set_data (G_OBJECT (program),
+	GValue goption_enable = { 0 };
+	g_value_init (&goption_enable, G_TYPE_BOOLEAN);
+	g_object_get_property (G_OBJECT (program),
+		GNOME_PARAM_GOPTION_ENABLE,&goption_enable);
+	
+	if (!g_value_get_boolean(&goption_enable)) {
+		bonobo_ui_gtk_init_info_t *init_info = g_new0 (bonobo_ui_gtk_init_info_t, 1);
+		init_info->gtk_args = g_ptr_array_new ();
+		g_object_set_data (G_OBJECT (program),
 			   "Libbonoboui-Gtk-Module-init-info",
 			   init_info);
+	}
+	g_value_unset (&goption_enable);
+
 }
 
 static void
 bonobo_ui_gtk_post_args_parse (GnomeProgram    *program,
 			       GnomeModuleInfo *mod_info)
 {
-	bonobo_ui_gtk_init_info_t *init_info;
-	int final_argc;
-	char **final_argv;
-	int i;
+	GValue goption_enable = { 0 };
+	g_value_init (&goption_enable, G_TYPE_BOOLEAN);
+	g_object_get_property (G_OBJECT (program),
+		GNOME_PARAM_GOPTION_ENABLE,&goption_enable);
+	
+	if (!g_value_get_boolean(&goption_enable)) {
+		bonobo_ui_gtk_init_info_t *init_info;
+		int final_argc;
+		char **final_argv;
+		int i;
 
-	init_info = g_object_get_data (G_OBJECT (program),
+		init_info = g_object_get_data (G_OBJECT (program),
 				       "Libbonoboui-Gtk-Module-init-info");
 
-	g_ptr_array_add (init_info->gtk_args, NULL);
+		g_ptr_array_add (init_info->gtk_args, NULL);
 
-	final_argc = init_info->gtk_args->len - 1;
-	final_argv = g_memdup (init_info->gtk_args->pdata,
+		final_argc = init_info->gtk_args->len - 1;
+		final_argv = g_memdup (init_info->gtk_args->pdata,
 			       sizeof (char *) * init_info->gtk_args->len);
 
-	gtk_init (&final_argc, &final_argv);
+		gtk_init (&final_argc, &final_argv);
 
-	g_free (final_argv);
+		g_free (final_argv);
 
-	for (i = 0; g_ptr_array_index (init_info->gtk_args, i) != NULL; i++) {
-		g_free (g_ptr_array_index (init_info->gtk_args, i));
-		g_ptr_array_index (init_info->gtk_args, i) = NULL;
-	}
-
-	g_ptr_array_free (init_info->gtk_args, TRUE);
-	init_info->gtk_args = NULL;
-	g_free (init_info);
+		for (i = 0; g_ptr_array_index (init_info->gtk_args, i) != NULL; i++) {
+			g_free (g_ptr_array_index (init_info->gtk_args, i));
+			g_ptr_array_index (init_info->gtk_args, i) = NULL;
+		}
 
-	g_object_set_data (G_OBJECT (program),
-			   "Libbonoboui-Gtk-Module-init-info",
-			   NULL);
+		g_ptr_array_free (init_info->gtk_args, TRUE);
+		init_info->gtk_args = NULL;
+		g_free (init_info);
+
+		g_object_set_data (G_OBJECT (program),
+				   "Libbonoboui-Gtk-Module-init-info",
+				   NULL);
+	}
 }
 
 static void
@@ -165,6 +179,9 @@
 		NULL,
 		NULL, NULL, NULL
 	};
+	
+	module_info.expansion1 = (gpointer) gtk_get_option_group(TRUE);
+
 	if (module_info.version == NULL) {
 		module_info.version = g_strdup_printf ("%d.%d.%d",
 						       GTK_MAJOR_VERSION,
? compile.log
? depcomp
? gtk-doc.make
? libgnome-zip
? stamp-h1
? doc/reference/version.xml
? libgnome/stamp-libgnometypebuiltins.h
Index: libgnome/gnome-init.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-init.c,v
retrieving revision 1.110
diff -u -r1.110 gnome-init.c
--- libgnome/gnome-init.c	28 Mar 2005 15:45:07 -0000	1.110
+++ libgnome/gnome-init.c	19 Jun 2005 18:25:07 -0000
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 
 #include <glib.h>
+#include <glib/goption.h>
 #include <glib/gstdio.h>
 #include "gnome-i18nP.h"
 
@@ -146,6 +147,9 @@
 		bonobo_activation_pre_args_parse, bonobo_activation_post_args_parse,
 		bonobo_activation_popt_options
 	};
+
+	module_info.expansion1 = (gpointer) bonobo_activation_get_goption_group();
+
 	if (module_info.version == NULL) {
 		module_info.version = g_strdup_printf
 			("%d.%d.%d",
@@ -263,6 +267,67 @@
 	}
 }
 
+static gboolean
+libgnome_goption_epeaker (const gchar *option_name,
+			const gchar *value,
+			gpointer data,
+			GError **error)
+{
+	GValue setvalue = { 0 };
+	g_value_init (&setvalue, G_TYPE_STRING);
+	g_value_set_string (&setvalue, value);
+	g_object_set_property (G_OBJECT (gnome_program_get()),
+		GNOME_PARAM_ESPEAKER, &setvalue);
+	g_value_unset (&setvalue);
+	return TRUE;
+}
+
+static gboolean
+libgnome_goption_disable_sound (const gchar *option_name,
+			const gchar *value,
+			gpointer data,
+			GError **error)
+{
+	GValue setvalue = { 0 };
+	g_value_init (&setvalue, G_TYPE_BOOLEAN);
+	g_value_set_boolean (&setvalue, FALSE);
+	g_object_set_property (G_OBJECT (gnome_program_get()),
+		GNOME_PARAM_ENABLE_SOUND, &setvalue);
+	g_value_unset (&setvalue);
+	return TRUE;
+}
+
+static gboolean
+libgnome_goption_enable_sound (const gchar *option_name,
+			const gchar *value,
+			gpointer data,
+			GError **error)
+{
+	GValue setvalue = { 0 };
+	g_value_init (&setvalue, G_TYPE_BOOLEAN);
+	g_value_set_boolean (&setvalue, TRUE);
+	
+	g_object_set_property (G_OBJECT (gnome_program_get()),
+		GNOME_PARAM_ENABLE_SOUND, &setvalue);
+	
+	g_value_unset (&setvalue);
+	return TRUE;
+}
+
+static void 
+libgnome_goption_version (void)
+{
+	GnomeProgram *program;
+
+	program = gnome_program_get ();
+
+	g_print ("Gnome %s %s\n",
+		gnome_program_get_app_id (program),
+		gnome_program_get_app_version (program));
+	
+	exit(0);
+}
+
 static int
 safe_mkdir (const char *pathname, mode_t mode)
 {
@@ -423,6 +488,24 @@
 	  NULL, 0 , NULL, NULL}
 };
 
+static GOptionEntry gnomelib_goptions [] = {
+	{ "disable-sound", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,                                 
+	  libgnome_goption_disable_sound, N_("Disable sound server usage"), NULL},     
+
+	{ "enable-sound", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,                                  
+	  libgnome_goption_enable_sound, N_("Enable sound server usage"), NULL},       
+
+	{ "espeaker", 'e',0, G_OPTION_ARG_CALLBACK,                                    
+	  libgnome_goption_epeaker, N_("Host:port on which the sound server to use is"
+				 " running"),
+	  N_("HOSTNAME:PORT")},                                                 
+
+	{"version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+	 (GOptionArgFunc) libgnome_goption_version, VERSION, NULL},
+	
+	{ NULL }
+};
+
 #ifndef G_OS_WIN32
 
 static void
@@ -467,6 +550,12 @@
 		NULL, NULL, NULL, NULL
 	};
 	int i = 0;
+	
+	GOptionGroup * gnomelib_group;
+	gnomelib_group = g_option_group_new("libgnome",_("GNOME Library"),_("Show Gnome Library Options"), NULL, NULL);
+	g_option_group_add_entries(gnomelib_group, gnomelib_goptions);
+	g_option_group_set_translation_domain (gnomelib_group, GETTEXT_PACKAGE);
+	module_info.expansion1 = (gpointer) gnomelib_group;
 
 	if (module_info.requirements == NULL) {
 		static GnomeModuleRequirement req[4];
Index: libgnome/gnome-program.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-program.c,v
retrieving revision 1.77
diff -u -r1.77 gnome-program.c
--- libgnome/gnome-program.c	9 Jun 2005 08:57:30 -0000	1.77
+++ libgnome/gnome-program.c	19 Jun 2005 18:25:08 -0000
@@ -75,6 +75,9 @@
     /* Construction properties */
     int prop_popt_flags;
     struct poptOptions *prop_popt_table;
+    GOptionEntry *prop_goption_table;
+    gboolean prop_goption_enable;
+    gchar *prop_goption_name;
     gchar *prop_human_readable_name;
     gchar *prop_gnome_prefix;
     gchar *prop_gnome_libdir;
@@ -98,6 +101,7 @@
 
     /* valid-while: state == APP_PREINIT_DONE */
     poptContext arg_context;
+    GOptionContext *goption_context;
 
     /* valid-while: state == APP_PREINIT_DONE */
     GArray *top_options_table;
@@ -124,6 +128,10 @@
     PROP_POPT_TABLE,
     PROP_POPT_FLAGS,
     PROP_POPT_CONTEXT,
+    PROP_GOPTION_TABLE,
+    PROP_GOPTION_CONTEXT,
+    PROP_GOPTION_ENABLE,
+    PROP_GOPTION_NAME,
     PROP_LAST
 };
 
@@ -157,6 +165,15 @@
     program = GNOME_PROGRAM (object);
 
     switch (param_id) {
+    case PROP_GOPTION_ENABLE:
+	program->_priv->prop_goption_enable = g_value_get_boolean (value);
+	break;
+    case PROP_GOPTION_TABLE:
+	program->_priv->prop_goption_table = g_value_peek_pointer (value);
+	break;
+    case PROP_GOPTION_NAME:
+	program->_priv->prop_goption_name = g_value_dup_string (value);
+	break;
     case PROP_POPT_TABLE:
 	program->_priv->prop_popt_table = g_value_peek_pointer (value);
 	break;
@@ -256,6 +273,18 @@
     case PROP_POPT_CONTEXT:
 	g_value_set_pointer (value, program->_priv->arg_context);
 	break;
+    case PROP_GOPTION_CONTEXT:
+	g_value_set_pointer (value, program->_priv->goption_context);
+	break;
+    case PROP_GOPTION_NAME:
+	g_value_set_string (value, program->_priv->prop_goption_name);
+	break;
+    case PROP_GOPTION_TABLE:
+	g_value_set_pointer (value, program->_priv->prop_goption_table);
+	break;
+    case PROP_GOPTION_ENABLE:
+	g_value_set_boolean (value, program->_priv->prop_goption_enable);
+	break;
     case PROP_GNOME_PATH:
 	if (program->_priv->gnome_path)
 	    g_value_take_string (value, g_strjoinv (":", program->_priv->gnome_path));
@@ -458,6 +487,44 @@
 
     g_object_class_install_property
 	(object_class,
+	 PROP_GOPTION_TABLE,
+	 g_param_spec_pointer (GNOME_PARAM_GOPTION_TABLE,
+			       _("GOption Table"), 
+			       _("The table of options for goption"),
+			      (G_PARAM_READABLE | G_PARAM_WRITABLE |
+			       G_PARAM_CONSTRUCT_ONLY)));
+ 
+    g_object_class_install_property
+	(object_class,
+	 PROP_GOPTION_NAME,
+	 g_param_spec_string (GNOME_PARAM_GOPTION_NAME,
+			       _("GOption Name"), 
+			       _("The string displayed after programname [OPTION..]"),
+			       NULL,
+			      (G_PARAM_READABLE | G_PARAM_WRITABLE |
+			       G_PARAM_CONSTRUCT_ONLY)));
+
+    g_object_class_install_property
+	(object_class,
+	 PROP_GOPTION_ENABLE,
+	 g_param_spec_boolean (GNOME_PARAM_GOPTION_ENABLE,
+			       _("Enable GOption"), 
+			       _("To turn on goption parsing"),
+			       FALSE,
+			      (G_PARAM_READABLE | G_PARAM_WRITABLE |
+			       G_PARAM_CONSTRUCT_ONLY)));
+
+    g_object_class_install_property
+	(object_class,
+	 PROP_GOPTION_CONTEXT,
+	 g_param_spec_pointer (GNOME_PARAM_GOPTION_CONTEXT,
+			      _("Goption Context"), 
+			      _("The goption context pointer that GnomeProgram "
+				"is using"),
+			       (G_PARAM_READABLE)));
+
+    g_object_class_install_property
+	(object_class,
 	 PROP_HUMAN_READABLE_NAME,
 	 g_param_spec_string (GNOME_PARAM_HUMAN_READABLE_NAME,
 			      _("Human readable name"), 
@@ -613,7 +680,7 @@
     program->_priv->state = APP_CREATE_DONE;
 
     program->_priv->prop_enable_sound = TRUE;
-    
+
     for (i = 0; i < program_modules->len; i++) {
 	GnomeModuleInfo *a_module = g_ptr_array_index (program_modules, i);
 
@@ -640,6 +707,7 @@
 
 	/* no free */
 	self->_priv->prop_popt_table = NULL;
+	self->_priv->prop_goption_table = NULL;
 
 	g_free (self->_priv->prop_human_readable_name);
 	self->_priv->prop_human_readable_name = NULL;
@@ -662,6 +730,9 @@
 	g_free (self->_priv->prop_espeaker);
 	self->_priv->prop_espeaker = NULL;
 
+	g_free (self->_priv->prop_goption_name);
+	self->_priv->prop_goption_name = NULL;
+	
 	g_strfreev (self->_priv->gnome_path);
 	self->_priv->gnome_path = NULL;
 
@@ -679,6 +750,12 @@
 	}
 	self->_priv->arg_context = NULL;
 
+	if (self->_priv->goption_context != NULL) {
+		g_option_context_free(self->_priv->goption_context);
+		g_dataset_destroy (self->_priv->goption_context);
+	}
+	self->_priv->goption_context = NULL;
+
 	if (self->_priv->top_options_table != NULL)
 		g_array_free (self->_priv->top_options_table, TRUE);
 	self->_priv->top_options_table = NULL;
@@ -1275,7 +1352,7 @@
 		       int argc, char **argv)
 {
     GnomeModuleInfo *a_module;
-    poptContext argctx;
+    poptContext argctx=NULL;
     int i;
 
     g_return_val_if_fail (program != NULL, NULL);
@@ -1340,8 +1417,31 @@
 	}
     }
 
-    /* 5. Create a top-level 'struct poptOption *' for use in arg-parsing. */
-    {
+    /* 5. Create a top-level 'struct poptOption *'/' for use in arg-parsing or GOptionContext
+     * with all the GOptionGroups*/
+    if (program->_priv->prop_goption_enable) {
+
+	program->_priv->goption_context = 
+		g_option_context_new (program->_priv->prop_goption_name);    
+
+	if (program->_priv->prop_goption_table) {
+		g_option_context_add_main_entries (
+			program->_priv->goption_context,
+			program->_priv->prop_goption_table,
+			GETTEXT_PACKAGE);
+	}
+
+	for (i = 0; (a_module = g_ptr_array_index(program_modules, i)); i++) {
+		if (a_module->expansion1) {
+			g_option_context_add_group (
+					program->_priv->goption_context,
+					(GOptionGroup*) a_module->expansion1);
+
+		}
+	}
+
+    } else {
+
 	struct poptOption includer = {NULL, '\0', POPT_ARG_INCLUDE_TABLE,
 				      NULL, 0, NULL, NULL};
 	struct poptOption callback =
@@ -1386,16 +1486,15 @@
 	includer.descrip = _("Dynamic modules to load");
 	includer.argDescrip = _("MODULE1,MODULE2,...");
 	g_array_append_val (program->_priv->top_options_table, includer);
-    }
 
-    argctx = program->_priv->arg_context = poptGetContext
-	(program->_priv->app_id, argc, (const char **) argv,
-	 (struct poptOption *) program->_priv->top_options_table->data,
-	 program->_priv->prop_popt_flags);
-  
+    	argctx = program->_priv->arg_context = poptGetContext
+		(program->_priv->app_id, argc, (const char **) argv,
+		 (struct poptOption *) program->_priv->top_options_table->data,
+		 program->_priv->prop_popt_flags);
+    }
     /* 7. Cleanup/return */
     program->_priv->state = APP_PREINIT_DONE;
-
+    
     return argctx;
 }
 
@@ -1449,30 +1548,38 @@
 void
 gnome_program_parse_args (GnomeProgram *program)
 {
-    int nextopt;
-    poptContext ctx;
+	g_return_if_fail (program != NULL);
+	g_return_if_fail (GNOME_IS_PROGRAM (program));
 
-    g_return_if_fail (program != NULL);
-    g_return_if_fail (GNOME_IS_PROGRAM (program));
+	if (program->_priv->state != APP_PREINIT_DONE)
+		return;
 
-    if (program->_priv->state != APP_PREINIT_DONE)
-	return;
+	if (program->_priv->prop_goption_enable) {
+		GOptionContext *gctx = program->_priv->goption_context;
+		gint argc = program->_priv->argc;
+		gchar **argv = program->_priv->argv;
+		g_option_context_parse(gctx,&argc,&argv,NULL);
 
-    /* translate popt output by default */
+	} else {
+		/* translate popt output by default */
+		int nextopt;
+		poptContext ctx;
 #ifdef ENABLE_NLS
-    setlocale (LC_ALL, "");
+		setlocale (LC_ALL, "");
 #endif
-    ctx = program->_priv->arg_context;
-    while ((nextopt = poptGetNextOpt (ctx)) > 0 || nextopt == POPT_ERROR_BADOPT)
-	/* do nothing */ ;
-
-    if (nextopt != -1) {
-	g_print ("Error on option %s: %s.\nRun '%s --help' to see a full list of available command line options.\n",
-		 poptBadOption (ctx, 0),
-		 poptStrerror (nextopt),
-		 program->_priv->argv[0]);
-	exit (1);
-    }
+		ctx = program->_priv->arg_context;
+		while ((nextopt = poptGetNextOpt (ctx)) > 0 || nextopt == POPT_ERROR_BADOPT)
+			/* do nothing */ ;
+
+		if (nextopt != -1) {
+			g_print ("Error on option %s: %s.\nRun '%s --help' to see a full list of available command line options.\n",
+			poptBadOption (ctx, 0),
+			poptStrerror (nextopt),
+			program->_priv->argv[0]);
+			exit (1);
+		}
+	
+	}
 }
 
 static char *
Index: libgnome/gnome-program.h
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-program.h,v
retrieving revision 1.29
diff -u -r1.29 gnome-program.h
--- libgnome/gnome-program.h	19 Jul 2004 09:49:59 -0000	1.29
+++ libgnome/gnome-program.h	19 Jun 2005 18:25:09 -0000
@@ -32,6 +32,7 @@
 #define GNOME_PROGRAM_H
 
 #include <glib.h>
+#include <glib/goption.h>
 #include <popt.h>
 #include <stdarg.h>
 #include <errno.h>
@@ -113,6 +114,10 @@
 #define GNOME_PARAM_POPT_TABLE          "popt-table"
 #define GNOME_PARAM_POPT_FLAGS          "popt-flags"
 #define GNOME_PARAM_POPT_CONTEXT        "popt-context"
+#define GNOME_PARAM_GOPTION_TABLE       "goption-table"
+#define GNOME_PARAM_GOPTION_ENABLE      "goption-enable"
+#define GNOME_PARAM_GOPTION_CONTEXT     "goption-context"
+#define GNOME_PARAM_GOPTION_NAME	"goption-name"
 #define GNOME_PARAM_CREATE_DIRECTORIES  "create-directories"
 #define GNOME_PARAM_ENABLE_SOUND        "enable-sound"
 #define GNOME_PARAM_ESPEAKER            "espeaker"
? depcomp
? gtk-doc.make
? libgnomeui-zip
? stamp-h1
? libgnomeui/stamp-gnome-marshal.h
? libgnomeui/stamp-gnometypebuiltins.h
Index: libgnomeui/gnome-client.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-client.c,v
retrieving revision 1.137
diff -u -r1.137 gnome-client.c
--- libgnomeui/gnome-client.c	13 May 2005 14:33:56 -0000	1.137
+++ libgnomeui/gnome-client.c	19 Jun 2005 18:25:54 -0000
@@ -846,6 +846,22 @@
 			       enum poptCallbackReason reason,
 			       const struct poptOption *opt,
 			       const char *arg, void *data);
+
+static gboolean gnome_client_goption_sm_client_id (const gchar *option_name,
+						const gchar *value,
+						gpointer data,
+						GError **error);
+
+static gboolean gnome_client_goption_sm_config_prefix (const gchar *option_name,
+						const gchar *value,
+						gpointer data,
+						GError **error);
+
+static gboolean gnome_client_goption_sm_disable (const gchar *option_name,
+						const gchar *value,
+						gpointer data,
+						GError **error);
+
 static void gnome_client_pre_args_parse(GnomeProgram *app, GnomeModuleInfo *mod_info);
 static void gnome_client_post_args_parse(GnomeProgram *app, GnomeModuleInfo *mod_info);
 
@@ -869,6 +885,19 @@
   {NULL, '\0', 0, NULL, 0}
 };
 
+static const GOptionEntry session_goptions[] = {
+  {"sm-client-id", '\0', 0, G_OPTION_ARG_CALLBACK, gnome_client_goption_sm_client_id, 
+   N_("Specify session management ID"), N_("ID")},
+
+  {"sm-config-prefix", '\0', 0, G_OPTION_ARG_CALLBACK, gnome_client_goption_sm_config_prefix, 
+   N_("Specify prefix of saved configuration"), N_("PREFIX")},
+
+  {"sm-disable", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, gnome_client_goption_sm_disable, 
+   N_("Disable connection to session manager"), NULL},
+
+  { NULL }
+};
+
 typedef struct {
 	guint sm_connect_id;
 } GnomeProgramClass_gnome_client;
@@ -978,6 +1007,12 @@
 		NULL, NULL
 	};
 
+	GOptionGroup * session_group;
+	session_group = g_option_group_new("gnome-client",_("Session management"),_("Show Session management Options"), NULL, NULL);
+	g_option_group_add_entries(session_group, session_goptions);
+	g_option_group_set_translation_domain (session_group, GETTEXT_PACKAGE);
+	module_info.expansion1 = (gpointer) session_group;
+
 	if (module_info.requirements == NULL) {
 		static GnomeModuleRequirement req[3];
 
@@ -1028,6 +1063,40 @@
   }
 }
 
+static gboolean
+gnome_client_goption_sm_client_id (const gchar *option_name,
+			const gchar *value,
+			gpointer data,
+			GError **error)
+{
+	gnome_client_set_id (master_client, value);
+	return TRUE;
+}
+
+static gboolean
+gnome_client_goption_sm_disable (const gchar *option_name,
+			const gchar *value,
+			gpointer data,
+			GError **error)
+{
+	g_object_set (G_OBJECT (gnome_program_get()),
+		GNOME_CLIENT_PARAM_SM_CONNECT, FALSE, NULL);
+	return TRUE;
+}
+
+static gboolean
+gnome_client_goption_sm_config_prefix (const gchar *option_name,
+			const gchar *value,
+			gpointer data,
+			GError **error)
+{
+	if(master_client->config_prefix)
+		g_free(master_client->config_prefix);
+	master_client->config_prefix= g_strdup (value);
+	master_client_restored = TRUE;
+ 
+	return TRUE;
+}
 
 static void
 gnome_client_pre_args_parse(GnomeProgram *app, GnomeModuleInfo *mod_info)
Index: libgnomeui/gnome-ui-init.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-ui-init.c,v
retrieving revision 1.196
diff -u -r1.196 gnome-ui-init.c
--- libgnomeui/gnome-ui-init.c	16 May 2005 11:14:23 -0000	1.196
+++ libgnomeui/gnome-ui-init.c	19 Jun 2005 18:25:55 -0000
@@ -80,6 +80,14 @@
 					 const struct poptOption * opt,
 					 const char * arg,
 					 void * data);
+static gboolean libgnomeui_goption_disable_crash_dialog (const gchar *option_name,
+						const gchar *value,
+						gpointer data,
+						GError **error);
+static gboolean libgnomeui_goption_display (const gchar *option_name,
+						const gchar *value,
+						gpointer data,
+						GError **error);
 static void libgnomeui_init_pass	(const GnomeModuleInfo *mod_info);
 static void libgnomeui_class_init	(GnomeProgramClass *klass,
 					 const GnomeModuleInfo *mod_info);
@@ -124,6 +132,14 @@
 	{NULL, '\0', 0, NULL, 0, NULL, NULL}
 };
 
+static GOptionEntry libgnomeui_goptions[] = {
+	{"disable-crash-dialog", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, 
+	libgnomeui_goption_disable_crash_dialog, N_("Disable Crash Dialog"), NULL},
+        {"display", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+	libgnomeui_goption_display, N_("X display to use"), N_("DISPLAY")},
+	{ NULL }
+};
+
 const GnomeModuleInfo *
 libgnomeui_module_info_get (void)
 {
@@ -136,6 +152,12 @@
 		NULL, NULL
 	};
 
+	GOptionGroup * libgnomeui_group;
+	libgnomeui_group = g_option_group_new("libgnomeui",_("GNOME GUI Library"),_("Show GNOME GUI Library Options"), NULL, NULL);
+	g_option_group_add_entries(libgnomeui_group, libgnomeui_goptions);
+	g_option_group_set_translation_domain (libgnomeui_group, GETTEXT_PACKAGE);
+	module_info.expansion1 = (gpointer) libgnomeui_group;
+
 	if (module_info.requirements == NULL) {
 		static GnomeModuleRequirement req[6];
 
@@ -593,6 +615,36 @@
         }
 }
 
+static gboolean libgnomeui_goption_disable_crash_dialog (const gchar *option_name,
+						const gchar *value,
+						gpointer data,
+						GError **error)
+{ 
+	GnomeProgram *program = gnome_program_get();
+	g_assert (program != NULL);
+
+	g_object_set (G_OBJECT (program),
+       		LIBGNOMEUI_PARAM_CRASH_DIALOG,
+		FALSE, NULL);
+
+	return TRUE;
+}
+
+static gboolean libgnomeui_goption_display (const gchar *option_name,
+						const gchar *value,
+						gpointer data,
+						GError **error)
+{
+	GnomeProgram *program = gnome_program_get();
+	g_assert (program != NULL);
+                 
+	g_object_set (G_OBJECT (program),
+		LIBGNOMEUI_PARAM_DISPLAY,
+		value, NULL);
+
+	return TRUE;
+}
+
 /* automagically parse all the gtkrc files for us.
  * 
  * Parse:


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