[Nautilus-list] [Updated Patch] Use GConf for background settings
- From: Håvard Wigtil <havardw stud ntnu no>
- To: Darin Adler <darin bentspoon com>
- Cc: Nautilus <nautilus-list lists eazel com>
- Subject: [Nautilus-list] [Updated Patch] Use GConf for background settings
- Date: 10 Feb 2002 00:58:07 +0100
On Thu, 2002-02-07 at 17:48, Darin Adler wrote:
> On 1/25/02 3:40 PM, "Håvard Wigtil" <havardw stud ntnu no> wrote:
>
> > The included patch reads desktop settings from GConf, and updates the
> > desktop when these settings change. This is (an attempt) at a straight
> > port, so it doesn't do any more error checking than the original code
> > did. It will crash on bad settings for colors or file name.
>
> Please fix that, regardless of the status of the original code. I don't
> think you need "complete" error checking, just enough to avoid a crash if
> you get an unexpected value from gconf.
Here is an improved patch that survives "gconftool --break-directory"
and handles corrupted values from GConf at startup fairly well. (At
least I haven't been able to break it, but I'm sure someone else will ;)
In addition to the improvements you suggested, this patch has a separate
callback for each GConf key (where the old had one callback for all
color settings), and the section for setting the initial desktop color
has been reworked to (hopefully) be clearer and more robust.
I don't think that the "Reset Desktop Background" option in the desktop
menu makes much sense for Gnome2, as MetaTheme will handle desktop
themes. I think it should be removed (and I'll do it together with the
code removal patch I promised if you agree), but it could also be made
to reset according to the current metatheme. But that sould be a job for
the metatheme capplet IMHO.
> How have you tested these changes?
This one (and also the previous patch) was tested with gconftool and the
background capplet.
> >+ image_name = gconf_value_get_string(entry->value);
> >+ eel_background_set_image_uri_sync (background, image_name);
>
> Need to free image_name here.
If I read the GConf sources correctly, this will only return a reference
to a field in the private details structure. From "gconf-value.h":
#define gconf_value_get_string(x) ((const
gchar*)(((GConfValue*)(x))->d.string_data))
> > + g_object_set_data (G_OBJECT (background), "theme_source", (gpointer)
> desktop_theme_source);
>
> Do you need this (gpointer) cast?
I get a warning if I don't, probably because desktop_theme_source is
defined as static. But it took some time before I was able to make any
sense of the error I got ("passing arg 3 of `g_object_set_data' discards
qualifiers from pointer target type"), so there might be other ways.
--
Håvard
mailto:havardw stud ntnu no||http://www.stud.ntnu.no/~havardw||73 52 55
76
All it takes to start an avalanche is a single snowflake||Or a
snowboarder
Oh! Un Fraggle! Regarde, maman! J'ai attrapé un Fraggle!
? gconf-background-improved.patch
? gconf-background.patch
? nautilus-1st.patch
? libnautilus-private/nautilus-directory-background.verbose.c
Index: libnautilus-private/nautilus-directory-background.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-background.c,v
retrieving revision 1.69
diff -u -r1.69 nautilus-directory-background.c
--- libnautilus-private/nautilus-directory-background.c 2002/01/18 15:10:34 1.69
+++ libnautilus-private/nautilus-directory-background.c 2002/02/09 23:29:35
@@ -63,6 +63,34 @@
const char* image, const char* default_image,
EelBackgroundImagePlacement placement, EelBackgroundImagePlacement default_placement);
+static void nautilus_desktop_primary_color_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data);
+
+static void nautilus_desktop_secondary_color_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data);
+
+static void nautilus_desktop_shading_type_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data);
+
+static void nautilus_desktop_picture_options_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data);
+
+static void nautilus_desktop_picture_filename_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data);
+
+static gboolean nautilus_desktop_parse_image_placement (const char *spec,
+ EelBackgroundImagePlacement *placement);
+
static void
desktop_background_realized (NautilusIconContainer *icon_container, void *disconnect_signal)
{
@@ -747,9 +775,7 @@
color = eel_background_get_color (background);
image = eel_background_get_image_uri (background);
- if (background_is_desktop (background)) {
- nautilus_file_background_write_desktop_settings (color, image, eel_background_get_image_placement (background));
- } else {
+ if (!background_is_desktop (background)) {
/* Block the other handler while we are writing metadata so it doesn't
* try to change the background.
*/
@@ -1003,4 +1029,408 @@
file = nautilus_file_get (uri);
nautilus_connect_background_to_file_metadata (widget, file);
nautilus_file_unref (file);
+}
+
+
+
+static void
+nautilus_desktop_primary_color_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data)
+{
+ EelBackground* background;
+ const char *primary_color;
+ char* color_spec;
+ char* gradient;
+ GdkColor gdk_color;
+
+ g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (user_data));
+ background = eel_get_widget_background (GTK_WIDGET (user_data));
+ g_return_if_fail (EEL_IS_BACKGROUND (background));
+
+ /* Check for a valid color. */
+ if (entry->value == NULL) {
+ return;
+ }
+ if (entry->value->type != GCONF_VALUE_STRING) {
+ return;
+ }
+ primary_color = gconf_value_get_string (entry->value);
+ if (!gdk_color_parse (primary_color, &gdk_color)) {
+ return;
+ }
+
+
+ color_spec = eel_background_get_color (background);
+ if (color_spec == NULL || !eel_gradient_is_gradient (color_spec)) {
+ eel_background_set_color (background, primary_color);
+ }
+ else {
+ if (eel_gradient_is_horizontal (color_spec)) {
+ gradient = eel_gradient_set_left_color_spec (color_spec, primary_color);
+ }
+ else {
+ gradient = eel_gradient_set_top_color_spec (color_spec, primary_color);
+ }
+ eel_background_set_color (background, gradient);
+ g_free (gradient);
+ }
+ g_free (color_spec);
+}
+
+
+static void
+nautilus_desktop_secondary_color_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data)
+{
+ EelBackground* background;
+ const char *secondary_color;
+ char* color_spec;
+ char *gradient;
+ GdkColor gdk_color;
+
+
+ g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (user_data));
+ background = eel_get_widget_background (GTK_WIDGET (user_data));
+ g_return_if_fail (EEL_IS_BACKGROUND (background));
+
+ /* Check for a valid color. */
+ if (entry->value == NULL) {
+ return;
+ }
+ if (entry->value->type != GCONF_VALUE_STRING) {
+ return;
+ }
+ secondary_color = gconf_value_get_string (entry->value);
+ if (!gdk_color_parse (secondary_color, &gdk_color)) {
+ return;
+ }
+
+
+ color_spec = eel_background_get_color (background);
+ if (eel_gradient_is_gradient (color_spec)) {
+ if (eel_gradient_is_horizontal (color_spec)) {
+ gradient = eel_gradient_set_right_color_spec (color_spec, secondary_color);
+ }
+ else {
+ gradient = eel_gradient_set_bottom_color_spec (color_spec, secondary_color);
+ }
+ eel_background_set_color (background, gradient);
+ g_free (gradient);
+ }
+ g_free (color_spec);
+}
+
+
+static void
+nautilus_desktop_shading_type_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data)
+{
+ EelBackground* background;
+ char *primary_color;
+ char *secondary_color;
+ const char *shading_type;
+ char* color_spec;
+ char *gradient;
+
+
+ g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (user_data));
+ background = eel_get_widget_background (GTK_WIDGET (user_data));
+ g_return_if_fail (EEL_IS_BACKGROUND (background));
+
+
+ if (entry->value == NULL) {
+ return;
+ }
+ if (entry->value->type != GCONF_VALUE_STRING) {
+ return;
+ }
+ shading_type = gconf_value_get_string (entry->value);
+
+
+ color_spec = eel_background_get_color (background);
+ if (color_spec == NULL) {
+ return;
+ }
+
+ primary_color = eel_gradient_get_start_color_spec (color_spec);
+ if (primary_color == NULL) {
+ /* The spec is broken, so I won't try to change it. */
+ g_free (color_spec);
+ g_free (primary_color);
+ return;
+ }
+
+ if (eel_gradient_is_gradient (color_spec)) {
+ secondary_color = eel_gradient_get_end_color_spec (color_spec);
+ }
+ else {
+ secondary_color = eel_gconf_get_string ("/desktop/gnome/background/secondary_color");
+ }
+
+ gradient = NULL;
+ if (strcmp (shading_type, "solid") == 0) {
+ gradient = g_strdup (primary_color);
+ }
+ else if (strcmp (shading_type, "vertical-gradient") == 0) {
+ gradient = eel_gradient_new (primary_color, secondary_color, FALSE);
+ }
+ else if (strcmp (shading_type, "horizontal-gradient") == 0) {
+ gradient = eel_gradient_new (primary_color, secondary_color, TRUE);
+ }
+
+ if (gradient != NULL) {
+ eel_background_set_color (background, gradient);
+ g_free (gradient);
+ }
+
+ g_free (color_spec);
+ g_free (primary_color);
+ g_free (secondary_color);
+}
+
+
+static void
+nautilus_desktop_picture_options_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data)
+{
+ const char *image_type;
+ char *image_name;
+ EelBackground *background;
+ EelBackgroundImagePlacement placement;
+
+ g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER(user_data));
+ background = eel_get_widget_background (GTK_WIDGET (user_data));
+ g_return_if_fail (EEL_IS_BACKGROUND (background));
+
+
+ if (entry->value == NULL) {
+ return;
+ }
+ if (entry->value->type != GCONF_VALUE_STRING) {
+ return;
+ }
+ image_type = gconf_value_get_string (entry->value);
+ image_name = eel_background_get_image_uri (background);
+
+ if (eel_strcmp (image_type, "none") == 0) {
+ if (image_name != NULL) {
+ eel_background_set_image_uri(background, NULL);
+ }
+ }
+ else if (nautilus_desktop_parse_image_placement (image_type, &placement)) {
+ if (image_name == NULL) {
+ image_name = eel_gconf_get_string ("/desktop/gnome/background/picture_filename");
+ eel_background_set_image_uri_sync (background, image_name);
+ g_free (image_name);
+ }
+ eel_background_set_image_placement (background, placement);
+ }
+}
+
+
+static void
+nautilus_desktop_picture_filename_changed_callback (GConfClient* client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data)
+{
+
+ char *image_type;
+ const char *image_name;
+ EelBackground *background;
+
+
+ g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER(user_data));
+ background = eel_get_widget_background (GTK_WIDGET (user_data));
+ g_return_if_fail (EEL_IS_BACKGROUND (background));
+
+ if (entry->value == NULL) {
+ return;
+ }
+ if (entry->value->type != GCONF_VALUE_STRING) {
+ return;
+ }
+
+ image_type = eel_gconf_get_string ("/desktop/gnome/background/picture_options");
+ if (eel_strcmp (image_type, "none") == 0) {
+ g_free (image_type);
+ return;
+ }
+ g_free (image_type);
+
+ /* Don't need to free this sting, it's a copy from entry->value */
+ image_name = gconf_value_get_string(entry->value);
+ eel_background_set_image_uri_sync (background, image_name);
+}
+
+
+void
+nautilus_desktop_set_background (NautilusIconContainer *icon_container,
+ NautilusFile *file)
+{
+ EelBackground *background;
+ EelBackgroundImagePlacement placement;
+ char *primary_color;
+ char *secondary_color;
+ char *color_type;
+ char *gradient;
+ char *image_name;
+ char *image_type;
+ GdkColor dummy_color; /* Used to call gdk_color_parse to check for valid color. */
+
+
+ background = eel_get_widget_background (GTK_WIDGET (icon_container));
+
+ /* Make sure this is recognized as the desktop view */
+ g_object_set_data (G_OBJECT (background), "theme_source", (gpointer) desktop_theme_source);
+
+ /* Set up callbacks for EelBackground, so that the background is
+ painted when we change settings later. */
+ g_signal_connect (background,
+ "settings_changed",
+ G_CALLBACK (background_changed_callback),
+ file);
+ g_signal_connect (background,
+ "destroy",
+ G_CALLBACK (background_destroyed_callback),
+ file);
+ /* FIXME: Ability to reset desktop background to Nautilus
+ theme specification should probably be removed. */
+ g_signal_connect (background,
+ "reset",
+ G_CALLBACK (background_reset_callback),
+ file);
+
+
+ /* Attach the new directory. */
+ nautilus_file_ref (file);
+ g_object_set_data_full (G_OBJECT (background),
+ "eel_background_file",
+ file,
+ (GtkDestroyNotify) nautilus_file_unref);
+
+ /* Block signals for synchronized update */
+ gtk_signal_handler_block_by_func (GTK_OBJECT (background),
+ G_CALLBACK (background_changed_callback),
+ file);
+
+
+ /* Set image from GConf */
+ image_type = eel_gconf_get_string ("/desktop/gnome/background/picture_options");
+
+ if (eel_strcmp (image_type, "none") != 0) {
+ image_name = eel_gconf_get_string ("/desktop/gnome/background/picture_filename");
+
+ if (nautilus_desktop_parse_image_placement(image_type, &placement)) {
+ eel_background_set_image_placement (background, placement);
+ eel_background_set_image_uri_sync (background, image_name);
+ }
+ g_free (image_name);
+ }
+ g_free (image_type);
+
+
+ /* Set colors from GConf */
+ primary_color = eel_gconf_get_string ("/desktop/gnome/background/primary_color");
+ secondary_color = eel_gconf_get_string ("/desktop/gnome/background/secondary_color");
+ color_type = eel_gconf_get_string ("/desktop/gnome/background/color_shading_type");
+
+ if (primary_color == NULL || !gdk_color_parse (primary_color, &dummy_color)) {
+ /* Default to solid white on no primary color */
+ eel_background_set_color (background, "#fff");
+ }
+ else if (secondary_color == NULL || !gdk_color_parse (secondary_color, &dummy_color)
+ || color_type == NULL) {
+ /* Default to solid on no secondary color or shading type */
+ eel_background_set_color (background, primary_color);
+ }
+ else if (strcmp (color_type, "solid") == 0) {
+ eel_background_set_color (background, primary_color);
+ }
+ else if (strcmp (color_type, "horizontal-gradient") == 0) {
+ gradient = eel_gradient_new (primary_color, secondary_color, TRUE);
+ eel_background_set_color (background, gradient);
+ g_free (gradient);
+ }
+ else if (strcmp (color_type, "vertical-gradient") == 0) {
+ gradient = eel_gradient_new (primary_color, secondary_color, FALSE);
+ eel_background_set_color (background, gradient);
+ g_free (gradient);
+ }
+ else {
+ /* Unrecognized value for color_type, default to solid */
+ eel_background_set_color (background, primary_color);
+ }
+
+ g_free (primary_color);
+ g_free (secondary_color);
+ g_free (color_type);
+
+
+ /* Unblock the handler, so updates wil take effect. */
+ gtk_signal_handler_unblock_by_func (GTK_OBJECT (background),
+ G_CALLBACK (background_changed_callback),
+ file);
+
+ /** Set up callbacks for GConf changes. */
+ eel_gconf_monitor_add ("/desktop/gnome/background");
+ eel_gconf_notification_add ("/desktop/gnome/background/primary_color",
+ nautilus_desktop_primary_color_changed_callback,
+ icon_container);
+ eel_gconf_notification_add ("/desktop/gnome/background/secondary_color",
+ nautilus_desktop_secondary_color_changed_callback,
+ icon_container);
+ eel_gconf_notification_add ("/desktop/gnome/background/color_shading_type",
+ nautilus_desktop_shading_type_changed_callback,
+ icon_container);
+ eel_gconf_notification_add ("/desktop/gnome/background/picture_options",
+ nautilus_desktop_picture_options_changed_callback,
+ icon_container);
+ eel_gconf_notification_add ("/desktop/gnome/background/picture_filename",
+ nautilus_desktop_picture_filename_changed_callback,
+ icon_container);
+
+
+ if (GTK_WIDGET_REALIZED (icon_container)) {
+ desktop_background_realized (icon_container, GINT_TO_POINTER (FALSE));
+ } else {
+ g_signal_connect (icon_container, "realize", G_CALLBACK (desktop_background_realized), GINT_TO_POINTER (TRUE));
+ }
+
+ nautilus_file_background_receive_root_window_changes (background);
+}
+
+static gboolean
+nautilus_desktop_parse_image_placement (const char *spec, EelBackgroundImagePlacement *placement) {
+
+ if (spec == NULL) {
+ return FALSE;
+ }
+ else if (strcmp (spec, "wallpaper") == 0) {
+ *placement = EEL_BACKGROUND_TILED;
+ return TRUE;
+ }
+ else if (strcmp (spec, "centered") == 0) {
+ *placement = EEL_BACKGROUND_CENTERED;
+ return TRUE;
+ }
+ else if (strcmp (spec, "scaled") == 0) {
+ *placement = EEL_BACKGROUND_SCALED_ASPECT;
+ return TRUE;
+ }
+ else if (strcmp (spec, "stretched") == 0) {
+ *placement = EEL_BACKGROUND_SCALED;
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
}
Index: libnautilus-private/nautilus-directory-background.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-background.h,v
retrieving revision 1.9
diff -u -r1.9 nautilus-directory-background.h
--- libnautilus-private/nautilus-directory-background.h 2001/09/15 19:17:45 1.9
+++ libnautilus-private/nautilus-directory-background.h 2002/02/09 23:29:35
@@ -33,6 +33,8 @@
NautilusFile *file);
void nautilus_connect_desktop_background_to_file_metadata (NautilusIconContainer *icon_container,
NautilusFile *file);
+void nautilus_desktop_set_background (NautilusIconContainer *icon_container,
+ NautilusFile *file);
void nautilus_connect_background_to_file_metadata_by_uri (GtkWidget *widget,
const char *uri);
gboolean nautilus_file_background_is_set (EelBackground *background);
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.240
diff -u -r1.240 fm-icon-view.c
--- src/file-manager/fm-icon-view.c 2002/02/05 19:22:53 1.240
+++ src/file-manager/fm-icon-view.c 2002/02/09 23:29:42
@@ -939,7 +939,7 @@
* of hardcoding desktop knowledge in here.
*/
if (FM_IS_DESKTOP_ICON_VIEW (view)) {
- nautilus_connect_desktop_background_to_file_metadata (NAUTILUS_ICON_CONTAINER (icon_container), file);
+ nautilus_desktop_set_background (NAUTILUS_ICON_CONTAINER (icon_container), file);
} else {
nautilus_connect_background_to_file_metadata (icon_container, file);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]