2010-08-10 15:26:07 +01:00
|
|
|
/* bg-wallpapers-source.c */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Intel, Inc
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 12:57:27 +01:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2010-08-10 15:26:07 +01:00
|
|
|
*
|
|
|
|
* Author: Thomas Wood <thomas.wood@intel.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "bg-wallpapers-source.h"
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
#include "cc-background-item.h"
|
2011-02-12 02:01:23 +00:00
|
|
|
#include "cc-background-xml.h"
|
2010-08-10 15:26:07 +01:00
|
|
|
|
2010-11-14 22:12:59 +00:00
|
|
|
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
|
2010-08-10 15:26:07 +01:00
|
|
|
#include <gio/gio.h>
|
|
|
|
|
2010-08-10 17:01:15 +01:00
|
|
|
G_DEFINE_TYPE (BgWallpapersSource, bg_wallpapers_source, BG_TYPE_SOURCE)
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
#define WALLPAPERS_SOURCE_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_WALLPAPERS_SOURCE, BgWallpapersSourcePrivate))
|
|
|
|
|
|
|
|
struct _BgWallpapersSourcePrivate
|
|
|
|
{
|
|
|
|
GnomeDesktopThumbnailFactory *thumb_factory;
|
2011-02-12 02:37:48 +00:00
|
|
|
CcBackgroundXml *xml;
|
2010-08-10 15:26:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-08-10 17:01:15 +01:00
|
|
|
load_wallpapers (gchar *key,
|
2011-02-11 20:24:31 +00:00
|
|
|
CcBackgroundItem *item,
|
2010-08-10 17:01:15 +01:00
|
|
|
BgWallpapersSource *source)
|
2010-08-10 15:26:07 +01:00
|
|
|
{
|
2010-08-10 17:01:15 +01:00
|
|
|
BgWallpapersSourcePrivate *priv = source->priv;
|
2010-08-10 15:26:07 +01:00
|
|
|
GtkTreeIter iter;
|
2010-12-14 20:29:33 +00:00
|
|
|
GIcon *pixbuf;
|
2010-08-10 17:01:15 +01:00
|
|
|
GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
|
2011-02-10 20:30:57 +00:00
|
|
|
gboolean deleted;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (item), "is-deleted", &deleted, NULL);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
if (deleted)
|
2010-08-10 15:26:07 +01:00
|
|
|
return;
|
|
|
|
|
2010-08-10 17:01:15 +01:00
|
|
|
gtk_list_store_append (store, &iter);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
pixbuf = cc_background_item_get_thumbnail (item, priv->thumb_factory,
|
2011-02-12 02:01:23 +00:00
|
|
|
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
2010-08-10 17:01:15 +01:00
|
|
|
gtk_list_store_set (store, &iter,
|
2010-08-10 15:26:07 +01:00
|
|
|
0, pixbuf,
|
2013-10-04 21:34:50 +02:00
|
|
|
1, item,
|
2011-05-16 00:12:44 -04:00
|
|
|
2, cc_background_item_get_name (item),
|
2010-08-10 15:26:07 +01:00
|
|
|
-1);
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
}
|
|
|
|
|
2011-02-10 12:01:17 +00:00
|
|
|
static void
|
|
|
|
list_load_cb (GObject *source_object,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2011-02-12 02:37:48 +00:00
|
|
|
cc_background_xml_load_list_finish (res);
|
2011-02-10 12:01:17 +00:00
|
|
|
}
|
|
|
|
|
2011-02-12 02:37:48 +00:00
|
|
|
static void
|
|
|
|
item_added (CcBackgroundXml *xml,
|
|
|
|
CcBackgroundItem *item,
|
|
|
|
BgWallpapersSource *self)
|
2010-08-10 15:26:07 +01:00
|
|
|
{
|
2011-02-12 02:37:48 +00:00
|
|
|
load_wallpapers (NULL, item, self);
|
2010-11-21 22:06:26 -05:00
|
|
|
}
|
|
|
|
|
2011-02-12 03:12:52 +00:00
|
|
|
static void
|
|
|
|
load_default_bg (BgWallpapersSource *self)
|
|
|
|
{
|
|
|
|
const char * const *system_data_dirs;
|
|
|
|
char *filename;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* FIXME We could do this nicer if we had the XML source in GSettings */
|
|
|
|
|
|
|
|
system_data_dirs = g_get_system_data_dirs ();
|
|
|
|
for (i = 0; system_data_dirs[i]; i++) {
|
|
|
|
filename = g_build_filename (system_data_dirs[i],
|
|
|
|
"gnome-background-properties",
|
|
|
|
"adwaita.xml",
|
|
|
|
NULL);
|
|
|
|
if (cc_background_xml_load_xml (self->priv->xml, filename)) {
|
|
|
|
g_free (filename);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-17 11:59:58 +02:00
|
|
|
static void
|
|
|
|
bg_wallpapers_source_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
BgWallpapersSourcePrivate *priv = BG_WALLPAPERS_SOURCE (object)->priv;
|
|
|
|
|
|
|
|
g_clear_object (&priv->thumb_factory);
|
|
|
|
g_clear_object (&priv->xml);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2010-11-21 22:06:26 -05:00
|
|
|
static void
|
|
|
|
bg_wallpapers_source_init (BgWallpapersSource *self)
|
|
|
|
{
|
|
|
|
BgWallpapersSourcePrivate *priv;
|
|
|
|
|
|
|
|
priv = self->priv = WALLPAPERS_SOURCE_PRIVATE (self);
|
|
|
|
|
|
|
|
priv->thumb_factory =
|
2012-05-22 11:34:20 -04:00
|
|
|
gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
|
2011-02-12 02:37:48 +00:00
|
|
|
priv->xml = cc_background_xml_new ();
|
|
|
|
g_signal_connect (G_OBJECT (priv->xml), "added",
|
|
|
|
G_CALLBACK (item_added), self);
|
2011-02-12 03:12:52 +00:00
|
|
|
|
|
|
|
/* Try adding the default background first */
|
|
|
|
load_default_bg (self);
|
|
|
|
|
2011-02-12 02:37:48 +00:00
|
|
|
cc_background_xml_load_list_async (priv->xml, NULL, list_load_cb, self);
|
2010-08-10 15:26:07 +01:00
|
|
|
}
|
|
|
|
|
2014-06-17 11:59:58 +02:00
|
|
|
static void
|
|
|
|
bg_wallpapers_source_class_init (BgWallpapersSourceClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (BgWallpapersSourcePrivate));
|
|
|
|
|
|
|
|
object_class->dispose = bg_wallpapers_source_dispose;
|
|
|
|
}
|
|
|
|
|
2010-08-10 15:26:07 +01:00
|
|
|
BgWallpapersSource *
|
|
|
|
bg_wallpapers_source_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (BG_TYPE_WALLPAPERS_SOURCE, NULL);
|
|
|
|
}
|
|
|
|
|