From 090908439b113f6cb0dc9741d0573ca623c241c8 Mon Sep 17 00:00:00 2001 From: Adel Gadllah Date: Wed, 2 Sep 2009 20:41:32 +0200 Subject: [PATCH] Add volumes support to places Display the mounted volumes in the places section of the overlay. Signed-off-by: Adel Gadllah Signed-off-by: Colin Walters --- js/ui/places.js | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/js/ui/places.js b/js/ui/places.js index 12bb8bd17..903cd4ef0 100644 --- a/js/ui/places.js +++ b/js/ui/places.js @@ -80,6 +80,9 @@ Places.prototype = { this._menuBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL, spacing: PLACES_VSPACING }); this.actor.append(this._menuBox, Big.BoxPackFlags.EXPAND); + this._devBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL, + spacing: PLACES_VSPACING }); + this._dirsBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL, spacing: PLACES_VSPACING }); this.actor.append(this._dirsBox, Big.BoxPackFlags.EXPAND); @@ -98,6 +101,23 @@ Places.prototype = { this._menuBox.append(home.actor, Big.BoxPackFlags.NONE); + /* + * Show devices, code more or less ported from nautilus-places-sidebar.c + */ + + this._menuBox.append(this._devBox, Big.BoxPackFlags.NONE); + this._volumeMonitor = Gio.VolumeMonitor.get(); + this._volumeMonitor.connect('volume-added', Lang.bind(this, this._updateDevices)); + this._volumeMonitor.connect('volume-removed',Lang.bind(this, this._updateDevices)); + this._volumeMonitor.connect('volume-changed', Lang.bind(this, this._updateDevices)); + this._volumeMonitor.connect('mount-added', Lang.bind(this, this._updateDevices)); + this._volumeMonitor.connect('mount-removed', Lang.bind(this, this._updateDevices)); + this._volumeMonitor.connect('mount-changed', Lang.bind(this, this._updateDevices)); + this._volumeMonitor.connect('drive-connected', Lang.bind(this, this._updateDevices)); + this._volumeMonitor.connect('drive-disconnected', Lang.bind(this, this._updateDevices)); + this._volumeMonitor.connect('drive-changed', Lang.bind(this, this._updateDevices)); + this._updateDevices(); + let networkApp = null; try { networkApp = Shell.AppSystem.get_default().load_from_desktop_file('gnome-network-scheme.desktop'); @@ -197,6 +217,62 @@ Places.prototype = { }); this._dirsBox.append(item.actor, Big.BoxPackFlags.NONE); } + }, + + _updateDevices: function() { + this._devBox.remove_all(); + + /* first go through all connected drives */ + let drives = this._volumeMonitor.get_connected_drives(); + for (let i = 0; i < drives.length; i++) { + let volumes = drives[i].get_volumes(); + for(let j = 0; j < volumes.length; j++) { + let mount = volumes[j].get_mount(); + if(mount != null) { + this._addMount(mount); + } + } + } + + /* add all volumes that is not associated with a drive */ + let volumes = this._volumeMonitor.get_volumes(); + for(let i = 0; i < volumes.length; i++) { + if(volumes[i].get_drive() != null) + continue; + + let mount = volumes[i].get_mount(); + if(mount != null) { + this._addMount(mount); + } + } + + /* add mounts that have no volume (/etc/mtab mounts, ftp, sftp,...) */ + let mounts = this._volumeMonitor.get_mounts(); + for(let i = 0; i < mounts.length; i++) { + if(mounts[i].is_shadowed()) + continue; + + if(mounts[i].get_volume()) + continue; + + this._addMount(mounts[i]); + } + }, + + _addMount: function(mount) { + let mountLabel = mount.get_name(); + let mountIcon = mount.get_icon(); + let root = mount.get_root(); + let mountUri = root.get_uri(); + let devItem = new PlaceDisplay(mountLabel, + function() { + return Shell.TextureCache.get_default().load_gicon(mountIcon, PLACES_ICON_SIZE); + }, + function() { + Gio.app_info_launch_default_for_uri(mountUri, Main.createAppLaunchContext()); + }); + this._devBox.append(devItem.actor, Big.BoxPackFlags.NONE); } + }; Signals.addSignalMethods(Places.prototype);