[nautilus/wip/csoriano/improve_list_view: 16/16] nautilus-list-view: add a modified column with time



commit 05734a8fd9dbf913daa2a5f6ed5b81fa056fc3da
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Feb 17 10:35:20 2015 +0100

    nautilus-list-view: add a modified column with time
    
    It is useful for cases like a folder with pictures from the
    same day.

 libnautilus-private/nautilus-column-utilities.c |    9 ++
 libnautilus-private/nautilus-file.c             |  117 ++++++++++++++++++----
 2 files changed, 104 insertions(+), 22 deletions(-)
---
diff --git a/libnautilus-private/nautilus-column-utilities.c b/libnautilus-private/nautilus-column-utilities.c
index 542be34..da8a1ab 100644
--- a/libnautilus-private/nautilus-column-utilities.c
+++ b/libnautilus-private/nautilus-column-utilities.c
@@ -39,6 +39,7 @@ static const char *default_column_order[] = {
        "permissions",
        "mime_type",
        "where",
+       "date_modified_with_time",
        "date_modified",
        "date_accessed",
        NULL
@@ -128,6 +129,14 @@ get_builtin_columns (void)
                                               "label", _("Location"),
                                               "description", _("The location of the file."),
                                               NULL));
+       columns = g_list_append (columns,
+                                g_object_new (NAUTILUS_TYPE_COLUMN,
+                                              "name", "date_modified_with_time",
+                                              "attribute", "date_modified_with_time",
+                                              "label", _("Modified - Time"),
+                                              "description", _("The date the file was modified."),
+                                              "xalign", 1.0,
+                                              NULL));
 
        return columns;
 }
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 5b8b9d2..64e7a2c 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -103,6 +103,12 @@ typedef enum {
        SHOW_HIDDEN = 1 << 0,
 } FilterOptions;
 
