[baobab] Add a column telling when the folder was last modified



commit 85bfbf77011e4b909c32bd4dd843b8abcb02ce38
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Sun Jul 21 13:33:45 2013 +0200

    Add a column telling when the folder was last modified
    
    https://bugzilla.gnome.org/show_bug.cgi?id=629561

 src/baobab-cellrenderers.vala |   27 +++++++++++++++++++++++++++
 src/baobab-main-window.ui     |   29 +++++++++++++++++++++++------
 src/baobab-scanner.vala       |   18 +++++++++++++++++-
 3 files changed, 67 insertions(+), 7 deletions(-)
---
diff --git a/src/baobab-cellrenderers.vala b/src/baobab-cellrenderers.vala
index e370e75..daacc1b 100644
--- a/src/baobab-cellrenderers.vala
+++ b/src/baobab-cellrenderers.vala
@@ -93,6 +93,33 @@ namespace Baobab {
         }
     }
 
+    public class CellRendererTime : Gtk.CellRendererText {
+        public uint64 time {
+            set {
+                if (value == 0) {
+                    text = _("Unknown");
+                    return;
+                }
+
+                var dt = new DateTime.from_unix_local ((int64)value);
+                var now = new DateTime.now_local ();
+                var ts = now.difference (dt);
+                if (ts < TimeSpan.DAY) {
+                    text = _("Today");
+                } else if (ts < 31 * TimeSpan.DAY) {
+                    var days = (ulong) (ts / TimeSpan.DAY);
+                    text = ngettext ("%d day", "%d days", days).printf (days);
+                } else if (ts < 365 * TimeSpan.DAY) {
+                    var months = (ulong) (ts / (31 * TimeSpan.DAY));
+                    text = ngettext ("%d month", "%d months", months).printf (months);
+                } else {
+                    var years = (ulong) (ts / (365 * TimeSpan.DAY));
+                    text = ngettext ("%d year", "%d years", years).printf (years);
+                }
+            }
+        }
+    }
+
     public class CellRendererProgress : Gtk.CellRendererProgress {
         public Scanner.State state { set; get; }
 
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index 804c8a4..d096ddf 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -266,14 +266,14 @@
                               </object>
                               <attributes>
                                 <attribute name="value">2</attribute>
-                                <attribute name="state">6</attribute>
+                                <attribute name="state">7</attribute>
                               </attributes>
                             </child>
                             <child>
                               <object class="BaobabCellRendererName" id="folder_column_text_renderer"/>
                               <attributes>
                                 <attribute name="name">0</attribute>
-                                <attribute name="state">6</attribute>
+                                <attribute name="state">7</attribute>
                               </attributes>
                             </child>
                           </object>
@@ -293,7 +293,7 @@
                               <attributes>
                                 <attribute name="size">3</attribute>
                                 <attribute name="alloc-size">4</attribute>
-                                <attribute name="state">6</attribute>
+                                <attribute name="state">7</attribute>
                               </attributes>
                             </child>
                           </object>
@@ -304,14 +304,31 @@
                             <property name="sizing">grow-only</property>
                             <property name="title" translatable="yes">Contents</property>
                             <property name="reorderable">True</property>
-                            <property name="sort_column_id">5</property>
+                            <property name="sort_column_id">6</property>
                             <child>
                               <object class="BaobabCellRendererItems" id="contents_column_items_renderer">
                                 <property name="xalign">1.0</property>
                               </object>
                               <attributes>
-                                <attribute name="items">5</attribute>
-                                <attribute name="state">6</attribute>
+                                <attribute name="items">6</attribute>
+                                <attribute name="state">7</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkTreeViewColumn" id="time_modified_column">
+                            <property name="resizable">True</property>
+                            <property name="sizing">grow-only</property>
+                            <property name="title" translatable="yes">Modified</property>
+                            <property name="reorderable">True</property>
+                            <property name="sort_column_id">5</property>
+                            <child>
+                              <object class="BaobabCellRendererTime" id="modified_column_time_renderer">
+                                <property name="xalign">1.0</property>
+                              </object>
+                              <attributes>
+                                <attribute name="time">5</attribute>
                               </attributes>
                             </child>
                           </object>
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index d160faf..648f88f 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -35,6 +35,7 @@ namespace Baobab {
             PERCENT,
             SIZE,
             ALLOC_SIZE,
+            TIME_MODIFIED,
             ELEMENTS,
             STATE,
             ERROR,
@@ -64,6 +65,7 @@ namespace Baobab {
             FileAttribute.STANDARD_TYPE + "," +
             FileAttribute.STANDARD_SIZE +  "," +
             FileAttribute.STANDARD_ALLOCATED_SIZE + "," +
+            FileAttribute.TIME_MODIFIED + "," +
             FileAttribute.UNIX_NLINK + "," +
             FileAttribute.UNIX_INODE + "," +
             FileAttribute.UNIX_DEVICE + "," +
@@ -145,6 +147,7 @@ namespace Baobab {
             // read from the main thread only after dispatch
             internal uint64 size;
             internal uint64 alloc_size;
+            internal uint64 time_modified;
             internal int elements;
             internal double percent;
             internal int max_depth;
@@ -168,6 +171,8 @@ namespace Baobab {
             results.parse_name = directory.get_parse_name ();
             results.parent = parent;
 
+            results.time_modified = info.get_attribute_uint64 (FileAttribute.TIME_MODIFIED);
+
             results.size = info.get_size ();
             if (info.has_attribute (FileAttribute.STANDARD_ALLOCATED_SIZE)) {
                 results.alloc_size = info.get_attribute_uint64 (FileAttribute.STANDARD_ALLOCATED_SIZE);
@@ -194,6 +199,10 @@ namespace Baobab {
                                     results.child_error = true;
                                 }
 
+                                if (results.time_modified < child_results.time_modified) {
+                                    results.time_modified = child_results.time_modified;
+                                }
+
                                 results_array.results += (owned) child_results;
                             }
                             break;
@@ -217,6 +226,11 @@ namespace Baobab {
                                 results.alloc_size += child_info.get_attribute_uint64 
(FileAttribute.STANDARD_ALLOCATED_SIZE);
                             }
                             results.elements++;
+
+                            var child_time = child_info.get_attribute_uint64 (FileAttribute.TIME_MODIFIED);
+                            if (results.time_modified < child_time) {
+                                results.time_modified = child_time;
+                            }
                             break;
 
                         default:
@@ -274,7 +288,8 @@ namespace Baobab {
             set (results.iter,
                  Columns.STATE,        State.SCANNING,
                  Columns.DISPLAY_NAME, results.display_name,
-                 Columns.PARSE_NAME,   results.parse_name);
+                 Columns.PARSE_NAME,   results.parse_name,
+                 Columns.TIME_MODIFIED,results.time_modified);
             results.iter_is_set = true;
         }
 
@@ -402,6 +417,7 @@ namespace Baobab {
                 typeof (double),  // PERCENT
                 typeof (uint64),  // SIZE
                 typeof (uint64),  // ALLOC_SIZE
+                typeof (uint64),  // TIME_MODIFIED
                 typeof (int),     // ELEMENTS
                 typeof (State),   // STATE
                 typeof (Error)    // ERROR (if STATE is ERROR)


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