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

« back to all changes in this revision

Viewing changes to panels/background/cc-background-panel.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
 * Copyright (C) 2010 Intel, Inc
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 *
 
18
 * Author: Thomas Wood <thomas.wood@intel.com>
 
19
 *
 
20
 */
 
21
 
 
22
#include <config.h>
 
23
 
 
24
#include <string.h>
 
25
#include <glib/gi18n-lib.h>
 
26
#include <gdesktop-enums.h>
 
27
 
 
28
#include "cc-background-panel.h"
 
29
#include "bg-wallpapers-source.h"
 
30
#include "bg-pictures-source.h"
 
31
#include "bg-colors-source.h"
 
32
 
 
33
#ifdef HAVE_LIBSOCIALWEB
 
34
#include "bg-flickr-source.h"
 
35
#endif
 
36
 
 
37
#include "cc-background-item.h"
 
38
#include "cc-background-xml.h"
 
39
 
 
40
#define WP_PATH_ID "org.gnome.desktop.background"
 
41
#define WP_URI_KEY "picture-uri"
 
42
#define WP_OPTIONS_KEY "picture-options"
 
43
#define WP_SHADING_KEY "color-shading-type"
 
44
#define WP_PCOLOR_KEY "primary-color"
 
45
#define WP_SCOLOR_KEY "secondary-color"
 
46
 
 
47
enum {
 
48
  COL_SOURCE_NAME,
 
49
  COL_SOURCE_TYPE,
 
50
  COL_SOURCE,
 
51
  NUM_COLS
 
52
};
 
53
 
 
54
G_DEFINE_DYNAMIC_TYPE (CcBackgroundPanel, cc_background_panel, CC_TYPE_PANEL)
 
55
 
 
56
#define BACKGROUND_PANEL_PRIVATE(o) \
 
57
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_BACKGROUND_PANEL, CcBackgroundPanelPrivate))
 
58
 
 
59
struct _CcBackgroundPanelPrivate
 
60
{
 
61
  GtkBuilder *builder;
 
62
 
 
63
  BgWallpapersSource *wallpapers_source;
 
64
  BgPicturesSource *pictures_source;
 
65
  BgColorsSource *colors_source;
 
66
 
 
67
#ifdef HAVE_LIBSOCIALWEB
 
68
  BgFlickrSource *flickr_source;
 
69
#endif
 
70
 
 
71
  GSettings *settings;
 
72
 
 
73
  GnomeDesktopThumbnailFactory *thumb_factory;
 
74
 
 
75
  CcBackgroundItem *current_background;
 
76
  gint current_source;
 
77
 
 
78
  GCancellable *copy_cancellable;
 
79
 
 
80
  GtkWidget *spinner;
 
81
 
 
82
  GdkPixbuf *display_base;
 
83
  GdkPixbuf *display_overlay;
 
84
};
 
85
 
 
86
enum
 
87
{
 
88
  SOURCE_WALLPAPERS,
 
89
  SOURCE_PICTURES,
 
90
  SOURCE_COLORS,
 
91
#ifdef HAVE_LIBSOCIALWEB
 
92
  SOURCE_FLICKR
 
93
#endif
 
94
};
 
95
 
 
96
 
 
97
#define WID(y) (GtkWidget *) gtk_builder_get_object (priv->builder, y)
 
98
 
 
99
static void
 
100
cc_background_panel_get_property (GObject    *object,
 
101
                                  guint       property_id,
 
102
                                  GValue     *value,
 
103
                                  GParamSpec *pspec)
 
104
{
 
105
  switch (property_id)
 
106
    {
 
107
    default:
 
108
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
109
    }
 
110
}
 
111
 
 
112
static void
 
113
cc_background_panel_set_property (GObject      *object,
 
114
                                  guint         property_id,
 
115
                                  const GValue *value,
 
116
                                  GParamSpec   *pspec)
 
117
{
 
118
  switch (property_id)
 
119
    {
 
120
    default:
 
121
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
122
    }
 
123
}
 
124
 
 
125
static void
 
126
cc_background_panel_dispose (GObject *object)
 
127
{
 
128
  CcBackgroundPanelPrivate *priv = CC_BACKGROUND_PANEL (object)->priv;
 
129
 
 
130
  if (priv->builder)
 
131
    {
 
132
      g_object_unref (priv->builder);
 
133
      priv->builder = NULL;
 
134
 
 
135
      /* destroying the builder object will also destroy the spinner */
 
136
      priv->spinner = NULL;
 
137
    }
 
138
 
 
139
  if (priv->wallpapers_source)
 
140
    {
 
141
      g_object_unref (priv->wallpapers_source);
 
142
      priv->wallpapers_source = NULL;
 
143
    }
 
144
 
 
145
  if (priv->pictures_source)
 
146
    {
 
147
      g_object_unref (priv->pictures_source);
 
148
      priv->pictures_source = NULL;
 
149
    }
 
150
 
 
151
  if (priv->colors_source)
 
152
    {
 
153
      g_object_unref (priv->colors_source);
 
154
      priv->colors_source = NULL;
 
155
    }
 
156
#ifdef HAVE_LIBSOCIALWEB
 
157
  if (priv->flickr_source)
 
158
    {
 
159
      g_object_unref (priv->flickr_source);
 
160
      priv->flickr_source = NULL;
 
161
    }
 
162
#endif
 
163
 
 
164
  if (priv->settings)
 
165
    {
 
166
      g_object_unref (priv->settings);
 
167
      priv->settings = NULL;
 
168
    }
 
169
 
 
170
  if (priv->copy_cancellable)
 
171
    {
 
172
      /* cancel any copy operation */
 
173
      g_cancellable_cancel (priv->copy_cancellable);
 
174
 
 
175
      g_object_unref (priv->copy_cancellable);
 
176
      priv->copy_cancellable = NULL;
 
177
    }
 
178
 
 
179
  if (priv->thumb_factory)
 
180
    {
 
181
      g_object_unref (priv->thumb_factory);
 
182
      priv->thumb_factory = NULL;
 
183
    }
 
184
 
 
185
  if (priv->display_base)
 
186
    {
 
187
      g_object_unref (priv->display_base);
 
188
      priv->display_base = NULL;
 
189
    }
 
190
 
 
191
  if (priv->display_overlay)
 
192
    {
 
193
      g_object_unref (priv->display_overlay);
 
194
      priv->display_overlay = NULL;
 
195
    }
 
196
 
 
197
  G_OBJECT_CLASS (cc_background_panel_parent_class)->dispose (object);
 
198
}
 
