Implemented censored names preference
Added case sensitivity preference Integer tags are not clearable anymore
This commit is contained in:
committed by
Kim Wittenburg
parent
e2bdcd21e5
commit
257a7811d6
@@ -33,6 +33,10 @@ internal class MainViewController: NSViewController {
|
||||
static let pasteboardType = "public.item.tagtunes"
|
||||
}
|
||||
|
||||
private struct KVOContexts {
|
||||
static var preferencesContext = "KVOPreferencesContext"
|
||||
}
|
||||
|
||||
internal enum Section: String {
|
||||
case SearchResults = "SearchResults"
|
||||
case Albums = "Albums"
|
||||
@@ -59,6 +63,8 @@ internal class MainViewController: NSViewController {
|
||||
/// The URL task currently loading the search results
|
||||
private var searchTask: NSURLSessionTask?
|
||||
|
||||
private var searchTerm: String?
|
||||
|
||||
/// If `true` the search section is displayed at the top of the
|
||||
/// `outlineView`.
|
||||
internal var showsSearch: Bool = false
|
||||
@@ -73,17 +79,27 @@ internal class MainViewController: NSViewController {
|
||||
|
||||
// MARK: View Life Cycle
|
||||
|
||||
private var observerObject: NSObjectProtocol?
|
||||
// Proxy objects that act as `NSNotificationCenter` observers.
|
||||
private var observerProxies = [NSObjectProtocol]()
|
||||
|
||||
override internal func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
NSNotificationCenter.defaultCenter().addObserverForName(AlbumCollection.AlbumFinishedLoadingNotificationName, object: albumCollection, queue: NSOperationQueue.mainQueue(), usingBlock: albumCollectionDidFinishLoadingTracks)
|
||||
|
||||
let startedLoadingTracksObserver = NSNotificationCenter.defaultCenter().addObserverForName(AlbumCollection.Notifications.albumStartedLoading, object: albumCollection, queue: NSOperationQueue.mainQueue(), usingBlock: albumCollectionDidBeginLoadingTracks)
|
||||
let finishedLoadingTracksObserver = NSNotificationCenter.defaultCenter().addObserverForName(AlbumCollection.Notifications.albumFinishedLoading, object: albumCollection, queue: NSOperationQueue.mainQueue(), usingBlock: albumCollectionDidFinishLoadingTracks)
|
||||
|
||||
observerProxies.append(startedLoadingTracksObserver)
|
||||
observerProxies.append(finishedLoadingTracksObserver)
|
||||
|
||||
Preferences.sharedPreferences.addObserver(self, forKeyPath: "useCensoredNames", options: [], context: &KVOContexts.preferencesContext)
|
||||
Preferences.sharedPreferences.addObserver(self, forKeyPath: "caseSensitive", options: [], context: &KVOContexts.preferencesContext)
|
||||
|
||||
outlineView.setDraggingSourceOperationMask(.Move, forLocal: true)
|
||||
outlineView.registerForDraggedTypes([OutlineViewConstants.pasteboardType])
|
||||
}
|
||||
|
||||
deinit {
|
||||
if let observer = observerObject {
|
||||
for observer in observerProxies {
|
||||
NSNotificationCenter.defaultCenter().removeObserver(observer)
|
||||
}
|
||||
}
|
||||
@@ -192,6 +208,7 @@ internal class MainViewController: NSViewController {
|
||||
cancelSearch()
|
||||
if let url = iTunesAPI.createAlbumSearchURLForTerm(term) {
|
||||
showsSearch = true
|
||||
searchTerm = term
|
||||
searchTask = urlSession.dataTaskWithURL(url, completionHandler: processSearchResults)
|
||||
searchTask?.resume()
|
||||
} else {
|
||||
@@ -216,6 +233,7 @@ internal class MainViewController: NSViewController {
|
||||
if let theData = data where error == nil {
|
||||
do {
|
||||
let searchResults = try iTunesAPI.parseAPIData(theData).map { SearchResult(representedAlbum: $0) }
|
||||
searchTerm = nil
|
||||
self.searchResults = searchResults
|
||||
} catch let theError as NSError {
|
||||
error = theError
|
||||
@@ -257,10 +275,6 @@ internal class MainViewController: NSViewController {
|
||||
outlineView.reloadData()
|
||||
}
|
||||
|
||||
private func albumCollectionDidFinishLoadingTracks(notification: NSNotification) {
|
||||
outlineView.reloadData()
|
||||
}
|
||||
|
||||
// MARK: Albums
|
||||
|
||||
private func saveTracks(tracks: [Track: [iTunesTrack]]) {
|
||||
@@ -307,11 +321,7 @@ internal class MainViewController: NSViewController {
|
||||
if errorCount > 0 {
|
||||
dispatch_sync(dispatch_get_main_queue()) {
|
||||
let alert = NSAlert()
|
||||
if errorCount == 1 {
|
||||
alert.messageText = NSLocalizedString("1 artwork could not be saved.", comment: "Error message indicating that one of the artworks could not be saved.")
|
||||
} else {
|
||||
alert.messageText = String(format: NSLocalizedString("%d artworks could not be saved.", comment: "Error message indicating that n artworks could not be saved."), errorCount)
|
||||
}
|
||||
alert.messageText = String(format: NSLocalizedString("%d artworks could not be saved.", comment: "Error message indicating that n artworks could not be saved."), errorCount)
|
||||
alert.informativeText = NSLocalizedString("Please check your privileges for the folder you set in the preferences and try again.", comment: "Informative text for 'artwork(s) could not be saved' errors")
|
||||
alert.alertStyle = .WarningAlertStyle
|
||||
alert.addButtonWithTitle("OK")
|
||||
@@ -320,6 +330,22 @@ internal class MainViewController: NSViewController {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
private func albumCollectionDidBeginLoadingTracks(notification: NSNotification) {
|
||||
outlineView.reloadData()
|
||||
}
|
||||
|
||||
private func albumCollectionDidFinishLoadingTracks(notification: NSNotification) {
|
||||
outlineView.reloadData()
|
||||
}
|
||||
|
||||
override internal func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
|
||||
if context == &KVOContexts.preferencesContext {
|
||||
outlineView.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
/// Adds the current iTunes selection
|
||||
@@ -465,7 +491,7 @@ extension MainViewController {
|
||||
|
||||
override internal func attemptRecoveryFromError(error: NSError, optionIndex recoveryOptionIndex: Int, delegate: AnyObject?, didRecoverSelector: Selector, contextInfo: UnsafeMutablePointer<Void>) {
|
||||
let didRecover = attemptRecoveryFromError(error, optionIndex: recoveryOptionIndex)
|
||||
// TODO: Notify the delegate
|
||||
delegate?.performSelector(didRecoverSelector, withObject: didRecover, withObject: contextInfo as! AnyObject)
|
||||
}
|
||||
|
||||
override internal func attemptRecoveryFromError(error: NSError, optionIndex recoveryOptionIndex: Int) -> Bool {
|
||||
@@ -473,13 +499,15 @@ extension MainViewController {
|
||||
return true
|
||||
}
|
||||
// TODO: Implementation
|
||||
if error == searchError {
|
||||
|
||||
if let term = searchTerm where error == searchError || error.userInfo[NSUnderlyingErrorKey] === searchError {
|
||||
beginSearchForTerm(term)
|
||||
return true
|
||||
} else {
|
||||
for album in albumCollection {
|
||||
let albumError = albumCollection.errorForAlbum(album)
|
||||
if error == albumError {
|
||||
|
||||
if error == albumError || error.userInfo[NSUnderlyingErrorKey] === albumError {
|
||||
albumCollection.beginLoadingTracksForAlbum(album)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user