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

« back to all changes in this revision

Viewing changes to panels/background/bg-flickr-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-flickr-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
#include "bg-flickr-source.h"
 
24
 
 
25
#include <libsocialweb-client/sw-client.h>
 
26
#include <libsocialweb-client/sw-item.h>
 
27
#include <libsocialweb-client/sw-client-service.h>
 
28
 
 
29
#include "cc-background-item.h"
 
30
#include <gdesktop-enums.h>
 
31
 
 
32
G_DEFINE_TYPE (BgFlickrSource, bg_flickr_source, BG_TYPE_SOURCE)
 
33
 
 
34
#define FLICKR_SOURCE_PRIVATE(o) \
 
35
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_FLICKR_SOURCE, BgFlickrSourcePrivate))
 
36
 
 
37
struct _BgFlickrSourcePrivate
 
38
{
 
39
  SwClient *client;
 
40
  SwClientService *service;
 
41
};
 
42
 
 
43
 
 
44
static void
 
45
bg_flickr_source_dispose (GObject *object)
 
46
{
 
47
  BgFlickrSourcePrivate *priv = BG_FLICKR_SOURCE (object)->priv;
 
48
 
 
49
  if (priv->client)
 
50
    {
 
51
      g_object_unref (priv->client);
 
52
      priv->client = NULL;
 
53
    }
 
54
 
 
55
  if (priv->service)
 
56
    {
 
57
      g_object_unref (priv->service);
 
58
      priv->service = NULL;
 
59
    }
 
60
 
 
61
  G_OBJECT_CLASS (bg_flickr_source_parent_class)->dispose (object);
 
62
}
 
63
 
 
64
static void
 
65
bg_flickr_source_finalize (GObject *object)
 
66
{
 
67
  G_OBJECT_CLASS (bg_flickr_source_parent_class)->finalize (object);
 
68
}
 
69
 
 
70
static void
 
71
bg_flickr_source_class_init (BgFlickrSourceClass *klass)
 
72
{
 
73
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
74
 
 
75
  g_type_class_add_private (klass, sizeof (BgFlickrSourcePrivate));
 
76
 
 
77
  object_class->dispose = bg_flickr_source_dispose;
 
78
  object_class->finalize = bg_flickr_source_finalize;
 
79
}
 
80
 
 
81
static void
 
82
_view_items_added_cb (SwClientItemView *item_view,
 
83
                      GList            *items,
 
84
                      gpointer          userdata)
 
85
{
 
86
  GList *l;
 
87
  BgFlickrSource *source = (BgFlickrSource *) userdata;
 
88
  GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
 
89
 
 
90
  for (l = items; l; l = l->next)
 
91
    {
 
92
      CcBackgroundItem *item;
 
93
      GdkPixbuf *pixbuf;
 
94
      SwItem *sw_item = (SwItem *) l->data;
 
95
      const gchar *thumb_url;
 
96
 
 
97
      item = cc_background_item_new (NULL);
 
98
 
 
99
      g_object_set (G_OBJECT (item),
 
100
                    "placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM,
 
101
                    "name", sw_item_get_value (sw_item, "title"),
 
102
                    "primary-color", "#000000000000",
 
103
                    "seconday-color", "#000000000000",
 
104
                    "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID,
 
105
                    "source-url", sw_item_get_value (sw_item, "x-flickr-photo-url"),
 
106
                    NULL);
 
107
 
 
108
      //FIXME
 
109
//      cc_background_item_ensure_gnome_bg (item);
 
110
 
 
111
      /* insert the item into the liststore */
 
112
      thumb_url = sw_item_get_value (sw_item, "thumbnail");
 
113
      pixbuf = gdk_pixbuf_new_from_file_at_scale (thumb_url, THUMBNAIL_WIDTH,
 
114
                                                  THUMBNAIL_HEIGHT, TRUE,
 
115
                                                  NULL);
 
116
      gtk_list_store_insert_with_values (store, NULL, 0,
 
117
                                         0, pixbuf,
 
118
                                         1, item,
 
119
                                         -1);
 
120
      g_object_unref (pixbuf);
 
121
    }
 
122
}
 
123
 
 
124
static void
 
125
_query_open_view_cb (SwClientService  *service,
 
126
                     SwClientItemView *item_view,
 
127
                     gpointer          userdata)
 
128
{
 
129
 
 
130
  if (!item_view)
 
131
  {
 
132
    g_warning ("Could not connect to Flickr service");
 
133
    return;
 
134
  }
 
135
 
 
136
  g_signal_connect (item_view,
 
137
                    "items-added",
 
138
                    (GCallback)_view_items_added_cb,
 
139
                    userdata);
 
140
  sw_client_item_view_start (item_view);
 
141
}
 
142
 
 
143
static void
 
144
bg_flickr_source_init (BgFlickrSource *self)
 
145
{
 
146
  GnomeDesktopThumbnailFactory *thumb_factory;
 
147
  BgFlickrSourcePrivate *priv;
 
148
 
 
149
  priv = self->priv = FLICKR_SOURCE_PRIVATE (self);
 
150
 
 
151
  priv->client = sw_client_new ();
 
152
  priv->service = sw_client_get_service (priv->client, "flickr");
 
153
  sw_client_service_query_open_view (priv->service,
 
154
                                     "feed",
 
155
                                     NULL,
 
156
                                     _query_open_view_cb,
 
157
                                     self);
 
158
 
 
159
  thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
 
160
 
 
161
  g_object_unref (thumb_factory);
 
162
}
 
163
 
 
164
BgFlickrSource *
 
165
bg_flickr_source_new (void)
 
166
{
 
167
  return g_object_new (BG_TYPE_FLICKR_SOURCE, NULL);
 
168
}
 
169