[baobab/reroot-view: 6/35] Add a FolderDisplay widget



commit 9cfef87f3935130657d69eba9aa1bd843536d343
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Wed Jun 17 14:22:34 2020 +0200

    Add a FolderDisplay widget
    
    Just a stub, lacks a ton of styling.

 data/baobab.gresource.xml        |  1 +
 data/ui/baobab-folder-display.ui | 97 ++++++++++++++++++++++++++++++++++++++++
 data/ui/baobab-main-window.ui    | 14 +++++-
 src/baobab-window.vala           | 59 ++++++++++++++++++++++++
 4 files changed, 169 insertions(+), 2 deletions(-)
---
diff --git a/data/baobab.gresource.xml b/data/baobab.gresource.xml
index a57fcc9..1465bbc 100644
--- a/data/baobab.gresource.xml
+++ b/data/baobab.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/baobab">
     <file compressed="true">baobab.css</file>
+    <file compressed="true">ui/baobab-folder-display.ui</file>
     <file compressed="true">ui/baobab-location-list.ui</file>
     <file compressed="true">ui/baobab-location-row.ui</file>
     <file compressed="true">ui/baobab-main-window.ui</file>
diff --git a/data/ui/baobab-folder-display.ui b/data/ui/baobab-folder-display.ui
new file mode 100644
index 0000000..7867495
--- /dev/null
+++ b/data/ui/baobab-folder-display.ui
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.0 -->
+<interface>
+  <requires lib="gtk+" version="3.22"/>
+  <template class="BaobabFolderDisplay" parent="GtkGrid">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">start</property>
+        <property name="hexpand">True</property>
+        <property name="label" translatable="yes">Current Folder</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Size</property>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Contents</property>
+      </object>
+      <packing>
+        <property name="left_attach">2</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="folder_name">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">start</property>
+        <property name="hexpand">True</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="folder_size">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="folder_elements">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+      <packing>
+        <property name="left_attach">2</property>
+        <property name="top_attach">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Modified</property>
+      </object>
+      <packing>
+        <property name="left_attach">3</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="folder_time">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+      <packing>
+        <property name="left_attach">3</property>
+        <property name="top_attach">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/data/ui/baobab-main-window.ui b/data/ui/baobab-main-window.ui
index 07515b9..fa1f5e9 100644
--- a/data/ui/baobab-main-window.ui
+++ b/data/ui/baobab-main-window.ui
@@ -225,12 +225,22 @@
                   <property name="visible">True</property>
                   <property name="can_focus">False</property>
                   <property name="column_homogeneous">True</property>
+                  <child>
+                    <object class="BaobabFolderDisplay" id="folder_display"/>
+                    <packing>
+                      <property name="left_attach">0</property>
+                      <property name="top_attach">0</property>
+                      <property name="width">1</property>
+                      <property name="height">1</property>
+                    </packing>
+                  </child>
                   <child>
                     <object class="GtkScrolledWindow" id="scrolled_window">
                       <property name="visible">True</property>
                       <property name="can_focus">True</property>
                       <property name="shadow_type">in</property>
                       <property name="hexpand">True</property>
+                      <property name="vexpand">True</property>
                       <child>
                         <object class="GtkTreeView" id="treeview">
                           <property name="visible">True</property>
@@ -324,7 +334,7 @@
                     </object>
                     <packing>
                       <property name="left_attach">0</property>
-                      <property name="top_attach">0</property>
+                      <property name="top_attach">1</property>
                       <property name="width">1</property>
                       <property name="height">1</property>
                     </packing>
@@ -409,7 +419,7 @@
                       <property name="left_attach">1</property>
                       <property name="top_attach">0</property>
                       <property name="width">1</property>
-                      <property name="height">1</property>
+                      <property name="height">2</property>
                     </packing>
                   </child>
                 </object>
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 4e0541e..d4ffb1f 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -22,6 +22,60 @@
 
 namespace Baobab {
 
+    [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-folder-display.ui")]
+    public class FolderDisplay : Gtk.Grid {
+        [GtkChild]
+        private Gtk.Label folder_name;
+        [GtkChild]
+        private Gtk.Label folder_size;
+        [GtkChild]
+        private Gtk.Label folder_elements;
+        [GtkChild]
+        private Gtk.Label folder_time;
+
+        Location location_;
+        public Location location {
+            set {
+                location_ = value;
+                //folder_name.label = location_.name;
+            }
+
+            get {
+                return location_;
+            }
+        }
+
+        public new Gtk.TreePath path {
+            set {
+                print("current_path=%s\n", value.to_string());
+                Gtk.TreeIter iter;
+                location.scanner.get_iter (out iter, value);
+
+                string name;
+                string display_name;
+                uint64 size;
+                int elements;
+                uint64 time;
+
+                location.scanner.get (iter,
+                           Scanner.Columns.NAME, out name,
+                           Scanner.Columns.DISPLAY_NAME, out display_name,
+                           Scanner.Columns.SIZE, out size,
+                           Scanner.Columns.ELEMENTS, out elements,
+                           Scanner.Columns.TIME_MODIFIED, out time);
+
+                if (value.get_depth () == 1) {
+                    folder_name.label = location.name;
+                } else {
+                    folder_name.label = display_name != null ? display_name : name;
+                }
+                folder_size.label = format_size (size);
+                folder_elements.label = "%d items".printf (elements);
+                folder_time.label = new DateTime.from_unix_local ((int64) time).format ("%F");
+            }
+        }
+    }
+
     [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-main-window.ui")]
     public class Window : Gtk.ApplicationWindow {
         [GtkChild]
@@ -51,6 +105,8 @@ namespace Baobab {
         [GtkChild]
         private LocationList location_list;
         [GtkChild]
+        private FolderDisplay folder_display;
+        [GtkChild]
         private Gtk.TreeView treeview;
         [GtkChild]
         private Gtk.Menu treeview_popup_menu;
@@ -226,6 +282,8 @@ namespace Baobab {
 
             active_location = location;
 
+            folder_display.location = location;
+
             // Update the timestamp for GtkRecentManager
             location_list.add_location (location);
 
@@ -424,6 +482,7 @@ namespace Baobab {
                     var path = active_location.scanner.get_path (iter);
                     rings_chart.root = path;
                     treemap_chart.root = path;
+                    folder_display.path = path;
                 }
             });
         }


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