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_screen_follow_mouse_ckb setTitle: _NS("Follow the mouse")];
221 [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
222 [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
223 [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
224 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
225 [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
226 [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
227 [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
228 [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
232 [[NSNotificationCenter defaultCenter] addObserver: self
233 selector: @selector(openFilePathChanged:)
234 name: NSControlTextDidChangeNotification
235 object: o_file_path];
237 [[NSNotificationCenter defaultCenter] addObserver: self
238 selector: @selector(openDiscInfoChanged:)
239 name: NSControlTextDidChangeNotification
240 object: o_disc_device];
241 [[NSNotificationCenter defaultCenter] addObserver: self
242 selector: @selector(openDiscInfoChanged:)
243 name: NSControlTextDidChangeNotification
244 object: o_disc_title];
245 [[NSNotificationCenter defaultCenter] addObserver: self
246 selector: @selector(openDiscInfoChanged:)
247 name: NSControlTextDidChangeNotification
248 object: o_disc_chapter];
249 [[NSNotificationCenter defaultCenter] addObserver: self
250 selector: @selector(openDiscInfoChanged:)
251 name: NSControlTextDidChangeNotification
252 object: o_disc_videots_folder];
254 [[NSNotificationCenter defaultCenter] addObserver: self
255 selector: @selector(openNetInfoChanged:)
256 name: NSControlTextDidChangeNotification
257 object: o_net_udp_port];
258 [[NSNotificationCenter defaultCenter] addObserver: self
259 selector: @selector(openNetInfoChanged:)
260 name: NSControlTextDidChangeNotification
261 object: o_net_udpm_addr];
262 [[NSNotificationCenter defaultCenter] addObserver: self
263 selector: @selector(openNetInfoChanged:)
264 name: NSControlTextDidChangeNotification
265 object: o_net_udpm_port];
266 [[NSNotificationCenter defaultCenter] addObserver: self
267 selector: @selector(openNetInfoChanged:)
268 name: NSControlTextDidChangeNotification
269 object: o_net_http_url];
271 [[NSDistributedNotificationCenter defaultCenter] addObserver: self
272 selector: @selector(eyetvChanged:)
274 object: @"VLCEyeTVSupport"
275 suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
277 [[NSNotificationCenter defaultCenter] addObserver: self
278 selector: @selector(screenFPSfieldChanged:)
279 name: NSControlTextDidChangeNotification
280 object: o_screen_fps_fld];
282 /* register clicks on text fields */
283 [[NSNotificationCenter defaultCenter] addObserver: self
284 selector: @selector(textFieldWasClicked:)
285 name: @"VLCOpenTextFieldWasClicked"
292 module_config_t * p_item;
294 [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
295 [o_file_sub_btn_settings setTitle: _NS("Settings...")];
296 [o_file_sub_btn_browse setTitle: _NS("Browse...")];
297 [o_file_sub_override setTitle: _NS("Override parametters")];
298 [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
299 [o_file_sub_delay_stp setEnabled: NO];
300 [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
301 [o_file_sub_fps_stp setEnabled: NO];
302 [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
303 [o_file_sub_encoding_pop removeAllItems];
304 [o_file_sub_size_lbl setStringValue: _NS("Font size")];
305 [o_file_sub_size_pop removeAllItems];
306 [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
307 [o_file_sub_align_pop removeAllItems];
308 [o_file_sub_ok_btn setStringValue: _NS("OK")];
309 [o_file_sub_font_box setTitle: _NS("Font Properties")];
310 [o_file_sub_file_box setTitle: _NS("Subtitle File")];
312 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
316 for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
319 [o_file_sub_encoding_pop addItemWithTitle:
320 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
322 [o_file_sub_encoding_pop selectItemWithTitle:
323 [NSString stringWithUTF8String: p_item->value.psz]];
326 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
330 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
332 [o_file_sub_align_pop addItemWithTitle:
333 [NSString stringWithUTF8String:
334 p_item->ppsz_list_text[i_index]]];
336 [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
339 p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
343 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
345 [o_file_sub_size_pop addItemWithTitle:
346 [NSString stringWithUTF8String:
347 p_item->ppsz_list_text[i_index]]];
348 if ( p_item->value.i == p_item->pi_list[i_index] )
350 [o_file_sub_size_pop selectItemAtIndex: i_index];
356 - (void)openTarget:(int)i_type
360 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
362 [o_tabview selectTabViewItemAtIndex: i_type];
363 [o_file_sub_ckbox setState: NSOffState];
365 i_result = [NSApp runModalForWindow: o_panel];
370 NSMutableDictionary *o_dic;
371 NSMutableArray *o_options = [NSMutableArray array];
374 o_dic = [NSMutableDictionary dictionaryWithObject: [o_mrl stringValue] forKey: @"ITEM_URL"];
375 if( [o_file_sub_ckbox state] == NSOnState )
377 module_config_t * p_item;
379 [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", [o_file_sub_path stringValue]]];
380 if( [o_file_sub_override state] == NSOnState )
382 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
383 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
385 [o_options addObject: [NSString stringWithFormat:
386 @"subsdec-encoding=%@",
387 [o_file_sub_encoding_pop titleOfSelectedItem]]];
388 [o_options addObject: [NSString stringWithFormat:
390 [o_file_sub_align_pop indexOfSelectedItem]]];
392 p_item = config_FindConfig( VLC_OBJECT(p_intf),
393 "freetype-rel-fontsize" );
397 [o_options addObject: [NSString stringWithFormat:
398 @"freetype-rel-fontsize=%i",
399 p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
402 if( [o_output_ckbox state] == NSOnState )
404 for (i = 0 ; i < [[o_sout_options mrl] count] ; i++)
406 [o_options addObject: [NSString stringWithString:
407 [[(VLCOutput *)o_sout_options mrl] objectAtIndex: i]]];
410 if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
412 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
413 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
414 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
415 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
416 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
417 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
418 if( [o_screen_follow_mouse_ckb intValue] == YES )
419 [o_options addObject: @"screen-follow-mouse"];
421 [o_options addObject: @"no-screen-follow-mouse"];
424 /* apply the options to our item(s) */
425 [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
427 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
429 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
433 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
435 NSString *o_label = [o_tvi label];
437 if( [o_label isEqualToString: _NS("File")] )
439 [self openFilePathChanged: nil];
441 else if( [o_label isEqualToString: _NS("Disc")] )
443 [self openDiscTypeChanged: nil];
445 else if( [o_label isEqualToString: _NS("Network")] )
447 [self openNetInfoChanged: nil];
449 else if( [o_label isEqualToString: _NS("Capture")] )
451 [self openCaptureModeChanged: nil];
455 - (IBAction)expandMRLfieldAction:(id)sender
457 NSRect o_win_rect, o_view_rect;
458 o_win_rect = [o_panel frame];
459 o_view_rect = [o_mrl_view frame];
461 if( [o_mrl_btn state] == NSOffState )
463 /* we need to collaps, restore the panel size */
464 o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
465 o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
467 /* remove the MRL view */
468 [o_mrl_view removeFromSuperviewWithoutNeedingDisplay];
470 /* we need to expand */
471 [o_mrl_view setFrame: NSMakeRect( 0,
472 [o_mrl_btn frame].origin.y,
473 o_view_rect.size.width,
474 o_view_rect.size.height )];
475 [o_mrl_view setNeedsDisplay: YES];
476 [o_mrl_view setAutoresizesSubviews: YES];
478 /* add the MRL view */
479 [[o_panel contentView] addSubview: o_mrl_view];
480 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
483 [o_panel setFrame: o_win_rect display:YES animate: YES];
484 [o_panel displayIfNeeded];
487 - (void)openFileGeneric
489 [self openFilePathChanged: nil];
490 [self openTarget: 0];
495 [self openDiscTypeChanged: nil];
496 [self openTarget: 1];
501 [self openNetInfoChanged: nil];
502 [self openTarget: 2];
507 [self openCaptureModeChanged: nil];
508 [self showCaptureView: o_capture_label_view];
509 [self openTarget: 3];
512 - (void)openFilePathChanged:(NSNotification *)o_notification
514 NSString *o_mrl_string;
515 NSString *o_filename = [o_file_path stringValue];
516 NSString *o_ext = [o_filename pathExtension];
517 bool b_stream = [o_file_stream state];
520 [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
524 o_mrl_string = [NSString stringWithFormat: @"directory://%@/", o_filename];
526 else if( [o_ext isEqualToString: @"bin"] ||
527 [o_ext isEqualToString: @"cue"] ||
528 [o_ext isEqualToString: @"vob"] ||
529 [o_ext isEqualToString: @"iso"] )
531 o_mrl_string = o_filename;
535 o_mrl_string = [NSString stringWithFormat: @"%s://%@",
536 b_stream ? "stream" : "file",
539 [o_mrl setStringValue: o_mrl_string];
542 - (IBAction)openFileBrowse:(id)sender
544 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
546 [o_open_panel setAllowsMultipleSelection: NO];
547 [o_open_panel setCanChooseDirectories: YES];
548 [o_open_panel setTitle: _NS("Open File")];
549 [o_open_panel setPrompt: _NS("Open")];
551 [o_open_panel beginSheetForDirectory:nil
554 modalForWindow:[sender window]
556 didEndSelector: @selector(pathChosenInPanel:
562 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void *)contextInfo
564 if (returnCode == NSFileHandlingPanelOKButton)
566 NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
567 [o_file_path setStringValue: o_filename];
568 [self openFilePathChanged: nil];
572 - (IBAction)openFileStreamChanged:(id)sender
574 [self openFilePathChanged: nil];
577 - (IBAction)openDiscTypeChanged:(id)sender
580 BOOL b_device, b_no_menus, b_title_chapter;
582 [o_disc_device removeAllItems];
583 b_title_chapter = ![o_disc_dvd_menus state];
585 o_type = [[o_disc_type selectedCell] title];
587 if ( [o_type isEqualToString: _NS("VIDEO_TS folder")] )
589 b_device = NO; b_no_menus = YES;
595 const char *psz_class = NULL;
598 if ( [o_type isEqualToString: _NS("VCD")] )
600 psz_class = kIOCDMediaClass;
602 b_no_menus = NO; b_title_chapter = YES;
604 else if ( [o_type isEqualToString: _NS("Audio CD")])
606 psz_class = kIOCDMediaClass;
608 b_no_menus = NO; b_title_chapter = NO;
612 psz_class = kIODVDMediaClass;
617 o_devices = GetEjectableMediaOfClass( psz_class );
618 if ( o_devices != nil )
620 int i_devices = [o_devices count];
624 for( int i = 0; i < i_devices; i++ )
627 addItemWithObjectValue: [o_devices objectAtIndex: i]];
630 [o_disc_device selectItemAtIndex: 0];
634 [o_disc_device setStringValue:
635 [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
640 [o_disc_device setEnabled: b_device];
641 [o_disc_title setEnabled: b_title_chapter];
642 [o_disc_title_stp setEnabled: b_title_chapter];
643 [o_disc_chapter setEnabled: b_title_chapter];
644 [o_disc_chapter_stp setEnabled: b_title_chapter];
645 [o_disc_videots_folder setEnabled: !b_device];
646 [o_disc_videots_btn_browse setEnabled: !b_device];
647 [o_disc_dvd_menus setEnabled: b_no_menus];
649 [self openDiscInfoChanged: nil];
652 - (IBAction)openDiscStepperChanged:(id)sender
654 int i_tag = [sender tag];
658 [o_disc_title setIntValue: [o_disc_title_stp intValue]];
660 else if( i_tag == 1 )
662 [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
665 [self openDiscInfoChanged: nil];
668 - (void)openDiscInfoChanged:(NSNotification *)o_notification
673 NSString *o_mrl_string;
674 int i_title, i_chapter;
677 o_type = [[o_disc_type selectedCell] title];
678 o_device = [o_disc_device stringValue];
679 i_title = [o_disc_title intValue];
680 i_chapter = [o_disc_chapter intValue];
681 o_videots = [o_disc_videots_folder stringValue];
682 b_no_menus = [o_disc_dvd_menus state];
684 if ( [o_type isEqualToString: _NS("VCD")] )
686 if ( [o_device isEqualToString:
687 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
689 o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i:%i",
690 o_device, i_title, i_chapter];
692 else if ( [o_type isEqualToString: _NS("Audio CD")] )
694 if ( [o_device isEqualToString:
695 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
697 o_mrl_string = [NSString stringWithFormat: @"cdda://%@",
700 else if ( [o_type isEqualToString: _NS("DVD")] )
702 if ( [o_device isEqualToString:
703 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
706 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i-",
707 o_device, i_title, i_chapter];
709 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
713 else /* VIDEO_TS folder */
716 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
717 o_videots, i_title, i_chapter];
719 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
723 [o_mrl setStringValue: o_mrl_string];
726 - (IBAction)openDiscMenusChanged:(id)sender
728 [self openDiscInfoChanged: nil];
729 [self openDiscTypeChanged: nil];
732 - (IBAction)openVTSBrowse:(id)sender
734 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
736 [o_open_panel setAllowsMultipleSelection: NO];
737 [o_open_panel setCanChooseFiles: NO];
738 [o_open_panel setCanChooseDirectories: YES];
739 [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
740 [o_open_panel setPrompt: _NS("Open")];
742 if( [o_open_panel runModalForDirectory: nil
743 file: nil types: nil] == NSOKButton )
745 NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
746 [o_disc_videots_folder setStringValue: o_dirname];
747 [self openDiscInfoChanged: nil];
751 - (void)textFieldWasClicked:(NSNotification *)o_notification
753 if( [o_notification object] == o_net_udp_port )
754 [o_net_mode selectCellAtRow: 0 column: 0];
755 else if( [o_notification object] == o_net_udpm_addr ||
756 [o_notification object] == o_net_udpm_port )
757 [o_net_mode selectCellAtRow: 1 column: 0];
759 [o_net_mode selectCellAtRow: 2 column: 0];
761 [self openNetInfoChanged: nil];
764 - (IBAction)openNetModeChanged:(id)sender
766 if( sender == o_net_mode )
768 if( [[sender selectedCell] tag] == 0 )
769 [o_panel makeFirstResponder: o_net_udp_port];
770 else if ( [[sender selectedCell] tag] == 1 )
771 [o_panel makeFirstResponder: o_net_udpm_addr];
773 msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
776 [self openNetInfoChanged: nil];
779 - (IBAction)openNetStepperChanged:(id)sender
781 int i_tag = [sender tag];
785 [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
786 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
787 object: o_net_udp_port];
788 [o_panel makeFirstResponder: o_net_udp_port];
790 else if( i_tag == 1 )
792 [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
793 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
794 object: o_net_udpm_port];
795 [o_panel makeFirstResponder: o_net_udpm_port];
798 [self openNetInfoChanged: nil];
801 - (void)openNetInfoChanged:(NSNotification *)o_notification
803 NSString *o_mrl_string = [NSString string];
805 if( [o_net_udp_panel isVisible] )
808 o_mode = [[o_net_mode selectedCell] title];
810 if( [o_mode isEqualToString: _NS("Unicast")] )
812 int i_port = [o_net_udp_port intValue];
814 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
815 o_mrl_string = [NSString stringWithString: @"udp://"];
817 o_mrl_string = [NSString stringWithString: @"rtp://"];
819 if( i_port != config_GetInt( p_intf, "server-port" ) )
822 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
825 else if( [o_mode isEqualToString: _NS("Multicast")] )
827 NSString *o_addr = [o_net_udpm_addr stringValue];
828 int i_port = [o_net_udpm_port intValue];
830 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
831 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
833 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
835 if( i_port != config_GetInt( p_intf, "server-port" ) )
838 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
844 NSString *o_url = [o_net_http_url stringValue];
846 if ( ![o_url hasPrefix:@"http:"] && ![o_url hasPrefix:@"ftp:"]
847 && ![o_url hasPrefix:@"mms"] && ![o_url hasPrefix:@"rtsp"] )
848 o_mrl_string = [NSString stringWithFormat: @"http://%@", o_url];
850 o_mrl_string = o_url;
852 [o_mrl setStringValue: o_mrl_string];
855 - (IBAction)openNetUDPButtonAction:(id)sender
857 if( sender == o_net_openUDP_btn )
859 [NSApp beginSheet: o_net_udp_panel
860 modalForWindow: o_panel
864 [self openNetInfoChanged: nil];
866 else if( sender == o_net_udp_cancel_btn )
868 [o_net_udp_panel orderOut: sender];
869 [NSApp endSheet: o_net_udp_panel];
871 else if( sender == o_net_udp_ok_btn )
873 NSString *o_mrl_string = [NSString string];
874 if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
876 int i_port = [o_net_udp_port intValue];
878 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
879 o_mrl_string = [NSString stringWithString: @"udp://"];
881 o_mrl_string = [NSString stringWithString: @"rtp://"];
883 if( i_port != config_GetInt( p_intf, "server-port" ) )
886 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
889 else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
891 NSString *o_addr = [o_net_udpm_addr stringValue];
892 int i_port = [o_net_udpm_port intValue];
894 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
895 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
897 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
899 if( i_port != config_GetInt( p_intf, "server-port" ) )
902 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
905 [o_mrl setStringValue: o_mrl_string];
906 [o_net_http_url setStringValue: o_mrl_string];
907 [o_net_udp_panel orderOut: sender];
908 [NSApp endSheet: o_net_udp_panel];
914 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
916 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
918 [o_open_panel setAllowsMultipleSelection: YES];
919 [o_open_panel setCanChooseDirectories: YES];
920 [o_open_panel setTitle: _NS("Open File")];
921 [o_open_panel setPrompt: _NS("Open")];
923 if( [o_open_panel runModalForDirectory: nil
924 file: nil types: nil] == NSOKButton )
926 NSArray *o_array = [NSArray array];
927 NSArray *o_values = [[o_open_panel filenames]
928 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
930 for( i = 0; i < (int)[o_values count]; i++)
933 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
934 o_array = [o_array arrayByAddingObject: o_dic];
937 [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
939 [o_playlist appendArray: o_array atPos: -1 enqueue:YES];
943 - (void)showCaptureView: theView
946 o_view_rect = [theView frame];
947 if( o_currentCaptureView )
949 [o_currentCaptureView removeFromSuperviewWithoutNeedingDisplay];
950 [o_currentCaptureView release];
952 [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
953 [theView setNeedsDisplay: YES];
954 [theView setAutoresizesSubviews: YES];
955 [[[o_tabview tabViewItemAtIndex: 3] view] addSubview: theView];
956 [theView displayIfNeeded];
957 o_currentCaptureView = theView;
958 [o_currentCaptureView retain];
961 - (IBAction)openCaptureModeChanged:(id)sender
963 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
965 if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
967 if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
969 [self showCaptureView: o_eyetv_running_view];
970 [self setupChannelInfo];
978 [self showCaptureView: o_eyetv_notLaunched_view];
979 [o_mrl setStringValue: @""];
981 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
983 [self showCaptureView: o_screen_view];
984 [o_mrl setStringValue: @"screen://"];
985 [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
986 [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
987 [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
988 [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
989 [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
990 [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
992 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"iSight"] )
994 [o_capture_lbl setStringValue: _NS("iSight Capture Input")];
995 [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.")];
996 [o_capture_lbl displayIfNeeded];
997 [o_capture_long_lbl displayIfNeeded];
999 [self showCaptureView: o_capture_label_view];
1000 [o_mrl setStringValue: @"qtcapture://"];
1004 - (IBAction)screenStepperChanged:(id)sender
1006 [o_screen_fps_fld setFloatValue: [o_screen_fps_stp floatValue]];
1007 [o_panel makeFirstResponder: o_screen_fps_fld];
1008 [o_mrl setStringValue: @"screen://"];
1011 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1013 [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1014 if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1015 [o_screen_fps_fld setFloatValue: 1.0];
1016 [o_mrl setStringValue: @"screen://"];
1019 - (IBAction)eyetvSwitchChannel:(id)sender
1021 if( sender == o_eyetv_nextProgram_btn )
1023 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1024 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1025 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1027 else if( sender == o_eyetv_previousProgram_btn )
1029 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1030 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1031 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1033 else if( sender == o_eyetv_channels_pop )
1035 int chanNum = [[sender selectedItem] tag];
1036 [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1037 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1040 msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1043 - (IBAction)eyetvLaunch:(id)sender
1045 [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1048 - (IBAction)eyetvGetPlugin:(id)sender
1050 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1053 - (void)eyetvChanged:(NSNotification *)o_notification
1055 if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1057 msg_Dbg( VLCIntf, "eyetv device was added" );
1058 [self showCaptureView: o_eyetv_running_view];
1059 [self setupChannelInfo];
1061 else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1063 /* leave the channel selection like that,
1064 * switch to our "no device" tab */
1065 msg_Dbg( VLCIntf, "eyetv device was removed" );
1066 setEyeTVUnconnected;
1068 else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1070 /* switch to the "launch eyetv" tab */
1071 msg_Dbg( VLCIntf, "eyetv was terminated" );
1072 [self showCaptureView: o_eyetv_notLaunched_view];
1074 else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1076 /* we got no device yet */
1077 msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1078 setEyeTVUnconnected;
1081 msg_Warn( VLCIntf, "unknown external notify '%s' received", [[o_notification name] UTF8String] );
1084 /* little helper method, since this code needs to be run by multiple objects */
1085 - (void)setupChannelInfo
1087 /* set up channel selection */
1088 [o_eyetv_channels_pop removeAllItems];
1089 [o_eyetv_chn_bgbar setHidden: NO];
1090 [o_eyetv_chn_bgbar animate: self];
1091 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1092 [o_eyetv_chn_status_txt setHidden: NO];
1095 NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1097 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1099 keyEquivalent: @""] setTag:x++];
1100 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1102 keyEquivalent: @""] setTag:x++];
1106 [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1107 while( channel = [channels nextObject] )
1109 /* we have to add items this way, because we accept duplicates
1110 * additionally, we save a bit of time */
1111 [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1113 keyEquivalent: @""] setTag:++x];
1115 /* make Tuner the default */
1116 [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1120 [o_eyetv_chn_bgbar setHidden: YES];
1121 [o_eyetv_chn_status_txt setHidden: YES];
1124 - (IBAction)subsChanged:(id)sender
1126 if ([o_file_sub_ckbox state] == NSOnState)
1128 [o_file_sub_btn_settings setEnabled:YES];
1132 [o_file_sub_btn_settings setEnabled:NO];
1136 - (IBAction)subSettings:(id)sender
1138 [NSApp beginSheet: o_file_sub_sheet
1139 modalForWindow: [sender window]
1141 didEndSelector: NULL
1145 - (IBAction)subCloseSheet:(id)sender
1147 [o_file_sub_sheet orderOut:sender];
1148 [NSApp endSheet: o_file_sub_sheet];
1151 - (IBAction)subFileBrowse:(id)sender
1153 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1155 [o_open_panel setAllowsMultipleSelection: NO];
1156 [o_open_panel setTitle: _NS("Open File")];
1157 [o_open_panel setPrompt: _NS("Open")];
1159 if( [o_open_panel runModalForDirectory: nil
1160 file: nil types: nil] == NSOKButton )
1162 NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
1163 [o_file_sub_path setStringValue: o_filename];
1167 - (IBAction)subOverride:(id)sender
1169 BOOL b_state = [o_file_sub_override state];
1170 [o_file_sub_delay setEnabled: b_state];
1171 [o_file_sub_delay_stp setEnabled: b_state];
1172 [o_file_sub_fps setEnabled: b_state];
1173 [o_file_sub_fps_stp setEnabled: b_state];
1176 - (IBAction)subDelayStepperChanged:(id)sender
1178 [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1181 - (IBAction)subFpsStepperChanged:(id)sender;
1183 [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1186 - (IBAction)panelCancel:(id)sender
1188 [NSApp stopModalWithCode: 0];
1191 - (IBAction)panelOk:(id)sender
1193 if( [[o_mrl stringValue] length] )
1195 [NSApp stopModalWithCode: 1];
1205 @implementation VLCOpenTextField
1207 - (void)mouseDown:(NSEvent *)theEvent
1209 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1211 [super mouseDown: theEvent];