diff --git a/ChangeLog b/ChangeLog index 3b8c48d4d..b46cb8950 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-07-13 Bradford Hovinen + + * capplets/Makefile.am (always_built_SUBDIRS): Add common + + * configure.in (AC_OUTPUT): Add capplets/common/Makefile + 2001-07-12 Chema Celorio * configure.in (vers): bump pkg-confi to version 0.8.0. Version diff --git a/capplets/Makefile.am b/capplets/Makefile.am index aa9135dd5..ea61b489b 100644 --- a/capplets/Makefile.am +++ b/capplets/Makefile.am @@ -1,5 +1,5 @@ always_built_SUBDIRS = \ - background keyboard mouse rollback screensaver sound + common background keyboard mouse rollback screensaver sound SUBDIRS = $(always_built_SUBDIRS) diff --git a/capplets/common/ChangeLog b/capplets/common/ChangeLog new file mode 100644 index 000000000..e69de29bb diff --git a/capplets/common/Makefile.am b/capplets/common/Makefile.am new file mode 100644 index 000000000..6d715b537 --- /dev/null +++ b/capplets/common/Makefile.am @@ -0,0 +1,15 @@ +EXTRA_DIST = ChangeLog + +INCLUDES = \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -DGNOME_ICONDIR=\""${prefix}/share/pixmaps"\" \ + -DG_LOG_DOMAIN=\"capplet-common\" \ + -DGLADE_DATADIR=\""$(datadir)/control-center/interfaces"\" \ + -I$(top_srcdir)/ \ + -I$(top_srcdir)/intl \ + @CAPPLET_CFLAGS@ + +noinst_LIBRARIES = libcommon.a + +libcommon_a_SOURCES = \ + capplet-util.c capplet-util.h diff --git a/capplets/common/capplet-util.c b/capplets/common/capplet-util.c new file mode 100644 index 000000000..8e8f44f65 --- /dev/null +++ b/capplets/common/capplet-util.c @@ -0,0 +1,353 @@ +/* -*- mode: c; style: linux -*- */ + +/* capplet-util.c + * Copyright (C) 2001 Ximian, Inc. + * + * Written by Bradford Hovinen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "capplet-util.h" + +static ApplySettingsFn apply_settings_cb = NULL; +static SetupPropertyEditorsFn setup_cb = NULL; + +static BonoboControl *control = NULL; +static GladeXML *dialog; +static GtkWidget *widget; + +static gchar *glade_filename; + +/* apply_cb + * + * Callback issued when the user clicks "Apply" or "Ok". This function is + * responsible for making sure the current settings are properly saved. + */ + +static void +apply_cb (BonoboPropertyControl *pc, Bonobo_PropertyControl_Action action) +{ + BonoboPropertyFrame *pf; + Bonobo_ConfigDatabase db; + CORBA_Environment ev; + + if (action == Bonobo_PropertyControl_APPLY) { + CORBA_exception_init (&ev); + + pf = gtk_object_get_data (GTK_OBJECT (pc), "property-frame"); + db = gtk_object_get_data (GTK_OBJECT (pf), "config-database"); + bonobo_pbproxy_update (pf->proxy); + Bonobo_ConfigDatabase_sync (db, &ev); + + CORBA_exception_free (&ev); + } +} + +/* changed_cb + * + * Callback issued when a setting in the ConfigDatabase changes. + */ + +static void +changed_cb (BonoboListener *listener, gchar *event_name, CORBA_any *any, + CORBA_Environment *ev, Bonobo_ConfigDatabase db) +{ + if (apply_settings_cb != NULL) + apply_settings_cb (db); +} + +/* get_moniker_cb + * + * Callback issued to retrieve the name of the moniker being used. This function + * is just a formality. + */ + +static void +get_moniker_cb (BonoboPropertyBag *bag, BonoboArg *arg, guint arg_id, + CORBA_Environment *ev, BonoboControl *control) +{ + BONOBO_ARG_SET_STRING (arg, gtk_object_get_data (GTK_OBJECT (control), "moniker")); +} + +/* set_moniker_cb + * + * Callback issued when the name of the moniker to be used is set. This function + * does most of the dirty work -- creating the property editors that connect + * properties to the dialog box. + */ + +static void +set_moniker_cb (BonoboPropertyBag *bag, BonoboArg *arg, guint arg_id, + CORBA_Environment *ev, BonoboControl *control) +{ + gchar *moniker; + gchar *full_moniker; + BonoboPropertyFrame *pf; + Bonobo_PropertyBag proxy; + GladeXML *dialog; + Bonobo_ConfigDatabase db; + + if (arg_id != 1) return; + + moniker = BONOBO_ARG_GET_STRING (arg); + full_moniker = g_strconcat (moniker, "#config:/main", NULL); + + pf = BONOBO_PROPERTY_FRAME (bonobo_control_get_widget (control)); + bonobo_property_frame_set_moniker (pf, full_moniker); + proxy = BONOBO_OBJREF (pf->proxy); + dialog = gtk_object_get_data (GTK_OBJECT (control), "dialog"); + + db = bonobo_get_object (moniker, "IDL:Bonobo/ConfigDatabase:1.0", ev); + + if (BONOBO_EX (ev) || db == CORBA_OBJECT_NIL) + g_critical ("Could not resolve configuration moniker; will not be able to save settings"); + + gtk_object_set_data (GTK_OBJECT (pf), "config-database", db); + + if (setup_cb != NULL) + setup_cb (dialog, proxy); +} + +/* close_cb + * + * Callback issued when the dialog is destroyed. Just resets the control pointer + * to NULL so that the program does not think the dialog exists when it does + * not. + */ + +static void +close_cb (void) +{ + gtk_object_destroy (GTK_OBJECT (dialog)); + control = NULL; +} + +/* create_dialog_cb + * + * Callback to construct the main dialog box for this capplet; invoked by Bonobo + * whenever capplet activation is requested. Returns a BonoboObject representing + * the control that encapsulates the object. + */ + +static BonoboObject * +create_dialog_cb (BonoboPropertyControl *property_control, gint page_number) +{ + BonoboPropertyBag *pb; + GtkWidget *pf; + + if (control == NULL) { + dialog = glade_xml_new (glade_filename, "prefs_widget"); + + if (dialog == NULL) { + g_critical ("Could not load glade file %s", glade_filename); + return NULL; + } + + widget = glade_xml_get_widget (dialog, "prefs_widget"); + + if (widget == NULL) { + g_critical ("Could not find preferences widget"); + return NULL; + } + + pf = bonobo_property_frame_new (NULL, NULL); + gtk_object_set_data (GTK_OBJECT (property_control), + "property-frame", pf); + gtk_container_add (GTK_CONTAINER (pf), widget); + gtk_widget_show_all (pf); + + control = bonobo_control_new (pf); + gtk_object_set_data (GTK_OBJECT (control), "dialog", dialog); + + pb = bonobo_property_bag_new ((BonoboPropertyGetFn) get_moniker_cb, + (BonoboPropertySetFn) set_moniker_cb, + control); + bonobo_control_set_properties (control, pb); + bonobo_object_unref (BONOBO_OBJECT (pb)); + + bonobo_property_bag_add (pb, "moniker", 1, BONOBO_ARG_STRING, NULL, + "Moniker for configuration", + BONOBO_PROPERTY_WRITEABLE); + + bonobo_control_set_automerge (control, TRUE); + + gtk_signal_connect (GTK_OBJECT (widget), "destroy", + GTK_SIGNAL_FUNC (close_cb), NULL); + gtk_signal_connect (GTK_OBJECT (control), "destroy", + GTK_SIGNAL_FUNC (close_cb), NULL); + } else { + gtk_widget_show_all (widget); + } + + return BONOBO_OBJECT (control); +} + +/* create_control_cb + * + * Small function to create the PropertyControl and return it. + */ + +static BonoboObject * +create_control_cb (BonoboGenericFactory *factory, Bonobo_ConfigDatabase db) +{ + BonoboPropertyControl *property_control; + CORBA_Environment ev; + + CORBA_exception_init (&ev); + + property_control = bonobo_property_control_new + ((BonoboPropertyControlGetControlFn) create_dialog_cb, 1, NULL); + gtk_signal_connect (GTK_OBJECT (property_control), "action", + GTK_SIGNAL_FUNC (apply_cb), NULL); + + bonobo_event_source_client_add_listener + (db, (BonoboListenerCallbackFn) changed_cb, + "Bonobo/ConfigDatabase:change", &ev, db); + + CORBA_exception_free (&ev); + + return BONOBO_OBJECT (property_control); +} + +/* get_factory_name + * + * Construct the OAF IID of the factory from the binary name + */ + +static gchar * +get_factory_name (const gchar *binary) +{ + gchar *tmp, *tmp1, *res; + + tmp = g_strdup (binary); + if ((tmp1 = strstr (tmp, "-capplet")) != NULL) *tmp1 = '\0'; + while ((tmp1 = strchr (tmp, '-')) != NULL) *tmp1 = '_'; + + res = g_strconcat ("OAFIID:Bonobo_Control_Capplet_", tmp, "_Factory", NULL); + g_free (tmp); + return res; +} + +/* get_glade_filename + * + * Construct the filename of the Glade file from the binary name + */ + +static gchar *get_glade_filename (const gchar *binary) +{ + gchar *tmp, *tmp1, *res; + + tmp = g_strdup (binary); + if ((tmp1 = strstr (tmp, "-capplet")) != NULL) *tmp1 = '\0'; + + res = g_strconcat (GLADE_DATADIR, "/", tmp, ".glade", NULL); + g_free (tmp); + return res; +} + +/* get_default_moniker + * + * Construct the default moniker for configuration from the binary name + */ + +static gchar * +get_default_moniker (const gchar *binary) +{ + gchar *tmp, *tmp1, *res; + + tmp = g_strdup (binary); + if ((tmp1 = strstr (tmp, "-capplet")) != NULL) *tmp1 = '\0'; + + res = g_strconcat ("archiver:", tmp, NULL); + g_free (tmp); + return res; +} + +/* capplet_init -- see documentation in capplet-util.h + */ + +void +capplet_init (int argc, + char **argv, + ApplySettingsFn apply_fn, + SetupPropertyEditorsFn setup_fn, + GetLegacySettingsFn get_legacy_fn) +{ + BonoboGenericFactory *factory; + Bonobo_ConfigDatabase db; + CORBA_ORB orb; + CORBA_Environment ev; + gchar *factory_iid; + gchar *default_moniker; + + static gboolean apply_only; + static gboolean get_legacy; + static struct poptOption cap_options[] = { + { "apply", '\0', POPT_ARG_NONE, &apply_only, 0, + N_("Just apply settings and quit"), NULL }, + { "get-legacy", '\0', POPT_ARG_NONE, &get_legacy, 0, + N_("Retrieve and store legacy settings"), NULL }, + { NULL, '\0', 0, NULL, 0, NULL, NULL } + }; + + bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE); + + CORBA_exception_init (&ev); + + glade_gnome_init (); + gnomelib_register_popt_table (cap_options, _("Capplet options")); + gnome_init_with_popt_table (argv[0], VERSION, argc, argv, + oaf_popt_options, 0, NULL); + + orb = oaf_init (argc, argv); + if (bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) + g_error ("Cannot initialize bonobo"); + + default_moniker = get_default_moniker (argv[0]); + db = bonobo_get_object (default_moniker, "IDL:Bonobo/ConfigDatabase:1.0", &ev); + g_free (default_moniker); + + if (db == CORBA_OBJECT_NIL) { + g_critical ("Cannot open configuration database %s", default_moniker); + exit (-1); + } + + if (apply_only && apply_fn != NULL) { + apply_fn (db); + } + else if (get_legacy && get_legacy_fn != NULL) { + get_legacy_fn (db); + Bonobo_ConfigDatabase_sync (db, &ev); + } else { + apply_settings_cb = apply_fn; + setup_cb = setup_fn; + factory_iid = get_factory_name (argv[0]); + glade_filename = get_glade_filename (argv[0]); + factory = bonobo_generic_factory_new + (factory_iid, (BonoboGenericFactoryFn) create_control_cb, db); + g_free (factory_iid); + bonobo_running_context_auto_exit_unref (BONOBO_OBJECT (factory)); + bonobo_main (); + } + + CORBA_exception_free (&ev); +} diff --git a/capplets/common/capplet-util.h b/capplets/common/capplet-util.h new file mode 100644 index 000000000..1092b6b38 --- /dev/null +++ b/capplets/common/capplet-util.h @@ -0,0 +1,102 @@ +/* -*- mode: c; style: linux -*- */ + +/* capplet-util.c + * Copyright (C) 2001 Ximian, Inc. + * + * Written by Bradford Hovinen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef __CAPPLET_UTIL_H +#define __CAPPLET_UTIL_H + +#include +#include + +#include + +/* FIXME: We should really have a single bonobo-conf.h header */ + +#include +#include +#include + +/* Macros to make certain repetitive tasks a bit easier */ + +/* Print a debugging message */ + +#define DEBUG_MSG(str, args...) \ + g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "(%d:%s) " str, \ + getpid (), __FUNCTION__ , ## args) + +/* Retrieve a widget from the Glade object */ + +#define WID(s) glade_xml_get_widget (dialog, s) + +/* Copy a setting from the legacy gnome-config settings to the ConfigDatabase */ + +#define COPY_FROM_LEGACY(type, key, legacy_type, legacy_key) \ + val_##type = gnome_config_get_##legacy_type##_with_default (legacy_key, &def); \ + \ + if (!def) \ + bonobo_config_set_##type (db, key, val_##type, NULL); + +/* Create a property editor */ + +#define CREATE_PEDITOR(type, key, widget) \ + { \ + BonoboPEditor *ed = BONOBO_PEDITOR \ + (bonobo_peditor_##type##_construct (WID (widget))); \ + bonobo_peditor_set_property (ed, bag, key, TC_##type, NULL); \ + } + +/* Callback to apply the settings in the given database */ +typedef void (*ApplySettingsFn) (Bonobo_ConfigDatabase db); + +/* Callback to set up property editors for the dialog */ +typedef void (*SetupPropertyEditorsFn) (GladeXML *dialog, Bonobo_PropertyBag bag); + +/* Callback to retrieve legacy settings and store them in the new configuration + * database */ +typedef void (*GetLegacySettingsFn) (Bonobo_ConfigDatabase db); + +/* Wrapper function for the entire capplet. This handles all initialization and + * runs the capplet for you. Just supply the appropriate callbacks and your argc + * and argv from main() + * + * This function makes several assumptions, requiring that all capplets follow a + * particular convention. In particular, suppose the name of the capplet binary + * is foo-properties-capplet. Then: + * + * - The glade file is named foo-properties.glade. It is located in + * $(datadir)/control-center/interfaces. The widget containing the property + * information is called prefs_widget. + * - The factory IID is Bonobo_Control_Capplet_foo_properties_Factory + * - The default configuration moniker is archiver:foo-properties + * + * Following this convention yields capplets that are more uniform and thus + * easier to maintain, and simplifies the interfaces quite a bit. All capplet in + * this package are required to follow this convention. + */ + +void capplet_init (int argc, + gchar **argv, + ApplySettingsFn apply_fn, + SetupPropertyEditorsFn setup_property_editors_fn, + GetLegacySettingsFn get_legacy_settings_fn); + +#endif /* __CAPPLET_UTIL_H */ diff --git a/capplets/sound/Makefile.am b/capplets/sound/Makefile.am index f8a5462eb..9f5ca235d 100644 --- a/capplets/sound/Makefile.am +++ b/capplets/sound/Makefile.am @@ -25,21 +25,17 @@ EXTRA_DIST = ChangeLog $(Applications_DATA) $(Glade_DATA) $(glade_msgs) $(oaf_DA INCLUDES = \ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ - -DGNOME_ICONDIR=\""${prefix}/share/pixmaps"\" \ -DG_LOG_DOMAIN=\"sound-properties\" \ - -DGLADE_DATADIR=\""$(Gladedir)"\" \ - @CAPPLET_CFLAGS@ \ -I$(top_srcdir)/ \ - -I$(top_srcdir)/intl + -I$(top_srcdir)/intl \ + -I$(top_srcdir)/capplets/common \ + @CAPPLET_CFLAGS@ bin_PROGRAMS = sound-properties-capplet -#sound_properties_capplet_SOURCES = \ -# prefs-widget.c prefs-widget.h \ -# preferences.c preferences.h \ -# main.c - sound_properties_capplet_SOURCES = \ sound-properties-capplet.c -sound_properties_capplet_LDADD = @CAPPLET_LIBS@ +sound_properties_capplet_LDADD = \ + @CAPPLET_LIBS@ \ + $(top_builddir)/capplets/common/libcommon.a diff --git a/capplets/sound/sound-properties-capplet.c b/capplets/sound/sound-properties-capplet.c index f0be48326..23e65d689 100644 --- a/capplets/sound/sound-properties-capplet.c +++ b/capplets/sound/sound-properties-capplet.c @@ -25,27 +25,7 @@ # include #endif -#define DEBUG_MSG(str, args...) \ - g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "(%d:%s) " str, \ - getpid (), __FUNCTION__ , ## args) - -/* Macros for variables that vary from capplet to capplet */ - -#define DEFAULT_MONIKER "archiver:sound-properties" -#define FACTORY_IID "OAFIID:Bonobo_Control_Capplet_sound_properties_Factory" -#define GLADE_FILE GLADE_DATADIR "/sound-properties.glade" -#define G_LOG_DOMAIN "sound-properties" - -#include -#include - -#include - -/* FIXME: We should really have a single bonobo-conf.h header */ - -#include -#include -#include +#include "capplet-util.h" /* Needed only for the sound capplet */ @@ -53,30 +33,6 @@ #include #include -/* Macros to make certain repetitive tasks a bit easier */ - -/* Retrieve a widget from the Glade object */ - -#define WID(s) glade_xml_get_widget (dialog, s) - -/* Copy a setting from the legacy gnome-config settings to the ConfigDatabase */ - -#define COPY_FROM_LEGACY(type, key, legacy_type, legacy_key) \ - val_##type = gnome_config_get_##legacy_type##_with_default (legacy_key, &def); \ - \ - if (!def) \ - bonobo_config_set_##type (db, key, val_##type, NULL); \ - -/* Create a property editor */ - -#define CREATE_PEDITOR(type, key, widget) \ - ed = BONOBO_PEDITOR (bonobo_peditor_##type##_construct (WID (widget))); \ - bonobo_peditor_set_property (ed, proxy, key, TC_##type, NULL); \ - -static BonoboControl *control = NULL; -static GladeXML *dialog; -static GtkWidget *widget; - /* Capplet-specific prototypes */ static void start_esd (void); @@ -106,68 +62,6 @@ apply_settings (Bonobo_ConfigDatabase db) * entirely too painful */ } -/* apply_cb - * - * Callback issued when the user clicks "Apply" or "Ok". This function is - * responsible for making sure the current settings are properly applied. It - * does not vary between capplets. - */ - -static void -apply_cb (BonoboPropertyControl *pc, Bonobo_PropertyControl_Action action) -{ - BonoboPropertyFrame *pf; - Bonobo_ConfigDatabase db; - CORBA_Environment ev; - - if (action == Bonobo_PropertyControl_APPLY) { - CORBA_exception_init (&ev); - - pf = gtk_object_get_data (GTK_OBJECT (pc), "property-frame"); - db = gtk_object_get_data (GTK_OBJECT (pf), "config-database"); - bonobo_pbproxy_update (pf->proxy); - Bonobo_ConfigDatabase_sync (db, &ev); - - CORBA_exception_free (&ev); - } -} - -/* changed_cb - * - * Callback issued when a setting in the ConfigDatabase changes. Does not vary - * from capplet to capplet. - */ - -static void -changed_cb (BonoboListener *listener, gchar *event_name, CORBA_any *any, - CORBA_Environment *ev, Bonobo_ConfigDatabase db) -{ - apply_settings (db); -} - -/* get_legacy_settings - * - * Retrieve older gnome_config -style settings and store them in the - * configuration database. This function is written per-capplet. - * - * In most cases, it's best to use the COPY_FROM_LEGACY macro defined above. */ - -static void -get_legacy_settings (Bonobo_ConfigDatabase db) -{ - gboolean val_boolean, def; - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - COPY_FROM_LEGACY (boolean, "enable_esd", bool, "/sound/system/settings/start_esd=false"); - COPY_FROM_LEGACY (boolean, "event_sounds", bool, "/sound/system/settings/event_sounds=false"); - - Bonobo_ConfigDatabase_sync (db, &ev); - - CORBA_exception_free (&ev); -} - /* start_esd * * Start the Enlightenment Sound Daemon. This function is specific to the sound @@ -203,230 +97,40 @@ start_esd (void) #endif } -/* get_moniker_cb +/* setup_dialog * - * Callback issued to retrieve the name of the moniker being used. This function - * is just a formality and does not vary between capplets + * Set up the property editors for our dialog */ static void -get_moniker_cb (BonoboPropertyBag *bag, BonoboArg *arg, guint arg_id, - CORBA_Environment *ev, BonoboControl *control) +setup_dialog (GladeXML *dialog, Bonobo_PropertyBag bag) { - BONOBO_ARG_SET_STRING (arg, gtk_object_get_data (GTK_OBJECT (control), "moniker")); -} - -/* set_moniker_cb - * - * Callback issued when the name of the moniker to be used is set. This function - * does most of the dirty work -- creating the property editors that connect - * properties to the dialog box. The portion of this function appropriately - * labelled must be written once for each capplet. - */ - -static void -set_moniker_cb (BonoboPropertyBag *bag, BonoboArg *arg, guint arg_id, - CORBA_Environment *ev, BonoboControl *control) -{ - gchar *moniker; - gchar *full_moniker; - BonoboPEditor *ed; - BonoboPropertyFrame *pf; - Bonobo_PropertyBag proxy; - GladeXML *dialog; - Bonobo_ConfigDatabase db; - - if (arg_id != 1) return; - - moniker = BONOBO_ARG_GET_STRING (arg); - full_moniker = g_strconcat (moniker, "#config:/main", NULL); - - pf = BONOBO_PROPERTY_FRAME (bonobo_control_get_widget (control)); - bonobo_property_frame_set_moniker (pf, full_moniker); - proxy = BONOBO_OBJREF (pf->proxy); - dialog = gtk_object_get_data (GTK_OBJECT (control), "dialog"); - - db = bonobo_get_object (moniker, "IDL:Bonobo/ConfigDatabase:1.0", ev); - - if (BONOBO_EX (ev) || db == CORBA_OBJECT_NIL) - g_critical ("Could not resolve configuration moniker; will not be able to save settings"); - - gtk_object_set_data (GTK_OBJECT (pf), "config-database", db); - - /* Begin per-capplet part */ - CREATE_PEDITOR (boolean, "enable_esd", "enable_toggle"); CREATE_PEDITOR (boolean, "event_sounds", "events_toggle"); - - /* End per-capplet part */ } -/* close_cb +/* get_legacy_settings * - * Callback issued when the dialog is destroyed. Just resets the control pointer - * to NULL so that the program does not think the dialog exists when it does - * not. Does not vary from capplet to capplet. + * Retrieve older gnome_config -style settings and store them in the + * configuration database. + * + * In most cases, it's best to use the COPY_FROM_LEGACY macro defined in + * capplets/common/capplet-util.h. */ static void -close_cb (void) +get_legacy_settings (Bonobo_ConfigDatabase db) { - gtk_object_destroy (GTK_OBJECT (dialog)); - control = NULL; + gboolean val_boolean, def; + + COPY_FROM_LEGACY (boolean, "enable_esd", bool, "/sound/system/settings/start_esd=false"); + COPY_FROM_LEGACY (boolean, "event_sounds", bool, "/sound/system/settings/event_sounds=false"); } -/* create_dialog_cb - * - * Callback to construct the main dialog box for this capplet; invoked by Bonobo - * whenever capplet activation is requested. Returns a BonoboObject representing - * the control that encapsulates the object. This function should not vary from - * capplet to capplet, though it assumes that the dialog data in the glade file - * has the name "prefs_widget". - */ - -static BonoboObject * -create_dialog_cb (BonoboPropertyControl *property_control, gint page_number) -{ - BonoboPropertyBag *pb; - GtkWidget *pf; - - if (control == NULL) { - dialog = glade_xml_new (GLADE_FILE, "prefs_widget"); - - if (dialog == NULL) { - g_critical ("Could not load glade file"); - return NULL; - } - - widget = glade_xml_get_widget (dialog, "prefs_widget"); - - if (widget == NULL) { - g_critical ("Could not find preferences widget"); - return NULL; - } - - pf = bonobo_property_frame_new (NULL, NULL); - gtk_object_set_data (GTK_OBJECT (property_control), - "property-frame", pf); - gtk_container_add (GTK_CONTAINER (pf), widget); - gtk_widget_show_all (pf); - - control = bonobo_control_new (pf); - gtk_object_set_data (GTK_OBJECT (control), "dialog", dialog); - - pb = bonobo_property_bag_new ((BonoboPropertyGetFn) get_moniker_cb, - (BonoboPropertySetFn) set_moniker_cb, - control); - bonobo_control_set_properties (control, pb); - bonobo_object_unref (BONOBO_OBJECT (pb)); - - bonobo_property_bag_add (pb, "moniker", 1, BONOBO_ARG_STRING, NULL, - "Moniker for configuration", - BONOBO_PROPERTY_WRITEABLE); - - bonobo_control_set_automerge (control, TRUE); - - gtk_signal_connect (GTK_OBJECT (widget), "destroy", - GTK_SIGNAL_FUNC (close_cb), NULL); - gtk_signal_connect (GTK_OBJECT (control), "destroy", - GTK_SIGNAL_FUNC (close_cb), NULL); - } else { - gtk_widget_show_all (widget); - } - - return BONOBO_OBJECT (control); -} - -/* create_control_cb - * - * Small function to create the PropertyControl and return it. It may be copied - * and pasted from capplet to capplet. - */ - -static BonoboObject * -create_control_cb (BonoboGenericFactory *factory, Bonobo_ConfigDatabase db) -{ - BonoboPropertyControl *property_control; - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - property_control = bonobo_property_control_new - ((BonoboPropertyControlGetControlFn) create_dialog_cb, 1, NULL); - gtk_signal_connect (GTK_OBJECT (property_control), "action", - GTK_SIGNAL_FUNC (apply_cb), NULL); - - bonobo_event_source_client_add_listener - (db, (BonoboListenerCallbackFn) changed_cb, - "Bonobo/ConfigDatabase:change", &ev, db); - - CORBA_exception_free (&ev); - - return BONOBO_OBJECT (property_control); -} - -/* main -- This function should not vary from capplet to capplet - * - * FIXME: Should there be this much code in main()? Seems a tad complicated; - * some of it could be factored into a library, but which library should we use? - * libcapplet is to be deprecated, so we don't want to use that, and it doesn't - * seem right to use bonobo-conf for this purpose. - * - * *sigh*. I have a headache. - */ - int main (int argc, char **argv) { - BonoboGenericFactory *factory; - Bonobo_ConfigDatabase db; - CORBA_ORB orb; - CORBA_Environment ev; - - static gboolean apply_only; - static gboolean get_legacy; - static struct poptOption cap_options[] = { - { "apply", '\0', POPT_ARG_NONE, &apply_only, 0, - N_("Just apply settings and quit"), NULL }, - { "get-legacy", '\0', POPT_ARG_NONE, &get_legacy, 0, - N_("Retrieve and store legacy settings"), NULL }, - { NULL, '\0', 0, NULL, 0, NULL, NULL } - }; - - bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE); - - CORBA_exception_init (&ev); - - glade_gnome_init (); - gnomelib_register_popt_table (cap_options, _("Capplet options")); - gnome_init_with_popt_table (argv[0], VERSION, argc, argv, - oaf_popt_options, 0, NULL); - - orb = oaf_init (argc, argv); - if (bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) - g_error ("Cannot initialize bonobo"); - - db = bonobo_get_object (DEFAULT_MONIKER, "IDL:Bonobo/ConfigDatabase:1.0", &ev); - - if (db == CORBA_OBJECT_NIL) { - g_critical ("Cannot open configuration database"); - return -1; - } - - if (apply_only) - apply_settings (db); - else if (get_legacy) - get_legacy_settings (db); - else { - factory = bonobo_generic_factory_new - ("OAFIID:Bonobo_Control_Capplet_sound_properties_Factory", - (BonoboGenericFactoryFn) create_control_cb, db); - bonobo_running_context_auto_exit_unref (BONOBO_OBJECT (factory)); - bonobo_main (); - } - - CORBA_exception_free (&ev); + capplet_init (argc, argv, apply_settings, setup_dialog, get_legacy_settings); return 0; } diff --git a/configure.in b/configure.in index dd0488a78..8268d018b 100644 --- a/configure.in +++ b/configure.in @@ -144,6 +144,7 @@ po/Makefile.in archiver/Makefile control-center/Makefile capplets/Makefile +capplets/common/Makefile capplets/background/Makefile capplets/keyboard/Makefile capplets/mouse/Makefile