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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/**
* @file
* Implementation of class HBPreferencesController.
*/
#import "HBPreferencesController.h"
#define TOOLBAR_GENERAL @"TOOLBAR_GENERAL"
#define TOOLBAR_PICTURE @"TOOLBAR_PICTURE"
#define TOOLBAR_AUDIO @"TOOLBAR_AUDIO"
#define TOOLBAR_ADVANCED @"TOOLBAR_ADVANCED"
/**
* This class controls the preferences window of HandBrake. Default values for
* all preferences and user defaults are specified in class method
* @c registerUserDefaults. The preferences window is loaded from
* Preferences.nib file when HBPreferencesController is initialized.
*
* All preferences are bound to user defaults in Interface Builder, therefore
* no getter/setter code is needed in this file (unless more complicated
* preference settings are added that cannot be handled with Cocoa bindings).
*/
@interface HBPreferencesController (Private)
- (void) setPrefView: (id) sender;
@end
@implementation HBPreferencesController
/**
* Registers default values to user defaults. This is called immediately
* when HandBrake starts, from [HBController init].
*/
+ (void)registerUserDefaults
{
NSString *desktopDirectory = [@"~/Desktop" stringByExpandingTildeInPath];
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
@"YES", @"CheckForUpdates",
@"English", @"DefaultLanguage",
@"NO", @"DefaultMpegName",
@"YES", @"DefaultCrf",
@"NO", @"DefaultDeinterlaceOn",
@"NO", @"PixelRatio",
@"", @"DefAdvancedx264Flags",
@"YES", @"DefaultPresetsDrawerShow",
desktopDirectory, @"LastDestinationDirectory",
desktopDirectory, @"LastSourceDirectory",
@"NO", @"DefaultAutoNaming",
@"NO", @"DefaultChapterMarkers",
@"YES", @"ShowVerboseOutput",
@"NO", @"AllowLargeFiles",
@"NO", @"DisableDvdAutoDetect",
@"Alert Window", @"AlertWhenDone",
nil]];
}
/**
* Initializes the preferences controller by loading Preferences.nib file.
*/
- (id)init
{
if (self = [super initWithWindowNibName:@"Preferences"])
{
NSAssert([self window], @"[HBPreferencesController init] window outlet is not connected in Preferences.nib");
}
return self;
}
- (void) awakeFromNib
{
NSToolbar * toolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"];
[toolbar setDelegate: self];
[toolbar setAllowsUserCustomization: NO];
[toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
[toolbar setSizeMode: NSToolbarSizeModeRegular];
[[self window] setToolbar: toolbar];
[toolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
[self setPrefView:nil];
}
- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident
willBeInsertedIntoToolbar: (BOOL) flag
{
NSToolbarItem * item;
item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
if ([ident isEqualToString: TOOLBAR_GENERAL])
{
[item setLabel: NSLocalizedString(@"General", "General")];
[item setImage: [NSImage imageNamed: @"pref-general"]];
[item setTarget: self];
[item setAction: @selector(setPrefView:)];
[item setAutovalidates: NO];
}
else if ([ident isEqualToString: TOOLBAR_PICTURE])
{
[item setLabel: NSLocalizedString(@"Picture", "Picture")];
[item setImage: [NSImage imageNamed: @"pref-picture"]];
[item setTarget: self];
[item setAction: @selector(setPrefView:)];
[item setAutovalidates: NO];
}
else if ([ident isEqualToString: TOOLBAR_AUDIO])
{
[item setLabel: NSLocalizedString(@"Audio", "Audio")];
[item setImage: [NSImage imageNamed: @"pref-audio"]];
[item setTarget: self];
[item setAction: @selector(setPrefView:)];
[item setAutovalidates: NO];
}
else if ([ident isEqualToString: TOOLBAR_ADVANCED])
{
[item setLabel: NSLocalizedString(@"Advanced", "Advanced")];
[item setImage: [NSImage imageNamed: @"pref-advanced"]];
[item setTarget: self];
[item setAction: @selector(setPrefView:)];
[item setAutovalidates: NO];
}
else
{
[item release];
return nil;
}
return item;
}
- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
{
return [self toolbarDefaultItemIdentifiers: toolbar];
}
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
{
return [self toolbarAllowedItemIdentifiers: toolbar];
}
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
{
return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_PICTURE,
TOOLBAR_AUDIO, TOOLBAR_ADVANCED, nil];
}
/**
* Closes the window and stops modal state. Any changes made in field editor
* are saved by [NSWindow endEditingFor:] before closing the window.
*/
- (IBAction)close:(id)sender
{
//[self makeFirstResponder: nil];
}
@end
@implementation HBPreferencesController (Private)
- (void) setPrefView: (id) sender
{
NSView * view = fGeneralView;
if (sender)
{
NSString * identifier = [sender itemIdentifier];
if ([identifier isEqualToString: TOOLBAR_PICTURE])
view = fPictureView;
else if ([identifier isEqualToString: TOOLBAR_AUDIO])
view = fAudioView;
else if ([identifier isEqualToString: TOOLBAR_ADVANCED])
view = fAdvancedView;
else;
}
NSWindow * window = [self window];
if ([window contentView] == view)
return;
NSRect windowRect = [window frame];
float difference = ([view frame].size.height - [[window contentView] frame].size.height) * [window userSpaceScaleFactor];
windowRect.origin.y -= difference;
windowRect.size.height += difference;
[view setHidden: YES];
[window setContentView: view];
[window setFrame: windowRect display: YES animate: YES];
[view setHidden: NO];
//set title label
if (sender)
[window setTitle: [sender label]];
else
{
NSToolbar * toolbar = [window toolbar];
NSString * itemIdentifier = [toolbar selectedItemIdentifier];
NSEnumerator * enumerator = [[toolbar items] objectEnumerator];
NSToolbarItem * item;
while ((item = [enumerator nextObject]))
if ([[item itemIdentifier] isEqualToString: itemIdentifier])
{
[window setTitle: [item label]];
break;
}
}
}
@end
|