1
/* bg-wallpapers-source.c */
3
* Copyright (C) 2010 Intel, Inc
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
* Author: Thomas Wood <thomas.wood@intel.com>
24
#include "bg-wallpapers-source.h"
26
#include "cc-background-item.h"
27
#include "cc-background-xml.h"
29
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
32
G_DEFINE_TYPE (BgWallpapersSource, bg_wallpapers_source, BG_TYPE_SOURCE)
34
#define WALLPAPERS_SOURCE_PRIVATE(o) \
35
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_WALLPAPERS_SOURCE, BgWallpapersSourcePrivate))
37
struct _BgWallpapersSourcePrivate
39
GnomeDesktopThumbnailFactory *thumb_factory;
45
bg_wallpapers_source_get_property (GObject *object,
53
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
58
bg_wallpapers_source_set_property (GObject *object,
66
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
71
bg_wallpapers_source_dispose (GObject *object)
73
BgWallpapersSourcePrivate *priv = BG_WALLPAPERS_SOURCE (object)->priv;
75
if (priv->thumb_factory)
77
g_object_unref (priv->thumb_factory);
78
priv->thumb_factory = NULL;
82
g_object_unref (priv->xml);
86
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->dispose (object);
90
bg_wallpapers_source_finalize (GObject *object)
92
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->finalize (object);
96
bg_wallpapers_source_class_init (BgWallpapersSourceClass *klass)
98
GObjectClass *object_class = G_OBJECT_CLASS (klass);
100
g_type_class_add_private (klass, sizeof (BgWallpapersSourcePrivate));
102
object_class->get_property = bg_wallpapers_source_get_property;
103
object_class->set_property = bg_wallpapers_source_set_property;
104
object_class->dispose = bg_wallpapers_source_dispose;
105
object_class->finalize = bg_wallpapers_source_finalize;
109
load_wallpapers (gchar *key,
110
CcBackgroundItem *item,
111
BgWallpapersSource *source)
113
BgWallpapersSourcePrivate *priv = source->priv;
116
GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
119
g_object_get (G_OBJECT (item), "is-deleted", &deleted, NULL);
124
gtk_list_store_append (store, &iter);
126
pixbuf = cc_background_item_get_thumbnail (item, priv->thumb_factory,
127
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
129
gtk_list_store_set (store, &iter,
131
1, g_object_ref (item),
135
g_object_unref (pixbuf);
139
list_load_cb (GObject *source_object,
143
cc_background_xml_load_list_finish (res);
147
item_added (CcBackgroundXml *xml,
148
CcBackgroundItem *item,
149
BgWallpapersSource *self)
151
load_wallpapers (NULL, item, self);
155
load_default_bg (BgWallpapersSource *self)
157
const char * const *system_data_dirs;
161
/* FIXME We could do this nicer if we had the XML source in GSettings */
163
system_data_dirs = g_get_system_data_dirs ();
164
for (i = 0; system_data_dirs[i]; i++) {
165
filename = g_build_filename (system_data_dirs[i],
166
"gnome-background-properties",
169
if (cc_background_xml_load_xml (self->priv->xml, filename)) {
178
bg_wallpapers_source_init (BgWallpapersSource *self)
180
BgWallpapersSourcePrivate *priv;
182
priv = self->priv = WALLPAPERS_SOURCE_PRIVATE (self);
184
priv->thumb_factory =
185
gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
186
priv->xml = cc_background_xml_new ();
187
g_signal_connect (G_OBJECT (priv->xml), "added",
188
G_CALLBACK (item_added), self);
190
/* Try adding the default background first */
191
load_default_bg (self);
193
cc_background_xml_load_list_async (priv->xml, NULL, list_load_cb, self);
197
bg_wallpapers_source_new (void)
199
return g_object_new (BG_TYPE_WALLPAPERS_SOURCE, NULL);