2010-08-10 15:26:07 +01:00
|
|
|
|
/*
|
|
|
|
|
* Authors: Rodney Dawes <dobey@ximian.com>
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2003-2006 Novell, Inc. (www.novell.com)
|
|
|
|
|
*
|
|
|
|
|
* 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 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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
#include <string.h>
|
2011-02-10 12:29:29 +00:00
|
|
|
|
#include "cc-background-item.h"
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
|
|
static void set_bg_properties (GnomeWPItem *item)
|
|
|
|
|
{
|
|
|
|
|
if (!item->bg)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (item->filename)
|
|
|
|
|
gnome_bg_set_filename (item->bg, item->filename);
|
|
|
|
|
|
|
|
|
|
gnome_bg_set_color (item->bg, item->shade_type, item->pcolor, item->scolor);
|
|
|
|
|
gnome_bg_set_placement (item->bg, item->options);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
void cc_background_item_ensure_gnome_bg (GnomeWPItem *item)
|
2010-08-10 15:26:07 +01:00
|
|
|
|
{
|
2010-12-14 17:44:35 +00:00
|
|
|
|
if (!item->bg)
|
2010-08-10 15:26:07 +01:00
|
|
|
|
item->bg = gnome_bg_new ();
|
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (item->bg), "cc-background-item", item);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2010-12-14 17:44:35 +00:00
|
|
|
|
set_bg_properties (item);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
void cc_background_item_update (GnomeWPItem *item) {
|
2010-10-14 14:57:35 +02:00
|
|
|
|
GSettings *settings;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
GdkColor color1 = { 0, 0, 0, 0 }, color2 = { 0, 0, 0, 0 };
|
|
|
|
|
gchar *s;
|
|
|
|
|
|
2010-10-14 14:57:35 +02:00
|
|
|
|
settings = g_settings_new (WP_PATH_ID);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2010-10-14 14:57:35 +02:00
|
|
|
|
item->options = g_settings_get_enum (settings, WP_OPTIONS_KEY);
|
2010-12-15 17:56:28 +00:00
|
|
|
|
item->shade_type = g_settings_get_enum (settings, WP_SHADING_KEY);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2010-10-14 14:57:35 +02:00
|
|
|
|
s = g_settings_get_string (settings, WP_PCOLOR_KEY);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
if (s != NULL) {
|
|
|
|
|
gdk_color_parse (s, &color1);
|
|
|
|
|
g_free (s);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-14 14:57:35 +02:00
|
|
|
|
s = g_settings_get_string (settings, WP_SCOLOR_KEY);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
if (s != NULL) {
|
|
|
|
|
gdk_color_parse (s, &color2);
|
|
|
|
|
g_free (s);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-14 14:57:35 +02:00
|
|
|
|
g_object_unref (settings);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
|
|
if (item->pcolor != NULL)
|
|
|
|
|
gdk_color_free (item->pcolor);
|
|
|
|
|
|
|
|
|
|
if (item->scolor != NULL)
|
|
|
|
|
gdk_color_free (item->scolor);
|
|
|
|
|
|
|
|
|
|
item->pcolor = gdk_color_copy (&color1);
|
|
|
|
|
item->scolor = gdk_color_copy (&color2);
|
|
|
|
|
|
|
|
|
|
set_bg_properties (item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
GnomeWPItem * cc_background_item_new (const gchar * filename,
|
2010-08-10 15:26:07 +01:00
|
|
|
|
GHashTable * wallpapers,
|
2010-12-13 15:30:22 +00:00
|
|
|
|
GFileInfo * file_info,
|
2010-08-10 15:26:07 +01:00
|
|
|
|
GnomeDesktopThumbnailFactory * thumbnails) {
|
|
|
|
|
GnomeWPItem *item = g_new0 (GnomeWPItem, 1);
|
|
|
|
|
|
|
|
|
|
item->filename = g_strdup (filename);
|
2010-12-13 15:30:22 +00:00
|
|
|
|
item->fileinfo = gnome_wp_info_new (filename, file_info, thumbnails);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
|
|
if (item->fileinfo != NULL && item->fileinfo->mime_type != NULL &&
|
|
|
|
|
(g_str_has_prefix (item->fileinfo->mime_type, "image/") ||
|
|
|
|
|
strcmp (item->fileinfo->mime_type, "application/xml") == 0)) {
|
|
|
|
|
|
|
|
|
|
if (g_utf8_validate (item->fileinfo->name, -1, NULL))
|
|
|
|
|
item->name = g_strdup (item->fileinfo->name);
|
|
|
|
|
else
|
|
|
|
|
item->name = g_filename_to_utf8 (item->fileinfo->name, -1, NULL,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
cc_background_item_update (item);
|
|
|
|
|
cc_background_item_ensure_gnome_bg (item);
|
|
|
|
|
cc_background_item_update_size (item, NULL);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
|
|
if (wallpapers)
|
|
|
|
|
g_hash_table_insert (wallpapers, item->filename, item);
|
|
|
|
|
} else {
|
2011-02-10 12:29:29 +00:00
|
|
|
|
cc_background_item_free (item);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
item = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
void cc_background_item_free (GnomeWPItem * item) {
|
2010-08-10 15:26:07 +01:00
|
|
|
|
if (item == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (item->name);
|
|
|
|
|
g_free (item->filename);
|
2010-12-14 17:56:52 +00:00
|
|
|
|
g_free (item->size);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
|
|
if (item->pcolor != NULL)
|
|
|
|
|
gdk_color_free (item->pcolor);
|
|
|
|
|
|
|
|
|
|
if (item->scolor != NULL)
|
|
|
|
|
gdk_color_free (item->scolor);
|
|
|
|
|
|
|
|
|
|
gnome_wp_info_free (item->fileinfo);
|
|
|
|
|
if (item->bg)
|
|
|
|
|
g_object_unref (item->bg);
|
|
|
|
|
|
|
|
|
|
gtk_tree_row_reference_free (item->rowref);
|
|
|
|
|
|
2010-08-12 11:23:55 +01:00
|
|
|
|
g_free (item->source_url);
|
|
|
|
|
|
2010-08-10 15:26:07 +01:00
|
|
|
|
g_free (item);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 20:29:33 +00:00
|
|
|
|
static GEmblem *
|
|
|
|
|
get_slideshow_icon (void)
|
2010-08-10 15:26:07 +01:00
|
|
|
|
{
|
2010-12-14 20:29:33 +00:00
|
|
|
|
GIcon *themed;
|
|
|
|
|
GEmblem *emblem;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2010-12-14 20:29:33 +00:00
|
|
|
|
themed = g_themed_icon_new ("slideshow-emblem");
|
|
|
|
|
emblem = g_emblem_new_with_origin (themed, G_EMBLEM_ORIGIN_DEVICE);
|
|
|
|
|
g_object_unref (themed);
|
|
|
|
|
return emblem;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
GIcon * cc_background_item_get_frame_thumbnail (GnomeWPItem * item,
|
2010-08-10 15:26:07 +01:00
|
|
|
|
GnomeDesktopThumbnailFactory * thumbs,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
gint frame) {
|
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
2010-12-14 20:29:33 +00:00
|
|
|
|
GIcon *icon = NULL;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
|
|
set_bg_properties (item);
|
|
|
|
|
|
2010-12-14 20:29:33 +00:00
|
|
|
|
if (frame >= 0)
|
2010-08-10 15:26:07 +01:00
|
|
|
|
pixbuf = gnome_bg_create_frame_thumbnail (item->bg, thumbs, gdk_screen_get_default (), width, height, frame);
|
|
|
|
|
else
|
|
|
|
|
pixbuf = gnome_bg_create_thumbnail (item->bg, thumbs, gdk_screen_get_default(), width, height);
|
|
|
|
|
|
2010-12-14 20:29:33 +00:00
|
|
|
|
if (pixbuf && frame != -2 && gnome_bg_changes_with_time (item->bg))
|
2010-08-10 15:26:07 +01:00
|
|
|
|
{
|
2010-12-14 20:29:33 +00:00
|
|
|
|
GEmblem *emblem;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2010-12-14 20:29:33 +00:00
|
|
|
|
emblem = get_slideshow_icon ();
|
|
|
|
|
icon = g_emblemed_icon_new (G_ICON (pixbuf), emblem);
|
|
|
|
|
g_object_unref (emblem);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
g_object_unref (pixbuf);
|
2010-12-14 20:29:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
icon = G_ICON (pixbuf);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gnome_bg_get_image_size (item->bg, thumbs, width, height, &item->width, &item->height);
|
|
|
|
|
|
2010-12-14 20:29:33 +00:00
|
|
|
|
return icon;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
GIcon * cc_background_item_get_thumbnail (GnomeWPItem * item,
|
2010-08-10 15:26:07 +01:00
|
|
|
|
GnomeDesktopThumbnailFactory * thumbs,
|
|
|
|
|
gint width,
|
|
|
|
|
gint height) {
|
2011-02-10 12:29:29 +00:00
|
|
|
|
return cc_background_item_get_frame_thumbnail (item, thumbs, width, height, -1);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
void cc_background_item_update_size (GnomeWPItem * item,
|
2010-12-14 19:24:19 +00:00
|
|
|
|
GnomeDesktopThumbnailFactory * thumbs) {
|
2010-12-14 17:56:52 +00:00
|
|
|
|
g_free (item->size);
|
2010-12-14 19:24:19 +00:00
|
|
|
|
item->size = NULL;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
|
|
if (!strcmp (item->filename, "(none)")) {
|
2010-12-15 13:15:07 +00:00
|
|
|
|
item->size = g_strdup ("");
|
2010-08-10 15:26:07 +01:00
|
|
|
|
} else {
|
2010-12-14 20:29:33 +00:00
|
|
|
|
if (gnome_bg_has_multiple_sizes (item->bg) || gnome_bg_changes_with_time (item->bg))
|
2010-12-14 17:56:52 +00:00
|
|
|
|
item->size = g_strdup (_("multiple sizes"));
|
2010-12-14 19:24:19 +00:00
|
|
|
|
else {
|
|
|
|
|
if (thumbs != NULL && (item->width <= 0 || item->height <= 0)) {
|
|
|
|
|
gnome_bg_get_image_size (item->bg, thumbs, 1, 1, &item->width, &item->height);
|
|
|
|
|
}
|
|
|
|
|
if (item->width > 0 && item->height > 0) {
|
|
|
|
|
/* translators: 100 × 100px
|
|
|
|
|
* Note that this is not an "x", but U+00D7 MULTIPLICATION SIGN */
|
|
|
|
|
item->size = g_strdup_printf (_("%d \303\227 %d"),
|
|
|
|
|
item->width,
|
|
|
|
|
item->height);
|
|
|
|
|
} else {
|
|
|
|
|
item->size = g_strdup ("");
|
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|