199
 
 
200
static void
 
201
cc_background_panel_finalize (GObject *object)
 
202
{
 
203
  CcBackgroundPanelPrivate *priv = CC_BACKGROUND_PANEL (object)->priv;
 
204
 
 
205
  if (priv->current_background)
 
206
    {
 
207
      g_object_unref (priv->current_background);
 
208
      priv->current_background = NULL;
 
209
    }
 
210
 
 
211
  G_OBJECT_CLASS (cc_background_panel_parent_class)->finalize (object);
 
212
}
 
213
 
 
214
static void
 
215
cc_background_panel_class_init (CcBackgroundPanelClass *klass)
 
216
{
 
217
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
218
 
 
219
  g_type_class_add_private (klass, sizeof (CcBackgroundPanelPrivate));
 
220
 
 
221
  object_class->get_property = cc_background_panel_get_property;
 
222
  object_class->set_property = cc_background_panel_set_property;
 
223
  object_class->dispose = cc_background_panel_dispose;
 
224
  object_class->finalize = cc_background_panel_finalize;
 
225
}
 
226
 
 
227
static void
 
228
cc_background_panel_class_finalize (CcBackgroundPanelClass *klass)
 
229
{
 
230
}
 
231
 
 
232
static void
 
233
source_update_edit_box (CcBackgroundPanelPrivate *priv,
 
234
                        gboolean                  initial)
 
235
{
 
236
  CcBackgroundItemFlags flags;
 
237
 
 
238
  flags = cc_background_item_get_flags (priv->current_background);
 
239
 
 
240
  if ((flags & CC_BACKGROUND_ITEM_HAS_SCOLOR &&
 
241
       priv->current_source != SOURCE_COLORS) ||
 
242
      cc_background_item_get_shading (priv->current_background) == G_DESKTOP_BACKGROUND_SHADING_SOLID)
 
243
    gtk_widget_hide (WID ("style-scolor"));
 
244
  else
 
245
    gtk_widget_show (WID ("style-scolor"));
 
246
 
 
247
  if (flags & CC_BACKGROUND_ITEM_HAS_PCOLOR &&
 
248
      priv->current_source != SOURCE_COLORS)
 
249
    gtk_widget_hide (WID ("style-pcolor"));
 
250
  else
 
251
    gtk_widget_show (WID ("style-pcolor"));
 
252
 
 
253
  if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT ||
 
254
      cc_background_item_get_uri (priv->current_background) == NULL)
 
255
    gtk_widget_hide (WID ("style-combobox"));
 
256
  else
 
257
    gtk_widget_show (WID ("style-combobox"));
 
258
 
 
259
  /* FIXME What to do if the background has a gradient shading
 
260
   * and provides the colours? */
 
261
}
 
262
 
 
263
static void
 
264
source_changed_cb (GtkComboBox              *combo,
 
265
                   CcBackgroundPanelPrivate *priv)
 
266
{
 
267
  GtkTreeIter iter;
 
268
  GtkTreeModel *model;
 
269
  GtkIconView *view;
 
270
  guint type;
 
271
  BgSource *source;
 
272
 
 
273
  gtk_combo_box_get_active_iter (combo, &iter);
 
274
  model = gtk_combo_box_get_model (combo);
 
275
  gtk_tree_model_get (model, &iter,
 
276
                      COL_SOURCE_TYPE, &type,
 
277
                      COL_SOURCE, &source, -1);
 
278
 
 
279
  view = (GtkIconView *) gtk_builder_get_object (priv->builder,
 
280
                                                 "backgrounds-iconview");
 
281
 
 
282
  gtk_icon_view_set_model (view,
 
283
                           GTK_TREE_MODEL (bg_source_get_liststore (source)));
 
284
}
 
285
 
 
286
static void
 
287
select_style (GtkComboBox *box,
 
288
              GDesktopBackgroundStyle new_style)
 
289
{
 
290
  GtkTreeModel *model;
 
291
  GtkTreeIter iter;
 
292
  gboolean cont;
 
293
 
 
294
  model = gtk_combo_box_get_model (box);
 
295
  cont = gtk_tree_model_get_iter_first (model, &iter);
 
296
  while (cont != FALSE)
 
297
    {
 
298
      GDesktopBackgroundStyle style;
 
299
 
 
300
      gtk_tree_model_get (model, &iter,
 
301
                          1, &style,
 
302
                          -1);
 
303
 
 
304
      if (style == new_style)
 
305
        {
 
306
          gtk_combo_box_set_active_iter (box, &iter);
 
307
          break;
 
308
        }
 
309
      cont = gtk_tree_model_iter_next (model, &iter);
 
310
    }
 
311
 
 
312
  if (cont == FALSE)
 
313
    gtk_combo_box_set_active (box, -1);
 
314
}
 
315
 
 
316
static void
 
317
update_preview (CcBackgroundPanelPrivate *priv,
 
318
                CcBackgroundItem         *item)
 
319
{
 
320
  gchar *markup;
 
321
  gboolean changes_with_time;
 
322
 
 
323
  if (item && priv->current_background)
 
324
    {
 
325
      g_object_unref (priv->current_background);
 
326
      priv->current_background = cc_background_item_copy (item);
 
327
      cc_background_item_load (priv->current_background, NULL);
 
328
    }
 
329
 
 
330
  source_update_edit_box (priv, FALSE);
 
331
 
 
332
  changes_with_time = FALSE;
 
333
 
 
334
  if (priv->current_background)
 
335
    {
 
336
      GdkColor pcolor, scolor;
 
337
 
 
338
      markup = g_strdup_printf ("<b>%s</b>", cc_background_item_get_name (priv->current_background));
 
339
      gtk_label_set_markup (GTK_LABEL (WID ("background-label")), markup);
 
340
      g_free (markup);
 
341
 
 
342
      gtk_label_set_text (GTK_LABEL (WID ("size_label")), cc_background_item_get_size (priv->current_background));
 
343
 
 
344
      gdk_color_parse (cc_background_item_get_pcolor (priv->current_background), &pcolor);
 
345
      gdk_color_parse (cc_background_item_get_scolor (priv->current_background), &scolor);
 
346
 
 
347
      gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-pcolor")), &pcolor);
 
348
      gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-scolor")), &scolor);
 
349
 
 
350
      select_style (GTK_COMBO_BOX (WID ("style-combobox")),
 
351
                    cc_background_item_get_placement (priv->current_background));
 
352
 
 
353
      changes_with_time = cc_background_item_changes_with_time (priv->current_background);
 
354
    }
 
355
 
 
356
  gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
 
357
  gtk_widget_set_visible (WID ("slide-label"), changes_with_time);
 
358
 
 
359
  gtk_widget_queue_draw (WID ("preview-area"));
 
360
}
 
