From 99b37e6ff5b7a8d00a7dd83eabbd15af7381acb8 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 2 Aug 2022 21:17:08 +0530 Subject: [PATCH 01/40] Port patch for item count in size column Re-rebased from an old patch in issue #61 Initial patch by: Andrew Updated by: Alexander Schwinn Rebased by: Amrit Borah --- thunar/thunar-column-editor.c | 31 ++++++++ thunar/thunar-folder.c | 62 ++++++++++++++++ thunar/thunar-folder.h | 1 + thunar/thunar-list-model.c | 135 +++++++++++++++++++++++++++++----- thunar/thunar-preferences.c | 11 +++ thunar/thunar-standard-view.c | 1 + 6 files changed, 221 insertions(+), 20 deletions(-) diff --git a/thunar/thunar-column-editor.c b/thunar/thunar-column-editor.c index d01e4ee50..5685bce7a 100644 --- a/thunar/thunar-column-editor.c +++ b/thunar/thunar-column-editor.c @@ -334,6 +334,37 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) thunar_gtk_label_set_a11y_relation (GTK_LABEL (label), button); gtk_widget_show (button); + frame = g_object_new (GTK_TYPE_FRAME, "border-width", 0, "shadow-type", GTK_SHADOW_NONE, NULL); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0); + gtk_widget_show (frame); + + label = gtk_label_new (_("File size of folders")); + gtk_label_set_attributes (GTK_LABEL (label), thunar_pango_attr_list_bold ()); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_widget_show (label); + + grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 6); + gtk_grid_set_row_spacing (GTK_GRID (grid), 6); + gtk_container_set_border_width (GTK_CONTAINER (grid), 12); + gtk_container_add (GTK_CONTAINER (frame), grid); + gtk_widget_show (grid); + + /* explain what it does */ + label = gtk_label_new (_("When the column 'size' is selected, you may choose to show the\n" + "number of items in a folder instead of the fixed folder size.")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0f); + gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); + gtk_widget_show (label); + + /* create the "Display number of files in size column of folders" button */ + button = gtk_check_button_new_with_mnemonic (_("Display the number of items instead of the fixed size")); + g_object_bind_property (G_OBJECT (column_editor->preferences), "misc-items-count-as-dir-size", G_OBJECT (button), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + gtk_widget_set_tooltip_text (button, _("Select this option to show the number of files in the 'size' column of folders.")); + gtk_widget_set_hexpand (button, TRUE); + gtk_grid_attach (GTK_GRID (grid), button, 0, 4, 2, 1); + gtk_widget_show (button); + /* setup the tree selection */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (column_editor->tree_view)); g_signal_connect_swapped (G_OBJECT (selection), "changed", G_CALLBACK (thunar_column_editor_update_buttons), column_editor); diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index fb128f9f0..bb785a747 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -113,6 +113,9 @@ struct _ThunarFolder GList *files; gboolean reload_info; + guint32 file_count; + gboolean file_count_is_cached; + GList *content_type_ptr; guint content_type_idle_id; @@ -962,6 +965,62 @@ thunar_folder_get_files (const ThunarFolder *folder) +/** + * thunar_folder_get_file_count: + * @file : a #ThunarFolder instance. + * + * Returns the number of items in the directory + * Counts the number of files in the directory as fast as possible. + * Will use cached data to do calculations only once + * + * Return value: Number of files in a folder + **/ +guint32 +thunar_folder_get_file_count (ThunarFolder *folder) +{ + ThunarFile *file; + GFileEnumerator *enumerator; + GFileInfo *child_info; + + _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); + + /* If we already have a cached value, just return it */ + if (G_LIKELY (folder->file_count_is_cached)) + return folder->file_count; + + /* If the content type loader already loaded the file-list, just count it*/ + if (folder->files != NULL) + { + folder->file_count = g_list_length (folder->files); + folder->file_count_is_cached = TRUE; + return folder->file_count; + } + + /* As fallback we will go through the list of gfiles */ + file = thunar_folder_get_corresponding_file (folder); + enumerator = g_file_enumerate_children (thunar_file_get_file (file), NULL, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, NULL); + if(!enumerator) + return 0; + + folder->file_count = 0; + child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); + while (child_info) + { + ++(folder->file_count); + g_object_unref (child_info); + child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); + } + g_file_enumerator_close (enumerator, NULL, NULL); + g_object_unref (enumerator); + + folder->file_count_is_cached = TRUE; + return folder->file_count; +} + + + /** * thunar_folder_get_loading: * @folder : a #ThunarFolder instance. @@ -1011,6 +1070,9 @@ thunar_folder_reload (ThunarFolder *folder, { _thunar_return_if_fail (THUNAR_IS_FOLDER (folder)); + folder->file_count = 0; + folder->file_count_is_cached = FALSE; + /* reload file info too? */ folder->reload_info = reload_info; diff --git a/thunar/thunar-folder.h b/thunar/thunar-folder.h index d5c202b6f..2f050b1a4 100644 --- a/thunar/thunar-folder.h +++ b/thunar/thunar-folder.h @@ -40,6 +40,7 @@ ThunarFolder *thunar_folder_get_for_file (ThunarFile *file); ThunarFile *thunar_folder_get_corresponding_file (const ThunarFolder *folder); GList *thunar_folder_get_files (const ThunarFolder *folder); +guint32 thunar_folder_get_file_count (ThunarFolder *folder); gboolean thunar_folder_get_loading (const ThunarFolder *folder); gboolean thunar_folder_has_folder_monitor (const ThunarFolder *folder); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 75aa77f1a..dfff77e87 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -55,6 +56,7 @@ enum PROP_FOLDERS_FIRST, PROP_NUM_FILES, PROP_SHOW_HIDDEN, + PROP_ITEMS_COUNT_AS_DIR_SIZE, PROP_FILE_SIZE_BINARY, N_PROPERTIES }; @@ -195,6 +197,9 @@ static gint sort_by_size (const ThunarF static gint sort_by_size_in_bytes (const ThunarFile *a, const ThunarFile *b, gboolean case_sensitive); +static gint sort_by_size_and_items_count (ThunarFile *a, + ThunarFile *b, + gboolean case_sensitive); static gint sort_by_type (const ThunarFile *a, const ThunarFile *b, gboolean case_sensitive); @@ -220,7 +225,9 @@ static void thunar_list_model_search_folder (ThunarListMod enum ThunarListModelSearch search_type, gboolean show_hidden); static void thunar_list_model_cancel_search_job (ThunarListModel *model); - +static gboolean thunar_list_model_get_items_count_as_dir_size (ThunarListModel *store); +static void thunar_list_model_set_items_count_as_dir_size (ThunarListModel *store, + gboolean items_count); struct _ThunarListModelClass @@ -249,6 +256,7 @@ struct _ThunarListModel GSList *hidden; ThunarFolder *folder; gboolean show_hidden : 1; + gboolean items_count_as_dir_size : 1; gboolean file_size_binary : 1; ThunarDateStyle date_style; char *date_custom_style; @@ -405,6 +413,16 @@ thunar_list_model_class_init (ThunarListModelClass *klass) TRUE, EXO_PARAM_READWRITE); + /** + * ThunarListModel:items-count-as-dir-size: + **/ + list_model_props[PROP_ITEMS_COUNT_AS_DIR_SIZE] = + g_param_spec_boolean ("items-count-as-dir-size", + "items-count-as-dir-size", + "items-count-as-dir-size", + TRUE, + EXO_PARAM_READWRITE); + /* install properties */ g_object_class_install_properties (gobject_class, N_PROPERTIES, list_model_props); @@ -594,6 +612,10 @@ thunar_list_model_get_property (GObject *object, g_value_set_boolean (value, thunar_list_model_get_file_size_binary (store)); break; + case PROP_ITEMS_COUNT_AS_DIR_SIZE: + g_value_set_boolean (value, thunar_list_model_get_items_count_as_dir_size (store)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -640,6 +662,10 @@ thunar_list_model_set_property (GObject *object, thunar_list_model_set_file_size_binary (store, g_value_get_boolean (value)); break; + case PROP_ITEMS_COUNT_AS_DIR_SIZE: + thunar_list_model_set_items_count_as_dir_size (store, g_value_get_boolean (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -776,16 +802,16 @@ thunar_list_model_get_value (GtkTreeModel *model, gint column, GValue *value) { - ThunarGroup *group; - const gchar *device_type; - const gchar *name; - const gchar *real_name; - ThunarUser *user; - ThunarFile *file; + ThunarGroup *group; + const gchar *device_type; + const gchar *name; + const gchar *real_name; + ThunarUser *user; + ThunarFile *file; ThunarFolder *folder; - GFile *g_file; - GFile *g_file_parent; - gchar *str; + gchar *str; + guint32 item_count; + GFile *g_file_parent; _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (model)); _thunar_return_if_fail (iter->stamp == (THUNAR_LIST_MODEL (model))->stamp); @@ -930,16 +956,12 @@ thunar_list_model_get_value (GtkTreeModel *model, case THUNAR_COLUMN_SIZE: g_value_init (value, G_TYPE_STRING); - if (thunar_file_is_mountable (file)) + if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size && thunar_file_is_directory (file) ) { - g_file = thunar_file_get_target_location (file); - if (g_file == NULL) - break; - g_value_take_string (value, thunar_g_file_get_free_space_string (g_file, THUNAR_LIST_MODEL (model)->file_size_binary)); - g_object_unref (g_file); - break; + item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file)); + g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } - if (!thunar_file_is_directory (file)) + else g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); break; @@ -1104,7 +1126,7 @@ thunar_list_model_get_sort_column_id (GtkTreeSortable *sortable, *sort_column_id = THUNAR_COLUMN_NAME; else if (store->sort_func == sort_by_permissions) *sort_column_id = THUNAR_COLUMN_PERMISSIONS; - else if (store->sort_func == sort_by_size) + else if (store->sort_func == sort_by_size || store->sort_func == (ThunarSortFunc) sort_by_size_and_items_count) *sort_column_id = THUNAR_COLUMN_SIZE; else if (store->sort_func == sort_by_size_in_bytes) *sort_column_id = THUNAR_COLUMN_SIZE_IN_BYTES; @@ -1199,7 +1221,7 @@ thunar_list_model_set_sort_column_id (GtkTreeSortable *sortable, break; case THUNAR_COLUMN_SIZE: - store->sort_func = sort_by_size; + store->sort_func = store->items_count_as_dir_size ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; break; case THUNAR_COLUMN_SIZE_IN_BYTES: @@ -1858,6 +1880,32 @@ sort_by_size_in_bytes (const ThunarFile *a, +static gint +sort_by_size_and_items_count (ThunarFile *a, + ThunarFile *b, + gboolean case_sensitive) +{ + guint32 count_a; + guint32 count_b; + + if (thunar_file_is_directory(a) && thunar_file_is_directory(b)) + { + count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a)); + count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b)); + + if (count_a < count_b) + return -1; + else if (count_a > count_b) + return 1; + else + return thunar_file_compare_by_name (a, b, case_sensitive); + } + + return sort_by_size(a, b, case_sensitive); +} + + + static gint sort_by_type (const ThunarFile *a, const ThunarFile *b, @@ -2691,6 +2739,53 @@ thunar_list_model_set_file_size_binary (ThunarListModel *store, +/** + * thunar_list_model_get_items_count_as_dir_size: + * @store : a #ThunarListModel. + * + * Return value: %TRUE if items count in directory will be shown as + * directory size, else %FALSE. + **/ +static gboolean +thunar_list_model_get_items_count_as_dir_size (ThunarListModel *store) +{ + _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), FALSE); + return store->items_count_as_dir_size; +} + + + +/** + * thunar_list_model_set_items_count_as_dir_size: + * @store : a #ThunarListModel. + * @count_as_dir_size : %TRUE if items count in directory will be shown + * as directory size, else %FALSE. + **/ +void +thunar_list_model_set_items_count_as_dir_size (ThunarListModel *store, + gboolean count_as_dir_size) +{ + _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); + + /* check if the new setting differs */ + if (store->items_count_as_dir_size == count_as_dir_size) + return; + + store->items_count_as_dir_size = count_as_dir_size; + g_object_notify_by_pspec (G_OBJECT (store), list_model_props[PROP_ITEMS_COUNT_AS_DIR_SIZE]); + + gtk_tree_model_foreach (GTK_TREE_MODEL (store), (GtkTreeModelForeachFunc) (void (*)(void)) gtk_tree_model_row_changed, NULL); + + /* re-sorting the store if needed */ + if (store->sort_func == sort_by_size || store->sort_func == (ThunarSortFunc) sort_by_size_and_items_count) + { + store->sort_func = store->items_count_as_dir_size ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; + thunar_list_model_sort (store); + } +} + + + /** * thunar_list_model_get_file: * @store : a #ThunarListModel. diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 2a5d6d4b8..d440a977c 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -89,6 +89,7 @@ enum PROP_MISC_DATE_CUSTOM_STYLE, PROP_EXEC_SHELL_SCRIPTS_BY_DEFAULT, PROP_MISC_FOLDERS_FIRST, + PROP_MISC_ITEMS_COUNT_AS_DIR_SIZE, PROP_MISC_FULL_PATH_IN_TAB_TITLE, PROP_MISC_FULL_PATH_IN_WINDOW_TITLE, PROP_MISC_HORIZONTAL_WHEEL_NAVIGATES, @@ -687,6 +688,16 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) TRUE, EXO_PARAM_READWRITE); + /** + * ThunarPreferences:misc-folders-first: + **/ + preferences_props[PROP_MISC_ITEMS_COUNT_AS_DIR_SIZE] = + g_param_spec_boolean ("misc-items-count-as-dir-size", + "MiscItemsCountAsDirSize", + NULL, + TRUE, + EXO_PARAM_READWRITE); + /** * ThunarPreferences:misc-full-path-in-tab-title: * diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 852dbaea4..9801b12ed 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -831,6 +831,7 @@ thunar_standard_view_init (ThunarStandardView *standard_view) g_object_bind_property (G_OBJECT (standard_view->preferences), "misc-date-custom-style", G_OBJECT (standard_view->model), "date-custom-style", G_BINDING_SYNC_CREATE); g_object_bind_property (G_OBJECT (standard_view->preferences), "misc-folders-first", G_OBJECT (standard_view->model), "folders-first", G_BINDING_SYNC_CREATE); g_object_bind_property (G_OBJECT (standard_view->preferences), "misc-file-size-binary", G_OBJECT (standard_view->model), "file-size-binary", G_BINDING_SYNC_CREATE); + g_object_bind_property (G_OBJECT (standard_view->preferences), "misc-items-count-as-dir-size", G_OBJECT (standard_view->model), "items-count-as-dir-size", G_BINDING_SYNC_CREATE); /* setup the icon renderer */ standard_view->icon_renderer = thunar_icon_renderer_new (); -- GitLab From 3dadf921d95d3a242d8578cb3ce3a9b011bedc52 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 9 Aug 2022 19:00:22 +0530 Subject: [PATCH 02/40] Temporarily remove file count caching --- thunar/thunar-folder.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index bb785a747..e85da43f6 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -114,7 +114,6 @@ struct _ThunarFolder gboolean reload_info; guint32 file_count; - gboolean file_count_is_cached; GList *content_type_ptr; guint content_type_idle_id; @@ -984,15 +983,10 @@ thunar_folder_get_file_count (ThunarFolder *folder) _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); - /* If we already have a cached value, just return it */ - if (G_LIKELY (folder->file_count_is_cached)) - return folder->file_count; - /* If the content type loader already loaded the file-list, just count it*/ if (folder->files != NULL) { folder->file_count = g_list_length (folder->files); - folder->file_count_is_cached = TRUE; return folder->file_count; } @@ -1015,7 +1009,6 @@ thunar_folder_get_file_count (ThunarFolder *folder) g_file_enumerator_close (enumerator, NULL, NULL); g_object_unref (enumerator); - folder->file_count_is_cached = TRUE; return folder->file_count; } @@ -1071,7 +1064,6 @@ thunar_folder_reload (ThunarFolder *folder, _thunar_return_if_fail (THUNAR_IS_FOLDER (folder)); folder->file_count = 0; - folder->file_count_is_cached = FALSE; /* reload file info too? */ folder->reload_info = reload_info; -- GitLab From 5133ddc389e09841526e092cdc9f5b68b4ff9cb0 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 9 Aug 2022 21:23:02 +0530 Subject: [PATCH 03/40] Add async file enumeration (not working) seg faults for some reason --- thunar/thunar-folder.c | 79 ++++++++++++++++++++++++++++++++++++++ thunar/thunar-folder.h | 2 + thunar/thunar-list-model.c | 3 +- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index e85da43f6..32ff7ca5c 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -1012,6 +1012,85 @@ thunar_folder_get_file_count (ThunarFolder *folder) return folder->file_count; } +static void +_enumerate_children_callback (GObject *source_object, + GAsyncResult *result, + gpointer *user_data) +{ + ThunarFolder *folder; + ThunarFile *file; + GFile *g_file; + GFileEnumerator *enumerator; + GFileInfo *child_info; + GValue *value; + GError *error = NULL; + + value = (GValue *) user_data; + g_file = G_FILE (source_object); + file = thunar_file_get (g_file, &error); + + if (error != NULL) + { + g_warning ("Error converting file to ThunarFile: %s\n", error->message); + g_clear_error (&error); + return; + } + + folder = thunar_folder_get_for_file (file); + enumerator = g_file_enumerate_children_finish (g_file, result, &error); + + if (error != NULL) + { + g_warning ("Error occured while enumerating children to get the file count for folder: %s\n", error->message); + g_clear_error (&error); + return; + } + + if (!enumerator) + return; + + folder->file_count = 0; + child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); + + while (child_info) + { + (folder->file_count)++; + g_object_unref (child_info); + child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); + } + + g_file_enumerator_close (enumerator, NULL, NULL); + g_object_unref (enumerator); + + g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", folder->file_count), folder->file_count)); + g_object_unref (value); +} + + +/** + * thunar_folder_get_file_count_async: + * @folder : A #ThunarFolder instance + * @value : A #GValue to store the final count string in + * + * Asynchronously get the file count and update the string given to reflect it. + **/ +guint32 +thunar_folder_get_file_count_async (ThunarFolder *folder, + GValue *value) +{ + ThunarFile *file; + + _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); + + file = thunar_folder_get_corresponding_file (folder); + + g_file_enumerate_children_async (thunar_file_get_file (file), NULL, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + 1, NULL, (GAsyncReadyCallback) _enumerate_children_callback, value); + + return folder->file_count; +} + /** diff --git a/thunar/thunar-folder.h b/thunar/thunar-folder.h index 2f050b1a4..9d58538ab 100644 --- a/thunar/thunar-folder.h +++ b/thunar/thunar-folder.h @@ -41,6 +41,8 @@ ThunarFolder *thunar_folder_get_for_file (ThunarFile *file); ThunarFile *thunar_folder_get_corresponding_file (const ThunarFolder *folder); GList *thunar_folder_get_files (const ThunarFolder *folder); guint32 thunar_folder_get_file_count (ThunarFolder *folder); +guint32 thunar_folder_get_file_count_async (ThunarFolder *folder, + GValue *value); gboolean thunar_folder_get_loading (const ThunarFolder *folder); gboolean thunar_folder_has_folder_monitor (const ThunarFolder *folder); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index dfff77e87..035762884 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -958,8 +958,7 @@ thunar_list_model_get_value (GtkTreeModel *model, g_value_init (value, G_TYPE_STRING); if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size && thunar_file_is_directory (file) ) { - item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file)); - g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); + item_count = thunar_folder_get_file_count_async (thunar_folder_get_for_file (file), g_object_ref (value)); } else g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); -- GitLab From fcda15fa08d97eb2851e8cce027832396030dd40 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 20 Sep 2022 21:30:46 +0530 Subject: [PATCH 04/40] Revert "Add async file enumeration (not working)" This reverts commit f4cbbfa962ad3ed30535e5d0d161b4fab6ff5574. --- thunar/thunar-folder.c | 79 -------------------------------------- thunar/thunar-folder.h | 2 - thunar/thunar-list-model.c | 3 +- 3 files changed, 2 insertions(+), 82 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index 32ff7ca5c..e85da43f6 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -1012,85 +1012,6 @@ thunar_folder_get_file_count (ThunarFolder *folder) return folder->file_count; } -static void -_enumerate_children_callback (GObject *source_object, - GAsyncResult *result, - gpointer *user_data) -{ - ThunarFolder *folder; - ThunarFile *file; - GFile *g_file; - GFileEnumerator *enumerator; - GFileInfo *child_info; - GValue *value; - GError *error = NULL; - - value = (GValue *) user_data; - g_file = G_FILE (source_object); - file = thunar_file_get (g_file, &error); - - if (error != NULL) - { - g_warning ("Error converting file to ThunarFile: %s\n", error->message); - g_clear_error (&error); - return; - } - - folder = thunar_folder_get_for_file (file); - enumerator = g_file_enumerate_children_finish (g_file, result, &error); - - if (error != NULL) - { - g_warning ("Error occured while enumerating children to get the file count for folder: %s\n", error->message); - g_clear_error (&error); - return; - } - - if (!enumerator) - return; - - folder->file_count = 0; - child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); - - while (child_info) - { - (folder->file_count)++; - g_object_unref (child_info); - child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); - } - - g_file_enumerator_close (enumerator, NULL, NULL); - g_object_unref (enumerator); - - g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", folder->file_count), folder->file_count)); - g_object_unref (value); -} - - -/** - * thunar_folder_get_file_count_async: - * @folder : A #ThunarFolder instance - * @value : A #GValue to store the final count string in - * - * Asynchronously get the file count and update the string given to reflect it. - **/ -guint32 -thunar_folder_get_file_count_async (ThunarFolder *folder, - GValue *value) -{ - ThunarFile *file; - - _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); - - file = thunar_folder_get_corresponding_file (folder); - - g_file_enumerate_children_async (thunar_file_get_file (file), NULL, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - 1, NULL, (GAsyncReadyCallback) _enumerate_children_callback, value); - - return folder->file_count; -} - /** diff --git a/thunar/thunar-folder.h b/thunar/thunar-folder.h index 9d58538ab..2f050b1a4 100644 --- a/thunar/thunar-folder.h +++ b/thunar/thunar-folder.h @@ -41,8 +41,6 @@ ThunarFolder *thunar_folder_get_for_file (ThunarFile *file); ThunarFile *thunar_folder_get_corresponding_file (const ThunarFolder *folder); GList *thunar_folder_get_files (const ThunarFolder *folder); guint32 thunar_folder_get_file_count (ThunarFolder *folder); -guint32 thunar_folder_get_file_count_async (ThunarFolder *folder, - GValue *value); gboolean thunar_folder_get_loading (const ThunarFolder *folder); gboolean thunar_folder_has_folder_monitor (const ThunarFolder *folder); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 035762884..dfff77e87 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -958,7 +958,8 @@ thunar_list_model_get_value (GtkTreeModel *model, g_value_init (value, G_TYPE_STRING); if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size && thunar_file_is_directory (file) ) { - item_count = thunar_folder_get_file_count_async (thunar_folder_get_for_file (file), g_object_ref (value)); + item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file)); + g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } else g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); -- GitLab From eec7aeebd73f0b2cccd5cefe736138b85d16e1c3 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 20 Sep 2022 21:30:54 +0530 Subject: [PATCH 05/40] Revert "Temporarily remove file count caching" This reverts commit 5497c6176b209a83a7a2907afa55c103d9104516. --- thunar/thunar-folder.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index e85da43f6..bb785a747 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -114,6 +114,7 @@ struct _ThunarFolder gboolean reload_info; guint32 file_count; + gboolean file_count_is_cached; GList *content_type_ptr; guint content_type_idle_id; @@ -983,10 +984,15 @@ thunar_folder_get_file_count (ThunarFolder *folder) _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); + /* If we already have a cached value, just return it */ + if (G_LIKELY (folder->file_count_is_cached)) + return folder->file_count; + /* If the content type loader already loaded the file-list, just count it*/ if (folder->files != NULL) { folder->file_count = g_list_length (folder->files); + folder->file_count_is_cached = TRUE; return folder->file_count; } @@ -1009,6 +1015,7 @@ thunar_folder_get_file_count (ThunarFolder *folder) g_file_enumerator_close (enumerator, NULL, NULL); g_object_unref (enumerator); + folder->file_count_is_cached = TRUE; return folder->file_count; } @@ -1064,6 +1071,7 @@ thunar_folder_reload (ThunarFolder *folder, _thunar_return_if_fail (THUNAR_IS_FOLDER (folder)); folder->file_count = 0; + folder->file_count_is_cached = FALSE; /* reload file info too? */ folder->reload_info = reload_info; -- GitLab From 14239d39b0104b4145999103adee1c1fd4024836 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Thu, 20 Oct 2022 15:15:53 +0530 Subject: [PATCH 06/40] Fix merge conflicts --- thunar/thunar-enum-types.c | 19 ++ thunar/thunar-enum-types.h | 24 +++ thunar/thunar-list-model.c | 379 ++++++++++++++++++------------------- 3 files changed, 232 insertions(+), 190 deletions(-) diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c index 9a7e2343c..bdc658fc0 100644 --- a/thunar/thunar-enum-types.c +++ b/thunar/thunar-enum-types.c @@ -712,3 +712,22 @@ thunar_image_preview_mode_get_type (void) return type; } +GType +thunar_items_as_folder_size_get_type (void) +{ + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GEnumValue values[] = + { + { THUNAR_FOLDER_ITEM_COUNT_NEVER, "THUNAR_FOLDER_ITEM_COUNT_NEVER", N_("Never") }, + { THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL, "THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL", N_("Only for local files") }, + { THUNAR_FOLDER_ITEM_COUNT_ALWAYS, "THUNAR_FOLDER_ITEM_COUNT_ALWAYS", N_("Always") }, + { 0, NULL, NULL } + }; + + type = g_enum_register_static ("ThunarItemsAsFolderSize", values); + } + return type; +} diff --git a/thunar/thunar-enum-types.h b/thunar/thunar-enum-types.h index f63092beb..e81b05622 100644 --- a/thunar/thunar-enum-types.h +++ b/thunar/thunar-enum-types.h @@ -480,6 +480,30 @@ typedef enum GType thunar_image_preview_mode_get_type (void) G_GNUC_CONST; +/** + * ThunarItemsAsFolderSize + * + * Specify when the size column on a folder + * should instead show the item count of the folder + **/ + +#define THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE (thunar_items_as_folder_size_get_type ()) + +/** + * ThunarItemsAsFolderSize: + * @THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER, : never show number of items as the size of the folder + * @THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL, : only show number of items as size of folder for local folders + * @THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS, : always show the number of items as the size of the folder + **/ +typedef enum +{ + THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER, + THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL, + THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS, +} ThunarItemsAsFolderSize; + +GType thunar_items_as_folder_size_get_type (void) G_GNUC_CONST; + G_END_DECLS; #endif /* !__THUNAR_ENUM_TYPES_H__ */ diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index dfff77e87..847ae1ecd 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -75,159 +75,159 @@ typedef gint (*ThunarSortFunc) (const ThunarFile *a, const ThunarFile *b, gboolean case_sensitive); -static void thunar_list_model_tree_model_init (GtkTreeModelIface *iface); -static void thunar_list_model_drag_dest_init (GtkTreeDragDestIface *iface); -static void thunar_list_model_sortable_init (GtkTreeSortableIface *iface); -static void thunar_list_model_dispose (GObject *object); -static void thunar_list_model_finalize (GObject *object); -static void thunar_list_model_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void thunar_list_model_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static GtkTreeModelFlags thunar_list_model_get_flags (GtkTreeModel *model); -static gint thunar_list_model_get_n_columns (GtkTreeModel *model); -static GType thunar_list_model_get_column_type (GtkTreeModel *model, - gint idx); -static gboolean thunar_list_model_get_iter (GtkTreeModel *model, - GtkTreeIter *iter, - GtkTreePath *path); -static GtkTreePath *thunar_list_model_get_path (GtkTreeModel *model, - GtkTreeIter *iter); -static void thunar_list_model_get_value (GtkTreeModel *model, - GtkTreeIter *iter, - gint column, - GValue *value); -static gboolean thunar_list_model_iter_next (GtkTreeModel *model, - GtkTreeIter *iter); -static gboolean thunar_list_model_iter_children (GtkTreeModel *model, - GtkTreeIter *iter, - GtkTreeIter *parent); -static gboolean thunar_list_model_iter_has_child (GtkTreeModel *model, - GtkTreeIter *iter); -static gint thunar_list_model_iter_n_children (GtkTreeModel *model, - GtkTreeIter *iter); -static gboolean thunar_list_model_iter_nth_child (GtkTreeModel *model, - GtkTreeIter *iter, - GtkTreeIter *parent, - gint n); -static gboolean thunar_list_model_iter_parent (GtkTreeModel *model, - GtkTreeIter *iter, - GtkTreeIter *child); -static gboolean thunar_list_model_drag_data_received (GtkTreeDragDest *dest, - GtkTreePath *path, - GtkSelectionData *data); -static gboolean thunar_list_model_row_drop_possible (GtkTreeDragDest *dest, - GtkTreePath *path, - GtkSelectionData *data); -static gboolean thunar_list_model_get_sort_column_id (GtkTreeSortable *sortable, - gint *sort_column_id, - GtkSortType *order); -static void thunar_list_model_set_sort_column_id (GtkTreeSortable *sortable, - gint sort_column_id, - GtkSortType order); -static void thunar_list_model_set_default_sort_func (GtkTreeSortable *sortable, - GtkTreeIterCompareFunc func, - gpointer data, - GDestroyNotify destroy); -static void thunar_list_model_set_sort_func (GtkTreeSortable *sortable, - gint sort_column_id, - GtkTreeIterCompareFunc func, - gpointer data, - GDestroyNotify destroy); -static gboolean thunar_list_model_has_default_sort_func (GtkTreeSortable *sortable); -static gint thunar_list_model_cmp_func (gconstpointer a, - gconstpointer b, - gpointer user_data); -static void thunar_list_model_sort (ThunarListModel *store); -static void thunar_list_model_file_changed (ThunarFileMonitor *file_monitor, - ThunarFile *file, - ThunarListModel *store); -static void thunar_list_model_folder_destroy (ThunarFolder *folder, - ThunarListModel *store); -static void thunar_list_model_folder_error (ThunarFolder *folder, - const GError *error, - ThunarListModel *store); -static void thunar_list_model_files_added (ThunarFolder *folder, - GList *files, - ThunarListModel *store); -static void thunar_list_model_files_removed (ThunarFolder *folder, - GList *files, - ThunarListModel *store); -static gint sort_by_date (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive, - gint type); -static gint sort_by_date_created (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_date_accessed (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_date_modified (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_date_deleted (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_recency (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_location (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_group (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_mime_type (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_owner (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_permissions (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_size (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_size_in_bytes (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_size_and_items_count (ThunarFile *a, - ThunarFile *b, - gboolean case_sensitive); -static gint sort_by_type (const ThunarFile *a, - const ThunarFile *b, - gboolean case_sensitive); - -static gboolean thunar_list_model_get_case_sensitive (ThunarListModel *store); -static void thunar_list_model_set_case_sensitive (ThunarListModel *store, - gboolean case_sensitive); -static ThunarDateStyle thunar_list_model_get_date_style (ThunarListModel *store); -static void thunar_list_model_set_date_style (ThunarListModel *store, - ThunarDateStyle date_style); -static const char* thunar_list_model_get_date_custom_style (ThunarListModel *store); -static void thunar_list_model_set_date_custom_style (ThunarListModel *store, - const char *date_custom_style); -static gint thunar_list_model_get_num_files (ThunarListModel *store); -static gboolean thunar_list_model_get_folders_first (ThunarListModel *store); -static ThunarJob* thunar_list_model_job_search_directory (ThunarListModel *model, - const gchar *search_query_c, - ThunarFile *directory); -static void thunar_list_model_search_folder (ThunarListModel *model, - ThunarJob *job, - gchar *uri, - gchar **search_query_c_terms, - enum ThunarListModelSearch search_type, - gboolean show_hidden); -static void thunar_list_model_cancel_search_job (ThunarListModel *model); -static gboolean thunar_list_model_get_items_count_as_dir_size (ThunarListModel *store); -static void thunar_list_model_set_items_count_as_dir_size (ThunarListModel *store, - gboolean items_count); +static void thunar_list_model_tree_model_init (GtkTreeModelIface *iface); +static void thunar_list_model_drag_dest_init (GtkTreeDragDestIface *iface); +static void thunar_list_model_sortable_init (GtkTreeSortableIface *iface); +static void thunar_list_model_dispose (GObject *object); +static void thunar_list_model_finalize (GObject *object); +static void thunar_list_model_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void thunar_list_model_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static GtkTreeModelFlags thunar_list_model_get_flags (GtkTreeModel *model); +static gint thunar_list_model_get_n_columns (GtkTreeModel *model); +static GType thunar_list_model_get_column_type (GtkTreeModel *model, + gint idx); +static gboolean thunar_list_model_get_iter (GtkTreeModel *model, + GtkTreeIter *iter, + GtkTreePath *path); +static GtkTreePath *thunar_list_model_get_path (GtkTreeModel *model, + GtkTreeIter *iter); +static void thunar_list_model_get_value (GtkTreeModel *model, + GtkTreeIter *iter, + gint column, + GValue *value); +static gboolean thunar_list_model_iter_next (GtkTreeModel *model, + GtkTreeIter *iter); +static gboolean thunar_list_model_iter_children (GtkTreeModel *model, + GtkTreeIter *iter, + GtkTreeIter *parent); +static gboolean thunar_list_model_iter_has_child (GtkTreeModel *model, + GtkTreeIter *iter); +static gint thunar_list_model_iter_n_children (GtkTreeModel *model, + GtkTreeIter *iter); +static gboolean thunar_list_model_iter_nth_child (GtkTreeModel *model, + GtkTreeIter *iter, + GtkTreeIter *parent, + gint n); +static gboolean thunar_list_model_iter_parent (GtkTreeModel *model, + GtkTreeIter *iter, + GtkTreeIter *child); +static gboolean thunar_list_model_drag_data_received (GtkTreeDragDest *dest, + GtkTreePath *path, + GtkSelectionData *data); +static gboolean thunar_list_model_row_drop_possible (GtkTreeDragDest *dest, + GtkTreePath *path, + GtkSelectionData *data); +static gboolean thunar_list_model_get_sort_column_id (GtkTreeSortable *sortable, + gint *sort_column_id, + GtkSortType *order); +static void thunar_list_model_set_sort_column_id (GtkTreeSortable *sortable, + gint sort_column_id, + GtkSortType order); +static void thunar_list_model_set_default_sort_func (GtkTreeSortable *sortable, + GtkTreeIterCompareFunc func, + gpointer data, + GDestroyNotify destroy); +static void thunar_list_model_set_sort_func (GtkTreeSortable *sortable, + gint sort_column_id, + GtkTreeIterCompareFunc func, + gpointer data, + GDestroyNotify destroy); +static gboolean thunar_list_model_has_default_sort_func (GtkTreeSortable *sortable); +static gint thunar_list_model_cmp_func (gconstpointer a, + gconstpointer b, + gpointer user_data); +static void thunar_list_model_sort (ThunarListModel *store); +static void thunar_list_model_file_changed (ThunarFileMonitor *file_monitor, + ThunarFile *file, + ThunarListModel *store); +static void thunar_list_model_folder_destroy (ThunarFolder *folder, + ThunarListModel *store); +static void thunar_list_model_folder_error (ThunarFolder *folder, + const GError *error, + ThunarListModel *store); +static void thunar_list_model_files_added (ThunarFolder *folder, + GList *files, + ThunarListModel *store); +static void thunar_list_model_files_removed (ThunarFolder *folder, + GList *files, + ThunarListModel *store); +static gint sort_by_date (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive, + gint type); +static gint sort_by_date_created (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_date_accessed (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_date_modified (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_date_deleted (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_recency (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_location (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_group (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_mime_type (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_owner (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_permissions (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_size (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_size_in_bytes (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_size_and_items_count (ThunarFile *a, + ThunarFile *b, + gboolean case_sensitive); +static gint sort_by_type (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); + +static gboolean thunar_list_model_get_case_sensitive (ThunarListModel *store); +static void thunar_list_model_set_case_sensitive (ThunarListModel *store, + gboolean case_sensitive); +static ThunarDateStyle thunar_list_model_get_date_style (ThunarListModel *store); +static void thunar_list_model_set_date_style (ThunarListModel *store, + ThunarDateStyle date_style); +static const char* thunar_list_model_get_date_custom_style (ThunarListModel *store); +static void thunar_list_model_set_date_custom_style (ThunarListModel *store, + const char *date_custom_style); +static gint thunar_list_model_get_num_files (ThunarListModel *store); +static gboolean thunar_list_model_get_folders_first (ThunarListModel *store); +static ThunarJob* thunar_list_model_job_search_directory (ThunarListModel *model, + const gchar *search_query_c, + ThunarFile *directory); +static void thunar_list_model_search_folder (ThunarListModel *model, + ThunarJob *job, + gchar *uri, + gchar **search_query_c_terms, + enum ThunarListModelSearch search_type, + gboolean show_hidden); +static void thunar_list_model_cancel_search_job (ThunarListModel *model); +static gint thunar_list_model_get_items_count_as_dir_size (ThunarListModel *store); +static void thunar_list_model_set_items_count_as_dir_size (ThunarListModel *store, + ThunarItemsAsFolderSize items_count); struct _ThunarListModelClass @@ -249,46 +249,46 @@ struct _ThunarListModel * generated by another model. */ #ifndef NDEBUG - gint stamp; + gint stamp; #endif - GSequence *rows; - GSList *hidden; - ThunarFolder *folder; - gboolean show_hidden : 1; - gboolean items_count_as_dir_size : 1; - gboolean file_size_binary : 1; - ThunarDateStyle date_style; - char *date_custom_style; + GSequence *rows; + GSList *hidden; + ThunarFolder *folder; + gboolean show_hidden : 1; + ThunarItemsAsFolderSize items_count_as_dir_size; + gboolean file_size_binary : 1; + ThunarDateStyle date_style; + char *date_custom_style; /* Use the shared ThunarFileMonitor instance, so we * do not need to connect "changed" handler to every * file in the model. */ - ThunarFileMonitor *file_monitor; + ThunarFileMonitor *file_monitor; /* ids for the "row-inserted" and "row-deleted" signals * of GtkTreeModel to speed up folder changing. */ - guint row_inserted_id; - guint row_deleted_id; + guint row_inserted_id; + guint row_deleted_id; - gboolean sort_case_sensitive : 1; - gboolean sort_folders_first : 1; - gint sort_sign; /* 1 = ascending, -1 descending */ - ThunarSortFunc sort_func; + gboolean sort_case_sensitive : 1; + gboolean sort_folders_first : 1; + gint sort_sign; /* 1 = ascending, -1 descending */ + ThunarSortFunc sort_func; /* searching runs in a separate thread which incrementally inserts results (files) * in the files_to_add list. * Periodically the main thread takes all the files in the files_to_add list * and adds them in the model. The list is then emptied. */ - ThunarJob *recursive_search_job; - GList *files_to_add; - GMutex mutex_files_to_add; + ThunarJob *recursive_search_job; + GList *files_to_add; + GMutex mutex_files_to_add; /* used to stop the periodic call to add_search_files when the search is finished/canceled */ - guint update_search_results_timeout_id; + guint update_search_results_timeout_id; }; @@ -417,11 +417,12 @@ thunar_list_model_class_init (ThunarListModelClass *klass) * ThunarListModel:items-count-as-dir-size: **/ list_model_props[PROP_ITEMS_COUNT_AS_DIR_SIZE] = - g_param_spec_boolean ("items-count-as-dir-size", - "items-count-as-dir-size", - "items-count-as-dir-size", - TRUE, - EXO_PARAM_READWRITE); + g_param_spec_enum ("items-count-as-dir-size", + "items-count-as-dir-size", + "items-count-as-dir-size", + THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE, + TRUE, + EXO_PARAM_READWRITE); /* install properties */ g_object_class_install_properties (gobject_class, N_PROPERTIES, list_model_props); @@ -613,7 +614,7 @@ thunar_list_model_get_property (GObject *object, break; case PROP_ITEMS_COUNT_AS_DIR_SIZE: - g_value_set_boolean (value, thunar_list_model_get_items_count_as_dir_size (store)); + g_value_set_enum (value, thunar_list_model_get_items_count_as_dir_size (store)); break; default: @@ -663,7 +664,7 @@ thunar_list_model_set_property (GObject *object, break; case PROP_ITEMS_COUNT_AS_DIR_SIZE: - thunar_list_model_set_items_count_as_dir_size (store, g_value_get_boolean (value)); + thunar_list_model_set_items_count_as_dir_size (store, g_value_get_enum (value)); break; default: @@ -956,7 +957,7 @@ thunar_list_model_get_value (GtkTreeModel *model, case THUNAR_COLUMN_SIZE: g_value_init (value, G_TYPE_STRING); - if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size && thunar_file_is_directory (file) ) + if ( (THUNAR_LIST_MODEL (model)->items_count_as_dir_size != THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) && thunar_file_is_directory (file) ) { item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file)); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); @@ -1221,7 +1222,7 @@ thunar_list_model_set_sort_column_id (GtkTreeSortable *sortable, break; case THUNAR_COLUMN_SIZE: - store->sort_func = store->items_count_as_dir_size ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; + store->sort_func = (store->items_count_as_dir_size != THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; break; case THUNAR_COLUMN_SIZE_IN_BYTES: @@ -2743,10 +2744,9 @@ thunar_list_model_set_file_size_binary (ThunarListModel *store, * thunar_list_model_get_items_count_as_dir_size: * @store : a #ThunarListModel. * - * Return value: %TRUE if items count in directory will be shown as - * directory size, else %FALSE. + * Return value: A value of the enum #ThunarItemsAsFolderSize **/ -static gboolean +static gint thunar_list_model_get_items_count_as_dir_size (ThunarListModel *store) { _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), FALSE); @@ -2758,12 +2758,11 @@ thunar_list_model_get_items_count_as_dir_size (ThunarListModel *store) /** * thunar_list_model_set_items_count_as_dir_size: * @store : a #ThunarListModel. - * @count_as_dir_size : %TRUE if items count in directory will be shown - * as directory size, else %FALSE. + * @count_as_dir_size : a value of the enum ThunarItemsAsFolderSize **/ void -thunar_list_model_set_items_count_as_dir_size (ThunarListModel *store, - gboolean count_as_dir_size) +thunar_list_model_set_items_count_as_dir_size (ThunarListModel *store, + ThunarItemsAsFolderSize count_as_dir_size) { _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); @@ -2779,7 +2778,7 @@ thunar_list_model_set_items_count_as_dir_size (ThunarListModel *store, /* re-sorting the store if needed */ if (store->sort_func == sort_by_size || store->sort_func == (ThunarSortFunc) sort_by_size_and_items_count) { - store->sort_func = store->items_count_as_dir_size ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; + store->sort_func = (store->items_count_as_dir_size != THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; thunar_list_model_sort (store); } } -- GitLab From a956aca36f3415eb76ae7d8ef8b075a49dfff51f Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Mon, 19 Sep 2022 17:01:38 +0530 Subject: [PATCH 07/40] Add three option box for number of items in size column for folders --- thunar/thunar-column-editor.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/thunar/thunar-column-editor.c b/thunar/thunar-column-editor.c index 5685bce7a..09fe83860 100644 --- a/thunar/thunar-column-editor.c +++ b/thunar/thunar-column-editor.c @@ -128,6 +128,7 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) GtkTreeIter iter; GtkWidget *separator; GtkWidget *button; + GtkWidget *combo; GtkWidget *frame; GtkWidget *image; GtkWidget *label; @@ -351,15 +352,32 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) gtk_widget_show (grid); /* explain what it does */ - label = gtk_label_new (_("When the column 'size' is selected, you may choose to show the\n" - "number of items in a folder instead of the fixed folder size.")); + label = gtk_label_new (_("Show the number of items in the 'size' column\n" + "for folders instead of the fixed folder size")); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); gtk_widget_show (label); + combo = gtk_combo_box_text_new (); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Always")); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Local files only")); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Never")); + + /* g_object_bind_property_full (G_OBJECT (dialog->preferences), "default-view", */ + /* G_OBJECT (combo), "active", */ + /* G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, */ + /* transform_view_string_to_index, */ + /* transform_view_index_to_string, */ + /* NULL, NULL); */ + + gtk_widget_set_hexpand (combo, TRUE); + gtk_grid_attach (GTK_GRID (grid), combo, 1, row - 1, 1, 1); + thunar_gtk_label_set_a11y_relation (GTK_LABEL (label), combo); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); + gtk_widget_show (combo); + /* create the "Display number of files in size column of folders" button */ - button = gtk_check_button_new_with_mnemonic (_("Display the number of items instead of the fixed size")); - g_object_bind_property (G_OBJECT (column_editor->preferences), "misc-items-count-as-dir-size", G_OBJECT (button), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + /* g_object_bind_property (G_OBJECT (column_editor->preferences), "misc-items-count-as-dir-size", G_OBJECT (button), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); */ gtk_widget_set_tooltip_text (button, _("Select this option to show the number of files in the 'size' column of folders.")); gtk_widget_set_hexpand (button, TRUE); gtk_grid_attach (GTK_GRID (grid), button, 0, 4, 2, 1); -- GitLab From 9d05861311f8bd98f84e9a0bc502a51bbbd35b2f Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Mon, 3 Oct 2022 15:05:07 +0530 Subject: [PATCH 08/40] [WIP] Add binding between properties --- thunar/thunar-column-editor.c | 75 ++++++++++++++++++++++++++++------- thunar/thunar-preferences.c | 13 +++--- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/thunar/thunar-column-editor.c b/thunar/thunar-column-editor.c index 09fe83860..417c46a14 100644 --- a/thunar/thunar-column-editor.c +++ b/thunar/thunar-column-editor.c @@ -50,6 +50,14 @@ static void thunar_column_editor_toggle_visibility (ThunarColumnEditor *c static void thunar_column_editor_update_buttons (ThunarColumnEditor *column_editor); static void thunar_column_editor_use_defaults (ThunarColumnEditor *column_editor, GtkWidget *button); +static gboolean transform_dirsize_string_to_enum (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data); +static gboolean transform_dirsize_enum_to_string (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data); @@ -359,16 +367,16 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) gtk_widget_show (label); combo = gtk_combo_box_text_new (); - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Always")); - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Local files only")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Never")); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Only for local files")); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Always")); - /* g_object_bind_property_full (G_OBJECT (dialog->preferences), "default-view", */ - /* G_OBJECT (combo), "active", */ - /* G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, */ - /* transform_view_string_to_index, */ - /* transform_view_index_to_string, */ - /* NULL, NULL); */ + g_object_bind_property_full (G_OBJECT (column_editor->preferences), "misc-items-count-as-dir-size", + G_OBJECT (combo), "active", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, + transform_dirsize_string_to_enum, + transform_dirsize_enum_to_string, + NULL, NULL); gtk_widget_set_hexpand (combo, TRUE); gtk_grid_attach (GTK_GRID (grid), combo, 1, row - 1, 1, 1); @@ -376,13 +384,6 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); gtk_widget_show (combo); - /* create the "Display number of files in size column of folders" button */ - /* g_object_bind_property (G_OBJECT (column_editor->preferences), "misc-items-count-as-dir-size", G_OBJECT (button), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); */ - gtk_widget_set_tooltip_text (button, _("Select this option to show the number of files in the 'size' column of folders.")); - gtk_widget_set_hexpand (button, TRUE); - gtk_grid_attach (GTK_GRID (grid), button, 0, 4, 2, 1); - gtk_widget_show (button); - /* setup the tree selection */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (column_editor->tree_view)); g_signal_connect_swapped (G_OBJECT (selection), "changed", G_CALLBACK (thunar_column_editor_update_buttons), column_editor); @@ -663,6 +664,50 @@ thunar_column_editor_use_defaults (ThunarColumnEditor *column_editor, +static gboolean +transform_dirsize_enum_to_string (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data) +{ + GEnumClass *enum_class; + GEnumValue *enum_value; + gint val; + + val = g_value_get_int (src_value); + enum_class = g_type_class_ref (THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE); + enum_value = g_enum_get_value (enum_class, val); + + g_value_set_static_string (dst_value, enum_value->value_nick); + + return TRUE; +} + + + +static gboolean +transform_dirsize_string_to_enum (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data) +{ + GEnumClass *enum_class; + GEnumValue *enum_value; + char *nick; + gint val; + + nick = g_value_get_string (src_value); + enum_class = g_type_class_ref (THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE); + enum_value = g_enum_get_value_by_nick (enum_class, nick); + + val = g_value_get_enum (enum_value); + g_value_set_enum (dst_value, val); + + return TRUE; +} + + + /** * thunar_show_column_editor: * @parent : the #GtkWidget the #GdkScreen on which to open the diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index d440a977c..70d42f1f8 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -689,14 +689,15 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) EXO_PARAM_READWRITE); /** - * ThunarPreferences:misc-folders-first: + * ThunarPreferences:misc-items-count-as-dir-size **/ preferences_props[PROP_MISC_ITEMS_COUNT_AS_DIR_SIZE] = - g_param_spec_boolean ("misc-items-count-as-dir-size", - "MiscItemsCountAsDirSize", - NULL, - TRUE, - EXO_PARAM_READWRITE); + g_param_spec_enum ("misc-items-count-as-dir-size", + "MiscItemsCountAsDirSize", + NULL, + THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE, + TRUE, + EXO_PARAM_READWRITE); /** * ThunarPreferences:misc-full-path-in-tab-title: -- GitLab From ac6a4ab178f31e62750c8e89a7a001fb5083f94d Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Mon, 3 Oct 2022 16:08:19 +0530 Subject: [PATCH 09/40] Fix bug with property binding of combo box The combo box's "active" property holds an index, not a string. --- thunar/thunar-column-editor.c | 80 +++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 32 deletions(-) diff --git a/thunar/thunar-column-editor.c b/thunar/thunar-column-editor.c index 417c46a14..8105e897a 100644 --- a/thunar/thunar-column-editor.c +++ b/thunar/thunar-column-editor.c @@ -50,11 +50,11 @@ static void thunar_column_editor_toggle_visibility (ThunarColumnEditor *c static void thunar_column_editor_update_buttons (ThunarColumnEditor *column_editor); static void thunar_column_editor_use_defaults (ThunarColumnEditor *column_editor, GtkWidget *button); -static gboolean transform_dirsize_string_to_enum (GBinding *binding, +static gboolean transform_dirsize_enum_to_index (GBinding *binding, const GValue *src_value, GValue *dst_value, gpointer user_data); -static gboolean transform_dirsize_enum_to_string (GBinding *binding, +static gboolean transform_dirsize_index_to_enum (GBinding *binding, const GValue *src_value, GValue *dst_value, gpointer user_data); @@ -374,8 +374,8 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) g_object_bind_property_full (G_OBJECT (column_editor->preferences), "misc-items-count-as-dir-size", G_OBJECT (combo), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, - transform_dirsize_string_to_enum, - transform_dirsize_enum_to_string, + transform_dirsize_enum_to_index, + transform_dirsize_index_to_enum, NULL, NULL); gtk_widget_set_hexpand (combo, TRUE); @@ -665,20 +665,31 @@ thunar_column_editor_use_defaults (ThunarColumnEditor *column_editor, static gboolean -transform_dirsize_enum_to_string (GBinding *binding, - const GValue *src_value, - GValue *dst_value, - gpointer user_data) +transform_dirsize_enum_to_index (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data) { - GEnumClass *enum_class; - GEnumValue *enum_value; - gint val; - - val = g_value_get_int (src_value); - enum_class = g_type_class_ref (THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE); - enum_value = g_enum_get_value (enum_class, val); - - g_value_set_static_string (dst_value, enum_value->value_nick); + gint val; + + val = g_value_get_enum (src_value); + + switch (val) + { + case THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER: + g_value_set_int (dst_value, 0); + break; + case THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL: + g_value_set_int (dst_value, 1); + break; + case THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS: + g_value_set_int (dst_value, 2); + break; + + default: + g_warning ("Invalid value for directory size display prefernce option."); + return FALSE; + } return TRUE; } @@ -686,22 +697,27 @@ transform_dirsize_enum_to_string (GBinding *binding, static gboolean -transform_dirsize_string_to_enum (GBinding *binding, - const GValue *src_value, - GValue *dst_value, - gpointer user_data) +transform_dirsize_index_to_enum (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data) { - GEnumClass *enum_class; - GEnumValue *enum_value; - char *nick; - gint val; - - nick = g_value_get_string (src_value); - enum_class = g_type_class_ref (THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE); - enum_value = g_enum_get_value_by_nick (enum_class, nick); - - val = g_value_get_enum (enum_value); - g_value_set_enum (dst_value, val); + switch (g_value_get_int (src_value)) + { + case 0: + g_value_set_enum (dst_value, THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER); + break; + case 1: + g_value_set_enum (dst_value, THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL); + break; + case 2: + g_value_set_enum (dst_value, THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS); + break; + + default: + g_warning ("Invalid value for directory size display prefernce option."); + return FALSE; + } return TRUE; } -- GitLab From 4a68dbfcc749123d0d856624b751d7cad353a79e Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Mon, 3 Oct 2022 16:42:48 +0530 Subject: [PATCH 10/40] Add working option for dir size column The preference option is reflected in the size column's results now --- thunar/thunar-folder.c | 12 ++++++++++-- thunar/thunar-folder.h | 3 ++- thunar/thunar-list-model.c | 18 +++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index bb785a747..5e9dcfc31 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -968,6 +968,7 @@ thunar_folder_get_files (const ThunarFolder *folder) /** * thunar_folder_get_file_count: * @file : a #ThunarFolder instance. + * @only_local_files: a gboolean stating whether only local files should be counted or remote ones as well * * Returns the number of items in the directory * Counts the number of files in the directory as fast as possible. @@ -976,14 +977,22 @@ thunar_folder_get_files (const ThunarFolder *folder) * Return value: Number of files in a folder **/ guint32 -thunar_folder_get_file_count (ThunarFolder *folder) +thunar_folder_get_file_count (ThunarFolder *folder, + gboolean only_local_files) { ThunarFile *file; GFileEnumerator *enumerator; GFileInfo *child_info; + gboolean is_local; _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); + file = thunar_folder_get_corresponding_file (folder); + is_local = thunar_g_file_is_on_local_device (thunar_file_get_file (file)); + + if (only_local_files && !is_local) + return 0; + /* If we already have a cached value, just return it */ if (G_LIKELY (folder->file_count_is_cached)) return folder->file_count; @@ -997,7 +1006,6 @@ thunar_folder_get_file_count (ThunarFolder *folder) } /* As fallback we will go through the list of gfiles */ - file = thunar_folder_get_corresponding_file (folder); enumerator = g_file_enumerate_children (thunar_file_get_file (file), NULL, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); diff --git a/thunar/thunar-folder.h b/thunar/thunar-folder.h index 2f050b1a4..2bfbaef32 100644 --- a/thunar/thunar-folder.h +++ b/thunar/thunar-folder.h @@ -40,7 +40,8 @@ ThunarFolder *thunar_folder_get_for_file (ThunarFile *file); ThunarFile *thunar_folder_get_corresponding_file (const ThunarFolder *folder); GList *thunar_folder_get_files (const ThunarFolder *folder); -guint32 thunar_folder_get_file_count (ThunarFolder *folder); +guint32 thunar_folder_get_file_count (ThunarFolder *folder, + gboolean only_local_files); gboolean thunar_folder_get_loading (const ThunarFolder *folder); gboolean thunar_folder_has_folder_monitor (const ThunarFolder *folder); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 847ae1ecd..a7b752031 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -959,7 +959,19 @@ thunar_list_model_get_value (GtkTreeModel *model, g_value_init (value, G_TYPE_STRING); if ( (THUNAR_LIST_MODEL (model)->items_count_as_dir_size != THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) && thunar_file_is_directory (file) ) { - item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file)); + gboolean only_local_files; + + if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL) + only_local_files = TRUE; + else if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS) + only_local_files = FALSE; + else + { + g_warning ("Error, unknown enum value for items_count_as_dir_size in the list model"); + break; + } + + item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), only_local_files); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } else @@ -1891,8 +1903,8 @@ sort_by_size_and_items_count (ThunarFile *a, if (thunar_file_is_directory(a) && thunar_file_is_directory(b)) { - count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a)); - count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b)); + count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a), TRUE); + count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b), TRUE); if (count_a < count_b) return -1; -- GitLab From e66f1166cb98fedb4ea8922834f1bd1926dd9771 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 4 Oct 2022 16:52:48 +0530 Subject: [PATCH 11/40] Fix the size column showing 0 items in some cases Size column earlier showed 0 items for remote locations if file counting for size column was switched on only for local files. This commit fixes that so it shows the binary file size reported instead. --- thunar/thunar-folder.c | 13 +++---------- thunar/thunar-folder.h | 3 +-- thunar/thunar-list-model.c | 36 ++++++++++++++++++++++++------------ 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index 5e9dcfc31..ff3e76378 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -968,7 +968,6 @@ thunar_folder_get_files (const ThunarFolder *folder) /** * thunar_folder_get_file_count: * @file : a #ThunarFolder instance. - * @only_local_files: a gboolean stating whether only local files should be counted or remote ones as well * * Returns the number of items in the directory * Counts the number of files in the directory as fast as possible. @@ -977,22 +976,14 @@ thunar_folder_get_files (const ThunarFolder *folder) * Return value: Number of files in a folder **/ guint32 -thunar_folder_get_file_count (ThunarFolder *folder, - gboolean only_local_files) +thunar_folder_get_file_count (ThunarFolder *folder) { ThunarFile *file; GFileEnumerator *enumerator; GFileInfo *child_info; - gboolean is_local; _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); - file = thunar_folder_get_corresponding_file (folder); - is_local = thunar_g_file_is_on_local_device (thunar_file_get_file (file)); - - if (only_local_files && !is_local) - return 0; - /* If we already have a cached value, just return it */ if (G_LIKELY (folder->file_count_is_cached)) return folder->file_count; @@ -1006,9 +997,11 @@ thunar_folder_get_file_count (ThunarFolder *folder, } /* As fallback we will go through the list of gfiles */ + file = thunar_folder_get_corresponding_file (folder); enumerator = g_file_enumerate_children (thunar_file_get_file (file), NULL, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); + if(!enumerator) return 0; diff --git a/thunar/thunar-folder.h b/thunar/thunar-folder.h index 2bfbaef32..2f050b1a4 100644 --- a/thunar/thunar-folder.h +++ b/thunar/thunar-folder.h @@ -40,8 +40,7 @@ ThunarFolder *thunar_folder_get_for_file (ThunarFile *file); ThunarFile *thunar_folder_get_corresponding_file (const ThunarFolder *folder); GList *thunar_folder_get_files (const ThunarFolder *folder); -guint32 thunar_folder_get_file_count (ThunarFolder *folder, - gboolean only_local_files); +guint32 thunar_folder_get_file_count (ThunarFolder *folder); gboolean thunar_folder_get_loading (const ThunarFolder *folder); gboolean thunar_folder_has_folder_monitor (const ThunarFolder *folder); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index a7b752031..d12945f1d 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -957,22 +957,34 @@ thunar_list_model_get_value (GtkTreeModel *model, case THUNAR_COLUMN_SIZE: g_value_init (value, G_TYPE_STRING); - if ( (THUNAR_LIST_MODEL (model)->items_count_as_dir_size != THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) && thunar_file_is_directory (file) ) + + if (thunar_file_is_directory (file)) { - gboolean only_local_files; + /* If the option is set to never show folder sizes as item counts, then just give the folder's binary size */ + if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) + g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); - if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL) - only_local_files = TRUE; + /* If the option is set to always show folder sizes as item counts, then give the folder's item count */ else if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS) - only_local_files = FALSE; - else { - g_warning ("Error, unknown enum value for items_count_as_dir_size in the list model"); - break; + item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file)); + g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } - item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), only_local_files); - g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); + /* If the option is set to always show folder sizes as item counts only for local files, + * check if the files is local or not, and act accordingly */ + else if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL) + { + if (thunar_file_is_local (file)) + { + item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file)); + g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); + } + else + g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); + } + else + g_warning ("Error, unknown enum value for items_count_as_dir_size in the list model"); } else g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); @@ -1903,8 +1915,8 @@ sort_by_size_and_items_count (ThunarFile *a, if (thunar_file_is_directory(a) && thunar_file_is_directory(b)) { - count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a), TRUE); - count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b), TRUE); + count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a)); + count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b)); if (count_a < count_b) return -1; -- GitLab From 8519cbb58aee8811e0b56ebfc69ca7b1d80eac6c Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 4 Oct 2022 18:15:22 +0530 Subject: [PATCH 12/40] Switch to 'for' loop to compute file count from enumerator --- thunar/thunar-folder.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index ff3e76378..e8022fbf2 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -1006,13 +1006,16 @@ thunar_folder_get_file_count (ThunarFolder *folder) return 0; folder->file_count = 0; - child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); - while (child_info) + + /* count through the files given by the enumerator */ + for (child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); + child_info != NULL; + child_info = g_file_enumerator_next_file (enumerator, NULL, NULL)) { ++(folder->file_count); g_object_unref (child_info); - child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); } + g_file_enumerator_close (enumerator, NULL, NULL); g_object_unref (enumerator); -- GitLab From 1c14daa2be7feea4b0ec9669dfd9c1e2314544da Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 4 Oct 2022 18:22:44 +0530 Subject: [PATCH 13/40] Fix formatting --- thunar/thunar-list-model.c | 62 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index d12945f1d..a7a519d39 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -249,46 +249,46 @@ struct _ThunarListModel * generated by another model. */ #ifndef NDEBUG - gint stamp; + gint stamp; #endif - GSequence *rows; - GSList *hidden; - ThunarFolder *folder; - gboolean show_hidden : 1; - ThunarItemsAsFolderSize items_count_as_dir_size; - gboolean file_size_binary : 1; - ThunarDateStyle date_style; - char *date_custom_style; + GSequence *rows; + GSList *hidden; + ThunarFolder *folder; + gboolean show_hidden : 1; + ThunarItemsAsFolderSize items_count_as_dir_size; + gboolean file_size_binary : 1; + ThunarDateStyle date_style; + char *date_custom_style; /* Use the shared ThunarFileMonitor instance, so we * do not need to connect "changed" handler to every * file in the model. */ - ThunarFileMonitor *file_monitor; + ThunarFileMonitor *file_monitor; /* ids for the "row-inserted" and "row-deleted" signals * of GtkTreeModel to speed up folder changing. */ - guint row_inserted_id; - guint row_deleted_id; + guint row_inserted_id; + guint row_deleted_id; - gboolean sort_case_sensitive : 1; - gboolean sort_folders_first : 1; - gint sort_sign; /* 1 = ascending, -1 descending */ - ThunarSortFunc sort_func; + gboolean sort_case_sensitive : 1; + gboolean sort_folders_first : 1; + gint sort_sign; /* 1 = ascending, -1 descending */ + ThunarSortFunc sort_func; /* searching runs in a separate thread which incrementally inserts results (files) * in the files_to_add list. * Periodically the main thread takes all the files in the files_to_add list * and adds them in the model. The list is then emptied. */ - ThunarJob *recursive_search_job; - GList *files_to_add; - GMutex mutex_files_to_add; + ThunarJob *recursive_search_job; + GList *files_to_add; + GMutex mutex_files_to_add; /* used to stop the periodic call to add_search_files when the search is finished/canceled */ - guint update_search_results_timeout_id; + guint update_search_results_timeout_id; }; @@ -803,16 +803,16 @@ thunar_list_model_get_value (GtkTreeModel *model, gint column, GValue *value) { - ThunarGroup *group; - const gchar *device_type; - const gchar *name; - const gchar *real_name; - ThunarUser *user; - ThunarFile *file; + ThunarGroup *group; + const gchar *device_type; + const gchar *name; + const gchar *real_name; + ThunarUser *user; + ThunarFile *file; ThunarFolder *folder; - gchar *str; - guint32 item_count; - GFile *g_file_parent; + gchar *str; + guint32 item_count; + GFile *g_file_parent; _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (model)); _thunar_return_if_fail (iter->stamp == (THUNAR_LIST_MODEL (model))->stamp); @@ -987,7 +987,9 @@ thunar_list_model_get_value (GtkTreeModel *model, g_warning ("Error, unknown enum value for items_count_as_dir_size in the list model"); } else - g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); + { + g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); + } break; case THUNAR_COLUMN_SIZE_IN_BYTES: -- GitLab From 0898d3572f3812585a212f214cb33db37c9f8e05 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Thu, 6 Oct 2022 06:57:48 +0530 Subject: [PATCH 14/40] Switch to timestamp based caching mechanism for file counts --- thunar/thunar-folder.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index e8022fbf2..7f8876b57 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -114,7 +114,7 @@ struct _ThunarFolder gboolean reload_info; guint32 file_count; - gboolean file_count_is_cached; + guint64 file_count_timestamp; GList *content_type_ptr; guint content_type_idle_id; @@ -981,18 +981,23 @@ thunar_folder_get_file_count (ThunarFolder *folder) ThunarFile *file; GFileEnumerator *enumerator; GFileInfo *child_info; + guint64 last_modified; _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); - /* If we already have a cached value, just return it */ - if (G_LIKELY (folder->file_count_is_cached)) + last_modified = thunar_file_get_date (thunar_folder_get_corresponding_file (folder), THUNAR_FILE_DATE_MODIFIED); + + /* return a cached value if last time that the file count was computed is later + * than the last time the file was modified */ + if (G_LIKELY (last_modified < folder->file_count_timestamp)) return folder->file_count; /* If the content type loader already loaded the file-list, just count it*/ if (folder->files != NULL) { folder->file_count = g_list_length (folder->files); - folder->file_count_is_cached = TRUE; + /* dividing by 1e6 to convert microseconds to seconds */ + folder->file_count_timestamp = g_get_real_time () / (guint64) 1e6; return folder->file_count; } @@ -1019,7 +1024,7 @@ thunar_folder_get_file_count (ThunarFolder *folder) g_file_enumerator_close (enumerator, NULL, NULL); g_object_unref (enumerator); - folder->file_count_is_cached = TRUE; + folder->file_count_timestamp = g_get_real_time () / (guint64) 1e6; return folder->file_count; } @@ -1075,7 +1080,7 @@ thunar_folder_reload (ThunarFolder *folder, _thunar_return_if_fail (THUNAR_IS_FOLDER (folder)); folder->file_count = 0; - folder->file_count_is_cached = FALSE; + folder->file_count_timestamp = 0; /* reload file info too? */ folder->reload_info = reload_info; -- GitLab From abe52bbd5952cbc78fc9cae72f4df7a6e57d436e Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Thu, 6 Oct 2022 07:21:29 +0530 Subject: [PATCH 15/40] Move file enumeration and counting to ThunarJob in seperate thread --- thunar/thunar-folder.c | 70 ++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index 7f8876b57..040c35df1 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -30,6 +30,7 @@ #include #include #include +#include #define DEBUG_FILE_CHANGES FALSE @@ -85,6 +86,9 @@ static void thunar_folder_monitor (GFileMonitor GFile *other_file, GFileMonitorEvent event_type, gpointer user_data); +static gboolean thunar_folder_get_file_count_in_job (ThunarJob *job, + GArray *param_values, + GError **error); @@ -978,10 +982,8 @@ thunar_folder_get_files (const ThunarFolder *folder) guint32 thunar_folder_get_file_count (ThunarFolder *folder) { - ThunarFile *file; - GFileEnumerator *enumerator; - GFileInfo *child_info; guint64 last_modified; + ThunarJob *job; _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); @@ -1001,31 +1003,65 @@ thunar_folder_get_file_count (ThunarFolder *folder) return folder->file_count; } - /* As fallback we will go through the list of gfiles */ + /* Set up a job to actually enumerate over the folder's contents and get its file count */ + job = thunar_simple_job_new (thunar_folder_get_file_count_in_job, 1, + THUNAR_TYPE_FOLDER, folder); + + /* set up the signal on finish to update the row model and ask for redraw + * TODO Add the callback */ + /* g_signal_connect (job, "finished", G_CALLBACK (), NULL); */ + exo_job_launch (EXO_JOB (job)); + + return folder->file_count; +} + + + +static gboolean +thunar_folder_get_file_count_in_job (ThunarJob *job, + GArray *param_values, + GError **error) +{ + GError *err = NULL; + ThunarFolder *folder; + ThunarFile *file; + GFileEnumerator *enumerator; + + _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE); + _thunar_return_val_if_fail (param_values != NULL, FALSE); + _thunar_return_val_if_fail (param_values->len == 1, FALSE); + _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + folder = THUNAR_FOLDER (g_value_get_object (&g_array_index (param_values, GValue, 0))); file = thunar_folder_get_corresponding_file (folder); + enumerator = g_file_enumerate_children (thunar_file_get_file (file), NULL, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, NULL); + NULL, &err); - if(!enumerator) - return 0; + if (err != NULL) + { + g_propagate_error (error, err); + return FALSE; + } folder->file_count = 0; - - /* count through the files given by the enumerator */ - for (child_info = g_file_enumerator_next_file (enumerator, NULL, NULL); + for (GFileInfo *child_info = g_file_enumerator_next_file (enumerator, NULL, &err); child_info != NULL; - child_info = g_file_enumerator_next_file (enumerator, NULL, NULL)) + child_info = g_file_enumerator_next_file (enumerator, NULL, &err)) { - ++(folder->file_count); + if (err != NULL) + { + g_propagate_error (error, err); + return FALSE; + } + + (folder->file_count)++; g_object_unref (child_info); } - g_file_enumerator_close (enumerator, NULL, NULL); - g_object_unref (enumerator); - - folder->file_count_timestamp = g_get_real_time () / (guint64) 1e6; - return folder->file_count; + folder->file_count_timestamp = g_get_real_time () / (guint64) 1e6; + return TRUE; } -- GitLab From c45ff6845c3ef22c4da588f7efb112031cb42bc3 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Thu, 6 Oct 2022 07:46:46 +0530 Subject: [PATCH 16/40] Add proper updation after asynchronous count --- thunar/thunar-folder.c | 52 ++++++++++++++++++++++++++++++++++---- thunar/thunar-folder.h | 4 ++- thunar/thunar-list-model.c | 8 +++--- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index 040c35df1..b397e02bd 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -89,6 +89,8 @@ static void thunar_folder_monitor (GFileMonitor static gboolean thunar_folder_get_file_count_in_job (ThunarJob *job, GArray *param_values, GError **error); +static void thunar_folder_file_count_callback (ExoJob *job, + gpointer user_data); @@ -130,6 +132,12 @@ struct _ThunarFolder GFileMonitor *monitor; }; +typedef struct { + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter *iter; +} EnumerateChildrenUserData; + static guint folder_signals[LAST_SIGNAL]; @@ -972,29 +980,41 @@ thunar_folder_get_files (const ThunarFolder *folder) /** * thunar_folder_get_file_count: * @file : a #ThunarFolder instance. + * @model: a #GtkTreeModel + * @iter: a #GtkTreeIter * * Returns the number of items in the directory * Counts the number of files in the directory as fast as possible. * Will use cached data to do calculations only once + * The @model and @iter are needed to force the redraw once the file count + * values are actually calculated. * * Return value: Number of files in a folder **/ guint32 -thunar_folder_get_file_count (ThunarFolder *folder) +thunar_folder_get_file_count (ThunarFolder *folder, + GtkTreeModel *model, + GtkTreeIter *iter) { - guint64 last_modified; - ThunarJob *job; + guint64 last_modified; + ThunarJob *job; + GtkTreePath *path; + EnumerateChildrenUserData *data; _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); last_modified = thunar_file_get_date (thunar_folder_get_corresponding_file (folder), THUNAR_FILE_DATE_MODIFIED); + /* This will only happen if it is called by the sorting function, so just return cached values to it */ + if (model == NULL && iter == NULL) + return folder->file_count; + /* return a cached value if last time that the file count was computed is later * than the last time the file was modified */ if (G_LIKELY (last_modified < folder->file_count_timestamp)) return folder->file_count; - /* If the content type loader already loaded the file-list, just count it*/ + /* If the content type loader already loaded the file-list, just count it */ if (folder->files != NULL) { folder->file_count = g_list_length (folder->files); @@ -1003,13 +1023,22 @@ thunar_folder_get_file_count (ThunarFolder *folder) return folder->file_count; } + /* Set up a job to actually enumerate over the folder's contents and get its file count */ job = thunar_simple_job_new (thunar_folder_get_file_count_in_job, 1, THUNAR_TYPE_FOLDER, folder); + /* set up the user data to pass to the callback once file counting is done */ + path = gtk_tree_model_get_path (model, iter); + data = g_malloc (sizeof (EnumerateChildrenUserData)); + + data->model = model; + data->path = path; + data->iter = iter; + /* set up the signal on finish to update the row model and ask for redraw * TODO Add the callback */ - /* g_signal_connect (job, "finished", G_CALLBACK (), NULL); */ + g_signal_connect (job, "finished", G_CALLBACK (thunar_folder_file_count_callback), data); exo_job_launch (EXO_JOB (job)); return folder->file_count; @@ -1066,6 +1095,19 @@ thunar_folder_get_file_count_in_job (ThunarJob *job, +static void +thunar_folder_file_count_callback (ExoJob *job, + gpointer user_data) +{ + EnumerateChildrenUserData data; + + data = *(EnumerateChildrenUserData *) user_data; + + gtk_tree_model_row_changed (data.model, data.path, data.iter); +} + + + /** * thunar_folder_get_loading: * @folder : a #ThunarFolder instance. diff --git a/thunar/thunar-folder.h b/thunar/thunar-folder.h index 2f050b1a4..427df9c8c 100644 --- a/thunar/thunar-folder.h +++ b/thunar/thunar-folder.h @@ -40,7 +40,9 @@ ThunarFolder *thunar_folder_get_for_file (ThunarFile *file); ThunarFile *thunar_folder_get_corresponding_file (const ThunarFolder *folder); GList *thunar_folder_get_files (const ThunarFolder *folder); -guint32 thunar_folder_get_file_count (ThunarFolder *folder); +guint32 thunar_folder_get_file_count (ThunarFolder *folder, + GtkTreeModel *model, + GtkTreeIter *iter); gboolean thunar_folder_get_loading (const ThunarFolder *folder); gboolean thunar_folder_has_folder_monitor (const ThunarFolder *folder); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index a7a519d39..b2bce7304 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -967,7 +967,7 @@ thunar_list_model_get_value (GtkTreeModel *model, /* If the option is set to always show folder sizes as item counts, then give the folder's item count */ else if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS) { - item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file)); + item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), model, iter); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } @@ -977,7 +977,7 @@ thunar_list_model_get_value (GtkTreeModel *model, { if (thunar_file_is_local (file)) { - item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file)); + item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), model, iter); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } else @@ -1917,8 +1917,8 @@ sort_by_size_and_items_count (ThunarFile *a, if (thunar_file_is_directory(a) && thunar_file_is_directory(b)) { - count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a)); - count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b)); + count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a), NULL, NULL); + count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b), NULL, NULL); if (count_a < count_b) return -1; -- GitLab From 364d7ddfdb6b33b420470d5c6144147aaf9b5a54 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Sat, 8 Oct 2022 10:05:45 +0530 Subject: [PATCH 17/40] Prevent creation of multiple count jobs for same folder --- thunar/thunar-folder.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index b397e02bd..a14e0acda 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -1014,15 +1014,10 @@ thunar_folder_get_file_count (ThunarFolder *folder, if (G_LIKELY (last_modified < folder->file_count_timestamp)) return folder->file_count; - /* If the content type loader already loaded the file-list, just count it */ - if (folder->files != NULL) - { - folder->file_count = g_list_length (folder->files); - /* dividing by 1e6 to convert microseconds to seconds */ - folder->file_count_timestamp = g_get_real_time () / (guint64) 1e6; - return folder->file_count; - } - + /* put the timestamp calculation at the *start* of the process to prevent another call to + * thunar_folder_get_file_count starting another job on the same folder before one has ended. + * Divide by 1e6 to convert from microseconds to seconds */ + folder->file_count_timestamp = g_get_real_time () / (guint64) 1e6; /* Set up a job to actually enumerate over the folder's contents and get its file count */ job = thunar_simple_job_new (thunar_folder_get_file_count_in_job, 1, @@ -1062,8 +1057,15 @@ thunar_folder_get_file_count_in_job (ThunarJob *job, _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE); folder = THUNAR_FOLDER (g_value_get_object (&g_array_index (param_values, GValue, 0))); - file = thunar_folder_get_corresponding_file (folder); + /* If the content type loader already loaded the file-list, just count it */ + if (folder->files != NULL) + { + folder->file_count = g_list_length (folder->files); + return TRUE; + } + + file = thunar_folder_get_corresponding_file (folder); enumerator = g_file_enumerate_children (thunar_file_get_file (file), NULL, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &err); @@ -1089,7 +1091,6 @@ thunar_folder_get_file_count_in_job (ThunarJob *job, g_object_unref (child_info); } - folder->file_count_timestamp = g_get_real_time () / (guint64) 1e6; return TRUE; } -- GitLab From cc8ccf5c26c2f6c80c8dff4744993e136600948c Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Wed, 12 Oct 2022 04:23:56 +0530 Subject: [PATCH 18/40] Fix redraw callback --- thunar/thunar-folder.c | 40 +++++++++----------------------------- thunar/thunar-folder.h | 3 +-- thunar/thunar-list-model.c | 8 ++++---- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index a14e0acda..8bd292135 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -132,12 +132,6 @@ struct _ThunarFolder GFileMonitor *monitor; }; -typedef struct { - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeIter *iter; -} EnumerateChildrenUserData; - static guint folder_signals[LAST_SIGNAL]; @@ -980,33 +974,30 @@ thunar_folder_get_files (const ThunarFolder *folder) /** * thunar_folder_get_file_count: * @file : a #ThunarFolder instance. - * @model: a #GtkTreeModel - * @iter: a #GtkTreeIter + * @model: a #GtkTreeModel or %NULL * * Returns the number of items in the directory * Counts the number of files in the directory as fast as possible. * Will use cached data to do calculations only once - * The @model and @iter are needed to force the redraw once the file count + * The @model is needed to force the redraw once the file count * values are actually calculated. + * Cached values aree returned if @model is NULL. * * Return value: Number of files in a folder **/ guint32 thunar_folder_get_file_count (ThunarFolder *folder, - GtkTreeModel *model, - GtkTreeIter *iter) + GtkTreeModel *model) { guint64 last_modified; ThunarJob *job; - GtkTreePath *path; - EnumerateChildrenUserData *data; _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); last_modified = thunar_file_get_date (thunar_folder_get_corresponding_file (folder), THUNAR_FILE_DATE_MODIFIED); /* This will only happen if it is called by the sorting function, so just return cached values to it */ - if (model == NULL && iter == NULL) + if (model == NULL) return folder->file_count; /* return a cached value if last time that the file count was computed is later @@ -1023,17 +1014,8 @@ thunar_folder_get_file_count (ThunarFolder *folder, job = thunar_simple_job_new (thunar_folder_get_file_count_in_job, 1, THUNAR_TYPE_FOLDER, folder); - /* set up the user data to pass to the callback once file counting is done */ - path = gtk_tree_model_get_path (model, iter); - data = g_malloc (sizeof (EnumerateChildrenUserData)); - - data->model = model; - data->path = path; - data->iter = iter; - - /* set up the signal on finish to update the row model and ask for redraw - * TODO Add the callback */ - g_signal_connect (job, "finished", G_CALLBACK (thunar_folder_file_count_callback), data); + /* set up the signal on finish to update the row model and ask for redraw */ + g_signal_connect (job, "finished", G_CALLBACK (thunar_folder_file_count_callback), model); exo_job_launch (EXO_JOB (job)); return folder->file_count; @@ -1098,13 +1080,9 @@ thunar_folder_get_file_count_in_job (ThunarJob *job, static void thunar_folder_file_count_callback (ExoJob *job, - gpointer user_data) + gpointer model) { - EnumerateChildrenUserData data; - - data = *(EnumerateChildrenUserData *) user_data; - - gtk_tree_model_row_changed (data.model, data.path, data.iter); + gtk_tree_model_foreach (GTK_TREE_MODEL (model), (GtkTreeModelForeachFunc) gtk_tree_model_row_changed, NULL); } diff --git a/thunar/thunar-folder.h b/thunar/thunar-folder.h index 427df9c8c..1b8cb7b9c 100644 --- a/thunar/thunar-folder.h +++ b/thunar/thunar-folder.h @@ -41,8 +41,7 @@ ThunarFolder *thunar_folder_get_for_file (ThunarFile *file); ThunarFile *thunar_folder_get_corresponding_file (const ThunarFolder *folder); GList *thunar_folder_get_files (const ThunarFolder *folder); guint32 thunar_folder_get_file_count (ThunarFolder *folder, - GtkTreeModel *model, - GtkTreeIter *iter); + GtkTreeModel *model); gboolean thunar_folder_get_loading (const ThunarFolder *folder); gboolean thunar_folder_has_folder_monitor (const ThunarFolder *folder); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index b2bce7304..c9eb53041 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -967,7 +967,7 @@ thunar_list_model_get_value (GtkTreeModel *model, /* If the option is set to always show folder sizes as item counts, then give the folder's item count */ else if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS) { - item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), model, iter); + item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), model); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } @@ -977,7 +977,7 @@ thunar_list_model_get_value (GtkTreeModel *model, { if (thunar_file_is_local (file)) { - item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), model, iter); + item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), model); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } else @@ -1917,8 +1917,8 @@ sort_by_size_and_items_count (ThunarFile *a, if (thunar_file_is_directory(a) && thunar_file_is_directory(b)) { - count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a), NULL, NULL); - count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b), NULL, NULL); + count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a), NULL); + count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b), NULL); if (count_a < count_b) return -1; -- GitLab From 487abe2d9793ab5dee173ee002eb7c653d5f9ab8 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Sat, 15 Oct 2022 01:01:43 +0530 Subject: [PATCH 19/40] Fix issue with folder size counts being stale --- thunar/thunar-folder.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index 8bd292135..54ded8e9a 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -981,7 +981,7 @@ thunar_folder_get_files (const ThunarFolder *folder) * Will use cached data to do calculations only once * The @model is needed to force the redraw once the file count * values are actually calculated. - * Cached values aree returned if @model is NULL. + * Cached values are returned if @model is NULL. * * Return value: Number of files in a folder **/ @@ -989,17 +989,35 @@ guint32 thunar_folder_get_file_count (ThunarFolder *folder, GtkTreeModel *model) { - guint64 last_modified; + GError *err = NULL; ThunarJob *job; + GFileInfo *info; + ThunarFile *file; + guint64 last_modified; _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); - last_modified = thunar_file_get_date (thunar_folder_get_corresponding_file (folder), THUNAR_FILE_DATE_MODIFIED); - /* This will only happen if it is called by the sorting function, so just return cached values to it */ if (model == NULL) return folder->file_count; + /* We need to make a new query so we don't get stale values */ + file = thunar_folder_get_corresponding_file (folder); + info = g_file_query_info (thunar_file_get_file (file), + G_FILE_ATTRIBUTE_TIME_MODIFIED, + G_FILE_QUERY_INFO_NONE, + NULL, + &err); + + if (err != NULL) + { + g_warning ("An error occured while trying to get file counts."); + return folder->file_count; + } + + last_modified = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); + g_object_unref (info); + /* return a cached value if last time that the file count was computed is later * than the last time the file was modified */ if (G_LIKELY (last_modified < folder->file_count_timestamp)) -- GitLab From 01db4ae89c2302d5228bd742bbcad820323c3f00 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 18 Oct 2022 12:08:00 +0530 Subject: [PATCH 20/40] Add property for file count to `ThunarFolder` --- thunar/thunar-folder.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index 54ded8e9a..eed9bd474 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -42,6 +42,7 @@ enum PROP_0, PROP_CORRESPONDING_FILE, PROP_LOADING, + PROP_FILE_COUNT, }; /* signal identifiers */ @@ -207,6 +208,21 @@ thunar_folder_class_init (ThunarFolderClass *klass) "loading", FALSE, EXO_PARAM_READABLE)); + + /** ThunarFolder::file-count: + * + * The number of files in the #ThunarFolder + **/ + g_object_class_install_property (gobject_class, + PROP_FILE_COUNT, + g_param_spec_uint ("file-count", + "file-count", + "file-count", + 0, + G_MAXUINT32, + 0, + EXO_PARAM_READWRITE)); + /** * ThunarFolder::destroy: * @folder : a #ThunarFolder. @@ -374,6 +390,10 @@ thunar_folder_get_property (GObject *object, g_value_set_boolean (value, thunar_folder_get_loading (folder)); break; + case PROP_FILE_COUNT: + g_value_set_uint (value, folder->file_count); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -402,6 +422,10 @@ thunar_folder_set_property (GObject *object, _thunar_assert_not_reached (); break; + case PROP_FILE_COUNT: + folder->file_count = g_value_get_uint (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; -- GitLab From 68bdded271170d764c5b85cfdb29d311d5b69984 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 18 Oct 2022 12:11:26 +0530 Subject: [PATCH 21/40] Move file counting job to `thunar-io-jobs` --- thunar/thunar-folder.c | 61 +--------------------------------- thunar/thunar-io-jobs.c | 73 +++++++++++++++++++++++++++++++++++++++-- thunar/thunar-io-jobs.h | 47 +++++++++++++------------- 3 files changed, 96 insertions(+), 85 deletions(-) diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index eed9bd474..3175c0fda 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -87,9 +87,6 @@ static void thunar_folder_monitor (GFileMonitor GFile *other_file, GFileMonitorEvent event_type, gpointer user_data); -static gboolean thunar_folder_get_file_count_in_job (ThunarJob *job, - GArray *param_values, - GError **error); static void thunar_folder_file_count_callback (ExoJob *job, gpointer user_data); @@ -1053,8 +1050,7 @@ thunar_folder_get_file_count (ThunarFolder *folder, folder->file_count_timestamp = g_get_real_time () / (guint64) 1e6; /* Set up a job to actually enumerate over the folder's contents and get its file count */ - job = thunar_simple_job_new (thunar_folder_get_file_count_in_job, 1, - THUNAR_TYPE_FOLDER, folder); + job = thunar_io_jobs_count_files (file); /* set up the signal on finish to update the row model and ask for redraw */ g_signal_connect (job, "finished", G_CALLBACK (thunar_folder_file_count_callback), model); @@ -1065,61 +1061,6 @@ thunar_folder_get_file_count (ThunarFolder *folder, -static gboolean -thunar_folder_get_file_count_in_job (ThunarJob *job, - GArray *param_values, - GError **error) -{ - GError *err = NULL; - ThunarFolder *folder; - ThunarFile *file; - GFileEnumerator *enumerator; - - _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE); - _thunar_return_val_if_fail (param_values != NULL, FALSE); - _thunar_return_val_if_fail (param_values->len == 1, FALSE); - _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - folder = THUNAR_FOLDER (g_value_get_object (&g_array_index (param_values, GValue, 0))); - - /* If the content type loader already loaded the file-list, just count it */ - if (folder->files != NULL) - { - folder->file_count = g_list_length (folder->files); - return TRUE; - } - - file = thunar_folder_get_corresponding_file (folder); - enumerator = g_file_enumerate_children (thunar_file_get_file (file), NULL, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, &err); - - if (err != NULL) - { - g_propagate_error (error, err); - return FALSE; - } - - folder->file_count = 0; - for (GFileInfo *child_info = g_file_enumerator_next_file (enumerator, NULL, &err); - child_info != NULL; - child_info = g_file_enumerator_next_file (enumerator, NULL, &err)) - { - if (err != NULL) - { - g_propagate_error (error, err); - return FALSE; - } - - (folder->file_count)++; - g_object_unref (child_info); - } - - return TRUE; -} - - - static void thunar_folder_file_count_callback (ExoJob *job, gpointer model) diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index 7d28833da..b3d2303c9 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -31,10 +31,11 @@ #include #include +#include #include -#include -#include #include +#include +#include #include #include #include @@ -1451,3 +1452,71 @@ thunar_io_jobs_rename_file (ThunarFile *file, G_TYPE_STRING, display_name, THUNAR_TYPE_OPERATION_LOG_MODE, log_mode); } + + + +static gboolean +_thunar_io_jobs_count (ThunarJob *job, + GArray *param_values, + GError **error) +{ + GError *err = NULL; + ThunarFolder *folder; + ThunarFile *file; + GFileEnumerator *enumerator; + guint32 count; + + _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE); + _thunar_return_val_if_fail (param_values != NULL, FALSE); + _thunar_return_val_if_fail (param_values->len == 1, FALSE); + _thunar_return_val_if_fail (G_VALUE_HOLDS (&g_array_index (param_values, GValue, 0), THUNAR_TYPE_FILE), FALSE); + _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + file = THUNAR_FILE (g_value_get_object (&g_array_index (param_values, GValue, 0))); + folder = THUNAR_FOLDER (thunar_folder_get_for_file (file)); + + if (file == NULL || folder == NULL) + return FALSE; + + enumerator = g_file_enumerate_children (thunar_file_get_file (file), NULL, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, &err); + if (err != NULL) + { + g_propagate_error (error, err); + return FALSE; + } + + count = 0; + for (GFileInfo *child_info = g_file_enumerator_next_file (enumerator, NULL, &err); + child_info != NULL; + child_info = g_file_enumerator_next_file (enumerator, NULL, &err)) + { + if (err != NULL) + { + g_propagate_error (error, err); + return FALSE; + } + + count++; + g_object_unref (child_info); + } + + g_object_set (folder, + "file-count", count, + NULL); + + return TRUE; +} + + + +ThunarJob * +thunar_io_jobs_count_files (ThunarFile *file) +{ + _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL); + + return thunar_simple_job_new (_thunar_io_jobs_count, 1, + THUNAR_TYPE_FILE, file); +} + diff --git a/thunar/thunar-io-jobs.h b/thunar/thunar-io-jobs.h index da7955d8d..a377b8c61 100644 --- a/thunar/thunar-io-jobs.h +++ b/thunar/thunar-io-jobs.h @@ -26,32 +26,33 @@ G_BEGIN_DECLS -ThunarJob *thunar_io_jobs_create_files (GList *file_list, - GFile *template_file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_make_directories (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_unlink_files (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_move_files (GList *source_file_list, - GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_copy_files (GList *source_file_list, - GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_link_files (GList *source_file_list, - GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_trash_files (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_restore_files (GList *source_file_list, - GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_change_group (GList *files, - guint32 gid, - gboolean recursive) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_change_mode (GList *files, - ThunarFileMode dir_mask, - ThunarFileMode dir_mode, - ThunarFileMode file_mask, - ThunarFileMode file_mode, - gboolean recursive) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -ThunarJob *thunar_io_jobs_list_directory (GFile *directory) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_create_files (GList *file_list, + GFile *template_file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_make_directories (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_unlink_files (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_move_files (GList *source_file_list, + GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_copy_files (GList *source_file_list, + GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_link_files (GList *source_file_list, + GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_trash_files (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_restore_files (GList *source_file_list, + GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_change_group (GList *files, + guint32 gid, + gboolean recursive) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_change_mode (GList *files, + ThunarFileMode dir_mask, + ThunarFileMode dir_mode, + ThunarFileMode file_mask, + ThunarFileMode file_mode, + gboolean recursive) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_list_directory (GFile *directory) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; ThunarJob *thunar_io_jobs_rename_file (ThunarFile *file, const gchar *display_name, ThunarOperationLogMode log_mode) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +ThunarJob *thunar_io_jobs_count_files (ThunarFile *file); G_END_DECLS -- GitLab From c8e878142bf97a9130604deb649518fbcdf3f2a3 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Wed, 19 Oct 2022 11:35:59 +0530 Subject: [PATCH 22/40] Switch file count struct member to ThunarFile --- thunar/thunar-file.c | 109 +++++++++++++++++++++++++++++++++-- thunar/thunar-file.h | 6 ++ thunar/thunar-folder.c | 114 ------------------------------------- thunar/thunar-folder.h | 2 - thunar/thunar-io-jobs.c | 8 +-- thunar/thunar-list-model.c | 9 +-- 6 files changed, 119 insertions(+), 129 deletions(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index c2d598d9e..e7f763636 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -58,16 +58,17 @@ #include #include -#include +#include #include +#include #include #include -#include +#include +#include #include +#include #include #include -#include -#include @@ -116,6 +117,8 @@ static gboolean thunar_file_load (ThunarFile static gboolean thunar_file_is_readable (const ThunarFile *file); static gboolean thunar_file_same_filesystem (const ThunarFile *file_a, const ThunarFile *file_b); +static void thunar_file_count_callback (ExoJob *job, + gpointer model); @@ -186,6 +189,11 @@ struct _ThunarFile /* tells whether the file watch is not set */ gboolean no_file_watch; + + /* the file count, valid only if the file is a directory */ + guint file_count; + guint64 file_count_timestamp; + }; typedef struct @@ -3485,6 +3493,90 @@ thunar_file_can_be_trashed (const ThunarFile *file) +/** + * thunar_file_get_file_count + * @file : a #ThunarFolder instance. + * @store: a #GtkTreeModel or %NULL + * + * Returns the number of items in the directory + * Counts the number of files in the directory as fast as possible. + * Will use cached data to do calculations only once + * The @store is needed to force the redraw once the file count + * values are actually calculated. + * Cached values are returned if @store is NULL. + * + * Return value: Number of files in a folder + **/ +guint +thunar_file_get_file_count (ThunarFile *file, + GtkTreeModel *store) +{ + GError *err = NULL; + ThunarJob *job; + GFileInfo *info; + guint64 last_modified; + + _thunar_return_val_if_fail (thunar_file_is_directory (file), 0); + + /* Forcefully get cached values by passing NULL as the second argument */ + if (file == NULL) + return file->file_count; + + info = g_file_query_info (thunar_file_get_file (file), + G_FILE_ATTRIBUTE_TIME_MODIFIED, + G_FILE_QUERY_INFO_NONE, + NULL, + &err); + + if (err != NULL) + { + g_warning ("An error occured while trying to get file counts."); + return file->file_count; + } + + last_modified = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); + g_object_unref (info); + + /* return a cached value if last time that the file count was computed is later + * than the last time the file was modified */ + if (G_LIKELY (last_modified < file->file_count_timestamp)) + return file->file_count; + + /* put the timestamp calculation at the *start* of the process to prevent another call to + * thunar_folder_get_file_count starting another job on the same folder before one has ended. + * Divide by 1e6 to convert from microseconds to seconds */ + file->file_count_timestamp = g_get_real_time () / (guint64) 1e6; + + /* set up a job to actually enumerate over the folder's contents and get its file count */ + job = thunar_io_jobs_count_files (file); + + /* set up the signal on finish to update the row model and ask for redraw */ + g_signal_connect (job, "finished", G_CALLBACK (thunar_file_count_callback), store); + exo_job_launch (EXO_JOB (job)); + + return file->file_count; +} + + + +/** + * thunar_file_set_file_count + * @file: A #ThunarFileInstance + * @count: The value to set the file's count to + * + * Set @file's count to the given number if it is a directory. + * Does *NOT* update the file's count timestamp. + **/ +void +thunar_file_set_file_count (ThunarFile *file, + const guint count) +{ + _thunar_return_if_fail (thunar_file_is_directory (file)); + + file->file_count = count; +} + + /** * thunar_file_get_emblem_names: * @file : a #ThunarFile instance. @@ -4468,6 +4560,15 @@ thunar_file_same_filesystem (const ThunarFile *file_a, +static void +thunar_file_count_callback (ExoJob *job, + gpointer model) +{ + gtk_tree_model_foreach (GTK_TREE_MODEL (model), (GtkTreeModelForeachFunc) gtk_tree_model_row_changed, NULL); +} + + + /** * thunar_file_cache_lookup: * @file : a #GFile. diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h index 7e163b16a..cb1d72ab3 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -235,6 +235,12 @@ gboolean thunar_file_is_chmodable (const ThunarFile gboolean thunar_file_is_renameable (const ThunarFile *file); gboolean thunar_file_can_be_trashed (const ThunarFile *file); + +guint thunar_file_get_file_count (ThunarFile *file, + GtkTreeModel *store); +void thunar_file_set_file_count (ThunarFile *file, + const guint count); + GList *thunar_file_get_emblem_names (ThunarFile *file); void thunar_file_set_emblem_names (ThunarFile *file, GList *emblem_names); diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index 3175c0fda..b392ffcfe 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -42,7 +42,6 @@ enum PROP_0, PROP_CORRESPONDING_FILE, PROP_LOADING, - PROP_FILE_COUNT, }; /* signal identifiers */ @@ -87,9 +86,6 @@ static void thunar_folder_monitor (GFileMonitor GFile *other_file, GFileMonitorEvent event_type, gpointer user_data); -static void thunar_folder_file_count_callback (ExoJob *job, - gpointer user_data); - struct _ThunarFolderClass @@ -117,9 +113,6 @@ struct _ThunarFolder GList *files; gboolean reload_info; - guint32 file_count; - guint64 file_count_timestamp; - GList *content_type_ptr; guint content_type_idle_id; @@ -205,21 +198,6 @@ thunar_folder_class_init (ThunarFolderClass *klass) "loading", FALSE, EXO_PARAM_READABLE)); - - /** ThunarFolder::file-count: - * - * The number of files in the #ThunarFolder - **/ - g_object_class_install_property (gobject_class, - PROP_FILE_COUNT, - g_param_spec_uint ("file-count", - "file-count", - "file-count", - 0, - G_MAXUINT32, - 0, - EXO_PARAM_READWRITE)); - /** * ThunarFolder::destroy: * @folder : a #ThunarFolder. @@ -387,10 +365,6 @@ thunar_folder_get_property (GObject *object, g_value_set_boolean (value, thunar_folder_get_loading (folder)); break; - case PROP_FILE_COUNT: - g_value_set_uint (value, folder->file_count); - break; - default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -419,10 +393,6 @@ thunar_folder_set_property (GObject *object, _thunar_assert_not_reached (); break; - case PROP_FILE_COUNT: - folder->file_count = g_value_get_uint (value); - break; - default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -989,87 +959,6 @@ thunar_folder_get_files (const ThunarFolder *folder) _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), NULL); return folder->files; } - - - -/** - * thunar_folder_get_file_count: - * @file : a #ThunarFolder instance. - * @model: a #GtkTreeModel or %NULL - * - * Returns the number of items in the directory - * Counts the number of files in the directory as fast as possible. - * Will use cached data to do calculations only once - * The @model is needed to force the redraw once the file count - * values are actually calculated. - * Cached values are returned if @model is NULL. - * - * Return value: Number of files in a folder - **/ -guint32 -thunar_folder_get_file_count (ThunarFolder *folder, - GtkTreeModel *model) -{ - GError *err = NULL; - ThunarJob *job; - GFileInfo *info; - ThunarFile *file; - guint64 last_modified; - - _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), 0); - - /* This will only happen if it is called by the sorting function, so just return cached values to it */ - if (model == NULL) - return folder->file_count; - - /* We need to make a new query so we don't get stale values */ - file = thunar_folder_get_corresponding_file (folder); - info = g_file_query_info (thunar_file_get_file (file), - G_FILE_ATTRIBUTE_TIME_MODIFIED, - G_FILE_QUERY_INFO_NONE, - NULL, - &err); - - if (err != NULL) - { - g_warning ("An error occured while trying to get file counts."); - return folder->file_count; - } - - last_modified = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); - g_object_unref (info); - - /* return a cached value if last time that the file count was computed is later - * than the last time the file was modified */ - if (G_LIKELY (last_modified < folder->file_count_timestamp)) - return folder->file_count; - - /* put the timestamp calculation at the *start* of the process to prevent another call to - * thunar_folder_get_file_count starting another job on the same folder before one has ended. - * Divide by 1e6 to convert from microseconds to seconds */ - folder->file_count_timestamp = g_get_real_time () / (guint64) 1e6; - - /* Set up a job to actually enumerate over the folder's contents and get its file count */ - job = thunar_io_jobs_count_files (file); - - /* set up the signal on finish to update the row model and ask for redraw */ - g_signal_connect (job, "finished", G_CALLBACK (thunar_folder_file_count_callback), model); - exo_job_launch (EXO_JOB (job)); - - return folder->file_count; -} - - - -static void -thunar_folder_file_count_callback (ExoJob *job, - gpointer model) -{ - gtk_tree_model_foreach (GTK_TREE_MODEL (model), (GtkTreeModelForeachFunc) gtk_tree_model_row_changed, NULL); -} - - - /** * thunar_folder_get_loading: * @folder : a #ThunarFolder instance. @@ -1119,9 +1008,6 @@ thunar_folder_reload (ThunarFolder *folder, { _thunar_return_if_fail (THUNAR_IS_FOLDER (folder)); - folder->file_count = 0; - folder->file_count_timestamp = 0; - /* reload file info too? */ folder->reload_info = reload_info; diff --git a/thunar/thunar-folder.h b/thunar/thunar-folder.h index 1b8cb7b9c..d5c202b6f 100644 --- a/thunar/thunar-folder.h +++ b/thunar/thunar-folder.h @@ -40,8 +40,6 @@ ThunarFolder *thunar_folder_get_for_file (ThunarFile *file); ThunarFile *thunar_folder_get_corresponding_file (const ThunarFolder *folder); GList *thunar_folder_get_files (const ThunarFolder *folder); -guint32 thunar_folder_get_file_count (ThunarFolder *folder, - GtkTreeModel *model); gboolean thunar_folder_get_loading (const ThunarFolder *folder); gboolean thunar_folder_has_folder_monitor (const ThunarFolder *folder); diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index b3d2303c9..b5d46d9b5 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -1464,7 +1464,7 @@ _thunar_io_jobs_count (ThunarJob *job, ThunarFolder *folder; ThunarFile *file; GFileEnumerator *enumerator; - guint32 count; + guint count; _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE); _thunar_return_val_if_fail (param_values != NULL, FALSE); @@ -1502,11 +1502,9 @@ _thunar_io_jobs_count (ThunarJob *job, g_object_unref (child_info); } - g_object_set (folder, - "file-count", count, - NULL); + thunar_file_set_file_count (file, count); - return TRUE; + return TRUE; } diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index c9eb53041..f8e2721a2 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -960,6 +960,7 @@ thunar_list_model_get_value (GtkTreeModel *model, if (thunar_file_is_directory (file)) { + /* TODO refactor as switch case */ /* If the option is set to never show folder sizes as item counts, then just give the folder's binary size */ if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); @@ -967,7 +968,7 @@ thunar_list_model_get_value (GtkTreeModel *model, /* If the option is set to always show folder sizes as item counts, then give the folder's item count */ else if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS) { - item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), model); + item_count = thunar_file_get_file_count (file, model); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } @@ -977,7 +978,7 @@ thunar_list_model_get_value (GtkTreeModel *model, { if (thunar_file_is_local (file)) { - item_count = thunar_folder_get_file_count (thunar_folder_get_for_file (file), model); + item_count = thunar_file_get_file_count (file, model); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } else @@ -1917,8 +1918,8 @@ sort_by_size_and_items_count (ThunarFile *a, if (thunar_file_is_directory(a) && thunar_file_is_directory(b)) { - count_a = thunar_folder_get_file_count (thunar_folder_get_for_file (a), NULL); - count_b = thunar_folder_get_file_count (thunar_folder_get_for_file (b), NULL); + count_a = thunar_file_get_file_count (thunar_folder_get_for_file (a), NULL); + count_b = thunar_file_get_file_count (thunar_folder_get_for_file (b), NULL); if (count_a < count_b) return -1; -- GitLab From b3fea092e747c14fc2cbf02bf699604a2441b82c Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Wed, 19 Oct 2022 16:31:23 +0530 Subject: [PATCH 23/40] Fix bug with lag; Remove `thunar_folder_get_for_file` --- thunar/thunar-io-jobs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index b5d46d9b5..1644757a4 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -1461,7 +1461,6 @@ _thunar_io_jobs_count (ThunarJob *job, GError **error) { GError *err = NULL; - ThunarFolder *folder; ThunarFile *file; GFileEnumerator *enumerator; guint count; @@ -1473,9 +1472,8 @@ _thunar_io_jobs_count (ThunarJob *job, _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE); file = THUNAR_FILE (g_value_get_object (&g_array_index (param_values, GValue, 0))); - folder = THUNAR_FOLDER (thunar_folder_get_for_file (file)); - if (file == NULL || folder == NULL) + if (file == NULL) return FALSE; enumerator = g_file_enumerate_children (thunar_file_get_file (file), NULL, -- GitLab From 2430866c4591af1d3939f4fff38ffd138c9c1ae0 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Wed, 19 Oct 2022 23:24:14 +0530 Subject: [PATCH 24/40] Move `transform_enum_value_to_index` --- thunar/thunar-column-editor.c | 87 +++++------------------------- thunar/thunar-enum-types.c | 39 ++++++++++++++ thunar/thunar-enum-types.h | 11 ++++ thunar/thunar-preferences-dialog.c | 39 -------------- 4 files changed, 63 insertions(+), 113 deletions(-) diff --git a/thunar/thunar-column-editor.c b/thunar/thunar-column-editor.c index 8105e897a..921ebfa77 100644 --- a/thunar/thunar-column-editor.c +++ b/thunar/thunar-column-editor.c @@ -50,14 +50,6 @@ static void thunar_column_editor_toggle_visibility (ThunarColumnEditor *c static void thunar_column_editor_update_buttons (ThunarColumnEditor *column_editor); static void thunar_column_editor_use_defaults (ThunarColumnEditor *column_editor, GtkWidget *button); -static gboolean transform_dirsize_enum_to_index (GBinding *binding, - const GValue *src_value, - GValue *dst_value, - gpointer user_data); -static gboolean transform_dirsize_index_to_enum (GBinding *binding, - const GValue *src_value, - GValue *dst_value, - gpointer user_data); @@ -143,6 +135,7 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) GtkWidget *grid; GtkWidget *vbox; GtkWidget *swin; + GEnumClass *enum_class; gint row = 0; /* grab a reference on the preferences */ @@ -367,16 +360,22 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) gtk_widget_show (label); combo = gtk_combo_box_text_new (); - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Never")); - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Only for local files")); - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Always")); + enum_class = g_type_class_ref (THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE); + + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), + g_enum_get_value (enum_class, THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER)->value_nick); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), + g_enum_get_value (enum_class, THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL)->value_nick); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), + g_enum_get_value (enum_class, THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS)->value_nick); + g_type_class_unref (enum_class); g_object_bind_property_full (G_OBJECT (column_editor->preferences), "misc-items-count-as-dir-size", G_OBJECT (combo), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, - transform_dirsize_enum_to_index, - transform_dirsize_index_to_enum, - NULL, NULL); + transform_enum_value_to_index, + transform_index_to_enum_value, + (gpointer) thunar_items_as_folder_size_get_type, NULL); gtk_widget_set_hexpand (combo, TRUE); gtk_grid_attach (GTK_GRID (grid), combo, 1, row - 1, 1, 1); @@ -664,66 +663,6 @@ thunar_column_editor_use_defaults (ThunarColumnEditor *column_editor, -static gboolean -transform_dirsize_enum_to_index (GBinding *binding, - const GValue *src_value, - GValue *dst_value, - gpointer user_data) -{ - gint val; - - val = g_value_get_enum (src_value); - - switch (val) - { - case THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER: - g_value_set_int (dst_value, 0); - break; - case THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL: - g_value_set_int (dst_value, 1); - break; - case THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS: - g_value_set_int (dst_value, 2); - break; - - default: - g_warning ("Invalid value for directory size display prefernce option."); - return FALSE; - } - - return TRUE; -} - - - -static gboolean -transform_dirsize_index_to_enum (GBinding *binding, - const GValue *src_value, - GValue *dst_value, - gpointer user_data) -{ - switch (g_value_get_int (src_value)) - { - case 0: - g_value_set_enum (dst_value, THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER); - break; - case 1: - g_value_set_enum (dst_value, THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL); - break; - case 2: - g_value_set_enum (dst_value, THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS); - break; - - default: - g_warning ("Invalid value for directory size display prefernce option."); - return FALSE; - } - - return TRUE; -} - - - /** * thunar_show_column_editor: * @parent : the #GtkWidget the #GdkScreen on which to open the diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c index bdc658fc0..586c089c9 100644 --- a/thunar/thunar-enum-types.c +++ b/thunar/thunar-enum-types.c @@ -37,6 +37,45 @@ static ThunarThumbnailSize thunar_icon_size_to_thumbnail_size (ThunarIconSize +gboolean +transform_enum_value_to_index (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data) +{ + GEnumClass *klass; + GType (*type_func)() = user_data; + guint n; + + klass = g_type_class_ref (type_func ()); + for (n = 0; n < klass->n_values; ++n) + if (klass->values[n].value == g_value_get_enum (src_value)) + g_value_set_int (dst_value, n); + g_type_class_unref (klass); + + return TRUE; +} + + + +gboolean +transform_index_to_enum_value (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data) +{ + GEnumClass *klass; + GType (*type_func)() = user_data; + + klass = g_type_class_ref (type_func ()); + g_value_set_enum (dst_value, klass->values[g_value_get_int (src_value)].value); + g_type_class_unref (klass); + + return TRUE; +} + + + GType thunar_renamer_mode_get_type (void) { diff --git a/thunar/thunar-enum-types.h b/thunar/thunar-enum-types.h index e81b05622..d07cfe4be 100644 --- a/thunar/thunar-enum-types.h +++ b/thunar/thunar-enum-types.h @@ -25,6 +25,17 @@ G_BEGIN_DECLS; + +gboolean transform_enum_value_to_index (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data); + +gboolean transform_index_to_enum_value (GBinding *binding, + const GValue *src_value, + GValue *dst_value, + gpointer user_data); + #define THUNAR_TYPE_RENAMER_MODE (thunar_renamer_mode_get_type ()) /** diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c index 04ffa239e..05f527235 100644 --- a/thunar/thunar-preferences-dialog.c +++ b/thunar/thunar-preferences-dialog.c @@ -164,45 +164,6 @@ transform_view_index_to_string (GBinding *binding, -static gboolean -transform_enum_value_to_index (GBinding *binding, - const GValue *src_value, - GValue *dst_value, - gpointer user_data) -{ - GEnumClass *klass; - GType (*type_func)() = user_data; - guint n; - - klass = g_type_class_ref (type_func ()); - for (n = 0; n < klass->n_values; ++n) - if (klass->values[n].value == g_value_get_enum (src_value)) - g_value_set_int (dst_value, n); - g_type_class_unref (klass); - - return TRUE; -} - - - -static gboolean -transform_index_to_enum_value (GBinding *binding, - const GValue *src_value, - GValue *dst_value, - gpointer user_data) -{ - GEnumClass *klass; - GType (*type_func)() = user_data; - - klass = g_type_class_ref (type_func ()); - g_value_set_enum (dst_value, klass->values[g_value_get_int (src_value)].value); - g_type_class_unref (klass); - - return TRUE; -} - - - static gboolean transform_string_to_uint64 (GBinding *binding, const GValue *src_value, -- GitLab From fa64ceae328440f7c05d2642892ee17b840e3a98 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Wed, 19 Oct 2022 18:03:07 +0000 Subject: [PATCH 25/40] Minor formatting/style fixes --- thunar/thunar-column-editor.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/thunar/thunar-column-editor.c b/thunar/thunar-column-editor.c index 921ebfa77..6b1e9871e 100644 --- a/thunar/thunar-column-editor.c +++ b/thunar/thunar-column-editor.c @@ -340,7 +340,7 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0); gtk_widget_show (frame); - label = gtk_label_new (_("File size of folders")); + label = gtk_label_new (_("Size Column of Folders")); gtk_label_set_attributes (GTK_LABEL (label), thunar_pango_attr_list_bold ()); gtk_frame_set_label_widget (GTK_FRAME (frame), label); gtk_widget_show (label); @@ -353,8 +353,7 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) gtk_widget_show (grid); /* explain what it does */ - label = gtk_label_new (_("Show the number of items in the 'size' column\n" - "for folders instead of the fixed folder size")); + label = gtk_label_new (_("Show number of containing items")); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); gtk_widget_show (label); -- GitLab From 3b370949efa20e9e5022557371b351313132092d Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Thu, 20 Oct 2022 15:22:54 +0530 Subject: [PATCH 26/40] Rename ThunarItemsAsFolderSize to ThunarFolderItemCount Also rename corresponding enum values, getters, setters, etc. --- thunar/thunar-column-editor.c | 12 +++--- thunar/thunar-enum-types.c | 20 ++++++++++ thunar/thunar-enum-types.h | 22 +++++------ thunar/thunar-list-model.c | 70 +++++++++++++++++------------------ thunar/thunar-preferences.c | 18 ++++----- thunar/thunar-standard-view.c | 2 +- 6 files changed, 82 insertions(+), 62 deletions(-) diff --git a/thunar/thunar-column-editor.c b/thunar/thunar-column-editor.c index 6b1e9871e..e920f507a 100644 --- a/thunar/thunar-column-editor.c +++ b/thunar/thunar-column-editor.c @@ -359,22 +359,22 @@ thunar_column_editor_init (ThunarColumnEditor *column_editor) gtk_widget_show (label); combo = gtk_combo_box_text_new (); - enum_class = g_type_class_ref (THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE); + enum_class = g_type_class_ref (THUNAR_TYPE_FOLDER_ITEM_COUNT); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), - g_enum_get_value (enum_class, THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER)->value_nick); + g_enum_get_value (enum_class, THUNAR_FOLDER_ITEM_COUNT_NEVER)->value_nick); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), - g_enum_get_value (enum_class, THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL)->value_nick); + g_enum_get_value (enum_class, THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL)->value_nick); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), - g_enum_get_value (enum_class, THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS)->value_nick); + g_enum_get_value (enum_class, THUNAR_FOLDER_ITEM_COUNT_ALWAYS)->value_nick); g_type_class_unref (enum_class); - g_object_bind_property_full (G_OBJECT (column_editor->preferences), "misc-items-count-as-dir-size", + g_object_bind_property_full (G_OBJECT (column_editor->preferences), "misc-folder-item-count", G_OBJECT (combo), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, transform_enum_value_to_index, transform_index_to_enum_value, - (gpointer) thunar_items_as_folder_size_get_type, NULL); + (gpointer) thunar_folder_item_count_get_type, NULL); gtk_widget_set_hexpand (combo, TRUE); gtk_grid_attach (GTK_GRID (grid), combo, 1, row - 1, 1, 1); diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c index 586c089c9..16a0af042 100644 --- a/thunar/thunar-enum-types.c +++ b/thunar/thunar-enum-types.c @@ -751,6 +751,26 @@ thunar_image_preview_mode_get_type (void) return type; } +GType thunar_folder_item_count_get_type (void) +{ + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GEnumValue values[] = + { + { THUNAR_FOLDER_ITEM_COUNT_NEVER, "THUNAR_FOLDER_ITEM_COUNT_NEVER", N_("Never") }, + { THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL, "THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL", N_("Only for local files") }, + { THUNAR_FOLDER_ITEM_COUNT_ALWAYS, "THUNAR_FOLDER_ITEM_COUNT_ALWAYS", N_("Always") }, + { 0, NULL, NULL } + }; + + type = g_enum_register_static ("ThunarFolderItemCount", values); + } + + return type; +} + GType thunar_items_as_folder_size_get_type (void) { diff --git a/thunar/thunar-enum-types.h b/thunar/thunar-enum-types.h index d07cfe4be..528badeb1 100644 --- a/thunar/thunar-enum-types.h +++ b/thunar/thunar-enum-types.h @@ -492,28 +492,28 @@ typedef enum GType thunar_image_preview_mode_get_type (void) G_GNUC_CONST; /** - * ThunarItemsAsFolderSize + * ThunarFolderItemCount * * Specify when the size column on a folder * should instead show the item count of the folder **/ -#define THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE (thunar_items_as_folder_size_get_type ()) +#define THUNAR_TYPE_FOLDER_ITEM_COUNT (thunar_folder_item_count_get_type ()) /** - * ThunarItemsAsFolderSize: - * @THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER, : never show number of items as the size of the folder - * @THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL, : only show number of items as size of folder for local folders - * @THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS, : always show the number of items as the size of the folder + * ThunarFolderItemCount: + * @THUNAR_FOLDER_ITEM_COUNT_NEVER, : never show number of items as the size of the folder + * @THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL, : only show number of items as size of folder for local folders + * @THUNAR_FOLDER_ITEM_COUNT_ALWAYS, : always show the number of items as the size of the folder **/ typedef enum { - THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER, - THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL, - THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS, -} ThunarItemsAsFolderSize; + THUNAR_FOLDER_ITEM_COUNT_NEVER, + THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL, + THUNAR_FOLDER_ITEM_COUNT_ALWAYS, +} ThunarFolderItemCount; -GType thunar_items_as_folder_size_get_type (void) G_GNUC_CONST; +GType thunar_folder_item_count_get_type (void) G_GNUC_CONST; G_END_DECLS; diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index f8e2721a2..0f7a435d0 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -56,7 +56,7 @@ enum PROP_FOLDERS_FIRST, PROP_NUM_FILES, PROP_SHOW_HIDDEN, - PROP_ITEMS_COUNT_AS_DIR_SIZE, + PROP_FOLDER_ITEM_COUNT, PROP_FILE_SIZE_BINARY, N_PROPERTIES }; @@ -225,10 +225,10 @@ static void thunar_list_model_search_folder (ThunarL enum ThunarListModelSearch search_type, gboolean show_hidden); static void thunar_list_model_cancel_search_job (ThunarListModel *model); -static gint thunar_list_model_get_items_count_as_dir_size (ThunarListModel *store); -static void thunar_list_model_set_items_count_as_dir_size (ThunarListModel *store, - ThunarItemsAsFolderSize items_count); +static gint thunar_list_model_get_folder_item_count (ThunarListModel *store); +static void thunar_list_model_set_folder_item_count (ThunarListModel *store, + ThunarFolderItemCount count_as_dir_size); struct _ThunarListModelClass { @@ -256,7 +256,7 @@ struct _ThunarListModel GSList *hidden; ThunarFolder *folder; gboolean show_hidden : 1; - ThunarItemsAsFolderSize items_count_as_dir_size; + ThunarFolderItemCount folder_item_count; gboolean file_size_binary : 1; ThunarDateStyle date_style; char *date_custom_style; @@ -414,13 +414,13 @@ thunar_list_model_class_init (ThunarListModelClass *klass) EXO_PARAM_READWRITE); /** - * ThunarListModel:items-count-as-dir-size: + * ThunarListModel:folder-item-count: **/ - list_model_props[PROP_ITEMS_COUNT_AS_DIR_SIZE] = - g_param_spec_enum ("items-count-as-dir-size", - "items-count-as-dir-size", - "items-count-as-dir-size", - THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE, + list_model_props[PROP_FOLDER_ITEM_COUNT] = + g_param_spec_enum ("folder-item-count", + "folder-item-count", + "folder-item-count", + THUNAR_TYPE_FOLDER_ITEM_COUNT, TRUE, EXO_PARAM_READWRITE); @@ -613,8 +613,8 @@ thunar_list_model_get_property (GObject *object, g_value_set_boolean (value, thunar_list_model_get_file_size_binary (store)); break; - case PROP_ITEMS_COUNT_AS_DIR_SIZE: - g_value_set_enum (value, thunar_list_model_get_items_count_as_dir_size (store)); + case PROP_FOLDER_ITEM_COUNT: + g_value_set_enum (value, thunar_list_model_get_folder_item_count (store)); break; default: @@ -663,8 +663,8 @@ thunar_list_model_set_property (GObject *object, thunar_list_model_set_file_size_binary (store, g_value_get_boolean (value)); break; - case PROP_ITEMS_COUNT_AS_DIR_SIZE: - thunar_list_model_set_items_count_as_dir_size (store, g_value_get_enum (value)); + case PROP_FOLDER_ITEM_COUNT: + thunar_list_model_set_folder_item_count (store, g_value_get_enum (value)); break; default: @@ -962,11 +962,11 @@ thunar_list_model_get_value (GtkTreeModel *model, { /* TODO refactor as switch case */ /* If the option is set to never show folder sizes as item counts, then just give the folder's binary size */ - if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) + if (THUNAR_LIST_MODEL (model)->folder_item_count == THUNAR_FOLDER_ITEM_COUNT_NEVER) g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); /* If the option is set to always show folder sizes as item counts, then give the folder's item count */ - else if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ALWAYS) + else if (THUNAR_LIST_MODEL (model)->folder_item_count == THUNAR_FOLDER_ITEM_COUNT_ALWAYS) { item_count = thunar_file_get_file_count (file, model); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); @@ -974,7 +974,7 @@ thunar_list_model_get_value (GtkTreeModel *model, /* If the option is set to always show folder sizes as item counts only for local files, * check if the files is local or not, and act accordingly */ - else if (THUNAR_LIST_MODEL (model)->items_count_as_dir_size == THUNAR_ITEMS_AS_FOLDER_SIZE_ONLY_LOCAL) + else if (THUNAR_LIST_MODEL (model)->folder_item_count == THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL) { if (thunar_file_is_local (file)) { @@ -985,7 +985,7 @@ thunar_list_model_get_value (GtkTreeModel *model, g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); } else - g_warning ("Error, unknown enum value for items_count_as_dir_size in the list model"); + g_warning ("Error, unknown enum value for folder_item_count in the list model"); } else { @@ -1249,7 +1249,7 @@ thunar_list_model_set_sort_column_id (GtkTreeSortable *sortable, break; case THUNAR_COLUMN_SIZE: - store->sort_func = (store->items_count_as_dir_size != THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; + store->sort_func = (store->folder_item_count != THUNAR_FOLDER_ITEM_COUNT_NEVER) ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; break; case THUNAR_COLUMN_SIZE_IN_BYTES: @@ -1918,8 +1918,8 @@ sort_by_size_and_items_count (ThunarFile *a, if (thunar_file_is_directory(a) && thunar_file_is_directory(b)) { - count_a = thunar_file_get_file_count (thunar_folder_get_for_file (a), NULL); - count_b = thunar_file_get_file_count (thunar_folder_get_for_file (b), NULL); + count_a = thunar_file_get_file_count (a, NULL); + count_b = thunar_file_get_file_count (b, NULL); if (count_a < count_b) return -1; @@ -2768,44 +2768,44 @@ thunar_list_model_set_file_size_binary (ThunarListModel *store, /** - * thunar_list_model_get_items_count_as_dir_size: + * thunar_list_model_get_folder_item_count: * @store : a #ThunarListModel. * - * Return value: A value of the enum #ThunarItemsAsFolderSize + * Return value: A value of the enum #ThunarFolderItemCount **/ static gint -thunar_list_model_get_items_count_as_dir_size (ThunarListModel *store) +thunar_list_model_get_folder_item_count (ThunarListModel *store) { _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), FALSE); - return store->items_count_as_dir_size; + return store->folder_item_count; } /** - * thunar_list_model_set_items_count_as_dir_size: + * thunar_list_model_set_folder_item_count: * @store : a #ThunarListModel. - * @count_as_dir_size : a value of the enum ThunarItemsAsFolderSize + * @count_as_dir_size : a value of the enum #ThunarFolderItemCount **/ -void -thunar_list_model_set_items_count_as_dir_size (ThunarListModel *store, - ThunarItemsAsFolderSize count_as_dir_size) +static void +thunar_list_model_set_folder_item_count (ThunarListModel *store, + ThunarFolderItemCount count_as_dir_size) { _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); /* check if the new setting differs */ - if (store->items_count_as_dir_size == count_as_dir_size) + if (store->folder_item_count == count_as_dir_size) return; - store->items_count_as_dir_size = count_as_dir_size; - g_object_notify_by_pspec (G_OBJECT (store), list_model_props[PROP_ITEMS_COUNT_AS_DIR_SIZE]); + store->folder_item_count = count_as_dir_size; + g_object_notify_by_pspec (G_OBJECT (store), list_model_props[PROP_FOLDER_ITEM_COUNT]); gtk_tree_model_foreach (GTK_TREE_MODEL (store), (GtkTreeModelForeachFunc) (void (*)(void)) gtk_tree_model_row_changed, NULL); /* re-sorting the store if needed */ if (store->sort_func == sort_by_size || store->sort_func == (ThunarSortFunc) sort_by_size_and_items_count) { - store->sort_func = (store->items_count_as_dir_size != THUNAR_ITEMS_AS_FOLDER_SIZE_NEVER) ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; + store->sort_func = (store->folder_item_count != THUNAR_FOLDER_ITEM_COUNT_NEVER) ? (ThunarSortFunc) sort_by_size_and_items_count : sort_by_size; thunar_list_model_sort (store); } } diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 70d42f1f8..013262977 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -89,7 +89,7 @@ enum PROP_MISC_DATE_CUSTOM_STYLE, PROP_EXEC_SHELL_SCRIPTS_BY_DEFAULT, PROP_MISC_FOLDERS_FIRST, - PROP_MISC_ITEMS_COUNT_AS_DIR_SIZE, + PROP_MISC_FOLDER_ITEM_COUNT, PROP_MISC_FULL_PATH_IN_TAB_TITLE, PROP_MISC_FULL_PATH_IN_WINDOW_TITLE, PROP_MISC_HORIZONTAL_WHEEL_NAVIGATES, @@ -689,15 +689,15 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) EXO_PARAM_READWRITE); /** - * ThunarPreferences:misc-items-count-as-dir-size + * ThunarPreferences:misc-folder-item-count **/ - preferences_props[PROP_MISC_ITEMS_COUNT_AS_DIR_SIZE] = - g_param_spec_enum ("misc-items-count-as-dir-size", - "MiscItemsCountAsDirSize", - NULL, - THUNAR_TYPE_ITEMS_AS_FOLDER_SIZE, - TRUE, - EXO_PARAM_READWRITE); + preferences_props[PROP_MISC_FOLDER_ITEM_COUNT] = + g_param_spec_enum ("misc-folder-item-count", + "MiscFolderItemCount", + NULL, + THUNAR_TYPE_FOLDER_ITEM_COUNT, + TRUE, + EXO_PARAM_READWRITE); /** * ThunarPreferences:misc-full-path-in-tab-title: diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 9801b12ed..d6ef4a2ba 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -831,7 +831,7 @@ thunar_standard_view_init (ThunarStandardView *standard_view) g_object_bind_property (G_OBJECT (standard_view->preferences), "misc-date-custom-style", G_OBJECT (standard_view->model), "date-custom-style", G_BINDING_SYNC_CREATE); g_object_bind_property (G_OBJECT (standard_view->preferences), "misc-folders-first", G_OBJECT (standard_view->model), "folders-first", G_BINDING_SYNC_CREATE); g_object_bind_property (G_OBJECT (standard_view->preferences), "misc-file-size-binary", G_OBJECT (standard_view->model), "file-size-binary", G_BINDING_SYNC_CREATE); - g_object_bind_property (G_OBJECT (standard_view->preferences), "misc-items-count-as-dir-size", G_OBJECT (standard_view->model), "items-count-as-dir-size", G_BINDING_SYNC_CREATE); + g_object_bind_property (G_OBJECT (standard_view->preferences), "misc-folder-item-count", G_OBJECT (standard_view->model), "folder-item-count", G_BINDING_SYNC_CREATE); /* setup the icon renderer */ standard_view->icon_renderer = thunar_icon_renderer_new (); -- GitLab From e64bafa42a992cc6ae711939921436651e0a409b Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Thu, 20 Oct 2022 14:53:00 +0530 Subject: [PATCH 27/40] Restore 'mountable' section in `thunar_list_model_get_value` --- thunar/thunar-file.c | 2 +- thunar/thunar-folder.c | 5 ++++- thunar/thunar-io-jobs.c | 2 ++ thunar/thunar-list-model.c | 13 +++++++++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index e7f763636..16b99cf5b 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -3543,7 +3543,7 @@ thunar_file_get_file_count (ThunarFile *file, return file->file_count; /* put the timestamp calculation at the *start* of the process to prevent another call to - * thunar_folder_get_file_count starting another job on the same folder before one has ended. + * thunar_file_get_count starting another job on the same folder before one has ended. * Divide by 1e6 to convert from microseconds to seconds */ file->file_count_timestamp = g_get_real_time () / (guint64) 1e6; diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index b392ffcfe..fb128f9f0 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -30,7 +30,6 @@ #include #include #include -#include #define DEBUG_FILE_CHANGES FALSE @@ -88,6 +87,7 @@ static void thunar_folder_monitor (GFileMonitor gpointer user_data); + struct _ThunarFolderClass { GObjectClass __parent__; @@ -959,6 +959,9 @@ thunar_folder_get_files (const ThunarFolder *folder) _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), NULL); return folder->files; } + + + /** * thunar_folder_get_loading: * @folder : a #ThunarFolder instance. diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index 1644757a4..e1d3ab640 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -1502,6 +1502,8 @@ _thunar_io_jobs_count (ThunarJob *job, thunar_file_set_file_count (file, count); + g_object_unref (enumerator); + return TRUE; } diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 0f7a435d0..2598bb7d4 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -812,6 +812,7 @@ thunar_list_model_get_value (GtkTreeModel *model, ThunarFolder *folder; gchar *str; guint32 item_count; + GFile *g_file; GFile *g_file_parent; _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (model)); @@ -958,9 +959,17 @@ thunar_list_model_get_value (GtkTreeModel *model, case THUNAR_COLUMN_SIZE: g_value_init (value, G_TYPE_STRING); - if (thunar_file_is_directory (file)) + if (thunar_file_is_mountable (file)) + { + g_file = thunar_file_get_target_location (file); + if (g_file == NULL) + break; + g_value_take_string (value, thunar_g_file_get_free_space_string (g_file, THUNAR_LIST_MODEL (model)->file_size_binary)); + g_object_unref (g_file); + break; + } + else if (thunar_file_is_directory (file)) { - /* TODO refactor as switch case */ /* If the option is set to never show folder sizes as item counts, then just give the folder's binary size */ if (THUNAR_LIST_MODEL (model)->folder_item_count == THUNAR_FOLDER_ITEM_COUNT_NEVER) g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); -- GitLab From 5218bf0b812837540e5ed9289a9d39f78273571e Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Sat, 22 Oct 2022 23:30:55 +0000 Subject: [PATCH 28/40] Fix comments --- thunar/thunar-file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 16b99cf5b..c0856f1db 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -190,7 +190,8 @@ struct _ThunarFile /* tells whether the file watch is not set */ gboolean no_file_watch; - /* the file count, valid only if the file is a directory */ + /* Number of files in this directory (only used if this #Thunarfile is a directory) */ + /* Note that this feature was added into #ThunarFile on purpose, because having inside #ThunarFolder caused lag when there were > 10.000 files in a folder (Creation of #ThunarFolder seems to be slow) */ guint file_count; guint64 file_count_timestamp; @@ -3495,7 +3496,7 @@ thunar_file_can_be_trashed (const ThunarFile *file) /** * thunar_file_get_file_count - * @file : a #ThunarFolder instance. + * @file : a #ThunarFile instance. * @store: a #GtkTreeModel or %NULL * * Returns the number of items in the directory -- GitLab From ae2d85b7b642b1266ede5d6968ef6d9aae8ddfa5 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Sun, 23 Oct 2022 05:04:41 +0530 Subject: [PATCH 29/40] Fix indent, init file count and timestamp --- thunar/thunar-file.c | 6 ++++-- thunar/thunar-io-jobs.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index c0856f1db..456b8c68b 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -192,8 +192,8 @@ struct _ThunarFile /* Number of files in this directory (only used if this #Thunarfile is a directory) */ /* Note that this feature was added into #ThunarFile on purpose, because having inside #ThunarFolder caused lag when there were > 10.000 files in a folder (Creation of #ThunarFolder seems to be slow) */ - guint file_count; - guint64 file_count_timestamp; + guint file_count; + guint64 file_count_timestamp; }; @@ -391,6 +391,8 @@ thunar_file_class_init (ThunarFileClass *klass) static void thunar_file_init (ThunarFile *file) { + file->file_count = 0; + file->file_count_timestamp = 0; } diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index e1d3ab640..8f40962c5 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -1460,7 +1460,7 @@ _thunar_io_jobs_count (ThunarJob *job, GArray *param_values, GError **error) { - GError *err = NULL; + GError *err = NULL; ThunarFile *file; GFileEnumerator *enumerator; guint count; -- GitLab From 29dcbe514a2a1ce9e02fa0573a3ad4924bd4b542 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Sat, 22 Oct 2022 23:35:46 +0000 Subject: [PATCH 30/40] Add descriptive comments for docs --- thunar/thunar-list-model.c | 2 ++ thunar/thunar-preferences.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 2598bb7d4..e1d559643 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -415,6 +415,8 @@ thunar_list_model_class_init (ThunarListModelClass *klass) /** * ThunarListModel:folder-item-count: + * + * Tells when the size column of folders should show the number of containing files **/ list_model_props[PROP_FOLDER_ITEM_COUNT] = g_param_spec_enum ("folder-item-count", diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 013262977..2ec51f2e7 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -690,6 +690,8 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) /** * ThunarPreferences:misc-folder-item-count + * + * Tells when the size column of folders should show the number of containing files **/ preferences_props[PROP_MISC_FOLDER_ITEM_COUNT] = g_param_spec_enum ("misc-folder-item-count", -- GitLab From 36b7a1a142e6eae663a8c230bc18881c697e94e9 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Sat, 22 Oct 2022 23:36:31 +0000 Subject: [PATCH 31/40] Minor style fix --- thunar/thunar-list-model.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index e1d559643..44005d2bd 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -1927,7 +1927,7 @@ sort_by_size_and_items_count (ThunarFile *a, guint32 count_a; guint32 count_b; - if (thunar_file_is_directory(a) && thunar_file_is_directory(b)) + if (thunar_file_is_directory (a) && thunar_file_is_directory (b)) { count_a = thunar_file_get_file_count (a, NULL); count_b = thunar_file_get_file_count (b, NULL); -- GitLab From 426237fd116889d19f2c9204a73aa32bd6f46bd1 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Sun, 23 Oct 2022 05:08:47 +0530 Subject: [PATCH 32/40] Fix default value for enum misc-folder-item-count --- thunar/thunar-preferences.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 2ec51f2e7..e110f1f93 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -698,7 +698,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) "MiscFolderItemCount", NULL, THUNAR_TYPE_FOLDER_ITEM_COUNT, - TRUE, + THUNAR_FOLDER_ITEM_COUNT_NEVER, EXO_PARAM_READWRITE); /** -- GitLab From 98638c353800937327822001e8b6a21df458313f Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Sun, 23 Oct 2022 05:10:59 +0530 Subject: [PATCH 33/40] Wrap long comment --- thunar/thunar-file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 456b8c68b..291ee1165 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -191,7 +191,8 @@ struct _ThunarFile gboolean no_file_watch; /* Number of files in this directory (only used if this #Thunarfile is a directory) */ - /* Note that this feature was added into #ThunarFile on purpose, because having inside #ThunarFolder caused lag when there were > 10.000 files in a folder (Creation of #ThunarFolder seems to be slow) */ + /* Note that this feature was added into #ThunarFile on purpose, because having inside #ThunarFolder caused lag when + * there were > 10.000 files in a folder (Creation of #ThunarFolder seems to be slow) */ guint file_count; guint64 file_count_timestamp; -- GitLab From 74d78a8fa637301b3c581b053d043c17dba69ebb Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Sun, 23 Oct 2022 05:27:52 +0530 Subject: [PATCH 34/40] Change thunar_file_get_file_count to use generic callback --- thunar/thunar-file.c | 31 +++++++++++-------------------- thunar/thunar-file.h | 3 ++- thunar/thunar-list-model.c | 20 ++++++++++++++++---- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 291ee1165..78aed85a6 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -117,8 +117,6 @@ static gboolean thunar_file_load (ThunarFile static gboolean thunar_file_is_readable (const ThunarFile *file); static gboolean thunar_file_same_filesystem (const ThunarFile *file_a, const ThunarFile *file_b); -static void thunar_file_count_callback (ExoJob *job, - gpointer model); @@ -3499,21 +3497,21 @@ thunar_file_can_be_trashed (const ThunarFile *file) /** * thunar_file_get_file_count - * @file : a #ThunarFile instance. - * @store: a #GtkTreeModel or %NULL + * @file : a #ThunarFile instance. + * @callback: a #GCallback to be executed after the file count + * @data : a #gpointer containing user data to pass to the callback * * Returns the number of items in the directory * Counts the number of files in the directory as fast as possible. - * Will use cached data to do calculations only once - * The @store is needed to force the redraw once the file count - * values are actually calculated. - * Cached values are returned if @store is NULL. + * Will use cached data to do calculations only when the file has + * been modified since the last time its contents were counted. * * Return value: Number of files in a folder **/ guint thunar_file_get_file_count (ThunarFile *file, - GtkTreeModel *store) + GCallback callback, + gpointer data) { GError *err = NULL; ThunarJob *job; @@ -3554,8 +3552,10 @@ thunar_file_get_file_count (ThunarFile *file, /* set up a job to actually enumerate over the folder's contents and get its file count */ job = thunar_io_jobs_count_files (file); - /* set up the signal on finish to update the row model and ask for redraw */ - g_signal_connect (job, "finished", G_CALLBACK (thunar_file_count_callback), store); + /* set up the signal on finish to call the callback */ + if (callback != NULL) + g_signal_connect (job, "finished", G_CALLBACK (callback), data); + exo_job_launch (EXO_JOB (job)); return file->file_count; @@ -4564,15 +4564,6 @@ thunar_file_same_filesystem (const ThunarFile *file_a, -static void -thunar_file_count_callback (ExoJob *job, - gpointer model) -{ - gtk_tree_model_foreach (GTK_TREE_MODEL (model), (GtkTreeModelForeachFunc) gtk_tree_model_row_changed, NULL); -} - - - /** * thunar_file_cache_lookup: * @file : a #GFile. diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h index cb1d72ab3..8b9a3e405 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -237,7 +237,8 @@ gboolean thunar_file_can_be_trashed (const ThunarFile guint thunar_file_get_file_count (ThunarFile *file, - GtkTreeModel *store); + GCallback callback, + gpointer data); void thunar_file_set_file_count (ThunarFile *file, const guint count); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 44005d2bd..abfb3f4e1 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -230,6 +230,9 @@ static gint thunar_list_model_get_folder_item_count (ThunarL static void thunar_list_model_set_folder_item_count (ThunarListModel *store, ThunarFolderItemCount count_as_dir_size); +static void thunar_list_model_file_count_callback (ExoJob *job, + gpointer model); + struct _ThunarListModelClass { GObjectClass __parent__; @@ -979,7 +982,7 @@ thunar_list_model_get_value (GtkTreeModel *model, /* If the option is set to always show folder sizes as item counts, then give the folder's item count */ else if (THUNAR_LIST_MODEL (model)->folder_item_count == THUNAR_FOLDER_ITEM_COUNT_ALWAYS) { - item_count = thunar_file_get_file_count (file, model); + item_count = thunar_file_get_file_count (file, G_CALLBACK (thunar_list_model_file_count_callback), model); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } @@ -989,7 +992,7 @@ thunar_list_model_get_value (GtkTreeModel *model, { if (thunar_file_is_local (file)) { - item_count = thunar_file_get_file_count (file, model); + item_count = thunar_file_get_file_count (file, G_CALLBACK (thunar_list_model_file_count_callback), model); g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); } else @@ -1929,8 +1932,8 @@ sort_by_size_and_items_count (ThunarFile *a, if (thunar_file_is_directory (a) && thunar_file_is_directory (b)) { - count_a = thunar_file_get_file_count (a, NULL); - count_b = thunar_file_get_file_count (b, NULL); + count_a = thunar_file_get_file_count (a, NULL, NULL); + count_b = thunar_file_get_file_count (b, NULL, NULL); if (count_a < count_b) return -1; @@ -3288,3 +3291,12 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store, g_object_unref (preferences); return text; } + + + +static void +thunar_list_model_file_count_callback (ExoJob *job, + gpointer model) +{ + gtk_tree_model_foreach (GTK_TREE_MODEL (model), (GtkTreeModelForeachFunc) gtk_tree_model_row_changed, NULL); +} -- GitLab From c182b4cc0571fa9333b0be5b0fa9844b8e9551cc Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Tue, 25 Oct 2022 16:19:59 +0530 Subject: [PATCH 35/40] Switch to using thunar_model_file_changed to emit signal --- thunar/thunar-list-model.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index abfb3f4e1..04a1f2a2a 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -1419,7 +1419,7 @@ thunar_list_model_file_changed (ThunarFileMonitor *file_monitor, GtkTreePath *path; GtkTreeIter iter; - _thunar_return_if_fail (THUNAR_IS_FILE_MONITOR (file_monitor)); + _thunar_return_if_fail (THUNAR_IS_FILE_MONITOR (file_monitor) || file_monitor == NULL); _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); _thunar_return_if_fail (THUNAR_IS_FILE (file)); @@ -3298,5 +3298,14 @@ static void thunar_list_model_file_count_callback (ExoJob *job, gpointer model) { - gtk_tree_model_foreach (GTK_TREE_MODEL (model), (GtkTreeModelForeachFunc) gtk_tree_model_row_changed, NULL); + GArray *param_values; + ThunarFile *file; + + param_values = thunar_simple_job_get_param_values (THUNAR_SIMPLE_JOB (job)); + file = THUNAR_FILE (g_value_get_object (&g_array_index (param_values, GValue, 0))); + + if (file == NULL) + return; + + thunar_list_model_file_changed (NULL, file, THUNAR_LIST_MODEL (model)); } -- GitLab From c6a6b0361ae78624f9836fc4bb4c616d51beecd1 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Tue, 25 Oct 2022 19:43:40 +0000 Subject: [PATCH 36/40] trailing whitespace --- thunar/thunar-list-model.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 04a1f2a2a..2aa3b6ffc 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -199,7 +199,7 @@ static gint sort_by_size_in_bytes (const T gboolean case_sensitive); static gint sort_by_size_and_items_count (ThunarFile *a, ThunarFile *b, - gboolean case_sensitive); + gboolean case_sensitive); static gint sort_by_type (const ThunarFile *a, const ThunarFile *b, gboolean case_sensitive); -- GitLab From d66afeb7a8b480820774e4878cbeed2ac47855da Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Tue, 25 Oct 2022 19:44:13 +0000 Subject: [PATCH 37/40] trailing whitespace --- thunar/thunar-list-model.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 2aa3b6ffc..7c069f38e 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -418,7 +418,7 @@ thunar_list_model_class_init (ThunarListModelClass *klass) /** * ThunarListModel:folder-item-count: - * + * * Tells when the size column of folders should show the number of containing files **/ list_model_props[PROP_FOLDER_ITEM_COUNT] = -- GitLab From 76c59aa2902e4ccc802e5c44b00b791835f93a64 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Tue, 25 Oct 2022 19:44:22 +0000 Subject: [PATCH 38/40] trailing whitespace --- thunar/thunar-preferences.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index e110f1f93..eb581a6c8 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -690,7 +690,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) /** * ThunarPreferences:misc-folder-item-count - * + * * Tells when the size column of folders should show the number of containing files **/ preferences_props[PROP_MISC_FOLDER_ITEM_COUNT] = -- GitLab From c7c624bb5dce917121cbea772f81c36f94d92bb0 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Tue, 25 Oct 2022 19:44:37 +0000 Subject: [PATCH 39/40] new blank line at EOF --- thunar/thunar-io-jobs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index 8f40962c5..75a06f1d6 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -1517,4 +1517,3 @@ thunar_io_jobs_count_files (ThunarFile *file) return thunar_simple_job_new (_thunar_io_jobs_count, 1, THUNAR_TYPE_FILE, file); } - -- GitLab From 17deaab4fd7f0b62632c875dcccc0e11a07beeaa Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Tue, 25 Oct 2022 19:46:40 +0000 Subject: [PATCH 40/40] remove duplicated method to prevent warning --- thunar/thunar-enum-types.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c index 16a0af042..5e989dee5 100644 --- a/thunar/thunar-enum-types.c +++ b/thunar/thunar-enum-types.c @@ -770,23 +770,3 @@ GType thunar_folder_item_count_get_type (void) return type; } - -GType -thunar_items_as_folder_size_get_type (void) -{ - static GType type = G_TYPE_INVALID; - - if (G_UNLIKELY (type == G_TYPE_INVALID)) - { - static const GEnumValue values[] = - { - { THUNAR_FOLDER_ITEM_COUNT_NEVER, "THUNAR_FOLDER_ITEM_COUNT_NEVER", N_("Never") }, - { THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL, "THUNAR_FOLDER_ITEM_COUNT_ONLY_LOCAL", N_("Only for local files") }, - { THUNAR_FOLDER_ITEM_COUNT_ALWAYS, "THUNAR_FOLDER_ITEM_COUNT_ALWAYS", N_("Always") }, - { 0, NULL, NULL } - }; - - type = g_enum_register_static ("ThunarItemsAsFolderSize", values); - } - return type; -} -- GitLab