[banshee] [Metadata] Add metadata-saving support for FSQ
- From: Andrés Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] [Metadata] Add metadata-saving support for FSQ
- Date: Sat, 29 May 2010 18:27:47 +0000 (UTC)
commit add40560eca0c57c0dd4be16b76fa5ae84e23d89
Author: Andrés G. Aragoneses <knocte gmail com>
Date: Sat May 29 20:24:45 2010 +0200
[Metadata] Add metadata-saving support for FSQ
This patch extends SaveTrackMetadataJob to be able to support more than
one primary source to be watched for metadata changes, so we now can
disable the ReadOnly mode for the TrackEditor when the user launches it
from the FileSystemQueueSource, but without letting the file be changed
on each play if the "Save ratings and playcounts" option is enabled.
Reviewed by Alexander Kojevnikov, and some parts (like the change in
DatabaseTrackInfo.cs) done by himself as well, kudos! (BGO#609411)
.../DatabaseTrackInfo.cs | 10 +++++++-
.../Banshee.Metadata/SaveTrackMetadataJob.cs | 25 +++++++++++++------
.../FileSystemQueueSource.cs | 4 +++
3 files changed, 30 insertions(+), 9 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
index 8f493d9..1a7b40b 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
@@ -188,7 +188,15 @@ namespace Banshee.Collection.Database
// TODO get rid of unused artists/albums
}
- if (fields_changed.Length == 0 || !transient_fields.IsSupersetOf (fields_changed)) {
+ // If PlayCountField is not transient we still want to update the file only if it's from the music library
+ Â Â Â Â Â Â var transient = transient_fields;
+ Â Â Â Â Â Â if (!transient.Contains (BansheeQuery.PlayCountField) &&
+ Â Â Â Â Â Â Â Â !ServiceManager.SourceManager.MusicLibrary.Equals (PrimarySource)) {
+ Â Â Â Â Â Â Â Â transient = new HashSet<QueryField> (transient_fields);
+ Â Â Â Â Â Â Â Â transient.Add (BansheeQuery.PlayCountField);
+ Â Â Â Â Â Â }
+
+ Â Â Â Â Â Â if (fields_changed.Length == 0 || !transient.IsSupersetOf (fields_changed)) {
DateUpdated = DateTime.Now;
}
diff --git a/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs b/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs
index 217009e..0f5ed1b 100644
--- a/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs
+++ b/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs
@@ -29,6 +29,7 @@
//
using System;
+using System.Linq;
using Mono.Unix;
using Hyena.Jobs;
@@ -46,20 +47,26 @@ namespace Banshee.Metadata
{
public class SaveTrackMetadataJob : DbIteratorJob
{
- private LibrarySource source = ServiceManager.SourceManager.MusicLibrary;
+ private LibrarySource musicLibrarySource = ServiceManager.SourceManager.MusicLibrary;
public SaveTrackMetadataJob () : base (Catalog.GetString ("Saving Metadata to File"))
{
SetResources (Resource.Cpu, Resource.Disk, Resource.Database);
IsBackground = true;
- CountCommand = new HyenaSqliteCommand (
- "SELECT COUNT(*) FROM CoreTracks WHERE DateUpdatedStamp > LastSyncedStamp AND PrimarySourceID = ?",
- source.DbId
+ var db_ids = ServiceManager.Get<SaveTrackMetadataService> ().Sources.
+ Select (s => s.DbId.ToString ()).ToArray ();
+
+ string range = String.Join (",", db_ids);
+
+ CountCommand = new HyenaSqliteCommand (String.Format (
+ @"SELECT COUNT(*) FROM CoreTracks
+ WHERE DateUpdatedStamp > LastSyncedStamp
+ AND PrimarySourceID IN ({0})", range)
);
SelectCommand = DatabaseTrackInfo.Provider.CreateFetchCommand (String.Format (
- "DateUpdatedStamp > LastSyncedStamp AND PrimarySourceID = {0}", source.DbId)
+ "DateUpdatedStamp > LastSyncedStamp AND PrimarySourceID IN ({0})", range)
);
}
@@ -87,7 +94,9 @@ namespace Banshee.Metadata
wrote = StreamTagger.SaveToFile (track, WriteMetadataEnabled, WriteRatingsAndPlayCountsEnabled);
}
- if (RenameEnabled) {
+ // Rename tracks only from the Music Library
+ if (RenameEnabled &&
+ track.PrimarySource.Equals (musicLibrarySource)) {
Hyena.Log.DebugFormat ("Updating file name for {0}", track);
renamed = RenameFile (track);
if (renamed && !wrote) {
@@ -115,13 +124,13 @@ namespace Banshee.Metadata
private bool RenameFile (DatabaseTrackInfo track)
{
SafeUri old_uri = track.Uri;
- bool in_library = old_uri.AbsolutePath.StartsWith (source.BaseDirectoryWithSeparator);
+ bool in_library = old_uri.AbsolutePath.StartsWith (musicLibrarySource.BaseDirectoryWithSeparator);
if (!in_library) {
return false;
}
- string new_filename = track.PathPattern.BuildFull (source.BaseDirectory, track, System.IO.Path.GetExtension (old_uri.ToString ()));
+ string new_filename = track.PathPattern.BuildFull (musicLibrarySource.BaseDirectory, track, System.IO.Path.GetExtension (old_uri.ToString ()));
SafeUri new_uri = new SafeUri (new_filename);
if (!new_uri.Equals (old_uri) && !Banshee.IO.File.Exists (new_uri)) {
diff --git a/src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue/FileSystemQueueSource.cs b/src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue/FileSystemQueueSource.cs
index a5e799c..e8abf67 100644
--- a/src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue/FileSystemQueueSource.cs
+++ b/src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue/FileSystemQueueSource.cs
@@ -238,6 +238,10 @@ namespace Banshee.FileSystemQueue
}
}
+ public override bool HasEditableTrackProperties {
+ get { return true; }
+ }
+
private void OnTrackModelReloaded (object sender, EventArgs args)
{
if (Count > 0 && !visible) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]