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;
};
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,19 +305,16 @@ 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 (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;
if (!in_content_types (content_type))
return FALSE;
/* create a new CcBackgroundItem */
uri = g_file_get_uri (file);
@ -317,9 +332,6 @@ add_single_file (BgPicturesSource *bg_source,
g_file_read_async (file, 0, NULL, picture_opened_for_read, bg_source);
g_object_unref (file);
return TRUE;
}
return FALSE;
}
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;
}

View file

@ -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 */

View file

@ -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"))),