blob: b9c88e9400f22114d098032fde99b4392da9764c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/* $Id: HBSubtitles.m
This file is part of the HandBrake source code.
Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
#import "HBSubtitlesController.h"
#import "HBSubtitlesDefaultsController.h"
@import HandBrakeKit;
@interface HBSubtitlesController ()
// Defaults
@property (nonatomic, readwrite, strong) HBSubtitlesDefaultsController *defaultsController;
@end
@implementation HBSubtitlesController
- (instancetype)init
{
self = [super initWithNibName:@"Subtitles" bundle:nil];
return self;
}
#pragma mark - Actions
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem
{
return (self.subtitles != nil);
}
/**
* Add every subtitles track that still isn't in the subtitles array.
*/
- (IBAction)addAll:(id)sender
{
[self.subtitles addAllTracks];
}
/**
* Remove all the subtitles tracks.
*/
- (IBAction)removeAll:(id)sender
{
[self.subtitles removeAll];
}
/**
* Remove all the subtitles tracks and
* add new ones based on the defaults settings
*/
- (IBAction)addTracksFromDefaults:(id)sender
{
[self.subtitles reloadDefaults];
}
- (IBAction)showSettingsSheet:(id)sender
{
HBSubtitlesDefaults *defaults = [self.subtitles.defaults copy];
self.defaultsController = [[HBSubtitlesDefaultsController alloc] initWithSettings:defaults];
[self.view.window beginSheet:self.defaultsController.window completionHandler:^(NSModalResponse returnCode) {
if (returnCode == NSModalResponseOK)
{
self.subtitles.defaults = defaults;
}
self.defaultsController = nil;
}];
}
#pragma mark - External subtitles import
/**
* Imports a srt/ssa file.
*
* @param sender
*/
- (IBAction)browseImportExternalFile:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
panel.allowsMultipleSelection = NO;
panel.canChooseFiles = YES;
panel.canChooseDirectories = NO;
NSURL *sourceDirectory;
if ([[NSUserDefaults standardUserDefaults] URLForKey:@"LastExternalSubImportDirectoryURL"])
{
sourceDirectory = [[NSUserDefaults standardUserDefaults] URLForKey:@"LastExternalSubImportDirectoryURL"];
}
else
{
sourceDirectory = [[NSURL fileURLWithPath:NSHomeDirectory()] URLByAppendingPathComponent:@"Desktop"];
}
panel.directoryURL = sourceDirectory;
panel.allowedFileTypes = @[@"srt", @"ssa", @"ass"];
[panel beginSheetModalForWindow:self.view.window completionHandler:^(NSInteger result)
{
if (result == NSModalResponseOK)
{
NSURL *importFileURL = panel.URL;
NSURL *importDirectory = importFileURL.URLByDeletingLastPathComponent;
[[NSUserDefaults standardUserDefaults] setURL:importDirectory forKey:@"LastExternalSubImportDirectoryURL"];
[self.subtitles addExternalTrackFromURL:importFileURL];
}
}];
}
@end
|