[nautilus/wip/antoniof/creation-time-attr: 19/20] file: Add "date_created" attribute




commit 71f057c3efd35a30b9f1bd608455452d4418bed5
Author: António Fernandes <antoniof gnome org>
Date:   Sat Aug 22 11:04:26 2020 +0100

    file: Add "date_created" attribute
    
    GIO 2.66 introduces support for Linux statx stx_btime.[0]
    
    Let's add support for this attribute in our file models, required for
    adding it to UI: https://gitlab.gnome.org/GNOME/nautilus/-/issues/1566
    
    [0] https://gitlab.gnome.org/GNOME/glib/-/commit/a396fa9027bf9aaab0697789fe38efec53b09431

 src/nautilus-file-private.h |  1 +
 src/nautilus-file.c         | 65 ++++++++++++++++++++++++++++++++++++++++++---
 src/nautilus-file.h         |  8 +++++-
 src/nautilus-list-view.c    |  1 +
 src/nautilus-vfs-file.c     | 16 +++++++++++
 5 files changed, 87 insertions(+), 4 deletions(-)
---
diff --git a/src/nautilus-file-private.h b/src/nautilus-file-private.h
index ed9725b23..831ed8d44 100644
--- a/src/nautilus-file-private.h
+++ b/src/nautilus-file-private.h
@@ -67,6 +67,7 @@ struct NautilusFileDetails
        
        time_t atime; /* 0 is unknown */
        time_t mtime; /* 0 is unknown */
+       time_t btime; /* 0 is unknown */
        
        char *symlink_name;
        
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index 3ba887e8d..23cd5c229 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -144,6 +144,9 @@ static GQuark attribute_name_q,
               attribute_accessed_date_q,
               attribute_date_accessed_q,
               attribute_date_accessed_full_q,
+              attribute_creation_date_q,
+              attribute_date_created_q,
+              attribute_date_created_full_q,
               attribute_mime_type_q,
               attribute_size_detail_q,
               attribute_deep_size_q,
@@ -554,6 +557,7 @@ nautilus_file_clear_info (NautilusFile *file)
     file->details->sort_order = 0;
     file->details->mtime = 0;
     file->details->atime = 0;
+    file->details->btime = 0;
     file->details->trash_time = 0;
     file->details->recency = 0;
     g_free (file->details->symlink_name);
