2
* Copyright (C) 2010 Intel, Inc
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.
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.
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.
18
* Author: Thomas Wood <thomas.wood@intel.com>
25
#include <glib/gi18n-lib.h>
26
#include <gdesktop-enums.h>
28
#include "cc-background-panel.h"
29
#include "bg-wallpapers-source.h"
30
#include "bg-pictures-source.h"
31
#include "bg-colors-source.h"
33
#ifdef HAVE_LIBSOCIALWEB
34
#include "bg-flickr-source.h"
37
#include "cc-background-item.h"
38
#include "cc-background-xml.h"
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"
54
G_DEFINE_DYNAMIC_TYPE (CcBackgroundPanel, cc_background_panel, CC_TYPE_PANEL)
56
#define BACKGROUND_PANEL_PRIVATE(o) \
57
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_BACKGROUND_PANEL, CcBackgroundPanelPrivate))
59
struct _CcBackgroundPanelPrivate
63
BgWallpapersSource *wallpapers_source;
64
BgPicturesSource *pictures_source;
65
BgColorsSource *colors_source;
67
#ifdef HAVE_LIBSOCIALWEB
68
BgFlickrSource *flickr_source;
73
GnomeDesktopThumbnailFactory *thumb_factory;
75
CcBackgroundItem *current_background;
78
GCancellable *copy_cancellable;
82
GdkPixbuf *display_base;
83
GdkPixbuf *display_overlay;
91
#ifdef HAVE_LIBSOCIALWEB
97
#define WID(y) (GtkWidget *) gtk_builder_get_object (priv->builder, y)
100
cc_background_panel_get_property (GObject *object,
108
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
113
cc_background_panel_set_property (GObject *object,
121
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
126
cc_background_panel_dispose (GObject *object)
128
CcBackgroundPanelPrivate *priv = CC_BACKGROUND_PANEL (object)->priv;
132
g_object_unref (priv->builder);
133
priv->builder = NULL;
135
/* destroying the builder object will also destroy the spinner */
136
priv->spinner = NULL;
139
if (priv->wallpapers_source)
141
g_object_unref (priv->wallpapers_source);
142
priv->wallpapers_source = NULL;
145
if (priv->pictures_source)
147
g_object_unref (priv->pictures_source);
148
priv->pictures_source = NULL;
151
if (priv->colors_source)
153
g_object_unref (priv->colors_source);
154
priv->colors_source = NULL;
156
#ifdef HAVE_LIBSOCIALWEB
157
if (priv->flickr_source)
159
g_object_unref (priv->flickr_source);
160
priv->flickr_source = NULL;
166
g_object_unref (priv->settings);
167
priv->settings = NULL;
170
if (priv->copy_cancellable)
172
/* cancel any copy operation */
173
g_cancellable_cancel (priv->copy_cancellable);
175
g_object_unref (priv->copy_cancellable);
176
priv->copy_cancellable = NULL;
179
if (priv->thumb_factory)
181
g_object_unref (priv->thumb_factory);
182
priv->thumb_factory = NULL;
185
if (priv->display_base)
187
g_object_unref (priv->display_base);
188
priv->display_base = NULL;
191
if (priv->display_overlay)
193
g_object_unref (priv->display_overlay);
194
priv->display_overlay = NULL;
197
G_OBJECT_CLASS (cc_background_panel_parent_class)->dispose (object);
201
cc_background_panel_finalize (GObject *object)
203
CcBackgroundPanelPrivate *priv = CC_BACKGROUND_PANEL (object)->priv;
205
if (priv->current_background)
207
g_object_unref (priv->current_background);
208
priv->current_background = NULL;
211
G_OBJECT_CLASS (cc_background_panel_parent_class)->finalize (object);
215
cc_background_panel_class_init (CcBackgroundPanelClass *klass)
217
GObjectClass *object_class = G_OBJECT_CLASS (klass);
219
g_type_class_add_private (klass, sizeof (CcBackgroundPanelPrivate));
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;
228
cc_background_panel_class_finalize (CcBackgroundPanelClass *klass)
233
source_update_edit_box (CcBackgroundPanelPrivate *priv,
236
CcBackgroundItemFlags flags;
238
flags = cc_background_item_get_flags (priv->current_background);
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"));
245
gtk_widget_show (WID ("style-scolor"));
247
if (flags & CC_BACKGROUND_ITEM_HAS_PCOLOR &&
248
priv->current_source != SOURCE_COLORS)
249
gtk_widget_hide (WID ("style-pcolor"));
251
gtk_widget_show (WID ("style-pcolor"));
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"));
257
gtk_widget_show (WID ("style-combobox"));
259
/* FIXME What to do if the background has a gradient shading
260
* and provides the colours? */
264
source_changed_cb (GtkComboBox *combo,
265
CcBackgroundPanelPrivate *priv)
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);
279
view = (GtkIconView *) gtk_builder_get_object (priv->builder,
280
"backgrounds-iconview");
282
gtk_icon_view_set_model (view,
283
GTK_TREE_MODEL (bg_source_get_liststore (source)));
287
select_style (GtkComboBox *box,
288
GDesktopBackgroundStyle new_style)
294
model = gtk_combo_box_get_model (box);
295
cont = gtk_tree_model_get_iter_first (model, &iter);
296
while (cont != FALSE)
298
GDesktopBackgroundStyle style;
300
gtk_tree_model_get (model, &iter,
304
if (style == new_style)
306
gtk_combo_box_set_active_iter (box, &iter);
309
cont = gtk_tree_model_iter_next (model, &iter);
313
gtk_combo_box_set_active (box, -1);
317
update_preview (CcBackgroundPanelPrivate *priv,
318
CcBackgroundItem *item)
321
gboolean changes_with_time;
323
if (item && priv->current_background)
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);
330
source_update_edit_box (priv, FALSE);
332
changes_with_time = FALSE;
334
if (priv->current_background)
336
GdkColor pcolor, scolor;
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);
342
gtk_label_set_text (GTK_LABEL (WID ("size_label")), cc_background_item_get_size (priv->current_background));
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);
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);
350
select_style (GTK_COMBO_BOX (WID ("style-combobox")),
351
cc_background_item_get_placement (priv->current_background));
353
changes_with_time = cc_background_item_changes_with_time (priv->current_background);
356
gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
357
gtk_widget_set_visible (WID ("slide-label"), changes_with_time);
359
gtk_widget_queue_draw (WID ("preview-area"));
365
return g_build_filename (g_get_user_config_dir (),
366
"gnome-control-center",
373
create_save_dir (void)
377
path = g_build_filename (g_get_user_config_dir (),
378
"gnome-control-center",
381
if (g_mkdir_with_parents (path, 0755) < 0)
383
g_warning ("Failed to create directory '%s'", path);
392
copy_finished_cb (GObject *source_object,
393
GAsyncResult *result,
397
CcBackgroundPanel *panel = (CcBackgroundPanel *) pointer;
398
CcBackgroundPanelPrivate *priv = panel->priv;
399
CcBackgroundItem *item;
401
if (!g_file_copy_finish (G_FILE (source_object), result, &err))
403
if (err->code != G_IO_ERROR_CANCELLED)
404
g_warning ("Failed to copy image to cache location: %s", err->message);
408
item = g_object_get_data (source_object, "item");
410
/* the panel may have been destroyed before the callback is run, so be sure
411
* to check the widgets are not NULL */
415
gtk_widget_destroy (GTK_WIDGET (priv->spinner));
416
priv->spinner = NULL;
419
if (priv->current_background)
420
cc_background_item_load (priv->current_background, NULL);
426
update_preview (priv, item);
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);
434
/* remove the reference taken when the copy was set up */
435
g_object_unref (panel);
439
update_remove_button (CcBackgroundPanel *panel,
440
CcBackgroundItem *item)
442
CcBackgroundPanelPrivate *priv;
445
GFile *bg, *cache, *parent;
446
gboolean sensitive = FALSE;
450
if (priv->current_source != SOURCE_PICTURES)
453
uri = cc_background_item_get_uri (item);
457
bg = g_file_new_for_uri (uri);
458
parent = g_file_get_parent (bg);
464
cache_path = bg_pictures_source_get_cache_path ();
465
cache = g_file_new_for_path (cache_path);
468
if (g_file_equal (parent, cache))
471
g_object_unref (parent);
472
g_object_unref (cache);
475
gtk_widget_set_sensitive (WID ("remove_button"), sensitive);
479
static CcBackgroundItem *
480
get_selected_item (CcBackgroundPanel *panel)
482
CcBackgroundPanelPrivate *priv = panel->priv;
483
GtkIconView *icon_view;
487
CcBackgroundItem *item;
489
icon_view = GTK_ICON_VIEW (WID ("backgrounds-iconview"));
491
list = gtk_icon_view_get_selected_items (icon_view);
496
model = gtk_icon_view_get_model (icon_view);
498
if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath*) list->data) == FALSE)
501
gtk_tree_model_get (model, &iter, 1, &item, -1);
504
g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
511
backgrounds_changed_cb (GtkIconView *icon_view,
512
CcBackgroundPanel *panel)
516
CcBackgroundItem *item;
517
CcBackgroundPanelPrivate *priv = panel->priv;
518
char *pcolor, *scolor;
519
gboolean draw_preview = TRUE;
521
CcBackgroundItemFlags flags;
524
item = get_selected_item (panel);
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")),
533
gtk_tree_model_get (model, &iter,
534
COL_SOURCE_TYPE, &priv->current_source, -1);
536
uri = cc_background_item_get_uri (item);
537
flags = cc_background_item_get_flags (item);
539
if ((flags & CC_BACKGROUND_ITEM_HAS_URI) && uri == NULL)
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, "");
544
else if (cc_background_item_get_source_url (item) != NULL &&
545
cc_background_item_get_needs_download (item))
547
GFile *source, *dest;
548
gchar *cache_path, *basename, *dest_path, *display_name, *dest_uri;
551
cache_path = bg_pictures_source_get_cache_path ();
552
if (g_mkdir_with_parents (cache_path, 0755) < 0)
554
g_warning ("Failed to create directory '%s'", cache_path);
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);
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);
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);
576
if (priv->copy_cancellable)
578
g_cancellable_cancel (priv->copy_cancellable);
579
g_cancellable_reset (priv->copy_cancellable);
584
gtk_widget_destroy (GTK_WIDGET (priv->spinner));
585
priv->spinner = NULL;
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,
593
gtk_widget_show (priv->spinner);
595
/* reference the panel in case it is removed before the copy is
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,
602
copy_finished_cb, panel);
603
g_object_unref (source);
604
dest_uri = g_file_get_uri (dest);
605
g_object_unref (dest);
607
g_settings_set_string (priv->settings, WP_URI_KEY, dest_uri);
608
g_object_set (G_OBJECT (item),
610
"needs-download", FALSE,
611
"name", display_name,
613
g_free (display_name);
616
/* delay the updated drawing of the preview until the copy finishes */
617
draw_preview = FALSE;
621
g_settings_set_string (priv->settings, WP_URI_KEY, uri);
624
/* Also set the placement if we have a URI and the previous value was none */
625
if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT)
627
g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
629
else if (uri != NULL)
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));
637
if (flags & CC_BACKGROUND_ITEM_HAS_SHADING)
638
g_settings_set_enum (priv->settings, WP_SHADING_KEY, cc_background_item_get_shading (item));
640
/* When changing to a background with colours set,
641
* don't overwrite what's in GSettings, but read
643
* We have a hack for the colors source though */
644
if (flags & CC_BACKGROUND_ITEM_HAS_PCOLOR &&
645
priv->current_source != SOURCE_COLORS)
647
g_settings_set_string (priv->settings, WP_PCOLOR_KEY, cc_background_item_get_pcolor (item));
651
pcolor = g_settings_get_string (priv->settings, WP_PCOLOR_KEY);
652
g_object_set (G_OBJECT (item), "primary-color", pcolor, NULL);
655
if (flags & CC_BACKGROUND_ITEM_HAS_SCOLOR &&
656
priv->current_source != SOURCE_COLORS)
658
g_settings_set_string (priv->settings, WP_SCOLOR_KEY, cc_background_item_get_scolor (item));
662
scolor = g_settings_get_string (priv->settings, WP_SCOLOR_KEY);
663
g_object_set (G_OBJECT (item), "secondary-color", scolor, NULL);
666
/* Apply all changes */
667
g_settings_apply (priv->settings);
669
update_remove_button (panel, item);
671
/* update the preview information */
672
if (draw_preview != FALSE)
674
update_preview (priv, item);
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);
684
preview_draw_cb (GtkWidget *widget,
686
CcBackgroundPanel *panel)
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;
698
gtk_widget_get_allocation (widget, &allocation);
700
if (priv->current_background)
703
icon = cc_background_item_get_frame_thumbnail (priv->current_background,
708
pixbuf = GDK_PIXBUF (icon);
711
if (!priv->display_base)
715
preview = gdk_pixbuf_copy (priv->display_base);
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);
725
g_object_unref (pixbuf);
729
if (priv->display_overlay)
731
gdk_pixbuf_composite (priv->display_overlay, preview,
734
GDK_INTERP_BILINEAR, 255);
738
if (allocation.width < allocation.height)
739
size = allocation.width;
741
size = allocation.height;
743
temp = gdk_pixbuf_scale_simple (preview, size, size, GDK_INTERP_BILINEAR);
745
gdk_cairo_set_source_pixbuf (cr,
747
allocation.width / 2 - (size / 2),
748
allocation.height / 2 - (size / 2));
751
g_object_unref (temp);
752
g_object_unref (preview);
758
style_changed_cb (GtkComboBox *box,
759
CcBackgroundPanel *panel)
761
CcBackgroundPanelPrivate *priv = panel->priv;
764
GDesktopBackgroundStyle value;
766
if (!gtk_combo_box_get_active_iter (box, &iter))
771
model = gtk_combo_box_get_model (box);
773
gtk_tree_model_get (model, &iter, 1, &value, -1);
775
g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, value);
777
if (priv->current_background)
778
g_object_set (G_OBJECT (priv->current_background), "placement", value, NULL);
780
g_settings_apply (priv->settings);
782
update_preview (priv, NULL);
786
color_changed_cb (GtkColorButton *button,
787
CcBackgroundPanel *panel)
789
CcBackgroundPanelPrivate *priv = panel->priv;
792
gboolean is_pcolor = FALSE;
794
gtk_color_button_get_color (button, &color);
795
if (WID ("style-pcolor") == GTK_WIDGET (button))
798
value = gdk_color_to_string (&color);
800
if (priv->current_background)
802
g_object_set (G_OBJECT (priv->current_background),
803
is_pcolor ? "primary-color" : "secondary-color", value, NULL);
806
g_settings_set_string (priv->settings,
807
is_pcolor ? WP_PCOLOR_KEY : WP_SCOLOR_KEY, value);
809
g_settings_apply (priv->settings);
813
update_preview (priv, NULL);
817
row_inserted (GtkTreeModel *tree_model,
820
CcBackgroundPanel *panel)
823
CcBackgroundPanelPrivate *priv;
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);
831
gtk_combo_box_set_active (GTK_COMBO_BOX (WID ("sources-combobox")), SOURCE_PICTURES);
833
/* And select the newly added item */
834
gtk_icon_view_select_path (GTK_ICON_VIEW (WID ("backgrounds-iconview")), path);
838
add_custom_wallpaper (CcBackgroundPanel *panel,
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);
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);
852
/* Wait for the item to get added */
856
file_chooser_response (GtkDialog *chooser,
858
CcBackgroundPanel *panel)
860
GSList *selected, *l;
862
if (response != GTK_RESPONSE_ACCEPT)
864
gtk_widget_destroy (GTK_WIDGET (chooser));
868
selected = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
869
gtk_widget_destroy (GTK_WIDGET (chooser));
871
for (l = selected; l != NULL; l = l->next)
874
add_custom_wallpaper (panel, uri);
877
g_slist_free (selected);
881
update_chooser_preview (GtkFileChooser *chooser,
882
CcBackgroundPanel *panel)
884
GnomeDesktopThumbnailFactory *thumb_factory;
887
thumb_factory = panel->priv->thumb_factory;
889
uri = gtk_file_chooser_get_preview_uri (chooser);
893
GdkPixbuf *pixbuf = NULL;
894
const gchar *mime_type = NULL;
896
GFileInfo *file_info;
899
preview = gtk_file_chooser_get_preview_widget (chooser);
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,
906
g_object_unref (file);
908
if (file_info != NULL) {
909
mime_type = g_file_info_get_content_type (file_info);
910
g_object_unref (file_info);
915
pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumb_factory,
920
gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
926
gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
927
g_object_unref (pixbuf);
931
gtk_image_set_from_stock (GTK_IMAGE (preview),
932
GTK_STOCK_DIALOG_QUESTION,
933
GTK_ICON_SIZE_DIALOG);
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);
939
gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT, TRUE);
944
gtk_file_chooser_set_preview_widget_active (chooser, TRUE);
948
add_button_clicked (GtkButton *button,
949
CcBackgroundPanel *panel)
954
GtkFileFilter *filter;
955
CcBackgroundPanelPrivate *priv;
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");
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,
969
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), filter);
970
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
972
gtk_window_set_modal (GTK_WINDOW (chooser), TRUE);
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);
982
folder = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
984
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
987
g_signal_connect (chooser, "response",
988
G_CALLBACK (file_chooser_response), panel);
990
gtk_window_present (GTK_WINDOW (chooser));
994
remove_button_clicked (GtkButton *button,
995
CcBackgroundPanel *panel)
997
CcBackgroundItem *item;
1000
CcBackgroundPanelPrivate *priv;
1004
item = get_selected_item (panel);
1006
g_assert_not_reached ();
1008
bg_pictures_source_remove (panel->priv->pictures_source, item);
1009
g_object_unref (item);
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);
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);
1022
load_current_bg (CcBackgroundPanel *self)
1024
CcBackgroundPanelPrivate *priv;
1025
CcBackgroundItem *saved, *configured;
1026
gchar *uri, *pcolor, *scolor;
1030
/* Load the saved configuration */
1031
uri = get_save_path ();
1032
saved = cc_background_xml_get_item (uri);
1035
/* initalise the current background information from settings */
1036
uri = g_settings_get_string (priv->settings, WP_URI_KEY);
1037
if (uri && *uri == '\0')
1046
file = g_file_new_for_commandline_arg (uri);
1047
g_object_unref (file);
1049
configured = cc_background_item_new (uri);
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,
1064
if (saved != NULL && cc_background_item_compare (saved, configured))
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),
1074
"source-url", cc_background_item_get_source_url (saved),
1075
"source-xml", cc_background_item_get_source_xml (saved),
1079
g_object_unref (saved);
1081
priv->current_background = configured;
1082
cc_background_item_load (priv->current_background, NULL);
1086
scrolled_realize_cb (GtkWidget *scrolled,
1087
CcBackgroundPanel *self)
1089
/* FIXME, hack for https://bugzilla.gnome.org/show_bug.cgi?id=645649 */
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);
1102
cc_background_panel_init (CcBackgroundPanel *self)
1104
CcBackgroundPanelPrivate *priv;
1105
gchar *objects[] = { "style-liststore",
1106
"sources-liststore", "background-panel", "sizegroup", NULL };
1109
GtkListStore *store;
1110
GtkStyleContext *context;
1112
priv = self->priv = BACKGROUND_PANEL_PRIVATE (self);
1114
priv->builder = gtk_builder_new ();
1116
gtk_builder_add_objects_from_file (priv->builder,
1117
DATADIR"/background.ui",
1122
g_warning ("Could not load ui: %s", err->message);
1127
/* See shell_notify_cb for details */
1128
g_signal_connect (WID ("scrolledwindow1"), "realize",
1129
G_CALLBACK (scrolled_realize_cb), self);
1131
priv->settings = g_settings_new (WP_PATH_ID);
1132
g_settings_delay (priv->settings);
1134
store = (GtkListStore*) gtk_builder_get_object (priv->builder,
1135
"sources-liststore");
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,
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,
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,
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,
1168
/* add the top level widget */
1169
widget = WID ("background-panel");
1171
gtk_container_add (GTK_CONTAINER (self), widget);
1172
gtk_widget_show_all (GTK_WIDGET (self));
1174
/* connect to source change signal */
1175
widget = WID ("sources-combobox");
1176
g_signal_connect (widget, "changed", G_CALLBACK (source_changed_cb), priv);
1178
/* select first item */
1179
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
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),
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);
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);
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),
1206
priv->display_base = gdk_pixbuf_new_from_file (DATADIR "/display-base.png",
1208
priv->display_overlay = gdk_pixbuf_new_from_file (DATADIR
1209
"/display-overlay.png",
1212
g_signal_connect (WID ("style-combobox"), "changed",
1213
G_CALLBACK (style_changed_cb), self);
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);
1220
priv->copy_cancellable = g_cancellable_new ();
1222
priv->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
1224
load_current_bg (self);
1226
update_preview (priv, NULL);
1228
/* Setup the edit box with our current settings */
1229
source_update_edit_box (priv, TRUE);
1233
cc_background_panel_register (GIOModule *module)
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,