]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
macosx/Open: merge the QTCapture and QTSound views
[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
756     [o_open_panel beginSheetForDirectory:nil
757         file:nil
758         types:nil
759         modalForWindow:[sender window]
760         modalDelegate: self
761         didEndSelector: @selector(pathChosenInPanel:
762                         withReturn:
763                         contextInfo:)
764         contextInfo: nil];
765 }
766
767 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void  *)contextInfo
768 {
769     if (returnCode == NSFileHandlingPanelOKButton)
770     {
771         if( o_file_path )
772             [o_file_path release];
773         o_file_path = [[[sheet URLs] objectAtIndex: 0] path];
774         [o_file_path retain];
775         [self openFilePathChanged: nil];
776     }
777 }
778
779 - (IBAction)openFileStreamChanged:(id)sender
780 {
781     [self openFilePathChanged: nil];
782 }
783
784 - (IBAction)inputSlaveAction:(id)sender
785 {
786     if( sender == o_file_slave_ckbox )
787         [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
788     else
789     {
790         NSOpenPanel *o_open_panel;
791         o_open_panel = [NSOpenPanel openPanel];
792         [o_open_panel setCanChooseFiles: YES];
793         [o_open_panel setCanChooseDirectories: NO];
794         if( [o_open_panel runModal] == NSOKButton )
795         {
796             if( o_file_slave_path )
797                 [o_file_slave_path release];
798             o_file_slave_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
799             [o_file_slave_path retain];
800         }
801     }
802     if( o_file_slave_path && [o_file_slave_ckbox state] == NSOnState)
803     {
804         [o_file_slave_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_slave_path]];
805         [o_file_slave_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_slave_path]];
806     }
807     else
808     {
809         [o_file_slave_filename_lbl setStringValue: @""];
810         [o_file_slave_icon_well setImage: NULL];
811     }
812 }
813
814 - (IBAction)fileTimeCustomization:(id)sender
815 {
816     BOOL b_value = [o_file_custom_timing_ckb state];
817     [o_file_starttime_fld setEnabled: b_value];
818     [o_file_starttime_lbl setEnabled: b_value];
819     [o_file_stoptime_fld setEnabled: b_value];
820     [o_file_stoptime_lbl setEnabled: b_value];
821 }
822
823 #pragma mark -
824 #pragma mark Optical Media Panel
825
826 - (void)showOpticalMediaView: theView withIcon:(NSImage *)icon
827 {
828     NSRect o_view_rect;
829     o_view_rect = [theView frame];
830     [theView setFrame: NSMakeRect( 233, 0, o_view_rect.size.width, o_view_rect.size.height)];
831     [theView setAutoresizesSubviews: YES];
832     if (o_currentOpticalMediaView)
833     {
834         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaView with: theView];
835         [o_currentOpticalMediaView release];
836     }
837     else
838         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: theView];
839     o_currentOpticalMediaView = theView;
840     [o_currentOpticalMediaView retain];
841
842     NSImageView *imageView;
843     imageView = [[NSImageView alloc] init];
844     [imageView setFrame: NSMakeRect( 53, 61, 128, 128 )];
845     [icon setSize: NSMakeSize(128,128)];
846     [imageView setImage: icon];
847     if (o_currentOpticalMediaIconView)
848     {
849         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaIconView with: imageView];
850         [o_currentOpticalMediaIconView release];
851     }
852     else
853          [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: imageView];
854     o_currentOpticalMediaIconView = imageView;
855     [o_currentOpticalMediaIconView retain];
856     [o_currentOpticalMediaView setNeedsDisplay: YES];
857     [o_currentOpticalMediaIconView setNeedsDisplay: YES];
858     [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] setNeedsDisplay: YES];
859     [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] displayIfNeeded];
860 }
861
862 - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
863 {
864     OSStatus err;
865     FSRef ref;
866     FSVolumeRefNum actualVolume;
867     err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
868
869     // get a FSVolumeRefNum from mountPath
870     if ( noErr == err ) {
871         FSCatalogInfo   catalogInfo;
872         err = FSGetCatalogInfo ( &ref,
873                                 kFSCatInfoVolume,
874                                 &catalogInfo,
875                                 NULL,
876                                 NULL,
877                                 NULL
878                                 );
879         if ( noErr == err )
880             actualVolume = catalogInfo.volume;
881         else
882             return @"";
883     }
884     else
885         return @"";
886
887     GetVolParmsInfoBuffer volumeParms;
888     err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
889     if ( noErr == err )
890     {
891         NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
892         return [NSString stringWithFormat:@"/dev/r%@", bsdName];
893     }
894
895     return @"";
896 }
897
898 - (char *)getVolumeTypeFromMountPath:(NSString *)mountPath
899 {
900     OSStatus err;
901     FSRef ref;
902     FSVolumeRefNum actualVolume;
903     err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
904
905     // get a FSVolumeRefNum from mountPath
906     if ( noErr == err ) {
907         FSCatalogInfo   catalogInfo;
908         err = FSGetCatalogInfo ( &ref,
909                                 kFSCatInfoVolume,
910                                 &catalogInfo,
911                                 NULL,
912                                 NULL,
913                                 NULL
914                                 );
915         if ( noErr == err )
916             actualVolume = catalogInfo.volume;
917         else
918             return NULL;
919     }
920     else
921         return NULL;
922
923     GetVolParmsInfoBuffer volumeParms;
924     err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
925
926     CFMutableDictionaryRef matchingDict;
927     io_service_t service;
928
929     if (!volumeParms.vMDeviceID)
930         return NULL;
931
932     matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
933     service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
934
935     char *returnValue;
936     if (IO_OBJECT_NULL != service) {
937         if (IOObjectConformsTo(service, kIOCDMediaClass)) {
938             returnValue = kVLCMediaAudioCD;
939         }
940         else if(IOObjectConformsTo(service, kIODVDMediaClass))
941             returnValue = kVLCMediaDVD;
942         else if(IOObjectConformsTo(service, kIOBDMediaClass))
943             returnValue = kVLCMediaBD;
944         else
945         {
946             if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
947                 returnValue = kVLCMediaVideoTSFolder;
948             else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
949                 returnValue = kVLCMediaBDMVFolder;
950             else
951             {
952                 // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
953                 NSFileManager * fm = [[NSFileManager alloc] init];
954
955                 NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
956                 for (int i = 0; i < [dirContents count]; i++)
957                 {
958                     NSString *currentFile = [dirContents objectAtIndex:i];
959                     NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
960
961                     BOOL isDir;
962                     if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
963                     {
964                         if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame)
965                         {
966                             returnValue = kVLCMediaSVCD;
967                             break;
968                         }
969                         if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame)
970                         {
971                             returnValue = kVLCMediaVCD;
972                             break;
973                         }
974                         if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame)
975                         {
976                             returnValue = kVLCMediaBDMVFolder;
977                             break;
978                         }
979                         if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame)
980                         {
981                             returnValue = kVLCMediaVideoTSFolder;
982                             break;
983                         }
984                     }
985                 }
986
987                 [fm release];
988
989                 if(!returnValue)
990                     returnValue = kVLCMediaVideoTSFolder;
991             }
992         }
993
994         IOObjectRelease(service);
995     }
996     return returnValue;
997 }
998
999 - (void)showOpticalAtPath: (NSString *)o_opticalDevicePath
1000 {
1001     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1002
1003     char *diskType = [self getVolumeTypeFromMountPath:o_opticalDevicePath];
1004
1005     if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder)
1006     {
1007         [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_opticalDevicePath]];
1008         [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
1009         NSString *pathToOpen;
1010         if (diskType == kVLCMediaVideoTSFolder)
1011             pathToOpen = o_opticalDevicePath;
1012         else
1013             pathToOpen = [self getBSDNodeFromMountPath: o_opticalDevicePath];
1014         if (!b_nodvdmenus) {
1015             [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1016             [self showOpticalMediaView: o_disc_dvd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1017         } else {
1018             [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1019             [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1020         }
1021     }
1022     else if (diskType == kVLCMediaAudioCD)
1023     {
1024         [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1025         [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_opticalDevicePath error:NULL] count] - 1]]; // minus .TOC.plist
1026         [self showOpticalMediaView: o_disc_audiocd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1027         [self setMRL: [NSString stringWithFormat: @"cdda://%@", [self getBSDNodeFromMountPath: o_opticalDevicePath]]];
1028     }
1029     else if (diskType == kVLCMediaVCD)
1030     {
1031         [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1032         [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1033         [self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1034     }
1035     else if (diskType == kVLCMediaSVCD)
1036     {
1037         [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1038         [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1039         [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1040     }
1041     else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
1042     {
1043         [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
1044         [self showOpticalMediaView: o_disc_bd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
1045         [self setMRL: [NSString stringWithFormat: @"bluray://%@", o_opticalDevicePath]];
1046     }
1047     else
1048     {
1049         msg_Warn( VLCIntf, "unknown disk type, no idea what to display" );
1050         [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
1051     }
1052
1053     [o_pool release];
1054 }
1055
1056 - (void)showSelectedOpticalDisc
1057 {
1058     NSString *o_opticalDevicePath = [o_opticalDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];
1059     [NSThread detachNewThreadSelector:@selector(showOpticalAtPath:) toTarget:self withObject:o_opticalDevicePath];
1060 }
1061
1062 - (void)scanOpticalMedia:(NSNotification *)o_notification
1063 {
1064     [o_opticalDevices removeAllObjects];
1065     [o_disc_selector_pop removeAllItems];
1066     [o_opticalDevices addObjectsFromArray: [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
1067     [o_opticalDevices addObjectsFromArray: o_specialMediaFolders];
1068     if ([o_opticalDevices count] > 0) {
1069         NSUInteger deviceCount = [o_opticalDevices count];
1070         for (NSUInteger i = 0; i < deviceCount ; i++)
1071             [o_disc_selector_pop addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: i]]];
1072
1073         if ([o_disc_selector_pop numberOfItems] <= 1)
1074             [o_disc_selector_pop setHidden: YES];
1075         else
1076             [o_disc_selector_pop setHidden: NO];
1077
1078         // select newly added media folder
1079         if (o_notification && [[o_notification name] isEqualToString:@"VLCNewMediaFolderNotification"])
1080             [o_disc_selector_pop selectItemAtIndex: [[o_disc_selector_pop itemArray] count] - 1];
1081
1082         [self showSelectedOpticalDisc];
1083     }
1084     else
1085     {
1086         msg_Dbg( VLCIntf, "no optical media found" );
1087         [o_disc_selector_pop setHidden: YES];
1088         [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed: @"NSApplicationIcon"]];
1089     }
1090 }
1091
1092 - (IBAction)discSelectorChanged:(id)sender
1093 {
1094     [self showSelectedOpticalDisc];
1095 }
1096
1097 - (IBAction)openSpecialMediaFolder:(id)sender
1098 {
1099     /* this is currently for VIDEO_TS and BDMV folders */
1100     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1101
1102     [o_open_panel setAllowsMultipleSelection: NO];
1103     [o_open_panel setCanChooseFiles: NO];
1104     [o_open_panel setCanChooseDirectories: YES];
1105     [o_open_panel setTitle: [sender title]];
1106     [o_open_panel setPrompt: _NS("Open")];
1107
1108     if ([o_open_panel runModal] == NSOKButton)
1109     {
1110         NSString *o_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1111         if ([o_path length] > 0 )
1112         {
1113             [o_specialMediaFolders addObject: o_path];
1114             [self scanOpticalMedia: [NSNotification notificationWithName:@"VLCNewMediaFolderNotification" object:nil]];
1115         }
1116     }
1117 }
1118
1119 - (IBAction)dvdreadOptionChanged:(id)sender
1120 {
1121     NSString *o_device_path = [o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]];
1122     char *diskType = [self getVolumeTypeFromMountPath:o_device_path];
1123
1124     NSString *pathToOpen;
1125     if (diskType == kVLCMediaVideoTSFolder)
1126         pathToOpen = o_device_path;
1127     else
1128         pathToOpen = [self getBSDNodeFromMountPath: o_device_path];
1129
1130     if (sender == o_disc_dvdwomenus_enablemenus_btn) {
1131         b_nodvdmenus = NO;
1132         [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
1133         [self showOpticalMediaView: o_disc_dvd_view withIcon: [o_currentOpticalMediaIconView image]];
1134         return;
1135     }
1136     if (sender == o_disc_dvd_disablemenus_btn) {
1137         b_nodvdmenus = YES;
1138         [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [o_currentOpticalMediaIconView image]];
1139     }
1140
1141     if (sender == o_disc_dvdwomenus_title)
1142         [o_disc_dvdwomenus_title_stp setIntValue: [o_disc_dvdwomenus_title intValue]];
1143     if (sender == o_disc_dvdwomenus_title_stp)
1144         [o_disc_dvdwomenus_title setIntValue: [o_disc_dvdwomenus_title_stp intValue]];
1145     if (sender == o_disc_dvdwomenus_chapter)
1146         [o_disc_dvdwomenus_chapter_stp setIntValue: [o_disc_dvdwomenus_chapter intValue]];
1147     if (sender == o_disc_dvdwomenus_chapter_stp)
1148         [o_disc_dvdwomenus_chapter setIntValue: [o_disc_dvdwomenus_chapter_stp intValue]];
1149
1150     [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1151 }
1152
1153 - (IBAction)vcdOptionChanged:(id)sender
1154 {
1155     if (sender == o_disc_vcd_title)
1156         [o_disc_vcd_title_stp setIntValue: [o_disc_vcd_title intValue]];
1157     if (sender == o_disc_vcd_title_stp)
1158         [o_disc_vcd_title setIntValue: [o_disc_vcd_title_stp intValue]];
1159     if (sender == o_disc_vcd_chapter)
1160         [o_disc_vcd_chapter_stp setIntValue: [o_disc_vcd_chapter intValue]];
1161     if (sender == o_disc_vcd_chapter_stp)
1162         [o_disc_vcd_chapter setIntValue: [o_disc_vcd_chapter_stp intValue]];
1163
1164     [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]]];
1165 }
1166
1167 #pragma mark -
1168 #pragma mark Network Panel
1169
1170 - (void)textFieldWasClicked:(NSNotification *)o_notification
1171 {
1172     if( [o_notification object] == o_net_udp_port )
1173         [o_net_mode selectCellAtRow: 0 column: 0];
1174     else if( [o_notification object] == o_net_udpm_addr ||
1175              [o_notification object] == o_net_udpm_port )
1176         [o_net_mode selectCellAtRow: 1 column: 0];
1177     else
1178         [o_net_mode selectCellAtRow: 2 column: 0];
1179
1180     [self openNetInfoChanged: nil];
1181 }
1182
1183 - (IBAction)openNetModeChanged:(id)sender
1184 {
1185     if( sender == o_net_mode )
1186     {
1187         if( [[sender selectedCell] tag] == 0 )
1188             [o_panel makeFirstResponder: o_net_udp_port];
1189         else if ( [[sender selectedCell] tag] == 1 )
1190             [o_panel makeFirstResponder: o_net_udpm_addr];
1191         else
1192             msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
1193     }
1194
1195     [self openNetInfoChanged: nil];
1196 }
1197
1198 - (IBAction)openNetStepperChanged:(id)sender
1199 {
1200     int i_tag = [sender tag];
1201
1202     if( i_tag == 0 )
1203     {
1204         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
1205         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1206                                                             object: o_net_udp_port];
1207         [o_panel makeFirstResponder: o_net_udp_port];
1208     }
1209     else if( i_tag == 1 )
1210     {
1211         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
1212         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1213                                                             object: o_net_udpm_port];
1214         [o_panel makeFirstResponder: o_net_udpm_port];
1215     }
1216
1217     [self openNetInfoChanged: nil];
1218 }
1219
1220 - (void)openNetInfoChanged:(NSNotification *)o_notification
1221 {
1222     NSString *o_mrl_string = [NSString string];
1223
1224     if( [o_net_udp_panel isVisible] )
1225     {
1226         NSString *o_mode;
1227         o_mode = [[o_net_mode selectedCell] title];
1228
1229         if( [o_mode isEqualToString: _NS("Unicast")] )
1230         {
1231             int i_port = [o_net_udp_port intValue];
1232
1233             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1234                 o_mrl_string = @"udp://";
1235             else
1236                 o_mrl_string = @"rtp://";
1237
1238             if( i_port != config_GetInt( p_intf, "server-port" ) )
1239             {
1240                 o_mrl_string =
1241                     [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1242             }
1243         }
1244         else if( [o_mode isEqualToString: _NS("Multicast")] )
1245         {
1246             NSString *o_addr = [o_net_udpm_addr stringValue];
1247             int i_port = [o_net_udpm_port intValue];
1248
1249             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1250                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1251             else
1252                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1253
1254             if( i_port != config_GetInt( p_intf, "server-port" ) )
1255             {
1256                 o_mrl_string =
1257                     [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1258             }
1259         }
1260     }
1261     else
1262     {
1263         o_mrl_string = [o_net_http_url stringValue];
1264     }
1265     [self setMRL: o_mrl_string];
1266 }
1267
1268 - (IBAction)openNetUDPButtonAction:(id)sender
1269 {
1270     if( sender == o_net_openUDP_btn )
1271     {
1272         [NSApp beginSheet: o_net_udp_panel
1273            modalForWindow: o_panel
1274             modalDelegate: self
1275            didEndSelector: NULL
1276               contextInfo: nil];
1277         [self openNetInfoChanged: nil];
1278     }
1279     else if( sender == o_net_udp_cancel_btn )
1280     {
1281         [o_net_udp_panel orderOut: sender];
1282         [NSApp endSheet: o_net_udp_panel];
1283     }
1284     else if( sender == o_net_udp_ok_btn )
1285     {
1286         NSString *o_mrl_string = [NSString string];
1287         if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
1288         {
1289             int i_port = [o_net_udp_port intValue];
1290
1291             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1292                 o_mrl_string = @"udp://";
1293             else
1294                 o_mrl_string = @"rtp://";
1295
1296             if( i_port != config_GetInt( p_intf, "server-port" ) )
1297             {
1298                 o_mrl_string =
1299                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1300             }
1301         }
1302         else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
1303         {
1304             NSString *o_addr = [o_net_udpm_addr stringValue];
1305             int i_port = [o_net_udpm_port intValue];
1306
1307             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1308                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1309             else
1310                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1311
1312             if( i_port != config_GetInt( p_intf, "server-port" ) )
1313             {
1314                 o_mrl_string =
1315                 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1316             }
1317         }
1318         [self setMRL: o_mrl_string];
1319         [o_net_http_url setStringValue: o_mrl_string];
1320         [o_net_udp_panel orderOut: sender];
1321         [NSApp endSheet: o_net_udp_panel];
1322     }
1323 }
1324
1325 #pragma mark -
1326 #pragma mark Capture Panel
1327
1328 - (void)showCaptureView: theView
1329 {
1330     NSRect o_view_rect;
1331     o_view_rect = [theView frame];
1332     [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
1333     [theView setAutoresizesSubviews: YES];
1334     if (o_currentCaptureView)
1335     {
1336         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] replaceSubview: o_currentCaptureView with: theView];
1337         [o_currentCaptureView release];
1338     }
1339     else
1340     {
1341         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] addSubview: theView];
1342     }
1343     o_currentCaptureView = theView;
1344     [o_currentCaptureView retain];
1345 }
1346
1347 - (IBAction)openCaptureModeChanged:(id)sender
1348 {
1349     if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1350     {
1351         if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1352         {
1353             if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1354             {
1355                 [self showCaptureView: o_eyetv_running_view];
1356                 [self setupChannelInfo];
1357             }
1358             else
1359             {
1360                 setEyeTVUnconnected;
1361             }
1362         }
1363         else
1364             [self showCaptureView: o_eyetv_notLaunched_view];
1365         [self setMRL: @""];
1366     }
1367     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1368     {
1369         [self showCaptureView: o_screen_view];
1370         [self setMRL: @"screen://"];
1371         [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
1372         [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
1373         [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
1374         [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
1375         [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
1376         [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
1377
1378         int screen_index = config_GetInt( p_intf, "screen-index" );
1379         int display_id = config_GetInt( p_intf, "screen-display-id" );
1380         unsigned int i, displayCount = 0;
1381         CGLError returnedError;
1382         struct display_info_t *item;
1383         NSValue *v;
1384
1385         returnedError = CGGetOnlineDisplayList( 0, NULL, &displayCount );
1386         if( !returnedError )
1387         {
1388             CGDirectDisplayID *ids;
1389             ids = ( CGDirectDisplayID * )malloc( displayCount * sizeof( CGDirectDisplayID ) );
1390             returnedError = CGGetOnlineDisplayList( displayCount, ids, &displayCount );
1391             if( !returnedError )
1392             {
1393                 for( i = 0; i < [o_displayInfos count]; i ++ )
1394                 {
1395                     v = [o_displayInfos objectAtIndex:i];
1396                     free( [v pointerValue] );
1397                 }
1398                 [o_displayInfos removeAllObjects];
1399                 [o_screen_screen_pop removeAllItems];
1400                 for( i = 0; i < displayCount; i ++ )
1401                 {
1402                     item = ( struct display_info_t * )malloc( sizeof( struct display_info_t ) );
1403                     item->id = ids[i];
1404                     item->rect = CGDisplayBounds( item->id );
1405                     [o_screen_screen_pop addItemWithTitle: [NSString stringWithFormat:@"Screen %d (%dx%d)", i + 1, (int)item->rect.size.width, (int)item->rect.size.height]];
1406                     v = [NSValue valueWithPointer:item];
1407                     [o_displayInfos addObject:v];
1408                     if( i == 0 || display_id == item->id || screen_index - 1 == i )
1409                     {
1410                         [o_screen_screen_pop selectItemAtIndex: i];
1411                         [o_screen_left_stp setMaxValue: item->rect.size.width];
1412                         [o_screen_top_stp setMaxValue: item->rect.size.height];
1413                         [o_screen_width_stp setMaxValue: item->rect.size.width];
1414                         [o_screen_height_stp setMaxValue: item->rect.size.height];
1415                     }
1416                 }
1417             }
1418             free( ids );
1419         }
1420     }
1421     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")] )
1422     {
1423         [self showCaptureView: o_qtk_view];
1424         if ([o_capture_width_fld intValue] <= 0)
1425             [self qtkChanged:nil];
1426
1427         [self qtkAudioChanged:nil];
1428
1429         [self setMRL: @""];
1430
1431         if ([o_qtk_video_ckb state] && qtk_currdevice_uid)
1432             [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
1433         else if([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
1434             [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
1435     }
1436 }
1437
1438 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1439 {
1440     [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1441     if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1442         [o_screen_fps_fld setFloatValue: 1.0];
1443     [self setMRL: @"screen://"];
1444 }
1445
1446 - (IBAction)eyetvSwitchChannel:(id)sender
1447 {
1448     if( sender == o_eyetv_nextProgram_btn )
1449     {
1450         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1451         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1452         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1453     }
1454     else if( sender == o_eyetv_previousProgram_btn )
1455     {
1456         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1457         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1458         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1459     }
1460     else if( sender == o_eyetv_channels_pop )
1461     {
1462         int chanNum = [[sender selectedItem] tag];
1463         [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1464         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1465     }
1466     else
1467         msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1468 }
1469
1470 - (IBAction)eyetvLaunch:(id)sender
1471 {
1472     [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1473 }
1474
1475 - (IBAction)eyetvGetPlugin:(id)sender
1476 {
1477     [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1478 }
1479
1480 - (void)eyetvChanged:(NSNotification *)o_notification
1481 {
1482     if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1483     {
1484         msg_Dbg( VLCIntf, "eyetv device was added" );
1485         [self showCaptureView: o_eyetv_running_view];
1486         [self setupChannelInfo];
1487     }
1488     else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1489     {
1490         /* leave the channel selection like that,
1491          * switch to our "no device" tab */
1492         msg_Dbg( VLCIntf, "eyetv device was removed" );
1493         setEyeTVUnconnected;
1494     }
1495     else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1496     {
1497         /* switch to the "launch eyetv" tab */
1498         msg_Dbg( VLCIntf, "eyetv was terminated" );
1499         [self showCaptureView: o_eyetv_notLaunched_view];
1500     }
1501     else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1502     {
1503         /* we got no device yet */
1504         msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1505         setEyeTVUnconnected;
1506     }
1507 }
1508
1509 /* little helper method, since this code needs to be run by multiple objects */
1510 - (void)setupChannelInfo
1511 {
1512     /* set up channel selection */
1513     [o_eyetv_channels_pop removeAllItems];
1514     [o_eyetv_chn_bgbar setHidden: NO];
1515     [o_eyetv_chn_bgbar animate: self];
1516     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1517     [o_eyetv_chn_status_txt setHidden: NO];
1518
1519     /* retrieve info */
1520     NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1521     int x = -2;
1522     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1523                                                action: nil
1524                                         keyEquivalent: @""] setTag:x++];
1525     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1526                                                action: nil
1527                                         keyEquivalent: @""] setTag:x++];
1528     if( channels )
1529     {
1530         NSString *channel;
1531         [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1532         while( channel = [channels nextObject] )
1533         {
1534             /* we have to add items this way, because we accept duplicates
1535              * additionally, we save a bit of time */
1536             [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1537                                                    action: nil
1538                                             keyEquivalent: @""] setTag:++x];
1539         }
1540         /* make Tuner the default */
1541         [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1542     }
1543
1544     /* clean up GUI */
1545     [o_eyetv_chn_bgbar setHidden: YES];
1546     [o_eyetv_chn_status_txt setHidden: YES];
1547 }
1548
1549 #pragma mark -
1550 #pragma mark Subtitle Settings
1551
1552 - (IBAction)subsChanged:(id)sender
1553 {
1554     if ([o_file_sub_ckbox state] == NSOnState)
1555     {
1556         [o_file_sub_btn_settings setEnabled:YES];
1557         if (o_sub_path) {
1558             [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1559             [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1560         }
1561     }
1562     else
1563     {
1564         [o_file_sub_btn_settings setEnabled:NO];
1565         [o_file_subtitles_filename_lbl setStringValue: @""];
1566         [o_file_subtitles_icon_well setImage: NULL];
1567     }
1568 }
1569
1570 - (IBAction)subSettings:(id)sender
1571 {
1572     [NSApp beginSheet: o_file_sub_sheet
1573         modalForWindow: [sender window]
1574         modalDelegate: self
1575         didEndSelector: NULL
1576         contextInfo: nil];
1577 }
1578
1579 - (IBAction)subCloseSheet:(id)sender
1580 {
1581     [self subsChanged: nil];
1582     [o_file_sub_sheet orderOut:sender];
1583     [NSApp endSheet: o_file_sub_sheet];
1584 }
1585
1586 - (IBAction)subFileBrowse:(id)sender
1587 {
1588     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1589
1590     [o_open_panel setAllowsMultipleSelection: NO];
1591     [o_open_panel setTitle: _NS("Open File")];
1592     [o_open_panel setPrompt: _NS("Open")];
1593
1594     if( [o_open_panel runModal] == NSOKButton )
1595     {
1596         o_sub_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
1597         [o_sub_path retain];
1598         [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1599         [o_file_sub_path_fld setStringValue: [o_file_subtitles_filename_lbl stringValue]];
1600         [o_file_sub_path_lbl setHidden: YES];
1601         [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1602         [o_file_sub_icon_view setImage: [o_file_subtitles_icon_well image]];
1603     }
1604     else
1605     {
1606         [o_file_sub_path_lbl setHidden: NO];
1607         [o_file_sub_path_fld setStringValue:@""];
1608         [o_file_subtitles_filename_lbl setStringValue:@""];
1609         [o_file_subtitles_icon_well setImage: nil];
1610         [o_file_sub_icon_view setImage: nil];
1611     }
1612 }
1613
1614 - (IBAction)subOverride:(id)sender
1615 {
1616     BOOL b_state = [o_file_sub_override state];
1617     [o_file_sub_delay setEnabled: b_state];
1618     [o_file_sub_delay_stp setEnabled: b_state];
1619     [o_file_sub_fps setEnabled: b_state];
1620     [o_file_sub_fps_stp setEnabled: b_state];
1621 }
1622
1623 - (IBAction)subDelayStepperChanged:(id)sender
1624 {
1625     [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1626 }
1627
1628 - (IBAction)subFpsStepperChanged:(id)sender;
1629 {
1630     [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1631 }
1632
1633 #pragma mark -
1634 #pragma mark Miscellaneous
1635
1636 - (IBAction)panelCancel:(id)sender
1637 {
1638     [NSApp stopModalWithCode: 0];
1639 }
1640
1641 - (IBAction)panelOk:(id)sender
1642 {
1643     if( [[self MRL] length] )
1644         [NSApp stopModalWithCode: 1];
1645     else
1646         NSBeep();
1647 }
1648
1649 - (NSArray *)qtkvideoDevices
1650 {
1651     if ( !qtkvideoDevices )
1652         [self qtkrefreshVideoDevices];
1653     return qtkvideoDevices;
1654 }
1655
1656 - (void)qtkrefreshVideoDevices
1657 {
1658     [qtkvideoDevices release];
1659     qtkvideoDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1660 }
1661
1662 - (NSArray *)qtkaudioDevices
1663 {
1664     if ( !qtkaudioDevices )
1665         [self qtkrefreshAudioDevices];
1666     return qtkaudioDevices;
1667 }
1668
1669 - (void)qtkrefreshAudioDevices
1670 {
1671     [qtkaudioDevices release];
1672     qtkaudioDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeSound] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1673 }
1674
1675 @end
1676
1677 @implementation VLCOpenTextField
1678
1679 - (void)mouseDown:(NSEvent *)theEvent
1680 {
1681     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1682                                                         object: self];
1683     [super mouseDown: theEvent];
1684 }
1685
1686 @end