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")];
755 [o_open_panel beginSheetModalForWindow:[sender window] completionHandler:^(NSInteger returnCode) {
756 if (returnCode == NSFileHandlingPanelOKButton)
759 [o_file_path release];
760 o_file_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
761 [o_file_path retain];
762 [self openFilePathChanged: nil];
767 - (IBAction)openFileStreamChanged:(id)sender
769 [self openFilePathChanged: nil];
772 - (IBAction)inputSlaveAction:(id)sender
774 if( sender == o_file_slave_ckbox )
775 [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
778 NSOpenPanel *o_open_panel;
779 o_open_panel = [NSOpenPanel openPanel];
780 [o_open_panel setCanChooseFiles: YES];
781 [o_open_panel setCanChooseDirectories: NO];
782 if( [o_open_panel runModal] == NSOKButton )
784 if( o_file_slave_path )
785 [o_file_slave_path release];
786 o_file_slave_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
787 [o_file_slave_path retain];
790 if( o_file_slave_path && [o_file_slave_ckbox state] == NSOnState)
792 [o_file_slave_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_slave_path]];
793 [o_file_slave_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_slave_path]];
797 [o_file_slave_filename_lbl setStringValue: @""];
798 [o_file_slave_icon_well setImage: NULL];
802 - (IBAction)fileTimeCustomization:(id)sender
804 BOOL b_value = [o_file_custom_timing_ckb state];
805 [o_file_starttime_fld setEnabled: b_value];
806 [o_file_starttime_lbl setEnabled: b_value];
807 [o_file_stoptime_fld setEnabled: b_value];
808 [o_file_stoptime_lbl setEnabled: b_value];
812 #pragma mark Optical Media Panel
814 - (void)showOpticalMediaView: theView withIcon:(NSImage *)icon
817 o_view_rect = [theView frame];
818 [theView setFrame: NSMakeRect( 233, 0, o_view_rect.size.width, o_view_rect.size.height)];
819 [theView setAutoresizesSubviews: YES];
820 if (o_currentOpticalMediaView)
822 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaView with: theView];
823 [o_currentOpticalMediaView release];
826 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: theView];
827 o_currentOpticalMediaView = theView;
828 [o_currentOpticalMediaView retain];
830 NSImageView *imageView;
831 imageView = [[NSImageView alloc] init];
832 [imageView setFrame: NSMakeRect( 53, 61, 128, 128 )];
833 [icon setSize: NSMakeSize(128,128)];
834 [imageView setImage: icon];
835 if (o_currentOpticalMediaIconView)
837 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaIconView with: imageView];
838 [o_currentOpticalMediaIconView release];
841 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: imageView];
842 o_currentOpticalMediaIconView = imageView;
843 [o_currentOpticalMediaIconView retain];
844 [o_currentOpticalMediaView setNeedsDisplay: YES];
845 [o_currentOpticalMediaIconView setNeedsDisplay: YES];
846 [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] setNeedsDisplay: YES];
847 [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] displayIfNeeded];
850 - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
854 FSVolumeRefNum actualVolume;
855 err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
857 // get a FSVolumeRefNum from mountPath
858 if ( noErr == err ) {
859 FSCatalogInfo catalogInfo;
860 err = FSGetCatalogInfo ( &ref,
868 actualVolume = catalogInfo.volume;
875 GetVolParmsInfoBuffer volumeParms;
876 err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
879 NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
880 return [NSString stringWithFormat:@"/dev/r%@", bsdName];
886 - (char *)getVolumeTypeFromMountPath:(NSString *)mountPath
890 FSVolumeRefNum actualVolume;
891 err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
893 // get a FSVolumeRefNum from mountPath
894 if ( noErr == err ) {
895 FSCatalogInfo catalogInfo;
896 err = FSGetCatalogInfo ( &ref,
904 actualVolume = catalogInfo.volume;
911 GetVolParmsInfoBuffer volumeParms;
912 err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
914 CFMutableDictionaryRef matchingDict;
915 io_service_t service;
917 if (!volumeParms.vMDeviceID)
920 matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
921 service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
924 if (IO_OBJECT_NULL != service) {
925 if (IOObjectConformsTo(service, kIOCDMediaClass)) {
926 returnValue = kVLCMediaAudioCD;
928 else if(IOObjectConformsTo(service, kIODVDMediaClass))
929 returnValue = kVLCMediaDVD;
930 else if(IOObjectConformsTo(service, kIOBDMediaClass))
931 returnValue = kVLCMediaBD;
934 if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
935 returnValue = kVLCMediaVideoTSFolder;
936 else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
937 returnValue = kVLCMediaBDMVFolder;
940 // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
941 NSFileManager * fm = [[NSFileManager alloc] init];
943 NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
944 for (int i = 0; i < [dirContents count]; i++)
946 NSString *currentFile = [dirContents objectAtIndex:i];
947 NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
950 if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
952 if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame)
954 returnValue = kVLCMediaSVCD;
957 if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame)
959 returnValue = kVLCMediaVCD;
962 if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame)
964 returnValue = kVLCMediaBDMVFolder;
967 if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame)
969 returnValue = kVLCMediaVideoTSFolder;
978 returnValue = kVLCMediaVideoTSFolder;
982 IOObjectRelease(service);
987 - (void)showOpticalAtPath: (NSString *)o_opticalDevicePath
989 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
991 char *diskType = [self getVolumeTypeFromMountPath:o_opticalDevicePath];
993 if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder)
995 [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_opticalDevicePath]];
996 [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
997 NSString *pathToOpen;
998 if (diskType == kVLCMediaVideoTSFolder)
999 pathToOpen = o_opticalDevicePath;
1001 pathToOpen = [self getBSDNodeFromMountPath: o_opticalDevicePath];
1002 if (!b_nodvdmenus) {
1003 [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1004 [self showOpticalMediaView: o_disc_dvd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1006 [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1007 [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1010 else if (diskType == kVLCMediaAudioCD)
1012 [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1013 [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_opticalDevicePath error:NULL] count] - 1]]; // minus .TOC.plist
1014 [self showOpticalMediaView: o_disc_audiocd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1015 [self setMRL: [NSString stringWithFormat: @"cdda://%@", [self getBSDNodeFromMountPath: o_opticalDevicePath]]];
1017 else if (diskType == kVLCMediaVCD)
1019 [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1020 [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1021 [self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1023 else if (diskType == kVLCMediaSVCD)
1025 [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1026 [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1027 [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1029 else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
1031 [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1032 [self showOpticalMediaView: o_disc_bd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1033 [self setMRL: [NSString stringWithFormat: @"bluray://%@", o_opticalDevicePath]];
1037 msg_Warn( VLCIntf, "unknown disk type, no idea what to display" );
1038 [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
1044 - (void)showSelectedOpticalDisc
1046 NSString *o_opticalDevicePath = [o_opticalDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];
1047 [NSThread detachNewThreadSelector:@selector(showOpticalAtPath:) toTarget:self withObject:o_opticalDevicePath];
1050 - (void)scanOpticalMedia:(NSNotification *)o_notification
1052 [o_opticalDevices removeAllObjects];
1053 [o_disc_selector_pop removeAllItems];
1054 [o_opticalDevices addObjectsFromArray: [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
1055 [o_opticalDevices addObjectsFromArray: o_specialMediaFolders];
1056 if ([o_opticalDevices count] > 0) {
1057 NSUInteger deviceCount = [o_opticalDevices count];
1058 for (NSUInteger i = 0; i < deviceCount ; i++)
1059 [o_disc_selector_pop addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: i]]];
1061 if ([o_disc_selector_pop numberOfItems] <= 1)
1062 [o_disc_selector_pop setHidden: YES];
1064 [o_disc_selector_pop setHidden: NO];
1066 // select newly added media folder
1067 if (o_notification && [[o_notification name] isEqualToString:@"VLCNewMediaFolderNotification"])
1068 [o_disc_selector_pop selectItemAtIndex: [[o_disc_selector_pop itemArray] count] - 1];
1070 [self showSelectedOpticalDisc];
1074 msg_Dbg( VLCIntf, "no optical media found" );
1075 [o_disc_selector_pop setHidden: YES];
1076 [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed: @"NSApplicationIcon"]];
1080 - (IBAction)discSelectorChanged:(id)sender
1082 [self showSelectedOpticalDisc];
1085 - (IBAction)openSpecialMediaFolder:(id)sender
1087 /* this is currently for VIDEO_TS and BDMV folders */
1088 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1090 [o_open_panel setAllowsMultipleSelection: NO];
1091 [o_open_panel setCanChooseFiles: NO];
1092 [o_open_panel setCanChooseDirectories: YES];
1093 [o_open_panel setTitle: [sender title]];
1094 [o_open_panel setPrompt: _NS("Open")];
1096 if ([o_open_panel runModal] == NSOKButton)
1098 NSString *o_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1099 if ([o_path length] > 0 )
1101 [o_specialMediaFolders addObject: o_path];
1102 [self scanOpticalMedia: [NSNotification notificationWithName:@"VLCNewMediaFolderNotification" object:nil]];
1107 - (IBAction)dvdreadOptionChanged:(id)sender
1109 NSString *o_device_path = [o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]];
1110 char *diskType = [self getVolumeTypeFromMountPath:o_device_path];
1112 NSString *pathToOpen;
1113 if (diskType == kVLCMediaVideoTSFolder)
1114 pathToOpen = o_device_path;
1116 pathToOpen = [self getBSDNodeFromMountPath: o_device_path];
1118 if (sender == o_disc_dvdwomenus_enablemenus_btn) {
1120 [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1121 [self showOpticalMediaView: o_disc_dvd_view withIcon: [o_currentOpticalMediaIconView image]];
1124 if (sender == o_disc_dvd_disablemenus_btn) {
1126 [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [o_currentOpticalMediaIconView image]];
1129 if (sender == o_disc_dvdwomenus_title)
1130 [o_disc_dvdwomenus_title_stp setIntValue: [o_disc_dvdwomenus_title intValue]];
1131 if (sender == o_disc_dvdwomenus_title_stp)
1132 [o_disc_dvdwomenus_title setIntValue: [o_disc_dvdwomenus_title_stp intValue]];
1133 if (sender == o_disc_dvdwomenus_chapter)
1134 [o_disc_dvdwomenus_chapter_stp setIntValue: [o_disc_dvdwomenus_chapter intValue]];
1135 if (sender == o_disc_dvdwomenus_chapter_stp)
1136 [o_disc_dvdwomenus_chapter setIntValue: [o_disc_dvdwomenus_chapter_stp intValue]];
1138 [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1141 - (IBAction)vcdOptionChanged:(id)sender
1143 if (sender == o_disc_vcd_title)
1144 [o_disc_vcd_title_stp setIntValue: [o_disc_vcd_title intValue]];
1145 if (sender == o_disc_vcd_title_stp)
1146 [o_disc_vcd_title setIntValue: [o_disc_vcd_title_stp intValue]];
1147 if (sender == o_disc_vcd_chapter)
1148 [o_disc_vcd_chapter_stp setIntValue: [o_disc_vcd_chapter intValue]];
1149 if (sender == o_disc_vcd_chapter_stp)
1150 [o_disc_vcd_chapter setIntValue: [o_disc_vcd_chapter_stp intValue]];
1152 [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]]];
1156 #pragma mark Network Panel
1158 - (void)textFieldWasClicked:(NSNotification *)o_notification
1160 if( [o_notification object] == o_net_udp_port )
1161 [o_net_mode selectCellAtRow: 0 column: 0];
1162 else if( [o_notification object] == o_net_udpm_addr ||
1163 [o_notification object] == o_net_udpm_port )
1164 [o_net_mode selectCellAtRow: 1 column: 0];
1166 [o_net_mode selectCellAtRow: 2 column: 0];
1168 [self openNetInfoChanged: nil];
1171 - (IBAction)openNetModeChanged:(id)sender
1173 if( sender == o_net_mode )
1175 if( [[sender selectedCell] tag] == 0 )
1176 [o_panel makeFirstResponder: o_net_udp_port];
1177 else if ( [[sender selectedCell] tag] == 1 )
1178 [o_panel makeFirstResponder: o_net_udpm_addr];
1180 msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
1183 [self openNetInfoChanged: nil];
1186 - (IBAction)openNetStepperChanged:(id)sender
1188 int i_tag = [sender tag];
1192 [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
1193 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1194 object: o_net_udp_port];
1195 [o_panel makeFirstResponder: o_net_udp_port];
1197 else if( i_tag == 1 )
1199 [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
1200 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1201 object: o_net_udpm_port];
1202 [o_panel makeFirstResponder: o_net_udpm_port];
1205 [self openNetInfoChanged: nil];
1208 - (void)openNetInfoChanged:(NSNotification *)o_notification
1210 NSString *o_mrl_string = [NSString string];
1212 if( [o_net_udp_panel isVisible] )
1215 o_mode = [[o_net_mode selectedCell] title];
1217 if( [o_mode isEqualToString: _NS("Unicast")] )
1219 int i_port = [o_net_udp_port intValue];
1221 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1222 o_mrl_string = @"udp://";
1224 o_mrl_string = @"rtp://";
1226 if( i_port != config_GetInt( p_intf, "server-port" ) )
1229 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1232 else if( [o_mode isEqualToString: _NS("Multicast")] )
1234 NSString *o_addr = [o_net_udpm_addr stringValue];
1235 int i_port = [o_net_udpm_port intValue];
1237 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1238 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1240 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1242 if( i_port != config_GetInt( p_intf, "server-port" ) )
1245 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1251 o_mrl_string = [o_net_http_url stringValue];
1253 [self setMRL: o_mrl_string];
1256 - (IBAction)openNetUDPButtonAction:(id)sender
1258 if( sender == o_net_openUDP_btn )
1260 [NSApp beginSheet: o_net_udp_panel
1261 modalForWindow: o_panel
1263 didEndSelector: NULL
1265 [self openNetInfoChanged: nil];
1267 else if( sender == o_net_udp_cancel_btn )
1269 [o_net_udp_panel orderOut: sender];
1270 [NSApp endSheet: o_net_udp_panel];
1272 else if( sender == o_net_udp_ok_btn )
1274 NSString *o_mrl_string = [NSString string];
1275 if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
1277 int i_port = [o_net_udp_port intValue];
1279 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1280 o_mrl_string = @"udp://";
1282 o_mrl_string = @"rtp://";
1284 if( i_port != config_GetInt( p_intf, "server-port" ) )
1287 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1290 else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
1292 NSString *o_addr = [o_net_udpm_addr stringValue];
1293 int i_port = [o_net_udpm_port intValue];
1295 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1296 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1298 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1300 if( i_port != config_GetInt( p_intf, "server-port" ) )
1303 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1306 [self setMRL: o_mrl_string];
1307 [o_net_http_url setStringValue: o_mrl_string];
1308 [o_net_udp_panel orderOut: sender];
1309 [NSApp endSheet: o_net_udp_panel];
1314 #pragma mark Capture Panel
1316 - (void)showCaptureView: theView
1319 o_view_rect = [theView frame];
1320 [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
1321 [theView setAutoresizesSubviews: YES];
1322 if (o_currentCaptureView)
1324 [[[[o_tabview tabViewItemAtIndex: 3] view] animator] replaceSubview: o_currentCaptureView with: theView];
1325 [o_currentCaptureView release];
1329 [[[[o_tabview tabViewItemAtIndex: 3] view] animator] addSubview: theView];
1331 o_currentCaptureView = theView;
1332 [o_currentCaptureView retain];
1335 - (IBAction)openCaptureModeChanged:(id)sender
1337 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1339 if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1341 if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1343 [self showCaptureView: o_eyetv_running_view];
1344 [self setupChannelInfo];
1348 setEyeTVUnconnected;
1352 [self showCaptureView: o_eyetv_notLaunched_view];
1355 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1357 [self showCaptureView: o_screen_view];
1358 [self setMRL: @"screen://"];
1359 [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
1360 [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
1361 [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
1362 [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
1363 [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
1364 [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
1366 int screen_index = config_GetInt( p_intf, "screen-index" );
1367 int display_id = config_GetInt( p_intf, "screen-display-id" );
1368 unsigned int i, displayCount = 0;
1369 CGLError returnedError;
1370 struct display_info_t *item;
1373 returnedError = CGGetOnlineDisplayList( 0, NULL, &displayCount );
1374 if( !returnedError )
1376 CGDirectDisplayID *ids;
1377 ids = ( CGDirectDisplayID * )malloc( displayCount * sizeof( CGDirectDisplayID ) );
1378 returnedError = CGGetOnlineDisplayList( displayCount, ids, &displayCount );
1379 if( !returnedError )
1381 for( i = 0; i < [o_displayInfos count]; i ++ )
1383 v = [o_displayInfos objectAtIndex:i];
1384 free( [v pointerValue] );
1386 [o_displayInfos removeAllObjects];
1387 [o_screen_screen_pop removeAllItems];
1388 for( i = 0; i < displayCount; i ++ )
1390 item = ( struct display_info_t * )malloc( sizeof( struct display_info_t ) );
1392 item->rect = CGDisplayBounds( item->id );
1393 [o_screen_screen_pop addItemWithTitle: [NSString stringWithFormat:@"Screen %d (%dx%d)", i + 1, (int)item->rect.size.width, (int)item->rect.size.height]];
1394 v = [NSValue valueWithPointer:item];
1395 [o_displayInfos addObject:v];
1396 if( i == 0 || display_id == item->id || screen_index - 1 == i )
1398 [o_screen_screen_pop selectItemAtIndex: i];
1399 [o_screen_left_stp setMaxValue: item->rect.size.width];
1400 [o_screen_top_stp setMaxValue: item->rect.size.height];
1401 [o_screen_width_stp setMaxValue: item->rect.size.width];
1402 [o_screen_height_stp setMaxValue: item->rect.size.height];
1409 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")] )
1411 [self showCaptureView: o_qtk_view];
1412 if ([o_capture_width_fld intValue] <= 0)
1413 [self qtkChanged:nil];
1415 [self qtkAudioChanged:nil];
1419 if ([o_qtk_video_ckb state] && qtk_currdevice_uid)
1420 [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
1421 else if([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
1422 [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
1426 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1428 [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1429 if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1430 [o_screen_fps_fld setFloatValue: 1.0];
1431 [self setMRL: @"screen://"];
1434 - (IBAction)eyetvSwitchChannel:(id)sender
1436 if( sender == o_eyetv_nextProgram_btn )
1438 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1439 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1440 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1442 else if( sender == o_eyetv_previousProgram_btn )
1444 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1445 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1446 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1448 else if( sender == o_eyetv_channels_pop )
1450 int chanNum = [[sender selectedItem] tag];
1451 [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1452 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1455 msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1458 - (IBAction)eyetvLaunch:(id)sender
1460 [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1463 - (IBAction)eyetvGetPlugin:(id)sender
1465 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1468 - (void)eyetvChanged:(NSNotification *)o_notification
1470 if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1472 msg_Dbg( VLCIntf, "eyetv device was added" );
1473 [self showCaptureView: o_eyetv_running_view];
1474 [self setupChannelInfo];
1476 else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1478 /* leave the channel selection like that,
1479 * switch to our "no device" tab */
1480 msg_Dbg( VLCIntf, "eyetv device was removed" );
1481 setEyeTVUnconnected;
1483 else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1485 /* switch to the "launch eyetv" tab */
1486 msg_Dbg( VLCIntf, "eyetv was terminated" );
1487 [self showCaptureView: o_eyetv_notLaunched_view];
1489 else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1491 /* we got no device yet */
1492 msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1493 setEyeTVUnconnected;
1497 /* little helper method, since this code needs to be run by multiple objects */
1498 - (void)setupChannelInfo
1500 /* set up channel selection */
1501 [o_eyetv_channels_pop removeAllItems];
1502 [o_eyetv_chn_bgbar setHidden: NO];
1503 [o_eyetv_chn_bgbar animate: self];
1504 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1505 [o_eyetv_chn_status_txt setHidden: NO];
1508 NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1510 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1512 keyEquivalent: @""] setTag:x++];
1513 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1515 keyEquivalent: @""] setTag:x++];
1519 [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1520 while( channel = [channels nextObject] )
1522 /* we have to add items this way, because we accept duplicates
1523 * additionally, we save a bit of time */
1524 [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1526 keyEquivalent: @""] setTag:++x];
1528 /* make Tuner the default */
1529 [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1533 [o_eyetv_chn_bgbar setHidden: YES];
1534 [o_eyetv_chn_status_txt setHidden: YES];
1538 #pragma mark Subtitle Settings
1540 - (IBAction)subsChanged:(id)sender
1542 if ([o_file_sub_ckbox state] == NSOnState)
1544 [o_file_sub_btn_settings setEnabled:YES];
1546 [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1547 [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1552 [o_file_sub_btn_settings setEnabled:NO];
1553 [o_file_subtitles_filename_lbl setStringValue: @""];
1554 [o_file_subtitles_icon_well setImage: NULL];
1558 - (IBAction)subSettings:(id)sender
1560 [NSApp beginSheet: o_file_sub_sheet
1561 modalForWindow: [sender window]
1563 didEndSelector: NULL
1567 - (IBAction)subCloseSheet:(id)sender
1569 [self subsChanged: nil];
1570 [o_file_sub_sheet orderOut:sender];
1571 [NSApp endSheet: o_file_sub_sheet];
1574 - (IBAction)subFileBrowse:(id)sender
1576 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1578 [o_open_panel setAllowsMultipleSelection: NO];
1579 [o_open_panel setTitle: _NS("Open File")];
1580 [o_open_panel setPrompt: _NS("Open")];
1582 if( [o_open_panel runModal] == NSOKButton )
1584 o_sub_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1585 [o_sub_path retain];
1586 [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1587 [o_file_sub_path_fld setStringValue: [o_file_subtitles_filename_lbl stringValue]];
1588 [o_file_sub_path_lbl setHidden: YES];
1589 [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1590 [o_file_sub_icon_view setImage: [o_file_subtitles_icon_well image]];
1594 [o_file_sub_path_lbl setHidden: NO];
1595 [o_file_sub_path_fld setStringValue:@""];
1596 [o_file_subtitles_filename_lbl setStringValue:@""];
1597 [o_file_subtitles_icon_well setImage: nil];
1598 [o_file_sub_icon_view setImage: nil];
1602 - (IBAction)subOverride:(id)sender
1604 BOOL b_state = [o_file_sub_override state];
1605 [o_file_sub_delay setEnabled: b_state];
1606 [o_file_sub_delay_stp setEnabled: b_state];
1607 [o_file_sub_fps setEnabled: b_state];
1608 [o_file_sub_fps_stp setEnabled: b_state];
1611 - (IBAction)subDelayStepperChanged:(id)sender
1613 [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1616 - (IBAction)subFpsStepperChanged:(id)sender;
1618 [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1622 #pragma mark Miscellaneous
1624 - (IBAction)panelCancel:(id)sender
1626 [NSApp stopModalWithCode: 0];
1629 - (IBAction)panelOk:(id)sender
1631 if( [[self MRL] length] )
1632 [NSApp stopModalWithCode: 1];
1637 - (NSArray *)qtkvideoDevices
1639 if ( !qtkvideoDevices )
1640 [self qtkrefreshVideoDevices];
1641 return qtkvideoDevices;
1644 - (void)qtkrefreshVideoDevices
1646 [qtkvideoDevices release];
1647 qtkvideoDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1650 - (NSArray *)qtkaudioDevices
1652 if ( !qtkaudioDevices )
1653 [self qtkrefreshAudioDevices];
1654 return qtkaudioDevices;
1657 - (void)qtkrefreshAudioDevices
1659 [qtkaudioDevices release];
1660 qtkaudioDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeSound] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1665 @implementation VLCOpenTextField
1667 - (void)mouseDown:(NSEvent *)theEvent
1669 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1671 [super mouseDown: theEvent];