1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
/*
* 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 02110-1301, USA.
*
*/
#include <config.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
#include <string.h>
#include "appearance.h"
#include "mate-wp-item.h"
const gchar *wp_item_option_to_string (MateBGPlacement type)
{
switch (type)
{
case MATE_BG_PLACEMENT_CENTERED:
return "centered";
break;
case MATE_BG_PLACEMENT_FILL_SCREEN:
return "stretched";
break;
case MATE_BG_PLACEMENT_SCALED:
return "scaled";
break;
case MATE_BG_PLACEMENT_ZOOMED:
return "zoom";
break;
case MATE_BG_PLACEMENT_TILED:
return "wallpaper";
break;
case MATE_BG_PLACEMENT_SPANNED:
return "spanned";
break;
}
return "";
}
const gchar *wp_item_shading_to_string (MateBGColorType type)
{
switch (type) {
case MATE_BG_COLOR_SOLID:
return "solid";
break;
case MATE_BG_COLOR_H_GRADIENT:
return "horizontal-gradient";
break;
case MATE_BG_COLOR_V_GRADIENT:
return "vertical-gradient";
break;
}
return "";
}
MateBGPlacement wp_item_string_to_option (const gchar *option)
{
if (!g_strcmp0(option, "centered"))
return MATE_BG_PLACEMENT_CENTERED;
else if (!g_strcmp0(option, "stretched"))
return MATE_BG_PLACEMENT_FILL_SCREEN;
else if (!g_strcmp0(option, "scaled"))
return MATE_BG_PLACEMENT_SCALED;
else if (!g_strcmp0(option, "zoom"))
return MATE_BG_PLACEMENT_ZOOMED;
else if (!g_strcmp0(option, "wallpaper"))
return MATE_BG_PLACEMENT_TILED;
else if (!g_strcmp0(option, "spanned"))
return MATE_BG_PLACEMENT_SPANNED;
else
return MATE_BG_PLACEMENT_SCALED;
}
MateBGColorType wp_item_string_to_shading (const gchar *shade_type)
{
if (!g_strcmp0(shade_type, "solid"))
return MATE_BG_COLOR_SOLID;
else if (!g_strcmp0(shade_type, "horizontal-gradient"))
return MATE_BG_COLOR_H_GRADIENT;
else if (!g_strcmp0(shade_type, "vertical-gradient"))
return MATE_BG_COLOR_V_GRADIENT;
else
return MATE_BG_COLOR_SOLID;
}
static void set_bg_properties (MateWPItem *item)
{
if (item->filename)
mate_bg_set_filename (item->bg, item->filename);
mate_bg_set_color (item->bg, item->shade_type, item->pcolor, item->scolor);
mate_bg_set_placement (item->bg, item->options);
}
void mate_wp_item_ensure_mate_bg (MateWPItem *item)
{
if (!item->bg) {
item->bg = mate_bg_new ();
set_bg_properties (item);
}
}
void mate_wp_item_update (MateWPItem *item) {
GSettings *settings;
#if GTK_CHECK_VERSION (3, 0, 0)
GdkRGBA color1 = { 0, 0, 0, 1.0 }, color2 = { 0, 0, 0, 1.0 };
#else
GdkColor color1 = { 0, 0, 0, 0 }, color2 = { 0, 0, 0, 0 };
#endif
gchar *s;
settings = g_settings_new (WP_SCHEMA);
item->options = g_settings_get_enum (settings, WP_OPTIONS_KEY);
item->shade_type = g_settings_get_enum (settings, WP_SHADING_KEY);
s = g_settings_get_string (settings, WP_PCOLOR_KEY);
if (s != NULL) {
#if GTK_CHECK_VERSION (3, 0, 0)
gdk_rgba_parse (&color1, s);
#else
gdk_color_parse (s, &color1);
#endif
g_free (s);
}
s = g_settings_get_string (settings, WP_SCOLOR_KEY);
if (s != NULL) {
#if GTK_CHECK_VERSION (3, 0, 0)
gdk_rgba_parse (&color2, s);
#else
gdk_color_parse (s, &color2);
#endif
g_free (s);
}
g_object_unref (settings);
if (item->pcolor != NULL)
#if GTK_CHECK_VERSION (3, 0, 0)
gdk_rgba_free (item->pcolor);
#else
gdk_color_free (item->pcolor);
#endif
if (item->scolor != NULL)
#if GTK_CHECK_VERSION (3, 0, 0)
gdk_rgba_free (item->scolor);
item->pcolor = gdk_rgba_copy (&color1);
item->scolor = gdk_rgba_copy (&color2);
#else
gdk_color_free (item->scolor);
item->pcolor = gdk_color_copy (&color1);
item->scolor = gdk_color_copy (&color2);
#endif
}
MateWPItem * mate_wp_item_new (const gchar * filename,
GHashTable * wallpapers,
MateDesktopThumbnailFactory * thumbnails) {
MateWPItem *item = g_new0 (MateWPItem, 1);
item->filename = g_strdup (filename);
item->fileinfo = mate_wp_info_new (filename, thumbnails);
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);
mate_wp_item_update (item);
mate_wp_item_ensure_mate_bg (item);
mate_wp_item_update_description (item);
g_hash_table_insert (wallpapers, item->filename, item);
} else {
mate_wp_item_free (item);
item = NULL;
}
return item;
}
void mate_wp_item_free (MateWPItem * item) {
if (item == NULL) {
return;
}
g_free (item->name);
g_free (item->filename);
g_free (item->description);
if (item->pcolor != NULL)
#if GTK_CHECK_VERSION (3, 0, 0)
gdk_rgba_free (item->pcolor);
if (item->scolor != NULL)
gdk_rgba_free (item->scolor);
#else
gdk_color_free (item->pcolor);
if (item->scolor != NULL)
gdk_color_free (item->scolor);
#endif
mate_wp_info_free (item->fileinfo);
if (item->bg)
g_object_unref (item->bg);
gtk_tree_row_reference_free (item->rowref);
g_free (item);
}
static GdkPixbuf *
add_slideshow_frame (GdkPixbuf *pixbuf)
{
GdkPixbuf *sheet, *sheet2;
GdkPixbuf *tmp;
gint w, h;
w = gdk_pixbuf_get_width (pixbuf);
h = gdk_pixbuf_get_height (pixbuf);
sheet = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, w, h);
gdk_pixbuf_fill (sheet, 0x00000000);
sheet2 = gdk_pixbuf_new_subpixbuf (sheet, 1, 1, w - 2, h - 2);
gdk_pixbuf_fill (sheet2, 0xffffffff);
g_object_unref (sheet2);
tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w + 6, h + 6);
gdk_pixbuf_fill (tmp, 0x00000000);
gdk_pixbuf_composite (sheet, tmp, 6, 6, w, h, 6.0, 6.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
gdk_pixbuf_composite (sheet, tmp, 3, 3, w, h, 3.0, 3.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
gdk_pixbuf_composite (pixbuf, tmp, 0, 0, w, h, 0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
g_object_unref (sheet);
return tmp;
}
GdkPixbuf * mate_wp_item_get_frame_thumbnail (MateWPItem * item,
MateDesktopThumbnailFactory * thumbs,
int width,
int height,
gint frame) {
GdkPixbuf *pixbuf = NULL;
set_bg_properties (item);
if (frame != -1)
pixbuf = mate_bg_create_frame_thumbnail (item->bg, thumbs, gdk_screen_get_default (), width, height, frame);
else
pixbuf = mate_bg_create_thumbnail (item->bg, thumbs, gdk_screen_get_default(), width, height);
if (pixbuf && mate_bg_changes_with_time (item->bg))
{
GdkPixbuf *tmp;
tmp = add_slideshow_frame (pixbuf);
g_object_unref (pixbuf);
pixbuf = tmp;
}
mate_bg_get_image_size (item->bg, thumbs, width, height, &item->width, &item->height);
return pixbuf;
}
GdkPixbuf * mate_wp_item_get_thumbnail (MateWPItem * item,
MateDesktopThumbnailFactory * thumbs,
gint width,
gint height) {
return mate_wp_item_get_frame_thumbnail (item, thumbs, width, height, -1);
}
void mate_wp_item_update_description (MateWPItem * item) {
g_free (item->description);
if (!strcmp (item->filename, "(none)")) {
item->description = g_strdup (item->name);
} else {
const gchar *description;
gchar *size;
gchar *dirname = g_path_get_dirname (item->filename);
gchar *artist;
description = NULL;
size = NULL;
if (!item->artist || item->artist[0] == 0 || !g_strcmp0(item->artist, "(none)"))
artist = g_strdup (_("unknown"));
else
artist = g_strdup (item->artist);
if (strcmp (item->fileinfo->mime_type, "application/xml") == 0)
{
if (mate_bg_changes_with_time (item->bg))
description = _("Slide Show");
else if (item->width > 0 && item->height > 0)
description = _("Image");
}
else
description = g_content_type_get_description (item->fileinfo->mime_type);
if (mate_bg_has_multiple_sizes (item->bg))
size = g_strdup (_("multiple sizes"));
else if (item->width > 0 && item->height > 0) {
/* translators: x pixel(s) by y pixel(s) */
size = g_strdup_printf (_("%d %s by %d %s"),
item->width,
ngettext ("pixel", "pixels", item->width),
item->height,
ngettext ("pixel", "pixels", item->height));
}
if (description && size) {
/* translators: <b>wallpaper name</b>
* mime type, size
* Folder: /path/to/file
* Artist: wallpaper author
*/
item->description = g_markup_printf_escaped (_("<b>%s</b>\n"
"%s, %s\n"
"Folder: %s\n"
"Artist: %s"),
item->name,
description,
size,
dirname,
artist);
} else {
/* translators: <b>wallpaper name</b>
* Image missing
* Folder: /path/to/file
* Artist: wallpaper author
*/
item->description = g_markup_printf_escaped (_("<b>%s</b>\n"
"%s\n"
"Folder: %s\n"
"Artist: %s"),
item->name,
_("Image missing"),
dirname,
artist);
}
g_free (size);
g_free (dirname);
g_free (artist);
}
}
|