From 3d79e1174e7287f29ad630a4aea55cfa0a6d2b2a Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 17 May 2012 18:12:13 +0100 Subject: [PATCH] background: Only show the image types we support And add image/bmp to those types. https://bugzilla.gnome.org/show_bug.cgi?id=669960 --- panels/background/bg-pictures-source.c | 67 ++++++++++++++++--------- panels/background/bg-pictures-source.h | 2 + panels/background/cc-background-panel.c | 6 ++- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/panels/background/bg-pictures-source.c b/panels/background/bg-pictures-source.c index e1e148399..2c0469548 100644 --- a/panels/background/bg-pictures-source.c +++ b/panels/background/bg-pictures-source.c @@ -46,6 +46,14 @@ struct _BgPicturesSourcePrivate GHashTable *known_items; }; +const char * const content_types[] = { + "image/png", + "image/jpeg", + "image/bmp", + "image/svg+xml", + NULL +}; + static char *bg_pictures_source_get_unique_filename (const char *uri); static void @@ -280,6 +288,16 @@ picture_opened_for_read (GObject *source_object, g_object_unref (stream); } +static gboolean +in_content_types (const char *content_type) +{ + guint i; + for (i = 0; content_types[i]; i++) + if (g_str_equal (content_types[i], content_type)) + return TRUE; + return FALSE; +} + static gboolean add_single_file (BgPicturesSource *bg_source, GFile *file, @@ -287,39 +305,33 @@ add_single_file (BgPicturesSource *bg_source, const char *source_uri) { const gchar *content_type; + CcBackgroundItem *item; + char *uri; /* find png and jpeg files */ content_type = g_file_info_get_content_type (info); if (!content_type) return FALSE; + if (!in_content_types (content_type)) + return FALSE; - if (g_str_equal ("image/png", content_type) || - g_str_equal ("image/jpeg", content_type) || - g_str_equal ("image/svg+xml", content_type)) - { - CcBackgroundItem *item; - char *uri; + /* create a new CcBackgroundItem */ + uri = g_file_get_uri (file); + item = cc_background_item_new (uri); + g_free (uri); + g_object_set (G_OBJECT (item), + "flags", CC_BACKGROUND_ITEM_HAS_URI | CC_BACKGROUND_ITEM_HAS_SHADING, + "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID, + "placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM, + NULL); + if (source_uri != NULL) + g_object_set (G_OBJECT (item), "source-url", source_uri, NULL); - /* create a new CcBackgroundItem */ - uri = g_file_get_uri (file); - item = cc_background_item_new (uri); - g_free (uri); - g_object_set (G_OBJECT (item), - "flags", CC_BACKGROUND_ITEM_HAS_URI | CC_BACKGROUND_ITEM_HAS_SHADING, - "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID, - "placement", G_DESKTOP_BACKGROUND_STYLE_ZOOM, - NULL); - if (source_uri != NULL) - g_object_set (G_OBJECT (item), "source-url", source_uri, NULL); - - g_object_set_data (G_OBJECT (file), "item", item); - g_file_read_async (file, 0, NULL, picture_opened_for_read, bg_source); - g_object_unref (file); - return TRUE; - } - - return FALSE; + g_object_set_data (G_OBJECT (file), "item", item); + g_file_read_async (file, 0, NULL, picture_opened_for_read, bg_source); + g_object_unref (file); + return TRUE; } gboolean @@ -554,3 +566,8 @@ bg_pictures_source_new (void) return g_object_new (BG_TYPE_PICTURES_SOURCE, NULL); } +const char * const * +bg_pictures_get_support_content_types (void) +{ + return content_types; +} diff --git a/panels/background/bg-pictures-source.h b/panels/background/bg-pictures-source.h index 9260cd12e..554a5c63d 100644 --- a/panels/background/bg-pictures-source.h +++ b/panels/background/bg-pictures-source.h @@ -80,6 +80,8 @@ gboolean bg_pictures_source_remove (BgPicturesSource *bg_source gboolean bg_pictures_source_is_known (BgPicturesSource *bg_source, const char *uri); +const char * const * bg_pictures_get_support_content_types (void); + G_END_DECLS #endif /* _BG_PICTURES_SOURCE_H */ diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c index 1ec9188d9..15b7221fd 100644 --- a/panels/background/cc-background-panel.c +++ b/panels/background/cc-background-panel.c @@ -992,11 +992,15 @@ add_button_clicked (GtkButton *button, GtkWidget *preview; GtkFileFilter *filter; CcBackgroundPanelPrivate *priv; + const char * const * content_types; + guint i; priv = panel->priv; filter = gtk_file_filter_new (); - gtk_file_filter_add_mime_type (filter, "image/*"); + content_types = bg_pictures_get_support_content_types (); + for (i = 0; content_types[i] != NULL; i++) + gtk_file_filter_add_mime_type (filter, content_types[i]); chooser = gtk_file_chooser_dialog_new (_("Browse for more pictures"), GTK_WINDOW (gtk_widget_get_toplevel (WID ("background-panel"))),