Re: [Banshee-List] Re: Mass Storage Support
- From: "James Stembridge" <jstembridge gmail com>
- To: banshee-list gnome org
- Subject: Re: [Banshee-List] Re: Mass Storage Support
- Date: Thu, 13 Apr 2006 17:50:31 +0100
Matt: Give the attached patch a go against clean CVS. Eject is still
broken (apparently in native code) but everything else should probably
be OK.
Gabriel: Is this a suitable format for you to incorporate or do you
want functionally separated patches?
Cheers,
James.
Index: src/Banshee.Base/Dap/Dap.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Base/Dap/Dap.cs,v
retrieving revision 1.15
diff -u -r1.15 Dap.cs
--- src/Banshee.Base/Dap/Dap.cs 9 Apr 2006 21:30:24 -0000 1.15
+++ src/Banshee.Base/Dap/Dap.cs 13 Apr 2006 16:39:52 -0000
@@ -153,6 +153,12 @@
source = new DapSource(this);
SourceManager.AddSource(source);
+ if(!Globals.UIManager.IsInitialized) {
+ Globals.UIManager.Initialized += OnUIManagerInitialized;
+ } else {
+ ReloadTracks();
+ }
+
return InitializeResult.Valid;
}
@@ -167,6 +173,13 @@
return tracks.GetEnumerator();
}
+ private void OnUIManagerInitialized(object o, EventArgs args)
+ {
+ Globals.UIManager.Initialized -= OnUIManagerInitialized;
+
+ ReloadTracks();
+ }
+
protected void OnPropertiesChanged()
{
if(PropertiesChanged != null) {
@@ -192,7 +205,7 @@
{
TrackInfo dap_track = OnTrackAdded(track);
- if(track == null) {
+ if(dap_track == null) {
return;
}
@@ -611,6 +624,7 @@
}
}
+ public abstract void ReloadTracks();
public abstract void Synchronize();
public abstract string Name { get; }
public abstract ulong StorageCapacity { get; }
Index: src/Banshee.Dap/Ipod/IpodDap.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Dap/Ipod/IpodDap.cs,v
retrieving revision 1.13
diff -u -r1.13 IpodDap.cs
--- src/Banshee.Dap/Ipod/IpodDap.cs 9 Apr 2006 21:30:26 -0000 1.13
+++ src/Banshee.Dap/Ipod/IpodDap.cs 13 Apr 2006 16:39:53 -0000
@@ -74,8 +74,6 @@
InstallProperty("Serial Number", device.SerialNumber);
InstallProperty("Firmware Version", device.FirmwareVersion);
InstallProperty("Database Version", device.SongDatabase.Version.ToString());
-
- ReloadDatabase(false);
CanCancelSave = false;
return InitializeResult.Valid;
@@ -123,7 +121,12 @@
}
}
- private void ReloadDatabase(bool refresh)
+ public override void ReloadTracks()
+ {
+ ReloadTracks(false);
+ }
+
+ private void ReloadTracks(bool refresh)
{
bool previous_database_supported = database_supported;
@@ -184,7 +187,7 @@
Console.Error.WriteLine (e);
LogCore.Instance.PushError(Catalog.GetString("Failed to synchronize iPod"), e.Message);
} finally {
- ReloadDatabase(true);
+ ReloadTracks(true);
FinishSave();
}
}
@@ -294,7 +297,7 @@
db_unsupported_container = new UnsupportedDatabaseView(this);
db_unsupported_container.Refresh += delegate(object o, EventArgs args) {
LoadIpod();
- ReloadDatabase(false);
+ ReloadTracks(false);
OnReactivate();
};
}
Index: src/Banshee.Dap/MassStorage/MassStorageDap.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Dap/MassStorage/MassStorageDap.cs,v
retrieving revision 1.6
diff -u -r1.6 MassStorageDap.cs
--- src/Banshee.Dap/MassStorage/MassStorageDap.cs 9 Apr 2006 21:30:26 -0000 1.6
+++ src/Banshee.Dap/MassStorage/MassStorageDap.cs 13 Apr 2006 16:39:53 -0000
@@ -63,7 +63,7 @@
player_device = Hal.Device.UdisToDevices (volume_device.Context, new string [] {volume_device ["info.parent"]}) [0];
usb_device = Hal.Device.UdisToDevices (player_device.Context, new string [] {player_device ["storage.physical_device"]}) [0];
} catch (Exception e) {
- return InitializeResult.Invalid;
+ return InitializeResult.Invalid;
}
if (!player_device.PropertyExists ("portable_audio_player.access_method") ||
@@ -77,31 +77,34 @@
if(!volume_device.PropertyExists ("volume.is_mounted") ||
!volume_device.GetPropertyBool("volume.is_mounted"))
return InitializeResult.WaitForPropertyChange;
-
-
- string block_device = volume_device ["block_device"];
- foreach (Gnome.Vfs.Volume vol in monitor.MountedVolumes) {
- if (vol.DevicePath == block_device) {
- this.volume = vol;
- break;
- }
+
+ volume = monitor.GetVolumeForPath(MountPoint);
+ if(volume == null) {
+ // Gnome VFS doesn't know volume is mounted yet
+ monitor.VolumeMounted += OnVolumeMounted;
+
+ is_read_only = true;
+ } else {
+ is_read_only = volume.IsReadOnly;
}
- if (volume == null)
- return InitializeResult.Invalid;
-
- is_read_only = volume.IsReadOnly;
-
base.Initialize (usb_device);
InstallProperty("Vendor", usb_device["usb.vendor"]);
-
- ReloadDatabase();
// FIXME probably should be able to cancel at some point when you can actually sync
CanCancelSave = false;
return InitializeResult.Valid;
}
+
+ public void OnVolumeMounted(object o, Gnome.Vfs.VolumeMountedArgs args) {
+ if(args.Volume.DevicePath == volume_device["block.device"]) {
+ monitor.VolumeMounted -= OnVolumeMounted;
+
+ volume = args.Volume;
+ is_read_only = volume.IsReadOnly;
+ }
+ }
public override void Dispose()
{
@@ -110,7 +113,7 @@
base.Dispose();
}
- private void ReloadDatabase()
+ public override void ReloadTracks()
{
ClearTracks (false);
@@ -145,7 +148,8 @@
public override void Eject ()
{
- volume.Unmount (UnmountCallback);
+ if(volume != null)
+ volume.Unmount (UnmountCallback);
}
private void UnmountCallback (bool succeeded, string error, string detailed_error)
@@ -170,6 +174,14 @@
return track;
string new_path = GetTrackPath (track);
+ if(File.Exists(new_path)) {
+ if(File.GetLastWriteTime(track.Uri.LocalPath) > File.GetLastWriteTime(new_path)) {
+ RemoveTrack(new MassStorageTrackInfo(new SafeUri(new_path)));
+ } else {
+ return null;
+ }
+ }
+
Directory.CreateDirectory (Path.GetDirectoryName (new_path));
File.Copy (track.Uri.LocalPath, new_path);
@@ -213,19 +225,24 @@
private string GetTrackPath (TrackInfo track)
{
string file_path = "";
+
+ string escaped_artist = FileNamePattern.Escape(track.Artist);
+ string escaped_album = FileNamePattern.Escape(track.Album);
+ string escaped_track = FileNamePattern.Escape(track.TrackNumberTitle);
+
if (player_device.PropertyExists ("portable_audio_player.filepath_format")) {
file_path = player_device.GetPropertyString ("portable_audio_player.filepath_format");
- file_path = file_path.Replace ("%Artist", track.Artist);
- file_path = file_path.Replace ("%Album", track.Album);
+ file_path = file_path.Replace ("%Artist", escaped_artist);
+ file_path = file_path.Replace ("%Album", escaped_album);
if (file_path.IndexOf ("%Track") == -1) {
- file_path = System.IO.Path.Combine (file_path, track.TrackNumberTitle);
+ file_path = System.IO.Path.Combine (file_path, escaped_track);
} else {
- file_path = file_path.Replace ("%Track", track.TrackNumberTitle);
+ file_path = file_path.Replace ("%Track", escaped_track);
}
} else {
- file_path = System.IO.Path.Combine (track.Artist, track.Album);
- file_path = System.IO.Path.Combine (file_path, track.TrackNumberTitle);
+ file_path = System.IO.Path.Combine (escaped_artist, escaped_album);
+ file_path = System.IO.Path.Combine (file_path, escaped_track);
}
file_path += Path.GetExtension (track.Uri.LocalPath);
@@ -242,7 +259,8 @@
public override string Name {
get {
- if (volume_device.PropertyExists("volume.label"))
+ if (volume_device.PropertyExists("volume.label") &&
+ (volume_device["volume.label"].Length > 0))
return volume_device["volume.label"];
if (player_device.PropertyExists("info.product"))
Index: src/Banshee.Dap/Njb/NjbDap.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Dap/Njb/NjbDap.cs,v
retrieving revision 1.12
diff -u -r1.12 NjbDap.cs
--- src/Banshee.Dap/Njb/NjbDap.cs 13 Feb 2006 22:18:11 -0000 1.12
+++ src/Banshee.Dap/Njb/NjbDap.cs 13 Apr 2006 16:39:53 -0000
@@ -119,8 +119,6 @@
InstallProperty("Serial Number", halDevice.PropertyExists("usb.serial")
? halDevice["usb.serial"] : device.SdmiIdString);
- ReloadDatabase();
-
CanCancelSave = false;
return InitializeResult.Valid;
}
@@ -134,7 +132,7 @@
base.Dispose();
}
- private void ReloadDatabase()
+ public override void ReloadTracks()
{
ClearTracks(false);
Index: src/Banshee.Dap/Njb/NjbDapTrackInfo.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Dap/Njb/NjbDapTrackInfo.cs,v
retrieving revision 1.2
diff -u -r1.2 NjbDapTrackInfo.cs
--- src/Banshee.Dap/Njb/NjbDapTrackInfo.cs 13 Feb 2006 22:18:11 -0000 1.2
+++ src/Banshee.Dap/Njb/NjbDapTrackInfo.cs 13 Apr 2006 16:39:53 -0000
@@ -74,7 +74,7 @@
private void LoadFromNjbSong(DapDevice dap)
{
- uri = new Uri(String.Format("dap://{0}/{1}", dap.Uid, song.Id));
+ uri = new SafeUri(String.Format("dap://{0}/{1}", dap.Uid, song.Id));
album = song.Album == String.Empty ? null : song.Album;
artist = song.Artist == String.Empty ? null : song.Artist;
title = song.Title == String.Empty ? null : song.Title;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]