background: Only show the image types we support

And add image/bmp to those types.

https://bugzilla.gnome.org/show_bug.cgi?id=669960
This commit is contained in:
Bastien Nocera 2012-05-17 18:12:13 +01:00
parent 0ed1bef14f
commit 3d79e1174e
3 changed files with 49 additions and 26 deletions

View file

@ -46,6 +46,14 @@ struct _BgPicturesSourcePrivate
GHashTable *known_items; 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 char *bg_pictures_source_get_unique_filename (const char *uri);
static void static void
@ -280,6 +288,16 @@ picture_opened_for_read (GObject *source_object,
g_object_unref (stream); 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 static gboolean
add_single_file (BgPicturesSource *bg_source, add_single_file (BgPicturesSource *bg_source,
GFile *file, GFile *file,
@ -287,39 +305,33 @@ add_single_file (BgPicturesSource *bg_source,
const char *source_uri) const char *source_uri)
{ {
const gchar *content_type; const gchar *content_type;
CcBackgroundItem *item;
char *uri;
/* find png and jpeg files */ /* find png and jpeg files */
content_type = g_file_info_get_content_type (info); content_type = g_file_info_get_content_type (info);
if (!content_type) if (!content_type)
return FALSE; return FALSE;
if (!in_content_types (content_type))
return FALSE;
if (g_str_equal ("image/png", content_type) || /* create a new CcBackgroundItem */
g_str_equal ("image/jpeg", content_type) || uri = g_file_get_uri (file);
g_str_equal ("image/svg+xml", content_type)) item = cc_background_item_new (uri);
{ g_free (uri);
CcBackgroundItem *item; g_object_set (G_OBJECT (item),
char *uri; "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 */ g_object_set_data (G_OBJECT (file), "item", item);
uri = g_file_get_uri (file); g_file_read_async (file, 0, NULL, picture_opened_for_read, bg_source);
item = cc_background_item_new (uri); g_object_unref (file);
g_free (uri); return TRUE;
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;
} }
gboolean gboolean
@ -554,3 +566,8 @@ bg_pictures_source_new (void)
return g_object_new (BG_TYPE_PICTURES_SOURCE, NULL); return g_object_new (BG_TYPE_PICTURES_SOURCE, NULL);
} }
const char * const *
bg_pictures_get_support_content_types (void)
{
return content_types;
}

View file

@ -80,6 +80,8 @@ gboolean bg_pictures_source_remove (BgPicturesSource *bg_source
gboolean bg_pictures_source_is_known (BgPicturesSource *bg_source, gboolean bg_pictures_source_is_known (BgPicturesSource *bg_source,
const char *uri); const char *uri);
const char * const * bg_pictures_get_support_content_types (void);
G_END_DECLS G_END_DECLS
#endif /* _BG_PICTURES_SOURCE_H */ #endif /* _BG_PICTURES_SOURCE_H */

View file

@ -992,11 +992,15 @@ add_button_clicked (GtkButton *button,
GtkWidget *preview; GtkWidget *preview;
GtkFileFilter *filter; GtkFileFilter *filter;
CcBackgroundPanelPrivate *priv; CcBackgroundPanelPrivate *priv;
const char * const * content_types;
guint i;
priv = panel->priv; priv = panel->priv;
filter = gtk_file_filter_new (); 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"), chooser = gtk_file_chooser_dialog_new (_("Browse for more pictures"),
GTK_WINDOW (gtk_widget_get_toplevel (WID ("background-panel"))), GTK_WINDOW (gtk_widget_get_toplevel (WID ("background-panel"))),