]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
typo: No newline before period
[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
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];
174
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")];
187
188     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
189     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
190
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" )];
193
194     [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
195
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:")];
220
221     [self qtkvideoDevices];
222     [o_qtk_device_pop removeAllItems];
223     msg_Dbg( VLCIntf, "Found %lu video capture devices", [qtkvideoDevices count] );
224
225     if([qtkvideoDevices count] >= 1)
226     {
227         if (!qtk_currdevice_uid) {
228             qtk_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo] uniqueID]
229                                                                 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
230         }
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];
238             }
239         }
240     }
241     else
242     {
243         [o_qtk_device_pop addItemWithTitle: _NS("None")];
244         [qtk_currdevice_uid release];
245     }
246
247     [self qtkaudioDevices];
248     [o_qtkaudio_device_pop removeAllItems];
249     msg_Dbg( VLCIntf, "Found %lu audio capture devices", [qtkaudioDevices count] );
250
251     if([qtkaudioDevices count] >= 1)
252     {
253         if (!qtkaudio_currdevice_uid) {
254             qtkaudio_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound] uniqueID]
255                                   stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
256         }
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];
264             }
265         }
266     }
267     else
268     {
269         [o_qtkaudio_device_pop addItemWithTitle: _NS("None")];
270         [qtkaudio_currdevice_uid release];
271     }
272
273     [self setSubPanel];
274
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];
291
292     [[NSDistributedNotificationCenter defaultCenter] addObserver: self
293                                                         selector: @selector(eyetvChanged:)
294                                                             name: NULL
295                                                           object: @"VLCEyeTVSupport"
296                                               suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
297
298     [[NSNotificationCenter defaultCenter] addObserver: self
299                                              selector: @selector(screenFPSfieldChanged:)
300                                                  name: NSControlTextDidChangeNotification
301                                                object: o_screen_fps_fld];
302
303     /* register clicks on text fields */
304     [[NSNotificationCenter defaultCenter] addObserver: self
305                                              selector: @selector(textFieldWasClicked:)
306                                                  name: @"VLCOpenTextFieldWasClicked"
307                                                object: nil];
308
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];
314
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];
320
321     [self setMRL: @""];
322 }
323
324 - (void)setMRL:(NSString *)newMRL
325 {
326     [o_mrl release];
327     o_mrl = newMRL;
328     [o_mrl retain];
329     [o_mrl_fld setStringValue: newMRL];
330     if ([o_mrl length] > 0)
331         [o_btn_ok setEnabled: YES];
332     else
333         [o_btn_ok setEnabled: NO];
334 }
335
336 - (NSString *)MRL
337 {
338     return o_mrl;
339 }
340
341 - (void)setSubPanel
342 {
343     int i_index;
344     module_config_t * p_item;
345
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")];
366
367     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
368
369     if( p_item )
370     {
371         for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
372              i_index++ )
373         {
374             [o_file_sub_encoding_pop addItemWithTitle:
375                 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
376         }
377         [o_file_sub_encoding_pop selectItemWithTitle:
378                 [NSString stringWithUTF8String: p_item->value.psz]];
379     }
380
381     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
382
383     if ( p_item )
384     {
385         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
386         {
387             [o_file_sub_align_pop addItemWithTitle:
388              _NS(p_item->ppsz_list_text[i_index])];
389         }
390         [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
391     }
392
393     p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
394
395     if ( p_item )
396     {
397         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
398         {
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] )
401             {
402                 [o_file_sub_size_pop selectItemAtIndex: i_index];
403             }
404         }
405     }
406 }
407
408 - (void)openTarget:(int)i_type
409 {
410     int i_result;
411
412     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
413
414     [o_tabview selectTabViewItemAtIndex: i_type];
415     [o_file_sub_ckbox setState: NSOffState];
416
417     i_result = [NSApp runModalForWindow: o_panel];
418     [o_panel close];
419
420     if( i_result )
421     {
422         NSMutableDictionary *o_dic;
423         NSMutableArray *o_options = [NSMutableArray array];
424
425         o_dic = [NSMutableDictionary dictionaryWithObject: [self MRL] forKey: @"ITEM_URL"];
426         if( [o_file_sub_ckbox state] == NSOnState )
427         {
428             module_config_t * p_item;
429
430             [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", o_sub_path]];
431             if( [o_file_sub_override state] == NSOnState )
432             {
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]]];
435             }
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]]];
442
443             p_item = config_FindConfig( VLC_OBJECT(p_intf),
444                                             "freetype-rel-fontsize" );
445
446             if ( p_item )
447             {
448                 [o_options addObject: [NSString stringWithFormat:
449                     @"freetype-rel-fontsize=%i",
450                     p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
451             }
452         }
453         if( [o_output_ckbox state] == NSOnState )
454         {
455             NSUInteger count = [[o_sout_options mrl] count];
456             for (NSUInteger i = 0 ; i < count ; i++)
457             {
458                 [o_options addObject: [NSString stringWithString: [[(VLCOutput *)o_sout_options mrl] objectAtIndex: i]]];
459             }
460         }
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")] )
464         {
465             if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
466             {
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];
470
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"];
479                 else
480                     [o_options addObject: @"no-screen-follow-mouse"];
481             }
482             else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Video Device")] )
483             {
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]]];
486             }
487         }
488
489         /* apply the options to our item(s) */
490         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
491         if( b_autoplay )
492             [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
493         else
494             [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
495     }
496 }
497
498 - (IBAction)screenChanged:(id)sender
499 {
500     int selected_index = [o_screen_screen_pop indexOfSelectedItem];
501     if( selected_index >= [o_displayInfos count] ) return;
502
503     NSValue *v = [o_displayInfos objectAtIndex:selected_index];
504     struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
505
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];
510 }
511
512 - (IBAction)qtkChanged:(id)sender
513 {
514     NSInteger i_selectedDevice = [o_qtk_device_pop indexOfSelectedItem];
515     if( [qtkvideoDevices count] >= 1 )
516     {
517         NSValue *sizes = [[[[qtkvideoDevices objectAtIndex:i_selectedDevice] formatDescriptions] objectAtIndex: 0] attributeForKey: QTFormatDescriptionVideoEncodedPixelsSizeAttribute];
518
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]];
525     }
526 }
527
528 - (IBAction)qtkAudioChanged:(id)sender
529 {
530     NSInteger i_selectedDevice = [o_qtkaudio_device_pop indexOfSelectedItem];
531     if( [qtkaudioDevices count] >= 1 )
532     {
533         qtkaudio_currdevice_uid = [[(QTCaptureDevice *)[qtkaudioDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
534         [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
535     }
536 }
537
538 #pragma mark -
539 #pragma mark Main Actions
540
541 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
542 {
543     NSString *o_label = [o_tvi label];
544
545     if( [o_label isEqualToString: _NS("File")] )
546     {
547         [self openFilePathChanged: nil];
548     }
549     else if( [o_label isEqualToString: _NS("Disc")] )
550     {
551         [self scanOpticalMedia: nil];
552     }
553     else if( [o_label isEqualToString: _NS("Network")] )
554     {
555         [self openNetInfoChanged: nil];
556     }
557     else if( [o_label isEqualToString: _NS("Capture")] )
558     {
559         [self openCaptureModeChanged: nil];
560     }
561 }
562
563 - (IBAction)expandMRLfieldAction:(id)sender
564 {
565     NSRect o_win_rect, o_view_rect;
566     o_win_rect = [o_panel frame];
567     o_view_rect = [o_mrl_view frame];
568
569     if( [o_mrl_btn state] == NSOffState )
570     {
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;
574
575         /* remove the MRL view */
576         [o_mrl_view removeFromSuperview];
577     } else {
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];
585
586         /* enlarge panel size for MRL view */
587         o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
588     }
589
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];
594 }
595
596 - (void)openFileGeneric
597 {
598     [self openFilePathChanged: nil];
599     [self openTarget: 0];
600 }
601
602 - (void)openDisc
603 {
604     [o_specialMediaFolders removeAllObjects];
605     [o_opticalDevices removeAllObjects];
606     [self scanOpticalMedia: nil];
607     [self openTarget: 1];
608 }
609
610 - (void)openNet
611 {
612     [self openNetInfoChanged: nil];
613     [self openTarget: 2];
614 }
615
616 - (void)openCapture
617 {
618     [self openCaptureModeChanged: nil];
619     [self openTarget: 3];
620 }
621
622 - (void)openFile
623 {
624     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
625     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
626
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")];
631
632     if( [o_open_panel runModal] == NSOKButton )
633     {
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++ )
639         {
640             [o_values addObject: [[o_urls objectAtIndex: i] path]];
641         }
642         [o_values sortUsingSelector:@selector(caseInsensitiveCompare:)];
643
644         for( NSUInteger i = 0; i < count; i++ )
645         {
646             NSDictionary *o_dic;
647             char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], "file");
648             if( !psz_uri )
649                 continue;
650
651             o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
652
653             free( psz_uri );
654
655             [o_array addObject: o_dic];
656         }
657         if( b_autoplay )
658             [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
659         else
660             [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
661     }
662 }
663
664 #pragma mark -
665 #pragma mark File Panel
666
667 - (void)openFilePathChanged:(NSNotification *)o_notification
668 {
669     if ( o_file_path && [o_file_path length] > 0 )
670     {
671         bool b_stream = [o_file_stream state];
672         BOOL b_dir = NO;
673
674         [[NSFileManager defaultManager] fileExistsAtPath:o_file_path isDirectory:&b_dir];
675
676         char *psz_uri = make_URI([o_file_path UTF8String], "file");
677         if( !psz_uri ) return;
678
679         NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
680         NSRange offile = [o_mrl_string rangeOfString:@"file"];
681         free( psz_uri );
682
683         if( b_dir )
684             [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
685         else if( b_stream )
686             [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
687
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];
694     }
695     else
696     {
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"]];
701         [self setMRL: @""];
702     }
703 }
704
705 - (IBAction)openFileBrowse:(id)sender
706 {
707     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
708
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")];
713
714     [o_open_panel beginSheetForDirectory:nil
715         file:nil
716         types:nil
717         modalForWindow:[sender window]
718         modalDelegate: self
719         didEndSelector: @selector(pathChosenInPanel:
720                         withReturn:
721                         contextInfo:)
722         contextInfo: nil];
723 }
724
725 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void  *)contextInfo
726 {
727     if (returnCode == NSFileHandlingPanelOKButton)
728     {
729         if( o_file_path )
730             [o_file_path release];
731         o_file_path = [[[sheet URLs] objectAtIndex: 0] path];
732         [o_file_path retain];
733         [self openFilePathChanged: nil];
734     }
735 }
736
737 - (IBAction)openFileStreamChanged:(id)sender
738 {
739     [self openFilePathChanged: nil];
740 }
741
742 - (IBAction)inputSlaveAction:(id)sender
743 {
744     if( sender == o_file_slave_ckbox )
745         [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
746     else
747     {
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 )
753         {
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];
758         }
759     }
760     if( o_file_slave_path && [o_file_slave_ckbox state] == NSOnState)
761     {
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]];
764     }
765     else
766     {
767         [o_file_slave_filename_lbl setStringValue: @""];
768         [o_file_slave_icon_well setImage: NULL];
769     }
770 }
771
772 #pragma mark -
773 #pragma mark Optical Media Panel
774
775 - (void)showOpticalMediaView: theView withIcon:(NSImage *)icon
776 {
777     NSRect o_view_rect;
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)
782     {
783         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaView with: theView];
784         [o_currentOpticalMediaView release];
785     }
786     else
787         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: theView];
788     o_currentOpticalMediaView = theView;
789     [o_currentOpticalMediaView retain];
790
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)
797     {
798         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaIconView with: imageView];
799         [o_currentOpticalMediaIconView release];
800     }
801     else
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];
809 }
810
811 - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
812 {
813     OSStatus err;
814     FSRef ref;
815     FSVolumeRefNum actualVolume;
816     err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
817
818     // get a FSVolumeRefNum from mountPath
819     if ( noErr == err ) {
820         FSCatalogInfo   catalogInfo;
821         err = FSGetCatalogInfo ( &ref,
822                                 kFSCatInfoVolume,
823                                 &catalogInfo,
824                                 NULL,
825                                 NULL,
826                                 NULL
827                                 );
828         if ( noErr == err ) {
829             actualVolume = catalogInfo.volume;
830         }
831     }
832
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" );
837         return @"";
838     }
839
840     NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
841     return [NSString stringWithFormat:@"/dev/r%@", bsdName];
842 }
843
844 - (char *)getVolumeTypeFromMountPath:(NSString *)mountPath
845 {
846     OSStatus err;
847     FSRef ref;
848     FSVolumeRefNum actualVolume;
849     err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
850
851     // get a FSVolumeRefNum from mountPath
852     if ( noErr == err ) {
853         FSCatalogInfo   catalogInfo;
854         err = FSGetCatalogInfo ( &ref,
855                                 kFSCatInfoVolume,
856                                 &catalogInfo,
857                                 NULL,
858                                 NULL,
859                                 NULL
860                                 );
861         if ( noErr == err ) {
862             actualVolume = catalogInfo.volume;
863         }
864     }
865
866     GetVolParmsInfoBuffer volumeParms;
867     err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
868
869     CFMutableDictionaryRef matchingDict;
870     io_service_t service;
871
872     matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
873     service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
874
875     char *returnValue;
876     if (IO_OBJECT_NULL != service) {
877         if (IOObjectConformsTo(service, kIOCDMediaClass)) {
878             returnValue = kVLCMediaAudioCD;
879         }
880         else if(IOObjectConformsTo(service, kIODVDMediaClass))
881             returnValue = kVLCMediaDVD;
882         else if(IOObjectConformsTo(service, kIOBDMediaClass))
883             returnValue = kVLCMediaBD;
884         else
885         {
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;
890             else
891             {
892                 // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
893                 NSFileManager * fm = [[NSFileManager alloc] init];
894
895                 NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
896                 for (int i = 0; i < [dirContents count]; i++)
897                 {
898                     NSString *currentFile = [dirContents objectAtIndex:i];
899                     NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
900
901                     BOOL isDir;
902                     if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
903                     {                        
904                         if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame)
905                         {
906                             returnValue = kVLCMediaSVCD;
907                             break;
908                         }
909                         if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame)
910                         {
911                             returnValue = kVLCMediaVCD;
912                             break;
913                         }
914                         if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame)
915                         {
916                             returnValue = kVLCMediaBDMVFolder;
917                             break;
918                         }
919                         if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame)
920                         {
921                             returnValue = kVLCMediaVideoTSFolder;
922                             break;
923                         }
924                     }
925                 }
926
927                 [fm release];
928
929                 if(!returnValue)
930                     returnValue = kVLCMediaVideoTSFolder;
931             }
932         }
933
934         IOObjectRelease(service);
935     }
936     return returnValue;
937 }
938
939 - (void)showOpticalAtPath: (NSString *)o_opticalDevicePath
940 {
941     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
942
943     char *diskType = [self getVolumeTypeFromMountPath:o_opticalDevicePath];
944
945     if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder)
946     {
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;
952         else
953             pathToOpen = [self getBSDNodeFromMountPath: o_opticalDevicePath];
954         if (!b_nodvdmenus) {
955             [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
956             [self showOpticalMediaView: o_disc_dvd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
957         } else {
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]];
960         }
961     }
962     else if (diskType == kVLCMediaAudioCD)
963     {
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]]];
968     }
969     else if (diskType == kVLCMediaVCD)
970     {
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]]];
974     }
975     else if (diskType == kVLCMediaSVCD)
976     {
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]]];
980     }
981     else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
982     {
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]];
986     }
987     else
988     {
989         msg_Warn( VLCIntf, "unknown disk type, no idea what to display" );
990         [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
991     }
992
993     [o_pool release];
994 }
995
996 - (void)showSelectedOpticalDisc
997 {
998     NSString *o_opticalDevicePath = [o_opticalDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];
999     [NSThread detachNewThreadSelector:@selector(showOpticalAtPath:) toTarget:self withObject:o_opticalDevicePath];
1000 }
1001
1002 - (void)scanOpticalMedia:(NSNotification *)o_notification
1003 {
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]]];
1012
1013         if ([o_disc_selector_pop numberOfItems] <= 1)
1014             [o_disc_selector_pop setHidden: YES];
1015         else
1016             [o_disc_selector_pop setHidden: NO];
1017
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];
1021
1022         [self showSelectedOpticalDisc];
1023     }
1024     else
1025     {
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"]];
1029     }
1030 }
1031
1032 - (IBAction)discSelectorChanged:(id)sender
1033 {
1034     [self showSelectedOpticalDisc];
1035 }
1036
1037 - (IBAction)openSpecialMediaFolder:(id)sender
1038 {
1039     /* this is currently for VIDEO_TS and BDMV folders */
1040     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1041
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")];
1047
1048     if ([o_open_panel runModal] == NSOKButton)
1049     {
1050         NSString *o_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1051         if ([o_path length] > 0 )
1052         {
1053             [o_specialMediaFolders addObject: o_path];
1054             [self scanOpticalMedia: [NSNotification notificationWithName:@"VLCNewMediaFolderNotification" object:nil]];
1055         }
1056     }
1057 }
1058
1059 - (IBAction)dvdreadOptionChanged:(id)sender
1060 {
1061     NSString *o_device_path = [o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]];
1062     char *diskType = [self getVolumeTypeFromMountPath:o_device_path];
1063
1064     NSString *pathToOpen;
1065     if (diskType == kVLCMediaVideoTSFolder)
1066         pathToOpen = o_device_path;
1067     else
1068         pathToOpen = [self getBSDNodeFromMountPath: o_device_path];
1069
1070     if (sender == o_disc_dvdwomenus_enablemenus_btn) {
1071         b_nodvdmenus = NO;
1072         [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1073         [self showOpticalMediaView: o_disc_dvd_view withIcon: [o_currentOpticalMediaIconView image]];
1074         return;
1075     }
1076     if (sender == o_disc_dvd_disablemenus_btn) {
1077         b_nodvdmenus = YES;
1078         [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [o_currentOpticalMediaIconView image]];
1079     }
1080
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]];
1089
1090     [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1091 }
1092
1093 - (IBAction)vcdOptionChanged:(id)sender
1094 {
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]];
1103
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]]];
1105 }
1106
1107 #pragma mark -
1108 #pragma mark Network Panel
1109
1110 - (void)textFieldWasClicked:(NSNotification *)o_notification
1111 {
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];
1117     else
1118         [o_net_mode selectCellAtRow: 2 column: 0];
1119
1120     [self openNetInfoChanged: nil];
1121 }
1122
1123 - (IBAction)openNetModeChanged:(id)sender
1124 {
1125     if( sender == o_net_mode )
1126     {
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];
1131         else
1132             msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
1133     }
1134
1135     [self openNetInfoChanged: nil];
1136 }
1137
1138 - (IBAction)openNetStepperChanged:(id)sender
1139 {
1140     int i_tag = [sender tag];
1141
1142     if( i_tag == 0 )
1143     {
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];
1148     }
1149     else if( i_tag == 1 )
1150     {
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];
1155     }
1156
1157     [self openNetInfoChanged: nil];
1158 }
1159
1160 - (void)openNetInfoChanged:(NSNotification *)o_notification
1161 {
1162     NSString *o_mrl_string = [NSString string];
1163
1164     if( [o_net_udp_panel isVisible] )
1165     {
1166         NSString *o_mode;
1167         o_mode = [[o_net_mode selectedCell] title];
1168
1169         if( [o_mode isEqualToString: _NS("Unicast")] )
1170         {
1171             int i_port = [o_net_udp_port intValue];
1172
1173             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1174                 o_mrl_string = @"udp://";
1175             else
1176                 o_mrl_string = @"rtp://";
1177
1178             if( i_port != config_GetInt( p_intf, "server-port" ) )
1179             {
1180                 o_mrl_string =
1181                     [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1182             }
1183         }
1184         else if( [o_mode isEqualToString: _NS("Multicast")] )
1185         {
1186             NSString *o_addr = [o_net_udpm_addr stringValue];
1187             int i_port = [o_net_udpm_port intValue];
1188
1189             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1190                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1191             else
1192                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1193
1194             if( i_port != config_GetInt( p_intf, "server-port" ) )
1195             {
1196                 o_mrl_string =
1197                     [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1198             }
1199         }
1200     }
1201     else
1202     {
1203         o_mrl_string = [o_net_http_url stringValue];
1204     }
1205     [self setMRL: o_mrl_string];
1206 }
1207
1208 - (IBAction)openNetUDPButtonAction:(id)sender
1209 {
1210     if( sender == o_net_openUDP_btn )
1211     {
1212         [NSApp beginSheet: o_net_udp_panel
1213            modalForWindow: o_panel
1214             modalDelegate: self
1215            didEndSelector: NULL
1216               contextInfo: nil];
1217         [self openNetInfoChanged: nil];
1218     }
1219     else if( sender == o_net_udp_cancel_btn )
1220     {
1221         [o_net_udp_panel orderOut: sender];
1222         [NSApp endSheet: o_net_udp_panel];
1223     }
1224     else if( sender == o_net_udp_ok_btn )
1225     {
1226         NSString *o_mrl_string = [NSString string];
1227         if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
1228         {
1229             int i_port = [o_net_udp_port intValue];
1230
1231             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1232                 o_mrl_string = @"udp://";
1233             else
1234                 o_mrl_string = @"rtp://";
1235
1236             if( i_port != config_GetInt( p_intf, "server-port" ) )
1237             {
1238                 o_mrl_string =
1239                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1240             }
1241         }
1242         else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
1243         {
1244             NSString *o_addr = [o_net_udpm_addr stringValue];
1245             int i_port = [o_net_udpm_port intValue];
1246
1247             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1248                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1249             else
1250                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1251
1252             if( i_port != config_GetInt( p_intf, "server-port" ) )
1253             {
1254                 o_mrl_string =
1255                 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1256             }
1257         }
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];
1262     }
1263 }
1264
1265 #pragma mark -
1266 #pragma mark Capture Panel
1267
1268 - (void)showCaptureView: theView
1269 {
1270     NSRect o_view_rect;
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)
1275     {
1276         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] replaceSubview: o_currentCaptureView with: theView];
1277         [o_currentCaptureView release];
1278     }
1279     else
1280     {
1281         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] addSubview: theView];
1282     }
1283     o_currentCaptureView = theView;
1284     [o_currentCaptureView retain];
1285 }
1286
1287 - (IBAction)openCaptureModeChanged:(id)sender
1288 {
1289     if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1290     {
1291         if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1292         {
1293             if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1294             {
1295                 [self showCaptureView: o_eyetv_running_view];
1296                 [self setupChannelInfo];
1297             }
1298             else
1299             {
1300                 setEyeTVUnconnected;
1301             }
1302         }
1303         else
1304             [self showCaptureView: o_eyetv_notLaunched_view];
1305         [self setMRL: @""];
1306     }
1307     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1308     {
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" )];
1317
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;
1323         NSValue *v;
1324
1325         returnedError = CGGetOnlineDisplayList( 0, NULL, &displayCount );
1326         if( !returnedError )
1327         {
1328             CGDirectDisplayID *ids;
1329             ids = ( CGDirectDisplayID * )malloc( displayCount * sizeof( CGDirectDisplayID ) );
1330             returnedError = CGGetOnlineDisplayList( displayCount, ids, &displayCount );
1331             if( !returnedError )
1332             {
1333                 for( i = 0; i < [o_displayInfos count]; i ++ )
1334                 {
1335                     v = [o_displayInfos objectAtIndex:i];
1336                     free( [v pointerValue] );
1337                 }
1338                 [o_displayInfos removeAllObjects];
1339                 [o_screen_screen_pop removeAllItems];
1340                 for( i = 0; i < displayCount; i ++ )
1341                 {
1342                     item = ( struct display_info_t * )malloc( sizeof( struct display_info_t ) );
1343                     item->id = ids[i];
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 )
1349                     {
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];
1355                     }
1356                 }
1357             }
1358             free( ids );
1359         }
1360     }
1361     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Video Device")] )
1362     {
1363         [self showCaptureView: o_qtk_view];
1364         if ([o_capture_width_fld intValue] <= 0)
1365             [self qtkChanged:nil];
1366
1367         if(!qtk_currdevice_uid)
1368             [self setMRL: @""];
1369         else
1370             [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
1371     }
1372     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Audio Device")] )
1373     {
1374         [self showCaptureView: o_qtkaudio_view];
1375         [self qtkAudioChanged:nil];
1376
1377         if(!qtkaudio_currdevice_uid)
1378             [self setMRL: @""];
1379         else
1380             [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
1381     }
1382 }
1383
1384 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1385 {
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://"];
1390 }
1391
1392 - (IBAction)eyetvSwitchChannel:(id)sender
1393 {
1394     if( sender == o_eyetv_nextProgram_btn )
1395     {
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]];
1399     }
1400     else if( sender == o_eyetv_previousProgram_btn )
1401     {
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]];
1405     }
1406     else if( sender == o_eyetv_channels_pop )
1407     {
1408         int chanNum = [[sender selectedItem] tag];
1409         [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1410         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1411     }
1412     else
1413         msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1414 }
1415
1416 - (IBAction)eyetvLaunch:(id)sender
1417 {
1418     [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1419 }
1420
1421 - (IBAction)eyetvGetPlugin:(id)sender
1422 {
1423     [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1424 }
1425
1426 - (void)eyetvChanged:(NSNotification *)o_notification
1427 {
1428     if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1429     {
1430         msg_Dbg( VLCIntf, "eyetv device was added" );
1431         [self showCaptureView: o_eyetv_running_view];
1432         [self setupChannelInfo];
1433     }
1434     else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1435     {
1436         /* leave the channel selection like that,
1437          * switch to our "no device" tab */
1438         msg_Dbg( VLCIntf, "eyetv device was removed" );
1439         setEyeTVUnconnected;
1440     }
1441     else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1442     {
1443         /* switch to the "launch eyetv" tab */
1444         msg_Dbg( VLCIntf, "eyetv was terminated" );
1445         [self showCaptureView: o_eyetv_notLaunched_view];
1446     }
1447     else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1448     {
1449         /* we got no device yet */
1450         msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1451         setEyeTVUnconnected;
1452     }
1453 }
1454
1455 /* little helper method, since this code needs to be run by multiple objects */
1456 - (void)setupChannelInfo
1457 {
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];
1464
1465     /* retrieve info */
1466     NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1467     int x = -2;
1468     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1469                                                action: nil
1470                                         keyEquivalent: @""] setTag:x++];
1471     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1472                                                action: nil
1473                                         keyEquivalent: @""] setTag:x++];
1474     if( channels )
1475     {
1476         NSString *channel;
1477         [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1478         while( channel = [channels nextObject] )
1479         {
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
1483                                                    action: nil
1484                                             keyEquivalent: @""] setTag:++x];
1485         }
1486         /* make Tuner the default */
1487         [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1488     }
1489
1490     /* clean up GUI */
1491     [o_eyetv_chn_bgbar setHidden: YES];
1492     [o_eyetv_chn_status_txt setHidden: YES];
1493 }
1494
1495 #pragma mark -
1496 #pragma mark Subtitle Settings
1497
1498 - (IBAction)subsChanged:(id)sender
1499 {
1500     if ([o_file_sub_ckbox state] == NSOnState)
1501     {
1502         [o_file_sub_btn_settings setEnabled:YES];
1503         if (o_sub_path) {
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]];
1506         }
1507     }
1508     else
1509     {
1510         [o_file_sub_btn_settings setEnabled:NO];
1511         [o_file_subtitles_filename_lbl setStringValue: @""];
1512         [o_file_subtitles_icon_well setImage: NULL];
1513     }
1514 }
1515
1516 - (IBAction)subSettings:(id)sender
1517 {
1518     [NSApp beginSheet: o_file_sub_sheet
1519         modalForWindow: [sender window]
1520         modalDelegate: self
1521         didEndSelector: NULL
1522         contextInfo: nil];
1523 }
1524
1525 - (IBAction)subCloseSheet:(id)sender
1526 {
1527     [self subsChanged: nil];
1528     [o_file_sub_sheet orderOut:sender];
1529     [NSApp endSheet: o_file_sub_sheet];
1530 }
1531
1532 - (IBAction)subFileBrowse:(id)sender
1533 {
1534     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1535
1536     [o_open_panel setAllowsMultipleSelection: NO];
1537     [o_open_panel setTitle: _NS("Open File")];
1538     [o_open_panel setPrompt: _NS("Open")];
1539
1540     if( [o_open_panel runModal] == NSOKButton )
1541     {
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]];
1549     }
1550     else
1551     {
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];
1557     }
1558 }
1559
1560 - (IBAction)subOverride:(id)sender
1561 {
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];
1567 }
1568
1569 - (IBAction)subDelayStepperChanged:(id)sender
1570 {
1571     [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1572 }
1573
1574 - (IBAction)subFpsStepperChanged:(id)sender;
1575 {
1576     [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1577 }
1578
1579 #pragma mark -
1580 #pragma mark Miscellaneous
1581
1582 - (IBAction)panelCancel:(id)sender
1583 {
1584     [NSApp stopModalWithCode: 0];
1585 }
1586
1587 - (IBAction)panelOk:(id)sender
1588 {
1589     if( [[self MRL] length] )
1590         [NSApp stopModalWithCode: 1];
1591     else
1592         NSBeep();
1593 }
1594
1595 - (NSArray *)qtkvideoDevices
1596 {
1597     if ( !qtkvideoDevices )
1598         [self qtkrefreshVideoDevices];
1599     return qtkvideoDevices;
1600 }
1601
1602 - (void)qtkrefreshVideoDevices
1603 {
1604     [qtkvideoDevices release];
1605     qtkvideoDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1606 }
1607
1608 - (NSArray *)qtkaudioDevices
1609 {
1610     if ( !qtkaudioDevices )
1611         [self qtkrefreshAudioDevices];
1612     return qtkaudioDevices;
1613 }
1614
1615 - (void)qtkrefreshAudioDevices
1616 {
1617     [qtkaudioDevices release];
1618     qtkaudioDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeSound] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1619 }
1620
1621 @end
1622
1623 @implementation VLCOpenTextField
1624
1625 - (void)mouseDown:(NSEvent *)theEvent
1626 {
1627     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1628                                                         object: self];
1629     [super mouseDown: theEvent];
1630 }
1631
1632 @end