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

Proposed by Sebastien Bacher
Status: Merged
Approved by: Robert Ancell
Approved revision: 12734
Merged at revision: 12738
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
Robert Ancell Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+208206@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
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Sure

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'panels/appearance/bg-pictures-source.c'
--- panels/appearance/bg-pictures-source.c 2013-12-02 02:45:53 +0000
+++ panels/appearance/bg-pictures-source.c 2014-02-25 18:47:29 +0000
@@ -45,6 +45,14 @@
45 GHashTable *known_items;45 GHashTable *known_items;
46};46};
4747
48const char * const content_types[] = {
49 "image/png",
50 "image/jpeg",
51 "image/bmp",
52 "image/svg+xml",
53 NULL
54};
55
48static char *bg_pictures_source_get_unique_filename (const char *uri);56static char *bg_pictures_source_get_unique_filename (const char *uri);
4957
50static void58static void
@@ -127,32 +135,91 @@
127 object_class->finalize = bg_pictures_source_finalize;135 object_class->finalize = bg_pictures_source_finalize;
128}136}
129137
138static int
139sort_func (GtkTreeModel *model,
140 GtkTreeIter *a,
141 GtkTreeIter *b,
142 BgPicturesSource *bg_source)
143{
144 CcAppearanceItem *item_a;
145 CcAppearanceItem *item_b;
146 const char *name_a;
147 const char *name_b;
148 int retval;
149
150 gtk_tree_model_get (model, a,
151 1, &item_a,
152 -1);
153 gtk_tree_model_get (model, b,
154 1, &item_b,
155 -1);
156
157 name_a = cc_appearance_item_get_name (item_a);
158 name_b = cc_appearance_item_get_name (item_b);
159
160 retval = g_utf8_collate (name_a, name_b);
161
162 g_object_unref (item_a);
163 g_object_unref (item_b);
164
165 return retval;
166}
167
130static void168static void
131picture_scaled (GObject *source_object,169picture_scaled (GObject *source_object,
132 GAsyncResult *res,170 GAsyncResult *res,
133 gpointer user_data)171 gpointer user_data)
134{172{
135 BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data);173 BgPicturesSource *bg_source;
136 CcAppearanceItem *item;174 CcAppearanceItem *item;
137 GError *error = NULL;175 GError *error = NULL;
138 GdkPixbuf *pixbuf;176 GdkPixbuf *pixbuf;
139 const char *source_url;177 const char *source_url;
140178 const char *software;
141 GtkTreeIter iter;179 GtkTreeIter iter;
142 GtkListStore *store;180 GtkListStore *store;
143181
144 store = bg_source_get_liststore (BG_SOURCE (bg_source));
145 item = g_object_get_data (source_object, "item");
146
147 pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error);182 pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error);
148 if (pixbuf == NULL)183 if (pixbuf == NULL)
149 {184 {
150 g_warning ("Failed to load image: %s", error->message);185 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
186 g_warning ("Failed to load image: %s", error->message);
187
151 g_error_free (error);188 g_error_free (error);
189 return;
190 }
191
192 /* since we were not cancelled, we can now cast user_data
193 * back to BgPicturesSource.
194 */
195 bg_source = BG_PICTURES_SOURCE (user_data);
196 store = bg_source_get_liststore (BG_SOURCE (bg_source));
197 item = g_object_get_data (source_object, "item");
198
199 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
200 1,
201 (GtkTreeIterCompareFunc)sort_func,
202 bg_source,
203 NULL);
204
205 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
206 1,
207 GTK_SORT_ASCENDING);
208
209 /* Ignore screenshots */
210 software = gdk_pixbuf_get_option (pixbuf, "tEXt::Software");
211 if (software != NULL &&
212 g_str_equal (software, "gnome-screenshot"))
213 {
214 g_debug ("Ignored URL '%s' as it's a screenshot from gnome-screenshot",
215 cc_appearance_item_get_uri (item));
216 g_object_unref (pixbuf);
152 g_object_unref (item);217 g_object_unref (item);
153 return;218 return;
154 }219 }
155220
221 cc_appearance_item_load (item, NULL);
222
156 /* insert the item into the liststore */223 /* insert the item into the liststore */
157 gtk_list_store_insert_with_values (store, &iter, 0,224 gtk_list_store_insert_with_values (store, &iter, 0,
158 0, pixbuf,225 0, pixbuf,
@@ -195,7 +262,7 @@
195 GAsyncResult *res,262 GAsyncResult *res,
196 gpointer user_data)263 gpointer user_data)
197{264{
198 BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data);265 BgPicturesSource *bg_source;
199 CcAppearanceItem *item;266 CcAppearanceItem *item;
200 GFileInputStream *stream;267 GFileInputStream *stream;
201 GError *error = NULL;268 GError *error = NULL;
@@ -204,66 +271,78 @@
204 stream = g_file_read_finish (G_FILE (source_object), res, &error);271 stream = g_file_read_finish (G_FILE (source_object), res, &error);
205 if (stream == NULL)272 if (stream == NULL)
206 {273 {
207 char *filename;274 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
275 {
276 char *filename = g_file_get_path (G_FILE (source_object));
277 g_warning ("Failed to load picture '%s': %s", filename, error->message);
278 g_free (filename);
279 }
208280
209 filename = g_file_get_path (G_FILE (source_object));
210 g_warning ("Failed to load picture '%s': %s", filename, error->message);
211 g_free (filename);
212 g_error_free (error);281 g_error_free (error);
213 g_object_unref (item);282 g_object_unref (item);
214 return;283 return;
215 }284 }
216285
286 /* since we were not cancelled, we can now cast user_data
287 * back to BgPicturesSource.
288 */
289 bg_source = BG_PICTURES_SOURCE (user_data);
290
217 g_object_set_data (G_OBJECT (stream), "item", item);291 g_object_set_data (G_OBJECT (stream), "item", item);
218
219 gdk_pixbuf_new_from_stream_at_scale_async (G_INPUT_STREAM (stream),292 gdk_pixbuf_new_from_stream_at_scale_async (G_INPUT_STREAM (stream),
220 THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,293 THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
221 TRUE,294 TRUE,
222 NULL,295 bg_source->priv->cancellable,
223 picture_scaled, bg_source);296 picture_scaled, bg_source);
224 g_object_unref (stream);297 g_object_unref (stream);
225}298}
226299
227static gboolean300static gboolean
301in_content_types (const char *content_type)
302{
303 guint i;
304 for (i = 0; content_types[i]; i++)
305 if (g_str_equal (content_types[i], content_type))
306 return TRUE;
307 return FALSE;
308}
309
310static gboolean
228add_single_file (BgPicturesSource *bg_source,311add_single_file (BgPicturesSource *bg_source,
229 GFile *file,312 GFile *file,
230 GFileInfo *info,313 GFileInfo *info,
231 const char *source_uri)314 const char *source_uri)
232{315{
233 const gchar *content_type;316 const gchar *content_type;
317 CcAppearanceItem *item;
318 char *uri;
234319
235 /* find png and jpeg files */320 /* find png and jpeg files */
236 content_type = g_file_info_get_content_type (info);321 content_type = g_file_info_get_content_type (info);
237322
238 if (!content_type)323 if (!content_type)
239 return FALSE;324 return FALSE;
240325 if (!in_content_types (content_type))
241 if (g_str_equal ("image/png", content_type) ||326 return FALSE;
242 g_str_equal ("image/jpeg", content_type) ||327
243 g_str_equal ("image/svg+xml", content_type))328 /* create a new CcAppearanceItem */
244 {329 uri = g_file_get_uri (file);
245 CcAppearanceItem *item;330 item = cc_appearance_item_new (uri);
246 char *uri;331 g_free (uri);
247332 g_object_set (G_OBJECT (item),
248 /* create a new CcAppearanceItem */333 "flags", CC_APPEARANCE_ITEM_HAS_URI | CC_APPEARANCE_ITEM_HAS_SHADING,
249 uri = g_file_get_uri (file);334 "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID,
250 item = cc_appearance_item_new (uri);335 "placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM,
251 g_free (uri);336 NULL);
252 g_object_set (G_OBJECT (item),337 if (source_uri != NULL && !g_file_is_native (file))
253 "flags", CC_APPEARANCE_ITEM_HAS_URI | CC_APPEARANCE_ITEM_HAS_SHADING,338 g_object_set (G_OBJECT (item), "source-url", source_uri, NULL);
254 "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID,339
255 "placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM,340 g_object_set_data (G_OBJECT (file), "item", item);
256 NULL);341 g_file_read_async (file, G_PRIORITY_DEFAULT,
257 if (source_uri != NULL && !g_file_is_native (file))342 bg_source->priv->cancellable,
258 g_object_set (G_OBJECT (item), "source-url", source_uri, NULL);343 picture_opened_for_read, bg_source);
259344 g_object_unref (file);
260 g_object_set_data (G_OBJECT (file), "item", item);345 return TRUE;
261 g_file_read_async (file, 0, NULL, picture_opened_for_read, bg_source);
262 g_object_unref (file);
263 return TRUE;
264 }
265
266 return FALSE;
267}346}
268347
269gboolean348gboolean
@@ -504,3 +583,8 @@
504 return g_object_new (BG_TYPE_PICTURES_SOURCE, NULL);583 return g_object_new (BG_TYPE_PICTURES_SOURCE, NULL);
505}584}
506585
586const char * const *
587bg_pictures_get_support_content_types (void)
588{
589 return content_types;
590}
507591
=== modified file 'panels/appearance/bg-pictures-source.h'
--- panels/appearance/bg-pictures-source.h 2013-12-02 02:45:53 +0000
+++ panels/appearance/bg-pictures-source.h 2014-02-25 18:47:29 +0000
@@ -79,6 +79,8 @@
79gboolean bg_pictures_source_is_known (BgPicturesSource *bg_source,79gboolean bg_pictures_source_is_known (BgPicturesSource *bg_source,
80 const char *uri);80 const char *uri);
8181
82const char * const * bg_pictures_get_support_content_types (void);
83
82G_END_DECLS84G_END_DECLS
8385
84#endif /* _BG_PICTURES_SOURCE_H */86#endif /* _BG_PICTURES_SOURCE_H */
8587
=== modified file 'panels/appearance/cc-appearance-panel.c'
--- panels/appearance/cc-appearance-panel.c 2014-02-20 21:17:51 +0000
+++ panels/appearance/cc-appearance-panel.c 2014-02-25 18:47:29 +0000
@@ -1086,11 +1086,15 @@
1086 GtkWidget *preview;1086 GtkWidget *preview;
1087 GtkFileFilter *filter;1087 GtkFileFilter *filter;
1088 CcAppearancePanelPrivate *priv;1088 CcAppearancePanelPrivate *priv;
1089 const char * const * content_types;
1090 guint i;
10891091
1090 priv = panel->priv;1092 priv = panel->priv;
10911093
1092 filter = gtk_file_filter_new ();1094 filter = gtk_file_filter_new ();
1093 gtk_file_filter_add_mime_type (filter, "image/*");1095 content_types = bg_pictures_get_support_content_types ();
1096 for (i = 0; content_types[i] != NULL; i++)
1097 gtk_file_filter_add_mime_type (filter, content_types[i]);
10941098
1095 chooser = gtk_file_chooser_dialog_new (_("Browse for more pictures"),1099 chooser = gtk_file_chooser_dialog_new (_("Browse for more pictures"),
1096 GTK_WINDOW (gtk_widget_get_toplevel (WID ("appearance-panel"))),1100 GTK_WINDOW (gtk_widget_get_toplevel (WID ("appearance-panel"))),

Subscribers

People subscribed via source and target branches