[gtk+/wip/native-file-chooser: 24/27] GtkFileFilter: Add private function to represent filter as pattern



commit d1dfb9f0519be312c5918782e9be3b58e8b92dea
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Nov 3 14:52:42 2015 +0100

    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.

 gtk/Makefile.am            |    1 +
 gtk/gtkfilefilter.c        |   49 +++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkfilefilterprivate.h |   30 ++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 1 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index a6a41b0..84f3ffe 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 46b1459..43cd05f 100644
--- a/gtk/gtkfilefilter.c
+++ b/gtk/gtkfilefilter.c
@@ -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
diff --git a/gtk/gtkfilefilterprivate.h b/gtk/gtkfilefilterprivate.h
new file mode 100644
index 0000000..0a3d4a4
--- /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 <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__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]