[baobab] Decide early whether allocated or apparent size is used
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab] Decide early whether allocated or apparent size is used
- Date: Sun, 14 Jun 2020 12:52:59 +0000 (UTC)
commit e56ffae68163d5dc89067791602a3ed8c3738092
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sun Jun 14 09:28:31 2020 +0200
Decide early whether allocated or apparent size is used
We do this consistently in the scanner, then everyone else follows.
As a bonus, percentages are now also consistent with this choice.
As further bonus, we can do away with a column in the model.
data/ui/baobab-main-window.ui | 22 ++++++++++-----------
src/baobab-cellrenderers.vala | 14 +-------------
src/baobab-chart.vala | 45 +++++++++----------------------------------
src/baobab-scanner.vala | 18 ++++++++++-------
src/baobab-window.vala | 35 ++++++---------------------------
5 files changed, 37 insertions(+), 97 deletions(-)
---
diff --git a/data/ui/baobab-main-window.ui b/data/ui/baobab-main-window.ui
index a5014a9..fbded4c 100644
--- a/data/ui/baobab-main-window.ui
+++ b/data/ui/baobab-main-window.ui
@@ -251,15 +251,15 @@
</object>
<attributes>
<attribute name="value">1</attribute>
- <attribute name="state">7</attribute>
+ <attribute name="state">6</attribute>
</attributes>
</child>
<child>
<object class="BaobabCellRendererName" id="folder_column_text_renderer"/>
<attributes>
<attribute name="name">0</attribute>
- <attribute name="display_name">5</attribute>
- <attribute name="state">7</attribute>
+ <attribute name="display_name">4</attribute>
+ <attribute name="state">6</attribute>
</attributes>
</child>
</object>
@@ -270,16 +270,14 @@
<property name="sizing">grow-only</property>
<property name="title" translatable="yes">Size</property>
<property name="reorderable">True</property>
- <property name="sort_column_id">3</property>
+ <property name="sort_column_id">2</property>
<child>
<object class="BaobabCellRendererSize" id="size_column_size_renderer">
<property name="xalign">1.0</property>
- <property name="show-allocated-size">True</property>
</object>
<attributes>
<attribute name="size">2</attribute>
- <attribute name="alloc-size">3</attribute>
- <attribute name="state">7</attribute>
+ <attribute name="state">6</attribute>
</attributes>
</child>
</object>
@@ -290,14 +288,14 @@
<property name="sizing">grow-only</property>
<property name="title" translatable="yes">Contents</property>
<property name="reorderable">True</property>
- <property name="sort_column_id">6</property>
+ <property name="sort_column_id">5</property>
<child>
<object class="BaobabCellRendererItems" id="contents_column_items_renderer">
<property name="xalign">1.0</property>
</object>
<attributes>
- <attribute name="items">6</attribute>
- <attribute name="state">7</attribute>
+ <attribute name="items">5</attribute>
+ <attribute name="state">6</attribute>
</attributes>
</child>
</object>
@@ -308,13 +306,13 @@
<property name="sizing">grow-only</property>
<property name="title" translatable="yes">Modified</property>
<property name="reorderable">True</property>
- <property name="sort_column_id">4</property>
+ <property name="sort_column_id">3</property>
<child>
<object class="BaobabCellRendererTime" id="modified_column_time_renderer">
<property name="xalign">1.0</property>
</object>
<attributes>
- <attribute name="time">4</attribute>
+ <attribute name="time">3</attribute>
</attributes>
</child>
</object>
diff --git a/src/baobab-cellrenderers.vala b/src/baobab-cellrenderers.vala
index 72be2f9..042be57 100644
--- a/src/baobab-cellrenderers.vala
+++ b/src/baobab-cellrenderers.vala
@@ -75,21 +75,9 @@ namespace Baobab {
public new uint64 size {
set {
- if (!show_allocated_size) {
- text = (state != Scanner.State.ERROR ? format_size (value) : "");
- }
+ text = (state != Scanner.State.ERROR ? format_size (value) : "");
}
}
-
- public uint64 alloc_size {
- set {
- if (show_allocated_size) {
- text = (state != Scanner.State.ERROR ? format_size (value) : "");
- }
- }
- }
-
- public bool show_allocated_size { private get; set; }
}
public class CellRendererItems : Gtk.CellRendererText {
diff --git a/src/baobab-chart.vala b/src/baobab-chart.vala
index 0e490a7..0275efe 100644
--- a/src/baobab-chart.vala
+++ b/src/baobab-chart.vala
@@ -57,12 +57,6 @@ namespace Baobab {
// Keep in sync with colors defined in CSS
const int NUM_TANGO_COLORS = 6;
- uint name_column;
- uint display_name_column;
- uint size_column;
- uint percentage_column;
- uint valid_column;
-
bool model_changed;
Gtk.Menu context_menu = null;
@@ -110,25 +104,6 @@ namespace Baobab {
}
}
- public void set_model_with_columns (Gtk.TreeModel m,
- uint name_column_,
- uint display_name_column_,
- uint size_column_,
- uint percentage_column_,
- uint valid_column_,
- Gtk.TreePath? r) {
- model = m;
- if (r != null) {
- root = r;
- }
-
- name_column = name_column_;
- display_name_column = display_name_column_;
- size_column = size_column_;
- percentage_column = percentage_column_;
- valid_column = valid_column_;
- }
-
Gtk.TreeRowReference? root_;
public Gtk.TreePath? root {
set {
@@ -265,7 +240,10 @@ namespace Baobab {
string name;
string display_name;
uint64 size;
- model.get (iter, name_column, out name, display_name_column, out display_name, size_column, out
size);
+ model.get (iter,
+ Scanner.Columns.NAME, out name,
+ Scanner.Columns.DISPLAY_NAME, out display_name,
+ Scanner.Columns.SIZE, out size);
var item = create_new_chartitem ();
item.name = "";
@@ -293,7 +271,7 @@ namespace Baobab {
void get_items (Gtk.TreePath root_path) {
unowned List<ChartItem> node = null;
Gtk.TreeIter initial_iter = {0};
- double size;
+ double percent;
Gtk.TreePath model_root_path;
Gtk.TreeIter model_root_iter;
Gtk.TreeIter child_iter = {0};
@@ -309,7 +287,7 @@ namespace Baobab {
model_root_path = new Gtk.TreePath.first ();
model.get_iter (out model_root_iter, model_root_path);
- model.get (model_root_iter, percentage_column, out size, -1);
+ model.get (model_root_iter, Scanner.Columns.PERCENT, out percent);
node = add_item (0, 0, 100, initial_iter);
@@ -327,11 +305,11 @@ namespace Baobab {
if ((item.has_any_child) && (item.depth < max_depth + 1)) {
rel_start = 0;
do {
- model.get (child_iter, percentage_column, out size, -1);
- child_node = add_item (item.depth + 1, rel_start, size, child_iter);
+ model.get (child_iter, Scanner.Columns.PERCENT, out percent);
+ child_node = add_item (item.depth + 1, rel_start, percent, child_iter);
var child = child_node.data;
child.parent = node;
- rel_start += size;
+ rel_start += percent;
} while (model.iter_next (ref child_iter));
}
@@ -413,11 +391,6 @@ namespace Baobab {
}
public override bool draw (Cairo.Context cr) {
- if (name_column == percentage_column) {
- // Columns not set
- return false;
- }
-
if (model != null) {
if (model_changed || items == null) {
get_items (root);
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index d1952cc..04dbfdf 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -33,7 +33,6 @@ namespace Baobab {
NAME,
PERCENT,
SIZE,
- ALLOC_SIZE,
TIME_MODIFIED,
DISPLAY_NAME,
ELEMENTS,
@@ -52,6 +51,8 @@ namespace Baobab {
public ScanFlags scan_flags { get; private set; }
+ public bool show_allocated_size { get; private set; }
+
public int max_depth { get; protected set; }
public signal void completed();
@@ -173,7 +174,6 @@ namespace Baobab {
// written in the worker thread before dispatch
// 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;
@@ -193,8 +193,10 @@ namespace Baobab {
display_name = info_display_name;
}
file_type = info.get_file_type ();
- size = info.get_size ();
- alloc_size = info.get_attribute_uint64 (FileAttribute.STANDARD_ALLOCATED_SIZE);
+ size = info.get_attribute_uint64 (FileAttribute.STANDARD_ALLOCATED_SIZE);
+ if (size == 0) {
+ size = info.get_size ();
+ }
time_modified = info.get_attribute_uint64 (FileAttribute.TIME_MODIFIED);
elements = 1;
error = null;
@@ -203,7 +205,6 @@ namespace Baobab {
public void update_with_child (Results child) {
size += child.size;
- alloc_size += child.alloc_size;
elements += child.elements;
max_depth = int.max (max_depth, child.max_depth + 1);
child_error |= child.child_error || (child.error != null);
@@ -286,6 +287,11 @@ namespace Baobab {
try {
var array = new ResultsArray ();
var info = directory.query_info (ATTRIBUTES, 0, cancellable);
+
+ // Use allocated size if available, where availability is defined as allocated size > 0
+ // for the root element. This is consistent with how we attribute sizes in the Results
structure
+ show_allocated_size = info.get_attribute_uint64 (FileAttribute.STANDARD_ALLOCATED_SIZE) > 0;
+
unix_device = info.get_attribute_uint32 (FileAttribute.UNIX_DEVICE);
var results = add_directory (directory, info);
results.percent = 100.0;
@@ -350,7 +356,6 @@ namespace Baobab {
set (results.iter,
Columns.PERCENT, results.percent,
Columns.SIZE, results.size,
- Columns.ALLOC_SIZE, results.alloc_size,
Columns.TIME_MODIFIED, results.time_modified);
// To save some memory, we only create these columns if they are needed
@@ -465,7 +470,6 @@ namespace Baobab {
typeof (string), // NAME
typeof (double), // PERCENT
typeof (uint64), // SIZE
- typeof (uint64), // ALLOC_SIZE
typeof (uint64), // TIME_MODIFIED
typeof (string), // DISPLAY_NAME
typeof (int), // ELEMENTS
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index afa4cf2..5674f2e 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -53,10 +53,6 @@ namespace Baobab {
[GtkChild]
private Gtk.TreeView treeview;
[GtkChild]
- private Gtk.TreeViewColumn size_column;
- [GtkChild]
- private CellRendererSize size_column_size_renderer;
- [GtkChild]
private Gtk.Menu treeview_popup_menu;
[GtkChild]
private Gtk.MenuItem treeview_popup_open;
@@ -506,21 +502,11 @@ namespace Baobab {
}
}
- void set_chart_model (Gtk.TreeModel model, bool show_allocated_size) {
+ void set_chart_model (Gtk.TreeModel model) {
model.bind_property ("max-depth", rings_chart, "max-depth", BindingFlags.SYNC_CREATE);
model.bind_property ("max-depth", treemap_chart, "max-depth", BindingFlags.SYNC_CREATE);
- treemap_chart.set_model_with_columns (model,
- Scanner.Columns.NAME,
- Scanner.Columns.DISPLAY_NAME,
- show_allocated_size ? Scanner.Columns.ALLOC_SIZE :
Scanner.Columns.SIZE,
- Scanner.Columns.PERCENT,
- Scanner.Columns.ELEMENTS, null);
- rings_chart.set_model_with_columns (model,
- Scanner.Columns.NAME,
- Scanner.Columns.DISPLAY_NAME,
- show_allocated_size ? Scanner.Columns.ALLOC_SIZE :
Scanner.Columns.SIZE,
- Scanner.Columns.PERCENT,
- Scanner.Columns.ELEMENTS, null);
+ rings_chart.model = model;
+ treemap_chart.model = model;
}
void scan_active_location (bool force) {
@@ -551,21 +537,12 @@ namespace Baobab {
}
}
- // Use allocated size if available, where available is defined as
- // alloc_size > 0 for the root element
- Gtk.TreeIter iter;
- scanner.get_iter_first (out iter);
- uint64 alloc_size;
- scanner.get (iter, Scanner.Columns.ALLOC_SIZE, out alloc_size, -1);
- bool show_allocated_size = alloc_size > 0;
- size_column_size_renderer.show_allocated_size = show_allocated_size;
- size_column.sort_column_id = show_allocated_size ? Scanner.Columns.ALLOC_SIZE :
Scanner.Columns.SIZE;
- set_chart_model (active_location.scanner, show_allocated_size);
+ set_chart_model (active_location.scanner);
set_ui_state (result_page, false);
- if (!show_allocated_size) {
- message (_("Could not detect occupied disk sizes."), _("Apparent sizes are shown
instead."), Gtk.MessageType.INFO);
+ if (!scanner.show_allocated_size) {
+ message (_("Could not always detect occupied disk sizes."), _("Apparent sizes may be
shown instead."), Gtk.MessageType.INFO);
}
if (!is_active) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]