[nautilus/wip/csoriano/improve_list_view: 7/8] nautilus-file: implement smarter dates



commit dc7a73f8651ef916de6919b1b2d86777ef644e89
Author: Carlos Soriano <csoriano gnome org>
Date:   Mon Feb 16 12:00:31 2015 +0100

    nautilus-file: implement smarter dates
    
    Design request. Now we show the name of the day of the week if the file
    was modified in the last week.
    On the other hand, given that now we have more space to show details, we
    show the hour and minutes on the date.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744237

 libnautilus-private/nautilus-file.c |  153 ++++++++++++++++++++++-------------
 1 files changed, 97 insertions(+), 56 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index b4a9fca..6b83951 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -4657,26 +4657,6 @@ nautilus_file_get_trash_original_file_parent_as_string (NautilusFile *file)
        return NULL;
 }
 
-/*
- * Note to localizers: You can look at man strftime
- * for details on the format, but you should only use
- * the specifiers from the C standard, not extensions.
- * These include "%" followed by one of
- * "aAbBcdHIjmMpSUwWxXyYZ". There are two extensions
- * in the Nautilus version of strftime that can be
- * used (and match GNU extensions). Putting a "-"
- * between the "%" and any numeric directive will turn
- * off zero padding, and putting a "_" there will use
- * space padding instead of zero padding.
- */
-#define TODAY_TIME_FORMAT_24 N_("%R")
-#define TODAY_TIME_FORMAT N_("%-I:%M %P")
-#define THIS_MONTH_TIME_FORMAT N_("%b %-e")
-#define THIS_YEAR_TIME_FORMAT N_("%b %-e")
-#define ANYTIME_TIME_FORMAT N_("%b %-d %Y")
-#define FULL_FORMAT N_("%a, %b %e %Y %I:%M:%S %p")
-#define FULL_FORMAT_24 N_("%a, %b %e %Y %T")
-
 /**
  * nautilus_file_get_date_as_string:
  * 
@@ -4688,49 +4668,110 @@ nautilus_file_get_trash_original_file_parent_as_string (NautilusFile *file)
  * 
  **/
 static char *
