[banshee] File Policies are dependend on Source
- From: Alexander Kojevnikov <alexk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] File Policies are dependend on Source
- Date: Fri, 29 Jun 2012 14:41:11 +0000 (UTC)
commit 37497cd468a7c45925b7a3e15968f7cfa10fc701
Author: Samuel Gyger <samuel gyger at>
Date: Fri May 25 18:50:25 2012 +0200
File Policies are dependend on Source
Added the Options copy-on-import and move-files to LibrarySource, which
makes it dependend on the Source if your files are copied to the
SourceDirectory or renamed on Metadata changes. Settings are migrated.
Closes bgo#535911
Signed-off-by: Alexander Kojevnikov <alexk gnome org>
.../DatabaseTrackInfo.cs | 8 +++-
.../Banshee.Library/LibrarySchema.cs | 7 ---
.../Banshee.Library/LibrarySource.cs | 44 ++++++++++++++++++++
.../Banshee.Library/MusicLibrarySource.cs | 17 ++++++++
.../Banshee.Library/VideoLibrarySource.cs | 12 +++++
.../Banshee.Metadata/SaveTrackMetadataJob.cs | 8 ++--
.../Banshee.Metadata/SaveTrackMetadataService.cs | 13 +-----
.../Banshee.Preferences/PreferenceService.cs | 4 --
.../Banshee.Sources/PrimarySource.cs | 2 +-
9 files changed, 87 insertions(+), 28 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
index 92dd047..1b5f984 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
@@ -731,6 +731,12 @@ namespace Banshee.Collection.Database
{
bool copy_success = true;
+ LibrarySource library_source = PrimarySource as LibrarySource;
+ if (library_source == null) {
+ // Get out, not a local Library
+ return false;
+ }
+
SafeUri old_uri = this.Uri;
if (old_uri == null) {
// Get out quick, no URI set yet.
@@ -739,7 +745,7 @@ namespace Banshee.Collection.Database
bool in_library = old_uri.IsLocalPath ? old_uri.AbsolutePath.StartsWith (PrimarySource.BaseDirectoryWithSeparator) : false;
- if (!in_library && (LibrarySchema.CopyOnImport.Get () || force_copy)) {
+ if (!in_library && ((library_source.HasCopyOnImport && library_source.CopyOnImport) || force_copy)) {
string new_filename = PathPattern.BuildFull (PrimarySource.BaseDirectory, this, Path.GetExtension (old_uri.ToString ()));
SafeUri new_uri = new SafeUri (new_filename);
diff --git a/src/Core/Banshee.Services/Banshee.Library/LibrarySchema.cs b/src/Core/Banshee.Services/Banshee.Library/LibrarySchema.cs
index efc5da4..3d1ff7e 100644
--- a/src/Core/Banshee.Services/Banshee.Library/LibrarySchema.cs
+++ b/src/Core/Banshee.Services/Banshee.Library/LibrarySchema.cs
@@ -55,13 +55,6 @@ namespace Banshee.Configuration.Schema
"%album_artist_initial%, %artist% (deprecated, use %album_artist%)."
);
- public static readonly SchemaEntry<bool> CopyOnImport = new SchemaEntry<bool>(
- "library", "copy_on_import",
- false,
- "Copy music on import",
- "Copy and rename music to banshee music library directory when importing"
- );
-
public static readonly SchemaEntry<bool> MoveOnInfoSave = new SchemaEntry<bool>(
"library", "move_on_info_save",
false,
diff --git a/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs b/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs
index 6e3c03d..d8f6b9b 100644
--- a/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs
+++ b/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs
@@ -42,6 +42,7 @@ using Banshee.ServiceStack;
using Banshee.Preferences;
using Banshee.Collection;
using Banshee.Collection.Database;
+using Banshee.Configuration;
namespace Banshee.Library
{
@@ -49,8 +50,12 @@ namespace Banshee.Library
{
// Deprecated, don't use in new code
internal static readonly Banshee.Configuration.SchemaEntry<string> OldLocationSchema = new Banshee.Configuration.SchemaEntry<string> ("library", "base_location", null, null, null);
+ internal static readonly Banshee.Configuration.SchemaEntry<bool> OldImportSetting = new Banshee.Configuration.SchemaEntry<bool> ("library", "copy_on_import", false, null, null);
+ internal static readonly Banshee.Configuration.SchemaEntry<bool> OldRenameSetting = new Banshee.Configuration.SchemaEntry<bool> ("library", "move_on_info_save", false, null, null);
private Banshee.Configuration.SchemaEntry<string> base_dir_schema;
+ private Banshee.Configuration.SchemaEntry<bool> copy_on_import;
+ private Banshee.Configuration.SchemaEntry<bool> move_files;
public LibrarySource (string label, string name, int order) : base (label, label, name, order)
{
@@ -58,11 +63,30 @@ namespace Banshee.Library
Properties.SetString ("RemoveTracksActionLabel", Catalog.GetString ("Remove From Library"));
IsLocal = true;
base_dir_schema = CreateSchema<string> ("library-location", null, "The base directory under which files for this library are stored", null);
+ copy_on_import = CreateSchema<bool> ("copy-on-import", false, "Copy files on import", "Copy and rename files to library directory when importing");
+ move_files = CreateSchema<bool>("move-on-info-save", false, "Move music on info save", "Move music within banshee music library directory when saving track info");
+
AfterInitialized ();
Section library_section = PreferencesPage.Add (new Section ("library-location", SectionName, 2));
library_section.Add (base_dir_schema);
+
+ if (this.HasCopyOnImport || this.HasMoveFiles) {
+ var file_system = PreferencesPage.FindOrAdd (new Section ("file-system", Catalog.GetString ("File Organization"), 5));
+
+ if (this.HasCopyOnImport) {
+ file_system.Add ( new SchemaPreference<bool> (copy_on_import, Catalog.GetString ("Co_py files to media folder when importing")));
+ }
+
+ if (this.HasMoveFiles) {
+ file_system.Add ( new SchemaPreference<bool> (
+ move_files,
+ Catalog.GetString ("_Update file and folder names"),
+ Catalog.GetString ("Rename files and folders according to media metadata")
+ ));
+ }
+ }
}
public string AttributesCondition {
@@ -111,6 +135,26 @@ namespace Banshee.Library
public abstract string DefaultBaseDirectory { get; }
+ public bool CopyOnImport {
+ get { return copy_on_import.Get (); }
+
+ protected set { copy_on_import.Set (value); }
+ }
+
+ public virtual bool HasCopyOnImport {
+ get { return false; }
+ }
+
+ public bool MoveFiles {
+ get { return move_files.Get (); }
+
+ protected set { move_files.Set (value); }
+ }
+
+ public virtual bool HasMoveFiles {
+ get { return false; }
+ }
+
public override bool Indexable {
get { return true; }
}
diff --git a/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs b/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs
index e1432c2..2fc7bc8 100644
--- a/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs
+++ b/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs
@@ -74,6 +74,15 @@ namespace Banshee.Library
DatabaseConfigurationClient.Client.Set<int> ("MusicLibraryLocationMigrated", 1);
}
+ // Migrate the old import and rename settings, if necessary
+ if (DatabaseConfigurationClient.Client.Get<int> ("MusicImportSettingsMigrated", 0) != 1) {
+ bool oldImportSettings = OldImportSetting.Get ();
+ bool oldRenameSettings = OldRenameSetting.Get ();
+ CopyOnImport = oldImportSettings;
+ MoveFiles = oldRenameSettings;
+ DatabaseConfigurationClient.Client.Set<int> ("MusicImportSettingsMigrated", 1);
+ }
+
SetFileNamePattern (MusicFileNamePattern);
Section misc = PreferencesPage.Add (new Section ("misc",
@@ -110,6 +119,14 @@ namespace Banshee.Library
get { return non_default_smart_playlists; }
}
+ public override bool HasCopyOnImport {
+ get { return true; }
+ }
+
+ public override bool HasMoveFiles {
+ get { return true; }
+ }
+
protected override string SectionName {
get { return Catalog.GetString ("Music Folder"); }
}
diff --git a/src/Core/Banshee.Services/Banshee.Library/VideoLibrarySource.cs b/src/Core/Banshee.Services/Banshee.Library/VideoLibrarySource.cs
index 64e2f14..894983e 100644
--- a/src/Core/Banshee.Services/Banshee.Library/VideoLibrarySource.cs
+++ b/src/Core/Banshee.Services/Banshee.Library/VideoLibrarySource.cs
@@ -34,6 +34,7 @@ using Mono.Unix;
using Banshee.SmartPlaylist;
using Banshee.Collection;
+using Banshee.Configuration;
namespace Banshee.Library
{
@@ -63,6 +64,13 @@ namespace Banshee.Library
</column>
</column-controller>
", Catalog.GetString ("Produced By")));
+
+ // Migrate the old import settings, if necessary
+ if (DatabaseConfigurationClient.Client.Get<int> ("VideoImportSettingsMigrated", 0) != 1) {
+ bool oldImportSettings = OldImportSetting.Get ();
+ CopyOnImport = oldImportSettings;
+ DatabaseConfigurationClient.Client.Set<int> ("VideoImportSettingsMigrated", 1);
+ }
}
public override string GetPluralItemCountString (int count)
@@ -86,6 +94,10 @@ namespace Banshee.Library
get { return default_smart_playlists; }
}
+ public override bool HasCopyOnImport {
+ get { return true; }
+ }
+
protected override string SectionName {
get { return Catalog.GetString ("Videos Folder"); }
}
diff --git a/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs b/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs
index b49673d..44c6e97 100644
--- a/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs
+++ b/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs
@@ -75,7 +75,6 @@ namespace Banshee.Metadata
public bool WriteMetadataEnabled { get; set; }
public bool WriteRatingsEnabled { get; set; }
public bool WritePlayCountsEnabled { get; set; }
- public bool RenameEnabled { get; set; }
private HyenaSqliteCommand update_synced_at;
@@ -97,9 +96,10 @@ namespace Banshee.Metadata
wrote = StreamTagger.SaveToFile (track, WriteMetadataEnabled, WriteRatingsEnabled, WritePlayCountsEnabled);
}
- // Rename tracks only from the Music Library
- if (RenameEnabled &&
- track.PrimarySource.Equals (musicLibrarySource)) {
+ // Rename tracks only from Libraries that support it.
+ var track_source = track.PrimarySource as LibrarySource;
+ if (null != track_source && track_source.HasMoveFiles &&
+ track_source.MoveFiles) {
Hyena.Log.DebugFormat ("Updating file name for {0}", track);
renamed = RenameFile (track);
if (renamed && !wrote) {
diff --git a/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataService.cs b/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataService.cs
index f9a0c3d..20eab6f 100644
--- a/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataService.cs
+++ b/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataService.cs
@@ -62,12 +62,6 @@ namespace Banshee.Metadata
Catalog.GetString ("Enable this option to have playcount metadata synced between your library and supported audio files")
);
- public static SchemaPreference<bool> RenameEnabled = new SchemaPreference<bool> (
- LibrarySchema.MoveOnInfoSave,
- Catalog.GetString ("_Update file and folder names"),
- Catalog.GetString ("Rename files and folders according to media metadata")
- );
-
private SaveTrackMetadataJob job;
private object sync = new object ();
private bool inited = false;
@@ -82,7 +76,6 @@ namespace Banshee.Metadata
WriteMetadataEnabled.ValueChanged += OnEnabledChanged;
WriteRatingsEnabled.ValueChanged += OnEnabledChanged;
WritePlayCountsEnabled.ValueChanged += OnEnabledChanged;
- RenameEnabled.ValueChanged += OnEnabledChanged;
foreach (var source in ServiceManager.SourceManager.Sources) {
AddPrimarySource (source);
@@ -135,7 +128,7 @@ namespace Banshee.Metadata
private void Save ()
{
- if (!(WriteMetadataEnabled.Value || WriteRatingsEnabled.Value || WritePlayCountsEnabled.Value || RenameEnabled.Value))
+ if (!(WriteMetadataEnabled.Value || WriteRatingsEnabled.Value || WritePlayCountsEnabled.Value))
return;
lock (sync) {
@@ -143,13 +136,11 @@ namespace Banshee.Metadata
job.WriteMetadataEnabled = WriteMetadataEnabled.Value;
job.WriteRatingsEnabled = WriteRatingsEnabled.Value;
job.WritePlayCountsEnabled = WritePlayCountsEnabled.Value;
- job.RenameEnabled = RenameEnabled.Value;
} else {
var new_job = new SaveTrackMetadataJob () {
WriteMetadataEnabled = WriteMetadataEnabled.Value,
WriteRatingsEnabled = WriteRatingsEnabled.Value,
WritePlayCountsEnabled = WritePlayCountsEnabled.Value,
- RenameEnabled = RenameEnabled.Value
};
new_job.Finished += delegate { lock (sync) { job = null; } };
job = new_job;
@@ -165,7 +156,7 @@ namespace Banshee.Metadata
private void OnEnabledChanged (Root pref)
{
- if (WriteMetadataEnabled.Value || WriteRatingsEnabled.Value || WritePlayCountsEnabled.Value || RenameEnabled.Value) {
+ if (WriteMetadataEnabled.Value || WriteRatingsEnabled.Value || WritePlayCountsEnabled.Value) {
Save ();
} else {
if (job != null) {
diff --git a/src/Core/Banshee.Services/Banshee.Preferences/PreferenceService.cs b/src/Core/Banshee.Services/Banshee.Preferences/PreferenceService.cs
index 8d61651..66e57ea 100644
--- a/src/Core/Banshee.Services/Banshee.Preferences/PreferenceService.cs
+++ b/src/Core/Banshee.Services/Banshee.Preferences/PreferenceService.cs
@@ -54,13 +54,9 @@ namespace Banshee.Preferences
// General policies
Section policies = general.Add (new Section ("policies", Catalog.GetString ("File Policies"), 0));
- policies.Add (new SchemaPreference<bool> (LibrarySchema.CopyOnImport,
- Catalog.GetString ("Co_py files to media folders when importing")));
-
policies.Add (Banshee.Metadata.SaveTrackMetadataService.WriteMetadataEnabled);
policies.Add (Banshee.Metadata.SaveTrackMetadataService.WriteRatingsEnabled);
policies.Add (Banshee.Metadata.SaveTrackMetadataService.WritePlayCountsEnabled);
- policies.Add (Banshee.Metadata.SaveTrackMetadataService.RenameEnabled);
// Misc section
var misc = new Section ("misc", Catalog.GetString ("Miscellaneous"), 20);
diff --git a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
index 9c2f310..c935aaa 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
@@ -246,7 +246,7 @@ namespace Banshee.Sources
{
PathPattern = pattern;
- var file_system = PreferencesPage.Add (new Section ("file-system", Catalog.GetString ("File Organization"), 5));
+ var file_system = PreferencesPage.FindOrAdd (new Section ("file-system", Catalog.GetString ("File Organization"), 5));
file_system.Add (new SchemaPreference<string> (pattern.FolderSchema, Catalog.GetString ("Folder hie_rarchy")));
file_system.Add (new SchemaPreference<string> (pattern.FileSchema, Catalog.GetString ("File _name")));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]