~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to capplets/appearance/gnome-wp-item.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 02111-1307, USA.
18
 
 *
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
 
23
 
#include <glib/gi18n.h>
24
 
#include <gconf/gconf-client.h>
25
 
#include <string.h>
26
 
#include "gnome-wp-item.h"
27
 
 
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" },
35
 
  { 0, NULL }
36
 
};
37
 
 
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" },
42
 
  { 0, NULL }
43
 
};
44
 
 
45
 
const gchar *wp_item_option_to_string (GnomeBGPlacement type)
46
 
{
47
 
  return gconf_enum_to_string (options_lookup, type);
48
 
}
49
 
 
50
 
const gchar *wp_item_shading_to_string (GnomeBGColorType type)
51
 
{
52
 
  return gconf_enum_to_string (shade_lookup, type);
53
 
}
54
 
 
55
 
GnomeBGPlacement wp_item_string_to_option (const gchar *option)
56
 
{
57
 
  int i = GNOME_BG_PLACEMENT_SCALED;
58
 
  gconf_string_to_enum (options_lookup, option, &i);
59
 
  return i;
60
 
}
61
 
 
62
 
GnomeBGColorType wp_item_string_to_shading (const gchar *shade_type)
63
 
{
64
 
  int i = GNOME_BG_COLOR_SOLID;
65
 
  gconf_string_to_enum (shade_lookup, shade_type, &i);
66
 
  return i;
67
 
}
68
 
 
69
 
static void set_bg_properties (GnomeWPItem *item)
70
 
{
71
 
  if (item->filename)
72
 
    gnome_bg_set_filename (item->bg, item->filename);
73
 
 
74
 
  gnome_bg_set_color (item->bg, item->shade_type, item->pcolor, item->scolor);
75
 
  gnome_bg_set_placement (item->bg, item->options);
76
 
}
77
 
 
78
 
void gnome_wp_item_ensure_gnome_bg (GnomeWPItem *item)
79
 
{
80
 
  if (!item->bg) {
81
 
    item->bg = gnome_bg_new ();
82
 
 
83
 
    set_bg_properties (item);
84
 
  }
85
 
}
86
 
 
87
 
void gnome_wp_item_update (GnomeWPItem *item) {
88
 
  GConfClient *client;
89
 
  GdkColor color1 = { 0, 0, 0, 0 }, color2 = { 0, 0, 0, 0 };
90
 
  gchar *s;
91
 
 
92
 
  client = gconf_client_get_default ();
93
 
 
94
 
  s = gconf_client_get_string (client, WP_OPTIONS_KEY, NULL);
95
 
  item->options = wp_item_string_to_option (s);
96
 
  g_free (s);
97
 
 
98
 
  s = gconf_client_get_string (client, WP_SHADING_KEY, NULL);
99
 
  item->shade_type = wp_item_string_to_shading (s);
100
 
  g_free (s);
101
 
 
102
 
  s = gconf_client_get_string (client, WP_PCOLOR_KEY, NULL);
103
 
  if (s != NULL) {
104
 
    gdk_color_parse (s, &color1);
105
 
    g_free (s);
106
 
  }
107
 
 
108
 
  s = gconf_client_get_string (client, WP_SCOLOR_KEY, NULL);
109
 
  if (s != NULL) {
110
 
    gdk_color_parse (s, &color2);
111
 
    g_free (s);
112
 
  }
113
 
 
114
 
  g_object_unref (client);
115
 
 
116
 
  if (item->pcolor != NULL)
117
 
    gdk_color_free (item->pcolor);
118
 
 
119
 
  if (item->scolor != NULL)
120
 
    gdk_color_free (item->scolor);
121
 
 
122
 
  item->pcolor = gdk_color_copy (&color1);
123
 
  item->scolor = gdk_color_copy (&color2);
124
 
}
125
 
 
126
 
GnomeWPItem * gnome_wp_item_new (const gchar * filename,
127
 
                                 GHashTable * wallpapers,
128
 
                                 GnomeDesktopThumbnailFactory * thumbnails) {
129
 
  GnomeWPItem *item = g_new0 (GnomeWPItem, 1);
130
 
 
131
 
  item->filename = g_strdup (filename);
132
 
  item->fileinfo = gnome_wp_info_new (filename, thumbnails);
133
 
 
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)) {
137
 
 
138
 
    if (g_utf8_validate (item->fileinfo->name, -1, NULL))
139
 
      item->name = g_strdup (item->fileinfo->name);
140
 
    else
141
 
      item->name = g_filename_to_utf8 (item->fileinfo->name, -1, NULL,
142
 
                                       NULL, NULL);
143
 
 
144
 
    gnome_wp_item_update (item);
145
 
    gnome_wp_item_ensure_gnome_bg (item);
146
 
    gnome_wp_item_update_description (item);
147
 
 
148
 
    g_hash_table_insert (wallpapers, item->filename, item);
149
 
  } else {
150
 
    gnome_wp_item_free (item);
151
 
    item = NULL;
152
 
  }
153
 
 
154
 
  return item;
155
 
}
156
 
 
157
 