+typedef enum {
+       NAUTILUS_DATE_FORMAT_REGULAR = 0,
+       NAUTILUS_DATE_FORMAT_REGULAR_WITH_TIME = 1,
+       NAUTILUS_DATE_FORMAT_FULL = 2,
+} NautilusDateFormat;
+
 typedef void (* ModifyListFunction) (GList **list, NautilusFile *file);
 
 enum {
@@ -128,6 +134,7 @@ static GQuark attribute_name_q,
        attribute_modification_date_q,
        attribute_date_modified_q,
        attribute_date_modified_full_q,
+       attribute_date_modified_with_time_q,
        attribute_accessed_date_q,
        attribute_date_accessed_q,
        attribute_date_accessed_full_q,
@@ -3227,7 +3234,7 @@ nautilus_file_compare_for_sort_by_attribute_q   (NautilusFile
                                                       NAUTILUS_FILE_SORT_BY_TYPE,
                                                       directories_first,
                                                       reversed);
-       } else if (attribute == attribute_modification_date_q || attribute == attribute_date_modified_q || 
attribute == attribute_date_modified_full_q) {
+       } else if (attribute == attribute_modification_date_q || attribute == attribute_date_modified_q || 
attribute == attribute_date_modified_with_time_q || attribute == attribute_date_modified_full_q) {
                return nautilus_file_compare_for_sort (file_1, file_2,
                                                       NAUTILUS_FILE_SORT_BY_MTIME,
                                                       directories_first,
@@ -4668,9 +4675,9 @@ 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          full_date)
+nautilus_file_get_date_as_string (NautilusFile       *file,
+                                  NautilusDateType    date_type,
+                                  NautilusDateFormat  date_format)
 {
        time_t file_time_raw;
        GDateTime *file_date, *now;
@@ -4683,7 +4690,7 @@ nautilus_file_get_date_as_string (NautilusFile     *file,
                return NULL;
 
        file_date = g_date_time_new_from_unix_local (file_time_raw);
-       if (!full_date) {
+       if (date_format != NAUTILUS_DATE_FORMAT_FULL) {
                now = g_date_time_new_now_local ();
 
                daysAgo = g_date_time_difference (now, file_date) / (24 * 60 * 60 * 1000 * 1000L);
@@ -4703,24 +4710,83 @@ nautilus_file_get_date_as_string (NautilusFile     *file,
                }
                // Show the word "Yesterday" and time if date is on yesterday
                else if (daysAgo < 2) {
+                       if (date_format == NAUTILUS_DATE_FORMAT_REGULAR) {
                                // xgettext:no-c-format
                                format = N_("Yesterday");
+                       } else {
+                               if (use_24) {
+                                       /* Translators: this is the word Yesterday followed by
+                                        * a time in 24h format. i.e. "Yesterday 23:04" */
+                                       // xgettext:no-c-format
+                                       format = N_("Yesterday %H\u2236%M");
+                               } else {
+                                       /* Translators: this is the word Yesterday followed by
+                                        * a time in 12h format. i.e. "Yesterday 9:04 PM" */
+                                       // xgettext:no-c-format
+                                       format = N_("Yesterday %l\u2236%M %p");
+                               }
+                       }
                }
                // Show a week day and time if date is in the last week
                else if (daysAgo < 7) {
-                       /* Translators: this is the week day name. i.e. "Monday" */
-                       // xgettext:no-c-format
-                       format = N_("%a");
+                       if (date_format == NAUTILUS_DATE_FORMAT_REGULAR) {
+                               // xgettext:no-c-format
+                               format = N_("%a");
+                       } else {
+                               if (use_24) {
+                                       /* Translators: this is the name of the week day followed by
+                                        * a time in 24h format. i.e. "Monday 23:04" */
+                                       // xgettext:no-c-format
+                                       format = N_("%a %H\u2236%M");
+                               } else {
+                                       /* Translators: this is the week day name followed by
+                                        * a time in 12h format. i.e. "Monday 9:04 PM" */
+                                       // xgettext:no-c-format
+                                       format = N_("%a %l\u2236%M %p");
+                               }
+                       }
                } else if (g_date_time_get_year (file_date) == g_date_time_get_year (now)) {
-                       /* Translators: this is the day of the month plus the short
-                        * month name i.e. "3 Feb" */
-                       // xgettext:no-c-format
-                       format = N_("%-e %b");
+                       if (date_format == NAUTILUS_DATE_FORMAT_REGULAR) {
+                               /* Translators: this is the day of the month plus the short
+                                * month name i.e. "3 Feb" */
+                               // xgettext:no-c-format
+                               format = N_("%-e %b");
+                       } else {
+                               if (use_24) {
+                                       /* Translators: this is the day of the month followed
+                                        * by the day number followed by a time in
+                                        * 24h format i.e. "3 Feb 23:04" */
+                                       // xgettext:no-c-format
+                                       format = N_("%-e %b %H\u2236%M");
+                               } else {
+                                       /* Translators: this is the day of the month followed
+                                        * by the day number followed by a time in
+                                        * 12h format i.e. "3 Feb 9:04 PM" */
+                                       // xgettext:no-c-format
+                                       format = N_("%-e %b %l\u2236%M %p");
+                               }
+                       }
                } else {
-                       /* Translators: this is the day of the month plus the short
-                        * month name plus the year i.e. "25 Feb 2015" */
-                       // xgettext:no-c-format
-                       format = N_("%-e %b %Y");
+                       if (date_format == NAUTILUS_DATE_FORMAT_REGULAR) {
+                               /* Translators: this is the day of the month followed by the short
+                                * month name followed by the year i.e. "3 Feb 2015" */
+                               // xgettext:no-c-format
+                               format = N_("%-e %b %Y");
+                       } else {
+                               if (use_24) {
+                                       /* Translators: this is the day number followed
+                                        * by the month name followed by the year followed
+                                        * by a time in 24h format i.e. "3 Feb 2015 23:04" */
+                                       // xgettext:no-c-format
+                                       format = N_("%-e %b %Y %H\u2236%M");
+                               } else {
+                                       /* Translators: this is the day number followed
+                                        * by the month name followed by the year followed
+                                        * by a time in 12h format i.e. "3 Feb 2015 9:04 PM" */
+                                       // xgettext:no-c-format
+                                       format = N_("%-e %b %Y %l\u2236%M %p");
+                               }
+                       }
                }
        } else {
                format = N_("%c");
@@ -6187,32 +6253,37 @@ 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,
-                                                        FALSE);
+                                                        NAUTILUS_DATE_FORMAT_REGULAR);
        }
        if (attribute_q == attribute_date_modified_full_q) {
                return nautilus_file_get_date_as_string (file, 
                                                         NAUTILUS_DATE_TYPE_MODIFIED,
-                                                        TRUE);
+                                                        NAUTILUS_DATE_FORMAT_FULL);
+       }
+       if (attribute_q == attribute_date_modified_with_time_q) {
+               return nautilus_file_get_date_as_string (file,
+                                                        NAUTILUS_DATE_TYPE_MODIFIED,
+                                                        NAUTILUS_DATE_FORMAT_REGULAR_WITH_TIME);
        }
        if (attribute_q == attribute_date_accessed_q) {
                return nautilus_file_get_date_as_string (file,
                                                         NAUTILUS_DATE_TYPE_ACCESSED,
-                                                        FALSE);
+                                                        NAUTILUS_DATE_FORMAT_REGULAR);
        }
        if (attribute_q == attribute_date_accessed_full_q) {
                return nautilus_file_get_date_as_string (file,
                                                         NAUTILUS_DATE_TYPE_ACCESSED,
-                                                        TRUE);
+                                                        NAUTILUS_DATE_FORMAT_FULL);
        }
        if (attribute_q == attribute_trashed_on_q) {
                return nautilus_file_get_date_as_string (file,
                                                         NAUTILUS_DATE_TYPE_TRASHED,
-                                                        FALSE);
+                                                        NAUTILUS_DATE_FORMAT_REGULAR);
        }
        if (attribute_q == attribute_trashed_on_full_q) {
                return nautilus_file_get_date_as_string (file,
                                                         NAUTILUS_DATE_TYPE_TRASHED,
-                                                        TRUE);
+                                                        NAUTILUS_DATE_FORMAT_FULL);
        }
        if (attribute_q == attribute_permissions_q) {
                return nautilus_file_get_permissions_as_string (file);
@@ -6361,6 +6432,7 @@ nautilus_file_is_date_sort_attribute_q (GQuark attribute_q)
        if (attribute_q == attribute_modification_date_q ||
            attribute_q == attribute_date_modified_q ||
            attribute_q == attribute_date_modified_full_q ||
+           attribute_q == attribute_date_modified_with_time_q ||
            attribute_q == attribute_accessed_date_q ||
            attribute_q == attribute_date_accessed_q ||
            attribute_q == attribute_date_accessed_full_q ||
@@ -7923,6 +7995,7 @@ nautilus_file_class_init (NautilusFileClass *class)
        attribute_modification_date_q = g_quark_from_static_string ("modification_date");
        attribute_date_modified_q = g_quark_from_static_string ("date_modified");
        attribute_date_modified_full_q = g_quark_from_static_string ("date_modified_full");
+       attribute_date_modified_with_time_q = g_quark_from_static_string ("date_modified_with_time");
        attribute_accessed_date_q = g_quark_from_static_string ("accessed_date");
        attribute_date_accessed_q = g_quark_from_static_string ("date_accessed");
        attribute_date_accessed_full_q = g_quark_from_static_string ("date_accessed_full");


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