gnome-control-center r8393 - in trunk: . capplets/appearance gnome-settings-daemon libbackground



Author: ssp
Date: Tue Jan 15 01:47:41 2008
New Revision: 8393
URL: http://svn.gnome.org/viewvc/gnome-control-center?rev=8393&view=rev

Log:
Index: gnome-settings-daemon/ChangeLog
===================================================================
--- gnome-settings-daemon/ChangeLog     (revision 8392)
+++ gnome-settings-daemon/ChangeLog     (working copy)
@@ -1,3 +1,9 @@
+2008-01-14  Soren Sandmann  <sandmann daimi au dk>
+
+       * gnome-settings-background.c: Use GnomeBG from gnome-desktop
+
+
+
 2008-01-14  Denis Washington  <denisw svn gnome org>
 
        * gnome-settings-mouse.c:

===================================================================
--- libbackground/ChangeLog     (revision 8336)
+++ libbackground/ChangeLog     (working copy)
@@ -1,3 +1,9 @@
+2008-01-14  Soren Sandmann <sandmann daimi au dk>
+
+       * applier.[ch]: Delete these files
+
+       * Makefile.am: Remove them here.
+
 2007-04-16  Jens Granseuer  <jensgr gmx net>
 
        Patch by: Erich Schubert <erich debian org>


Index: capplets/appearance/ChangeLog
===================================================================
--- capplets/appearance/ChangeLog       (revision 8392)
+++ capplets/appearance/ChangeLog       (working copy)
@@ -1,3 +1,13 @@
+2008-01-14  Soren Sandmann  <sandmann redhat com>
+
+       * appearance-desktop.c: Update list model when the background
+       changes. 
+       * gnome-wp-item.c: Create a GnomeBG for the item.
+       * gnome-wp-item.h: Add a GnomeBG field - Remove
+       gnome_wp_item_dup() function.
+       * gnome-wp-info.c: Delete gnome_wp_item_dup() function.
+       * gnome-wp-xml.c: Ensure that a GnomeBG exists.
+
 2007-12-22  Thomas Wood  <thos gnome org>
 
        * theme-installer.c: (transfer_done_tgz_tbz),



Added:
   trunk/libbackground/
   trunk/libbackground/ChangeLog
   trunk/libbackground/Makefile.am
   trunk/libbackground/preferences.c
   trunk/libbackground/preferences.h
Modified:
   trunk/capplets/appearance/ChangeLog
   trunk/capplets/appearance/appearance-desktop.c
   trunk/capplets/appearance/gnome-wp-info.c
   trunk/capplets/appearance/gnome-wp-info.h
   trunk/capplets/appearance/gnome-wp-item.c
   trunk/capplets/appearance/gnome-wp-item.h
   trunk/capplets/appearance/gnome-wp-xml.c
   trunk/configure.in
   trunk/gnome-settings-daemon/ChangeLog
   trunk/gnome-settings-daemon/gnome-settings-background.c

Modified: trunk/capplets/appearance/appearance-desktop.c
==============================================================================
--- trunk/capplets/appearance/appearance-desktop.c	(original)
+++ trunk/capplets/appearance/appearance-desktop.c	Tue Jan 15 01:47:41 2008
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <gconf/gconf-client.h>
 #include <libgnomeui/gnome-thumbnail.h>
+#include <libgnomeui/gnome-bg.h>
 
 typedef enum {
   GNOME_WP_SHADE_TYPE_SOLID,
@@ -112,6 +113,43 @@
   return item;
 }
 
+static gboolean predicate (gpointer key, gpointer value, gpointer data)
+{
+  GnomeBG *bg = data;
+  GnomeWPItem *item = value;
+
+  return item->bg == bg;
+}
+
+static void on_item_changed (GnomeBG *bg, AppearanceData *data) {
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GtkTreePath *path;
+  GnomeWPItem *item;
+
+  item = g_hash_table_find (data->wp_hash, predicate, bg);
+
+  if (!item)
+    return;
+  
+  model = gtk_tree_row_reference_get_model (item->rowref);
+  path = gtk_tree_row_reference_get_path (item->rowref);
+
+  if (gtk_tree_model_get_iter (model, &iter, path)) {
+    g_signal_handlers_block_by_func (bg, G_CALLBACK (on_item_changed), data);
+      
+    GdkPixbuf *pixbuf = gnome_wp_item_get_thumbnail (item, data->thumb_factory);
+    if (pixbuf) {
+      gtk_list_store_set (GTK_LIST_STORE (data->wp_model), &iter,
+                          0, pixbuf,
+                         -1);
+      g_object_unref (pixbuf);
+    }
+
+    g_signal_handlers_unblock_by_func (bg, G_CALLBACK (on_item_changed), data);
+  }
+}
+
 static void
 wp_props_load_wallpaper (gchar *key,
                          GnomeWPItem *item,
@@ -140,6 +178,7 @@
 
   path = gtk_tree_model_get_path (data->wp_model, &iter);
   item->rowref = gtk_tree_row_reference_new (data->wp_model, path);
+  g_signal_connect (item->bg, "changed", G_CALLBACK (on_item_changed), data);
   gtk_tree_path_free (path);
 }
 

Modified: trunk/capplets/appearance/gnome-wp-info.c
==============================================================================
--- trunk/capplets/appearance/gnome-wp-info.c	(original)
+++ trunk/capplets/appearance/gnome-wp-info.c	Tue Jan 15 01:47:41 2008
@@ -67,27 +67,6 @@
   return new;
 }
 
