Commit 7a08ab25 authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen
Browse files

New convenience function to add a filter for image files which can be

2004-11-07  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkfilefilter.h:
	* gtk/gtkfilefilter.c (gtk_file_filter_add_pixbuf_formats):
	New convenience function to add a filter for image files
	which can be loaded by GdkPixbuf. (#145388, Anders Carlsson)

	* tests/testfilechooser.c: Test the image filter.
parent 1be34ede
2004-11-07 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkfilefilter.h:
* gtk/gtkfilefilter.c (gtk_file_filter_add_pixbuf_formats):
New convenience function to add a filter for image files
which can be loaded by GdkPixbuf. (#145388, Anders Carlsson)
* tests/testfilechooser.c: Test the image filter.
* gtk/gtkmenu.c (menu_change_screen): Remove some warnings.
Show files in folder modes. (#157013, Nickolay V. Shmyrev)
......
2004-11-07 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkfilefilter.h:
* gtk/gtkfilefilter.c (gtk_file_filter_add_pixbuf_formats):
New convenience function to add a filter for image files
which can be loaded by GdkPixbuf. (#145388, Anders Carlsson)
* tests/testfilechooser.c: Test the image filter.
* gtk/gtkmenu.c (menu_change_screen): Remove some warnings.
Show files in folder modes. (#157013, Nickolay V. Shmyrev)
......
2004-11-07 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkfilefilter.h:
* gtk/gtkfilefilter.c (gtk_file_filter_add_pixbuf_formats):
New convenience function to add a filter for image files
which can be loaded by GdkPixbuf. (#145388, Anders Carlsson)
* tests/testfilechooser.c: Test the image filter.
* gtk/gtkmenu.c (menu_change_screen): Remove some warnings.
Show files in folder modes. (#157013, Nickolay V. Shmyrev)
......
2004-11-07 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkfilefilter.h:
* gtk/gtkfilefilter.c (gtk_file_filter_add_pixbuf_formats):
New convenience function to add a filter for image files
which can be loaded by GdkPixbuf. (#145388, Anders Carlsson)
* tests/testfilechooser.c: Test the image filter.
* gtk/gtkmenu.c (menu_change_screen): Remove some warnings.
Show files in folder modes. (#157013, Nickolay V. Shmyrev)
......
2004-11-07 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk-sections.txt: Add gtk_file_filter_add_pixbuf_formats.
2004-11-04 Matthias Clasen <mclasen@redhat.com>
* gtk/tmpl/gtkaboutdialog.sgml:
......
......@@ -1311,6 +1311,7 @@ gtk_file_filter_set_name
gtk_file_filter_get_name
gtk_file_filter_add_mime_type
gtk_file_filter_add_pattern
gtk_file_filter_add_pixbuf_formats
gtk_file_filter_add_custom
gtk_file_filter_get_needed
gtk_file_filter_filter
......
......@@ -36,6 +36,7 @@ typedef struct _FilterRule FilterRule;
typedef enum {
FILTER_RULE_PATTERN,
FILTER_RULE_MIME_TYPE,
FILTER_RULE_PIXBUF_FORMATS,
FILTER_RULE_CUSTOM
} FilterRuleType;
......@@ -62,6 +63,7 @@ struct _FilterRule
union {
gchar *pattern;
gchar *mime_type;
GSList *pixbuf_formats;
struct {
GtkFileFilterFunc func;
gpointer data;
......@@ -127,6 +129,9 @@ filter_rule_free (FilterRule *rule)
if (rule->u.custom.notify)
rule->u.custom.notify (rule->u.custom.data);
break;
case FILTER_RULE_PIXBUF_FORMATS:
g_slist_free (rule->u.pixbuf_formats);
break;
default:
g_assert_not_reached ();
}
......@@ -277,6 +282,30 @@ gtk_file_filter_add_pattern (GtkFileFilter *filter,
file_filter_add_rule (filter, rule);
}
/**
* gtk_file_filter_add_pixbuf_formats:
* @filter: a #GtkFileFilter
*
* Adds a rule allowing image files in the formats supported
* by GdkPixbuf.
*
* Since: 2.6
**/
void
gtk_file_filter_add_pixbuf_formats (GtkFileFilter *filter)
{
FilterRule *rule;
g_return_if_fail (GTK_IS_FILE_FILTER (filter));
rule = g_new (FilterRule, 1);
rule->type = FILTER_RULE_PIXBUF_FORMATS;
rule->needed = GTK_FILE_FILTER_MIME_TYPE;
rule->u.pixbuf_formats = gdk_pixbuf_get_formats ();
file_filter_add_rule (filter, rule);
}
/**
* gtk_file_filter_add_custom:
* @filter: a #GtkFileFilter
......@@ -382,6 +411,30 @@ gtk_file_filter_filter (GtkFileFilter *filter,
_gtk_fnmatch (rule->u.pattern, filter_info->display_name, FALSE))
return TRUE;
break;
case FILTER_RULE_PIXBUF_FORMATS:
{
GSList *list;
for (list = rule->u.pixbuf_formats; list; list = list->next)
{
int i;
gchar **mime_types;
mime_types = gdk_pixbuf_format_get_mime_types (list->data);
for (i = 0; mime_types[i] != NULL; i++)
{
if (strcmp (mime_types[i], filter_info->mime_type) == 0)
{
g_strfreev (mime_types);
return TRUE;
}
}
g_strfreev (mime_types);
}
break;
}
case FILTER_RULE_CUSTOM:
if (rule->u.custom.func (filter_info, rule->u.custom.data))
return TRUE;
......
......@@ -59,15 +59,16 @@ void gtk_file_filter_set_name (GtkFileFilter *filter,
const gchar *name);
G_CONST_RETURN gchar *gtk_file_filter_get_name (GtkFileFilter *filter);
void gtk_file_filter_add_mime_type (GtkFileFilter *filter,
const gchar *mime_type);
void gtk_file_filter_add_pattern (GtkFileFilter *filter,
const gchar *pattern);
void gtk_file_filter_add_custom (GtkFileFilter *filter,
GtkFileFilterFlags needed,
GtkFileFilterFunc func,
gpointer data,
GDestroyNotify notify);
void gtk_file_filter_add_mime_type (GtkFileFilter *filter,
const gchar *mime_type);
void gtk_file_filter_add_pattern (GtkFileFilter *filter,
const gchar *pattern);
void gtk_file_filter_add_pixbuf_formats (GtkFileFilter *filter);
void gtk_file_filter_add_custom (GtkFileFilter *filter,
GtkFileFilterFlags needed,
GtkFileFilterFunc func,
gpointer data,
GDestroyNotify notify);
GtkFileFilterFlags gtk_file_filter_get_needed (GtkFileFilter *filter);
gboolean gtk_file_filter_filter (GtkFileFilter *filter,
......
......@@ -95,6 +95,13 @@ no_backup_files_filter (const GtkFileFilterInfo *filter_info,
return 1;
}
static void
filter_changed (GtkFileChooserDialog *dialog,
gpointer data)
{
g_print ("file filter changed\n");
}
static char *
format_time (time_t t)
{
......@@ -403,6 +410,10 @@ main (int argc, char **argv)
gtk_init (&argc, &argv);
/* to test rtl layout, set RTL=1 in the environment */
if (g_getenv ("RTL"))
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
action = GTK_FILE_CHOOSER_ACTION_OPEN;
/* lame-o arg parsing */
......@@ -466,6 +477,9 @@ main (int argc, char **argv)
gtk_file_filter_add_mime_type (filter, "image/png");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
g_signal_connect (dialog, "notify::filter",
G_CALLBACK (filter_changed), NULL);
/* Make this filter the default */
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
......@@ -475,11 +489,16 @@ main (int argc, char **argv)
gtk_file_filter_add_mime_type (filter, "image/png");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "Images");
gtk_file_filter_add_pixbuf_formats (filter);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
/* Preview widget */
/* THIS IS A TERRIBLE PREVIEW WIDGET, AND SHOULD NOT BE COPIED AT ALL.
*/
preview_vbox = gtk_vbox_new (0, FALSE);
/* gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog), preview_vbox);*/
/*gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog), preview_vbox);*/
preview_label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (preview_vbox), preview_label, TRUE, TRUE, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment