From ee94900e331b084e296dd02db74ed060fbf6e0b2 Mon Sep 17 00:00:00 2001 From: galad87 Date: Sat, 29 Aug 2015 13:12:26 +0200 Subject: [PATCH] OCD --- Classes/Compatibility/NSArray+Subscripting.h | 2 +- Classes/Compatibility/NSArray+Subscripting.m | 7 +-- .../Compatibility/NSDictionary+Subscript.h | 2 +- .../Compatibility/NSDictionary+Subscript.m | 9 ++-- .../Compatibility/NSMutableArray+Subscript.h | 2 +- .../Compatibility/NSMutableArray+Subscript.m | 18 +++----- .../NSMutableDictionary+Subscript.h | 2 +- .../NSMutableDictionary+Subscript.m | 9 ++-- Classes/SBAppDelegate.m | 28 ++++++------ Classes/SBDocument.m | 44 ++++++++++--------- 10 files changed, 56 insertions(+), 67 deletions(-) diff --git a/Classes/Compatibility/NSArray+Subscripting.h b/Classes/Compatibility/NSArray+Subscripting.h index 813579a..18ba964 100644 --- a/Classes/Compatibility/NSArray+Subscripting.h +++ b/Classes/Compatibility/NSArray+Subscripting.h @@ -1,5 +1,5 @@ // -// SBLogger.m +// NSArray+Subscripting.h // Subler // diff --git a/Classes/Compatibility/NSArray+Subscripting.m b/Classes/Compatibility/NSArray+Subscripting.m index 4a961cd..554d90b 100644 --- a/Classes/Compatibility/NSArray+Subscripting.m +++ b/Classes/Compatibility/NSArray+Subscripting.m @@ -1,5 +1,5 @@ // -// SBLogger.m +// NSArray+Subscripting.m // Subler // @@ -11,9 +11,7 @@ + (void)load { Class class = [self class]; - SEL swizzledSelector = @selector(dg_objectAtIndexedSubscript:); - Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); class_addMethod([NSArray class], @@ -23,8 +21,7 @@ ); } -- (id)dg_objectAtIndexedSubscript:(NSInteger)index -{ +- (id)dg_objectAtIndexedSubscript:(NSInteger)index { return [self objectAtIndex:index]; } diff --git a/Classes/Compatibility/NSDictionary+Subscript.h b/Classes/Compatibility/NSDictionary+Subscript.h index ea99964..aed0f85 100755 --- a/Classes/Compatibility/NSDictionary+Subscript.h +++ b/Classes/Compatibility/NSDictionary+Subscript.h @@ -1,5 +1,5 @@ // -// SBLogger.m +// NSDictionary+Subscript.h // Subler // diff --git a/Classes/Compatibility/NSDictionary+Subscript.m b/Classes/Compatibility/NSDictionary+Subscript.m index 4b44180..71ceeac 100755 --- a/Classes/Compatibility/NSDictionary+Subscript.m +++ b/Classes/Compatibility/NSDictionary+Subscript.m @@ -1,5 +1,5 @@ // -// SBLogger.m +// NSDictionary+Subscript.m // Subler // @@ -8,10 +8,8 @@ @implementation NSDictionary (Subscript) -+ (void)load -{ ++ (void)load { Class class = [self class]; - SEL swizzledSelector = @selector(dg_objectForKeyedSubscript:); Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); @@ -22,8 +20,7 @@ ); } --(id)dg_objectForKeyedSubscript:(id)key -{ +-(id)dg_objectForKeyedSubscript:(id)key { return [self objectForKey:key]; } diff --git a/Classes/Compatibility/NSMutableArray+Subscript.h b/Classes/Compatibility/NSMutableArray+Subscript.h index 1f5c316..12c5da2 100755 --- a/Classes/Compatibility/NSMutableArray+Subscript.h +++ b/Classes/Compatibility/NSMutableArray+Subscript.h @@ -1,5 +1,5 @@ // -// SBLogger.m +// NSMutableArray+Subscript.h // Subler // diff --git a/Classes/Compatibility/NSMutableArray+Subscript.m b/Classes/Compatibility/NSMutableArray+Subscript.m index 924e033..3d36360 100755 --- a/Classes/Compatibility/NSMutableArray+Subscript.m +++ b/Classes/Compatibility/NSMutableArray+Subscript.m @@ -1,5 +1,5 @@ // -// SBLogger.m +// NSMutableArray+Subscript.m // Subler // @@ -11,7 +11,6 @@ + (void)load { Class class = [self class]; - SEL swizzledSelector = @selector(dg_setObject:atIndexedSubscript:); Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); @@ -22,22 +21,17 @@ ); } -- (void)dg_setObject:(id)anObject atIndexedSubscript:(NSUInteger)index -{ - if(anObject == nil) - { +- (void)dg_setObject:(id)anObject atIndexedSubscript:(NSUInteger)index { + if (anObject == nil) { [NSException raise:NSInvalidArgumentException format:@"setObject:atIndexedSubscript does not allow objects to be nil"]; } - if(index > self.count) - { + if (index > self.count) { [NSException raise:NSRangeException format:@"setObject:atIndexedSubscript does not allow the index to be out of array bounds"]; } - if(index == self.count) - { + if (index == self.count) { [self addObject:anObject]; } - else - { + else { [self replaceObjectAtIndex:index withObject:anObject]; } } diff --git a/Classes/Compatibility/NSMutableDictionary+Subscript.h b/Classes/Compatibility/NSMutableDictionary+Subscript.h index ccd07b0..a07a731 100755 --- a/Classes/Compatibility/NSMutableDictionary+Subscript.h +++ b/Classes/Compatibility/NSMutableDictionary+Subscript.h @@ -1,5 +1,5 @@ // -// SBLogger.m +// NSMutableDictionary+Subscript.h // Subler // diff --git a/Classes/Compatibility/NSMutableDictionary+Subscript.m b/Classes/Compatibility/NSMutableDictionary+Subscript.m index 3254204..84738ce 100755 --- a/Classes/Compatibility/NSMutableDictionary+Subscript.m +++ b/Classes/Compatibility/NSMutableDictionary+Subscript.m @@ -1,5 +1,5 @@ // -// SBLogger.m +// NSMutableDictionary+Subscript.m // Subler // @@ -8,10 +8,8 @@ @implementation NSMutableDictionary (Subscript) -+ (void)load -{ ++ (void)load { Class class = [self class]; - SEL swizzledSelector = @selector(dg_setObject:forKeyedSubscript:); Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); @@ -22,8 +20,7 @@ ); } -- (void)dg_setObject:(id)object forKeyedSubscript:(id < NSCopying >)aKey -{ +- (void)dg_setObject:(id)object forKeyedSubscript:(id < NSCopying >)aKey { [self setObject:object forKey:aKey]; } diff --git a/Classes/SBAppDelegate.m b/Classes/SBAppDelegate.m index 448b24f..305fe8d 100644 --- a/Classes/SBAppDelegate.m +++ b/Classes/SBAppDelegate.m @@ -88,20 +88,21 @@ #ifdef DONATION BOOL firstLaunch = YES; - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"]) + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"]) { firstLaunch = NO; + } - if (![[NSUserDefaults standardUserDefaults] valueForKey:@"WarningDonate"]) { - NSDate * lastDonateDate = [[NSUserDefaults standardUserDefaults] valueForKey:@"DonateAskDate"]; + if (![[NSUserDefaults standardUserDefaults] valueForKey:@"WarningDonate"]) { + NSDate *lastDonateDate = [[NSUserDefaults standardUserDefaults] valueForKey:@"DonateAskDate"]; const BOOL timePassed = !lastDonateDate || (-1 * [lastDonateDate timeIntervalSinceNow]) >= DONATE_NAG_TIME; if (!firstLaunch && timePassed) { [[NSUserDefaults standardUserDefaults] setValue:[NSDate date] forKey:@"DonateAskDate"]; - NSAlert * alert = [[NSAlert alloc] init]; + NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText: NSLocalizedString(@"Support Subler", "Donation -> title")]; - NSString * donateMessage = [NSString stringWithFormat: @"%@", + NSString *donateMessage = [NSString stringWithFormat: @"%@", NSLocalizedString(@" A lot of time and effort have gone into development, coding, and refinement." " If you enjoy using it, please consider showing your appreciation with a donation.", "Donation -> message")]; @@ -114,22 +115,26 @@ const BOOL allowNeverAgain = lastDonateDate != nil; //hide the "don't show again" check the first time - give them time to try the app [alert setShowsSuppressionButton:allowNeverAgain]; - if (allowNeverAgain) + if (allowNeverAgain) { [[alert suppressionButton] setTitle:NSLocalizedString(@"Don't ask me about this ever again.", "Donation -> button")]; + } const NSInteger donateResult = [alert runModal]; - if (donateResult == NSAlertFirstButtonReturn) + if (donateResult == NSAlertFirstButtonReturn) { [self linkDonate:self]; + } - if (allowNeverAgain) + if (allowNeverAgain) { [[NSUserDefaults standardUserDefaults] setBool:([[alert suppressionButton] state] != NSOnState) forKey:@"WarningDonate"]; + } [alert release]; } } - if (firstLaunch) + if (firstLaunch) { [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstLaunch"]; + } #endif [SBQueueController sharedManager]; @@ -184,11 +189,6 @@ @implementation SBDocumentController -- (instancetype)init -{ - return [super init]; -} - - (void)openDocumentWithContentsOfURL:(NSURL * _Nonnull)url display:(BOOL)displayDocument completionHandler:(void (^ _Nonnull)(NSDocument * _Nullable document, diff --git a/Classes/SBDocument.m b/Classes/SBDocument.m index b9c0684..11c30ac 100755 --- a/Classes/SBDocument.m +++ b/Classes/SBDocument.m @@ -167,8 +167,8 @@ case NSSaveAsOperation: // movie does not exist, create a new one from scratch. - if ([_64bit_data state]) { attributes[MP4264BitData] = @YES; } - if ([_64bit_time state]) { attributes[MP4264BitTime] = @YES; } + if (_64bit_data.state) { attributes[MP4264BitData] = @YES; } + if (_64bit_time.state) { attributes[MP4264BitTime] = @YES; } result = [self.mp4 writeToUrl:url withAttributes:attributes error:outError]; break; @@ -597,18 +597,18 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn [self close]; } else { NSSavePanel *panel = [NSSavePanel savePanel]; - [self prepareSavePanel:panel]; + panel.prompt = NSLocalizedString(@"Send To Queue", nil); - [panel setPrompt:@"Send To Queue"]; + [self prepareSavePanel:panel]; [panel beginSheetModalForWindow:documentWindow completionHandler:^(NSInteger result) { if (result == NSFileHandlingPanelOKButton) { NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init]; - if ([_64bit_data state]) [attributes setObject:@YES forKey:MP4264BitData]; - if ([_64bit_time state]) [attributes setObject:@YES forKey:MP4264BitTime]; + if (_64bit_data.state) { attributes[MP4264BitData] = @YES; } + if (_64bit_time.state) { attributes[MP4264BitTime] = @YES; } if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue]) { - [attributes setObject:@YES forKey:MP42GenerateChaptersPreviewTrack]; + attributes[MP42GenerateChaptersPreviewTrack] = @YES; } SBQueueItem *item = [SBQueueItem itemWithMP4:self.mp4 destinationURL:panel.URL attributes:attributes]; @@ -626,7 +626,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn NSString *filename = nil; for (MP42Track *track in self.mp4.tracks) { if (track.sourceURL) { - filename = [track.sourceURL lastPathComponent]; + filename = track.sourceURL.lastPathComponent; break; } } @@ -801,7 +801,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn - (void)addMetadata:(NSURL *)URL { - if ([[URL pathExtension] isEqualToString:@"xml"] || [[URL pathExtension] isEqualToString:@"nfo"]) { + if ([URL.pathExtension isEqualToString:@"xml"] || [URL.pathExtension isEqualToString:@"nfo"]) { MP42Metadata *xmlMetadata = [[MP42Metadata alloc] initWithFileURL:URL]; [self.mp4.metadata mergeMetadata:xmlMetadata]; [xmlMetadata release]; @@ -835,9 +835,13 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn - (IBAction)export:(id)sender { - NSInteger row = [fileTracksTable selectedRow]; - NSSavePanel * panel = [NSSavePanel savePanel]; - NSString *filename = [[[[self fileURL] path] stringByDeletingPathExtension] lastPathComponent]; + NSString *filename = self.fileURL.URLByDeletingPathExtension.lastPathComponent; + + NSSavePanel *panel = [NSSavePanel savePanel]; + panel.canSelectHiddenExtension = YES; + panel.nameFieldStringValue = filename; + + NSInteger row = fileTracksTable.selectedRow; if (row != -1 && [[self.mp4 trackAtIndex:row] isKindOfClass:[MP42SubtitleTrack class]]) { panel.allowedFileTypes = @[@"srt"]; @@ -848,20 +852,20 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn panel.allowedFileTypes = @[@"txt"]; } - [panel setCanSelectHiddenExtension: YES]; - [panel setNameFieldStringValue:filename]; - [panel beginSheetModalForWindow:documentWindow completionHandler:^(NSInteger result) { if (result == NSFileHandlingPanelOKButton) { - id track = [self.mp4 trackAtIndex:[fileTracksTable selectedRow]]; - - if (![track exportToURL: [panel URL] error: nil]) { - NSAlert * alert = [[NSAlert alloc] init]; + + NSError *error; + id track = [self.mp4 trackAtIndex:row]; + + if (![track exportToURL:panel.URL error:&error]) { + + NSAlert *alert = [[NSAlert alloc] init]; [alert addButtonWithTitle: NSLocalizedString(@"OK", "Export alert panel -> button")]; [alert setMessageText: NSLocalizedString(@"File Could Not Be Saved", "Export alert panel -> title")]; [alert setInformativeText: [NSString stringWithFormat: NSLocalizedString(@"There was a problem creating the file \"%@\".", - "Export alert panel -> message"), [[[panel URL] path] lastPathComponent]]]; + "Export alert panel -> message"), panel.URL.lastPathComponent]]; [alert setAlertStyle: NSWarningAlertStyle]; [alert runModal];