[nautilus] background: make NautilusDesktopBackground a singleton
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] background: make NautilusDesktopBackground a singleton
- Date: Sun, 10 Oct 2010 00:56:53 +0000 (UTC)
commit 843e6a9b9331a3e7a318df03b4074deb1163e386
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Oct 10 02:56:09 2010 +0200
background: make NautilusDesktopBackground a singleton
This avoids the need of using g_object_set_data() hacks to get the
background from the desktop icon container.
libnautilus-private/nautilus-desktop-background.c | 36 ++++++++++++++-------
libnautilus-private/nautilus-desktop-background.h | 4 +--
2 files changed, 25 insertions(+), 15 deletions(-)
---
diff --git a/libnautilus-private/nautilus-desktop-background.c b/libnautilus-private/nautilus-desktop-background.c
index b501cb3..d737f59 100644
--- a/libnautilus-private/nautilus-desktop-background.c
+++ b/libnautilus-private/nautilus-desktop-background.c
@@ -45,6 +45,8 @@ static void init_fade (NautilusDesktopBackground *self);
static void free_fade (NautilusDesktopBackground *self);
static void queue_background_change (NautilusDesktopBackground *self);
+static NautilusDesktopBackground *singleton = NULL;
+
G_DEFINE_TYPE (NautilusDesktopBackground, nautilus_desktop_background, G_TYPE_OBJECT);
enum {
@@ -481,11 +483,6 @@ nautilus_desktop_background_constructed (GObject *obj)
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",
@@ -519,6 +516,26 @@ nautilus_desktop_background_set_property (GObject *object,
}
}
+static GObject *
+nautilus_desktop_background_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ GObject *retval;
+
+ if (singleton != NULL) {
+ return g_object_ref (singleton);
+ }
+
+ retval = G_OBJECT_CLASS (nautilus_desktop_background_parent_class)->constructor
+ (type, n_construct_params, construct_params);
+
+ singleton = NAUTILUS_DESKTOP_BACKGROUND (retval);
+ g_object_add_weak_pointer (retval, (gpointer) &singleton);
+
+ return retval;
+}
+
static void
nautilus_desktop_background_class_init (NautilusDesktopBackgroundClass *klass)
{
@@ -528,6 +545,7 @@ nautilus_desktop_background_class_init (NautilusDesktopBackgroundClass *klass)
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = nautilus_desktop_background_finalize;
object_class->set_property = nautilus_desktop_background_set_property;
+ object_class->constructor = nautilus_desktop_background_constructor;
object_class->constructed = nautilus_desktop_background_constructed;
pspec = g_param_spec_object ("widget", "The widget for this background",
@@ -559,15 +577,9 @@ nautilus_desktop_background_init (NautilusDesktopBackground *self)
}
void
-nautilus_desktop_background_receive_dropped_background_image (NautilusIconContainer *container,
+nautilus_desktop_background_receive_dropped_background_image (NautilusDesktopBackground *self,
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,
diff --git a/libnautilus-private/nautilus-desktop-background.h b/libnautilus-private/nautilus-desktop-background.h
index 1ef2dc0..69fd35c 100644
--- a/libnautilus-private/nautilus-desktop-background.h
+++ b/libnautilus-private/nautilus-desktop-background.h
@@ -31,8 +31,6 @@
#include <gtk/gtk.h>
-#include "nautilus-icon-container.h"
-
typedef struct NautilusDesktopBackground NautilusDesktopBackground;
typedef struct NautilusDesktopBackgroundClass NautilusDesktopBackgroundClass;
@@ -51,7 +49,7 @@ typedef struct NautilusDesktopBackgroundClass 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,
+void nautilus_desktop_background_receive_dropped_background_image (NautilusDesktopBackground *self,
const gchar *image_uri);
typedef struct NautilusDesktopBackgroundDetails NautilusDesktopBackgroundDetails;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]