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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Author: Thomas Wood <thomas.wood@intel.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "bg-wallpapers-source.h"
|
|
|
|
|
|
|
|
#include "gnome-wp-item.h"
|
|
|
|
#include "gnome-wp-xml.h"
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
GnomeDesktopThumbnailFactory *thumb_factory;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
bg_wallpapers_source_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bg_wallpapers_source_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bg_wallpapers_source_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
BgWallpapersSourcePrivate *priv = BG_WALLPAPERS_SOURCE (object)->priv;
|
|
|
|
|
|
|
|
if (priv->thumb_factory)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->thumb_factory);
|
|
|
|
priv->thumb_factory = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bg_wallpapers_source_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
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->get_property = bg_wallpapers_source_get_property;
|
|
|
|
object_class->set_property = bg_wallpapers_source_set_property;
|
|
|
|
object_class->dispose = bg_wallpapers_source_dispose;
|
|
|
|
object_class->finalize = bg_wallpapers_source_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_wallpaper (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GnomeBG *bg = data;
|
|
|
|
GnomeWPItem *item = value;
|
|
|
|
|
|
|
|
return item->bg == bg;
|
|
|
|
}
|
|
|
|
|
2010-09-20 18:01:27 +01:00
|
|
|
/* FIXME: Is this used for anything? */
|
2010-08-10 15:26:07 +01:00
|
|
|
static void
|
|
|
|
item_changed_cb (GnomeBG *bg,
|
|
|
|
GnomeWpXml *data)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GnomeWPItem *item;
|
|
|
|
|
|
|
|
item = g_hash_table_find (data->wp_hash, find_wallpaper, 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))
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (bg, G_CALLBACK (item_changed_cb), data);
|
|
|
|
|
|
|
|
pixbuf = gnome_wp_item_get_thumbnail (item,
|
|
|
|
data->thumb_factory,
|
|
|
|
data->thumb_width,
|
|
|
|
data->thumb_height);
|
|
|
|
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 (item_changed_cb),
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-08-10 17:01:15 +01:00
|
|
|
load_wallpapers (gchar *key,
|
|
|
|
GnomeWPItem *item,
|
|
|
|
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;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GdkPixbuf *pixbuf;
|
2010-08-10 17:01:15 +01:00
|
|
|
GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
if (item->deleted == TRUE)
|
|
|
|
return;
|
|
|
|
|
2010-08-10 17:01:15 +01:00
|
|
|
gtk_list_store_append (store, &iter);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
pixbuf = gnome_wp_item_get_thumbnail (item, priv->thumb_factory,
|
2010-08-25 19:18:05 +01:00
|
|
|
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
|
2010-08-10 15:26:07 +01:00
|
|
|
gnome_wp_item_update_description (item);
|
|
|
|
|
2010-08-10 17:01:15 +01:00
|
|
|
gtk_list_store_set (store, &iter,
|
2010-08-10 15:26:07 +01:00
|
|
|
0, pixbuf,
|
|
|
|
1, item,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
2010-08-10 17:01:15 +01:00
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
|
|
|
|
item->rowref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
|
2010-08-10 15:26:07 +01:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bg_wallpapers_source_init (BgWallpapersSource *self)
|
|
|
|
{
|
|
|
|
GnomeWpXml *wp_xml;
|
|
|
|
BgWallpapersSourcePrivate *priv;
|
|
|
|
|
|
|
|
priv = self->priv = WALLPAPERS_SOURCE_PRIVATE (self);
|
|
|
|
|
|
|
|
priv->thumb_factory =
|
|
|
|
gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
|
|
|
|
|
|
|
|
/* set up wallpaper source */
|
|
|
|
wp_xml = g_new0 (GnomeWpXml, 1);
|
|
|
|
wp_xml->wp_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
2010-10-14 14:57:35 +02:00
|
|
|
wp_xml->settings = g_settings_new (WP_PATH_ID);
|
2010-08-10 17:01:15 +01:00
|
|
|
wp_xml->wp_model = bg_source_get_liststore (BG_SOURCE (self));
|
2010-08-25 19:18:05 +01:00
|
|
|
wp_xml->thumb_width = THUMBNAIL_WIDTH;
|
|
|
|
wp_xml->thumb_height = THUMBNAIL_HEIGHT;
|
2010-08-10 15:26:07 +01:00
|
|
|
wp_xml->thumb_factory = priv->thumb_factory;
|
|
|
|
|
|
|
|
gnome_wp_xml_load_list (wp_xml);
|
|
|
|
g_hash_table_foreach (wp_xml->wp_hash,
|
|
|
|
(GHFunc) load_wallpapers,
|
2010-08-10 17:01:15 +01:00
|
|
|
self);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
g_hash_table_destroy (wp_xml->wp_hash);
|
2010-10-14 14:57:35 +02:00
|
|
|
g_object_unref (wp_xml->settings);
|
2010-08-10 15:26:07 +01:00
|
|
|
g_free (wp_xml);
|
|
|
|
}
|
|
|
|
|
|
|
|
BgWallpapersSource *
|
|
|
|
bg_wallpapers_source_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (BG_TYPE_WALLPAPERS_SOURCE, NULL);
|
|
|
|
}
|
|
|
|
|