]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
* seperated the open, sout and sub-open dialogues from the main nib
[vlc] / modules / gui / macosx / open.m
1 /*****************************************************************************
2  * open.m: MacOS X module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002-2003 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)getReady
151 {
152     [NSBundle loadNibNamed:@"Open" owner:self];
153 }
154
155 - (void)awakeFromNib
156 {
157     intf_thread_t * p_intf = VLCIntf;
158
159     [o_panel setTitle: _NS("Open Source")];
160     [o_mrl_lbl setTitle: _NS("Media Resource Locator (MRL)")];
161
162     [o_btn_ok setTitle: _NS("OK")];
163     [o_btn_cancel setTitle: _NS("Cancel")];
164
165     [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
166     [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
167     [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
168
169     [o_file_btn_browse setTitle: _NS("Browse...")];
170     [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
171
172     [o_disc_device_lbl setStringValue: _NS("Device name")];
173     [o_disc_title_lbl setStringValue: _NS("Title")];
174     [o_disc_chapter_lbl setStringValue: _NS("Chapter")];
175     [o_disc_videots_btn_browse setTitle: _NS("Browse...")];
176     [o_disc_dvd_menus setTitle: _NS("Use DVD menus")];
177
178     [[o_disc_type cellAtRow:0 column:0] setTitle: _NS("VIDEO_TS folder")];
179     [[o_disc_type cellAtRow:1 column:0] setTitle: _NS("DVD")];
180     [[o_disc_type cellAtRow:2 column:0] setTitle: _NS("VCD")];
181     [[o_disc_type cellAtRow:3 column:0] setTitle: _NS("Audio CD")];
182
183     [o_net_udp_port_lbl setStringValue: _NS("Port")];
184     [o_net_udpm_addr_lbl setStringValue: _NS("Address")];
185     [o_net_udpm_port_lbl setStringValue: _NS("Port")];
186     [o_net_http_url_lbl setStringValue: _NS("URL")];
187
188     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("UDP/RTP")];
189     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("UDP/RTP Multicast")];
190     [[o_net_mode cellAtRow:2 column:0] setTitle: _NS("HTTP/FTP/MMS/RTSP")];
191
192     [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
193     [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
194
195     [self setSubPanel];
196
197
198     [[NSNotificationCenter defaultCenter] addObserver: self
199         selector: @selector(openFilePathChanged:)
200         name: NSControlTextDidChangeNotification
201         object: o_file_path];
202
203     [[NSNotificationCenter defaultCenter] addObserver: self
204         selector: @selector(openDiscInfoChanged:)
205         name: NSControlTextDidChangeNotification
206         object: o_disc_device];
207     [[NSNotificationCenter defaultCenter] addObserver: self
208         selector: @selector(openDiscInfoChanged:)
209         name: NSControlTextDidChangeNotification
210         object: o_disc_title];
211     [[NSNotificationCenter defaultCenter] addObserver: self
212         selector: @selector(openDiscInfoChanged:)
213         name: NSControlTextDidChangeNotification
214         object: o_disc_chapter];
215     [[NSNotificationCenter defaultCenter] addObserver: self
216         selector: @selector(openDiscInfoChanged:)
217         name: NSControlTextDidChangeNotification
218         object: o_disc_videots_folder];
219
220     [[NSNotificationCenter defaultCenter] addObserver: self
221         selector: @selector(openNetInfoChanged:)
222         name: NSControlTextDidChangeNotification
223         object: o_net_udp_port];
224     [[NSNotificationCenter defaultCenter] addObserver: self
225         selector: @selector(openNetInfoChanged:)
226         name: NSControlTextDidChangeNotification
227         object: o_net_udpm_addr];
228     [[NSNotificationCenter defaultCenter] addObserver: self
229         selector: @selector(openNetInfoChanged:)
230         name: NSControlTextDidChangeNotification
231         object: o_net_udpm_port];
232     [[NSNotificationCenter defaultCenter] addObserver: self
233         selector: @selector(openNetInfoChanged:)
234         name: NSControlTextDidChangeNotification
235         object: o_net_http_url];
236 }
237
238 - (void)setSubPanel
239 {
240     intf_thread_t * p_intf = VLCIntf;
241     int i_index;
242     module_config_t * p_item;
243
244     [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
245     [o_file_sub_btn_settings setTitle: _NS("Settings...")];
246     [o_file_sub_btn_browse setTitle: _NS("Browse...")];
247     [o_file_sub_override setTitle: _NS("Override")];
248     [o_file_sub_delay_lbl setStringValue: _NS("delay")];
249     [o_file_sub_delay_stp setEnabled: NO];
250     [o_file_sub_fps_lbl setStringValue: _NS("fps")];
251     [o_file_sub_fps_stp setEnabled: NO];
252     [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
253     [o_file_sub_encoding_pop removeAllItems];
254     [o_file_sub_size_lbl setStringValue: _NS("Font size")];
255     [o_file_sub_size_pop removeAllItems];
256     [o_file_sub_align_lbl setStringValue: _NS("Subtitles justification")];
257     [o_file_sub_align_pop removeAllItems];
258     [o_file_sub_ok_btn setStringValue: _NS("OK")];
259     [o_file_sub_font_box setTitle: _NS("Font Properties")];
260     [o_file_sub_file_box setTitle: _NS("Subtitle File")];
261
262     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
263
264     if( p_item )
265     {
266         for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
267              i_index++ )
268         {
269             [o_file_sub_encoding_pop addItemWithTitle:
270                 [NSString stringWithCString:
271                 p_item->ppsz_list[i_index]]];
272         }
273         [o_file_sub_encoding_pop selectItemWithTitle:
274                 [NSString stringWithCString:
275                 p_item->psz_value]];
276     }
277
278     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
279
280     if ( p_item )
281     {
282         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
283         {
284             [o_file_sub_align_pop addItemWithTitle:
285                 [NSString stringWithUTF8String:
286                 p_item->ppsz_list_text[i_index]]];
287         }
288         [o_file_sub_align_pop selectItemAtIndex: p_item->i_value];
289     }
290
291     p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
292
293     if ( p_item )
294     {
295         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
296         {
297             [o_file_sub_size_pop addItemWithTitle:
298                 [NSString stringWithUTF8String:
299                 p_item->ppsz_list_text[i_index]]];
300             if ( p_item->i_value == p_item->pi_list[i_index] )
301             {
302                 [o_file_sub_size_pop selectItemAtIndex: i_index];
303             }
304         }
305     }
306 }
307
308 - (void)openTarget:(int)i_type
309 {
310     int i_result;
311
312     [o_tabview selectTabViewItemAtIndex: i_type];
313     [o_file_sub_ckbox setState: NSOffState];
314     
315     i_result = [NSApp runModalForWindow: o_panel];
316     [o_panel close];
317
318     if( i_result )
319     {
320         NSMutableDictionary *o_dic;
321         NSMutableArray *o_options = [NSMutableArray array];
322         unsigned int i;
323
324         o_dic = [NSMutableDictionary dictionaryWithObject: [o_mrl stringValue] forKey: @"ITEM_URL"];
325         if( [o_file_sub_ckbox state] == NSOnState )
326         {
327             intf_thread_t * p_intf = VLCIntf;
328             module_config_t * p_item;
329
330             [o_options addObject: [NSString stringWithFormat: @"sub-file=%s", [[o_file_sub_path stringValue] fileSystemRepresentation]]];
331             if( [o_file_sub_override state] == NSOnState )
332             {
333                 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
334                 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
335             }
336             [o_options addObject: [NSString stringWithFormat:
337                     @"subsdec-encoding=%@",
338                     [o_file_sub_encoding_pop titleOfSelectedItem]]];
339             [o_options addObject: [NSString stringWithFormat:
340                     @"subsdec-align=%i",
341                     [o_file_sub_align_pop indexOfSelectedItem]]];
342
343             p_item = config_FindConfig( VLC_OBJECT(p_intf),
344                                             "freetype-rel-fontsize" );
345
346             if ( p_item )
347             {
348                 [o_options addObject: [NSString stringWithFormat:
349                     @"freetype-rel-fontsize=%i",
350                     p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
351             }
352         }
353         if( [o_output_ckbox state] == NSOnState )
354         {
355             for (i = 0 ; i < [[o_sout_options getMRL] count] ; i++)
356             {
357                 [o_options addObject: [NSString stringWithString:
358                       [[(VLCOutput *)o_sout_options getMRL] objectAtIndex: i]]];
359             }
360         }
361         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
362         [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
363     }
364 }
365
366 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
367 {
368     NSString *o_label = [o_tvi label];
369
370     if( [o_label isEqualToString: _NS("File")] )
371     {
372         [self openFilePathChanged: nil];
373     }
374     else if( [o_label isEqualToString: _NS("Disc")] )
375     {
376         [self openDiscTypeChanged: nil];
377     }
378     else if( [o_label isEqualToString: _NS("Network")] )
379     {
380         [self openNetModeChanged: nil];
381     }  
382 }
383
384 - (void)openFileGeneric
385 {
386     [self openFilePathChanged: nil];
387     [self openTarget: 0];
388 }
389
390 - (void)openDisc
391 {
392     [self openDiscTypeChanged: nil];
393     [self openTarget: 1];
394 }
395
396 - (void)openNet
397 {
398     [self openNetModeChanged: nil];
399     [self openTarget: 2];
400 }
401
402 - (void)openFilePathChanged:(NSNotification *)o_notification
403 {
404     NSString *o_mrl_string;
405     NSString *o_filename = [o_file_path stringValue];
406     NSString *o_ext = [o_filename pathExtension];
407     vlc_bool_t b_stream = [o_file_stream state];
408     BOOL b_dir = NO;
409     
410     [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
411
412     if( b_dir )
413     {
414         o_mrl_string = [NSString stringWithFormat: @"dir:%@", o_filename];
415     }
416     else if( [o_ext isEqualToString: @"bin"] ||
417         [o_ext isEqualToString: @"cue"] ||
418         [o_ext isEqualToString: @"vob"] ||
419         [o_ext isEqualToString: @"iso"] )
420     {
421         o_mrl_string = o_filename;
422     }
423     else
424     {
425         o_mrl_string = [NSString stringWithFormat: @"%s://%@",
426                         b_stream ? "stream" : "file",
427                         o_filename];
428     }
429     [o_mrl setStringValue: o_mrl_string]; 
430 }
431
432 - (IBAction)openFileBrowse:(id)sender
433 {
434     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
435     
436     [o_open_panel setAllowsMultipleSelection: NO];
437     [o_open_panel setCanChooseDirectories: YES];
438     [o_open_panel setTitle: _NS("Open File")];
439     [o_open_panel setPrompt: _NS("Open")];
440
441     [o_open_panel beginSheetForDirectory:nil
442         file:nil
443         types:nil
444         modalForWindow:[sender window]
445         modalDelegate: self
446         didEndSelector: @selector(pathChosenInPanel: 
447                         withReturn:
448                         contextInfo:)
449         contextInfo: nil];
450 }
451
452 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void  *)contextInfo
453 {
454     if (returnCode == NSFileHandlingPanelOKButton)
455     {
456         NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
457         [o_file_path setStringValue: o_filename];
458         [self openFilePathChanged: nil];
459     }
460 }
461
462 - (IBAction)openFileStreamChanged:(id)sender
463 {
464     [self openFilePathChanged: nil];
465 }
466
467 - (IBAction)openDiscTypeChanged:(id)sender
468 {
469     NSString *o_type;
470     vlc_bool_t b_device, b_menus, b_title_chapter;
471     
472     [o_disc_device removeAllItems];
473     b_title_chapter = ![o_disc_dvd_menus state];
474     
475     o_type = [[o_disc_type selectedCell] title];
476
477     if ( [o_type isEqualToString: _NS("VIDEO_TS folder")] )
478     {
479         b_device = 0; b_menus = 1;
480     }
481     else
482     {
483         NSArray *o_devices;
484         NSString *o_disc;
485         const char *psz_class = NULL;
486         b_device = 1;
487
488         if ( [o_type isEqualToString: _NS("VCD")] )
489         {
490             psz_class = kIOCDMediaClass;
491             o_disc = o_type;
492             b_menus = 0; b_title_chapter = 1;
493             [o_disc_dvd_menus setState: FALSE];
494         }
495         else if ( [o_type isEqualToString: _NS("Audio CD")])
496         {
497             psz_class = kIOCDMediaClass;
498             o_disc = o_type;
499             b_menus = 0; b_title_chapter = 0;
500             [o_disc_dvd_menus setState: FALSE];
501         }
502         else
503         {
504             psz_class = kIODVDMediaClass;
505             o_disc = o_type;
506             b_menus = 1;
507         }
508     
509         o_devices = GetEjectableMediaOfClass( psz_class );
510         if ( o_devices != nil )
511         {
512             int i_devices = [o_devices count];
513         
514             if ( i_devices )
515             {
516                 int i;
517         
518                 for( i = 0; i < i_devices; i++ )
519                 {
520                     [o_disc_device 
521                         addItemWithObjectValue: [o_devices objectAtIndex: i]];
522                 }
523
524                 [o_disc_device selectItemAtIndex: 0];
525             }
526             else
527             {
528                 [o_disc_device setStringValue: 
529                     [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
530             }
531         }
532     }
533
534     [o_disc_device setEnabled: b_device];
535     [o_disc_title setEnabled: b_title_chapter];
536     [o_disc_title_stp setEnabled: b_title_chapter];
537     [o_disc_chapter setEnabled: b_title_chapter];
538     [o_disc_chapter_stp setEnabled: b_title_chapter];
539     [o_disc_videots_folder setEnabled: !b_device];
540     [o_disc_videots_btn_browse setEnabled: !b_device];
541     [o_disc_dvd_menus setEnabled: b_menus];
542
543     [self openDiscInfoChanged: nil];
544 }
545
546 - (IBAction)openDiscStepperChanged:(id)sender
547 {
548     int i_tag = [sender tag];
549
550     if( i_tag == 0 )
551     {
552         [o_disc_title setIntValue: [o_disc_title_stp intValue]];
553     }
554     else if( i_tag == 1 )
555     {
556         [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
557     }
558
559     [self openDiscInfoChanged: nil];
560 }
561
562 - (void)openDiscInfoChanged:(NSNotification *)o_notification
563 {
564     NSString *o_type;
565     NSString *o_device;
566     NSString *o_videots;
567     NSString *o_mrl_string;
568     int i_title, i_chapter;
569     vlc_bool_t b_menus;
570
571     o_type = [[o_disc_type selectedCell] title];
572     o_device = [o_disc_device stringValue];
573     i_title = [o_disc_title intValue];
574     i_chapter = [o_disc_chapter intValue];
575     o_videots = [o_disc_videots_folder stringValue];
576     b_menus = [o_disc_dvd_menus state];
577
578     if ( [o_type isEqualToString: _NS("VCD")] )
579     {
580         if ( [o_device isEqualToString:
581                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
582             o_device = @"";
583         o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i:%i",
584                         o_device, i_title, i_chapter]; 
585     }
586     else if ( [o_type isEqualToString: _NS("Audio CD")] )
587     {
588         if ( [o_device isEqualToString:
589                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
590             o_device = @"";
591         o_mrl_string = [NSString stringWithFormat: @"cdda://%@",
592                         o_device]; 
593     }
594     else if ( [o_type isEqualToString: _NS("DVD")] )
595     {
596         if ( [o_device isEqualToString:
597                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
598             o_device = @"";
599         if ( b_menus )
600             o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
601                             o_device]; 
602         else
603             o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
604                             o_device, i_title, i_chapter]; 
605     }
606     else /* VIDEO_TS folder */
607     {
608         if ( b_menus )
609             o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
610                             o_videots]; 
611         else
612             o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
613                             o_videots, i_title, i_chapter]; 
614     }
615
616     [o_mrl setStringValue: o_mrl_string]; 
617 }
618
619 - (IBAction)openDiscMenusChanged:(id)sender
620 {
621     [self openDiscInfoChanged: nil];
622     [self openDiscTypeChanged: nil];
623 }
624
625 - (IBAction)openVTSBrowse:(id)sender
626 {
627     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
628
629     [o_open_panel setAllowsMultipleSelection: NO];
630     [o_open_panel setCanChooseFiles: NO];
631     [o_open_panel setCanChooseDirectories: YES];
632     [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
633     [o_open_panel setPrompt: _NS("Open")];
634
635     if( [o_open_panel runModalForDirectory: nil
636             file: nil types: nil] == NSOKButton )
637     {
638         NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
639         [o_disc_videots_folder setStringValue: o_dirname];
640         [self openDiscInfoChanged: nil];
641     }
642 }
643
644 - (IBAction)openNetModeChanged:(id)sender
645 {
646     NSString *o_mode;
647     BOOL b_udp = FALSE;
648     BOOL b_udpm = FALSE;
649     BOOL b_http = FALSE;
650
651     o_mode = [[o_net_mode selectedCell] title];
652
653     if( [o_mode isEqualToString: _NS("UDP/RTP")] ) b_udp = TRUE;   
654     else if( [o_mode isEqualToString: _NS("UDP/RTP Multicast")] ) b_udpm = TRUE;
655     else if( [o_mode isEqualToString: _NS("HTTP/FTP/MMS/RTSP")] ) b_http = TRUE;
656
657     [o_net_udp_port setEnabled: b_udp];
658     [o_net_udp_port_stp setEnabled: b_udp];
659     [o_net_udpm_addr setEnabled: b_udpm];
660     [o_net_udpm_port setEnabled: b_udpm];
661     [o_net_udpm_port_stp setEnabled: b_udpm];
662     [o_net_http_url setEnabled: b_http];
663
664     [self openNetInfoChanged: nil];
665 }
666
667 - (IBAction)openNetStepperChanged:(id)sender
668 {
669     int i_tag = [sender tag];
670
671     if( i_tag == 0 )
672     {
673         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
674     }
675     else if( i_tag == 1 )
676     {
677         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
678     }
679
680     [self openNetInfoChanged: nil];
681 }
682
683 - (void)openNetInfoChanged:(NSNotification *)o_notification
684 {
685     NSString *o_mode;
686     NSString *o_mrl_string = [NSString string];
687     intf_thread_t * p_intf = VLCIntf;
688
689     o_mode = [[o_net_mode selectedCell] title];
690
691     if( [o_mode isEqualToString: _NS("UDP/RTP")] )
692     {
693         int i_port = [o_net_udp_port intValue];
694
695         o_mrl_string = [NSString stringWithString: @"udp://"]; 
696
697         if( i_port != config_GetInt( p_intf, "server-port" ) )
698         {
699             o_mrl_string = 
700                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port]; 
701         } 
702     }
703     else if( [o_mode isEqualToString: _NS("UDP/RTP Multicast")] ) 
704     {
705         NSString *o_addr = [o_net_udpm_addr stringValue];
706         int i_port = [o_net_udpm_port intValue];
707
708         o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr]; 
709
710         if( i_port != config_GetInt( p_intf, "server-port" ) )
711         {
712             o_mrl_string = 
713                 [o_mrl_string stringByAppendingFormat: @":%i", i_port]; 
714         } 
715     }
716     else if( [o_mode isEqualToString: _NS("HTTP/FTP/MMS/RTSP")] )
717     {
718         NSString *o_url = [o_net_http_url stringValue];
719
720         if ( ![o_url hasPrefix:@"http:"] && ![o_url hasPrefix:@"ftp:"]
721               && ![o_url hasPrefix:@"mms"] && ![o_url hasPrefix:@"rtsp"] )
722             o_mrl_string = [NSString stringWithFormat: @"http://%@", o_url];
723         else
724             o_mrl_string = o_url;
725     }
726
727     [o_mrl setStringValue: o_mrl_string];
728 }
729
730 - (void)openFile
731 {
732     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
733     int i;
734     
735     [o_open_panel setAllowsMultipleSelection: YES];
736     [o_open_panel setCanChooseDirectories: YES];
737     [o_open_panel setTitle: _NS("Open File")];
738     [o_open_panel setPrompt: _NS("Open")];
739     
740     if( [o_open_panel runModalForDirectory: nil
741             file: nil types: nil] == NSOKButton )
742     {
743         NSArray *o_array = [NSArray array];
744         NSArray *o_values = [[o_open_panel filenames]
745                 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
746
747         for( i = 0; i < (int)[o_values count]; i++)
748         {
749             NSDictionary *o_dic;
750             o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
751             o_array = [o_array arrayByAddingObject: o_dic];
752         }
753         [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
754     }
755 }
756
757 - (IBAction)subsChanged:(id)sender
758 {
759     if ([o_file_sub_ckbox state] == NSOnState)
760     {
761         [o_file_sub_btn_settings setEnabled:YES];
762     }
763     else
764     {
765         [o_file_sub_btn_settings setEnabled:NO];
766     }
767 }
768
769 - (IBAction)subSettings:(id)sender
770 {
771     [NSApp beginSheet: o_file_sub_sheet
772         modalForWindow: [sender window]
773         modalDelegate: self
774         didEndSelector: NULL
775         contextInfo: nil];
776 }
777
778 - (IBAction)subFileBrowse:(id)sender
779 {
780     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
781     
782     [o_open_panel setAllowsMultipleSelection: NO];
783     [o_open_panel setTitle: _NS("Open File")];
784     [o_open_panel setPrompt: _NS("Open")];
785
786     if( [o_open_panel runModalForDirectory: nil 
787             file: nil types: nil] == NSOKButton )
788     {
789         NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
790         [o_file_sub_path setStringValue: o_filename];
791     }
792 }
793
794 - (IBAction)subOverride:(id)sender
795 {
796     BOOL b_state = [o_file_sub_override state];
797     [o_file_sub_delay setEnabled: b_state];
798     [o_file_sub_delay_stp setEnabled: b_state];
799     [o_file_sub_fps setEnabled: b_state];
800     [o_file_sub_fps_stp setEnabled: b_state];
801 }
802
803 - (IBAction)subDelayStepperChanged:(id)sender
804 {
805     [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
806 }
807
808 - (IBAction)subFpsStepperChanged:(id)sender;
809 {
810     [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
811 }
812
813 - (IBAction)subCloseSheet:(id)sender
814 {
815     [o_file_sub_sheet orderOut:sender];
816     [NSApp endSheet: o_file_sub_sheet];
817 }
818
819 - (IBAction)panelCancel:(id)sender
820 {
821     [NSApp stopModalWithCode: 0];
822 }
823
824 - (IBAction)panelOk:(id)sender
825 {
826     if( [[o_mrl stringValue] length] )
827     {
828         [NSApp stopModalWithCode: 1];
829     }
830     else
831     {
832         NSBeep();
833     }
834 }
835
836 @end