diff --git a/Changelog.txt b/Changelog.txt index 618b687..5483856 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -4,5 +4,12 @@ Version 1.0 Version 1.1 +Added: ++ 'Try again' option for errors. ++ Options for tags not to be saved ++ Option to use censored names ++ Option for case (in)sensitivity + Fixed: -* Error descriptions are now understandable \ No newline at end of file +* Added support for OS X 10.11 El Capitan +* Error descriptions are now more understandable \ No newline at end of file diff --git a/TagTunes/AlbumCollection.swift b/TagTunes/AlbumCollection.swift index 76f0b4e..8139070 100644 --- a/TagTunes/AlbumCollection.swift +++ b/TagTunes/AlbumCollection.swift @@ -24,37 +24,53 @@ public class AlbumCollection: CollectionType { } - // MARK: Constants - - /// Posted when an album is added to a collection. This notification is only - /// posted if the album collection actually changed. - public static let AlbumAddedNotificationName = "AlbumAddedNotificationName" - - /// Posted when an album is removed from a collection. This notification is - /// only posted if the album collection actually changed. - public static let AlbumRemovedNotificationName = "AlbumRemovedNotificationName" - - /// Posted when an album collection finished loading the tracks for an album. - /// Receiving this notification does not mean that the tracks were actually - /// loaded successfully. It just means that the network connection - /// terminated. Use `errorForAlbum` to determine if an error occured while - /// the tracks have been loaded. - /// - /// - note: Since the actual `Album` instance in the album collection may - /// change during loading its tracks it is preferred that you use the - /// `AlbumIndexKey` of the notification to determine which album finished - /// loading its tracks. You can however use the `AlbumKey` as well to access - /// the `Album` instance that is currently present in the collection at the - /// respective index. - public static let AlbumFinishedLoadingNotificationName = "AlbumFinishedLoadingNotificationName" - - /// Key in the `userInfo` dictionary of a notification. The associated value - /// is an `Int` indicating the index of the album that is affected. - public static let AlbumIndexKey = "AlbumIndexKey" - - /// Key in the `userInfo` dictionary of a notification. The associated value - /// is the `Album` instance that is affected. - public static let AlbumKey = "AlbumKey" + /// Notifications posted by an album collection. The `userInfo` of these + /// notifications contains all keys specified in `Keys`. + public struct Notifications { + + /// Posted when an album is added to a collection. This notification is + /// only posted if the album collection actually changed. + public static let albumAdded = "AlbumAddedNotificationName" + + /// Posted when an album is removed from a collection. This notification + /// is only posted if the album collection actually changed. + public static let albumRemoved = "AlbumRemovedNotificationName" + + /// Posted when the album collection started a network request for an + /// album's tracks. + /// + /// Note that the values for the keys `Album` and `AlbumIndex` for the + /// corresponding `AlbumFinishedLoading` notification may both be + /// different. + public static let albumStartedLoading = "AlbumStartedLoadingNotificationName" + + /// Posted when an album collection finished loading the tracks for an + /// album. Receiving this notification does not mean that the tracks were + /// actually loaded successfully. It just means that the networ + /// connection terminated. Use `errorForAlbum` to determine if an error + /// occured while the tracks have been loaded. + /// + /// - note: Since the actual `Album` instance in the album collection may + /// change during loading its tracks it is preferred that you use the + /// `AlbumIndexKey` of the notification to determine which album finished + /// loading its tracks. You can however use the `AlbumKey` as well to + /// access the `Album` instance that is currently present in the + /// collection at the respective index. + public static let albumFinishedLoading = "AlbumFinishedLoadingNotificationName" + + /// These constants are available as keys in the `userInfo` dictionary + /// for any notification an album collection may post. + public struct Keys { + + /// The `Album` instance affected by the notification. + public static let album = "AlbumKey" + + /// The index of the album affected by the notification. + public static let albumIndex = "AlbumIndexKey" + + } + + } // MARK: Properties @@ -94,10 +110,11 @@ public class AlbumCollection: CollectionType { public func addAlbum(album: Album, beginLoading flag: Bool = true) { if !albums.contains(album) { albums.append(album) + let userInfo: [NSObject: AnyObject] = [AlbumCollection.Notifications.Keys.album: album, AlbumCollection.Notifications.Keys.albumIndex: albums.count-1] + NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.Notifications.albumAdded, object: self, userInfo: userInfo) if flag { beginLoadingTracksForAlbum(album) } - NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.AlbumAddedNotificationName, object: self, userInfo: [AlbumCollection.AlbumIndexKey: albums.count-1]) } } @@ -115,7 +132,8 @@ public class AlbumCollection: CollectionType { let album = self[index] setAlbumState(nil, forAlbum: album) albums.removeAtIndex(index) - NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.AlbumRemovedNotificationName, object: self, userInfo: [AlbumCollection.AlbumIndexKey: index]) + let userInfo: [NSObject: AnyObject] = [AlbumCollection.Notifications.Keys.album: album, AlbumCollection.Notifications.Keys.albumIndex: index] + NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.Notifications.albumRemoved, object: self, userInfo: userInfo) } /// Begins to load the tracks for the specified album. If there is already a @@ -123,11 +141,15 @@ public class AlbumCollection: CollectionType { /// specified album have been loaded or an error occured, a /// `AlbumFinishedLoadingNotification` is posted. public func beginLoadingTracksForAlbum(album: Album) { + guard let albumIndex = albums.indexOf(album) else { + return + } let url = iTunesAPI.createAlbumLookupURLForId(album.id) let task = urlSession.dataTaskWithURL(url) { (data, response, error) -> Void in - var albumIndex = self.albums.indexOf(album)! + var newAlbumIndex = self.albums.indexOf(album)! defer { - NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.AlbumFinishedLoadingNotificationName, object: self, userInfo: [AlbumCollection.AlbumIndexKey: albumIndex]) + let userInfo: [NSObject: AnyObject] = [AlbumCollection.Notifications.Keys.album: self.albums[albumIndex], AlbumCollection.Notifications.Keys.albumIndex: albumIndex] + NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.Notifications.albumFinishedLoading, object: self, userInfo: userInfo) } guard error == nil else { if error!.code != NSUserCancelledError { @@ -137,9 +159,8 @@ public class AlbumCollection: CollectionType { } do { let newAlbum = try iTunesAPI.parseAPIData(data!)[0] - albumIndex = self.albums.indexOf(album)! - self.albums.removeAtIndex(albumIndex) - self.albums.insert(newAlbum, atIndex: albumIndex) + self.albums.removeAtIndex(newAlbumIndex) + self.albums.insert(newAlbum, atIndex: newAlbumIndex) self.setAlbumState(.Normal, forAlbum: album) } catch let error as NSError { self.setAlbumState(.Error(error), forAlbum: album) @@ -149,6 +170,9 @@ public class AlbumCollection: CollectionType { } setAlbumState(.Loading(task), forAlbum: album) task.resume() + let userInfo: [NSObject: AnyObject] = [AlbumCollection.Notifications.Keys.album: album, AlbumCollection.Notifications.Keys.albumIndex: albumIndex] + NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.Notifications.albumStartedLoading, object: self, userInfo: userInfo) + } /// Cancels the request to load the tracks for the specified album and sets diff --git a/TagTunes/AlbumTableCellView.swift b/TagTunes/AlbumTableCellView.swift index 50e4da4..1c408e3 100644 --- a/TagTunes/AlbumTableCellView.swift +++ b/TagTunes/AlbumTableCellView.swift @@ -118,7 +118,7 @@ public class AlbumTableCellView: AdvancedTableCellView { /// - loading: `true` if a loading indicator should be displayed at the /// album view. public func setupForAlbum(album: Album, loading: Bool, error: NSError?) { - textField?.stringValue = album.name + textField?.stringValue = Preferences.sharedPreferences.useCensoredNames ? album.censoredName : album.name secondaryTextField?.stringValue = album.artistName asyncImageView.downloadImageFromURL(album.artwork.hiResURL) if loading { @@ -160,7 +160,7 @@ public class AlbumTableCellView: AdvancedTableCellView { /// - selectable: `true` if the search result can be selected, `false` /// otherwise. public func setupForSearchResult(searchResult: SearchResult, selectable: Bool) { - textField?.stringValue = searchResult.name + textField?.stringValue = Preferences.sharedPreferences.useCensoredNames ? searchResult.censoredName : searchResult.name textField?.textColor = NSColor.controlTextColor() secondaryTextField?.stringValue = searchResult.artistName asyncImageView.downloadImageFromURL(searchResult.artwork.hiResURL) diff --git a/TagTunes/Base.lproj/Main.storyboard b/TagTunes/Base.lproj/Main.storyboard index 0100286..b28911d 100644 --- a/TagTunes/Base.lproj/Main.storyboard +++ b/TagTunes/Base.lproj/Main.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -731,6 +732,7 @@ CA + @@ -755,14 +757,15 @@ CA + @@ -798,12 +804,13 @@ CA + - + @@ -821,6 +828,7 @@ CA + @@ -836,7 +844,7 @@ CA - + @@ -845,17 +853,18 @@ CA - + + - + + - + + @@ -900,8 +922,9 @@ CA - - + + + @@ -914,6 +937,7 @@ CA + @@ -928,7 +952,7 @@ CA - + @@ -945,6 +969,7 @@ CA + @@ -969,25 +994,36 @@ CA + -