Use infos from search engine instead of getting them again

When the search engine provides hits with GFileInfo, use that
to add the hits to the model directly, without going through
another round of async get_info calls.

To do this, we add a batched variant of the
_gtk_file_system_model_update_file call that takes lists of
GFiles and GFileInfos. Again, we can avoid repeated resorting
that happens when the files are updated individually.
This commit is contained in:
Matthias Clasen 2015-06-18 15:18:30 -04:00
parent 1b755c546e
commit 1d63335c8e
3 changed files with 36 additions and 5 deletions

View File

@ -6125,27 +6125,38 @@ search_engine_hits_added_cb (GtkSearchEngine *engine,
GList *hits,
GtkFileChooserWidget *impl)
{
GList *l, *files;
GList *l, *files, *files_with_info, *infos;
GFile *file;
files = NULL;
files_with_info = NULL;
infos = NULL;
for (l = hits; l; l = l->next)
{
GtkSearchHit *hit = (GtkSearchHit *)l->data;
file = g_file_new_for_uri (hit->uri);
if (!file)
continue;
files = g_list_prepend (files, file);
if (hit->info)
{
files_with_info = g_list_prepend (files_with_info, file);
infos = g_list_prepend (infos, g_object_ref (hit->info));
}
else
files = g_list_prepend (files, file);
}
if (files)
if (files || files_with_info)
impl->priv->search_model_empty = FALSE;
_gtk_file_system_model_update_files (impl->priv->search_model,
files_with_info, infos);
_gtk_file_system_model_add_and_query_files (impl->priv->search_model,
files,
MODEL_ATTRIBUTES);
files, MODEL_ATTRIBUTES);
g_list_free_full (files, g_object_unref);
g_list_free_full (files_with_info, g_object_unref);
g_list_free_full (infos, g_object_unref);
}
/* Callback used from GtkSearchEngine when the query is done running */

View File

@ -1962,6 +1962,23 @@ _gtk_file_system_model_update_file (GtkFileSystemModel *model,
emit_row_changed_for_node (model, id);
}
void
_gtk_file_system_model_update_files (GtkFileSystemModel *model,
GList *files,
GList *infos)
{
GList *l, *i;
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
freeze_updates (model);
for (l = files, i = infos; l; l = l->next, i = i->next)
_gtk_file_system_model_update_file (model, (GFile *)l->data, (GFileInfo *)i->data);
thaw_updates (model);
}
/**
* _gtk_file_system_model_set_filter:
* @mode: a #GtkFileSystemModel

View File

@ -75,6 +75,9 @@ void _gtk_file_system_model_add_and_query_files (GtkFileSystemMod
void _gtk_file_system_model_update_file (GtkFileSystemModel *model,
GFile *file,
GFileInfo *info);
void _gtk_file_system_model_update_files (GtkFileSystemModel *model,
GList *files,
GList *infos);
void _gtk_file_system_model_set_show_hidden (GtkFileSystemModel *model,
gboolean show_hidden);