file: Deduplicate speed tradeoff code

The nautilus_file_should_show_thumbnail() method was first introduced
in commit 469047a2a5

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 00e59a6b3c

Instead, let's make should_show_thumbnail() use the shared function.
This commit is contained in:
António Fernandes 2020-05-11 12:13:49 +01:00 committed by Ondrej Holy
parent b3a6ec8293
commit 1ef42ee77c

View file

@ -4744,13 +4744,57 @@ nautilus_file_get_filesystem_remote (NautilusFile *file)
return FALSE; return FALSE;
} }
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;
}
}
else if (value == NAUTILUS_SPEED_TRADEOFF_NEVER)
{
return FALSE;
}
else if (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);
}
}
return FALSE;
}
gboolean gboolean
nautilus_file_should_show_thumbnail (NautilusFile *file) nautilus_file_should_show_thumbnail (NautilusFile *file)
{ {
const char *mime_type; const char *mime_type;
GFilesystemPreviewType use_preview;
use_preview = nautilus_file_get_filesystem_use_preview (file);
mime_type = file->details->mime_type; mime_type = file->details->mime_type;
if (mime_type == NULL) if (mime_type == NULL)
@ -4768,41 +4812,7 @@ nautilus_file_should_show_thumbnail (NautilusFile *file)
return FALSE; return FALSE;
} }
if (show_file_thumbs == NAUTILUS_SPEED_TRADEOFF_ALWAYS) return get_speed_tradeoff_preference_for_file (file, show_file_thumbs);
{
if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
{
return FALSE;
}
else
{
return TRUE;
}
}
else if (show_file_thumbs == NAUTILUS_SPEED_TRADEOFF_NEVER)
{
return FALSE;
}
else
{
if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
{
/* file system says to never thumbnail 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);
}
}
return FALSE;
} }
static gboolean static gboolean
@ -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); 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 gboolean
nautilus_file_should_show_directory_item_count (NautilusFile *file) nautilus_file_should_show_directory_item_count (NautilusFile *file)
{ {