diff options
Diffstat (limited to 'capplets')
-rw-r--r-- | capplets/background/ChangeLog | 38 | ||||
-rw-r--r-- | capplets/background/applier.c | 17 | ||||
-rw-r--r-- | capplets/background/applier.h | 2 | ||||
-rw-r--r-- | capplets/background/background-properties-capplet.c | 96 | ||||
-rw-r--r-- | capplets/background/preferences.c | 120 | ||||
-rw-r--r-- | capplets/background/preferences.h | 50 |
6 files changed, 242 insertions, 81 deletions
diff --git a/capplets/background/ChangeLog b/capplets/background/ChangeLog index df40ea5c4..26bcae34d 100644 --- a/capplets/background/ChangeLog +++ b/capplets/background/ChangeLog @@ -1,3 +1,41 @@ +2001-08-27 Bradford Hovinen <hovinen@ximian.com> + + * background-properties-capplet.c (setup_dialog): Initialize/free + the CORBA environment structure + (real_realize_cb): Put into an idle handler, called by + realize_2_cb, the new timeout handler + + * preferences.c (preferences_load_from_bonobo_pbag): + (preferences_load_from_bonobo_db): Extract from preferences_new_* + + * background-properties-capplet.c (property_change_cb): + (realize_cb): Accept prefs structure in lieu of + Bonobo_PropertyBag; don't reload the preferences structure from + the property bag + (property_change_cb): Call preferences_apply_event to modify the + preferences structure appropriately + (property_change_cb): + (realize_cb): If the preferences structure is marked destroyed, + just return + (setup_dialog): Create a preferences structure from the property + bag given and use that as the extra data passed to callbacks + (realize_cb): Put into an idle handler real_realize_cb + + * preferences.c (preferences_apply_event): Implement + + * applier.c (output_compat_prefs): Make prefs const + + * applier.[ch]: Have applier_apply_prefs take a const Preferences + structure + + * preferences.[ch]: Make preferences_clone take a const + Preferences structure + +2001-08-26 Bradford Hovinen <hovinen@ximian.com> + + * applier.c (renderer_render_background): Remove debugging message + (renderer_render_wallpaper): Ditto + 2001-08-17 Bradford Hovinen <hovinen@ximian.com> * applier.c (renderer_render_wallpaper): Adjust opacity value to diff --git a/capplets/background/applier.c b/capplets/background/applier.c index 1dfc470a9..bc38afdc5 100644 --- a/capplets/background/applier.c +++ b/capplets/background/applier.c @@ -45,8 +45,6 @@ #define MONITOR_CONTENTS_WIDTH 157 #define MONITOR_CONTENTS_HEIGHT 111 -#define PDEBUG(pix) (g_print ("file %s: line %d (%s): Setting pixbuf to %i %i\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, gdk_pixbuf_get_width (pix), gdk_pixbuf_get_height (pix))) - static gboolean gdk_pixbuf_xlib_inited = FALSE; typedef struct _Renderer Renderer; @@ -165,7 +163,7 @@ static void set_root_pixmap (Pixmap pixmap); static gboolean is_nautilus_running (void); -static void output_compat_prefs (Preferences *prefs); +static void output_compat_prefs (const Preferences *prefs); guint applier_get_type (void) @@ -302,8 +300,10 @@ applier_destroy (GtkObject *object) } void -applier_apply_prefs (Applier *applier, Preferences *prefs, - gboolean do_root, gboolean do_preview) +applier_apply_prefs (Applier *applier, + const Preferences *prefs, + gboolean do_root, + gboolean do_preview) { Preferences *new_prefs; @@ -719,7 +719,6 @@ renderer_render_background (Renderer *renderer) (GdkPixbufDestroyNotify) g_free, NULL); - PDEBUG (renderer->pixbuf); } } @@ -828,7 +827,6 @@ renderer_render_wallpaper (Renderer *renderer) GDK_INTERP_BILINEAR, alpha_value, 65536, colorv, colorv); - PDEBUG (renderer->pixbuf); } } else if (renderer->wwidth != renderer->pwidth || @@ -882,7 +880,6 @@ renderer_render_wallpaper (Renderer *renderer) gdk_pixbuf_unref (renderer->pixbuf); renderer->pixbuf = renderer->wallpaper_pixbuf; - PDEBUG (renderer->pixbuf); gdk_pixbuf_ref (renderer->pixbuf); } @@ -1382,10 +1379,10 @@ is_nautilus_running (void) static void -output_compat_prefs (Preferences *prefs) +output_compat_prefs (const Preferences *prefs) { gchar *color; - + gnome_config_pop_prefix (); gnome_config_set_bool ("/Background/Default/Enabled", prefs->enabled); gnome_config_set_string ("/Background/Default/wallpaper", diff --git a/capplets/background/applier.h b/capplets/background/applier.h index d43a89052..6264f7f1b 100644 --- a/capplets/background/applier.h +++ b/capplets/background/applier.h @@ -56,7 +56,7 @@ guint applier_get_type (void); GtkObject *applier_new (void); void applier_destroy (GtkObject *object); -void applier_apply_prefs (Applier *applier, Preferences *prefs, +void applier_apply_prefs (Applier *applier, const Preferences *prefs, gboolean do_root, gboolean do_preview); GtkWidget *applier_get_preview_widget (Applier *applier); diff --git a/capplets/background/background-properties-capplet.c b/capplets/background/background-properties-capplet.c index 53d7a88cb..b3af984f1 100644 --- a/capplets/background/background-properties-capplet.c +++ b/capplets/background/background-properties-capplet.c @@ -57,12 +57,11 @@ apply_settings (Bonobo_ConfigDatabase db) CORBA_Environment ev; CORBA_exception_init (&ev); - if (!applier) + if (applier == NULL) applier = APPLIER (applier_new ()); - /* HAckity hackty */ - if (background_image) - { + /* Hackity hackty */ + if (background_image != NULL) { bonobo_config_set_filename (db, "/main/wallpaper_filename", background_image, NULL); Bonobo_ConfigDatabase_sync (db, &ev); } @@ -130,10 +129,10 @@ copy_color_from_legacy (Bonobo_ConfigDatabase db, } static void -bonobo_config_set_filename (Bonobo_ConfigDatabase db, - const char *key, - const char *value, - CORBA_Environment *opt_ev) +bonobo_config_set_filename (Bonobo_ConfigDatabase db, + const char *key, + const char *value, + CORBA_Environment *opt_ev) { CORBA_any *any; @@ -148,7 +147,7 @@ get_legacy_settings (Bonobo_ConfigDatabase db) { gboolean val_boolean, def; gchar *val_string, *val_filename; - int val_ulong, val_long; + int val_ulong = -1, val_long = -1; COPY_FROM_LEGACY (boolean, "/main/enabled", bool, "/Background/Default/Enabled=true"); COPY_FROM_LEGACY (filename, "/main/wallpaper_filename", string, "/Background/Default/wallpaper=none"); @@ -177,51 +176,70 @@ get_legacy_settings (Bonobo_ConfigDatabase db) val_boolean = gnome_config_get_bool_with_default ("/Background/Default/adjustOpacity=true", &def); - if (!def && val_boolean) { + if (!def && val_boolean) COPY_FROM_LEGACY (long, "/main/opacity", int, "/Background/Default/opacity=100"); - } } static void -property_change_cb (BonoboListener *listener, - char *event_name, - CORBA_any *any, - CORBA_Environment *ev, - Bonobo_PropertyBag pb) +property_change_cb (BonoboListener *listener, + char *event_name, + CORBA_any *any, + CORBA_Environment *ev, + Preferences *prefs) { - Preferences *prefs; + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); - prefs = PREFERENCES (preferences_new_from_bonobo_pbag (pb, ev)); + if (GTK_OBJECT_DESTROYED (prefs)) + return; + + preferences_apply_event (prefs, event_name, any); applier_apply_prefs (applier, prefs, FALSE, TRUE); - gtk_object_destroy (GTK_OBJECT (prefs)); } -static void -realize_cb (GtkWidget *widget, Bonobo_PropertyBag bag) +static gboolean +real_realize_cb (Preferences *prefs) { - CORBA_Environment ev; - Preferences *prefs; - - CORBA_exception_init (&ev); - prefs = PREFERENCES (preferences_new_from_bonobo_pbag (bag, &ev)); + g_return_val_if_fail (prefs != NULL, TRUE); + g_return_val_if_fail (IS_PREFERENCES (prefs), TRUE); + + if (GTK_OBJECT_DESTROYED (prefs)) + return FALSE; + applier_apply_prefs (applier, prefs, FALSE, TRUE); - gtk_object_destroy (GTK_OBJECT (prefs)); - CORBA_exception_free (&ev); + + return FALSE; } -#define CUSTOM_CREATE_PEDITOR(type, corba_type, key, widget) \ +static gboolean +realize_2_cb (Preferences *prefs) +{ + gtk_idle_add ((GtkFunction) real_realize_cb, prefs); + return FALSE; +} + +static void +realize_cb (GtkWidget *widget, Preferences *prefs) +{ + gtk_timeout_add (100, (GtkFunction) realize_2_cb, prefs); +} + +#define CUSTOM_CREATE_PEDITOR(type, corba_type, key, widget) \ { \ BonoboPEditor *ed = BONOBO_PEDITOR \ (bonobo_peditor_##type##_construct (WID (widget))); \ - bonobo_peditor_set_property (ed, bag, key, TC_##corba_type, NULL); \ + bonobo_peditor_set_property (ed, bag, key, TC_##corba_type, NULL); \ } - static void setup_dialog (GtkWidget *widget, Bonobo_PropertyBag bag) { - GladeXML *dialog; - Applier *applier; + GladeXML *dialog; + Applier *applier; + GtkObject *prefs; + CORBA_Environment ev; + + CORBA_exception_init (&ev); dialog = gtk_object_get_data (GTK_OBJECT (widget), "glade-data"); CUSTOM_CREATE_PEDITOR (option_menu, ulong, "orientation", "color_option"); @@ -233,15 +251,23 @@ setup_dialog (GtkWidget *widget, Bonobo_PropertyBag bag) CUSTOM_CREATE_PEDITOR (option_menu, ulong, "wallpaper_type", "image_option"); CUSTOM_CREATE_PEDITOR (int_range, long, "opacity", "opacity_spin"); + /* Disable opacity controls */ gtk_widget_hide (WID ("opacity_spin")); gtk_widget_hide (WID ("opacity_label")); bonobo_property_bag_client_set_value_gboolean (bag, "enabled", TRUE, NULL); + + prefs = preferences_new_from_bonobo_pbag (bag, &ev); bonobo_event_source_client_add_listener (bag, (BonoboListenerCallbackFn) property_change_cb, - NULL, NULL, bag); + NULL, NULL, prefs); applier = gtk_object_get_data (GTK_OBJECT (widget), "applier"); - gtk_signal_connect_after (GTK_OBJECT (applier_get_preview_widget (applier)), "realize", realize_cb, bag); + gtk_signal_connect_after (GTK_OBJECT (applier_get_preview_widget (applier)), "realize", realize_cb, prefs); + + gtk_signal_connect_object (GTK_OBJECT (widget), "destroy", + GTK_SIGNAL_FUNC (gtk_object_destroy), prefs); + + CORBA_exception_free (&ev); } static GtkWidget* diff --git a/capplets/background/preferences.c b/capplets/background/preferences.c index 7c839a0c5..2978f11fe 100644 --- a/capplets/background/preferences.c +++ b/capplets/background/preferences.c @@ -127,7 +127,7 @@ preferences_new (void) } GtkObject * -preferences_clone (Preferences *prefs) +preferences_clone (const Preferences *prefs) { GtkObject *object; Preferences *new_prefs; @@ -139,11 +139,11 @@ preferences_clone (Preferences *prefs) new_prefs = PREFERENCES (object); - new_prefs->enabled = prefs->enabled; - new_prefs->gradient_enabled = prefs->gradient_enabled; - new_prefs->wallpaper_enabled = prefs->wallpaper_enabled; - new_prefs->orientation = prefs->orientation; - new_prefs->wallpaper_type = prefs->wallpaper_type; + new_prefs->enabled = prefs->enabled; + new_prefs->gradient_enabled = prefs->gradient_enabled; + new_prefs->wallpaper_enabled = prefs->wallpaper_enabled; + new_prefs->orientation = prefs->orientation; + new_prefs->wallpaper_type = prefs->wallpaper_type; if (prefs->color1) new_prefs->color1 = gdk_color_copy (prefs->color1); @@ -153,9 +153,9 @@ preferences_clone (Preferences *prefs) new_prefs->wallpaper_filename = g_strdup (prefs->wallpaper_filename); new_prefs->wallpaper_sel_path = g_strdup (prefs->wallpaper_sel_path);; - new_prefs->auto_apply = prefs->auto_apply; - new_prefs->adjust_opacity = prefs->adjust_opacity; - new_prefs->opacity = prefs->opacity; + new_prefs->auto_apply = prefs->auto_apply; + new_prefs->adjust_opacity = prefs->adjust_opacity; + new_prefs->opacity = prefs->opacity; return object; } @@ -177,6 +177,7 @@ preferences_destroy (GtkObject *object) } #ifdef BONOBO_CONF_ENABLE + static GdkColor* bonobo_color_to_gdk (Bonobo_Config_Color *color) { @@ -208,7 +209,7 @@ bonobo_property_bag_client_get_value_gulong (Bonobo_PropertyBag pb, gchar *propn #define PB_GET_VALUE(v) (bonobo_property_bag_client_get_value_any (pb, (v), NULL)) -GtkObject* +GtkObject * preferences_new_from_bonobo_pbag (Bonobo_PropertyBag pb, CORBA_Environment *ev) { Preferences *prefs; @@ -217,7 +218,21 @@ preferences_new_from_bonobo_pbag (Bonobo_PropertyBag pb, CORBA_Environment *ev) g_return_val_if_fail (ev != NULL, NULL); prefs = PREFERENCES (preferences_new ()); - + preferences_load_from_bonobo_pbag (prefs, pb, ev); + + return GTK_OBJECT (prefs); +} + +void +preferences_load_from_bonobo_pbag (Preferences *prefs, + Bonobo_PropertyBag pb, + CORBA_Environment *ev) +{ + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + g_return_if_fail (pb != CORBA_OBJECT_NIL); + g_return_if_fail (ev != NULL); + prefs->wallpaper_type = bonobo_property_bag_client_get_value_gulong (pb, "wallpaper_type", ev); prefs->wallpaper_filename = g_strdup (*((CORBA_char **)(PB_GET_VALUE ("wallpaper_filename"))->_value)); @@ -241,13 +256,11 @@ preferences_new_from_bonobo_pbag (Bonobo_PropertyBag pb, CORBA_Environment *ev) prefs->gradient_enabled = FALSE; else prefs->gradient_enabled = TRUE; - - return GTK_OBJECT (prefs); } #define DB_GET_VALUE(v) (bonobo_config_get_value (db, (v), NULL, NULL)) -GtkObject* +GtkObject * preferences_new_from_bonobo_db (Bonobo_ConfigDatabase db, CORBA_Environment *ev) { Preferences *prefs; @@ -256,6 +269,20 @@ preferences_new_from_bonobo_db (Bonobo_ConfigDatabase db, CORBA_Environment *ev) g_return_val_if_fail (ev != NULL, NULL); prefs = PREFERENCES (preferences_new ()); + preferences_load_from_bonobo_db (prefs, db, ev); + + return GTK_OBJECT (prefs); +} + +void +preferences_load_from_bonobo_db (Preferences *prefs, + Bonobo_ConfigDatabase db, + CORBA_Environment *ev) +{ + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + g_return_if_fail (db != CORBA_OBJECT_NIL); + g_return_if_fail (ev != NULL); prefs->enabled = bonobo_config_get_boolean (db, "/main/enabled", NULL); prefs->orientation = bonobo_config_get_ulong (db, "/main/orientation", NULL); @@ -280,10 +307,68 @@ preferences_new_from_bonobo_db (Bonobo_ConfigDatabase db, CORBA_Environment *ev) prefs->opacity = BONOBO_ARG_GET_LONG (DB_GET_VALUE ("/main/opacity")); if (prefs->opacity >= 100) prefs->adjust_opacity = FALSE; +} - return GTK_OBJECT (prefs); +void +preferences_apply_event (Preferences *prefs, + const gchar *event_name, + const CORBA_any *value) +{ + const gchar *name; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + g_return_if_fail (event_name != NULL); + + if (strncmp (event_name, "Bonobo/Property:change:", strlen ("Bonobo/Property:change:"))) + return; + + name = event_name + strlen ("Bonobo/Property:change:"); + + if (!strcmp (name, "wallpaper_type")) { + prefs->wallpaper_type = BONOBO_ARG_GET_GENERAL (value, TC_ulong, CORBA_long, NULL); + } + else if (!strcmp (name, "wallpaper_filename")) { + if (!bonobo_arg_type_is_equal (value->_type, TC_Bonobo_Config_FileName, NULL)) { + g_warning ("Filename property not of filename type"); + return; + } + + prefs->wallpaper_filename = g_strdup (*((char **)value->_value)); + + if (prefs->wallpaper_filename != NULL && + strcmp (prefs->wallpaper_filename, "") != 0 && + strcmp (prefs->wallpaper_filename, "(none)") != 0) + prefs->wallpaper_enabled = TRUE; + else + prefs->wallpaper_enabled = FALSE; + } + else if (!strcmp (name, "color1")) { + prefs->color1 = bonobo_color_to_gdk ((Bonobo_Config_Color *)value->_value); + } + else if (!strcmp (name, "color2")) { + prefs->color2 = bonobo_color_to_gdk ((Bonobo_Config_Color *)value->_value); + } + else if (!strcmp (name, "opacity")) { + prefs->opacity = BONOBO_ARG_GET_LONG (value); + + if (prefs->opacity >= 100) + prefs->adjust_opacity = FALSE; + } + else if (!strcmp (name, "orientation")) { + prefs->orientation = BONOBO_ARG_GET_GENERAL (value, TC_ulong, CORBA_long, NULL); + + if (prefs->orientation == ORIENTATION_SOLID) + prefs->gradient_enabled = FALSE; + else + prefs->gradient_enabled = TRUE; + } else { + g_warning ("%s: Unknown property: %s", __FUNCTION__, name); + } } -#else + +#else /* !BONOBO_CONF_ENABLE */ + void preferences_load (Preferences *prefs) { @@ -681,7 +766,8 @@ apply_timeout_cb (Preferences *prefs) return TRUE; } -#endif + +#endif /* BONOBO_CONF_ENABLE */ static GdkColor * read_color_from_string (gchar *string) diff --git a/capplets/background/preferences.h b/capplets/background/preferences.h index 43d33d837..719052a90 100644 --- a/capplets/background/preferences.h +++ b/capplets/background/preferences.h @@ -79,30 +79,44 @@ struct _PreferencesClass GtkObjectClass klass; }; -guint preferences_get_type (void); +guint preferences_get_type (void); -GtkObject *preferences_new (void); -GtkObject *preferences_clone (Preferences *prefs); +GtkObject *preferences_new (void); +GtkObject *preferences_clone (const Preferences *prefs); -void preferences_destroy (GtkObject *object); +void preferences_destroy (GtkObject *object); #ifdef BONOBO_CONF_ENABLE -GtkObject *preferences_new_from_bonobo_pbag (Bonobo_PropertyBag pb, - CORBA_Environment *ev); -GtkObject *preferences_new_from_bonobo_db (Bonobo_ConfigDatabase db, - CORBA_Environment *ev); -#else -void preferences_load (Preferences *prefs); -void preferences_save (Preferences *prefs); -void preferences_changed (Preferences *prefs); -void preferences_apply_now (Preferences *prefs); -void preferences_apply_preview (Preferences *prefs); -void preferences_freeze (Preferences *prefs); -void preferences_thaw (Preferences *prefs); +GtkObject *preferences_new_from_bonobo_pbag (Bonobo_PropertyBag pb, + CORBA_Environment *ev); +GtkObject *preferences_new_from_bonobo_db (Bonobo_ConfigDatabase db, + CORBA_Environment *ev); +void preferences_load_from_bonobo_pbag (Preferences *prefs, + Bonobo_ConfigDatabase db, + CORBA_Environment *ev); +void preferences_load_from_bonobo_db (Preferences *prefs, + Bonobo_ConfigDatabase db, + CORBA_Environment *ev); + +void preferences_apply_event (Preferences *prefs, + const gchar *event_name, + const CORBA_any *value); + +#else /* !BONOBO_CONF_ENABLE */ + +void preferences_load (Preferences *prefs); +void preferences_save (Preferences *prefs); +void preferences_changed (Preferences *prefs); +void preferences_apply_now (Preferences *prefs); +void preferences_apply_preview (Preferences *prefs); + +void preferences_freeze (Preferences *prefs); +void preferences_thaw (Preferences *prefs); + +Preferences *preferences_read_xml (xmlDocPtr xml_doc); +xmlDocPtr preferences_write_xml (Preferences *prefs); -Preferences *preferences_read_xml (xmlDocPtr xml_doc); -xmlDocPtr preferences_write_xml (Preferences *prefs); #endif /* BONOBO_CONF_ENABLE */ #endif /* __PREFERENCES_H */ |