@@ -2442,7 +2446,7 @@ update_info_internal (NautilusFile *file,
     int uid, gid;
     goffset size;
     int sort_order;
-    time_t atime, mtime;
+    time_t atime, mtime, btime;
     time_t trash_time;
     time_t recency;
     GTimeVal g_trash_time;
@@ -2774,6 +2778,7 @@ update_info_internal (NautilusFile *file,
 
     atime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
     mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+    btime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CREATED);
     if (file->details->atime != atime ||
         file->details->mtime != mtime)
     {
@@ -2786,6 +2791,7 @@ update_info_internal (NautilusFile *file,
     }
     file->details->atime = atime;
     file->details->mtime = mtime;
+    file->details->btime = btime;
 
     if (file->details->thumbnail != NULL &&
         file->details->thumbnail_mtime != 0 &&
@@ -3163,6 +3169,12 @@ get_time (NautilusFile     *file,
         }
         break;
 
+        case NAUTILUS_DATE_TYPE_CREATED:
+        {
+            time = file->details->btime;
+        }
+        break;
+
         case NAUTILUS_DATE_TYPE_TRASHED:
         {
             time = file->details->trash_time;
@@ -3738,6 +3750,16 @@ nautilus_file_compare_for_sort (NautilusFile         *file_1,
             }
             break;
 
+            case NAUTILUS_FILE_SORT_BY_BTIME:
+            {
+                result = compare_by_time (file_1, file_2, NAUTILUS_DATE_TYPE_CREATED);
+                if (result == 0)
+                {
+                    result = compare_by_full_path (file_1, file_2);
+                }
+            }
+            break;
+
             case NAUTILUS_FILE_SORT_BY_TRASHED_TIME:
             {
                 result = compare_by_time (file_1, file_2, NAUTILUS_DATE_TYPE_TRASHED);
@@ -3843,6 +3865,13 @@ nautilus_file_compare_for_sort_by_attribute_q   (NautilusFile *file_1,
                                                directories_first,
                                                reversed);
     }
+    else if (attribute == attribute_creation_date_q || attribute == attribute_date_created_q || attribute == 
attribute_date_created_full_q)
+    {
+        return nautilus_file_compare_for_sort (file_1, file_2,
+                                               NAUTILUS_FILE_SORT_BY_BTIME,
+                                               directories_first,
+                                               reversed);
+    }
     else if (attribute == attribute_trashed_on_q || attribute == attribute_trashed_on_full_q)
     {
         return nautilus_file_compare_for_sort (file_1, file_2,
@@ -5386,6 +5415,7 @@ nautilus_file_get_date (NautilusFile     *file,
 
     g_return_val_if_fail (date_type == NAUTILUS_DATE_TYPE_ACCESSED
                           || date_type == NAUTILUS_DATE_TYPE_MODIFIED
+                          || date_type == NAUTILUS_DATE_TYPE_CREATED
                           || date_type == NAUTILUS_DATE_TYPE_TRASHED
                           || date_type == NAUTILUS_DATE_TYPE_RECENCY,
                           FALSE);
@@ -5861,6 +5891,12 @@ nautilus_file_get_atime (NautilusFile *file)
     return file->details->atime;
 }
 
+time_t
+nautilus_file_get_btime (NautilusFile *file)
+{
+    return file->details->btime;
+}
+
 time_t
 nautilus_file_get_recency (NautilusFile *file)
 {
@@ -7144,8 +7180,8 @@ nautilus_file_get_deep_directory_count_as_string (NautilusFile *file)
  * @file: NautilusFile representing the file in question.
  * @attribute_name: The name of the desired attribute. The currently supported
  * set includes "name", "type", "detailed_type", "mime_type", "size", "deep_size", "deep_directory_count",
- * "deep_file_count", "deep_total_count", "date_modified", "date_accessed",
- * "date_modified_full", "date_accessed_full",
+ * "deep_file_count", "deep_total_count", "date_modified", "date_accessed", "date_created",
+ * "date_modified_full", "date_accessed_full", "date_created_full",
  * "owner", "group", "permissions", "octal_permissions", "uri", "where",
  * "link_target", "volume", "free_space", "selinux_context", "trashed_on", "trashed_on_full", 
"trashed_orig_path",
  * "recency"
@@ -7234,6 +7270,18 @@ nautilus_file_get_string_attribute_q (NautilusFile *file,
                                                  NAUTILUS_DATE_TYPE_ACCESSED,
                                                  NAUTILUS_DATE_FORMAT_FULL);
     }
+    if (attribute_q == attribute_date_created_q)
+    {
+        return nautilus_file_get_date_as_string (file,
+                                                 NAUTILUS_DATE_TYPE_CREATED,
+                                                 NAUTILUS_DATE_FORMAT_REGULAR);
+    }
+    if (attribute_q == attribute_date_created_full_q)
+    {
+        return nautilus_file_get_date_as_string (file,
+                                                 NAUTILUS_DATE_TYPE_CREATED,
+                                                 NAUTILUS_DATE_FORMAT_FULL);
+    }
     if (attribute_q == attribute_trashed_on_q)
     {
         return nautilus_file_get_date_as_string (file,
@@ -7417,6 +7465,11 @@ nautilus_file_get_string_attribute_with_default_q (NautilusFile *file,
         /* If n/a */
         return g_strdup ("");
     }
+    if (attribute_q == attribute_date_created_full_q)
+    {
+        /* If n/a */
+        return g_strdup ("—");
+    }
 
     /* Fallback, use for both unknown attributes and attributes
      * for which we have no more appropriate default.
@@ -7441,6 +7494,9 @@ nautilus_file_is_date_sort_attribute_q (GQuark attribute_q)
         attribute_q == attribute_accessed_date_q ||
         attribute_q == attribute_date_accessed_q ||
         attribute_q == attribute_date_accessed_full_q ||
+        attribute_q == attribute_creation_date_q ||
+        attribute_q == attribute_date_created_q ||
+        attribute_q == attribute_date_created_full_q ||
         attribute_q == attribute_trashed_on_q ||
         attribute_q == attribute_trashed_on_full_q ||
         attribute_q == attribute_recency_q)
@@ -9215,6 +9271,9 @@ nautilus_file_class_init (NautilusFileClass *class)
     attribute_accessed_date_q = g_quark_from_static_string ("accessed_date");
     attribute_date_accessed_q = g_quark_from_static_string ("date_accessed");
     attribute_date_accessed_full_q = g_quark_from_static_string ("date_accessed_full");
+    attribute_creation_date_q = g_quark_from_static_string ("creation_date");
+    attribute_date_created_q = g_quark_from_static_string ("date_created");
+    attribute_date_created_full_q = g_quark_from_static_string ("date_created_full");
     attribute_mime_type_q = g_quark_from_static_string ("mime_type");
     attribute_size_detail_q = g_quark_from_static_string ("size_detail");
     attribute_deep_size_q = g_quark_from_static_string ("deep_size");
diff --git a/src/nautilus-file.h b/src/nautilus-file.h
index 2164808ca..ab2ebdb31 100644
--- a/src/nautilus-file.h
+++ b/src/nautilus-file.h
@@ -67,7 +67,11 @@ typedef enum {
         */
        NAUTILUS_FILE_SORT_BY_TRASHED_TIME,
        NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE,
-       NAUTILUS_FILE_SORT_BY_RECENCY
+       NAUTILUS_FILE_SORT_BY_RECENCY,
+
+       /* The following is not used for sorting yet.
+        */
+       NAUTILUS_FILE_SORT_BY_BTIME
 } NautilusFileSortType;        
 
 typedef enum {
@@ -196,6 +200,7 @@ gboolean                nautilus_file_can_get_size                      (Nautilu
 goffset                 nautilus_file_get_size                          (NautilusFile                   
*file);
 time_t                  nautilus_file_get_mtime                         (NautilusFile                   
*file);
 time_t                  nautilus_file_get_atime                         (NautilusFile                   
*file);
+time_t                  nautilus_file_get_btime                         (NautilusFile                   
*file);
 time_t                  nautilus_file_get_recency                       (NautilusFile                   
*file);
 time_t                  nautilus_file_get_trash_time                    (NautilusFile                   
*file);
 GFileType               nautilus_file_get_file_type                     (NautilusFile                   
*file);
@@ -529,6 +534,7 @@ struct NautilusFile {
 typedef enum {
        NAUTILUS_DATE_TYPE_MODIFIED,
        NAUTILUS_DATE_TYPE_ACCESSED,
+       NAUTILUS_DATE_TYPE_CREATED,
        NAUTILUS_DATE_TYPE_TRASHED,
        NAUTILUS_DATE_TYPE_RECENCY
 } NautilusDateType;
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 66e3373e2..b706a977d 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -146,6 +146,7 @@ get_default_sort_order (NautilusFile *file,
         "trashed_on",
         "search_relevance",
         "recency",
+        "date_created", /* Not used yet */
         NULL
     };
 
diff --git a/src/nautilus-vfs-file.c b/src/nautilus-vfs-file.c
index 66dff20a2..ccbbc3536 100644
--- a/src/nautilus-vfs-file.c
+++ b/src/nautilus-vfs-file.c
@@ -225,11 +225,13 @@ vfs_file_get_date (NautilusFile     *file,
 {
     time_t atime;
     time_t mtime;
+    time_t btime;
     time_t recency;
     time_t trash_time;
 
     atime = nautilus_file_get_atime (file);
     mtime = nautilus_file_get_mtime (file);
+    btime = nautilus_file_get_btime (file);
     recency = nautilus_file_get_recency (file);
     trash_time = nautilus_file_get_trash_time (file);
 
@@ -263,6 +265,20 @@ vfs_file_get_date (NautilusFile     *file,
             return TRUE;
         }
 
+        case NAUTILUS_DATE_TYPE_CREATED:
+        {
+            /* Before we have info on a file, the date is unknown. */
+            if (btime == 0)
+            {
+                return FALSE;
+            }
+            if (date != NULL)
+            {
+                *date = btime;
+            }
+            return TRUE;
+        }
+
         case NAUTILUS_DATE_TYPE_TRASHED:
         {
             /* Before we have info on a file, the date is unknown. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]