[nautilus/636-default-sort-order-settings-not-respected-in-3-30-no-docs-no-ui-regression-since-3-26: 3/4] file: Centralize getting default sort order



commit ca5084b1439300a5445c1d0b52f11f7f6cc379c3
Author: António Fernandes <antoniof gnome org>
Date:   Thu Nov 29 00:14:31 2018 +0000

    file: Centralize getting default sort order
    
    nautilus_file_get_default_sort_type() has a misleading name. It doesn't
    actually get the default sort type for any folder, but only for certain
    special folders.
    
    For regular folders, the default comes from GSettings keys, but this is
    implemented in the views instead, with a lot of reduncant code.
    
    So, let's do that in nautilus_file_get_default_sort_type() directly,
    and clearly document it.

 src/nautilus-canvas-view.c          | 11 ++------
 src/nautilus-file.c                 | 54 +++++++++++++------------------------
 src/nautilus-file.h                 |  5 ++--
 src/nautilus-list-view.c            | 26 +++++++-----------
 src/nautilus-view-icon-controller.c | 10 +------
 5 files changed, 33 insertions(+), 73 deletions(-)
---
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index 4ee8d6ea3..ffbc59814 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -407,21 +407,14 @@ nautilus_canvas_view_get_directory_sort_by (NautilusCanvasView *canvas_view,
 static const SortCriterion *
 get_default_sort_order (NautilusFile *file)
 {
-    NautilusFileSortType sort_type, default_sort_order;
+    NautilusFileSortType sort_type;
     gboolean reversed;
 
-    default_sort_order = g_settings_get_enum (nautilus_preferences,
-                                              NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER);
-    reversed = g_settings_get_boolean (nautilus_preferences,
-                                       NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
-
-    /* If this is a special folder (e.g. search or recent), override the sort
-     * order and reversed flag with values appropriate for the folder */
     sort_type = nautilus_file_get_default_sort_type (file, &reversed);
 
     if (sort_type == NAUTILUS_FILE_SORT_NONE)
     {
-        sort_type = CLAMP (default_sort_order,
+        sort_type = CLAMP (sort_type,
                            NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
                            NAUTILUS_FILE_SORT_BY_ATIME);
     }
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index b9ae81e08..b39dd1d8e 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -8813,7 +8813,19 @@ get_attributes_for_default_sort_type (NautilusFile *file,
 
     return retval;
 }
-
+/**
+ * nautilus_file_get_default_sort_type:
+ * @file: A #NautilusFile representing a location
+ * @reversed: (out): Location to store whether the order is reversed by default.
+ *
+ * Gets which sort order applies by default for the provided locations.
+ *
+ * If @file is a location with special needs (e.g. Trash or Recent), the return
+ * value and @reversed flag are dictated by design. Otherwise, they stem from
+ * the "default-sort-order" and "default-sort-in-reverse-order" preference keys.
+ *
+ * Returns: The default #NautilusFileSortType for this @file.
+ */
 NautilusFileSortType
 nautilus_file_get_default_sort_type (NautilusFile *file,
                                      gboolean     *reversed)
@@ -8821,7 +8833,6 @@ nautilus_file_get_default_sort_type (NautilusFile *file,
     NautilusFileSortType retval;
     gboolean is_recent, is_download, is_trash, is_search, res;
 
-    retval = NAUTILUS_FILE_SORT_NONE;
     is_recent = is_download = is_trash = is_search = FALSE;
     res = get_attributes_for_default_sort_type (file, &is_recent, &is_download, &is_trash, &is_search);
 
@@ -8849,43 +8860,14 @@ nautilus_file_get_default_sort_type (NautilusFile *file,
             *reversed = res;
         }
     }
-
-    return retval;
-}
-
-const gchar *
-nautilus_file_get_default_sort_attribute (NautilusFile *file,
-                                          gboolean     *reversed)
-{
-    const gchar *retval;
-    gboolean is_recent, is_download, is_trash, is_search, res;
-
-    retval = NULL;
-    is_download = is_trash = is_search = FALSE;
-    res = get_attributes_for_default_sort_type (file, &is_recent, &is_download, &is_trash, &is_search);
-
-    if (res)
+    else
     {
-        if (is_recent)
-        {
-            retval = g_quark_to_string (attribute_recency_q);
-        }
-        else if (is_download)
-        {
-            retval = g_quark_to_string (attribute_date_modified_q);
-        }
-        else if (is_trash)
-        {
-            retval = g_quark_to_string (attribute_trashed_on_q);
-        }
-        else if (is_search)
-        {
-            retval = g_quark_to_string (attribute_search_relevance_q);
-        }
-
+        retval = g_settings_get_enum (nautilus_preferences,
+                                      NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER);
         if (reversed != NULL)
         {
-            *reversed = res;
+            *reversed = g_settings_get_boolean (nautilus_preferences,
+                                                NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
         }
     }
 
diff --git a/src/nautilus-file.h b/src/nautilus-file.h
index ce5f57846..5f120a874 100644
--- a/src/nautilus-file.h
+++ b/src/nautilus-file.h
@@ -52,7 +52,8 @@ typedef struct NautilusFile NautilusFile;
 typedef enum {
        /* These may be set as default-sort-order. When touching this, make sure to
         * keep the values in sync with the "org.gnome.nautilus.SortOrder" enum in the
-        * `data/org.gnome.nautilus.gschema.xml` schemas file.
+        * `data/org.gnome.nautilus.gschema.xml` schemas file, and the attributes[]
+        * array in `src/nautilus-list-view.c`.
         */
        NAUTILUS_FILE_SORT_NONE = 0, /* Formerly used for "manual" sorting. */
        NAUTILUS_FILE_SORT_BY_DISPLAY_NAME = 1,
@@ -426,8 +427,6 @@ gboolean                nautilus_file_is_local_or_fuse                  (Nautilu
 /* Comparing two file objects for sorting */
 NautilusFileSortType    nautilus_file_get_default_sort_type             (NautilusFile                   
*file,
                                                                         gboolean                       
*reversed);
-const gchar *           nautilus_file_get_default_sort_attribute        (NautilusFile                   
*file,
-                                                                        gboolean                       
*reversed);
 
 int                     nautilus_file_compare_for_sort                  (NautilusFile                   
*file_1,
                                                                         NautilusFile                   
*file_2,
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 9ea98383d..82f377570 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -129,9 +129,11 @@ static const gchar *
 get_default_sort_order (NautilusFile *file,
                         gboolean     *reversed)
 {
-    NautilusFileSortType default_sort_order;
-    gboolean default_sort_reversed;
-    const gchar *retval;
+    NautilusFileSortType sort_type;
+
+    /* This array makes the #NautilusFileSortType values correspond to the
+     * respective column attribute.
+     */
     const char *attributes[] =
     {
         "name",         /* is really "manually" which doesn't apply to lists */
@@ -140,24 +142,16 @@ get_default_sort_order (NautilusFile *file,
         "type",
         "date_modified",
         "date_accessed",
+        "starred",
         "trashed_on",
+        "search_relevance",
+        "recency",
         NULL
     };
 
-    retval = nautilus_file_get_default_sort_attribute (file, reversed);
-
-    if (retval == NULL)
-    {
-        default_sort_order = g_settings_get_enum (nautilus_preferences,
-                                                  NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER);
-        default_sort_reversed = g_settings_get_boolean (nautilus_preferences,
-                                                        NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
-
-        retval = attributes[default_sort_order];
-        *reversed = default_sort_reversed;
-    }
+    sort_type = nautilus_file_get_default_sort_type (file, reversed);
 
-    return retval;
+    return attributes[sort_type];
 }
 
 static void
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index f96efbd81..2a9f1c7e2 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -156,21 +156,13 @@ static const SortConstants *
 get_default_sort_order (NautilusFile *file)
 {
     NautilusFileSortType sort_type;
-    NautilusFileSortType default_sort_order;
     gboolean reversed;
 
-    default_sort_order = g_settings_get_enum (nautilus_preferences,
-                                              NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER);
-    reversed = g_settings_get_boolean (nautilus_preferences,
-                                       NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
-
-    /* If this is a special folder (e.g. search or recent), override the sort
-     * order and reversed flag with values appropriate for the folder */
     sort_type = nautilus_file_get_default_sort_type (file, &reversed);
 
     if (sort_type == NAUTILUS_FILE_SORT_NONE)
     {
-        sort_type = CLAMP (default_sort_order,
+        sort_type = CLAMP (sort_type,
                            NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
                            NAUTILUS_FILE_SORT_BY_ATIME);
     }


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