[nautilus/gnome-3-20] Search popover: limit options to max 5 years



commit 2cc130d519b476db7d87c2b7b8b3d42ba62f88db
Author: Alexandru Pandelea <alexandru pandelea gmail com>
Date:   Wed Feb 24 14:16:31 2016 +0200

    Search popover: limit options to max 5 years
    
    The list displayed too many options for older dates.
    
    In order to limit this, the max_days variable was decreased to
    the number of days corresponding to 5 years
    
    The value of the step for months was updated to the proper value, 90.
    
    The days variable contained an unnecessary offset. To prevent it,
    for the first occurrence of each timeslice (month, week, year) there
    was added an if clause to remove the offset
    
    Due to limiting the max number of years displayed, there was removed
    (a now redundant) else from the function get_text_for_date_range.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762240

 libnautilus-private/nautilus-ui-utilities.c |    7 +-----
 src/nautilus-search-popover.c               |   28 +++++++++++++++-----------
 2 files changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/libnautilus-private/nautilus-ui-utilities.c b/libnautilus-private/nautilus-ui-utilities.c
index 786b55b..3099883 100644
--- a/libnautilus-private/nautilus-ui-utilities.c
+++ b/libnautilus-private/nautilus-ui-utilities.c
@@ -420,14 +420,9 @@ get_text_for_date_range (GPtrArray *date_range)
           /* months */
           normalized = days / 30;
         }
-      else if (days < 1825)
-        {
-          /* years */
-          normalized = days / 365;
-        }
       else
         {
-          /* after the first 5 years, jump at a 5-year pace */
+          /* years */
           normalized = days / 365;
         }
 
diff --git a/src/nautilus-search-popover.c b/src/nautilus-search-popover.c
index 27b2844..e51f01c 100644
--- a/src/nautilus-search-popover.c
+++ b/src/nautilus-search-popover.c
@@ -25,6 +25,8 @@
 #include <libnautilus-private/nautilus-ui-utilities.h>
 #include <libnautilus-private/nautilus-global-preferences.h>
 
+ #define SEARCH_FILTER_MAX_YEARS 5
+
 struct _NautilusSearchPopover
 {
   GtkPopover          parent;
@@ -378,7 +380,7 @@ fill_fuzzy_dates_listbox (NautilusSearchPopover *popover)
   days = 1;
   maximum_dt = g_date_time_new_from_unix_local (0);
   now = g_date_time_new_now_local ();
-  max_days = (g_date_time_get_year (now) - g_date_time_get_year (maximum_dt)) * 365;
+  max_days = SEARCH_FILTER_MAX_YEARS * 365;
   current_date = g_date_time_new_now_local ();
 
   /* Add the no date filter element first */
@@ -386,10 +388,12 @@ fill_fuzzy_dates_listbox (NautilusSearchPopover *popover)
   gtk_container_add (GTK_CONTAINER (popover->dates_listbox), row);
 
   /* This is a tricky loop. The main intention here is that each
-   * timeslice (day, week, month) have 2 or 3 entries. Years,
-   * however, are exceptions and should show many entries.
+   * timeslice (day, week, month) have 2 or 3 entries.
+   * 
+   * For the first appearance of each timeslice, there is made a
+   * check in order to be sure that there is no offset added to days.
    */
-  while (days < max_days)
+  while (days <= max_days)
     {
       gchar *label;
       gint normalized;
@@ -405,26 +409,26 @@ fill_fuzzy_dates_listbox (NautilusSearchPopover *popover)
         {
           /* weeks */
           normalized = days / 7;
+          if (normalized == 1)
+               days = 7;
           step = 7;
         }
       else if (days < 365)
         {
           /* months */
           normalized = days / 30;
-          step = 84;
+          if (normalized == 1)
+               days = 30;
+          step = 90;
         }
-      else if (days < 1825)
+      else
         {
           /* years */
           normalized = days / 365;
+          if (normalized == 1)
+               days = 365;
           step = 365;
         }
-      else
-        {
-          /* after the first 5 years, jump at a 5-year pace */
-          normalized = days / 365;
-          step = 1825;
-        }
 
       current_date = g_date_time_add_days (now, -days);
       date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);


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