1 /*****************************************************************************
2 * open.m: MacOS X module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2008 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 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];
157 return _o_sharedMainInstance;
162 intf_thread_t * p_intf = VLCIntf;
164 [o_panel setTitle: _NS("Open Source")];
165 [o_mrl_lbl setTitle: _NS("Media Resource Locator (MRL)")];
167 [o_btn_ok setTitle: _NS("OK")];
168 [o_btn_cancel setTitle: _NS("Cancel")];
170 [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
171 [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
172 [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
173 [[o_tabview tabViewItemAtIndex: 3] setLabel: _NS("Capture")];
175 [o_file_btn_browse setTitle: _NS("Browse...")];
176 [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
178 [o_disc_device_lbl setStringValue: _NS("Device name")];
179 [o_disc_title_lbl setStringValue: _NS("Title")];
180 [o_disc_chapter_lbl setStringValue: _NS("Chapter")];
181 [o_disc_videots_btn_browse setTitle: _NS("Browse...")];
182 [o_disc_dvd_menus setTitle: _NS("No DVD menus")];
184 [[o_disc_type cellAtRow:0 column:0] setTitle: _NS("VIDEO_TS directory")];
185 [[o_disc_type cellAtRow:1 column:0] setTitle: _NS("DVD")];
186 [[o_disc_type cellAtRow:2 column:0] setTitle: _NS("VCD")];
187 [[o_disc_type cellAtRow:3 column:0] setTitle: _NS("Audio CD")];
189 [o_net_udp_port_lbl setStringValue: _NS("Port")];
190 [o_net_udpm_addr_lbl setStringValue: _NS("Address")];
191 [o_net_udpm_port_lbl setStringValue: _NS("Port")];
192 [o_net_http_url_lbl setStringValue: _NS("URL")];
194 [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("UDP/RTP")];
195 [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("UDP/RTP Multicast")];
196 [[o_net_mode cellAtRow:2 column:0] setTitle: _NS("HTTP/FTP/MMS/RTSP")];
197 [o_net_timeshift_ckbox setTitle: _NS("Allow timeshifting")];
199 [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
200 [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
202 [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
204 [o_capture_mode_pop removeAllItems];
205 if( MACOS_VERSION > 10.4f )
206 [o_capture_mode_pop addItemWithTitle: @"iSight"];
207 [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
208 [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
209 [o_screen_lbl setStringValue: _NS("Screen Capture Input")];
210 [o_screen_long_lbl setStringValue: _NS("This facility allows you to process your screen's output.")];
211 [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
212 [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
213 [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
214 [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
215 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
216 [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
217 [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
218 [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
219 [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
223 [[NSNotificationCenter defaultCenter] addObserver: self
224 selector: @selector(openFilePathChanged:)
225 name: NSControlTextDidChangeNotification
226 object: o_file_path];
228 [[NSNotificationCenter defaultCenter] addObserver: self
229 selector: @selector(openDiscInfoChanged:)
230 name: NSControlTextDidChangeNotification
231 object: o_disc_device];
232 [[NSNotificationCenter defaultCenter] addObserver: self
233 selector: @selector(openDiscInfoChanged:)
234 name: NSControlTextDidChangeNotification
235 object: o_disc_title];
236 [[NSNotificationCenter defaultCenter] addObserver: self
237 selector: @selector(openDiscInfoChanged:)
238 name: NSControlTextDidChangeNotification
239 object: o_disc_chapter];
240 [[NSNotificationCenter defaultCenter] addObserver: self
241 selector: @selector(openDiscInfoChanged:)
242 name: NSControlTextDidChangeNotification
243 object: o_disc_videots_folder];
245 [[NSNotificationCenter defaultCenter] addObserver: self
246 selector: @selector(openNetInfoChanged:)
247 name: NSControlTextDidChangeNotification
248 object: o_net_udp_port];
249 [[NSNotificationCenter defaultCenter] addObserver: self
250 selector: @selector(openNetInfoChanged:)
251 name: NSControlTextDidChangeNotification
252 object: o_net_udpm_addr];
253 [[NSNotificationCenter defaultCenter] addObserver: self
254 selector: @selector(openNetInfoChanged:)
255 name: NSControlTextDidChangeNotification
256 object: o_net_udpm_port];
257 [[NSNotificationCenter defaultCenter] addObserver: self
258 selector: @selector(openNetInfoChanged:)
259 name: NSControlTextDidChangeNotification
260 object: o_net_http_url];
262 [[NSDistributedNotificationCenter defaultCenter] addObserver: self
263 selector: @selector(eyetvChanged:)
265 object: @"VLCEyeTVSupport"
266 suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
268 [[NSNotificationCenter defaultCenter] addObserver: self
269 selector: @selector(screenFPSfieldChanged:)
270 name: NSControlTextDidChangeNotification
271 object: o_screen_fps_fld];
273 /* register clicks on text fields */
274 [[NSNotificationCenter defaultCenter] addObserver: self
275 selector: @selector(textFieldWasClicked:)
276 name: @"VLCOpenTextFieldWasClicked"
282 intf_thread_t * p_intf = VLCIntf;
284 module_config_t * p_item;
286 [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
287 [o_file_sub_btn_settings setTitle: _NS("Settings...")];
288 [o_file_sub_btn_browse setTitle: _NS("Browse...")];
289 [o_file_sub_override setTitle: _NS("Override parametters")];
290 [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
291 [o_file_sub_delay_stp setEnabled: NO];
292 [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
293 [o_file_sub_fps_stp setEnabled: NO];
294 [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
295 [o_file_sub_encoding_pop removeAllItems];
296 [o_file_sub_size_lbl setStringValue: _NS("Font size")];
297 [o_file_sub_size_pop removeAllItems];
298 [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
299 [o_file_sub_align_pop removeAllItems];
300 [o_file_sub_ok_btn setStringValue: _NS("OK")];
301 [o_file_sub_font_box setTitle: _NS("Font Properties")];
302 [o_file_sub_file_box setTitle: _NS("Subtitle File")];
304 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
308 for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
311 [o_file_sub_encoding_pop addItemWithTitle:
312 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
314 [o_file_sub_encoding_pop selectItemWithTitle:
315 [NSString stringWithUTF8String: p_item->value.psz]];
318 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
322 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
324 [o_file_sub_align_pop addItemWithTitle:
325 [NSString stringWithUTF8String:
326 p_item->ppsz_list_text[i_index]]];
328 [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
331 p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
335 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
337 [o_file_sub_size_pop addItemWithTitle:
338 [NSString stringWithUTF8String:
339 p_item->ppsz_list_text[i_index]]];
340 if ( p_item->value.i == p_item->pi_list[i_index] )
342 [o_file_sub_size_pop selectItemAtIndex: i_index];
348 - (void)openTarget:(int)i_type
351 intf_thread_t * p_intf = VLCIntf;
353 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
355 [o_tabview selectTabViewItemAtIndex: i_type];
356 [o_file_sub_ckbox setState: NSOffState];
358 i_result = [NSApp runModalForWindow: o_panel];
363 NSMutableDictionary *o_dic;
364 NSMutableArray *o_options = [NSMutableArray array];
367 o_dic = [NSMutableDictionary dictionaryWithObject: [o_mrl stringValue] forKey: @"ITEM_URL"];
368 if( [o_file_sub_ckbox state] == NSOnState )
370 module_config_t * p_item;
372 [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", [o_file_sub_path stringValue]]];
373 if( [o_file_sub_override state] == NSOnState )
375 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
376 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
378 [o_options addObject: [NSString stringWithFormat:
379 @"subsdec-encoding=%@",
380 [o_file_sub_encoding_pop titleOfSelectedItem]]];
381 [o_options addObject: [NSString stringWithFormat:
383 [o_file_sub_align_pop indexOfSelectedItem]]];
385 p_item = config_FindConfig( VLC_OBJECT(p_intf),
386 "freetype-rel-fontsize" );
390 [o_options addObject: [NSString stringWithFormat:
391 @"freetype-rel-fontsize=%i",
392 p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
395 if( [o_output_ckbox state] == NSOnState )
397 for (i = 0 ; i < [[o_sout_options getMRL] count] ; i++)
399 [o_options addObject: [NSString stringWithString:
400 [[(VLCOutput *)o_sout_options getMRL] objectAtIndex: i]]];
403 if( [o_net_timeshift_ckbox state] == NSOnState )
405 [o_options addObject: [NSString stringWithString:
406 @"access-filter=timeshift"]];
408 [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
410 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
412 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
416 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
418 NSString *o_label = [o_tvi label];
420 if( [o_label isEqualToString: _NS("File")] )
422 [self openFilePathChanged: nil];
424 else if( [o_label isEqualToString: _NS("Disc")] )
426 [self openDiscTypeChanged: nil];
428 else if( [o_label isEqualToString: _NS("Network")] )
430 [self openNetInfoChanged: nil];
432 else if( [o_label isEqualToString: _NS("Capture")] )
434 [self openCaptureModeChanged: nil];
438 - (void)openFileGeneric
440 [self openFilePathChanged: nil];
441 [self openTarget: 0];
446 [self openDiscTypeChanged: nil];
447 [self openTarget: 1];
452 [self openNetInfoChanged: nil];
453 [self openTarget: 2];
458 [self openCaptureModeChanged: nil];
459 [self showCaptureView: o_capture_label_view];
460 [self openTarget: 3];
463 - (void)openFilePathChanged:(NSNotification *)o_notification
465 NSString *o_mrl_string;
466 NSString *o_filename = [o_file_path stringValue];
467 NSString *o_ext = [o_filename pathExtension];
468 bool b_stream = [o_file_stream state];
471 [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
475 o_mrl_string = [NSString stringWithFormat: @"directory://%@", o_filename];
477 else if( [o_ext isEqualToString: @"bin"] ||
478 [o_ext isEqualToString: @"cue"] ||
479 [o_ext isEqualToString: @"vob"] ||
480 [o_ext isEqualToString: @"iso"] )
482 o_mrl_string = o_filename;
486 o_mrl_string = [NSString stringWithFormat: @"%s://%@",
487 b_stream ? "stream" : "file",
490 [o_mrl setStringValue: o_mrl_string];
493 - (IBAction)openFileBrowse:(id)sender
495 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
497 [o_open_panel setAllowsMultipleSelection: NO];
498 [o_open_panel setCanChooseDirectories: YES];
499 [o_open_panel setTitle: _NS("Open File")];
500 [o_open_panel setPrompt: _NS("Open")];
502 [o_open_panel beginSheetForDirectory:nil
505 modalForWindow:[sender window]
507 didEndSelector: @selector(pathChosenInPanel:
513 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void *)contextInfo
515 if (returnCode == NSFileHandlingPanelOKButton)
517 NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
518 [o_file_path setStringValue: o_filename];
519 [self openFilePathChanged: nil];
523 - (IBAction)openFileStreamChanged:(id)sender
525 [self openFilePathChanged: nil];
528 - (IBAction)openDiscTypeChanged:(id)sender
531 BOOL b_device, b_no_menus, b_title_chapter;
533 [o_disc_device removeAllItems];
534 b_title_chapter = ![o_disc_dvd_menus state];
536 o_type = [[o_disc_type selectedCell] title];
538 if ( [o_type isEqualToString: _NS("VIDEO_TS directory")] )
540 b_device = NO; b_no_menus = YES;
546 const char *psz_class = NULL;
549 if ( [o_type isEqualToString: _NS("VCD")] )
551 psz_class = kIOCDMediaClass;
553 b_no_menus = NO; b_title_chapter = YES;
555 else if ( [o_type isEqualToString: _NS("Audio CD")])
557 psz_class = kIOCDMediaClass;
559 b_no_menus = NO; b_title_chapter = NO;
563 psz_class = kIODVDMediaClass;
568 o_devices = GetEjectableMediaOfClass( psz_class );
569 if ( o_devices != nil )
571 int i_devices = [o_devices count];
575 for( int i = 0; i < i_devices; i++ )
578 addItemWithObjectValue: [o_devices objectAtIndex: i]];
581 [o_disc_device selectItemAtIndex: 0];
585 [o_disc_device setStringValue:
586 [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
591 [o_disc_device setEnabled: b_device];
592 [o_disc_title setEnabled: b_title_chapter];
593 [o_disc_title_stp setEnabled: b_title_chapter];
594 [o_disc_chapter setEnabled: b_title_chapter];
595 [o_disc_chapter_stp setEnabled: b_title_chapter];
596 [o_disc_videots_folder setEnabled: !b_device];
597 [o_disc_videots_btn_browse setEnabled: !b_device];
598 [o_disc_dvd_menus setEnabled: b_no_menus];
600 [self openDiscInfoChanged: nil];
603 - (IBAction)openDiscStepperChanged:(id)sender
605 int i_tag = [sender tag];
609 [o_disc_title setIntValue: [o_disc_title_stp intValue]];
611 else if( i_tag == 1 )
613 [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
616 [self openDiscInfoChanged: nil];
619 - (void)openDiscInfoChanged:(NSNotification *)o_notification
624 NSString *o_mrl_string;
625 int i_title, i_chapter;
628 o_type = [[o_disc_type selectedCell] title];
629 o_device = [o_disc_device stringValue];
630 i_title = [o_disc_title intValue];
631 i_chapter = [o_disc_chapter intValue];
632 o_videots = [o_disc_videots_folder stringValue];
633 b_no_menus = [o_disc_dvd_menus state];
635 if ( [o_type isEqualToString: _NS("VCD")] )
637 if ( [o_device isEqualToString:
638 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
640 o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i:%i",
641 o_device, i_title, i_chapter];
643 else if ( [o_type isEqualToString: _NS("Audio CD")] )
645 if ( [o_device isEqualToString:
646 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
648 o_mrl_string = [NSString stringWithFormat: @"cdda://%@",
651 else if ( [o_type isEqualToString: _NS("DVD")] )
653 if ( [o_device isEqualToString:
654 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
657 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i-",
658 o_device, i_title, i_chapter];
660 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
664 else /* VIDEO_TS folder */
667 o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
668 o_videots, i_title, i_chapter];
670 o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
674 [o_mrl setStringValue: o_mrl_string];
677 - (IBAction)openDiscMenusChanged:(id)sender
679 [self openDiscInfoChanged: nil];
680 [self openDiscTypeChanged: nil];
683 - (IBAction)openVTSBrowse:(id)sender
685 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
687 [o_open_panel setAllowsMultipleSelection: NO];
688 [o_open_panel setCanChooseFiles: NO];
689 [o_open_panel setCanChooseDirectories: YES];
690 [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
691 [o_open_panel setPrompt: _NS("Open")];
693 if( [o_open_panel runModalForDirectory: nil
694 file: nil types: nil] == NSOKButton )
696 NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
697 [o_disc_videots_folder setStringValue: o_dirname];
698 [self openDiscInfoChanged: nil];
702 - (void)textFieldWasClicked:(NSNotification *)o_notification
704 if( [o_notification object] == o_net_udp_port )
705 [o_net_mode selectCellAtRow: 0 column: 0];
706 else if( [o_notification object] == o_net_udpm_addr ||
707 [o_notification object] == o_net_udpm_port )
708 [o_net_mode selectCellAtRow: 1 column: 0];
710 [o_net_mode selectCellAtRow: 2 column: 0];
712 [self openNetInfoChanged: nil];
715 - (IBAction)openNetModeChanged:(id)sender
717 if( [[sender selectedCell] tag] == 0 )
718 [o_panel makeFirstResponder: o_net_udp_port];
719 else if ( [[sender selectedCell] tag] == 1 )
720 [o_panel makeFirstResponder: o_net_udpm_addr];
722 [o_panel makeFirstResponder: o_net_http_url];
724 [self openNetInfoChanged: nil];
727 - (IBAction)openNetStepperChanged:(id)sender
729 int i_tag = [sender tag];
733 [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
734 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
735 object: o_net_udp_port];
736 [o_panel makeFirstResponder: o_net_udp_port];
738 else if( i_tag == 1 )
740 [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
741 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
742 object: o_net_udpm_port];
743 [o_panel makeFirstResponder: o_net_udpm_port];
746 [self openNetInfoChanged: nil];
749 - (void)openNetInfoChanged:(NSNotification *)o_notification
752 NSString *o_mrl_string = [NSString string];
753 intf_thread_t * p_intf = VLCIntf;
755 o_mode = [[o_net_mode selectedCell] title];
757 if( [o_mode isEqualToString: _NS("UDP/RTP")] )
759 int i_port = [o_net_udp_port intValue];
761 o_mrl_string = [NSString stringWithString: @"udp://"];
763 if( i_port != config_GetInt( p_intf, "server-port" ) )
766 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
769 else if( [o_mode isEqualToString: _NS("UDP/RTP Multicast")] )
771 NSString *o_addr = [o_net_udpm_addr stringValue];
772 int i_port = [o_net_udpm_port intValue];
774 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
776 if( i_port != config_GetInt( p_intf, "server-port" ) )
779 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
782 else if( [o_mode isEqualToString: _NS("HTTP/FTP/MMS/RTSP")] )
784 NSString *o_url = [o_net_http_url stringValue];
786 if ( ![o_url hasPrefix:@"http:"] && ![o_url hasPrefix:@"ftp:"]
787 && ![o_url hasPrefix:@"mms"] && ![o_url hasPrefix:@"rtsp"] )
788 o_mrl_string = [NSString stringWithFormat: @"http://%@", o_url];
790 o_mrl_string = o_url;
792 [o_mrl setStringValue: o_mrl_string];
797 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
799 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
801 [o_open_panel setAllowsMultipleSelection: YES];
802 [o_open_panel setCanChooseDirectories: YES];
803 [o_open_panel setTitle: _NS("Open File")];
804 [o_open_panel setPrompt: _NS("Open")];
806 if( [o_open_panel runModalForDirectory: nil
807 file: nil types: nil] == NSOKButton )
809 NSArray *o_array = [NSArray array];
810 NSArray *o_values = [[o_open_panel filenames]
811 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
813 for( i = 0; i < (int)[o_values count]; i++)
816 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
817 o_array = [o_array arrayByAddingObject: o_dic];
820 [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
822 [o_playlist appendArray: o_array atPos: -1 enqueue:YES];
826 - (void)showCaptureView: theView
829 o_view_rect = [theView frame];
830 if( o_currentCaptureView )
832 [o_currentCaptureView removeFromSuperviewWithoutNeedingDisplay];
833 [o_currentCaptureView release];
835 [theView setFrame: NSMakeRect( 0, 10, o_view_rect.size.width, o_view_rect.size.height)];
836 [theView setNeedsDisplay: YES];
837 [theView setAutoresizesSubviews: YES];
838 [[[o_tabview tabViewItemAtIndex: 3] view] addSubview: theView];
839 [theView displayIfNeeded];
840 o_currentCaptureView = theView;
841 [o_currentCaptureView retain];
844 - (IBAction)openCaptureModeChanged:(id)sender
846 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
848 if( [[[VLCMain sharedInstance] getEyeTVController] isEyeTVrunning] == YES )
850 if( [[[VLCMain sharedInstance] getEyeTVController] isDeviceConnected] == YES )
852 [self showCaptureView: o_eyetv_running_view];
853 [self setupChannelInfo];
861 [self showCaptureView: o_eyetv_notLaunched_view];
862 [o_mrl setStringValue: @""];
864 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
866 [self showCaptureView: o_screen_view];
867 [o_mrl setStringValue: [NSString stringWithFormat:@"screen:// :screen-fps=%@", [o_screen_fps_fld stringValue]]];
869 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"iSight"] )
871 [o_capture_lbl setStringValue: _NS("iSight Capture Input")];
872 [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.")];
873 [o_capture_lbl displayIfNeeded];
874 [o_capture_long_lbl displayIfNeeded];
876 [self showCaptureView: o_capture_label_view];
877 [o_mrl setStringValue: @"qtcapture://"];
881 - (IBAction)screenStepperChanged:(id)sender
883 [o_screen_fps_fld setIntValue: [o_screen_fps_stp intValue]];
884 [o_panel makeFirstResponder: o_screen_fps_fld];
885 [o_mrl setStringValue: [NSString stringWithFormat:@"screen:// :screen-fps=%@", [o_screen_fps_fld stringValue]]];
888 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
890 [o_screen_fps_stp setIntValue: [o_screen_fps_fld intValue]];
891 if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
892 [o_screen_fps_fld setIntValue: 1];
893 [o_mrl setStringValue: [NSString stringWithFormat:@"screen:// :screen-fps=%i", [o_screen_fps_fld intValue]]];
896 - (IBAction)eyetvSwitchChannel:(id)sender
898 if( sender == o_eyetv_nextProgram_btn )
900 int chanNum = [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: YES];
901 [o_eyetv_channels_pop selectItemWithTag:chanNum];
902 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
904 else if( sender == o_eyetv_previousProgram_btn )
906 int chanNum = [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: NO];
907 [o_eyetv_channels_pop selectItemWithTag:chanNum];
908 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
910 else if( sender == o_eyetv_channels_pop )
912 int chanNum = [[sender selectedItem] tag];
913 [[[VLCMain sharedInstance] getEyeTVController] selectChannel:chanNum];
914 [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
917 msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
920 - (IBAction)eyetvLaunch:(id)sender
922 [[[VLCMain sharedInstance] getEyeTVController] launchEyeTV];
925 - (IBAction)eyetvGetPlugin:(id)sender
927 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
930 - (void)eyetvChanged:(NSNotification *)o_notification
932 if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
934 msg_Dbg( VLCIntf, "eyetv device was added" );
935 [self showCaptureView: o_eyetv_running_view];
936 [self setupChannelInfo];
938 else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
940 /* leave the channel selection like that,
941 * switch to our "no device" tab */
942 msg_Dbg( VLCIntf, "eyetv device was removed" );
945 else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
947 /* switch to the "launch eyetv" tab */
948 msg_Dbg( VLCIntf, "eyetv was terminated" );
949 [self showCaptureView: o_eyetv_notLaunched_view];
951 else if( [[o_notification name] isEqualToString: @"PluginInit"] )
953 /* we got no device yet */
954 msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
958 msg_Warn( VLCIntf, "unknown external notify '%s' received", [[o_notification name] UTF8String] );
961 /* little helper method, since this code needs to be run by multiple objects */
962 - (void)setupChannelInfo
964 /* set up channel selection */
965 [o_eyetv_channels_pop removeAllItems];
966 [o_eyetv_chn_bgbar setHidden: NO];
967 [o_eyetv_chn_bgbar animate: self];
968 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
969 [o_eyetv_chn_status_txt setHidden: NO];
972 NSEnumerator *channels = [[[VLCMain sharedInstance] getEyeTVController] allChannels];
974 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
976 keyEquivalent: @""] setTag:x++];
977 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
979 keyEquivalent: @""] setTag:x++];
983 [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
984 while( channel = [channels nextObject] )
986 /* we have to add items this way, because we accept duplicates
987 * additionally, we save a bit of time */
988 [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
990 keyEquivalent: @""] setTag:++x];
992 /* make Tuner the default */
993 [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] getEyeTVController] currentChannel]];
997 [o_eyetv_chn_bgbar setHidden: YES];
998 [o_eyetv_chn_status_txt setHidden: YES];
1001 - (IBAction)subsChanged:(id)sender
1003 if ([o_file_sub_ckbox state] == NSOnState)
1005 [o_file_sub_btn_settings setEnabled:YES];
1009 [o_file_sub_btn_settings setEnabled:NO];
1013 - (IBAction)subSettings:(id)sender
1015 [NSApp beginSheet: o_file_sub_sheet
1016 modalForWindow: [sender window]
1018 didEndSelector: NULL
1022 - (IBAction)subFileBrowse:(id)sender
1024 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1026 [o_open_panel setAllowsMultipleSelection: NO];
1027 [o_open_panel setTitle: _NS("Open File")];
1028 [o_open_panel setPrompt: _NS("Open")];
1030 if( [o_open_panel runModalForDirectory: nil
1031 file: nil types: nil] == NSOKButton )
1033 NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
1034 [o_file_sub_path setStringValue: o_filename];
1038 - (IBAction)subOverride:(id)sender
1040 BOOL b_state = [o_file_sub_override state];
1041 [o_file_sub_delay setEnabled: b_state];
1042 [o_file_sub_delay_stp setEnabled: b_state];
1043 [o_file_sub_fps setEnabled: b_state];
1044 [o_file_sub_fps_stp setEnabled: b_state];
1047 - (IBAction)subDelayStepperChanged:(id)sender
1049 [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1052 - (IBAction)subFpsStepperChanged:(id)sender;
1054 [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1057 - (IBAction)subCloseSheet:(id)sender
1059 [o_file_sub_sheet orderOut:sender];
1060 [NSApp endSheet: o_file_sub_sheet];
1063 - (IBAction)panelCancel:(id)sender
1065 [NSApp stopModalWithCode: 0];
1068 - (IBAction)panelOk:(id)sender
1070 if( [[o_mrl stringValue] length] )
1072 [NSApp stopModalWithCode: 1];
1082 @implementation VLCOpenTextField
1084 - (void)mouseDown:(NSEvent *)theEvent
1086 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1088 [super mouseDown: theEvent];