1 /*****************************************************************************
2 * open.m: Open dialogues for VLC's MacOS X port
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <thedj@users.sourceforge.net>
10 * Benjamin Pracht <bigben at videolan dot org>
11 * Felix Paul Kühne <fkuehne at videolan dot org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #include <stdlib.h> /* malloc(), free() */
32 #include <sys/param.h> /* for MAXPATHLEN */
36 #include <IOKit/IOKitLib.h>
37 #include <IOKit/IOBSD.h>
38 #include <IOKit/storage/IOMedia.h>
39 #include <IOKit/storage/IOCDMedia.h>
40 #include <IOKit/storage/IODVDMedia.h>
48 #define setEyeTVUnconnected \
49 [o_capture_lbl setStringValue: _NS("No device connected")]; \
50 [o_capture_long_lbl setStringValue: _NS("VLC could not detect any EyeTV compatible device.\n\nCheck the device's connection, make sure that the latest EyeTV software is installed and try again.")]; \
51 [o_capture_lbl displayIfNeeded]; \
52 [o_capture_long_lbl displayIfNeeded]; \
53 [self showCaptureView: o_capture_label_view]
56 /*****************************************************************************
57 * GetEjectableMediaOfClass
58 *****************************************************************************/
59 NSArray *GetEjectableMediaOfClass( const char *psz_class )
61 io_object_t next_media;
62 mach_port_t master_port;
63 kern_return_t kern_result;
64 NSArray *o_devices = nil;
65 NSMutableArray *p_list = nil;
66 io_iterator_t media_iterator;
67 CFMutableDictionaryRef classes_to_match;
69 kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
70 if( kern_result != KERN_SUCCESS )
75 classes_to_match = IOServiceMatching( psz_class );
76 if( classes_to_match == NULL )
81 CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectableKey ),
84 kern_result = IOServiceGetMatchingServices( master_port, classes_to_match,
86 if( kern_result != KERN_SUCCESS )
91 p_list = [NSMutableArray arrayWithCapacity: 1];
93 next_media = IOIteratorNext( media_iterator );
97 size_t dev_path_length;
98 CFTypeRef str_bsd_path;
102 str_bsd_path = IORegistryEntryCreateCFProperty( next_media,
103 CFSTR( kIOBSDNameKey ),
106 if( str_bsd_path == NULL )
108 IOObjectRelease( next_media );
112 snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' );
113 dev_path_length = strlen( psz_buf );
115 if( CFStringGetCString( str_bsd_path,
116 (char*)&psz_buf + dev_path_length,
117 sizeof(psz_buf) - dev_path_length,
118 kCFStringEncodingASCII ) )
120 [p_list addObject: [NSString stringWithUTF8String: psz_buf]];
123 CFRelease( str_bsd_path );
125 IOObjectRelease( next_media );
127 } while( ( next_media = IOIteratorNext( media_iterator ) ) );
130 IOObjectRelease( media_iterator );
132 o_devices = [NSArray arrayWithArray: p_list];
137 /*****************************************************************************
138 * VLCOpen implementation
139 *****************************************************************************/
140 @implementation VLCOpen
142 static VLCOpen *_o_sharedMainInstance = nil;
144 + (VLCOpen *)sharedInstance
146 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
151 if( _o_sharedMainInstance) {
154 _o_sharedMainInstance = [super init];
158 return _o_sharedMainInstance;
163 [o_panel setTitle: _NS("Open Source")];
164 [o_mrl_lbl setTitle: _NS("Media Resource Locator (MRL)")];
166 [o_btn_ok setTitle: _NS("Open")];
167 [o_btn_cancel setTitle: _NS("Cancel")];
169 [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
170 [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
171 [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
172 [[o_tabview tabViewItemAtIndex: 3] setLabel: _NS("Capture")];
174 [o_file_btn_browse setTitle: _NS("Browse...")];
175 [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
177 [o_disc_device_lbl setStringValue: _NS("Device name")];
178 [o_disc_title_lbl setStringValue: _NS("Title")];
179 [o_disc_chapter_lbl setStringValue: _NS("Chapter")];
180 [o_disc_videots_btn_browse setTitle: _NS("Browse...")];
181 [o_disc_dvd_menus setTitle: _NS("No DVD menus")];
183 [[o_disc_type cellAtRow:0 column:0] setTitle: _NS("VIDEO_TS folder")];
184 [[o_disc_type cellAtRow:1 column:0] setTitle: _NS("DVD")];
185 [[o_disc_type cellAtRow:2 column:0] setTitle: _NS("VCD")];
186 [[o_disc_type cellAtRow:3 column:0] setTitle: _NS("Audio CD")];
188 [o_net_udp_port_lbl setStringValue: _NS("Port")];
189 [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
190 [o_net_udpm_port_lbl setStringValue: _NS("Port")];
191 [o_net_http_url_lbl setStringValue: _NS("URL")];
192 [o_net_help_lbl setStringValue: _NS("To Open a usual network stream (HTTP, RTSP, MMS, FTP, etc.), just enter the URL in the field above. If you want to open a RTP or UDP stream, press the button below.")];
193 [o_net_help_udp_lbl setStringValue: _NS("If you want to open a multicast stream, enter the respective IP address given by the stream provider. In unicast mode, VLC use your machine's IP automatically.\n\nTo open a stream using a different protocol, just press Cancel to close this sheet.")];
194 [o_net_udp_cancel_btn setTitle: _NS("Cancel")];
195 [o_net_udp_ok_btn setTitle: _NS("Open")];
196 [o_net_openUDP_btn setTitle: _NS("Open RTP/UDP Stream")];
198 [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("UDP/RTP")];
199 [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("UDP/RTP Multicast")];
201 [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
202 [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
204 [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
206 [o_capture_mode_pop removeAllItems];
207 [o_capture_mode_pop addItemWithTitle: @"iSight"];
208 [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
209 [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
210 [o_screen_lbl setStringValue: _NS("Screen Capture Input")];
211 [o_screen_long_lbl setStringValue: _NS("This facility allows you to process your screen's output.")];
212 [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
213 [o_screen_left_lbl setStringValue: _NS("Subscreen left:")];
214 [o_screen_top_lbl setStringValue: _NS("Subscreen top:")];
215 [o_screen_width_lbl setStringValue: _NS("Subscreen width:")];
216 [o_screen_height_lbl setStringValue: _NS("Subscreen height:")];
217 [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
218 [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
219 [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
220 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
221 [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
222 [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
223 [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
224 [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
228 [[NSNotificationCenter defaultCenter] addObserver: self
229 selector: @selector(openFilePathChanged:)
230 name: NSControlTextDidChangeNotification
231 object: o_file_path];
233 [[NSNotificationCenter defaultCenter] addObserver: self
234 selector: @selector(openDiscInfoChanged:)
235 name: NSControlTextDidChangeNotification
236 object: o_disc_device];
237 [[NSNotificationCenter defaultCenter] addObserver: self
238 selector: @selector(openDiscInfoChanged:)
239 name: NSControlTextDidChangeNotification
240 object: o_disc_title];
241 [[NSNotificationCenter defaultCenter] addObserver: self
242 selector: @selector(openDiscInfoChanged:)
243 name: NSControlTextDidChangeNotification
244 object: o_disc_chapter];
245 [[NSNotificationCenter defaultCenter] addObserver: self
246 selector: @selector(openDiscInfoChanged:)
247 name: NSControlTextDidChangeNotification
248 object: o_disc_videots_folder];
250 [[NSNotificationCenter defaultCenter] addObserver: self
251 selector: @selector(openNetInfoChanged:)
252 name: NSControlTextDidChangeNotification
253 object: o_net_udp_port];
254 [[NSNotificationCenter defaultCenter] addObserver: self
255 selector: @selector(openNetInfoChanged:)
256 name: NSControlTextDidChangeNotification
257 object: o_net_udpm_addr];
258 [[NSNotificationCenter defaultCenter] addObserver: self
259 selector: @selector(openNetInfoChanged:)
260 name: NSControlTextDidChangeNotification
261 object: o_net_udpm_port];
262 [[NSNotificationCenter defaultCenter] addObserver: self
263 selector: @selector(openNetInfoChanged:)
264 name: NSControlTextDidChangeNotification
265 object: o_net_http_url];
267 [[NSDistributedNotificationCenter defaultCenter] addObserver: self
268 selector: @selector(eyetvChanged:)
270 object: @"VLCEyeTVSupport"
271 suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
273 [[NSNotificationCenter defaultCenter] addObserver: self
274 selector: @selector(screenFPSfieldChanged:)
275 name: NSControlTextDidChangeNotification
276 object: o_screen_fps_fld];
278 /* register clicks on text fields */
279 [[NSNotificationCenter defaultCenter] addObserver: self
280 selector: @selector(textFieldWasClicked:)
281 name: @"VLCOpenTextFieldWasClicked"
288 module_config_t * p_item;
290 [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
291 [o_file_sub_btn_settings setTitle: _NS("Settings...")];
292 [o_file_sub_btn_browse setTitle: _NS("Browse...")];
293 [o_file_sub_override setTitle: _NS("Override parametters")];
294 [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
295 [o_file_sub_delay_stp setEnabled: NO];
296 [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
297 [o_file_sub_fps_stp setEnabled: NO];
298 [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
299 [o_file_sub_encoding_pop removeAllItems];
300 [o_file_sub_size_lbl setStringValue: _NS("Font size")];
301 [o_file_sub_size_pop removeAllItems];
302 [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
303 [o_file_sub_align_pop removeAllItems];
304 [o_file_sub_ok_btn setStringValue: _NS("OK")];
305 [o_file_sub_font_box setTitle: _NS("Font Properties")];
306 [o_file_sub_file_box setTitle: _NS("Subtitle File")];
308 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
312 for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
315 [o_file_sub_encoding_pop addItemWithTitle:
316 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
318 [o_file_sub_encoding_pop selectItemWithTitle:
319 [NSString stringWithUTF8String: p_item->value.psz]];
322 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
326 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
328 [o_file_sub_align_pop addItemWithTitle:
329 [NSString stringWithUTF8String:
330 p_item->ppsz_list_text[i_index]]];
332 [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
335 p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
339 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
341 [o_file_sub_size_pop addItemWithTitle:
342 [NSString stringWithUTF8String:
343 p_item->ppsz_list_text[i_index]]];
344 if ( p_item->value.i == p_item->pi_list[i_index] )
346 [o_file_sub_size_pop selectItemAtIndex: i_index];
352 - (void)openTarget:(int)i_type
356 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
358 [o_tabview selectTabViewItemAtIndex: i_type];
359 [o_file_sub_ckbox setState: NSOffState];
361 i_result = [NSApp runModalForWindow: o_panel];
366 NSMutableDictionary *o_dic;
367 NSMutableArray *o_options = [NSMutableArray array];
370 o_dic = [NSMutableDictionary dictionaryWithObject: [o_mrl stringValue] forKey: @"ITEM_URL"];
371 if( [o_file_sub_ckbox state] == NSOnState )
373 module_config_t * p_item;
375 [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", [o_file_sub_path stringValue]]];
376 if( [o_file_sub_override state] == NSOnState )
378 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
379 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
381 [o_options addObject: [NSString stringWithFormat:
382 @"subsdec-encoding=%@",
383 [o_file_sub_encoding_pop titleOfSelectedItem]]];
384 [o_options addObject: [NSString stringWithFormat:
386 [o_file_sub_align_pop indexOfSelectedItem]]];
388 p_item = config_FindConfig( VLC_OBJECT(p_intf),
389 "freetype-rel-fontsize" );
393 [o_options addObject: [NSString stringWithFormat:
394 @"freetype-rel-fontsize=%i",
395 p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
398 if( [o_output_ckbox state] == NSOnState )
400 for (i = 0 ; i < [[o_sout_options getMRL] count] ; i++)
402 [o_options addObject: [NSString stringWithString:
403 [[(VLCOutput *)o_sout_options getMRL] objectAtIndex: i]]];
406 if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
408 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
409 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
410 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
411 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
412 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
413 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
414 if( [o_screen_follow_mouse_ckb intValue] == YES )
415 [o_options addObject: @"screen-follow-mouse"];
417 [o_options addObject: @"no-screen-follow-mouse"];
420 /* apply the options to our item(s) */
421 [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
423 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
425 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
429 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
431 NSString *o_label = [o_tvi label];
433 if( [o_label isEqualToString: _NS("File")] )
435 [self openFilePathChanged: nil];
437 else if( [o_label isEqualToString: _NS("Disc")] )
439 [self openDiscTypeChanged: nil];
441 else if( [o_label isEqualToString: _NS("Network")] )
443 [self openNetInfoChanged: nil];
445 else if( [o_label isEqualToString: _NS("Capture")] )
447 [self openCaptureModeChanged: nil];
451 - (void)openFileGeneric
453 [self openFilePathChanged: nil];
454 [self openTarget: 0];
459 [self openDiscTypeChanged: nil];
460 [self openTarget: 1];
465 [self openNetInfoChanged: nil];
466 [self openTarget: 2];
471 [self openCaptureModeChanged: nil];
472 [self showCaptureView: o_capture_label_view];
473 [self openTarget: 3];
476 - (void)openFilePathChanged:(NSNotification *)o_notification
478 NSString *o_mrl_string;
479 NSString *o_filename = [o_file_path stringValue];
480 NSString *o_ext = [o_filename pathExtension];
481 bool b_stream = [o_file_stream state];
484 [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
488 o_mrl_string = [NSString stringWithFormat: @"directory://%@/", o_filename];
490 else if( [o_ext isEqualToString: @"bin"] ||
491 [o_ext isEqualToString: @"cue"] ||
492 [o_ext isEqualToString: @"vob"] ||
493 [o_ext isEqualToString: @"iso"] )
495 o_mrl_string = o_filename;
499 o_mrl_string = [NSString stringWithFormat: @"%s://%@",
500 b_stream ? "stream" : "file",
503 [o_mrl setStringValue: o_mrl_string];
506 - (IBAction)openFileBrowse:(id)sender
508 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
510 [o_open_panel setAllowsMultipleSelection: NO];
511 [o_open_panel setCanChooseDirectories: YES];
512 [o_open_panel setTitle: _NS("Open File")];
513 [o_open_panel setPrompt: _NS("Open")];
515 [o_open_panel beginSheetForDirectory:nil
518 modalForWindow:[sender window]
520 didEndSelector: @selector(pathChosenInPanel:
526 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void *)contextInfo
528 if (returnCode == NSFileHandlingPanelOKButton)
530 NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
531 [o_file_path setStringValue: o_filename];
532 [self openFilePathChanged: nil];
536 - (IBAction)openFileStreamChanged:(id)sender
538 [self openFilePathChanged: nil];
541 - (IBAction)openDiscTypeChanged:(id)sender
544 BOOL b_device, b_no_menus, b_title_chapter;
546 [o_disc_device removeAllItems];
547 b_title_chapter = ![o_disc_dvd_menus state];
549 o_type = [[o_disc_type selectedCell] title];
551 if ( [o_type isEqualToString: _NS("VIDEO_TS directory")] )
553 b_device = NO; b_no_menus = YES;
559 const char *psz_class = NULL;
562 if ( [o_type isEqualToString: _NS("VCD")] )
564 psz_class = kIOCDMediaClass;
566 b_no_menus = NO; b_title_chapter = YES;
568 else if ( [o_type isEqualToString: _NS("Audio CD")])
570 psz_class = kIOCDMediaClass;
572 b_no_menus = NO; b_title_chapter = NO;
576 psz_class = kIODVDMediaClass;
581 o_devices = GetEjectableMediaOfClass( psz_class );
582 if ( o_devices != nil )
584 int i_devices = [o_devices count];
588 for( int i = 0; i < i_devices; i++ )
591 addItemWithObjectValue: [o_devices objectAtIndex: i]];
594 [o_disc_device selectItemAtIndex: 0];
598 [o_disc_device setStringValue:
599 [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
604 [o_disc_device setEnabled: b_device];
605 [o_disc_title setEnabled: b_title_chapter];
606 [o_disc_title_stp setEnabled: b_title_chapter];
607 [o_disc_chapter setEnabled: b_title_chapter];
608 [o_disc_chapter_stp setEnabled: b_title_chapter];
609 [o_disc_videots_folder setEnabled: !b_device];
610 [o_disc_videots_btn_browse setEnabled: !b_device];
611 [o_disc_dvd_menus setEnabled: b_no_menus];
613 [self openDiscInfoChanged: nil];
616 - (IBAction)openDiscStepperChanged:(id)sender
618 int i_tag = [sender tag];
622 [o_disc_title setIntValue: [o_disc_title_stp intValue]];
624 else if( i_tag == 1 )
626 [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
629 [self openDiscInfoChanged: nil];
632 - (void)openDiscInfoChanged:(NSNotification *)o_notification
637 NSString *o_mrl_string;
638 int i_title, i_chapter;
641 o_type = [[o_disc_type selectedCell] title];
642 o_device = [o_disc_device stringValue];
643 i_title = [o_disc_title intValue];
644 i_chapter = [o_disc_chapter intValue];
645 o_videots = [o_disc_videots_folder stringValue];
646 b_no_menus = [o_disc_dvd_menus state];
648 if ( [o_type isEqualToString: _NS("VCD")] )
650 if ( [o_device isEqualToString:
651 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
653 o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i:%i",
654 o_device, i_title, i_chapter];
656 else if ( [o_type isEqualToString: _NS("Audio CD")] )
658 if ( [o_device isEqualToString:
659 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
661 o_mrl_string = [NSString stringWithFormat: @"cdda://%@",
664 else if ( [o_type isEqualToString: _NS("DVD")] )
666 if ( [o_device isEqualToString:
667 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
670 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i-",
671 o_device, i_title, i_chapter];
673 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
677 else /* VIDEO_TS folder */
680 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
681 o_videots, i_title, i_chapter];
683 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
687 [o_mrl setStringValue: o_mrl_string];
690 - (IBAction)openDiscMenusChanged:(id)sender
692 [self openDiscInfoChanged: nil];
693 [self openDiscTypeChanged: nil];
696 - (IBAction)openVTSBrowse:(id)sender
698 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
700 [o_open_panel setAllowsMultipleSelection: NO];
701 [o_open_panel setCanChooseFiles: NO];
702 [o_open_panel setCanChooseDirectories: YES];
703 [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
704 [o_open_panel setPrompt: _NS("Open")];
706 if( [o_open_panel runModalForDirectory: nil
707 file: nil types: nil] == NSOKButton )
709 NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
710 [o_disc_videots_folder setStringValue: o_dirname];
711 [self openDiscInfoChanged: nil];
715 - (void)textFieldWasClicked:(NSNotification *)o_notification
717 if( [o_notification object] == o_net_udp_port )
718 [o_net_mode selectCellAtRow: 0 column: 0];
719 else if( [o_notification object] == o_net_udpm_addr ||
720 [o_notification object] == o_net_udpm_port )
721 [o_net_mode selectCellAtRow: 1 column: 0];
723 [o_net_mode selectCellAtRow: 2 column: 0];
725 [self openNetInfoChanged: nil];
728 - (IBAction)openNetModeChanged:(id)sender
730 if( [[sender selectedCell] tag] == 0 )
731 [o_panel makeFirstResponder: o_net_udp_port];
732 else if ( [[sender selectedCell] tag] == 1 )
733 [o_panel makeFirstResponder: o_net_udpm_addr];
735 msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
738 [self openNetInfoChanged: nil];
741 - (IBAction)openNetStepperChanged:(id)sender
743 int i_tag = [sender tag];
747 [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
748 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
749 object: o_net_udp_port];
750 [o_panel makeFirstResponder: o_net_udp_port];
752 else if( i_tag == 1 )
754 [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
755 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
756 object: o_net_udpm_port];
757 [o_panel makeFirstResponder: o_net_udpm_port];
760 [self openNetInfoChanged: nil];
763 - (void)openNetInfoChanged:(NSNotification *)o_notification
765 NSString *o_mrl_string = [NSString string];
767 if( [o_net_udp_panel isVisible] )
770 o_mode = [[o_net_mode selectedCell] title];
772 if( [o_mode isEqualToString: _NS("UDP/RTP")] )
774 int i_port = [o_net_udp_port intValue];
776 o_mrl_string = [NSString stringWithString: @"udp://"];
778 if( i_port != config_GetInt( p_intf, "server-port" ) )
781 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
784 else if( [o_mode isEqualToString: _NS("UDP/RTP Multicast")] )
786 NSString *o_addr = [o_net_udpm_addr stringValue];
787 int i_port = [o_net_udpm_port intValue];
789 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
791 if( i_port != config_GetInt( p_intf, "server-port" ) )
794 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
800 NSString *o_url = [o_net_http_url stringValue];
802 if ( ![o_url hasPrefix:@"http:"] && ![o_url hasPrefix:@"ftp:"]
803 && ![o_url hasPrefix:@"mms"] && ![o_url hasPrefix:@"rtsp"] )
804 o_mrl_string = [NSString stringWithFormat: @"http://%@", o_url];
806 o_mrl_string = o_url;
808 [o_mrl setStringValue: o_mrl_string];
811 - (IBAction)openNetUDPButtonAction:(id)sender
813 if( sender == o_net_openUDP_btn )
815 [NSApp beginSheet: o_net_udp_panel
816 modalForWindow: o_panel
821 else if( sender == o_net_udp_cancel_btn )
823 [o_net_udp_panel orderOut: sender];
824 [NSApp endSheet: o_net_udp_panel];
826 else if( sender == o_net_udp_ok_btn )
828 NSString *o_mrl_string = [NSString string];
829 if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("UDP/RTP")] )
831 int i_port = [o_net_udp_port intValue];
833 o_mrl_string = [NSString stringWithString: @"udp://"];
835 if( i_port != config_GetInt( p_intf, "server-port" ) )
838 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
841 else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("UDP/RTP Multicast")] )
843 NSString *o_addr = [o_net_udpm_addr stringValue];
844 int i_port = [o_net_udpm_port intValue];
846 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
848 if( i_port != config_GetInt( p_intf, "server-port" ) )
851 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
854 [o_mrl setStringValue: o_mrl_string];
855 [o_net_udp_panel orderOut: sender];
856 [NSApp endSheet: o_net_udp_panel];
862 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
864 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
866 [o_open_panel setAllowsMultipleSelection: YES];
867 [o_open_panel setCanChooseDirectories: YES];
868 [o_open_panel setTitle: _NS("Open File")];
869 [o_open_panel setPrompt: _NS("Open")];
871 if( [o_open_panel runModalForDirectory: nil
872 file: nil types: nil] == NSOKButton )
874 NSArray *o_array = [NSArray array];
875 NSArray *o_values = [[o_open_panel filenames]
876 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
878 for( i = 0; i < (int)[o_values count]; i++)
881 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
882 o_array = [o_array arrayByAddingObject: o_dic];
885 [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
887 [o_playlist appendArray: o_array atPos: -1 enqueue:YES];
891 - (void)showCaptureView: theView
894 o_view_rect = [theView frame];
895 if( o_currentCaptureView )
897 [o_currentCaptureView removeFromSuperviewWithoutNeedingDisplay];
898 [o_currentCaptureView release];
900 [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
901 [theView setNeedsDisplay: YES];
902 [theView setAutoresizesSubviews: YES];
903 [[[o_tabview tabViewItemAtIndex: 3] view] addSubview: theView];
904 [theView displayIfNeeded];
905 o_currentCaptureView = theView;
906 [o_currentCaptureView retain];
909 - (IBAction)openCaptureModeChanged:(id)sender
911 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
913 if( [[[VLCMain sharedInstance] getEyeTVController] isEyeTVrunning] == YES )
915 if( [[[VLCMain sharedInstance] getEyeTVController] isDeviceConnected] == YES )
917 [self showCaptureView: o_eyetv_running_view];
918 [self setupChannelInfo];
926 [self showCaptureView: o_eyetv_notLaunched_view];
927 [o_mrl setStringValue: @""];
929 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
931 [self showCaptureView: o_screen_view];
932 [o_mrl setStringValue: @"screen://"];
933 [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
934 [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
935 [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
936 [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
937 [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
938 [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
940 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"iSight"] )
942 [o_capture_lbl setStringValue: _NS("iSight Capture Input")];
943 [o_capture_long_lbl setStringValue: _NS("This facility allows you to process your iSight's input signal.\n\nNo settings are available in this version, so you will be provided a 640px*480px raw video stream.\n\nLive Audio input is not supported.")];
944 [o_capture_lbl displayIfNeeded];
945 [o_capture_long_lbl displayIfNeeded];
947 [self showCaptureView: o_capture_label_view];
948 [o_mrl setStringValue: @"qtcapture://"];
952 - (IBAction)screenStepperChanged:(id)sender
954 [o_screen_fps_fld setFloatValue: [o_screen_fps_stp floatValue]];
955 [o_panel makeFirstResponder: o_screen_fps_fld];
956 [o_mrl setStringValue: @"screen://"];
959 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
961 [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
962 if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
963 [o_screen_fps_fld setFloatValue: 1.0];
964 [o_mrl setStringValue: @"screen://"];
967 - (IBAction)eyetvSwitchChannel:(id)sender
969 if( sender == o_eyetv_nextProgram_btn )
971 int chanNum = [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: YES];
972 [o_eyetv_channels_pop selectItemWithTag:chanNum];
973 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
975 else if( sender == o_eyetv_previousProgram_btn )
977 int chanNum = [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: NO];
978 [o_eyetv_channels_pop selectItemWithTag:chanNum];
979 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
981 else if( sender == o_eyetv_channels_pop )
983 int chanNum = [[sender selectedItem] tag];
984 [[[VLCMain sharedInstance] getEyeTVController] selectChannel:chanNum];
985 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
988 msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
991 - (IBAction)eyetvLaunch:(id)sender
993 [[[VLCMain sharedInstance] getEyeTVController] launchEyeTV];
996 - (IBAction)eyetvGetPlugin:(id)sender
998 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1001 - (void)eyetvChanged:(NSNotification *)o_notification
1003 if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1005 msg_Dbg( VLCIntf, "eyetv device was added" );
1006 [self showCaptureView: o_eyetv_running_view];
1007 [self setupChannelInfo];
1009 else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1011 /* leave the channel selection like that,
1012 * switch to our "no device" tab */
1013 msg_Dbg( VLCIntf, "eyetv device was removed" );
1014 setEyeTVUnconnected;
1016 else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1018 /* switch to the "launch eyetv" tab */
1019 msg_Dbg( VLCIntf, "eyetv was terminated" );
1020 [self showCaptureView: o_eyetv_notLaunched_view];
1022 else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1024 /* we got no device yet */
1025 msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1026 setEyeTVUnconnected;
1029 msg_Warn( VLCIntf, "unknown external notify '%s' received", [[o_notification name] UTF8String] );
1032 /* little helper method, since this code needs to be run by multiple objects */
1033 - (void)setupChannelInfo
1035 /* set up channel selection */
1036 [o_eyetv_channels_pop removeAllItems];
1037 [o_eyetv_chn_bgbar setHidden: NO];
1038 [o_eyetv_chn_bgbar animate: self];
1039 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1040 [o_eyetv_chn_status_txt setHidden: NO];
1043 NSEnumerator *channels = [[[VLCMain sharedInstance] getEyeTVController] allChannels];
1045 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1047 keyEquivalent: @""] setTag:x++];
1048 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1050 keyEquivalent: @""] setTag:x++];
1054 [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1055 while( channel = [channels nextObject] )
1057 /* we have to add items this way, because we accept duplicates
1058 * additionally, we save a bit of time */
1059 [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1061 keyEquivalent: @""] setTag:++x];
1063 /* make Tuner the default */
1064 [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] getEyeTVController] currentChannel]];
1068 [o_eyetv_chn_bgbar setHidden: YES];
1069 [o_eyetv_chn_status_txt setHidden: YES];
1072 - (IBAction)subsChanged:(id)sender
1074 if ([o_file_sub_ckbox state] == NSOnState)
1076 [o_file_sub_btn_settings setEnabled:YES];
1080 [o_file_sub_btn_settings setEnabled:NO];
1084 - (IBAction)subSettings:(id)sender
1086 [NSApp beginSheet: o_file_sub_sheet
1087 modalForWindow: [sender window]
1089 didEndSelector: NULL
1093 - (IBAction)subCloseSheet:(id)sender
1095 [o_file_sub_sheet orderOut:sender];
1096 [NSApp endSheet: o_file_sub_sheet];
1099 - (IBAction)subFileBrowse:(id)sender
1101 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1103 [o_open_panel setAllowsMultipleSelection: NO];
1104 [o_open_panel setTitle: _NS("Open File")];
1105 [o_open_panel setPrompt: _NS("Open")];
1107 if( [o_open_panel runModalForDirectory: nil
1108 file: nil types: nil] == NSOKButton )
1110 NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
1111 [o_file_sub_path setStringValue: o_filename];
1115 - (IBAction)subOverride:(id)sender
1117 BOOL b_state = [o_file_sub_override state];
1118 [o_file_sub_delay setEnabled: b_state];
1119 [o_file_sub_delay_stp setEnabled: b_state];
1120 [o_file_sub_fps setEnabled: b_state];
1121 [o_file_sub_fps_stp setEnabled: b_state];
1124 - (IBAction)subDelayStepperChanged:(id)sender
1126 [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1129 - (IBAction)subFpsStepperChanged:(id)sender;
1131 [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1134 - (IBAction)panelCancel:(id)sender
1136 [NSApp stopModalWithCode: 0];
1139 - (IBAction)panelOk:(id)sender
1141 if( [[o_mrl stringValue] length] )
1143 [NSApp stopModalWithCode: 1];
1153 @implementation VLCOpenTextField
1155 - (void)mouseDown:(NSEvent *)theEvent
1157 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1159 [super mouseDown: theEvent];