-GnomeWPInfo * gnome_wp_info_dup (const GnomeWPInfo * info) {
-  GnomeWPInfo * new;
-
-  if (info == NULL) {
-    return NULL;
-  }
-
-  new = g_new0 (GnomeWPInfo, 1);
-
-  new->uri = g_strdup (info->uri);
-  new->thumburi = g_strdup (info->uri);
-
-  new->name = g_strdup (info->name);
-  new->mime_type = g_strdup (info->mime_type);
-
-  new->size = info->size;
-  new->mtime = info->mtime;
-
-  return new;
-}
-
 void gnome_wp_info_free (GnomeWPInfo * info) {
   if (info == NULL) {
     return;

Modified: trunk/capplets/appearance/gnome-wp-info.h
==============================================================================
--- trunk/capplets/appearance/gnome-wp-info.h	(original)
+++ trunk/capplets/appearance/gnome-wp-info.h	Tue Jan 15 01:47:41 2008
@@ -40,7 +40,6 @@
 
 GnomeWPInfo * gnome_wp_info_new (const gchar * uri,
 				 GnomeThumbnailFactory * thumbs);
-GnomeWPInfo * gnome_wp_info_dup (const GnomeWPInfo * info);
 void gnome_wp_info_free (GnomeWPInfo * info);
 
 #endif

Modified: trunk/capplets/appearance/gnome-wp-item.c
==============================================================================
--- trunk/capplets/appearance/gnome-wp-item.c	(original)
+++ trunk/capplets/appearance/gnome-wp-item.c	Tue Jan 15 01:47:41 2008
@@ -25,10 +25,56 @@
 #include <gnome.h>
 #include <string.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
+#include <libgnomeui/gnome-bg.h>
 
 #include "gnome-wp-item.h"
 #include "gnome-wp-utils.h"
 
+static void set_bg_properties (GnomeWPItem *item)
+{
+  GnomeBGColorType color;
+  GnomeBGPlacement placement;
+
+  color = GNOME_BG_COLOR_SOLID;
+  
+  if (item->shade_type) {
+    if (!strcmp (item->shade_type, "horizontal-gradient")) {
+      color = GNOME_BG_COLOR_H_GRADIENT;
+    } else if (!strcmp (item->shade_type, "vertical-gradient")) {
+      color = GNOME_BG_COLOR_V_GRADIENT;
+    }
+  }
+
+  placement = GNOME_BG_PLACEMENT_TILED;
+  
+  if (item->options) {
+    if (!strcmp (item->options, "centered")) {
+      placement = GNOME_BG_PLACEMENT_CENTERED;
+    } else if (!strcmp (item->options, "stretched")) {
+      placement = GNOME_BG_PLACEMENT_FILL_SCREEN;
+    } else if (!strcmp (item->options, "scaled")) {
+      placement = GNOME_BG_PLACEMENT_SCALED;
+    } else if (!strcmp (item->options, "zoom")) {
+      placement = GNOME_BG_PLACEMENT_ZOOMED;
+    }
+  }
+
+  if (item->filename)
+    gnome_bg_set_uri (item->bg, item->filename);
+
+  gnome_bg_set_color (item->bg, color, item->pcolor, item->scolor);
+  gnome_bg_set_placement (item->bg, placement);
+}
+
+void gnome_wp_item_ensure_gnome_bg (GnomeWPItem *item)
+{
+  if (!item->bg) {
+    item->bg = gnome_bg_new ();
+
+    set_bg_properties (item);
+  }
+}
+
 GnomeWPItem * gnome_wp_item_new (const gchar * filename,
 				 GHashTable * wallpapers,
 				 GnomeThumbnailFactory * thumbnails) {
@@ -46,7 +92,8 @@
   item->fileinfo = gnome_wp_info_new (item->filename, thumbnails);
 
   if (item->fileinfo != NULL &&
-      g_str_has_prefix (item->fileinfo->mime_type, "image/")) {
+      (g_str_has_prefix (item->fileinfo->mime_type, "image/") ||
+       strcmp (item->fileinfo->mime_type, "application/xml") == 0)) {
     if (item->name == NULL) {
       if (g_utf8_validate (item->fileinfo->name, -1, NULL))
 	item->name = g_strdup (item->fileinfo->name);
@@ -88,6 +135,10 @@
     item = NULL;
   }
 
+  if (item) {
+    gnome_wp_item_ensure_gnome_bg (item);
+  }
+  
   g_object_unref (client);
 
   return item;
@@ -111,43 +162,14 @@
     gdk_color_free (item->scolor);
 
   gnome_wp_info_free (item->fileinfo);
-  gnome_wp_info_free (item->uriinfo);
+  if (item->bg)
+    g_object_unref (item->bg);
 
   gtk_tree_row_reference_free (item->rowref);
 
   g_free (item);
 }
 
-GnomeWPItem * gnome_wp_item_dup (GnomeWPItem * item) {
-  GnomeWPItem * new_item;
-
-  if (item == NULL) {
-    return NULL;
-  }
-
-  new_item = g_new0 (GnomeWPItem, 1);
-
-  new_item->name = g_strdup (item->name);
-  new_item->filename = g_strdup (item->filename);
-  new_item->description = g_strdup (item->description);
-  new_item->options = g_strdup (item->options);
-  new_item->shade_type = g_strdup (item->shade_type);
-
-  new_item->pcolor = gdk_color_copy (item->pcolor);
-  new_item->scolor = gdk_color_copy (item->scolor);
-
-  new_item->fileinfo = gnome_wp_info_dup (item->fileinfo);
-  new_item->uriinfo = gnome_wp_info_dup (item->uriinfo);
-
-  new_item->rowref = gtk_tree_row_reference_copy (item->rowref);
-
-  new_item->deleted = item->deleted;
-  new_item->width = item->width;
-  new_item->height = item->height;
-
-  return new_item;
-}
-
 static void collect_save_options (GdkPixbuf * pixbuf,
 				  gchar *** keys,
 				  gchar *** vals,
@@ -201,153 +223,18 @@
 
 GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item,
 					 GnomeThumbnailFactory * thumbs) {
-  GdkPixbuf * pixbuf, * bgpixbuf;
-  GdkPixbuf * scaled = NULL;
-  gint sw, sh, bw, bh, pw, ph, tw, th;
-  gdouble ratio;
-
-  sw = sh = bw = bh = pw = ph = tw = th = 0;
-
-  /*
-     Get the size of the screen and calculate our aspect ratio divisor
-     We do this, so that images are thumbnailed as they would look on
-     the screen in reality
-  */
-  sw = gdk_screen_get_width (gdk_screen_get_default ());
-  sh = gdk_screen_get_height (gdk_screen_get_default ());
-  ratio = (gdouble) sw / (gdouble) LIST_IMAGE_WIDTH;
-  bw = sw / ratio;
-  bh = sh / ratio;
-
-  /*
-     Create the pixbuf for the background colors, which will show up for
-     oddly sized images, smaller images that are centered, or alpha images
-  */
-  if (!strcmp (item->shade_type, "solid")) {
-    bgpixbuf = gnome_wp_pixbuf_new_solid (item->pcolor, bw, bh);
-  } else if (!strcmp (item->shade_type, "vertical-gradient")) {
-    bgpixbuf = gnome_wp_pixbuf_new_gradient (GTK_ORIENTATION_VERTICAL,
-					     item->pcolor, item->scolor,
-					     bw, bh);
-  } else {
-    bgpixbuf = gnome_wp_pixbuf_new_gradient (GTK_ORIENTATION_HORIZONTAL,
-					     item->pcolor, item->scolor,
-					     bw, bh);
-  }
-
-  /*
-     Load up the thumbnail image using the thumbnail spec
-     If the image doesn't exist, we create it
-     If we are creating the thumbnail for "No Wallpaper", then we just copy
-     the background colors pixbuf we created above, here
-  */
-  pixbuf = NULL;
-  if (!strcmp (item->filename, "(none)")) {
-    return bgpixbuf;
-  } else {
-    gchar * escaped_path, * thumbnail_filename;
-
-    escaped_path = gnome_vfs_escape_path_string (item->filename);
-    thumbnail_filename = gnome_thumbnail_factory_lookup (thumbs,
-                                                         escaped_path,
-                                                         item->fileinfo->mtime);
-
-    if (thumbnail_filename == NULL) {
-    pixbuf = gnome_thumbnail_factory_generate_thumbnail (thumbs,
-							 escaped_path,
-							 item->fileinfo->mime_type);
-    gnome_thumbnail_factory_save_thumbnail (thumbs, pixbuf,
-					    escaped_path,
-					    item->fileinfo->mtime);
-       g_object_unref (pixbuf);
-       pixbuf = NULL;
-
-       thumbnail_filename = gnome_thumbnail_factory_lookup (thumbs,
-                                                            escaped_path,
-                                                            item->fileinfo->mtime);
-    }
-
-    if (thumbnail_filename != NULL) {
-
-      pixbuf = gdk_pixbuf_new_from_file (thumbnail_filename, NULL);
-
-      if (pixbuf != NULL) {
-      	g_free (item->fileinfo->thumburi);
-        item->fileinfo->thumburi = thumbnail_filename;
-        thumbnail_filename = NULL;
-      }
-
-      g_free (thumbnail_filename);
-    }
-
-    g_free (escaped_path);
-  }
-
-  if (pixbuf != NULL) {
-    const gchar * w_val, * h_val;
-
-    w_val = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::Image::Width");
-    h_val = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::Image::Height");
-    if (item->width <= 0 || item->height <= 0) {
-      if (w_val && h_val) {
-	item->width = atoi (w_val);
-	item->height = atoi (h_val);
-      } else {
-	gchar ** keys = NULL;
-	gchar ** vals = NULL;
-
-        gdk_pixbuf_get_file_info (item->filename,
-                                  &item->width, &item->height);
-	collect_save_options (pixbuf, &keys, &vals, item->width, item->height);
-	gdk_pixbuf_savev (pixbuf, item->fileinfo->thumburi, "png",
-			  keys, vals, NULL);
-
-	g_strfreev (keys);
-	g_strfreev (vals);
-      }
-    }
-
-    pw = gdk_pixbuf_get_width (pixbuf);
-    ph = gdk_pixbuf_get_height (pixbuf);
-
-    if (item->width <= bw && item->height <= bh)
-      ratio = 1.0;
-
-    tw = item->width / ratio;
-    th = item->height / ratio;
-
-    if (!strcmp (item->options, "wallpaper")) {
-      scaled = gnome_wp_pixbuf_tile (pixbuf, bgpixbuf, tw, th);
-    } else if (!strcmp (item->options, "centered")) {
-      scaled = gnome_wp_pixbuf_center (pixbuf, bgpixbuf, tw, th);
-    } else if (!strcmp (item->options, "stretched")) {
-      scaled = gnome_wp_pixbuf_center (pixbuf, bgpixbuf, bw, bh);
-    } else if (!strcmp (item->options, "scaled")) {
-      if ((gdouble) ph * (gdouble) bw > (gdouble) pw * (gdouble) bh) {
-	tw = 0.5 + (gdouble) pw * (gdouble) bh / (gdouble) ph;
-	th = bh;
-      } else {
-	th = 0.5 + (gdouble) ph * (gdouble) bw / (gdouble) pw;
-	tw = bw;
-      }
-      scaled = gnome_wp_pixbuf_center (pixbuf, bgpixbuf, tw, th);
-    } else if (!strcmp (item->options, "zoom")) {
-      if ((gdouble) ph * (gdouble) bw < (gdouble) pw * (gdouble) bh) {
-	tw = 0.5 + (gdouble) pw * (gdouble) bh / (gdouble) ph;
-	th = bh;
-      } else {
-	th = 0.5 + (gdouble) ph * (gdouble) bw / (gdouble) pw;
-	tw = bw;
-      }
-      scaled = gnome_wp_pixbuf_center (pixbuf, bgpixbuf, tw, th);
-    }
-
-    g_object_unref (pixbuf);
-  }
-
-  g_object_unref (bgpixbuf);
-
-  return scaled;
+  GdkPixbuf *pixbuf;
+  double aspect =
+    (double)gdk_screen_get_height (gdk_screen_get_default()) / 
+    gdk_screen_get_width (gdk_screen_get_default());
+
+  set_bg_properties (item);
+  
+  pixbuf = gnome_bg_create_thumbnail (item->bg, thumbs, gdk_screen_get_default(), LIST_IMAGE_WIDTH, LIST_IMAGE_WIDTH * aspect);
+
+  gnome_bg_get_image_size (item->bg, thumbs, &item->width, &item->height);
+  
+  return pixbuf;
 }
 
 void gnome_wp_item_update_description (GnomeWPItem * item) {
@@ -356,6 +243,12 @@
   if (!strcmp (item->filename, "(none)")) {
     item->description = g_strdup (item->name);
   } else {
+    gchar *description;
+
+    if (strcmp (item->fileinfo->mime_type, "application/xml") == 0)
+      description = _("Slide Show");
+    else
+      description = gnome_vfs_mime_get_description (item->fileinfo->mime_type);
     gchar *dirname = g_path_get_dirname (item->filename);
     /* translators: <b>wallpaper name</b>
      * mime type, x pixel(s) by y pixel(s)
@@ -365,7 +258,7 @@
                                    "%s, %d %s by %d %s\n"
                                    "Folder: %s"),
                                  item->name,
-                                 gnome_vfs_mime_get_description (item->fileinfo->mime_type),
+                                 description,
                                  item->width,
                                  ngettext ("pixel", "pixels", item->width),
                                  item->height,

Modified: trunk/capplets/appearance/gnome-wp-item.h
==============================================================================
--- trunk/capplets/appearance/gnome-wp-item.h	(original)
+++ trunk/capplets/appearance/gnome-wp-item.h	Tue Jan 15 01:47:41 2008
@@ -24,6 +24,7 @@
 #include <libgnomeui/gnome-thumbnail.h>
 #include <gnome-wp-info.h>
 #include <libgnomevfs/gnome-vfs.h>
+#include <libgnomeui/gnome-bg.h>
 
 #ifndef _GNOME_WP_ITEM_H_
 #define _GNOME_WP_ITEM_H_
@@ -31,6 +32,8 @@
 typedef struct _GnomeWPItem GnomeWPItem;
 
 struct _GnomeWPItem {
+  GnomeBG *bg;
+    
   gchar * name;
   gchar * filename;
   gchar * description;
@@ -45,7 +48,6 @@
   GdkColor * scolor;
 
   GnomeWPInfo * fileinfo;
-  GnomeWPInfo * uriinfo;
 
   /* Did the user remove us? */
   gboolean deleted;
@@ -59,10 +61,10 @@
 				 GHashTable * wallpapers,
 				 GnomeThumbnailFactory * thumbnails);
 void gnome_wp_item_free (GnomeWPItem * item);
-GnomeWPItem * gnome_wp_item_dup (GnomeWPItem * item);
 GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item,
 					 GnomeThumbnailFactory * thumbs);
 void gnome_wp_item_update_description (GnomeWPItem * item);
+void gnome_wp_item_ensure_gnome_bg (GnomeWPItem *item);
 
 #endif
 

Modified: trunk/capplets/appearance/gnome-wp-xml.c
==============================================================================
--- trunk/capplets/appearance/gnome-wp-xml.c	(original)
+++ trunk/capplets/appearance/gnome-wp-xml.c	Tue Jan 15 01:47:41 2008
@@ -231,7 +231,11 @@
 	g_hash_table_insert (data->wp_hash, wp->filename, wp);
       } else {
 	gnome_wp_item_free (wp);
+        wp = NULL;
       }
+
+      if (wp)
+        gnome_wp_item_ensure_gnome_bg (wp);
     }
   }
   xmlFreeDoc (wplist);

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Tue Jan 15 01:47:41 2008
@@ -95,7 +95,7 @@
  libglade-2.0 >= 2.0.0 dnl
  libbonobo-2.0 dnl
  libbonoboui-2.0 dnl
