playlist: use boolean for playlist_AddInput() mode parameter
[vlc.git] / modules / gui / macosx / VLCConvertAndSaveWindowController.m
blobf203a5e78abe7d95ae2b8ba26ba964e534795761
1 /*****************************************************************************
2  * VLCConvertAndSaveWindowController.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2012 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
24 #import "VLCConvertAndSaveWindowController.h"
26 #import "VLCMain.h"
27 #import "VLCPlaylist.h"
28 #import "misc.h"
29 #import "VLCPopupPanelController.h"
30 #import "VLCTextfieldPanelController.h"
32 #import <vlc_common.h>
33 #import <vlc_url.h>
35 /* mini doc:
36  * the used NSMatrix includes a bunch of cells referenced most easily by tags. There you go: */
37 #define MPEGTS 0
38 #define WEBM 1
39 #define OGG 2
40 #define MP4 3
41 #define MPEGPS 4
42 #define MJPEG 5
43 #define WAV 6
44 #define FLV 7
45 #define MPEG1 8
46 #define MKV 9
47 #define RAW 10
48 #define AVI 11
49 #define ASF 12
50 /* 13-15 are present, but not set */
52 @interface VLCConvertAndSaveWindowController()
54     NSArray *_videoCodecs;
55     NSArray *_audioCodecs;
56     NSArray *_subsCodecs;
57     BOOL b_streaming;
60 - (void)updateDropView;
61 - (void)updateOKButton;
62 - (void)resetCustomizationSheetBasedOnProfile:(NSString *)profileString;
63 - (void)selectCellByEncapsulationFormat:(NSString *)format;
64 - (NSString *)currentEncapsulationFormatAsFileExtension:(BOOL)b_extension;
65 - (NSString *)composedOptions;
66 - (void)updateCurrentProfile;
67 - (void)storeProfilesOnDisk;
68 - (void)recreateProfilePopup;
69 @end
71 @implementation VLCConvertAndSaveWindowController
73 #pragma mark -
74 #pragma mark Initialization
76 + (void)initialize
78     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
80     /* We are using the same format as the Qt intf here:
81      * Container(string), transcode video(bool), transcode audio(bool),
82      * use subtitles(bool), video codec(string), video bitrate(integer),
83      * scale(float), fps(float), width(integer, height(integer),
84      * audio codec(string), audio bitrate(integer), channels(integer),
85      * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */
86     NSArray * defaultProfiles = [[NSArray alloc] initWithObjects:
87                                  @"mp4;1;1;0;h264;0;0;0;0;0;mpga;128;2;44100;0;1",
88                                  @"webm;1;1;0;VP80;2000;0;0;0;0;vorb;128;2;44100;0;1",
89                                  @"ts;1;1;0;h264;800;1;0;0;0;mpga;128;2;44100;0;0",
90                                  @"ts;1;1;0;drac;800;1;0;0;0;mpga;128;2;44100;0;0",
91                                  @"ogg;1;1;0;theo;800;1;0;0;0;vorb;128;2;44100;0;0",
92                                  @"ogg;1;1;0;theo;800;1;0;0;0;flac;128;2;44100;0;0",
93                                  @"ts;1;1;0;mp2v;800;1;0;0;0;mpga;128;2;44100;0;0",
94                                  @"asf;1;1;0;WMV2;800;1;0;0;0;wma2;128;2;44100;0;0",
95                                  @"asf;1;1;0;DIV3;800;1;0;0;0;mp3;128;2;44100;0;0",
96                                  @"ogg;0;1;0;none;800;1;0;0;0;vorb;128;2;44100;none;0",
97                                  @"raw;0;1;0;none;800;1;0;0;0;mp3;128;2;44100;none;0",
98                                  @"mp4;0;1;0;none;800;1;0;0;0;mpga;128;2;44100;none;0",
99                                  @"raw;0;1;0;none;800;1;0;0;0;flac;128;2;44100;none;0",
100                                  @"wav;0;1;0;none;800;1;0;0;0;s16l;128;2;44100;none;0", nil];
102     NSArray * defaultProfileNames = [[NSArray alloc] initWithObjects:
103                                      @"Video - H.264 + MP3 (MP4)",
104                                      @"Video - VP80 + Vorbis (Webm)",
105                                      @"Video - H.264 + MP3 (TS)",
106                                      @"Video - Dirac + MP3 (TS)",
107                                      @"Video - Theora + Vorbis (OGG)",
108                                      @"Video - Theora + Flac (OGG)",
109                                      @"Video - MPEG-2 + MPGA (TS)",
110                                      @"Video - WMV + WMA (ASF)",
111                                      @"Video - DIV3 + MP3 (ASF)",
112                                      @"Audio - Vorbis (OGG)",
113                                      @"Audio - MP3",
114                                      @"Audio - MP3 (MP4)",
115                                      @"Audio - FLAC",
116                                      @"Audio - CD",
117                                      nil];
119     NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:defaultProfiles, @"CASProfiles", defaultProfileNames, @"CASProfileNames", nil];
121     [defaults registerDefaults:appDefaults];
124 - (id)init
126     self = [super initWithWindowNibName:@"ConvertAndSave"];
127     if (self) {
128         self.popupPanel = [[VLCPopupPanelController alloc] init];
129         self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
130     }
131     return self;
134 - (void)windowDidLoad
136     [self.window setTitle: _NS("Convert & Stream")];
137     [_okButton setTitle: _NS("Go!")];
138     [_dropLabel setStringValue: _NS("Drop media here")];
139     [_dropButton setTitle: _NS("Open media...")];
140     [_profileLabel setStringValue: _NS("Choose Profile")];
141     [_customizeButton setTitle: _NS("Customize...")];
142     [_destinationLabel setStringValue: _NS("Choose Destination")];
143     [_fileDestinationFileNameStub setStringValue: _NS("Choose an output location")];
144     [_fileDestinationFileName setHidden: YES];
145     [_fileDestinationBrowseButton setTitle:_NS("Browse...")];
146     [_streamDestinationButton setTitle:_NS("Setup Streaming...")];
147     [_streamDestinationURLLabel setStringValue:_NS("Select Streaming Method")];
148     [_destinationFileButton setTitle:_NS("Save as File")];
149     [_destinationStreamButton setTitle:_NS("Stream")];
150     [_destinationCancelBtn setHidden:YES];
152     [_customizeOkButton setTitle: _NS("Apply")];
153     [_customizeCancelButton setTitle: _NS("Cancel")];
154     [_customizeNewProfileButton setTitle: _NS("Save as new Profile...")];
155     [[_customizeTabView tabViewItemAtIndex:0] setLabel: _NS("Encapsulation")];
156     [[_customizeTabView tabViewItemAtIndex:1] setLabel: _NS("Video codec")];
157     [[_customizeTabView tabViewItemAtIndex:2] setLabel: _NS("Audio codec")];
158     [[_customizeTabView tabViewItemAtIndex:3] setLabel: _NS("Subtitles")];
159     [_customizeTabView selectTabViewItemAtIndex: 0];
160     [_customizeVidCheckbox setTitle: _NS("Video")];
161     [_customizeVidKeepCheckbox setTitle: _NS("Keep original video track")];
162     [_customizeVidCodecLabel setStringValue: _NS("Codec")];
163     [_customizeVidBitrateLabel setStringValue: _NS("Bitrate")];
164     [_customizeVidFramerateLabel setStringValue: _NS("Frame rate")];
165     [_customizeVidResolutionBox setTitle: _NS("Resolution")];
166     [_customizeVidResLabel setStringValue: _NS("You just need to fill one of the three following parameters, VLC will autodetect the other using the original aspect ratio")];
167     [_customizeVidWidthLabel setStringValue: _NS("Width")];
168     [_customizeVidHeightLabel setStringValue: _NS("Height")];
169     [_customizeVidScaleLabel setStringValue: _NS("Scale")];
171     [_customizeAudCheckbox setTitle: _NS("Audio")];
172     [_customizeAudKeepCheckbox setTitle: _NS("Keep original audio track")];
173     [_customizeAudCodecLabel setStringValue: _NS("Codec")];
174     [_customizeAudBitrateLabel setStringValue: _NS("Bitrate")];
175     [_customizeAudChannelsLabel setStringValue: _NS("Channels")];
176     [_customizeAudSamplerateLabel setStringValue: _NS("Samplerate")];
178     [_customizeSubsCheckbox setTitle: _NS("Subtitles")];
179     [_customizeSubsOverlayCheckbox setTitle: _NS("Overlay subtitles on the video")];
181     [_streamOkButton setTitle: _NS("Apply")];
182     [_streamCancelButton setTitle: _NS("Cancel")];
183     [_streamDestinationLabel setStringValue:_NS("Stream Destination")];
184     [_streamAnnouncementLabel setStringValue:_NS("Stream Announcement")];
185     [_streamTypeLabel setStringValue:_NS("Type")];
186     [_streamAddressLabel setStringValue:_NS("Address")];
187     [_streamTTLLabel setStringValue:_NS("TTL")];
188     [_streamTTLStepper setEnabled:NO];
189     [_streamPortLabel setStringValue:_NS("Port")];
190     [_streamSAPCheckbox setStringValue:_NS("SAP Announcement")];
191     [[_streamSDPMatrix cellWithTag:0] setTitle:_NS("None")];
192     [[_streamSDPMatrix cellWithTag:1] setTitle:_NS("HTTP Announcement")];
193     [[_streamSDPMatrix cellWithTag:2] setTitle:_NS("RTSP Announcement")];
194     [[_streamSDPMatrix cellWithTag:3] setTitle:_NS("Export SDP as file")];
195     [_streamSAPCheckbox setState:NSOffState];
196     [_streamSDPMatrix setEnabled:NO];
197     [_streamSDPFileBrowseButton setStringValue:_NS("Browse...")];
198     [_streamChannelLabel setStringValue:_NS("Channel Name")];
199     [_streamSDPLabel setStringValue:_NS("SDP URL")];
201     /* there is no way to hide single cells, so replace the existing ones with empty cells.. */
202     id blankCell = [[NSCell alloc] init];
203     [blankCell setEnabled:NO];
204     [_customizeEncapMatrix putCell:blankCell atRow:3 column:1];
205     [_customizeEncapMatrix putCell:blankCell atRow:3 column:2];
206     [_customizeEncapMatrix putCell:blankCell atRow:3 column:3];
208     /* fetch profiles from defaults */
209     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
210     [self setProfileValueList: [defaults arrayForKey:@"CASProfiles"]];
211     [self setProfileNames: [defaults arrayForKey:@"CASProfileNames"]];
212     [self recreateProfilePopup];
214     _videoCodecs = [[NSArray alloc] initWithObjects:
215                     [NSArray arrayWithObjects:@"MPEG-1", @"MPEG-2", @"MPEG-4", @"DIVX 1", @"DIVX 2", @"DIVX 3", @"H.263", @"H.264", @"VP8", @"WMV1", @"WMV2", @"M-JPEG", @"Theora", @"Dirac", nil],
216                     [NSArray arrayWithObjects:@"mpgv", @"mp2v", @"mp4v", @"DIV1", @"DIV2", @"DIV3", @"H263", @"h264", @"VP80", @"WMV1", @"WMV2", @"MJPG", @"theo", @"drac", nil],
217                     nil];
218     _audioCodecs = [[NSArray alloc] initWithObjects:
219                     [NSArray arrayWithObjects:@"MPEG Audio", @"MP3", @"MPEG 4 Audio (AAC)", @"A52/AC-3", @"Vorbis", @"Flac", @"Speex", @"WAV", @"WMA2", nil],
220                     [NSArray arrayWithObjects:@"mpga", @"mp3", @"mp4a", @"a52", @"vorb", @"flac", @"spx", @"s16l", @"wma2", nil],
221                     nil];
222     _subsCodecs = [[NSArray alloc] initWithObjects:
223                    [NSArray arrayWithObjects:@"DVB subtitle", @"T.140", nil],
224                    [NSArray arrayWithObjects:@"dvbs", @"t140", nil],
225                     nil];
227     [_customizeVidCodecPopup removeAllItems];
228     [_customizeVidScalePopup removeAllItems];
229     [_customizeAudCodecPopup removeAllItems];
230     [_customizeAudSampleratePopup removeAllItems];
231     [_customizeSubsPopup removeAllItems];
233     [_customizeVidCodecPopup addItemsWithTitles:[_videoCodecs firstObject]];
234     [_customizeAudCodecPopup addItemsWithTitles:[_audioCodecs firstObject]];
235     [_customizeSubsPopup addItemsWithTitles:[_subsCodecs firstObject]];
237     [_customizeAudSampleratePopup addItemWithTitle:@"8000"];
238     [_customizeAudSampleratePopup addItemWithTitle:@"11025"];
239     [_customizeAudSampleratePopup addItemWithTitle:@"22050"];
240     [_customizeAudSampleratePopup addItemWithTitle:@"44100"];
241     [_customizeAudSampleratePopup addItemWithTitle:@"48000"];
243     [_customizeVidScalePopup addItemWithTitle:@"1"];
244     [_customizeVidScalePopup addItemWithTitle:@"0.25"];
245     [_customizeVidScalePopup addItemWithTitle:@"0.5"];
246     [_customizeVidScalePopup addItemWithTitle:@"0.75"];
247     [_customizeVidScalePopup addItemWithTitle:@"1.25"];
248     [_customizeVidScalePopup addItemWithTitle:@"1.5"];
249     [_customizeVidScalePopup addItemWithTitle:@"1.75"];
250     [_customizeVidScalePopup addItemWithTitle:@"2"];
252     [_okButton setEnabled: NO];
254     // setup drop view
255     [_dropBox enablePlaylistItems];
256     [_dropBox setDropHandler: self];
258     [self resetCustomizationSheetBasedOnProfile:[self.profileValueList firstObject]];
261 # pragma mark -
262 # pragma mark User Interaction - main window
264 - (IBAction)finalizePanel:(id)sender
266     if (b_streaming) {
267         if ([[[_streamTypePopup selectedItem] title] isEqualToString:@"HTTP"]) {
268             NSString *muxformat = [self.currentProfile firstObject];
269             if ([muxformat isEqualToString:@"wav"] || [muxformat isEqualToString:@"mov"] || [muxformat isEqualToString:@"mp4"] || [muxformat isEqualToString:@"mkv"]) {
270                 NSBeginInformationalAlertSheet(_NS("Invalid container format for HTTP streaming"), _NS("OK"), @"", @"", self.window,
271                                                nil, nil, nil, nil,
272                                                _NS("Media encapsulated as %@ cannot be streamed through the HTTP protocol for technical reasons."),
273                                                [[self currentEncapsulationFormatAsFileExtension:YES] uppercaseString]);
274                 return;
275             }
276         }
277     }
279     playlist_t * p_playlist = pl_Get(getIntf());
281     input_item_t *p_input = input_item_New([_MRL UTF8String], [[_dropinMediaLabel stringValue] UTF8String]);
282     if (!p_input)
283         return;
285     input_item_AddOption(p_input, [[self composedOptions] UTF8String], VLC_INPUT_OPTION_TRUSTED);
286     if (b_streaming)
287         input_item_AddOption(p_input, [[NSString stringWithFormat:@"ttl=%@", [_streamTTLField stringValue]] UTF8String], VLC_INPUT_OPTION_TRUSTED);
289     int returnValue;
290     returnValue = playlist_AddInput(p_playlist, p_input, false, true );
292     if (returnValue == VLC_SUCCESS) {
293         /* let's "play" */
294         PL_LOCK;
295         playlist_item_t *p_item = playlist_ItemGetByInput(p_playlist, p_input);
296         playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, NULL,
297                          p_item);
298         PL_UNLOCK;
299     }
300     else
301         msg_Err(getIntf(), "CAS: playlist add input failed :(");
303     /* we're done with this input */
304     input_item_Release(p_input);
306     [self.window performClose:sender];
309 - (IBAction)openMedia:(id)sender
311     /* preliminary implementation until the open panel is cleaned up */
312     NSOpenPanel * openPanel = [NSOpenPanel openPanel];
313     [openPanel setCanChooseDirectories:NO];
314     [openPanel setResolvesAliases:YES];
315     [openPanel setAllowsMultipleSelection:NO];
316     [openPanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger returnCode) {
317         if (returnCode == NSOKButton)
318         {
319             [self setMRL: toNSStr(vlc_path2uri([[[openPanel URL] path] UTF8String], NULL))];
320             [self updateOKButton];
321             [self updateDropView];
322         }
323     }];
326 - (IBAction)switchProfile:(id)sender
328     NSUInteger index = [_profilePopup indexOfSelectedItem];
329     // last index is "custom"
330     if (index <= ([self.profileValueList count] - 1))
331         [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:index]];
334 - (IBAction)deleteProfileAction:(id)sender
336     /* show panel */
337     [_popupPanel setTitleString:_NS("Remove a profile")];
338     [_popupPanel setSubTitleString:_NS("Select the profile you would like to remove:")];
339     [_popupPanel setOkButtonString:_NS("Remove")];
340     [_popupPanel setCancelButtonString:_NS("Cancel")];
341     [_popupPanel setPopupButtonContent:self.profileNames];
343     __weak typeof(self) _self = self;
344     [_popupPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSInteger selectedIndex) {
346         if (returnCode != NSOKButton)
347             return;
349         /* remove requested profile from the arrays */
350         NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:_self.profileNames];
351         [workArray removeObjectAtIndex:selectedIndex];
352         [_self setProfileNames:[[NSArray alloc] initWithArray:workArray]];
353         workArray = [[NSMutableArray alloc] initWithArray:_self.profileValueList];
354         [workArray removeObjectAtIndex:selectedIndex];
355         [_self setProfileValueList:[[NSArray alloc] initWithArray:workArray]];
357         /* update UI */
358         [_self recreateProfilePopup];
360         /* update internals */
361         [_self switchProfile:_self];
362         [_self storeProfilesOnDisk];
363     }];
366 - (IBAction)iWantAFile:(id)sender
368     NSRect boxFrame = [_destinationBox frame];
369     NSRect subViewFrame = [_fileDestinationView frame];
370     subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2;
371     subViewFrame.origin.y = ((boxFrame.size.height - subViewFrame.size.height) / 2) - 15.;
372     [_fileDestinationView setFrame: subViewFrame];
373     [[_destinationFileButton animator] setHidden: YES];
374     [[_destinationStreamButton animator] setHidden: YES];
375     [_destinationBox performSelector:@selector(addSubview:) withObject:_fileDestinationView afterDelay:0.2];
376     [[_destinationCancelBtn animator] setHidden:NO];
377     b_streaming = NO;
378     [_okButton setTitle:_NS("Save")];
381 - (IBAction)iWantAStream:(id)sender
383     NSRect boxFrame = [_destinationBox frame];
384     NSRect subViewFrame = [_streamDestinationView frame];
385     subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2;
386     subViewFrame.origin.y = ((boxFrame.size.height - subViewFrame.size.height) / 2) - 15.;
387     [_streamDestinationView setFrame: subViewFrame];
388     [[_destinationFileButton animator] setHidden: YES];
389     [[_destinationStreamButton animator] setHidden: YES];
390     [_destinationBox performSelector:@selector(addSubview:) withObject:_streamDestinationView afterDelay:0.2];
391     [[_destinationCancelBtn animator] setHidden:NO];
392     b_streaming = YES;
393     [_okButton setTitle:_NS("Stream")];
396 - (IBAction)cancelDestination:(id)sender
398     if ([_streamDestinationView superview] != nil)
399         [_streamDestinationView removeFromSuperview];
400     if ([_fileDestinationView superview] != nil)
401         [_fileDestinationView removeFromSuperview];
403     [_destinationCancelBtn setHidden:YES];
404     [[_destinationFileButton animator] setHidden: NO];
405     [[_destinationStreamButton animator] setHidden: NO];
406     b_streaming = NO;
409 - (IBAction)browseFileDestination:(id)sender
411     NSSavePanel * saveFilePanel = [NSSavePanel savePanel];
412     [saveFilePanel setCanSelectHiddenExtension: YES];
413     [saveFilePanel setCanCreateDirectories: YES];
414     if ([[_customizeEncapMatrix selectedCell] tag] != RAW) // there is no clever guess for this
415         [saveFilePanel setAllowedFileTypes:[NSArray arrayWithObject:[self currentEncapsulationFormatAsFileExtension:YES]]];
416     [saveFilePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger returnCode) {
417         if (returnCode == NSOKButton) {
418             [self setOutputDestination:[[saveFilePanel URL] path]];
419             [_fileDestinationFileName setStringValue: [[NSFileManager defaultManager] displayNameAtPath:_outputDestination]];
420             [[_fileDestinationFileNameStub animator] setHidden: YES];
421             [[_fileDestinationFileName animator] setHidden: NO];
422         } else {
423             [self setOutputDestination:@""];
424             [[_fileDestinationFileName animator] setHidden: YES];
425             [[_fileDestinationFileNameStub animator] setHidden: NO];
426         }
427         [self updateOKButton];
428     }];
431 #pragma mark -
432 #pragma mark User interaction - customization panel
434 - (IBAction)customizeProfile:(id)sender
436     [NSApp beginSheet:_customizePanel modalForWindow:self.window modalDelegate:self didEndSelector:NULL contextInfo:nil];
439 - (IBAction)closeCustomizationSheet:(id)sender
441     [_customizePanel orderOut:sender];
442     [NSApp endSheet: _customizePanel];
444     if (sender == _customizeOkButton)
445         [self updateCurrentProfile];
450 - (IBAction)videoSettingsChanged:(id)sender
452     bool enableSettings = [_customizeVidCheckbox state] == NSOnState && [_customizeVidKeepCheckbox state] == NSOffState;
453     [_customizeVidSettingsBox enableSubviews:enableSettings];
454     [_customizeVidKeepCheckbox setEnabled:[_customizeVidCheckbox state] == NSOnState];
457 - (IBAction)audioSettingsChanged:(id)sender
459     bool enableSettings = [_customizeAudCheckbox state] == NSOnState && [_customizeAudKeepCheckbox state] == NSOffState;
460     [_customizeAudSettingsBox enableSubviews:enableSettings];
461     [_customizeAudKeepCheckbox setEnabled:[_customizeAudCheckbox state] == NSOnState];
464 - (IBAction)subSettingsChanged:(id)sender
466     bool enableSettings = [_customizeSubsCheckbox state] == NSOnState;
467     [_customizeSubsOverlayCheckbox setEnabled:enableSettings];
468     [_customizeSubsPopup setEnabled:enableSettings];
471 - (IBAction)newProfileAction:(id)sender
473     /* show panel */
474     [_textfieldPanel setTitleString: _NS("Save as new profile")];
475     [_textfieldPanel setSubTitleString: _NS("Enter a name for the new profile:")];
476     [_textfieldPanel setCancelButtonString: _NS("Cancel")];
477     [_textfieldPanel setOkButtonString: _NS("Save")];
479     __weak typeof(self) _self = self;
480     [_textfieldPanel runModalForWindow:_customizePanel completionHandler:^(NSInteger returnCode, NSString *resultingText) {
481         if (returnCode != NSOKButton || [resultingText length] == 0)
482             return;
484         /* prepare current data */
485         [_self updateCurrentProfile];
487         /* add profile to arrays */
488         NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
489         [workArray addObject:resultingText];
490         [_self setProfileNames:[[NSArray alloc] initWithArray:workArray]];
492         workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
493         [workArray addObject:[self.currentProfile componentsJoinedByString:@";"]];
494         [_self setProfileValueList:[[NSArray alloc] initWithArray:workArray]];
496         /* update UI */
497         [_self recreateProfilePopup];
498         [_profilePopup selectItemWithTitle:resultingText];
500         /* update internals */
501         [_self switchProfile:self];
502         [_self storeProfilesOnDisk];
503     }];
506 #pragma mark -
507 #pragma mark User interaction - stream panel
509 - (IBAction)showStreamPanel:(id)sender
511     [NSApp beginSheet:_streamPanel modalForWindow:self.window modalDelegate:self didEndSelector:NULL contextInfo:nil];
514 - (IBAction)closeStreamPanel:(id)sender
516     [_streamPanel orderOut:sender];
517     [NSApp endSheet: _streamPanel];
519     if (sender == _streamCancelButton)
520         return;
522     /* provide a summary of the user selections */
523     NSMutableString * labelContent = [[NSMutableString alloc] initWithFormat:_NS("%@ stream to %@:%@"), [_streamTypePopup titleOfSelectedItem], [_streamAddressField stringValue], [_streamPortField stringValue]];
525     if ([_streamTypePopup indexOfSelectedItem] > 1)
526         [labelContent appendFormat:@" (\"%@\")", [_streamChannelField stringValue]];
528     [_streamDestinationURLLabel setStringValue:labelContent];
530     /* catch obvious errors */
531     if ([[_streamAddressField stringValue] length] == 0) {
532         NSBeginInformationalAlertSheet(_NS("No Address given"),
533                                        _NS("OK"), @"", @"", _streamPanel, nil, nil, nil, nil,
534                                        @"%@", _NS("In order to stream, a valid destination address is required."));
535         return;
536     }
538     if ([_streamSAPCheckbox state] && [[_streamChannelField stringValue] length] == 0) {
539         NSBeginInformationalAlertSheet(_NS("No Channel Name given"),
540                                        _NS("OK"), @"", @"", _streamPanel, nil, nil, nil, nil,
541                                        @"%@", _NS("SAP stream announcement is enabled. However, no channel name is provided."));
542         return;
543     }
545     if ([_streamSDPMatrix isEnabled] && [_streamSDPMatrix selectedCell] != [_streamSDPMatrix cellWithTag:0] && [[_streamSDPField stringValue] length] == 0) {
546         NSBeginInformationalAlertSheet(_NS("No SDP URL given"),
547                                        _NS("OK"), @"", @"", _streamPanel, nil, nil, nil, nil,
548                                        @"%@", _NS("A SDP export is requested, but no URL is provided."));
549         return;
550     }
552     /* store destination for further reference and update UI */
553     [self setOutputDestination: [_streamAddressField stringValue]];
554     [self updateOKButton];
557 - (IBAction)streamTypeToggle:(id)sender
559     NSUInteger index = [_streamTypePopup indexOfSelectedItem];
560     if (index <= 1) { // HTTP, MMSH
561         [_streamTTLField setEnabled:NO];
562         [_streamTTLStepper setEnabled:NO];
563         [_streamSAPCheckbox setEnabled:NO];
564         [_streamSDPMatrix setEnabled:NO];
565     } else if (index == 2) { // RTP
566         [_streamTTLField setEnabled:YES];
567         [_streamTTLStepper setEnabled:YES];
568         [_streamSAPCheckbox setEnabled:YES];
569         [_streamSDPMatrix setEnabled:YES];
570     } else { // UDP
571         [_streamTTLField setEnabled:YES];
572         [_streamTTLStepper setEnabled:YES];
573         [_streamSAPCheckbox setEnabled:YES];
574         [_streamSDPMatrix setEnabled:NO];
575     }
576     [self streamAnnouncementToggle:sender];
579 - (IBAction)streamAnnouncementToggle:(id)sender
581     [_streamChannelField setEnabled:[_streamSAPCheckbox state] && [_streamSAPCheckbox isEnabled]];
582     [_streamSDPField setEnabled:[_streamSDPMatrix isEnabled] && ([_streamSDPMatrix selectedCell] != [_streamSDPMatrix cellWithTag:0])];
584     if ([[_streamSDPMatrix selectedCell] tag] == 3)
585         [_streamSDPFileBrowseButton setEnabled: YES];
586     else
587         [_streamSDPFileBrowseButton setEnabled: NO];
590 - (IBAction)sdpFileLocationSelector:(id)sender
592     NSSavePanel * saveFilePanel = [NSSavePanel savePanel];
593     [saveFilePanel setCanSelectHiddenExtension: YES];
594     [saveFilePanel setCanCreateDirectories: YES];
595     [saveFilePanel setAllowedFileTypes:[NSArray arrayWithObject:@"sdp"]];
596     [saveFilePanel beginSheetModalForWindow:_streamPanel completionHandler:^(NSInteger returnCode) {
597         if (returnCode == NSOKButton)
598             [_streamSDPField setStringValue:[[saveFilePanel URL] path]];
599     }];
602 #pragma mark -
603 #pragma mark User interaction - misc
605 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
607     NSPasteboard *paste = [sender draggingPasteboard];
608     NSArray *types = [NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil];
609     NSString *desired_type = [paste availableTypeFromArray: types];
610     NSData *carried_data = [paste dataForType: desired_type];
612     if (carried_data) {
613         if ([desired_type isEqualToString:NSFilenamesPboardType]) {
614             NSArray *values = [[paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
616             if ([values count] > 0) {
617                 [self setMRL: toNSStr(vlc_path2uri([[values firstObject] UTF8String], NULL))];
618                 [self updateOKButton];
619                 [self updateDropView];
620                 return YES;
621             }
622         } else if ([desired_type isEqualToString:@"VLCPlaylistItemPboardType"]) {
623             NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
624             NSUInteger count = [array count];
625             if (count > 0) {
626                 playlist_t * p_playlist = pl_Get(getIntf());
627                 playlist_item_t * p_item = NULL;
629                 PL_LOCK;
630                 /* let's look for the first proper input item */
631                 for (NSUInteger x = 0; x < count; x++) {
632                     p_item = [[array objectAtIndex:x] pointerValue];
633                     if (p_item) {
634                         if (p_item->p_input) {
635                             if (p_item->p_input->psz_uri != nil) {
636                                 [self setMRL: toNSStr(p_item->p_input->psz_uri)];
637                                 [self updateDropView];
638                                 [self updateOKButton];
640                                 PL_UNLOCK;
642                                 return YES;
643                             }
644                         }
645                     }
646                 }
647                 PL_UNLOCK;
648             }
649         }
650     }
651     return NO;
654 # pragma mark -
655 # pragma mark Private Functionality
657 - (void)updateDropView
659     if ([_MRL length] > 0) {
660         NSString * path = [[NSURL URLWithString:_MRL] path];
661         [_dropinMediaLabel setStringValue: [[NSFileManager defaultManager] displayNameAtPath: path]];
662         NSImage * image = [[NSWorkspace sharedWorkspace] iconForFile: path];
663         [image setSize:NSMakeSize(128,128)];
664         [_dropinIcon setImage: image];
666         if (![_dropinView superview]) {
667             NSRect boxFrame = [_dropBox frame];
668             NSRect subViewFrame = [_dropinView frame];
669             subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2;
670             subViewFrame.origin.y = (boxFrame.size.height - subViewFrame.size.height) / 2;
671             [_dropinView setFrame: subViewFrame];
672             [[_dropImage animator] setHidden: YES];
673             [_dropBox performSelector:@selector(addSubview:) withObject:_dropinView afterDelay:0.6];
674         }
675     } else {
676         [_dropinView removeFromSuperview];
677         [[_dropImage animator] setHidden: NO];
678     }
681 - (void)updateOKButton
683     if ([_outputDestination length] > 0 && [_MRL length] > 0)
684         [_okButton setEnabled: YES];
685     else
686         [_okButton setEnabled: NO];
689 - (void)resetCustomizationSheetBasedOnProfile:(NSString *)profileString
691     /* Container(string), transcode video(bool), transcode audio(bool),
692     * use subtitles(bool), video codec(string), video bitrate(integer),
693     * scale(float), fps(float), width(integer, height(integer),
694     * audio codec(string), audio bitrate(integer), channels(integer),
695     * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */
697     NSArray * components = [profileString componentsSeparatedByString:@";"];
698     if ([components count] != 16) {
699         msg_Err(getIntf(), "CAS: the requested profile '%s' is invalid", [profileString UTF8String]);
700         return;
701     }
703     [self selectCellByEncapsulationFormat:[components firstObject]];
704     [_customizeVidCheckbox setState:[[components objectAtIndex:1] intValue]];
705     [_customizeAudCheckbox setState:[[components objectAtIndex:2] intValue]];
706     [_customizeSubsCheckbox setState:[[components objectAtIndex:3] intValue]];
707     [self setVidBitrate:[[components objectAtIndex:5] intValue]];
708     [_customizeVidScalePopup selectItemWithTitle:[components objectAtIndex:6]];
709     [self setVidFramerate:[[components objectAtIndex:7] intValue]];
710     [_customizeVidWidthField setStringValue:[components objectAtIndex:8]];
711     [_customizeVidHeightField setStringValue:[components objectAtIndex:9]];
712     [self setAudBitrate:[[components objectAtIndex:11] intValue]];
713     [self setAudChannels:[[components objectAtIndex:12] intValue]];
714     [_customizeAudSampleratePopup selectItemWithTitle:[components objectAtIndex:13]];
715     [_customizeSubsOverlayCheckbox setState:[[components objectAtIndex:15] intValue]];
717     /* since there is no proper lookup mechanism in arrays, we need to implement a string specific one ourselves */
718     NSArray * tempArray = [_videoCodecs objectAtIndex:1];
719     NSUInteger count = [tempArray count];
720     NSString * searchString = [components objectAtIndex:4];
721     int videoKeep = [searchString isEqualToString:@"copy"];
722     [_customizeVidKeepCheckbox setState:videoKeep];
723     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"] || videoKeep) {
724         [_customizeVidCodecPopup selectItemAtIndex:-1];
725     } else {
726         for (NSUInteger x = 0; x < count; x++) {
727             if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
728                 [_customizeVidCodecPopup selectItemAtIndex:x];
729                 break;
730             }
731         }
732     }
734     tempArray = [_audioCodecs objectAtIndex:1];
735     count = [tempArray count];
736     searchString = [components objectAtIndex:10];
737     int audioKeep = [searchString isEqualToString:@"copy"];
738     [_customizeAudKeepCheckbox setState:audioKeep];
739     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"] || audioKeep) {
740         [_customizeAudCodecPopup selectItemAtIndex:-1];
741     } else {
742         for (NSUInteger x = 0; x < count; x++) {
743             if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
744                 [_customizeAudCodecPopup selectItemAtIndex:x];
745                 break;
746             }
747         }
748     }
750     tempArray = [_subsCodecs objectAtIndex:1];
751     count = [tempArray count];
752     searchString = [components objectAtIndex:14];
753     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"]) {
754         [_customizeSubsPopup selectItemAtIndex:-1];
755     } else {
756         for (NSUInteger x = 0; x < count; x++) {
757             if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
758                 [_customizeSubsPopup selectItemAtIndex:x];
759                 break;
760             }
761         }
762     }
764     [self videoSettingsChanged:nil];
765     [self audioSettingsChanged:nil];
766     [self subSettingsChanged:nil];
768     [self setCurrentProfile: [[NSMutableArray alloc] initWithArray:[profileString componentsSeparatedByString:@";"]]];
771 - (void)selectCellByEncapsulationFormat:(NSString *)format
773     if ([format isEqualToString:@"ts"])
774         [_customizeEncapMatrix selectCellWithTag:MPEGTS];
775     else if ([format isEqualToString:@"webm"])
776         [_customizeEncapMatrix selectCellWithTag:WEBM];
777     else if ([format isEqualToString:@"ogg"])
778         [_customizeEncapMatrix selectCellWithTag:OGG];
779     else if ([format isEqualToString:@"ogm"])
780         [_customizeEncapMatrix selectCellWithTag:OGG];
781     else if ([format isEqualToString:@"mp4"])
782         [_customizeEncapMatrix selectCellWithTag:MP4];
783     else if ([format isEqualToString:@"mov"])
784         [_customizeEncapMatrix selectCellWithTag:MP4];
785     else if ([format isEqualToString:@"ps"])
786         [_customizeEncapMatrix selectCellWithTag:MPEGPS];
787     else if ([format isEqualToString:@"mpjpeg"])
788         [_customizeEncapMatrix selectCellWithTag:MJPEG];
789     else if ([format isEqualToString:@"wav"])
790         [_customizeEncapMatrix selectCellWithTag:WAV];
791     else if ([format isEqualToString:@"flv"])
792         [_customizeEncapMatrix selectCellWithTag:FLV];
793     else if ([format isEqualToString:@"mpeg1"])
794         [_customizeEncapMatrix selectCellWithTag:MPEG1];
795     else if ([format isEqualToString:@"mkv"])
796         [_customizeEncapMatrix selectCellWithTag:MKV];
797     else if ([format isEqualToString:@"raw"])
798         [_customizeEncapMatrix selectCellWithTag:RAW];
799     else if ([format isEqualToString:@"avi"])
800         [_customizeEncapMatrix selectCellWithTag:AVI];
801     else if ([format isEqualToString:@"asf"])
802         [_customizeEncapMatrix selectCellWithTag:ASF];
803     else if ([format isEqualToString:@"wmv"])
804         [_customizeEncapMatrix selectCellWithTag:ASF];
805     else
806         msg_Err(getIntf(), "CAS: unknown encap format requested for customization");
809 - (NSString *)currentEncapsulationFormatAsFileExtension:(BOOL)b_extension
811     NSUInteger cellTag = (NSUInteger) [[_customizeEncapMatrix selectedCell] tag];
812     NSString * returnValue;
813     switch (cellTag) {
814         case MPEGTS:
815             returnValue = @"ts";
816             break;
817         case WEBM:
818             returnValue = @"webm";
819             break;
820         case OGG:
821             returnValue = @"ogg";
822             break;
823         case MP4:
824         {
825             if (b_extension)
826                 returnValue = @"m4v";
827             else
828                 returnValue = @"mp4";
829             break;
830         }
831         case MPEGPS:
832         {
833             if (b_extension)
834                 returnValue = @"mpg";
835             else
836                 returnValue = @"ps";
837             break;
838         }
839         case MJPEG:
840             returnValue = @"mjpeg";
841             break;
842         case WAV:
843             returnValue = @"wav";
844             break;
845         case FLV:
846             returnValue = @"flv";
847             break;
848         case MPEG1:
849         {
850             if (b_extension)
851                 returnValue = @"mpg";
852             else
853                 returnValue = @"mpeg1";
854             break;
855         }
856         case MKV:
857             returnValue = @"mkv";
858             break;
859         case RAW:
860             returnValue = @"raw";
861             break;
862         case AVI:
863             returnValue = @"avi";
864             break;
865         case ASF:
866             returnValue = @"asf";
867             break;
869         default:
870             returnValue = @"none";
871             break;
872     }
874     return returnValue;
877 - (NSString *)composedOptions
879     NSMutableString *composedOptions = [[NSMutableString alloc] initWithString:@":sout=#transcode{"];
880     BOOL haveVideo = YES;
881     if ([[self.currentProfile objectAtIndex:1] intValue]) {
882         // video is enabled
883         if (![[self.currentProfile objectAtIndex:4] isEqualToString:@"copy"]) {
884         [composedOptions appendFormat:@"vcodec=%@", [self.currentProfile objectAtIndex:4]];
885             if ([[self.currentProfile objectAtIndex:5] intValue] > 0) // bitrate
886                 [composedOptions appendFormat:@",vb=%@", [self.currentProfile objectAtIndex:5]];
887             if ([[self.currentProfile objectAtIndex:6] floatValue] > 0.) // scale
888                 [composedOptions appendFormat:@",scale=%@", [self.currentProfile objectAtIndex:6]];
889             if ([[self.currentProfile objectAtIndex:7] floatValue] > 0.) // fps
890                 [composedOptions appendFormat:@",fps=%@", [self.currentProfile objectAtIndex:7]];
891             if ([[self.currentProfile objectAtIndex:8] intValue] > 0) // width
892                 [composedOptions appendFormat:@",width=%@", [self.currentProfile objectAtIndex:8]];
893             if ([[self.currentProfile objectAtIndex:9] intValue] > 0) // height
894                 [composedOptions appendFormat:@",height=%@", [self.currentProfile objectAtIndex:9]];
895         } else {
896             haveVideo = NO;
897         }
898     } else {
899         [composedOptions appendString:@"vcodec=none"];
900     }
902     BOOL haveAudio = YES;
903     if ([[self.currentProfile objectAtIndex:2] intValue]) {
904         // audio is enabled
905         if (![[self.currentProfile objectAtIndex:10] isEqualToString:@"copy"]) {
906             if(haveVideo)
907                 [composedOptions appendString:@","];
908             [composedOptions appendFormat:@"acodec=%@", [self.currentProfile objectAtIndex:10]];
909             [composedOptions appendFormat:@",ab=%@", [self.currentProfile objectAtIndex:11]]; // bitrate
910             [composedOptions appendFormat:@",channels=%@", [self.currentProfile objectAtIndex:12]]; // channel number
911             [composedOptions appendFormat:@",samplerate=%@", [self.currentProfile objectAtIndex:13]]; // sample rate
912         } else {
913             haveAudio = NO;
914         }
915     } else {
916         if(haveVideo)
917             [composedOptions appendString:@","];
919         [composedOptions appendString:@"acodec=none"];
920     }
921     if ([self.currentProfile objectAtIndex:3]) {
922         if(haveVideo || haveAudio)
923             [composedOptions appendString:@","];
924         // subtitles enabled
925         [composedOptions appendFormat:@"scodec=%@", [self.currentProfile objectAtIndex:14]];
926         if ([[self.currentProfile objectAtIndex:15] intValue])
927             [composedOptions appendFormat:@",soverlay"];
928     }
930     if (!b_streaming) {
931         /* file transcoding */
932         // add muxer
933         [composedOptions appendFormat:@"}:standard{mux=%@", [self.currentProfile firstObject]];
936         // add output destination
937         [composedOptions appendFormat:@",access=file{no-overwrite},dst=%@}", _outputDestination];
938     } else {
939         /* streaming */
940         if ([[[_streamTypePopup selectedItem] title] isEqualToString:@"RTP"])
941             [composedOptions appendFormat:@":rtp{mux=ts,dst=%@,port=%@", _outputDestination, [_streamPortField stringValue]];
942         else if ([[[_streamTypePopup selectedItem] title] isEqualToString:@"UDP"])
943             [composedOptions appendFormat:@":standard{mux=ts,dst=%@,port=%@,access=udp", _outputDestination, [_streamPortField stringValue]];
944         else if ([[[_streamTypePopup selectedItem] title] isEqualToString:@"MMSH"])
945             [composedOptions appendFormat:@":standard{mux=asfh,dst=%@,port=%@,access=mmsh", _outputDestination, [_streamPortField stringValue]];
946         else
947             [composedOptions appendFormat:@":standard{mux=%@,dst=%@,port=%@,access=http", [self.currentProfile firstObject], [_streamPortField stringValue], _outputDestination];
949         if ([_streamSAPCheckbox state])
950             [composedOptions appendFormat:@",sap,name=\"%@\"", [_streamChannelField stringValue]];
951         if ([_streamSDPMatrix selectedCell] != [_streamSDPMatrix cellWithTag:0]) {
952             NSInteger tag = [[_streamSDPMatrix selectedCell] tag];
953             switch (tag) {
954                 case 1:
955                     [composedOptions appendFormat:@",sdp=\"http://%@\"", [_streamSDPField stringValue]];
956                     break;
957                 case 2:
958                     [composedOptions appendFormat:@",sdp=\"rtsp://%@\"", [_streamSDPField stringValue]];
959                     break;
960                 case 3:
961                     [composedOptions appendFormat:@",sdp=\"file://%s\"", vlc_path2uri([[_streamSDPField stringValue] UTF8String], NULL)];
962                 default:
963                     break;
964             }
965         }
967         [composedOptions appendString:@"} :sout-keep"];
968     }
970     return [NSString stringWithString:composedOptions];
973 - (void)updateCurrentProfile
975     [self.currentProfile removeAllObjects];
977     NSInteger i;
978     [self.currentProfile addObject: [self currentEncapsulationFormatAsFileExtension:NO]];
979     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customizeVidCheckbox state]]];
980     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customizeAudCheckbox state]]];
981     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customizeSubsCheckbox state]]];
982     
983     NSString *videoCodec;
984     if([_customizeVidKeepCheckbox state] == NSOnState)
985         videoCodec = @"copy";
986     else {
987         i = [_customizeVidCodecPopup indexOfSelectedItem];
988         if (i >= 0)
989             videoCodec = [[_videoCodecs objectAtIndex:1] objectAtIndex:i];
990         else
991             videoCodec = @"none";
992     }
993     [self.currentProfile addObject: videoCodec];
995     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self vidBitrate]]];
996     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [[[_customizeVidScalePopup selectedItem] title] intValue]]];
997     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self vidFramerate]]];
998     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customizeVidWidthField intValue]]];
999     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customizeVidHeightField intValue]]];
1001     NSString *audioCodec;
1002     if([_customizeAudKeepCheckbox state] == NSOnState)
1003         audioCodec = @"copy";
1004     else {
1005         i = [_customizeAudCodecPopup indexOfSelectedItem];
1006         if (i >= 0)
1007             audioCodec = [[_audioCodecs objectAtIndex:1] objectAtIndex:i];
1008         else
1009             audioCodec = @"none";
1010     }
1011     [self.currentProfile addObject: audioCodec];
1012     
1013     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self audBitrate]]];
1014     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self audChannels]]];
1015     [self.currentProfile addObject: [[_customizeAudSampleratePopup selectedItem] title]];
1016     i = [_customizeSubsPopup indexOfSelectedItem];
1017     if (i >= 0)
1018         [self.currentProfile addObject: [[_subsCodecs objectAtIndex:1] objectAtIndex:i]];
1019     else
1020         [self.currentProfile addObject: @"none"];
1021     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customizeSubsOverlayCheckbox state]]];
1024 - (void)storeProfilesOnDisk
1026     NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
1027     [defaults setObject:_profileNames forKey:@"CASProfileNames"];
1028     [defaults setObject:_profileValueList forKey:@"CASProfiles"];
1029     [defaults synchronize];
1032 - (void)recreateProfilePopup
1034     [_profilePopup removeAllItems];
1035     [_profilePopup addItemsWithTitles:self.profileNames];
1036     [_profilePopup addItemWithTitle:_NS("Custom")];
1037     [[_profilePopup menu] addItem:[NSMenuItem separatorItem]];
1038     [_profilePopup addItemWithTitle:_NS("Organize Profiles...")];
1039     [[_profilePopup lastItem] setTarget: self];
1040     [[_profilePopup lastItem] setAction: @selector(deleteProfileAction:)];
1043 - (IBAction)customizeSubsCheckbox:(id)sender {
1045 @end