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>
50 #define setEyeTVUnconnected \
51 [o_capture_lbl setStringValue: _NS("No device connected")]; \
52 [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.")]; \
53 [o_capture_lbl displayIfNeeded]; \
54 [o_capture_long_lbl displayIfNeeded]; \
55 [self showCaptureView: o_capture_label_view]
58 /*****************************************************************************
59 * GetEjectableMediaOfClass
60 *****************************************************************************/
61 NSArray *GetEjectableMediaOfClass( const char *psz_class )
63 io_object_t next_media;
64 mach_port_t master_port;
65 kern_return_t kern_result;
66 NSArray *o_devices = nil;
67 NSMutableArray *p_list = nil;
68 io_iterator_t media_iterator;
69 CFMutableDictionaryRef classes_to_match;
71 kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
72 if( kern_result != KERN_SUCCESS )
77 classes_to_match = IOServiceMatching( psz_class );
78 if( classes_to_match == NULL )
83 CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectableKey ),
86 kern_result = IOServiceGetMatchingServices( master_port, classes_to_match,
88 if( kern_result != KERN_SUCCESS )
93 p_list = [NSMutableArray arrayWithCapacity: 1];
95 next_media = IOIteratorNext( media_iterator );
99 size_t dev_path_length;
100 CFTypeRef str_bsd_path;
104 str_bsd_path = IORegistryEntryCreateCFProperty( next_media,
105 CFSTR( kIOBSDNameKey ),
108 if( str_bsd_path == NULL )
110 IOObjectRelease( next_media );
114 snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' );
115 dev_path_length = strlen( psz_buf );
117 if( CFStringGetCString( str_bsd_path,
118 (char*)&psz_buf + dev_path_length,
119 sizeof(psz_buf) - dev_path_length,
120 kCFStringEncodingASCII ) )
122 [p_list addObject: [NSString stringWithUTF8String: psz_buf]];
125 CFRelease( str_bsd_path );
127 IOObjectRelease( next_media );
129 } while( ( next_media = IOIteratorNext( media_iterator ) ) );
132 IOObjectRelease( media_iterator );
134 o_devices = [NSArray arrayWithArray: p_list];
139 /*****************************************************************************
140 * VLCOpen implementation
141 *****************************************************************************/
142 @implementation VLCOpen
144 static VLCOpen *_o_sharedMainInstance = nil;
146 + (VLCOpen *)sharedInstance
148 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
153 if( _o_sharedMainInstance) {
156 _o_sharedMainInstance = [super init];
160 return _o_sharedMainInstance;
165 if( o_file_slave_path )
166 [o_file_slave_path release];
172 [o_panel setTitle: _NS("Open Source")];
173 [o_mrl_lbl setStringValue: _NS("Media Resource Locator (MRL)")];
175 [o_btn_ok setTitle: _NS("Open")];
176 [o_btn_cancel setTitle: _NS("Cancel")];
178 [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
179 [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
180 [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
181 [[o_tabview tabViewItemAtIndex: 3] setLabel: _NS("Capture")];
183 [o_file_btn_browse setTitle: _NS("Browse...")];
184 [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
185 [o_file_slave_ckbox setTitle: _NS("Play another media synchronously")];
186 [o_file_slave_select_btn setTitle: _NS("Choose...")];
187 [o_file_slave_filename_txt setStringValue: @""];
189 [o_disc_device_lbl setStringValue: _NS("Device name")];
190 [o_disc_title_lbl setStringValue: _NS("Title")];
191 [o_disc_chapter_lbl setStringValue: _NS("Chapter")];
192 [o_disc_videots_btn_browse setTitle: _NS("Browse...")];
193 [o_disc_dvd_menus setTitle: _NS("No DVD menus")];
195 [[o_disc_type cellAtRow:0 column:0] setTitle: _NS("VIDEO_TS folder")];
196 [[o_disc_type cellAtRow:1 column:0] setTitle: _NS("DVD")];
197 [[o_disc_type cellAtRow:2 column:0] setTitle: _NS("VCD")];
198 [[o_disc_type cellAtRow:3 column:0] setTitle: _NS("Audio CD")];
200 [o_net_udp_port_lbl setStringValue: _NS("Port")];
201 [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
202 [o_net_udpm_port_lbl setStringValue: _NS("Port")];
203 [o_net_http_url_lbl setStringValue: _NS("URL")];
204 [o_net_help_lbl setStringValue: _NS("To Open a usual network stream (HTTP, RTSP, RTMP, 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.")];
205 [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 will use your machine's IP automatically.\n\nTo open a stream using a different protocol, just press Cancel to close this sheet.")];
206 [o_net_udp_cancel_btn setTitle: _NS("Cancel")];
207 [o_net_udp_ok_btn setTitle: _NS("Open")];
208 [o_net_openUDP_btn setTitle: _NS("Open RTP/UDP Stream")];
209 [o_net_udp_mode_lbl setStringValue: _NS("Mode")];
210 [o_net_udp_protocol_lbl setStringValue: _NS("Protocol")];
211 [o_net_udp_address_lbl setStringValue: _NS("Address")];
213 [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
214 [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
216 [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
217 [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
219 [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
221 [o_capture_mode_pop removeAllItems];
222 [o_capture_mode_pop addItemWithTitle: @"iSight"];
223 [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
224 [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
225 [o_screen_lbl setStringValue: _NS("Screen Capture Input")];
226 [o_screen_long_lbl setStringValue: _NS("This facility allows you to process your screen's output.")];
227 [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
228 [o_screen_left_lbl setStringValue: _NS("Subscreen left:")];
229 [o_screen_top_lbl setStringValue: _NS("Subscreen top:")];
230 [o_screen_width_lbl setStringValue: _NS("Subscreen width:")];
231 [o_screen_height_lbl setStringValue: _NS("Subscreen height:")];
232 [o_screen_follow_mouse_ckb setTitle: _NS("Follow the mouse")];
233 [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
234 [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
235 [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
236 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
237 [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
238 [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
239 [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
240 [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
244 [[NSNotificationCenter defaultCenter] addObserver: self
245 selector: @selector(openFilePathChanged:)
246 name: NSControlTextDidChangeNotification
247 object: o_file_path];
249 [[NSNotificationCenter defaultCenter] addObserver: self
250 selector: @selector(openDiscInfoChanged:)
251 name: NSControlTextDidChangeNotification
252 object: o_disc_device];
253 [[NSNotificationCenter defaultCenter] addObserver: self
254 selector: @selector(openDiscInfoChanged:)
255 name: NSControlTextDidChangeNotification
256 object: o_disc_title];
257 [[NSNotificationCenter defaultCenter] addObserver: self
258 selector: @selector(openDiscInfoChanged:)
259 name: NSControlTextDidChangeNotification
260 object: o_disc_chapter];
261 [[NSNotificationCenter defaultCenter] addObserver: self
262 selector: @selector(openDiscInfoChanged:)
263 name: NSControlTextDidChangeNotification
264 object: o_disc_videots_folder];
266 [[NSNotificationCenter defaultCenter] addObserver: self
267 selector: @selector(openNetInfoChanged:)
268 name: NSControlTextDidChangeNotification
269 object: o_net_udp_port];
270 [[NSNotificationCenter defaultCenter] addObserver: self
271 selector: @selector(openNetInfoChanged:)
272 name: NSControlTextDidChangeNotification
273 object: o_net_udpm_addr];
274 [[NSNotificationCenter defaultCenter] addObserver: self
275 selector: @selector(openNetInfoChanged:)
276 name: NSControlTextDidChangeNotification
277 object: o_net_udpm_port];
278 [[NSNotificationCenter defaultCenter] addObserver: self
279 selector: @selector(openNetInfoChanged:)
280 name: NSControlTextDidChangeNotification
281 object: o_net_http_url];
283 [[NSDistributedNotificationCenter defaultCenter] addObserver: self
284 selector: @selector(eyetvChanged:)
286 object: @"VLCEyeTVSupport"
287 suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
289 [[NSNotificationCenter defaultCenter] addObserver: self
290 selector: @selector(screenFPSfieldChanged:)
291 name: NSControlTextDidChangeNotification
292 object: o_screen_fps_fld];
294 /* register clicks on text fields */
295 [[NSNotificationCenter defaultCenter] addObserver: self
296 selector: @selector(textFieldWasClicked:)
297 name: @"VLCOpenTextFieldWasClicked"
304 module_config_t * p_item;
306 [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
307 [o_file_sub_btn_settings setTitle: _NS("Settings...")];
308 [o_file_sub_btn_browse setTitle: _NS("Browse...")];
309 [o_file_sub_override setTitle: _NS("Override parametters")];
310 [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
311 [o_file_sub_delay_stp setEnabled: NO];
312 [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
313 [o_file_sub_fps_stp setEnabled: NO];
314 [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
315 [o_file_sub_encoding_pop removeAllItems];
316 [o_file_sub_size_lbl setStringValue: _NS("Font size")];
317 [o_file_sub_size_pop removeAllItems];
318 [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
319 [o_file_sub_align_pop removeAllItems];
320 [o_file_sub_ok_btn setStringValue: _NS("OK")];
321 [o_file_sub_font_box setTitle: _NS("Font Properties")];
322 [o_file_sub_file_box setTitle: _NS("Subtitle File")];
324 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
328 for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
331 [o_file_sub_encoding_pop addItemWithTitle:
332 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
334 [o_file_sub_encoding_pop selectItemWithTitle:
335 [NSString stringWithUTF8String: p_item->value.psz]];
338 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
342 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
344 [o_file_sub_align_pop addItemWithTitle:
345 [NSString stringWithUTF8String:
346 p_item->ppsz_list_text[i_index]]];
348 [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
351 p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
355 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
357 [o_file_sub_size_pop addItemWithTitle:
358 [NSString stringWithUTF8String:
359 p_item->ppsz_list_text[i_index]]];
360 if ( p_item->value.i == p_item->pi_list[i_index] )
362 [o_file_sub_size_pop selectItemAtIndex: i_index];
368 - (void)openTarget:(int)i_type
372 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
374 [o_tabview selectTabViewItemAtIndex: i_type];
375 [o_file_sub_ckbox setState: NSOffState];
377 i_result = [NSApp runModalForWindow: o_panel];
382 NSMutableDictionary *o_dic;
383 NSMutableArray *o_options = [NSMutableArray array];
386 o_dic = [NSMutableDictionary dictionaryWithObject: [o_mrl stringValue] forKey: @"ITEM_URL"];
387 if( [o_file_sub_ckbox state] == NSOnState )
389 module_config_t * p_item;
391 [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", [o_file_sub_path stringValue]]];
392 if( [o_file_sub_override state] == NSOnState )
394 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
395 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
397 [o_options addObject: [NSString stringWithFormat:
398 @"subsdec-encoding=%@",
399 [o_file_sub_encoding_pop titleOfSelectedItem]]];
400 [o_options addObject: [NSString stringWithFormat:
402 [o_file_sub_align_pop indexOfSelectedItem]]];
404 p_item = config_FindConfig( VLC_OBJECT(p_intf),
405 "freetype-rel-fontsize" );
409 [o_options addObject: [NSString stringWithFormat:
410 @"freetype-rel-fontsize=%i",
411 p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
414 if( [o_output_ckbox state] == NSOnState )
416 for (i = 0 ; i < [[o_sout_options mrl] count] ; i++)
418 [o_options addObject: [NSString stringWithString:
419 [[(VLCOutput *)o_sout_options mrl] objectAtIndex: i]]];
422 if( [o_file_slave_ckbox state] && o_file_slave_path )
423 [o_options addObject: [NSString stringWithFormat: @"input-slave=%@", o_file_slave_path]];
424 if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
426 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
427 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
428 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
429 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
430 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
431 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
432 if( [o_screen_follow_mouse_ckb intValue] == YES )
433 [o_options addObject: @"screen-follow-mouse"];
435 [o_options addObject: @"no-screen-follow-mouse"];
438 /* apply the options to our item(s) */
439 [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
441 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
443 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
447 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
449 NSString *o_label = [o_tvi label];
451 if( [o_label isEqualToString: _NS("File")] )
453 [self openFilePathChanged: nil];
455 else if( [o_label isEqualToString: _NS("Disc")] )
457 [self openDiscTypeChanged: nil];
459 else if( [o_label isEqualToString: _NS("Network")] )
461 [self openNetInfoChanged: nil];
463 else if( [o_label isEqualToString: _NS("Capture")] )
465 [self openCaptureModeChanged: nil];
469 - (IBAction)expandMRLfieldAction:(id)sender
471 NSRect o_win_rect, o_view_rect;
472 o_win_rect = [o_panel frame];
473 o_view_rect = [o_mrl_view frame];
475 if( [o_mrl_btn state] == NSOffState )
477 /* we need to collaps, restore the panel size */
478 o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
479 o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
481 /* remove the MRL view */
482 [o_mrl_view removeFromSuperviewWithoutNeedingDisplay];
484 /* we need to expand */
485 [o_mrl_view setFrame: NSMakeRect( 0,
486 [o_mrl_btn frame].origin.y,
487 o_view_rect.size.width,
488 o_view_rect.size.height )];
489 [o_mrl_view setNeedsDisplay: YES];
490 [o_mrl_view setAutoresizesSubviews: YES];
492 /* add the MRL view */
493 [[o_panel contentView] addSubview: o_mrl_view];
494 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
497 [o_panel setFrame: o_win_rect display:YES animate: YES];
498 [o_panel displayIfNeeded];
501 - (IBAction)inputSlaveAction:(id)sender
503 if( sender == o_file_slave_ckbox )
504 [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
507 NSOpenPanel *o_open_panel;
508 o_open_panel = [NSOpenPanel openPanel];
509 [o_open_panel setCanChooseFiles: YES];
510 [o_open_panel setCanChooseDirectories: NO];
511 if( [o_open_panel runModalForDirectory: nil file: nil types: nil] == NSOKButton )
513 if( o_file_slave_path )
514 [o_file_slave_path release];
515 o_file_slave_path = [[o_open_panel filenames] objectAtIndex: 0];
516 [o_file_slave_path retain];
519 [o_file_slave_filename_txt setStringValue: @""];
521 if( o_file_slave_path )
523 NSFileWrapper *o_file_wrapper;
524 o_file_wrapper = [[NSFileWrapper alloc] initWithPath: o_file_slave_path];
525 [o_file_slave_filename_txt setStringValue: [NSString stringWithFormat: @"\"%@\"", [o_file_wrapper preferredFilename]]];
526 [o_file_wrapper release];
530 - (void)openFileGeneric
532 [self openFilePathChanged: nil];
533 [self openTarget: 0];
538 [self openDiscTypeChanged: nil];
539 [self openTarget: 1];
544 [self openNetInfoChanged: nil];
545 [self openTarget: 2];
550 [self openCaptureModeChanged: nil];
551 [self showCaptureView: o_capture_label_view];
552 [self openTarget: 3];
555 - (void)openFilePathChanged:(NSNotification *)o_notification
557 NSString *o_filename = [o_file_path stringValue];
558 bool b_stream = [o_file_stream state];
561 [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
563 char *psz_uri = make_URI([o_filename UTF8String]);
564 if( !psz_uri ) return;
566 NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
567 NSRange offile = [o_mrl_string rangeOfString:@"file"];
572 [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
576 [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
578 [o_mrl setStringValue: o_mrl_string];
581 - (IBAction)openFileBrowse:(id)sender
583 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
585 [o_open_panel setAllowsMultipleSelection: NO];
586 [o_open_panel setCanChooseDirectories: YES];
587 [o_open_panel setTitle: _NS("Open File")];
588 [o_open_panel setPrompt: _NS("Open")];
590 [o_open_panel beginSheetForDirectory:nil
593 modalForWindow:[sender window]
595 didEndSelector: @selector(pathChosenInPanel:
601 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void *)contextInfo
603 if (returnCode == NSFileHandlingPanelOKButton)
605 NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
606 [o_file_path setStringValue: o_filename];
607 [self openFilePathChanged: nil];
611 - (IBAction)openFileStreamChanged:(id)sender
613 [self openFilePathChanged: nil];
616 - (IBAction)openDiscTypeChanged:(id)sender
619 BOOL b_device, b_no_menus, b_title_chapter;
621 [o_disc_device removeAllItems];
622 b_title_chapter = ![o_disc_dvd_menus state];
624 o_type = [[o_disc_type selectedCell] title];
626 if ( [o_type isEqualToString: _NS("VIDEO_TS folder")] )
628 b_device = NO; b_no_menus = YES;
634 const char *psz_class = NULL;
637 if ( [o_type isEqualToString: _NS("VCD")] )
639 psz_class = kIOCDMediaClass;
641 b_no_menus = NO; b_title_chapter = YES;
643 else if ( [o_type isEqualToString: _NS("Audio CD")])
645 psz_class = kIOCDMediaClass;
647 b_no_menus = NO; b_title_chapter = NO;
651 psz_class = kIODVDMediaClass;
656 o_devices = GetEjectableMediaOfClass( psz_class );
657 if ( o_devices != nil )
659 int i_devices = [o_devices count];
663 for( int i = 0; i < i_devices; i++ )
666 addItemWithObjectValue: [o_devices objectAtIndex: i]];
669 [o_disc_device selectItemAtIndex: 0];
673 [o_disc_device setStringValue:
674 [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
679 [o_disc_device setEnabled: b_device];
680 [o_disc_title setEnabled: b_title_chapter];
681 [o_disc_title_stp setEnabled: b_title_chapter];
682 [o_disc_chapter setEnabled: b_title_chapter];
683 [o_disc_chapter_stp setEnabled: b_title_chapter];
684 [o_disc_videots_folder setEnabled: !b_device];
685 [o_disc_videots_btn_browse setEnabled: !b_device];
686 [o_disc_dvd_menus setEnabled: b_no_menus];
688 [self openDiscInfoChanged: nil];
691 - (IBAction)openDiscStepperChanged:(id)sender
693 int i_tag = [sender tag];
697 [o_disc_title setIntValue: [o_disc_title_stp intValue]];
699 else if( i_tag == 1 )
701 [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
704 [self openDiscInfoChanged: nil];
707 - (void)openDiscInfoChanged:(NSNotification *)o_notification
712 NSString *o_mrl_string;
713 int i_title, i_chapter;
716 o_type = [[o_disc_type selectedCell] title];
717 o_device = [o_disc_device stringValue];
718 i_title = [o_disc_title intValue];
719 i_chapter = [o_disc_chapter intValue];
720 o_videots = [o_disc_videots_folder stringValue];
721 b_no_menus = [o_disc_dvd_menus state];
723 if ( [o_type isEqualToString: _NS("VCD")] )
725 if ( [o_device isEqualToString:
726 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
728 o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i:%i",
729 o_device, i_title, i_chapter];
731 else if ( [o_type isEqualToString: _NS("Audio CD")] )
733 if ( [o_device isEqualToString:
734 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
736 o_mrl_string = [NSString stringWithFormat: @"cdda://%@",
739 else if ( [o_type isEqualToString: _NS("DVD")] )
741 if ( [o_device isEqualToString:
742 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
745 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i-",
746 o_device, i_title, i_chapter];
748 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
752 else /* VIDEO_TS folder */
755 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
756 o_videots, i_title, i_chapter];
758 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
762 [o_mrl setStringValue: o_mrl_string];
765 - (IBAction)openDiscMenusChanged:(id)sender
767 [self openDiscInfoChanged: nil];
768 [self openDiscTypeChanged: nil];
771 - (IBAction)openVTSBrowse:(id)sender
773 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
775 [o_open_panel setAllowsMultipleSelection: NO];
776 [o_open_panel setCanChooseFiles: NO];
777 [o_open_panel setCanChooseDirectories: YES];
778 [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
779 [o_open_panel setPrompt: _NS("Open")];
781 if( [o_open_panel runModalForDirectory: nil
782 file: nil types: nil] == NSOKButton )
784 NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
785 [o_disc_videots_folder setStringValue: o_dirname];
786 [self openDiscInfoChanged: nil];
790 - (void)textFieldWasClicked:(NSNotification *)o_notification
792 if( [o_notification object] == o_net_udp_port )
793 [o_net_mode selectCellAtRow: 0 column: 0];
794 else if( [o_notification object] == o_net_udpm_addr ||
795 [o_notification object] == o_net_udpm_port )
796 [o_net_mode selectCellAtRow: 1 column: 0];
798 [o_net_mode selectCellAtRow: 2 column: 0];
800 [self openNetInfoChanged: nil];
803 - (IBAction)openNetModeChanged:(id)sender
805 if( sender == o_net_mode )
807 if( [[sender selectedCell] tag] == 0 )
808 [o_panel makeFirstResponder: o_net_udp_port];
809 else if ( [[sender selectedCell] tag] == 1 )
810 [o_panel makeFirstResponder: o_net_udpm_addr];
812 msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
815 [self openNetInfoChanged: nil];
818 - (IBAction)openNetStepperChanged:(id)sender
820 int i_tag = [sender tag];
824 [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
825 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
826 object: o_net_udp_port];
827 [o_panel makeFirstResponder: o_net_udp_port];
829 else if( i_tag == 1 )
831 [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
832 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
833 object: o_net_udpm_port];
834 [o_panel makeFirstResponder: o_net_udpm_port];
837 [self openNetInfoChanged: nil];
840 - (void)openNetInfoChanged:(NSNotification *)o_notification
842 NSString *o_mrl_string = [NSString string];
844 if( [o_net_udp_panel isVisible] )
847 o_mode = [[o_net_mode selectedCell] title];
849 if( [o_mode isEqualToString: _NS("Unicast")] )
851 int i_port = [o_net_udp_port intValue];
853 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
854 o_mrl_string = [NSString stringWithString: @"udp://"];
856 o_mrl_string = [NSString stringWithString: @"rtp://"];
858 if( i_port != config_GetInt( p_intf, "server-port" ) )
861 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
864 else if( [o_mode isEqualToString: _NS("Multicast")] )
866 NSString *o_addr = [o_net_udpm_addr stringValue];
867 int i_port = [o_net_udpm_port intValue];
869 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
870 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
872 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
874 if( i_port != config_GetInt( p_intf, "server-port" ) )
877 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
883 o_mrl_string = [o_net_http_url stringValue];
885 [o_mrl setStringValue: o_mrl_string];
888 - (IBAction)openNetUDPButtonAction:(id)sender
890 if( sender == o_net_openUDP_btn )
892 [NSApp beginSheet: o_net_udp_panel
893 modalForWindow: o_panel
897 [self openNetInfoChanged: nil];
899 else if( sender == o_net_udp_cancel_btn )
901 [o_net_udp_panel orderOut: sender];
902 [NSApp endSheet: o_net_udp_panel];
904 else if( sender == o_net_udp_ok_btn )
906 NSString *o_mrl_string = [NSString string];
907 if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
909 int i_port = [o_net_udp_port intValue];
911 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
912 o_mrl_string = [NSString stringWithString: @"udp://"];
914 o_mrl_string = [NSString stringWithString: @"rtp://"];
916 if( i_port != config_GetInt( p_intf, "server-port" ) )
919 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
922 else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
924 NSString *o_addr = [o_net_udpm_addr stringValue];
925 int i_port = [o_net_udpm_port intValue];
927 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
928 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
930 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
932 if( i_port != config_GetInt( p_intf, "server-port" ) )
935 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
938 [o_mrl setStringValue: o_mrl_string];
939 [o_net_http_url setStringValue: o_mrl_string];
940 [o_net_udp_panel orderOut: sender];
941 [NSApp endSheet: o_net_udp_panel];
947 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
949 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
951 [o_open_panel setAllowsMultipleSelection: YES];
952 [o_open_panel setCanChooseDirectories: YES];
953 [o_open_panel setTitle: _NS("Open File")];
954 [o_open_panel setPrompt: _NS("Open")];
956 if( [o_open_panel runModalForDirectory: nil
957 file: nil types: nil] == NSOKButton )
959 NSArray *o_array = [NSArray array];
960 NSArray *o_values = [[o_open_panel filenames]
961 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
963 for( i = 0; i < (int)[o_values count]; i++)
966 char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String]);
970 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
974 o_array = [o_array arrayByAddingObject: o_dic];
977 [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
979 [o_playlist appendArray: o_array atPos: -1 enqueue:YES];
983 - (void)showCaptureView: theView
986 o_view_rect = [theView frame];
987 if( o_currentCaptureView )
989 [o_currentCaptureView removeFromSuperviewWithoutNeedingDisplay];
990 [o_currentCaptureView release];
992 [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
993 [theView setNeedsDisplay: YES];
994 [theView setAutoresizesSubviews: YES];
995 [[[o_tabview tabViewItemAtIndex: 3] view] addSubview: theView];
996 [theView displayIfNeeded];
997 o_currentCaptureView = theView;
998 [o_currentCaptureView retain];
1001 - (IBAction)openCaptureModeChanged:(id)sender
1003 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1005 if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1007 if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1009 [self showCaptureView: o_eyetv_running_view];
1010 [self setupChannelInfo];
1014 setEyeTVUnconnected;
1018 [self showCaptureView: o_eyetv_notLaunched_view];
1019 [o_mrl setStringValue: @""];
1021 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1023 [self showCaptureView: o_screen_view];
1024 [o_mrl setStringValue: @"screen://"];
1025 [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
1026 [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
1027 [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
1028 [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
1029 [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
1030 [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
1032 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"iSight"] )
1034 [o_capture_lbl setStringValue: _NS("iSight Capture Input")];
1035 [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.")];
1036 [o_capture_lbl displayIfNeeded];
1037 [o_capture_long_lbl displayIfNeeded];
1039 [self showCaptureView: o_capture_label_view];
1040 [o_mrl setStringValue: @"qtcapture://"];
1044 - (IBAction)screenStepperChanged:(id)sender
1046 [o_screen_fps_fld setFloatValue: [o_screen_fps_stp floatValue]];
1047 [o_panel makeFirstResponder: o_screen_fps_fld];
1048 [o_mrl setStringValue: @"screen://"];
1051 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1053 [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1054 if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1055 [o_screen_fps_fld setFloatValue: 1.0];
1056 [o_mrl setStringValue: @"screen://"];
1059 - (IBAction)eyetvSwitchChannel:(id)sender
1061 if( sender == o_eyetv_nextProgram_btn )
1063 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1064 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1065 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1067 else if( sender == o_eyetv_previousProgram_btn )
1069 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1070 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1071 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1073 else if( sender == o_eyetv_channels_pop )
1075 int chanNum = [[sender selectedItem] tag];
1076 [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1077 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1080 msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1083 - (IBAction)eyetvLaunch:(id)sender
1085 [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1088 - (IBAction)eyetvGetPlugin:(id)sender
1090 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1093 - (void)eyetvChanged:(NSNotification *)o_notification
1095 if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1097 msg_Dbg( VLCIntf, "eyetv device was added" );
1098 [self showCaptureView: o_eyetv_running_view];
1099 [self setupChannelInfo];
1101 else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1103 /* leave the channel selection like that,
1104 * switch to our "no device" tab */
1105 msg_Dbg( VLCIntf, "eyetv device was removed" );
1106 setEyeTVUnconnected;
1108 else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1110 /* switch to the "launch eyetv" tab */
1111 msg_Dbg( VLCIntf, "eyetv was terminated" );
1112 [self showCaptureView: o_eyetv_notLaunched_view];
1114 else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1116 /* we got no device yet */
1117 msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1118 setEyeTVUnconnected;
1121 msg_Warn( VLCIntf, "unknown external notify '%s' received", [[o_notification name] UTF8String] );
1124 /* little helper method, since this code needs to be run by multiple objects */
1125 - (void)setupChannelInfo
1127 /* set up channel selection */
1128 [o_eyetv_channels_pop removeAllItems];
1129 [o_eyetv_chn_bgbar setHidden: NO];
1130 [o_eyetv_chn_bgbar animate: self];
1131 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1132 [o_eyetv_chn_status_txt setHidden: NO];
1135 NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1137 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1139 keyEquivalent: @""] setTag:x++];
1140 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1142 keyEquivalent: @""] setTag:x++];
1146 [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1147 while( channel = [channels nextObject] )
1149 /* we have to add items this way, because we accept duplicates
1150 * additionally, we save a bit of time */
1151 [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1153 keyEquivalent: @""] setTag:++x];
1155 /* make Tuner the default */
1156 [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1160 [o_eyetv_chn_bgbar setHidden: YES];
1161 [o_eyetv_chn_status_txt setHidden: YES];
1164 - (IBAction)subsChanged:(id)sender
1166 if ([o_file_sub_ckbox state] == NSOnState)
1168 [o_file_sub_btn_settings setEnabled:YES];
1172 [o_file_sub_btn_settings setEnabled:NO];
1176 - (IBAction)subSettings:(id)sender
1178 [NSApp beginSheet: o_file_sub_sheet
1179 modalForWindow: [sender window]
1181 didEndSelector: NULL
1185 - (IBAction)subCloseSheet:(id)sender
1187 [o_file_sub_sheet orderOut:sender];
1188 [NSApp endSheet: o_file_sub_sheet];
1191 - (IBAction)subFileBrowse:(id)sender
1193 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1195 [o_open_panel setAllowsMultipleSelection: NO];
1196 [o_open_panel setTitle: _NS("Open File")];
1197 [o_open_panel setPrompt: _NS("Open")];
1199 if( [o_open_panel runModalForDirectory: nil
1200 file: nil types: nil] == NSOKButton )
1202 NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
1203 [o_file_sub_path setStringValue: o_filename];
1207 - (IBAction)subOverride:(id)sender
1209 BOOL b_state = [o_file_sub_override state];
1210 [o_file_sub_delay setEnabled: b_state];
1211 [o_file_sub_delay_stp setEnabled: b_state];
1212 [o_file_sub_fps setEnabled: b_state];
1213 [o_file_sub_fps_stp setEnabled: b_state];
1216 - (IBAction)subDelayStepperChanged:(id)sender
1218 [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1221 - (IBAction)subFpsStepperChanged:(id)sender;
1223 [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1226 - (IBAction)panelCancel:(id)sender
1228 [NSApp stopModalWithCode: 0];
1231 - (IBAction)panelOk:(id)sender
1233 if( [[o_mrl stringValue] length] )
1235 [NSApp stopModalWithCode: 1];
1245 @implementation VLCOpenTextField
1247 - (void)mouseDown:(NSEvent *)theEvent
1249 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1251 [super mouseDown: theEvent];