361
 
 
362
static char *
 
363
get_save_path (void)
 
364
{
 
365
  return g_build_filename (g_get_user_config_dir (),
 
366
                           "gnome-control-center",
 
367
                           "backgrounds",
 
368
                           "last-edited.xml",
 
369
                           NULL);
 
370
}
 
371
 
 
372
static gboolean
 
373
create_save_dir (void)
 
374
{
 
375
  char *path;
 
376
 
 
377
  path = g_build_filename (g_get_user_config_dir (),
 
378
                           "gnome-control-center",
 
379
                           "backgrounds",
 
380
                           NULL);
 
381
  if (g_mkdir_with_parents (path, 0755) < 0)
 
382
    {
 
383
      g_warning ("Failed to create directory '%s'", path);
 
384
      g_free (path);
 
385
      return FALSE;
 
386
    }
 
387
  g_free (path);
 
388
  return TRUE;
 
389
}
 
390
 
 
391
static void
 
392
copy_finished_cb (GObject      *source_object,
 
393
                  GAsyncResult *result,
 
394
                  gpointer      pointer)
 
395
{
 
396
  GError *err = NULL;
 
397
  CcBackgroundPanel *panel = (CcBackgroundPanel *) pointer;
 
398
  CcBackgroundPanelPrivate *priv = panel->priv;
 
399
  CcBackgroundItem *item;
 
400
 
 
401
  if (!g_file_copy_finish (G_FILE (source_object), result, &err))
 
402
    {
 
403
      if (err->code != G_IO_ERROR_CANCELLED)
 
404
        g_warning ("Failed to copy image to cache location: %s", err->message);
 
405
 
 
406
      g_error_free (err);
 
407
    }
 
408
  item = g_object_get_data (source_object, "item");
 
409
 
 
410
  /* the panel may have been destroyed before the callback is run, so be sure
 
411
   * to check the widgets are not NULL */
 
412
 
 
413
  if (priv->spinner)
 
414
    {
 
415
      gtk_widget_destroy (GTK_WIDGET (priv->spinner));
 
416
      priv->spinner = NULL;
 
417
    }
 
418
 
 
419
  if (priv->current_background)
 
420
    cc_background_item_load (priv->current_background, NULL);
 
421
 
 
422
  if (priv->builder)
 
423
    {
 
424
      char *filename;
 
425
 
 
426
      update_preview (priv, item);
 
427
 
 
428
      /* Save the source XML if there is one */
 
429
      filename = get_save_path ();
 
430
      if (create_save_dir ())
 
431
        cc_background_xml_save (priv->current_background, filename);
 
432
    }
 
433
 
 
434
  /* remove the reference taken when the copy was set up */
 
435
  g_object_unref (panel);
 
436
}
 
437
 
 
438
static void
 
439
update_remove_button (CcBackgroundPanel *panel,
 
440
                      CcBackgroundItem  *item)
 
441
{
 
442
  CcBackgroundPanelPrivate *priv;
 
443
  const char *uri;
 
444
  char *cache_path;
 
445
  GFile *bg, *cache, *parent;
 
446
  gboolean sensitive = FALSE;
 
447
 
 
448
  priv = panel->priv;
 
449
 
 
450
  if (priv->current_source != SOURCE_PICTURES)
 
451
    goto bail;
 
452
 
 
453
  uri = cc_background_item_get_uri (item);
 
454
  if (uri == NULL)
 
455
    goto bail;
 
456
 
 
457
  bg = g_file_new_for_uri (uri);
 
458
  parent = g_file_get_parent (bg);
 
459
  if (parent == NULL)
 
460
    {
 
461
      g_object_unref (bg);
 
462
      goto bail;
 
463
    }
 
464
  cache_path = bg_pictures_source_get_cache_path ();
 
465
  cache = g_file_new_for_path (cache_path);
 
466
  g_free (cache_path);
 
467
 
 
468
  if (g_file_equal (parent, cache))
 
469
    sensitive = TRUE;
 
470
 
 
471
  g_object_unref (parent);
 
472
  g_object_unref (cache);
 
473
 
 
474
bail:
 
475
  gtk_widget_set_sensitive (WID ("remove_button"), sensitive);
 
476
 
 
477
}
 
478
 
 
479
static CcBackgroundItem *
 
480
get_selected_item (CcBackgroundPanel *panel)
 
481
{
 
482
  CcBackgroundPanelPrivate *priv = panel->priv;
 
483
  GtkIconView *icon_view;
 
484
  GtkTreeIter iter;
 
485
  GtkTreeModel *model;
 
486
  GList *list;
 
487
  CcBackgroundItem *item;
 
488
 
 
489
  icon_view = GTK_ICON_VIEW (WID ("backgrounds-iconview"));
 
490
  item = NULL;
 
491
  list = gtk_icon_view_get_selected_items (icon_view);
 
492
 
 
493
  if (!list)
 
494
    return NULL;
 
495
 
 
496
  model = gtk_icon_view_get_model (icon_view);
 
497
 
 
498
  if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath*) list->data) == FALSE)
 
499
    goto bail;
 
500
 
 
501
  gtk_tree_model_get (model, &iter, 1, &item, -1);
 
502
 
 
503
bail:
 
504
  g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
 
505
  g_list_free (list);
 
506
 
 
507
  return item;
 
508
}
 
509
 
 
510
static void
 
511
backgrounds_changed_cb (GtkIconView       *icon_view,
 
512
                        CcBackgroundPanel *panel)
 
