blob: 99c0ac99806c167efc496c20eb27cd7b2e5e28ee (
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
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* $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 "HBSubtitles.h"
#import "HBSubtitlesDefaults.h"
@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];
[NSApp beginSheet:self.defaultsController.window
modalForWindow:self.view.window
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:(void *)CFBridgingRetain(defaults)];
}
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
HBSubtitlesDefaults *defaults = (HBSubtitlesDefaults *)CFBridgingRelease(contextInfo);
// If things changed, do this ugly
// operation to group the changes for the undo manager.
if (returnCode)
{
defaults.undo = self.subtitles.defaults.undo;
self.subtitles.defaults = defaults;
}
self.defaultsController = nil;
}
#pragma mark - Srt import
/**
* Imports a srt file.
*
* @param sender
*/
- (IBAction)browseImportSrtFile:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
panel.allowsMultipleSelection = NO;
panel.canChooseFiles = YES;
panel.canChooseDirectories = NO;
NSURL *sourceDirectory;
if ([[NSUserDefaults standardUserDefaults] URLForKey:@"LastSrtImportDirectoryURL"])
{
sourceDirectory = [[NSUserDefaults standardUserDefaults] URLForKey:@"LastSrtImportDirectoryURL"];
}
else
{
sourceDirectory = [[NSURL fileURLWithPath:NSHomeDirectory()] URLByAppendingPathComponent:@"Desktop"];
}
panel.directoryURL = sourceDirectory;
panel.allowedFileTypes = @[@"srt"];
[panel beginSheetModalForWindow:self.view.window completionHandler:^(NSInteger result)
{
if (result == NSFileHandlingPanelOKButton)
{
NSURL *importSrtFileURL = panel.URL;
NSURL *importSrtDirectory = importSrtFileURL.URLByDeletingLastPathComponent;
[[NSUserDefaults standardUserDefaults] setURL:importSrtDirectory forKey:@"LastSrtImportDirectoryURL"];
[self.subtitles addSrtTrackFromURL:importSrtFileURL];
}
}];
}
@end
|