[gnome-photos] photos-item-manager: Sort photos by creation time first



commit 34900c5f6b3aebaefe182e1d967d48c98592b189
Author: Cédric Bellegarde <cedric bellegarde adishatz org>
Date:   Thu May 6 13:18:53 2021 +0200

    photos-item-manager: Sort photos by creation time first
    
    Importing photos from random devices can break sorting when using
    modification time.
    
    Fallback to modification time if creation time absent.
    
    Fix #53

 src/photos-item-manager.c  | 18 ++++++++++++------
 src/photos-query-builder.c |  2 +-
 2 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 85b9830b..b6102a84 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -1015,15 +1015,21 @@ photos_item_manager_sort_func (gconstpointer a, gconstpointer b, gpointer user_d
   PhotosBaseItem *item_a = PHOTOS_BASE_ITEM ((gpointer) a);
   PhotosBaseItem *item_b = PHOTOS_BASE_ITEM ((gpointer) b);
   gint ret_val;
-  gint64 mtime_a;
-  gint64 mtime_b;
+  gint64 time_a;
+  gint64 time_b;
 
-  mtime_a = photos_base_item_get_mtime (item_a);
-  mtime_b = photos_base_item_get_mtime (item_b);
+  time_a = photos_base_item_get_date_created (item_a);
+  time_b = photos_base_item_get_date_created (item_b);
 
-  if (mtime_a > mtime_b)
+  /* if creation time is missing, we use modification time */
+  if (time_a < 0)
+    time_a = photos_base_item_get_mtime (item_a);
+  if (time_b < 0)
+    time_b = photos_base_item_get_mtime (item_b);
+
+  if (time_a > time_b)
     ret_val = -1;
-  else if (mtime_a == mtime_b)
+  else if (time_a == time_b)
     ret_val = 0;
   else
     ret_val = 1;
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index 4a24100d..e0e88fd1 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -185,7 +185,7 @@ photos_query_builder_query (PhotosSearchContextState *state,
                                          "collections_filter", COLLECTIONS_FILTER,
                                          "item_where", item_mngr_where == NULL ? "" : item_mngr_where,
                                          "miner_files_name", miner_files_name,
-                                         "order", "ORDER BY DESC (?mtime)",
+                                         "order", "ORDER BY DESC (?ctime) DESC (?mtime)",
                                          "offset_limit", offset_limit ? offset_limit : "",
                                          "projection", projection,
                                          "projection_dbus", projection_database,


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