- gnome-desktop-2.0 >= 2.2.0"
+ gnome-desktop-2.0 >= 2.21.4"
 PKG_CHECK_MODULES(LIBSLAB, $COMMON_MODULES gnome-desktop-2.0 librsvg-2.0 libgnome-menu pango eel-2.0)
 PKG_CHECK_MODULES(CAPPLET, $COMMON_MODULES)
 PKG_CHECK_MODULES(GNOMECC, $COMMON_MODULES libgnome-menu >= 2.10.1 libpanelapplet-2.0)
@@ -518,10 +518,10 @@
 capplets/sound/gnome-settings-sound.desktop.in
 capplets/windows/Makefile
 capplets/windows/window-properties.desktop.in
-#gnome-settings-daemon/Makefile
-#gnome-settings-daemon/actions/Makefile
-#gnome-settings-daemon/gnome-settings-daemon.pc
-#gnome-settings-daemon/xrdb/Makefile
+gnome-settings-daemon/Makefile
+gnome-settings-daemon/actions/Makefile
+gnome-settings-daemon/gnome-settings-daemon.pc
+gnome-settings-daemon/xrdb/Makefile
 help/Makefile
 libbackground/Makefile
 libslab/Makefile

Modified: trunk/gnome-settings-daemon/gnome-settings-background.c
==============================================================================
--- trunk/gnome-settings-daemon/gnome-settings-background.c	(original)
+++ trunk/gnome-settings-daemon/gnome-settings-background.c	Tue Jan 15 01:47:41 2008
@@ -30,11 +30,13 @@
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #include <gconf/gconf.h>
+#include <libgnomeui/gnome-bg.h>
+#include <X11/Xatom.h>
+#include <string.h>
 
 #include "gnome-settings-module.h"
 
 #include "preferences.h"
