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

« back to all changes in this revision

Viewing changes to panels/background/bg-wallpapers-source.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
/* bg-wallpapers-source.c */
 
2
/*
 
3
 * Copyright (C) 2010 Intel, Inc
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
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 Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * Author: Thomas Wood <thomas.wood@intel.com>
 
20
 *
 
21
 */
 
22
 
 
23
 
 
24
#include "bg-wallpapers-source.h"
 
25
 
 
26
#include "cc-background-item.h"
 
27
#include "cc-background-xml.h"
 
28
 
 
29
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
 
30
#include <gio/gio.h>
 
31
 
 
32
G_DEFINE_TYPE (BgWallpapersSource, bg_wallpapers_source, BG_TYPE_SOURCE)
 
33
 
 
34
#define WALLPAPERS_SOURCE_PRIVATE(o) \
 
35
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_WALLPAPERS_SOURCE, BgWallpapersSourcePrivate))
 
36
 
 
37
struct _BgWallpapersSourcePrivate
 
38
{
 
39
  GnomeDesktopThumbnailFactory *thumb_factory;
 
40
  CcBackgroundXml *xml;
 
41
};
 
42
 
 
43
 
 
44
static void
 
45
bg_wallpapers_source_get_property (GObject    *object,
 
46
                                   guint       property_id,
 
47
                                   GValue     *value,
 
48
                                   GParamSpec *pspec)
 
49
{
 
50
  switch (property_id)
 
51
    {
 
52
    default:
 
53
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
54
    }
 
55
}
 
56
 
 
57
static void
 
58
bg_wallpapers_source_set_property (GObject      *object,
 
59
                                    guint         property_id,
 
60
                                    const GValue *value,
 
61
                                    GParamSpec   *pspec)
 
62
{
 
63
  switch (property_id)
 
64
    {
 
65
    default:
 
66
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
67
    }
 
68
}
 
69
 
 
70
static void
 
71
bg_wallpapers_source_dispose (GObject *object)
 
72
{
 
73
  BgWallpapersSourcePrivate *priv = BG_WALLPAPERS_SOURCE (object)->priv;
 
74
 
 
75
  if (priv->thumb_factory)
 
76
    {
 
77
      g_object_unref (priv->thumb_factory);
 
78
      priv->thumb_factory = NULL;
 
79
    }
 
80
  if (priv->xml)
 
81
    {
 
82
      g_object_unref (priv->xml);
 
83
      priv->xml = NULL;
 
84
    }
 
85
 
 
86
  G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->dispose (object);
 
87
}
 
88
 
 
89
static void
 
90
bg_wallpapers_source_finalize (GObject *object)
 
91
{
 
92
  G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->finalize (object);
 
93
}
 
94
 
 
95
static void
 
96
bg_wallpapers_source_class_init (BgWallpapersSourceClass *klass)
 
97
{
 
98
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
99
 
 
100
  g_type_class_add_private (klass, sizeof (BgWallpapersSourcePrivate));
 
101
 
 
102
  object_class->get_property = bg_wallpapers_source_get_property;
 
103
  object_class->set_property = bg_wallpapers_source_set_property;
 
104
  object_class->dispose = bg_wallpapers_source_dispose;
 
105
  object_class->finalize = bg_wallpapers_source_finalize;
 
106
}
 
107
 
 
108
static void
 
109
load_wallpapers (gchar              *key,
 
110
                 CcBackgroundItem   *item,
 
111
                 BgWallpapersSource *source)
 
112
{
 
113
  BgWallpapersSourcePrivate *priv = source->priv;
 
114
  GtkTreeIter iter;
 
115
  GIcon *pixbuf;
 
116
  GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
 
117
  gboolean deleted;
 
118
 
 
119
  g_object_get (G_OBJECT (item), "is-deleted", &deleted, NULL);
 
120
 
 
121
  if (deleted)
 
122
    return;
 
123
 
 
124
  gtk_list_store_append (store, &iter);
 
125
 
 
126
  pixbuf = cc_background_item_get_thumbnail (item, priv->thumb_factory,
 
127
                                             THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
 
128
 
 
129
  gtk_list_store_set (store, &iter,
 
130
                      0, pixbuf,
 
131
                      1, g_object_ref (item),
 
132
                      -1);
 
133
 
 
134
  if (pixbuf)
 
135
    g_object_unref (pixbuf);
 
136
}
 
137
 
 
138
static void
 
139
list_load_cb (GObject *source_object,
 
140
              GAsyncResult *res,
 
141
              gpointer user_data)
 
142
{
 
143
  cc_background_xml_load_list_finish (res);
 
144
}
 
145
 
 
146
static void
 
147
item_added (CcBackgroundXml    *xml,
 
148
            CcBackgroundItem   *item,
 
149
            BgWallpapersSource *self)
 
150
{
 
151
  load_wallpapers (NULL, item, self);
 
152
}
 
153
 
 
154
static void
 
155
load_default_bg (BgWallpapersSource *self)
 
156
{
 
157
  const char * const *system_data_dirs;
 
158
  char *filename;
 
159
  guint i;
 
160
 
 
161
  /* FIXME We could do this nicer if we had the XML source in GSettings */
 
162
 
 
163
  system_data_dirs = g_get_system_data_dirs ();
 
164
  for (i = 0; system_data_dirs[i]; i++) {
 
165
    filename = g_build_filename (system_data_dirs[i],
 
166
                                 "gnome-background-properties",
 
167
                                 "adwaita.xml",
 
168
                                 NULL);
 
169
    if (cc_background_xml_load_xml (self->priv->xml, filename)) {
 
170
      g_free (filename);
 
171
      break;
 
172
    }
 
173
    g_free (filename);
 
174
  }
 
175
}
 
176
 
 
177
static void
 
178
bg_wallpapers_source_init (BgWallpapersSource *self)
 
179
{
 
180
  BgWallpapersSourcePrivate *priv;
 
181
 
 
182
  priv = self->priv = WALLPAPERS_SOURCE_PRIVATE (self);
 
183
 
 
184
  priv->thumb_factory =
 
185
    gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
 
186
  priv->xml = cc_background_xml_new ();
 
187
  g_signal_connect (G_OBJECT (priv->xml), "added",
 
188
                    G_CALLBACK (item_added), self);
 
189
 
 
190
  /* Try adding the default background first */
 
191
  load_default_bg (self);
 
192
 
 
193
  cc_background_xml_load_list_async (priv->xml, NULL, list_load_cb, self);
 
194
}
 
195
 
 
196
BgWallpapersSource *
 
197
bg_wallpapers_source_new (void)
 
198
{
 
199
  return g_object_new (BG_TYPE_WALLPAPERS_SOURCE, NULL);
 
200
}
 
201