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 (gtk_widget_get_visible (WID ("style-pcolor")) &&
254
gtk_widget_get_visible (WID ("style-scolor")))
255
gtk_widget_show (WID ("swap-color-button"));
257
gtk_widget_hide (WID ("swap-color-button"));
259
if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT ||
260
cc_background_item_get_uri (priv->current_background) == NULL)
261
gtk_widget_hide (WID ("style-combobox"));
263
gtk_widget_show (WID ("style-combobox"));
265
/* FIXME What to do if the background has a gradient shading
266
* and provides the colours? */
270
source_changed_cb (GtkComboBox *combo,
271
CcBackgroundPanelPrivate *priv)
279
gtk_combo_box_get_active_iter (combo, &iter);
280
model = gtk_combo_box_get_model (combo);
281
gtk_tree_model_get (model, &iter,
282
COL_SOURCE_TYPE, &type,
283
COL_SOURCE, &source, -1);
285
view = (GtkIconView *) gtk_builder_get_object (priv->builder,
286
"backgrounds-iconview");
288
gtk_icon_view_set_model (view,
289
GTK_TREE_MODEL (bg_source_get_liststore (source)));
293
select_style (GtkComboBox *box,
294
GDesktopBackgroundStyle new_style)
300
model = gtk_combo_box_get_model (box);
301
cont = gtk_tree_model_get_iter_first (model, &iter);
302
while (cont != FALSE)
304
GDesktopBackgroundStyle style;
306
gtk_tree_model_get (model, &iter,
310
if (style == new_style)
312
gtk_combo_box_set_active_iter (box, &iter);
315
cont = gtk_tree_model_iter_next (model, &iter);
319
gtk_combo_box_set_active (box, -1);
323
update_preview (CcBackgroundPanelPrivate *priv,
324
CcBackgroundItem *item)
327
gboolean changes_with_time;
329
if (item && priv->current_background)
331
g_object_unref (priv->current_background);
332
priv->current_background = cc_background_item_copy (item);
333
cc_background_item_load (priv->current_background, NULL);
336
source_update_edit_box (priv, FALSE);
338
changes_with_time = FALSE;
340
if (priv->current_background)
342
GdkColor pcolor, scolor;
344
markup = g_strdup_printf ("<b>%s</b>", cc_background_item_get_name (priv->current_background));
345
gtk_label_set_markup (GTK_LABEL (WID ("background-label")), markup);
348
gtk_label_set_text (GTK_LABEL (WID ("size_label")), cc_background_item_get_size (priv->current_background));
350
gdk_color_parse (cc_background_item_get_pcolor (priv->current_background), &pcolor);
351
gdk_color_parse (cc_background_item_get_scolor (priv->current_background), &scolor);
353
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-pcolor")), &pcolor);
354
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-scolor")), &scolor);
356
select_style (GTK_COMBO_BOX (WID ("style-combobox")),
357
cc_background_item_get_placement (priv->current_background));
359
changes_with_time = cc_background_item_changes_with_time (priv->current_background);
362
gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
363
gtk_widget_set_visible (WID ("slide-label"), changes_with_time);
365
gtk_widget_queue_draw (WID ("preview-area"));
371
return g_build_filename (g_get_user_config_dir (),
372
"gnome-control-center",
379
create_save_dir (void)
383
path = g_build_filename (g_get_user_config_dir (),
384
"gnome-control-center",
387
if (g_mkdir_with_parents (path, 0755) < 0)
389
g_warning ("Failed to create directory '%s'", path);
398
copy_finished_cb (GObject *source_object,
399
GAsyncResult *result,
403
CcBackgroundPanel *panel = (CcBackgroundPanel *) pointer;
404
CcBackgroundPanelPrivate *priv = panel->priv;
405
CcBackgroundItem *item;
407
if (!g_file_copy_finish (G_FILE (source_object), result, &err))
409
if (err->code != G_IO_ERROR_CANCELLED)
410
g_warning ("Failed to copy image to cache location: %s", err->message);
414
item = g_object_get_data (source_object, "item");
416
/* the panel may have been destroyed before the callback is run, so be sure
417
* to check the widgets are not NULL */
421
gtk_widget_destroy (GTK_WIDGET (priv->spinner));
422
priv->spinner = NULL;
425
if (priv->current_background)
426
cc_background_item_load (priv->current_background, NULL);
432
update_preview (priv, item);
434
/* Save the source XML if there is one */
435
filename = get_save_path ();
436
if (create_save_dir ())
437
cc_background_xml_save (priv->current_background, filename);
440
/* remove the reference taken when the copy was set up */
441
g_object_unref (panel);
445
update_remove_button (CcBackgroundPanel *panel,
446
CcBackgroundItem *item)
448
CcBackgroundPanelPrivate *priv;
451
GFile *bg, *cache, *parent;
452
gboolean sensitive = FALSE;
456
if (priv->current_source != SOURCE_PICTURES)
459
uri = cc_background_item_get_uri (item);
463
bg = g_file_new_for_uri (uri);
464
parent = g_file_get_parent (bg);
470
cache_path = bg_pictures_source_get_cache_path ();
471
cache = g_file_new_for_path (cache_path);
474
if (g_file_equal (parent, cache))
477
g_object_unref (parent);
478
g_object_unref (cache);
481
gtk_widget_set_sensitive (WID ("remove_button"), sensitive);
485
static CcBackgroundItem *
486
get_selected_item (CcBackgroundPanel *panel)
488
CcBackgroundPanelPrivate *priv = panel->priv;
489
GtkIconView *icon_view;
493
CcBackgroundItem *item;
495
icon_view = GTK_ICON_VIEW (WID ("backgrounds-iconview"));
497
list = gtk_icon_view_get_selected_items (icon_view);
502
model = gtk_icon_view_get_model (icon_view);
504
if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath*) list->data) == FALSE)
507
gtk_tree_model_get (model, &iter, 1, &item, -1);
510
g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
517
backgrounds_changed_cb (GtkIconView *icon_view,
518
CcBackgroundPanel *panel)
522
CcBackgroundItem *item;
523
CcBackgroundPanelPrivate *priv = panel->priv;
524
char *pcolor, *scolor;
525
gboolean draw_preview = TRUE;
527
CcBackgroundItemFlags flags;
530
item = get_selected_item (panel);
535
/* Update current source */
536
model = gtk_combo_box_get_model (GTK_COMBO_BOX (WID ("sources-combobox")));
537
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (WID ("sources-combobox")),
539
gtk_tree_model_get (model, &iter,
540
COL_SOURCE_TYPE, &priv->current_source, -1);
542
uri = cc_background_item_get_uri (item);
543
flags = cc_background_item_get_flags (item);
545
if ((flags & CC_BACKGROUND_ITEM_HAS_URI) && uri == NULL)
547
g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, G_DESKTOP_BACKGROUND_STYLE_NONE);
548
g_settings_set_string (priv->settings, WP_URI_KEY, "");
550
else if (cc_background_item_get_source_url (item) != NULL &&
551
cc_background_item_get_needs_download (item))
553
GFile *source, *dest;
554
gchar *cache_path, *basename, *dest_path, *display_name, *dest_uri;
557
cache_path = bg_pictures_source_get_cache_path ();
558
if (g_mkdir_with_parents (cache_path, 0755) < 0)
560
g_warning ("Failed to create directory '%s'", cache_path);
566
dest_path = bg_pictures_source_get_unique_path (cc_background_item_get_source_url (item));
567
dest = g_file_new_for_path (dest_path);
569
source = g_file_new_for_uri (cc_background_item_get_source_url (item));
570
basename = g_file_get_basename (source);
571
display_name = g_filename_display_name (basename);
572
dest_path = g_file_get_path (dest);
575
/* create a blank image to use until the source image is ready */
576
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
577
gdk_pixbuf_fill (pixbuf, 0x00000000);
578
gdk_pixbuf_save (pixbuf, dest_path, "png", NULL, NULL);
579
g_object_unref (pixbuf);
582
if (priv->copy_cancellable)
584
g_cancellable_cancel (priv->copy_cancellable);
585
g_cancellable_reset (priv->copy_cancellable);
590
gtk_widget_destroy (GTK_WIDGET (priv->spinner));
591
priv->spinner = NULL;
594
/* create a spinner while the file downloads */
595
priv->spinner = gtk_spinner_new ();
596
gtk_spinner_start (GTK_SPINNER (priv->spinner));
597
gtk_box_pack_start (GTK_BOX (WID ("bottom-hbox")), priv->spinner, FALSE,
599
gtk_widget_show (priv->spinner);
601
/* reference the panel in case it is removed before the copy is
603
g_object_ref (panel);
604
g_object_set_data_full (G_OBJECT (source), "item", g_object_ref (item), g_object_unref);
605
g_file_copy_async (source, dest, G_FILE_COPY_OVERWRITE,
606
G_PRIORITY_DEFAULT, priv->copy_cancellable,
608
copy_finished_cb, panel);
609
g_object_unref (source);
610
dest_uri = g_file_get_uri (dest);
611
g_object_unref (dest);
613
g_settings_set_string (priv->settings, WP_URI_KEY, dest_uri);
614
g_object_set (G_OBJECT (item),
616
"needs-download", FALSE,
617
"name", display_name,
619
g_free (display_name);
622
/* delay the updated drawing of the preview until the copy finishes */
623
draw_preview = FALSE;
627
g_settings_set_string (priv->settings, WP_URI_KEY, uri);
630
/* Also set the placement if we have a URI and the previous value was none */
631
if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT)
633
g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
635
else if (uri != NULL)
637
GDesktopBackgroundStyle style;
638
style = g_settings_get_enum (priv->settings, WP_OPTIONS_KEY);
639
if (style == G_DESKTOP_BACKGROUND_STYLE_NONE)
640
g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item));
643
if (flags & CC_BACKGROUND_ITEM_HAS_SHADING)
644
g_settings_set_enum (priv->settings, WP_SHADING_KEY, cc_background_item_get_shading (item));
646
/* When changing to a background with colours set,
647
* don't overwrite what's in GSettings, but read
649
* We have a hack for the colors source though */
650
if (flags & CC_BACKGROUND_ITEM_HAS_PCOLOR &&
651
priv->current_source != SOURCE_COLORS)
653
g_settings_set_string (priv->settings, WP_PCOLOR_KEY, cc_background_item_get_pcolor (item));
657
pcolor = g_settings_get_string (priv->settings, WP_PCOLOR_KEY);
658
g_object_set (G_OBJECT (item), "primary-color", pcolor, NULL);
661
if (flags & CC_BACKGROUND_ITEM_HAS_SCOLOR &&
662
priv->current_source != SOURCE_COLORS)
664
g_settings_set_string (priv->settings, WP_SCOLOR_KEY, cc_background_item_get_scolor (item));
668
scolor = g_settings_get_string (priv->settings, WP_SCOLOR_KEY);
669
g_object_set (G_OBJECT (item), "secondary-color", scolor, NULL);
672
/* Apply all changes */
673
g_settings_apply (priv->settings);
675
update_remove_button (panel, item);
677
/* update the preview information */
678
if (draw_preview != FALSE)
680
update_preview (priv, item);
682
/* Save the source XML if there is one */
683
filename = get_save_path ();
684
if (create_save_dir ())
685
cc_background_xml_save (priv->current_background, filename);
690
preview_draw_cb (GtkWidget *widget,
692
CcBackgroundPanel *panel)
694
GtkAllocation allocation;
695
CcBackgroundPanelPrivate *priv = panel->priv;
696
GdkPixbuf *pixbuf = NULL;
697
const gint preview_width = 416;
698
const gint preview_height = 248;
699
const gint preview_x = 45;
700
const gint preview_y = 84;
701
GdkPixbuf *preview, *temp;
704
gtk_widget_get_allocation (widget, &allocation);
706
if (priv->current_background)
709
icon = cc_background_item_get_frame_thumbnail (priv->current_background,
714
pixbuf = GDK_PIXBUF (icon);
717
if (!priv->display_base)
721
preview = gdk_pixbuf_copy (priv->display_base);
725
gdk_pixbuf_composite (pixbuf, preview,
726
preview_x, preview_y,
727
preview_width, preview_height,
728
preview_x, preview_y, 1, 1,
729
GDK_INTERP_BILINEAR, 255);
731
g_object_unref (pixbuf);
735
if (priv->display_overlay)
737
gdk_pixbuf_composite (priv->display_overlay, preview,
740
GDK_INTERP_BILINEAR, 255);
744
if (allocation.width < allocation.height)
745
size = allocation.width;
747
size = allocation.height;
749
temp = gdk_pixbuf_scale_simple (preview, size, size, GDK_INTERP_BILINEAR);
751
gdk_cairo_set_source_pixbuf (cr,
753
allocation.width / 2 - (size / 2),
754
allocation.height / 2 - (size / 2));
757
g_object_unref (temp);
758
g_object_unref (preview);
764
style_changed_cb (GtkComboBox *box,
765
CcBackgroundPanel *panel)
767
CcBackgroundPanelPrivate *priv = panel->priv;
770
GDesktopBackgroundStyle value;
772
if (!gtk_combo_box_get_active_iter (box, &iter))
777
model = gtk_combo_box_get_model (box);
779
gtk_tree_model_get (model, &iter, 1, &value, -1);
781
g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, value);
783
if (priv->current_background)
784
g_object_set (G_OBJECT (priv->current_background), "placement", value, NULL);
786
g_settings_apply (priv->settings);
788
update_preview (priv, NULL);
792
color_changed_cb (GtkColorButton *button,
793
CcBackgroundPanel *panel)
795
CcBackgroundPanelPrivate *priv = panel->priv;
798
gboolean is_pcolor = FALSE;
800
gtk_color_button_get_color (button, &color);
801
if (WID ("style-pcolor") == GTK_WIDGET (button))
804
value = gdk_color_to_string (&color);
806
if (priv->current_background)
808
g_object_set (G_OBJECT (priv->current_background),
809
is_pcolor ? "primary-color" : "secondary-color", value, NULL);
812
g_settings_set_string (priv->settings,
813
is_pcolor ? WP_PCOLOR_KEY : WP_SCOLOR_KEY, value);
815
g_settings_apply (priv->settings);
819
update_preview (priv, NULL);
823
swap_colors_clicked (GtkButton *button,
824
CcBackgroundPanel *panel)
826
CcBackgroundPanelPrivate *priv = panel->priv;
827
GdkColor pcolor, scolor;
828
char *new_pcolor, *new_scolor;
830
gtk_color_button_get_color (GTK_COLOR_BUTTON (WID ("style-pcolor")), &pcolor);
831
gtk_color_button_get_color (GTK_COLOR_BUTTON (WID ("style-scolor")), &scolor);
833
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-scolor")), &pcolor);
834
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-pcolor")), &scolor);
836
new_pcolor = gdk_color_to_string (&scolor);
837
new_scolor = gdk_color_to_string (&pcolor);
839
g_object_set (priv->current_background,
840
"primary-color", new_pcolor,
841
"secondary-color", new_scolor,
844
g_settings_set_string (priv->settings, WP_PCOLOR_KEY, new_pcolor);
845
g_settings_set_string (priv->settings, WP_SCOLOR_KEY, new_scolor);
850
g_settings_apply (priv->settings);
852
update_preview (priv, NULL);
856
row_inserted (GtkTreeModel *tree_model,
859
CcBackgroundPanel *panel)
862
CcBackgroundPanelPrivate *priv;
866
store = bg_source_get_liststore (BG_SOURCE (panel->priv->pictures_source));
867
g_signal_handlers_disconnect_by_func (G_OBJECT (store), G_CALLBACK (row_inserted), panel);
870
gtk_combo_box_set_active (GTK_COMBO_BOX (WID ("sources-combobox")), SOURCE_PICTURES);
872
/* And select the newly added item */
873
gtk_icon_view_select_path (GTK_ICON_VIEW (WID ("backgrounds-iconview")), path);
877
add_custom_wallpaper (CcBackgroundPanel *panel,
882
store = bg_source_get_liststore (BG_SOURCE (panel->priv->pictures_source));
883
g_signal_connect (G_OBJECT (store), "row-inserted",
884
G_CALLBACK (row_inserted), panel);
886
if (bg_pictures_source_add (panel->priv->pictures_source, uri) == FALSE) {
887
g_signal_handlers_disconnect_by_func (G_OBJECT (store), G_CALLBACK (row_inserted), panel);
891
/* Wait for the item to get added */
895
file_chooser_response (GtkDialog *chooser,
897
CcBackgroundPanel *panel)
899
GSList *selected, *l;
901
if (response != GTK_RESPONSE_ACCEPT)
903
gtk_widget_destroy (GTK_WIDGET (chooser));
907
selected = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
908
gtk_widget_destroy (GTK_WIDGET (chooser));
910
for (l = selected; l != NULL; l = l->next)
913
add_custom_wallpaper (panel, uri);
916
g_slist_free (selected);
920
update_chooser_preview (GtkFileChooser *chooser,
921
CcBackgroundPanel *panel)
923
GnomeDesktopThumbnailFactory *thumb_factory;
926
thumb_factory = panel->priv->thumb_factory;
928
uri = gtk_file_chooser_get_preview_uri (chooser);
932
GdkPixbuf *pixbuf = NULL;
933
const gchar *mime_type = NULL;
935
GFileInfo *file_info;
938
preview = gtk_file_chooser_get_preview_widget (chooser);
940
file = g_file_new_for_uri (uri);
941
file_info = g_file_query_info (file,
942
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
943
G_FILE_QUERY_INFO_NONE,
945
g_object_unref (file);
947
if (file_info != NULL) {
948
mime_type = g_file_info_get_content_type (file_info);
949
g_object_unref (file_info);
954
pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumb_factory,
959
gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
965
gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
966
g_object_unref (pixbuf);
970
gtk_image_set_from_stock (GTK_IMAGE (preview),
971
GTK_STOCK_DIALOG_QUESTION,
972
GTK_ICON_SIZE_DIALOG);
975
if (bg_pictures_source_is_known (panel->priv->pictures_source, uri))
976
gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT, FALSE);
978
gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT, TRUE);
983
gtk_file_chooser_set_preview_widget_active (chooser, TRUE);
987
add_button_clicked (GtkButton *button,
988
CcBackgroundPanel *panel)
993
GtkFileFilter *filter;
994
CcBackgroundPanelPrivate *priv;
998
filter = gtk_file_filter_new ();
999
gtk_file_filter_add_mime_type (filter, "image/*");
1001
chooser = gtk_file_chooser_dialog_new (_("Browse for more pictures"),
1002
GTK_WINDOW (gtk_widget_get_toplevel (WID ("background-panel"))),
1003
GTK_FILE_CHOOSER_ACTION_OPEN,
1004
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1005
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1007
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), filter);
1008
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
1010
gtk_window_set_modal (GTK_WINDOW (chooser), TRUE);
1012
preview = gtk_image_new ();
1013
gtk_widget_set_size_request (preview, 128, -1);
1014
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (chooser), preview);
1015
gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (chooser), FALSE);
1016
gtk_widget_show (preview);
1017
g_signal_connect (chooser, "update-preview",
1018
G_CALLBACK (update_chooser_preview), panel);
1020
folder = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
1022
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
1025
g_signal_connect (chooser, "response",
1026
G_CALLBACK (file_chooser_response), panel);
1028
gtk_window_present (GTK_WINDOW (chooser));
1032
remove_button_clicked (GtkButton *button,
1033
CcBackgroundPanel *panel)
1035
CcBackgroundItem *item;
1036
GtkListStore *store;
1038
CcBackgroundPanelPrivate *priv;
1042
item = get_selected_item (panel);
1044
g_assert_not_reached ();
1046
bg_pictures_source_remove (panel->priv->pictures_source, item);
1047
g_object_unref (item);
1049
/* Are there any items left in the pictures tree store? */
1050
store = bg_source_get_liststore (BG_SOURCE (panel->priv->pictures_source));
1051
if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 0)
1052
gtk_combo_box_set_active (GTK_COMBO_BOX (WID ("sources-combobox")), SOURCE_WALLPAPERS);
1054
path = gtk_tree_path_new_from_string ("0");
1055
gtk_icon_view_select_path (GTK_ICON_VIEW (WID ("backgrounds-iconview")), path);
1056
gtk_tree_path_free (path);
1060
load_current_bg (CcBackgroundPanel *self)
1062
CcBackgroundPanelPrivate *priv;
1063
CcBackgroundItem *saved, *configured;
1064
gchar *uri, *pcolor, *scolor;
1068
/* Load the saved configuration */
1069
uri = get_save_path ();
1070
saved = cc_background_xml_get_item (uri);
1073
/* initalise the current background information from settings */
1074
uri = g_settings_get_string (priv->settings, WP_URI_KEY);
1075
if (uri && *uri == '\0')
1084
file = g_file_new_for_commandline_arg (uri);
1085
g_object_unref (file);
1087
configured = cc_background_item_new (uri);
1090
pcolor = g_settings_get_string (priv->settings, WP_PCOLOR_KEY);
1091
scolor = g_settings_get_string (priv->settings, WP_SCOLOR_KEY);
1092
g_object_set (G_OBJECT (configured),
1093
"name", _("Current background"),
1094
"placement", g_settings_get_enum (priv->settings, WP_OPTIONS_KEY),
1095
"shading", g_settings_get_enum (priv->settings, WP_SHADING_KEY),
1096
"primary-color", pcolor,
1097
"secondary-color", scolor,
1102
if (saved != NULL && cc_background_item_compare (saved, configured))
1104
CcBackgroundItemFlags flags;
1105
flags = cc_background_item_get_flags (saved);
1106
/* Special case for colours */
1107
if (cc_background_item_get_placement (saved) == G_DESKTOP_BACKGROUND_STYLE_NONE)
1108
flags &=~ (CC_BACKGROUND_ITEM_HAS_PCOLOR | CC_BACKGROUND_ITEM_HAS_SCOLOR);
1109
g_object_set (G_OBJECT (configured),
1110
"name", cc_background_item_get_name (saved),
1112
"source-url", cc_background_item_get_source_url (saved),
1113
"source-xml", cc_background_item_get_source_xml (saved),
1117
g_object_unref (saved);
1119
priv->current_background = configured;
1120
cc_background_item_load (priv->current_background, NULL);
1124
scrolled_realize_cb (GtkWidget *scrolled,
1125
CcBackgroundPanel *self)
1127
/* FIXME, hack for https://bugzilla.gnome.org/show_bug.cgi?id=645649 */
1132
screen = gtk_widget_get_screen (scrolled);
1133
monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (scrolled));
1134
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
1135
if (rect.height <= 768)
1136
g_object_set (G_OBJECT (scrolled), "height-request", 280, NULL);
1140
cc_background_panel_drag_uris (GtkWidget *widget,
1141
GdkDragContext *context, gint x, gint y,
1142
GtkSelectionData *data, guint info, guint time,
1143
CcBackgroundPanel *panel)
1149
uris = gtk_selection_data_get_uris (data);
1153
gtk_drag_finish (context, TRUE, FALSE, time);
1155
for (i = 0; uris[i] != NULL; i++) {
1157
if (!bg_pictures_source_is_known (panel->priv->pictures_source, uri)) {
1158
add_custom_wallpaper (panel, uri);
1166
cc_background_panel_init (CcBackgroundPanel *self)
1168
CcBackgroundPanelPrivate *priv;
1169
gchar *objects[] = { "style-liststore",
1170
"sources-liststore", "background-panel", "sizegroup", NULL };
1173
GtkListStore *store;
1174
GtkStyleContext *context;
1176
priv = self->priv = BACKGROUND_PANEL_PRIVATE (self);
1178
priv->builder = gtk_builder_new ();
1180
gtk_builder_add_objects_from_file (priv->builder,
1181
DATADIR"/background.ui",
1186
g_warning ("Could not load ui: %s", err->message);
1191
/* See shell_notify_cb for details */
1192
g_signal_connect (WID ("scrolledwindow1"), "realize",
1193
G_CALLBACK (scrolled_realize_cb), self);
1195
priv->settings = g_settings_new (WP_PATH_ID);
1196
g_settings_delay (priv->settings);
1198
store = (GtkListStore*) gtk_builder_get_object (priv->builder,
1199
"sources-liststore");
1201
priv->wallpapers_source = bg_wallpapers_source_new ();
1202
gtk_list_store_insert_with_values (store, NULL, G_MAXINT,
1203
COL_SOURCE_NAME, _("Wallpapers"),
1204
COL_SOURCE_TYPE, SOURCE_WALLPAPERS,
1205
COL_SOURCE, priv->wallpapers_source,
1208
priv->pictures_source = bg_pictures_source_new ();
1209
gtk_list_store_insert_with_values (store, NULL, G_MAXINT,
1210
COL_SOURCE_NAME, _("Pictures Folder"),
1211
COL_SOURCE_TYPE, SOURCE_PICTURES,
1212
COL_SOURCE, priv->pictures_source,
1215
priv->colors_source = bg_colors_source_new ();
1216
gtk_list_store_insert_with_values (store, NULL, G_MAXINT,
1217
COL_SOURCE_NAME, _("Colors & Gradients"),
1218
COL_SOURCE_TYPE, SOURCE_COLORS,
1219
COL_SOURCE, priv->colors_source,
1222
#ifdef HAVE_LIBSOCIALWEB
1223
priv->flickr_source = bg_flickr_source_new ();
1224
gtk_list_store_insert_with_values (store, NULL, G_MAXINT,
1225
COL_SOURCE_NAME, _("Flickr"),
1226
COL_SOURCE_TYPE, SOURCE_FLICKR,
1227
COL_SOURCE, priv->flickr_source,
1232
/* add the top level widget */
1233
widget = WID ("background-panel");
1235
gtk_container_add (GTK_CONTAINER (self), widget);
1236
gtk_widget_show_all (GTK_WIDGET (self));
1238
/* connect to source change signal */
1239
widget = WID ("sources-combobox");
1240
g_signal_connect (widget, "changed", G_CALLBACK (source_changed_cb), priv);
1242
/* select first item */
1243
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
1245
/* connect to the background iconview change signal */
1246
widget = WID ("backgrounds-iconview");
1247
g_signal_connect (widget, "selection-changed",
1248
G_CALLBACK (backgrounds_changed_cb),
1251
/* Join treeview and buttons */
1252
widget = WID ("scrolledwindow1");
1253
context = gtk_widget_get_style_context (widget);
1254
gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
1255
widget = WID ("toolbar1");
1256
context = gtk_widget_get_style_context (widget);
1257
gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
1259
g_signal_connect (WID ("add_button"), "clicked",
1260
G_CALLBACK (add_button_clicked), self);
1261
g_signal_connect (WID ("remove_button"), "clicked",
1262
G_CALLBACK (remove_button_clicked), self);
1264
/* Add drag and drop support for bg images */
1265
widget = WID ("scrolledwindow1");
1266
gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY);
1267
gtk_drag_dest_add_uri_targets (widget);
1268
g_signal_connect (widget, "drag-data-received",
1269
G_CALLBACK (cc_background_panel_drag_uris), self);
1272
/* setup preview area */
1273
gtk_label_set_ellipsize (GTK_LABEL (WID ("background-label")), PANGO_ELLIPSIZE_END);
1274
widget = WID ("preview-area");
1275
g_signal_connect (widget, "draw", G_CALLBACK (preview_draw_cb),
1278
priv->display_base = gdk_pixbuf_new_from_file (DATADIR "/display-base.png",
1280
priv->display_overlay = gdk_pixbuf_new_from_file (DATADIR
1281
"/display-overlay.png",
1284
g_signal_connect (WID ("style-combobox"), "changed",
1285
G_CALLBACK (style_changed_cb), self);
1287
g_signal_connect (WID ("style-pcolor"), "color-set",
1288
G_CALLBACK (color_changed_cb), self);
1289
g_signal_connect (WID ("style-scolor"), "color-set",
1290
G_CALLBACK (color_changed_cb), self);
1291
g_signal_connect (WID ("swap-color-button"), "clicked",
1292
G_CALLBACK (swap_colors_clicked), self);
1294
priv->copy_cancellable = g_cancellable_new ();
1296
priv->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
1298
load_current_bg (self);
1300
update_preview (priv, NULL);
1302
/* Setup the edit box with our current settings */
1303
source_update_edit_box (priv, TRUE);
1307
cc_background_panel_register (GIOModule *module)
1309
cc_background_panel_register_type (G_TYPE_MODULE (module));
1310
g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
1311
CC_TYPE_BACKGROUND_PANEL,