Fix presets in the Queue.

This commit is contained in:
Damiano Galassi committed 2017-08-28 16:25:37 +02:00
1 parent f8c861df15
commit 107c9273fd
7 files changed
+45 -29

No files matched your search

+4 -4
View File
@@ -124,7 +124,7 @@
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="KWg-Ak-bB6">
<rect key="frame" x="176" y="80" width="128" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="128" id="FJx-GH-nWg"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="128" id="FJx-GH-nWg"/>
</constraints>
<popUpButtonCell key="cell" type="roundRect" title="mp4" bezelStyle="roundedRect" imagePosition="left" alignment="left" controlSize="small" lineBreakMode="truncatingTail" state="on" borderStyle="border" tag="10" imageScaling="proportionallyDown" inset="2" autoenablesItems="NO" selectedItem="iXb-rA-1f3" id="Tgc-fW-mN5">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -227,7 +227,7 @@
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZVm-yi-3cE">
<rect key="frame" x="177" y="401" width="111" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="111" id="GuB-yU-C8O"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="111" id="GuB-yU-C8O"/>
</constraints>
<popUpButtonCell key="cell" type="roundRect" bezelStyle="roundedRect" alignment="left" controlSize="small" lineBreakMode="truncatingTail" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="CbR-eu-sGI">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -513,9 +513,9 @@
</connections>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="s2g-Iz-52P">
<rect key="frame" x="216" y="152" width="111" height="17"/>
<rect key="frame" x="216" y="152" width="120" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="111" id="57c-cZ-60x"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="111" id="57c-cZ-60x"/>
</constraints>
<popUpButtonCell key="cell" type="roundRect" title="Implicit" bezelStyle="roundedRect" alignment="left" controlSize="small" lineBreakMode="truncatingTail" state="on" borderStyle="border" tag="1" imageScaling="proportionallyDown" inset="2" selectedItem="psY-0V-t0k" id="QT5-Bh-4Hc">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+26 -10
View File
@@ -7,16 +7,35 @@
import Foundation
extension PresetManager.Error: LocalizedError {
public var errorDescription: String? {
switch self {
case .alreadyExists:
return NSLocalizedString("A preset already exists with the same name.", comment: "")
}
}
public var recoverySuggestion: String? {
switch self {
case .alreadyExists:
return NSLocalizedString("Please enter a different name for the preset.", comment: "")
}
}
}
@objc(SBPresetManager) final class PresetManager: NSObject {
@objc static let shared = PresetManager()
let updateNotificationName = Notification.Name(rawValue: "SBPresetManagerUpdatedNotification")
let updateNotification = Notification.Name(rawValue: "SBPresetManagerUpdatedNotification")
var presets: [Preset]
@objc var metadataPresets: [MetadataPreset] {
return presets.flatMap { $0 as? MetadataPreset }
}
var queuePresets: [QueuePreset] {
return presets.flatMap { $0 as? QueuePreset }
}
private override init() {
self.presets = Array()
super.init()
@@ -26,13 +45,12 @@ import Foundation
// MARK: management
enum Error : Swift.Error {
case presetAlreadyExists
case presetNotFound
case alreadyExists
}
@objc func append(newElement: Preset) throws {
if item(name: newElement.title) != nil {
throw Error.presetAlreadyExists
throw Error.alreadyExists
}
presets.append(newElement)
postNotification()
@@ -50,7 +68,7 @@ import Foundation
}
private func postNotification() {
NotificationCenter.default.post(name: updateNotificationName, object: self)
NotificationCenter.default.post(name: updateNotification, object: self)
}
// MARK: read/write
@@ -74,7 +92,7 @@ import Foundation
}
}
private func migrateOldPreset(at fileURL: URL) throws {
private func migratePreset(at fileURL: URL) throws {
let manager = FileManager.default
guard let url = appSupportURL() else { return }
@@ -94,7 +112,7 @@ import Foundation
defer { unarchiver.finishDecoding() }
if version == 1, let preset = unarchiver.decodeObject(of: [MP42Metadata.self], forKey: NSKeyedArchiveRootObjectKey) as? MP42Metadata {
try migrateOldPreset(at: fileURL)
try migratePreset(at: fileURL)
return MetadataPreset(title: preset.presetName, metadata: preset)
}
else if let preset = unarchiver.decodeObject(of: [MetadataPreset.self], forKey: NSKeyedArchiveRootObjectKey) as? MetadataPreset {
@@ -118,9 +136,7 @@ import Foundation
let preset = try load(fileURL: fileURL)
presets.append(preset)
}
catch {
print(error)
}
catch {}
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTabl
override func loadView() {
super.loadView()
observer = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "SBPresetManagerUpdatedNotification"),
observer = NotificationCenter.default.addObserver(forName: presetManager.updateNotification,
object: nil,
queue: OperationQueue.main) { [weak self] notification in
guard let s = self else { return }
+1 -1
View File
@@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
* An actions that applies a set to the item.
*/
@interface SBQueueSetAction : NSObject <SBQueueActionProtocol>
- (instancetype)initWithSet:(MP42Metadata *)set;
- (instancetype)initWithPreset:(MP42Metadata *)set;
@end
/**
+7 -7
View File
@@ -89,27 +89,27 @@
@end
@implementation SBQueueSetAction {
MP42Metadata *_set;
SBMetadataPreset *_set;
}
- (instancetype)initWithSet:(MP42Metadata *)set {
- (instancetype)initWithPreset:(SBMetadataPreset *)preset {
self = [super init];
if (self) {
_set = [set copy];
_set = [preset copy];
}
return self;
}
- (void)runAction:(SBQueueItem *)item {
[item.mp4File.metadata mergeMetadata:_set];
[item.mp4File.metadata mergeMetadata:_set.metadata];
}
- (NSString *)description {
return [NSString stringWithFormat:NSLocalizedString(@"Apply %@ Set", @""), _set.presetName];
return [NSString stringWithFormat:NSLocalizedString(@"Apply %@ Set", @""), _set.title];
}
- (NSString *)localizedDescription {
return [NSString stringWithFormat:NSLocalizedString(@"Applying %@ set", @""), _set.presetName];
return [NSString stringWithFormat:NSLocalizedString(@"Applying %@ set", @""), _set.title];
}
+ (BOOL)supportsSecureCoding {
@@ -119,7 +119,7 @@
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super init];
if (self) {
_set = [coder decodeObjectOfClass:[MP42Metadata class] forKey:@"SBQueueActionSet"];
_set = [coder decodeObjectOfClass:[SBMetadataPreset class] forKey:@"SBQueueActionSet"];
}
return self;
}
+2 -2
View File
@@ -289,8 +289,8 @@ static void *SBQueueContex = &SBQueueContex;
[item addAction:[[SBQueueColorSpaceAction alloc] initWithTag:[self.options[SBQueueApplyColorSpaceValue] unsignedIntegerValue]]];
}
if ((self.options)[SBQueueSet]) {
[item addAction:[[SBQueueSetAction alloc] initWithSet:(self.options)[SBQueueSet]]];
if (self.options[SBQueueSet]) {
[item addAction:[[SBQueueSetAction alloc] initWithPreset:self.options[SBQueueSet]]];
}
id type;
+4 -4
View File
@@ -56,9 +56,9 @@ NSString * const SBQueueSet = @"SBQueueSet";
}
if ([[NSUserDefaults standardUserDefaults] valueForKey:SBQueueSet]) {
MP42Metadata *set = [(SBMetadataPreset *)[SBPresetManager.shared itemWithName:[[NSUserDefaults standardUserDefaults] valueForKey:SBQueueSet]] metadata];
if (set) {
self.options[SBQueueSet] = set;
SBMetadataPreset *preset = (SBMetadataPreset *)[SBPresetManager.shared itemWithName:[[NSUserDefaults standardUserDefaults] valueForKey:SBQueueSet]];
if (preset) {
self.options[SBQueueSet] = preset;
}
}
@@ -101,7 +101,7 @@ NSString * const SBQueueSet = @"SBQueueSet";
}];
[[NSUserDefaults standardUserDefaults] setValue:[self.options[SBQueueDestination] path] forKey:SBQueueDestination];
[[NSUserDefaults standardUserDefaults] setValue:[self.options[SBQueueSet] presetName] forKey:SBQueueSet];
[[NSUserDefaults standardUserDefaults] setValue:[self.options[SBQueueSet] title] forKey:SBQueueSet];
}
- (nullable NSURL *)queueURL {