]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
macosx/open: replace deprecated API call with modern blocks-based counterpart
[vlc] / modules / gui / macosx / open.m
1 /*****************************************************************************
2  * open.m: Open dialogues for VLC's MacOS X port
3  *****************************************************************************
4  * Copyright (C) 2002-2012 VLC authors and VideoLAN
5  * $Id$
6  *
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>
12  *
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.
17  *
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.
22  *
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  *****************************************************************************/
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #import <stdlib.h>                                      /* malloc(), free() */
32 #import <sys/param.h>                                    /* for MAXPATHLEN */
33
34 #import "CompatibilityFixes.h"
35
36 #import <paths.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>
44
45 #import "intf.h"
46 #import "playlist.h"
47 #import "open.h"
48 #import "output.h"
49 #import "eyetv.h"
50
51 #import <vlc_url.h>
52
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]
61
62 struct display_info_t
63 {
64     CGRect rect;
65     CGDirectDisplayID id;
66 };
67
68 /*****************************************************************************
69  * VLCOpen implementation
70  *****************************************************************************/
71 @implementation VLCOpen
72
73 #pragma mark -
74 #pragma mark Init
75
76 static VLCOpen *_o_sharedMainInstance = nil;
77
78 + (VLCOpen *)sharedInstance
79 {
80     return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
81 }
82
83 - (id)init
84 {
85     if( _o_sharedMainInstance) {
86         [self dealloc];
87     } else {
88         _o_sharedMainInstance = [super init];
89         p_intf = VLCIntf;
90     }
91
92     return _o_sharedMainInstance;
93 }
94
95 - (void)dealloc
96 {
97     [o_specialMediaFolders release];
98     [o_opticalDevices release];
99     if( o_file_slave_path )
100         [o_file_slave_path release];
101     [o_mrl release];
102     if (o_sub_path)
103         [o_sub_path release];
104     [o_currentOpticalMediaIconView release];
105     [o_currentOpticalMediaView release];
106     int i;
107     for( i = 0; i < [o_displayInfos count]; i ++ )
108     {
109         NSValue *v = [o_displayInfos objectAtIndex:i];
110         free( [v pointerValue] );
111     }
112     [o_displayInfos removeAllObjects];
113     [o_displayInfos release];
114
115     [super dealloc];
116 }
117
118 - (void)awakeFromNib
119 {
120     if (OSX_LION)
121         [o_panel setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
122
123     [o_panel setTitle: _NS("Open Source")];
124     [o_mrl_lbl setStringValue: _NS("Media Resource Locator (MRL)")];
125
126     [o_btn_ok setTitle: _NS("Open")];
127     [o_btn_cancel setTitle: _NS("Cancel")];
128
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")];
133
134     [o_file_name setStringValue: @""];
135     [o_file_name_stub setStringValue: _NS("Choose a file")];
136     [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
137     [o_file_btn_browse setTitle: _NS("Browse...")];
138     [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
139     [o_file_stream setHidden: NO];
140     [o_file_slave_ckbox setTitle: _NS("Play another media synchronously")];
141     [o_file_slave_select_btn setTitle: _NS("Choose...")];
142     [o_file_slave_filename_lbl setStringValue: @""];
143     [o_file_slave_icon_well setImage: NULL];
144     [o_file_subtitles_filename_lbl setStringValue: @""];
145     [o_file_subtitles_icon_well setImage: NULL];
146     [o_file_custom_timing_ckb setTitle: _NS("Custom playback")];
147     [o_file_starttime_lbl setStringValue: _NS("Start time")];
148     [o_file_starttime_fld setStringValue: @""];
149     [o_file_stoptime_lbl setStringValue: _NS("Stop time")];
150     [o_file_stoptime_fld setStringValue: @""];
151
152     [o_disc_selector_pop removeAllItems];
153     [o_disc_selector_pop setHidden: NO];
154     NSString *o_videots = _NS("Open VIDEO_TS folder");
155     NSString *o_bdmv = _NS("Open BDMV folder");
156     [o_disc_nodisc_lbl setStringValue: _NS("Insert Disc")];
157     [o_disc_nodisc_videots_btn setTitle: o_videots];
158     [o_disc_nodisc_bdmv_btn setTitle: o_bdmv];
159     [o_disc_audiocd_lbl setStringValue: _NS("Audio CD")];
160     [o_disc_audiocd_trackcount_lbl setStringValue: @""];
161     [o_disc_audiocd_videots_btn setTitle: o_videots];
162     [o_disc_audiocd_bdmv_btn setTitle: o_bdmv];
163     [o_disc_dvd_lbl setStringValue: @""];
164     [o_disc_dvd_disablemenus_btn setTitle: _NS("Disable DVD menus")];
165     [o_disc_dvd_videots_btn setTitle: o_videots];
166     [o_disc_dvd_bdmv_btn setTitle: o_bdmv];
167     [o_disc_dvdwomenus_lbl setStringValue: @""];
168     [o_disc_dvdwomenus_enablemenus_btn setTitle: _NS("Enable DVD menus")];
169     [o_disc_dvdwomenus_videots_btn setTitle: o_videots];
170     [o_disc_dvdwomenus_bdmv_btn setTitle: o_bdmv];
171     [o_disc_dvdwomenus_title_lbl setStringValue: _NS("Title")];
172     [o_disc_dvdwomenus_chapter_lbl setStringValue: _NS("Chapter")];
173     [o_disc_vcd_title_lbl setStringValue: _NS("Title")];
174     [o_disc_vcd_chapter_lbl setStringValue: _NS("Chapter")];
175     [o_disc_vcd_videots_btn setTitle: o_videots];
176     [o_disc_vcd_bdmv_btn setTitle: o_bdmv];
177     [o_disc_bd_videots_btn setTitle: o_videots];
178     [o_disc_bd_bdmv_btn setTitle: o_bdmv];
179
180     [o_net_udp_port_lbl setStringValue: _NS("Port")];
181     [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
182     [o_net_udpm_port_lbl setStringValue: _NS("Port")];
183     [o_net_http_url_lbl setStringValue: _NS("URL")];
184     [o_net_help_lbl setStringValue: _NS("To Open a usual network stream (HTTP, RTSP, RTMP, MMS, FTP, etc.), just enter the URL in the field above. If you want to open a RTP or UDP stream, press the button below.")];
185     [o_net_help_udp_lbl setStringValue: _NS("If you want to open a multicast stream, enter the respective IP address given by the stream provider. In unicast mode, VLC will use your machine's IP automatically.\n\nTo open a stream using a different protocol, just press Cancel to close this sheet.")];
186     [o_net_udp_cancel_btn setTitle: _NS("Cancel")];
187     [o_net_udp_ok_btn setTitle: _NS("Open")];
188     [o_net_openUDP_btn setTitle: _NS("Open RTP/UDP Stream")];
189     [o_net_udp_mode_lbl setStringValue: _NS("Mode")];
190     [o_net_udp_protocol_lbl setStringValue: _NS("Protocol")];
191     [o_net_udp_address_lbl setStringValue: _NS("Address")];
192
193     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
194     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
195
196     [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
197     [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
198
199     [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
200
201     [o_capture_mode_pop removeAllItems];
202     [o_capture_mode_pop addItemWithTitle: _NS("Input Devices")];
203     [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
204     [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
205     [o_screen_long_lbl setStringValue: _NS("This input allows you to save, stream or display your current screen contents.")];
206     [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
207     [o_screen_screen_lbl setStringValue: _NS("Screen:")];
208     [o_screen_left_lbl setStringValue: _NS("Subscreen left:")];
209     [o_screen_top_lbl setStringValue: _NS("Subscreen top:")];
210     [o_screen_width_lbl setStringValue: _NS("Subscreen width:")];
211     [o_screen_height_lbl setStringValue: _NS("Subscreen height:")];
212     [o_screen_follow_mouse_ckb setTitle: _NS("Follow the mouse")];
213     [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
214     [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
215     [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
216     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
217     [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
218     [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
219     [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
220     [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
221     [o_capture_width_lbl setStringValue: _NS("Image width:")];
222     [o_capture_height_lbl setStringValue: _NS("Image height:")];
223
224     [self qtkvideoDevices];
225     [o_qtk_video_device_pop removeAllItems];
226     msg_Dbg( VLCIntf, "Found %lu video capture devices", [qtkvideoDevices count] );
227
228     if([qtkvideoDevices count] >= 1)
229     {
230         if (!qtk_currdevice_uid) {
231             qtk_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo] uniqueID]
232                                                                 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
233         }
234         NSUInteger deviceCount = [qtkvideoDevices count];
235         for(int ivideo = 0; ivideo < deviceCount; ivideo++){
236             QTCaptureDevice *qtk_device;
237             qtk_device = [qtkvideoDevices objectAtIndex:ivideo];
238             [o_qtk_video_device_pop addItemWithTitle: [qtk_device localizedDisplayName]];
239             if([[[qtk_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid]){
240                 [o_qtk_video_device_pop selectItemAtIndex:ivideo];
241             }
242         }
243     }
244     else
245     {
246         [o_qtk_video_device_pop addItemWithTitle: _NS("None")];
247         [qtk_currdevice_uid release];
248     }
249
250     [self qtkaudioDevices];
251     [o_qtk_audio_device_pop removeAllItems];
252     msg_Dbg( VLCIntf, "Found %lu audio capture devices", [qtkaudioDevices count] );
253
254     if([qtkaudioDevices count] >= 1)
255     {
256         if (!qtkaudio_currdevice_uid) {
257             qtkaudio_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound] uniqueID]
258                                   stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
259         }
260         NSUInteger deviceCount = [qtkaudioDevices count];
261         for(int iaudio = 0; iaudio < deviceCount; iaudio++){
262             QTCaptureDevice *qtkaudio_device;
263             qtkaudio_device = [qtkaudioDevices objectAtIndex:iaudio];
264             [o_qtk_audio_device_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
265             if([[[qtkaudio_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtkaudio_currdevice_uid]){
266                 [o_qtk_audio_device_pop selectItemAtIndex:iaudio];
267             }
268         }
269     }
270     else
271     {
272         [o_qtk_audio_device_pop addItemWithTitle: _NS("None")];
273         [qtkaudio_currdevice_uid release];
274     }
275
276     [self setSubPanel];
277
278     [[NSNotificationCenter defaultCenter] addObserver: self
279         selector: @selector(openNetInfoChanged:)
280         name: NSControlTextDidChangeNotification
281         object: o_net_udp_port];
282     [[NSNotificationCenter defaultCenter] addObserver: self
283         selector: @selector(openNetInfoChanged:)
284         name: NSControlTextDidChangeNotification
285         object: o_net_udpm_addr];
286     [[NSNotificationCenter defaultCenter] addObserver: self
287         selector: @selector(openNetInfoChanged:)
288         name: NSControlTextDidChangeNotification
289         object: o_net_udpm_port];
290     [[NSNotificationCenter defaultCenter] addObserver: self
291         selector: @selector(openNetInfoChanged:)
292         name: NSControlTextDidChangeNotification
293         object: o_net_http_url];
294
295     [[NSDistributedNotificationCenter defaultCenter] addObserver: self
296                                                         selector: @selector(eyetvChanged:)
297                                                             name: NULL
298                                                           object: @"VLCEyeTVSupport"
299                                               suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
300
301     [[NSNotificationCenter defaultCenter] addObserver: self
302                                              selector: @selector(screenFPSfieldChanged:)
303                                                  name: NSControlTextDidChangeNotification
304                                                object: o_screen_fps_fld];
305
306     /* register clicks on text fields */
307     [[NSNotificationCenter defaultCenter] addObserver: self
308                                              selector: @selector(textFieldWasClicked:)
309                                                  name: @"VLCOpenTextFieldWasClicked"
310                                                object: nil];
311
312     /* we want to be notified about removed or added media */
313     o_specialMediaFolders = [[NSMutableArray alloc] init];
314     o_opticalDevices = [[NSMutableArray alloc] init];
315     o_displayInfos = [[NSMutableArray alloc] init];
316     NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
317
318     [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidMountNotification object:nil];
319     [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidUnmountNotification object:nil];
320     [self performSelector:@selector(qtkToggleUIElements:) withObject:nil afterDelay:.3];
321     [self performSelector:@selector(scanOpticalMedia:) withObject:nil afterDelay:.5];
322
323     [self setMRL: @""];
324 }
325
326 - (void)setMRL:(NSString *)newMRL
327 {
328     if (o_mrl)
329         [o_mrl release];
330
331     o_mrl = newMRL;
332     [o_mrl retain];
333     [o_mrl_fld setStringValue: o_mrl];
334     if ([o_mrl length] > 0)
335         [o_btn_ok setEnabled: YES];
336     else
337         [o_btn_ok setEnabled: NO];
338 }
339
340 - (NSString *)MRL
341 {
342     return o_mrl;
343 }
344
345 - (void)setSubPanel
346 {
347     int i_index;
348     module_config_t * p_item;
349
350     [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
351     [o_file_sub_path_lbl setStringValue: _NS("Choose a file")];
352     [o_file_sub_path_lbl setHidden: NO];
353     [o_file_sub_path_fld setStringValue: @""];
354     [o_file_sub_btn_settings setTitle: _NS("Choose...")];
355     [o_file_sub_btn_browse setTitle: _NS("Browse...")];
356     [o_file_sub_override setTitle: _NS("Override parameters")];
357     [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
358     [o_file_sub_delay_stp setEnabled: NO];
359     [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
360     [o_file_sub_fps_stp setEnabled: NO];
361     [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
362     [o_file_sub_encoding_pop removeAllItems];
363     [o_file_sub_size_lbl setStringValue: _NS("Font size")];
364     [o_file_sub_size_pop removeAllItems];
365     [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
366     [o_file_sub_align_pop removeAllItems];
367     [o_file_sub_ok_btn setStringValue: _NS("OK")];
368     [o_file_sub_font_box setTitle: _NS("Font Properties")];
369     [o_file_sub_file_box setTitle: _NS("Subtitle File")];
370
371     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
372
373     if( p_item )
374     {
375         for( i_index = 0; p_item->list.psz && p_item->list.psz[i_index];
376              i_index++ )
377         {
378             [o_file_sub_encoding_pop addItemWithTitle:
379                 [NSString stringWithUTF8String: p_item->list.psz[i_index]]];
380         }
381         [o_file_sub_encoding_pop selectItemWithTitle:
382                 [NSString stringWithUTF8String: p_item->value.psz]];
383     }
384
385     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
386
387     if ( p_item )
388     {
389         for ( i_index = 0; i_index < p_item->list_count; i_index++ )
390         {
391             [o_file_sub_align_pop addItemWithTitle:
392              _NS(p_item->list_text[i_index])];
393         }
394         [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
395     }
396
397     p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
398
399     if ( p_item )
400     {
401         for ( i_index = 0; i_index < p_item->list_count; i_index++ )
402         {
403             [o_file_sub_size_pop addItemWithTitle: _NS(p_item->list_text[i_index])];
404             if ( p_item->value.i == p_item->list.i[i_index] )
405             {
406                 [o_file_sub_size_pop selectItemAtIndex: i_index];
407             }
408         }
409     }
410 }
411
412 - (void)openTarget:(int)i_type
413 {
414     int i_result;
415
416     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
417
418     [o_tabview selectTabViewItemAtIndex: i_type];
419     [o_file_sub_ckbox setState: NSOffState];
420
421     i_result = [NSApp runModalForWindow: o_panel];
422     [o_panel close];
423
424     if( i_result )
425     {
426         NSMutableDictionary *o_dic;
427         NSMutableArray *o_options = [NSMutableArray array];
428
429         o_dic = [NSMutableDictionary dictionaryWithObject: [self MRL] forKey: @"ITEM_URL"];
430         if( [o_file_sub_ckbox state] == NSOnState )
431         {
432             module_config_t * p_item;
433
434             [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", o_sub_path]];
435             if( [o_file_sub_override state] == NSOnState )
436             {
437                 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
438                 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
439             }
440             [o_options addObject: [NSString stringWithFormat:
441                     @"subsdec-encoding=%@",
442                     [o_file_sub_encoding_pop titleOfSelectedItem]]];
443             [o_options addObject: [NSString stringWithFormat:
444                     @"subsdec-align=%li",
445                     [o_file_sub_align_pop indexOfSelectedItem]]];
446
447             p_item = config_FindConfig( VLC_OBJECT(p_intf),
448                                             "freetype-rel-fontsize" );
449
450             if ( p_item )
451             {
452                 [o_options addObject: [NSString stringWithFormat:
453                     @"freetype-rel-fontsize=%i",
454                     p_item->list.i[[o_file_sub_size_pop indexOfSelectedItem]]]];
455             }
456         }
457         NSArray * components = [[o_file_starttime_fld stringValue] componentsSeparatedByString:@":"];
458         NSUInteger componentCount = [components count];
459         NSInteger tempValue;
460         if( componentCount == 1 )
461             tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] );
462         else if( componentCount == 2 )
463             tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue] );
464         else if( componentCount == 3 )
465             tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue] );
466         if (tempValue > 0)
467             [o_options addObject: [NSString stringWithFormat:@"start-time=%li", tempValue]];
468         components = [[o_file_stoptime_fld stringValue] componentsSeparatedByString:@":"];
469         componentCount = [components count];
470         if( componentCount == 1 )
471             tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] );
472         else if( componentCount == 2 )
473             tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue] );
474         else if( componentCount == 3 )
475             tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue] );
476         if (tempValue > 0)
477             [o_options addObject: [NSString stringWithFormat:@"stop-time=%li", tempValue]];
478         if( [o_output_ckbox state] == NSOnState )
479         {
480             NSUInteger count = [[o_sout_options mrl] count];
481             for (NSUInteger i = 0 ; i < count ; i++)
482             {
483                 [o_options addObject: [NSString stringWithString: [[(VLCOutput *)o_sout_options mrl] objectAtIndex: i]]];
484             }
485         }
486         if( [o_file_slave_ckbox state] && o_file_slave_path )
487            [o_options addObject: [NSString stringWithFormat: @"input-slave=%@", o_file_slave_path]];
488         if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
489         {
490             if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
491             {
492                 int selected_index = [o_screen_screen_pop indexOfSelectedItem];
493                 NSValue *v = [o_displayInfos objectAtIndex:selected_index];
494                 struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
495
496                 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
497                 [o_options addObject: [NSString stringWithFormat: @"screen-display-id=%i", item->id]];
498                 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
499                 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
500                 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
501                 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
502                 if( [o_screen_follow_mouse_ckb intValue] == YES )
503                     [o_options addObject: @"screen-follow-mouse"];
504                 else
505                     [o_options addObject: @"no-screen-follow-mouse"];
506             }
507             else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")] )
508             {
509                 if ([o_qtk_video_ckb state])
510                 {
511                     [o_options addObject: [NSString stringWithFormat: @"qtcapture-width=%i", [o_capture_width_fld intValue]]];
512                     [o_options addObject: [NSString stringWithFormat: @"qtcapture-height=%i", [o_capture_height_fld intValue]]];
513                     if ([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
514                        [o_options addObject: [NSString stringWithFormat: @"input-slave=qtsound://%@", qtkaudio_currdevice_uid]];
515                 }
516             }
517         }
518
519         /* apply the options to our item(s) */
520         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
521         if( b_autoplay )
522             [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
523         else
524             [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
525     }
526 }
527
528 - (IBAction)screenChanged:(id)sender
529 {
530     int selected_index = [o_screen_screen_pop indexOfSelectedItem];
531     if( selected_index >= [o_displayInfos count] ) return;
532
533     NSValue *v = [o_displayInfos objectAtIndex:selected_index];
534     struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
535
536     [o_screen_left_stp setMaxValue: item->rect.size.width];
537     [o_screen_top_stp setMaxValue: item->rect.size.height];
538     [o_screen_width_stp setMaxValue: item->rect.size.width];
539     [o_screen_height_stp setMaxValue: item->rect.size.height];
540 }
541
542 - (IBAction)qtkChanged:(id)sender
543 {
544     NSInteger i_selectedDevice = [o_qtk_video_device_pop indexOfSelectedItem];
545     if( [qtkvideoDevices count] >= 1 )
546     {
547         NSValue *sizes = [[[[qtkvideoDevices objectAtIndex:i_selectedDevice] formatDescriptions] objectAtIndex: 0] attributeForKey: QTFormatDescriptionVideoEncodedPixelsSizeAttribute];
548
549         [o_capture_width_fld setIntValue: [sizes sizeValue].width];
550         [o_capture_height_fld setIntValue: [sizes sizeValue].height];
551         [o_capture_width_stp setIntValue: [o_capture_width_fld intValue]];
552         [o_capture_height_stp setIntValue: [o_capture_height_fld intValue]];
553         qtk_currdevice_uid = [[(QTCaptureDevice *)[qtkvideoDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
554     }
555 }
556
557 - (IBAction)qtkAudioChanged:(id)sender
558 {
559     NSInteger i_selectedDevice = [o_qtk_audio_device_pop indexOfSelectedItem];
560     if( [qtkaudioDevices count] >= 1 )
561     {
562         qtkaudio_currdevice_uid = [[(QTCaptureDevice *)[qtkaudioDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
563     }
564 }
565
566 - (IBAction)qtkToggleUIElements:(id)sender
567 {
568     [o_qtk_audio_device_pop setEnabled:[o_qtk_audio_ckb state]];
569     BOOL b_state = [o_qtk_video_ckb state];
570     [o_qtk_video_device_pop setEnabled:b_state];
571     [o_capture_width_fld setEnabled:b_state];
572     [o_capture_width_stp setEnabled:b_state];
573     [o_capture_height_fld setEnabled:b_state];
574     [o_capture_height_stp setEnabled:b_state];
575     [self qtkAudioChanged:sender];
576     [self qtkChanged:sender];
577     [self openCaptureModeChanged:sender];
578 }
579
580 #pragma mark -
581 #pragma mark Main Actions
582
583 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
584 {
585     NSString *o_label = [o_tvi label];
586
587     if( [o_label isEqualToString: _NS("File")] )
588     {
589         [self openFilePathChanged: nil];
590     }
591     else if( [o_label isEqualToString: _NS("Disc")] )
592     {
593         [self scanOpticalMedia: nil];
594     }
595     else if( [o_label isEqualToString: _NS("Network")] )
596     {
597         [self openNetInfoChanged: nil];
598     }
599     else if( [o_label isEqualToString: _NS("Capture")] )
600     {
601         [self openCaptureModeChanged: nil];
602     }
603 }
604
605 - (IBAction)expandMRLfieldAction:(id)sender
606 {
607     NSRect o_win_rect, o_view_rect;
608     o_win_rect = [o_panel frame];
609     o_view_rect = [o_mrl_view frame];
610
611     if( [o_mrl_btn state] == NSOffState )
612     {
613         /* we need to collaps, restore the panel size */
614         o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
615         o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
616
617         /* remove the MRL view */
618         [o_mrl_view removeFromSuperview];
619     } else {
620         /* we need to expand */
621         [o_mrl_view setFrame: NSMakeRect( 0,
622                                          [o_mrl_btn frame].origin.y,
623                                          o_view_rect.size.width,
624                                          o_view_rect.size.height )];
625         [o_mrl_view setNeedsDisplay: NO];
626         [o_mrl_view setAutoresizesSubviews: YES];
627
628         /* enlarge panel size for MRL view */
629         o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
630     }
631
632     [[o_panel animator] setFrame: o_win_rect display:YES];
633 //    [o_panel displayIfNeeded];
634     if( [o_mrl_btn state] == NSOnState )
635         [[o_panel contentView] addSubview: o_mrl_view];
636 }
637
638 - (void)openFileGeneric
639 {
640     [self openFilePathChanged: nil];
641     [self openTarget: 0];
642 }
643
644 - (void)openDisc
645 {
646     [o_specialMediaFolders removeAllObjects];
647     [o_opticalDevices removeAllObjects];
648     [self scanOpticalMedia: nil];
649     [self openTarget: 1];
650 }
651
652 - (void)openNet
653 {
654     [self openNetInfoChanged: nil];
655     [self openTarget: 2];
656 }
657
658 - (void)openCapture
659 {
660     [self openCaptureModeChanged: nil];
661     [self openTarget: 3];
662 }
663
664 - (void)openFile
665 {
666     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
667     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
668
669     [o_open_panel setAllowsMultipleSelection: YES];
670     [o_open_panel setCanChooseDirectories: YES];
671     [o_open_panel setTitle: _NS("Open File")];
672     [o_open_panel setPrompt: _NS("Open")];
673
674     if( [o_open_panel runModal] == NSOKButton )
675     {
676         NSArray * o_urls = [o_open_panel URLs];
677         NSUInteger count = [o_urls count];
678         NSMutableArray *o_values = [NSMutableArray arrayWithCapacity:count];
679         NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
680         for( NSUInteger i = 0; i < count; i++ )
681         {
682             [o_values addObject: [[o_urls objectAtIndex: i] path]];
683         }
684         [o_values sortUsingSelector:@selector(caseInsensitiveCompare:)];
685
686         for( NSUInteger i = 0; i < count; i++ )
687         {
688             NSDictionary *o_dic;
689             char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], "file");
690             if( !psz_uri )
691                 continue;
692
693             o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
694
695             free( psz_uri );
696
697             [o_array addObject: o_dic];
698         }
699         if( b_autoplay )
700             [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
701         else
702             [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
703     }
704 }
705
706 #pragma mark -
707 #pragma mark File Panel
708
709 - (void)openFilePathChanged:(NSNotification *)o_notification
710 {
711     if ( o_file_path && [o_file_path length] > 0 )
712     {
713         bool b_stream = [o_file_stream state];
714         BOOL b_dir = NO;
715
716         [[NSFileManager defaultManager] fileExistsAtPath:o_file_path isDirectory:&b_dir];
717
718         char *psz_uri = vlc_path2uri([o_file_path UTF8String], "file");
719         if( !psz_uri ) return;
720
721         NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
722         NSRange offile = [o_mrl_string rangeOfString:@"file"];
723         free( psz_uri );
724
725         if( b_dir )
726             [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
727         else if( b_stream )
728             [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
729
730         [o_file_name setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_path]];
731         [o_file_name_stub setHidden: YES];
732         [o_file_stream setHidden: NO];
733         [o_file_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_path]];
734         [o_file_icon_well setHidden: NO];
735         [self setMRL: o_mrl_string];
736     }
737     else
738     {
739         [o_file_name setStringValue: @""];
740         [o_file_name_stub setHidden: NO];
741         [o_file_stream setHidden: YES];
742         [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
743         [self setMRL: @""];
744     }
745 }
746
747 - (IBAction)openFileBrowse:(id)sender
748 {
749     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
750
751     [o_open_panel setAllowsMultipleSelection: NO];
752     [o_open_panel setCanChooseDirectories: YES];
753     [o_open_panel setTitle: _NS("Open File")];
754     [o_open_panel setPrompt: _NS("Open")];
755     [o_open_panel beginSheetModalForWindow:[sender window] completionHandler:^(NSInteger returnCode) {
756         if (returnCode == NSFileHandlingPanelOKButton)
757         {
758             if( o_file_path )
759                 [o_file_path release];
760             o_file_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
761             [o_file_path retain];
762             [self openFilePathChanged: nil];
763         }
764     }];
765 }
766
767 - (IBAction)openFileStreamChanged:(id)sender
768 {
769     [self openFilePathChanged: nil];
770 }
771
772 - (IBAction)inputSlaveAction:(id)sender
773 {
774     if( sender == o_file_slave_ckbox )
775         [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
776     else
777     {
778         NSOpenPanel *o_open_panel;
779         o_open_panel = [NSOpenPanel openPanel];
780         [o_open_panel setCanChooseFiles: YES];
781         [o_open_panel setCanChooseDirectories: NO];
782         if( [o_open_panel runModal] == NSOKButton )
783         {
784             if( o_file_slave_path )
785                 [o_file_slave_path release];
786             o_file_slave_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
787             [o_file_slave_path retain];
788         }
789     }
790     if( o_file_slave_path && [o_file_slave_ckbox state] == NSOnState)
791     {
792         [o_file_slave_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_slave_path]];
793         [o_file_slave_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_slave_path]];
794     }
795     else
796     {
797         [o_file_slave_filename_lbl setStringValue: @""];
798         [o_file_slave_icon_well setImage: NULL];
799     }
800 }
801
802 - (IBAction)fileTimeCustomization:(id)sender
803 {
804     BOOL b_value = [o_file_custom_timing_ckb state];
805     [o_file_starttime_fld setEnabled: b_value];
806     [o_file_starttime_lbl setEnabled: b_value];
807     [o_file_stoptime_fld setEnabled: b_value];
808     [o_file_stoptime_lbl setEnabled: b_value];
809 }
810
811 #pragma mark -
812 #pragma mark Optical Media Panel
813
814 - (void)showOpticalMediaView: theView withIcon:(NSImage *)icon
815 {
816     NSRect o_view_rect;
817     o_view_rect = [theView frame];
818     [theView setFrame: NSMakeRect( 233, 0, o_view_rect.size.width, o_view_rect.size.height)];
819     [theView setAutoresizesSubviews: YES];
820     if (o_currentOpticalMediaView)
821     {
822         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaView with: theView];
823         [o_currentOpticalMediaView release];
824     }
825     else
826         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: theView];
827     o_currentOpticalMediaView = theView;
828     [o_currentOpticalMediaView retain];
829
830     NSImageView *imageView;
831     imageView = [[NSImageView alloc] init];
832     [imageView setFrame: NSMakeRect( 53, 61, 128, 128 )];
833     [icon setSize: NSMakeSize(128,128)];
834     [imageView setImage: icon];
835     if (o_currentOpticalMediaIconView)
836     {
837         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaIconView with: imageView];
838         [o_currentOpticalMediaIconView release];
839     }
840     else
841          [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: imageView];
842     o_currentOpticalMediaIconView = imageView;
843     [o_currentOpticalMediaIconView retain];
844     [o_currentOpticalMediaView setNeedsDisplay: YES];
845     [o_currentOpticalMediaIconView setNeedsDisplay: YES];
846     [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] setNeedsDisplay: YES];
847     [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] displayIfNeeded];
848 }
849
850 - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
851 {
852     OSStatus err;
853     FSRef ref;
854     FSVolumeRefNum actualVolume;
855     err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
856
857     // get a FSVolumeRefNum from mountPath
858     if ( noErr == err ) {
859         FSCatalogInfo   catalogInfo;
860         err = FSGetCatalogInfo ( &ref,
861                                 kFSCatInfoVolume,
862                                 &catalogInfo,
863                                 NULL,
864                                 NULL,
865                                 NULL
866                                 );
867         if ( noErr == err )
868             actualVolume = catalogInfo.volume;
869         else
870             return @"";
871     }
872     else
873         return @"";
874
875     GetVolParmsInfoBuffer volumeParms;
876     err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
877     if ( noErr == err )
878     {
879         NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
880         return [NSString stringWithFormat:@"/dev/r%@", bsdName];
881     }
882
883     return @"";
884 }
885
886 - (char *)getVolumeTypeFromMountPath:(NSString *)mountPath
887 {
888     OSStatus err;
889     FSRef ref;
890     FSVolumeRefNum actualVolume;
891     err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
892
893     // get a FSVolumeRefNum from mountPath
894     if ( noErr == err ) {
895         FSCatalogInfo   catalogInfo;
896         err = FSGetCatalogInfo ( &ref,
897                                 kFSCatInfoVolume,
898                                 &catalogInfo,
899                                 NULL,
900                                 NULL,
901                                 NULL
902                                 );
903         if ( noErr == err )
904             actualVolume = catalogInfo.volume;
905         else
906             return NULL;
907     }
908     else
909         return NULL;
910
911     GetVolParmsInfoBuffer volumeParms;
912     err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
913
914     CFMutableDictionaryRef matchingDict;
915     io_service_t service;
916
917     if (!volumeParms.vMDeviceID)
918         return NULL;
919
920     matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
921     service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
922
923     char *returnValue;
924     if (IO_OBJECT_NULL != service) {
925         if (IOObjectConformsTo(service, kIOCDMediaClass)) {
926             returnValue = kVLCMediaAudioCD;
927         }
928         else if(IOObjectConformsTo(service, kIODVDMediaClass))
929             returnValue = kVLCMediaDVD;
930         else if(IOObjectConformsTo(service, kIOBDMediaClass))
931             returnValue = kVLCMediaBD;
932         else
933         {
934             if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
935                 returnValue = kVLCMediaVideoTSFolder;
936             else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
937                 returnValue = kVLCMediaBDMVFolder;
938             else
939             {
940                 // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
941                 NSFileManager * fm = [[NSFileManager alloc] init];
942
943                 NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
944                 for (int i = 0; i < [dirContents count]; i++)
945                 {
946                     NSString *currentFile = [dirContents objectAtIndex:i];
947                     NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
948
949                     BOOL isDir;
950                     if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
951                     {
952                         if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame)
953                         {
954                             returnValue = kVLCMediaSVCD;
955                             break;
956                         }
957                         if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame)
958                         {
959                             returnValue = kVLCMediaVCD;
960                             break;
961                         }
962                         if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame)
963                         {
964                             returnValue = kVLCMediaBDMVFolder;
965                             break;
966                         }
967                         if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame)
968                         {
969                             returnValue = kVLCMediaVideoTSFolder;
970                             break;
971                         }
972                     }
973                 }
974
975                 [fm release];
976
977                 if(!returnValue)
978                     returnValue = kVLCMediaVideoTSFolder;
979             }
980         }
981
982         IOObjectRelease(service);
983     }
984     return returnValue;
985 }
986
987 - (void)showOpticalAtPath: (NSString *)o_opticalDevicePath
988 {
989     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
990
991     char *diskType = [self getVolumeTypeFromMountPath:o_opticalDevicePath];
992
993     if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder)
994     {
995         [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_opticalDevicePath]];
996         [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
997         NSString *pathToOpen;
998         if (diskType == kVLCMediaVideoTSFolder)
999             pathToOpen = o_opticalDevicePath;
1000         else
1001             pathToOpen = [self getBSDNodeFromMountPath: o_opticalDevicePath];
1002         if (!b_nodvdmenus) {
1003             [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1004             [self showOpticalMediaView: o_disc_dvd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1005         } else {
1006             [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1007             [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1008         }
1009     }
1010     else if (diskType == kVLCMediaAudioCD)
1011     {
1012         [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1013         [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_opticalDevicePath error:NULL] count] - 1]]; // minus .TOC.plist
1014         [self showOpticalMediaView: o_disc_audiocd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1015         [self setMRL: [NSString stringWithFormat: @"cdda://%@", [self getBSDNodeFromMountPath: o_opticalDevicePath]]];
1016     }
1017     else if (diskType == kVLCMediaVCD)
1018     {
1019         [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1020         [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1021         [self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1022     }
1023     else if (diskType == kVLCMediaSVCD)
1024     {
1025         [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1026         [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1027         [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1028     }
1029     else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
1030     {
1031         [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1032         [self showOpticalMediaView: o_disc_bd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1033         [self setMRL: [NSString stringWithFormat: @"bluray://%@", o_opticalDevicePath]];
1034     }
1035     else
1036     {
1037         msg_Warn( VLCIntf, "unknown disk type, no idea what to display" );
1038         [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
1039     }
1040
1041     [o_pool release];
1042 }
1043
1044 - (void)showSelectedOpticalDisc
1045 {
1046     NSString *o_opticalDevicePath = [o_opticalDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];
1047     [NSThread detachNewThreadSelector:@selector(showOpticalAtPath:) toTarget:self withObject:o_opticalDevicePath];
1048 }
1049
1050 - (void)scanOpticalMedia:(NSNotification *)o_notification
1051 {
1052     [o_opticalDevices removeAllObjects];
1053     [o_disc_selector_pop removeAllItems];
1054     [o_opticalDevices addObjectsFromArray: [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
1055     [o_opticalDevices addObjectsFromArray: o_specialMediaFolders];
1056     if ([o_opticalDevices count] > 0) {
1057         NSUInteger deviceCount = [o_opticalDevices count];
1058         for (NSUInteger i = 0; i < deviceCount ; i++)
1059             [o_disc_selector_pop addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: i]]];
1060
1061         if ([o_disc_selector_pop numberOfItems] <= 1)
1062             [o_disc_selector_pop setHidden: YES];
1063         else
1064             [o_disc_selector_pop setHidden: NO];
1065
1066         // select newly added media folder
1067         if (o_notification && [[o_notification name] isEqualToString:@"VLCNewMediaFolderNotification"])
1068             [o_disc_selector_pop selectItemAtIndex: [[o_disc_selector_pop itemArray] count] - 1];
1069
1070         [self showSelectedOpticalDisc];
1071     }
1072     else
1073     {
1074         msg_Dbg( VLCIntf, "no optical media found" );
1075         [o_disc_selector_pop setHidden: YES];
1076         [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed: @"NSApplicationIcon"]];
1077     }
1078 }
1079
1080 - (IBAction)discSelectorChanged:(id)sender
1081 {
1082     [self showSelectedOpticalDisc];
1083 }
1084
1085 - (IBAction)openSpecialMediaFolder:(id)sender
1086 {
1087     /* this is currently for VIDEO_TS and BDMV folders */
1088     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1089
1090     [o_open_panel setAllowsMultipleSelection: NO];
1091     [o_open_panel setCanChooseFiles: NO];
1092     [o_open_panel setCanChooseDirectories: YES];
1093     [o_open_panel setTitle: [sender title]];
1094     [o_open_panel setPrompt: _NS("Open")];
1095
1096     if ([o_open_panel runModal] == NSOKButton)
1097     {
1098         NSString *o_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1099         if ([o_path length] > 0 )
1100         {
1101             [o_specialMediaFolders addObject: o_path];
1102             [self scanOpticalMedia: [NSNotification notificationWithName:@"VLCNewMediaFolderNotification" object:nil]];
1103         }
1104     }
1105 }
1106
1107 - (IBAction)dvdreadOptionChanged:(id)sender
1108 {
1109     NSString *o_device_path = [o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]];
1110     char *diskType = [self getVolumeTypeFromMountPath:o_device_path];
1111
1112     NSString *pathToOpen;
1113     if (diskType == kVLCMediaVideoTSFolder)
1114         pathToOpen = o_device_path;
1115     else
1116         pathToOpen = [self getBSDNodeFromMountPath: o_device_path];
1117
1118     if (sender == o_disc_dvdwomenus_enablemenus_btn) {
1119         b_nodvdmenus = NO;
1120         [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1121         [self showOpticalMediaView: o_disc_dvd_view withIcon: [o_currentOpticalMediaIconView image]];
1122         return;
1123     }
1124     if (sender == o_disc_dvd_disablemenus_btn) {
1125         b_nodvdmenus = YES;
1126         [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [o_currentOpticalMediaIconView image]];
1127     }
1128
1129     if (sender == o_disc_dvdwomenus_title)
1130         [o_disc_dvdwomenus_title_stp setIntValue: [o_disc_dvdwomenus_title intValue]];
1131     if (sender == o_disc_dvdwomenus_title_stp)
1132         [o_disc_dvdwomenus_title setIntValue: [o_disc_dvdwomenus_title_stp intValue]];
1133     if (sender == o_disc_dvdwomenus_chapter)
1134         [o_disc_dvdwomenus_chapter_stp setIntValue: [o_disc_dvdwomenus_chapter intValue]];
1135     if (sender == o_disc_dvdwomenus_chapter_stp)
1136         [o_disc_dvdwomenus_chapter setIntValue: [o_disc_dvdwomenus_chapter_stp intValue]];
1137
1138     [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1139 }
1140
1141 - (IBAction)vcdOptionChanged:(id)sender
1142 {
1143     if (sender == o_disc_vcd_title)
1144         [o_disc_vcd_title_stp setIntValue: [o_disc_vcd_title intValue]];
1145     if (sender == o_disc_vcd_title_stp)
1146         [o_disc_vcd_title setIntValue: [o_disc_vcd_title_stp intValue]];
1147     if (sender == o_disc_vcd_chapter)
1148         [o_disc_vcd_chapter_stp setIntValue: [o_disc_vcd_chapter intValue]];
1149     if (sender == o_disc_vcd_chapter_stp)
1150         [o_disc_vcd_chapter setIntValue: [o_disc_vcd_chapter_stp intValue]];
1151
1152     [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]]], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1153 }
1154
1155 #pragma mark -
1156 #pragma mark Network Panel
1157
1158 - (void)textFieldWasClicked:(NSNotification *)o_notification
1159 {
1160     if( [o_notification object] == o_net_udp_port )
1161         [o_net_mode selectCellAtRow: 0 column: 0];
1162     else if( [o_notification object] == o_net_udpm_addr ||
1163              [o_notification object] == o_net_udpm_port )
1164         [o_net_mode selectCellAtRow: 1 column: 0];
1165     else
1166         [o_net_mode selectCellAtRow: 2 column: 0];
1167
1168     [self openNetInfoChanged: nil];
1169 }
1170
1171 - (IBAction)openNetModeChanged:(id)sender
1172 {
1173     if( sender == o_net_mode )
1174     {
1175         if( [[sender selectedCell] tag] == 0 )
1176             [o_panel makeFirstResponder: o_net_udp_port];
1177         else if ( [[sender selectedCell] tag] == 1 )
1178             [o_panel makeFirstResponder: o_net_udpm_addr];
1179         else
1180             msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
1181     }
1182
1183     [self openNetInfoChanged: nil];
1184 }
1185
1186 - (IBAction)openNetStepperChanged:(id)sender
1187 {
1188     int i_tag = [sender tag];
1189
1190     if( i_tag == 0 )
1191     {
1192         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
1193         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1194                                                             object: o_net_udp_port];
1195         [o_panel makeFirstResponder: o_net_udp_port];
1196     }
1197     else if( i_tag == 1 )
1198     {
1199         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
1200         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1201                                                             object: o_net_udpm_port];
1202         [o_panel makeFirstResponder: o_net_udpm_port];
1203     }
1204
1205     [self openNetInfoChanged: nil];
1206 }
1207
1208 - (void)openNetInfoChanged:(NSNotification *)o_notification
1209 {
1210     NSString *o_mrl_string = [NSString string];
1211
1212     if( [o_net_udp_panel isVisible] )
1213     {
1214         NSString *o_mode;
1215         o_mode = [[o_net_mode selectedCell] title];
1216
1217         if( [o_mode isEqualToString: _NS("Unicast")] )
1218         {
1219             int i_port = [o_net_udp_port intValue];
1220
1221             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1222                 o_mrl_string = @"udp://";
1223             else
1224                 o_mrl_string = @"rtp://";
1225
1226             if( i_port != config_GetInt( p_intf, "server-port" ) )
1227             {
1228                 o_mrl_string =
1229                     [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1230             }
1231         }
1232         else if( [o_mode isEqualToString: _NS("Multicast")] )
1233         {
1234             NSString *o_addr = [o_net_udpm_addr stringValue];
1235             int i_port = [o_net_udpm_port intValue];
1236
1237             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1238                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1239             else
1240                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1241
1242             if( i_port != config_GetInt( p_intf, "server-port" ) )
1243             {
1244                 o_mrl_string =
1245                     [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1246             }
1247         }
1248     }
1249     else
1250     {
1251         o_mrl_string = [o_net_http_url stringValue];
1252     }
1253     [self setMRL: o_mrl_string];
1254 }
1255
1256 - (IBAction)openNetUDPButtonAction:(id)sender
1257 {
1258     if( sender == o_net_openUDP_btn )
1259     {
1260         [NSApp beginSheet: o_net_udp_panel
1261            modalForWindow: o_panel
1262             modalDelegate: self
1263            didEndSelector: NULL
1264               contextInfo: nil];
1265         [self openNetInfoChanged: nil];
1266     }
1267     else if( sender == o_net_udp_cancel_btn )
1268     {
1269         [o_net_udp_panel orderOut: sender];
1270         [NSApp endSheet: o_net_udp_panel];
1271     }
1272     else if( sender == o_net_udp_ok_btn )
1273     {
1274         NSString *o_mrl_string = [NSString string];
1275         if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
1276         {
1277             int i_port = [o_net_udp_port intValue];
1278
1279             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1280                 o_mrl_string = @"udp://";
1281             else
1282                 o_mrl_string = @"rtp://";
1283
1284             if( i_port != config_GetInt( p_intf, "server-port" ) )
1285             {
1286                 o_mrl_string =
1287                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1288             }
1289         }
1290         else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
1291         {
1292             NSString *o_addr = [o_net_udpm_addr stringValue];
1293             int i_port = [o_net_udpm_port intValue];
1294
1295             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1296                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1297             else
1298                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1299
1300             if( i_port != config_GetInt( p_intf, "server-port" ) )
1301             {
1302                 o_mrl_string =
1303                 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1304             }
1305         }
1306         [self setMRL: o_mrl_string];
1307         [o_net_http_url setStringValue: o_mrl_string];
1308         [o_net_udp_panel orderOut: sender];
1309         [NSApp endSheet: o_net_udp_panel];
1310     }
1311 }
1312
1313 #pragma mark -
1314 #pragma mark Capture Panel
1315
1316 - (void)showCaptureView: theView
1317 {
1318     NSRect o_view_rect;
1319     o_view_rect = [theView frame];
1320     [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
1321     [theView setAutoresizesSubviews: YES];
1322     if (o_currentCaptureView)
1323     {
1324         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] replaceSubview: o_currentCaptureView with: theView];
1325         [o_currentCaptureView release];
1326     }
1327     else
1328     {
1329         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] addSubview: theView];
1330     }
1331     o_currentCaptureView = theView;
1332     [o_currentCaptureView retain];
1333 }
1334
1335 - (IBAction)openCaptureModeChanged:(id)sender
1336 {
1337     if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1338     {
1339         if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1340         {
1341             if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1342             {
1343                 [self showCaptureView: o_eyetv_running_view];
1344                 [self setupChannelInfo];
1345             }
1346             else
1347             {
1348                 setEyeTVUnconnected;
1349             }
1350         }
1351         else
1352             [self showCaptureView: o_eyetv_notLaunched_view];
1353         [self setMRL: @""];
1354     }
1355     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1356     {
1357         [self showCaptureView: o_screen_view];
1358         [self setMRL: @"screen://"];
1359         [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
1360         [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
1361         [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
1362         [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
1363         [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
1364         [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
1365
1366         int screen_index = config_GetInt( p_intf, "screen-index" );
1367         int display_id = config_GetInt( p_intf, "screen-display-id" );
1368         unsigned int i, displayCount = 0;
1369         CGLError returnedError;
1370         struct display_info_t *item;
1371         NSValue *v;
1372
1373         returnedError = CGGetOnlineDisplayList( 0, NULL, &displayCount );
1374         if( !returnedError )
1375         {
1376             CGDirectDisplayID *ids;
1377             ids = ( CGDirectDisplayID * )malloc( displayCount * sizeof( CGDirectDisplayID ) );
1378             returnedError = CGGetOnlineDisplayList( displayCount, ids, &displayCount );
1379             if( !returnedError )
1380             {
1381                 for( i = 0; i < [o_displayInfos count]; i ++ )
1382                 {
1383                     v = [o_displayInfos objectAtIndex:i];
1384                     free( [v pointerValue] );
1385                 }
1386                 [o_displayInfos removeAllObjects];
1387                 [o_screen_screen_pop removeAllItems];
1388                 for( i = 0; i < displayCount; i ++ )
1389                 {
1390                     item = ( struct display_info_t * )malloc( sizeof( struct display_info_t ) );
1391                     item->id = ids[i];
1392                     item->rect = CGDisplayBounds( item->id );
1393                     [o_screen_screen_pop addItemWithTitle: [NSString stringWithFormat:@"Screen %d (%dx%d)", i + 1, (int)item->rect.size.width, (int)item->rect.size.height]];
1394                     v = [NSValue valueWithPointer:item];
1395                     [o_displayInfos addObject:v];
1396                     if( i == 0 || display_id == item->id || screen_index - 1 == i )
1397                     {
1398                         [o_screen_screen_pop selectItemAtIndex: i];
1399                         [o_screen_left_stp setMaxValue: item->rect.size.width];
1400                         [o_screen_top_stp setMaxValue: item->rect.size.height];
1401                         [o_screen_width_stp setMaxValue: item->rect.size.width];
1402                         [o_screen_height_stp setMaxValue: item->rect.size.height];
1403                     }
1404                 }
1405             }
1406             free( ids );
1407         }
1408     }
1409     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")] )
1410     {
1411         [self showCaptureView: o_qtk_view];
1412         if ([o_capture_width_fld intValue] <= 0)
1413             [self qtkChanged:nil];
1414
1415         [self qtkAudioChanged:nil];
1416
1417         [self setMRL: @""];
1418
1419         if ([o_qtk_video_ckb state] && qtk_currdevice_uid)
1420             [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
1421         else if([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
1422             [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
1423     }
1424 }
1425
1426 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1427 {
1428     [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1429     if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1430         [o_screen_fps_fld setFloatValue: 1.0];
1431     [self setMRL: @"screen://"];
1432 }
1433
1434 - (IBAction)eyetvSwitchChannel:(id)sender
1435 {
1436     if( sender == o_eyetv_nextProgram_btn )
1437     {
1438         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1439         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1440         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1441     }
1442     else if( sender == o_eyetv_previousProgram_btn )
1443     {
1444         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1445         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1446         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1447     }
1448     else if( sender == o_eyetv_channels_pop )
1449     {
1450         int chanNum = [[sender selectedItem] tag];
1451         [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1452         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1453     }
1454     else
1455         msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1456 }
1457
1458 - (IBAction)eyetvLaunch:(id)sender
1459 {
1460     [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1461 }
1462
1463 - (IBAction)eyetvGetPlugin:(id)sender
1464 {
1465     [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1466 }
1467
1468 - (void)eyetvChanged:(NSNotification *)o_notification
1469 {
1470     if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1471     {
1472         msg_Dbg( VLCIntf, "eyetv device was added" );
1473         [self showCaptureView: o_eyetv_running_view];
1474         [self setupChannelInfo];
1475     }
1476     else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1477     {
1478         /* leave the channel selection like that,
1479          * switch to our "no device" tab */
1480         msg_Dbg( VLCIntf, "eyetv device was removed" );
1481         setEyeTVUnconnected;
1482     }
1483     else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1484     {
1485         /* switch to the "launch eyetv" tab */
1486         msg_Dbg( VLCIntf, "eyetv was terminated" );
1487         [self showCaptureView: o_eyetv_notLaunched_view];
1488     }
1489     else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1490     {
1491         /* we got no device yet */
1492         msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1493         setEyeTVUnconnected;
1494     }
1495 }
1496
1497 /* little helper method, since this code needs to be run by multiple objects */
1498 - (void)setupChannelInfo
1499 {
1500     /* set up channel selection */
1501     [o_eyetv_channels_pop removeAllItems];
1502     [o_eyetv_chn_bgbar setHidden: NO];
1503     [o_eyetv_chn_bgbar animate: self];
1504     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1505     [o_eyetv_chn_status_txt setHidden: NO];
1506
1507     /* retrieve info */
1508     NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1509     int x = -2;
1510     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1511                                                action: nil
1512                                         keyEquivalent: @""] setTag:x++];
1513     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1514                                                action: nil
1515                                         keyEquivalent: @""] setTag:x++];
1516     if( channels )
1517     {
1518         NSString *channel;
1519         [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1520         while( channel = [channels nextObject] )
1521         {
1522             /* we have to add items this way, because we accept duplicates
1523              * additionally, we save a bit of time */
1524             [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1525                                                    action: nil
1526                                             keyEquivalent: @""] setTag:++x];
1527         }
1528         /* make Tuner the default */
1529         [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1530     }
1531
1532     /* clean up GUI */
1533     [o_eyetv_chn_bgbar setHidden: YES];
1534     [o_eyetv_chn_status_txt setHidden: YES];
1535 }
1536
1537 #pragma mark -
1538 #pragma mark Subtitle Settings
1539
1540 - (IBAction)subsChanged:(id)sender
1541 {
1542     if ([o_file_sub_ckbox state] == NSOnState)
1543     {
1544         [o_file_sub_btn_settings setEnabled:YES];
1545         if (o_sub_path) {
1546             [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1547             [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1548         }
1549     }
1550     else
1551     {
1552         [o_file_sub_btn_settings setEnabled:NO];
1553         [o_file_subtitles_filename_lbl setStringValue: @""];
1554         [o_file_subtitles_icon_well setImage: NULL];
1555     }
1556 }
1557
1558 - (IBAction)subSettings:(id)sender
1559 {
1560     [NSApp beginSheet: o_file_sub_sheet
1561         modalForWindow: [sender window]
1562         modalDelegate: self
1563         didEndSelector: NULL
1564         contextInfo: nil];
1565 }
1566
1567 - (IBAction)subCloseSheet:(id)sender
1568 {
1569     [self subsChanged: nil];
1570     [o_file_sub_sheet orderOut:sender];
1571     [NSApp endSheet: o_file_sub_sheet];
1572 }
1573
1574 - (IBAction)subFileBrowse:(id)sender
1575 {
1576     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1577
1578     [o_open_panel setAllowsMultipleSelection: NO];
1579     [o_open_panel setTitle: _NS("Open File")];
1580     [o_open_panel setPrompt: _NS("Open")];
1581
1582     if( [o_open_panel runModal] == NSOKButton )
1583     {
1584         o_sub_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1585         [o_sub_path retain];
1586         [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1587         [o_file_sub_path_fld setStringValue: [o_file_subtitles_filename_lbl stringValue]];
1588         [o_file_sub_path_lbl setHidden: YES];
1589         [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1590         [o_file_sub_icon_view setImage: [o_file_subtitles_icon_well image]];
1591     }
1592     else
1593     {
1594         [o_file_sub_path_lbl setHidden: NO];
1595         [o_file_sub_path_fld setStringValue:@""];
1596         [o_file_subtitles_filename_lbl setStringValue:@""];
1597         [o_file_subtitles_icon_well setImage: nil];
1598         [o_file_sub_icon_view setImage: nil];
1599     }
1600 }
1601
1602 - (IBAction)subOverride:(id)sender
1603 {
1604     BOOL b_state = [o_file_sub_override state];
1605     [o_file_sub_delay setEnabled: b_state];
1606     [o_file_sub_delay_stp setEnabled: b_state];
1607     [o_file_sub_fps setEnabled: b_state];
1608     [o_file_sub_fps_stp setEnabled: b_state];
1609 }
1610
1611 - (IBAction)subDelayStepperChanged:(id)sender
1612 {
1613     [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1614 }
1615
1616 - (IBAction)subFpsStepperChanged:(id)sender;
1617 {
1618     [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1619 }
1620
1621 #pragma mark -
1622 #pragma mark Miscellaneous
1623
1624 - (IBAction)panelCancel:(id)sender
1625 {
1626     [NSApp stopModalWithCode: 0];
1627 }
1628
1629 - (IBAction)panelOk:(id)sender
1630 {
1631     if( [[self MRL] length] )
1632         [NSApp stopModalWithCode: 1];
1633     else
1634         NSBeep();
1635 }
1636
1637 - (NSArray *)qtkvideoDevices
1638 {
1639     if ( !qtkvideoDevices )
1640         [self qtkrefreshVideoDevices];
1641     return qtkvideoDevices;
1642 }
1643
1644 - (void)qtkrefreshVideoDevices
1645 {
1646     [qtkvideoDevices release];
1647     qtkvideoDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1648 }
1649
1650 - (NSArray *)qtkaudioDevices
1651 {
1652     if ( !qtkaudioDevices )
1653         [self qtkrefreshAudioDevices];
1654     return qtkaudioDevices;
1655 }
1656
1657 - (void)qtkrefreshAudioDevices
1658 {
1659     [qtkaudioDevices release];
1660     qtkaudioDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeSound] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1661 }
1662
1663 @end
1664
1665 @implementation VLCOpenTextField
1666
1667 - (void)mouseDown:(NSEvent *)theEvent
1668 {
1669     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1670                                                         object: self];
1671     [super mouseDown: theEvent];
1672 }
1673
1674 @end