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 setStringValue: _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 will 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")];
197 [o_net_udp_mode_lbl setStringValue: _NS("Mode")];
198 [o_net_udp_protocol_lbl setStringValue: _NS("Protocol")];
199 [o_net_udp_address_lbl setStringValue: _NS("Address")];
201 [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
202 [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
204 [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
205 [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
207 [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
209 [o_capture_mode_pop removeAllItems];
210 [o_capture_mode_pop addItemWithTitle: @"iSight"];
211 [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
212 [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
213 [o_screen_lbl setStringValue: _NS("Screen Capture Input")];
214 [o_screen_long_lbl setStringValue: _NS("This facility allows you to process your screen's output.")];
215 [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
216 [o_screen_left_lbl setStringValue: _NS("Subscreen left:")];
217 [o_screen_top_lbl setStringValue: _NS("Subscreen top:")];
218 [o_screen_width_lbl setStringValue: _NS("Subscreen width:")];
219 [o_screen_height_lbl setStringValue: _NS("Subscreen height:")];
220 [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
221 [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
222 [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
223 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
224 [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
225 [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
226 [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
227 [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
231 [[NSNotificationCenter defaultCenter] addObserver: self
232 selector: @selector(openFilePathChanged:)
233 name: NSControlTextDidChangeNotification
234 object: o_file_path];
236 [[NSNotificationCenter defaultCenter] addObserver: self
237 selector: @selector(openDiscInfoChanged:)
238 name: NSControlTextDidChangeNotification
239 object: o_disc_device];
240 [[NSNotificationCenter defaultCenter] addObserver: self
241 selector: @selector(openDiscInfoChanged:)
242 name: NSControlTextDidChangeNotification
243 object: o_disc_title];
244 [[NSNotificationCenter defaultCenter] addObserver: self
245 selector: @selector(openDiscInfoChanged:)
246 name: NSControlTextDidChangeNotification
247 object: o_disc_chapter];
248 [[NSNotificationCenter defaultCenter] addObserver: self
249 selector: @selector(openDiscInfoChanged:)
250 name: NSControlTextDidChangeNotification
251 object: o_disc_videots_folder];
253 [[NSNotificationCenter defaultCenter] addObserver: self
254 selector: @selector(openNetInfoChanged:)
255 name: NSControlTextDidChangeNotification
256 object: o_net_udp_port];
257 [[NSNotificationCenter defaultCenter] addObserver: self
258 selector: @selector(openNetInfoChanged:)
259 name: NSControlTextDidChangeNotification
260 object: o_net_udpm_addr];
261 [[NSNotificationCenter defaultCenter] addObserver: self
262 selector: @selector(openNetInfoChanged:)
263 name: NSControlTextDidChangeNotification
264 object: o_net_udpm_port];
265 [[NSNotificationCenter defaultCenter] addObserver: self
266 selector: @selector(openNetInfoChanged:)
267 name: NSControlTextDidChangeNotification
268 object: o_net_http_url];
270 [[NSDistributedNotificationCenter defaultCenter] addObserver: self
271 selector: @selector(eyetvChanged:)
273 object: @"VLCEyeTVSupport"
274 suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
276 [[NSNotificationCenter defaultCenter] addObserver: self
277 selector: @selector(screenFPSfieldChanged:)
278 name: NSControlTextDidChangeNotification
279 object: o_screen_fps_fld];
281 /* register clicks on text fields */
282 [[NSNotificationCenter defaultCenter] addObserver: self
283 selector: @selector(textFieldWasClicked:)
284 name: @"VLCOpenTextFieldWasClicked"
291 module_config_t * p_item;
293 [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
294 [o_file_sub_btn_settings setTitle: _NS("Settings...")];
295 [o_file_sub_btn_browse setTitle: _NS("Browse...")];
296 [o_file_sub_override setTitle: _NS("Override parametters")];
297 [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
298 [o_file_sub_delay_stp setEnabled: NO];
299 [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
300 [o_file_sub_fps_stp setEnabled: NO];
301 [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
302 [o_file_sub_encoding_pop removeAllItems];
303 [o_file_sub_size_lbl setStringValue: _NS("Font size")];
304 [o_file_sub_size_pop removeAllItems];
305 [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
306 [o_file_sub_align_pop removeAllItems];
307 [o_file_sub_ok_btn setStringValue: _NS("OK")];
308 [o_file_sub_font_box setTitle: _NS("Font Properties")];
309 [o_file_sub_file_box setTitle: _NS("Subtitle File")];
311 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
315 for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
318 [o_file_sub_encoding_pop addItemWithTitle:
319 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
321 [o_file_sub_encoding_pop selectItemWithTitle:
322 [NSString stringWithUTF8String: p_item->value.psz]];
325 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
329 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
331 [o_file_sub_align_pop addItemWithTitle:
332 [NSString stringWithUTF8String:
333 p_item->ppsz_list_text[i_index]]];
335 [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
338 p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
342 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
344 [o_file_sub_size_pop addItemWithTitle:
345 [NSString stringWithUTF8String:
346 p_item->ppsz_list_text[i_index]]];
347 if ( p_item->value.i == p_item->pi_list[i_index] )
349 [o_file_sub_size_pop selectItemAtIndex: i_index];
355 - (void)openTarget:(int)i_type
359 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
361 [o_tabview selectTabViewItemAtIndex: i_type];
362 [o_file_sub_ckbox setState: NSOffState];
364 i_result = [NSApp runModalForWindow: o_panel];
369 NSMutableDictionary *o_dic;
370 NSMutableArray *o_options = [NSMutableArray array];
373 o_dic = [NSMutableDictionary dictionaryWithObject: [o_mrl stringValue] forKey: @"ITEM_URL"];
374 if( [o_file_sub_ckbox state] == NSOnState )
376 module_config_t * p_item;
378 [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", [o_file_sub_path stringValue]]];
379 if( [o_file_sub_override state] == NSOnState )
381 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
382 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
384 [o_options addObject: [NSString stringWithFormat:
385 @"subsdec-encoding=%@",
386 [o_file_sub_encoding_pop titleOfSelectedItem]]];
387 [o_options addObject: [NSString stringWithFormat:
389 [o_file_sub_align_pop indexOfSelectedItem]]];
391 p_item = config_FindConfig( VLC_OBJECT(p_intf),
392 "freetype-rel-fontsize" );
396 [o_options addObject: [NSString stringWithFormat:
397 @"freetype-rel-fontsize=%i",
398 p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
401 if( [o_output_ckbox state] == NSOnState )
403 for (i = 0 ; i < [[o_sout_options getMRL] count] ; i++)
405 [o_options addObject: [NSString stringWithString:
406 [[(VLCOutput *)o_sout_options getMRL] objectAtIndex: i]]];
409 if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
411 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
412 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
413 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
414 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
415 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
416 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
417 if( [o_screen_follow_mouse_ckb intValue] == YES )
418 [o_options addObject: @"screen-follow-mouse"];
420 [o_options addObject: @"no-screen-follow-mouse"];
423 /* apply the options to our item(s) */
424 [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
426 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
428 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
432 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
434 NSString *o_label = [o_tvi label];
436 if( [o_label isEqualToString: _NS("File")] )
438 [self openFilePathChanged: nil];
440 else if( [o_label isEqualToString: _NS("Disc")] )
442 [self openDiscTypeChanged: nil];
444 else if( [o_label isEqualToString: _NS("Network")] )
446 [self openNetInfoChanged: nil];
448 else if( [o_label isEqualToString: _NS("Capture")] )
450 [self openCaptureModeChanged: nil];
454 - (IBAction)expandMRLfieldAction:(id)sender
456 NSRect o_win_rect, o_view_rect;
457 o_win_rect = [o_panel frame];
458 o_view_rect = [o_mrl_view frame];
460 if( [o_mrl_btn state] == NSOffState )
462 /* we need to collaps, restore the panel size */
463 o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
464 o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
466 /* remove the MRL view */
467 [o_mrl_view removeFromSuperviewWithoutNeedingDisplay];
469 /* we need to expand */
470 [o_mrl_view setFrame: NSMakeRect( 0,
471 [o_mrl_btn frame].origin.y,
472 o_view_rect.size.width,
473 o_view_rect.size.height )];
474 [o_mrl_view setNeedsDisplay: YES];
475 [o_mrl_view setAutoresizesSubviews: YES];
477 /* add the MRL view */
478 [[o_panel contentView] addSubview: o_mrl_view];
479 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
482 [o_panel setFrame: o_win_rect display:YES animate: YES];
483 [o_panel displayIfNeeded];
486 - (void)openFileGeneric
488 [self openFilePathChanged: nil];
489 [self openTarget: 0];
494 [self openDiscTypeChanged: nil];
495 [self openTarget: 1];
500 [self openNetInfoChanged: nil];
501 [self openTarget: 2];
506 [self openCaptureModeChanged: nil];
507 [self showCaptureView: o_capture_label_view];
508 [self openTarget: 3];
511 - (void)openFilePathChanged:(NSNotification *)o_notification
513 NSString *o_mrl_string;
514 NSString *o_filename = [o_file_path stringValue];
515 NSString *o_ext = [o_filename pathExtension];
516 bool b_stream = [o_file_stream state];
519 [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
523 o_mrl_string = [NSString stringWithFormat: @"directory://%@/", o_filename];
525 else if( [o_ext isEqualToString: @"bin"] ||
526 [o_ext isEqualToString: @"cue"] ||
527 [o_ext isEqualToString: @"vob"] ||
528 [o_ext isEqualToString: @"iso"] )
530 o_mrl_string = o_filename;
534 o_mrl_string = [NSString stringWithFormat: @"%s://%@",
535 b_stream ? "stream" : "file",
538 [o_mrl setStringValue: o_mrl_string];
541 - (IBAction)openFileBrowse:(id)sender
543 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
545 [o_open_panel setAllowsMultipleSelection: NO];
546 [o_open_panel setCanChooseDirectories: YES];
547 [o_open_panel setTitle: _NS("Open File")];
548 [o_open_panel setPrompt: _NS("Open")];
550 [o_open_panel beginSheetForDirectory:nil
553 modalForWindow:[sender window]
555 didEndSelector: @selector(pathChosenInPanel:
561 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void *)contextInfo
563 if (returnCode == NSFileHandlingPanelOKButton)
565 NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
566 [o_file_path setStringValue: o_filename];
567 [self openFilePathChanged: nil];
571 - (IBAction)openFileStreamChanged:(id)sender
573 [self openFilePathChanged: nil];
576 - (IBAction)openDiscTypeChanged:(id)sender
579 BOOL b_device, b_no_menus, b_title_chapter;
581 [o_disc_device removeAllItems];
582 b_title_chapter = ![o_disc_dvd_menus state];
584 o_type = [[o_disc_type selectedCell] title];
586 if ( [o_type isEqualToString: _NS("VIDEO_TS directory")] )
588 b_device = NO; b_no_menus = YES;
594 const char *psz_class = NULL;
597 if ( [o_type isEqualToString: _NS("VCD")] )
599 psz_class = kIOCDMediaClass;
601 b_no_menus = NO; b_title_chapter = YES;
603 else if ( [o_type isEqualToString: _NS("Audio CD")])
605 psz_class = kIOCDMediaClass;
607 b_no_menus = NO; b_title_chapter = NO;
611 psz_class = kIODVDMediaClass;
616 o_devices = GetEjectableMediaOfClass( psz_class );
617 if ( o_devices != nil )
619 int i_devices = [o_devices count];
623 for( int i = 0; i < i_devices; i++ )
626 addItemWithObjectValue: [o_devices objectAtIndex: i]];
629 [o_disc_device selectItemAtIndex: 0];
633 [o_disc_device setStringValue:
634 [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
639 [o_disc_device setEnabled: b_device];
640 [o_disc_title setEnabled: b_title_chapter];
641 [o_disc_title_stp setEnabled: b_title_chapter];
642 [o_disc_chapter setEnabled: b_title_chapter];
643 [o_disc_chapter_stp setEnabled: b_title_chapter];
644 [o_disc_videots_folder setEnabled: !b_device];
645 [o_disc_videots_btn_browse setEnabled: !b_device];
646 [o_disc_dvd_menus setEnabled: b_no_menus];
648 [self openDiscInfoChanged: nil];
651 - (IBAction)openDiscStepperChanged:(id)sender
653 int i_tag = [sender tag];
657 [o_disc_title setIntValue: [o_disc_title_stp intValue]];
659 else if( i_tag == 1 )
661 [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
664 [self openDiscInfoChanged: nil];
667 - (void)openDiscInfoChanged:(NSNotification *)o_notification
672 NSString *o_mrl_string;
673 int i_title, i_chapter;
676 o_type = [[o_disc_type selectedCell] title];
677 o_device = [o_disc_device stringValue];
678 i_title = [o_disc_title intValue];
679 i_chapter = [o_disc_chapter intValue];
680 o_videots = [o_disc_videots_folder stringValue];
681 b_no_menus = [o_disc_dvd_menus state];
683 if ( [o_type isEqualToString: _NS("VCD")] )
685 if ( [o_device isEqualToString:
686 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
688 o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i:%i",
689 o_device, i_title, i_chapter];
691 else if ( [o_type isEqualToString: _NS("Audio CD")] )
693 if ( [o_device isEqualToString:
694 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
696 o_mrl_string = [NSString stringWithFormat: @"cdda://%@",
699 else if ( [o_type isEqualToString: _NS("DVD")] )
701 if ( [o_device isEqualToString:
702 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
705 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i-",
706 o_device, i_title, i_chapter];
708 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
712 else /* VIDEO_TS folder */
715 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
716 o_videots, i_title, i_chapter];
718 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
722 [o_mrl setStringValue: o_mrl_string];
725 - (IBAction)openDiscMenusChanged:(id)sender
727 [self openDiscInfoChanged: nil];
728 [self openDiscTypeChanged: nil];
731 - (IBAction)openVTSBrowse:(id)sender
733 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
735 [o_open_panel setAllowsMultipleSelection: NO];
736 [o_open_panel setCanChooseFiles: NO];
737 [o_open_panel setCanChooseDirectories: YES];
738 [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
739 [o_open_panel setPrompt: _NS("Open")];
741 if( [o_open_panel runModalForDirectory: nil
742 file: nil types: nil] == NSOKButton )
744 NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
745 [o_disc_videots_folder setStringValue: o_dirname];
746 [self openDiscInfoChanged: nil];
750 - (void)textFieldWasClicked:(NSNotification *)o_notification
752 if( [o_notification object] == o_net_udp_port )
753 [o_net_mode selectCellAtRow: 0 column: 0];
754 else if( [o_notification object] == o_net_udpm_addr ||
755 [o_notification object] == o_net_udpm_port )
756 [o_net_mode selectCellAtRow: 1 column: 0];
758 [o_net_mode selectCellAtRow: 2 column: 0];
760 [self openNetInfoChanged: nil];
763 - (IBAction)openNetModeChanged:(id)sender
765 if( sender == o_net_mode )
767 if( [[sender selectedCell] tag] == 0 )
768 [o_panel makeFirstResponder: o_net_udp_port];
769 else if ( [[sender selectedCell] tag] == 1 )
770 [o_panel makeFirstResponder: o_net_udpm_addr];
772 msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
775 [self openNetInfoChanged: nil];
778 - (IBAction)openNetStepperChanged:(id)sender
780 int i_tag = [sender tag];
784 [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
785 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
786 object: o_net_udp_port];
787 [o_panel makeFirstResponder: o_net_udp_port];
789 else if( i_tag == 1 )
791 [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
792 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
793 object: o_net_udpm_port];
794 [o_panel makeFirstResponder: o_net_udpm_port];
797 [self openNetInfoChanged: nil];
800 - (void)openNetInfoChanged:(NSNotification *)o_notification
802 NSString *o_mrl_string = [NSString string];
804 if( [o_net_udp_panel isVisible] )
807 o_mode = [[o_net_mode selectedCell] title];
809 if( [o_mode isEqualToString: _NS("Unicast")] )
811 int i_port = [o_net_udp_port intValue];
813 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
814 o_mrl_string = [NSString stringWithString: @"udp://"];
816 o_mrl_string = [NSString stringWithString: @"rtp://"];
818 if( i_port != config_GetInt( p_intf, "server-port" ) )
821 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
824 else if( [o_mode isEqualToString: _NS("Multicast")] )
826 NSString *o_addr = [o_net_udpm_addr stringValue];
827 int i_port = [o_net_udpm_port intValue];
829 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
830 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
832 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
834 if( i_port != config_GetInt( p_intf, "server-port" ) )
837 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
843 NSString *o_url = [o_net_http_url stringValue];
845 if ( ![o_url hasPrefix:@"http:"] && ![o_url hasPrefix:@"ftp:"]
846 && ![o_url hasPrefix:@"mms"] && ![o_url hasPrefix:@"rtsp"] )
847 o_mrl_string = [NSString stringWithFormat: @"http://%@", o_url];
849 o_mrl_string = o_url;
851 [o_mrl setStringValue: o_mrl_string];
854 - (IBAction)openNetUDPButtonAction:(id)sender
856 if( sender == o_net_openUDP_btn )
858 [NSApp beginSheet: o_net_udp_panel
859 modalForWindow: o_panel
863 [self openNetInfoChanged: nil];
865 else if( sender == o_net_udp_cancel_btn )
867 [o_net_udp_panel orderOut: sender];
868 [NSApp endSheet: o_net_udp_panel];
870 else if( sender == o_net_udp_ok_btn )
872 NSString *o_mrl_string = [NSString string];
873 if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
875 int i_port = [o_net_udp_port intValue];
877 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
878 o_mrl_string = [NSString stringWithString: @"udp://"];
880 o_mrl_string = [NSString stringWithString: @"rtp://"];
882 if( i_port != config_GetInt( p_intf, "server-port" ) )
885 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
888 else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
890 NSString *o_addr = [o_net_udpm_addr stringValue];
891 int i_port = [o_net_udpm_port intValue];
893 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
894 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
896 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
898 if( i_port != config_GetInt( p_intf, "server-port" ) )
901 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
904 [o_mrl setStringValue: o_mrl_string];
905 [o_net_http_url setStringValue: o_mrl_string];
906 [o_net_udp_panel orderOut: sender];
907 [NSApp endSheet: o_net_udp_panel];
913 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
915 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
917 [o_open_panel setAllowsMultipleSelection: YES];
918 [o_open_panel setCanChooseDirectories: YES];
919 [o_open_panel setTitle: _NS("Open File")];
920 [o_open_panel setPrompt: _NS("Open")];
922 if( [o_open_panel runModalForDirectory: nil
923 file: nil types: nil] == NSOKButton )
925 NSArray *o_array = [NSArray array];
926 NSArray *o_values = [[o_open_panel filenames]
927 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
929 for( i = 0; i < (int)[o_values count]; i++)
932 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
933 o_array = [o_array arrayByAddingObject: o_dic];
936 [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
938 [o_playlist appendArray: o_array atPos: -1 enqueue:YES];
942 - (void)showCaptureView: theView
945 o_view_rect = [theView frame];
946 if( o_currentCaptureView )
948 [o_currentCaptureView removeFromSuperviewWithoutNeedingDisplay];
949 [o_currentCaptureView release];
951 [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
952 [theView setNeedsDisplay: YES];
953 [theView setAutoresizesSubviews: YES];
954 [[[o_tabview tabViewItemAtIndex: 3] view] addSubview: theView];
955 [theView displayIfNeeded];
956 o_currentCaptureView = theView;
957 [o_currentCaptureView retain];
960 - (IBAction)openCaptureModeChanged:(id)sender
962 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
964 if( [[[VLCMain sharedInstance] getEyeTVController] isEyeTVrunning] == YES )
966 if( [[[VLCMain sharedInstance] getEyeTVController] isDeviceConnected] == YES )
968 [self showCaptureView: o_eyetv_running_view];
969 [self setupChannelInfo];
977 [self showCaptureView: o_eyetv_notLaunched_view];
978 [o_mrl setStringValue: @""];
980 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
982 [self showCaptureView: o_screen_view];
983 [o_mrl setStringValue: @"screen://"];
984 [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
985 [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
986 [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
987 [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
988 [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
989 [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
991 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"iSight"] )
993 [o_capture_lbl setStringValue: _NS("iSight Capture Input")];
994 [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.")];
995 [o_capture_lbl displayIfNeeded];
996 [o_capture_long_lbl displayIfNeeded];
998 [self showCaptureView: o_capture_label_view];
999 [o_mrl setStringValue: @"qtcapture://"];
1003 - (IBAction)screenStepperChanged:(id)sender
1005 [o_screen_fps_fld setFloatValue: [o_screen_fps_stp floatValue]];
1006 [o_panel makeFirstResponder: o_screen_fps_fld];
1007 [o_mrl setStringValue: @"screen://"];
1010 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1012 [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1013 if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1014 [o_screen_fps_fld setFloatValue: 1.0];
1015 [o_mrl setStringValue: @"screen://"];
1018 - (IBAction)eyetvSwitchChannel:(id)sender
1020 if( sender == o_eyetv_nextProgram_btn )
1022 int chanNum = [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: YES];
1023 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1024 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1026 else if( sender == o_eyetv_previousProgram_btn )
1028 int chanNum = [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: NO];
1029 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1030 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1032 else if( sender == o_eyetv_channels_pop )
1034 int chanNum = [[sender selectedItem] tag];
1035 [[[VLCMain sharedInstance] getEyeTVController] selectChannel:chanNum];
1036 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1039 msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1042 - (IBAction)eyetvLaunch:(id)sender
1044 [[[VLCMain sharedInstance] getEyeTVController] launchEyeTV];
1047 - (IBAction)eyetvGetPlugin:(id)sender
1049 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1052 - (void)eyetvChanged:(NSNotification *)o_notification
1054 if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1056 msg_Dbg( VLCIntf, "eyetv device was added" );
1057 [self showCaptureView: o_eyetv_running_view];
1058 [self setupChannelInfo];
1060 else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1062 /* leave the channel selection like that,
1063 * switch to our "no device" tab */
1064 msg_Dbg( VLCIntf, "eyetv device was removed" );
1065 setEyeTVUnconnected;
1067 else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1069 /* switch to the "launch eyetv" tab */
1070 msg_Dbg( VLCIntf, "eyetv was terminated" );
1071 [self showCaptureView: o_eyetv_notLaunched_view];
1073 else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1075 /* we got no device yet */
1076 msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1077 setEyeTVUnconnected;
1080 msg_Warn( VLCIntf, "unknown external notify '%s' received", [[o_notification name] UTF8String] );
1083 /* little helper method, since this code needs to be run by multiple objects */
1084 - (void)setupChannelInfo
1086 /* set up channel selection */
1087 [o_eyetv_channels_pop removeAllItems];
1088 [o_eyetv_chn_bgbar setHidden: NO];
1089 [o_eyetv_chn_bgbar animate: self];
1090 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1091 [o_eyetv_chn_status_txt setHidden: NO];
1094 NSEnumerator *channels = [[[VLCMain sharedInstance] getEyeTVController] allChannels];
1096 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1098 keyEquivalent: @""] setTag:x++];
1099 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1101 keyEquivalent: @""] setTag:x++];
1105 [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1106 while( channel = [channels nextObject] )
1108 /* we have to add items this way, because we accept duplicates
1109 * additionally, we save a bit of time */
1110 [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1112 keyEquivalent: @""] setTag:++x];
1114 /* make Tuner the default */
1115 [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] getEyeTVController] currentChannel]];
1119 [o_eyetv_chn_bgbar setHidden: YES];
1120 [o_eyetv_chn_status_txt setHidden: YES];
1123 - (IBAction)subsChanged:(id)sender
1125 if ([o_file_sub_ckbox state] == NSOnState)
1127 [o_file_sub_btn_settings setEnabled:YES];
1131 [o_file_sub_btn_settings setEnabled:NO];
1135 - (IBAction)subSettings:(id)sender
1137 [NSApp beginSheet: o_file_sub_sheet
1138 modalForWindow: [sender window]
1140 didEndSelector: NULL
1144 - (IBAction)subCloseSheet:(id)sender
1146 [o_file_sub_sheet orderOut:sender];
1147 [NSApp endSheet: o_file_sub_sheet];
1150 - (IBAction)subFileBrowse:(id)sender
1152 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1154 [o_open_panel setAllowsMultipleSelection: NO];
1155 [o_open_panel setTitle: _NS("Open File")];
1156 [o_open_panel setPrompt: _NS("Open")];
1158 if( [o_open_panel runModalForDirectory: nil
1159 file: nil types: nil] == NSOKButton )
1161 NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
1162 [o_file_sub_path setStringValue: o_filename];
1166 - (IBAction)subOverride:(id)sender
1168 BOOL b_state = [o_file_sub_override state];
1169 [o_file_sub_delay setEnabled: b_state];
1170 [o_file_sub_delay_stp setEnabled: b_state];
1171 [o_file_sub_fps setEnabled: b_state];
1172 [o_file_sub_fps_stp setEnabled: b_state];
1175 - (IBAction)subDelayStepperChanged:(id)sender
1177 [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1180 - (IBAction)subFpsStepperChanged:(id)sender;
1182 [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1185 - (IBAction)panelCancel:(id)sender
1187 [NSApp stopModalWithCode: 0];
1190 - (IBAction)panelOk:(id)sender
1192 if( [[o_mrl stringValue] length] )
1194 [NSApp stopModalWithCode: 1];
1204 @implementation VLCOpenTextField
1206 - (void)mouseDown:(NSEvent *)theEvent
1208 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1210 [super mouseDown: theEvent];