core: Use basename rather than URI for file loading
Certain cloud providers return a blobname rather than the actual filename with g_file_get_uri (). Since our code only checks the suffix and extension of non-native files, we received "Unknown File Type" when trying to load images from those providers. This patch replaces g_file_get_uri () so that we get the display-name instead, which should always have the extension. This may be changed in the future when we switch to a FileChooser portal. This same pattern is also used on the GimpThumbBox so we see the display-name rather than the blob name. Thanks to Khalid Abu Shawarib for the additional information!
This commit is contained in:
@ -745,31 +745,54 @@ gimp_file_is_executable (GFile *file)
|
||||
gchar *
|
||||
gimp_file_get_extension (GFile *file)
|
||||
{
|
||||
gchar *uri;
|
||||
gint uri_len;
|
||||
gchar *ext = NULL;
|
||||
gint search_len;
|
||||
GFileInfo *info;
|
||||
gchar *basename;
|
||||
gint basename_len;
|
||||
gchar *ext = NULL;
|
||||
gint search_len;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
|
||||
uri = g_file_get_uri (file);
|
||||
uri_len = strlen (uri);
|
||||
/* Certain cloud providers return a blob name rather than the
|
||||
* actual file with g_file_get_uri (). Since we don't check
|
||||
* the magic numbers for remote files, we can't open it. The
|
||||
* actual name is stored as "display-name" in all cases, so we
|
||||
* use that instead. */
|
||||
info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
|
||||
0, NULL, NULL);
|
||||
|
||||
if (g_str_has_suffix (uri, ".gz"))
|
||||
search_len = uri_len - 3;
|
||||
else if (g_str_has_suffix (uri, ".bz2"))
|
||||
search_len = uri_len - 4;
|
||||
else if (g_str_has_suffix (uri, ".xz"))
|
||||
search_len = uri_len - 3;
|
||||
if (info != NULL)
|
||||
basename =
|
||||
g_file_info_get_attribute_as_string (info,
|
||||
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
|
||||
else
|
||||
search_len = uri_len;
|
||||
basename = g_file_get_basename (file);
|
||||
|
||||
ext = g_strrstr_len (uri, search_len, ".");
|
||||
g_clear_object (&info);
|
||||
|
||||
/* When making a temporary file for saving/exporting, we may not
|
||||
* have the display-name yet, so let's fallback to the URI */
|
||||
if (! basename)
|
||||
basename = g_file_get_uri (file);
|
||||
|
||||
basename_len = strlen (basename);
|
||||
|
||||
if (g_str_has_suffix (basename, ".gz"))
|
||||
search_len = basename_len - 3;
|
||||
else if (g_str_has_suffix (basename, ".bz2"))
|
||||
search_len = basename_len - 4;
|
||||
else if (g_str_has_suffix (basename, ".xz"))
|
||||
search_len = basename_len - 3;
|
||||
else
|
||||
search_len = basename_len;
|
||||
|
||||
ext = g_strrstr_len (basename, search_len, ".");
|
||||
|
||||
if (ext)
|
||||
ext = g_strdup (ext);
|
||||
|
||||
g_free (uri);
|
||||
g_free (basename);
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
@ -447,9 +447,23 @@ gimp_thumb_box_take_file (GimpThumbBox *box,
|
||||
|
||||
if (file)
|
||||
{
|
||||
gchar *basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
||||
GFileInfo *info;
|
||||
gchar *basename;
|
||||
|
||||
info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
|
||||
0, NULL, NULL);
|
||||
|
||||
if (info != NULL)
|
||||
basename =
|
||||
g_file_info_get_attribute_as_string (info,
|
||||
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
|
||||
else
|
||||
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
||||
|
||||
gtk_label_set_text (GTK_LABEL (box->filename), basename);
|
||||
g_free (basename);
|
||||
g_clear_object (&info);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -663,11 +677,23 @@ gimp_thumb_box_create_thumbnail (GimpThumbBox *box,
|
||||
GimpProgress *progress)
|
||||
{
|
||||
GimpThumbnail *thumb = gimp_imagefile_get_thumbnail (box->imagefile);
|
||||
GFileInfo *info;
|
||||
gchar *basename;
|
||||
|
||||
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
||||
info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
|
||||
0, NULL, NULL);
|
||||
|
||||
if (info != NULL)
|
||||
basename =
|
||||
g_file_info_get_attribute_as_string (info,
|
||||
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
|
||||
else
|
||||
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
||||
|
||||
gtk_label_set_text (GTK_LABEL (box->filename), basename);
|
||||
g_free (basename);
|
||||
g_clear_object (&info);
|
||||
|
||||
gimp_imagefile_set_file (box->imagefile, file);
|
||||
|
||||
|
Reference in New Issue
Block a user