Commit 693db082 authored by Alexander Larsson's avatar Alexander Larsson

GtkFileFilter: Add private function to represent filter as pattern

This will be needed for the win32 native file chooser which
does not support mimetype sniffing.
parent 81cef009
......@@ -442,6 +442,7 @@ gtk_private_h_sources = \
gtkfilechooserprivate.h \
gtkfilechooserwidgetprivate.h \
gtkfilechooserutils.h \
gtkfilefilterprivate.h \
gtkfilesystem.h \
gtkfilesystemmodel.h \
gtkfontchooserprivate.h \
......
......@@ -67,7 +67,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#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
......
/* -*- 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_FILE_FILTER_PRIVATE_H__
#define __GTK_FILE_FILTER_PRIVATE_H__
#include <gtk/gtkfilefilter.h>
G_BEGIN_DECLS
char ** _gtk_file_filter_get_as_patterns (GtkFileFilter *filter);
G_END_DECLS
#endif /* __GTK_FILE_FILTER_PRIVATE_H__ */
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