[gtk/wip/otte/listview: 49/135] testlistview: Port to directory list
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 49/135] testlistview: Port to directory list
- Date: Sun, 8 Dec 2019 04:13:49 +0000 (UTC)
commit d7d8b8b8fe96b4e4dace38e59b6930c0cd1f3c88
Author: Benjamin Otte <otte redhat com>
Date: Mon Nov 25 08:26:55 2019 +0100
testlistview: Port to directory list
tests/testlistview.c | 141 ++++++++++++++++-----------------------------------
1 file changed, 44 insertions(+), 97 deletions(-)
---
diff --git a/tests/testlistview.c b/tests/testlistview.c
index 8ed262d9b0..dea1384403 100644
--- a/tests/testlistview.c
+++ b/tests/testlistview.c
@@ -6,104 +6,56 @@ GSList *pending = NULL;
guint active = 0;
static void
-got_files (GObject *enumerate,
- GAsyncResult *res,
- gpointer store);
-
-static gboolean
-start_enumerate (GListStore *store)
+loading_cb (GtkDirectoryList *dir,
+ GParamSpec *pspec,
+ gpointer unused)
{
- GFileEnumerator *enumerate;
- GFile *file = g_object_get_data (G_OBJECT (store), "file");
- GError *error = NULL;
-
- enumerate = g_file_enumerate_children (file,
- G_FILE_ATTRIBUTE_STANDARD_TYPE
- "," G_FILE_ATTRIBUTE_STANDARD_ICON
- "," G_FILE_ATTRIBUTE_STANDARD_NAME
- "," G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
- 0,
- NULL,
- &error);
-
- if (enumerate == NULL)
+ if (gtk_directory_list_is_loading (dir))
{
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_TOO_MANY_OPEN_FILES) && active)
- {
- g_clear_error (&error);
- pending = g_slist_prepend (pending, g_object_ref (store));
- return TRUE;
- }
-
- g_clear_error (&error);
- g_object_unref (store);
- return FALSE;
+ active++;
+ /* HACK: ensure loading finishes and the dir doesn't get destroyed */
+ g_object_ref (dir);
}
-
- if (active > 20)
+ else
{
- g_object_unref (enumerate);
- pending = g_slist_prepend (pending, g_object_ref (store));
- return TRUE;
- }
-
- active++;
- g_file_enumerator_next_files_async (enumerate,
- g_file_is_native (file) ? 5000 : 100,
- G_PRIORITY_DEFAULT_IDLE,
- NULL,
- got_files,
- g_object_ref (store));
+ active--;
+ g_object_unref (dir);
- g_object_unref (enumerate);
- return TRUE;
+ while (active < 20 && pending)
+ {
+ GtkDirectoryList *dir2 = pending->data;
+ pending = g_slist_remove (pending, dir2);
+ gtk_directory_list_set_file (dir2, g_object_get_data (G_OBJECT (dir2), "file"));
+ g_object_unref (dir2);
+ }
+ }
}
-static void
-got_files (GObject *enumerate,
- GAsyncResult *res,
- gpointer store)
+static GtkDirectoryList *
+create_directory_list (GFile *file)
{
- GList *l, *files;
- GFile *file = g_object_get_data (store, "file");
- GPtrArray *array;
+ GtkDirectoryList *dir;
+
+ dir = gtk_directory_list_new (G_FILE_ATTRIBUTE_STANDARD_TYPE
+ "," G_FILE_ATTRIBUTE_STANDARD_ICON
+ "," G_FILE_ATTRIBUTE_STANDARD_NAME
+ "," G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ NULL);
+ gtk_directory_list_set_io_priority (dir, G_PRIORITY_DEFAULT_IDLE);
+ g_signal_connect (dir, "notify::loading", G_CALLBACK (loading_cb), NULL);
+ g_assert (!gtk_directory_list_is_loading (dir));
- files = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (enumerate), res, NULL);
- if (files == NULL)
+ if (active > 20)
{
- g_object_unref (store);
- if (pending)
- {
- GListStore *store = pending->data;
- pending = g_slist_remove (pending, store);
- start_enumerate (store);
- }
- active--;
- return;
+ g_object_set_data_full (G_OBJECT (dir), "file", g_object_ref (file), g_object_unref);
+ pending = g_slist_prepend (pending, g_object_ref (dir));
}
-
- array = g_ptr_array_new ();
- g_ptr_array_new_with_free_func (g_object_unref);
- for (l = files; l; l = l->next)
+ else
{
- GFileInfo *info = l->data;
- GFile *child;
-
- child = g_file_get_child (file, g_file_info_get_name (info));
- g_object_set_data_full (G_OBJECT (info), "file", child, g_object_unref);
- g_ptr_array_add (array, info);
+ gtk_directory_list_set_file (dir, file);
}
- g_list_free (files);
-
- g_list_store_splice (store, g_list_model_get_n_items (store), 0, array->pdata, array->len);
- g_ptr_array_unref (array);
- g_file_enumerator_next_files_async (G_FILE_ENUMERATOR (enumerate),
- g_file_is_native (file) ? 5000 : 100,
- G_PRIORITY_DEFAULT_IDLE,
- NULL,
- got_files,
- store);
+ return dir;
}
static int
@@ -127,8 +79,8 @@ compare_files (gconstpointer first,
return 1;
#endif
- first_file = g_object_get_data (G_OBJECT (first), "file");
- second_file = g_object_get_data (G_OBJECT (second), "file");
+ first_file = G_FILE (g_file_info_get_attribute_object (G_FILE_INFO (first), "standard::file"));
+ second_file = G_FILE (g_file_info_get_attribute_object (G_FILE_INFO (second), "standard::file"));
first_path = g_file_get_path (first_file);
second_path = g_file_get_path (second_file);
@@ -144,21 +96,16 @@ static GListModel *
create_list_model_for_directory (gpointer file)
{
GtkSortListModel *sort;
- GListStore *store;
+ GtkDirectoryList *dir;
if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) != G_FILE_TYPE_DIRECTORY)
return NULL;
- store = g_list_store_new (G_TYPE_FILE_INFO);
- g_object_set_data_full (G_OBJECT (store), "file", g_object_ref (file), g_object_unref);
-
- if (!start_enumerate (store))
- return NULL;
-
- sort = gtk_sort_list_model_new (G_LIST_MODEL (store),
+ dir = create_directory_list(file);
+ sort = gtk_sort_list_model_new (G_LIST_MODEL (dir),
compare_files,
NULL, NULL);
- g_object_unref (store);
+ g_object_unref (dir);
return G_LIST_MODEL (sort);
}
@@ -289,7 +236,7 @@ static GListModel *
create_list_model_for_file_info (gpointer file_info,
gpointer unused)
{
- GFile *file = g_object_get_data (file_info, "file");
+ GFile *file = G_FILE (g_file_info_get_attribute_object (file_info, "standard::file"));
if (file == NULL)
return NULL;
@@ -334,7 +281,7 @@ match_file (gpointer item, gpointer data)
{
GtkWidget *search_entry = data;
GFileInfo *info = gtk_tree_list_row_get_item (item);
- GFile *file = g_object_get_data (G_OBJECT (info), "file");
+ GFile *file = G_FILE (g_file_info_get_attribute_object (info, "standard::file"));
char *path;
gboolean result;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]