Commit ca14846e authored by Bastien Nocera's avatar Bastien Nocera

background: Major rework of the CcBackgroundItem code

It now is a full GObject, will be able to track the original
XML file for a wallpaper, as well as which values are set in it.

This will allow us to restore wallpapers properly, and only offer
editing options when those aren't already hard-coded inside the
item.
parent 9a209fa1
......@@ -55,6 +55,8 @@ PKG_CHECK_MODULES(LIBCANBERRA_GTK, libcanberra-gtk3, [
], [:])
AM_CONDITIONAL(HAVE_LIBCANBERRA_GTK, test "x$CANBERRA_GTK" = "x1")
AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
dnl Region panel
savecppflags=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $X_CFLAGS"
......
......@@ -34,6 +34,8 @@ libbackground_la_SOURCES = \
cc-background-panel.h \
cc-background-item.c \
cc-background-item.h \
gdesktop-enums-types.c \
gdesktop-enums-types.h \
bg-source.c \
bg-source.h \
bg-pictures-source.c \
......@@ -60,12 +62,36 @@ INCLUDES += $(SOCIALWEB_CFLAGS)
libbackground_la_LIBADD += $(SOCIALWEB_LIBS)
endif
gdesktop-enums-types.h: stamp-gdesktop-enums-types.h
@true
stamp-gdesktop-enums-types.h: $(includedir)/gsettings-desktop-schemas/gdesktop-enums.h cc-background-item.h Makefile
$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) \
--fhead "#ifndef __GDESKTOP_ENUMS_TYPES_H__\n#define __GDESKTOP_ENUMS_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
--fprod "/* enumerations from \"@filename@\" */\n" \
--vhead "GType @enum_name@_get_type (void) G_GNUC_CONST;\n#define G_DESKTOP_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \
--ftail "G_END_DECLS\n\n#endif /* __GDESKTOP_ENUMS_TYPES_H__ */" $(includedir)/gsettings-desktop-schemas/gdesktop-enums.h cc-background-item.h) >> xgen-gtbh \
&& (cmp -s xgen-gtbh gdesktop-enums-types.h || cp xgen-gtbh gdesktop-enums-types.h ) \
&& rm -f xgen-gtbh \
&& echo timestamp > $(@F)
gdesktop-enums-types.c: $(includedir)/gsettings-desktop-schemas/gdesktop-enums.h cc-background-item.h Makefile gdesktop-enums-types.h
$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) \
--fhead "#include <gdesktop-enums.h>\n#include \"gdesktop-enums-types.h\"\n#include \"cc-background-item.h\"" \
--fprod "\n/* enumerations from \"@filename@\" */" \
--vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \
--vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
--vtail " { 0, NULL, NULL }\n };\n etype = g_@type@_register_static (\"@EnumName@\", values);\n }\n return etype;\n}\n" \
$(includedir)/gsettings-desktop-schemas/gdesktop-enums.h cc-background-item.h) > xgen-gtbc \
&& cp xgen-gtbc gdesktop-enums-types.c \
&& rm -f xgen-gtbc
@INTLTOOL_DESKTOP_RULE@
desktopdir = $(datadir)/applications
desktop_in_files = gnome-background-panel.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
CLEANFILES = $(desktop_in_files) $(desktop_DATA)
CLEANFILES = $(desktop_in_files) $(desktop_DATA) stamp-gdesktop-enums-types.h gdesktop-enums-types.h gdesktop-enums-types.c
-include $(top_srcdir)/git.mk
......@@ -26,6 +26,7 @@
#include "cc-background-item.h"
#include <glib/gi18n-lib.h>
#include <gsettings-desktop-schemas/gdesktop-enums.h>
G_DEFINE_TYPE (BgColorsSource, bg_colors_source, BG_TYPE_SOURCE)
......@@ -55,36 +56,29 @@ bg_colors_source_init (BgColorsSource *self)
GnomeDesktopThumbnailFactory *thumb_factory;
guint i;
GtkListStore *store;
GdkColor pcolor, scolor;
store = bg_source_get_liststore (BG_SOURCE (self));
thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
gdk_color_parse (PCOLOR, &pcolor);
gdk_color_parse (SCOLOR, &scolor);
for (i = 0; i < G_N_ELEMENTS (items); i++)
{
GnomeWPItem *item;
CcBackgroundItem *item;
GIcon *pixbuf;
item = g_new0 (GnomeWPItem, 1);
item->filename = g_strdup ("(none)");
item->name = g_strdup (_(items[i].name));
item->pcolor = gdk_color_copy (&pcolor);
item->scolor = gdk_color_copy (&scolor);
item->shade_type = items[i].type;
item = cc_background_item_new (NULL);
cc_background_item_ensure_gnome_bg (item);
g_object_set (G_OBJECT (item),
"name", _(items[i].name),
"primary-color", PCOLOR,
"secondary-color", SCOLOR,
"shading", items[i].type,
NULL);
/* insert the item into the liststore */
pixbuf = cc_background_item_get_thumbnail (item,
thumb_factory,
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
thumb_factory,
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
gtk_list_store_insert_with_values (store, NULL, 0,
0, pixbuf,
1, item,
......
......@@ -27,6 +27,7 @@
#include <libsocialweb-client/sw-client-service.h>
#include "cc-background-item.h"
#include <gsettings-desktop-schemas/gdesktop-enums.h>
G_DEFINE_TYPE (BgFlickrSource, bg_flickr_source, BG_TYPE_SOURCE)
......@@ -88,25 +89,24 @@ _view_items_added_cb (SwClientItemView *item_view,
for (l = items; l; l = l->next)
{
GnomeWPItem *item;
CcBackgroundItem *item;
GdkPixbuf *pixbuf;
GdkColor color = { 0, 0, 0, 0 };
SwItem *sw_item = (SwItem *) l->data;
const gchar *thumb_url;
item = g_new0 (GnomeWPItem, 1);
item = cc_background_item_new (NULL);
item->options = G_DESKTOP_BACKGROUND_STYLE_ZOOM;
item->name = g_strdup (sw_item_get_value (sw_item, "title"));
item->source_url = g_strdup (sw_item_get_value (sw_item,
"x-flickr-photo-url"));
g_object_set (G_OBJECT (item),
"placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM,
"name", sw_item_get_value (sw_item, "title"),
"primary-color", "#000000000000",
"seconday-color", "#000000000000",
"shading", G_DESKTOP_BACKGROUND_SHADING_SOLID,
"source-url", sw_item_get_value (sw_item, "x-flickr-photo-url"),
NULL);
item->pcolor = gdk_color_copy (&color);
item->scolor = gdk_color_copy (&color);
item->shade_type = G_DESKTOP_BACKGROUND_SHADING_SOLID;
cc_background_item_ensure_gnome_bg (item);
//FIXME
// cc_background_item_ensure_gnome_bg (item);
/* insert the item into the liststore */
thumb_url = sw_item_get_value (sw_item, "thumbnail");
......
......@@ -27,7 +27,7 @@
#include <string.h>
#include <gio/gio.h>
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
#include <gsettings-desktop-schemas/gdesktop-enums.h>
G_DEFINE_TYPE (BgPicturesSource, bg_pictures_source, BG_TYPE_SOURCE)
......@@ -122,7 +122,7 @@ picture_scaled (GObject *source_object,
gpointer user_data)
{
BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data);
GnomeWPItem *item;
CcBackgroundItem *item;
GError *error = NULL;
GdkPixbuf *pixbuf;
......@@ -138,7 +138,7 @@ picture_scaled (GObject *source_object,
{
g_warning ("Failed to load image: %s", error->message);
g_error_free (error);
cc_background_item_free (item);
g_object_unref (item);
return;
}
......@@ -149,8 +149,11 @@ picture_scaled (GObject *source_object,
-1);
tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store),
&iter);
//FIXME rowref
#if 0
item->rowref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store),
tree_path);
#endif
gtk_tree_path_free (tree_path);
g_object_unref (pixbuf);
......@@ -162,7 +165,7 @@ picture_opened_for_read (GObject *source_object,
gpointer user_data)
{
BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data);
GnomeWPItem *item;
CcBackgroundItem *item;
GFileInputStream *stream;
GError *error = NULL;
......@@ -176,7 +179,7 @@ picture_opened_for_read (GObject *source_object,
g_warning ("Failed to load picture '%s': %s", filename, error->message);
g_free (filename);
g_error_free (error);
cc_background_item_free (item);
g_object_unref (item);
return;
}
......@@ -196,7 +199,6 @@ file_info_async_ready (GObject *source,
gpointer user_data)
{
BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data);
BgPicturesSourcePrivate *priv = bg_source->priv;
GList *files, *l;
GError *err = NULL;
GFile *parent;
......@@ -234,17 +236,15 @@ file_info_async_ready (GObject *source,
if (!strcmp ("image/png", content_type)
|| !strcmp ("image/jpeg", content_type))
{
GnomeWPItem *item;
CcBackgroundItem *item;
gchar *filename;
GFile *file;
filename = g_build_filename (path, g_file_info_get_name (info), NULL);
/* create a new GnomeWpItem */
item = cc_background_item_new (filename, NULL,
info,
priv->thumb_factory);
/* create a new CcBackgroundItem */
item = cc_background_item_new (filename);
cc_background_item_load (item, info);
if (!item)
{
g_warning ("Could not load picture \"%s\"", filename);
......@@ -254,8 +254,8 @@ file_info_async_ready (GObject *source,
file = g_file_new_for_path (filename);
g_free (filename);
if (item->options == G_DESKTOP_BACKGROUND_STYLE_NONE)
item->options = G_DESKTOP_BACKGROUND_STYLE_ZOOM;
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);
g_file_read_async (file, 0, NULL, picture_opened_for_read, bg_source);
g_object_unref (file);
......
......@@ -76,12 +76,12 @@ free_tree_model_items (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
GnomeWPItem *item = NULL;
CcBackgroundItem *item = NULL;
gtk_tree_model_get (model, iter, 1, &item, -1);
if (item)
cc_background_item_free (item);
g_object_unref (item);
return FALSE;
}
......
......@@ -107,13 +107,15 @@ bg_wallpapers_source_class_init (BgWallpapersSourceClass *klass)
object_class->finalize = bg_wallpapers_source_finalize;
}
//FIXME
#if 0
static gboolean
find_wallpaper (gpointer key,
gpointer value,
gpointer data)
{
GnomeBG *bg = data;
GnomeWPItem *item = value;
CcBackgroundItem *item = value;
return item->bg == bg;
}
......@@ -126,7 +128,7 @@ item_changed_cb (GnomeBG *bg,
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreePath *path;
GnomeWPItem *item;
CcBackgroundItem *item;
item = g_hash_table_find (data->wp_hash, find_wallpaper, bg);
......@@ -157,29 +159,32 @@ item_changed_cb (GnomeBG *bg,
data);
}
}
#endif
static void
load_wallpapers (gchar *key,
GnomeWPItem *item,
CcBackgroundItem *item,
BgWallpapersSource *source)
{
BgWallpapersSourcePrivate *priv = source->priv;
GtkTreeIter iter;
GtkTreePath *path;
// GtkTreePath *path;
GIcon *pixbuf;
GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
gboolean deleted;
g_object_get (G_OBJECT (item), "is-deleted", &deleted, NULL);
if (item->deleted == TRUE)
if (deleted)
return;
gtk_list_store_append (store, &iter);
pixbuf = cc_background_item_get_thumbnail (item, priv->thumb_factory,
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
cc_background_item_update_size (item, NULL);
// cc_background_item_update_size (item, NULL);
gtk_list_store_set (store, &iter,
0, pixbuf,
......@@ -189,9 +194,11 @@ load_wallpapers (gchar *key,
if (pixbuf)
g_object_unref (pixbuf);
#if 0
path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
item->rowref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
gtk_tree_path_free (path);
#endif
}
static void
......@@ -208,7 +215,7 @@ list_load_cb (GObject *source_object,
self);
g_hash_table_destroy (wp_xml->wp_hash);
g_object_unref (wp_xml->settings);
// g_object_unref (wp_xml->settings);
g_free (wp_xml);
}
......@@ -220,7 +227,7 @@ 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->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;
......
This diff is collapsed.
/*
* Authors: Rodney Dawes <dobey@ximian.com>
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright 2003-2006 Novell, Inc. (www.novell.com)
* Copyright (C) 2010-2011 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation
* 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.
* 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 Street #330, Boston, MA 02111-1307, USA.
* 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.
*
*/
#include <glib.h>
#include <gio/gio.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
#include <libgnome-desktop/gnome-bg.h>
#include <gsettings-desktop-schemas/gdesktop-enums.h>
#include "gnome-wp-info.h"
#ifndef __CC_BACKGROUND_ITEM_H
#define __CC_BACKGROUND_ITEM_H
#include <glib-object.h>
#ifndef _GNOME_WP_ITEM_H_
#define _GNOME_WP_ITEM_H_
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
#include <gsettings-desktop-schemas/gdesktop-enums.h>
#include <libgnome-desktop/gnome-bg.h>
#define WP_PATH_ID "org.gnome.desktop.background"
#define WP_FILE_KEY "picture-filename"
#define WP_OPTIONS_KEY "picture-options"
#define WP_SHADING_KEY "color-shading-type"
#define WP_PCOLOR_KEY "primary-color"
#define WP_SCOLOR_KEY "secondary-color"
G_BEGIN_DECLS
typedef struct _GnomeWPItem GnomeWPItem;
#define CC_TYPE_BACKGROUND_ITEM (cc_background_item_get_type ())
#define CC_BACKGROUND_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CC_TYPE_BACKGROUND_ITEM, CcBackgroundItem))
#define CC_BACKGROUND_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CC_TYPE_BACKGROUND_ITEM, CcBackgroundItemClass))
#define CC_IS_BACKGROUND_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CC_TYPE_BACKGROUND_ITEM))
#define CC_IS_BACKGROUND_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CC_TYPE_BACKGROUND_ITEM))
#define CC_BACKGROUND_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CC_TYPE_BACKGROUND_ITEM, CcBackgroundItemClass))
struct _GnomeWPItem {
GnomeBG *bg;
typedef enum {
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
} CcBackgroundItemFlags;
gchar * name;
gchar * filename;
gchar * size;
GDesktopBackgroundStyle options;
GDesktopBackgroundShading shade_type;
#define CC_BACKGROUND_ITEM_HAS_ALL (CC_BACKGROUND_ITEM_HAS_SHADING & \
CC_BACKGROUND_ITEM_HAS_PLACEMENT & \
CC_BACKGROUND_ITEM_HAS_PCOLOR & \
CC_BACKGROUND_ITEM_HAS_SCOLOR & \
CC_BACKGROUND_ITEM_HAS_FNAME)
gchar * source_url;
typedef struct CcBackgroundItemPrivate CcBackgroundItemPrivate;
/* Where the Item is in the List */
GtkTreeRowReference * rowref;
typedef struct
{
GObject parent;
CcBackgroundItemPrivate *priv;
} CcBackgroundItem;
/* Real colors */
GdkColor * pcolor;
GdkColor * scolor;
typedef struct
{
GObjectClass parent_class;
void (* changed) (CcBackgroundItem *item);
} CcBackgroundItemClass;
GnomeWPInfo * fileinfo;
GType cc_background_item_get_type (void);
/* Did the user remove us? */
gboolean deleted;
CcBackgroundItem * cc_background_item_new (const char *filename);
gboolean cc_background_item_load (CcBackgroundItem *item,
GFileInfo *info);
gboolean cc_background_item_changes_with_time (CcBackgroundItem *item);
/* Width and Height of the original image */
gint width;
gint height;
};
GIcon * cc_background_item_get_thumbnail (CcBackgroundItem *item,
GnomeDesktopThumbnailFactory *thumbs,
int width,
int height);
GIcon * cc_background_item_get_frame_thumbnail (CcBackgroundItem *item,
GnomeDesktopThumbnailFactory *thumbs,
int width,
int height,
int frame);
GnomeWPItem * cc_background_item_new (const gchar *filename,
GHashTable *wallpapers,
GFileInfo *file_info,
GnomeDesktopThumbnailFactory *thumbnails);
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_source_url (CcBackgroundItem *item);
const char * cc_background_item_get_source_xml (CcBackgroundItem *item);
CcBackgroundItemFlags cc_background_item_get_flags (CcBackgroundItem *item);
const char * cc_background_item_get_pcolor (CcBackgroundItem *item);
const char * cc_background_item_get_scolor (CcBackgroundItem *item);
const char * cc_background_item_get_name (CcBackgroundItem *item);
const char * cc_background_item_get_size (CcBackgroundItem *item);
void cc_background_item_free (GnomeWPItem *item);
GIcon * cc_background_item_get_thumbnail (GnomeWPItem *item,
GnomeDesktopThumbnailFactory *thumbs,
gint width,
gint height);
GIcon * cc_background_item_get_frame_thumbnail (GnomeWPItem *item,
GnomeDesktopThumbnailFactory *thumbs,
gint width,
gint height,
gint frame);
void cc_background_item_update (GnomeWPItem *item);
void cc_background_item_update_size (GnomeWPItem *item, GnomeDesktopThumbnailFactory *thumbs);
void cc_background_item_ensure_gnome_bg (GnomeWPItem *item);
G_END_DECLS
#endif
#endif /* __CC_BACKGROUND_ITEM_H */
......@@ -21,6 +21,10 @@
#include <config.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <gsettings-desktop-schemas/gdesktop-enums.h>
#include "cc-background-panel.h"
#include "bg-wallpapers-source.h"
#include "bg-pictures-source.h"
......@@ -33,8 +37,12 @@
#include "gnome-wp-xml.h"
#include "cc-background-item.h"
#include <string.h>
#include <glib/gi18n-lib.h>
#define WP_PATH_ID "org.gnome.desktop.background"
#define WP_FILE_KEY "picture-filename"
#define WP_OPTIONS_KEY "picture-options"
#define WP_SHADING_KEY "color-shading-type"
#define WP_PCOLOR_KEY "primary-color"
#define WP_SCOLOR_KEY "secondary-color"
enum {
COL_SOURCE_NAME,
......@@ -65,7 +73,7 @@ struct _CcBackgroundPanelPrivate
GnomeDesktopThumbnailFactory *thumb_factory;
GnomeWPItem *current_background;
CcBackgroundItem *current_background;
gboolean current_source_readonly;
gint current_source;
......@@ -198,7 +206,7 @@ cc_background_panel_finalize (GObject *object)
if (priv->current_background)
{
cc_background_item_free (priv->current_background);
g_object_unref (priv->current_background);
priv->current_background = NULL;
}
......@@ -232,7 +240,7 @@ source_update_edit_box (CcBackgroundPanelPrivate *priv)
gtk_widget_show (WID ("style-pcolor"));
if (priv->current_background &&
priv->current_background->shade_type == G_DESKTOP_BACKGROUND_SHADING_SOLID)
cc_background_item_get_shading (priv->current_background) == G_DESKTOP_BACKGROUND_SHADING_SOLID)
gtk_widget_hide (WID ("style-scolor"));
else
gtk_widget_show (WID ("style-scolor"));
......@@ -259,12 +267,12 @@ setup_edit_box (CcBackgroundPanelPrivate *priv)
{
g_assert (priv->current_background);
if (g_str_equal (priv->current_background->filename, "(none)"))
if (cc_background_item_get_filename (priv->current_background) == NULL)
{
gtk_widget_hide (WID ("style-combobox"));
gtk_widget_show (WID ("style-pcolor"));
if (priv->current_background->shade_type == G_DESKTOP_BACKGROUND_SHADING_SOLID)
if (cc_background_item_get_shading (priv->current_background) == G_DESKTOP_BACKGROUND_SHADING_SOLID)
gtk_widget_hide (WID ("style-scolor"));
else
gtk_widget_show (WID ("style-scolor"));
......@@ -363,7 +371,7 @@ select_style (GtkComboBox *box,
static void
update_preview (CcBackgroundPanelPrivate *priv,
GnomeWPItem *item,
CcBackgroundItem *item,
gboolean redraw_preview)
{
gchar *markup;
......@@ -371,6 +379,17 @@ update_preview (CcBackgroundPanelPrivate *priv,
if (item && priv->current_background)
{
//FIXME is that correct?
g_object_unref (priv->current_background);
priv->current_background = g_object_ref (item);
#if 0
g_object_set (G_OBJECT (priv->current_background),
"primary-color", cc_background_item_get_pcolor (item),
"secondary-color", cc_background_item_get_scolor (item),
"filename", cc_background_item_get_filename (item),
"placement", cc_background_item_get_placement (item),
"shading", cc_background_item_get_shading (item),
if (priv->current_background->pcolor)
gdk_color_free (priv->current_background->pcolor);
priv->current_background->pcolor = gdk_color_copy (item->pcolor);
......@@ -393,6 +412,7 @@ update_preview (CcBackgroundPanelPrivate *priv,
cc_background_item_ensure_gnome_bg (priv->current_background);
cc_background_item_update_size (priv->current_background, priv->thumb_factory);
#endif
}
source_update_edit_box (priv);
......@@ -401,22 +421,24 @@ update_preview (CcBackgroundPanelPrivate *priv,
if (priv->current_background)
{
markup = g_strdup_printf ("<b>%s</b>", priv->current_background->name);
GdkColor pcolor, scolor;
markup = g_strdup_printf ("<b>%s</b>", cc_background_item_get_name (priv->current_background));
gtk_label_set_markup (GTK_LABEL (WID ("background-label")), markup);
g_free (markup);
gtk_label_set_text (GTK_LABEL (WID ("size_label")), priv->current_background->size);
gtk_label_set_text (GTK_LABEL (WID ("size_label")), cc_background_item_get_size (priv->current_background));
gdk_color_parse (cc_background_item_get_pcolor (priv->current_background), &pcolor);
gdk_color_parse (cc_background_item_get_scolor (priv->current_background), &scolor);
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-pcolor")),
priv->current_background->pcolor);
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-scolor")),
priv->current_background->scolor);
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-pcolor")), &pcolor);
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-scolor")), &scolor);
select_style (GTK_COMBO_BOX (WID ("style-combobox")),
priv->current_background->options);
cc_background_item_get_placement (priv->current_background));
if (priv->current_background->bg)
changes_with_time = gnome_bg_changes_with_time (priv->current_background->bg);
changes_with_time = cc_background_item_changes_with_time (priv->current_background);
}
gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
......@@ -433,10 +455,11 @@ backgrounds_changed_cb (GtkIconView *icon_view,
GtkTreeIter iter;
GList *list;
GtkTreeModel *model;
GnomeWPItem *item;
gchar *pcolor, *scolor;
CcBackgroundItem *item;
CcBackgroundPanelPrivate *priv = panel->priv;
char *pcolor, *scolor;
gboolean draw_preview = TRUE;
const char *filename;
list = gtk_icon_view_get_selected_items (icon_view);
......@@ -449,8 +472,8 @@ backgrounds_changed_cb (GtkIconView *icon_view,
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (WID ("sources-combobox")),
&iter);
gtk_tree_model_get (model, &iter,
COL_SOURCE_READONLY, &priv->current_source_readonly,
COL_SOURCE_TYPE, &priv->current_source, -1);
COL_SOURCE_READONLY, &priv->current_source_readonly,
COL_SOURCE_TYPE, &priv->current_source, -1);
model = gtk_icon_view_get_model (icon_view);
......@@ -461,12 +484,14 @@ backgrounds_changed_cb (GtkIconView *icon_view,
gtk_tree_model_get (model, &iter, 1, &item, -1);
if (!g_strcmp0 (item->filename, "(none)"))
filename = cc_background_item_get_filename (item);
if (filename == NULL)
{
g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, G_DESKTOP_BACKGROUND_STYLE_NONE);
g_settings_set_string (priv->settings, WP_FILE_KEY, "");
}
else if (item->source_url)
else if (cc_background_item_get_source_url (item) != NULL)
{
GFile *source, *dest;
gchar *cache_path;
......@@ -476,7 +501,7 @@ backgrounds_changed_cb (GtkIconView *icon_view,
"gnome-background",
NULL);
source = g_file_new_for_uri (item->source_url);
source = g_file_new_for_uri (cc_background_item_get_source_url (item));
dest = g_file_new_for_path (cache_path);
/* create a blank image to use until the source image is ready */
......@@ -514,9 +539,8 @@ backgrounds_changed_cb (GtkIconView *icon_view,
copy_finished_cb, panel);
g_settings_set_string (priv->settings, WP_FILE_KEY, cache_path);
g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, item->options);
g_free (item->filename);
item->filename = cache_path;
g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
g_object_set (G_OBJECT (item), "filename", cache_path, NULL);
/* delay the updated drawing of the preview until the copy finishes */
draw_preview = FALSE;
......@@ -525,15 +549,15 @@ backgrounds_changed_cb (GtkIconView *icon_view,
{
gchar *uri;
if (g_utf8_validate (item->filename, -1, NULL))
uri = g_strdup (item->filename);
//FIXME this is garbage, either use uri, or not
if (g_utf8_validate (filename, -1, NULL))
uri = g_strdup (filename);
else
<