[Nautilus-list] Nautilus background patch



I fixed nautilus-directory-background to load and save the background
settings via libbackground. May I commit?

-- Richard

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.5021
diff -u -r1.5021 ChangeLog
--- ChangeLog	2002/02/22 21:30:13	1.5021
+++ ChangeLog	2002/02/23 05:05:43
@@ -1,3 +1,24 @@
+2002-02-22  Richard Hestilow  <hestilow ximian com>
+
+	* Makefile.am: add libbackground to SUBDIRS.
+
+	* configure.in: Check CAPPLET_CFLAGS (for libbackground),
+	and output libbackground/Makefile.
+
+	* libnautilus-private/Makefile.am (dependency_static_libs):
+	Link to libbackground.la.
+
+	* libnautilus-private/nautilus-directory-background.c:
+	Include libbackground/preferences.h.
+	(eel_gnome_config_string_match_no_case_with_default): Remove.
+	(nautilus_file_background_read_desktop_settings): Use BGPreferences.
+	(nautilus_file_background_write_desktop_settings): Use BGPreferences.
+	(nautilus_file_background_event_filter): Remove.
+	(desktop_background_gconf_notify_cb): Added.
+	(nautilus_file_background_receive_root_window_changes): Simply
+	use a gconf notify.
+	(desktop_background_destroyed_callback): Remove gconf notify.
+	
 2002-02-22  Gediminas Paulauskas <menesis delfi lt>
 
 	* configure.in: remove obsolete
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/nautilus/Makefile.am,v
retrieving revision 1.69
diff -u -r1.69 Makefile.am
--- Makefile.am	2002/01/19 00:05:38	1.69
+++ Makefile.am	2002/02/23 05:05:43
@@ -8,6 +8,7 @@
 SUBDIRS =			\
 	libnautilus 		\
 	cut-n-paste-code 	\
+	libbackground		\
 	libnautilus-private 	\
 	libnautilus-adapter	\
 	src 			\
Index: configure.in
===================================================================
RCS file: /cvs/gnome/nautilus/configure.in,v
retrieving revision 1.416
diff -u -r1.416 configure.in
--- configure.in	2002/02/22 21:30:17	1.416
+++ configure.in	2002/02/23 05:05:45
@@ -62,7 +62,6 @@
 	libgnomeui-2.0 >= $GNOME_UI_REQUIRED \
 	librsvg-2.0 >= $RSVG_REQUIRED \
 	libxml-2.0 >= $XML_REQUIRED)
-
 dnl ==========================================================================
 
 ALL_LINGUAS="az ca cs da de el en_GB es fi fr ga gl hu it ja ko lt lv nl nn no pl pt pt_BR ro ru sk sl sv ta tr uk zh_CN zh_TW"
@@ -303,6 +302,8 @@
 	-DBONOBO_DISABLE_DEPRECATED"
 AC_SUBST(DISABLE_DEPRECATED_CFLAGS)
 
+dnl libbackground
+PKG_CHECK_MODULES(CAPPLET, "gtk+-2.0 gconf-2.0 libgnomeui-2.0 libbonoboui-2.0")
 dnl ==========================================================================
 
 AC_OUTPUT([
@@ -362,6 +363,7 @@
 icons/sierra/Makefile
 icons/tahoe/Makefile
 icons/throbber/Makefile
+libbackground/Makefile
 libnautilus-adapter/Makefile
 libnautilus-private/Makefile
 libnautilus/Makefile
Index: libnautilus-private/Makefile.am
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/Makefile.am,v
retrieving revision 1.212
diff -u -r1.212 Makefile.am
--- libnautilus-private/Makefile.am	2002/02/22 18:54:14	1.212
+++ libnautilus-private/Makefile.am	2002/02/23 05:05:58
@@ -13,6 +13,7 @@
 
 dependency_static_libs = \
         $(top_builddir)/cut-n-paste-code/widgets/gimphwrapbox/libgtkhwrapbox.la \
+	$(top_builddir)/libbackground/libbackground.la \
         $(NULL)
 
 libnautilus_private_la_LDFLAGS =	\
Index: libnautilus-private/nautilus-directory-background.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-background.c,v
retrieving revision 1.70
diff -u -r1.70 nautilus-directory-background.c
--- libnautilus-private/nautilus-directory-background.c	2002/02/19 09:11:09	1.70
+++ libnautilus-private/nautilus-directory-background.c	2002/02/23 05:06:12
@@ -41,6 +41,7 @@
 #include <libgnome/gnome-config.h>
 #include <libgnome/gnome-util.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
+#include <libbackground/preferences.h>
 
 static void background_changed_callback     (EelBackground *background, 
                                              NautilusFile       *file);
@@ -206,23 +207,12 @@
 	g_free (theme_name);
 }
 
-static gboolean
-eel_gnome_config_string_match_no_case_with_default (const char *path, const char *test_value, gboolean *was_default)
-{
-	char *value;
-	gboolean result;
-	value = gnome_config_get_string_with_default (path, was_default);
-	result = !eel_strcasecmp (value, test_value);
-	g_free (value);
-	return result;
-}
-
 /* This enum is from gnome-source/control-center/capplets/background-properties/render-background.h */
 enum {
 	WALLPAPER_TILED,
 	WALLPAPER_CENTERED,
-	WALLPAPER_SCALED,
 	WALLPAPER_SCALED_KEEP,
+	WALLPAPER_SCALED,
 	WALLPAPER_EMBOSSED
 };
 
@@ -231,27 +221,24 @@
                                                 char **image,
                                                 EelBackgroundImagePlacement *placement)
 {
-	int	 image_alignment;
-	char*	 image_local_path;
+	int      image_alignment;
+	const char* image_local_path;
 	char*	 default_image_uri;
-	gboolean no_alignment_set;
-	gboolean no_image_set;
 	EelBackgroundImagePlacement default_placement;
 	
+	char    *cur_theme_name;
 	char	*end_color;
 	char	*start_color;
 	char	*default_color;
 	gboolean use_gradient;
 	gboolean is_horizontal;
-	gboolean no_start_color_set;
-	gboolean no_end_color_set;
-	gboolean no_gradient_set;
-	gboolean no_gradient_orientation_set;
+	gboolean switch_to_cur_theme_default;
 
 	char *theme_name;
-	char *cur_theme_name;
 	gboolean no_theme_name_set;
-	gboolean switch_to_cur_theme_default;
+	BGPreferences *prefs = BG_PREFERENCES (bg_preferences_new ());
+
+	bg_preferences_load (prefs);
 
 	theme_name = gnome_config_get_string_with_default ("/Background/Default/nautilus_theme", &no_theme_name_set);
 
@@ -263,9 +250,9 @@
 			(theme_name, desktop_theme_source, &default_color, &default_image_uri, &default_placement);
 	}
 
-	image_local_path = gnome_config_get_string_with_default ("/Background/Default/wallpaper", &no_image_set);
+	image_local_path = prefs->wallpaper_filename; 
 
-	if (no_image_set) {
+	if (!(prefs->wallpaper_filename && prefs->wallpaper_enabled)) {
 		*image = g_strdup (default_image_uri);
 	} else if (eel_strcasecmp (image_local_path, "none") != 0) {
 		*image = gnome_vfs_get_uri_from_local_path (image_local_path);
@@ -273,48 +260,36 @@
 		*image = NULL;
 	}
 	
-	g_free(image_local_path);
+	image_alignment  = prefs->wallpaper_type;
 
-	image_alignment  = gnome_config_get_int_with_default ("/Background/Default/wallpaperAlign", &no_alignment_set);
-
-	if (no_alignment_set) {
-		*placement = default_placement;
-	} else {
-		 switch (image_alignment) {
-		 	default:
-		 		g_assert_not_reached ();
-			case WALLPAPER_EMBOSSED:
-				/* FIXME bugzilla.gnome.org 42193: we don't support embossing.
-				 * Just treat it as centered - ugh.
-				 */
-			case WALLPAPER_CENTERED:
-				*placement = EEL_BACKGROUND_CENTERED;
-				break;
-			case WALLPAPER_TILED:
-				*placement = EEL_BACKGROUND_TILED;
-				break;
-			case WALLPAPER_SCALED:
-				*placement = EEL_BACKGROUND_SCALED;
-				break;
-			case WALLPAPER_SCALED_KEEP:
-				*placement = EEL_BACKGROUND_SCALED_ASPECT;
-				break;
-		 }
-	}
+	 switch (image_alignment) {
+	 	default:
+	 		g_assert_not_reached ();
+		case WALLPAPER_EMBOSSED:
+			/* FIXME bugzilla.gnome.org 42193: we don't support embossing.
+			 * Just treat it as centered - ugh.
+			 */
+		case WALLPAPER_CENTERED:
+			*placement = EEL_BACKGROUND_CENTERED;
+			break;
+		case WALLPAPER_TILED:
+			*placement = EEL_BACKGROUND_TILED;
+			break;
+		case WALLPAPER_SCALED:
+			*placement = EEL_BACKGROUND_SCALED;
+			break;
+		case WALLPAPER_SCALED_KEEP:
+			*placement = EEL_BACKGROUND_SCALED_ASPECT;
+			break;
+	 }
+	
+	end_color     = g_strdup_printf ("#%02x%02x%02x", prefs->color2->red >> 8, prefs->color2->green >> 8, prefs->color2->blue >> 8); 
+	start_color   = g_strdup_printf ("#%02x%02x%02x", prefs->color1->red >> 8, prefs->color1->green >> 8, prefs->color1->blue >> 8); 
+	use_gradient  = prefs->gradient_enabled;
+	is_horizontal = (prefs->wallpaper_enabled == ORIENTATION_HORIZ);
 
-	end_color     = gnome_config_get_string_with_default ("/Background/Default/color2", &no_end_color_set);
-	start_color   = gnome_config_get_string_with_default ("/Background/Default/color1", &no_start_color_set);
-	use_gradient  = !eel_gnome_config_string_match_no_case_with_default ("/Background/Default/simple", "solid", &no_gradient_set);
-	is_horizontal = !eel_gnome_config_string_match_no_case_with_default ("/Background/Default/gradient", "vertical", &no_gradient_orientation_set);
-
-	if (no_gradient_set || no_gradient_orientation_set || no_start_color_set) {
-		*color = g_strdup (default_color);
-	} else if (use_gradient) {
-		if (no_end_color_set) {
-			*color = g_strdup (default_color);
-		} else {
-			*color = eel_gradient_new (start_color, end_color , is_horizontal);
-		}
+	if (use_gradient) {
+		*color = eel_gradient_new (start_color, end_color , is_horizontal);
 	} else {
 		*color = g_strdup (start_color);
 	}
@@ -361,6 +336,8 @@
 	g_free (cur_theme_name);	
 	g_free(default_color);
 	g_free(default_image_uri);
+
+	g_object_unref (G_OBJECT (prefs));
 }
 
 static void
@@ -372,38 +349,43 @@
 	char *theme_name;
 
 	int wallpaper_align;
+	BGPreferences *prefs = BG_PREFERENCES (bg_preferences_new ());
 
-	int i;
-	int wallpaper_count;
-	char *wallpaper_path_i;
-	char *wallpaper_config_path_i;
-	gboolean found_wallpaper;
+	bg_preferences_load (prefs);
 
 	if (color != NULL) {
 		start_color = eel_gradient_get_start_color_spec (color);
-		gnome_config_set_string ("/Background/Default/color1", start_color);		
+		gdk_color_parse (start_color, prefs->color1);
 		g_free (start_color);
 
 		/* if color is not a gradient, this ends up writing same as start_color */
 		end_color = eel_gradient_get_end_color_spec (color);
-		gnome_config_set_string ("/Background/Default/color2", end_color);		
+		gdk_color_parse (end_color, prefs->color2);
 		g_free (end_color);
 
-		gnome_config_set_string ("/Background/Default/simple", eel_gradient_is_gradient (color) ? "gradient" : "solid");
-		gnome_config_set_string ("/Background/Default/gradient", eel_gradient_is_horizontal (color) ? "horizontal" : "vertical");
+		if (eel_gradient_is_gradient (color)) {
+			prefs->gradient_enabled = TRUE;
+			prefs->orientation = ORIENTATION_SOLID;
+		} else {
+			prefs->gradient_enabled = FALSE;
+			prefs->orientation = eel_gradient_is_horizontal (color) ? ORIENTATION_HORIZ : ORIENTATION_VERT;
+		}
 	} else {
 		/* We set it to white here because that's how backgrounds with a NULL color
 		 * are drawn by Nautilus - due to usage of eel_gdk_color_parse_with_white_default.
 		 */
-		gnome_config_set_string ("/Background/Default/color1", "#FFFFFF");		
-		gnome_config_set_string ("/Background/Default/color2", "#FFFFFF");		
-		gnome_config_set_string ("/Background/Default/simple", "solid");
-		gnome_config_set_string ("/Background/Default/gradient", "vertical");
+		gdk_color_parse ("#FFFFFF", prefs->color1);
+		gdk_color_parse ("#FFFFFF", prefs->color2);
+		prefs->gradient_enabled = FALSE;
+		prefs->orientation = ORIENTATION_SOLID;
 	}
 
+	g_free (prefs->wallpaper_filename);
 	if (image != NULL) {
 		image_local_path = gnome_vfs_get_local_path_from_uri (image);
 		gnome_config_set_string ("/Background/Default/wallpaper", image_local_path);
+		prefs->wallpaper_filename = g_strdup (image_local_path);
+
 		switch (placement) {
 			case EEL_BACKGROUND_TILED:
 				wallpaper_align = WALLPAPER_TILED;
@@ -422,33 +404,10 @@
 				wallpaper_align = WALLPAPER_TILED;
 				break;	
 		}
-		
-		gnome_config_set_int ("/Background/Default/wallpaperAlign", wallpaper_align);
-
-		wallpaper_count = gnome_config_get_int ("/Background/Default/wallpapers=0");
-		found_wallpaper = FALSE;
-		for (i = 1; i <= wallpaper_count && !found_wallpaper; ++i) {
-			wallpaper_config_path_i = g_strdup_printf ("/Background/Default/wallpaper%d", i);
-			wallpaper_path_i = gnome_config_get_string (wallpaper_config_path_i);
-			g_free (wallpaper_config_path_i);
-			if (eel_strcmp (wallpaper_path_i, image_local_path) == 0) {
-				found_wallpaper = TRUE;
-			}
-			
-			g_free (wallpaper_path_i);			
-		}
-
-		if (!found_wallpaper) {
-			gnome_config_set_int ("/Background/Default/wallpapers", wallpaper_count + 1);
-			gnome_config_set_string ("/Background/Default/wallpapers_dir", image_local_path);
-			wallpaper_config_path_i = g_strdup_printf ("/Background/Default/wallpaper%d", wallpaper_count + 1);
-			gnome_config_set_string (wallpaper_config_path_i, image_local_path);
-			g_free (wallpaper_config_path_i);
-		}
-		
-		g_free (image_local_path);		
+	
+		prefs->wallpaper_type = wallpaper_align;
 	} else {
-		gnome_config_set_string ("/Background/Default/wallpaper", "none");
+		prefs->wallpaper_filename = NULL;
 	}
 
 	theme_name = nautilus_theme_get_theme ();
@@ -456,6 +415,9 @@
 	g_free (theme_name);
 
 	gnome_config_sync ();
+
+	bg_preferences_save (prefs);
+	g_object_unref (G_OBJECT (prefs));
 }
 
 static void
@@ -486,64 +448,26 @@
  */
 static int set_root_pixmap_count = 0;
 
-static GdkFilterReturn
-nautilus_file_background_event_filter (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
+static void
+desktop_background_destroyed_callback (EelBackground *background, void *georgeWBush)
 {
-	XEvent *xevent;
-	EelBackground *background;
-
-	xevent = (XEvent *) gdk_xevent;
-
-	if (xevent->type == PropertyNotify && xevent->xproperty.atom == gdk_x11_get_xatom_by_name ("ESETROOT_PMAP_ID")) {
-
-		/* If we caused it, ignore it.
-		 */
-		if (set_root_pixmap_count > 0) {
-			--set_root_pixmap_count;
-			return GDK_FILTER_CONTINUE;
-		}
-		
-	    	background = EEL_BACKGROUND (data);
-	    	/* FIXME bugzilla.gnome.org 42220:
-	    	 * We'd like to call saved_settings_changed_callback right here, directly.
-	    	 * However, the current version of the property-background capplet saves
-	    	 * the new setting in gnome_config AFTER setting the root window's property -
-	    	 * i.e. after we get this event. How long afterwards is not knowable - we
-	    	 * guess half a second. Fixing this requires changing the capplet.
-	    	 */
-	    	gtk_timeout_add (500, (GtkFunction) (call_settings_changed), background);
-	}
-
-	return GDK_FILTER_CONTINUE;
+	guint cnxn_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (background), "desktop_gconf_cnxn"));
+	eel_gconf_notification_remove (cnxn_id);
 }
 
 static void
-desktop_background_destroyed_callback (EelBackground *background, void *georgeWBush)
+desktop_background_gconf_notify_cb (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
 {
-	gdk_window_remove_filter (
-                gdk_get_default_root_window (),
-                nautilus_file_background_event_filter, background);
+	call_settings_changed (EEL_BACKGROUND (data));
 }
 
 static void
 nautilus_file_background_receive_root_window_changes (EelBackground *background)
 {
-	XWindowAttributes attribs = { 0 };
+	guint cnxn_id = eel_gconf_notification_add ("/desktop/gnome/background", desktop_background_gconf_notify_cb, background);
 
-	/* set up a filter on the root window to get notified about property changes */
-	gdk_window_add_filter (
-                gdk_get_default_root_window (),
-                nautilus_file_background_event_filter, background);
-
-	gdk_error_trap_push ();
-
-	/* select events, we need to trap the kde status thingies anyway */
-	XGetWindowAttributes (GDK_DISPLAY (), GDK_ROOT_WINDOW (), &attribs);
-	XSelectInput (GDK_DISPLAY (), GDK_ROOT_WINDOW (), attribs.your_event_mask | PropertyChangeMask);
-	
-	gdk_flush ();
-	gdk_error_trap_pop ();
-
+	g_object_set_data (G_OBJECT (background), "desktop_gconf_cnxn", GUINT_TO_POINTER (cnxn_id));
+			
 	g_signal_connect (background,
  			    "destroy",
 			    G_CALLBACK (desktop_background_destroyed_callback),



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