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];
147 [o_disc_selector_pop removeAllItems];
148 [o_disc_selector_pop setHidden: NO];
149 NSString *o_videots = _NS("Open VIDEO_TS folder");
150 NSString *o_bdmv = _NS("Open BDMV folder");
151 [o_disc_nodisc_lbl setStringValue: _NS("Insert Disc")];
152 [o_disc_nodisc_videots_btn setTitle: o_videots];
153 [o_disc_nodisc_bdmv_btn setTitle: o_bdmv];
154 [o_disc_audiocd_lbl setStringValue: _NS("Audio CD")];
155 [o_disc_audiocd_trackcount_lbl setStringValue: @""];
156 [o_disc_audiocd_videots_btn setTitle: o_videots];
157 [o_disc_audiocd_bdmv_btn setTitle: o_bdmv];
158 [o_disc_dvd_lbl setStringValue: @""];
159 [o_disc_dvd_disablemenus_btn setTitle: _NS("Disable DVD menus")];
160 [o_disc_dvd_videots_btn setTitle: o_videots];
161 [o_disc_dvd_bdmv_btn setTitle: o_bdmv];
162 [o_disc_dvdwomenus_lbl setStringValue: @""];
163 [o_disc_dvdwomenus_enablemenus_btn setTitle: _NS("Enable DVD menus")];
164 [o_disc_dvdwomenus_videots_btn setTitle: o_videots];
165 [o_disc_dvdwomenus_bdmv_btn setTitle: o_bdmv];
166 [o_disc_dvdwomenus_title_lbl setStringValue: _NS("Title")];
167 [o_disc_dvdwomenus_chapter_lbl setStringValue: _NS("Chapter")];
168 [o_disc_vcd_title_lbl setStringValue: _NS("Title")];
169 [o_disc_vcd_chapter_lbl setStringValue: _NS("Chapter")];
170 [o_disc_vcd_videots_btn setTitle: o_videots];
171 [o_disc_vcd_bdmv_btn setTitle: o_bdmv];
172 [o_disc_bd_videots_btn setTitle: o_videots];
173 [o_disc_bd_bdmv_btn setTitle: o_bdmv];
175 [o_net_udp_port_lbl setStringValue: _NS("Port")];
176 [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
177 [o_net_udpm_port_lbl setStringValue: _NS("Port")];
178 [o_net_http_url_lbl setStringValue: _NS("URL")];
179 [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.")];
180 [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.")];
181 [o_net_udp_cancel_btn setTitle: _NS("Cancel")];
182 [o_net_udp_ok_btn setTitle: _NS("Open")];
183 [o_net_openUDP_btn setTitle: _NS("Open RTP/UDP Stream")];
184 [o_net_udp_mode_lbl setStringValue: _NS("Mode")];
185 [o_net_udp_protocol_lbl setStringValue: _NS("Protocol")];
186 [o_net_udp_address_lbl setStringValue: _NS("Address")];
188 [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
189 [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
191 [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
192 [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
194 [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
196 [o_capture_mode_pop removeAllItems];
197 [o_capture_mode_pop addItemWithTitle: _NS("Video Device")];
198 [o_capture_mode_pop addItemWithTitle: _NS("Audio Device")];
199 [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
200 [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
201 [o_screen_long_lbl setStringValue: _NS("This input allows you to save, stream or display your current screen contents.")];
202 [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
203 [o_screen_screen_lbl setStringValue: _NS("Screen:")];
204 [o_screen_left_lbl setStringValue: _NS("Subscreen left:")];
205 [o_screen_top_lbl setStringValue: _NS("Subscreen top:")];
206 [o_screen_width_lbl setStringValue: _NS("Subscreen width:")];
207 [o_screen_height_lbl setStringValue: _NS("Subscreen height:")];
208 [o_screen_follow_mouse_ckb setTitle: _NS("Follow the mouse")];
209 [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
210 [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
211 [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
212 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
213 [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
214 [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
215 [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
216 [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
217 [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.")];
218 [o_capture_width_lbl setStringValue: _NS("Image width:")];
219 [o_capture_height_lbl setStringValue: _NS("Image height:")];
221 [self qtkvideoDevices];
222 [o_qtk_device_pop removeAllItems];
223 msg_Dbg( VLCIntf, "Found %lu video capture devices", [qtkvideoDevices count] );
225 if([qtkvideoDevices count] >= 1)
227 if (!qtk_currdevice_uid) {
228 qtk_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo] uniqueID]
229 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
231 NSUInteger deviceCount = [qtkvideoDevices count];
232 for(int ivideo = 0; ivideo < deviceCount; ivideo++){
233 QTCaptureDevice *qtk_device;
234 qtk_device = [qtkvideoDevices objectAtIndex:ivideo];
235 [o_qtk_device_pop addItemWithTitle: [qtk_device localizedDisplayName]];
236 if([[[qtk_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid]){
237 [o_qtk_device_pop selectItemAtIndex:ivideo];
243 [o_qtk_device_pop addItemWithTitle: _NS("None")];
244 [qtk_currdevice_uid release];
247 [self qtkaudioDevices];
248 [o_qtkaudio_device_pop removeAllItems];
249 msg_Dbg( VLCIntf, "Found %lu audio capture devices", [qtkaudioDevices count] );
251 if([qtkaudioDevices count] >= 1)
253 if (!qtkaudio_currdevice_uid) {
254 qtkaudio_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound] uniqueID]
255 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
257 NSUInteger deviceCount = [qtkaudioDevices count];
258 for(int iaudio = 0; iaudio < deviceCount; iaudio++){
259 QTCaptureDevice *qtkaudio_device;
260 qtkaudio_device = [qtkaudioDevices objectAtIndex:iaudio];
261 [o_qtkaudio_device_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
262 if([[[qtkaudio_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtkaudio_currdevice_uid]){
263 [o_qtkaudio_device_pop selectItemAtIndex:iaudio];
269 [o_qtkaudio_device_pop addItemWithTitle: _NS("None")];
270 [qtkaudio_currdevice_uid release];
275 [[NSNotificationCenter defaultCenter] addObserver: self
276 selector: @selector(openNetInfoChanged:)
277 name: NSControlTextDidChangeNotification
278 object: o_net_udp_port];
279 [[NSNotificationCenter defaultCenter] addObserver: self
280 selector: @selector(openNetInfoChanged:)
281 name: NSControlTextDidChangeNotification
282 object: o_net_udpm_addr];
283 [[NSNotificationCenter defaultCenter] addObserver: self
284 selector: @selector(openNetInfoChanged:)
285 name: NSControlTextDidChangeNotification
286 object: o_net_udpm_port];
287 [[NSNotificationCenter defaultCenter] addObserver: self
288 selector: @selector(openNetInfoChanged:)
289 name: NSControlTextDidChangeNotification
290 object: o_net_http_url];
292 [[NSDistributedNotificationCenter defaultCenter] addObserver: self
293 selector: @selector(eyetvChanged:)
295 object: @"VLCEyeTVSupport"
296 suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
298 [[NSNotificationCenter defaultCenter] addObserver: self
299 selector: @selector(screenFPSfieldChanged:)
300 name: NSControlTextDidChangeNotification
301 object: o_screen_fps_fld];
303 /* register clicks on text fields */
304 [[NSNotificationCenter defaultCenter] addObserver: self
305 selector: @selector(textFieldWasClicked:)
306 name: @"VLCOpenTextFieldWasClicked"
309 /* we want to be notified about removed or added media */
310 o_specialMediaFolders = [[NSMutableArray alloc] init];
311 o_opticalDevices = [[NSMutableArray alloc] init];
312 o_displayInfos = [[NSMutableArray alloc] init];
313 NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
315 [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidMountNotification object:nil];
316 [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidUnmountNotification object:nil];
317 [self performSelector:@selector(scanOpticalMedia:) withObject:nil afterDelay:2.0];
318 [self performSelector:@selector(qtkChanged:) withObject:nil afterDelay:2.5];
319 [self performSelector:@selector(qtkAudioChanged:) withObject:nil afterDelay:3.0];
324 - (void)setMRL:(NSString *)newMRL
329 [o_mrl_fld setStringValue: newMRL];
330 if ([o_mrl length] > 0)
331 [o_btn_ok setEnabled: YES];
333 [o_btn_ok setEnabled: NO];
344 module_config_t * p_item;
346 [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
347 [o_file_sub_path_lbl setStringValue: _NS("Choose a file")];
348 [o_file_sub_path_lbl setHidden: NO];
349 [o_file_sub_path_fld setStringValue: @""];
350 [o_file_sub_btn_settings setTitle: _NS("Choose...")];
351 [o_file_sub_btn_browse setTitle: _NS("Browse...")];
352 [o_file_sub_override setTitle: _NS("Override parameters")];
353 [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
354 [o_file_sub_delay_stp setEnabled: NO];
355 [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
356 [o_file_sub_fps_stp setEnabled: NO];
357 [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
358 [o_file_sub_encoding_pop removeAllItems];
359 [o_file_sub_size_lbl setStringValue: _NS("Font size")];
360 [o_file_sub_size_pop removeAllItems];
361 [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
362 [o_file_sub_align_pop removeAllItems];
363 [o_file_sub_ok_btn setStringValue: _NS("OK")];
364 [o_file_sub_font_box setTitle: _NS("Font Properties")];
365 [o_file_sub_file_box setTitle: _NS("Subtitle File")];
367 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
371 for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
374 [o_file_sub_encoding_pop addItemWithTitle:
375 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
377 [o_file_sub_encoding_pop selectItemWithTitle:
378 [NSString stringWithUTF8String: p_item->value.psz]];
381 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
385 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
387 [o_file_sub_align_pop addItemWithTitle:
388 _NS(p_item->ppsz_list_text[i_index])];
390 [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
393 p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
397 for ( i_index = 0; i_index < p_item->i_list; i_index++ )
399 [o_file_sub_size_pop addItemWithTitle: _NS(p_item->ppsz_list_text[i_index])];
400 if ( p_item->value.i == p_item->pi_list[i_index] )
402 [o_file_sub_size_pop selectItemAtIndex: i_index];
408 - (void)openTarget:(int)i_type
412 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
414 [o_tabview selectTabViewItemAtIndex: i_type];
415 [o_file_sub_ckbox setState: NSOffState];
417 i_result = [NSApp runModalForWindow: o_panel];
422 NSMutableDictionary *o_dic;
423 NSMutableArray *o_options = [NSMutableArray array];
425 o_dic = [NSMutableDictionary dictionaryWithObject: [self MRL] forKey: @"ITEM_URL"];
426 if( [o_file_sub_ckbox state] == NSOnState )
428 module_config_t * p_item;
430 [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", o_sub_path]];
431 if( [o_file_sub_override state] == NSOnState )
433 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
434 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
436 [o_options addObject: [NSString stringWithFormat:
437 @"subsdec-encoding=%@",
438 [o_file_sub_encoding_pop titleOfSelectedItem]]];
439 [o_options addObject: [NSString stringWithFormat:
440 @"subsdec-align=%li",
441 [o_file_sub_align_pop indexOfSelectedItem]]];
443 p_item = config_FindConfig( VLC_OBJECT(p_intf),
444 "freetype-rel-fontsize" );
448 [o_options addObject: [NSString stringWithFormat:
449 @"freetype-rel-fontsize=%i",
450 p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
453 if( [o_output_ckbox state] == NSOnState )
455 NSUInteger count = [[o_sout_options mrl] count];
456 for (NSUInteger i = 0 ; i < count ; i++)
458 [o_options addObject: [NSString stringWithString: [[(VLCOutput *)o_sout_options mrl] objectAtIndex: i]]];
461 if( [o_file_slave_ckbox state] && o_file_slave_path )
462 [o_options addObject: [NSString stringWithFormat: @"input-slave=%@", o_file_slave_path]];
463 if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
465 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
467 int selected_index = [o_screen_screen_pop indexOfSelectedItem];
468 NSValue *v = [o_displayInfos objectAtIndex:selected_index];
469 struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
471 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
472 [o_options addObject: [NSString stringWithFormat: @"screen-display-id=%i", item->id]];
473 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
474 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
475 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
476 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
477 if( [o_screen_follow_mouse_ckb intValue] == YES )
478 [o_options addObject: @"screen-follow-mouse"];
480 [o_options addObject: @"no-screen-follow-mouse"];
482 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Video Device")] )
484 [o_options addObject: [NSString stringWithFormat: @"qtcapture-width=%i", [o_capture_width_fld intValue]]];
485 [o_options addObject: [NSString stringWithFormat: @"qtcapture-height=%i", [o_capture_height_fld intValue]]];
489 /* apply the options to our item(s) */
490 [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
492 [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
494 [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
498 - (IBAction)screenChanged:(id)sender
500 int selected_index = [o_screen_screen_pop indexOfSelectedItem];
501 if( selected_index >= [o_displayInfos count] ) return;
503 NSValue *v = [o_displayInfos objectAtIndex:selected_index];
504 struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
506 [o_screen_left_stp setMaxValue: item->rect.size.width];
507 [o_screen_top_stp setMaxValue: item->rect.size.height];
508 [o_screen_width_stp setMaxValue: item->rect.size.width];
509 [o_screen_height_stp setMaxValue: item->rect.size.height];
512 - (IBAction)qtkChanged:(id)sender
514 NSInteger i_selectedDevice = [o_qtk_device_pop indexOfSelectedItem];
515 if( [qtkvideoDevices count] >= 1 )
517 NSValue *sizes = [[[[qtkvideoDevices objectAtIndex:i_selectedDevice] formatDescriptions] objectAtIndex: 0] attributeForKey: QTFormatDescriptionVideoEncodedPixelsSizeAttribute];
519 [o_capture_width_fld setIntValue: [sizes sizeValue].width];
520 [o_capture_height_fld setIntValue: [sizes sizeValue].height];
521 [o_capture_width_stp setIntValue: [o_capture_width_fld intValue]];
522 [o_capture_height_stp setIntValue: [o_capture_height_fld intValue]];
523 qtk_currdevice_uid = [[(QTCaptureDevice *)[qtkvideoDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
524 [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
528 - (IBAction)qtkAudioChanged:(id)sender
530 NSInteger i_selectedDevice = [o_qtkaudio_device_pop indexOfSelectedItem];
531 if( [qtkaudioDevices count] >= 1 )
533 qtkaudio_currdevice_uid = [[(QTCaptureDevice *)[qtkaudioDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
534 [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
539 #pragma mark Main Actions
541 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
543 NSString *o_label = [o_tvi label];
545 if( [o_label isEqualToString: _NS("File")] )
547 [self openFilePathChanged: nil];
549 else if( [o_label isEqualToString: _NS("Disc")] )
551 [self scanOpticalMedia: nil];
553 else if( [o_label isEqualToString: _NS("Network")] )
555 [self openNetInfoChanged: nil];
557 else if( [o_label isEqualToString: _NS("Capture")] )
559 [self openCaptureModeChanged: nil];
563 - (IBAction)expandMRLfieldAction:(id)sender
565 NSRect o_win_rect, o_view_rect;
566 o_win_rect = [o_panel frame];
567 o_view_rect = [o_mrl_view frame];
569 if( [o_mrl_btn state] == NSOffState )
571 /* we need to collaps, restore the panel size */
572 o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
573 o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
575 /* remove the MRL view */
576 [o_mrl_view removeFromSuperview];
578 /* we need to expand */
579 [o_mrl_view setFrame: NSMakeRect( 0,
580 [o_mrl_btn frame].origin.y,
581 o_view_rect.size.width,
582 o_view_rect.size.height )];
583 [o_mrl_view setNeedsDisplay: NO];
584 [o_mrl_view setAutoresizesSubviews: YES];
586 /* enlarge panel size for MRL view */
587 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
590 [[o_panel animator] setFrame: o_win_rect display:YES];
591 // [o_panel displayIfNeeded];
592 if( [o_mrl_btn state] == NSOnState )
593 [[o_panel contentView] addSubview: o_mrl_view];
596 - (void)openFileGeneric
598 [self openFilePathChanged: nil];
599 [self openTarget: 0];
604 [o_specialMediaFolders removeAllObjects];
605 [o_opticalDevices removeAllObjects];
606 [self scanOpticalMedia: nil];
607 [self openTarget: 1];
612 [self openNetInfoChanged: nil];
613 [self openTarget: 2];
618 [self openCaptureModeChanged: nil];
619 [self openTarget: 3];
624 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
625 b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
627 [o_open_panel setAllowsMultipleSelection: YES];
628 [o_open_panel setCanChooseDirectories: YES];
629 [o_open_panel setTitle: _NS("Open File")];
630 [o_open_panel setPrompt: _NS("Open")];
632 if( [o_open_panel runModal] == NSOKButton )
634 NSArray * o_urls = [o_open_panel URLs];
635 NSUInteger count = [o_urls count];
636 NSMutableArray *o_values = [NSMutableArray arrayWithCapacity:count];
637 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
638 for( NSUInteger i = 0; i < count; i++ )
640 [o_values addObject: [[o_urls objectAtIndex: i] path]];
642 [o_values sortUsingSelector:@selector(caseInsensitiveCompare:)];
644 for( NSUInteger i = 0; i < count; i++ )
647 char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], "file");
651 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
655 [o_array addObject: o_dic];
658 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
660 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
665 #pragma mark File Panel
667 - (void)openFilePathChanged:(NSNotification *)o_notification
669 if ( o_file_path && [o_file_path length] > 0 )
671 bool b_stream = [o_file_stream state];
674 [[NSFileManager defaultManager] fileExistsAtPath:o_file_path isDirectory:&b_dir];
676 char *psz_uri = make_URI([o_file_path UTF8String], "file");
677 if( !psz_uri ) return;
679 NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
680 NSRange offile = [o_mrl_string rangeOfString:@"file"];
684 [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
686 [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
688 [o_file_name setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_path]];
689 [o_file_name_stub setHidden: YES];
690 [o_file_stream setHidden: NO];
691 [o_file_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_path]];
692 [o_file_icon_well setHidden: NO];
693 [self setMRL: o_mrl_string];
697 [o_file_name setStringValue: @""];
698 [o_file_name_stub setHidden: NO];
699 [o_file_stream setHidden: YES];
700 [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
705 - (IBAction)openFileBrowse:(id)sender
707 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
709 [o_open_panel setAllowsMultipleSelection: NO];
710 [o_open_panel setCanChooseDirectories: YES];
711 [o_open_panel setTitle: _NS("Open File")];
712 [o_open_panel setPrompt: _NS("Open")];
714 [o_open_panel beginSheetForDirectory:nil
717 modalForWindow:[sender window]
719 didEndSelector: @selector(pathChosenInPanel:
725 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void *)contextInfo
727 if (returnCode == NSFileHandlingPanelOKButton)
730 [o_file_path release];
731 o_file_path = [[[sheet URLs] objectAtIndex: 0] path];
732 [o_file_path retain];
733 [self openFilePathChanged: nil];
737 - (IBAction)openFileStreamChanged:(id)sender
739 [self openFilePathChanged: nil];
742 - (IBAction)inputSlaveAction:(id)sender
744 if( sender == o_file_slave_ckbox )
745 [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
748 NSOpenPanel *o_open_panel;
749 o_open_panel = [NSOpenPanel openPanel];
750 [o_open_panel setCanChooseFiles: YES];
751 [o_open_panel setCanChooseDirectories: NO];
752 if( [o_open_panel runModal] == NSOKButton )
754 if( o_file_slave_path )
755 [o_file_slave_path release];
756 o_file_slave_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
757 [o_file_slave_path retain];
760 if( o_file_slave_path && [o_file_slave_ckbox state] == NSOnState)
762 [o_file_slave_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_slave_path]];
763 [o_file_slave_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_slave_path]];
767 [o_file_slave_filename_lbl setStringValue: @""];
768 [o_file_slave_icon_well setImage: NULL];
773 #pragma mark Optical Media Panel
775 - (void)showOpticalMediaView: theView withIcon:(NSImage *)icon
778 o_view_rect = [theView frame];
779 [theView setFrame: NSMakeRect( 233, 0, o_view_rect.size.width, o_view_rect.size.height)];
780 [theView setAutoresizesSubviews: YES];
781 if (o_currentOpticalMediaView)
783 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaView with: theView];
784 [o_currentOpticalMediaView release];
787 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: theView];
788 o_currentOpticalMediaView = theView;
789 [o_currentOpticalMediaView retain];
791 NSImageView *imageView;
792 imageView = [[NSImageView alloc] init];
793 [imageView setFrame: NSMakeRect( 53, 61, 128, 128 )];
794 [icon setSize: NSMakeSize(128,128)];
795 [imageView setImage: icon];
796 if (o_currentOpticalMediaIconView)
798 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaIconView with: imageView];
799 [o_currentOpticalMediaIconView release];
802 [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: imageView];
803 o_currentOpticalMediaIconView = imageView;
804 [o_currentOpticalMediaIconView retain];
805 [o_currentOpticalMediaView setNeedsDisplay: YES];
806 [o_currentOpticalMediaIconView setNeedsDisplay: YES];
807 [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] setNeedsDisplay: YES];
808 [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] displayIfNeeded];
811 - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
815 FSVolumeRefNum actualVolume;
816 err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
818 // get a FSVolumeRefNum from mountPath
819 if ( noErr == err ) {
820 FSCatalogInfo catalogInfo;
821 err = FSGetCatalogInfo ( &ref,
828 if ( noErr == err ) {
829 actualVolume = catalogInfo.volume;
833 GetVolParmsInfoBuffer volumeParms;
834 err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
835 if ( noErr != err ) {
836 msg_Err( p_intf, "error retrieving volume params, bailing out" );
840 NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
841 return [NSString stringWithFormat:@"/dev/r%@", bsdName];
844 - (char *)getVolumeTypeFromMountPath:(NSString *)mountPath
848 FSVolumeRefNum actualVolume;
849 err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
851 // get a FSVolumeRefNum from mountPath
852 if ( noErr == err ) {
853 FSCatalogInfo catalogInfo;
854 err = FSGetCatalogInfo ( &ref,
861 if ( noErr == err ) {
862 actualVolume = catalogInfo.volume;
866 GetVolParmsInfoBuffer volumeParms;
867 err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
869 CFMutableDictionaryRef matchingDict;
870 io_service_t service;
872 matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
873 service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
876 if (IO_OBJECT_NULL != service) {
877 if (IOObjectConformsTo(service, kIOCDMediaClass)) {
878 returnValue = kVLCMediaAudioCD;
880 else if(IOObjectConformsTo(service, kIODVDMediaClass))
881 returnValue = kVLCMediaDVD;
882 else if(IOObjectConformsTo(service, kIOBDMediaClass))
883 returnValue = kVLCMediaBD;
886 if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
887 returnValue = kVLCMediaVideoTSFolder;
888 else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
889 returnValue = kVLCMediaBDMVFolder;
892 // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
893 NSFileManager * fm = [[NSFileManager alloc] init];
895 NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
896 for (int i = 0; i < [dirContents count]; i++)
898 NSString *currentFile = [dirContents objectAtIndex:i];
899 NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
902 if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
904 if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame)
906 returnValue = kVLCMediaSVCD;
909 if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame)
911 returnValue = kVLCMediaVCD;
914 if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame)
916 returnValue = kVLCMediaBDMVFolder;
919 if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame)
921 returnValue = kVLCMediaVideoTSFolder;
930 returnValue = kVLCMediaVideoTSFolder;
934 IOObjectRelease(service);
939 - (void)showOpticalAtPath: (NSString *)o_opticalDevicePath
941 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
943 char *diskType = [self getVolumeTypeFromMountPath:o_opticalDevicePath];
945 if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder)
947 [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_opticalDevicePath]];
948 [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
949 NSString *pathToOpen;
950 if (diskType == kVLCMediaVideoTSFolder)
951 pathToOpen = o_opticalDevicePath;
953 pathToOpen = [self getBSDNodeFromMountPath: o_opticalDevicePath];
955 [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
956 [self showOpticalMediaView: o_disc_dvd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
958 [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
959 [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
962 else if (diskType == kVLCMediaAudioCD)
964 [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
965 [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_opticalDevicePath error:NULL] count] - 1]]; // minus .TOC.plist
966 [self showOpticalMediaView: o_disc_audiocd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
967 [self setMRL: [NSString stringWithFormat: @"cdda://%@", [self getBSDNodeFromMountPath: o_opticalDevicePath]]];
969 else if (diskType == kVLCMediaVCD)
971 [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
972 [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
973 [self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
975 else if (diskType == kVLCMediaSVCD)
977 [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
978 [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
979 [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
981 else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
983 [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
984 [self showOpticalMediaView: o_disc_bd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
985 [self setMRL: [NSString stringWithFormat: @"bluray://%@", o_opticalDevicePath]];
989 msg_Warn( VLCIntf, "unknown disk type, no idea what to display" );
990 [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
996 - (void)showSelectedOpticalDisc
998 NSString *o_opticalDevicePath = [o_opticalDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];
999 [NSThread detachNewThreadSelector:@selector(showOpticalAtPath:) toTarget:self withObject:o_opticalDevicePath];
1002 - (void)scanOpticalMedia:(NSNotification *)o_notification
1004 [o_opticalDevices removeAllObjects];
1005 [o_disc_selector_pop removeAllItems];
1006 [o_opticalDevices addObjectsFromArray: [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
1007 [o_opticalDevices addObjectsFromArray: o_specialMediaFolders];
1008 if ([o_opticalDevices count] > 0) {
1009 NSUInteger deviceCount = [o_opticalDevices count];
1010 for (NSUInteger i = 0; i < deviceCount ; i++)
1011 [o_disc_selector_pop addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: i]]];
1013 if ([o_disc_selector_pop numberOfItems] <= 1)
1014 [o_disc_selector_pop setHidden: YES];
1016 [o_disc_selector_pop setHidden: NO];
1018 // select newly added media folder
1019 if (o_notification && [[o_notification name] isEqualToString:@"VLCNewMediaFolderNotification"])
1020 [o_disc_selector_pop selectItemAtIndex: [[o_disc_selector_pop itemArray] count] - 1];
1022 [self showSelectedOpticalDisc];
1026 msg_Dbg( VLCIntf, "no optical media found" );
1027 [o_disc_selector_pop setHidden: YES];
1028 [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed: @"NSApplicationIcon"]];
1032 - (IBAction)discSelectorChanged:(id)sender
1034 [self showSelectedOpticalDisc];
1037 - (IBAction)openSpecialMediaFolder:(id)sender
1039 /* this is currently for VIDEO_TS and BDMV folders */
1040 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1042 [o_open_panel setAllowsMultipleSelection: NO];
1043 [o_open_panel setCanChooseFiles: NO];
1044 [o_open_panel setCanChooseDirectories: YES];
1045 [o_open_panel setTitle: [sender title]];
1046 [o_open_panel setPrompt: _NS("Open")];
1048 if ([o_open_panel runModal] == NSOKButton)
1050 NSString *o_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1051 if ([o_path length] > 0 )
1053 [o_specialMediaFolders addObject: o_path];
1054 [self scanOpticalMedia: [NSNotification notificationWithName:@"VLCNewMediaFolderNotification" object:nil]];
1059 - (IBAction)dvdreadOptionChanged:(id)sender
1061 NSString *o_device_path = [o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]];
1062 char *diskType = [self getVolumeTypeFromMountPath:o_device_path];
1064 NSString *pathToOpen;
1065 if (diskType == kVLCMediaVideoTSFolder)
1066 pathToOpen = o_device_path;
1068 pathToOpen = [self getBSDNodeFromMountPath: o_device_path];
1070 if (sender == o_disc_dvdwomenus_enablemenus_btn) {
1072 [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1073 [self showOpticalMediaView: o_disc_dvd_view withIcon: [o_currentOpticalMediaIconView image]];
1076 if (sender == o_disc_dvd_disablemenus_btn) {
1078 [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [o_currentOpticalMediaIconView image]];
1081 if (sender == o_disc_dvdwomenus_title)
1082 [o_disc_dvdwomenus_title_stp setIntValue: [o_disc_dvdwomenus_title intValue]];
1083 if (sender == o_disc_dvdwomenus_title_stp)
1084 [o_disc_dvdwomenus_title setIntValue: [o_disc_dvdwomenus_title_stp intValue]];
1085 if (sender == o_disc_dvdwomenus_chapter)
1086 [o_disc_dvdwomenus_chapter_stp setIntValue: [o_disc_dvdwomenus_chapter intValue]];
1087 if (sender == o_disc_dvdwomenus_chapter_stp)
1088 [o_disc_dvdwomenus_chapter setIntValue: [o_disc_dvdwomenus_chapter_stp intValue]];
1090 [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1093 - (IBAction)vcdOptionChanged:(id)sender
1095 if (sender == o_disc_vcd_title)
1096 [o_disc_vcd_title_stp setIntValue: [o_disc_vcd_title intValue]];
1097 if (sender == o_disc_vcd_title_stp)
1098 [o_disc_vcd_title setIntValue: [o_disc_vcd_title_stp intValue]];
1099 if (sender == o_disc_vcd_chapter)
1100 [o_disc_vcd_chapter_stp setIntValue: [o_disc_vcd_chapter intValue]];
1101 if (sender == o_disc_vcd_chapter_stp)
1102 [o_disc_vcd_chapter setIntValue: [o_disc_vcd_chapter_stp intValue]];
1104 [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]]];
1108 #pragma mark Network Panel
1110 - (void)textFieldWasClicked:(NSNotification *)o_notification
1112 if( [o_notification object] == o_net_udp_port )
1113 [o_net_mode selectCellAtRow: 0 column: 0];
1114 else if( [o_notification object] == o_net_udpm_addr ||
1115 [o_notification object] == o_net_udpm_port )
1116 [o_net_mode selectCellAtRow: 1 column: 0];
1118 [o_net_mode selectCellAtRow: 2 column: 0];
1120 [self openNetInfoChanged: nil];
1123 - (IBAction)openNetModeChanged:(id)sender
1125 if( sender == o_net_mode )
1127 if( [[sender selectedCell] tag] == 0 )
1128 [o_panel makeFirstResponder: o_net_udp_port];
1129 else if ( [[sender selectedCell] tag] == 1 )
1130 [o_panel makeFirstResponder: o_net_udpm_addr];
1132 msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
1135 [self openNetInfoChanged: nil];
1138 - (IBAction)openNetStepperChanged:(id)sender
1140 int i_tag = [sender tag];
1144 [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
1145 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1146 object: o_net_udp_port];
1147 [o_panel makeFirstResponder: o_net_udp_port];
1149 else if( i_tag == 1 )
1151 [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
1152 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1153 object: o_net_udpm_port];
1154 [o_panel makeFirstResponder: o_net_udpm_port];
1157 [self openNetInfoChanged: nil];
1160 - (void)openNetInfoChanged:(NSNotification *)o_notification
1162 NSString *o_mrl_string = [NSString string];
1164 if( [o_net_udp_panel isVisible] )
1167 o_mode = [[o_net_mode selectedCell] title];
1169 if( [o_mode isEqualToString: _NS("Unicast")] )
1171 int i_port = [o_net_udp_port intValue];
1173 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1174 o_mrl_string = @"udp://";
1176 o_mrl_string = @"rtp://";
1178 if( i_port != config_GetInt( p_intf, "server-port" ) )
1181 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1184 else if( [o_mode isEqualToString: _NS("Multicast")] )
1186 NSString *o_addr = [o_net_udpm_addr stringValue];
1187 int i_port = [o_net_udpm_port intValue];
1189 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1190 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1192 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1194 if( i_port != config_GetInt( p_intf, "server-port" ) )
1197 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1203 o_mrl_string = [o_net_http_url stringValue];
1205 [self setMRL: o_mrl_string];
1208 - (IBAction)openNetUDPButtonAction:(id)sender
1210 if( sender == o_net_openUDP_btn )
1212 [NSApp beginSheet: o_net_udp_panel
1213 modalForWindow: o_panel
1215 didEndSelector: NULL
1217 [self openNetInfoChanged: nil];
1219 else if( sender == o_net_udp_cancel_btn )
1221 [o_net_udp_panel orderOut: sender];
1222 [NSApp endSheet: o_net_udp_panel];
1224 else if( sender == o_net_udp_ok_btn )
1226 NSString *o_mrl_string = [NSString string];
1227 if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
1229 int i_port = [o_net_udp_port intValue];
1231 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1232 o_mrl_string = @"udp://";
1234 o_mrl_string = @"rtp://";
1236 if( i_port != config_GetInt( p_intf, "server-port" ) )
1239 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1242 else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
1244 NSString *o_addr = [o_net_udpm_addr stringValue];
1245 int i_port = [o_net_udpm_port intValue];
1247 if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1248 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1250 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1252 if( i_port != config_GetInt( p_intf, "server-port" ) )
1255 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1258 [self setMRL: o_mrl_string];
1259 [o_net_http_url setStringValue: o_mrl_string];
1260 [o_net_udp_panel orderOut: sender];
1261 [NSApp endSheet: o_net_udp_panel];
1266 #pragma mark Capture Panel
1268 - (void)showCaptureView: theView
1271 o_view_rect = [theView frame];
1272 [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
1273 [theView setAutoresizesSubviews: YES];
1274 if (o_currentCaptureView)
1276 [[[[o_tabview tabViewItemAtIndex: 3] view] animator] replaceSubview: o_currentCaptureView with: theView];
1277 [o_currentCaptureView release];
1281 [[[[o_tabview tabViewItemAtIndex: 3] view] animator] addSubview: theView];
1283 o_currentCaptureView = theView;
1284 [o_currentCaptureView retain];
1287 - (IBAction)openCaptureModeChanged:(id)sender
1289 if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1291 if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1293 if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1295 [self showCaptureView: o_eyetv_running_view];
1296 [self setupChannelInfo];
1300 setEyeTVUnconnected;
1304 [self showCaptureView: o_eyetv_notLaunched_view];
1307 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1309 [self showCaptureView: o_screen_view];
1310 [self setMRL: @"screen://"];
1311 [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
1312 [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
1313 [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
1314 [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
1315 [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
1316 [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
1318 int screen_index = config_GetInt( p_intf, "screen-index" );
1319 int display_id = config_GetInt( p_intf, "screen-display-id" );
1320 unsigned int i, displayCount = 0;
1321 CGLError returnedError;
1322 struct display_info_t *item;
1325 returnedError = CGGetOnlineDisplayList( 0, NULL, &displayCount );
1326 if( !returnedError )
1328 CGDirectDisplayID *ids;
1329 ids = ( CGDirectDisplayID * )malloc( displayCount * sizeof( CGDirectDisplayID ) );
1330 returnedError = CGGetOnlineDisplayList( displayCount, ids, &displayCount );
1331 if( !returnedError )
1333 for( i = 0; i < [o_displayInfos count]; i ++ )
1335 v = [o_displayInfos objectAtIndex:i];
1336 free( [v pointerValue] );
1338 [o_displayInfos removeAllObjects];
1339 [o_screen_screen_pop removeAllItems];
1340 for( i = 0; i < displayCount; i ++ )
1342 item = ( struct display_info_t * )malloc( sizeof( struct display_info_t ) );
1344 item->rect = CGDisplayBounds( item->id );
1345 [o_screen_screen_pop addItemWithTitle: [NSString stringWithFormat:@"Screen %d (%dx%d)", i + 1, (int)item->rect.size.width, (int)item->rect.size.height]];
1346 v = [NSValue valueWithPointer:item];
1347 [o_displayInfos addObject:v];
1348 if( i == 0 || display_id == item->id || screen_index - 1 == i )
1350 [o_screen_screen_pop selectItemAtIndex: i];
1351 [o_screen_left_stp setMaxValue: item->rect.size.width];
1352 [o_screen_top_stp setMaxValue: item->rect.size.height];
1353 [o_screen_width_stp setMaxValue: item->rect.size.width];
1354 [o_screen_height_stp setMaxValue: item->rect.size.height];
1361 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Video Device")] )
1363 [self showCaptureView: o_qtk_view];
1364 if ([o_capture_width_fld intValue] <= 0)
1365 [self qtkChanged:nil];
1367 if(!qtk_currdevice_uid)
1370 [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
1372 else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Audio Device")] )
1374 [self showCaptureView: o_qtkaudio_view];
1375 [self qtkAudioChanged:nil];
1377 if(!qtkaudio_currdevice_uid)
1380 [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
1384 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1386 [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1387 if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1388 [o_screen_fps_fld setFloatValue: 1.0];
1389 [self setMRL: @"screen://"];
1392 - (IBAction)eyetvSwitchChannel:(id)sender
1394 if( sender == o_eyetv_nextProgram_btn )
1396 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1397 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1398 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1400 else if( sender == o_eyetv_previousProgram_btn )
1402 int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1403 [o_eyetv_channels_pop selectItemWithTag:chanNum];
1404 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1406 else if( sender == o_eyetv_channels_pop )
1408 int chanNum = [[sender selectedItem] tag];
1409 [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1410 [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1413 msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1416 - (IBAction)eyetvLaunch:(id)sender
1418 [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1421 - (IBAction)eyetvGetPlugin:(id)sender
1423 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1426 - (void)eyetvChanged:(NSNotification *)o_notification
1428 if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1430 msg_Dbg( VLCIntf, "eyetv device was added" );
1431 [self showCaptureView: o_eyetv_running_view];
1432 [self setupChannelInfo];
1434 else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1436 /* leave the channel selection like that,
1437 * switch to our "no device" tab */
1438 msg_Dbg( VLCIntf, "eyetv device was removed" );
1439 setEyeTVUnconnected;
1441 else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1443 /* switch to the "launch eyetv" tab */
1444 msg_Dbg( VLCIntf, "eyetv was terminated" );
1445 [self showCaptureView: o_eyetv_notLaunched_view];
1447 else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1449 /* we got no device yet */
1450 msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1451 setEyeTVUnconnected;
1455 /* little helper method, since this code needs to be run by multiple objects */
1456 - (void)setupChannelInfo
1458 /* set up channel selection */
1459 [o_eyetv_channels_pop removeAllItems];
1460 [o_eyetv_chn_bgbar setHidden: NO];
1461 [o_eyetv_chn_bgbar animate: self];
1462 [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1463 [o_eyetv_chn_status_txt setHidden: NO];
1466 NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1468 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1470 keyEquivalent: @""] setTag:x++];
1471 [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1473 keyEquivalent: @""] setTag:x++];
1477 [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1478 while( channel = [channels nextObject] )
1480 /* we have to add items this way, because we accept duplicates
1481 * additionally, we save a bit of time */
1482 [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1484 keyEquivalent: @""] setTag:++x];
1486 /* make Tuner the default */
1487 [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1491 [o_eyetv_chn_bgbar setHidden: YES];
1492 [o_eyetv_chn_status_txt setHidden: YES];
1496 #pragma mark Subtitle Settings
1498 - (IBAction)subsChanged:(id)sender
1500 if ([o_file_sub_ckbox state] == NSOnState)
1502 [o_file_sub_btn_settings setEnabled:YES];
1504 [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1505 [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1510 [o_file_sub_btn_settings setEnabled:NO];
1511 [o_file_subtitles_filename_lbl setStringValue: @""];
1512 [o_file_subtitles_icon_well setImage: NULL];
1516 - (IBAction)subSettings:(id)sender
1518 [NSApp beginSheet: o_file_sub_sheet
1519 modalForWindow: [sender window]
1521 didEndSelector: NULL
1525 - (IBAction)subCloseSheet:(id)sender
1527 [self subsChanged: nil];
1528 [o_file_sub_sheet orderOut:sender];
1529 [NSApp endSheet: o_file_sub_sheet];
1532 - (IBAction)subFileBrowse:(id)sender
1534 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1536 [o_open_panel setAllowsMultipleSelection: NO];
1537 [o_open_panel setTitle: _NS("Open File")];
1538 [o_open_panel setPrompt: _NS("Open")];
1540 if( [o_open_panel runModal] == NSOKButton )
1542 o_sub_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1543 [o_sub_path retain];
1544 [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1545 [o_file_sub_path_fld setStringValue: [o_file_subtitles_filename_lbl stringValue]];
1546 [o_file_sub_path_lbl setHidden: YES];
1547 [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1548 [o_file_sub_icon_view setImage: [o_file_subtitles_icon_well image]];
1552 [o_file_sub_path_lbl setHidden: NO];
1553 [o_file_sub_path_fld setStringValue:@""];
1554 [o_file_subtitles_filename_lbl setStringValue:@""];
1555 [o_file_subtitles_icon_well setImage: nil];
1556 [o_file_sub_icon_view setImage: nil];
1560 - (IBAction)subOverride:(id)sender
1562 BOOL b_state = [o_file_sub_override state];
1563 [o_file_sub_delay setEnabled: b_state];
1564 [o_file_sub_delay_stp setEnabled: b_state];
1565 [o_file_sub_fps setEnabled: b_state];
1566 [o_file_sub_fps_stp setEnabled: b_state];
1569 - (IBAction)subDelayStepperChanged:(id)sender
1571 [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1574 - (IBAction)subFpsStepperChanged:(id)sender;
1576 [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1580 #pragma mark Miscellaneous
1582 - (IBAction)panelCancel:(id)sender
1584 [NSApp stopModalWithCode: 0];
1587 - (IBAction)panelOk:(id)sender
1589 if( [[self MRL] length] )
1590 [NSApp stopModalWithCode: 1];
1595 - (NSArray *)qtkvideoDevices
1597 if ( !qtkvideoDevices )
1598 [self qtkrefreshVideoDevices];
1599 return qtkvideoDevices;
1602 - (void)qtkrefreshVideoDevices
1604 [qtkvideoDevices release];
1605 qtkvideoDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1608 - (NSArray *)qtkaudioDevices
1610 if ( !qtkaudioDevices )
1611 [self qtkrefreshAudioDevices];
1612 return qtkaudioDevices;
1615 - (void)qtkrefreshAudioDevices
1617 [qtkaudioDevices release];
1618 qtkaudioDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeSound] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1623 @implementation VLCOpenTextField
1625 - (void)mouseDown:(NSEvent *)theEvent
1627 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1629 [super mouseDown: theEvent];