Add a new sheet to configure the media characterist tags

This commit is contained in:
Damiano Galassi committed 2015-09-13 08:05:35 +02:00
1 parent 428a28bc9e
commit 119c818d51
7 files changed
+245 -30

No files matched your search

+7 -1
View File
@@ -222,11 +222,17 @@
- (nullable __kindof NSDocument *)documentForURL:(NSURL *)url
{
for (NSDocument *doc in self.documents) {
NSArray<__kindof NSDocument *> *documents = nil;
@synchronized(self) {
documents = [self.documents copy];
}
for (NSDocument *doc in documents) {
if ([doc.fileURL isEqualTo:url.filePathURL]) {
return doc;
}
}
return nil;
}
+1 -1
View File
@@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
NSViewController *propertyView;
IBOutlet NSView *targetView;
id importWindow;
NSWindowController *_sheet;
IBOutlet NSWindow *offsetWindow;
IBOutlet NSTextField *offset;
+36 -14
View File
@@ -20,6 +20,8 @@
#import "SBMetadataSearchController.h"
#import "SBArtworkSelector.h"
#import "SBMediaTagsController.h"
#import <MP42Foundation/MP42File.h>
#import <MP42Foundation/MP42Languages.h>
#import <MP42Foundation/MP42Utilities.h>
@@ -86,7 +88,7 @@
+ (BOOL)canConcurrentlyReadDocumentsOfType:(NSString *)type
{
return YES;
return NO;
}
- (BOOL)isEntireFileLoaded
@@ -373,6 +375,9 @@
if (action == @selector(showTrackOffsetSheet:) && [fileTracksTable selectedRow] != -1)
return YES;
if (action == @selector(showMediaCharacteristicTags:) && [fileTracksTable selectedRow] != -1)
return YES;
if (action == @selector(addChaptersEvery:))
return YES;
@@ -593,8 +598,8 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
- (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
[[importWindow window] orderOut:nil];
[importWindow autorelease], importWindow = nil;
[_sheet.window orderOut:nil];
[_sheet autorelease], _sheet = nil;
[fileTracksTable reloadData];
[self reloadPropertyView];
@@ -640,9 +645,9 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
filename = self.fileURL.lastPathComponent;
}
importWindow = [[SBMetadataSearchController alloc] initWithDelegate:self searchString:filename];
_sheet = [[SBMetadataSearchController alloc] initWithDelegate:self searchString:filename];
[NSApp beginSheet:[importWindow window]
[NSApp beginSheet:_sheet.window
modalForWindow:documentWindow
modalDelegate:self
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
@@ -686,7 +691,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
[self updateChangeCount:NSChangeDone];
[NSApp endSheet: offsetWindow];
[NSApp endSheet:offsetWindow];
[offsetWindow orderOut:self];
}
@@ -696,6 +701,26 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
[offsetWindow orderOut:self];
}
- (IBAction)showMediaCharacteristicTags:(id)sender
{
_sheet = [[SBMediaTagsController alloc] initWithTrack:self.mp4.tracks[fileTracksTable.selectedRow]];
[NSApp beginSheet:_sheet.window
modalForWindow:documentWindow
modalDelegate:self
didEndSelector:@selector(mediaSheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void)mediaSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSOKButton) {
[self updateChangeCount:NSChangeDone];
}
[_sheet.window orderOut:self];
[_sheet release];
_sheet = nil;
}
- (IBAction)deleteTrack:(id)sender
{
if ([fileTracksTable selectedRow] == -1 || [fileTracksTable editedRow] != -1) {
@@ -771,15 +796,15 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
{
NSError *error = nil;
importWindow = [[SBFileImport alloc] initWithURLs:fileURLs delegate:self error:&error];
_sheet = [[SBFileImport alloc] initWithURLs:fileURLs delegate:self error:&error];
if (importWindow) {
if ([importWindow onlyContainsSubtitleTracks]) {
[importWindow addTracks:self];
if (_sheet) {
if ([(SBFileImport *)_sheet onlyContainsSubtitleTracks]) {
[(SBFileImport *)_sheet addTracks:self];
[self didEndSheet:nil returnCode:NSOKButton contextInfo:nil];
}
else { // show the dialog
[NSApp beginSheet:[importWindow window] modalForWindow:documentWindow
[NSApp beginSheet:_sheet.window modalForWindow:documentWindow
modalDelegate:self didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) contextInfo:NULL];
}
}
@@ -968,9 +993,6 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
- (void)dealloc
{
[fileTracksTable setDelegate:nil];
[fileTracksTable setDataSource:nil];
[propertyView release];
propertyView = nil;
+16 -1
View File
@@ -8,6 +8,21 @@
#import <Cocoa/Cocoa.h>
@interface SBMediaTagsController : NSWindowController
NS_ASSUME_NONNULL_BEGIN
@class MP42Track;
@class SBMediaTag;
@interface SBMediaTagsController : NSWindowController {
@private
MP42Track *_track;
NSArray<SBMediaTag *> *_tags;
IBOutlet NSTableView *_tableView;
}
- (instancetype)initWithTrack:(MP42Track *)track;
@end
NS_ASSUME_NONNULL_END
+165 -6
View File
@@ -7,17 +7,176 @@
//
#import "SBMediaTagsController.h"
#import <MP42Foundation/MP42Track.h>
@interface SBMediaTagsController ()
#pragma mark - Helpers
@interface SBMediaTag : NSObject {
BOOL _state;
NSString *_name;
NSString *_localizedName;
NSString *_localizedDescription;
}
@property (nonatomic, readwrite) BOOL state;
@property (nonatomic, readonly, nonnull) NSString *name;
@end
@implementation SBMediaTagsController
@implementation SBMediaTag
- (void)windowDidLoad {
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- (instancetype)initWithName:(NSString *)name state:(BOOL)state {
self = [super init];
if (self) {
_state = state;
_name = [name copy];
}
return self;
}
@synthesize state = _state;
@synthesize name = _name;
- (void)dealloc {
[_name release];
_name = nil;
[super dealloc];
}
@end
@interface SBCheckBoxTableCellView : NSTableCellView {
IBOutlet NSButton *_checkBox;
SBMediaTag *_representedTag;
}
@property (nonatomic, readwrite, retain, nonnull) SBMediaTag *representedTag;
@end
@implementation SBCheckBoxTableCellView
@synthesize representedTag = _representedTag;
- (void)setRepresentedTag:(SBMediaTag *)representedTag {
[_representedTag autorelease];
_representedTag = [representedTag retain];
_checkBox.title = _representedTag.name;
_checkBox.state = _representedTag.state;
}
@end
@interface SBMediaTagsController () <NSTableViewDataSource, NSTableViewDelegate>
@property (nonatomic, readonly, nonnull) MP42Track *track;
@property (nonatomic, readonly, nonnull) NSArray<SBMediaTag *> *tags;
@end
#pragma mark - Main Class
@implementation SBMediaTagsController
- (instancetype)init {
self = [super initWithWindowNibName:@"SBMediaTagsController"];
if (self) {
}
return self;
}
- (instancetype)initWithTrack:(MP42Track *)track {
self = [self init];
if (self) {
_track = [track retain];
NSArray *predefinedTags = @[@"public.main-program-content", @"public.auxiliary-content",
@"public.subtitles.forced-only", @"public.accessibility.transcribes-spoken-dialog",
@"public.accessibility.describes-music-and-sound", @"public.easy-to-read",
@"public.accessibility.describes-video", @"public.translation.dubbed",
@"public.translation.voice-over", @"public.translation"];
NSMutableArray<SBMediaTag *> *tags = [[NSMutableArray alloc] init];
// Add the predefined tags
for (NSString *availableTag in predefinedTags) {
BOOL state = [track.mediaCharacteristicTags containsObject:availableTag] ? YES : NO;
SBMediaTag *tag = [[SBMediaTag alloc] initWithName:availableTag state:state];
[tags addObject:tag];
[tag release];
}
// Keep the custom ones if present
NSMutableSet<NSString *> *custom = [track.mediaCharacteristicTags mutableCopy];
[custom minusSet:[NSSet setWithArray:predefinedTags]];
for (NSString *customTag in custom) {
SBMediaTag *tag = [[SBMediaTag alloc] initWithName:customTag state:YES];
[tags addObject:tag];
[tag release];
}
[custom release];
_tags = [tags copy];
[tags release];
}
return self;
}
@synthesize track = _track;
@synthesize tags = _tags;
- (void)dealloc {
[_tableView setDelegate:nil];
[_tableView setDataSource:nil];
[_track release];
_track = nil;
[_tags release];
_tags = nil;
[super dealloc];
}
- (void)windowDidLoad {
[super windowDidLoad];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return self.tags.count;
}
- (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row {
SBCheckBoxTableCellView *result = [tableView makeViewWithIdentifier:@"SBCheckBoxTableCellView" owner:self];
result.representedTag = self.tags[row];
return result;
}
- (IBAction)setTagState:(NSButton *)sender {
NSInteger row = [_tableView rowForView:sender];
self.tags[row].state = sender.state;
}
- (IBAction)done:(id)sender {
NSMutableSet *set = [NSMutableSet set];
for (SBMediaTag *tag in self.tags) {
if (tag.state == YES) {
[set addObject:tag.name];
}
}
self.track.mediaCharacteristicTags = set;
[NSApp endSheet:self.window returnCode:NSOKButton];
}
- (IBAction)cancel:(id)sender{
[NSApp endSheet:self.window returnCode:NSCancelButton];
}
@end
+8 -2
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8187.4" systemVersion="15A262e" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8191" systemVersion="15A282a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8187.4"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8191"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -242,6 +242,12 @@
<action selector="showTrackOffsetSheet:" target="-1" id="570"/>
</connections>
</menuItem>
<menuItem title="Media Characteristic Tags…" id="zCE-Af-jYS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showMediaCharacteristicTags:" target="-1" id="yFp-aa-11o"/>
</connections>
</menuItem>
<menuItem title="Insert a Chapter" id="573">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Insert a Chapter" id="574">
+12 -5
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8187.4" systemVersion="15A262e" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8191" systemVersion="15A282a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8187.4"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8191"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SBDocument">
@@ -213,7 +213,7 @@
<rect key="frame" x="2" y="14" width="38" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<animations/>
<popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" imagePosition="left" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" pullsDown="YES" arrowPosition="arrowAtCenter" id="100333">
<popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" imagePosition="left" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" pullsDown="YES" arrowPosition="arrowAtCenter" selectedItem="100336" id="100333">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="100334">
@@ -274,10 +274,17 @@
<action selector="iTunesFriendlyTrackGroups:" target="-2" id="100348"/>
</connections>
</menuItem>
<menuItem title="Offset…" id="100336">
<menuItem isSeparatorItem="YES" id="83X-pX-gUO"/>
<menuItem title="Offset…" id="lZI-ub-uVG">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showTrackOffsetSheet:" target="-2" id="100350"/>
<action selector="showTrackOffsetSheet:" target="-2" id="kyN-OW-t8L"/>
</connections>
</menuItem>
<menuItem title="Media Characteristic Tags…" id="100336">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showMediaCharacteristicTags:" target="-2" id="K9P-B5-14p"/>
</connections>
</menuItem>
</items>