diff --git a/gtk/Makefile.am b/gtk/Makefile.am index a6a41b0177..84f3ffe032 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -442,6 +442,7 @@ gtk_private_h_sources = \ gtkfilechooserprivate.h \ gtkfilechooserwidgetprivate.h \ gtkfilechooserutils.h \ + gtkfilefilterprivate.h \ gtkfilesystem.h \ gtkfilesystemmodel.h \ gtkfontchooserprivate.h \ diff --git a/gtk/gtkfilefilter.c b/gtk/gtkfilefilter.c index 46b1459388..43cd05fd15 100644 --- a/gtk/gtkfilefilter.c +++ b/gtk/gtkfilefilter.c @@ -67,7 +67,7 @@ #include -#include "gtkfilefilter.h" +#include "gtkfilefilterprivate.h" #include "gtkbuildable.h" #include "gtkbuilderprivate.h" #include "gtkintl.h" @@ -592,6 +592,53 @@ gtk_file_filter_get_needed (GtkFileFilter *filter) return filter->needed; } +char ** +_gtk_file_filter_get_as_patterns (GtkFileFilter *filter) +{ + GPtrArray *array; + GSList *tmp_list; + + array = g_ptr_array_new_with_free_func (g_free); + + for (tmp_list = filter->rules; tmp_list; tmp_list = tmp_list->next) + { + FilterRule *rule = tmp_list->data; + + switch (rule->type) + { + case FILTER_RULE_CUSTOM: + case FILTER_RULE_MIME_TYPE: + g_ptr_array_free (array, TRUE); + return NULL; + break; + case FILTER_RULE_PATTERN: + g_ptr_array_add (array, g_strdup (rule->u.pattern)); + break; + case FILTER_RULE_PIXBUF_FORMATS: + { + GSList *list; + + for (list = rule->u.pixbuf_formats; list; list = list->next) + { + int i; + gchar **extensions; + + extensions = gdk_pixbuf_format_get_extensions (list->data); + + for (i = 0; extensions[i] != NULL; i++) + g_ptr_array_add (array, g_strdup_printf ("*.%s", extensions[i])); + + g_strfreev (extensions); + } + break; + } + } + } + + g_ptr_array_add (array, NULL); /* Null terminate */ + return (char **)g_ptr_array_free (array, FALSE); +} + /** * gtk_file_filter_filter: * @filter: a #GtkFileFilter diff --git a/gtk/gtkfilefilterprivate.h b/gtk/gtkfilefilterprivate.h new file mode 100644 index 0000000000..0a3d4a452e --- /dev/null +++ b/gtk/gtkfilefilterprivate.h @@ -0,0 +1,30 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* GTK - The GIMP Toolkit + * Copyright (C) 2015 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef __GTK_FILE_FILTER_PRIVATE_H__ +#define __GTK_FILE_FILTER_PRIVATE_H__ + +#include + +G_BEGIN_DECLS + +char ** _gtk_file_filter_get_as_patterns (GtkFileFilter *filter); + +G_END_DECLS + +#endif /* __GTK_FILE_FILTER_PRIVATE_H__ */