[gnome-control-center] background: Use URIs everywhere internally



commit 2735c788b400210b257d0b7f2453e0bc432f64c4
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Feb 11 18:04:57 2011 +0000

    background: Use URIs everywhere internally
    
    Now we'd just need gnome-bg to make the jump.
    
    This also fixes unique IDs for the wallpapers source, as
    multiple backgrounds can be defined in a single XML file.

 panels/background/bg-colors-source.c     |    4 +-
 panels/background/bg-pictures-source.c   |   16 ++---
 panels/background/bg-wallpapers-source.c |    2 -
 panels/background/cc-background-item.c   |   95 ++++++++++++++----------------
 panels/background/cc-background-item.h   |   12 ++--
 panels/background/cc-background-panel.c  |   47 ++++++---------
 panels/background/gnome-wp-xml.c         |   54 +++++++++---------
 7 files changed, 105 insertions(+), 125 deletions(-)
---
diff --git a/panels/background/bg-colors-source.c b/panels/background/bg-colors-source.c
index 3fd96e3..2e4eb8d 100644
--- a/panels/background/bg-colors-source.c
+++ b/panels/background/bg-colors-source.c
@@ -71,8 +71,8 @@ bg_colors_source_init (BgColorsSource *self)
       flags = CC_BACKGROUND_ITEM_HAS_PCOLOR |
 	      CC_BACKGROUND_ITEM_HAS_SCOLOR |
 	      CC_BACKGROUND_ITEM_HAS_SHADING |
-	      CC_BACKGROUND_ITEM_HAS_FNAME;
-      /* It does have a filename, it's "none" */
+	      CC_BACKGROUND_ITEM_HAS_URI;
+      /* It does have a URI, it's "none" */
 
       g_object_set (G_OBJECT (item),
 		    "name", _(items[i].name),
diff --git a/panels/background/bg-pictures-source.c b/panels/background/bg-pictures-source.c
index e363b75..7cf8392 100644
--- a/panels/background/bg-pictures-source.c
+++ b/panels/background/bg-pictures-source.c
@@ -202,7 +202,6 @@ file_info_async_ready (GObject      *source,
   GList *files, *l;
   GError *err = NULL;
   GFile *parent;
-  gchar *path;
   files = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source),
                                                res,
                                                &err);
@@ -218,7 +217,6 @@ file_info_async_ready (GObject      *source,
     }
 
   parent = g_file_enumerator_get_container (G_FILE_ENUMERATOR (source));
-  path = g_file_get_path (parent);
 
   /* iterate over the available files */
   for (l = files; l; l = g_list_next (l))
@@ -236,18 +234,18 @@ file_info_async_ready (GObject      *source,
           || !strcmp ("image/jpeg", content_type))
         {
           CcBackgroundItem *item;
-          gchar *filename;
           GFile *file;
+          char *uri;
 
-          filename = g_build_filename (path, g_file_info_get_name (info), NULL);
+          file = g_file_get_child (parent, g_file_info_get_name (info));
 
           /* create a new CcBackgroundItem */
-          item = cc_background_item_new (filename);
-          g_object_set (G_OBJECT (item), "flags", CC_BACKGROUND_ITEM_HAS_FNAME, NULL);
+          uri = g_file_get_uri (file);
+          item = cc_background_item_new (uri);
+          g_free (uri);
+          g_object_set (G_OBJECT (item), "flags", CC_BACKGROUND_ITEM_HAS_URI, NULL);
           cc_background_item_load (item, info); /* FIXME use asynchronous load, and remove if failed */
 
-          file = g_file_new_for_path (filename);
-          g_free (filename);
           if (cc_background_item_get_placement (item) == G_DESKTOP_BACKGROUND_STYLE_NONE)
             g_object_set (G_OBJECT (item), "placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM, NULL);
           g_object_set_data (G_OBJECT (file), "item", item);
@@ -258,8 +256,6 @@ file_info_async_ready (GObject      *source,
 
   g_list_foreach (files, (GFunc) g_object_unref, NULL);
   g_list_free (files);
-
-  g_free (path);
 }
 
 static void
diff --git a/panels/background/bg-wallpapers-source.c b/panels/background/bg-wallpapers-source.c
index 2d5e9d8..c8fe50e 100644
--- a/panels/background/bg-wallpapers-source.c
+++ b/panels/background/bg-wallpapers-source.c
@@ -215,7 +215,6 @@ list_load_cb (GObject *source_object,
 			self);
 
   g_hash_table_destroy (wp_xml->wp_hash);
-//  g_object_unref (wp_xml->settings);
   g_free (wp_xml);
 }
 
@@ -227,7 +226,6 @@ reload_wallpapers (BgWallpapersSource *self)
   /* set up wallpaper source */
   wp_xml = g_new0 (GnomeWpXml, 1);
   wp_xml->wp_hash = g_hash_table_new (g_str_hash, g_str_equal);
-//  wp_xml->settings = g_settings_new (WP_PATH_ID);
   wp_xml->wp_model = bg_source_get_liststore (BG_SOURCE (self));
   wp_xml->thumb_width = THUMBNAIL_WIDTH;
   wp_xml->thumb_height = THUMBNAIL_HEIGHT;
diff --git a/panels/background/cc-background-item.c b/panels/background/cc-background-item.c
index fbf857c..981eb6c 100644
--- a/panels/background/cc-background-item.c
+++ b/panels/background/cc-background-item.c
@@ -41,7 +41,7 @@ struct CcBackgroundItemPrivate
 {
         /* properties */
         char            *name;
-        char            *filename;
+        char            *uri;
         char            *size;
         GDesktopBackgroundStyle placement;
         GDesktopBackgroundShading shading;
@@ -62,7 +62,7 @@ struct CcBackgroundItemPrivate
 enum {
         PROP_0,
         PROP_NAME,
-        PROP_FILENAME,
+        PROP_URI,
         PROP_PLACEMENT,
         PROP_SHADING,
         PROP_PRIMARY_COLOR,
@@ -104,8 +104,17 @@ set_bg_properties (CcBackgroundItem *item)
         GdkColor pcolor = { 0, 0, 0, 0 };
         GdkColor scolor = { 0, 0, 0, 0 };
 
-        if (item->priv->filename)
-                gnome_bg_set_filename (item->priv->bg, item->priv->filename);
+        if (item->priv->uri) {
+		GFile *file;
+		char *filename;
+
+		file = g_file_new_for_commandline_arg (item->priv->uri);
+		filename = g_file_get_path (file);
+		g_object_unref (file);
+
+		gnome_bg_set_filename (item->priv->bg, filename);
+		g_free (filename);
+	}
 
         if (item->priv->primary_color != NULL) {
                 gdk_color_parse (item->priv->primary_color, &pcolor);
@@ -139,7 +148,7 @@ update_size (CcBackgroundItem *item)
 	g_free (item->priv->size);
 	item->priv->size = NULL;
 
-	if (item->priv->filename == NULL || g_str_equal (item->priv->filename, "(none)")) {
+	if (item->priv->uri == NULL) {
 		item->priv->size = g_strdup ("");
 	} else {
 		if (gnome_bg_has_multiple_sizes (item->priv->bg) || gnome_bg_changes_with_time (item->priv->bg)) {
@@ -226,12 +235,13 @@ update_info (CcBackgroundItem *item,
         GFileInfo *info;
 
 	if (_info == NULL) {
-		file = g_file_new_for_commandline_arg (item->priv->filename);
+		file = g_file_new_for_uri (item->priv->uri);
 
 		info = g_file_query_info (file,
 					  G_FILE_ATTRIBUTE_STANDARD_NAME ","
 					  G_FILE_ATTRIBUTE_STANDARD_SIZE ","
 					  G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+					  G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
 					  G_FILE_ATTRIBUTE_TIME_MODIFIED,
 					  G_FILE_QUERY_INFO_NONE,
 					  NULL,
@@ -246,36 +256,16 @@ update_info (CcBackgroundItem *item,
 
         if (info == NULL
             || g_file_info_get_content_type (info) == NULL) {
-                if (item->priv->filename == NULL) {
+                if (item->priv->uri == NULL) {
                         item->priv->mime_type = g_strdup ("image/x-no-data");
                         g_free (item->priv->name);
                         item->priv->name = g_strdup (_("No Desktop Background"));
-                        //item->priv->size = 0;
                 }
         } else {
-                if (item->priv->name == NULL) {
-                        const char *name;
-
-                        g_free (item->priv->name);
-
-                        name = g_file_info_get_name (info);
-                        if (g_utf8_validate (name, -1, NULL))
-                                item->priv->name = g_strdup (name);
-                        else
-                                item->priv->name = g_filename_to_utf8 (name,
-                                                                       -1,
-                                                                       NULL,
-                                                                       NULL,
-                                                                       NULL);
-                }
+                if (item->priv->name == NULL)
+                        item->priv->name = g_strdup (g_file_info_get_display_name (info));
 
                 item->priv->mime_type = g_strdup (g_file_info_get_content_type (info));
-
-#if 0
-                item->priv->size = g_file_info_get_size (info);
-                item->priv->mtime = g_file_info_get_attribute_uint64 (info,
-                                                                      G_FILE_ATTRIBUTE_TIME_MODIFIED);
-#endif
         }
 
         if (info != NULL)
@@ -295,7 +285,7 @@ cc_background_item_load (CcBackgroundItem *item,
 			 GFileInfo        *info)
 {
         g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), FALSE);
-        g_return_val_if_fail (item->priv->filename != NULL, FALSE);
+        g_return_val_if_fail (item->priv->uri != NULL, FALSE);
 
         update_info (item, info);
 
@@ -310,9 +300,13 @@ cc_background_item_load (CcBackgroundItem *item,
 	/* FIXME we should handle XML files as well */
         if (item->priv->mime_type != NULL &&
             g_str_has_prefix (item->priv->mime_type, "image/")) {
-		gdk_pixbuf_get_file_info (item->priv->filename,
+		char *filename;
+
+		filename = g_filename_from_uri (item->priv->uri, NULL, NULL);
+		gdk_pixbuf_get_file_info (filename,
 					  &item->priv->width,
 					  &item->priv->height);
+		g_free (filename);
 		update_size (item);
 	}
 
@@ -336,19 +330,19 @@ cc_background_item_get_name (CcBackgroundItem *item)
 }
 
 static void
-_set_filename (CcBackgroundItem *item,
-               const char       *value)
+_set_uri (CcBackgroundItem *item,
+	  const char       *value)
 {
-        g_free (item->priv->filename);
-        item->priv->filename = g_strdup (value);
+        g_free (item->priv->uri);
+        item->priv->uri = g_strdup (value);
 }
 
 const char *
-cc_background_item_get_filename (CcBackgroundItem *item)
+cc_background_item_get_uri (CcBackgroundItem *item)
 {
 	g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
 
-	return item->priv->filename;
+	return item->priv->uri;
 }
 
 static void
@@ -489,8 +483,8 @@ cc_background_item_set_property (GObject      *object,
         case PROP_NAME:
                 _set_name (self, g_value_get_string (value));
                 break;
-        case PROP_FILENAME:
-                _set_filename (self, g_value_get_string (value));
+        case PROP_URI:
+                _set_uri (self, g_value_get_string (value));
                 break;
         case PROP_PLACEMENT:
                 _set_placement (self, g_value_get_enum (value));
@@ -536,8 +530,8 @@ cc_background_item_get_property (GObject    *object,
         case PROP_NAME:
                 g_value_set_string (value, self->priv->name);
                 break;
-        case PROP_FILENAME:
-                g_value_set_string (value, self->priv->filename);
+	case PROP_URI:
+                g_value_set_string (value, self->priv->uri);
                 break;
         case PROP_PLACEMENT:
                 g_value_set_enum (value, self->priv->placement);
@@ -615,10 +609,10 @@ cc_background_item_class_init (CcBackgroundItemClass *klass)
                                                               NULL,
                                                               G_PARAM_READWRITE));
         g_object_class_install_property (object_class,
-                                         PROP_FILENAME,
-                                         g_param_spec_string ("filename",
-                                                              "filename",
-                                                              "filename",
+                                         PROP_URI,
+                                         g_param_spec_string ("uri",
+                                                              "uri",
+                                                              "uri",
                                                               NULL,
                                                               G_PARAM_READWRITE));
         g_object_class_install_property (object_class,
@@ -730,7 +724,7 @@ cc_background_item_finalize (GObject *object)
         g_return_if_fail (item->priv != NULL);
 
         g_free (item->priv->name);
-        g_free (item->priv->filename);
+        g_free (item->priv->uri);
         g_free (item->priv->primary_color);
         g_free (item->priv->secondary_color);
         g_free (item->priv->mime_type);
@@ -743,12 +737,12 @@ cc_background_item_finalize (GObject *object)
 }
 
 CcBackgroundItem *
-cc_background_item_new (const char *filename)
+cc_background_item_new (const char *uri)
 {
         GObject *object;
 
         object = g_object_new (CC_TYPE_BACKGROUND_ITEM,
-                               "filename", filename,
+                               "uri", uri,
                                NULL);
 
         return CC_BACKGROUND_ITEM (object);
@@ -759,9 +753,8 @@ cc_background_item_copy (CcBackgroundItem *item)
 {
 	CcBackgroundItem *ret;
 
-	ret = cc_background_item_new (item->priv->filename);
+	ret = cc_background_item_new (item->priv->uri);
 	ret->priv->name = g_strdup (item->priv->name);
-	ret->priv->filename = g_strdup (item->priv->filename);
 	ret->priv->size = g_strdup (item->priv->size);
 	ret->priv->placement = item->priv->placement;
 	ret->priv->shading = item->priv->shading;
@@ -801,7 +794,7 @@ cc_background_item_dump (CcBackgroundItem *item)
 	priv = item->priv;
 
 	g_debug ("name:\t\t\t%s", priv->name);
-	g_debug ("filename:\t\t%s", priv->filename ? priv->filename : "NULL");
+	g_debug ("URI:\t\t\t%s", priv->uri ? priv->uri : "NULL");
 	if (priv->size)
 		g_debug ("size:\t\t\t'%s'", priv->size);
 	flags = g_string_new (NULL);
diff --git a/panels/background/cc-background-item.h b/panels/background/cc-background-item.h
index 55b1c29..dd88db9 100644
--- a/panels/background/cc-background-item.h
+++ b/panels/background/cc-background-item.h
@@ -37,11 +37,11 @@ G_BEGIN_DECLS
 #define CC_BACKGROUND_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CC_TYPE_BACKGROUND_ITEM, CcBackgroundItemClass))
 
 typedef enum {
-	CC_BACKGROUND_ITEM_HAS_SHADING = 1 << 0,
+	CC_BACKGROUND_ITEM_HAS_SHADING   = 1 << 0,
 	CC_BACKGROUND_ITEM_HAS_PLACEMENT = 1 << 1,
-	CC_BACKGROUND_ITEM_HAS_PCOLOR = 1 << 2,
-	CC_BACKGROUND_ITEM_HAS_SCOLOR = 1 << 3,
-	CC_BACKGROUND_ITEM_HAS_FNAME = 1 << 4
+	CC_BACKGROUND_ITEM_HAS_PCOLOR    = 1 << 2,
+	CC_BACKGROUND_ITEM_HAS_SCOLOR    = 1 << 3,
+	CC_BACKGROUND_ITEM_HAS_URI       = 1 << 4
 } CcBackgroundItemFlags;
 
 #define CC_BACKGROUND_ITEM_HAS_ALL (CC_BACKGROUND_ITEM_HAS_SHADING &	\
@@ -66,7 +66,7 @@ typedef struct
 
 GType              cc_background_item_get_type (void);
 
-CcBackgroundItem * cc_background_item_new                 (const char                   *filename);
+CcBackgroundItem * cc_background_item_new                 (const char                   *uri);
 CcBackgroundItem * cc_background_item_copy                (CcBackgroundItem             *item);
 gboolean           cc_background_item_load                (CcBackgroundItem             *item,
 							   GFileInfo                    *info);
@@ -84,7 +84,7 @@ GIcon     *        cc_background_item_get_frame_thumbnail (CcBackgroundItem
 
 GDesktopBackgroundStyle   cc_background_item_get_placement  (CcBackgroundItem *item);
 GDesktopBackgroundShading cc_background_item_get_shading    (CcBackgroundItem *item);
-const char *              cc_background_item_get_filename   (CcBackgroundItem *item);
+const char *              cc_background_item_get_uri        (CcBackgroundItem *item);
 const char *              cc_background_item_get_source_url (CcBackgroundItem *item);
 const char *              cc_background_item_get_source_xml (CcBackgroundItem *item);
 CcBackgroundItemFlags     cc_background_item_get_flags      (CcBackgroundItem *item);
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index fe4099b..61f4031 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -251,7 +251,7 @@ source_update_edit_box (CcBackgroundPanelPrivate *priv,
     gtk_widget_show (WID ("style-pcolor"));
 
   if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT ||
-      cc_background_item_get_filename (priv->current_background) == NULL)
+      cc_background_item_get_uri (priv->current_background) == NULL)
     gtk_widget_hide (WID ("style-combobox"));
   else
     gtk_widget_show (WID ("style-combobox"));
@@ -405,7 +405,7 @@ backgrounds_changed_cb (GtkIconView       *icon_view,
   CcBackgroundPanelPrivate *priv = panel->priv;
   char *pcolor, *scolor;
   gboolean draw_preview = TRUE;
-  const char *filename;
+  const char *uri;
   CcBackgroundItemFlags flags;
 
   list = gtk_icon_view_get_selected_items (icon_view);
@@ -430,10 +430,10 @@ backgrounds_changed_cb (GtkIconView       *icon_view,
 
   gtk_tree_model_get (model, &iter, 1, &item, -1);
 
-  filename = cc_background_item_get_filename (item);
+  uri = cc_background_item_get_uri (item);
   flags = cc_background_item_get_flags (item);
 
-  if ((flags & CC_BACKGROUND_ITEM_HAS_FNAME) && filename == NULL)
+  if ((flags & CC_BACKGROUND_ITEM_HAS_URI) && uri == NULL)
     {
       g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, G_DESKTOP_BACKGROUND_STYLE_NONE);
       g_settings_set_string (priv->settings, WP_FILE_KEY, "");
@@ -444,6 +444,7 @@ backgrounds_changed_cb (GtkIconView       *icon_view,
       gchar *cache_path;
       GdkPixbuf *pixbuf;
 
+      /* FIXME we want a URI here */
       cache_path = g_build_filename (g_get_user_cache_dir (),
                                      "gnome-background",
                                      NULL);
@@ -485,30 +486,17 @@ backgrounds_changed_cb (GtkIconView       *icon_view,
                          copy_finished_cb, panel);
 
       g_settings_set_string (priv->settings, WP_FILE_KEY, cache_path);
-      g_object_set (G_OBJECT (item), "filename", cache_path, NULL);
+      g_object_set (G_OBJECT (item), "uri", cache_path, NULL);
 
       /* delay the updated drawing of the preview until the copy finishes */
       draw_preview = FALSE;
     }
   else
     {
-       gchar *uri;
-
-       //FIXME this is garbage, either use uri, or not
-       if (g_utf8_validate (filename, -1, NULL))
-         uri = g_strdup (filename);
-       else
-         uri = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
-
-       if (uri == NULL)
-         {
-           g_warning ("Failed to convert filename to UTF-8: %s", filename);
-         }
-       else
-         {
-	   g_settings_set_string (priv->settings, WP_FILE_KEY, uri);
-           g_free (uri);
-         }
+      char *filename;
+      filename = g_filename_from_uri (uri, NULL, NULL);
+      g_settings_set_string (priv->settings, WP_FILE_KEY, filename);
+      g_free (filename);
     }
 
   if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT)
@@ -692,7 +680,7 @@ cc_background_panel_init (CcBackgroundPanel *self)
   GError *err = NULL;
   GtkWidget *widget;
   GtkListStore *store;
-  gchar *filename;
+  gchar *uri, *pcolor, *scolor;
 
   priv = self->priv = BACKGROUND_PANEL_PRIVATE (self);
 
@@ -790,21 +778,26 @@ cc_background_panel_init (CcBackgroundPanel *self)
   priv->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
 
   /* initalise the current background information from settings */
-  filename = g_settings_get_string (priv->settings, WP_FILE_KEY);
-  priv->current_background = cc_background_item_new (filename);
+  uri = g_settings_get_string (priv->settings, WP_FILE_KEY);
+  priv->current_background = cc_background_item_new (uri);
+  g_free (uri);
 
   /* FIXME Set flags too:
    * - if we have a gradient and no filename, set PCOLOR, etc.
    *
    * Move into cc-background-item.c like the old cc_background_item_update()?
    */
+  pcolor = g_settings_get_string (priv->settings, WP_PCOLOR_KEY);
+  scolor = g_settings_get_string (priv->settings, WP_SCOLOR_KEY);
   g_object_set (G_OBJECT (priv->current_background),
 		"name", _("Current background"),
 		"placement", g_settings_get_enum (priv->settings, WP_OPTIONS_KEY),
 		"shading", g_settings_get_enum (priv->settings, WP_SHADING_KEY),
-		"primary-color", g_settings_get_string (priv->settings, WP_PCOLOR_KEY),
-		"secondary-color", g_settings_get_string (priv->settings, WP_SCOLOR_KEY),
+		"primary-color", pcolor,
+		"secondary-color", scolor,
 		NULL);
+  g_free (pcolor);
+  g_free (scolor);
 
   cc_background_item_load (priv->current_background, NULL);
 
diff --git a/panels/background/gnome-wp-xml.c b/panels/background/gnome-wp-xml.c
index 0778166..5860f32 100644
--- a/panels/background/gnome-wp-xml.c
+++ b/panels/background/gnome-wp-xml.c
@@ -107,7 +107,6 @@ static void gnome_wp_xml_load_xml (GnomeWpXml *data,
   xmlChar * nodelang;
   const gchar * const * syslangs;
   gint i;
-  char *fname;
 
   wplist = xmlParseFile (filename);
 
@@ -115,15 +114,17 @@ static void gnome_wp_xml_load_xml (GnomeWpXml *data,
     return;
 
   syslangs = g_get_language_names ();
-  fname = NULL;
 
   root = xmlDocGetRootElement (wplist);
 
   for (list = root->children; list != NULL; list = list->next) {
     if (!strcmp ((gchar *)list->name, "wallpaper")) {
       CcBackgroundItem * item;
-      CcBackgroundItemFlags flags = 0;
+      CcBackgroundItemFlags flags;
+      char *uri, *cname, *id;
 
+      flags = 0;
+      cname = NULL;
       item = cc_background_item_new (NULL);
 
       g_object_set (G_OBJECT (item),
@@ -137,17 +138,20 @@ static void gnome_wp_xml_load_xml (GnomeWpXml *data,
 	} else if (!strcmp ((gchar *)wpa->name, "filename")) {
 	  if (wpa->last != NULL && wpa->last->content != NULL) {
 	    gchar *content = g_strstrip ((gchar *)wpa->last->content);
+	    char *bg_uri;
 
+	    /* FIXME same rubbish as in other parts of the code */
 	    if (strcmp (content, NONE) == 0) {
-	      fname = NULL;
-	    } else if (g_utf8_validate (content, -1, NULL) &&
-		     g_file_test (content, G_FILE_TEST_EXISTS)) {
-	      fname = g_strdup (content);
+	      bg_uri = NULL;
 	    } else {
-	      fname = g_filename_from_utf8 (content, -1, NULL, NULL, NULL);
+	      GFile *file;
+	      file = g_file_new_for_commandline_arg (content);
+	      bg_uri = g_file_get_uri (file);
+	      g_object_unref (file);
 	    }
-	    SET_FLAG(CC_BACKGROUND_ITEM_HAS_FNAME);
-	    g_object_set (G_OBJECT (item), "filename", fname, NULL);
+	    SET_FLAG(CC_BACKGROUND_ITEM_HAS_URI);
+	    g_object_set (G_OBJECT (item), "uri", bg_uri, NULL);
+	    g_free (bg_uri);
 	  } else {
 	    break;
 	  }
@@ -159,8 +163,9 @@ static void gnome_wp_xml_load_xml (GnomeWpXml *data,
 	    g_object_get (G_OBJECT (item), "name", &name, NULL);
 
 	    if (name == NULL && nodelang == NULL) {
-	       g_object_set (G_OBJECT (item), "name",
-			     g_strstrip ((gchar *)wpa->last->content), NULL);
+	       g_free (cname);
+	       cname = g_strdup (g_strstrip ((gchar *)wpa->last->content));
+	       g_object_set (G_OBJECT (item), "name", cname, NULL);
             } else {
 	       for (i = 0; syslangs[i] != NULL; i++) {
 	         if (!strcmp (syslangs[i], (gchar *)nodelang)) {
@@ -209,29 +214,24 @@ static void gnome_wp_xml_load_xml (GnomeWpXml *data,
 	}
       }
 
-      /* Make sure we don't already have this one and that filename exists */
-      if (fname == NULL ||
-	  g_hash_table_lookup (data->wp_hash, fname) != NULL) {
+      /* FIXME, this is a broken way of doing,
+       * need to use proper code here */
+      uri = g_filename_to_uri (filename, NULL, NULL);
+      id = g_strdup_printf ("%s#%s", uri, cname);
+      g_free (uri);
 
+      /* Make sure we don't already have this one and that filename exists */
+      if (g_hash_table_lookup (data->wp_hash, id) != NULL) {
 	g_object_unref (item);
+	g_free (id);
 	continue;
       }
 
       g_object_set (G_OBJECT (item), "flags", flags, NULL);
-
-      if (fname != NULL) {
-#if 0
-        cc_background_item_ensure_gnome_bg (wp);
-	cc_background_item_update_size (wp, NULL);
-#endif
-	g_hash_table_insert (data->wp_hash, g_strdup (filename), item);
-      } else {
-	g_object_unref (item);
-        item = NULL;
-      }
+      g_hash_table_insert (data->wp_hash, id, item);
+      /* Don't free ID, we added it to the hash table */
     }
   }
-  g_free (fname);
   xmlFreeDoc (wplist);
 }
 



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