-#include "applier.h"
 
 typedef struct _GnomeSettingsModuleBackground      GnomeSettingsModuleBackground;
 typedef struct _GnomeSettingsModuleBackgroundClass GnomeSettingsModuleBackgroundClass;
@@ -42,11 +44,13 @@
 struct _GnomeSettingsModuleBackground {
 	GnomeSettingsModule parent;
 
-	BGApplier **bg_appliers;
 	BGPreferences *prefs;
-	guint applier_idle_id;
+        GnomeBG *bg;
+        guint timeout_id;
 };
 
+static gboolean nautilus_is_running (void);
+
 struct _GnomeSettingsModuleBackgroundClass {
 	GnomeSettingsModuleClass parent_class;
 };
@@ -59,20 +63,104 @@
 static gboolean gnome_settings_module_background_start (GnomeSettingsModule *module);
 
 static gboolean
-applier_idle (gpointer data)
+apply_prefs (gpointer data)
 {
 	GnomeSettingsModuleBackground *module;
-	int i;
 
 	module = (GnomeSettingsModuleBackground *) data;
 
-	for (i = 0; module->bg_appliers [i]; i++)
-		bg_applier_apply_prefs (module->bg_appliers [i], module->prefs);
-	module->applier_idle_id = 0;
+        if (!nautilus_is_running()) {
+                GdkDisplay *display;
+                int n_screens, i;
+                GnomeBGPlacement placement;
+                GnomeBGColorType color;
+                const char *uri;
+ 
+                display = gdk_display_get_default ();
+                n_screens = gdk_display_get_n_screens (display);
+ 
+                uri = module->prefs->wallpaper_filename;
+ 
+                placement = GNOME_BG_PLACEMENT_TILED;
+ 
+                switch (module->prefs->wallpaper_type) {
+                case WPTYPE_TILED:
+                        placement = GNOME_BG_PLACEMENT_TILED;
+                        break;
+                case WPTYPE_CENTERED:
+                        placement = GNOME_BG_PLACEMENT_CENTERED;
+                        break;
+                case WPTYPE_SCALED:
+                        placement = GNOME_BG_PLACEMENT_SCALED;
+                        break;
+                case WPTYPE_STRETCHED:
+                        placement = GNOME_BG_PLACEMENT_FILL_SCREEN;
+                        break;
+                case WPTYPE_ZOOM:
+                        placement = GNOME_BG_PLACEMENT_ZOOMED;
+                        break;
+                case WPTYPE_NONE:
+                case WPTYPE_UNSET:
+                        uri = NULL;
+                        break;
+                }
+ 
+                switch (module->prefs->orientation) {
+                case ORIENTATION_SOLID:
+                        color = GNOME_BG_COLOR_SOLID;
+                        break;
+                case ORIENTATION_HORIZ:
+                        color = GNOME_BG_COLOR_H_GRADIENT;
+                        break;
+                case ORIENTATION_VERT:
+                        color = GNOME_BG_COLOR_V_GRADIENT;
+                        break;
+                default:
+                        color = GNOME_BG_COLOR_SOLID;
+                        break;
+                }
+ 
+                gnome_bg_set_uri (module->bg, uri);
+                gnome_bg_set_placement (module->bg, placement);
+                gnome_bg_set_color (module->bg, color, module->prefs->color1, module->prefs->color2);
+ 
+                for (i = 0; i < n_screens; ++i) {
+                        GdkScreen *screen;
+                        GdkWindow *root_window;
+                        GdkPixmap *pixmap;
+ 
+                        screen = gdk_display_get_screen (display, i);
+ 
+                        root_window = gdk_screen_get_root_window (screen);
+ 
+                        pixmap = gnome_bg_create_pixmap (module->bg, root_window,
+                                                         gdk_screen_get_width (screen),
+                                                         gdk_screen_get_height (screen),
+                                                         TRUE);
+
+                        gnome_bg_set_pixmap_as_root (screen, pixmap);
+
+                        g_object_unref (pixmap);
+                }
+        }
+
 	return FALSE;
 }
 
 static void
