Merge lp:~seb128/unity-control-center/some-background-bugfixes into lp:unity-control-center

Proposed by Sebastien Bacher
Status: Superseded
Proposed branch: lp:~seb128/unity-control-center/some-background-bugfixes
Merge into: lp:unity-control-center
Diff against target: 280 lines (+131/-41)
3 files modified
panels/appearance/bg-pictures-source.c (+124/-40)
panels/appearance/bg-pictures-source.h (+2/-0)
panels/appearance/cc-appearance-panel.c (+5/-1)
To merge this branch: bzr merge lp:~seb128/unity-control-center/some-background-bugfixes
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Unity Control Center development team Pending
Review via email: mp+208203@code.launchpad.net

Commit message

Backport some bugfixes and small improvements

Description of the change

Backport some bugfixes and small improvements

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
12734. By Sebastien Bacher

Backport some bugfixes and small improvements

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'panels/appearance/bg-pictures-source.c'
2--- panels/appearance/bg-pictures-source.c 2013-12-02 02:45:53 +0000
3+++ panels/appearance/bg-pictures-source.c 2014-02-25 18:40:29 +0000
4@@ -45,6 +45,14 @@
5 GHashTable *known_items;
6 };
7
8+const char * const content_types[] = {
9+ "image/png",
10+ "image/jpeg",
11+ "image/bmp",
12+ "image/svg+xml",
13+ NULL
14+};
15+
16 static char *bg_pictures_source_get_unique_filename (const char *uri);
17
18 static void
19@@ -127,32 +135,91 @@
20 object_class->finalize = bg_pictures_source_finalize;
21 }
22
23+static int
24+sort_func (GtkTreeModel *model,
25+ GtkTreeIter *a,
26+ GtkTreeIter *b,
27+ BgPicturesSource *bg_source)
28+{
29+ CcAppearanceItem *item_a;
30+ CcAppearanceItem *item_b;
31+ const char *name_a;
32+ const char *name_b;
33+ int retval;
34+
35+ gtk_tree_model_get (model, a,
36+ 1, &item_a,
37+ -1);
38+ gtk_tree_model_get (model, b,
39+ 1, &item_b,
40+ -1);
41+
42+ name_a = cc_appearance_item_get_name (item_a);
43+ name_b = cc_appearance_item_get_name (item_b);
44+
45+ retval = g_utf8_collate (name_a, name_b);
46+
47+ g_object_unref (item_a);
48+ g_object_unref (item_b);
49+
50+ return retval;
51+}
52+
53 static void
54 picture_scaled (GObject *source_object,
55 GAsyncResult *res,
56 gpointer user_data)
57 {
58- BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data);
59+ BgPicturesSource *bg_source;
60 CcAppearanceItem *item;
61 GError *error = NULL;
62 GdkPixbuf *pixbuf;
63 const char *source_url;
64-
65+ const char *software;
66 GtkTreeIter iter;
67 GtkListStore *store;
68
69- store = bg_source_get_liststore (BG_SOURCE (bg_source));
70- item = g_object_get_data (source_object, "item");
71-
72 pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error);
73 if (pixbuf == NULL)
74 {
75- g_warning ("Failed to load image: %s", error->message);
76+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
77+ g_warning ("Failed to load image: %s", error->message);
78+
79 g_error_free (error);
80+ return;
81+ }
82+
83+ /* since we were not cancelled, we can now cast user_data
84+ * back to BgPicturesSource.
85+ */
86+ bg_source = BG_PICTURES_SOURCE (user_data);
87+ store = bg_source_get_liststore (BG_SOURCE (bg_source));
88+ item = g_object_get_data (source_object, "item");
89+
90+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
91+ 1,
92+ (GtkTreeIterCompareFunc)sort_func,
93+ bg_source,
94+ NULL);
95+
96+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
97+ 1,
98+ GTK_SORT_ASCENDING);
99+
100+ /* Ignore screenshots */
101+ software = gdk_pixbuf_get_option (pixbuf, "tEXt::Software");
102+ if (software != NULL &&
103+ g_str_equal (software, "gnome-screenshot"))
104+ {
105+ g_debug ("Ignored URL '%s' as it's a screenshot from gnome-screenshot",
106+ cc_background_item_get_uri (item));
107+ g_object_unref (pixbuf);
108 g_object_unref (item);
109 return;
110 }
111
112+ cc_background_item_load (item, NULL);
113+
114 /* insert the item into the liststore */
115 gtk_list_store_insert_with_values (store, &iter, 0,
116 0, pixbuf,
117@@ -195,7 +262,7 @@
118 GAsyncResult *res,
119 gpointer user_data)
120 {
121- BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data);
122+ BgPicturesSource *bg_source;
123 CcAppearanceItem *item;
124 GFileInputStream *stream;
125 GError *error = NULL;
126@@ -204,66 +271,78 @@
127 stream = g_file_read_finish (G_FILE (source_object), res, &error);
128 if (stream == NULL)
129 {
130- char *filename;
131+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
132+ {
133+ char *filename = g_file_get_path (G_FILE (source_object));
134+ g_warning ("Failed to load picture '%s': %s", filename, error->message);
135+ g_free (filename);
136+ }
137
138- filename = g_file_get_path (G_FILE (source_object));
139- g_warning ("Failed to load picture '%s': %s", filename, error->message);
140- g_free (filename);
141 g_error_free (error);
142 g_object_unref (item);
143 return;
144 }
145
146+ /* since we were not cancelled, we can now cast user_data
147+ * back to BgPicturesSource.
148+ */
149+ bg_source = BG_PICTURES_SOURCE (user_data);
150+
151 g_object_set_data (G_OBJECT (stream), "item", item);
152-
153 gdk_pixbuf_new_from_stream_at_scale_async (G_INPUT_STREAM (stream),
154 THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
155 TRUE,
156- NULL,
157+ bg_source->priv->cancellable,
158 picture_scaled, bg_source);
159 g_object_unref (stream);
160 }
161
162 static gboolean
163+in_content_types (const char *content_type)
164+{
165+ guint i;
166+ for (i = 0; content_types[i]; i++)
167+ if (g_str_equal (content_types[i], content_type))
168+ return TRUE;
169+ return FALSE;
170+}
171+
172+static gboolean
173 add_single_file (BgPicturesSource *bg_source,
174 GFile *file,
175 GFileInfo *info,
176 const char *source_uri)
177 {
178 const gchar *content_type;
179+ CcAppearanceItem *item;
180+ char *uri;
181
182 /* find png and jpeg files */
183 content_type = g_file_info_get_content_type (info);
184
185 if (!content_type)
186 return FALSE;
187-
188- if (g_str_equal ("image/png", content_type) ||
189- g_str_equal ("image/jpeg", content_type) ||
190- g_str_equal ("image/svg+xml", content_type))
191- {
192- CcAppearanceItem *item;
193- char *uri;
194-
195- /* create a new CcAppearanceItem */
196- uri = g_file_get_uri (file);
197- item = cc_appearance_item_new (uri);
198- g_free (uri);
199- g_object_set (G_OBJECT (item),
200- "flags", CC_APPEARANCE_ITEM_HAS_URI | CC_APPEARANCE_ITEM_HAS_SHADING,
201- "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID,
202- "placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM,
203- NULL);
204- if (source_uri != NULL && !g_file_is_native (file))
205- g_object_set (G_OBJECT (item), "source-url", source_uri, NULL);
206-
207- g_object_set_data (G_OBJECT (file), "item", item);
208- g_file_read_async (file, 0, NULL, picture_opened_for_read, bg_source);
209- g_object_unref (file);
210- return TRUE;
211- }
212-
213- return FALSE;
214+ if (!in_content_types (content_type))
215+ return FALSE;
216+
217+ /* create a new CcAppearanceItem */
218+ uri = g_file_get_uri (file);
219+ item = cc_appearance_item_new (uri);
220+ g_free (uri);
221+ g_object_set (G_OBJECT (item),
222+ "flags", CC_APPEARANCE_ITEM_HAS_URI | CC_APPEARANCE_ITEM_HAS_SHADING,
223+ "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID,
224+ "placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM,
225+ NULL);
226+ if (source_uri != NULL && !g_file_is_native (file))
227+ g_object_set (G_OBJECT (item), "source-url", source_uri, NULL);
228+
229+ g_object_set_data (G_OBJECT (file), "item", item);
230+ g_file_read_async (file, G_PRIORITY_DEFAULT,
231+ bg_source->priv->cancellable,
232+ picture_opened_for_read, bg_source);
233+ g_object_unref (file);
234+ return TRUE;
235 }
236
237 gboolean
238@@ -504,3 +583,8 @@
239 return g_object_new (BG_TYPE_PICTURES_SOURCE, NULL);
240 }
241
242+const char * const *
243+bg_pictures_get_support_content_types (void)
244+{
245+ return content_types;
246+}
247
248=== modified file 'panels/appearance/bg-pictures-source.h'
249--- panels/appearance/bg-pictures-source.h 2013-12-02 02:45:53 +0000
250+++ panels/appearance/bg-pictures-source.h 2014-02-25 18:40:29 +0000
251@@ -79,6 +79,8 @@
252 gboolean bg_pictures_source_is_known (BgPicturesSource *bg_source,
253 const char *uri);
254
255+const char * const * bg_pictures_get_support_content_types (void);
256+
257 G_END_DECLS
258
259 #endif /* _BG_PICTURES_SOURCE_H */
260
261=== modified file 'panels/appearance/cc-appearance-panel.c'
262--- panels/appearance/cc-appearance-panel.c 2014-02-20 21:17:51 +0000
263+++ panels/appearance/cc-appearance-panel.c 2014-02-25 18:40:29 +0000
264@@ -1086,11 +1086,15 @@
265 GtkWidget *preview;
266 GtkFileFilter *filter;
267 CcAppearancePanelPrivate *priv;
268+ const char * const * content_types;
269+ guint i;
270
271 priv = panel->priv;
272
273 filter = gtk_file_filter_new ();
274- gtk_file_filter_add_mime_type (filter, "image/*");
275+ content_types = bg_pictures_get_support_content_types ();
276+ for (i = 0; content_types[i] != NULL; i++)
277+ gtk_file_filter_add_mime_type (filter, content_types[i]);
278
279 chooser = gtk_file_chooser_dialog_new (_("Browse for more pictures"),
280 GTK_WINDOW (gtk_widget_get_toplevel (WID ("appearance-panel"))),

Subscribers

People subscribed via source and target branches