Audit more code.

This commit is contained in:
Damiano Galassi authored and Damiano Galassi committed 2015-08-25 10:59:37 +02:00
1 parent 8c3802ae53
commit 221c2748ba
23 files changed
+190 -96

No files matched your search

@@ -10,6 +10,8 @@
#import <MP42Foundation/MP42File.h>
#import <MP42Foundation/MP42ChapterTrack.h>
NS_ASSUME_NONNULL_BEGIN
@class SBTableView;
@interface SBChapterViewController : NSViewController {
@@ -27,3 +29,5 @@
- (IBAction) renameChapters: (id) sender;
@end
NS_ASSUME_NONNULL_END
+18 -11
View File
@@ -13,12 +13,14 @@
@implementation SBChapterViewController
- (void)awakeFromNib
- (void)loadView
{
[super loadView];
NSMutableParagraphStyle * ps = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
[ps setHeadIndent: -10.0];
[ps setAlignment:NSRightTextAlignment];
detailBoldAttr = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont boldSystemFontOfSize:11.0], NSFontAttributeName,
ps, NSParagraphStyleAttributeName,
@@ -47,12 +49,15 @@
objectValueForTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)rowIndex
{
MP42TextSample * chapter = [track chapterAtIndex:rowIndex];
if ([tableColumn.identifier isEqualToString:@"time"])
return [self boldString:StringFromTime(chapter.timestamp, 1000)];
MP42TextSample *chapter = [track chapterAtIndex:rowIndex];
if ([tableColumn.identifier isEqualToString:@"title"])
if ([tableColumn.identifier isEqualToString:@"time"]) {
return [self boldString:StringFromTime(chapter.timestamp, 1000)];
}
if ([tableColumn.identifier isEqualToString:@"title"]) {
return chapter.title;
}
return nil;
}
@@ -84,10 +89,12 @@
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
if ([chapterTableView selectedRow] != -1)
if ([chapterTableView selectedRow] != -1) {
[removeChapter setEnabled:YES];
else
}
else {
[removeChapter setEnabled:NO];
}
}
- (IBAction)removeChapter:(id)sender {
@@ -96,7 +103,7 @@
[track removeChapterAtIndex:current_index];
[chapterTableView reloadData];
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
[[[[[self view] window] windowController] document] updateChangeCount:NSChangeDone];
}
}
@@ -104,7 +111,7 @@
[track addChapter:@"Chapter" duration:0];
[chapterTableView reloadData];
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
[[[[[self view] window] windowController] document] updateChangeCount:NSChangeDone];
}
- (IBAction)renameChapters:(id)sender {
@@ -120,8 +127,8 @@
- (void)dealloc
{
[track release];
[detailBoldAttr release];
[super dealloc];
}
+1 -4
View File
@@ -8,8 +8,5 @@
#import <Cocoa/Cocoa.h>
@interface SBEmptyViewController : NSViewController {
}
@interface SBEmptyViewController : NSViewController
@end
@@ -11,5 +11,4 @@
@implementation SBEmptyViewController
@end
+7 -3
View File
@@ -9,6 +9,8 @@
#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>
NS_ASSUME_NONNULL_BEGIN
@class MP42File;
@class MP42Metadata;
@class SBTableView;
@@ -36,9 +38,9 @@
NSPopUpButtonCell *ratingCell;
NSComboBoxCell *genreCell;
NSDictionary *tags;
NSArray *_tagsArray;
NSArray *tagsMenu;
NSDictionary<NSString *, id> *tags;
NSArray<NSString *> *_tagsArray;
NSArray<NSString *> *tagsMenu;
NSDictionary *detailBoldAttr;
NSMutableDictionary *dct;
@@ -75,3 +77,5 @@
- (IBAction) removeArtwork: (id) sender;
@end
NS_ASSUME_NONNULL_END
+56 -38
View File
@@ -6,7 +6,7 @@
// Copyright 2009 Damiano Galassi. All rights reserved.
//
NSString *MetadataPBoardType = @"MetadataPBoardType";
NSString *MetadataPBoardType = @"SublerMetadataPBoardType";
#import "SBMovieViewController.h"
#import "SBTableView.h"
@@ -20,7 +20,7 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
@interface SBMovieViewController () <SBTableViewDelegate, SBImageBrowserViewDelegate>
@property (nonatomic, retain) NSArray *tagsArray;
@property (nonatomic, retain) NSArray<NSString *> *tagsArray;
- (void) updateSetsMenu: (id)sender;
@@ -30,8 +30,10 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
@synthesize tagsArray = _tagsArray;
- (void)awakeFromNib
- (void)loadView
{
[super loadView];
[self updateSetsMenu:self];
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -39,8 +41,9 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
name:@"SBPresetManagerUpdatedNotification" object:nil];
tagsMenu = [[metadata writableMetadata] retain];
for (id tag in tagsMenu)
for (id tag in tagsMenu) {
[tagList addItemWithTitle:tag];
}
ratingCell = [[NSPopUpButtonCell alloc] init];
[ratingCell setAutoenablesItems:NO];
@@ -105,7 +108,7 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
- (void) updateTagsArray
{
NSArray *context = [metadata availableMetadata];
NSArray<NSString *> *context = [metadata availableMetadata];
self.tagsArray = [[tags allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSInteger right = [context indexOfObject:obj2];
NSInteger left = [context indexOfObject:obj1];
@@ -215,8 +218,9 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
- (IBAction) addMetadataSet: (id)sender
{
NSArray *metadataKeys = nil;
if ([sender tag] == 0)
if ([sender tag] == 0) {
metadataKeys = [self allSet];
}
else if ([sender tag] == 1) {
metadataKeys = [self movieSet];
metadata.mediaKind = 9;
@@ -278,8 +282,9 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
SBPresetManager *presetManager = [SBPresetManager sharedManager];
NSMenu * setListMenu = [setList menu];
while ([setListMenu numberOfItems] > 1)
while ([setListMenu numberOfItems] > 1) {
[setListMenu removeItemAtIndex: 1];
}
NSMenuItem *newItem = [[[NSMenuItem alloc] initWithTitle:@"Save Set" action:@selector(showSaveSet:) keyEquivalent:@""] autorelease];
[newItem setTarget:self];
@@ -302,15 +307,16 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
[newItem setTag: 2];
[setListMenu addItem:newItem];
if ([[presetManager presets] count])
if (presetManager.presets.count) {
[setListMenu addItem:[NSMenuItem separatorItem]];
}
NSUInteger i = 0;
for (MP42Metadata *set in [presetManager presets]) {
for (MP42Metadata *set in presetManager.presets) {
newItem = [[NSMenuItem alloc] initWithTitle:[set presetName] action:@selector(applySet:) keyEquivalent:@""];
if (i < 9)
if (i < 9) {
[newItem setKeyEquivalent:[NSString stringWithFormat:@"%lu", (unsigned long)i+1]];
}
[newItem setTarget:self];
[newItem setTag:i++];
@@ -381,8 +387,7 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
current_index = [rowIndexes indexLessThanIndex: current_index];
}
NSArray *types = [NSArray arrayWithObjects:
MetadataPBoardType, NSStringPboardType, nil];
NSArray *types = @[MetadataPBoardType, NSStringPboardType];
[pb declareTypes:types owner:nil];
[pb setString:string forType: NSStringPboardType];
[pb setData:[NSArchiver archivedDataWithRootObject:data] forType:MetadataPBoardType];
@@ -414,8 +419,9 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
NSArray *copiedItems = [pasteboard readObjectsForClasses:classes options:options];
if (copiedItems != nil) {
for (id item in copiedItems)
for (id item in copiedItems) {
[self addArtwork:item];
}
metadata.isArtworkEdited = YES;
metadata.isEdited = YES;
@@ -435,6 +441,7 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
{
NSCell *cell = nil;
NSString *tagName = nil;
if (tableColumn != nil)
tagName = [self.tagsArray objectAtIndex:row];
@@ -448,11 +455,13 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
else if ([tagName isEqualToString:@"Genre"]) {
cell = genreCell;
}
else
else {
cell = [tableColumn dataCell];
}
}
else
else {
cell = nil;
}
return cell;
}
@@ -461,11 +470,13 @@ NSString *MetadataPBoardType = @"MetadataPBoardType";
objectValueForTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)rowIndex
{
if ([tableColumn.identifier isEqualToString:@"name"])
return [self.tagsArray objectAtIndex:rowIndex];
if ([tableColumn.identifier isEqualToString:@"name"]) {
return self.tagsArray[rowIndex];
}
if ([tableColumn.identifier isEqualToString:@"value"])
return [tags objectForKey:[self.tagsArray objectAtIndex:rowIndex]];
if ([tableColumn.identifier isEqualToString:@"value"]) {
return tags[self.tagsArray[rowIndex]];
}
return nil;
}
@@ -498,13 +509,15 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
[dct setObject:@(height) forKey:key];
}
if (height < 14.0)
if (height < 14.0) {
return 14.0;
else
}
else {
return height;
}
}
- (NSString *) tableView: (NSTableView *) aTableView
- (NSString *) tableView: (NSTableView *) aTableView
toolTipForCell: (NSCell *) aCell
rect: (NSRectPointer) rect
tableColumn: (NSTableColumn *) aTableColumn
@@ -568,8 +581,9 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
- (IBAction) changeGapless: (id) sender
{
uint8_t newValue;
if (sender == gapless)
if (sender == gapless) {
newValue = (uint8_t)[gapless state];
}
else {
newValue = ![gapless state];
[gapless setState:newValue];
@@ -642,8 +656,9 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
NSArray *objects = [metadata.artworks objectsAtIndexes:indexes];
[metadata.artworks removeObjectsAtIndexes:indexes];
for (id object in [objects reverseObjectEnumerator])
for (id object in objects.reverseObjectEnumerator) {
[metadata.artworks insertObject:object atIndex:destinationIndex];
}
metadata.isEdited = YES;
metadata.isArtworkEdited = YES;
@@ -655,7 +670,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
- (NSUInteger)imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:(NSPasteboard *)pasteboard
{
NSInteger index;
[pasteboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil];
[pasteboard declareTypes:@[NSTIFFPboardType] owner:nil];
for (index = [itemIndexes lastIndex]; index != NSNotFound; index = [itemIndexes indexLessThanIndex:index]) {
NSArray *representations = [[[metadata.artworks objectAtIndex:index] image] representations];
@@ -686,10 +701,12 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
{
NSIndexSet *rowIndexes = [aBrowser selectionIndexes];
if ([rowIndexes count])
if (rowIndexes.count) {
[removeArtwork setEnabled:YES];
else
}
else {
[removeArtwork setEnabled:NO];
}
}
- (IBAction)zoomSliderDidChange:(id)sender {
@@ -740,17 +757,18 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
panel.allowsMultipleSelection = YES;
panel.canChooseFiles = YES;
panel.canChooseDirectories = NO;
[panel setAllowedFileTypes:[NSArray arrayWithObject:@"public.image"]];
panel.allowedFileTypes = @[@"public.image"];
[panel beginSheetModalForWindow: [[self view] window] completionHandler:^(NSInteger result) {
[panel beginSheetModalForWindow:self.view.window completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
for (NSURL *url in [panel URLs])
for (NSURL *url in panel.URLs) {
[self addArtwork:url];
}
metadata.isArtworkEdited = YES;
metadata.isEdited = YES;
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
[[[[[self view] window] windowController] document] updateChangeCount:NSChangeDone];
[imageBrowser reloadData];
}
}];
@@ -771,19 +789,19 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
BOOL edited = NO;
NSPasteboard *pasteboard = [sender draggingPasteboard];
NSArray *classes = [NSArray arrayWithObjects:[NSURL class], [NSImage class], nil];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSImage imageTypes]
forKey:NSPasteboardURLReadingContentsConformToTypesKey];
NSArray *classes = @[[NSURL class], [NSImage class]];
NSDictionary *options = @{NSPasteboardURLReadingContentsConformToTypesKey: [NSImage imageTypes]};
NSArray *draggedItems = [pasteboard readObjectsForClasses:classes options:options];
if (draggedItems) {
for (id dragItem in draggedItems)
for (id dragItem in draggedItems) {
edited = [self addArtwork:dragItem];
}
if (edited) {
metadata.isArtworkEdited = YES;
metadata.isEdited = YES;
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
[[[[[self view] window] windowController] document] updateChangeCount:NSChangeDone];
[imageBrowser reloadData];
return YES;
+7 -2
View File
@@ -8,6 +8,9 @@
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@class MP42Track;
@class MP42AudioTrack;
@class MP42File;
@@ -15,8 +18,8 @@
MP42AudioTrack *track;
MP42File *mp4file;
NSMutableArray *_fallbacks;
NSMutableArray *_follows;
NSMutableArray<MP42AudioTrack *> *_fallbacks;
NSMutableArray<__kindof MP42Track *> *_follows;
IBOutlet NSSlider *volume;
IBOutlet NSPopUpButton *alternateGroup;
@@ -33,3 +36,5 @@
- (IBAction)setFollowsTrack:(id)sender;
@end
NS_ASSUME_NONNULL_END
+3 -1
View File
@@ -11,8 +11,10 @@
@implementation SBSoundViewController
- (void)awakeFromNib
- (void)loadView
{
[super loadView];
[alternateGroup selectItemAtIndex:(NSInteger)track.alternate_group];
_fallbacks = [[NSMutableArray alloc] init];
@@ -8,6 +8,8 @@
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@class MP42File;
@class MP42VideoTrack;
@class MP42SubtitleTrack;
@@ -60,3 +62,5 @@
- (IBAction)setForcedTrack:(id)sender;
@end
NS_ASSUME_NONNULL_END
+3 -1
View File
@@ -56,8 +56,10 @@ static NSString *getLevelName(uint8_t level) {
}
}
- (void)awakeFromNib
- (void)loadView
{
[super loadView];
[sampleWidth setStringValue: [NSString stringWithFormat:@"%lld", track.width]];
[sampleHeight setStringValue: [NSString stringWithFormat:@"%lld", track.height]];