[glib/gio-thumbnail-sizes] file-info: Add a set of attributes for large thumbnails
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/gio-thumbnail-sizes] file-info: Add a set of attributes for large thumbnails
- Date: Thu, 22 Sep 2022 20:46:53 +0000 (UTC)
commit 44aa3e61c797f49019adcc83fb2e96cf1298e4b1
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Sep 22 16:29:41 2022 -0400
file-info: Add a set of attributes for large thumbnails
Some applications (eg., gnome-photos) really want a large thumbnail,
if one can be created. Simply falling back to a smaller one (probably
created by an old nautilus), without giving the application a chance
to create a bigger thumbnail, is undesirable because they will appear
fuzzy.
Therefore, at separate attribute sets for all the thumbnail sizes
that are supported in the spec: normal/large/xlarge/xxlarge.
docs/reference/gio/gio-sections-common.txt | 9 ++
gio/gfileinfo-priv.h | 9 ++
gio/gfileinfo.c | 9 ++
gio/gfileinfo.h | 131 ++++++++++++++++++++++++++++-
gio/glocalfileinfo.c | 110 ++++++++++++++++++------
5 files changed, 240 insertions(+), 28 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections-common.txt b/docs/reference/gio/gio-sections-common.txt
index a6ff920caa..0d77b45743 100644
--- a/docs/reference/gio/gio-sections-common.txt
+++ b/docs/reference/gio/gio-sections-common.txt
@@ -350,6 +350,15 @@ G_FILE_ATTRIBUTE_OWNER_GROUP
G_FILE_ATTRIBUTE_THUMBNAIL_PATH
G_FILE_ATTRIBUTE_THUMBNAILING_FAILED
G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID
+G_FILE_ATTRIBUTE_THUMBNAIL_PATH_LARGE
+G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_LARGE
+G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_LARGE
+G_FILE_ATTRIBUTE_THUMBNAIL_PATH_XLARGE
+G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XLARGE
+G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_XLARGE
+G_FILE_ATTRIBUTE_THUMBNAIL_PATH_XXLARGE
+G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XXLARGE
+G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_XXLARGE
G_FILE_ATTRIBUTE_PREVIEW_ICON
G_FILE_ATTRIBUTE_FILESYSTEM_SIZE
G_FILE_ATTRIBUTE_FILESYSTEM_FREE
diff --git a/gio/gfileinfo-priv.h b/gio/gfileinfo-priv.h
index 8fc085973b..4bbed98005 100644
--- a/gio/gfileinfo-priv.h
+++ b/gio/gfileinfo-priv.h
@@ -99,6 +99,15 @@
#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH (10485760 + 1)
#define G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED (10485760 + 2)
#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID (10485760 + 3)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_LARGE (10485760 + 4)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_LARGE (10485760 + 5)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_LARGE (10485760 + 6)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_XLARGE (10485760 + 7)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_XLARGE (10485760 + 8)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_XLARGE (10485760 + 9)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_XXLARGE (10485760 + 10)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_XXLARGE (10485760 + 11)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_XXLARGE (10485760 + 12)
#define G_FILE_ATTRIBUTE_ID_PREVIEW_ICON (11534336 + 1)
#define G_FILE_ATTRIBUTE_ID_FILESYSTEM_SIZE (12582912 + 1)
#define G_FILE_ATTRIBUTE_ID_FILESYSTEM_FREE (12582912 + 2)
diff --git a/gio/gfileinfo.c b/gio/gfileinfo.c
index f709bf4f1f..288a922865 100644
--- a/gio/gfileinfo.c
+++ b/gio/gfileinfo.c
@@ -265,6 +265,15 @@ ensure_attribute_hash (void)
REGISTER_ATTRIBUTE (THUMBNAIL_PATH);
REGISTER_ATTRIBUTE (THUMBNAILING_FAILED);
REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID);
+ REGISTER_ATTRIBUTE (THUMBNAIL_PATH_LARGE);
+ REGISTER_ATTRIBUTE (THUMBNAILING_FAILED_LARGE);
+ REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID_LARGE);
+ REGISTER_ATTRIBUTE (THUMBNAIL_PATH_XLARGE);
+ REGISTER_ATTRIBUTE (THUMBNAILING_FAILED_XLARGE);
+ REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID_XLARGE);
+ REGISTER_ATTRIBUTE (THUMBNAIL_PATH_XXLARGE);
+ REGISTER_ATTRIBUTE (THUMBNAILING_FAILED_XXLARGE);
+ REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID_XXLARGE);
REGISTER_ATTRIBUTE (PREVIEW_ICON);
REGISTER_ATTRIBUTE (FILESYSTEM_SIZE);
REGISTER_ATTRIBUTE (FILESYSTEM_FREE);
diff --git a/gio/gfileinfo.h b/gio/gfileinfo.h
index 28bddfebcd..025fda6f5b 100644
--- a/gio/gfileinfo.h
+++ b/gio/gfileinfo.h
@@ -916,7 +916,7 @@ typedef struct _GFileInfoClass GFileInfoClass;
/**
* G_FILE_ATTRIBUTE_THUMBNAIL_PATH:
*
- * A key in the "thumbnail" namespace for getting the path to the thumbnail
+ * A key in the "thumbnail" namespace for getting the path to the normal-size thumbnail
* image.
*
* Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING.
@@ -949,6 +949,135 @@ typedef struct _GFileInfoClass GFileInfoClass;
*/
#define G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID "thumbnail::is-valid" /* boolean */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAIL_PATH_LARGE:
+ *
+ * A key in the "thumbnail" namespace for getting the path to the large thumbnail
+ * image.
+ *
+ * Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAIL_PATH_LARGE "thumbnail::path-large" /* bytestring */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_LARGE:
+ *
+ * A key in the "thumbnail" namespace for checking if thumbnailing failed
+ * for the large image.
+ *
+ * This attribute is %TRUE if thumbnailing failed.
+ *
+ * Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BOOLEAN.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_LARGE "thumbnail::failed-large" /* boolean */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_LARGE:
+ *
+ * A key in the "thumbnail" namespace for checking whether the large
+ * thumbnail is outdated.
+ *
+ * This attribute is %TRUE if the large thumbnail is up-to-date with the file
+ * it represents, and %FALSE if the file has been modified since the thumbnail
+ * was generated.
+ *
+ * If %G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_LARGE is %TRUE and this attribute
+ * is %FALSE, it indicates that thumbnailing may be attempted again and may succeed.
+ *
+ * Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BOOLEAN.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_LARGE "thumbnail::is-valid-large" /* boolean */
+
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAIL_PATH_XLARGE:
+ *
+ * A key in the "thumbnail" namespace for getting the path to the x-large thumbnail
+ * image.
+ *
+ * Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAIL_PATH_XLARGE "thumbnail::path-xlarge" /* bytestring */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XLARGE:
+ *
+ * A key in the "thumbnail" namespace for checking if thumbnailing failed
+ * for the x-large image.
+ *
+ * This attribute is %TRUE if thumbnailing failed.
+ *
+ * Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BOOLEAN.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XLARGE "thumbnail::failed-xlarge" /* boolean */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_XLARGE:
+ *
+ * A key in the "thumbnail" namespace for checking whether the x-large
+ * thumbnail is outdated.
+ *
+ * This attribute is %TRUE if the x-large thumbnail is up-to-date with the file
+ * it represents, and %FALSE if the file has been modified since the thumbnail
+ * was generated.
+ *
+ * If %G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XLARGE is %TRUE and this attribute
+ * is %FALSE, it indicates that thumbnailing may be attempted again and may succeed.
+ *
+ * Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BOOLEAN.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_XLARGE "thumbnail::is-valid-xlarge" /* boolean */
+
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAIL_PATH_XXLARGE:
+ *
+ * A key in the "thumbnail" namespace for getting the path to the xx-large thumbnail
+ * image.
+ *
+ * Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAIL_PATH_XXLARGE "thumbnail::path-xxlarge" /* bytestring */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XXLARGE:
+ *
+ * A key in the "thumbnail" namespace for checking if thumbnailing failed
+ * for the xx-large image.
+ *
+ * This attribute is %TRUE if thumbnailing failed.
+ *
+ * Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BOOLEAN.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XXLARGE "thumbnail::failed-xxlarge" /* boolean */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_XXLARGE:
+ *
+ * A key in the "thumbnail" namespace for checking whether the xx-large
+ * thumbnail is outdated.
+ *
+ * This attribute is %TRUE if the x-large thumbnail is up-to-date with the file
+ * it represents, and %FALSE if the file has been modified since the thumbnail
+ * was generated.
+ *
+ * If %G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XXLARGE is %TRUE and this attribute
+ * is %FALSE, it indicates that thumbnailing may be attempted again and may succeed.
+ *
+ * Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BOOLEAN.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_XXLARGE "thumbnail::is-valid-xxlarge" /* boolean */
+
/* Preview */
/**
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index 6f186957ae..590422c63c 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -1418,16 +1418,58 @@ get_content_type (const char *basename,
}
+typedef enum {
+ THUMBNAIL_SIZE_NORMAL,
+ THUMBNAIL_SIZE_LARGE,
+ THUMBNAIL_SIZE_XLARGE,
+ THUMBNAIL_SIZE_XXLARGE
+} ThumbnailSize;
+
/* @stat_buf is the pre-calculated result of stat(path), or %NULL if that failed. */
static void
get_thumbnail_attributes (const char *path,
GFileInfo *info,
- const GLocalFileStat *stat_buf)
+ const GLocalFileStat *stat_buf,
+ ThumbnailSize size)
{
GChecksum *checksum;
+ const char *dirname;
char *uri;
char *filename;
char *basename;
+ guint32 failed_attr_id;
+ guint32 is_valid_attr_id;
+ guint32 path_attr_id;
+
+ switch (size)
+ {
+ case THUMBNAIL_SIZE_NORMAL:
+ dirname = "normal";
+ failed_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED;
+ is_valid_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID;
+ path_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH;
+ break;
+ case THUMBNAIL_SIZE_LARGE:
+ dirname = "large";
+ failed_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_LARGE;
+ is_valid_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_LARGE;
+ path_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_LARGE;
+ break;
+ case THUMBNAIL_SIZE_XLARGE:
+ dirname = "xlarge";
+ failed_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_XLARGE;
+ is_valid_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_XLARGE;
+ path_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_XLARGE;
+ break;
+ case THUMBNAIL_SIZE_XXLARGE:
+ dirname = "xxlarge";
+ failed_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_XXLARGE;
+ is_valid_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_XXLARGE;
+ path_attr_id = G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_XXLARGE;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
uri = g_filename_to_uri (path, NULL, NULL);
@@ -1438,45 +1480,32 @@ get_thumbnail_attributes (const char *path,
g_checksum_free (checksum);
filename = g_build_filename (g_get_user_cache_dir (),
- "thumbnails", "large", basename,
+ "thumbnails", dirname, basename,
NULL);
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
- _g_file_info_set_attribute_byte_string_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH, filename);
- _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID,
+ _g_file_info_set_attribute_byte_string_by_id (info, path_attr_id, filename);
+ _g_file_info_set_attribute_boolean_by_id (info, is_valid_attr_id,
thumbnail_verify (filename, uri, stat_buf));
}
else
{
g_free (filename);
filename = g_build_filename (g_get_user_cache_dir (),
- "thumbnails", "normal", basename,
+ "thumbnails", "fail",
+ "gnome-thumbnail-factory",
+ basename,
NULL);
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
- _g_file_info_set_attribute_byte_string_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH, filename);
- _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID,
+ _g_file_info_set_attribute_boolean_by_id (info, failed_attr_id, TRUE);
+ _g_file_info_set_attribute_boolean_by_id (info, is_valid_attr_id,
thumbnail_verify (filename, uri, stat_buf));
}
- else
- {
- g_free (filename);
- filename = g_build_filename (g_get_user_cache_dir (),
- "thumbnails", "fail",
- "gnome-thumbnail-factory",
- basename,
- NULL);
-
- if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
- {
- _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED, TRUE);
- _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID,
- thumbnail_verify (filename, uri, stat_buf));
- }
- }
}
+
g_free (basename);
g_free (filename);
g_free (uri);
@@ -2115,10 +2144,37 @@ _g_local_file_info_get (const char *basename,
_g_file_attribute_matcher_matches_id (attribute_matcher,
G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED))
{
- if (stat_ok)
- get_thumbnail_attributes (path, info, &statbuf);
- else
- get_thumbnail_attributes (path, info, NULL);
+ get_thumbnail_attributes (path, info, stat_ok ? &statbuf : NULL, THUMBNAIL_SIZE_NORMAL);
+ }
+
+ if (_g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_LARGE) ||
+ _g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_LARGE) ||
+ _g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_LARGE))
+ {
+ get_thumbnail_attributes (path, info, stat_ok ? &statbuf : NULL, THUMBNAIL_SIZE_LARGE);
+ }
+
+ if (_g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_XLARGE) ||
+ _g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_XLARGE) ||
+ _g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_XLARGE))
+ {
+ get_thumbnail_attributes (path, info, stat_ok ? &statbuf : NULL, THUMBNAIL_SIZE_XLARGE);
+ }
+
+ if (_g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_XXLARGE) ||
+ _g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_XXLARGE) ||
+ _g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_XXLARGE))
+ {
+ get_thumbnail_attributes (path, info, stat_ok ? &statbuf : NULL, THUMBNAIL_SIZE_XXLARGE);
}
vfs = g_vfs_get_default ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]