void gnome_wp_item_free (GnomeWPItem * item) {
158
 
  if (item == NULL) {
159
 
    return;
160
 
  }
161
 
 
162
 
  g_free (item->name);
163
 
  g_free (item->filename);
164
 
  g_free (item->description);
165
 
 
166
 
  if (item->pcolor != NULL)
167
 
    gdk_color_free (item->pcolor);
168
 
 
169
 
  if (item->scolor != NULL)
170
 
    gdk_color_free (item->scolor);
171
 
 
172
 
  gnome_wp_info_free (item->fileinfo);
173
 
  if (item->bg)
174
 
    g_object_unref (item->bg);
175
 
 
176
 
  gtk_tree_row_reference_free (item->rowref);
177
 
 
178
 
  g_free (item);
179
 
}
180
 
 
181
 
static GdkPixbuf *
182
 
add_slideshow_frame (GdkPixbuf *pixbuf)
183
 
{
184
 
  GdkPixbuf *sheet, *sheet2;
185
 
  GdkPixbuf *tmp;
186
 
  gint w, h;
187
 
 
188
 
  w = gdk_pixbuf_get_width (pixbuf);
189
 
  h = gdk_pixbuf_get_height (pixbuf);
190
 
 
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);
196
 
 
197
 
  tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w + 6, h + 6);
198
 
 
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);
203
 
 
204
 
  g_object_unref (sheet);
205
 
 
206
 
  return tmp;
207
 
}
208
 
 
209
 
GdkPixbuf * gnome_wp_item_get_frame_thumbnail (GnomeWPItem * item,
210
 
                                               GnomeDesktopThumbnailFactory * thumbs,
211
 
                                               int width,
212
 
                                               int height,
213
 
                                               gint frame) {
214
 
  GdkPixbuf *pixbuf = NULL;
215
 
 
216
 
  set_bg_properties (item);
217
 
 
218
 
  if (frame != -1)
219
 
    pixbuf = gnome_bg_create_frame_thumbnail (item->bg, thumbs, gdk_screen_get_default (), width, height, frame);
220
 
  else
221
 
    pixbuf = gnome_bg_create_thumbnail (item->bg, thumbs, gdk_screen_get_default(), width, height);
222
 
 
223
 
  if (pixbuf && gnome_bg_changes_with_time (item->bg))
224
 
    {
225
 
      GdkPixbuf *tmp;
226
 
 
227
 
      tmp = add_slideshow_frame (pixbuf);
228
 
      g_object_unref (pixbuf);
229
 
      pixbuf = tmp;
230
 
    }
231
 
 
232
 
  gnome_bg_get_image_size (item->bg, thumbs, width, height, &item->width, &item->height);
233
 
 
234
 
  return pixbuf;
235
 
}
236
 
 
237
 
 
238
 
GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item,
239
 
                                         GnomeDesktopThumbnailFactory * thumbs,
240
 
                                         gint width,
241
 
                                         gint height) {
242
 
  return gnome_wp_item_get_frame_thumbnail (item, thumbs, width, height, -1);
243
 
}
244
 
 
245
 
void gnome_wp_item_update_description (GnomeWPItem * item) {
246
 
  g_free (item->description);
247
 
 
248
 
  if (!strcmp (item->filename, "(none)")) {
249
 
    item->description = g_strdup (item->name);
250
 
  } else {
251
 
    const gchar *description;
252
 
    gchar *size;
253
 
    gchar *dirname = g_path_get_dirname (item->filename);
254
 
 
255
 
    description = NULL;
256
 
    size = NULL;
257
 
 
258
 
    if (strcmp (item->fileinfo->mime_type, "application/xml") == 0)
259
 
      {
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");
264
 
      }
265
 
    else
266
 
      description = g_content_type_get_description (item->fileinfo->mime_type);
267
 
 
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"),
273
 
                              item->width,
274
 
                              ngettext ("pixel", "pixels", item->width),
275
 
                              item->height,
276
 
                              ngettext ("pixel", "pixels", item->height));
277
 
    }
278
 
 
279
 
    if (description && size) {
280
 
      /* translators: <b>wallpaper name</b>
281
 
       * mime type, size
282
 
       * Folder: /path/to/file
283
 
       */
284
 
      item->description = g_markup_printf_escaped (_("<b>%s</b>\n"
285
 
                                                     "%s, %s\n"
286
 
                                                     "Folder: %s"),
287
 
                                                   item->name,
288
 
                                                   description,
289
 
                                                   size,
290
 
                                                   dirname);
291
 
    } else {
292
 
      /* translators: <b>wallpaper name</b>
293
 
       * Image missing
294
 
       * Folder: /path/to/file
295
 
       */
296
 
      item->description = g_markup_printf_escaped (_("<b>%s</b>\n"
297
 
                                                     "%s\n"
298
 
                                                     "Folder: %s"),
299
 
                                                   item->name,
300
 
                                                   _("Image missing"),
301
 
                                                   dirname);
302
 
    }
303
 
 
304
 
    g_free (size);
305
 
    g_free (dirname);
306
 
  }
307
 
}