From 3cc367a00d0076d0ec9a7053aa8f48951be1ec04 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 10 Feb 2018 14:53:39 +0100 Subject: [PATCH] Convert SBDocument to swift. --- Classes/ArtworkSelector.swift | 12 +- Classes/Document.swift | 197 +++++++++++++++ Classes/DocumentWindowController.swift | 12 +- Classes/MP42FileAdditions.swift | 2 +- Classes/OffsetViewController.swift | 4 +- Classes/SBAppDelegate.m | 1 - Classes/SBDocument.h | 26 -- Classes/SBDocument.m | 322 ------------------------- Classes/SBQueueController.m | 4 +- Classes/SaveOptions.swift | 52 ++++ Classes/SaveOptions.xib | 7 +- Classes/TracksViewController.swift | 4 +- Subler-Bridging-Header.h | 1 - Subler.xcodeproj/project.pbxproj | 15 +- 14 files changed, 280 insertions(+), 379 deletions(-) create mode 100644 Classes/Document.swift delete mode 100755 Classes/SBDocument.h delete mode 100644 Classes/SBDocument.m diff --git a/Classes/ArtworkSelector.swift b/Classes/ArtworkSelector.swift index 0d926e6..873cbfc 100644 --- a/Classes/ArtworkSelector.swift +++ b/Classes/ArtworkSelector.swift @@ -36,7 +36,7 @@ private class ArtworkImageObject : NSObject { } } - @objc override func imageRepresentation() -> Any! { + override func imageRepresentation() -> Any! { // Get the data outside the main thread var startDownload: Bool = false queue.sync { @@ -76,15 +76,15 @@ private class ArtworkImageObject : NSObject { return localData } - @objc override func imageRepresentationType() -> String { + override func imageRepresentationType() -> String { return IKImageBrowserNSDataRepresentationType } - @objc override func imageUID() -> String { + override func imageUID() -> String { return source.thumbURL.absoluteString } - @objc override func imageVersion()-> Int { + override func imageVersion()-> Int { var returnValue: Int = 0 queue.sync { returnValue = self.version @@ -92,11 +92,11 @@ private class ArtworkImageObject : NSObject { return returnValue } - @objc override func imageTitle() -> String { + override func imageTitle() -> String { return source.service } - @objc override func imageSubtitle() -> String { + override func imageSubtitle() -> String { return source.type.description } diff --git a/Classes/Document.swift b/Classes/Document.swift new file mode 100644 index 0000000..a7ea5d1 --- /dev/null +++ b/Classes/Document.swift @@ -0,0 +1,197 @@ +// +// Document.swift +// Subler +// +// Created by Damiano Galassi on 10/02/2018. +// + +import Cocoa +import IOKit.pwr_mgt + +@objc(SBDocument) class Document: NSDocument { + + var mp4: MP42File + + override init() { + self.options = [:] + self.optimize = false + self.mp4 = MP42File() + } + + @objc init(mp4: MP42File) throws { + self.options = [:] + self.optimize = false + self.mp4 = mp4 + super.init() + + if let url = mp4.url { + fileURL = url + } else { + updateChangeCount(.changeDone) + } + } + + override func makeWindowControllers() { + let documentWindowController = DocumentWindowController() + addWindowController(documentWindowController) + documentWindowController.showWindow(self) + } + + // MARK: Read + + override class func canConcurrentlyReadDocuments(ofType typeName: String) -> Bool { return true } + + override open var isEntireFileLoaded: Bool { get { return false } } + + override func read(from url: URL, ofType typeName: String) throws { + mp4 = try MP42File(url: url) + } + + override func revert(toContentsOf url: URL, ofType typeName: String) throws { + mp4 = try MP42File(url: url) + + if let docController = windowControllers.first as? DocumentWindowController { + docController.reloadData() + } + + updateChangeCount(.changeCleared) + } + + // MARK: Save + + private var optimize: Bool + private var options: [String : Any] + + private func defaultSaveOptions() -> [String : Any] { + var options = [String : Any]() + + if UserDefaults.standard.bool(forKey: "chaptersPreviewTrack") { + options[MP42GenerateChaptersPreviewTrack] = true + options[MP42ChaptersPreviewPosition] = UserDefaults.standard.float(forKey: "SBChaptersPreviewPosition") + + } + + if let accessoryViewController = accessoryViewController { + options[MP4264BitData] = accessoryViewController._64bit_data.state == .on ? true : false + options[MP4264BitTime] = accessoryViewController._64bit_time.state == .on ? true : false + } + return options + } + + @IBAction func saveAndOptimize(_ sender: Any) { + optimize = true + save(self) + } + + override func canAsynchronouslyWrite(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType) -> Bool { return true } + + override func save(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, completionHandler: @escaping (Error?) -> Void) { + let docController = windowControllers.first as? DocumentWindowController + + let modifiedCompletionhandler = { (error: Error?) -> Void in + if let error = error { + completionHandler(error); + } else { + do { + let reloadedFile = try MP42File(url: url) + self.mp4 = reloadedFile + docController?.reloadData() + completionHandler(error) + } + catch { + completionHandler(error) + } + } + + docController?.endProgressReporting() + } + + options = defaultSaveOptions() + accessoryViewController = nil + + docController?.startProgressReporting() + super.save(to: url, ofType: typeName, for: saveOperation, completionHandler: modifiedCompletionhandler) + } + + private var sleepAssertion: IOPMAssertionID = IOPMAssertionID(0) + private var sleepAssertionSuccess: IOReturn = kIOReturnInvalid + + private func preventSleep() { + sleepAssertionSuccess = IOPMAssertionCreateWithName(kIOPMAssertPreventUserIdleSystemSleep as CFString, + IOPMAssertionLevel(kIOPMAssertionLevelOn), + "Subler Save Operation" as CFString, + &sleepAssertion) + } + + private func allowSleep() { + if sleepAssertionSuccess == kIOReturnSuccess { + IOPMAssertionRelease(sleepAssertion) + sleepAssertionSuccess = kIOReturnInvalid + sleepAssertion = IOPMAssertionID(0) + } + } + + override func writeSafely(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType) throws { + unblockUserInteraction() + preventSleep() + + if UserDefaults.standard.bool(forKey: "SBOrganizeAlternateGroups") { + mp4.organizeAlternateGroups() + if UserDefaults.standard.bool(forKey: "SBInferMediaCharacteristics") { + mp4.inferMediaCharacteristics() + } + } + + defer { + allowSleep() + mp4.progressHandler = nil + optimize = false + options = [:] + } + + switch saveOperation { + case .saveOperation: + try mp4.update(options: options) + case .saveAsOperation: + try mp4.write(to: url, options: options) + default: + fatalError("Unsupported save operation") + } + + if optimize { + // TODO: Update progress string + mp4.optimize() + } + } + + // MARK: Save panel + + private var accessoryViewController: SaveOptions? + + override func prepareSavePanel(_ savePanel: NSSavePanel) -> Bool { + self.accessoryViewController = SaveOptions(doc: self, savePanel: savePanel) + + savePanel.isExtensionHidden = false + savePanel.accessoryView = accessoryViewController?.view + + return true + } + + // MARK: User interface validation + + override func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool { + switch item.action { + case #selector(revertToSaved(_:)) where isDocumentEdited == true: + return true + case #selector(save(_:)) where isDocumentEdited == true: + return true + case #selector(saveAs(_:)): + return true + case #selector(saveAndOptimize(_:)) where isDocumentEdited == false && mp4.hasFileRepresentation == true: + return true + default: + return false + } + } + +} diff --git a/Classes/DocumentWindowController.swift b/Classes/DocumentWindowController.swift index 4e58bbc..659d92e 100644 --- a/Classes/DocumentWindowController.swift +++ b/Classes/DocumentWindowController.swift @@ -19,10 +19,10 @@ extension NSPasteboard.PasteboardType { } -@objc(SBDocumentWindowController) class DocumentWindowController: NSWindowController, TracksViewControllerDelegate, ChapterSearchControllerDelegate, MetadataSearchControllerDelegate, FileImportControllerDelegate, ProgressViewControllerDelegate, NSDraggingDestination { +class DocumentWindowController: NSWindowController, TracksViewControllerDelegate, ChapterSearchControllerDelegate, MetadataSearchControllerDelegate, FileImportControllerDelegate, ProgressViewControllerDelegate, NSDraggingDestination { - private var doc: SBDocument { - return document as! SBDocument + private var doc: Document { + return document as! Document } private var mp4: MP42File { @@ -133,7 +133,7 @@ extension NSPasteboard.PasteboardType { } } - @objc func reloadData() { + func reloadData() { tracksViewController.mp4 = doc.mp4 } @@ -231,7 +231,7 @@ extension NSPasteboard.PasteboardType { var progressController: ProgressViewController? - @objc func startProgressReporting() { + func startProgressReporting() { let progressController = ProgressViewController() progressController.delegate = self contentViewController?.presentViewControllerAsSheet(progressController) @@ -244,7 +244,7 @@ extension NSPasteboard.PasteboardType { } } - @objc func endProgressReporting() { + func endProgressReporting() { if let progressController = self.progressController { contentViewController?.dismissViewController(progressController) self.progressController = nil diff --git a/Classes/MP42FileAdditions.swift b/Classes/MP42FileAdditions.swift index 503ee95..649d447 100644 --- a/Classes/MP42FileAdditions.swift +++ b/Classes/MP42FileAdditions.swift @@ -82,7 +82,7 @@ extension MP42File { // MARK: File name - @objc func preferredFileName() -> String? { + func preferredFileName() -> String? { if let mediaKind = metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyMediaKind).first?.numberValue?.intValue, (mediaKind == 10 && UserDefaults.standard.bool(forKey: "SBSetTVShowFormat")) || (mediaKind == 9 && UserDefaults.standard.bool(forKey: "SBSetMovieFormat")), diff --git a/Classes/OffsetViewController.swift b/Classes/OffsetViewController.swift index dfbfe7e..f1522b7 100644 --- a/Classes/OffsetViewController.swift +++ b/Classes/OffsetViewController.swift @@ -9,12 +9,12 @@ import Cocoa class OffsetViewController: NSViewController { - private let doc: SBDocument + private let doc: Document private let track: MP42Track @IBOutlet var offsetField: NSTextField! - init(doc: SBDocument, track: MP42Track) { + init(doc: Document, track: MP42Track) { self.doc = doc self.track = track super.init(nibName: nil, bundle: nil) diff --git a/Classes/SBAppDelegate.m b/Classes/SBAppDelegate.m index 2d3ffd9..c9b24df 100644 --- a/Classes/SBAppDelegate.m +++ b/Classes/SBAppDelegate.m @@ -7,7 +7,6 @@ // #import "SBAppDelegate.h" -#import "SBDocument.h" #import "SBQueueController.h" #import "Subler-Swift.h" diff --git a/Classes/SBDocument.h b/Classes/SBDocument.h deleted file mode 100755 index c0ae7e1..0000000 --- a/Classes/SBDocument.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// SBDocument.h -// Subler -// -// Created by Damiano Galassi on 29/01/09. -// Copyright Damiano Galassi 2009 . All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@class MP42File; - -@interface SBDocument : NSDocument - -@property (nonatomic, strong) MP42File *mp4; - -- (instancetype)initWithMP4:(MP42File *)mp4File error:(NSError * __autoreleasing *)outError; - -- (IBAction)setSaveFormat:(NSPopUpButton *)sender; -- (IBAction)saveAndOptimize:(id)sender; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Classes/SBDocument.m b/Classes/SBDocument.m deleted file mode 100644 index b964d55..0000000 --- a/Classes/SBDocument.m +++ /dev/null @@ -1,322 +0,0 @@ -// -// SBDocument.m -// Subler -// -// Created by Damiano Galassi on 29/01/09. -// Copyright Damiano Galassi 2009 . All rights reserved. -// - -#import "SBDocument.h" - -#import -#import -#import - -#import "Subler-Swift.h" - -@interface SBDocument () - -@property (atomic) BOOL optimize; - -@property (nonatomic, strong, nullable) NSSavePanel *savePanel; -@property (nonatomic, strong, nullable) SaveOptions *saveOptions; -@property (nonatomic, strong, nullable) NSDictionary *currentSaveAttributes; - -@end - -@implementation SBDocument - -- (void)makeWindowControllers -{ - SBDocumentWindowController *documentWindowController = [[SBDocumentWindowController alloc] init]; - [self addWindowController:documentWindowController]; - [documentWindowController showWindow:self]; -} -- (instancetype)initWithMP4:(MP42File *)mp4File error:(NSError * __autoreleasing *)outError -{ - if (self = [super initWithType:@"Video-MPEG4" error:outError]) { - self.mp4 = mp4File; - if (mp4File.URL){ - self.fileURL = mp4File.URL; - } - else { - [self updateChangeCount:NSChangeDone]; - } - } - - return self; -} - -- (instancetype)initWithType:(NSString *)typeName error:(NSError * __autoreleasing *)outError -{ - if (self = [super initWithType:typeName error:outError]) { - self.mp4 = [[MP42File alloc] init]; - } - - return self; -} - -#pragma mark - Restorable state - -- (void)restoreDocumentWindowWithIdentifier:(NSString *)identifier - state:(NSCoder *)state - completionHandler:(void (^)(NSWindow *, NSError *))completionHandler -{ - if (!self.windowControllers.count) { - [self makeWindowControllers]; - } - - completionHandler(self.windowControllers.firstObject.window, nil); -} - -#pragma mark - Read methods - -+ (BOOL)canConcurrentlyReadDocumentsOfType:(NSString *)type -{ - return YES; -} - -- (BOOL)isEntireFileLoaded -{ - return NO; -} - -- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError * __autoreleasing *)outError -{ - self.mp4 = [[MP42File alloc] initWithURL:absoluteURL error:outError]; - - if (!self.mp4) { - return NO; - } - - return YES; -} - -- (BOOL)revertToContentsOfURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError * __autoreleasing *)outError -{ - self.mp4 = [[MP42File alloc] initWithURL:absoluteURL error:outError]; - - SBDocumentWindowController *docController = self.windowControllers.firstObject; - [docController reloadData]; - - [self updateChangeCount:NSChangeCleared]; - - if (!self.mp4) { - return NO; - } - - return YES; -} - -#pragma mark - Save methods - -- (IBAction)saveAndOptimize:(id)sender -{ - self.optimize = YES; - [self saveDocument:sender]; -} - -- (BOOL)canAsynchronouslyWriteToURL:(NSURL *)url - ofType:(NSString *)typeName - forSaveOperation:(NSSaveOperationType)saveOperation -{ - return YES; -} - -- (void)saveToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation completionHandler:(void (^)(NSError * _Nullable))completionHandler -{ - SBDocumentWindowController *docController = self.windowControllers.firstObject; - - void (^modifiedCompletionhandler)(NSError * _Nullable) = ^void(NSError * _Nullable error) { - MP42File *reloadedFile = nil; - NSError *reloadError; - - if (error == nil) { - reloadedFile = [[MP42File alloc] initWithURL:[NSURL fileURLWithPath:url.path] error:&reloadError]; - } - - [docController endProgressReporting]; - - if (reloadedFile) { - self.mp4 = reloadedFile; - - [docController reloadData]; - - completionHandler(error); - } - else if (reloadError) { - completionHandler(reloadError); - } - else { - completionHandler(error); - } - - self.savePanel = nil; - self.saveOptions = nil; - }; - - self.currentSaveAttributes = [self saveAttributes]; - [docController startProgressReporting]; - [super saveToURL:url ofType:typeName forSaveOperation:saveOperation completionHandler:modifiedCompletionhandler]; -} - -- (BOOL)writeSafelyToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError * _Nullable *)outError -{ - [self unblockUserInteraction]; - - IOPMAssertionID assertionID; - // Enable sleep assertion - CFStringRef reasonForActivity= CFSTR("Subler Save Operation"); - IOReturn io_success = IOPMAssertionCreateWithName(kIOPMAssertPreventUserIdleSystemSleep, - kIOPMAssertionLevelOn, reasonForActivity, &assertionID); - BOOL result = NO; - - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"SBOrganizeAlternateGroups"]) { - [self.mp4 organizeAlternateGroups]; - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"SBInferMediaCharacteristics"]) { - [self.mp4 inferMediaCharacteristics]; - } - } - - switch (saveOperation) { - case NSSaveOperation: - // movie file already exists, so we'll just update - // the movie resource. - result = [self.mp4 updateMP4FileWithOptions:self.currentSaveAttributes error:outError]; - break; - - case NSSaveAsOperation: - // movie does not exist, create a new one from scratch. - result = [self.mp4 writeToUrl:url options:self.currentSaveAttributes error:outError]; - break; - - default: - NSAssert(NO, @"Unhandled save operation"); - break; - } - - if (result && self.optimize) { - dispatch_async(dispatch_get_main_queue(), ^{ -// [weakSelf.saveOperationName setStringValue:NSLocalizedString(@"Optimizing…", @"Document Optimize sheet.")]; - }); - result = [self.mp4 optimize]; - self.optimize = NO; - } - - self.mp4.progressHandler = nil; - - if (io_success == kIOReturnSuccess) { - IOPMAssertionRelease(assertionID); - } - - return result; -} - -#pragma mark - Save panel - -- (BOOL)prepareSavePanel:(NSSavePanel *)savePanel -{ - self.savePanel = savePanel; - self.saveOptions = [[SaveOptions alloc] init]; - - savePanel.extensionHidden = NO; - savePanel.accessoryView = self.saveOptions.view; - - NSArray *formats = [self writableTypesForSaveOperation:NSSaveAsOperation]; - - [self.saveOptions.fileFormat removeAllItems]; - for (NSString *format in formats) { - NSString *formatName = CFBridgingRelease(UTTypeCopyDescription((__bridge CFStringRef _Nonnull)(format))); - - if (formatName == nil) { - formatName = format; - } - [self.saveOptions.fileFormat addItemWithTitle:formatName]; - } - - [self.saveOptions.fileFormat selectItemAtIndex:[[NSUserDefaults standardUserDefaults] integerForKey:@"defaultSaveFormat"]]; - - if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBSaveFormat"]) { - self.savePanel.allowedFileTypes = @[[[NSUserDefaults standardUserDefaults] valueForKey:@"SBSaveFormat"]]; - } - - NSString *filename = [self.mp4 preferredFileName]; - - if (filename) { - savePanel.nameFieldStringValue = filename; - } - - if (self.mp4.dataSize > 4200000000) { - self.saveOptions._64bit_data.state = NSControlStateValueOn; - } - - return YES; -} - -- (IBAction)setSaveFormat:(NSPopUpButton *)sender -{ - NSString *requiredFileType = nil; - NSInteger index = sender.indexOfSelectedItem; - - switch (index) { - case 0: - requiredFileType = MP42FileTypeM4V; - break; - case 1: - requiredFileType = MP42FileTypeMP4; - break; - case 2: - requiredFileType = MP42FileTypeM4A; - break; - case 3: - requiredFileType = MP42FileTypeM4B; - break; - case 4: - requiredFileType = MP42FileTypeM4R; - break; - default: - requiredFileType = MP42FileTypeM4V; - break; - } - - self.savePanel.allowedFileTypes = @[requiredFileType]; - [[NSUserDefaults standardUserDefaults] setObject:requiredFileType forKey:@"SBSaveFormat"]; -} - -- (NSDictionary *)saveAttributes { - NSMutableDictionary * attributes = [[NSMutableDictionary alloc] init]; - - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"chaptersPreviewTrack"]) { - attributes[MP42GenerateChaptersPreviewTrack] = @YES; - attributes[MP42ChaptersPreviewPosition] = @([[NSUserDefaults standardUserDefaults] floatForKey:@"SBChaptersPreviewPosition"]); - } - - if (self.saveOptions._64bit_data.state) { attributes[MP4264BitData] = @YES; } - if (self.saveOptions._64bit_time.state) { attributes[MP4264BitTime] = @YES; } - - return attributes; -} - -- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem -{ - SEL action = anItem.action; - - if (action == @selector(saveDocument:)) - if (self.documentEdited) - return YES; - - if (action == @selector(saveDocumentAs:)) - return YES; - - if (action == @selector(revertDocumentToSaved:)) - if (self.documentEdited) - return YES; - - if (action == @selector(saveAndOptimize:)) - if (!self.documentEdited && self.mp4.hasFileRepresentation) - return YES; - - return NO; -} - -@end diff --git a/Classes/SBQueueController.m b/Classes/SBQueueController.m index d8bd8fd..b921fc6 100755 --- a/Classes/SBQueueController.m +++ b/Classes/SBQueueController.m @@ -12,8 +12,6 @@ #import "SBOptionsViewController.h" -#import "SBDocument.h" - #import #import "Subler-Swift.h" @@ -227,7 +225,7 @@ static void *SBQueueContex = &SBQueueContex; MP42File *mp4 = item.mp4File; dispatch_async(dispatch_get_main_queue(), ^{ - SBDocument *doc = [[SBDocument alloc] initWithMP4:mp4 error:&error]; + SBDocument *doc = [[SBDocument alloc] initWithMp4:mp4 error:&error]; if (doc) { [[NSDocumentController sharedDocumentController] addDocument:doc]; diff --git a/Classes/SaveOptions.swift b/Classes/SaveOptions.swift index c7228ed..2630811 100644 --- a/Classes/SaveOptions.swift +++ b/Classes/SaveOptions.swift @@ -14,14 +14,47 @@ class SaveOptions: NSViewController { @IBOutlet var _64bit_data: NSButton! @IBOutlet var _64bit_time: NSButton! + private let doc: Document + private let savePanel: NSSavePanel + + init(doc: Document, savePanel: NSSavePanel) { + self.doc = doc + self.savePanel = savePanel + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func viewDidLoad() { super.viewDidLoad() + let formats = doc.writableTypes(for: .saveAsOperation) + fileFormat.removeAllItems() + + for format in formats { + let name = UTTypeCopyDescription(format as CFString)?.takeRetainedValue() as String? ?? format + fileFormat.addItem(withTitle: name) + } + let index = UserDefaults.standard.integer(forKey: "defaultSaveFormat") fileFormat.selectItem(at: index) + if let format = UserDefaults.standard.string(forKey: "SBSaveFormat") { + savePanel.allowedFileTypes = [format] + } + + if let filename = doc.mp4.preferredFileName() { + savePanel.nameFieldStringValue = filename + } + _64bit_data.state = UserDefaults.standard.bool(forKey: "mp464bitOffset") ? .on : .off _64bit_time.state = UserDefaults.standard.bool(forKey: "mp464bitTimes") ? .on : .off + + if doc.mp4.dataSize > 4000000000 { + _64bit_data.state = .on + } } override func viewWillDisappear() { @@ -32,4 +65,23 @@ class SaveOptions: NSViewController { UserDefaults.standard.set(_64bit_time.state == .on, forKey: "mp464bitTimes") } + @IBAction func setSaveFormat(_ sender: NSPopUpButton) { + var requiredFileType = MP42FileTypeM4V + switch sender.indexOfSelectedItem { + case 0: + requiredFileType = MP42FileTypeM4V + case 1: + requiredFileType = MP42FileTypeMP4 + case 2: + requiredFileType = MP42FileTypeM4A + case 3: + requiredFileType = MP42FileTypeM4B + case 4: + requiredFileType = MP42FileTypeM4R + default: + break + } + savePanel.allowedFileTypes = [requiredFileType] + UserDefaults.standard.set(requiredFileType, forKey: "SBSaveFormat") + } } diff --git a/Classes/SaveOptions.xib b/Classes/SaveOptions.xib index 7e5b4ab..43a129b 100644 --- a/Classes/SaveOptions.xib +++ b/Classes/SaveOptions.xib @@ -1,8 +1,8 @@ - + - + @@ -60,6 +60,9 @@ + + + diff --git a/Classes/TracksViewController.swift b/Classes/TracksViewController.swift index 8351eae..9900b73 100644 --- a/Classes/TracksViewController.swift +++ b/Classes/TracksViewController.swift @@ -15,7 +15,7 @@ class TracksViewController: NSViewController, NSTableViewDataSource, NSTableView weak var delegate: TracksViewControllerDelegate? - private let document: SBDocument + private let document: Document var mp4: MP42File { didSet { @@ -44,7 +44,7 @@ class TracksViewController: NSViewController, NSTableViewDataSource, NSTableView tracksTable.doubleAction = #selector(doubleClickAction) } - init(document: SBDocument, delegate: TracksViewControllerDelegate) { + init(document: Document, delegate: TracksViewControllerDelegate) { self.document = document; self.mp4 = document.mp4 self.delegate = delegate diff --git a/Subler-Bridging-Header.h b/Subler-Bridging-Header.h index 6ceeba9..8ca1459 100644 --- a/Subler-Bridging-Header.h +++ b/Subler-Bridging-Header.h @@ -2,7 +2,6 @@ // Use this file to import your target's public headers that you would like to expose to Swift. // -#import "SBDocument.h" #import "SBQueueController.h" #import "SBQueueItem.h" #import "SBMovieViewController.h" diff --git a/Subler.xcodeproj/project.pbxproj b/Subler.xcodeproj/project.pbxproj index cd11cf7..10dc16c 100644 --- a/Subler.xcodeproj/project.pbxproj +++ b/Subler.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ A9433A911F2F5D8A00BB38CA /* ChapterDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9433A901F2F5D8A00BB38CA /* ChapterDB.swift */; }; A944E5921F498FC4002E43F6 /* PresetPrefsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A944E5911F498FC4002E43F6 /* PresetPrefsViewController.swift */; }; A94A6A591ED1C5CC00049F7D /* ParseFilename in Resources */ = {isa = PBXBuildFile; fileRef = A94A6A581ED1C5CA00049F7D /* ParseFilename */; }; + A956C1E4202F1B170050C5E2 /* Document.swift in Sources */ = {isa = PBXBuildFile; fileRef = A956C1E3202F1B170050C5E2 /* Document.swift */; }; A956CE651F99E5BB00093992 /* ActivityWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A956CE641F99E5BB00093992 /* ActivityWindowController.swift */; }; A956CE691F99E93D00093992 /* ButtonToolbarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A956CE681F99E93D00093992 /* ButtonToolbarItem.swift */; }; A956CE6B1F99EAAD00093992 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = A956CE6A1F99EAAD00093992 /* Logger.swift */; }; @@ -84,7 +85,6 @@ A9AE70E11F2F7B3D001CF27C /* MetadataHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9AE70E01F2F7B3D001CF27C /* MetadataHelper.swift */; }; A9B1056E2025D9B9009E91FC /* TracksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B1056C2025D9B9009E91FC /* TracksViewController.swift */; }; A9B46AA412B79BB10040517A /* Subler.icns in Resources */ = {isa = PBXBuildFile; fileRef = A9B46AA312B79BB10040517A /* Subler.icns */; }; - A9B46ABF12B79D1C0040517A /* SBDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B46ABE12B79D1C0040517A /* SBDocument.m */; }; A9B514191EFC12310055A035 /* TheTVDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B514181EFC12310055A035 /* TheTVDB.swift */; }; A9BA1AEE1DBF7DD700FD0B38 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = A9BA1AF01DBF7DD700FD0B38 /* InfoPlist.strings */; }; A9BA1AF31DBF7DD800FD0B38 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A9BA1AF51DBF7DD800FD0B38 /* Localizable.strings */; }; @@ -237,6 +237,7 @@ A944E5911F498FC4002E43F6 /* PresetPrefsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PresetPrefsViewController.swift; path = Classes/PresetPrefsViewController.swift; sourceTree = ""; }; A94868D31F56BA0F00C47B75 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = Classes/it.lproj/PresetEditorViewController.strings; sourceTree = ""; }; A94A6A581ED1C5CA00049F7D /* ParseFilename */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ParseFilename; path = Utilities/ParseFilename; sourceTree = ""; }; + A956C1E3202F1B170050C5E2 /* Document.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Document.swift; path = Classes/Document.swift; sourceTree = ""; }; A956CE641F99E5BB00093992 /* ActivityWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ActivityWindowController.swift; path = Classes/ActivityWindowController.swift; sourceTree = ""; }; A956CE681F99E93D00093992 /* ButtonToolbarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ButtonToolbarItem.swift; path = Classes/ButtonToolbarItem.swift; sourceTree = ""; }; A956CE6A1F99EAAD00093992 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Logger.swift; path = Classes/Logger.swift; sourceTree = ""; }; @@ -285,8 +286,6 @@ A9B1056C2025D9B9009E91FC /* TracksViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TracksViewController.swift; path = Classes/TracksViewController.swift; sourceTree = ""; }; A9B3411B1679CA3E00E6EE0C /* QTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QTKit.framework; path = System/Library/Frameworks/QTKit.framework; sourceTree = SDKROOT; }; A9B46AA312B79BB10040517A /* Subler.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = Subler.icns; path = images/Subler.icns; sourceTree = ""; }; - A9B46ABD12B79D1C0040517A /* SBDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBDocument.h; path = Classes/SBDocument.h; sourceTree = ""; }; - A9B46ABE12B79D1C0040517A /* SBDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = SBDocument.m; path = Classes/SBDocument.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; A9B4EE4E1643EBF3009AF6BC /* Subler.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Subler.entitlements; sourceTree = ""; }; A9B514181EFC12310055A035 /* TheTVDB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TheTVDB.swift; path = Classes/MetadataImporters/TheTVDB.swift; sourceTree = ""; }; A9BA1ACF1DBF773600FD0B38 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/SBPresetPrefsViewController.strings; sourceTree = ""; }; @@ -605,8 +604,7 @@ A9FAC5FE1BAC3BAC00525E42 /* Document */ = { isa = PBXGroup; children = ( - A9B46ABD12B79D1C0040517A /* SBDocument.h */, - A9B46ABE12B79D1C0040517A /* SBDocument.m */, + A956C1E3202F1B170050C5E2 /* Document.swift */, A979B3842025C8BF00468362 /* DocumentWindowController.swift */, A9ECA0592029A10B00D5F30C /* DocumentWindowController.xib */, A9B1056C2025D9B9009E91FC /* TracksViewController.swift */, @@ -871,6 +869,7 @@ A9AB484917F0AEA2000AA72E /* SBAppDelegate.m in Sources */, A99D23212029CD32002E7F27 /* PrefsWindow.swift in Sources */, A9915ABF1F4B26CF003C57D1 /* MetadataPreset.swift in Sources */, + A956C1E4202F1B170050C5E2 /* Document.swift in Sources */, A9F680A81FD06E0200018371 /* OutputPrefsViewController.swift in Sources */, A900CE3E1F3ACF9700CCA08E /* MetadataResultMap.swift in Sources */, A9915AC11F4B28ED003C57D1 /* Preset.swift in Sources */, @@ -886,7 +885,6 @@ A9A8CEF91E43754400BC2AE1 /* SBQueueScriptCommand.m in Sources */, A9C09C9A1F9A0808007939EE /* EmptyViewController.swift in Sources */, A9C09C981F99F971007939EE /* ExpandedTableView.swift in Sources */, - A9B46ABF12B79D1C0040517A /* SBDocument.m in Sources */, A997B0AA1F348AB000974C9C /* MetadataSearchController.swift in Sources */, A9E932A71F34D31D00B1790B /* ArtworkSelector.swift in Sources */, A9D73C5218BF3F1100C6FFA6 /* SBQueue.m in Sources */, @@ -1325,6 +1323,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_OPTIMIZATION = space; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; @@ -1356,11 +1355,11 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_OPTIMIZATION = space; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; CODE_SIGN_ENTITLEMENTS = ""; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)\"", @@ -1385,6 +1384,7 @@ C05733CC08A9546B00998B17 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ASSETCATALOG_COMPILER_OPTIMIZATION = space; CLANG_ANALYZER_LOCALIZABILITY = YES; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; @@ -1453,6 +1453,7 @@ C05733CD08A9546B00998B17 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ASSETCATALOG_COMPILER_OPTIMIZATION = space; CLANG_ANALYZER_LOCALIZABILITY = YES; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES;