[nautilus: 8/9] background: refactor code into NautilusDesktopBackground



commit 66cd22c908cc73954fad3e261d28ae6a05ea1bc2
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Oct 9 15:39:14 2010 +0200

    background: refactor code into NautilusDesktopBackground
    
    Remove the DirectoryBackground->EelBackground->GnomeBG abstraction and
    add a new object, NautilusDesktopBackground, which is a thin wrapper
    around GnomeBG, which takes care of handling background changes.

 eel/Makefile.am                                    |    2 -
 eel/eel-background.c                               |  717 --------------------
 eel/eel-background.h                               |  110 ---
 eel/eel-lib-self-check-functions.h                 |    1 -
 eel/eel.h                                          |    1 -
 libnautilus-private/Makefile.am                    |    4 +-
 libnautilus-private/nautilus-autorun.h             |    1 -
 libnautilus-private/nautilus-desktop-background.c  |  586 ++++++++++++++++
 libnautilus-private/nautilus-desktop-background.h  |   68 ++
 .../nautilus-directory-background.c                |  280 --------
 .../nautilus-directory-background.h                |   29 -
 libnautilus-private/nautilus-icon-dnd.c            |    7 +-
 src/file-manager/fm-desktop-icon-view.c            |   10 +-
 src/file-manager/fm-directory-view.c               |    1 -
 src/file-manager/fm-directory-view.h               |    1 -
 src/file-manager/fm-list-view.c                    |    1 -
 test/Makefile.am                                   |    3 -
 test/test.c                                        |   33 -
 18 files changed, 667 insertions(+), 1188 deletions(-)
---
diff --git a/eel/Makefile.am b/eel/Makefile.am
index 0bacfff..dd93f47 100644
--- a/eel/Makefile.am
+++ b/eel/Makefile.am
@@ -32,7 +32,6 @@ libeel_2_la_LIBADD = 				\
 eel_headers =					\
 	eel-accessibility.h			\
 	eel-art-extensions.h			\
-	eel-background.h			\
 	eel-canvas.h				\
 	eel-canvas-util.h			\
 	eel-canvas-rect-ellipse.h		\
@@ -55,7 +54,6 @@ eel_headers =					\
 libeel_2_la_SOURCES =				\
 	eel-accessibility.c			\
 	eel-art-extensions.c			\
-	eel-background.c			\
 	eel-canvas.c				\
 	eel-canvas-util.c			\
 	eel-canvas-rect-ellipse.c		\
diff --git a/eel/eel-lib-self-check-functions.h b/eel/eel-lib-self-check-functions.h
index d43bd76..2221a9f 100644
--- a/eel/eel-lib-self-check-functions.h
+++ b/eel/eel-lib-self-check-functions.h
@@ -39,7 +39,6 @@ void eel_run_lib_self_checks (void);
 */
 
 #define EEL_LIB_FOR_EACH_SELF_CHECK_FUNCTION(macro) \
-	macro (eel_self_check_background) \
 	macro (eel_self_check_gdk_extensions) \
 	macro (eel_self_check_glib_extensions) \
 	macro (eel_self_check_string) \
diff --git a/eel/eel.h b/eel/eel.h
index c0f2005..a5228f7 100644
--- a/eel/eel.h
+++ b/eel/eel.h
@@ -26,7 +26,6 @@
 #define EEL_H
 
 #include <eel/eel-art-extensions.h>
-#include <eel/eel-background.h>
 #include <eel/eel-gdk-extensions.h>
 #include <eel/eel-gdk-pixbuf-extensions.h>
 #include <eel/eel-glib-extensions.h>
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 3ef76f3..5a4556d 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -59,6 +59,8 @@ libnautilus_private_la_SOURCES = \
 	nautilus-debug-log.h \
 	nautilus-default-file-icon.c \
 	nautilus-default-file-icon.h \
+	nautilus-desktop-background.c \
+	nautilus-desktop-background.h \
 	nautilus-desktop-directory-file.c \
 	nautilus-desktop-directory-file.h \
 	nautilus-desktop-directory.c \
@@ -70,8 +72,6 @@ libnautilus_private_la_SOURCES = \
 	nautilus-desktop-link.c \
 	nautilus-desktop-link.h \
 	nautilus-directory-async.c \
-	nautilus-directory-background.c \
-	nautilus-directory-background.h \
 	nautilus-directory-notify.h \
 	nautilus-directory-private.h \
 	nautilus-directory.c \
diff --git a/libnautilus-private/nautilus-autorun.h b/libnautilus-private/nautilus-autorun.h
index 81d758e..cc995aa 100644
--- a/libnautilus-private/nautilus-autorun.h
+++ b/libnautilus-private/nautilus-autorun.h
@@ -41,7 +41,6 @@
 #define NAUTILUS_AUTORUN_H
 
 #include <gtk/gtk.h>
-#include <eel/eel-background.h>
 #include <libnautilus-private/nautilus-file.h>
 
 typedef void (*NautilusAutorunComboBoxChanged) (gboolean selected_ask,
diff --git a/libnautilus-private/nautilus-desktop-background.c b/libnautilus-private/nautilus-desktop-background.c
new file mode 100644
index 0000000..b501cb3
--- /dev/null
+++ b/libnautilus-private/nautilus-desktop-background.c
@@ -0,0 +1,586 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ * nautilus-desktop-background.c: Helper object to handle desktop background
+ *                                changes.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ * Copyright (C) 2010 Cosimo Cecchi <cosimoc gnome org>
+ *
+ * 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 of the
+ * License, 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.
+ *
+ * Authors: Darin Adler <darin bentspoon com>
+ *          Cosimo Cecchi <cosimoc gnome org>
+ */
+
+#include <config.h>
+
+#include "nautilus-desktop-background.h"
+
+#include <eel/eel-canvas.h>
+#include <eel/eel-gdk-extensions.h>
+#include <eel/eel-gtk-extensions.h>
+#include "nautilus-global-preferences.h"
+
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include <libgnomeui/gnome-bg.h>
+
+#include <gtk/gtk.h>
+#include <string.h>
+
+static void init_fade (NautilusDesktopBackground *self);
+static void free_fade (NautilusDesktopBackground *self);
+static void queue_background_change (NautilusDesktopBackground *self);
+
+G_DEFINE_TYPE (NautilusDesktopBackground, nautilus_desktop_background, G_TYPE_OBJECT);
+
+enum {
+        PROP_WIDGET = 1,
+        NUM_PROPERTIES,
+};
+
+struct NautilusDesktopBackgroundDetails {
+
+	GtkWidget *widget;
+        GnomeBG *bg;
+
+	/* Realized data: */
+	cairo_surface_t *background_surface;
+	GnomeBGCrossfade *fade;
+	int background_entire_width;
+	int background_entire_height;
+	GdkColor default_color;
+
+	/* Desktop screen size watcher */
+	gulong screen_size_handler;
+	/* Desktop monitors configuration watcher */
+	gulong screen_monitors_handler;
+	guint change_idle_id;
+
+        guint gconf_notify_id;
+        guint gconf_timeout_id;
+};
+
+static void
+free_fade (NautilusDesktopBackground *self)
+{
+	if (self->details->fade != NULL) {
+		g_object_unref (self->details->fade);
+		self->details->fade = NULL;
+	}
+}
+
+static void
+free_background_surface (NautilusDesktopBackground *self)
+{
+	cairo_surface_t *surface;
+
+	surface = self->details->background_surface;
+	if (surface != NULL) {
+		cairo_surface_destroy (surface);
+		self->details->background_surface = NULL;
+	}
+}
+
+static void
+nautilus_desktop_background_finalize (GObject *object)
+{
+	NautilusDesktopBackground *self;
+
+	self = NAUTILUS_DESKTOP_BACKGROUND (object);
+
+        gconf_client_notify_remove (nautilus_gconf_client,
+                                    self->details->gconf_notify_id);
+        if (self->details->gconf_timeout_id != 0) {
+                g_source_remove (self->details->gconf_timeout_id);
+                self->details->gconf_timeout_id = 0;
+        }
+
+	free_background_surface (self);
+	free_fade (self);
+
+	G_OBJECT_CLASS (nautilus_desktop_background_parent_class)->finalize (object);
+}
+
+static void
+nautilus_desktop_background_unrealize (NautilusDesktopBackground *self)
+{
+	free_background_surface (self);
+
+	self->details->background_entire_width = 0;
+	self->details->background_entire_height = 0;
+	self->details->default_color.red = 0xffff;
+	self->details->default_color.green = 0xffff;
+	self->details->default_color.blue = 0xffff;
+}
+
+static void
+nautilus_desktop_background_set_image_uri (NautilusDesktopBackground *self,
+                                           const char *image_uri)
+{
+	char *filename;
+
+	if (image_uri != NULL) {
+		filename = g_filename_from_uri (image_uri, NULL, NULL);
+	}
+	else {
+		filename = NULL;
+	}
+
+	gnome_bg_set_filename (self->details->bg, filename);
+
+	g_free (filename);
+}
+
+static void
+init_fade (NautilusDesktopBackground *self)
+{
+	GtkWidget *widget;
+
+	widget = self->details->widget;
+
+	if (widget == NULL || !gtk_widget_get_realized (widget))
+		return;
+
+	if (self->details->fade == NULL) {
+		GdkWindow *window;
+		GdkScreen *screen;
+		int old_width, old_height, width, height;
+
+		/* If this was the result of a screen size change,
+		 * we don't want to crossfade
+		 */
+		window = gtk_widget_get_window (widget);
+		old_width = gdk_window_get_width (window);
+		old_height = gdk_window_get_height (window);
+
+		screen = gtk_widget_get_screen (widget);
+		width = gdk_screen_get_width (screen);
+		height = gdk_screen_get_height (screen);
+
+		if (old_width == width && old_height == height) {
+			self->details->fade = gnome_bg_crossfade_new (width, height);
+			g_signal_connect_swapped (self->details->fade,
+                                                  "finished",
+                                                  G_CALLBACK (free_fade),
+                                                  self);
+		}
+	}
+
+	if (self->details->fade != NULL && !gnome_bg_crossfade_is_started (self->details->fade)) {
+		cairo_surface_t *start_surface;
+
+		if (self->details->background_surface == NULL) {
+			start_surface = gnome_bg_get_surface_from_root (gtk_widget_get_screen (widget));
+		} else {
+			start_surface = cairo_surface_reference (self->details->background_surface);
+		}
+		gnome_bg_crossfade_set_start_surface (self->details->fade,
+						      start_surface);
+                cairo_surface_destroy (start_surface);
+	}
+}
+
+static void
+screen_size_changed (GdkScreen *screen,
+                     NautilusDesktopBackground *self)
+{
+	queue_background_change (self);
+}
+
+static gboolean
+nautilus_desktop_background_ensure_realized (NautilusDesktopBackground *self)
+{
+	int entire_width;
+	int entire_height;
+	GdkScreen *screen;
+	GdkWindow *window;
+
+	screen = gtk_widget_get_screen (self->details->widget);
+	entire_height = gdk_screen_get_height (screen);
+	entire_width = gdk_screen_get_width (screen);
+
+	/* If the window size is the same as last time, don't update */
+	if (entire_width == self->details->background_entire_width &&
+	    entire_height == self->details->background_entire_height) {
+		return FALSE;
+	}
+
+	free_background_surface (self);
+
+	window = gtk_widget_get_window (self->details->widget);
+	self->details->background_surface = gnome_bg_create_surface (self->details->bg,
+                                                                     window,
+                                                                     entire_width, entire_height,
+                                                                     TRUE);
+
+	/* We got the surface and everything, so we don't care about a change
+	   that is pending (unless things actually change after this time) */
+	g_object_set_data (G_OBJECT (self),
+			   "ignore-pending-change", GINT_TO_POINTER (TRUE));
+
+	self->details->background_entire_width = entire_width;
+	self->details->background_entire_height = entire_height;
+
+	return TRUE;
+}
+
+static void
+on_fade_finished (GnomeBGCrossfade *fade,
+		  GdkWindow *window,
+		  gpointer user_data)
+{
+        NautilusDesktopBackground *self = user_data;
+
+	nautilus_desktop_background_ensure_realized (self);
+	gnome_bg_set_surface_as_root (gdk_window_get_screen (window),
+                                      self->details->background_surface);
+}
+
+static gboolean
+fade_to_surface (NautilusDesktopBackground *self,
+		 GdkWindow     *window,
+		 cairo_surface_t *surface)
+{
+	if (self->details->fade == NULL) {
+		return FALSE;
+	}
+
+	if (!gnome_bg_crossfade_set_end_surface (self->details->fade,
+				                 surface)) {
+		return FALSE;
+	}
+
+	if (!gnome_bg_crossfade_is_started (self->details->fade)) {
+		gnome_bg_crossfade_start (self->details->fade, window);
+		g_signal_connect (self->details->fade,
+				  "finished",
+				  G_CALLBACK (on_fade_finished), self);
+	}
+
+	return gnome_bg_crossfade_is_started (self->details->fade);
+}
+
+static void
+nautilus_desktop_background_set_up_widget (NautilusDesktopBackground *self)
+{
+	GtkStyle *style;
+	GdkWindow *window;
+	GdkWindow *widget_window;
+	gboolean in_fade = FALSE;
+        GtkWidget *widget;
+
+        widget = self->details->widget;
+
+	if (!gtk_widget_get_realized (widget)) {
+		return;
+	}
+
+	widget_window = gtk_widget_get_window (widget);
+	nautilus_desktop_background_ensure_realized (self);
+	style = gtk_widget_get_style (widget);
+
+	if (EEL_IS_CANVAS (widget)) {
+		window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
+	} else {
+		window = widget_window;
+	}
+
+	in_fade = fade_to_surface (self, window,
+				   self->details->background_surface);
+
+	if (!in_fade) {
+		cairo_pattern_t *pattern;
+
+		pattern = cairo_pattern_create_for_surface (self->details->background_surface);
+		gdk_window_set_background_pattern (window, pattern);
+		cairo_pattern_destroy (pattern);
+
+                gnome_bg_set_surface_as_root (gtk_widget_get_screen (widget),
+                                              self->details->background_surface);
+	}
+}
+
+static gboolean
+background_changed_cb (NautilusDesktopBackground *self)
+{
+	self->details->change_idle_id = 0;
+
+	nautilus_desktop_background_unrealize (self);
+	nautilus_desktop_background_set_up_widget (self);
+
+	gtk_widget_queue_draw (self->details->widget);
+
+	return FALSE;
+}
+
+static void
+queue_background_change (NautilusDesktopBackground *self)
+{
+	if (self->details->change_idle_id != 0) {
+                g_source_remove (self->details->change_idle_id);
+	}
+
+	self->details->change_idle_id =
+                g_idle_add ((GSourceFunc) background_changed_cb, self);
+}
+
+static void
+nautilus_desktop_background_changed (GnomeBG *bg,
+                                     gpointer user_data)
+{
+        NautilusDesktopBackground *self;
+
+        self = user_data;
+	init_fade (self);
+	queue_background_change (self);
+}
+
+static void
+nautilus_desktop_background_transitioned (GnomeBG *bg,
+                                          gpointer user_data)
+{
+        NautilusDesktopBackground *self;
+
+        self = user_data;
+	free_fade (self);
+	queue_background_change (self);
+}
+
+static void
+widget_realize_cb (GtkWidget *widget,
+                   gpointer user_data)
+{
+	GdkScreen *screen;
+        NautilusDesktopBackground *self = user_data;
+
+	screen = gtk_widget_get_screen (widget);
+
+	if (self->details->screen_size_handler > 0) {
+		g_signal_handler_disconnect (screen,
+					     self->details->screen_size_handler);
+	}
+	self->details->screen_size_handler = 
+		g_signal_connect (screen, "size_changed",
+				  G_CALLBACK (screen_size_changed), self);
+
+	if (self->details->screen_monitors_handler > 0) {
+		g_signal_handler_disconnect (screen,
+					     self->details->screen_monitors_handler);
+	}
+	self->details->screen_monitors_handler =
+		g_signal_connect (screen, "monitors-changed",
+				  G_CALLBACK (screen_size_changed), self);
+
+	init_fade (self);
+	nautilus_desktop_background_set_up_widget (self);
+}
+
+static void
+widget_unrealize_cb (GtkWidget *widget,
+                     gpointer user_data)
+{
+        NautilusDesktopBackground *self = user_data;
+
+	if (self->details->screen_size_handler > 0) {
+		        g_signal_handler_disconnect (gtk_widget_get_screen (GTK_WIDGET (widget)),
+				                     self->details->screen_size_handler);
+			self->details->screen_size_handler = 0;
+	}
+	if (self->details->screen_monitors_handler > 0) {
+		        g_signal_handler_disconnect (gtk_widget_get_screen (GTK_WIDGET (widget)),
+				                     self->details->screen_monitors_handler);
+			self->details->screen_monitors_handler = 0;
+	}
+}
+
+static void
+on_widget_destroyed (GtkWidget *widget,
+                     gpointer user_data)
+{
+        NautilusDesktopBackground *self = user_data;
+
+	if (self->details->change_idle_id != 0) {
+		g_source_remove (self->details->change_idle_id);
+		self->details->change_idle_id = 0;
+	}
+
+	self->details->widget = NULL;
+}
+
+static gboolean
+call_settings_changed (NautilusDesktopBackground *self)
+{
+        self->details->gconf_timeout_id = 0;
+        gnome_bg_load_from_preferences (self->details->bg, nautilus_gconf_client);
+
+	return FALSE;
+}
+
+static void
+desktop_background_gconf_notify_cb (GConfClient *client,
+                                    guint notification_id,
+                                    GConfEntry *entry,
+                                    gpointer user_data)
+{
+        NautilusDesktopBackground *self = user_data;
+        gboolean is_stamp;
+
+        is_stamp = (g_strcmp0 (entry->key, "/desktop/gnome/background/stamp") == 0);
+
+        if (is_stamp) {
+                if (self->details->gconf_timeout_id != 0) {
+                        g_source_remove (self->details->gconf_timeout_id);
+                        self->details->gconf_timeout_id = 0;
+                }
+
+                call_settings_changed (self);
+        } else if (self->details->gconf_timeout_id == 0) {
+                self->details->gconf_timeout_id =
+                        g_timeout_add (300,
+                                       (GSourceFunc) call_settings_changed, self);
+        }
+}
+
+static void
+nautilus_desktop_background_initialize_gconf (NautilusDesktopBackground *self)
+{
+        self->details->gconf_notify_id =
+                gconf_client_notify_add (nautilus_gconf_client,
+                                         "/desktop/gnome/background",
+                                         desktop_background_gconf_notify_cb,
+                                         self, NULL, NULL);
+}
+
+static void
+nautilus_desktop_background_constructed (GObject *obj)
+{
+        NautilusDesktopBackground *self;
+        GtkWidget *widget;
+
+        self = NAUTILUS_DESKTOP_BACKGROUND (obj);
+
+        if (G_OBJECT_CLASS (nautilus_desktop_background_parent_class)->constructed != NULL) {
+                G_OBJECT_CLASS (nautilus_desktop_background_parent_class)->constructed (obj);
+        }
+
+        widget = self->details->widget;
+
+        g_assert (widget != NULL);
+
+        /* FIXME: this is ugly, but it's the only way of handling background DnD on
+         * the desktop without refactoring half nautilus.
+         */
+        g_object_set_data (G_OBJECT (widget), "desktop-background", self);
+
+ 	g_signal_connect_object (widget, "destroy",
+                                 G_CALLBACK (on_widget_destroyed), self, 0);
+	g_signal_connect_object (widget, "realize",
+				 G_CALLBACK (widget_realize_cb), self, 0);
+	g_signal_connect_object (widget, "unrealize",
+				 G_CALLBACK (widget_unrealize_cb), self, 0);
+
+        gnome_bg_load_from_preferences (self->details->bg, nautilus_gconf_client);
+        nautilus_desktop_background_initialize_gconf (self);
+
+	queue_background_change (self);
+}
+
+static void
+nautilus_desktop_background_set_property (GObject *object,
+                                          guint property_id,
+                                          const GValue *value,
+                                          GParamSpec *pspec)
+{
+        NautilusDesktopBackground *self;
+
+        self = NAUTILUS_DESKTOP_BACKGROUND (object);
+
+        switch (property_id) {
+        case PROP_WIDGET:
+                self->details->widget = g_value_get_object (value);
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+static void
+nautilus_desktop_background_class_init (NautilusDesktopBackgroundClass *klass)
+{
+	GObjectClass *object_class;
+        GParamSpec *pspec;
+
+	object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = nautilus_desktop_background_finalize;
+        object_class->set_property = nautilus_desktop_background_set_property;
+        object_class->constructed = nautilus_desktop_background_constructed;
+
+        pspec = g_param_spec_object ("widget", "The widget for this background",
+                                     "The widget that gets its background set",
+                                     GTK_TYPE_WIDGET,
+                                     G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (object_class, PROP_WIDGET, pspec);
+
+	g_type_class_add_private (klass, sizeof (NautilusDesktopBackgroundDetails));
+}
+
+static void
+nautilus_desktop_background_init (NautilusDesktopBackground *self)
+{
+	self->details =
+		G_TYPE_INSTANCE_GET_PRIVATE (self,
+					     NAUTILUS_TYPE_DESKTOP_BACKGROUND,
+					     NautilusDesktopBackgroundDetails);
+
+        self->details->bg = gnome_bg_new ();
+	self->details->default_color.red = 0xffff;
+	self->details->default_color.green = 0xffff;
+	self->details->default_color.blue = 0xffff;
+
+	g_signal_connect (self->details->bg, "changed",
+			  G_CALLBACK (nautilus_desktop_background_changed), self);
+	g_signal_connect (self->details->bg, "transitioned",
+			  G_CALLBACK (nautilus_desktop_background_transitioned), self);
+}
+
+void
+nautilus_desktop_background_receive_dropped_background_image (NautilusIconContainer *container,
+                                                              const char *image_uri)
+{
+        NautilusDesktopBackground *self;
+
+        self = g_object_get_data (G_OBJECT (container), "desktop-background");
+
+        g_assert (self != NULL);
+
+	/* Currently, we only support tiled images. So we set the placement.
+	 */
+	gnome_bg_set_placement (self->details->bg,
+				GNOME_BG_PLACEMENT_TILED);
+	nautilus_desktop_background_set_image_uri (self, image_uri);
+
+	gnome_bg_save_to_preferences (self->details->bg, nautilus_gconf_client);
+}
+
+NautilusDesktopBackground *
+nautilus_desktop_background_new (GtkWidget *widget)
+{
+        return g_object_new (NAUTILUS_TYPE_DESKTOP_BACKGROUND,
+                             "widget", widget,
+                             NULL);
+}
diff --git a/libnautilus-private/nautilus-desktop-background.h b/libnautilus-private/nautilus-desktop-background.h
new file mode 100644
index 0000000..1ef2dc0
--- /dev/null
+++ b/libnautilus-private/nautilus-desktop-background.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/*
+ * nautilus-desktop-background.c: Helper object to handle desktop background
+ *                                changes.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ * Copyright (C) 2010 Cosimo Cecchi <cosimoc gnome org>
+ *
+ * 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 of the
+ * License, 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.
+ *
+ * Authors: Darin Adler <darin bentspoon com>
+ *          Cosimo Cecchi <cosimoc gnome org>
+ */
+
+#ifndef __NAUTILIUS_DESKTOP_BACKGROUND_H__
+#define __NAUTILIUS_DESKTOP_BACKGROUND_H__
+
+#include <gtk/gtk.h>
+
+#include "nautilus-icon-container.h"
+
+typedef struct NautilusDesktopBackground NautilusDesktopBackground;
+typedef struct NautilusDesktopBackgroundClass NautilusDesktopBackgroundClass;
+
+#define NAUTILUS_TYPE_DESKTOP_BACKGROUND nautilus_desktop_background_get_type()
+#define NAUTILUS_DESKTOP_BACKGROUND(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_DESKTOP_BACKGROUND, NautilusDesktopBackground))
+#define NAUTILUS_DESKTOP_BACKGROUND_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_DESKTOP_BACKGROUND, NautilusDesktopBackgroundClass))
+#define NAUTILUS_IS_DESKTOP_BACKGROUND(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_DESKTOP_BACKGROUND))
+#define NAUTILUS_IS_DESKTOP_BACKGROUND_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_DESKTOP_BACKGROUND))
+#define NAUTILUS_DESKTOP_BACKGROUND_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_DESKTOP_BACKGROUND, NautilusDesktopBackgroundClass))
+
+GType nautilus_desktop_background_get_type (void);
+NautilusDesktopBackground * nautilus_desktop_background_new (GtkWidget *widget);
+
+void nautilus_desktop_background_receive_dropped_background_image (NautilusIconContainer *container,
+								   const gchar *image_uri);
+
+typedef struct NautilusDesktopBackgroundDetails NautilusDesktopBackgroundDetails;
+
+struct NautilusDesktopBackground {
+	GObject parent;
+	NautilusDesktopBackgroundDetails *details;
+};
+
+struct NautilusDesktopBackgroundClass {
+	GObjectClass parent_class;
+};
+
+#endif /* __NAUTILIUS_DESKTOP_BACKGROUND_H__ */
diff --git a/libnautilus-private/nautilus-icon-dnd.c b/libnautilus-private/nautilus-icon-dnd.c
index 6a65f06..91bc195 100644
--- a/libnautilus-private/nautilus-icon-dnd.c
+++ b/libnautilus-private/nautilus-icon-dnd.c
@@ -40,7 +40,6 @@
 #include "nautilus-icon-private.h"
 #include "nautilus-link.h"
 #include "nautilus-metadata.h"
-#include <eel/eel-background.h>
 #include <eel/eel-gdk-pixbuf-extensions.h>
 #include <eel/eel-glib-extensions.h>
 #include <eel/eel-gnome-extensions.h>
@@ -55,6 +54,7 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 #include <eel/eel-canvas-rect-ellipse.h>
+#include <libnautilus-private/nautilus-desktop-background.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
 #include <libnautilus-private/nautilus-file-changes-queue.h>
 #include <stdio.h>
@@ -1068,9 +1068,8 @@ nautilus_icon_container_receive_dropped_icons (NautilusIconContainer *container,
 	
 	if (real_action == (GdkDragAction) NAUTILUS_DND_ACTION_SET_AS_BACKGROUND) {
 		selected_item = container->details->dnd_info->drag_info.selection_list->data;
-		eel_background_receive_dropped_background_image
-			(eel_get_widget_background (GTK_WIDGET (container)),
-			 selected_item->uri);
+		nautilus_desktop_background_receive_dropped_background_image (container,
+									      selected_item->uri);
 		return;
 	}
 		
diff --git a/src/file-manager/fm-desktop-icon-view.c b/src/file-manager/fm-desktop-icon-view.c
index b2cfb05..e486282 100644
--- a/src/file-manager/fm-desktop-icon-view.c
+++ b/src/file-manager/fm-desktop-icon-view.c
@@ -37,8 +37,8 @@
 #include <fcntl.h>
 #include <gdk/gdkx.h>
 #include <glib/gi18n.h>
+#include <libnautilus-private/nautilus-desktop-background.h>
 #include <libnautilus-private/nautilus-desktop-icon-file.h>
-#include <libnautilus-private/nautilus-directory-background.h>
 #include <libnautilus-private/nautilus-directory-notify.h>
 #include <libnautilus-private/nautilus-file-changes-queue.h>
 #include <libnautilus-private/nautilus-file-operations.h>
@@ -73,6 +73,8 @@ struct FMDesktopIconViewDetails
 	gulong delayed_init_signal;
 	guint reload_desktop_timeout;
 	gboolean pending_rescan;
+
+	NautilusDesktopBackground *background;
 };
 
 static void     default_zoom_level_changed                        (gpointer                user_data);
@@ -255,7 +257,9 @@ real_begin_loading (FMDirectoryView *object)
 	view = FM_DESKTOP_ICON_VIEW (object);
 
 	icon_container = get_icon_container (view);
-	nautilus_connect_desktop_background_to_file_metadata (icon_container);
+	if (view->details->background == NULL) {
+		view->details->background = nautilus_desktop_background_new (GTK_WIDGET (icon_container));
+	}
 
 	FM_DIRECTORY_VIEW_CLASS (fm_desktop_icon_view_parent_class)->begin_loading (object);
 }
@@ -296,6 +300,8 @@ fm_desktop_icon_view_dispose (GObject *object)
 					      fm_directory_view_update_menus,
 					      icon_view);
 
+	g_object_unref (icon_view->details->background);
+
 	G_OBJECT_CLASS (fm_desktop_icon_view_parent_class)->dispose (object);
 }
 
diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c
index 455afe2..6bab36f 100644
--- a/src/file-manager/fm-directory-view.c
+++ b/src/file-manager/fm-directory-view.c
@@ -59,7 +59,6 @@
 #include <libnautilus-private/nautilus-desktop-icon-file.h>
 #include <libnautilus-private/nautilus-desktop-directory.h>
 #include <libnautilus-private/nautilus-search-directory.h>
-#include <libnautilus-private/nautilus-directory-background.h>
 #include <libnautilus-private/nautilus-directory.h>
 #include <libnautilus-private/nautilus-dnd.h>
 #include <libnautilus-private/nautilus-file-attributes.h>
diff --git a/src/file-manager/fm-directory-view.h b/src/file-manager/fm-directory-view.h
index 6d12a26..07402a0 100644
--- a/src/file-manager/fm-directory-view.h
+++ b/src/file-manager/fm-directory-view.h
@@ -29,7 +29,6 @@
 #define FM_DIRECTORY_VIEW_H
 
 #include <gtk/gtk.h>
-#include <eel/eel-background.h>
 #include <libnautilus-private/nautilus-directory.h>
 #include <libnautilus-private/nautilus-file.h>
 #include <libnautilus-private/nautilus-icon-container.h>
diff --git a/src/file-manager/fm-list-view.c b/src/file-manager/fm-list-view.c
index 1000280..fc85c9b 100644
--- a/src/file-manager/fm-list-view.c
+++ b/src/file-manager/fm-list-view.c
@@ -47,7 +47,6 @@
 #include <libnautilus-private/nautilus-column-chooser.h>
 #include <libnautilus-private/nautilus-column-utilities.h>
 #include <libnautilus-private/nautilus-debug-log.h>
-#include <libnautilus-private/nautilus-directory-background.h>
 #include <libnautilus-private/nautilus-dnd.h>
 #include <libnautilus-private/nautilus-file-dnd.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
diff --git a/test/Makefile.am b/test/Makefile.am
index 50f9675..af4780c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -18,7 +18,6 @@ noinst_PROGRAMS =\
 	test-nautilus-search-engine \
 	test-nautilus-directory-async \
 	test-nautilus-copy \
-	test-eel-background \
 	test-eel-editable-label	\
 	$(NULL)
 
@@ -28,8 +27,6 @@ test_nautilus_search_engine_SOURCES = test-nautilus-search-engine.c
 
 test_nautilus_directory_async_SOURCES = test-nautilus-directory-async.c
 
-test_eel_background_SOURCES = test-eel-background.c
-
 EXTRA_DIST = \
 	test.h \
 	$(NULL)
diff --git a/test/test.c b/test/test.c
index 76fd44c..5481044 100644
--- a/test/test.c
+++ b/test/test.c
@@ -48,39 +48,6 @@ test_window_new (const char *title, guint border_width)
 	return window;
 }
 
-void
-test_gtk_widget_set_background_image (GtkWidget *widget,
-				      const char *image_name)
-{
-	EelBackground *background;
-	char *uri;
-
-	g_return_if_fail (GTK_IS_WIDGET (widget));
-	g_return_if_fail (image_name != NULL);
-
-	background = eel_get_widget_background (widget);
-	
-	uri = g_strdup_printf ("file://%s/%s", NAUTILUS_DATADIR, image_name);
-
-	eel_background_set_image_uri (background, uri);
-
-	g_free (uri);
-}
-
-void
-test_gtk_widget_set_background_color (GtkWidget *widget,
-				      const char *color_spec)
-{
-	EelBackground *background;
-
-	g_return_if_fail (GTK_IS_WIDGET (widget));
-	g_return_if_fail (color_spec != NULL);
-
-	background = eel_get_widget_background (widget);
-	
-	eel_background_set_color (background, color_spec);
-}
-
 GdkPixbuf *
 test_pixbuf_new_named (const char *name, float scale)
 {



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