-nautilus_file_get_date_as_string (NautilusFile *file, NautilusDateType date_type, gboolean compact)
+nautilus_file_get_date_as_string (NautilusFile     *file,
+                                  NautilusDateType  date_type,
+                                  gboolean          include_time,
+                                  gboolean          full_date)
 {
        time_t file_time_raw;
-       const char *format;
-       char *result = NULL;
-       GDateTime *date_time, *today;
-       int y, m, d;
-       int y_now, m_now, d_now;
-       GDesktopClockFormat value;
+       GDateTime *file_date, *now;
+       gint daysAgo;
        gboolean use_24;
+       gchar *format;
+       gchar *result;
 
-       if (!nautilus_file_get_date (file, date_type, &file_time_raw)) {
+       if (!nautilus_file_get_date (file, date_type, &file_time_raw))
                return NULL;
-       }
-
-       date_time = g_date_time_new_from_unix_local (file_time_raw);
 
-       g_date_time_get_ymd (date_time, &y, &m, &d);
+       file_date = g_date_time_new_from_unix_local (file_time_raw);
+       if (!full_date) {
+               now = g_date_time_new_now_local ();
 
-       today = g_date_time_new_now_local ();
-       g_date_time_get_ymd (today, &y_now, &m_now, &d_now);
-       g_date_time_unref (today);
+               daysAgo = g_date_time_difference (now, file_date) / (24 * 60 * 60 * 1000 * 1000L);
 
-       value = g_settings_get_enum (gnome_interface_preferences, "clock-format");
-       use_24 = value == G_DESKTOP_CLOCK_FORMAT_24H;
+               use_24 = g_settings_get_enum (gnome_interface_preferences, "clock-format") ==
+                        G_DESKTOP_CLOCK_FORMAT_24H;
 
-       if (!compact) {
-               format = use_24 ? FULL_FORMAT_24 : FULL_FORMAT;
-       } else if (y == y_now && m == m_now && d == d_now) {
-               format = use_24 ? TODAY_TIME_FORMAT_24 : TODAY_TIME_FORMAT;
-       } else if (y == y_now && m == m_now) {
-               format = THIS_MONTH_TIME_FORMAT;
-       } else if (y == y_now) {
-               format = THIS_YEAR_TIME_FORMAT;
+               // Show only the time if date is on today
+               if (daysAgo < 1) {
+                       if (use_24) {
+                               /* Translators: Time in 24h format */
+                               format = N_("%H\u2236%M");
+                       } else {
+                               /* Translators: Time in 12h format */
+                               format = N_("%l\u2236%M %p");
+                       }
+               }
+               // Show the word "Yesterday" and time if date is on yesterday
+               else if (daysAgo < 2) {
+                       if (include_time) {
+                               if (use_24) {
+                                       /* Translators: this is the word "Yesterday" followed by a
+                                        time string in 24h format. i.e. "Yesterday, 14:30" */
+                                       // xgettext:no-c-format
+                                       format = N_("Yesterday %H\u2236%M");
+                               } else {
+                                       /* Translators: this is the word "Yesterday" followed by a
+                                        time string in 12h format. i.e. "Yesterday, 2:30 pm" */
+                                       // xgettext:no-c-format
+                                       format = N_("Yesterday %l\u2236%M %p");
+                               }
+                       } else {
+                               format = N_("Yesterday");
+                       }
+               }
+               // Show a week day and time if date is in the last week
+               else if (daysAgo < 7) {
+                       if (include_time) {
+                               if (use_24) {
+                                       /* Translators: this is the week day name. i.e. "Monday" */
+                                       // xgettext:no-c-format
+                                       format = N_("%a %H\u2236%M");
+                               } else {
+                                       /* Translators: this is the week day name. i.e. "Monday" */
+                                       // xgettext:no-c-format
+                                       format = N_("%a %l\u2236%M %p");
+                               }
+                       } else {
+                               format = N_("%a");
+                       }
+               } else if (g_date_time_get_year (file_date) == g_date_time_get_year (now)) {
+                       if (include_time) {
+                               if (use_24) {
+                                       /* Translators: this is the week day name. i.e. "Monday" */
+                                       // xgettext:no-c-format
+                                       format = N_("%-e %H\u2236%M");
+                               } else {
+                                       /* Translators: this is the week day name. i.e. "Monday" */
+                                       // xgettext:no-c-format
+                                       format = N_("%-e %l\u2236%M %p");
+                               }
+                       } else {
+                               format = N_("%-e");
+                       }
+               } else {
+                       if (include_time) {
+                               if (use_24) {
+                                       /* Translators: this is the week day name. i.e. "Monday" */
+                                       // xgettext:no-c-format
+                                       format = N_("%-e %b %Y %H\u2236%M");
+                               } else {
+                                       /* Translators: this is the week day name. i.e. "Monday" */
+                                       // xgettext:no-c-format
+                                       format = N_("%-e %b %Y %l\u2236%M %p");
+                               }
+                       } else {
+                               format = N_("%-e %b %Y");
+                       }
+               }
        } else {
-               format = ANYTIME_TIME_FORMAT;
+               format = N_("%c");
        }
 
-       result = g_date_time_format (date_time, _(format));
-
-       g_date_time_unref (date_time);
+       result = g_date_time_format (file_date, format);
+       g_date_time_unref (file_date);
 
-       return result;
+        return  result;
 }
 
 static void
@@ -6188,32 +6229,32 @@ nautilus_file_get_string_attribute_q (NautilusFile *file, GQuark attribute_q)
        if (attribute_q == attribute_date_modified_q) {
                return nautilus_file_get_date_as_string (file, 
                                                         NAUTILUS_DATE_TYPE_MODIFIED,
-                                                        TRUE);
+                                                        FALSE);
        }
        if (attribute_q == attribute_date_modified_full_q) {
                return nautilus_file_get_date_as_string (file, 
                                                         NAUTILUS_DATE_TYPE_MODIFIED,
-                                                        FALSE);
+                                                        TRUE);
        }
        if (attribute_q == attribute_date_accessed_q) {
                return nautilus_file_get_date_as_string (file,
                                                         NAUTILUS_DATE_TYPE_ACCESSED,
-                                                        TRUE);
+                                                        FALSE);
        }
        if (attribute_q == attribute_date_accessed_full_q) {
                return nautilus_file_get_date_as_string (file,
                                                         NAUTILUS_DATE_TYPE_ACCESSED,
-                                                        FALSE);
+                                                        TRUE);
        }
        if (attribute_q == attribute_trashed_on_q) {
                return nautilus_file_get_date_as_string (file,
                                                         NAUTILUS_DATE_TYPE_TRASHED,
-                                                        TRUE);
+                                                        FALSE);
        }
        if (attribute_q == attribute_trashed_on_full_q) {
                return nautilus_file_get_date_as_string (file,
                                                         NAUTILUS_DATE_TYPE_TRASHED,
-                                                        FALSE);
+                                                        TRUE);
        }
        if (attribute_q == attribute_permissions_q) {
                return nautilus_file_get_permissions_as_string (file);


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