[baobab/wip/vala: 46/53] First cut at implementing initial state.
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala: 46/53] First cut at implementing initial state.
- Date: Thu, 5 Apr 2012 21:37:35 +0000 (UTC)
commit a06c4038facf53d9ba86fee9d24bb8b45bb30751
Author: Paolo Borelli <pborelli gnome org>
Date: Wed Feb 15 00:40:03 2012 +0100
First cut at implementing initial state.
As in the old baobab the "initial state" represents the file system
usage. Right now this is done with a sync query, but I guess it could be
made async pretty easily. The old code iterated through all mounts,
while for now I am just querying /.
src/baobab-application.vala | 3 +-
src/baobab-cellrenderers.vala | 2 +-
src/baobab-scanner.vala | 51 +++++++++++++++++++++++++++++++++++++++++
src/baobab-window.vala | 40 +++++++++++++++++++++++---------
4 files changed, 83 insertions(+), 13 deletions(-)
---
diff --git a/src/baobab-application.vala b/src/baobab-application.vala
index 3d1451f..b8981d1 100644
--- a/src/baobab-application.vala
+++ b/src/baobab-application.vala
@@ -11,7 +11,8 @@ namespace Baobab {
Settings ui_settings;
protected override void activate () {
- new Window (this);
+ var window = new Window (this);
+ window.show_filesystem_usage ();
}
protected override void open (File[] files, string hint) {
diff --git a/src/baobab-cellrenderers.vala b/src/baobab-cellrenderers.vala
index 743b56f..54d13a7 100644
--- a/src/baobab-cellrenderers.vala
+++ b/src/baobab-cellrenderers.vala
@@ -30,7 +30,7 @@ namespace Baobab {
public class CellRendererItems : Gtk.CellRendererText {
public int items {
set {
- text = ngettext ("%d item", "%d items", value).printf (value);
+ text = value >= 0 ? ngettext ("%d item", "%d items", value).printf (value) : "";
}
}
}
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 864300b..071f6da 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -64,6 +64,57 @@ namespace Baobab {
}
}
+ protected static const string FS_ATTRIBUTES =
+ FileAttribute.FILESYSTEM_SIZE + "," +
+ FileAttribute.FILESYSTEM_USED + "," +
+ FileAttribute.FILESYSTEM_FREE;
+
+ public void get_filesystem_usage () throws Error {
+ var info = directory.query_filesystem_info (FS_ATTRIBUTES, cancellable);
+
+ var size = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_SIZE);
+ var used = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_USED);
+ var free = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_FREE);
+ var reserved = size - free - used;
+
+ var used_perc = 100 * ((double) used) / ((double) size);
+ var reserved_perc = 100 * ((double) reserved) / ((double) size);
+
+ Gtk.TreeIter? root_iter, iter;
+ append (out root_iter, null);
+ set (root_iter,
+ Columns.STATE, State.DONE,
+ Columns.DISPLAY_NAME, _("Total filesystem capacity"),
+ Columns.PARSE_NAME, "",
+ Columns.SIZE, size,
+ Columns.ALLOC_SIZE, size,
+ Columns.PERCENT, 100.0,
+ Columns.ELEMENTS, -1,
+ Columns.ERROR, null);
+
+ append (out iter, root_iter);
+ set (iter,
+ Columns.STATE, State.DONE,
+ Columns.DISPLAY_NAME, _("Used"),
+ Columns.PARSE_NAME, "",
+ Columns.SIZE, used,
+ Columns.ALLOC_SIZE, used,
+ Columns.PERCENT, used_perc,
+ Columns.ELEMENTS, -1,
+ Columns.ERROR, null);
+
+ append (out iter, root_iter);
+ set (iter,
+ Columns.STATE, State.DONE,
+ Columns.DISPLAY_NAME, _("Reserved"),
+ Columns.PARSE_NAME, "",
+ Columns.SIZE, reserved,
+ Columns.ALLOC_SIZE, reserved,
+ Columns.PERCENT, reserved_perc,
+ Columns.ELEMENTS, -1,
+ Columns.ERROR, null);
+ }
+
public Scanner (File directory) {
this.directory = directory;
cancellable = new Cancellable();
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 844b795..0c7140c 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -409,7 +409,7 @@ namespace Baobab {
treeview.expand_row (path, false);
}
- void set_model (Scanner model) {
+ void set_model (Gtk.TreeModel model) {
Gtk.TreeIter first;
treeview.model = model;
@@ -434,9 +434,31 @@ namespace Baobab {
Scanner.Columns.PARSE_NAME,
Scanner.Columns.PERCENT,
Scanner.Columns.ELEMENTS, null);
+ }
+
+ public void show_filesystem_usage () {
+ var dir = File.new_for_uri ("file:///");
+
+ scanner = new ThreadedScanner (dir);
+ set_model (scanner);
+
+ try {
+ scanner.get_filesystem_usage ();
+ } catch (Error e) {
+ message (_("Could not get filesytem usage."), e.message, Gtk.MessageType.WARNING);
+ }
+
+ treeview.set_headers_visible (false);
+ }
+
+ public void scan_directory (File directory) {
+ if (!check_dir (directory)) {
+ return;
+ }
+
+ scanner = new ThreadedScanner (directory);
+ set_model (scanner);
- clear_message ();
- set_busy (true);
scanner.completed.connect(() => {
set_busy (false);
try {
@@ -444,20 +466,16 @@ namespace Baobab {
} catch (IOError.CANCELLED e) {
// Handle cancellation silently
scanner.clear ();
+ show_filesystem_usage ();
} catch (Error e) {
var primary = _("Could not scan folder \"%s\" or some of the folders it contains.").printf (scanner.directory.get_parse_name ());
message (primary, e.message, Gtk.MessageType.WARNING);
}
});
- }
- public void scan_directory (File directory) {
- if (!check_dir (directory)) {
- return;
- }
-
- scanner = new ThreadedScanner (directory);
- set_model (scanner);
+ clear_message ();
+ treeview.set_headers_visible (true);
+ set_busy (true);
scanner.scan ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]