1 /*****************************************************************************
2 * open.m: Open dialogues for VLC's MacOS X port
3 *****************************************************************************
4 * Copyright (C) 2002-2012 VLC authors and VideoLAN
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 #import <stdlib.h> /* malloc(), free() */
32 #import <sys/param.h> /* for MAXPATHLEN */
34 #import "CompatibilityFixes.h"
37 #import <IOKit/IOBSD.h>
38 #import <IOKit/storage/IOMedia.h>
39 #import <IOKit/storage/IOCDMedia.h>
40 #import <IOKit/storage/IODVDMedia.h>
41 #import <IOKit/storage/IOBDMedia.h>
42 #import <Cocoa/Cocoa.h>
43 #import <QTKit/QTKit.h>
53 NSArray *qtkvideoDevices;
54 NSArray *qtkaudioDevices;
55 #define setEyeTVUnconnected \
56 [o_capture_lbl setStringValue: _NS("No device is selected")]; \
57 [o_capture_long_lbl setStringValue: _NS("No device is selected.\n\nChoose available device in above pull-down menu.\n")]; \
58 [o_capture_lbl displayIfNeeded]; \
59 [o_capture_long_lbl displayIfNeeded]; \
60 [self showCaptureView: o_capture_label_view]
68 /*****************************************************************************
69 * VLCOpen implementation
70 *****************************************************************************/
71 @implementation VLCOpen
76 static VLCOpen *_o_sharedMainInstance = nil;
78 + (VLCOpen *)sharedInstance
80 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
85 if( _o_sharedMainInstance) {
88 _o_sharedMainInstance = [super init];
92 return _o_sharedMainInstance;
97 [o_specialMediaFolders release];
98 [o_opticalDevices release];
99 if( o_file_slave_path )
100 [o_file_slave_path release];
103 [o_sub_path release];
104 [o_currentOpticalMediaIconView release];
105 [o_currentOpticalMediaView release];
107 for( i = 0; i < [o_displayInfos count]; i ++ )
109 NSValue *v = [o_displayInfos objectAtIndex:i];
110 free( [v pointerValue] );
112 [o_displayInfos removeAllObjects];
113 [o_displayInfos release];
121 [o_panel setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
123 [o_panel setTitle: _NS("Open Source")];
124 [o_mrl_lbl setStringValue: _NS("Media Resource Locator (MRL)")];
126 [o_btn_ok setTitle: _NS("Open")];
127 [o_btn_cancel setTitle: _NS("Cancel")];
129 [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
130 [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
131 [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
132 [[o_tabview tabViewItemAtIndex: 3] setLabel: _NS("Capture")];
134 [o_file_name setStringValue: @""];
135 [o_file_name_stub setStringValue: _NS("Choose a file")];
136 [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
137 [o_file_btn_browse setTitle: _NS("Browse...")];
138 [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
139 [o_file_stream setHidden: NO];
140 [o_file_slave_ckbox setTitle: _NS("Play another media synchronously")];
141 [o_file_slave_select_btn setTitle: _NS("Choose...")];
142 [o_file_slave_filename_lbl setStringValue: @""];
143 [o_file_slave_icon_well setImage: NULL];
144 [o_file_subtitles_filename_lbl setStringValue: @""];
145 [o_file_subtitles_icon_well setImage: NULL];
146 [o_file_custom_timing_ckb setTitle: _NS("Custom playback")];
147 [o_file_starttime_lbl setStringValue: _NS("Start time")];
148 [o_file_starttime_fld setStringValue: @""];
149 [o_file_stoptime_lbl setStringValue: _NS("Stop time")];
150 [o_file_stoptime_fld setStringValue: @""];
152 [o_disc_selector_pop removeAllItems];
153 [o_disc_selector_pop setHidden: NO];
154 NSString *o_videots = _NS("Open VIDEO_TS folder");
155 NSString *o_bdmv = _NS("Open BDMV folder");
156 [o_disc_nodisc_lbl setStringValue: _NS("Insert Disc")];
157 [o_disc_nodisc_videots_btn setTitle: o_videots];
158 [o_disc_nodisc_bdmv_btn setTitle: o_bdmv];
159 [o_disc_audiocd_lbl setStringValue: _NS("Audio CD")];
160 [o_disc_audiocd_trackcount_lbl setStringValue: @""];
161 [o_disc_audiocd_videots_btn setTitle: o_videots];
162 [o_disc_audiocd_bdmv_btn setTitle: o_bdmv];
163 [o_disc_dvd_lbl setStringValue: @""];
164 [o_disc_dvd_disablemenus_btn setTitle: _NS("Disable DVD menus")];
165 [o_disc_dvd_videots_btn setTitle: o_videots];
166 [o_disc_dvd_bdmv_btn setTitle: o_bdmv];
167 [o_disc_dvdwomenus_lbl setStringValue: @""];
168 [o_disc_dvdwomenus_enablemenus_btn setTitle: _NS("Enable DVD menus")];
169 [o_disc_dvdwomenus_videots_btn setTitle: o_videots];
170 [o_disc_dvdwomenus_bdmv_btn setTitle: o_bdmv];
171 [o_disc_dvdwomenus_title_lbl setStringValue: _NS("Title")];
172 [o_disc_dvdwomenus_chapter_lbl setStringValue: _NS("Chapter")];
173 [o_disc_vcd_title_lbl setStringValue: _NS("Title")];
174 [o_disc_vcd_chapter_lbl setStringValue: _NS("Chapter")];
175 [o_disc_vcd_videots_btn setTitle: o_videots];
176 [o_disc_vcd_bdmv_btn setTitle: o_bdmv];
177 [o_disc_bd_videots_btn setTitle: o_videots];
178 [o_disc_bd_bdmv_btn setTitle: o_bdmv];
180 [o_net_udp_port_lbl setStringValue: _NS("Port")];
181 [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
182 [o_net_udpm_port_lbl setStringValue: _NS("Port")];
183 [o_net_http_url_lbl setStringValue: _NS("URL")];
184 [o_net_help_lbl setStringValue: _NS("To Open a usual network stream (HTTP, RTSP, RTMP, MMS, FTP, etc.), just enter the URL in the field above. If you want to open a RTP or UDP stream, press the button below.")];
185 [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.")];
186 [o_net_udp_cancel_btn setTitle: _NS("Cancel")];
187 [o_net_udp_ok_btn setTitle: _NS("Open")];
188 [o_net_openUDP_btn setTitle: _NS("Open RTP/UDP Stream")];
189 [o_net_udp_mode_lbl setStringValue: _NS("Mode")];
190 [o_net_udp_protocol_lbl setStringValue: _NS("Protocol")];
191 [o_net_udp_address_lbl setStringValue: _NS("Address")];
193 [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
194 [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
196 [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
197 [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
199 [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
201 [o_capture_mode_pop removeAllItems];
202 [o_capture_mode_pop addItemWithTitle: _NS("Input Devices")];
203 [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
204 [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
205 [o_screen_long_lbl setStringValue: _NS("This input allows you to save, stream or display your current screen contents.")];
206 [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
207 [o_screen_screen_lbl setStringValue: _NS("Screen:")];
208 [o_screen_left_lbl setStringValue: _NS("Subscreen left:")];
209 [o_screen_top_lbl setStringValue: _NS("Subscreen top:")];
210 [o_screen_width_lbl setStringValue: _NS("Subscreen width:")];
211 [o_screen_height_lbl setStringValue: _NS("Subscreen height:")];
212 [o_screen_follow_mouse_ckb setTitle: _NS("Follow the mouse")];
213 [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
214 [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
215 [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
216 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
217 [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
218 [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
219 [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
220 [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
221 [o_capture_width_lbl setStringValue: _NS("Image width:")];
222 [o_capture_height_lbl setStringValue: _NS("Image height:")];
224 [self qtkvideoDevices];
225 [o_qtk_video_device_pop removeAllItems];
226 msg_Dbg( VLCIntf, "Found %lu video capture devices", [qtkvideoDevices count] );
228 if([qtkvideoDevices count] >= 1)
230 if (!qtk_currdevice_uid) {
231 qtk_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo] uniqueID]
232 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
234 NSUInteger deviceCount = [qtkvideoDevices count];
235 for(int ivideo = 0; ivideo < deviceCount; ivideo++){
236 QTCaptureDevice *qtk_device;
237 qtk_device = [qtkvideoDevices objectAtIndex:ivideo];
238 [o_qtk_video_device_pop addItemWithTitle: [qtk_device localizedDisplayName]];
239 if([[[qtk_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid]){
240 [o_qtk_video_device_pop selectItemAtIndex:ivideo];
246 [o_qtk_video_device_pop addItemWithTitle: _NS("None")];
247 [qtk_currdevice_uid release];
250 [self qtkaudioDevices];
251 [o_qtk_audio_device_pop removeAllItems];
252 msg_Dbg( VLCIntf, "Found %lu audio capture devices", [qtkaudioDevices count] );
254 if([qtkaudioDevices count] >= 1)
256 if (!qtkaudio_currdevice_uid) {
257 qtkaudio_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound] uniqueID]
258 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
260 NSUInteger deviceCount = [qtkaudioDevices count];
261 for(int iaudio = 0; iaudio < deviceCount; iaudio++){
262 QTCaptureDevice *qtkaudio_device;
263 qtkaudio_device = [qtkaudioDevices objectAtIndex:iaudio];
264 [o_qtk_audio_device_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
265 if([[[qtkaudio_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtkaudio_currdevice_uid]){
266 [o_qtk_audio_device_pop selectItemAtIndex:iaudio];
272 [o_qtk_audio_device_pop addItemWithTitle: _NS("None")];
273 [qtkaudio_currdevice_uid release];
278 [[NSNotificationCenter defaultCenter] addObserver: self
279 selector: @selector(openNetInfoChanged:)
280 name: NSControlTextDidChangeNotification
281 object: o_net_udp_port];
282 [[NSNotificationCenter defaultCenter] addObserver: self
283 selector: @selector(openNetInfoChanged:)
284 name: NSControlTextDidChangeNotification
285 object: o_net_udpm_addr];
286 [[NSNotificationCenter defaultCenter] addObserver: self
287 selector: @selector(openNetInfoChanged:)
288 name: NSControlTextDidChangeNotification
289 object: o_net_udpm_port];
290 [[NSNotificationCenter defaultCenter] addObserver: self
291 selector: @selector(openNetInfoChanged:)
292 name: NSControlTextDidChangeNotification
293 object: o_net_http_url];
295 [[NSDistributedNotificationCenter defaultCenter] addObserver: self
296 selector: @selector(eyetvChanged:)
298 object: @"VLCEyeTVSupport"
299 suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
301 [[NSNotificationCenter defaultCenter] addObserver: self
302 selector: @selector(screenFPSfieldChanged:)
303 name: NSControlTextDidChangeNotification
304 object: o_screen_fps_fld];
306 /* register clicks on text fields */
307 [[NSNotificationCenter defaultCenter] addObserver: self
308 selector: @selector(textFieldWasClicked:)
309 name: @"VLCOpenTextFieldWasClicked"
312 /* we want to be notified about removed or added media */
313 o_specialMediaFolders = [[NSMutableArray alloc] init];
314 o_opticalDevices = [[NSMutableArray alloc] init];
315 o_displayInfos = [[NSMutableArray alloc] init];
316 NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
318 [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidMountNotification object:nil];
319 [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidUnmountNotification object:nil];
320 [self performSelector:@selector(qtkToggleUIElements:) withObject:nil afterDelay:.3];
321 [self performSelector:@selector(scanOpticalMedia:) withObject:nil afterDelay:.5];
326 - (void)setMRL:(NSString *)newMRL
333 [o_mrl_fld setStringValue: o_mrl];
334 if ([o_mrl length] > 0)
335 [o_btn_ok setEnabled: YES];
337 [o_btn_ok setEnabled: NO];
348 module_config_t * p_item;
350 [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
351 [o_file_sub_path_lbl setStringValue: _NS("Choose a file")];
352 [o_file_sub_path_lbl setHidden: NO];
353 [o_file_sub_path_fld setStringValue: @""];
354 [o_file_sub_btn_settings setTitle: _NS("Choose...")];
355 [o_file_sub_btn_browse setTitle: _NS("Browse...")];
356 [o_file_sub_override setTitle: _NS("Override parameters")];
357 [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
358 [o_file_sub_delay_stp setEnabled: NO];
359 [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
360 [o_file_sub_fps_stp setEnabled: NO];
361 [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
362 [o_file_sub_encoding_pop removeAllItems];
363 [o_file_sub_size_lbl setStringValue: _NS("Font size")];
364 [o_file_sub_size_pop removeAllItems];
365 [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
366 [o_file_sub_align_pop removeAllItems];
367 [o_file_sub_ok_btn setStringValue: _NS("OK")];
368 [o_file_sub_font_box setTitle: _NS("Font Properties")];
369 [o_file_sub_file_box setTitle: _NS("Subtitle File")];
371 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
375 for( i_index = 0; p_item->list.psz && p_item->list.psz[i_index];
378 [o_file_sub_encoding_pop addItemWithTitle:
379 [NSString stringWithUTF8String: p_item->list.psz[i_index]]];
381 [o_file_sub_encoding_pop selectItemWithTitle:
382 [NSString stringWithUTF8String: p_item->value.psz]];
385 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
389 for ( i_index = 0; i_index < p_item->list_count; i_index++ )
391 [o_file_sub_align_pop addItemWithTitle:
392 _NS(p_item->list_text[i_index])];
394 [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
397 p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
401 for ( i_index = 0; i_index < p_item->list_count; i_index++ )
403 [o_file_sub_size_pop addItemWithTitle: _NS(p_item->list_text[i_index])];
404 if ( p_item->value.i == p_item->list.i[i_index] )
406 [o_file_sub_size_pop selectItemAtIndex: i_index];
412 - (void)openTarget:(int)i_type
416 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
418 [o_tabview selectTabViewItemAtIndex: i_type];
419 [o_file_sub_ckbox setState: NSOffState];
421 i_result = [NSApp runModalForWindow: o_panel];
426 NSMutableDictionary *o_dic;
427 NSMutableArray *o_options = [NSMutableArray array];
429 o_dic = [NSMutableDictionary dictionaryWithObject: [self MRL] forKey: @"ITEM_URL"];
430 if( [o_file_sub_ckbox state] == NSOnState )
432 module_config_t * p_item;
434 [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", o_sub_path]];
435 if( [o_file_sub_override state] == NSOnState )
437 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
438 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
440 [o_options addObject: [NSString stringWithFormat:
441 @"subsdec-encoding=%@",
442 [o_file_sub_encoding_pop titleOfSelectedItem]]];
443 [o_options addObject: [NSString stringWithFormat:
444 @"subsdec-align=%li",
445 [o_file_sub_align_pop indexOfSelectedItem]]];
447 p_item = config_FindConfig( VLC_OBJECT(p_intf),
448 "freetype-rel-fontsize" );
452 [o_options addObject: [NSString stringWithFormat:
453 @"freetype-rel-fontsize=%i",
454 p_item->list.i[[o_file_sub_size_pop indexOfSelectedItem]]]];
457 NSArray * components = [[o_file_starttime_fld stringValue] componentsSeparatedByString:@":"];
458 NSUInteger componentCount = [components count];
460 if( componentCount == 1 )
461 tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] );
462 else if( componentCount == 2 )
463 tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue] );
464 else if( componentCount == 3 )
465 tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue] );
467 [o_options addObject: [NSString stringWithFormat:@"start-time=%li", tempValue]];
468 components = [[o_file_stoptime_fld stringValue] componentsSeparatedByString:@":"];
469 componentCount = [components count];
470 if( componentCount == 1 )
471 tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] );
472 else if( componentCount == 2 )
473 tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue] );
474 else if( componentCount == 3 )
475 tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue] );
477 [o_options addObject: [NSString stringWithFormat:@"stop-time=%li", tempValue]];
478 if( [o_output_ckbox state] == NSOnState )
480 NSUInteger count = [[o_sout_options mrl] count];
481 for (NSUInteger i = 0 ; i < count ; i++)
483 [o_options addObject: [NSString stringWithString: [[(VLCOutput *)o_sout_options mrl] objectAtIndex: i]]];
486 if( [o_file_slave_ckbox state] && o_file_slave_path )
487 [o_options addObject: [NSString stringWithFormat: @"input-slave=%@", o_file_slave_path]];
488 if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
490 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
492 int selected_index = [o_screen_screen_pop indexOfSelectedItem];
493 NSValue *v = [o_displayInfos objectAtIndex:selected_index];
494 struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
496 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
497 [o_options addObject: [NSString stringWithFormat: @"screen-display-id=%i", item->id]];
498 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
499 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
500 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
501 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
502 if( [o_screen_follow_mouse_ckb intValue] == YES )
503 [o_options addObject: @"screen-follow-mouse"];
505 [o_options addObject: @"no-screen-follow-mouse"];
507 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")] )
509 if ([o_qtk_video_ckb state])
511 [o_options addObject: [NSString stringWithFormat: @"qtcapture-width=%i", [o_capture_width_fld intValue]]];
512 [o_options addObject: [NSString stringWithFormat: @"qtcapture-height=%i", [o_capture_height_fld intValue]]];
513 if ([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
514 [o_options addObject: [NSString stringWithFormat: @"input-slave=qtsound://%@", qtkaudio_currdevice_uid]];
519 /* apply the options to our item(s) */
520 [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
522 [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
524 [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
528 - (IBAction)screenChanged:(id)sender
530 int selected_index = [o_screen_screen_pop indexOfSelectedItem];
531 if( selected_index >= [o_displayInfos count] ) return;
533 NSValue *v = [o_displayInfos objectAtIndex:selected_index];
534 struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
536 [o_screen_left_stp setMaxValue: item->rect.size.width];
537 [o_screen_top_stp setMaxValue: item->rect.size.height];
538 [o_screen_width_stp setMaxValue: item->rect.size.width];
539 [o_screen_height_stp setMaxValue: item->rect.size.height];
542 - (IBAction)qtkChanged:(id)sender
544 NSInteger i_selectedDevice = [o_qtk_video_device_pop indexOfSelectedItem];
545 if( [qtkvideoDevices count] >= 1 )
547 NSValue *sizes = [[[[qtkvideoDevices objectAtIndex:i_selectedDevice] formatDescriptions] objectAtIndex: 0] attributeForKey: QTFormatDescriptionVideoEncodedPixelsSizeAttribute];
549 [o_capture_width_fld setIntValue: [sizes sizeValue].width];
550 [o_capture_height_fld setIntValue: [sizes sizeValue].height];
551 [o_capture_width_stp setIntValue: [o_capture_width_fld intValue]];
552 [o_capture_height_stp setIntValue: [o_capture_height_fld intValue]];
553 qtk_currdevice_uid = [[(QTCaptureDevice *)[qtkvideoDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
557 - (IBAction)qtkAudioChanged:(id)sender
559 NSInteger i_selectedDevice = [o_qtk_audio_device_pop indexOfSelectedItem];
560 if( [qtkaudioDevices count] >= 1 )
562 qtkaudio_currdevice_uid = [[(QTCaptureDevice *)[qtkaudioDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
566 - (IBAction)qtkToggleUIElements:(id)sender
568 [o_qtk_audio_device_pop setEnabled:[o_qtk_audio_ckb state]];
569 BOOL b_state = [o_qtk_video_ckb state];
570 [o_qtk_video_device_pop setEnabled:b_state];
571 [o_capture_width_fld setEnabled:b_state];
572 [o_capture_width_stp setEnabled:b_state];
573 [o_capture_height_fld setEnabled:b_state];
574 [o_capture_height_stp setEnabled:b_state];
575 [self qtkAudioChanged:sender];
576 [self qtkChanged:sender];
577 [self openCaptureModeChanged:sender];
581 #pragma mark Main Actions
583 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
585 NSString *o_label = [o_tvi label];
587 if( [o_label isEqualToString: _NS("File")] )
589 [self openFilePathChanged: nil];
591 else if( [o_label isEqualToString: _NS("Disc")] )
593 [self scanOpticalMedia: nil];
595 else if( [o_label isEqualToString: _NS("Network")] )
597 [self openNetInfoChanged: nil];
599 else if( [o_label isEqualToString: _NS("Capture")] )
601 [self openCaptureModeChanged: nil];
605 - (IBAction)expandMRLfieldAction:(id)sender
607 NSRect o_win_rect, o_view_rect;
608 o_win_rect = [o_panel frame];
609 o_view_rect = [o_mrl_view frame];
611 if( [o_mrl_btn state] == NSOffState )
613 /* we need to collaps, restore the panel size */
614 o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
615 o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
617 /* remove the MRL view */
618 [o_mrl_view removeFromSuperview];
620 /* we need to expand */
621 [o_mrl_view setFrame: NSMakeRect( 0,
622 [o_mrl_btn frame].origin.y,
623 o_view_rect.size.width,
624 o_view_rect.size.height )];
625 [o_mrl_view setNeedsDisplay: NO];
626 [o_mrl_view setAutoresizesSubviews: YES];
628 /* enlarge panel size for MRL view */
629 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
632 [[o_panel animator] setFrame: o_win_rect display:YES];
633 // [o_panel displayIfNeeded];
634 if( [o_mrl_btn state] == NSOnState )
635 [[o_panel contentView] addSubview: o_mrl_view];
638 - (void)openFileGeneric
640 [self openFilePathChanged: nil];
641 [self openTarget: 0];
646 [o_specialMediaFolders removeAllObjects];
647 [o_opticalDevices removeAllObjects];
648 [self scanOpticalMedia: nil];
649 [self openTarget: 1];
654 [self openNetInfoChanged: nil];
655 [self openTarget: 2];
660 [self openCaptureModeChanged: nil];
661 [self openTarget: 3];
666 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
667 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
669 [o_open_panel setAllowsMultipleSelection: YES];
670 [o_open_panel setCanChooseDirectories: YES];
671 [o_open_panel setTitle: _NS("Open File")];
672 [o_open_panel setPrompt: _NS("Open")];
674 if( [o_open_panel runModal] == NSOKButton )
676 NSArray * o_urls = [o_open_panel URLs];
677 NSUInteger count = [o_urls count];
678 NSMutableArray *o_values = [NSMutableArray arrayWithCapacity:count];
679 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
680 for( NSUInteger i = 0; i < count; i++ )
682 [o_values addObject: [[o_urls objectAtIndex: i] path]];
684 [o_values sortUsingSelector:@selector(caseInsensitiveCompare:)];
686 for( NSUInteger i = 0; i < count; i++ )
689 char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], "file");
693 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
697 [o_array addObject: o_dic];
700 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
702 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
707 #pragma mark File Panel
709 - (void)openFilePathChanged:(NSNotification *)o_notification
711 if ( o_file_path && [o_file_path length] > 0 )
713 bool b_stream = [o_file_stream state];
716 [[NSFileManager defaultManager] fileExistsAtPath:o_file_path isDirectory:&b_dir];
718 char *psz_uri = vlc_path2uri([o_file_path UTF8String], "file");
719 if( !psz_uri ) return;
721 NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
722 NSRange offile = [o_mrl_string rangeOfString:@"file"];
726 [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
728 [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
730 [o_file_name setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_path]];
731 [o_file_name_stub setHidden: YES];
732 [o_file_stream setHidden: NO];
733 [o_file_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_path]];
734 [o_file_icon_well setHidden: NO];
735 [self setMRL: o_mrl_string];
739 [o_file_name setStringValue: @""];
740 [o_file_name_stub setHidden: NO];
741 [o_file_stream setHidden: YES];
742 [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
747 - (IBAction)openFileBrowse:(id)sender
749 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
751 [o_open_panel setAllowsMultipleSelection: NO];
752 [o_open_panel setCanChooseDirectories: YES];
753 [o_open_panel setTitle: _NS("Open File")];
754 [o_open_panel setPrompt: _NS("Open")];
756 [o_open_panel beginSheetForDirectory:nil
759 modalForWindow:[sender window]
761 didEndSelector: @selector(pathChosenInPanel:
767 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void *)contextInfo
769 if (returnCode == NSFileHandlingPanelOKButton)
772 [o_file_path release];
773 o_file_path = [[[sheet URLs] objectAtIndex: 0] path];
774 [o_file_path retain];
775 [self openFilePathChanged: nil];
779 - (IBAction)openFileStreamChanged:(id)sender
781 [self openFilePathChanged: nil];
784 - (IBAction)inputSlaveAction:(id)sender
786 if( sender == o_file_slave_ckbox )
787 [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
790 NSOpenPanel *o_open_panel;
791 o_open_panel = [NSOpenPanel openPanel];
792 [o_open_panel setCanChooseFiles: YES];
793 [o_open_panel setCanChooseDirectories: NO];
794 if( [o_open_panel runModal] == NSOKButton )
796 if( o_file_slave_path )
797 [o_file_slave_path release];
798 o_file_slave_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
799 [o_file_slave_path retain];
802 if( o_file_slave_path && [o_file_slave_ckbox state] == NSOnState)
804 [o_file_slave_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_slave_path]];
805 [o_file_slave_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_slave_path]];
809 [o_file_slave_filename_lbl setStringValue: @""];
810 [o_file_slave_icon_well setImage: NULL];
814 - (IBAction)fileTimeCustomization:(id)sender
816 BOOL b_value = [o_file_custom_timing_ckb state];
817 [o_file_starttime_fld setEnabled: b_value];
818 [o_file_starttime_lbl setEnabled: b_value];
819 [o_file_stoptime_fld setEnabled: b_value];
820 [o_file_stoptime_lbl setEnabled: b_value];
824 #pragma mark Optical Media Panel
826 - (void)showOpticalMediaView: theView withIcon:(NSImage *)icon
829 o_view_rect = [theView frame];
830 [theView setFrame: NSMakeRect( 233, 0, o_view_rect.size.width, o_view_rect.size.height)];
831 [theView setAutoresizesSubviews: YES];
832 if (o_currentOpticalMediaView)
834 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaView with: theView];
835 [o_currentOpticalMediaView release];
838 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: theView];
839 o_currentOpticalMediaView = theView;
840 [o_currentOpticalMediaView retain];
842 NSImageView *imageView;
843 imageView = [[NSImageView alloc] init];
844 [imageView setFrame: NSMakeRect( 53, 61, 128, 128 )];
845 [icon setSize: NSMakeSize(128,128)];
846 [imageView setImage: icon];
847 if (o_currentOpticalMediaIconView)
849 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaIconView with: imageView];
850 [o_currentOpticalMediaIconView release];
853 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: imageView];
854 o_currentOpticalMediaIconView = imageView;
855 [o_currentOpticalMediaIconView retain];
856 [o_currentOpticalMediaView setNeedsDisplay: YES];
857 [o_currentOpticalMediaIconView setNeedsDisplay: YES];
858 [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] setNeedsDisplay: YES];
859 [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] displayIfNeeded];
862 - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
866 FSVolumeRefNum actualVolume;
867 err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
869 // get a FSVolumeRefNum from mountPath
870 if ( noErr == err ) {
871 FSCatalogInfo catalogInfo;
872 err = FSGetCatalogInfo ( &ref,
880 actualVolume = catalogInfo.volume;
887 GetVolParmsInfoBuffer volumeParms;
888 err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
891 NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
892 return [NSString stringWithFormat:@"/dev/r%@", bsdName];
898 - (char *)getVolumeTypeFromMountPath:(NSString *)mountPath
902 FSVolumeRefNum actualVolume;
903 err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
905 // get a FSVolumeRefNum from mountPath
906 if ( noErr == err ) {
907 FSCatalogInfo catalogInfo;
908 err = FSGetCatalogInfo ( &ref,
916 actualVolume = catalogInfo.volume;
923 GetVolParmsInfoBuffer volumeParms;
924 err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
926 CFMutableDictionaryRef matchingDict;
927 io_service_t service;
929 if (!volumeParms.vMDeviceID)
932 matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
933 service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
936 if (IO_OBJECT_NULL != service) {
937 if (IOObjectConformsTo(service, kIOCDMediaClass)) {
938 returnValue = kVLCMediaAudioCD;
940 else if(IOObjectConformsTo(service, kIODVDMediaClass))
941 returnValue = kVLCMediaDVD;
942 else if(IOObjectConformsTo(service, kIOBDMediaClass))
943 returnValue = kVLCMediaBD;
946 if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
947 returnValue = kVLCMediaVideoTSFolder;
948 else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
949 returnValue = kVLCMediaBDMVFolder;
952 // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
953 NSFileManager * fm = [[NSFileManager alloc] init];
955 NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
956 for (int i = 0; i < [dirContents count]; i++)
958 NSString *currentFile = [dirContents objectAtIndex:i];
959 NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
962 if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
964 if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame)
966 returnValue = kVLCMediaSVCD;
969 if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame)
971 returnValue = kVLCMediaVCD;
974 if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame)
976 returnValue = kVLCMediaBDMVFolder;
979 if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame)
981 returnValue = kVLCMediaVideoTSFolder;
990 returnValue = kVLCMediaVideoTSFolder;
994 IOObjectRelease(service);
999 - (void)showOpticalAtPath: (NSString *)o_opticalDevicePath
1001 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1003 char *diskType = [self getVolumeTypeFromMountPath:o_opticalDevicePath];
1005 if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder)
1007 [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_opticalDevicePath]];
1008 [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
1009 NSString *pathToOpen;
1010 if (diskType == kVLCMediaVideoTSFolder)
1011 pathToOpen = o_opticalDevicePath;
1013 pathToOpen = [self getBSDNodeFromMountPath: o_opticalDevicePath];
1014 if (!b_nodvdmenus) {
1015 [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1016 [self showOpticalMediaView: o_disc_dvd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1018 [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1019 [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1022 else if (diskType == kVLCMediaAudioCD)
1024 [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1025 [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_opticalDevicePath error:NULL] count] - 1]]; // minus .TOC.plist
1026 [self showOpticalMediaView: o_disc_audiocd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1027 [self setMRL: [NSString stringWithFormat: @"cdda://%@", [self getBSDNodeFromMountPath: o_opticalDevicePath]]];
1029 else if (diskType == kVLCMediaVCD)
1031 [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1032 [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1033 [self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1035 else if (diskType == kVLCMediaSVCD)
1037 [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1038 [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1039 [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1041 else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
1043 [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1044 [self showOpticalMediaView: o_disc_bd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1045 [self setMRL: [NSString stringWithFormat: @"bluray://%@", o_opticalDevicePath]];
1049 msg_Warn( VLCIntf, "unknown disk type, no idea what to display" );
1050 [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
1056 - (void)showSelectedOpticalDisc
1058 NSString *o_opticalDevicePath = [o_opticalDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];
1059 [NSThread detachNewThreadSelector:@selector(showOpticalAtPath:) toTarget:self withObject:o_opticalDevicePath];
1062 - (void)scanOpticalMedia:(NSNotification *)o_notification
1064 [o_opticalDevices removeAllObjects];
1065 [o_disc_selector_pop removeAllItems];
1066 [o_opticalDevices addObjectsFromArray: [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
1067 [o_opticalDevices addObjectsFromArray: o_specialMediaFolders];
1068 if ([o_opticalDevices count] > 0) {
1069 NSUInteger deviceCount = [o_opticalDevices count];
1070 for (NSUInteger i = 0; i < deviceCount ; i++)
1071 [o_disc_selector_pop addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: i]]];
1073 if ([o_disc_selector_pop numberOfItems] <= 1)
1074 [o_disc_selector_pop setHidden: YES];
1076 [o_disc_selector_pop setHidden: NO];
1078 // select newly added media folder
1079 if (o_notification && [[o_notification name] isEqualToString:@"VLCNewMediaFolderNotification"])
1080 [o_disc_selector_pop selectItemAtIndex: [[o_disc_selector_pop itemArray] count] - 1];
1082 [self showSelectedOpticalDisc];
1086 msg_Dbg( VLCIntf, "no optical media found" );
1087 [o_disc_selector_pop setHidden: YES];
1088 [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed: @"NSApplicationIcon"]];
1092 - (IBAction)discSelectorChanged:(id)sender
1094 [self showSelectedOpticalDisc];
1097 - (IBAction)openSpecialMediaFolder:(id)sender
1099 /* this is currently for VIDEO_TS and BDMV folders */
1100 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1102 [o_open_panel setAllowsMultipleSelection: NO];
1103 [o_open_panel setCanChooseFiles: NO];
1104 [o_open_panel setCanChooseDirectories: YES];
1105 [o_open_panel setTitle: [sender title]];
1106 [o_open_panel setPrompt: _NS("Open")];
1108 if ([o_open_panel runModal] == NSOKButton)
1110 NSString *o_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1111 if ([o_path length] > 0 )
1113 [o_specialMediaFolders addObject: o_path];
1114 [self scanOpticalMedia: [NSNotification notificationWithName:@"VLCNewMediaFolderNotification" object:nil]];
1119 - (IBAction)dvdreadOptionChanged:(id)sender
1121 NSString *o_device_path = [o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]];
1122 char *diskType = [self getVolumeTypeFromMountPath:o_device_path];
1124 NSString *pathToOpen;
1125 if (diskType == kVLCMediaVideoTSFolder)
1126 pathToOpen = o_device_path;
1128 pathToOpen = [self getBSDNodeFromMountPath: o_device_path];
1130 if (sender == o_disc_dvdwomenus_enablemenus_btn) {
1132 [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1133 [self showOpticalMediaView: o_disc_dvd_view withIcon: [o_currentOpticalMediaIconView image]];
1136 if (sender == o_disc_dvd_disablemenus_btn) {
1138 [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [o_currentOpticalMediaIconView image]];
1141 if (sender == o_disc_dvdwomenus_title)
1142 [o_disc_dvdwomenus_title_stp setIntValue: [o_disc_dvdwomenus_title intValue]];
1143 if (sender == o_disc_dvdwomenus_title_stp)
1144 [o_disc_dvdwomenus_title setIntValue: [o_disc_dvdwomenus_title_stp intValue]];
1145 if (sender == o_disc_dvdwomenus_chapter)
1146 [o_disc_dvdwomenus_chapter_stp setIntValue: [o_disc_dvdwomenus_chapter intValue]];
1147 if (sender == o_disc_dvdwomenus_chapter_stp)
1148 [o_disc_dvdwomenus_chapter setIntValue: [o_disc_dvdwomenus_chapter_stp intValue]];
1150 [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1153 - (IBAction)vcdOptionChanged:(id)sender
1155 if (sender == o_disc_vcd_title)
1156 [o_disc_vcd_title_stp setIntValue: [o_disc_vcd_title intValue]];
1157 if (sender == o_disc_vcd_title_stp)
1158 [o_disc_vcd_title setIntValue: [o_disc_vcd_title_stp intValue]];
1159 if (sender == o_disc_vcd_chapter)
1160 [o_disc_vcd_chapter_stp setIntValue: [o_disc_vcd_chapter intValue]];
1161 if (sender == o_disc_vcd_chapter_stp)
1162 [o_disc_vcd_chapter setIntValue: [o_disc_vcd_chapter_stp intValue]];
1164 [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]]], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1168 #pragma mark Network Panel
1170 - (void)textFieldWasClicked:(NSNotification *)o_notification
1172 if( [o_notification object] == o_net_udp_port )
1173 [o_net_mode selectCellAtRow: 0 column: 0];
1174 else if( [o_notification object] == o_net_udpm_addr ||
1175 [o_notification object] == o_net_udpm_port )
1176 [o_net_mode selectCellAtRow: 1 column: 0];
1178 [o_net_mode selectCellAtRow: 2 column: 0];
1180 [self openNetInfoChanged: nil];
1183 - (IBAction)openNetModeChanged:(id)sender
1185 if( sender == o_net_mode )
1187 if( [[sender selectedCell] tag] == 0 )
1188 [o_panel makeFirstResponder: o_net_udp_port];
1189 else if ( [[sender selectedCell] tag] == 1 )
1190 [o_panel makeFirstResponder: o_net_udpm_addr];
1192 msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
1195 [self openNetInfoChanged: nil];
1198 - (IBAction)openNetStepperChanged:(id)sender
1200 int i_tag = [sender tag];
1204 [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
1205 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1206 object: o_net_udp_port];
1207 [o_panel makeFirstResponder: o_net_udp_port];
1209 else if( i_tag == 1 )
1211 [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
1212 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1213 object: o_net_udpm_port];
1214 [o_panel makeFirstResponder: o_net_udpm_port];
1217 [self openNetInfoChanged: nil];
1220 - (void)openNetInfoChanged:(NSNotification *)o_notification
1222 NSString *o_mrl_string = [NSString string];
1224 if( [o_net_udp_panel isVisible] )
1227 o_mode = [[o_net_mode selectedCell] title];
1229 if( [o_mode isEqualToString: _NS("Unicast")] )
1231 int i_port = [o_net_udp_port intValue];
1233 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1234 o_mrl_string = @"udp://";
1236 o_mrl_string = @"rtp://";
1238 if( i_port != config_GetInt( p_intf, "server-port" ) )
1241 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1244 else if( [o_mode isEqualToString: _NS("Multicast")] )
1246 NSString *o_addr = [o_net_udpm_addr stringValue];
1247 int i_port = [o_net_udpm_port intValue];
1249 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1250 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1252 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1254 if( i_port != config_GetInt( p_intf, "server-port" ) )
1257 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1263 o_mrl_string = [o_net_http_url stringValue];
1265 [self setMRL: o_mrl_string];
1268 - (IBAction)openNetUDPButtonAction:(id)sender
1270 if( sender == o_net_openUDP_btn )
1272 [NSApp beginSheet: o_net_udp_panel
1273 modalForWindow: o_panel
1275 didEndSelector: NULL
1277 [self openNetInfoChanged: nil];
1279 else if( sender == o_net_udp_cancel_btn )
1281 [o_net_udp_panel orderOut: sender];
1282 [NSApp endSheet: o_net_udp_panel];
1284 else if( sender == o_net_udp_ok_btn )
1286 NSString *o_mrl_string = [NSString string];
1287 if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
1289 int i_port = [o_net_udp_port intValue];
1291 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1292 o_mrl_string = @"udp://";
1294 o_mrl_string = @"rtp://";
1296 if( i_port != config_GetInt( p_intf, "server-port" ) )
1299 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1302 else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
1304 NSString *o_addr = [o_net_udpm_addr stringValue];
1305 int i_port = [o_net_udpm_port intValue];
1307 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1308 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1310 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1312 if( i_port != config_GetInt( p_intf, "server-port" ) )
1315 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1318 [self setMRL: o_mrl_string];
1319 [o_net_http_url setStringValue: o_mrl_string];
1320 [o_net_udp_panel orderOut: sender];
1321 [NSApp endSheet: o_net_udp_panel];
1326 #pragma mark Capture Panel
1328 - (void)showCaptureView: theView
1331 o_view_rect = [theView frame];
1332 [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
1333 [theView setAutoresizesSubviews: YES];
1334 if (o_currentCaptureView)
1336 [[[[o_tabview tabViewItemAtIndex: 3] view] animator] replaceSubview: o_currentCaptureView with: theView];
1337 [o_currentCaptureView release];
1341 [[[[o_tabview tabViewItemAtIndex: 3] view] animator] addSubview: theView];
1343 o_currentCaptureView = theView;
1344 [o_currentCaptureView retain];
1347 - (IBAction)openCaptureModeChanged:(id)sender
1349 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1351 if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1353 if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1355 [self showCaptureView: o_eyetv_running_view];
1356 [self setupChannelInfo];
1360 setEyeTVUnconnected;
1364 [self showCaptureView: o_eyetv_notLaunched_view];
1367 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1369 [self showCaptureView: o_screen_view];
1370 [self setMRL: @"screen://"];
1371 [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
1372 [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
1373 [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
1374 [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
1375 [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
1376 [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
1378 int screen_index = config_GetInt( p_intf, "screen-index" );
1379 int display_id = config_GetInt( p_intf, "screen-display-id" );
1380 unsigned int i, displayCount = 0;
1381 CGLError returnedError;
1382 struct display_info_t *item;
1385 returnedError = CGGetOnlineDisplayList( 0, NULL, &displayCount );
1386 if( !returnedError )
1388 CGDirectDisplayID *ids;
1389 ids = ( CGDirectDisplayID * )malloc( displayCount * sizeof( CGDirectDisplayID ) );
1390 returnedError = CGGetOnlineDisplayList( displayCount, ids, &displayCount );
1391 if( !returnedError )
1393 for( i = 0; i < [o_displayInfos count]; i ++ )
1395 v = [o_displayInfos objectAtIndex:i];
1396 free( [v pointerValue] );
1398 [o_displayInfos removeAllObjects];
1399 [o_screen_screen_pop removeAllItems];
1400 for( i = 0; i < displayCount; i ++ )
1402 item = ( struct display_info_t * )malloc( sizeof( struct display_info_t ) );
1404 item->rect = CGDisplayBounds( item->id );
1405 [o_screen_screen_pop addItemWithTitle: [NSString stringWithFormat:@"Screen %d (%dx%d)", i + 1, (int)item->rect.size.width, (int)item->rect.size.height]];
1406 v = [NSValue valueWithPointer:item];
1407 [o_displayInfos addObject:v];
1408 if( i == 0 || display_id == item->id || screen_index - 1 == i )
1410 [o_screen_screen_pop selectItemAtIndex: i];
1411 [o_screen_left_stp setMaxValue: item->rect.size.width];
1412 [o_screen_top_stp setMaxValue: item->rect.size.height];
1413 [o_screen_width_stp setMaxValue: item->rect.size.width];
1414 [o_screen_height_stp setMaxValue: item->rect.size.height];
1421 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")] )
1423 [self showCaptureView: o_qtk_view];
1424 if ([o_capture_width_fld intValue] <= 0)
1425 [self qtkChanged:nil];
1427 [self qtkAudioChanged:nil];
1431 if ([o_qtk_video_ckb state] && qtk_currdevice_uid)
1432 [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
1433 else if([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
1434 [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
1438 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1440 [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1441 if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1442 [o_screen_fps_fld setFloatValue: 1.0];
1443 [self setMRL: @"screen://"];
1446 - (IBAction)eyetvSwitchChannel:(id)sender
1448 if( sender == o_eyetv_nextProgram_btn )
1450 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1451 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1452 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1454 else if( sender == o_eyetv_previousProgram_btn )
1456 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1457 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1458 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1460 else if( sender == o_eyetv_channels_pop )
1462 int chanNum = [[sender selectedItem] tag];
1463 [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1464 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1467 msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1470 - (IBAction)eyetvLaunch:(id)sender
1472 [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1475 - (IBAction)eyetvGetPlugin:(id)sender
1477 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1480 - (void)eyetvChanged:(NSNotification *)o_notification
1482 if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1484 msg_Dbg( VLCIntf, "eyetv device was added" );
1485 [self showCaptureView: o_eyetv_running_view];
1486 [self setupChannelInfo];
1488 else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1490 /* leave the channel selection like that,
1491 * switch to our "no device" tab */
1492 msg_Dbg( VLCIntf, "eyetv device was removed" );
1493 setEyeTVUnconnected;
1495 else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1497 /* switch to the "launch eyetv" tab */
1498 msg_Dbg( VLCIntf, "eyetv was terminated" );
1499 [self showCaptureView: o_eyetv_notLaunched_view];
1501 else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1503 /* we got no device yet */
1504 msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1505 setEyeTVUnconnected;
1509 /* little helper method, since this code needs to be run by multiple objects */
1510 - (void)setupChannelInfo
1512 /* set up channel selection */
1513 [o_eyetv_channels_pop removeAllItems];
1514 [o_eyetv_chn_bgbar setHidden: NO];
1515 [o_eyetv_chn_bgbar animate: self];
1516 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1517 [o_eyetv_chn_status_txt setHidden: NO];
1520 NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1522 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1524 keyEquivalent: @""] setTag:x++];
1525 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1527 keyEquivalent: @""] setTag:x++];
1531 [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1532 while( channel = [channels nextObject] )
1534 /* we have to add items this way, because we accept duplicates
1535 * additionally, we save a bit of time */
1536 [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1538 keyEquivalent: @""] setTag:++x];
1540 /* make Tuner the default */
1541 [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1545 [o_eyetv_chn_bgbar setHidden: YES];
1546 [o_eyetv_chn_status_txt setHidden: YES];
1550 #pragma mark Subtitle Settings
1552 - (IBAction)subsChanged:(id)sender
1554 if ([o_file_sub_ckbox state] == NSOnState)
1556 [o_file_sub_btn_settings setEnabled:YES];
1558 [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1559 [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1564 [o_file_sub_btn_settings setEnabled:NO];
1565 [o_file_subtitles_filename_lbl setStringValue: @""];
1566 [o_file_subtitles_icon_well setImage: NULL];
1570 - (IBAction)subSettings:(id)sender
1572 [NSApp beginSheet: o_file_sub_sheet
1573 modalForWindow: [sender window]
1575 didEndSelector: NULL
1579 - (IBAction)subCloseSheet:(id)sender
1581 [self subsChanged: nil];
1582 [o_file_sub_sheet orderOut:sender];
1583 [NSApp endSheet: o_file_sub_sheet];
1586 - (IBAction)subFileBrowse:(id)sender
1588 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1590 [o_open_panel setAllowsMultipleSelection: NO];
1591 [o_open_panel setTitle: _NS("Open File")];
1592 [o_open_panel setPrompt: _NS("Open")];
1594 if( [o_open_panel runModal] == NSOKButton )
1596 o_sub_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1597 [o_sub_path retain];
1598 [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1599 [o_file_sub_path_fld setStringValue: [o_file_subtitles_filename_lbl stringValue]];
1600 [o_file_sub_path_lbl setHidden: YES];
1601 [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1602 [o_file_sub_icon_view setImage: [o_file_subtitles_icon_well image]];
1606 [o_file_sub_path_lbl setHidden: NO];
1607 [o_file_sub_path_fld setStringValue:@""];
1608 [o_file_subtitles_filename_lbl setStringValue:@""];
1609 [o_file_subtitles_icon_well setImage: nil];
1610 [o_file_sub_icon_view setImage: nil];
1614 - (IBAction)subOverride:(id)sender
1616 BOOL b_state = [o_file_sub_override state];
1617 [o_file_sub_delay setEnabled: b_state];
1618 [o_file_sub_delay_stp setEnabled: b_state];
1619 [o_file_sub_fps setEnabled: b_state];
1620 [o_file_sub_fps_stp setEnabled: b_state];
1623 - (IBAction)subDelayStepperChanged:(id)sender
1625 [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1628 - (IBAction)subFpsStepperChanged:(id)sender;
1630 [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1634 #pragma mark Miscellaneous
1636 - (IBAction)panelCancel:(id)sender
1638 [NSApp stopModalWithCode: 0];
1641 - (IBAction)panelOk:(id)sender
1643 if( [[self MRL] length] )
1644 [NSApp stopModalWithCode: 1];
1649 - (NSArray *)qtkvideoDevices
1651 if ( !qtkvideoDevices )
1652 [self qtkrefreshVideoDevices];
1653 return qtkvideoDevices;
1656 - (void)qtkrefreshVideoDevices
1658 [qtkvideoDevices release];
1659 qtkvideoDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1662 - (NSArray *)qtkaudioDevices
1664 if ( !qtkaudioDevices )
1665 [self qtkrefreshAudioDevices];
1666 return qtkaudioDevices;
1669 - (void)qtkrefreshAudioDevices
1671 [qtkaudioDevices release];
1672 qtkaudioDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeSound] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1677 @implementation VLCOpenTextField
1679 - (void)mouseDown:(NSEvent *)theEvent
1681 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1683 [super mouseDown: theEvent];