513
{
 
514
  GtkTreeIter iter;
 
515
  GtkTreeModel *model;
 
516
  CcBackgroundItem *item;
 
517
  CcBackgroundPanelPrivate *priv = panel->priv;
 
518
  char *pcolor, *scolor;
 
519
  gboolean draw_preview = TRUE;
 
520
  const char *uri;
 
521
  CcBackgroundItemFlags flags;
 
522
  char *filename;
 
523
 
 
524
  item = get_selected_item (panel);
 
525
 
 
526
  if (item == NULL)
 
527
    return;
 
528
 
 
529
  /* Update current source */
 
530
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (WID ("sources-combobox")));
 
531
  gtk_combo_box_get_active_iter (GTK_COMBO_BOX (WID ("sources-combobox")),
 
532
                                 &iter);
 
533
  gtk_tree_model_get (model, &iter,
 
534
                      COL_SOURCE_TYPE, &priv->current_source, -1);
 
535
 
 
536
  uri = cc_background_item_get_uri (item);
 
537
  flags = cc_background_item_get_flags (item);
 
538
 
 
539
  if ((flags & CC_BACKGROUND_ITEM_HAS_URI) && uri == NULL)
 
540
    {
 
541
      g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, G_DESKTOP_BACKGROUND_STYLE_NONE);
 
542
      g_settings_set_string (priv->settings, WP_URI_KEY, "");
 
543
    }
 
544
  else if (cc_background_item_get_source_url (item) != NULL &&
 
545
           cc_background_item_get_needs_download (item))
 
546
    {
 
547
      GFile *source, *dest;
 
548
      gchar *cache_path, *basename, *dest_path, *display_name, *dest_uri;
 
549
      GdkPixbuf *pixbuf;
 
550
 
 
551
      cache_path = bg_pictures_source_get_cache_path ();
 
552
      if (g_mkdir_with_parents (cache_path, 0755) < 0)
 
553
        {
 
554
          g_warning ("Failed to create directory '%s'", cache_path);
 
555
          g_free (cache_path);
 
556
          return;
 
557
        }
 
558
      g_free (cache_path);
 
559
 
 
560
      dest_path = bg_pictures_source_get_unique_path (cc_background_item_get_source_url (item));
 
561
      dest = g_file_new_for_path (dest_path);
 
562
      g_free (dest_path);
 
563
      source = g_file_new_for_uri (cc_background_item_get_source_url (item));
 
564
      basename = g_file_get_basename (source);
 
565
      display_name = g_filename_display_name (basename);
 
566
      dest_path = g_file_get_path (dest);
 
567
      g_free (basename);
 
568
 
 
569
      /* create a blank image to use until the source image is ready */
 
570
      pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
 
571
      gdk_pixbuf_fill (pixbuf, 0x00000000);
 
572
      gdk_pixbuf_save (pixbuf, dest_path, "png", NULL, NULL);
 
573
      g_object_unref (pixbuf);
 
574
      g_free (dest_path);
 
575
 
 
576
      if (priv->copy_cancellable)
 
577
        {
 
578
          g_cancellable_cancel (priv->copy_cancellable);
 
579
          g_cancellable_reset (priv->copy_cancellable);
 
580
        }
 
581
 
 
582
      if (priv->spinner)
 
583
        {
 
584
          gtk_widget_destroy (GTK_WIDGET (priv->spinner));
 
585
          priv->spinner = NULL;
 
586
        }
 
587
 
 
588
      /* create a spinner while the file downloads */
 
589
      priv->spinner = gtk_spinner_new ();
 
590
      gtk_spinner_start (GTK_SPINNER (priv->spinner));
 
591
      gtk_box_pack_start (GTK_BOX (WID ("bottom-hbox")), priv->spinner, FALSE,
 
592
                          FALSE, 6);
 
593
      gtk_widget_show (priv->spinner);
 
594
 
 
595
      /* reference the panel in case it is removed before the copy is
 
596
       * finished */
 
597
      g_object_ref (panel);
 
598
      g_object_set_data_full (G_OBJECT (source), "item", g_object_ref (item), g_object_unref);
 
599
      g_file_copy_async (source, dest, G_FILE_COPY_OVERWRITE,
 
600
                         G_PRIORITY_DEFAULT, priv->copy_cancellable,
 
601
                         NULL, NULL,
 
602
                         copy_finished_cb, panel);
 
603
      g_object_unref (source);
 
604
      dest_uri = g_file_get_uri (dest);
 
605
      g_object_unref (dest);
 
606
 
 
607
      g_settings_set_string (priv->settings, WP_URI_KEY, dest_uri);
 
608
      g_object_set (G_OBJECT (item),
 
609
                    "uri", dest_uri,
 
610
                    "needs-download", FALSE,
 
611
                    "name", display_name,
 
612
                    NULL);
 
613
      g_free (display_name);
 
614
      g_free (dest_uri);
 
615
 
 
616
      /* delay the updated drawing of the preview until the copy finishes */
 
617
      draw_preview = FALSE;
 
618
    }
 
619
  else
 
620
    {
 
621
      g_settings_set_string (priv->settings, WP_URI_KEY, uri);
 
622
    }
 
623
 
 
624
  /* Also set the placement if we have a URI and the previous value was none */
 
625
  if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT)
 
626
    {
 
627
      g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
 
628
    }
 
629
  else if (uri != NULL)
 
630
    {
 
631
      GDesktopBackgroundStyle style;
 
632
      style = g_settings_get_enum (priv->settings, WP_OPTIONS_KEY);
 
633
      if (style == G_DESKTOP_BACKGROUND_STYLE_NONE)
 
634
        g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
 
635
    }
 
636
 
 
637
  if (flags & CC_BACKGROUND_ITEM_HAS_SHADING)
 
638
    g_settings_set_enum (priv->settings, WP_SHADING_KEY, cc_background_item_get_shading (item));
 
639
 
 
640
  /* When changing to a background with colours set,
 
641
   * don't overwrite what's in GSettings, but read
 
642
   * from it instead.
 
643
   * We have a hack for the colors source though */
 
644
  if (flags & CC_BACKGROUND_ITEM_HAS_PCOLOR &&
 
645
      priv->current_source != SOURCE_COLORS)
 
646
    {
 
647
      g_settings_set_string (priv->settings, WP_PCOLOR_KEY, cc_background_item_get_pcolor (item));
 
648
    }
 
649
  else
 
650
    {
 
651
      pcolor = g_settings_get_string (priv->settings, WP_PCOLOR_KEY);
 
652
      g_object_set (G_OBJECT (item), "primary-color", pcolor, NULL);
 
653
    }
 
