[nautilus] ui-utilities: clarify date label



commit 01476a1e9acdea7a8e5a14ca9a7394acd8dc9263
Author: Monica Baluna <monicamariabaluna gmail com>
Date:   Wed Nov 2 18:27:28 2016 +0200

    ui-utilities: clarify date label
    
    Date label does not point out that nautilus searches for files modified or used
    after that date. In order to fix this, prepend "Since" to the date label.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767400

 src/nautilus-query-editor.c   |    2 +-
 src/nautilus-search-popover.c |    4 ++--
 src/nautilus-ui-utilities.c   |   36 +++++++++++++++++++++++-------------
 src/nautilus-ui-utilities.h   |    3 ++-
 4 files changed, 28 insertions(+), 17 deletions(-)
---
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index b909ea9..54f2a23 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -493,7 +493,7 @@ search_popover_date_range_changed_cb (NautilusSearchPopover *popover,
     {
         g_autofree gchar *text_for_date_range = NULL;
 
-        text_for_date_range = get_text_for_date_range (date_range);
+        text_for_date_range = get_text_for_date_range (date_range, TRUE);
         gd_tagged_entry_tag_set_label (priv->date_range_tag,
                                        text_for_date_range);
         gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
diff --git a/src/nautilus-search-popover.c b/src/nautilus-search-popover.c
index d68bdda..db95a2b 100644
--- a/src/nautilus-search-popover.c
+++ b/src/nautilus-search-popover.c
@@ -443,7 +443,7 @@ fill_fuzzy_dates_listbox (NautilusSearchPopover *popover)
         date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);
         g_ptr_array_add (date_range, g_date_time_ref (current_date));
         g_ptr_array_add (date_range, g_date_time_ref (now));
-        label = get_text_for_date_range (date_range);
+        label = get_text_for_date_range (date_range, FALSE);
         row = create_row_for_label (label, normalized == 1);
         g_object_set_data_full (G_OBJECT (row),
                                 "date",
@@ -620,7 +620,7 @@ update_date_label (NautilusSearchPopover *popover,
         end_date = g_ptr_array_index (date_range, 0);
         days = g_date_time_difference (end_date, initial_date) / G_TIME_SPAN_DAY;
 
-        label = get_text_for_date_range (date_range);
+        label = get_text_for_date_range (date_range, TRUE);
 
         gtk_entry_set_text (GTK_ENTRY (popover->date_entry), days < 1 ? label : "");
 
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index e8fdab8..07aca02 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -369,32 +369,40 @@ nautilus_file_date_in_between (guint64    unix_file_time,
 }
 
 static const gchar *
-get_text_for_days_ago (gint days)
+get_text_for_days_ago (gint     days,
+                       gboolean prefix_with_since)
 {
     if (days < 7)
     {
         /* days */
-        return ngettext ("%d day ago", "%d days ago", days);
+        return prefix_with_since ?
+               ngettext ("Since %d day ago", "Since %d days ago", days) :
+               ngettext ("%d day ago", "%d days ago", days);
     }
-    else if (days < 30)
+    if (days < 30)
     {
         /* weeks */
-        return ngettext ("Last week", "%d weeks ago", days / 7);
+        return prefix_with_since ?
+               ngettext ("Since last week", "Since %d weeks ago", days / 7) :
+               ngettext ("Last week", "%d weeks ago", days / 7);
     }
-    else if (days < 365)
+    if (days < 365)
     {
         /* months */
-        return ngettext ("Last month", "%d months ago", days / 30);
-    }
-    else
-    {
-        /* years */
-        return ngettext ("Last year", "%d years ago", days / 365);
+        return prefix_with_since ?
+               ngettext ("Since last month", "Since %d months ago", days / 30) :
+               ngettext ("Last month", "%d months ago", days / 30);
     }
+
+    /* years */
+    return prefix_with_since ?
+           ngettext ("Since last year", "Since %d years ago", days / 365) :
+           ngettext ("Last year", "%d years ago", days / 365);
 }
 
 gchar *
-get_text_for_date_range (GPtrArray *date_range)
+get_text_for_date_range (GPtrArray *date_range,
+                         gboolean   prefix_with_since)
 {
     gint days;
     gint normalized;
@@ -442,7 +450,9 @@ get_text_for_date_range (GPtrArray *date_range)
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
-        label = g_strdup_printf (get_text_for_days_ago (days), normalized);
+        label = g_strdup_printf (get_text_for_days_ago (days,
+                                                        prefix_with_since),
+                                 normalized);
 #pragma GCC diagnostic pop
     }
 
diff --git a/src/nautilus-ui-utilities.h b/src/nautilus-ui-utilities.h
index aa90424..2f7436e 100644
--- a/src/nautilus-ui-utilities.h
+++ b/src/nautilus-ui-utilities.h
@@ -46,6 +46,7 @@ void   nautilus_ui_frame_video                     (GdkPixbuf        **pixbuf);
 gboolean   nautilus_file_date_in_between           (guint64           file_unix_time,
                                                     GDateTime         *initial_date,
                                                     GDateTime         *end_date);
-gchar*     get_text_for_date_range                 (GPtrArray         *date_range);
+gchar*     get_text_for_date_range                 (GPtrArray         *date_range,
+                                                    gboolean           prefix_with_since);
 
 #endif /* NAUTILUS_UI_UTILITIES_H */


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