Version 1.0 of TagTunes.
This commit is contained in:
69
TagTunes/Preferences.swift
Normal file
69
TagTunes/Preferences.swift
Normal file
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// Preferences.swift
|
||||
// TagTunes
|
||||
//
|
||||
// Created by Kim Wittenburg on 29.08.15.
|
||||
// Copyright © 2015 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
/// A custom interface for the `NSUserDefaults`. It is recommended to use this
|
||||
/// class insted of accessing the user defaults directly to prevent errors due
|
||||
/// to misspelled strings.
|
||||
///
|
||||
/// All properties in this class are KCO compliant.
|
||||
@objc public class Preferences: NSObject {
|
||||
|
||||
public static var sharedPreferences = Preferences()
|
||||
|
||||
/// Initializes the default preferences. This method must be called the very
|
||||
/// first time the application is launched. It is perfectly valid to call
|
||||
/// this method every time the application launches. Existing values are not
|
||||
/// overridden.
|
||||
public func initializeDefaultValues() {
|
||||
let initialArtworkFolder = NSURL.fileURLWithPath(NSHomeDirectory(), isDirectory: true)
|
||||
NSUserDefaults.standardUserDefaults().registerDefaults([
|
||||
"Save Artwork": false,
|
||||
"Keep Search Results": false,
|
||||
"Remove Saved Albums": false])
|
||||
if NSUserDefaults.standardUserDefaults().URLForKey("Artwork Target") == nil {
|
||||
NSUserDefaults.standardUserDefaults().setURL(initialArtworkFolder, forKey: "Artwork Target")
|
||||
}
|
||||
}
|
||||
|
||||
/// If `true` the album artwork should be saved to the `artworkTarget` URL
|
||||
/// when an item is saved.
|
||||
public dynamic var saveArtwork: Bool {
|
||||
set {
|
||||
NSUserDefaults.standardUserDefaults().setBool(newValue, forKey: "Save Artwork")
|
||||
}
|
||||
get {
|
||||
return NSUserDefaults.standardUserDefaults().boolForKey("Save Artwork")
|
||||
}
|
||||
}
|
||||
|
||||
/// The URL of the folder album artwork is saved to.
|
||||
///
|
||||
/// The URL must be a valid file URL pointing to a directory.
|
||||
public dynamic var artworkTarget: NSURL {
|
||||
set {
|
||||
NSUserDefaults.standardUserDefaults().setURL(newValue, forKey: "Artwork Target")
|
||||
}
|
||||
get {
|
||||
return NSUserDefaults.standardUserDefaults().URLForKey("Artwork Target")!
|
||||
}
|
||||
}
|
||||
|
||||
/// If `true` the search results are not removed from the main outline view
|
||||
/// when the user selects a result.
|
||||
public dynamic var keepSearchResults: Bool {
|
||||
set {
|
||||
NSUserDefaults.standardUserDefaults().setBool(newValue, forKey: "Keep Search Results")
|
||||
}
|
||||
get {
|
||||
return NSUserDefaults.standardUserDefaults().boolForKey("Keep Search Results")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user