[baobab] Improve detection of duplicated locations
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab] Improve detection of duplicated locations
- Date: Sun, 31 May 2020 08:07:04 +0000 (UTC)
commit 03d7c2bd653d202cc3ed42e97c88aa07dfa3353c
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sat May 30 19:21:04 2020 +0200
Improve detection of duplicated locations
src/baobab-location-list.vala | 37 ++++++++++++++++++++++++++++++-------
src/baobab-location.vala | 11 +++--------
2 files changed, 33 insertions(+), 15 deletions(-)
---
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index 5ea7957..2eb4658 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -148,6 +148,25 @@ namespace Baobab {
}
void volume_changed (Volume volume) {
+ foreach (var location in locations) {
+ if (location.volume == volume) {
+ location.update_volume_info ();
+ }
+ }
+
+ // Collect duplicated mounts
+ var mount = volume.get_mount ();
+ if (mount == null) {
+ return;
+ }
+ foreach (var location in locations) {
+ // We can't just check location.mount == mount because there could be multiple GMounts with
the same root...
+ var same_mount = location.mount != null && location.mount.get_root ().equal (mount.get_root
());
+ if (same_mount && location.volume != volume) {
+ locations.remove(location);
+ }
+ }
+
update ();
}
@@ -164,6 +183,10 @@ namespace Baobab {
void volume_added (Volume volume) {
locations.append (new Location.from_volume (volume));
+ volume.changed.connect (() => {
+ volume_changed (volume);
+ });
+
update ();
}
@@ -171,8 +194,13 @@ namespace Baobab {
}
void mount_removed (Mount mount) {
+ var volume = mount.get_volume ();
+ if (volume != null) {
+ volume_changed (volume);
+ }
+
foreach (var location in locations) {
- if (location.mount == mount) {
+ if (location.mount == mount && location.volume == null) {
locations.remove (location);
break;
}
@@ -188,12 +216,7 @@ namespace Baobab {
locations.append (new Location.from_mount (mount));
}
} else {
- foreach (var location in locations) {
- if (location.volume == volume) {
- location.update ();
- break;
- }
- }
+ volume_changed (volume);
}
update ();
diff --git a/src/baobab-location.vala b/src/baobab-location.vala
index 909a8c9..779a2a2 100644
--- a/src/baobab-location.vala
+++ b/src/baobab-location.vala
@@ -81,9 +81,6 @@ namespace Baobab {
public Location.from_volume (Volume volume_) {
volume = volume_;
- volume.changed.connect((vol) => {
- update_volume_info ();
- });
update_volume_info ();
}
@@ -129,11 +126,7 @@ namespace Baobab {
scanner = new Scanner (file, flags);
}
- public void update () {
- update_volume_info ();
- }
-
- void update_volume_info () {
+ public void update_volume_info () {
mount = volume.get_mount ();
is_remote = volume.get_identifier (VolumeIdentifier.CLASS) == "network";
@@ -148,6 +141,8 @@ namespace Baobab {
used = null;
scanner = null;
}
+
+ changed ();
}
void fill_from_mount () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]