654
 
 
655
  if (flags & CC_BACKGROUND_ITEM_HAS_SCOLOR &&
 
656
      priv->current_source != SOURCE_COLORS)
 
657
    {
 
658
      g_settings_set_string (priv->settings, WP_SCOLOR_KEY, cc_background_item_get_scolor (item));
 
659
    }
 
660
  else
 
661
    {
 
662
      scolor = g_settings_get_string (priv->settings, WP_SCOLOR_KEY);
 
663
      g_object_set (G_OBJECT (item), "secondary-color", scolor, NULL);
 
664
    }
 
665
 
 
666
  /* Apply all changes */
 
667
  g_settings_apply (priv->settings);
 
668
 
 
669
  update_remove_button (panel, item);
 
670
 
 
671
  /* update the preview information */
 
672
  if (draw_preview != FALSE)
 
673
    {
 
674
      update_preview (priv, item);
 
675
 
 
676
      /* Save the source XML if there is one */
 
677
      filename = get_save_path ();
 
678
      if (create_save_dir ())
 
679
        cc_background_xml_save (priv->current_background, filename);
 
680
    }
 
681
}
 
682
 
 
683
static gboolean
 
684
preview_draw_cb (GtkWidget         *widget,
 
685
                 cairo_t           *cr,
 
686
                 CcBackgroundPanel *panel)
 
687
{
 
688
  GtkAllocation allocation;
 
689
  CcBackgroundPanelPrivate *priv = panel->priv;
 
690
  GdkPixbuf *pixbuf = NULL;
 
691
  const gint preview_width = 416;
 
692
  const gint preview_height = 248;
 
693
  const gint preview_x = 45;
 
694
  const gint preview_y = 84;
 
695
  GdkPixbuf *preview, *temp;
 
696
  gint size;
 
697
 
 
698
  gtk_widget_get_allocation (widget, &allocation);
 
699
 
 
700
  if (priv->current_background)
 
701
    {
 
702
      GIcon *icon;
 
703
      icon = cc_background_item_get_frame_thumbnail (priv->current_background,
 
704
                                                     priv->thumb_factory,
 
705
                                                     preview_width,
 
706
                                                     preview_height,
 
707
                                                     -2, TRUE);
 
708
      pixbuf = GDK_PIXBUF (icon);
 
709
    }
 
710
 
 
711
  if (!priv->display_base)
 
712
    return FALSE;
 
713
 
 
714
 
 
715
  preview = gdk_pixbuf_copy (priv->display_base);
 
716
 
 
717
  if (pixbuf)
 
718
    {
 
719
      gdk_pixbuf_composite (pixbuf, preview,
 
720
                            preview_x, preview_y,
 
721
                            preview_width, preview_height,
 
722
                            preview_x, preview_y, 1, 1,
 
723
                            GDK_INTERP_BILINEAR, 255);
 
724
 
 
725
      g_object_unref (pixbuf);
 
726
    }
 
727
 
 
728
 
 
729
  if (priv->display_overlay)
 
730
    {
 
731
      gdk_pixbuf_composite (priv->display_overlay, preview,
 
732
                            0, 0, 512, 512,
 
733
                            0, 0, 1, 1,
 
734
                            GDK_INTERP_BILINEAR, 255);
 
735
    }
 
736
 
 
737
 
 
738
  if (allocation.width < allocation.height)
 
739
    size = allocation.width;
 
740
  else
 
741
    size = allocation.height;
 
742
 
 
743
  temp = gdk_pixbuf_scale_simple (preview, size, size, GDK_INTERP_BILINEAR);
 
744
 
 
745
  gdk_cairo_set_source_pixbuf (cr,
 
746
                               temp,
 
747
                               allocation.width / 2 - (size / 2),
 
748
                               allocation.height / 2 - (size / 2));
 
749
  cairo_paint (cr);
 
750
 
 
751
  g_object_unref (temp);
 
752
  g_object_unref (preview);
 
753
 
 
754
  return TRUE;
 
755
}
 
756
 
 
757
static void
 
758
style_changed_cb (GtkComboBox       *box,
 
759
                  CcBackgroundPanel *panel)
 
760
{
 
761
  CcBackgroundPanelPrivate *priv = panel->priv;
 
762
  GtkTreeModel *model;
 
763
  GtkTreeIter iter;
 
764
  GDesktopBackgroundStyle value;
 
765
 
 
766
  if (!gtk_combo_box_get_active_iter (box, &iter))
 
767
    {
 
768
      return;
 
769
    }
 
770
 
 
771
  model = gtk_combo_box_get_model (box);
 
772
 
 
773
  gtk_tree_model_get (model, &iter, 1, &value, -1);
 
774
 
 
775
  g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, value);
 
776
 
 
777
  if (priv->current_background)
 
778
    g_object_set (G_OBJECT (priv->current_background), "placement", value, NULL);
 
779
 
 
780
  g_settings_apply (priv->settings);
 
781
 
 
782
  update_preview (priv, NULL);
 
783
}
 
784
 
 
785
static void
 
786
color_changed_cb (GtkColorButton    *button,
 
787
                  CcBackgroundPanel *panel)
 
788
{
 
789
  CcBackgroundPanelPrivate *priv = panel->priv;
 
790
  GdkColor color;
 
791
  gchar *value;
 
792
  gboolean is_pcolor = FALSE;
 
793
 
 
794
  gtk_color_button_get_color (button, &color);
 
795
  if (WID ("style-pcolor") == GTK_WIDGET (button))
 
796
    is_pcolor = TRUE;
 
797
 
 
798
  value = gdk_color_to_string (&color);
 
799
 
 
800
  if (priv->current_background)
 
801
    {
 
802
      g_object_set (G_OBJECT (priv->current_background),
 
803
                    is_pcolor ? "primary-color" : "secondary-color", value, NULL);
 
804
    }
 
805
 
 
806
  g_settings_set_string (priv->settings,
 
807
                         is_pcolor ? WP_PCOLOR_KEY : WP_SCOLOR_KEY, value);
 
808
 
 
809
  g_settings_apply (priv->settings);
 
810
 
 
811
  g_free (value);
 
812
 
 
813
  update_preview (priv, NULL);
 
814
}
 
815
 
 
816
static void
 
