diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 779c62177a8d45aae9d3c304d2ff1c70423cdf8b..f4df1a9021e4ba22a932a4e4a3d7529f12346a94 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -3595,9 +3595,11 @@ thunar_file_can_be_trashed (const ThunarFile *file) * Will use cached data to do calculations only when the file has * been modified since the last time its contents were counted. * + * Will return -1 if the file info cannot be loaded + * * Return value: Number of files in a folder **/ -guint +gint thunar_file_get_file_count (ThunarFile *file, GCallback callback, gpointer data) @@ -3619,10 +3621,13 @@ thunar_file_get_file_count (ThunarFile *file, NULL, &err); + /* If the file info cannot be loaded, return -1 */ if (err != NULL) { - g_warning ("An error occurred while trying to get file counts."); - return file->file_count; + if (info != NULL) + g_object_unref (info); + g_error_free (err); + return -1; } last_modified = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); @@ -5192,11 +5197,11 @@ thunar_cmp_files_by_size_in_bytes (const ThunarFile *a, gint thunar_cmp_files_by_size_and_items_count (ThunarFile *a, - ThunarFile *b, - gboolean case_sensitive) + ThunarFile *b, + gboolean case_sensitive) { - guint32 count_a; - guint32 count_b; + gint32 count_a; + gint32 count_b; if (thunar_file_is_directory (a) && thunar_file_is_directory (b)) { diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h index 5dfb04f66d326be3fe664dc64e87f91ad67e5724..931302739db7b6e1eebae4990deb267dfa9555a5 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -258,7 +258,7 @@ gboolean thunar_file_is_renameable (const ThunarFile gboolean thunar_file_can_be_trashed (const ThunarFile *file); -guint thunar_file_get_file_count (ThunarFile *file, +gint thunar_file_get_file_count (ThunarFile *file, GCallback callback, gpointer data); void thunar_file_set_file_count (ThunarFile *file, diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 04c2c358f8be19043aeadde1a59ee2a8c8004a66..ddb824fb05417ca8808fe51131201429b94ced18 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -767,7 +767,7 @@ thunar_list_model_get_value (GtkTreeModel *model, ThunarFile *file; ThunarFolder *folder; gchar *str; - guint32 item_count; + gint32 item_count; GFile *g_file; GFile *g_file_parent; @@ -963,7 +963,10 @@ thunar_list_model_get_value (GtkTreeModel *model, else if (THUNAR_LIST_MODEL (model)->folder_item_count == THUNAR_FOLDER_ITEM_COUNT_ALWAYS) { 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)); + if (item_count < 0) + g_value_take_string (value, g_strdup (_("unknown"))); + else + 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, @@ -973,7 +976,10 @@ thunar_list_model_get_value (GtkTreeModel *model, if (thunar_file_is_local (file)) { 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)); + if (item_count < 0) + g_value_take_string (value, g_strdup (_("unknown"))); + else + 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)); diff --git a/thunar/thunar-tree-view-model.c b/thunar/thunar-tree-view-model.c index 17e2f295a8184a84f63f1bd242bf0895477709a1..b957a9ac17ea2336e1d8943e6585558a806bca1f 100644 --- a/thunar/thunar-tree-view-model.c +++ b/thunar/thunar-tree-view-model.c @@ -1064,7 +1064,7 @@ thunar_tree_view_model_get_value (GtkTreeModel *model, const gchar *real_name; ThunarUser *user = NULL; ThunarFolder *folder; - guint32 item_count; + gint32 item_count; GFile *g_file; GFile *g_file_parent = NULL; gchar *str = NULL; @@ -1284,7 +1284,10 @@ thunar_tree_view_model_get_value (GtkTreeModel *model, else if (THUNAR_TREE_VIEW_MODEL (model)->folder_item_count == THUNAR_FOLDER_ITEM_COUNT_ALWAYS) { item_count = thunar_file_get_file_count (file, G_CALLBACK (thunar_tree_view_model_file_count_callback), model); - g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); + if (item_count < 0) + g_value_take_string (value, g_strdup (_("unknown"))); + else + 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, @@ -1294,7 +1297,10 @@ thunar_tree_view_model_get_value (GtkTreeModel *model, if (thunar_file_is_local (file)) { item_count = thunar_file_get_file_count (file, G_CALLBACK (thunar_tree_view_model_file_count_callback), model); - g_value_take_string (value, g_strdup_printf (ngettext ("%u item", "%u items", item_count), item_count)); + if (item_count < 0) + g_value_take_string (value, g_strdup (_("unknown"))); + else + 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_TREE_VIEW_MODEL (model)->file_size_binary));