summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2020-05-11 12:13:49 +0100
committerOndrej Holy <oholy@redhat.com>2021-01-25 10:54:10 +0000
commit1ef42ee77ccc11f7131ff002a6061f70ee879bb5 (patch)
tree053a958ebc22c0d01316804d13ec14cd12d60a06
parentb3a6ec8293c5f47ac2ef6583e1627bcb85fba020 (diff)
downloadnautilus-1ef42ee77ccc11f7131ff002a6061f70ee879bb5.tar.gz
file: Deduplicate speed tradeoff code
The nautilus_file_should_show_thumbnail() method was first introduced in commit 469047a2a58430026d68a3b99b223b922b18b8d1 It duplicated the tradeoff setting logic that was already present in get_speed_tradeoff_preference_for_file(), a shared function for both top left text preview and child directories item count. (Top left text preview has since been phased out.) The code duplication grew when support for the filesystem::use-preview attribute was added in commit 00e59a6b3c10ec4c3915b61d09498b4110189917 Instead, let's make should_show_thumbnail() use the shared function.
-rw-r--r--src/nautilus-file.c102
1 files changed, 33 insertions, 69 deletions
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index a9047d3de..817241a21 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -4744,31 +4744,17 @@ nautilus_file_get_filesystem_remote (NautilusFile *file)
return FALSE;
}
-gboolean
-nautilus_file_should_show_thumbnail (NautilusFile *file)
+static gboolean
+get_speed_tradeoff_preference_for_file (NautilusFile *file,
+ NautilusSpeedTradeoffValue value)
{
- const char *mime_type;
GFilesystemPreviewType use_preview;
- use_preview = nautilus_file_get_filesystem_use_preview (file);
-
- mime_type = file->details->mime_type;
- if (mime_type == NULL)
- {
- mime_type = "application/octet-stream";
- }
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- /* If the thumbnail has already been created, don't care about the size
- * of the original file.
- */
- if (nautilus_thumbnail_is_mimetype_limited_by_size (mime_type) &&
- file->details->thumbnail_path == NULL &&
- nautilus_file_get_size (file) > cached_thumbnail_limit)
- {
- return FALSE;
- }
+ use_preview = nautilus_file_get_filesystem_use_preview (file);
- if (show_file_thumbs == NAUTILUS_SPEED_TRADEOFF_ALWAYS)
+ if (value == NAUTILUS_SPEED_TRADEOFF_ALWAYS)
{
if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
{
@@ -4779,15 +4765,15 @@ nautilus_file_should_show_thumbnail (NautilusFile *file)
return TRUE;
}
}
- else if (show_file_thumbs == NAUTILUS_SPEED_TRADEOFF_NEVER)
+ else if (value == NAUTILUS_SPEED_TRADEOFF_NEVER)
{
return FALSE;
}
- else
+ else if (value == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY)
{
if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
{
- /* file system says to never thumbnail anything */
+ /* file system says to never preview anything */
return FALSE;
}
else if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_IF_LOCAL)
@@ -4805,6 +4791,30 @@ nautilus_file_should_show_thumbnail (NautilusFile *file)
return FALSE;
}
+gboolean
+nautilus_file_should_show_thumbnail (NautilusFile *file)
+{
+ const char *mime_type;
+
+ mime_type = file->details->mime_type;
+ if (mime_type == NULL)
+ {
+ mime_type = "application/octet-stream";
+ }
+
+ /* If the thumbnail has already been created, don't care about the size
+ * of the original file.
+ */
+ if (nautilus_thumbnail_is_mimetype_limited_by_size (mime_type) &&
+ file->details->thumbnail_path == NULL &&
+ nautilus_file_get_size (file) > cached_thumbnail_limit)
+ {
+ return FALSE;
+ }
+
+ return get_speed_tradeoff_preference_for_file (file, show_file_thumbs);
+}
+
static gboolean
nautilus_is_video_file (NautilusFile *file)
{
@@ -5660,52 +5670,6 @@ show_directory_item_count_changed_callback (gpointer callback_data)
show_directory_item_count = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS);
}
-static gboolean
-get_speed_tradeoff_preference_for_file (NautilusFile *file,
- NautilusSpeedTradeoffValue value)
-{
- GFilesystemPreviewType use_preview;
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
-
- use_preview = nautilus_file_get_filesystem_use_preview (file);
-
- if (value == NAUTILUS_SPEED_TRADEOFF_ALWAYS)
- {
- if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
- {
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
-
- if (value == NAUTILUS_SPEED_TRADEOFF_NEVER)
- {
- return FALSE;
- }
-
- g_assert (value == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);
-
- if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
- {
- /* file system says to never preview anything */
- return FALSE;
- }
- else if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_IF_LOCAL)
- {
- /* file system says we should treat file as if it's local */
- return TRUE;
- }
- else
- {
- /* only local files */
- return !nautilus_file_is_remote (file);
- }
-}
-
gboolean
nautilus_file_should_show_directory_item_count (NautilusFile *file)
{