817
row_inserted (GtkTreeModel      *tree_model,
 
818
              GtkTreePath       *path,
 
819
              GtkTreeIter       *iter,
 
820
              CcBackgroundPanel *panel)
 
821
{
 
822
  GtkListStore *store;
 
823
  CcBackgroundPanelPrivate *priv;
 
824
 
 
825
  priv = panel->priv;
 
826
 
 
827
  store = bg_source_get_liststore (BG_SOURCE (panel->priv->pictures_source));
 
828
  g_signal_handlers_disconnect_by_func (G_OBJECT (store), G_CALLBACK (row_inserted), panel);
 
829
 
 
830
  /* Change source */
 
831
  gtk_combo_box_set_active (GTK_COMBO_BOX (WID ("sources-combobox")), SOURCE_PICTURES);
 
832
 
 
833
  /* And select the newly added item */
 
834
  gtk_icon_view_select_path (GTK_ICON_VIEW (WID ("backgrounds-iconview")), path);
 
835
}
 
836
 
 
837
static void
 
838
add_custom_wallpaper (CcBackgroundPanel *panel,
 
839
                      const char        *uri)
 
840
{
 
841
  GtkListStore *store;
 
842
 
 
843
  store = bg_source_get_liststore (BG_SOURCE (panel->priv->pictures_source));
 
844
  g_signal_connect (G_OBJECT (store), "row-inserted",
 
845
                    G_CALLBACK (row_inserted), panel);
 
846
 
 
847
  if (bg_pictures_source_add (panel->priv->pictures_source, uri) == FALSE) {
 
848
    g_signal_handlers_disconnect_by_func (G_OBJECT (store), G_CALLBACK (row_inserted), panel);
 
849
    return;
 
850
  }
 
851
 
 
852
  /* Wait for the item to get added */
 
853
}
 
854
 
 
855
static void
 
856
file_chooser_response (GtkDialog         *chooser,
 
857
                       gint               response,
 
858
                       CcBackgroundPanel *panel)
 
859
{
 
860
  GSList *selected, *l;
 
861
 
 
862
  if (response != GTK_RESPONSE_ACCEPT)
 
863
    {
 
864
      gtk_widget_destroy (GTK_WIDGET (chooser));
 
865
      return;
 
866
    }
 
867
 
 
868
  selected = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
 
869
  gtk_widget_destroy (GTK_WIDGET (chooser));
 
870
 
 
871
  for (l = selected; l != NULL; l = l->next)
 
872
    {
 
873
      char *uri = l->data;
 
874
      add_custom_wallpaper (panel, uri);
 
875
      g_free (uri);
 
876
    }
 
877
  g_slist_free (selected);
 
878
}
 
879
 
 
880
static void
 
881
update_chooser_preview (GtkFileChooser    *chooser,
 
882
                        CcBackgroundPanel *panel)
 
883
{
 
884
  GnomeDesktopThumbnailFactory *thumb_factory;
 
885
  char *uri;
 
886
 
 
887
  thumb_factory = panel->priv->thumb_factory;
 
888
 
 
889
  uri = gtk_file_chooser_get_preview_uri (chooser);
 
890
 
 
891
  if (uri)
 
892
    {
 
893
      GdkPixbuf *pixbuf = NULL;
 
894
      const gchar *mime_type = NULL;
 
895
      GFile *file;
 
896
      GFileInfo *file_info;
 
897
      GtkWidget *preview;
 
898
 
 
899
      preview = gtk_file_chooser_get_preview_widget (chooser);
 
900
 
 
901
      file = g_file_new_for_uri (uri);
 
902
      file_info = g_file_query_info (file,
 
903
                                     G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
 
904
                                     G_FILE_QUERY_INFO_NONE,
 
905
                                     NULL, NULL);
 
906
      g_object_unref (file);
 
907
 
 
908
      if (file_info != NULL) {
 
909
              mime_type = g_file_info_get_content_type (file_info);
 
910
              g_object_unref (file_info);
 
911
      }
 
912
 
 
913
      if (mime_type)
 
914
        {
 
915
        pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumb_factory,
 
916
                                                                     uri,
 
917
                                                                     mime_type);
 
918
        }
 
919
 
 
920
      gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
 
921
                                         GTK_RESPONSE_ACCEPT,
 
922
                                         (pixbuf != NULL));
 
923
 
 
924
      if (pixbuf != NULL)
 
925
        {
 
926
          gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
 
927
          g_object_unref (pixbuf);
 
928
        }
 
929
      else
 
930
        {
 
931
          gtk_image_set_from_stock (GTK_IMAGE (preview),
 
932
                                    GTK_STOCK_DIALOG_QUESTION,
 
933
                                    GTK_ICON_SIZE_DIALOG);
 
934
        }
 
935
 
 
936
      if (bg_pictures_source_is_known (panel->priv->pictures_source, uri))
 
937
        gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT, FALSE);
 
938
      else
 
939
        gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT, TRUE);
 
940
 
 
941
      g_free (uri);
 
942
    }
 
943
 
 
944
  gtk_file_chooser_set_preview_widget_active (chooser, TRUE);
 
945
}
 
946
 
 
947
static void
 
948
add_button_clicked (GtkButton         *button,
 
949
                    CcBackgroundPanel *panel)
 
950
{
 
951
  GtkWidget *chooser;
 
952
  const gchar *folder;
 
953
  GtkWidget *preview;
 
954
  GtkFileFilter *filter;
 
955
  CcBackgroundPanelPrivate *priv;
 
956
 
 
957
  priv = panel->priv;
 
958
 
 
959
  filter = gtk_file_filter_new ();
 
960
  gtk_file_filter_add_mime_type (filter, "image/png");
 
961
  gtk_file_filter_add_mime_type (filter, "image/jpeg");
 
962
 
 
963
  chooser = gtk_file_chooser_dialog_new (_("Browse for more pictures"),
 
964
                                         GTK_WINDOW (gtk_widget_get_toplevel (WID ("background-panel"))),
 
965
                                         GTK_FILE_CHOOSER_ACTION_OPEN,
 
966
                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
967
                                         GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 
968
                                         NULL);
 
969
  gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), filter);
 
970
  gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
 
971
 
 
972
  gtk_window_set_modal (GTK_WINDOW (chooser), TRUE);
 
973
 
 
974
  preview = gtk_image_new ();
 
975
  gtk_widget_set_size_request (preview, 128, -1);
 
