banshee r3659 - in trunk/banshee: . src/Backends/Banshee.Hal/Banshee.HalBackend src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3659 - in trunk/banshee: . src/Backends/Banshee.Hal/Banshee.HalBackend src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage
- Date: Thu, 3 Apr 2008 22:24:51 +0100 (BST)
Author: gburt
Date: Thu Apr 3 22:24:46 2008
New Revision: 3659
URL: http://svn.gnome.org/viewvc/banshee?rev=3659&view=rev
Log:
2008-04-03 Gabriel Burt <gabriel burt gmail com>
* src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs: Bring a function
for getting the best name for a Hal.Device over from stable.
* src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/RemovableSource.cs:
Add BytesUsed, BytesCapacity, and StorageUsageFraction properties.
* src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs:
Implement BytesUsed, BytesCapacity.
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs
trunk/banshee/src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
trunk/banshee/src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/RemovableSource.cs
Modified: trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs (original)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs Thu Apr 3 22:24:46 2008
@@ -27,6 +27,7 @@
//
using System;
+using System.Collections.Generic;
using Banshee.Hardware;
@@ -58,14 +59,68 @@
public virtual string Name {
get {
if (name == null) {
- name = device["info.product"];
- if (String.IsNullOrEmpty (name)) {
- name = device["volume.label"];
+ Stack<Hal.Device> usb_devices = CollectUsbDeviceStack (device);
+ while (usb_devices.Count > 0 && name == null) {
+ name = usb_devices.Pop() ["info.product"];
}
+ name = name ?? device["volume.label"];
}
return name;
}
}
+
+ private static Stack<Hal.Device> CollectUsbDeviceStack(Hal.Device device)
+ {
+ Stack<Hal.Device> device_stack = new Stack<Hal.Device>();
+ int usb_vendor_id = -1;
+ int usb_product_id = -1;
+
+ Hal.Device tmp_device = device;
+
+ while(tmp_device != null) {
+ // Skip the SCSI parents of the player volume if they are in the tree
+ if((tmp_device.PropertyExists("info.bus") && tmp_device["info.bus"] == "scsi") ||
+ (tmp_device.PropertyExists("info.category") && tmp_device["info.category"] == "scsi_host")) {
+ device_stack.Push(tmp_device);
+ tmp_device = tmp_device.Parent;
+ continue;
+ }
+
+ bool have_usb_ids = false;
+ int _usb_vendor_id = -1;
+ int _usb_product_id = -1;
+
+ // Figure out the IDs if they exist
+ if(tmp_device.PropertyExists("usb.vendor_id") && tmp_device.PropertyExists("usb.product_id")) {
+ _usb_vendor_id = tmp_device.GetPropertyInteger("usb.vendor_id");
+ _usb_product_id = tmp_device.GetPropertyInteger("usb.product_id");
+ have_usb_ids = true;
+ } else if(tmp_device.PropertyExists("usb_device.vendor_id") && tmp_device.PropertyExists("usb_device.product_id")) {
+ _usb_vendor_id = tmp_device.GetPropertyInteger("usb_device.vendor_id");
+ _usb_product_id = tmp_device.GetPropertyInteger("usb_device.product_id");
+ have_usb_ids = true;
+ }
+
+ if(have_usb_ids) {
+ if(usb_vendor_id == -1 && usb_product_id == -1) {
+ // We found the first raw USB device, remember it
+ usb_vendor_id = _usb_vendor_id;
+ usb_product_id = _usb_product_id;
+ } else if(usb_vendor_id != _usb_vendor_id || usb_product_id != _usb_product_id) {
+ // We are no longer looking at the device we care about (could now be at a hub or something)
+ break;
+ }
+ } else if(usb_vendor_id != -1 || usb_product_id != -1) {
+ // We are no longer even looking at USB devices
+ break;
+ }
+
+ device_stack.Push(tmp_device);
+ tmp_device = tmp_device.Parent;
+ }
+
+ return device_stack;
+ }
}
}
Modified: trunk/banshee/src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs (original)
+++ trunk/banshee/src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs Thu Apr 3 22:24:46 2008
@@ -68,6 +68,14 @@
importer.QueueSource (new string [] { volume.MountPoint });
});
}
+
+ public override long BytesUsed {
+ get { return BytesCapacity - volume.Available; }
+ }
+
+ public override long BytesCapacity {
+ get { return (long) volume.Capacity; }
+ }
protected override bool IsReadOnly {
get { return volume.IsReadOnly; }
Modified: trunk/banshee/src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/RemovableSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/RemovableSource.cs (original)
+++ trunk/banshee/src/Extensions/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/RemovableSource.cs Thu Apr 3 22:24:46 2008
@@ -75,9 +75,9 @@
get { return !IsReadOnly; }
}
- /*public double DiskUsageFraction {
- get { return (double)device.StorageUsed / (double)device.StorageCapacity; }
- }*/
+ public double StorageUsageFraction {
+ get { return (double) BytesUsed / (double) BytesCapacity; }
+ }
#region Source Overrides
@@ -161,6 +161,9 @@
}
protected abstract bool IsReadOnly { get; }
+
+ public abstract long BytesUsed { get; }
+ public abstract long BytesCapacity { get; }
#endregion
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]