make libbonoboui initialisable via gnome_program_init()
- From: James Henstridge <james daa com au>
- To: gnome-libs-devel gnome org, Anders Carlsson <andersca codefactory se>, Michael Meeks <michael ximian com>
- Subject: make libbonoboui initialisable via gnome_program_init()
- Date: Mon, 21 Jan 2002 16:04:18 +0800
I was talking with Michael about adding support for initialising
libbonoboui through gnome_program_init(), and the following patch adds
that support. It adds one function to the API, and moves another from
libgnomeui to libbonoboui.
This was mainly done because languages like python don't ask for
additional arguments when importing a module. For the gnome libs, we
need some extra information for initialisation, so I would like to keep
the number of init calls required to a minimum (preferably a single
gnome.init() call).
The patch adds a BONOBO_UI_MODULE GnomeModuleInfo, which can be used to
initialise libbonoboui. It also moves the GnomeModuleInfo struct for
gtk+ from libgnomeui to libbonoboui, so that it can be listed as a
dependency of the bonoboui module (it is currently in libgnomeui, which
depends on libbonoboui). Libgnomeui is then tidied up to use the moved
gtk+ GnomeModuleInfo struct. Possibly the LIBGNOMEUI_MODULE should list
BONOBO_UI_MODULE as a dep.
An unrelated fix in the patch is to make bonobo_ui_init_full() use the
orb, poa and manager arguments, which were being ignored (the change was
to pass these args on to bonobo_init_full()).
It would be very useful to get this change in (michael agreed on irc).
There are still some bad problems with the gnome_program_init()
framework though, not all of which look fixable for 2.0. These include:
1) no way for modules to signal failure during initialisation. Ideally
this would use GError or something.
2) gnome_program_init() being unusable for languages that can't create C
argument vectors (ie. almost any scripting language). The
gnome_program_init_full() variant takes a va_list argument, which is
equally difficult to construct, and takes a GType argument, which
doesn't really make sense, given that GnomeProgram is meant to be a
singleton. It uses GObject properties for the varargs stuff, but some
of the properties may not be registered until the gnome_program_init()
function body, which is bad for language bindings.
There are probably others. It would be great if (2) could be solved in
2.0 timeframe, and make (1) doable for 2.2.
James.
--
Email: james daa com au
WWW: http://www.daa.com.au/~james/
Index: libbonoboui/ChangeLog
===================================================================
RCS file: /cvs/gnome/libbonoboui/ChangeLog,v
retrieving revision 1.247
diff -u -p -u -r1.247 ChangeLog
--- libbonoboui/ChangeLog 2002/01/19 19:29:15 1.247
+++ libbonoboui/ChangeLog 2002/01/21 07:07:08
@@ -1,3 +1,13 @@
+2002-01-20 James Henstridge <james daa com au>
+
+ * bonobo/bonobo-ui-main.c (bonobo_ui_module_info_get): function to
+ get a GnomeModuleInfo for BonoboUI.
+ (bonobo_gtk_module_info_get): move the gtk module info from
+ libgnomeui to here.
+ (bonobo_ui_init_full): call bonbo_init_full() instead of
+ bonobo_init(), so that the orb, poa and manager arguments are
+ actually used.
+
2002-01-20 Hasbullah Bin Pit <sebol ikhlas com>
* configure.ini: Added Malay (ms)to ALL_LINGUAS.
Index: libbonoboui/bonobo/bonobo-ui-main.c
===================================================================
RCS file: /cvs/gnome/libbonoboui/bonobo/bonobo-ui-main.c,v
retrieving revision 1.12
diff -u -p -u -r1.12 bonobo-ui-main.c
--- libbonoboui/bonobo/bonobo-ui-main.c 2001/12/13 12:38:25 1.12
+++ libbonoboui/bonobo/bonobo-ui-main.c 2002/01/21 07:07:08
@@ -20,6 +20,7 @@
#include <libgnome/gnome-init.h>
#include <gtk/gtkmain.h>
+#include <gtk/gtkversion.h>
#include <X11/Xlib.h>
@@ -107,7 +108,7 @@ bonobo_ui_init_full (const gchar *app_na
else
bonobo_ui_inited = TRUE;
- if (!bonobo_init (argc, argv))
+ if (!bonobo_init_full (argc, argv, orb, poa, manager))
return FALSE;
g_set_prgname (app_name);
@@ -141,4 +142,235 @@ bonobo_ui_debug_shutdown (void)
bonobo_ui_preferences_shutdown ();
return bonobo_debug_shutdown ();
+}
+
+static void
+bonobo_ui_post_args_parse(GnomeProgram *program, GnomeModuleInfo *mod_info)
+{
+ bonobo_setup_x_error_handler ();
+}
+
+const GnomeModuleInfo *
+bonobo_ui_module_info_get (void)
+{
+ static GnomeModuleInfo module_info = {
+ "bonoboui", VERSION, N_("Bonobo UI"),
+ NULL, NULL,
+ NULL, bonobo_ui_post_args_parse, NULL,
+ NULL,
+ NULL, NULL, NULL
+ };
+ if (module_info.requirements == NULL) {
+ static GnomeModuleRequirement req[2];
+
+ req[0].required_version = "1.3.12";
+ req[0].module_info = BONOBO_GTK_MODULE;
+
+ req[1].required_version = "1.109.0";
+ req[1].module_info = GNOME_BONOBO_MODULE;
+
+ req[2].required_version = "1.109.0";
+ req[2].module_info = LIBGNOME_MODULE;
+
+ req[3].required_version = NULL;
+ req[3].module_info = NULL;
+
+ module_info.requirements = req;
+ }
+
+ return &module_info;
+}
+
+/*
+ * GTK init stuff
+ */
+
+typedef struct {
+ GPtrArray *gtk_args;
+} gnome_gtk_init_info;
+
+static void add_gtk_arg_callback (poptContext con,
+ enum poptCallbackReason reason,
+ const struct poptOption * opt,
+ const char * arg, void * data);
+
+static struct poptOption gtk_options [] = {
+ { NULL, '\0', POPT_ARG_CALLBACK|POPT_CBFLAG_PRE,
+ &add_gtk_arg_callback, 0, NULL, NULL },
+
+ { NULL, '\0', POPT_ARG_INTL_DOMAIN, GETTEXT_PACKAGE, 0, NULL, NULL },
+
+ { "gdk-debug", '\0', POPT_ARG_STRING, NULL, 0,
+ N_("Gdk debugging flags to set"), N_("FLAGS")},
+
+ { "gdk-no-debug", '\0', POPT_ARG_STRING, NULL, 0,
+ N_("Gdk debugging flags to unset"), N_("FLAGS")},
+
+ /* X11 only */
+ { "display", '\0', POPT_ARG_STRING, NULL, 0,
+ N_("X display to use"), N_("DISPLAY")},
+
+ /* X11 only */
+ { "sync", '\0', POPT_ARG_NONE, NULL, 0,
+ N_("Make X calls synchronous"), NULL},
+
+ /* FIXME: this doesn't seem to exist */
+#if 0
+ /* X11 only */
+ { "no-xshm", '\0', POPT_ARG_NONE, NULL, 0,
+ N_("Don't use X shared memory extension"), NULL},
+#endif
+
+ { "name", '\0', POPT_ARG_STRING, NULL, 0,
+ N_("Program name as used by the window manager"), N_("NAME")},
+
+ { "class", '\0', POPT_ARG_STRING, NULL, 0,
+ N_("Program class as used by the window manager"), N_("CLASS")},
+
+ /* X11 only */
+ { "gxid-host", '\0', POPT_ARG_STRING, NULL, 0,
+ NULL, N_("HOST")},
+
+ /* X11 only */
+ { "gxid-port", '\0', POPT_ARG_STRING, NULL, 0,
+ NULL, N_("PORT")},
+
+ /* FIXME: this doesn't seem to exist */
+#if 0
+ { "xim-preedit", '\0', POPT_ARG_STRING, NULL, 0,
+ NULL, N_("STYLE")},
+
+ { "xim-status", '\0', POPT_ARG_STRING, NULL, 0,
+ NULL, N_("STYLE")},
+#endif
+
+ { "gtk-debug", '\0', POPT_ARG_STRING, NULL, 0,
+ N_("Gtk+ debugging flags to set"), N_("FLAGS")},
+
+ { "gtk-no-debug", '\0', POPT_ARG_STRING, NULL, 0,
+ N_("Gtk+ debugging flags to unset"), N_("FLAGS")},
+
+ { "g-fatal-warnings", '\0', POPT_ARG_NONE, NULL, 0,
+ N_("Make all warnings fatal"), NULL},
+
+ { "gtk-module", '\0', POPT_ARG_STRING, NULL, 0,
+ N_("Load an additional Gtk module"), N_("MODULE")},
+
+ { NULL, '\0', 0, NULL, 0}
+};
+
+
+static void
+gtk_pre_args_parse (GnomeProgram *program, GnomeModuleInfo *mod_info)
+{
+ gnome_gtk_init_info *init_info = g_new0 (gnome_gtk_init_info, 1);
+
+ init_info->gtk_args = g_ptr_array_new ();
+
+ g_object_set_data (G_OBJECT (program),
+ "Libgnomeui-Gtk-Module-init-info",
+ init_info);
+}
+
+static void
+gtk_post_args_parse (GnomeProgram *program, GnomeModuleInfo *mod_info)
+{
+ gnome_gtk_init_info *init_info;
+ int final_argc;
+ char **final_argv;
+ int i;
+
+ init_info = g_object_get_data (G_OBJECT (program),
+ "Libgnomeui-Gtk-Module-init-info");
+
+ 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,
+ sizeof (char *) * init_info->gtk_args->len);
+
+ gtk_init (&final_argc, &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);
+
+ g_object_set_data (G_OBJECT (program),
+ "Libgnomeui-Gtk-Module-init-info",
+ NULL);
+}
+
+
+
+static void
+add_gtk_arg_callback (poptContext con, enum poptCallbackReason reason,
+ const struct poptOption * opt,
+ const char * arg, void * data)
+{
+ GnomeProgram *program;
+ gnome_gtk_init_info *init_info;
+ char *newstr;
+
+ program = g_dataset_get_data (con, "GnomeProgram");
+ g_assert (program != NULL);
+
+ init_info = g_object_get_data (G_OBJECT (program),
+ "Libgnomeui-Gtk-Module-init-info");
+ g_assert (init_info != NULL);
+
+
+ switch (reason) {
+ case POPT_CALLBACK_REASON_PRE:
+ /* Note that the value of argv[0] passed to main() may be
+ * different from the value that this passes to gtk
+ */
+ g_ptr_array_add (init_info->gtk_args,
+ (char *) g_strdup (poptGetInvocationName (con)));
+ break;
+
+ case POPT_CALLBACK_REASON_OPTION:
+ switch (opt->argInfo) {
+ case POPT_ARG_STRING:
+ case POPT_ARG_INT:
+ case POPT_ARG_LONG:
+ newstr = g_strconcat ("--", opt->longName, "=", arg, NULL);
+ break;
+ default:
+ newstr = g_strconcat ("--", opt->longName, NULL);
+ break;
+ }
+
+ g_ptr_array_add (init_info->gtk_args, newstr);
+ /* XXX gnome-client tie-in */
+ break;
+ default:
+ break;
+ }
+}
+
+const GnomeModuleInfo *
+bonobo_gtk_module_info_get (void)
+{
+ static GnomeModuleInfo module_info = {
+ "gtk", NULL, N_("GTK+"),
+ NULL, NULL,
+ gtk_pre_args_parse, gtk_post_args_parse, gtk_options,
+ NULL,
+ NULL, NULL, NULL
+ };
+ if (module_info.version == NULL) {
+ module_info.version = g_strdup_printf ("%d.%d.%d",
+ GTK_MAJOR_VERSION,
+ GTK_MINOR_VERSION,
+ GTK_MICRO_VERSION);
+ }
+
+ return &module_info;
}
Index: libbonoboui/bonobo/bonobo-ui-main.h
===================================================================
RCS file: /cvs/gnome/libbonoboui/bonobo/bonobo-ui-main.h,v
retrieving revision 1.4
diff -u -p -u -r1.4 bonobo-ui-main.h
--- libbonoboui/bonobo/bonobo-ui-main.h 2001/12/13 12:38:25 1.4
+++ libbonoboui/bonobo/bonobo-ui-main.h 2002/01/21 07:07:08
@@ -14,8 +14,16 @@
#define __BONOBO_UI_MAIN_H__ 1
#include <bonobo/bonobo-main.h>
+#include <libgnome/gnome-program.h>
G_BEGIN_DECLS
+
+/* module defs for use with gnome_program_init() */
+#define BONOBO_GTK_MODULE bonobo_gtk_module_info_get()
+#define BONOBO_UI_MODULE bonobo_ui_module_info_get()
+
+const GnomeModuleInfo *bonobo_gtk_module_info_get (void) G_GNUC_CONST;
+const GnomeModuleInfo *bonobo_ui_module_info_get (void) G_GNUC_CONST;
gboolean bonobo_ui_is_initialized (void);
gboolean bonobo_ui_init (const gchar *app_name,
Index: libgnomeui/libgnomeui/ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/ChangeLog,v
retrieving revision 1.1776
diff -u -p -u -r1.1776 ChangeLog
--- libgnomeui/libgnomeui/ChangeLog 2002/01/16 14:04:46 1.1776
+++ libgnomeui/libgnomeui/ChangeLog 2002/01/21 07:09:05
@@ -1,3 +1,14 @@
+2002-01-21 James Henstridge <james daa com au>
+
+ * gnome-client.c (gnome_client_module_info_get): fix up reference
+ to gnome_gtk_module_info_get().
+
+ * gnome-ui-init.c (libgnomeui_module_info_get): use the gtk
+ GnomeModuleInfo from libbonoboui.
+
+ * gnome-ui-init.h (GNOME_GTK_MODULE): define this to
+ BONOBO_GTK_MODULE for compatibility.
+
2002-01-16 Richard Hult <rhult codefactory se>
* gnome-app-helper.c (gnome_app_setup_toolbar): Remove unused
Index: libgnomeui/libgnomeui/gnome-ui-init.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-ui-init.c,v
retrieving revision 1.169
diff -u -p -u -r1.169 gnome-ui-init.c
--- libgnomeui/libgnomeui/gnome-ui-init.c 2002/01/08 21:28:46 1.169
+++ libgnomeui/libgnomeui/gnome-ui-init.c 2002/01/21 07:09:05
@@ -119,8 +119,8 @@ libgnomeui_module_info_get (void)
if (module_info.requirements == NULL) {
static GnomeModuleRequirement req[6];
- req[0].required_version = "1.3.7";
- req[0].module_info = gnome_gtk_module_info_get ();
+ req[0].required_version = "1.3.12";
+ req[0].module_info = BONOBO_GTK_MODULE;
req[1].required_version = "1.102.0";
req[1].module_info = LIBGNOME_MODULE;
@@ -714,197 +714,3 @@ gnome_init_with_popt_table (const char *
*/
/* This is a macro */
-
-/*
- * GTK init stuff
- */
-
-typedef struct {
- GPtrArray *gtk_args;
-} gnome_gtk_init_info;
-
-static void add_gtk_arg_callback (poptContext con,
- enum poptCallbackReason reason,
- const struct poptOption * opt,
- const char * arg, void * data);
-
-static struct poptOption gtk_options [] = {
- { NULL, '\0', POPT_ARG_CALLBACK|POPT_CBFLAG_PRE,
- &add_gtk_arg_callback, 0, NULL, NULL },
-
- { NULL, '\0', POPT_ARG_INTL_DOMAIN, GETTEXT_PACKAGE, 0, NULL, NULL },
-
- { "gdk-debug", '\0', POPT_ARG_STRING, NULL, 0,
- N_("Gdk debugging flags to set"), N_("FLAGS")},
-
- { "gdk-no-debug", '\0', POPT_ARG_STRING, NULL, 0,
- N_("Gdk debugging flags to unset"), N_("FLAGS")},
-
- /* X11 only */
- { "display", '\0', POPT_ARG_STRING, NULL, 0,
- N_("X display to use"), N_("DISPLAY")},
-
- /* X11 only */
- { "sync", '\0', POPT_ARG_NONE, NULL, 0,
- N_("Make X calls synchronous"), NULL},
-
- /* FIXME: this doesn't seem to exist */
-#if 0
- /* X11 only */
- { "no-xshm", '\0', POPT_ARG_NONE, NULL, 0,
- N_("Don't use X shared memory extension"), NULL},
-#endif
-
- { "name", '\0', POPT_ARG_STRING, NULL, 0,
- N_("Program name as used by the window manager"), N_("NAME")},
-
- { "class", '\0', POPT_ARG_STRING, NULL, 0,
- N_("Program class as used by the window manager"), N_("CLASS")},
-
- /* X11 only */
- { "gxid-host", '\0', POPT_ARG_STRING, NULL, 0,
- NULL, N_("HOST")},
-
- /* X11 only */
- { "gxid-port", '\0', POPT_ARG_STRING, NULL, 0,
- NULL, N_("PORT")},
-
- /* FIXME: this doesn't seem to exist */
-#if 0
- { "xim-preedit", '\0', POPT_ARG_STRING, NULL, 0,
- NULL, N_("STYLE")},
-
- { "xim-status", '\0', POPT_ARG_STRING, NULL, 0,
- NULL, N_("STYLE")},
-#endif
-
- { "gtk-debug", '\0', POPT_ARG_STRING, NULL, 0,
- N_("Gtk+ debugging flags to set"), N_("FLAGS")},
-
- { "gtk-no-debug", '\0', POPT_ARG_STRING, NULL, 0,
- N_("Gtk+ debugging flags to unset"), N_("FLAGS")},
-
- { "g-fatal-warnings", '\0', POPT_ARG_NONE, NULL, 0,
- N_("Make all warnings fatal"), NULL},
-
- { "gtk-module", '\0', POPT_ARG_STRING, NULL, 0,
- N_("Load an additional Gtk module"), N_("MODULE")},
-
- { NULL, '\0', 0, NULL, 0}
-};
-
-
-static void
-gtk_pre_args_parse (GnomeProgram *program, GnomeModuleInfo *mod_info)
-{
- gnome_gtk_init_info *init_info = g_new0 (gnome_gtk_init_info, 1);
-
- init_info->gtk_args = g_ptr_array_new ();
-
- g_object_set_data (G_OBJECT (program),
- "Libgnomeui-Gtk-Module-init-info",
- init_info);
-}
-
-static void
-gtk_post_args_parse (GnomeProgram *program, GnomeModuleInfo *mod_info)
-{
- gnome_gtk_init_info *init_info;
- int final_argc;
- char **final_argv;
- int i;
-
- init_info = g_object_get_data (G_OBJECT (program),
- "Libgnomeui-Gtk-Module-init-info");
-
- 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,
- sizeof (char *) * init_info->gtk_args->len);
-
- gtk_init (&final_argc, &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);
-
- g_object_set_data (G_OBJECT (program),
- "Libgnomeui-Gtk-Module-init-info",
- NULL);
-}
-
-
-
-static void
-add_gtk_arg_callback (poptContext con, enum poptCallbackReason reason,
- const struct poptOption * opt,
- const char * arg, void * data)
-{
- GnomeProgram *program;
- gnome_gtk_init_info *init_info;
- char *newstr;
-
- program = g_dataset_get_data (con, "GnomeProgram");
- g_assert (program != NULL);
-
- init_info = g_object_get_data (G_OBJECT (program),
- "Libgnomeui-Gtk-Module-init-info");
- g_assert (init_info != NULL);
-
-
- switch (reason) {
- case POPT_CALLBACK_REASON_PRE:
- /* Note that the value of argv[0] passed to main() may be
- * different from the value that this passes to gtk
- */
- g_ptr_array_add (init_info->gtk_args,
- (char *) g_strdup (poptGetInvocationName (con)));
- break;
-
- case POPT_CALLBACK_REASON_OPTION:
- switch (opt->argInfo) {
- case POPT_ARG_STRING:
- case POPT_ARG_INT:
- case POPT_ARG_LONG:
- newstr = g_strconcat ("--", opt->longName, "=", arg, NULL);
- break;
- default:
- newstr = g_strconcat ("--", opt->longName, NULL);
- break;
- }
-
- g_ptr_array_add (init_info->gtk_args, newstr);
- /* XXX gnome-client tie-in */
- break;
- default:
- break;
- }
-}
-
-const GnomeModuleInfo *
-gnome_gtk_module_info_get (void)
-{
- static GnomeModuleInfo module_info = {
- "gtk", NULL, N_("GTK+"),
- NULL, NULL,
- gtk_pre_args_parse, gtk_post_args_parse, gtk_options,
- NULL,
- NULL, NULL, NULL
- };
- if (module_info.version == NULL) {
- module_info.version = g_strdup_printf ("%d.%d.%d",
- GTK_MAJOR_VERSION,
- GTK_MINOR_VERSION,
- GTK_MICRO_VERSION);
- }
-
- return &module_info;
-}
Index: libgnomeui/libgnomeui/gnome-ui-init.h
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-ui-init.h,v
retrieving revision 1.16
diff -u -p -u -r1.16 gnome-ui-init.h
--- libgnomeui/libgnomeui/gnome-ui-init.h 2001/09/03 06:52:13 1.16
+++ libgnomeui/libgnomeui/gnome-ui-init.h 2002/01/21 07:09:05
@@ -29,6 +29,7 @@
G_BEGIN_DECLS
#include <libgnome/gnome-program.h>
+#include <bonobo/bonobo-ui-main.h>
#define LIBGNOMEUI_PARAM_CRASH_DIALOG "show-crash-dialog"
#define LIBGNOMEUI_PARAM_DISPLAY "display"
@@ -36,8 +37,7 @@ G_BEGIN_DECLS
#define LIBGNOMEUI_MODULE libgnomeui_module_info_get()
const GnomeModuleInfo * libgnomeui_module_info_get (void) G_GNUC_CONST;
-#define GNOME_GTK_MODULE gnomeui_gtk_module_info_get()
-const GnomeModuleInfo * gnome_gtk_module_info_get (void) G_GNUC_CONST;
+#define GNOME_GTK_MODULE BONOBO_GTK_MODULE
#ifndef GNOME_DISABLE_DEPRECATED
Index: libgnomeui/libgnomeui/gnome-client.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-client.c,v
retrieving revision 1.119
diff -u -p -u -r1.119 gnome-client.c
--- libgnomeui/libgnomeui/gnome-client.c 2001/12/08 15:16:30 1.119
+++ libgnomeui/libgnomeui/gnome-client.c 2002/01/21 07:09:06
@@ -956,10 +956,10 @@ gnome_client_module_info_get (void)
static GnomeModuleRequirement req[3];
req[0].required_version = "1.3.7";
- req[0].module_info = gnome_gtk_module_info_get ();
+ req[0].module_info = GNOME_GTK_MODULE;
req[1].required_version = "1.102.0";
- req[1].module_info = libgnome_module_info_get ();
+ req[1].module_info = LIBGNOME_MODULE;
req[2].required_version = NULL;
req[2].module_info = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]