976
  gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (chooser), preview);
 
977
  gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (chooser), FALSE);
 
978
  gtk_widget_show (preview);
 
979
  g_signal_connect (chooser, "update-preview",
 
980
                    G_CALLBACK (update_chooser_preview), panel);
 
981
 
 
982
  folder = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
 
983
  if (folder)
 
984
    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
 
985
                                         folder);
 
986
 
 
987
  g_signal_connect (chooser, "response",
 
988
                    G_CALLBACK (file_chooser_response), panel);
 
989
 
 
990
  gtk_window_present (GTK_WINDOW (chooser));
 
991
}
 
992
 
 
993
static void
 
994
remove_button_clicked (GtkButton         *button,
 
995
                       CcBackgroundPanel *panel)
 
996
{
 
997
  CcBackgroundItem *item;
 
998
  GtkListStore *store;
 
999
  GtkTreePath *path;
 
1000
  CcBackgroundPanelPrivate *priv;
 
1001
 
 
1002
  priv = panel->priv;
 
1003
 
 
1004
  item = get_selected_item (panel);
 
1005
  if (item == NULL)
 
1006
    g_assert_not_reached ();
 
1007
 
 
1008
  bg_pictures_source_remove (panel->priv->pictures_source, item);
 
1009
  g_object_unref (item);
 
1010
 
 
1011
  /* Are there any items left in the pictures tree store? */
 
1012
  store = bg_source_get_liststore (BG_SOURCE (panel->priv->pictures_source));
 
1013
  if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 0)
 
1014
    gtk_combo_box_set_active (GTK_COMBO_BOX (WID ("sources-combobox")), SOURCE_WALLPAPERS);
 
1015
 
 
1016
  path = gtk_tree_path_new_from_string ("0");
 
1017
  gtk_icon_view_select_path (GTK_ICON_VIEW (WID ("backgrounds-iconview")), path);
 
1018
  gtk_tree_path_free (path);
 
1019
}
 
1020
 
 
1021
static void
 
1022
load_current_bg (CcBackgroundPanel *self)
 
1023
{
 
1024
  CcBackgroundPanelPrivate *priv;
 
1025
  CcBackgroundItem *saved, *configured;
 
1026
  gchar *uri, *pcolor, *scolor;
 
1027
 
 
1028
  priv = self->priv;
 
1029
 
 
1030
  /* Load the saved configuration */
 
1031
  uri = get_save_path ();
 
1032
  saved = cc_background_xml_get_item (uri);
 
1033
  g_free (uri);
 
1034
 
 
1035
  /* initalise the current background information from settings */
 
1036
  uri = g_settings_get_string (priv->settings, WP_URI_KEY);
 
1037
  if (uri && *uri == '\0')
 
1038
    {
 
1039
      g_free (uri);
 
1040
      uri = NULL;
 
1041
    }
 
1042
  else
 
1043
    {
 
1044
      GFile *file;
 
1045
 
 
1046
      file = g_file_new_for_commandline_arg (uri);
 
1047
      g_object_unref (file);
 
1048
    }
 
1049
  configured = cc_background_item_new (uri);
 
1050
  g_free (uri);
 
1051
 
 
1052
  pcolor = g_settings_get_string (priv->settings, WP_PCOLOR_KEY);
 
1053
  scolor = g_settings_get_string (priv->settings, WP_SCOLOR_KEY);
 
1054
  g_object_set (G_OBJECT (configured),
 
1055
                "name", _("Current background"),
 
1056
                "placement", g_settings_get_enum (priv->settings, WP_OPTIONS_KEY),
 
1057
                "shading", g_settings_get_enum (priv->settings, WP_SHADING_KEY),
 
1058
                "primary-color", pcolor,
 
1059
                "secondary-color", scolor,
 
1060
                NULL);
 
1061
  g_free (pcolor);
 
1062
  g_free (scolor);
 
1063
 
 
1064
  if (saved != NULL && cc_background_item_compare (saved, configured))
 
1065
    {
 
1066
      CcBackgroundItemFlags flags;
 
1067
      flags = cc_background_item_get_flags (saved);
 
1068
      /* Special case for colours */
 
1069
      if (cc_background_item_get_placement (saved) == G_DESKTOP_BACKGROUND_STYLE_NONE)
 
1070
        flags &=~ (CC_BACKGROUND_ITEM_HAS_PCOLOR | CC_BACKGROUND_ITEM_HAS_SCOLOR);
 
1071
      g_object_set (G_OBJECT (configured),
 
1072
                    "name", cc_background_item_get_name (saved),
 
1073
                    "flags", flags,
 
1074
                    "source-url", cc_background_item_get_source_url (saved),
 
1075
                    "source-xml", cc_background_item_get_source_xml (saved),
 
1076
                    NULL);
 
1077
    }
 
1078
  if (saved != NULL)
 
1079
    g_object_unref (saved);
 
1080
 
 
1081
  priv->current_background = configured;
 
1082
  cc_background_item_load (priv->current_background, NULL);
 
1083
}
 
1084
 
 
1085
static void
 
1086
scrolled_realize_cb (GtkWidget         *scrolled,
 
1087
                     CcBackgroundPanel *self)
 
1088
{
 
1089
  /* FIXME, hack for https://bugzilla.gnome.org/show_bug.cgi?id=645649 */
 
1090
  GdkScreen *screen;
 
1091
  GdkRectangle rect;
 
1092
  int monitor;
 
1093
 
 
1094
  screen = gtk_widget_get_screen (scrolled);
 
1095
  monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (scrolled));
 
1096
  gdk_screen_get_monitor_geometry (screen, monitor, &rect);
 
1097
  if (rect.height <= 768)
 
1098
    g_object_set (G_OBJECT (scrolled), "height-request", 280, NULL);
 
1099
}
 
1100
 
 
1101
static void
 
1102
cc_background_panel_init (CcBackgroundPanel *self)
 
