[baobab] Show scan errors in the treeview using colors
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab] Show scan errors in the treeview using colors
- Date: Sat, 13 Oct 2012 15:07:04 +0000 (UTC)
commit 5374f0292d007758332a91d476acf3c573e7dc6b
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sat Sep 29 17:25:33 2012 +0200
Show scan errors in the treeview using colors
https://bugzilla.gnome.org/show_bug.cgi?id=622473
src/baobab-cellrenderers.vala | 60 ++++++++++++++++++++++++++++++++++++++---
src/baobab-main-window.ui | 9 +++++-
src/baobab-scanner.vala | 18 +++++++++++-
3 files changed, 80 insertions(+), 7 deletions(-)
---
diff --git a/src/baobab-cellrenderers.vala b/src/baobab-cellrenderers.vala
index d7c14ee..230616a 100644
--- a/src/baobab-cellrenderers.vala
+++ b/src/baobab-cellrenderers.vala
@@ -21,18 +21,62 @@
namespace Baobab {
public class CellRendererPercent : Gtk.CellRendererText {
+ public Scanner.State state { set; get; }
+
public double percent {
set {
- text = "%.1f %%".printf (value);
+ text = (state != Scanner.State.ERROR ? "%.1f %%".printf (value) : "");
+ }
+ }
+ }
+
+ public class CellRendererName : Gtk.CellRendererText {
+ public Scanner.State state { set; get; }
+
+ public string name {
+ set {
+ switch (state) {
+ case Scanner.State.ERROR:
+ markup = "<b>%s</b>".printf (value);
+ break;
+ case Scanner.State.CHILD_ERROR:
+ markup = "<b>%s</b>".printf (value);
+ break;
+ default:
+ markup = value;
+ break;
+ }
+ }
+ }
+
+ protected override void render (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
+ var context = widget.get_style_context ();
+
+ context.save ();
+
+ switch (state) {
+ case Scanner.State.ERROR:
+ context.add_class ("baobab-cell-error");
+ break;
+ case Scanner.State.CHILD_ERROR:
+ context.add_class ("baobab-cell-warning");
+ break;
}
+
+ base.render (cr, widget, background_area, cell_area, flags);
+
+ context.restore ();
}
+
}
public class CellRendererSize : Gtk.CellRendererText {
+ public Scanner.State state { set; get; }
+
public new uint64 size {
set {
if (!show_allocated_size) {
- text = format_size (value);
+ text = (state != Scanner.State.ERROR ? format_size (value) : "");
}
}
}
@@ -40,7 +84,7 @@ namespace Baobab {
public uint64 alloc_size {
set {
if (show_allocated_size) {
- text = format_size (value);
+ text = (state != Scanner.State.ERROR ? format_size (value) : "");
}
}
}
@@ -49,15 +93,23 @@ namespace Baobab {
}
public class CellRendererItems : Gtk.CellRendererText {
+ public Scanner.State state { set; get; }
+
public int items {
set {
- text = value >= 0 ? ngettext ("%d item", "%d items", value).printf (value) : "";
+ text = (value >= 0 && state != Scanner.State.ERROR) ? ngettext ("%d item", "%d items", value).printf (value) : "";
}
}
}
public class CellRendererProgress : Gtk.CellRendererProgress {
+ public Scanner.State state { set; get; }
+
public override void render (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
+ if (state == Scanner.State.ERROR) {
+ return;
+ }
+
int xpad;
int ypad;
get_padding (out xpad, out ypad);
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index c10ad17..68bed5d 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -177,9 +177,10 @@
<property name="reorderable">True</property>
<property name="sort_column_id">0</property>
<child>
- <object class="GtkCellRendererText" id="folder-column-text-renderer"/>
+ <object class="BaobabCellRendererName" id="folder-column-text-renderer"/>
<attributes>
- <attribute name="text">0</attribute>
+ <attribute name="name">0</attribute>
+ <attribute name="state">6</attribute>
</attributes>
</child>
</object>
@@ -198,6 +199,7 @@
</object>
<attributes>
<attribute name="value">2</attribute>
+ <attribute name="state">6</attribute>
</attributes>
</child>
<child>
@@ -206,6 +208,7 @@
</object>
<attributes>
<attribute name="percent">2</attribute>
+ <attribute name="state">6</attribute>
</attributes>
</child>
</object>
@@ -225,6 +228,7 @@
<attributes>
<attribute name="size">3</attribute>
<attribute name="alloc-size">4</attribute>
+ <attribute name="state">6</attribute>
</attributes>
</child>
</object>
@@ -242,6 +246,7 @@
</object>
<attributes>
<attribute name="items">5</attribute>
+ <attribute name="state">6</attribute>
</attributes>
</child>
</object>
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 08d428e..eca85ce 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -46,6 +46,7 @@ namespace Baobab {
CANCELLED,
NEED_PERCENT,
ERROR,
+ CHILD_ERROR,
DONE
}
@@ -148,6 +149,7 @@ namespace Baobab {
internal double percent;
internal int max_depth;
internal Error? error;
+ internal bool child_error;
// accessed only by the main thread
internal Gtk.TreeIter iter;
@@ -172,6 +174,7 @@ namespace Baobab {
}
results.elements = 1;
results.error = null;
+ results.child_error = false;
try {
var children = directory.enumerate_children (ATTRIBUTES, FileQueryInfoFlags.NOFOLLOW_SYMLINKS, cancellable);
@@ -187,6 +190,10 @@ namespace Baobab {
results.alloc_size += child_results.alloc_size;
results.elements += child_results.elements;
results.max_depth = int.max (results.max_depth, child_results.max_depth + 1);
+ if (child_results.error != null) {
+ results.child_error = true;
+ }
+
results_array.results += (owned) child_results;
}
break;
@@ -282,12 +289,21 @@ namespace Baobab {
foreach (unowned Results results in results_array.results) {
ensure_iter_exists (results);
+ State state;
+ if (results.child_error) {
+ state = State.CHILD_ERROR;
+ } else if (results.error != null) {
+ state = State.ERROR;
+ } else {
+ state = State.DONE;
+ }
+
set (results.iter,
Columns.SIZE, results.size,
Columns.ALLOC_SIZE, results.alloc_size,
Columns.PERCENT, results.percent,
Columns.ELEMENTS, results.elements,
- Columns.STATE, results.error == null ? State.DONE : State.ERROR,
+ Columns.STATE, state,
Columns.ERROR, results.error);
if (results.max_depth > max_depth) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]