]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
025c94f2649c128bd073fe6d54d18d9eeca25087
[vlc] / modules / gui / macosx / open.m
1 /*****************************************************************************
2  * open.m: Open dialogues for VLC's MacOS X port
3  *****************************************************************************
4  * Copyright (C) 2002-2009 the VideoLAN team
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 #include <stdlib.h>                                      /* malloc(), free() */
32 #include <sys/param.h>                                    /* for MAXPATHLEN */
33 #include <string.h>
34
35 #include <paths.h>
36 #include <IOKit/IOKitLib.h>
37 #include <IOKit/IOBSD.h>
38 #include <IOKit/storage/IOMedia.h>
39 #include <IOKit/storage/IOCDMedia.h>
40 #include <IOKit/storage/IODVDMedia.h>
41
42 #import "intf.h"
43 #import "playlist.h"
44 #import "open.h"
45 #import "output.h"
46 #import "eyetv.h"
47
48 #include <vlc_url.h>
49
50 #define setEyeTVUnconnected \
51 [o_capture_lbl setStringValue: _NS("No device connected")]; \
52 [o_capture_long_lbl setStringValue: _NS("VLC could not detect any EyeTV compatible device.\n\nCheck the device's connection, make sure that the latest EyeTV software is installed and try again.")]; \
53 [o_capture_lbl displayIfNeeded]; \
54 [o_capture_long_lbl displayIfNeeded]; \
55 [self showCaptureView: o_capture_label_view]
56
57
58 /*****************************************************************************
59  * GetEjectableMediaOfClass
60  *****************************************************************************/
61 NSArray *GetEjectableMediaOfClass( const char *psz_class )
62 {
63     io_object_t next_media;
64     mach_port_t master_port;
65     kern_return_t kern_result;
66     NSArray *o_devices = nil;
67     NSMutableArray *p_list = nil;
68     io_iterator_t media_iterator;
69     CFMutableDictionaryRef classes_to_match;
70
71     kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
72     if( kern_result != KERN_SUCCESS )
73     {
74         return( nil );
75     }
76  
77     classes_to_match = IOServiceMatching( psz_class );
78     if( classes_to_match == NULL )
79     {
80         return( nil );
81     }
82  
83     CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectableKey ),
84                           kCFBooleanTrue );
85  
86     kern_result = IOServiceGetMatchingServices( master_port, classes_to_match,
87                                                 &media_iterator );
88     if( kern_result != KERN_SUCCESS )
89     {
90         return( nil );
91     }
92
93     p_list = [NSMutableArray arrayWithCapacity: 1];
94  
95     next_media = IOIteratorNext( media_iterator );
96     if( next_media )
97     {
98         char psz_buf[0x32];
99         size_t dev_path_length;
100         CFTypeRef str_bsd_path;
101  
102         do
103         {
104             str_bsd_path = IORegistryEntryCreateCFProperty( next_media,
105                                                             CFSTR( kIOBSDNameKey ),
106                                                             kCFAllocatorDefault,
107                                                             0 );
108             if( str_bsd_path == NULL )
109             {
110                 IOObjectRelease( next_media );
111                 continue;
112             }
113  
114             snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' );
115             dev_path_length = strlen( psz_buf );
116  
117             if( CFStringGetCString( str_bsd_path,
118                                     (char*)&psz_buf + dev_path_length,
119                                     sizeof(psz_buf) - dev_path_length,
120                                     kCFStringEncodingASCII ) )
121             {
122                 [p_list addObject: [NSString stringWithUTF8String: psz_buf]];
123             }
124  
125             CFRelease( str_bsd_path );
126  
127             IOObjectRelease( next_media );
128  
129         } while( ( next_media = IOIteratorNext( media_iterator ) ) );
130     }
131  
132     IOObjectRelease( media_iterator );
133
134     o_devices = [NSArray arrayWithArray: p_list];
135
136     return( o_devices );
137 }
138
139 /*****************************************************************************
140  * VLCOpen implementation
141  *****************************************************************************/
142 @implementation VLCOpen
143
144 static VLCOpen *_o_sharedMainInstance = nil;
145
146 + (VLCOpen *)sharedInstance
147 {
148     return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
149 }
150
151 - (id)init
152 {
153     if( _o_sharedMainInstance) {
154         [self dealloc];
155     } else {
156         _o_sharedMainInstance = [super init];
157         p_intf = VLCIntf;
158     }
159  
160     return _o_sharedMainInstance;
161 }
162
163 - (void)dealloc
164 {
165     if( o_file_slave_path )
166         [o_file_slave_path release];
167     [super dealloc];
168 }
169
170 - (void)awakeFromNib
171 {
172     [o_panel setTitle: _NS("Open Source")];
173     [o_mrl_lbl setStringValue: _NS("Media Resource Locator (MRL)")];
174
175     [o_btn_ok setTitle: _NS("Open")];
176     [o_btn_cancel setTitle: _NS("Cancel")];
177
178     [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
179     [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
180     [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
181     [[o_tabview tabViewItemAtIndex: 3] setLabel: _NS("Capture")];
182
183     [o_file_btn_browse setTitle: _NS("Browse...")];
184     [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
185     [o_file_slave_ckbox setTitle: _NS("Play another media synchronously")];
186     [o_file_slave_select_btn setTitle: _NS("Choose...")];
187     [o_file_slave_filename_txt setStringValue: @""];
188
189     [o_disc_device_lbl setStringValue: _NS("Device name")];
190     [o_disc_title_lbl setStringValue: _NS("Title")];
191     [o_disc_chapter_lbl setStringValue: _NS("Chapter")];
192     [o_disc_videots_btn_browse setTitle: _NS("Browse...")];
193     [o_disc_dvd_menus setTitle: _NS("No DVD menus")];
194
195     [[o_disc_type cellAtRow:0 column:0] setTitle: _NS("VIDEO_TS folder")];
196     [[o_disc_type cellAtRow:1 column:0] setTitle: _NS("DVD")];
197     [[o_disc_type cellAtRow:2 column:0] setTitle: _NS("VCD")];
198     [[o_disc_type cellAtRow:3 column:0] setTitle: _NS("Audio CD")];
199
200     [o_net_udp_port_lbl setStringValue: _NS("Port")];
201     [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
202     [o_net_udpm_port_lbl setStringValue: _NS("Port")];
203     [o_net_http_url_lbl setStringValue: _NS("URL")];
204     [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.")];
205     [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.")];
206     [o_net_udp_cancel_btn setTitle: _NS("Cancel")];
207     [o_net_udp_ok_btn setTitle: _NS("Open")];
208     [o_net_openUDP_btn setTitle: _NS("Open RTP/UDP Stream")];
209     [o_net_udp_mode_lbl setStringValue: _NS("Mode")];
210     [o_net_udp_protocol_lbl setStringValue: _NS("Protocol")];
211     [o_net_udp_address_lbl setStringValue: _NS("Address")];
212
213     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
214     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
215
216     [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
217     [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
218
219     [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
220
221     [o_capture_mode_pop removeAllItems];
222     [o_capture_mode_pop addItemWithTitle: @"iSight"];
223     [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
224     [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
225     [o_screen_lbl setStringValue: _NS("Screen Capture Input")];
226     [o_screen_long_lbl setStringValue: _NS("This facility allows you to process your screen's output.")];
227     [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
228     [o_screen_left_lbl setStringValue: _NS("Subscreen left:")];
229     [o_screen_top_lbl setStringValue: _NS("Subscreen top:")];
230     [o_screen_width_lbl setStringValue: _NS("Subscreen width:")];
231     [o_screen_height_lbl setStringValue: _NS("Subscreen height:")];
232     [o_screen_follow_mouse_ckb setTitle: _NS("Follow the mouse")];
233     [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
234     [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
235     [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
236     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
237     [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
238     [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
239     [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
240     [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
241
242     [self setSubPanel];
243
244     [[NSNotificationCenter defaultCenter] addObserver: self
245         selector: @selector(openFilePathChanged:)
246         name: NSControlTextDidChangeNotification
247         object: o_file_path];
248
249     [[NSNotificationCenter defaultCenter] addObserver: self
250         selector: @selector(openDiscInfoChanged:)
251         name: NSControlTextDidChangeNotification
252         object: o_disc_device];
253     [[NSNotificationCenter defaultCenter] addObserver: self
254         selector: @selector(openDiscInfoChanged:)
255         name: NSControlTextDidChangeNotification
256         object: o_disc_title];
257     [[NSNotificationCenter defaultCenter] addObserver: self
258         selector: @selector(openDiscInfoChanged:)
259         name: NSControlTextDidChangeNotification
260         object: o_disc_chapter];
261     [[NSNotificationCenter defaultCenter] addObserver: self
262         selector: @selector(openDiscInfoChanged:)
263         name: NSControlTextDidChangeNotification
264         object: o_disc_videots_folder];
265
266     [[NSNotificationCenter defaultCenter] addObserver: self
267         selector: @selector(openNetInfoChanged:)
268         name: NSControlTextDidChangeNotification
269         object: o_net_udp_port];
270     [[NSNotificationCenter defaultCenter] addObserver: self
271         selector: @selector(openNetInfoChanged:)
272         name: NSControlTextDidChangeNotification
273         object: o_net_udpm_addr];
274     [[NSNotificationCenter defaultCenter] addObserver: self
275         selector: @selector(openNetInfoChanged:)
276         name: NSControlTextDidChangeNotification
277         object: o_net_udpm_port];
278     [[NSNotificationCenter defaultCenter] addObserver: self
279         selector: @selector(openNetInfoChanged:)
280         name: NSControlTextDidChangeNotification
281         object: o_net_http_url];
282
283     [[NSDistributedNotificationCenter defaultCenter] addObserver: self
284                                                         selector: @selector(eyetvChanged:)
285                                                             name: NULL
286                                                           object: @"VLCEyeTVSupport"
287                                               suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
288
289     [[NSNotificationCenter defaultCenter] addObserver: self
290                                              selector: @selector(screenFPSfieldChanged:)
291                                                  name: NSControlTextDidChangeNotification
292                                                object: o_screen_fps_fld];
293
294     /* register clicks on text fields */
295     [[NSNotificationCenter defaultCenter] addObserver: self
296                                              selector: @selector(textFieldWasClicked:)
297                                                  name: @"VLCOpenTextFieldWasClicked"
298                                                object: nil];
299 }
300
301 - (void)setSubPanel
302 {
303     int i_index;
304     module_config_t * p_item;
305
306     [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
307     [o_file_sub_btn_settings setTitle: _NS("Settings...")];
308     [o_file_sub_btn_browse setTitle: _NS("Browse...")];
309     [o_file_sub_override setTitle: _NS("Override parametters")];
310     [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
311     [o_file_sub_delay_stp setEnabled: NO];
312     [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
313     [o_file_sub_fps_stp setEnabled: NO];
314     [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
315     [o_file_sub_encoding_pop removeAllItems];
316     [o_file_sub_size_lbl setStringValue: _NS("Font size")];
317     [o_file_sub_size_pop removeAllItems];
318     [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
319     [o_file_sub_align_pop removeAllItems];
320     [o_file_sub_ok_btn setStringValue: _NS("OK")];
321     [o_file_sub_font_box setTitle: _NS("Font Properties")];
322     [o_file_sub_file_box setTitle: _NS("Subtitle File")];
323
324     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
325
326     if( p_item )
327     {
328         for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
329              i_index++ )
330         {
331             [o_file_sub_encoding_pop addItemWithTitle:
332                 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
333         }
334         [o_file_sub_encoding_pop selectItemWithTitle:
335                 [NSString stringWithUTF8String: p_item->value.psz]];
336     }
337
338     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
339
340     if ( p_item )
341     {
342         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
343         {
344             [o_file_sub_align_pop addItemWithTitle:
345                 [NSString stringWithUTF8String:
346                 p_item->ppsz_list_text[i_index]]];
347         }
348         [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
349     }
350
351     p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
352
353     if ( p_item )
354     {
355         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
356         {
357             [o_file_sub_size_pop addItemWithTitle:
358                 [NSString stringWithUTF8String:
359                 p_item->ppsz_list_text[i_index]]];
360             if ( p_item->value.i == p_item->pi_list[i_index] )
361             {
362                 [o_file_sub_size_pop selectItemAtIndex: i_index];
363             }
364         }
365     }
366 }
367
368 - (void)openTarget:(int)i_type
369 {
370     int i_result;
371
372     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
373
374     [o_tabview selectTabViewItemAtIndex: i_type];
375     [o_file_sub_ckbox setState: NSOffState];
376  
377     i_result = [NSApp runModalForWindow: o_panel];
378     [o_panel close];
379
380     if( i_result )
381     {
382         NSMutableDictionary *o_dic;
383         NSMutableArray *o_options = [NSMutableArray array];
384         unsigned int i;
385
386         o_dic = [NSMutableDictionary dictionaryWithObject: [o_mrl stringValue] forKey: @"ITEM_URL"];
387         if( [o_file_sub_ckbox state] == NSOnState )
388         {
389             module_config_t * p_item;
390
391             [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", [o_file_sub_path stringValue]]];
392             if( [o_file_sub_override state] == NSOnState )
393             {
394                 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
395                 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
396             }
397             [o_options addObject: [NSString stringWithFormat:
398                     @"subsdec-encoding=%@",
399                     [o_file_sub_encoding_pop titleOfSelectedItem]]];
400             [o_options addObject: [NSString stringWithFormat:
401                     @"subsdec-align=%i",
402                     [o_file_sub_align_pop indexOfSelectedItem]]];
403
404             p_item = config_FindConfig( VLC_OBJECT(p_intf),
405                                             "freetype-rel-fontsize" );
406
407             if ( p_item )
408             {
409                 [o_options addObject: [NSString stringWithFormat:
410                     @"freetype-rel-fontsize=%i",
411                     p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
412             }
413         }
414         if( [o_output_ckbox state] == NSOnState )
415         {
416             for (i = 0 ; i < [[o_sout_options mrl] count] ; i++)
417             {
418                 [o_options addObject: [NSString stringWithString:
419                       [[(VLCOutput *)o_sout_options mrl] objectAtIndex: i]]];
420             }
421         }
422         if( [o_file_slave_ckbox state] && o_file_slave_path )
423            [o_options addObject: [NSString stringWithFormat: @"input-slave=%@", o_file_slave_path]];
424         if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
425         {
426             if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
427                 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
428                 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
429                 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
430                 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
431                 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
432                 if( [o_screen_follow_mouse_ckb intValue] == YES )
433                     [o_options addObject: @"screen-follow-mouse"];
434                 else
435                     [o_options addObject: @"no-screen-follow-mouse"];
436         }
437
438         /* apply the options to our item(s) */
439         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
440         if( b_autoplay )
441             [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
442         else
443             [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
444     }
445 }
446
447 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
448 {
449     NSString *o_label = [o_tvi label];
450
451     if( [o_label isEqualToString: _NS("File")] )
452     {
453         [self openFilePathChanged: nil];
454     }
455     else if( [o_label isEqualToString: _NS("Disc")] )
456     {
457         [self openDiscTypeChanged: nil];
458     }
459     else if( [o_label isEqualToString: _NS("Network")] )
460     {
461         [self openNetInfoChanged: nil];
462     }
463     else if( [o_label isEqualToString: _NS("Capture")] )
464     {
465         [self openCaptureModeChanged: nil];
466     }
467 }
468
469 - (IBAction)expandMRLfieldAction:(id)sender
470 {
471     NSRect o_win_rect, o_view_rect;
472     o_win_rect = [o_panel frame];
473     o_view_rect = [o_mrl_view frame];
474
475     if( [o_mrl_btn state] == NSOffState )
476     {
477         /* we need to collaps, restore the panel size */
478         o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
479         o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
480
481         /* remove the MRL view */
482         [o_mrl_view removeFromSuperviewWithoutNeedingDisplay];
483     } else {
484         /* we need to expand */
485         [o_mrl_view setFrame: NSMakeRect( 0,
486                                          [o_mrl_btn frame].origin.y,
487                                          o_view_rect.size.width,
488                                          o_view_rect.size.height )];
489         [o_mrl_view setNeedsDisplay: YES];
490         [o_mrl_view setAutoresizesSubviews: YES];
491
492         /* add the MRL view */
493         [[o_panel contentView] addSubview: o_mrl_view];
494         o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
495     }
496
497     [o_panel setFrame: o_win_rect display:YES animate: YES];
498     [o_panel displayIfNeeded];
499 }
500
501 - (IBAction)inputSlaveAction:(id)sender
502 {
503     if( sender == o_file_slave_ckbox )
504         [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
505     else
506     {
507         NSOpenPanel *o_open_panel;
508         o_open_panel = [NSOpenPanel openPanel];
509         [o_open_panel setCanChooseFiles: YES];
510         [o_open_panel setCanChooseDirectories: NO];
511         if( [o_open_panel runModalForDirectory: nil file: nil types: nil] == NSOKButton )
512         {
513             if( o_file_slave_path )
514                 [o_file_slave_path release];
515             o_file_slave_path = [[o_open_panel filenames] objectAtIndex: 0];
516             [o_file_slave_path retain];
517         }
518         else
519             [o_file_slave_filename_txt setStringValue: @""];
520     }
521     if( o_file_slave_path )
522     {
523         NSFileWrapper *o_file_wrapper;
524         o_file_wrapper = [[NSFileWrapper alloc] initWithPath: o_file_slave_path];
525         [o_file_slave_filename_txt setStringValue: [NSString stringWithFormat: @"\"%@\"", [o_file_wrapper preferredFilename]]];
526         [o_file_wrapper release];
527     }
528 }
529
530 - (void)openFileGeneric
531 {
532     [self openFilePathChanged: nil];
533     [self openTarget: 0];
534 }
535
536 - (void)openDisc
537 {
538     [self openDiscTypeChanged: nil];
539     [self openTarget: 1];
540 }
541
542 - (void)openNet
543 {
544     [self openNetInfoChanged: nil];
545     [self openTarget: 2];
546 }
547
548 - (void)openCapture
549 {
550     [self openCaptureModeChanged: nil];
551     [self showCaptureView: o_capture_label_view];
552     [self openTarget: 3];
553 }
554
555 - (void)openFilePathChanged:(NSNotification *)o_notification
556 {
557     NSString *o_filename = [o_file_path stringValue];
558     bool b_stream = [o_file_stream state];
559     BOOL b_dir = NO;
560
561     [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
562
563     char *psz_uri = make_URI([o_filename UTF8String]);
564     if( !psz_uri ) return;
565
566     NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
567     NSRange offile = [o_mrl_string rangeOfString:@"file"];
568     free( psz_uri );
569
570     if( b_dir )
571     {
572         [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
573     }
574     else if( b_stream )
575     {
576         [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
577     }
578     [o_mrl setStringValue: o_mrl_string];
579 }
580
581 - (IBAction)openFileBrowse:(id)sender
582 {
583     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
584  
585     [o_open_panel setAllowsMultipleSelection: NO];
586     [o_open_panel setCanChooseDirectories: YES];
587     [o_open_panel setTitle: _NS("Open File")];
588     [o_open_panel setPrompt: _NS("Open")];
589
590     [o_open_panel beginSheetForDirectory:nil
591         file:nil
592         types:nil
593         modalForWindow:[sender window]
594         modalDelegate: self
595         didEndSelector: @selector(pathChosenInPanel:
596                         withReturn:
597                         contextInfo:)
598         contextInfo: nil];
599 }
600
601 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void  *)contextInfo
602 {
603     if (returnCode == NSFileHandlingPanelOKButton)
604     {
605         NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
606         [o_file_path setStringValue: o_filename];
607         [self openFilePathChanged: nil];
608     }
609 }
610
611 - (IBAction)openFileStreamChanged:(id)sender
612 {
613     [self openFilePathChanged: nil];
614 }
615
616 - (IBAction)openDiscTypeChanged:(id)sender
617 {
618     NSString *o_type;
619     BOOL b_device, b_no_menus, b_title_chapter;
620  
621     [o_disc_device removeAllItems];
622     b_title_chapter = ![o_disc_dvd_menus state];
623  
624     o_type = [[o_disc_type selectedCell] title];
625
626     if ( [o_type isEqualToString: _NS("VIDEO_TS folder")] )
627     {
628         b_device = NO; b_no_menus = YES;
629     }
630     else
631     {
632         NSArray *o_devices;
633         NSString *o_disc;
634         const char *psz_class = NULL;
635         b_device = YES;
636
637         if ( [o_type isEqualToString: _NS("VCD")] )
638         {
639             psz_class = kIOCDMediaClass;
640             o_disc = o_type;
641             b_no_menus = NO; b_title_chapter = YES;
642                 }
643         else if ( [o_type isEqualToString: _NS("Audio CD")])
644         {
645             psz_class = kIOCDMediaClass;
646             o_disc = o_type;
647             b_no_menus = NO; b_title_chapter = NO;
648         }
649         else
650         {
651             psz_class = kIODVDMediaClass;
652             o_disc = o_type;
653             b_no_menus = YES;
654         }
655  
656         o_devices = GetEjectableMediaOfClass( psz_class );
657         if ( o_devices != nil )
658         {
659             int i_devices = [o_devices count];
660  
661             if ( i_devices )
662             {
663                                 for( int i = 0; i < i_devices; i++ )
664                 {
665                     [o_disc_device
666                         addItemWithObjectValue: [o_devices objectAtIndex: i]];
667                 }
668
669                 [o_disc_device selectItemAtIndex: 0];
670             }
671             else
672             {
673                 [o_disc_device setStringValue:
674                     [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
675             }
676         }
677     }
678
679     [o_disc_device setEnabled: b_device];
680     [o_disc_title setEnabled: b_title_chapter];
681     [o_disc_title_stp setEnabled: b_title_chapter];
682     [o_disc_chapter setEnabled: b_title_chapter];
683     [o_disc_chapter_stp setEnabled: b_title_chapter];
684     [o_disc_videots_folder setEnabled: !b_device];
685     [o_disc_videots_btn_browse setEnabled: !b_device];
686     [o_disc_dvd_menus setEnabled: b_no_menus];
687
688     [self openDiscInfoChanged: nil];
689 }
690
691 - (IBAction)openDiscStepperChanged:(id)sender
692 {
693     int i_tag = [sender tag];
694
695     if( i_tag == 0 )
696     {
697         [o_disc_title setIntValue: [o_disc_title_stp intValue]];
698     }
699     else if( i_tag == 1 )
700     {
701         [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
702     }
703
704     [self openDiscInfoChanged: nil];
705 }
706
707 - (void)openDiscInfoChanged:(NSNotification *)o_notification
708 {
709     NSString *o_type;
710     NSString *o_device;
711     NSString *o_videots;
712     NSString *o_mrl_string;
713     int i_title, i_chapter;
714     BOOL b_no_menus;
715
716     o_type = [[o_disc_type selectedCell] title];
717     o_device = [o_disc_device stringValue];
718     i_title = [o_disc_title intValue];
719     i_chapter = [o_disc_chapter intValue];
720     o_videots = [o_disc_videots_folder stringValue];
721     b_no_menus = [o_disc_dvd_menus state];
722
723     if ( [o_type isEqualToString: _NS("VCD")] )
724     {
725         if ( [o_device isEqualToString:
726                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
727             o_device = @"";
728         o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i:%i",
729                         o_device, i_title, i_chapter];
730     }
731     else if ( [o_type isEqualToString: _NS("Audio CD")] )
732     {
733         if ( [o_device isEqualToString:
734                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
735             o_device = @"";
736         o_mrl_string = [NSString stringWithFormat: @"cdda://%@",
737                         o_device];
738     }
739     else if ( [o_type isEqualToString: _NS("DVD")] )
740     {
741         if ( [o_device isEqualToString:
742                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
743             o_device = @"";
744         if ( b_no_menus )
745             o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i-",
746                             o_device, i_title, i_chapter];
747         else
748                         o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
749                             o_device];
750             
751     }
752     else /* VIDEO_TS folder */
753     {
754         if ( b_no_menus )
755             o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
756                             o_videots, i_title, i_chapter];
757         else
758                         o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
759                             o_videots];            
760     }
761
762     [o_mrl setStringValue: o_mrl_string];
763 }
764
765 - (IBAction)openDiscMenusChanged:(id)sender
766 {
767     [self openDiscInfoChanged: nil];
768     [self openDiscTypeChanged: nil];
769 }
770
771 - (IBAction)openVTSBrowse:(id)sender
772 {
773     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
774
775     [o_open_panel setAllowsMultipleSelection: NO];
776     [o_open_panel setCanChooseFiles: NO];
777     [o_open_panel setCanChooseDirectories: YES];
778     [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
779     [o_open_panel setPrompt: _NS("Open")];
780
781     if( [o_open_panel runModalForDirectory: nil
782             file: nil types: nil] == NSOKButton )
783     {
784         NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
785         [o_disc_videots_folder setStringValue: o_dirname];
786         [self openDiscInfoChanged: nil];
787     }
788 }
789
790 - (void)textFieldWasClicked:(NSNotification *)o_notification
791 {
792     if( [o_notification object] == o_net_udp_port )
793         [o_net_mode selectCellAtRow: 0 column: 0];
794     else if( [o_notification object] == o_net_udpm_addr ||
795              [o_notification object] == o_net_udpm_port )
796         [o_net_mode selectCellAtRow: 1 column: 0];
797     else
798         [o_net_mode selectCellAtRow: 2 column: 0];
799
800     [self openNetInfoChanged: nil];
801 }
802
803 - (IBAction)openNetModeChanged:(id)sender
804 {
805     if( sender == o_net_mode )
806     {
807         if( [[sender selectedCell] tag] == 0 )
808             [o_panel makeFirstResponder: o_net_udp_port];
809         else if ( [[sender selectedCell] tag] == 1 )
810             [o_panel makeFirstResponder: o_net_udpm_addr];
811         else
812             msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
813     }
814
815     [self openNetInfoChanged: nil];
816 }
817
818 - (IBAction)openNetStepperChanged:(id)sender
819 {
820     int i_tag = [sender tag];
821
822     if( i_tag == 0 )
823     {
824         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
825         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
826                                                             object: o_net_udp_port];
827         [o_panel makeFirstResponder: o_net_udp_port];
828     }
829     else if( i_tag == 1 )
830     {
831         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
832         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
833                                                             object: o_net_udpm_port];
834         [o_panel makeFirstResponder: o_net_udpm_port];
835     }
836
837     [self openNetInfoChanged: nil];
838 }
839
840 - (void)openNetInfoChanged:(NSNotification *)o_notification
841 {
842     NSString *o_mrl_string = [NSString string];
843
844     if( [o_net_udp_panel isVisible] )
845     {
846         NSString *o_mode;
847         o_mode = [[o_net_mode selectedCell] title];
848
849         if( [o_mode isEqualToString: _NS("Unicast")] )
850         {
851             int i_port = [o_net_udp_port intValue];
852
853             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
854                 o_mrl_string = [NSString stringWithString: @"udp://"];
855             else
856                 o_mrl_string = [NSString stringWithString: @"rtp://"];
857
858             if( i_port != config_GetInt( p_intf, "server-port" ) )
859             {
860                 o_mrl_string =
861                     [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
862             }
863         }
864         else if( [o_mode isEqualToString: _NS("Multicast")] )
865         {
866             NSString *o_addr = [o_net_udpm_addr stringValue];
867             int i_port = [o_net_udpm_port intValue];
868
869             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
870                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
871             else
872                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
873
874             if( i_port != config_GetInt( p_intf, "server-port" ) )
875             {
876                 o_mrl_string =
877                     [o_mrl_string stringByAppendingFormat: @":%i", i_port];
878             }
879         }
880     }
881     else
882     {
883         o_mrl_string = [o_net_http_url stringValue];
884     }
885     [o_mrl setStringValue: o_mrl_string];
886 }
887
888 - (IBAction)openNetUDPButtonAction:(id)sender
889 {
890     if( sender == o_net_openUDP_btn )
891     {
892         [NSApp beginSheet: o_net_udp_panel
893            modalForWindow: o_panel
894             modalDelegate: self
895            didEndSelector: NULL
896               contextInfo: nil];
897         [self openNetInfoChanged: nil];
898     }
899     else if( sender == o_net_udp_cancel_btn )
900     {
901         [o_net_udp_panel orderOut: sender];
902         [NSApp endSheet: o_net_udp_panel];
903     }
904     else if( sender == o_net_udp_ok_btn )
905     {
906         NSString *o_mrl_string = [NSString string];
907         if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
908         {
909             int i_port = [o_net_udp_port intValue];
910             
911             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
912                 o_mrl_string = [NSString stringWithString: @"udp://"];
913             else
914                 o_mrl_string = [NSString stringWithString: @"rtp://"];
915
916             if( i_port != config_GetInt( p_intf, "server-port" ) )
917             {
918                 o_mrl_string =
919                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
920             }
921         }
922         else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
923         {
924             NSString *o_addr = [o_net_udpm_addr stringValue];
925             int i_port = [o_net_udpm_port intValue];
926             
927             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
928                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
929             else
930                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
931
932             if( i_port != config_GetInt( p_intf, "server-port" ) )
933             {
934                 o_mrl_string =
935                 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
936             }
937         }
938         [o_mrl setStringValue: o_mrl_string];
939         [o_net_http_url setStringValue: o_mrl_string];
940         [o_net_udp_panel orderOut: sender];
941         [NSApp endSheet: o_net_udp_panel];
942     }
943 }
944     
945 - (void)openFile
946 {
947     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
948     int i;
949     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
950  
951     [o_open_panel setAllowsMultipleSelection: YES];
952     [o_open_panel setCanChooseDirectories: YES];
953     [o_open_panel setTitle: _NS("Open File")];
954     [o_open_panel setPrompt: _NS("Open")];
955  
956     if( [o_open_panel runModalForDirectory: nil
957             file: nil types: nil] == NSOKButton )
958     {
959         NSArray *o_array = [NSArray array];
960         NSArray *o_values = [[o_open_panel filenames]
961                 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
962
963         for( i = 0; i < (int)[o_values count]; i++)
964         {
965             NSDictionary *o_dic;
966             char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String]);
967             if( !psz_uri )
968                 continue;
969
970             o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
971
972             free( psz_uri );
973
974             o_array = [o_array arrayByAddingObject: o_dic];
975         }
976         if( b_autoplay )
977             [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
978         else
979             [o_playlist appendArray: o_array atPos: -1 enqueue:YES];
980     }
981 }
982
983 - (void)showCaptureView: theView
984 {
985     NSRect o_view_rect;
986     o_view_rect = [theView frame];
987     if( o_currentCaptureView )
988     {
989         [o_currentCaptureView removeFromSuperviewWithoutNeedingDisplay];
990         [o_currentCaptureView release];
991     }
992     [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
993     [theView setNeedsDisplay: YES];
994     [theView setAutoresizesSubviews: YES];
995     [[[o_tabview tabViewItemAtIndex: 3] view] addSubview: theView];
996     [theView displayIfNeeded];
997     o_currentCaptureView = theView;
998     [o_currentCaptureView retain];
999 }
1000
1001 - (IBAction)openCaptureModeChanged:(id)sender
1002 {
1003     if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1004     {
1005         if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1006         {
1007             if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1008             {
1009                 [self showCaptureView: o_eyetv_running_view];
1010                 [self setupChannelInfo];
1011             }
1012             else
1013             {
1014                 setEyeTVUnconnected;
1015             }
1016         }
1017         else
1018             [self showCaptureView: o_eyetv_notLaunched_view];
1019         [o_mrl setStringValue: @""];
1020     } 
1021     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1022     {
1023         [self showCaptureView: o_screen_view];
1024         [o_mrl setStringValue: @"screen://"];
1025         [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
1026         [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
1027         [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
1028         [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
1029         [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
1030         [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
1031     }
1032     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"iSight"] )
1033     {
1034         [o_capture_lbl setStringValue: _NS("iSight Capture Input")];
1035         [o_capture_long_lbl setStringValue: _NS("This facility allows you to process your iSight's input signal.\n\nNo settings are available in this version, so you will be provided a 640px*480px raw video stream.\n\nLive Audio input is not supported.")];
1036         [o_capture_lbl displayIfNeeded];
1037         [o_capture_long_lbl displayIfNeeded];
1038         
1039         [self showCaptureView: o_capture_label_view];
1040         [o_mrl setStringValue: @"qtcapture://"];
1041     }
1042 }
1043
1044 - (IBAction)screenStepperChanged:(id)sender
1045 {
1046     [o_screen_fps_fld setFloatValue: [o_screen_fps_stp floatValue]];
1047     [o_panel makeFirstResponder: o_screen_fps_fld];
1048     [o_mrl setStringValue: @"screen://"];
1049 }
1050
1051 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1052 {
1053     [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1054     if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1055         [o_screen_fps_fld setFloatValue: 1.0];
1056     [o_mrl setStringValue: @"screen://"];
1057 }
1058
1059 - (IBAction)eyetvSwitchChannel:(id)sender
1060 {
1061     if( sender == o_eyetv_nextProgram_btn )
1062     {
1063         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1064         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1065         [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1066     }
1067     else if( sender == o_eyetv_previousProgram_btn )
1068     {
1069         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1070         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1071         [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1072     }
1073     else if( sender == o_eyetv_channels_pop )
1074     {
1075         int chanNum = [[sender selectedItem] tag];
1076         [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1077         [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1078     }
1079     else
1080         msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1081 }
1082
1083 - (IBAction)eyetvLaunch:(id)sender
1084 {
1085     [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1086 }
1087
1088 - (IBAction)eyetvGetPlugin:(id)sender
1089 {
1090     [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1091 }
1092
1093 - (void)eyetvChanged:(NSNotification *)o_notification
1094 {
1095     if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1096     {
1097         msg_Dbg( VLCIntf, "eyetv device was added" );
1098         [self showCaptureView: o_eyetv_running_view];
1099         [self setupChannelInfo];
1100     }
1101     else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1102     {
1103         /* leave the channel selection like that,
1104          * switch to our "no device" tab */
1105         msg_Dbg( VLCIntf, "eyetv device was removed" );
1106         setEyeTVUnconnected;
1107     }
1108     else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1109     {
1110         /* switch to the "launch eyetv" tab */
1111         msg_Dbg( VLCIntf, "eyetv was terminated" );
1112         [self showCaptureView: o_eyetv_notLaunched_view];
1113     }
1114     else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1115     {
1116         /* we got no device yet */
1117         msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1118         setEyeTVUnconnected;
1119     }
1120     else
1121         msg_Warn( VLCIntf, "unknown external notify '%s' received", [[o_notification name] UTF8String] );
1122 }    
1123
1124 /* little helper method, since this code needs to be run by multiple objects */
1125 - (void)setupChannelInfo
1126 {
1127     /* set up channel selection */
1128     [o_eyetv_channels_pop removeAllItems];
1129     [o_eyetv_chn_bgbar setHidden: NO];
1130     [o_eyetv_chn_bgbar animate: self];
1131     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1132     [o_eyetv_chn_status_txt setHidden: NO];
1133  
1134     /* retrieve info */
1135     NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1136     int x = -2;
1137     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1138                                                action: nil
1139                                         keyEquivalent: @""] setTag:x++];
1140     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1141                                                action: nil
1142                                         keyEquivalent: @""] setTag:x++];
1143     if( channels ) 
1144     {
1145         NSString *channel;
1146         [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1147         while( channel = [channels nextObject] )
1148         {
1149             /* we have to add items this way, because we accept duplicates
1150              * additionally, we save a bit of time */
1151             [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1152                                                    action: nil
1153                                             keyEquivalent: @""] setTag:++x];
1154         }
1155         /* make Tuner the default */
1156         [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1157     }
1158  
1159     /* clean up GUI */
1160     [o_eyetv_chn_bgbar setHidden: YES];
1161     [o_eyetv_chn_status_txt setHidden: YES];
1162 }
1163
1164 - (IBAction)subsChanged:(id)sender
1165 {
1166     if ([o_file_sub_ckbox state] == NSOnState)
1167     {
1168         [o_file_sub_btn_settings setEnabled:YES];
1169     }
1170     else
1171     {
1172         [o_file_sub_btn_settings setEnabled:NO];
1173     }
1174 }
1175
1176 - (IBAction)subSettings:(id)sender
1177 {
1178     [NSApp beginSheet: o_file_sub_sheet
1179         modalForWindow: [sender window]
1180         modalDelegate: self
1181         didEndSelector: NULL
1182         contextInfo: nil];
1183 }
1184
1185 - (IBAction)subCloseSheet:(id)sender
1186 {
1187     [o_file_sub_sheet orderOut:sender];
1188     [NSApp endSheet: o_file_sub_sheet];
1189 }
1190     
1191 - (IBAction)subFileBrowse:(id)sender
1192 {
1193     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1194  
1195     [o_open_panel setAllowsMultipleSelection: NO];
1196     [o_open_panel setTitle: _NS("Open File")];
1197     [o_open_panel setPrompt: _NS("Open")];
1198
1199     if( [o_open_panel runModalForDirectory: nil
1200             file: nil types: nil] == NSOKButton )
1201     {
1202         NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
1203         [o_file_sub_path setStringValue: o_filename];
1204     }
1205 }
1206
1207 - (IBAction)subOverride:(id)sender
1208 {
1209     BOOL b_state = [o_file_sub_override state];
1210     [o_file_sub_delay setEnabled: b_state];
1211     [o_file_sub_delay_stp setEnabled: b_state];
1212     [o_file_sub_fps setEnabled: b_state];
1213     [o_file_sub_fps_stp setEnabled: b_state];
1214 }
1215
1216 - (IBAction)subDelayStepperChanged:(id)sender
1217 {
1218     [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1219 }
1220
1221 - (IBAction)subFpsStepperChanged:(id)sender;
1222 {
1223     [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1224 }
1225
1226 - (IBAction)panelCancel:(id)sender
1227 {
1228     [NSApp stopModalWithCode: 0];
1229 }
1230
1231 - (IBAction)panelOk:(id)sender
1232 {
1233     if( [[o_mrl stringValue] length] )
1234     {
1235         [NSApp stopModalWithCode: 1];
1236     }
1237     else
1238     {
1239         NSBeep();
1240     }
1241 }
1242
1243 @end
1244
1245 @implementation VLCOpenTextField
1246
1247 - (void)mouseDown:(NSEvent *)theEvent
1248 {
1249     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1250                                                         object: self];
1251     [super mouseDown: theEvent];
1252 }
1253
1254 @end