+queue_apply (gpointer data)
+{
+	GnomeSettingsModuleBackground *module;
+
+	module = (GnomeSettingsModuleBackground *) data;
+	if (module->timeout_id) {
+		g_source_remove (module->timeout_id);
+	}
+
+	module->timeout_id = g_timeout_add (100, apply_prefs, data);
+}
+
+static void
 background_callback (GConfClient *client,
                      guint cnxn_id,
                      GConfEntry *entry,
@@ -84,13 +172,17 @@
 
 	bg_preferences_merge_entry (module_bg->prefs, entry);
 
-	if (module_bg->applier_idle_id != 0) {
-		g_source_remove (module_bg->applier_idle_id);
-	}
+	queue_apply (user_data);
+}
 
-	module_bg->applier_idle_id = g_timeout_add (100, applier_idle, module_bg);
+static void
+on_bg_changed (GnomeBG *bg,
+               gpointer user_data)
+{
+	queue_apply (user_data);
 }
 
+
 static void
 gnome_settings_module_background_class_init (GnomeSettingsModuleBackgroundClass *klass)
 {
@@ -105,7 +197,7 @@
 static void
 gnome_settings_module_background_init (GnomeSettingsModuleBackground *module)
 {
-	module->applier_idle_id = 0;
+	module->timeout_id = 0;
 }
 
 GType
@@ -145,28 +237,17 @@
 					     GConfClient *config_client)
 {
 	GnomeSettingsModuleBackground *module_bg;
-	GdkDisplay *display;
-	int         n_screens;
-	int         i;
 
 	module_bg = (GnomeSettingsModuleBackground *) module;
-	display = gdk_display_get_default ();
-	n_screens = gdk_display_get_n_screens (display);
-
-	module_bg->bg_appliers = g_new (BGApplier *, n_screens + 1);
-
-	for (i = 0; i < n_screens; i++) {
-		GdkScreen *screen;
-
-		screen = gdk_display_get_screen (display, i);
-
-		module_bg->bg_appliers [i] = BG_APPLIER (bg_applier_new_for_screen (BG_APPLIER_ROOT, screen));
-	}
-	module_bg->bg_appliers [i] = NULL;
 
 	module_bg->prefs = BG_PREFERENCES (bg_preferences_new ());
+	module_bg->bg = gnome_bg_new ();
+
+        g_signal_connect (module_bg->bg, "changed", G_CALLBACK (on_bg_changed), module_bg);
 	bg_preferences_load (module_bg->prefs);
 
+        apply_prefs (module_bg);
+
 	gconf_client_notify_add (config_client,
 	                         "/desktop/gnome/background",
 	                         background_callback,
@@ -181,7 +262,6 @@
 gnome_settings_module_background_start (GnomeSettingsModule *module)
 {
 	GnomeSettingsModuleBackground *module_bg;
-	int i;
 
 	module_bg = (GnomeSettingsModuleBackground *) module;
 
@@ -197,8 +277,72 @@
 				   "/apps/nautilus/preferences/show_desktop", NULL))
 		return TRUE;
 
-	for (i = 0; module_bg->bg_appliers [i]; i++)
-		bg_applier_apply_prefs (module_bg->bg_appliers [i], module_bg->prefs);
+	apply_prefs (module_bg);
 
 	return TRUE;
 }
+
+static gboolean
+nautilus_is_running (void)
+{
+	Atom window_id_atom;
+	Window nautilus_xid;
+	Atom actual_type;
+	int actual_format;
+	unsigned long nitems, bytes_after;
+	unsigned char *data;
+	int retval;
+	Atom wmclass_atom;
+	gboolean running;
+	gint error;
+
+	window_id_atom = XInternAtom (GDK_DISPLAY (),
+				      "NAUTILUS_DESKTOP_WINDOW_ID", True);
+
+	if (window_id_atom == None) return FALSE;
+
+	retval = XGetWindowProperty (GDK_DISPLAY (), GDK_ROOT_WINDOW (),
+				     window_id_atom, 0, 1, False, XA_WINDOW,
+				     &actual_type, &actual_format, &nitems,
+				     &bytes_after, &data);
+
+	if (data != NULL) {
+		nautilus_xid = *(Window *) data;
+		XFree (data);
+	} else {
+		return FALSE;
+	}
+
+	if (actual_type != XA_WINDOW) return FALSE;
+	if (actual_format != 32) return FALSE;
+
+	wmclass_atom = XInternAtom (GDK_DISPLAY (), "WM_CLASS", False);
+
+	gdk_error_trap_push ();
+
+	retval = XGetWindowProperty (GDK_DISPLAY (), nautilus_xid,
+				     wmclass_atom, 0, 24, False, XA_STRING,
+				     &actual_type, &actual_format, &nitems,
+				     &bytes_after, &data);
+
+	error = gdk_error_trap_pop ();
+
+	if (error == BadWindow) return FALSE;
+
+	if (actual_type == XA_STRING &&
+	    nitems == 24 &&
+	    bytes_after == 0 &&
+	    actual_format == 8 &&
+	    data != NULL &&
+	    !strcmp ((char *)data, "desktop_window") &&
+	    !strcmp ((char *)data + strlen ((char *)data) + 1, "Nautilus"))
+		running = TRUE;
+	else
+		running = FALSE;
+
+	if (data != NULL)
+		XFree (data);
+
+	return running;
+}
+

Added: trunk/libbackground/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/libbackground/Makefile.am	Tue Jan 15 01:47:41 2008
@@ -0,0 +1,12 @@
+EXTRA_DIST = ChangeLog
+
+INCLUDES = \
+	-DG_LOG_DOMAIN=\"capplet-common\"				\
+	-DGNOMELOCALEDIR="\"$(datadir)/locale\""			\
+	-I$(top_srcdir)/						\
+	@CAPPLET_CFLAGS@
+
+noinst_LTLIBRARIES = libbackground.la
+
+libbackground_la_SOURCES = \
+	preferences.c	preferences.h

Added: trunk/libbackground/preferences.c
==============================================================================
--- (empty file)
+++ trunk/libbackground/preferences.c	Tue Jan 15 01:47:41 2008
@@ -0,0 +1,510 @@
+/* -*- mode: c; style: linux -*- */
+
+/* preferences.c
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Written by Bradford Hovinen <hovinen ximian com>
+ *
+ * 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, 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gdk/gdk.h>
+
+#include "preferences.h"
+
+static GObjectClass *parent_class;
+
+static void      bg_preferences_init       (BGPreferences      *prefs,
+					    BGPreferencesClass *class);
+static void      bg_preferences_class_init (BGPreferencesClass *class);
+
+static void      bg_preferences_finalize   (GObject            *object);
+
+static GdkColor *read_color_from_string    (const gchar        *string);
+static orientation_t read_orientation_from_string  (const gchar *string);
+static wallpaper_type_t read_wptype_from_string (const gchar *string);
+
+static GEnumValue _bg_wptype_values[] = {
+	{ WPTYPE_TILED, "WPTYPE_TILED", "wallpaper"},
+	{ WPTYPE_CENTERED, "WPTYPE_CENTERED", "centered"},
+	{ WPTYPE_SCALED, "WPTYPE_SCALED", "scaled"},
+	{ WPTYPE_STRETCHED, "WPTYPE_STRETCHED", "stretched"},
+	{ WPTYPE_ZOOM, "WPTYPE_ZOOM", "zoom"},
+	{ WPTYPE_NONE, "WPTYPE_NONE", "none"},
+	{ 0, NULL, NULL }
+};
+
+static GEnumValue _bg_orientation_values[] = {
+	{ ORIENTATION_SOLID, "ORIENTATION_SOLID", "solid"},
+	{ ORIENTATION_HORIZ, "ORIENTATION_HORIZ", "horizontal-gradient"},
+	{ ORIENTATION_VERT, "ORIENTATION_VERT", "vertical-gradient"},
+	{ 0, NULL, NULL }
+};
+
+GType
+bg_preferences_wptype_get_type (void)
+{
+	static GType type = 0;
+
+	if (!type)
+	{
+		type = g_enum_register_static ("BgPreferencesWptype",
+					       _bg_wptype_values);
+	}
+
+	return type;
+}
+
+GType
+bg_preferences_orientation_get_type (void)
+{
+	static GType type = 0;
+
+	if (!type)
+	{
+		type = g_enum_register_static ("BgPreferencesOrientation",
+					       _bg_orientation_values);
+	}
+
+	return type;
+}
+
+GType
+bg_preferences_get_type (void)
+{
+	static GType bg_preferences_type = 0;
+
+	if (!bg_preferences_type) {
+		GTypeInfo bg_preferences_info = {
+			sizeof (BGPreferencesClass),
+			NULL,
+			NULL,
+			(GClassInitFunc) bg_preferences_class_init,
+			NULL,
+			NULL,
+			sizeof (BGPreferences),
+			0,
+			(GInstanceInitFunc) bg_preferences_init,
+		};
+
+		bg_preferences_type = 
+			g_type_register_static (G_TYPE_OBJECT, "BGPreferences", &bg_preferences_info, 0);
+	}
+
+	return bg_preferences_type;
+}
+
+static void
+bg_preferences_init (BGPreferences      *prefs,
+		     BGPreferencesClass *class)
+{
+	prefs->frozen             = FALSE;
+
+	/* Load default values */
+	prefs->color1             = read_color_from_string ("#39374b");
+	prefs->color2             = read_color_from_string ("#42528f");
+	prefs->enabled            = TRUE;
+	prefs->wallpaper_enabled  = FALSE;
+	prefs->gradient_enabled   = TRUE;
+	prefs->orientation        = ORIENTATION_VERT;
+	prefs->wallpaper_type     = WPTYPE_TILED;
+	prefs->wallpaper_filename = NULL;
+	prefs->wallpaper_sel_path = g_strdup (g_get_home_dir ());
+	prefs->auto_apply         = TRUE;
+	prefs->wallpapers         = NULL;
+	prefs->adjust_opacity     = TRUE;
+	prefs->opacity            = 255;
+}
+
+static void
+bg_preferences_class_init (BGPreferencesClass *class) 
+{
+	GObjectClass *object_class;
+
+	object_class = (GObjectClass *) class;
+	object_class->finalize = bg_preferences_finalize;
+
+	parent_class = 
+		G_OBJECT_CLASS (g_type_class_ref (G_TYPE_OBJECT));
+}
+
+GObject *
+bg_preferences_new (void) 
+{
+	GObject *object;
+
+	object = g_object_new (bg_preferences_get_type (), NULL);
+	BG_PREFERENCES (object)->enabled = TRUE;
+
+	return object;
+}
+
+GObject *
+bg_preferences_clone (const BGPreferences *prefs)
+{
+	GObject *object;
+	BGPreferences *new_prefs;
+
+	g_return_val_if_fail (prefs != NULL, NULL);
+	g_return_val_if_fail (IS_BG_PREFERENCES (prefs), NULL);
+
+	object = bg_preferences_new ();
+
+	new_prefs = BG_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;
+
+	if (new_prefs->color1 != NULL)
+		gdk_color_free (new_prefs->color1);
+	new_prefs->color1 = (prefs->color1 != NULL)
+		? gdk_color_copy (prefs->color1) : NULL;
+
+	if (new_prefs->color2 != NULL)
+		gdk_color_free (new_prefs->color2);
+	new_prefs->color2 = (prefs->color2 != NULL)
+		? gdk_color_copy (prefs->color2) : NULL;
+
+	if (new_prefs->wallpaper_filename != NULL)
+		g_free (new_prefs->wallpaper_filename);
+	new_prefs->wallpaper_filename = g_strdup (prefs->wallpaper_filename);
+
+	if (new_prefs->wallpaper_sel_path != NULL)
+		g_free (new_prefs->wallpaper_sel_path);
+	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;
+
+	return object;
+}
+
+static void
+bg_preferences_finalize (GObject *object) 
+{
+	BGPreferences *prefs;
+
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (IS_BG_PREFERENCES (object));
+
+	prefs = BG_PREFERENCES (object);
+
+	g_free (prefs->wallpaper_filename);
+	prefs->wallpaper_filename = NULL;
+
+	g_free (prefs->wallpaper_sel_path);
+	prefs->wallpaper_sel_path = NULL;
+
+	if (prefs->color1 != NULL) {
+		gdk_color_free (prefs->color1);
+		prefs->color1 = NULL;
+	}
+	if (prefs->color2 != NULL) {
+		gdk_color_free (prefs->color2);
+		prefs->color2 = NULL;
+	}
+	
+	parent_class->finalize (object);
+}
+
+void
+bg_preferences_load (BGPreferences *prefs)
+{
+	GConfClient *client;
+	GError      *error = NULL;
+	char *tmp;
+
+	g_return_if_fail (prefs != NULL);
+	g_return_if_fail (IS_BG_PREFERENCES (prefs));
+
+	client = gconf_client_get_default ();
+
+	prefs->enabled = gconf_client_get_bool (client, BG_PREFERENCES_DRAW_BACKGROUND, &error);
+	tmp = gconf_client_get_string (client, BG_PREFERENCES_PICTURE_FILENAME, &error);
+	if (tmp) {
+		if (g_utf8_validate (tmp, -1, NULL) &&
+		    g_file_test (tmp, G_FILE_TEST_EXISTS))
+			prefs->wallpaper_filename = g_strdup (tmp);
+		else
+			prefs->wallpaper_filename = g_filename_from_utf8 (tmp, -1, NULL,
+									  NULL, NULL);
+	}
+	g_free (tmp);
+
+	if (prefs->color1 != NULL)
+		gdk_color_free (prefs->color1);
+	tmp = gconf_client_get_string (client, BG_PREFERENCES_PRIMARY_COLOR, &error);
+	prefs->color1 = read_color_from_string (tmp);
+	g_free (tmp);
+
+	if (prefs->color2 != NULL)
+		gdk_color_free (prefs->color2);
+	tmp = gconf_client_get_string (client, BG_PREFERENCES_SECONDARY_COLOR, &error);
+	prefs->color2 = read_color_from_string (tmp);
+	g_free (tmp);
+	
+	prefs->opacity = gconf_client_get_int (client, BG_PREFERENCES_PICTURE_OPACITY, &error);
+	if (prefs->opacity >= 100 || prefs->opacity < 0)
+		prefs->adjust_opacity = FALSE;
+
+	tmp = gconf_client_get_string (client, BG_PREFERENCES_COLOR_SHADING_TYPE, &error);
+	prefs->orientation = read_orientation_from_string (tmp);
+	g_free (tmp);
+
+	if (prefs->orientation == ORIENTATION_SOLID)
+		prefs->gradient_enabled = FALSE;
+	else
+		prefs->gradient_enabled = TRUE;
+
+	tmp = gconf_client_get_string (client, BG_PREFERENCES_PICTURE_OPTIONS, &error);
+	prefs->wallpaper_type = read_wptype_from_string (tmp);
+	g_free (tmp);
+
+	if (prefs->wallpaper_type == WPTYPE_UNSET) {
+	  prefs->wallpaper_enabled = FALSE;
+	  prefs->wallpaper_type = WPTYPE_CENTERED;
+	} else {
+	  prefs->wallpaper_enabled = TRUE;
+	}
+
+	g_object_unref (client);
+}
+
+/* Parse the event name given (the event being notification of a property having
+ * changed and apply that change to the bg_preferences structure. Eliminates the
+ * need to reload the structure entirely on every event notification
+ */
+
+void
+bg_preferences_merge_entry (BGPreferences    *prefs,
+			    const GConfEntry *entry)
+{
+	const GConfValue *value = gconf_entry_get_value (entry);
+
+	g_return_if_fail (prefs != NULL);
+	g_return_if_fail (IS_BG_PREFERENCES (prefs));
+
+	if (!strcmp (entry->key, BG_PREFERENCES_PICTURE_OPTIONS)) {
+  	        wallpaper_type_t wallpaper_type = read_wptype_from_string (gconf_value_get_string (value));
+		if (wallpaper_type == WPTYPE_UNSET) {
+		  prefs->wallpaper_enabled = FALSE;
+		} else {
+		  prefs->wallpaper_type = wallpaper_type;
+		  prefs->wallpaper_enabled = TRUE;
+		}
+	}
+	else if (!strcmp (entry->key, BG_PREFERENCES_PICTURE_FILENAME)) {
+	        const char *tmp;
+
+		tmp = gconf_value_get_string (value);
+		if (g_utf8_validate (tmp, -1, NULL) &&
+		    g_file_test (tmp, G_FILE_TEST_EXISTS))
+		  prefs->wallpaper_filename = g_strdup (tmp);
+		else
+		  prefs->wallpaper_filename = g_filename_from_utf8 (tmp, -1,
+								    NULL,
+								    NULL,
+								    NULL);
+
+		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 (entry->key, BG_PREFERENCES_PRIMARY_COLOR)) {
+		if (prefs->color1 != NULL)
+			gdk_color_free (prefs->color1);
+		prefs->color1 = read_color_from_string (gconf_value_get_string (value));
+	}
+	else if (!strcmp (entry->key, BG_PREFERENCES_SECONDARY_COLOR)) {
+		if (prefs->color2 != NULL)
+			gdk_color_free (prefs->color2);
+		prefs->color2 = read_color_from_string (gconf_value_get_string (value));
+	}
+	else if (!strcmp (entry->key, BG_PREFERENCES_PICTURE_OPACITY)) {
+		prefs->opacity = gconf_value_get_int (value);
+
+		if (prefs->opacity >= 100)
+			prefs->adjust_opacity = FALSE;
+	}
+	else if (!strcmp (entry->key, BG_PREFERENCES_COLOR_SHADING_TYPE)) {
+		prefs->orientation = read_orientation_from_string (gconf_value_get_string (value));
+
+		if (prefs->orientation == ORIENTATION_SOLID)
+			prefs->gradient_enabled = FALSE;
+		else
+			prefs->gradient_enabled = TRUE;
+	}
+	else if (!strcmp (entry->key, BG_PREFERENCES_DRAW_BACKGROUND)) {
+		if (gconf_value_get_bool (value) &&
+				(prefs->wallpaper_filename != NULL) &&
+		    strcmp (prefs->wallpaper_filename, "") != 0 &&
+		    strcmp (prefs->wallpaper_filename, "(none)") != 0)
+			prefs->enabled = TRUE;
+		else
+			prefs->enabled = FALSE;
+	} else {
+		g_warning ("%s: Unknown property: %s", G_GNUC_FUNCTION, entry->key);
+	}
+}
+
+static wallpaper_type_t
+read_wptype_from_string (const gchar *string)
+{
+        wallpaper_type_t type = WPTYPE_UNSET;
+      
+	if (string) {
+		if (!strncmp (string, "wallpaper", sizeof ("wallpaper"))) {
+			type =  WPTYPE_TILED;
+		} else if (!strncmp (string, "centered", sizeof ("centered"))) {
+			type =  WPTYPE_CENTERED;
+		} else if (!strncmp (string, "scaled", sizeof ("scaled"))) {
+			type =  WPTYPE_SCALED;
+		} else if (!strncmp (string, "stretched", sizeof ("stretched"))) {
+			type =  WPTYPE_STRETCHED;
+		} else if (!strncmp (string, "zoom", sizeof ("zoom"))) {
+			type =  WPTYPE_ZOOM;
+		}
+	}
+
+	return type;
+}
+
+static orientation_t
+read_orientation_from_string (const gchar *string)
+{
+        orientation_t type = ORIENTATION_SOLID;
+
+	if (string) {
+		if (!strncmp (string, "vertical-gradient", sizeof ("vertical-gradient"))) {
+			type = ORIENTATION_VERT;
+		} else if (!strncmp (string, "horizontal-gradient", sizeof ("horizontal-gradient"))) {
+			type = ORIENTATION_HORIZ;
+		}
+	}
+	   
+	return type;
+}
+
+static GdkColor *
+read_color_from_string (const gchar *string) 
+{
+	GdkColor color;
+
+	/* If all else fails use black */
+	if (string == NULL || !gdk_color_parse (string, &color))
+		gdk_color_parse ("black", &color);
+	gdk_rgb_find_color (gdk_rgb_get_colormap (), &color);
+	return gdk_color_copy (&color);
+}
+
+const gchar*
+bg_preferences_get_wptype_as_string (wallpaper_type_t wp)
+{
+	switch (wp)
+	{
+		case WPTYPE_TILED:
+			return "wallpaper";
+		case WPTYPE_CENTERED:
+			return "centered";
+		case WPTYPE_SCALED:
+			return "scaled";
+		case WPTYPE_STRETCHED:
+			return "stretched";
+		case WPTYPE_ZOOM:
+			return "zoom";
+		case WPTYPE_NONE:
+			return "none";
+	        case WPTYPE_UNSET:
+		        return NULL;
+	}
+
+	return NULL;
+}
+
+const gchar*
+bg_preferences_get_orientation_as_string (orientation_t o)
+{
+	switch (o)
+	{
+		case ORIENTATION_SOLID:
+			return "solid";
+		case ORIENTATION_HORIZ:
+			return "horizontal-gradient";
+		case ORIENTATION_VERT:
+			return "vertical-gradient";
+	}
+
+	return NULL;
+}
+
+void
+bg_preferences_save (BGPreferences *prefs)
+{
+	GConfChangeSet *cs;
+	gchar *tmp;
+	GConfClient *client;
+	
+	g_return_if_fail (prefs != NULL);
+	g_return_if_fail (IS_BG_PREFERENCES (prefs));
+
+	client = gconf_client_get_default();
+	
+	cs = gconf_change_set_new ();
+	gconf_change_set_set_bool (cs, BG_PREFERENCES_DRAW_BACKGROUND, prefs->enabled);
+	if (prefs->wallpaper_enabled)
+		gconf_change_set_set_string (cs, BG_PREFERENCES_PICTURE_OPTIONS, bg_preferences_get_wptype_as_string (prefs->wallpaper_type));
+	else
+		gconf_change_set_set_string (cs, BG_PREFERENCES_PICTURE_OPTIONS, "none");
+
+	gconf_change_set_set_string (cs, BG_PREFERENCES_PICTURE_FILENAME, prefs->wallpaper_filename);
+	
+	tmp = g_strdup_printf ("#%02x%02x%02x",
+		prefs->color1->red >> 8,
+		prefs->color1->green >> 8,
+		prefs->color1->blue >> 8);
+	gconf_change_set_set_string (cs, BG_PREFERENCES_PRIMARY_COLOR, tmp);
+	g_free (tmp);
+	
+	tmp = g_strdup_printf ("#%02x%02x%02x",
+		prefs->color2->red >> 8,
+		prefs->color2->green >> 8,
+		prefs->color2->blue >> 8);
+	gconf_change_set_set_string (cs, BG_PREFERENCES_SECONDARY_COLOR, tmp);
+	g_free (tmp);
+
+	gconf_change_set_set_string (cs, BG_PREFERENCES_COLOR_SHADING_TYPE, bg_preferences_get_orientation_as_string (prefs->orientation));
+
+	gconf_client_commit_change_set (client, cs, TRUE, NULL);
+	gconf_change_set_unref (cs);
+	g_object_unref (client);
+}
+
+

