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
73 static VLCOpen *_o_sharedMainInstance = nil;
75 + (VLCOpen *)sharedInstance
77 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
82 if( _o_sharedMainInstance) {
85 _o_sharedMainInstance = [super init];
89 return _o_sharedMainInstance;
94 [o_specialMediaFolders release];
95 [o_opticalDevices release];
96 if( o_file_slave_path )
97 [o_file_slave_path release];
100 [o_sub_path release];
101 [o_currentOpticalMediaIconView release];
102 [o_currentOpticalMediaView release];
104 for( i = 0; i < [o_displayInfos count]; i ++ )
106 NSValue *v = [o_displayInfos objectAtIndex:i];
107 free( [v pointerValue] );
109 [o_displayInfos removeAllObjects];
110 [o_displayInfos release];
118 [o_panel setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
120 [o_panel setTitle: _NS("Open Source")];
121 [o_mrl_lbl setStringValue: _NS("Media Resource Locator (MRL)")];
123 [o_btn_ok setTitle: _NS("Open")];
124 [o_btn_cancel setTitle: _NS("Cancel")];
126 [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
127 [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
128 [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
129 [[o_tabview tabViewItemAtIndex: 3] setLabel: _NS("Capture")];
131 [o_file_name setStringValue: @""];
132 [o_file_name_stub setStringValue: _NS("Choose a file")];
133 [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
134 [o_file_btn_browse setTitle: _NS("Browse...")];
135 [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
136 [o_file_stream setHidden: NO];
137 [o_file_slave_ckbox setTitle: _NS("Play another media synchronously")];
138 [o_file_slave_select_btn setTitle: _NS("Choose...")];
139 [o_file_slave_filename_lbl setStringValue: @""];
140 [o_file_slave_icon_well setImage: NULL];
141 [o_file_subtitles_filename_lbl setStringValue: @""];
142 [o_file_subtitles_icon_well setImage: NULL];
144 [o_disc_selector_pop removeAllItems];
145 [o_disc_selector_pop setHidden: NO];
146 NSString *o_videots = _NS("Open VIDEO_TS folder");
147 NSString *o_bdmv = _NS("Open BDMV folder");
148 [o_disc_nodisc_lbl setStringValue: _NS("Insert Disc")];
149 [o_disc_nodisc_videots_btn setTitle: o_videots];
150 [o_disc_nodisc_bdmv_btn setTitle: o_bdmv];
151 [o_disc_audiocd_lbl setStringValue: _NS("Audio CD")];
152 [o_disc_audiocd_trackcount_lbl setStringValue: @""];
153 [o_disc_audiocd_videots_btn setTitle: o_videots];
154 [o_disc_audiocd_bdmv_btn setTitle: o_bdmv];
155 [o_disc_dvd_lbl setStringValue: @""];
156 [o_disc_dvd_disablemenus_btn setTitle: _NS("Disable DVD menus")];
157 [o_disc_dvd_videots_btn setTitle: o_videots];
158 [o_disc_dvd_bdmv_btn setTitle: o_bdmv];
159 [o_disc_dvdwomenus_lbl setStringValue: @""];
160 [o_disc_dvdwomenus_enablemenus_btn setTitle: _NS("Enable DVD menus")];
161 [o_disc_dvdwomenus_videots_btn setTitle: o_videots];
162 [o_disc_dvdwomenus_bdmv_btn setTitle: o_bdmv];
163 [o_disc_dvdwomenus_title_lbl setStringValue: _NS("Title")];
164 [o_disc_dvdwomenus_chapter_lbl setStringValue: _NS("Chapter")];
165 [o_disc_vcd_title_lbl setStringValue: _NS("Title")];
166 [o_disc_vcd_chapter_lbl setStringValue: _NS("Chapter")];
167 [o_disc_vcd_videots_btn setTitle: o_videots];
168 [o_disc_vcd_bdmv_btn setTitle: o_bdmv];
169 [o_disc_bd_videots_btn setTitle: o_videots];
170 [o_disc_bd_bdmv_btn setTitle: o_bdmv];
172 [o_net_udp_port_lbl setStringValue: _NS("Port")];
173 [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
174 [o_net_udpm_port_lbl setStringValue: _NS("Port")];
175 [o_net_http_url_lbl setStringValue: _NS("URL")];
176 [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.")];
177 [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.")];
178 [o_net_udp_cancel_btn setTitle: _NS("Cancel")];
179 [o_net_udp_ok_btn setTitle: _NS("Open")];
180 [o_net_openUDP_btn setTitle: _NS("Open RTP/UDP Stream")];
181 [o_net_udp_mode_lbl setStringValue: _NS("Mode")];
182 [o_net_udp_protocol_lbl setStringValue: _NS("Protocol")];
183 [o_net_udp_address_lbl setStringValue: _NS("Address")];
185 [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
186 [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
188 [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
189 [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
191 [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
193 [o_capture_mode_pop removeAllItems];
194 [o_capture_mode_pop addItemWithTitle: _NS("Video Device")];
195 [o_capture_mode_pop addItemWithTitle: _NS("Audio Device")];
196 [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
197 [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
198 [o_screen_long_lbl setStringValue: _NS("This input allows you to save, stream or display your current screen contents.")];
199 [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
200 [o_screen_screen_lbl setStringValue: _NS("Screen:")];
201 [o_screen_left_lbl setStringValue: _NS("Subscreen left:")];
202 [o_screen_top_lbl setStringValue: _NS("Subscreen top:")];
203 [o_screen_width_lbl setStringValue: _NS("Subscreen width:")];
204 [o_screen_height_lbl setStringValue: _NS("Subscreen height:")];
205 [o_screen_follow_mouse_ckb setTitle: _NS("Follow the mouse")];
206 [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
207 [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
208 [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
209 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
210 [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
211 [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
212 [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
213 [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
214 [o_qtk_long_lbl setStringValue: _NS("This input allows you to process input signals from QuickTime-compatible video devices.\nSimultaneous live Audio input is not supported.")];
215 [o_capture_width_lbl setStringValue: _NS("Image width:")];
216 [o_capture_height_lbl setStringValue: _NS("Image height:")];
218 [self qtkvideoDevices];
219 [o_qtk_device_pop removeAllItems];
220 msg_Dbg( VLCIntf, "Found %lu video capture devices", [qtkvideoDevices count] );
222 if([qtkvideoDevices count] >= 1)
224 if (!qtk_currdevice_uid) {
225 qtk_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo] uniqueID]
226 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
228 NSUInteger deviceCount = [qtkvideoDevices count];
229 for(int ivideo = 0; ivideo < deviceCount; ivideo++){
230 QTCaptureDevice *qtk_device;
231 qtk_device = [qtkvideoDevices objectAtIndex:ivideo];
232 [o_qtk_device_pop addItemWithTitle: [qtk_device localizedDisplayName]];
233 if([[[qtk_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid]){
234 [o_qtk_device_pop selectItemAtIndex:ivideo];
240 [o_qtk_device_pop addItemWithTitle: _NS("None")];
241 [qtk_currdevice_uid release];
244 [self qtkaudioDevices];
245 [o_qtkaudio_device_pop removeAllItems];
246 msg_Dbg( VLCIntf, "Found %lu audio capture devices", [qtkaudioDevices count] );
248 if([qtkaudioDevices count] >= 1)
250 if (!qtkaudio_currdevice_uid) {
251 qtkaudio_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound] uniqueID]
252 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
254 NSUInteger deviceCount = [qtkaudioDevices count];
255 for(int iaudio = 0; iaudio < deviceCount; iaudio++){
256 QTCaptureDevice *qtkaudio_device;
257 qtkaudio_device = [qtkaudioDevices objectAtIndex:iaudio];
258 [o_qtkaudio_device_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
259 if([[[qtkaudio_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtkaudio_currdevice_uid]){
260 [o_qtkaudio_device_pop selectItemAtIndex:iaudio];
266 [o_qtkaudio_device_pop addItemWithTitle: _NS("None")];
267 [qtkaudio_currdevice_uid release];
272 [[NSNotificationCenter defaultCenter] addObserver: self
273 selector: @selector(openNetInfoChanged:)
274 name: NSControlTextDidChangeNotification
275 object: o_net_udp_port];
276 [[NSNotificationCenter defaultCenter] addObserver: self
277 selector: @selector(openNetInfoChanged:)
278 name: NSControlTextDidChangeNotification
279 object: o_net_udpm_addr];
280 [[NSNotificationCenter defaultCenter] addObserver: self
281 selector: @selector(openNetInfoChanged:)
282 name: NSControlTextDidChangeNotification
283 object: o_net_udpm_port];
284 [[NSNotificationCenter defaultCenter] addObserver: self
285 selector: @selector(openNetInfoChanged:)
286 name: NSControlTextDidChangeNotification
287 object: o_net_http_url];
289 [[NSDistributedNotificationCenter defaultCenter] addObserver: self
290 selector: @selector(eyetvChanged:)
292 object: @"VLCEyeTVSupport"
293 suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
295 [[NSNotificationCenter defaultCenter] addObserver: self
296 selector: @selector(screenFPSfieldChanged:)
297 name: NSControlTextDidChangeNotification
298 object: o_screen_fps_fld];
300 /* register clicks on text fields */
301 [[NSNotificationCenter defaultCenter] addObserver: self
302 selector: @selector(textFieldWasClicked:)
303 name: @"VLCOpenTextFieldWasClicked"
306 /* we want to be notified about removed or added media */
307 o_specialMediaFolders = [[NSMutableArray alloc] init];
308 o_opticalDevices = [[NSMutableArray alloc] init];
309 o_displayInfos = [[NSMutableArray alloc] init];
310 NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
312 [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidMountNotification object:nil];
313 [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidUnmountNotification object:nil];
314 [self performSelector:@selector(scanOpticalMedia:) withObject:nil afterDelay:2.0];
315 [self performSelector:@selector(qtkChanged:) withObject:nil afterDelay:2.5];
316 [self performSelector:@selector(qtkAudioChanged:) withObject:nil afterDelay:3.0];
321 - (void)setMRL:(NSString *)newMRL
326 [o_mrl_fld setStringValue: newMRL];
327 if ([o_mrl length] > 0)
328 [o_btn_ok setEnabled: YES];
330 [o_btn_ok setEnabled: NO];
341 module_config_t * p_item;
343 [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
344 [o_file_sub_path_lbl setStringValue: _NS("Choose a file")];
345 [o_file_sub_path_lbl setHidden: NO];
346 [o_file_sub_path_fld setStringValue: @""];
347 [o_file_sub_btn_settings setTitle: _NS("Choose...")];
348 [o_file_sub_btn_browse setTitle: _NS("Browse...")];
349 [o_file_sub_override setTitle: _NS("Override parameters")];
350 [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
351 [o_file_sub_delay_stp setEnabled: NO];
352 [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
353 [o_file_sub_fps_stp setEnabled: NO];
354 [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
355 [o_file_sub_encoding_pop removeAllItems];
356 [o_file_sub_size_lbl setStringValue: _NS("Font size")];
357 [o_file_sub_size_pop removeAllItems];
358 [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
359 [o_file_sub_align_pop removeAllItems];
360 [o_file_sub_ok_btn setStringValue: _NS("OK")];
361 [o_file_sub_font_box setTitle: _NS("Font Properties")];
362 [o_file_sub_file_box setTitle: _NS("Subtitle File")];
364 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
368 for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
371 [o_file_sub_encoding_pop addItemWithTitle:
372 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
374 [o_file_sub_encoding_pop selectItemWithTitle:
375 [NSString stringWithUTF8String: p_item->value.psz]];
378 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
382 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
384 [o_file_sub_align_pop addItemWithTitle:
385 _NS(p_item->ppsz_list_text[i_index])];
387 [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
390 p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
394 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
396 [o_file_sub_size_pop addItemWithTitle: _NS(p_item->ppsz_list_text[i_index])];
397 if ( p_item->value.i == p_item->pi_list[i_index] )
399 [o_file_sub_size_pop selectItemAtIndex: i_index];
405 - (void)openTarget:(int)i_type
409 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
411 [o_tabview selectTabViewItemAtIndex: i_type];
412 [o_file_sub_ckbox setState: NSOffState];
414 i_result = [NSApp runModalForWindow: o_panel];
419 NSMutableDictionary *o_dic;
420 NSMutableArray *o_options = [NSMutableArray array];
422 o_dic = [NSMutableDictionary dictionaryWithObject: [self MRL] forKey: @"ITEM_URL"];
423 if( [o_file_sub_ckbox state] == NSOnState )
425 module_config_t * p_item;
427 [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", o_sub_path]];
428 if( [o_file_sub_override state] == NSOnState )
430 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
431 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
433 [o_options addObject: [NSString stringWithFormat:
434 @"subsdec-encoding=%@",
435 [o_file_sub_encoding_pop titleOfSelectedItem]]];
436 [o_options addObject: [NSString stringWithFormat:
437 @"subsdec-align=%li",
438 [o_file_sub_align_pop indexOfSelectedItem]]];
440 p_item = config_FindConfig( VLC_OBJECT(p_intf),
441 "freetype-rel-fontsize" );
445 [o_options addObject: [NSString stringWithFormat:
446 @"freetype-rel-fontsize=%i",
447 p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
450 if( [o_output_ckbox state] == NSOnState )
452 NSUInteger count = [[o_sout_options mrl] count];
453 for (NSUInteger i = 0 ; i < count ; i++)
455 [o_options addObject: [NSString stringWithString: [[(VLCOutput *)o_sout_options mrl] objectAtIndex: i]]];
458 if( [o_file_slave_ckbox state] && o_file_slave_path )
459 [o_options addObject: [NSString stringWithFormat: @"input-slave=%@", o_file_slave_path]];
460 if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
462 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
464 int selected_index = [o_screen_screen_pop indexOfSelectedItem];
465 NSValue *v = [o_displayInfos objectAtIndex:selected_index];
466 struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
468 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
469 [o_options addObject: [NSString stringWithFormat: @"screen-display-id=%i", item->id]];
470 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
471 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
472 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
473 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
474 if( [o_screen_follow_mouse_ckb intValue] == YES )
475 [o_options addObject: @"screen-follow-mouse"];
477 [o_options addObject: @"no-screen-follow-mouse"];
479 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Video Device")] )
481 [o_options addObject: [NSString stringWithFormat: @"qtcapture-width=%i", [o_capture_width_fld intValue]]];
482 [o_options addObject: [NSString stringWithFormat: @"qtcapture-height=%i", [o_capture_height_fld intValue]]];
486 /* apply the options to our item(s) */
487 [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
489 [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
491 [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
495 - (IBAction)screenChanged:(id)sender
497 int selected_index = [o_screen_screen_pop indexOfSelectedItem];
498 if( selected_index >= [o_displayInfos count] ) return;
500 NSValue *v = [o_displayInfos objectAtIndex:selected_index];
501 struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
503 [o_screen_left_stp setMaxValue: item->rect.size.width];
504 [o_screen_top_stp setMaxValue: item->rect.size.height];
505 [o_screen_width_stp setMaxValue: item->rect.size.width];
506 [o_screen_height_stp setMaxValue: item->rect.size.height];
509 - (IBAction)qtkChanged:(id)sender
511 NSInteger i_selectedDevice = [o_qtk_device_pop indexOfSelectedItem];
512 if( [qtkvideoDevices count] >= 1 )
514 NSValue *sizes = [[[[qtkvideoDevices objectAtIndex:i_selectedDevice] formatDescriptions] objectAtIndex: 0] attributeForKey: QTFormatDescriptionVideoEncodedPixelsSizeAttribute];
516 [o_capture_width_fld setIntValue: [sizes sizeValue].width];
517 [o_capture_height_fld setIntValue: [sizes sizeValue].height];
518 [o_capture_width_stp setIntValue: [o_capture_width_fld intValue]];
519 [o_capture_height_stp setIntValue: [o_capture_height_fld intValue]];
520 qtk_currdevice_uid = [[(QTCaptureDevice *)[qtkvideoDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
521 [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
525 - (IBAction)qtkAudioChanged:(id)sender
527 NSInteger i_selectedDevice = [o_qtkaudio_device_pop indexOfSelectedItem];
528 if( [qtkaudioDevices count] >= 1 )
530 qtkaudio_currdevice_uid = [[(QTCaptureDevice *)[qtkaudioDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
531 [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
535 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
537 NSString *o_label = [o_tvi label];
539 if( [o_label isEqualToString: _NS("File")] )
541 [self openFilePathChanged: nil];
543 else if( [o_label isEqualToString: _NS("Disc")] )
545 [self scanOpticalMedia: nil];
547 else if( [o_label isEqualToString: _NS("Network")] )
549 [self openNetInfoChanged: nil];
551 else if( [o_label isEqualToString: _NS("Capture")] )
553 [self openCaptureModeChanged: nil];
557 - (IBAction)expandMRLfieldAction:(id)sender
559 NSRect o_win_rect, o_view_rect;
560 o_win_rect = [o_panel frame];
561 o_view_rect = [o_mrl_view frame];
563 if( [o_mrl_btn state] == NSOffState )
565 /* we need to collaps, restore the panel size */
566 o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
567 o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
569 /* remove the MRL view */
570 [o_mrl_view removeFromSuperview];
572 /* we need to expand */
573 [o_mrl_view setFrame: NSMakeRect( 0,
574 [o_mrl_btn frame].origin.y,
575 o_view_rect.size.width,
576 o_view_rect.size.height )];
577 [o_mrl_view setNeedsDisplay: NO];
578 [o_mrl_view setAutoresizesSubviews: YES];
580 /* enlarge panel size for MRL view */
581 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
584 [[o_panel animator] setFrame: o_win_rect display:YES];
585 // [o_panel displayIfNeeded];
586 if( [o_mrl_btn state] == NSOnState )
587 [[o_panel contentView] addSubview: o_mrl_view];
590 - (IBAction)inputSlaveAction:(id)sender
592 if( sender == o_file_slave_ckbox )
593 [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
596 NSOpenPanel *o_open_panel;
597 o_open_panel = [NSOpenPanel openPanel];
598 [o_open_panel setCanChooseFiles: YES];
599 [o_open_panel setCanChooseDirectories: NO];
600 if( [o_open_panel runModal] == NSOKButton )
602 if( o_file_slave_path )
603 [o_file_slave_path release];
604 o_file_slave_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
605 [o_file_slave_path retain];
608 if( o_file_slave_path && [o_file_slave_ckbox state] == NSOnState)
610 [o_file_slave_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_slave_path]];
611 [o_file_slave_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_slave_path]];
615 [o_file_slave_filename_lbl setStringValue: @""];
616 [o_file_slave_icon_well setImage: NULL];
620 - (void)openFileGeneric
622 [self openFilePathChanged: nil];
623 [self openTarget: 0];
628 [o_specialMediaFolders removeAllObjects];
629 [o_opticalDevices removeAllObjects];
630 [self scanOpticalMedia: nil];
631 [self openTarget: 1];
636 [self openNetInfoChanged: nil];
637 [self openTarget: 2];
642 [self openCaptureModeChanged: nil];
643 [self openTarget: 3];
646 - (void)openFilePathChanged:(NSNotification *)o_notification
648 if ( o_file_path && [o_file_path length] > 0 )
650 bool b_stream = [o_file_stream state];
653 [[NSFileManager defaultManager] fileExistsAtPath:o_file_path isDirectory:&b_dir];
655 char *psz_uri = make_URI([o_file_path UTF8String], "file");
656 if( !psz_uri ) return;
658 NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
659 NSRange offile = [o_mrl_string rangeOfString:@"file"];
663 [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
665 [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
667 [o_file_name setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_path]];
668 [o_file_name_stub setHidden: YES];
669 [o_file_stream setHidden: NO];
670 [o_file_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_path]];
671 [o_file_icon_well setHidden: NO];
672 [self setMRL: o_mrl_string];
676 [o_file_name setStringValue: @""];
677 [o_file_name_stub setHidden: NO];
678 [o_file_stream setHidden: YES];
679 [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
684 - (IBAction)openFileBrowse:(id)sender
686 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
688 [o_open_panel setAllowsMultipleSelection: NO];
689 [o_open_panel setCanChooseDirectories: YES];
690 [o_open_panel setTitle: _NS("Open File")];
691 [o_open_panel setPrompt: _NS("Open")];
693 [o_open_panel beginSheetForDirectory:nil
696 modalForWindow:[sender window]
698 didEndSelector: @selector(pathChosenInPanel:
704 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void *)contextInfo
706 if (returnCode == NSFileHandlingPanelOKButton)
709 [o_file_path release];
710 o_file_path = [[[sheet URLs] objectAtIndex: 0] path];
711 [o_file_path retain];
712 [self openFilePathChanged: nil];
716 - (IBAction)openFileStreamChanged:(id)sender
718 [self openFilePathChanged: nil];
721 - (void)showOpticalMediaView: theView withIcon:(NSImage *)icon
724 o_view_rect = [theView frame];
725 [theView setFrame: NSMakeRect( 233, 0, o_view_rect.size.width, o_view_rect.size.height)];
726 [theView setAutoresizesSubviews: YES];
727 if (o_currentOpticalMediaView)
729 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaView with: theView];
730 [o_currentOpticalMediaView release];
733 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: theView];
734 o_currentOpticalMediaView = theView;
735 [o_currentOpticalMediaView retain];
737 NSImageView *imageView;
738 imageView = [[NSImageView alloc] init];
739 [imageView setFrame: NSMakeRect( 53, 61, 128, 128 )];
740 [icon setSize: NSMakeSize(128,128)];
741 [imageView setImage: icon];
742 if (o_currentOpticalMediaIconView)
744 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaIconView with: imageView];
745 [o_currentOpticalMediaIconView release];
748 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: imageView];
749 o_currentOpticalMediaIconView = imageView;
750 [o_currentOpticalMediaIconView retain];
751 [o_currentOpticalMediaView setNeedsDisplay: YES];
752 [o_currentOpticalMediaIconView setNeedsDisplay: YES];
753 [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] setNeedsDisplay: YES];
754 [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] displayIfNeeded];
757 - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
761 FSVolumeRefNum actualVolume;
762 err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
764 // get a FSVolumeRefNum from mountPath
765 if ( noErr == err ) {
766 FSCatalogInfo catalogInfo;
767 err = FSGetCatalogInfo ( &ref,
774 if ( noErr == err ) {
775 actualVolume = catalogInfo.volume;
779 GetVolParmsInfoBuffer volumeParms;
780 err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
781 if ( noErr != err ) {
782 msg_Err( p_intf, "error retrieving volume params, bailing out" );
786 NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
787 return [NSString stringWithFormat:@"/dev/r%@", bsdName];
790 - (char *)getVolumeTypeFromMountPath:(NSString *)mountPath
794 FSVolumeRefNum actualVolume;
795 err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
797 // get a FSVolumeRefNum from mountPath
798 if ( noErr == err ) {
799 FSCatalogInfo catalogInfo;
800 err = FSGetCatalogInfo ( &ref,
807 if ( noErr == err ) {
808 actualVolume = catalogInfo.volume;
812 GetVolParmsInfoBuffer volumeParms;
813 err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
815 CFMutableDictionaryRef matchingDict;
816 io_service_t service;
818 matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
819 service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
822 if (IO_OBJECT_NULL != service) {
823 if (IOObjectConformsTo(service, kIOCDMediaClass)) {
824 returnValue = kVLCMediaAudioCD;
826 else if(IOObjectConformsTo(service, kIODVDMediaClass))
827 returnValue = kVLCMediaDVD;
828 else if(IOObjectConformsTo(service, kIOBDMediaClass))
829 returnValue = kVLCMediaBD;
832 if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
833 returnValue = kVLCMediaVideoTSFolder;
834 else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
835 returnValue = kVLCMediaBDMVFolder;
838 // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
839 NSFileManager * fm = [[NSFileManager alloc] init];
840 NSArray * topLevelItems;
841 topLevelItems = [fm subpathsOfDirectoryAtPath: mountPath error: NULL];
844 NSUInteger itemCount = [topLevelItems count];
845 for (int i = 0; i < itemCount; i++) {
846 if([[topLevelItems objectAtIndex:i] rangeOfString:@"SVCD"].location != NSNotFound) {
847 returnValue = kVLCMediaSVCD;
850 if([[topLevelItems objectAtIndex:i] rangeOfString:@"VCD"].location != NSNotFound) {
851 returnValue = kVLCMediaVCD;
856 returnValue = kVLCMediaVideoTSFolder;
860 IOObjectRelease(service);
865 - (void)showOpticalAtPath: (NSString *)o_opticalDevicePath
867 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
869 char *diskType = [self getVolumeTypeFromMountPath:o_opticalDevicePath];
871 if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder)
873 [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_opticalDevicePath]];
874 [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
875 NSString *pathToOpen;
876 if (diskType == kVLCMediaVideoTSFolder)
877 pathToOpen = o_opticalDevicePath;
879 pathToOpen = [self getBSDNodeFromMountPath: o_opticalDevicePath];
881 [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
882 [self showOpticalMediaView: o_disc_dvd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
884 [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
885 [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
888 else if (diskType == kVLCMediaAudioCD)
890 [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
891 [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_opticalDevicePath error:NULL] count] - 1]]; // minus .TOC.plist
892 [self showOpticalMediaView: o_disc_audiocd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
893 [self setMRL: [NSString stringWithFormat: @"cdda://%@", [self getBSDNodeFromMountPath: o_opticalDevicePath]]];
895 else if (diskType == kVLCMediaVCD)
897 [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
898 [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
899 [self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
901 else if (diskType == kVLCMediaSVCD)
903 [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
904 [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
905 [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
907 else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
909 [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
910 [self showOpticalMediaView: o_disc_bd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
911 [self setMRL: [NSString stringWithFormat: @"bluray://%@", o_opticalDevicePath]];
915 msg_Warn( VLCIntf, "unknown disk type, no idea what to display" );
916 [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
922 - (void)showSelectedOpticalDisc
924 NSString *o_opticalDevicePath = [o_opticalDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];
925 [NSThread detachNewThreadSelector:@selector(showOpticalAtPath:) toTarget:self withObject:o_opticalDevicePath];
928 - (void)scanOpticalMedia:(NSNotification *)o_notification
930 [o_opticalDevices removeAllObjects];
931 [o_disc_selector_pop removeAllItems];
932 [o_opticalDevices addObjectsFromArray: [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
933 [o_opticalDevices addObjectsFromArray: o_specialMediaFolders];
934 if ([o_opticalDevices count] > 0) {
935 NSUInteger deviceCount = [o_opticalDevices count];
936 for (NSUInteger i = 0; i < deviceCount ; i++)
937 [o_disc_selector_pop addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: i]]];
939 if ([o_disc_selector_pop numberOfItems] <= 1)
940 [o_disc_selector_pop setHidden: YES];
942 [o_disc_selector_pop setHidden: NO];
944 [self showSelectedOpticalDisc];
948 msg_Dbg( VLCIntf, "no optical media found" );
949 [o_disc_selector_pop setHidden: YES];
950 [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed: @"NSApplicationIcon"]];
954 - (IBAction)discSelectorChanged:(id)sender
956 [self showSelectedOpticalDisc];
959 - (IBAction)openSpecialMediaFolder:(id)sender
961 /* this is currently for VIDEO_TS and BDMV folders */
962 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
964 [o_open_panel setAllowsMultipleSelection: NO];
965 [o_open_panel setCanChooseFiles: NO];
966 [o_open_panel setCanChooseDirectories: YES];
967 [o_open_panel setTitle: [sender title]];
968 [o_open_panel setPrompt: _NS("Open")];
970 if ([o_open_panel runModal] == NSOKButton)
972 NSString *o_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
973 if ([o_path length] > 0 )
975 [o_specialMediaFolders addObject: o_path];
976 [self scanOpticalMedia: nil];
981 - (IBAction)dvdreadOptionChanged:(id)sender
983 if (sender == o_disc_dvdwomenus_enablemenus_btn) {
985 [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]]]]];
986 [self showOpticalMediaView: o_disc_dvd_view withIcon: [o_currentOpticalMediaIconView image]];
989 if (sender == o_disc_dvd_disablemenus_btn) {
991 [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [o_currentOpticalMediaIconView image]];
994 if (sender == o_disc_dvdwomenus_title)
995 [o_disc_dvdwomenus_title_stp setIntValue: [o_disc_dvdwomenus_title intValue]];
996 if (sender == o_disc_dvdwomenus_title_stp)
997 [o_disc_dvdwomenus_title setIntValue: [o_disc_dvdwomenus_title_stp intValue]];
998 if (sender == o_disc_dvdwomenus_chapter)
999 [o_disc_dvdwomenus_chapter_stp setIntValue: [o_disc_dvdwomenus_chapter intValue]];
1000 if (sender == o_disc_dvdwomenus_chapter_stp)
1001 [o_disc_dvdwomenus_chapter setIntValue: [o_disc_dvdwomenus_chapter_stp intValue]];
1003 [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]]], [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1006 - (IBAction)vcdOptionChanged:(id)sender
1008 if (sender == o_disc_vcd_title)
1009 [o_disc_vcd_title_stp setIntValue: [o_disc_vcd_title intValue]];
1010 if (sender == o_disc_vcd_title_stp)
1011 [o_disc_vcd_title setIntValue: [o_disc_vcd_title_stp intValue]];
1012 if (sender == o_disc_vcd_chapter)
1013 [o_disc_vcd_chapter_stp setIntValue: [o_disc_vcd_chapter intValue]];
1014 if (sender == o_disc_vcd_chapter_stp)
1015 [o_disc_vcd_chapter setIntValue: [o_disc_vcd_chapter_stp intValue]];
1017 [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]]];
1020 - (void)textFieldWasClicked:(NSNotification *)o_notification
1022 if( [o_notification object] == o_net_udp_port )
1023 [o_net_mode selectCellAtRow: 0 column: 0];
1024 else if( [o_notification object] == o_net_udpm_addr ||
1025 [o_notification object] == o_net_udpm_port )
1026 [o_net_mode selectCellAtRow: 1 column: 0];
1028 [o_net_mode selectCellAtRow: 2 column: 0];
1030 [self openNetInfoChanged: nil];
1033 - (IBAction)openNetModeChanged:(id)sender
1035 if( sender == o_net_mode )
1037 if( [[sender selectedCell] tag] == 0 )
1038 [o_panel makeFirstResponder: o_net_udp_port];
1039 else if ( [[sender selectedCell] tag] == 1 )
1040 [o_panel makeFirstResponder: o_net_udpm_addr];
1042 msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
1045 [self openNetInfoChanged: nil];
1048 - (IBAction)openNetStepperChanged:(id)sender
1050 int i_tag = [sender tag];
1054 [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
1055 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1056 object: o_net_udp_port];
1057 [o_panel makeFirstResponder: o_net_udp_port];
1059 else if( i_tag == 1 )
1061 [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
1062 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1063 object: o_net_udpm_port];
1064 [o_panel makeFirstResponder: o_net_udpm_port];
1067 [self openNetInfoChanged: nil];
1070 - (void)openNetInfoChanged:(NSNotification *)o_notification
1072 NSString *o_mrl_string = [NSString string];
1074 if( [o_net_udp_panel isVisible] )
1077 o_mode = [[o_net_mode selectedCell] title];
1079 if( [o_mode isEqualToString: _NS("Unicast")] )
1081 int i_port = [o_net_udp_port intValue];
1083 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1084 o_mrl_string = @"udp://";
1086 o_mrl_string = @"rtp://";
1088 if( i_port != config_GetInt( p_intf, "server-port" ) )
1091 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1094 else if( [o_mode isEqualToString: _NS("Multicast")] )
1096 NSString *o_addr = [o_net_udpm_addr stringValue];
1097 int i_port = [o_net_udpm_port intValue];
1099 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1100 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1102 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1104 if( i_port != config_GetInt( p_intf, "server-port" ) )
1107 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1113 o_mrl_string = [o_net_http_url stringValue];
1115 [self setMRL: o_mrl_string];
1118 - (IBAction)openNetUDPButtonAction:(id)sender
1120 if( sender == o_net_openUDP_btn )
1122 [NSApp beginSheet: o_net_udp_panel
1123 modalForWindow: o_panel
1125 didEndSelector: NULL
1127 [self openNetInfoChanged: nil];
1129 else if( sender == o_net_udp_cancel_btn )
1131 [o_net_udp_panel orderOut: sender];
1132 [NSApp endSheet: o_net_udp_panel];
1134 else if( sender == o_net_udp_ok_btn )
1136 NSString *o_mrl_string = [NSString string];
1137 if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
1139 int i_port = [o_net_udp_port intValue];
1141 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1142 o_mrl_string = @"udp://";
1144 o_mrl_string = @"rtp://";
1146 if( i_port != config_GetInt( p_intf, "server-port" ) )
1149 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1152 else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
1154 NSString *o_addr = [o_net_udpm_addr stringValue];
1155 int i_port = [o_net_udpm_port intValue];
1157 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1158 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1160 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1162 if( i_port != config_GetInt( p_intf, "server-port" ) )
1165 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1168 [self setMRL: o_mrl_string];
1169 [o_net_http_url setStringValue: o_mrl_string];
1170 [o_net_udp_panel orderOut: sender];
1171 [NSApp endSheet: o_net_udp_panel];
1177 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1178 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
1180 [o_open_panel setAllowsMultipleSelection: YES];
1181 [o_open_panel setCanChooseDirectories: YES];
1182 [o_open_panel setTitle: _NS("Open File")];
1183 [o_open_panel setPrompt: _NS("Open")];
1185 if( [o_open_panel runModal] == NSOKButton )
1187 NSArray * o_urls = [o_open_panel URLs];
1188 NSUInteger count = [o_urls count];
1189 NSMutableArray *o_values = [NSMutableArray arrayWithCapacity:count];
1190 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1191 for( NSUInteger i = 0; i < count; i++ )
1193 [o_values addObject: [[o_urls objectAtIndex: i] path]];
1195 [o_values sortUsingSelector:@selector(caseInsensitiveCompare:)];
1197 for( NSUInteger i = 0; i < count; i++ )
1199 NSDictionary *o_dic;
1200 char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], "file");
1204 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1208 [o_array addObject: o_dic];
1211 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
1213 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
1217 - (void)showCaptureView: theView
1220 o_view_rect = [theView frame];
1221 [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
1222 [theView setAutoresizesSubviews: YES];
1223 if (o_currentCaptureView)
1225 [[[[o_tabview tabViewItemAtIndex: 3] view] animator] replaceSubview: o_currentCaptureView with: theView];
1226 [o_currentCaptureView release];
1230 [[[[o_tabview tabViewItemAtIndex: 3] view] animator] addSubview: theView];
1232 o_currentCaptureView = theView;
1233 [o_currentCaptureView retain];
1236 - (IBAction)openCaptureModeChanged:(id)sender
1238 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1240 if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1242 if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1244 [self showCaptureView: o_eyetv_running_view];
1245 [self setupChannelInfo];
1249 setEyeTVUnconnected;
1253 [self showCaptureView: o_eyetv_notLaunched_view];
1256 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1258 [self showCaptureView: o_screen_view];
1259 [self setMRL: @"screen://"];
1260 [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
1261 [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
1262 [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
1263 [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
1264 [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
1265 [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
1267 int screen_index = config_GetInt( p_intf, "screen-index" );
1268 int display_id = config_GetInt( p_intf, "screen-display-id" );
1269 unsigned int i, displayCount = 0;
1270 CGLError returnedError;
1271 struct display_info_t *item;
1274 returnedError = CGGetOnlineDisplayList( 0, NULL, &displayCount );
1275 if( !returnedError )
1277 CGDirectDisplayID *ids;
1278 ids = ( CGDirectDisplayID * )malloc( displayCount * sizeof( CGDirectDisplayID ) );
1279 returnedError = CGGetOnlineDisplayList( displayCount, ids, &displayCount );
1280 if( !returnedError )
1282 for( i = 0; i < [o_displayInfos count]; i ++ )
1284 v = [o_displayInfos objectAtIndex:i];
1285 free( [v pointerValue] );
1287 [o_displayInfos removeAllObjects];
1288 [o_screen_screen_pop removeAllItems];
1289 for( i = 0; i < displayCount; i ++ )
1291 item = ( struct display_info_t * )malloc( sizeof( struct display_info_t ) );
1293 item->rect = CGDisplayBounds( item->id );
1294 [o_screen_screen_pop addItemWithTitle: [NSString stringWithFormat:@"Screen %d (%dx%d)", i + 1, (int)item->rect.size.width, (int)item->rect.size.height]];
1295 v = [NSValue valueWithPointer:item];
1296 [o_displayInfos addObject:v];
1297 if( i == 0 || display_id == item->id || screen_index - 1 == i )
1299 [o_screen_screen_pop selectItemAtIndex: i];
1300 [o_screen_left_stp setMaxValue: item->rect.size.width];
1301 [o_screen_top_stp setMaxValue: item->rect.size.height];
1302 [o_screen_width_stp setMaxValue: item->rect.size.width];
1303 [o_screen_height_stp setMaxValue: item->rect.size.height];
1310 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Video Device")] )
1312 [self showCaptureView: o_qtk_view];
1313 if ([o_capture_width_fld intValue] <= 0)
1314 [self qtkChanged:nil];
1316 if(!qtk_currdevice_uid)
1319 [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
1321 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Audio Device")] )
1323 [self showCaptureView: o_qtkaudio_view];
1324 [self qtkAudioChanged:nil];
1326 if(!qtkaudio_currdevice_uid)
1329 [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
1333 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1335 [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1336 if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1337 [o_screen_fps_fld setFloatValue: 1.0];
1338 [self setMRL: @"screen://"];
1341 - (IBAction)eyetvSwitchChannel:(id)sender
1343 if( sender == o_eyetv_nextProgram_btn )
1345 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1346 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1347 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1349 else if( sender == o_eyetv_previousProgram_btn )
1351 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1352 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1353 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1355 else if( sender == o_eyetv_channels_pop )
1357 int chanNum = [[sender selectedItem] tag];
1358 [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1359 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1362 msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1365 - (IBAction)eyetvLaunch:(id)sender
1367 [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1370 - (IBAction)eyetvGetPlugin:(id)sender
1372 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1375 - (void)eyetvChanged:(NSNotification *)o_notification
1377 if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1379 msg_Dbg( VLCIntf, "eyetv device was added" );
1380 [self showCaptureView: o_eyetv_running_view];
1381 [self setupChannelInfo];
1383 else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1385 /* leave the channel selection like that,
1386 * switch to our "no device" tab */
1387 msg_Dbg( VLCIntf, "eyetv device was removed" );
1388 setEyeTVUnconnected;
1390 else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1392 /* switch to the "launch eyetv" tab */
1393 msg_Dbg( VLCIntf, "eyetv was terminated" );
1394 [self showCaptureView: o_eyetv_notLaunched_view];
1396 else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1398 /* we got no device yet */
1399 msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1400 setEyeTVUnconnected;
1404 /* little helper method, since this code needs to be run by multiple objects */
1405 - (void)setupChannelInfo
1407 /* set up channel selection */
1408 [o_eyetv_channels_pop removeAllItems];
1409 [o_eyetv_chn_bgbar setHidden: NO];
1410 [o_eyetv_chn_bgbar animate: self];
1411 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1412 [o_eyetv_chn_status_txt setHidden: NO];
1415 NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1417 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1419 keyEquivalent: @""] setTag:x++];
1420 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1422 keyEquivalent: @""] setTag:x++];
1426 [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1427 while( channel = [channels nextObject] )
1429 /* we have to add items this way, because we accept duplicates
1430 * additionally, we save a bit of time */
1431 [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1433 keyEquivalent: @""] setTag:++x];
1435 /* make Tuner the default */
1436 [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1440 [o_eyetv_chn_bgbar setHidden: YES];
1441 [o_eyetv_chn_status_txt setHidden: YES];
1444 - (IBAction)subsChanged:(id)sender
1446 if ([o_file_sub_ckbox state] == NSOnState)
1448 [o_file_sub_btn_settings setEnabled:YES];
1450 [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1451 [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1456 [o_file_sub_btn_settings setEnabled:NO];
1457 [o_file_subtitles_filename_lbl setStringValue: @""];
1458 [o_file_subtitles_icon_well setImage: NULL];
1462 - (IBAction)subSettings:(id)sender
1464 [NSApp beginSheet: o_file_sub_sheet
1465 modalForWindow: [sender window]
1467 didEndSelector: NULL
1471 - (IBAction)subCloseSheet:(id)sender
1473 [self subsChanged: nil];
1474 [o_file_sub_sheet orderOut:sender];
1475 [NSApp endSheet: o_file_sub_sheet];
1478 - (IBAction)subFileBrowse:(id)sender
1480 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1482 [o_open_panel setAllowsMultipleSelection: NO];
1483 [o_open_panel setTitle: _NS("Open File")];
1484 [o_open_panel setPrompt: _NS("Open")];
1486 if( [o_open_panel runModal] == NSOKButton )
1488 o_sub_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1489 [o_sub_path retain];
1490 [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1491 [o_file_sub_path_fld setStringValue: [o_file_subtitles_filename_lbl stringValue]];
1492 [o_file_sub_path_lbl setHidden: YES];
1493 [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1494 [o_file_sub_icon_view setImage: [o_file_subtitles_icon_well image]];
1498 [o_file_sub_path_lbl setHidden: NO];
1499 [o_file_sub_path_fld setStringValue:@""];
1500 [o_file_subtitles_filename_lbl setStringValue:@""];
1501 [o_file_subtitles_icon_well setImage: nil];
1502 [o_file_sub_icon_view setImage: nil];
1506 - (IBAction)subOverride:(id)sender
1508 BOOL b_state = [o_file_sub_override state];
1509 [o_file_sub_delay setEnabled: b_state];
1510 [o_file_sub_delay_stp setEnabled: b_state];
1511 [o_file_sub_fps setEnabled: b_state];
1512 [o_file_sub_fps_stp setEnabled: b_state];
1515 - (IBAction)subDelayStepperChanged:(id)sender
1517 [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1520 - (IBAction)subFpsStepperChanged:(id)sender;
1522 [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1525 - (IBAction)panelCancel:(id)sender
1527 [NSApp stopModalWithCode: 0];
1530 - (IBAction)panelOk:(id)sender
1532 if( [[self MRL] length] )
1533 [NSApp stopModalWithCode: 1];
1538 - (NSArray *)qtkvideoDevices
1540 if ( !qtkvideoDevices )
1541 [self qtkrefreshVideoDevices];
1542 return qtkvideoDevices;
1545 - (void)qtkrefreshVideoDevices
1547 [qtkvideoDevices release];
1548 qtkvideoDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1551 - (NSArray *)qtkaudioDevices
1553 if ( !qtkaudioDevices )
1554 [self qtkrefreshAudioDevices];
1555 return qtkaudioDevices;
1558 - (void)qtkrefreshAudioDevices
1560 [qtkaudioDevices release];
1561 qtkaudioDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeSound] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1566 @implementation VLCOpenTextField
1568 - (void)mouseDown:(NSEvent *)theEvent
1570 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1572 [super mouseDown: theEvent];