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