Added: trunk/libbackground/preferences.h
==============================================================================
--- (empty file)
+++ trunk/libbackground/preferences.h	Tue Jan 15 01:47:41 2008
@@ -0,0 +1,108 @@
+/* -*- mode: c; style: linux -*- */
+
+/* preferences.h
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Written by Bradford Hovinen <hovinen helixcode com>
+ *
+ * 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, 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.
+ */
+
+#ifndef __BGPREFERENCES_H
+#define __BGPREFERENCES_H
+
+#include <glib-object.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gconf/gconf-client.h>
+
+#define BG_PREFERENCES(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, bg_preferences_get_type (), BGPreferences)
+#define BG_PREFERENCES_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, bg_preferences_get_type (), BGPreferencesClass)
+#define IS_BG_PREFERENCES(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, bg_preferences_get_type ())
+
+#define BG_PREFERENCES_DRAW_BACKGROUND    "/desktop/gnome/background/draw_background"
+#define BG_PREFERENCES_PRIMARY_COLOR      "/desktop/gnome/background/primary_color"
+#define BG_PREFERENCES_SECONDARY_COLOR    "/desktop/gnome/background/secondary_color"
+#define BG_PREFERENCES_COLOR_SHADING_TYPE "/desktop/gnome/background/color_shading_type"
+#define BG_PREFERENCES_PICTURE_OPTIONS    "/desktop/gnome/background/picture_options"
+#define BG_PREFERENCES_PICTURE_OPACITY    "/desktop/gnome/background/picture_opacity"
+#define BG_PREFERENCES_PICTURE_FILENAME   "/desktop/gnome/background/picture_filename"
+
+
+typedef struct _BGPreferences BGPreferences;
+typedef struct _BGPreferencesClass BGPreferencesClass;
+
+typedef enum _orientation_t {
+	ORIENTATION_SOLID = 0, 
+	ORIENTATION_HORIZ, 
+	ORIENTATION_VERT
+} orientation_t;
+
+typedef enum _wallpaper_type_t {
+	WPTYPE_TILED = 0, WPTYPE_CENTERED, WPTYPE_SCALED,
+	WPTYPE_STRETCHED, WPTYPE_ZOOM, WPTYPE_NONE,
+	WPTYPE_UNSET
+} wallpaper_type_t;
+
+struct _BGPreferences
+{
+	GObject           object;
+
+	gint              frozen;
+	gboolean          auto_apply;
+	guint             timeout_id;
+
+	gboolean          enabled;
+	gboolean          gradient_enabled;
+	gboolean          wallpaper_enabled;
+	orientation_t     orientation;
+	wallpaper_type_t  wallpaper_type;
+
+	GdkColor         *color1;
+	GdkColor         *color2;
+
+	gchar            *wallpaper_filename;
+	gchar            *wallpaper_sel_path;
+
+	GSList           *wallpapers;
+
+	gboolean          adjust_opacity;
+	gint              opacity;
+};
+
+struct _BGPreferencesClass
+{
+	GObjectClass klass;
+};
+
+GType    bg_preferences_get_type    (void);
+
+GObject *bg_preferences_new         (void);
+GObject *bg_preferences_clone       (const BGPreferences   *prefs);
+
+void     bg_preferences_load        (BGPreferences         *prefs);
+
+void     bg_preferences_merge_entry (BGPreferences         *prefs,
+				     const GConfEntry      *entry);
+
+void     bg_preferences_save        (BGPreferences *prefs);
+
+const gchar *bg_preferences_get_wptype_as_string      (wallpaper_type_t wp);
+const gchar *bg_preferences_get_orientation_as_string (orientation_t    o);
+GType        bg_preferences_wptype_get_type	      (void);
+GType	     bg_preferences_orientation_get_type      (void);
+
+	
+#endif /* __PREFERENCES_H */



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