File: | capplets/appearance/cafe-wp-item.c |
Warning: | line 60, column 7 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Authors: Rodney Dawes <dobey@ximian.com> |
3 | * |
4 | * Copyright 2003-2006 Novell, Inc. (www.novell.com) |
5 | * |
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 |
9 | * |
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. |
14 | * |
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 02110-1301, USA. |
18 | * |
19 | */ |
20 | |
21 | #include <config.h> |
22 | |
23 | #include <glib/gi18n.h> |
24 | #include <gio/gio.h> |
25 | #include <string.h> |
26 | #include "appearance.h" |
27 | #include "cafe-wp-item.h" |
28 | |
29 | const gchar *wp_item_option_to_string (CafeBGPlacement type) |
30 | { |
31 | switch (type) |
32 | { |
33 | case CAFE_BG_PLACEMENT_CENTERED: |
34 | return "centered"; |
35 | break; |
36 | case CAFE_BG_PLACEMENT_FILL_SCREEN: |
37 | return "stretched"; |
38 | break; |
39 | case CAFE_BG_PLACEMENT_SCALED: |
40 | return "scaled"; |
41 | break; |
42 | case CAFE_BG_PLACEMENT_ZOOMED: |
43 | return "zoom"; |
44 | break; |
45 | case CAFE_BG_PLACEMENT_TILED: |
46 | return "wallpaper"; |
47 | break; |
48 | case CAFE_BG_PLACEMENT_SPANNED: |
49 | return "spanned"; |
50 | break; |
51 | } |
52 | return ""; |
53 | } |
54 | |
55 | const gchar *wp_item_shading_to_string (CafeBGColorType type) |
56 | { |
57 | switch (type) { |
58 | case CAFE_BG_COLOR_SOLID: |
59 | return "solid"; |
60 | break; |
This statement is never executed | |
61 | case CAFE_BG_COLOR_H_GRADIENT: |
62 | return "horizontal-gradient"; |
63 | break; |
64 | case CAFE_BG_COLOR_V_GRADIENT: |
65 | return "vertical-gradient"; |
66 | break; |
67 | } |
68 | return ""; |
69 | } |
70 | |
71 | CafeBGPlacement wp_item_string_to_option (const gchar *option) |
72 | { |
73 | if (!g_strcmp0(option, "centered")) |
74 | return CAFE_BG_PLACEMENT_CENTERED; |
75 | else if (!g_strcmp0(option, "stretched")) |
76 | return CAFE_BG_PLACEMENT_FILL_SCREEN; |
77 | else if (!g_strcmp0(option, "scaled")) |
78 | return CAFE_BG_PLACEMENT_SCALED; |
79 | else if (!g_strcmp0(option, "zoom")) |
80 | return CAFE_BG_PLACEMENT_ZOOMED; |
81 | else if (!g_strcmp0(option, "wallpaper")) |
82 | return CAFE_BG_PLACEMENT_TILED; |
83 | else if (!g_strcmp0(option, "spanned")) |
84 | return CAFE_BG_PLACEMENT_SPANNED; |
85 | else |
86 | return CAFE_BG_PLACEMENT_SCALED; |
87 | } |
88 | |
89 | CafeBGColorType wp_item_string_to_shading (const gchar *shade_type) |
90 | { |
91 | if (!g_strcmp0(shade_type, "solid")) |
92 | return CAFE_BG_COLOR_SOLID; |
93 | else if (!g_strcmp0(shade_type, "horizontal-gradient")) |
94 | return CAFE_BG_COLOR_H_GRADIENT; |
95 | else if (!g_strcmp0(shade_type, "vertical-gradient")) |
96 | return CAFE_BG_COLOR_V_GRADIENT; |
97 | else |
98 | return CAFE_BG_COLOR_SOLID; |
99 | } |
100 | |
101 | static void set_bg_properties (CafeWPItem *item) |
102 | { |
103 | if (item->filename) |
104 | cafe_bg_set_filename (item->bg, item->filename); |
105 | |
106 | cafe_bg_set_color (item->bg, item->shade_type, item->pcolor, item->scolor); |
107 | cafe_bg_set_placement (item->bg, item->options); |
108 | } |
109 | |
110 | void cafe_wp_item_ensure_cafe_bg (CafeWPItem *item) |
111 | { |
112 | if (!item->bg) { |
113 | item->bg = cafe_bg_new (); |
114 | |
115 | set_bg_properties (item); |
116 | } |
117 | } |
118 | |
119 | void cafe_wp_item_update (CafeWPItem *item) { |
120 | GSettings *settings; |
121 | CdkRGBA color1 = { 0, 0, 0, 1.0 }, color2 = { 0, 0, 0, 1.0 }; |
122 | gchar *s; |
123 | |
124 | settings = g_settings_new (WP_SCHEMA"org.cafe.background"); |
125 | |
126 | item->options = g_settings_get_enum (settings, WP_OPTIONS_KEY"picture-options"); |
127 | |
128 | item->shade_type = g_settings_get_enum (settings, WP_SHADING_KEY"color-shading-type"); |
129 | |
130 | s = g_settings_get_string (settings, WP_PCOLOR_KEY"primary-color"); |
131 | if (s != NULL((void*)0)) { |
132 | cdk_rgba_parse (&color1, s); |
133 | g_free (s); |
134 | } |
135 | |
136 | s = g_settings_get_string (settings, WP_SCOLOR_KEY"secondary-color"); |
137 | if (s != NULL((void*)0)) { |
138 | cdk_rgba_parse (&color2, s); |
139 | g_free (s); |
140 | } |
141 | |
142 | g_object_unref (settings); |
143 | |
144 | if (item->pcolor != NULL((void*)0)) |
145 | cdk_rgba_free (item->pcolor); |
146 | |
147 | if (item->scolor != NULL((void*)0)) |
148 | cdk_rgba_free (item->scolor); |
149 | |
150 | item->pcolor = cdk_rgba_copy (&color1); |
151 | item->scolor = cdk_rgba_copy (&color2); |
152 | } |
153 | |
154 | CafeWPItem * cafe_wp_item_new (const gchar * filename, |
155 | GHashTable * wallpapers, |
156 | CafeDesktopThumbnailFactory * thumbnails) { |
157 | CafeWPItem *item = g_new0 (CafeWPItem, 1)((CafeWPItem *) g_malloc0_n ((1), sizeof (CafeWPItem))); |
158 | |
159 | item->filename = g_strdup (filename)g_strdup_inline (filename); |
160 | item->fileinfo = cafe_wp_info_new (filename, thumbnails); |
161 | |
162 | if (item->fileinfo != NULL((void*)0) && item->fileinfo->mime_type != NULL((void*)0) && |
163 | (g_str_has_prefix (item->fileinfo->mime_type, "image/")(__builtin_constant_p ("image/")? __extension__ ({ const char * const __str = (item->fileinfo->mime_type); const char * const __prefix = ("image/"); gboolean __result = (0); if ( __str == ((void*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix ) (__str, __prefix); else { const size_t __str_len = strlen ( ((__str) + !(__str))); const size_t __prefix_len = strlen ((( __prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len ) == 0; } __result; }) : (g_str_has_prefix) (item->fileinfo ->mime_type, "image/") ) || |
164 | strcmp (item->fileinfo->mime_type, "application/xml") == 0)) { |
165 | |
166 | if (g_utf8_validate (item->fileinfo->name, -1, NULL((void*)0))) |
167 | item->name = g_strdup (item->fileinfo->name)g_strdup_inline (item->fileinfo->name); |
168 | else |
169 | item->name = g_filename_to_utf8 (item->fileinfo->name, -1, NULL((void*)0), |
170 | NULL((void*)0), NULL((void*)0)); |
171 | |
172 | cafe_wp_item_update (item); |
173 | cafe_wp_item_ensure_cafe_bg (item); |
174 | cafe_wp_item_update_description (item); |
175 | |
176 | g_hash_table_insert (wallpapers, item->filename, item); |
177 | } else { |
178 | cafe_wp_item_free (item); |
179 | item = NULL((void*)0); |
180 | } |
181 | |
182 | return item; |
183 | } |
184 | |
185 | void cafe_wp_item_free (CafeWPItem * item) { |
186 | if (item == NULL((void*)0)) { |
187 | return; |
188 | } |
189 | |
190 | g_free (item->name); |
191 | g_free (item->filename); |
192 | g_free (item->description); |
193 | |
194 | if (item->pcolor != NULL((void*)0)) |
195 | cdk_rgba_free (item->pcolor); |
196 | |
197 | if (item->scolor != NULL((void*)0)) |
198 | cdk_rgba_free (item->scolor); |
199 | |
200 | cafe_wp_info_free (item->fileinfo); |
201 | if (item->bg) |
202 | g_object_unref (item->bg); |
203 | |
204 | ctk_tree_row_reference_free (item->rowref); |
205 | |
206 | g_free (item); |
207 | } |
208 | |
209 | static GdkPixbuf * |
210 | add_slideshow_frame (GdkPixbuf *pixbuf) |
211 | { |
212 | GdkPixbuf *sheet, *sheet2; |
213 | GdkPixbuf *tmp; |
214 | gint w, h; |
215 | |
216 | w = gdk_pixbuf_get_width (pixbuf); |
217 | h = gdk_pixbuf_get_height (pixbuf); |
218 | |
219 | sheet = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE(0), 8, w, h); |
220 | gdk_pixbuf_fill (sheet, 0x00000000); |
221 | sheet2 = gdk_pixbuf_new_subpixbuf (sheet, 1, 1, w - 2, h - 2); |
222 | gdk_pixbuf_fill (sheet2, 0xffffffff); |
223 | g_object_unref (sheet2); |
224 | |
225 | tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE(!(0)), 8, w + 6, h + 6); |
226 | |
227 | gdk_pixbuf_fill (tmp, 0x00000000); |
228 | gdk_pixbuf_composite (sheet, tmp, 6, 6, w, h, 6.0, 6.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255); |
229 | gdk_pixbuf_composite (sheet, tmp, 3, 3, w, h, 3.0, 3.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255); |
230 | gdk_pixbuf_composite (pixbuf, tmp, 0, 0, w, h, 0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255); |
231 | |
232 | g_object_unref (sheet); |
233 | |
234 | return tmp; |
235 | } |
236 | |
237 | GdkPixbuf * cafe_wp_item_get_frame_thumbnail (CafeWPItem * item, |
238 | CafeDesktopThumbnailFactory * thumbs, |
239 | int width, |
240 | int height, |
241 | gint frame) { |
242 | GdkPixbuf *pixbuf = NULL((void*)0); |
243 | |
244 | set_bg_properties (item); |
245 | |
246 | if (frame != -1) |
247 | pixbuf = cafe_bg_create_frame_thumbnail (item->bg, thumbs, cdk_screen_get_default (), width, height, frame); |
248 | else |
249 | pixbuf = cafe_bg_create_thumbnail (item->bg, thumbs, cdk_screen_get_default(), width, height); |
250 | |
251 | if (pixbuf && cafe_bg_changes_with_time (item->bg)) |
252 | { |
253 | GdkPixbuf *tmp; |
254 | |
255 | tmp = add_slideshow_frame (pixbuf); |
256 | g_object_unref (pixbuf); |
257 | pixbuf = tmp; |
258 | } |
259 | |
260 | cafe_bg_get_image_size (item->bg, thumbs, width, height, &item->width, &item->height); |
261 | |
262 | return pixbuf; |
263 | } |
264 | |
265 | |
266 | GdkPixbuf * cafe_wp_item_get_thumbnail (CafeWPItem * item, |
267 | CafeDesktopThumbnailFactory * thumbs, |
268 | gint width, |
269 | gint height) { |
270 | return cafe_wp_item_get_frame_thumbnail (item, thumbs, width, height, -1); |
271 | } |
272 | |
273 | void cafe_wp_item_update_description (CafeWPItem * item) { |
274 | g_free (item->description); |
275 | |
276 | if (!strcmp (item->filename, "(none)")) { |
277 | item->description = g_strdup (item->name)g_strdup_inline (item->name); |
278 | } else { |
279 | const gchar *description; |
280 | gchar *size; |
281 | gchar *dirname = g_path_get_dirname (item->filename); |
282 | gchar *artist; |
283 | |
284 | description = NULL((void*)0); |
285 | size = NULL((void*)0); |
286 | |
287 | if (!item->artist || item->artist[0] == 0 || !g_strcmp0(item->artist, "(none)")) |
288 | artist = g_strdup (_("unknown"))g_strdup_inline (gettext ("unknown")); |
289 | else |
290 | artist = g_strdup (item->artist)g_strdup_inline (item->artist); |
291 | |
292 | if (strcmp (item->fileinfo->mime_type, "application/xml") == 0) |
293 | { |
294 | if (cafe_bg_changes_with_time (item->bg)) |
295 | description = _("Slide Show")gettext ("Slide Show"); |
296 | else if (item->width > 0 && item->height > 0) |
297 | description = _("Image")gettext ("Image"); |
298 | } |
299 | else |
300 | description = g_content_type_get_description (item->fileinfo->mime_type); |
301 | |
302 | if (cafe_bg_has_multiple_sizes (item->bg)) |
303 | size = g_strdup (_("multiple sizes"))g_strdup_inline (gettext ("multiple sizes")); |
304 | else if (item->width > 0 && item->height > 0) { |
305 | /* translators: x pixel(s) by y pixel(s) */ |
306 | size = g_strdup_printf (_("%d %s by %d %s")gettext ("%d %s by %d %s"), |
307 | item->width, |
308 | ngettext ("pixel", "pixels", item->width), |
309 | item->height, |
310 | ngettext ("pixel", "pixels", item->height)); |
311 | } |
312 | |
313 | if (description && size) { |
314 | /* translators: <b>wallpaper name</b> |
315 | * mime type, size |
316 | * Folder: /path/to/file |
317 | * Artist: wallpaper author |
318 | */ |
319 | item->description = g_markup_printf_escaped (_("<b>%s</b>\n"gettext ("<b>%s</b>\n" "%s, %s\n" "Folder: %s\n" "Artist: %s" ) |
320 | "%s, %s\n"gettext ("<b>%s</b>\n" "%s, %s\n" "Folder: %s\n" "Artist: %s" ) |
321 | "Folder: %s\n"gettext ("<b>%s</b>\n" "%s, %s\n" "Folder: %s\n" "Artist: %s" ) |
322 | "Artist: %s")gettext ("<b>%s</b>\n" "%s, %s\n" "Folder: %s\n" "Artist: %s" ), |
323 | item->name, |
324 | description, |
325 | size, |
326 | dirname, |
327 | artist); |
328 | } else { |
329 | /* translators: <b>wallpaper name</b> |
330 | * Image missing |
331 | * Folder: /path/to/file |
332 | * Artist: wallpaper author |
333 | */ |
334 | item->description = g_markup_printf_escaped (_("<b>%s</b>\n"gettext ("<b>%s</b>\n" "%s\n" "Folder: %s\n" "Artist: %s" ) |
335 | "%s\n"gettext ("<b>%s</b>\n" "%s\n" "Folder: %s\n" "Artist: %s" ) |
336 | "Folder: %s\n"gettext ("<b>%s</b>\n" "%s\n" "Folder: %s\n" "Artist: %s" ) |
337 | "Artist: %s")gettext ("<b>%s</b>\n" "%s\n" "Folder: %s\n" "Artist: %s" ), |
338 | item->name, |
339 | _("Image missing")gettext ("Image missing"), |
340 | dirname, |
341 | artist); |
342 | } |
343 | |
344 | g_free (size); |
345 | g_free (dirname); |
346 | g_free (artist); |
347 | } |
348 | } |