From ebae031384273b94fa3e0f1ac7b015ba2939a6bf Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 10 May 2007 00:06:43 +0100 Subject: Add visibility function for the search model filter Add a copy of get_is_file_filtered() using the data stored inside the search model. This is the third copy, so it should really be abstracted out into its own function and called when necessary. Signed-off-by: Emmanuele Bassi --- gtk/gtkfilechooserdefault.c | 71 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 70 insertions(+), 1 deletions(-) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 8d43008..dc75f28 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -8944,13 +8944,82 @@ search_column_mtime_sort_func (GtkTreeModel *model, return 0; } +static gboolean +search_get_is_filtered (GtkFileChooserDefault *impl, + const GtkFilePath *path, + const gchar *display_name, + const gchar *mime_type) +{ + GtkFileFilterInfo filter_info; + GtkFileFilterFlags needed; + gboolean result; + + if (!impl->current_filter) + return FALSE; + + filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE; + needed = gtk_file_filter_get_needed (impl->current_filter); + + filter_info.display_name = display_name; + filter_info.mime_type = mime_type; + + if (needed & GTK_FILE_FILTER_FILENAME) + { + filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path); + if (filter_info.filename) + filter_info.contains |= GTK_FILE_FILTER_FILENAME; + } + else + filter_info.filename = NULL; + + if (needed & GTK_FILE_FILTER_URI) + { + filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path); + if (filter_info.uri) + filter_info.contains |= GTK_FILE_FILTER_URI; + } + else + filter_info.uri = NULL; + + result = gtk_file_filter_filter (impl->current_filter, &filter_info); + + if (filter_info.filename) + g_free ((gchar *) filter_info.filename); + if (filter_info.uri) + g_free ((gchar *) filter_info.uri); + + return !result; + +} + /* Visibility function for the recent filter model */ static gboolean search_model_visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) { - return TRUE; + GtkFileChooserDefault *impl = user_data; + GtkFilePath *file_path; + gchar *display_name, *mime_type; + gboolean is_folder; + + if (!impl->current_filter) + return TRUE; + + gtk_tree_model_get (model, iter, + SEARCH_MODEL_COL_PATH, &file_path, + SEARCH_MODEL_COL_IS_FOLDER, &is_folder, + SEARCH_MODEL_COL_DISPLAY_NAME, &display_name, + SEARCH_MODEL_COL_MIME_TYPE, &mime_type, + -1); + + if (!display_name) + return TRUE; + + if (is_folder) + return TRUE; + + return !search_get_is_filtered (impl, file_path, display_name, mime_type); } /* Creates the search_model and puts it in the tree view */ -- 1.4.4.2