[banshee] Avoid some code duplication around Unknown tags



commit 7b210ef83bce8e08847ad130ca4701ce254855ee
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Sat Jan 19 19:13:43 2013 +0000

    Avoid some code duplication around Unknown tags
    
    No change of behaviour in this commit.

 src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs |   22 ++++++++++++-------
 .../Banshee.Core/Banshee.Collection/AlbumInfo.cs   |    1 +
 .../Banshee.Core/Banshee.Collection/ArtistInfo.cs  |    1 +
 .../Banshee.Core/Banshee.Collection/TrackInfo.cs   |    1 +
 .../Banshee.Database/BansheeDbFormatMigrator.cs    |   20 ++++++++++-------
 .../AudioCdDiscModel.cs                            |    4 +-
 6 files changed, 31 insertions(+), 18 deletions(-)
---
diff --git a/src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs b/src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs
index 3ab2849..16cf854 100644
--- a/src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs
+++ b/src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs
@@ -35,16 +35,12 @@ using System.Text;
 using System.Text.RegularExpressions;
 
 using Mono.Unix;
+using Banshee.Collection;
 
 namespace Banshee.Base
 {
     public static class CoverArtSpec
     {
-        private static string unknown_artist_tr = Catalog.GetString ("Unknown Artist");
-        private static string unknown_artist = "Unknown Artist";
-        private static string unknown_album_tr = Catalog.GetString ("Unknown Album");
-        private static string unknown_album = "Unknown Album";
-
         public static bool CoverExists (string artist, string album)
         {
             return CoverExists (CreateArtistAlbumId (artist, album));
@@ -87,12 +83,12 @@ namespace Banshee.Base
 
         public static string CreateArtistAlbumId (string artist, string album)
         {
-            if (album == null || album == unknown_album || album == unknown_album_tr) {
+            if (IsAlbumUnknown (album)) {
                 // do not attempt to group unknown album tracks together
                 return null;
             }
 
-            if (artist == null || artist == unknown_artist || artist == unknown_artist_tr) {
+            if (IsArtistUnknown (artist)) {
                 return null;
             }
 
@@ -114,6 +110,16 @@ namespace Banshee.Base
             Hyena.Log.DebugFormat ("Album artwork path set to {0}", root_path);
         }
 
+        static bool IsAlbumUnknown (string album)
+        {
+            return album == null || album == AlbumInfo.UnknownAlbumTitleUntranslated || album == AlbumInfo.UnknownAlbumTitle;
+        }
+
+        static bool IsArtistUnknown (string artist)
+        {
+            return artist == null || artist == ArtistInfo.UnknownArtistNameUntranslated || artist == ArtistInfo.UnknownArtistName;
+        }
+
         private static string root_path = Path.Combine (XdgBaseDirectorySpec.GetUserDirectory (
             "XDG_CACHE_HOME", ".cache"),  "media-art");
 
@@ -132,7 +138,7 @@ namespace Banshee.Base
 
         public static string CreateLegacyArtistAlbumId (string artist, string album)
         {
-            if (artist == unknown_artist || artist == unknown_artist_tr || album == unknown_album || album == unknown_album_tr) {
+            if (IsArtistUnknown (artist) || IsAlbumUnknown (album)) {
                 return null;
             }
 
diff --git a/src/Core/Banshee.Core/Banshee.Collection/AlbumInfo.cs b/src/Core/Banshee.Core/Banshee.Collection/AlbumInfo.cs
index 0d9fbc1..44124aa 100644
--- a/src/Core/Banshee.Core/Banshee.Collection/AlbumInfo.cs
+++ b/src/Core/Banshee.Core/Banshee.Collection/AlbumInfo.cs
@@ -38,6 +38,7 @@ namespace Banshee.Collection
     public class AlbumInfo : CacheableItem
     {
         public static readonly string UnknownAlbumTitle = Catalog.GetString ("Unknown Album");
+        public static readonly string UnknownAlbumTitleUntranslated = "Unknown Album";
 
         private string title;
         private string title_sort;
diff --git a/src/Core/Banshee.Core/Banshee.Collection/ArtistInfo.cs b/src/Core/Banshee.Core/Banshee.Collection/ArtistInfo.cs
index bbf9253..50025b7 100644
--- a/src/Core/Banshee.Core/Banshee.Collection/ArtistInfo.cs
+++ b/src/Core/Banshee.Core/Banshee.Collection/ArtistInfo.cs
@@ -35,6 +35,7 @@ namespace Banshee.Collection
     public class ArtistInfo : CacheableItem
     {
         public static readonly string UnknownArtistName = Catalog.GetString ("Unknown Artist");
+        public static readonly string UnknownArtistNameUntranslated = "Unknown Artist";
 
         private string name;
         private string name_sort;
diff --git a/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs b/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs
index 8ecefc7..2014e72 100644
--- a/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs
+++ b/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs
@@ -47,6 +47,7 @@ namespace Banshee.Collection
         public static readonly double PlaybackSkippedThreshold = 0.5;
 
         public static readonly string UnknownTitle = Catalog.GetString ("Unknown Title");
+        public static readonly string UnknownTitleUntranslated = "Unknown Title";
 
         public class ExportableAttribute : Attribute
         {
diff --git a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
index f63455d..522f556 100644
--- a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
+++ b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
@@ -603,25 +603,29 @@ namespace Banshee.Database
         [DatabaseVersion (26)]
         private bool Migrate_26 ()
         {
-            string unknown_artist = "Unknown Artist";
-            string unknown_album = "Unknown Album";
-            string unknown_title = "Unknown Title";
-
             connection.Execute ("UPDATE CoreArtists SET Name = NULL, NameLowered = HYENA_SEARCH_KEY(?)" +
                                 " WHERE Name  IN ('', ?, ?) OR Name IS NULL",
-                                ArtistInfo.UnknownArtistName, unknown_artist, ArtistInfo.UnknownArtistName);
+                                ArtistInfo.UnknownArtistName,
+                                ArtistInfo.UnknownArtistNameUntranslated,
+                                ArtistInfo.UnknownArtistName);
 
             connection.Execute ("UPDATE CoreAlbums SET ArtistName = NULL, ArtistNameLowered = HYENA_SEARCH_KEY(?)" +
                                 " WHERE ArtistName IN ('', ?, ?) OR ArtistName IS NULL",
-                                ArtistInfo.UnknownArtistName, unknown_artist, ArtistInfo.UnknownArtistName);
+                                ArtistInfo.UnknownArtistName,
+                                ArtistInfo.UnknownArtistNameUntranslated,
+                                ArtistInfo.UnknownArtistName);
 
             connection.Execute ("UPDATE CoreAlbums SET Title = NULL, TitleLowered = HYENA_SEARCH_KEY(?)" +
                                 " WHERE Title IN ('', ?, ?) OR Title IS NULL",
-                                AlbumInfo.UnknownAlbumTitle, unknown_album, AlbumInfo.UnknownAlbumTitle);
+                                AlbumInfo.UnknownAlbumTitle,
+                                AlbumInfo.UnknownAlbumTitleUntranslated,
+                                AlbumInfo.UnknownAlbumTitle);
 
             connection.Execute ("UPDATE CoreTracks SET Title = NULL, TitleLowered = HYENA_SEARCH_KEY(?)" +
                                 " WHERE Title IN ('', ?, ?) OR Title IS NULL",
-                                TrackInfo.UnknownTitle, unknown_title, TrackInfo.UnknownTitle);
+                                TrackInfo.UnknownTitle,
+                                TrackInfo.UnknownTitleUntranslated,
+                                TrackInfo.UnknownTitle);
 
             return true;
         }
diff --git a/src/Extensions/Banshee.OpticalDisc/Banshee.OpticalDisc.AudioCd/AudioCdDiscModel.cs b/src/Extensions/Banshee.OpticalDisc/Banshee.OpticalDisc.AudioCd/AudioCdDiscModel.cs
index 842ec2b..a93bf10 100644
--- a/src/Extensions/Banshee.OpticalDisc/Banshee.OpticalDisc.AudioCd/AudioCdDiscModel.cs
+++ b/src/Extensions/Banshee.OpticalDisc/Banshee.OpticalDisc.AudioCd/AudioCdDiscModel.cs
@@ -98,8 +98,8 @@ namespace Banshee.OpticalDisc.AudioCd
                 track.TrackCount = n;
                 track.DiscNumber = 1;
                 track.Duration = durations[i];
-                track.ArtistName = Catalog.GetString ("Unknown Artist");
-                track.AlbumTitle = Catalog.GetString ("Unknown Album");
+                track.ArtistName = ArtistInfo.UnknownArtistName;
+                track.AlbumTitle = AlbumInfo.UnknownAlbumTitle;
                 track.TrackTitle = String.Format (Catalog.GetString ("Track {0}"), track.TrackNumber);
                 track.FileSize = PCM_FACTOR * (uint)track.Duration.TotalSeconds;
                 Add (track);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]