2
* Authors: Rodney Dawes <dobey@ximian.com>
4
* Copyright 2003-2006 Novell, Inc. (www.novell.com)
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of version 2 of the GNU General Public License
8
* as published by the Free Software Foundation
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 Street #330, Boston, MA 02111-1307, USA.
23
#include <glib/gi18n.h>
24
#include <gconf/gconf-client.h>
26
#include "gnome-wp-item.h"
28
static GConfEnumStringPair options_lookup[] = {
29
{ GNOME_BG_PLACEMENT_CENTERED, "centered" },
30
{ GNOME_BG_PLACEMENT_FILL_SCREEN, "stretched" },
31
{ GNOME_BG_PLACEMENT_SCALED, "scaled" },
32
{ GNOME_BG_PLACEMENT_ZOOMED, "zoom" },
33
{ GNOME_BG_PLACEMENT_TILED, "wallpaper" },
34
{ GNOME_BG_PLACEMENT_SPANNED, "spanned" },
38
static GConfEnumStringPair shade_lookup[] = {
39
{ GNOME_BG_COLOR_SOLID, "solid" },
40
{ GNOME_BG_COLOR_H_GRADIENT, "horizontal-gradient" },
41
{ GNOME_BG_COLOR_V_GRADIENT, "vertical-gradient" },
45
const gchar *wp_item_option_to_string (GnomeBGPlacement type)
47
return gconf_enum_to_string (options_lookup, type);
50
const gchar *wp_item_shading_to_string (GnomeBGColorType type)
52
return gconf_enum_to_string (shade_lookup, type);
55
GnomeBGPlacement wp_item_string_to_option (const gchar *option)
57
int i = GNOME_BG_PLACEMENT_SCALED;
58
gconf_string_to_enum (options_lookup, option, &i);
62
GnomeBGColorType wp_item_string_to_shading (const gchar *shade_type)
64
int i = GNOME_BG_COLOR_SOLID;
65
gconf_string_to_enum (shade_lookup, shade_type, &i);
69
static void set_bg_properties (GnomeWPItem *item)
72
gnome_bg_set_filename (item->bg, item->filename);
74
gnome_bg_set_color (item->bg, item->shade_type, item->pcolor, item->scolor);
75
gnome_bg_set_placement (item->bg, item->options);
78
void gnome_wp_item_ensure_gnome_bg (GnomeWPItem *item)
81
item->bg = gnome_bg_new ();
83
set_bg_properties (item);
87
void gnome_wp_item_update (GnomeWPItem *item) {
89
GdkColor color1 = { 0, 0, 0, 0 }, color2 = { 0, 0, 0, 0 };
92
client = gconf_client_get_default ();
94
s = gconf_client_get_string (client, WP_OPTIONS_KEY, NULL);
95
item->options = wp_item_string_to_option (s);
98
s = gconf_client_get_string (client, WP_SHADING_KEY, NULL);
99
item->shade_type = wp_item_string_to_shading (s);
102
s = gconf_client_get_string (client, WP_PCOLOR_KEY, NULL);
104
gdk_color_parse (s, &color1);
108
s = gconf_client_get_string (client, WP_SCOLOR_KEY, NULL);
110
gdk_color_parse (s, &color2);
114
g_object_unref (client);
116
if (item->pcolor != NULL)
117
gdk_color_free (item->pcolor);
119
if (item->scolor != NULL)
120
gdk_color_free (item->scolor);
122
item->pcolor = gdk_color_copy (&color1);
123
item->scolor = gdk_color_copy (&color2);
126
GnomeWPItem * gnome_wp_item_new (const gchar * filename,
127
GHashTable * wallpapers,
128
GnomeDesktopThumbnailFactory * thumbnails) {
129
GnomeWPItem *item = g_new0 (GnomeWPItem, 1);
131
item->filename = g_strdup (filename);
132
item->fileinfo = gnome_wp_info_new (filename, thumbnails);
134
if (item->fileinfo != NULL && item->fileinfo->mime_type != NULL &&
135
(g_str_has_prefix (item->fileinfo->mime_type, "image/") ||
136
strcmp (item->fileinfo->mime_type, "application/xml") == 0)) {
138
if (g_utf8_validate (item->fileinfo->name, -1, NULL))
139
item->name = g_strdup (item->fileinfo->name);
141
item->name = g_filename_to_utf8 (item->fileinfo->name, -1, NULL,
144
gnome_wp_item_update (item);
145
gnome_wp_item_ensure_gnome_bg (item);
146
gnome_wp_item_update_description (item);
148
g_hash_table_insert (wallpapers, item->filename, item);
150
gnome_wp_item_free (item);
157
void gnome_wp_item_free (GnomeWPItem * item) {
163
g_free (item->filename);
164
g_free (item->description);
166
if (item->pcolor != NULL)
167
gdk_color_free (item->pcolor);
169
if (item->scolor != NULL)
170
gdk_color_free (item->scolor);
172
gnome_wp_info_free (item->fileinfo);
174
g_object_unref (item->bg);
176
gtk_tree_row_reference_free (item->rowref);
182
add_slideshow_frame (GdkPixbuf *pixbuf)
184
GdkPixbuf *sheet, *sheet2;
188
w = gdk_pixbuf_get_width (pixbuf);
189
h = gdk_pixbuf_get_height (pixbuf);
191
sheet = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, w, h);
192
gdk_pixbuf_fill (sheet, 0x00000000);
193
sheet2 = gdk_pixbuf_new_subpixbuf (sheet, 1, 1, w - 2, h - 2);
194
gdk_pixbuf_fill (sheet2, 0xffffffff);
195
g_object_unref (sheet2);
197
tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w + 6, h + 6);
199
gdk_pixbuf_fill (tmp, 0x00000000);
200
gdk_pixbuf_composite (sheet, tmp, 6, 6, w, h, 6.0, 6.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
201
gdk_pixbuf_composite (sheet, tmp, 3, 3, w, h, 3.0, 3.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
202
gdk_pixbuf_composite (pixbuf, tmp, 0, 0, w, h, 0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
204
g_object_unref (sheet);
209
GdkPixbuf * gnome_wp_item_get_frame_thumbnail (GnomeWPItem * item,
210
GnomeDesktopThumbnailFactory * thumbs,
214
GdkPixbuf *pixbuf = NULL;
216
set_bg_properties (item);
219
pixbuf = gnome_bg_create_frame_thumbnail (item->bg, thumbs, gdk_screen_get_default (), width, height, frame);
221
pixbuf = gnome_bg_create_thumbnail (item->bg, thumbs, gdk_screen_get_default(), width, height);
223
if (pixbuf && gnome_bg_changes_with_time (item->bg))
227
tmp = add_slideshow_frame (pixbuf);
228
g_object_unref (pixbuf);
232
gnome_bg_get_image_size (item->bg, thumbs, width, height, &item->width, &item->height);
238
GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item,
239
GnomeDesktopThumbnailFactory * thumbs,
242
return gnome_wp_item_get_frame_thumbnail (item, thumbs, width, height, -1);
245
void gnome_wp_item_update_description (GnomeWPItem * item) {
246
g_free (item->description);
248
if (!strcmp (item->filename, "(none)")) {
249
item->description = g_strdup (item->name);
251
const gchar *description;
253
gchar *dirname = g_path_get_dirname (item->filename);
258
if (strcmp (item->fileinfo->mime_type, "application/xml") == 0)
260
if (gnome_bg_changes_with_time (item->bg))
261
description = _("Slide Show");
262
else if (item->width > 0 && item->height > 0)
263
description = _("Image");
266
description = g_content_type_get_description (item->fileinfo->mime_type);
268
if (gnome_bg_has_multiple_sizes (item->bg))
269
size = g_strdup (_("multiple sizes"));
270
else if (item->width > 0 && item->height > 0) {
271
/* translators: x pixel(s) by y pixel(s) */
272
size = g_strdup_printf (_("%d %s by %d %s"),
274
ngettext ("pixel", "pixels", item->width),
276
ngettext ("pixel", "pixels", item->height));
279
if (description && size) {
280
/* translators: <b>wallpaper name</b>
282
* Folder: /path/to/file
284
item->description = g_markup_printf_escaped (_("<b>%s</b>\n"
292
/* translators: <b>wallpaper name</b>
294
* Folder: /path/to/file
296
item->description = g_markup_printf_escaped (_("<b>%s</b>\n"