[baobab/wip/vala: 61/65] Get rid of UDisks
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala: 61/65] Get rid of UDisks
- Date: Thu, 5 Apr 2012 12:20:05 +0000 (UTC)
commit f149a8bf9de29f63250c80504b4f964118e9e69e
Author: Stefano Facchini <stefano facchini gmail com>
Date: Wed Apr 4 11:45:19 2012 +0200
Get rid of UDisks
src/baobab-main-window.ui | 10 ++-
src/baobab-volume-list.vala | 223 +++++++++++++++++++++++++------------------
src/baobab-window.vala | 74 +++++++--------
3 files changed, 175 insertions(+), 132 deletions(-)
---
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index 1cc73cb..9e0dfa9 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -195,7 +195,15 @@
<property name="vexpand">True</property>
<property name="hexpand">True</property>
<child>
- <placeholder/>
+ <object class="GtkViewport" id="volume-viewport">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkGrid" id="location-view">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ </object>
+ </child>
+ </object>
</child>
</object>
</child>
diff --git a/src/baobab-volume-list.vala b/src/baobab-volume-list.vala
index 0f1a258..9870983 100644
--- a/src/baobab-volume-list.vala
+++ b/src/baobab-volume-list.vala
@@ -1,62 +1,91 @@
namespace Baobab {
- public class Location : Object {
+ public class Location {
public string name { get; private set; }
public string? mount_point { get; private set; }
+
public uint64? size { get; private set; }
public uint64? used { get; private set; }
public Icon? icon { get; private set; }
- public UDisks.Object? udisks_volume { get; private set; }
+
+ public Volume? volume { get; private set; }
+ public Mount? mount { get; private set; }
+
+ protected static const string FS_ATTRIBUTES =
+ FileAttribute.FILESYSTEM_SIZE + "," +
+ FileAttribute.FILESYSTEM_USED;
+
+ public Location.from_volume (Volume volume_) {
+ volume = volume_;
+ volume.changed.connect((vol) => {
+ print ("Vol changed: %s\n", volume.get_name ());
+ update_volume_info ();
+ });
+ update_volume_info ();
+ }
+
+ public Location.from_mount (Mount mount_) {
+ mount = mount_;
+ fill_from_mount ();
+ }
+
+ public Location.for_main_volume () {
+ name = _("Main volume");
+ mount_point = "/";
+ icon = new ThemedIcon ("drive-harddisk-system");
+
+ uint64? size_ = null;
+ uint64? used_ = null;
+ get_fs_size (File.new_for_path ("/"), out size_, out used_);
+
+ size = size_;
+ used = used_;
+ }
public Location (string name_,
string? mount_point_,
uint64? size_,
uint64? used_,
- Icon? icon_,
- UDisks.Object? udisks_volume_) {
+ Icon? icon_) {
name = name_;
mount_point = mount_point_;
size = size_;
used = used_;
icon = icon_;
- udisks_volume = udisks_volume_;
}
- public void mount () throws Error {
- if (mount_point != null || udisks_volume == null)
- return;
+ void update_volume_info () {
+ mount = volume.get_mount ();
- string mount_point_;
- var fs = udisks_volume.get_filesystem ();
- fs.call_mount_sync (new GLib.Variant ("a{sv}", null), out mount_point_, null);
- mount_point = mount_point_;
+ if (mount != null) {
+ fill_from_mount ();
+ } else {
+ name = volume.get_name ();
+ icon = volume.get_icon ();
+ mount_point = null;
+ size = null;
+ used = null;
+ }
}
- }
- public class LocationMonitor {
- private UDisks.Client client = null;
- private VolumeMonitor monitor;
+ void fill_from_mount () {
+ name = mount.get_name ();
- public signal void changed ();
+ var file = mount.get_root ();
- public LocationMonitor () throws Error {
- client = new UDisks.Client.sync (null);
- client.changed.connect(() => { changed (); });
+ uint64? size_ = null;
+ uint64? used_ = null;
+ get_fs_size (file, out size_, out used_);
- monitor = VolumeMonitor.get ();
- monitor.mount_changed.connect ((mount) => { changed (); });
- monitor.mount_removed.connect ((mount) => { changed (); });
- monitor.mount_added.connect ((mount) => { changed (); });
+ size = size_;
+ used = used_;
+ mount_point = file.get_path ();
+ icon = mount.get_icon ();
}
-
- protected static const string FS_ATTRIBUTES =
- FileAttribute.FILESYSTEM_SIZE + "," +
- FileAttribute.FILESYSTEM_USED;
-
- private void compute_usage (File file, ref uint64? size, ref uint64? used) {
+ static void get_fs_size (File file, out uint64? size, out uint64? used) {
try {
var info = file.query_filesystem_info (FS_ATTRIBUTES, null);
- if (size == null && info.has_attribute (FileAttribute.FILESYSTEM_SIZE))
+ if (info.has_attribute (FileAttribute.FILESYSTEM_SIZE))
size = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_SIZE);
if (info.has_attribute (FileAttribute.FILESYSTEM_USED))
used = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_USED);
@@ -64,85 +93,93 @@ namespace Baobab {
}
}
- public List<Location> get_locations () {
- List<Location> list = null;
+ public async void mount_volume () throws Error {
+ if (mount != null || volume == null)
+ return;
- var mount_points = new HashTable<string, unowned string> (str_hash, str_equal);
+ var mount_op = new Gtk.MountOperation (null);
+ yield volume.mount (MountMountFlags.NONE, mount_op, null);
- var pretty_names = new HashTable<string, string> (str_hash, str_equal);
- var icons = new HashTable<string, Icon> (str_hash, str_equal);
+ print("Mount finished on: %s\n", volume.get_mount ().get_root ().get_path ());
+ update_volume_info ();
+ }
+ }
- foreach (unowned UnixMountEntry mount in UnixMountEntry.get (null)) {
- var device = mount.get_device_path ();
- pretty_names.insert (device, mount.guess_name ());
- icons.insert (device, mount.guess_icon ());
- }
+ public class LocationMonitor {
+ private VolumeMonitor monitor;
- foreach (var volume in monitor.get_volumes ()) {
- var device = volume.get_identifier (VolumeIdentifier.UNIX_DEVICE);
- if (device != null) {
- pretty_names.insert (device, volume.get_name ());
- icons.insert (device, volume.get_icon ());
- }
- }
+ private List<Location> locations = null;
+
+ public signal void changed ();
+
+ public LocationMonitor () {
+ monitor = VolumeMonitor.get ();
+ monitor.mount_changed.connect (mount_changed);
+ monitor.mount_removed.connect (mount_removed);
+ monitor.mount_added.connect (mount_added);
+ monitor.volume_changed.connect (volume_changed);
+ monitor.volume_removed.connect (volume_removed);
+ monitor.volume_added.connect (volume_added);
+
+ initial_fill ();
+ }
- var dbus_objects = client.get_object_manager ().get_objects ();
- foreach (var dbus_object in dbus_objects) {
- UDisks.Object volume = (UDisks.Object) dbus_object;
+ public unowned List<Location> get_locations () {
+ return locations;
+ }
- var block = volume.get_block ();
- if (block == null || block.hint_ignore || volume.get_filesystem () == null)
- continue;
+ void volume_changed (Volume volume) {
+ changed ();
+ }
- uint64? size = block.size;
- uint64? used = null;
+ void volume_removed (Volume volume) {
+ print ("Vol removed: %s\n", volume.get_name ());
+ }
- var mount_point = volume.get_filesystem ().mount_points[0];
- if (mount_point != null) {
- var file = File.new_for_path (mount_point);
- compute_usage (file, ref size, ref used);
+ void volume_added (Volume volume) {
+ print ("Vol added: %s\n", volume.get_name ());
+ locations.append (new Location.from_volume (volume));
- mount_points.add (mount_point);
- }
+ changed ();
+ }
- var icon = icons.lookup (block.device);
- var pretty_name = pretty_names.lookup (block.device);
- var name = pretty_name != null ? pretty_name : block.device;
+ void mount_changed (Mount mount) {
+ print ("Changed: %s\n", mount.get_root ().get_path ());
+ }
- if (mount_point == "/") {
- name = _("Main volume");
- icon = new ThemedIcon ("drive-harddisk-system");
+ void mount_removed (Mount mount) {
+ print ("Removed: %s\n", mount.get_root ().get_path ());
+ foreach (var location in locations) {
+ if (location.mount == mount) {
+ locations.remove (location);
+ break;
}
+ }
- var location = new Location (name,
- mount_point,
- size,
- used,
- icon,
- volume);
- list.append (location);
+ changed ();
+ }
+
+ void mount_added (Mount mount) {
+ print ("Added: %s\n", mount.get_root ().get_path ());
+ if (mount.get_volume () == null)
+ locations.append (new Location.from_mount (mount));
+
+ changed ();
+ }
+
+ void initial_fill () {
+ locations.append (new Location.for_main_volume ());
+
+ foreach (var volume in monitor.get_volumes ()) {
+ locations.append (new Location.from_volume (volume));
}
foreach (var mount in monitor.get_mounts ()) {
- var mount_point = mount.get_root ().get_path ();
-
- if (mount_point in mount_points)
- continue;
-
- uint64? size = null;
- uint64? used = null;
- compute_usage (mount.get_root (), ref size, ref used);
-
- var location = new Location (mount.get_name (),
- mount_point,
- size,
- used,
- mount.get_icon (),
- null);
- list.append (location);
+ if (mount.get_volume () == null)
+ locations.append (new Location.from_mount (mount));
}
- return list;
+ changed ();
}
}
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index a01c97d..4604cad 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -12,10 +12,12 @@ namespace Baobab {
Gtk.Label infobar_secondary;
Gtk.TreeView treeview;
Gtk.Notebook chart_notebook;
+ Gtk.Grid location_view;
Chart rings_chart;
Chart treemap_chart;
Gtk.Spinner spinner;
Scanner? scanner;
+ LocationMonitor location_monitor;
static Gdk.Cursor busy_cursor;
@@ -105,8 +107,9 @@ namespace Baobab {
rings_chart = builder.get_object ("rings-chart") as Chart;
treemap_chart = builder.get_object ("treemap-chart") as Chart;
spinner = builder.get_object ("spinner") as Gtk.Spinner;
+ location_view = builder.get_object ("location-view") as Gtk.Grid;
- setup_home_page (builder);
+ setup_home_page ();
setup_treeview (builder);
// To make it draggable like a primary toolbar
@@ -307,32 +310,14 @@ namespace Baobab {
Gtk.drag_dest_unset (this);
}
- bool show_treeview_popup (Gtk.Menu popup, Gdk.EventButton? event) {
- if (event != null) {
- popup.popup (null, null, null, event.button, event.time);
- } else {
- popup.popup (null, null, null, 0, Gtk.get_current_event_time ());
- popup.select_first (false);
- }
- return true;
- }
-
- delegate void UpdateFunc ();
- void setup_home_page (Gtk.Builder builder) {
- var location_monitor = new LocationMonitor ();
-
- var scrolled_window = builder.get_object ("volume-scrolled-window") as Gtk.ScrolledWindow;
- var grid = new Gtk.Grid ();
- grid.orientation = Gtk.Orientation.VERTICAL;
- scrolled_window.add_with_viewport (grid);
+ void update_locations () {
+ location_view.foreach ((widget) => { widget.destroy (); });
- UpdateFunc update_locations = () => {
- grid.foreach ((widget) => { widget.destroy (); });
-
- foreach (var location in location_monitor.get_locations ()) {
- var loc_widget = new LocationWidget (location, (location_) => {
+ foreach (var location in location_monitor.get_locations ()) {
+ var loc_widget = new LocationWidget (location, (location_) => {
+ location_.mount_volume.begin ((location__, res) => {
try {
- location_.mount ();
+ location_.mount_volume.end (res);
set_ui_page (UIPage.RESULT);
scan_directory (File.new_for_path (location_.mount_point),
ScanFlags.EXCLUDE_MOUNTS);
@@ -340,27 +325,40 @@ namespace Baobab {
message (_("Could not analyze volume."), e.message, Gtk.MessageType.ERROR);
}
});
- grid.add (loc_widget);
- }
+ });
- var home_loc = new Location (_("Home folder"),
- GLib.Environment.get_home_dir (),
- null,
- null,
- new ThemedIcon (Gtk.Stock.HOME),
- null);
+ location_view.add (loc_widget);
+ }
- grid.add (new LocationWidget (home_loc, (location) => {
- on_scan_home_activate ();
- }));
+ var home_loc = new Location (_("Home folder"),
+ GLib.Environment.get_home_dir (),
+ null,
+ null,
+ new ThemedIcon (Gtk.Stock.HOME));
- grid.show_all ();
- };
+ location_view.add (new LocationWidget (home_loc, (location) => {
+ on_scan_home_activate ();
+ }));
+
+ location_view.show_all ();
+ }
+ void setup_home_page () {
+ location_monitor = new LocationMonitor ();
location_monitor.changed.connect (() => { update_locations (); });
update_locations ();
}
+ bool show_treeview_popup (Gtk.Menu popup, Gdk.EventButton? event) {
+ if (event != null) {
+ popup.popup (null, null, null, event.button, event.time);
+ } else {
+ popup.popup (null, null, null, 0, Gtk.get_current_event_time ());
+ popup.select_first (false);
+ }
+ return true;
+ }
+
void setup_treeview (Gtk.Builder builder) {
var popup = builder.get_object ("treeview-popup-menu") as Gtk.Menu;
var open_item = builder.get_object ("treeview-popup-open") as Gtk.MenuItem;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]