]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
* gui behaviour change: the textfields are no longer disabled if another protocol...
[vlc] / modules / gui / macosx / open.m
1 /*****************************************************************************
2  * open.m: MacOS X module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002-2006 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 K\9fhne <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 #include "intf.h"
43 #include "playlist.h"
44 #include "open.h"
45 #include "output.h"
46 #import <vlc_interface.h>
47
48 /*****************************************************************************
49  * GetEjectableMediaOfClass 
50  *****************************************************************************/
51 NSArray *GetEjectableMediaOfClass( const char *psz_class )
52 {
53     io_object_t next_media;
54     mach_port_t master_port;
55     kern_return_t kern_result;
56     NSArray *o_devices = nil;
57     NSMutableArray *p_list = nil;
58     io_iterator_t media_iterator;
59     CFMutableDictionaryRef classes_to_match;
60
61     kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
62     if( kern_result != KERN_SUCCESS )
63     {
64         return( nil );
65     }
66     
67     classes_to_match = IOServiceMatching( psz_class );
68     if( classes_to_match == NULL )
69     {
70         return( nil );
71     }
72     
73     CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectableKey ), 
74                           kCFBooleanTrue );
75     
76     kern_result = IOServiceGetMatchingServices( master_port, classes_to_match, 
77                                                 &media_iterator );
78     if( kern_result != KERN_SUCCESS )
79     {
80         return( nil );
81     }
82
83     p_list = [NSMutableArray arrayWithCapacity: 1];
84     
85     next_media = IOIteratorNext( media_iterator );
86     if( next_media != nil )
87     {
88         char psz_buf[0x32];
89         size_t dev_path_length;
90         CFTypeRef str_bsd_path;
91     
92         do
93         {
94             str_bsd_path = IORegistryEntryCreateCFProperty( next_media,
95                                                             CFSTR( kIOBSDNameKey ),
96                                                             kCFAllocatorDefault,
97                                                             0 );
98             if( str_bsd_path == NULL )
99             {
100                 IOObjectRelease( next_media );
101                 continue;
102             }
103             
104             snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' );
105             dev_path_length = strlen( psz_buf );
106             
107             if( CFStringGetCString( str_bsd_path,
108                                     (char*)&psz_buf + dev_path_length,
109                                     sizeof(psz_buf) - dev_path_length,
110                                     kCFStringEncodingASCII ) )
111             {
112                 [p_list addObject: [NSString stringWithCString: psz_buf]];
113             }
114             
115             CFRelease( str_bsd_path );
116             
117             IOObjectRelease( next_media );
118         
119         } while( ( next_media = IOIteratorNext( media_iterator ) ) != nil );
120     }
121     
122     IOObjectRelease( media_iterator );
123
124     o_devices = [NSArray arrayWithArray: p_list];
125
126     return( o_devices );
127 }
128
129 /*****************************************************************************
130  * VLCOpen implementation 
131  *****************************************************************************/
132 @implementation VLCOpen
133
134 static VLCOpen *_o_sharedMainInstance = nil;
135
136 + (VLCOpen *)sharedInstance
137 {
138     return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
139 }
140
141 - (id)init
142 {
143     if( _o_sharedMainInstance) {
144         [self dealloc];
145     } else {
146         _o_sharedMainInstance = [super init];
147     }
148     
149     return _o_sharedMainInstance;
150 }
151
152 - (void)awakeFromNib
153 {
154     intf_thread_t * p_intf = VLCIntf;
155
156     [o_panel setTitle: _NS("Open Source")];
157     [o_mrl_lbl setTitle: _NS("Media Resource Locator (MRL)")];
158
159     [o_btn_ok setTitle: _NS("OK")];
160     [o_btn_cancel setTitle: _NS("Cancel")];
161
162     [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
163     [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
164     [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
165
166     [o_file_btn_browse setTitle: _NS("Browse...")];
167     [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
168
169     [o_disc_device_lbl setStringValue: _NS("Device name")];
170     [o_disc_title_lbl setStringValue: _NS("Title")];
171     [o_disc_chapter_lbl setStringValue: _NS("Chapter")];
172     [o_disc_videots_btn_browse setTitle: _NS("Browse...")];
173     [o_disc_dvd_menus setTitle: _NS("Use DVD menus")];
174
175     [[o_disc_type cellAtRow:0 column:0] setTitle: _NS("VIDEO_TS directory")];
176     [[o_disc_type cellAtRow:1 column:0] setTitle: _NS("DVD")];
177     [[o_disc_type cellAtRow:2 column:0] setTitle: _NS("VCD")];
178     [[o_disc_type cellAtRow:3 column:0] setTitle: _NS("Audio CD")];
179
180     [o_net_udp_port_lbl setStringValue: _NS("Port")];
181     [o_net_udpm_addr_lbl setStringValue: _NS("Address")];
182     [o_net_udpm_port_lbl setStringValue: _NS("Port")];
183     [o_net_http_url_lbl setStringValue: _NS("URL")];
184
185     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("UDP/RTP")];
186     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("UDP/RTP Multicast")];
187     [[o_net_mode cellAtRow:2 column:0] setTitle: _NS("HTTP/FTP/MMS/RTSP")];
188     [o_net_timeshift_ckbox setTitle: _NS("Allow timeshifting")];
189
190     [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
191     [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
192
193     [self setSubPanel];
194
195
196     [[NSNotificationCenter defaultCenter] addObserver: self
197         selector: @selector(openFilePathChanged:)
198         name: NSControlTextDidChangeNotification
199         object: o_file_path];
200
201     [[NSNotificationCenter defaultCenter] addObserver: self
202         selector: @selector(openDiscInfoChanged:)
203         name: NSControlTextDidChangeNotification
204         object: o_disc_device];
205     [[NSNotificationCenter defaultCenter] addObserver: self
206         selector: @selector(openDiscInfoChanged:)
207         name: NSControlTextDidChangeNotification
208         object: o_disc_title];
209     [[NSNotificationCenter defaultCenter] addObserver: self
210         selector: @selector(openDiscInfoChanged:)
211         name: NSControlTextDidChangeNotification
212         object: o_disc_chapter];
213     [[NSNotificationCenter defaultCenter] addObserver: self
214         selector: @selector(openDiscInfoChanged:)
215         name: NSControlTextDidChangeNotification
216         object: o_disc_videots_folder];
217
218     [[NSNotificationCenter defaultCenter] addObserver: self
219         selector: @selector(openNetInfoChanged:)
220         name: NSControlTextDidChangeNotification
221         object: o_net_udp_port];
222     [[NSNotificationCenter defaultCenter] addObserver: self
223         selector: @selector(openNetInfoChanged:)
224         name: NSControlTextDidChangeNotification
225         object: o_net_udpm_addr];
226     [[NSNotificationCenter defaultCenter] addObserver: self
227         selector: @selector(openNetInfoChanged:)
228         name: NSControlTextDidChangeNotification
229         object: o_net_udpm_port];
230     [[NSNotificationCenter defaultCenter] addObserver: self
231         selector: @selector(openNetInfoChanged:)
232         name: NSControlTextDidChangeNotification
233         object: o_net_http_url];
234     
235     /* register clicks on text fields */
236     [[NSNotificationCenter defaultCenter] addObserver: self
237                                              selector: @selector(textFieldWasClicked:)
238                                                  name: @"VLCOpenTextFieldWasClicked"
239                                                object: nil];
240 }
241
242 - (void)setSubPanel
243 {
244     intf_thread_t * p_intf = VLCIntf;
245     int i_index;
246     module_config_t * p_item;
247
248     [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
249     [o_file_sub_btn_settings setTitle: _NS("Settings...")];
250     [o_file_sub_btn_browse setTitle: _NS("Browse...")];
251     [o_file_sub_override setTitle: _NS("Override parametters")];
252     [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
253     [o_file_sub_delay_stp setEnabled: NO];
254     [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
255     [o_file_sub_fps_stp setEnabled: NO];
256     [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
257     [o_file_sub_encoding_pop removeAllItems];
258     [o_file_sub_size_lbl setStringValue: _NS("Font size")];
259     [o_file_sub_size_pop removeAllItems];
260     [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
261     [o_file_sub_align_pop removeAllItems];
262     [o_file_sub_ok_btn setStringValue: _NS("OK")];
263     [o_file_sub_font_box setTitle: _NS("Font Properties")];
264     [o_file_sub_file_box setTitle: _NS("Subtitle File")];
265
266     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
267
268     if( p_item )
269     {
270         for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
271              i_index++ )
272         {
273             [o_file_sub_encoding_pop addItemWithTitle:
274                 [NSString stringWithCString:
275                 p_item->ppsz_list[i_index]]];
276         }
277         [o_file_sub_encoding_pop selectItemWithTitle:
278                 [NSString stringWithCString:
279                 p_item->value.psz]];
280     }
281
282     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
283
284     if ( p_item )
285     {
286         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
287         {
288             [o_file_sub_align_pop addItemWithTitle:
289                 [NSString stringWithUTF8String:
290                 p_item->ppsz_list_text[i_index]]];
291         }
292         [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
293     }
294
295     p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
296
297     if ( p_item )
298     {
299         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
300         {
301             [o_file_sub_size_pop addItemWithTitle:
302                 [NSString stringWithUTF8String:
303                 p_item->ppsz_list_text[i_index]]];
304             if ( p_item->value.i == p_item->pi_list[i_index] )
305             {
306                 [o_file_sub_size_pop selectItemAtIndex: i_index];
307             }
308         }
309     }
310 }
311
312 - (void)openTarget:(int)i_type
313 {
314     int i_result;
315     intf_thread_t * p_intf = VLCIntf;
316
317     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
318
319     [o_tabview selectTabViewItemAtIndex: i_type];
320     [o_file_sub_ckbox setState: NSOffState];
321     
322     i_result = [NSApp runModalForWindow: o_panel];
323     [o_panel close];
324
325     if( i_result )
326     {
327         NSMutableDictionary *o_dic;
328         NSMutableArray *o_options = [NSMutableArray array];
329         unsigned int i;
330
331         o_dic = [NSMutableDictionary dictionaryWithObject: [o_mrl stringValue] forKey: @"ITEM_URL"];
332         if( [o_file_sub_ckbox state] == NSOnState )
333         {
334             module_config_t * p_item;
335
336             [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", [o_file_sub_path stringValue]]];
337             if( [o_file_sub_override state] == NSOnState )
338             {
339                 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
340                 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
341             }
342             [o_options addObject: [NSString stringWithFormat:
343                     @"subsdec-encoding=%@",
344                     [o_file_sub_encoding_pop titleOfSelectedItem]]];
345             [o_options addObject: [NSString stringWithFormat:
346                     @"subsdec-align=%i",
347                     [o_file_sub_align_pop indexOfSelectedItem]]];
348
349             p_item = config_FindConfig( VLC_OBJECT(p_intf),
350                                             "freetype-rel-fontsize" );
351
352             if ( p_item )
353             {
354                 [o_options addObject: [NSString stringWithFormat:
355                     @"freetype-rel-fontsize=%i",
356                     p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
357             }
358         }
359         if( [o_output_ckbox state] == NSOnState )
360         {
361             for (i = 0 ; i < [[o_sout_options getMRL] count] ; i++)
362             {
363                 [o_options addObject: [NSString stringWithString:
364                       [[(VLCOutput *)o_sout_options getMRL] objectAtIndex: i]]];
365             }
366         }
367         if( [o_net_timeshift_ckbox state] == NSOnState )
368         {
369             [o_options addObject: [NSString stringWithString:
370                                                 @"access-filter=timeshift"]];
371         }
372         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
373         if( b_autoplay )
374             [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
375         else
376             [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
377     }
378 }
379
380 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
381 {
382     NSString *o_label = [o_tvi label];
383
384     if( [o_label isEqualToString: _NS("File")] )
385     {
386         [self openFilePathChanged: nil];
387     }
388     else if( [o_label isEqualToString: _NS("Disc")] )
389     {
390         [self openDiscTypeChanged: nil];
391     }
392     else if( [o_label isEqualToString: _NS("Network")] )
393     {
394         [self openNetInfoChanged: nil];
395     }  
396 }
397
398 - (void)openFileGeneric
399 {
400     [self openFilePathChanged: nil];
401     [self openTarget: 0];
402 }
403
404 - (void)openDisc
405 {
406     [self openDiscTypeChanged: nil];
407     [self openTarget: 1];
408 }
409
410 - (void)openNet
411 {
412     [self openNetInfoChanged: nil];
413     [self openTarget: 2];
414 }
415
416 - (void)openFilePathChanged:(NSNotification *)o_notification
417 {
418     NSString *o_mrl_string;
419     NSString *o_filename = [o_file_path stringValue];
420     NSString *o_ext = [o_filename pathExtension];
421     vlc_bool_t b_stream = [o_file_stream state];
422     BOOL b_dir = NO;
423     
424     [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
425
426     if( b_dir )
427     {
428         o_mrl_string = [NSString stringWithFormat: @"dir:%@", o_filename];
429     }
430     else if( [o_ext isEqualToString: @"bin"] ||
431         [o_ext isEqualToString: @"cue"] ||
432         [o_ext isEqualToString: @"vob"] ||
433         [o_ext isEqualToString: @"iso"] )
434     {
435         o_mrl_string = o_filename;
436     }
437     else
438     {
439         o_mrl_string = [NSString stringWithFormat: @"%s://%@",
440                         b_stream ? "stream" : "file",
441                         o_filename];
442     }
443     [o_mrl setStringValue: o_mrl_string]; 
444 }
445
446 - (IBAction)openFileBrowse:(id)sender
447 {
448     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
449     
450     [o_open_panel setAllowsMultipleSelection: NO];
451     [o_open_panel setCanChooseDirectories: YES];
452     [o_open_panel setTitle: _NS("Open File")];
453     [o_open_panel setPrompt: _NS("Open")];
454
455     [o_open_panel beginSheetForDirectory:nil
456         file:nil
457         types:nil
458         modalForWindow:[sender window]
459         modalDelegate: self
460         didEndSelector: @selector(pathChosenInPanel: 
461                         withReturn:
462                         contextInfo:)
463         contextInfo: nil];
464 }
465
466 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void  *)contextInfo
467 {
468     if (returnCode == NSFileHandlingPanelOKButton)
469     {
470         NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
471         [o_file_path setStringValue: o_filename];
472         [self openFilePathChanged: nil];
473     }
474 }
475
476 - (IBAction)openFileStreamChanged:(id)sender
477 {
478     [self openFilePathChanged: nil];
479 }
480
481 - (IBAction)openDiscTypeChanged:(id)sender
482 {
483     NSString *o_type;
484     vlc_bool_t b_device, b_menus, b_title_chapter;
485     
486     [o_disc_device removeAllItems];
487     b_title_chapter = ![o_disc_dvd_menus state];
488     
489     o_type = [[o_disc_type selectedCell] title];
490
491     if ( [o_type isEqualToString: _NS("VIDEO_TS directory")] )
492     {
493         b_device = 0; b_menus = 1;
494     }
495     else
496     {
497         NSArray *o_devices;
498         NSString *o_disc;
499         const char *psz_class = NULL;
500         b_device = 1;
501
502         if ( [o_type isEqualToString: _NS("VCD")] )
503         {
504             psz_class = kIOCDMediaClass;
505             o_disc = o_type;
506             b_menus = 0; b_title_chapter = 1;
507             [o_disc_dvd_menus setState: FALSE];
508         }
509         else if ( [o_type isEqualToString: _NS("Audio CD")])
510         {
511             psz_class = kIOCDMediaClass;
512             o_disc = o_type;
513             b_menus = 0; b_title_chapter = 0;
514             [o_disc_dvd_menus setState: FALSE];
515         }
516         else
517         {
518             psz_class = kIODVDMediaClass;
519             o_disc = o_type;
520             b_menus = 1;
521         }
522     
523         o_devices = GetEjectableMediaOfClass( psz_class );
524         if ( o_devices != nil )
525         {
526             int i_devices = [o_devices count];
527         
528             if ( i_devices )
529             {
530                 int i;
531         
532                 for( i = 0; i < i_devices; i++ )
533                 {
534                     [o_disc_device 
535                         addItemWithObjectValue: [o_devices objectAtIndex: i]];
536                 }
537
538                 [o_disc_device selectItemAtIndex: 0];
539             }
540             else
541             {
542                 [o_disc_device setStringValue: 
543                     [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
544             }
545         }
546     }
547
548     [o_disc_device setEnabled: b_device];
549     [o_disc_title setEnabled: b_title_chapter];
550     [o_disc_title_stp setEnabled: b_title_chapter];
551     [o_disc_chapter setEnabled: b_title_chapter];
552     [o_disc_chapter_stp setEnabled: b_title_chapter];
553     [o_disc_videots_folder setEnabled: !b_device];
554     [o_disc_videots_btn_browse setEnabled: !b_device];
555     [o_disc_dvd_menus setEnabled: b_menus];
556
557     [self openDiscInfoChanged: nil];
558 }
559
560 - (IBAction)openDiscStepperChanged:(id)sender
561 {
562     int i_tag = [sender tag];
563
564     if( i_tag == 0 )
565     {
566         [o_disc_title setIntValue: [o_disc_title_stp intValue]];
567     }
568     else if( i_tag == 1 )
569     {
570         [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
571     }
572
573     [self openDiscInfoChanged: nil];
574 }
575
576 - (void)openDiscInfoChanged:(NSNotification *)o_notification
577 {
578     NSString *o_type;
579     NSString *o_device;
580     NSString *o_videots;
581     NSString *o_mrl_string;
582     int i_title, i_chapter;
583     vlc_bool_t b_menus;
584
585     o_type = [[o_disc_type selectedCell] title];
586     o_device = [o_disc_device stringValue];
587     i_title = [o_disc_title intValue];
588     i_chapter = [o_disc_chapter intValue];
589     o_videots = [o_disc_videots_folder stringValue];
590     b_menus = [o_disc_dvd_menus state];
591
592     if ( [o_type isEqualToString: _NS("VCD")] )
593     {
594         if ( [o_device isEqualToString:
595                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
596             o_device = @"";
597         o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i:%i",
598                         o_device, i_title, i_chapter]; 
599     }
600     else if ( [o_type isEqualToString: _NS("Audio CD")] )
601     {
602         if ( [o_device isEqualToString:
603                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
604             o_device = @"";
605         o_mrl_string = [NSString stringWithFormat: @"cdda://%@",
606                         o_device]; 
607     }
608     else if ( [o_type isEqualToString: _NS("DVD")] )
609     {
610         if ( [o_device isEqualToString:
611                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
612             o_device = @"";
613         if ( b_menus )
614             o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
615                             o_device]; 
616         else
617             o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i-",
618                             o_device, i_title, i_chapter]; 
619     }
620     else /* VIDEO_TS folder */
621     {
622         if ( b_menus )
623             o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
624                             o_videots]; 
625         else
626             o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
627                             o_videots, i_title, i_chapter]; 
628     }
629
630     [o_mrl setStringValue: o_mrl_string]; 
631 }
632
633 - (IBAction)openDiscMenusChanged:(id)sender
634 {
635     [self openDiscInfoChanged: nil];
636     [self openDiscTypeChanged: nil];
637 }
638
639 - (IBAction)openVTSBrowse:(id)sender
640 {
641     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
642
643     [o_open_panel setAllowsMultipleSelection: NO];
644     [o_open_panel setCanChooseFiles: NO];
645     [o_open_panel setCanChooseDirectories: YES];
646     [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
647     [o_open_panel setPrompt: _NS("Open")];
648
649     if( [o_open_panel runModalForDirectory: nil
650             file: nil types: nil] == NSOKButton )
651     {
652         NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
653         [o_disc_videots_folder setStringValue: o_dirname];
654         [self openDiscInfoChanged: nil];
655     }
656 }
657
658 - (void)textFieldWasClicked:(NSNotification *)o_notification
659 {
660     if( [o_notification object] == o_net_udp_port )
661         [o_net_mode selectCellAtRow: 0 column: 0];
662     else if( [o_notification object] == o_net_udpm_addr ||
663              [o_notification object] == o_net_udpm_port )
664         [o_net_mode selectCellAtRow: 1 column: 0];
665     else
666         [o_net_mode selectCellAtRow: 2 column: 0];
667
668     [self openNetInfoChanged: nil];
669 }
670
671 - (IBAction)openNetModeChanged:(id)sender
672 {
673     if( [[sender selectedCell] tag] == 0 )
674         [o_panel makeFirstResponder: o_net_udp_port];
675     else if ( [[sender selectedCell] tag] == 1 )
676         [o_panel makeFirstResponder: o_net_udpm_addr];
677     else
678         [o_panel makeFirstResponder: o_net_http_url];
679
680     [self openNetInfoChanged: nil];
681 }
682
683 - (IBAction)openNetStepperChanged:(id)sender
684 {
685     int i_tag = [sender tag];
686
687     if( i_tag == 0 )
688     {
689         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
690         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked" 
691                                                             object: o_net_udp_port];
692         [o_panel makeFirstResponder: o_net_udp_port];
693     }
694     else if( i_tag == 1 )
695     {
696         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
697         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked" 
698                                                             object: o_net_udpm_port];
699         [o_panel makeFirstResponder: o_net_udpm_port];
700     }
701
702     [self openNetInfoChanged: nil];
703 }
704
705 - (void)openNetInfoChanged:(NSNotification *)o_notification
706 {
707     NSString *o_mode;
708     NSString *o_mrl_string = [NSString string];
709     intf_thread_t * p_intf = VLCIntf;
710
711     o_mode = [[o_net_mode selectedCell] title];
712
713     if( [o_mode isEqualToString: _NS("UDP/RTP")] )
714     {
715         int i_port = [o_net_udp_port intValue];
716
717         o_mrl_string = [NSString stringWithString: @"udp://"]; 
718
719         if( i_port != config_GetInt( p_intf, "server-port" ) )
720         {
721             o_mrl_string = 
722                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port]; 
723         } 
724     }
725     else if( [o_mode isEqualToString: _NS("UDP/RTP Multicast")] ) 
726     {
727         NSString *o_addr = [o_net_udpm_addr stringValue];
728         int i_port = [o_net_udpm_port intValue];
729
730         o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr]; 
731
732         if( i_port != config_GetInt( p_intf, "server-port" ) )
733         {
734             o_mrl_string = 
735                 [o_mrl_string stringByAppendingFormat: @":%i", i_port]; 
736         } 
737     }
738     else if( [o_mode isEqualToString: _NS("HTTP/FTP/MMS/RTSP")] )
739     {
740         NSString *o_url = [o_net_http_url stringValue];
741
742         if ( ![o_url hasPrefix:@"http:"] && ![o_url hasPrefix:@"ftp:"]
743               && ![o_url hasPrefix:@"mms"] && ![o_url hasPrefix:@"rtsp"] )
744             o_mrl_string = [NSString stringWithFormat: @"http://%@", o_url];
745         else
746             o_mrl_string = o_url;
747     }
748     [o_mrl setStringValue: o_mrl_string];
749 }
750
751 - (void)openFile
752 {
753     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
754     int i;
755     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
756     
757     [o_open_panel setAllowsMultipleSelection: YES];
758     [o_open_panel setCanChooseDirectories: YES];
759     [o_open_panel setTitle: _NS("Open File")];
760     [o_open_panel setPrompt: _NS("Open")];
761     
762     if( [o_open_panel runModalForDirectory: nil
763             file: nil types: nil] == NSOKButton )
764     {
765         NSArray *o_array = [NSArray array];
766         NSArray *o_values = [[o_open_panel filenames]
767                 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
768
769         for( i = 0; i < (int)[o_values count]; i++)
770         {
771             NSDictionary *o_dic;
772             o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
773             o_array = [o_array arrayByAddingObject: o_dic];
774         }
775         if( b_autoplay )
776             [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
777         else
778             [o_playlist appendArray: o_array atPos: -1 enqueue:YES];
779     }
780 }
781
782 - (IBAction)subsChanged:(id)sender
783 {
784     if ([o_file_sub_ckbox state] == NSOnState)
785     {
786         [o_file_sub_btn_settings setEnabled:YES];
787     }
788     else
789     {
790         [o_file_sub_btn_settings setEnabled:NO];
791     }
792 }
793
794 - (IBAction)subSettings:(id)sender
795 {
796     [NSApp beginSheet: o_file_sub_sheet
797         modalForWindow: [sender window]
798         modalDelegate: self
799         didEndSelector: NULL
800         contextInfo: nil];
801 }
802
803 - (IBAction)subFileBrowse:(id)sender
804 {
805     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
806     
807     [o_open_panel setAllowsMultipleSelection: NO];
808     [o_open_panel setTitle: _NS("Open File")];
809     [o_open_panel setPrompt: _NS("Open")];
810
811     if( [o_open_panel runModalForDirectory: nil 
812             file: nil types: nil] == NSOKButton )
813     {
814         NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
815         [o_file_sub_path setStringValue: o_filename];
816     }
817 }
818
819 - (IBAction)subOverride:(id)sender
820 {
821     BOOL b_state = [o_file_sub_override state];
822     [o_file_sub_delay setEnabled: b_state];
823     [o_file_sub_delay_stp setEnabled: b_state];
824     [o_file_sub_fps setEnabled: b_state];
825     [o_file_sub_fps_stp setEnabled: b_state];
826 }
827
828 - (IBAction)subDelayStepperChanged:(id)sender
829 {
830     [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
831 }
832
833 - (IBAction)subFpsStepperChanged:(id)sender;
834 {
835     [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
836 }
837
838 - (IBAction)subCloseSheet:(id)sender
839 {
840     [o_file_sub_sheet orderOut:sender];
841     [NSApp endSheet: o_file_sub_sheet];
842 }
843
844 - (IBAction)panelCancel:(id)sender
845 {
846     [NSApp stopModalWithCode: 0];
847 }
848
849 - (IBAction)panelOk:(id)sender
850 {
851     if( [[o_mrl stringValue] length] )
852     {
853         [NSApp stopModalWithCode: 1];
854     }
855     else
856     {
857         NSBeep();
858     }
859 }
860
861 @end
862
863 @implementation VLCOpenTextField
864
865 - (void)mouseDown:(NSEvent *)theEvent
866 {
867     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
868                                                         object: self];
869     [super mouseDown: theEvent];
870 }
871
872 @end
873