~ubuntu-branches/ubuntu/trusty/unity-control-center/trusty

« back to all changes in this revision

Viewing changes to panels/appearance/bg-wallpapers-source.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-01-08 16:29:18 UTC
  • Revision ID: package-import@ubuntu.com-20140108162918-g29dd08tr913y2qh
Tags: upstream-14.04.0
ImportĀ upstreamĀ versionĀ 14.04.0

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, see <http://www.gnu.org/licenses/>.
 
17
 *
 
18
 * Author: Thomas Wood <thomas.wood@intel.com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "bg-wallpapers-source.h"
 
24
 
 
25
#include "cc-appearance-item.h"
 
26
#include "cc-appearance-xml.h"
 
27
 
 
28
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
 
29
#include <gio/gio.h>
 
30
 
 
31
G_DEFINE_TYPE (BgWallpapersSource, bg_wallpapers_source, BG_TYPE_SOURCE)
 
32
 
 
33
#define WALLPAPERS_SOURCE_PRIVATE(o) \
 
34
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_WALLPAPERS_SOURCE, BgWallpapersSourcePrivate))
 
35
 
 
36
struct _BgWallpapersSourcePrivate
 
37
{
 
38
  GnomeDesktopThumbnailFactory *thumb_factory;
 
39
  CcAppearanceXml *xml;
 
40
};
 
41
 
 
42
 
 
43
static void
 
44
bg_wallpapers_source_get_property (GObject    *object,
 
45
                                   guint       property_id,
 
46
                                   GValue     *value,
 
47
                                   GParamSpec *pspec)
 
48
{
 
49
  switch (property_id)
 
50
    {
 
51
    default:
 
52
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
53
    }
 
54
}
 
55
 
 
56
static void
 
57
bg_wallpapers_source_set_property (GObject      *object,
 
58
                                    guint         property_id,
 
59
                                    const GValue *value,
 
60
                                    GParamSpec   *pspec)
 
61
{
 
62
  switch (property_id)
 
63
    {
 
64
    default:
 
65
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
66
    }
 
67
}
 
68
 
 
69
static void
 
70
bg_wallpapers_source_dispose (GObject *object)
 
71
{
 
72
  BgWallpapersSourcePrivate *priv = BG_WALLPAPERS_SOURCE (object)->priv;
 
73
 
 
74
  if (priv->thumb_factory)
 
75
    {
 
76
      g_object_unref (priv->thumb_factory);
 
77
      priv->thumb_factory = NULL;
 
78
    }
 
79
  if (priv->xml)
 
80
    {
 
81
      g_object_unref (priv->xml);
 
82
      priv->xml = NULL;
 
83
    }
 
84
 
 
85
  G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->dispose (object);
 
86
}
 
87
 
 
88
static void
 
89
bg_wallpapers_source_finalize (GObject *object)
 
90
{
 
91
  G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->finalize (object);
 
92
}
 
93
 
 
94
static void
 
95
bg_wallpapers_source_class_init (BgWallpapersSourceClass *klass)
 
96
{
 
97
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
98
 
 
99
  g_type_class_add_private (klass, sizeof (BgWallpapersSourcePrivate));
 
100
 
 
101
  object_class->get_property = bg_wallpapers_source_get_property;
 
102
  object_class->set_property = bg_wallpapers_source_set_property;
 
103
  object_class->dispose = bg_wallpapers_source_dispose;
 
104
  object_class->finalize = bg_wallpapers_source_finalize;
 
105
}
 
106
 
 
107
static void
 
108
load_wallpapers (gchar              *key,
 
109
                 CcAppearanceItem   *item,
 
110
                 BgWallpapersSource *source)
 
111
{
 
112
  BgWallpapersSourcePrivate *priv = source->priv;
 
113
  GtkTreeIter iter;
 
114
  GIcon *pixbuf;
 
115
  GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
 
116
  gboolean deleted;
 
117
 
 
118
  g_object_get (G_OBJECT (item), "is-deleted", &deleted, NULL);
 
119
 
 
120
  if (deleted)
 
121
    return;
 
122
 
 
123
  gtk_list_store_append (store, &iter);
 
124
 
 
125
  pixbuf = cc_appearance_item_get_thumbnail (item, priv->thumb_factory,
 
126
                                             THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
 
127
 
 
128
  gtk_list_store_set (store, &iter,
 
129
                      0, pixbuf,
 
130
                      1, g_object_ref (item),
 
131
                      2, cc_appearance_item_get_name (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_appearance_xml_load_list_finish (res);
 
144
}
 
145
 
 
146
static void
 
147
item_added (CcAppearanceXml    *xml,
 
148
            CcAppearanceItem   *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_appearance_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_appearance_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_appearance_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