1103
{
 
1104
  CcBackgroundPanelPrivate *priv;
 
1105
  gchar *objects[] = { "style-liststore",
 
1106
      "sources-liststore", "background-panel", "sizegroup", NULL };
 
1107
  GError *err = NULL;
 
1108
  GtkWidget *widget;
 
1109
  GtkListStore *store;
 
1110
  GtkStyleContext *context;
 
1111
 
 
1112
  priv = self->priv = BACKGROUND_PANEL_PRIVATE (self);
 
1113
 
 
1114
  priv->builder = gtk_builder_new ();
 
1115
 
 
1116
  gtk_builder_add_objects_from_file (priv->builder,
 
1117
                                     DATADIR"/background.ui",
 
1118
                                     objects, &err);
 
1119
 
 
1120
  if (err)
 
1121
    {
 
1122
      g_warning ("Could not load ui: %s", err->message);
 
1123
      g_error_free (err);
 
1124
      return;
 
1125
    }
 
1126
 
 
1127
  /* See shell_notify_cb for details */
 
1128
  g_signal_connect (WID ("scrolledwindow1"), "realize",
 
1129
                    G_CALLBACK (scrolled_realize_cb), self);
 
1130
 
 
1131
  priv->settings = g_settings_new (WP_PATH_ID);
 
1132
  g_settings_delay (priv->settings);
 
1133
 
 
1134
  store = (GtkListStore*) gtk_builder_get_object (priv->builder,
 
1135
                                                  "sources-liststore");
 
1136
 
 
1137
  priv->wallpapers_source = bg_wallpapers_source_new ();
 
1138
  gtk_list_store_insert_with_values (store, NULL, G_MAXINT,
 
1139
                                     COL_SOURCE_NAME, _("Wallpapers"),
 
1140
                                     COL_SOURCE_TYPE, SOURCE_WALLPAPERS,
 
1141
                                     COL_SOURCE, priv->wallpapers_source,
 
1142
                                     -1);
 
1143
 
 
1144
  priv->pictures_source = bg_pictures_source_new ();
 
1145
  gtk_list_store_insert_with_values (store, NULL, G_MAXINT,
 
1146
                                     COL_SOURCE_NAME, _("Pictures Folder"),
 
1147
                                     COL_SOURCE_TYPE, SOURCE_PICTURES,
 
1148
                                     COL_SOURCE, priv->pictures_source,
 
1149
                                     -1);
 
1150
 
 
1151
  priv->colors_source = bg_colors_source_new ();
 
1152
  gtk_list_store_insert_with_values (store, NULL, G_MAXINT,
 
1153
                                     COL_SOURCE_NAME, _("Colors & Gradients"),
 
1154
                                     COL_SOURCE_TYPE, SOURCE_COLORS,
 
1155
                                     COL_SOURCE, priv->colors_source,
 
1156
                                     -1);
 
1157
 
 
1158
#ifdef HAVE_LIBSOCIALWEB
 
1159
  priv->flickr_source = bg_flickr_source_new ();
 
1160
  gtk_list_store_insert_with_values (store, NULL, G_MAXINT,
 
1161
                                     COL_SOURCE_NAME, _("Flickr"),
 
1162
                                     COL_SOURCE_TYPE, SOURCE_FLICKR,
 
1163
                                     COL_SOURCE, priv->flickr_source,
 
1164
                                     -1);
 
1165
#endif
 
1166
 
 
1167
 
 
1168
  /* add the top level widget */
 
1169
  widget = WID ("background-panel");
 
1170
 
 
1171
  gtk_container_add (GTK_CONTAINER (self), widget);
 
1172
  gtk_widget_show_all (GTK_WIDGET (self));
 
1173
 
 
1174
  /* connect to source change signal */
 
1175
  widget = WID ("sources-combobox");
 
1176
  g_signal_connect (widget, "changed", G_CALLBACK (source_changed_cb), priv);
 
1177
 
 
1178
  /* select first item */
 
1179
  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
 
1180
 
 
1181
  /* connect to the background iconview change signal */
 
1182
  widget = WID ("backgrounds-iconview");
 
1183
  g_signal_connect (widget, "selection-changed",
 
1184
                    G_CALLBACK (backgrounds_changed_cb),
 
1185
                    self);
 
1186
 
 
1187
  /* Join treeview and buttons */
 
1188
  widget = WID ("scrolledwindow1");
 
1189
  context = gtk_widget_get_style_context (widget);
 
1190
  gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
 
1191
  widget = WID ("toolbar1");
 
1192
  context = gtk_widget_get_style_context (widget);
 
1193
  gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
 
1194
 
 
1195
  g_signal_connect (WID ("add_button"), "clicked",
 
1196
                    G_CALLBACK (add_button_clicked), self);
 
1197
  g_signal_connect (WID ("remove_button"), "clicked",
 
1198
                    G_CALLBACK (remove_button_clicked), self);
 
1199
 
 
1200
  /* setup preview area */
 
1201
  gtk_label_set_ellipsize (GTK_LABEL (WID ("background-label")), PANGO_ELLIPSIZE_END);
 
1202
  widget = WID ("preview-area");
 
1203
  g_signal_connect (widget, "draw", G_CALLBACK (preview_draw_cb),
 
1204
                    self);
 
1205
 
 
1206
  priv->display_base = gdk_pixbuf_new_from_file (DATADIR "/display-base.png",
 
1207
                                                 NULL);
 
1208
  priv->display_overlay = gdk_pixbuf_new_from_file (DATADIR
 
1209
                                                    "/display-overlay.png",
 
1210
                                                    NULL);
 
1211
 
 
1212
  g_signal_connect (WID ("style-combobox"), "changed",
 
1213
                    G_CALLBACK (style_changed_cb), self);
 
1214
 
 
1215
  g_signal_connect (WID ("style-pcolor"), "color-set",
 
1216
                    G_CALLBACK (color_changed_cb), self);
 
1217
  g_signal_connect (WID ("style-scolor"), "color-set",
 
1218
                    G_CALLBACK (color_changed_cb), self);
 
1219
 
 
1220
  priv->copy_cancellable = g_cancellable_new ();
 
1221
 
 
1222
  priv->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
 
1223
 
 
1224
  load_current_bg (self);
 
1225
 
 
1226
  update_preview (priv, NULL);
 
1227
 
 
1228
  /* Setup the edit box with our current settings */
 
1229
  source_update_edit_box (priv, TRUE);
 
1230
}
 
1231
 
 
1232
void
 
1233
cc_background_panel_register (GIOModule *module)
 
1234
{
 
1235
  cc_background_panel_register_type (G_TYPE_MODULE (module));
 
1236
  g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
 
1237
                                  CC_TYPE_BACKGROUND_PANEL,
 
1238
                                  "background", 0);
 
1239
}
 
1240