From dcd7d2620d62f5589193d6ee21649129f0cc0b23 Mon Sep 17 00:00:00 2001 From: Kim Wittenburg Date: Tue, 15 Sep 2015 14:17:40 +0200 Subject: [PATCH] Added option to use lower resolution artworks in TagTunes --- TagTunes/AlbumTableCellView.swift | 4 ++-- TagTunes/Artwork.swift | 16 +++++++++++++++- TagTunes/Base.lproj/Main.storyboard | 5 ++++- TagTunes/Preferences.swift | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/TagTunes/AlbumTableCellView.swift b/TagTunes/AlbumTableCellView.swift index 1c408e3..49d9df4 100644 --- a/TagTunes/AlbumTableCellView.swift +++ b/TagTunes/AlbumTableCellView.swift @@ -120,7 +120,7 @@ public class AlbumTableCellView: AdvancedTableCellView { public func setupForAlbum(album: Album, loading: Bool, error: NSError?) { textField?.stringValue = Preferences.sharedPreferences.useCensoredNames ? album.censoredName : album.name secondaryTextField?.stringValue = album.artistName - asyncImageView.downloadImageFromURL(album.artwork.hiResURL) + asyncImageView.downloadImageFromURL(album.artwork.displayImageURL) if loading { textField?.textColor = NSColor.disabledControlTextColor() rightAccessoryView = loadingIndicator @@ -163,7 +163,7 @@ public class AlbumTableCellView: AdvancedTableCellView { textField?.stringValue = Preferences.sharedPreferences.useCensoredNames ? searchResult.censoredName : searchResult.name textField?.textColor = NSColor.controlTextColor() secondaryTextField?.stringValue = searchResult.artistName - asyncImageView.downloadImageFromURL(searchResult.artwork.hiResURL) + asyncImageView.downloadImageFromURL(searchResult.artwork.displayImageURL) if selectable { button.title = NSLocalizedString("Select", comment: "Button title for 'selecting a search result'") button.enabled = true diff --git a/TagTunes/Artwork.swift b/TagTunes/Artwork.swift index 527d58b..de18c9e 100644 --- a/TagTunes/Artwork.swift +++ b/TagTunes/Artwork.swift @@ -56,7 +56,7 @@ public class Artwork: iTunesType { let filePath = directory.stringByAppendingString("/\(filename).tiff") try NSFileManager.defaultManager().createDirectoryAtPath(directory, withIntermediateDirectories: true, attributes: nil) - let _ = NSFileManager.defaultManager().createFileAtPath(filePath, contents: hiResImage?.TIFFRepresentation, attributes: nil) + let _ = NSFileManager.defaultManager().createFileAtPath(filePath, contents: saveImage?.TIFFRepresentation, attributes: nil) } // MARK: Calculated Properties @@ -103,4 +103,18 @@ public class Artwork: iTunesType { return cachedHiResImage } + /// Returns the url of an image that should be used to display this artwork + /// with respect to the user's preferences. + public var displayImageURL: NSURL { + if !Preferences.sharedPreferences.useLowResolutionArtwork && hiResURL != nil { + return hiResURL + } + return url100 + } + + /// Returns the image that should be used to save this artwork. + public var saveImage: NSImage? { + return hiResImage != nil ? hiResImage : image100 + } + } diff --git a/TagTunes/Base.lproj/Main.storyboard b/TagTunes/Base.lproj/Main.storyboard index fc6f366..262aff4 100644 --- a/TagTunes/Base.lproj/Main.storyboard +++ b/TagTunes/Base.lproj/Main.storyboard @@ -831,6 +831,9 @@ CA + + + @@ -932,7 +935,7 @@ CA - + diff --git a/TagTunes/Preferences.swift b/TagTunes/Preferences.swift index 2850af2..3e124ad 100644 --- a/TagTunes/Preferences.swift +++ b/TagTunes/Preferences.swift @@ -36,6 +36,8 @@ import Cocoa static let removeSavedAlbumsKey = "Remove Saved Albums" + static let useLowResolutionArtworkKey = "Use Low Resolution Artwork" + static let useCensoredNamesKey = "Use Censored Names" static let caseSensitiveKey = "Case Sensitive" @@ -72,6 +74,7 @@ import Cocoa UserDefaultsConstants.saveArtworkKey: false, UserDefaultsConstants.keepSearchResultsKey: false, UserDefaultsConstants.removeSavedAlbumsKey: false, + UserDefaultsConstants.useLowResolutionArtworkKey: false, UserDefaultsConstants.useCensoredNamesKey: false, UserDefaultsConstants.caseSensitiveKey: true, UserDefaultsConstants.clearArtworksKey: false @@ -121,6 +124,17 @@ import Cocoa } } + /// If `true` the main table view will use 100x100 artworks instead of full + /// sized images. This option does not affect saving. + public dynamic var useLowResolutionArtwork: Bool { + set { + NSUserDefaults.standardUserDefaults().setBool(newValue, forKey: UserDefaultsConstants.useLowResolutionArtworkKey) + } + get { + return NSUserDefaults.standardUserDefaults().boolForKey(UserDefaultsConstants.useLowResolutionArtworkKey) + } + } + // MARK: Tag Preferences /// If `true` TagTunes displays and saves censored names instead of the