[glib/fix-gstrerror-warning: 3/4] gio: Add more thumbnail-related file attributes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/fix-gstrerror-warning: 3/4] gio: Add more thumbnail-related file attributes
- Date: Sun, 16 Oct 2022 23:47:25 +0000 (UTC)
commit 40155c579ec5ca754ae13c8d79b32288b8442b87
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Oct 11 15:05:51 2022 -0400
gio: Add more thumbnail-related file attributes
Add _NORMAL thumbnail attributes for normal-size
thumbnail properties, and make the unsized properties
once again carry information about the larged found
thumbnail, as it was before.
gio/gfileinfo-priv.h | 21 ++++++++------
gio/gfileinfo.c | 3 ++
gio/gfileinfo.h | 47 ++++++++++++++++++++++++++++--
gio/glocalfileinfo.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++------
4 files changed, 133 insertions(+), 19 deletions(-)
---
diff --git a/gio/gfileinfo-priv.h b/gio/gfileinfo-priv.h
index 4bbed98005..4d31818c3b 100644
--- a/gio/gfileinfo-priv.h
+++ b/gio/gfileinfo-priv.h
@@ -99,15 +99,18 @@
#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_THUMBNAIL_PATH_NORMAL (10485760 + 4)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_NORMAL (10485760 + 5)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_NORMAL (10485760 + 6)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_LARGE (10485760 + 7)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_LARGE (10485760 + 8)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_LARGE (10485760 + 9)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_XLARGE (10485760 + 10)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_XLARGE (10485760 + 11)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_XLARGE (10485760 + 12)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_XXLARGE (10485760 + 13)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_XXLARGE (10485760 + 14)
+#define G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_XXLARGE (10485760 + 15)
#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 288a922865..43a73ee386 100644
--- a/gio/gfileinfo.c
+++ b/gio/gfileinfo.c
@@ -265,6 +265,9 @@ ensure_attribute_hash (void)
REGISTER_ATTRIBUTE (THUMBNAIL_PATH);
REGISTER_ATTRIBUTE (THUMBNAILING_FAILED);
REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID);
+ REGISTER_ATTRIBUTE (THUMBNAIL_PATH_NORMAL);
+ REGISTER_ATTRIBUTE (THUMBNAILING_FAILED_NORMAL);
+ REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID_NORMAL);
REGISTER_ATTRIBUTE (THUMBNAIL_PATH_LARGE);
REGISTER_ATTRIBUTE (THUMBNAILING_FAILED_LARGE);
REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID_LARGE);
diff --git a/gio/gfileinfo.h b/gio/gfileinfo.h
index 025fda6f5b..45e881d21b 100644
--- a/gio/gfileinfo.h
+++ b/gio/gfileinfo.h
@@ -916,8 +916,8 @@ typedef struct _GFileInfoClass GFileInfoClass;
/**
* G_FILE_ATTRIBUTE_THUMBNAIL_PATH:
*
- * A key in the "thumbnail" namespace for getting the path to the normal-size thumbnail
- * image.
+ * A key in the "thumbnail" namespace for getting the path to the largest
+ * available thumbnail image.
*
* Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING.
**/
@@ -949,6 +949,49 @@ typedef struct _GFileInfoClass GFileInfoClass;
*/
#define G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID "thumbnail::is-valid" /* boolean */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAIL_PATH_NORMAL:
+ *
+ * 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.
+ *
+ * Since: 2.76
+ */
+#define G_FILE_ATTRIBUTE_THUMBNAIL_PATH_NORMAL "thumbnail::path-normal" /* bytestring */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_NORMAL:
+ *
+ * A key in the "thumbnail" namespace for checking if thumbnailing failed
+ * for the normal-size 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_NORMAL "thumbnail::failed-normal" /* boolean */
+/**
+ * G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_NORMAL:
+ *
+ * A key in the "thumbnail" namespace for checking whether the normal-size
+ * 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_NORMAL 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_NORMAL "thumbnail::is-valid-normal" /* boolean */
+
/**
* G_FILE_ATTRIBUTE_THUMBNAIL_PATH_LARGE:
*
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index 590422c63c..3997fe0d1f 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -1426,7 +1426,7 @@ typedef enum {
} ThumbnailSize;
/* @stat_buf is the pre-calculated result of stat(path), or %NULL if that failed. */
-static void
+static gboolean
get_thumbnail_attributes (const char *path,
GFileInfo *info,
const GLocalFileStat *stat_buf,
@@ -1440,6 +1440,7 @@ get_thumbnail_attributes (const char *path,
guint32 failed_attr_id;
guint32 is_valid_attr_id;
guint32 path_attr_id;
+ gboolean success = FALSE;
switch (size)
{
@@ -1485,9 +1486,9 @@ get_thumbnail_attributes (const char *path,
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
+ success = thumbnail_verify (filename, uri, stat_buf);
_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));
+ _g_file_info_set_attribute_boolean_by_id (info, is_valid_attr_id, success);
}
else
{
@@ -1500,15 +1501,62 @@ get_thumbnail_attributes (const char *path,
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
+ success = thumbnail_verify (filename, uri, stat_buf);
_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));
+ _g_file_info_set_attribute_boolean_by_id (info, is_valid_attr_id, success);
}
}
g_free (basename);
g_free (filename);
g_free (uri);
+
+ return success;
+}
+
+static void
+copy_thumbnail_attributes (GFileInfo *info,
+ ThumbnailSize size)
+{
+ const char *failed_attr_id;
+ const char *is_valid_attr_id;
+ const char *path_attr_id;
+
+ switch (size)
+ {
+ case THUMBNAIL_SIZE_NORMAL:
+ failed_attr_id = G_FILE_ATTRIBUTE_THUMBNAILING_FAILED;
+ is_valid_attr_id = G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID;
+ path_attr_id = G_FILE_ATTRIBUTE_THUMBNAIL_PATH;
+ break;
+ case THUMBNAIL_SIZE_LARGE:
+ failed_attr_id = G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_LARGE;
+ is_valid_attr_id = G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_LARGE;
+ path_attr_id = G_FILE_ATTRIBUTE_THUMBNAIL_PATH_LARGE;
+ break;
+ case THUMBNAIL_SIZE_XLARGE:
+ failed_attr_id = G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XLARGE;
+ is_valid_attr_id = G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_XLARGE;
+ path_attr_id = G_FILE_ATTRIBUTE_THUMBNAIL_PATH_XLARGE;
+ break;
+ case THUMBNAIL_SIZE_XXLARGE:
+ failed_attr_id = G_FILE_ATTRIBUTE_THUMBNAILING_FAILED_XXLARGE;
+ is_valid_attr_id = G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID_XXLARGE;
+ path_attr_id = G_FILE_ATTRIBUTE_THUMBNAIL_PATH_XXLARGE;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ if (g_file_info_has_attribute (info, failed_attr_id))
+ g_file_info_set_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH,
+ g_file_info_get_attribute_byte_string (info, failed_attr_id));
+ if (g_file_info_has_attribute (info, path_attr_id))
+ g_file_info_set_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH,
+ g_file_info_get_attribute_byte_string (info, path_attr_id));
+ if (g_file_info_has_attribute (info, is_valid_attr_id))
+ g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID,
+ g_file_info_get_attribute_boolean (info, is_valid_attr_id));
}
#ifdef G_OS_WIN32
@@ -2138,11 +2186,11 @@ _g_local_file_info_get (const char *basename,
get_xattrs (path, FALSE, info, attribute_matcher, (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS) == 0);
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
- G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH) ||
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH_NORMAL) ||
_g_file_attribute_matcher_matches_id (attribute_matcher,
- G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID) ||
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID_NORMAL) ||
_g_file_attribute_matcher_matches_id (attribute_matcher,
- G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED))
+ G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED_NORMAL))
{
get_thumbnail_attributes (path, info, stat_ok ? &statbuf : NULL, THUMBNAIL_SIZE_NORMAL);
}
@@ -2177,6 +2225,23 @@ _g_local_file_info_get (const char *basename,
get_thumbnail_attributes (path, info, stat_ok ? &statbuf : NULL, THUMBNAIL_SIZE_XXLARGE);
}
+ if (_g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH) ||
+ _g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID) ||
+ _g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED))
+ {
+ for (int size = THUMBNAIL_SIZE_XXLARGE; size >= THUMBNAIL_SIZE_NORMAL; size--)
+ {
+ if (get_thumbnail_attributes (path, info, stat_ok ? &statbuf : NULL, size))
+ {
+ copy_thumbnail_attributes (info, size);
+ break;
+ }
+ }
+ }
+
vfs = g_vfs_get_default ();
class = G_VFS_GET_CLASS (vfs);
if (class->local_file_add_info)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]