]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
* modules/gui/macosx/*:
[vlc] / modules / gui / macosx / open.m
1 /*****************************************************************************
2  * open.m: MacOS X plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2002-2003 VideoLAN
5  * $Id: open.m,v 1.28 2003/04/09 14:12:49 hartman Exp $
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  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdlib.h>                                      /* malloc(), free() */
30 #include <sys/param.h>                                    /* for MAXPATHLEN */
31 #include <string.h>
32
33 #include <paths.h>
34 #include <IOKit/IOKitLib.h>
35 #include <IOKit/IOBSD.h>
36 #include <IOKit/storage/IOMedia.h>
37 #include <IOKit/storage/IOCDMedia.h>
38 #include <IOKit/storage/IODVDMedia.h>
39
40 #include "intf.h"
41 #include "playlist.h"
42 #include "open.h"
43
44 #include "netutils.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( kIOMediaEjectable ), 
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( kIOBSDName ),
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 - (void)awakeFromNib
133 {
134     intf_thread_t * p_intf = [NSApp getIntf];
135     char * psz_sout = config_GetPsz( p_intf, "sout" );
136
137     if ( psz_sout != NULL && *psz_sout )
138     {
139         [o_sout_cbox setState: YES];
140     }
141     else
142     {
143         [o_sout_cbox setState: NO];
144     }
145     free(psz_sout);
146
147     [o_panel setTitle: _NS("Open Source")];
148     [o_mrl_lbl setTitle: _NS("Media Resource Locator (MRL)")];
149     [o_ckbox_enqueue setTitle: _NS("Only enqueue in playlist, do not play")];
150
151     [o_btn_ok setTitle: _NS("OK")];
152     [o_btn_cancel setTitle: _NS("Cancel")];
153
154     [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
155     [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
156     [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
157
158     [o_file_btn_browse setTitle: _NS("Browse...")];
159     [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
160
161     [o_disc_device_lbl setStringValue: _NS("Device name")];
162     [o_disc_title_lbl setStringValue: _NS("Title")];
163     [o_disc_chapter_lbl setStringValue: _NS("Chapter")];
164     [o_disc_videots_btn_browse setTitle: _NS("Browse...")];
165     [o_disc_dvd_menus setTitle: _NS("Use DVD menus (EXPERIMENTAL)")];
166
167     [[o_disc_type cellAtRow:0 column:0] setTitle: _NS("VIDEO_TS folder")];
168     [[o_disc_type cellAtRow:1 column:0] setTitle: _NS("DVD")];
169     [[o_disc_type cellAtRow:2 column:0] setTitle: _NS("VCD")];
170
171     [o_net_udp_port_lbl setStringValue: _NS("Port")];
172     [o_net_udpm_addr_lbl setStringValue: _NS("Address")];
173     [o_net_udpm_port_lbl setStringValue: _NS("Port")];
174     [o_net_http_url_lbl setStringValue: _NS("URL")];
175
176     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("UDP/RTP")];
177     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("UDP/RTP Multicast")];
178     [[o_net_mode cellAtRow:2 column:0] setTitle: _NS("HTTP/FTP/MMS")];
179
180     [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
181     [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
182
183     [o_sout_cbox setTitle: _NS("Stream output:")];
184     [o_sout_btn_ok setTitle: _NS("OK")];
185     [o_sout_settings setTitle: _NS("Settings...")];
186     [o_sout_mrl_lbl setTitle: _NS("Stream output MRL")];
187     
188     [o_sout_access_lbl setTitle: _NS("Output Method")];
189     [[o_sout_access cellAtRow:0 column:0] setTitle: _NS("File")];
190     [[o_sout_access cellAtRow:1 column:0] setTitle: _NS("HTTP")];
191     [[o_sout_access cellAtRow:2 column:0] setTitle: _NS("UDP")];
192     [[o_sout_access cellAtRow:3 column:0] setTitle: _NS("RTP")];
193
194     [o_sout_file_btn_browse setTitle: _NS("Browse...")];
195     [o_sout_udp_addr_lbl setStringValue: _NS("Address")];
196     [o_sout_udp_port_lbl setStringValue: _NS("Port")];
197
198     [o_sout_mux_lbl setTitle: _NS("Encapsulation Method")];
199     [[o_sout_mux cellAtRow:0 column:0] setTitle: _NS("MPEG TS")];
200     [[o_sout_mux cellAtRow:0 column:1] setTitle: _NS("MPEG PS")];
201     [[o_sout_mux cellAtRow:0 column:2] setTitle: _NS("AVI")];
202     [[o_sout_mux cellAtRow:0 column:3] setTitle: _NS("Ogg")];
203     
204     [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
205     [o_file_sub_btn_settings setTitle: _NS("Settings...")];
206     [o_file_sub_btn_browse setTitle: _NS("Browse...")];
207     [o_file_sub_override setTitle: _NS("Override")];
208     [o_file_sub_delay_lbl setStringValue: _NS("delay")];
209     [o_file_sub_delay_stp setEnabled: NO];
210     [o_file_sub_fps_lbl setStringValue: _NS("fps")];
211     [o_file_sub_fps_stp setEnabled: NO];
212     [o_file_sub_ok_btn setStringValue: _NS("OK")];
213     
214     [[NSNotificationCenter defaultCenter] addObserver: self
215         selector: @selector(openFilePathChanged:)
216         name: NSControlTextDidChangeNotification
217         object: o_file_path];
218
219     [[NSNotificationCenter defaultCenter] addObserver: self
220         selector: @selector(openDiscInfoChanged:)
221         name: NSControlTextDidChangeNotification
222         object: o_disc_device];
223     [[NSNotificationCenter defaultCenter] addObserver: self
224         selector: @selector(openDiscInfoChanged:)
225         name: NSControlTextDidChangeNotification
226         object: o_disc_title];
227     [[NSNotificationCenter defaultCenter] addObserver: self
228         selector: @selector(openDiscInfoChanged:)
229         name: NSControlTextDidChangeNotification
230         object: o_disc_chapter];
231     [[NSNotificationCenter defaultCenter] addObserver: self
232         selector: @selector(openDiscInfoChanged:)
233         name: NSControlTextDidChangeNotification
234         object: o_disc_videots_folder];
235
236     [[NSNotificationCenter defaultCenter] addObserver: self
237         selector: @selector(openNetInfoChanged:)
238         name: NSControlTextDidChangeNotification
239         object: o_net_udp_port];
240     [[NSNotificationCenter defaultCenter] addObserver: self
241         selector: @selector(openNetInfoChanged:)
242         name: NSControlTextDidChangeNotification
243         object: o_net_udpm_addr];
244     [[NSNotificationCenter defaultCenter] addObserver: self
245         selector: @selector(openNetInfoChanged:)
246         name: NSControlTextDidChangeNotification
247         object: o_net_udpm_port];
248     [[NSNotificationCenter defaultCenter] addObserver: self
249         selector: @selector(openNetInfoChanged:)
250         name: NSControlTextDidChangeNotification
251         object: o_net_http_url];
252
253     [[NSNotificationCenter defaultCenter] addObserver: self
254         selector: @selector(soutInfoChanged:)
255         name: NSControlTextDidChangeNotification
256         object: o_sout_file_path];
257     [[NSNotificationCenter defaultCenter] addObserver: self
258         selector: @selector(soutInfoChanged:)
259         name: NSControlTextDidChangeNotification
260         object: o_sout_udp_addr];
261     [[NSNotificationCenter defaultCenter] addObserver: self
262         selector: @selector(soutInfoChanged:)
263         name: NSControlTextDidChangeNotification
264         object: o_sout_udp_port];
265 }
266
267 - (void)openTarget:(int)i_type
268 {
269     int i_result;
270
271     [o_tabview selectTabViewItemAtIndex: i_type];
272     [o_ckbox_enqueue setState: NSOnState];
273     [o_file_sub_ckbox setState: NSOffState];
274     
275     i_result = [NSApp runModalForWindow: o_panel];
276     [o_panel close];
277
278     if( i_result )
279     {
280         NSString *o_sout = [o_sout_mrl stringValue];
281         intf_thread_t * p_intf = [NSApp getIntf];
282         
283         if ( [o_sout_cbox state] )
284         {
285             config_PutPsz( p_intf, "sout", [o_sout lossyCString] );
286         }
287
288         NSString *o_source = [o_mrl stringValue];
289         BOOL b_enq = [o_ckbox_enqueue state] == NSOnState ? YES : NO;
290         NSString *subPath = [o_file_sub_path stringValue];
291         
292         [o_playlist appendArray: 
293             [NSArray arrayWithObject: o_source] atPos: -1 enqueue:b_enq];
294         
295         if (([o_file_sub_ckbox state] == NSOnState) && !([subPath isEqualTo: @""]))
296         {
297             config_PutPsz( p_intf, "sub-file", strdup( [subPath cString] ) );
298             if ( [o_file_sub_override state] )
299             {
300                 config_PutInt( p_intf, "sub-delay", (int)( [o_file_sub_delay intValue] * 10 ) );
301                 config_PutFloat( p_intf, "sub-fps", [o_file_sub_fps floatValue] );
302             }
303         }
304         else
305         {
306             config_PutPsz( p_intf, "sub-file", "" );
307             config_PutInt( p_intf, "sub-delay", 0 );
308             config_PutFloat( p_intf, "sub-fps", 0.0 );
309         }
310     }
311     [self soutModeChanged: nil];
312 }
313
314 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
315 {
316     NSString *o_label = [o_tvi label];
317
318     if( [o_label isEqualToString: _NS("File")] )
319     {
320         [self openFilePathChanged: nil];
321     }
322     else if( [o_label isEqualToString: _NS("Disc")] )
323     {
324         [self openDiscTypeChanged: nil];
325     }
326     else if( [o_label isEqualToString: _NS("Network")] )
327     {
328         [self openNetModeChanged: nil];
329     }  
330 }
331
332 - (IBAction)openFileGeneric:(id)sender
333 {
334     [self openFilePathChanged: nil];
335     [self openTarget: 0];
336 }
337
338 - (IBAction)openDisc:(id)sender
339 {
340     [self openDiscTypeChanged: nil];
341     [self openTarget: 1];
342 }
343
344 - (IBAction)openNet:(id)sender
345 {
346     [self openNetModeChanged: nil];
347     [self openTarget: 2];
348 }
349
350 - (void)openFilePathChanged:(NSNotification *)o_notification
351 {
352     NSString *o_mrl_string;
353     NSString *o_filename = [o_file_path stringValue];
354     NSString *o_ext = [o_filename pathExtension];
355     vlc_bool_t b_stream = [o_file_stream state];
356     BOOL b_dir = NO;
357     
358     [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
359
360     if( b_dir )
361     {
362         o_mrl_string = [NSString stringWithFormat: @"dir:%@", o_filename];
363     }
364     else if( [o_ext isEqualToString: @"bin"] ||
365         [o_ext isEqualToString: @"cue"] ||
366         [o_ext isEqualToString: @"vob"] ||
367         [o_ext isEqualToString: @"iso"] )
368     {
369         o_mrl_string = o_filename;
370     }
371     else
372     {
373         o_mrl_string = [NSString stringWithFormat: @"%s://%@",
374                         b_stream ? "stream" : "file",
375                         o_filename];
376     }
377     [o_mrl setStringValue: o_mrl_string]; 
378 }
379
380 - (IBAction)openFileBrowse:(id)sender
381 {
382     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
383     
384     [o_open_panel setAllowsMultipleSelection: NO];
385     [o_open_panel setCanChooseDirectories: YES];
386     [o_open_panel setTitle: _NS("Open File")];
387     [o_open_panel setPrompt: _NS("Open")];
388
389     [o_open_panel beginSheetForDirectory:nil
390         file:nil
391         types:nil
392         modalForWindow:[sender window]
393         modalDelegate: self
394         didEndSelector: @selector(pathChosenInPanel: 
395                         withReturn:
396                         contextInfo:)
397         contextInfo: nil];
398 }
399
400 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void  *)contextInfo
401 {
402     if (returnCode == NSFileHandlingPanelOKButton)
403     {
404         NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
405         [o_file_path setStringValue: o_filename];
406         [self openFilePathChanged: nil];
407     }
408 }
409
410 - (IBAction)openFileStreamChanged:(id)sender
411 {
412     [self openFilePathChanged: nil];
413 }
414
415 - (IBAction)openDiscTypeChanged:(id)sender
416 {
417     NSString *o_type;
418     vlc_bool_t b_device, b_menus, b_title_chapter;
419     
420     [o_disc_device removeAllItems];
421     b_title_chapter = ![o_disc_dvd_menus state];
422     
423     o_type = [[o_disc_type selectedCell] title];
424
425     if ( [o_type isEqualToString: _NS("VIDEO_TS folder")] )
426     {
427         b_device = 0; b_menus = 1;
428     }
429     else
430     {
431         NSArray *o_devices;
432         NSString *o_disc;
433         const char *psz_class = NULL;
434         b_device = 1;
435
436         if ( [o_type isEqualToString: _NS("VCD")] )
437         {
438             psz_class = kIOCDMediaClass;
439             o_disc = o_type;
440             b_menus = 0; b_title_chapter = 1;
441             [o_disc_dvd_menus setState: FALSE];
442         }
443         else
444         {
445             psz_class = kIODVDMediaClass;
446             o_disc = o_type;
447             b_menus = 1;
448         }
449     
450         o_devices = GetEjectableMediaOfClass( psz_class );
451         if ( o_devices != nil )
452         {
453             int i_devices = [o_devices count];
454         
455             if ( i_devices )
456             {
457                 int i;
458         
459                 for( i = 0; i < i_devices; i++ )
460                 {
461                     [o_disc_device 
462                         addItemWithObjectValue: [o_devices objectAtIndex: i]];
463                 }
464
465                 [o_disc_device selectItemAtIndex: 0];
466             }
467             else
468             {
469                 [o_disc_device setStringValue: 
470                     [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
471             }
472         }
473     }
474
475     [o_disc_device setEnabled: b_device];
476     [o_disc_title setEnabled: b_title_chapter];
477     [o_disc_title_stp setEnabled: b_title_chapter];
478     [o_disc_chapter setEnabled: b_title_chapter];
479     [o_disc_chapter_stp setEnabled: b_title_chapter];
480     [o_disc_videots_folder setEnabled: !b_device];
481     [o_disc_videots_btn_browse setEnabled: !b_device];
482     [o_disc_dvd_menus setEnabled: b_menus];
483
484     [self openDiscInfoChanged: nil];
485 }
486
487 - (IBAction)openDiscStepperChanged:(id)sender
488 {
489     int i_tag = [sender tag];
490
491     if( i_tag == 0 )
492     {
493         [o_disc_title setIntValue: [o_disc_title_stp intValue]];
494     }
495     else if( i_tag == 1 )
496     {
497         [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
498     }
499
500     [self openDiscInfoChanged: nil];
501 }
502
503 - (void)openDiscInfoChanged:(NSNotification *)o_notification
504 {
505     NSString *o_type;
506     NSString *o_device;
507     NSString *o_videots;
508     NSString *o_mrl_string;
509     int i_title, i_chapter;
510     vlc_bool_t b_menus;
511
512     o_type = [[o_disc_type selectedCell] title];
513     o_device = [o_disc_device stringValue];
514     i_title = [o_disc_title intValue];
515     i_chapter = [o_disc_chapter intValue];
516     o_videots = [o_disc_videots_folder stringValue];
517     b_menus = [o_disc_dvd_menus state];
518
519     if ( [o_type isEqualToString: _NS("VCD")] )
520     {
521         if ( [o_device isEqualToString:
522                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
523             o_device = @"";
524         o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i,%i",
525                         o_device, i_title, i_chapter]; 
526     }
527     else if ( [o_type isEqualToString: _NS("DVD")] )
528     {
529         if ( [o_device isEqualToString:
530                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
531             o_device = @"";
532         if ( b_menus )
533             o_mrl_string = [NSString stringWithFormat: @"dvdplay://%@",
534                             o_device]; 
535         else
536             o_mrl_string = [NSString stringWithFormat: @"dvdold://%@@%i,%i",
537                             o_device, i_title, i_chapter]; 
538     }
539     else /* VIDEO_TS folder */
540     {
541         if ( b_menus )
542             o_mrl_string = [NSString stringWithFormat: @"dvdplay://%@",
543                             o_videots]; 
544         else
545             o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i,%i",
546                             o_videots, i_title, i_chapter]; 
547     }
548
549     [o_mrl setStringValue: o_mrl_string]; 
550 }
551
552 - (IBAction)openDiscMenusChanged:(id)sender
553 {
554     [self openDiscInfoChanged: nil];
555     [self openDiscTypeChanged: nil];
556 }
557
558 - (IBAction)openVTSBrowse:(id)sender
559 {
560     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
561
562     [o_open_panel setAllowsMultipleSelection: NO];
563     [o_open_panel setCanChooseFiles: NO];
564     [o_open_panel setCanChooseDirectories: YES];
565     [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
566     [o_open_panel setPrompt: _NS("Open")];
567
568     if( [o_open_panel runModalForDirectory: nil
569             file: nil types: nil] == NSOKButton )
570     {
571         NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
572         [o_disc_videots_folder setStringValue: o_dirname];
573         [self openDiscInfoChanged: nil];
574     }
575 }
576
577 - (IBAction)openNetModeChanged:(id)sender
578 {
579     NSString *o_mode;
580     BOOL b_udp = FALSE;
581     BOOL b_udpm = FALSE;
582     BOOL b_http = FALSE;
583
584     o_mode = [[o_net_mode selectedCell] title];
585
586     if( [o_mode isEqualToString: _NS("UDP/RTP")] ) b_udp = TRUE;   
587     else if( [o_mode isEqualToString: _NS("UDP/RTP Multicast")] ) b_udpm = TRUE;
588     else if( [o_mode isEqualToString: _NS("HTTP/FTP/MMS")] ) b_http = TRUE;
589
590     [o_net_udp_port setEnabled: b_udp];
591     [o_net_udp_port_stp setEnabled: b_udp];
592     [o_net_udpm_addr setEnabled: b_udpm];
593     [o_net_udpm_port setEnabled: b_udpm];
594     [o_net_udpm_port_stp setEnabled: b_udpm];
595     [o_net_http_url setEnabled: b_http];
596
597     [self openNetInfoChanged: nil];
598 }
599
600 - (IBAction)openNetStepperChanged:(id)sender
601 {
602     int i_tag = [sender tag];
603
604     if( i_tag == 0 )
605     {
606         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
607     }
608     else if( i_tag == 1 )
609     {
610         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
611     }
612
613     [self openNetInfoChanged: nil];
614 }
615
616 - (void)openNetInfoChanged:(NSNotification *)o_notification
617 {
618     NSString *o_mode;
619     NSString *o_mrl_string = [NSString string];
620     intf_thread_t * p_intf = [NSApp getIntf];
621
622     o_mode = [[o_net_mode selectedCell] title];
623
624     if( [o_mode isEqualToString: _NS("UDP/RTP")] )
625     {
626         int i_port = [o_net_udp_port intValue];
627
628         o_mrl_string = [NSString stringWithString: @"udp://"]; 
629
630         if( i_port != config_GetInt( p_intf, "server-port" ) )
631         {
632             o_mrl_string = 
633                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port]; 
634         } 
635     }
636     else if( [o_mode isEqualToString: _NS("UDP/RTP Multicast")] ) 
637     {
638         NSString *o_addr = [o_net_udpm_addr stringValue];
639         int i_port = [o_net_udpm_port intValue];
640
641         o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr]; 
642
643         if( i_port != config_GetInt( p_intf, "server-port" ) )
644         {
645             o_mrl_string = 
646                 [o_mrl_string stringByAppendingFormat: @":%i", i_port]; 
647         } 
648     }
649     else if( [o_mode isEqualToString: _NS("HTTP/FTP/MMS")] )
650     {
651         NSString *o_url = [o_net_http_url stringValue];
652
653         if ( ![o_url hasPrefix:@"http:"] && ![o_url hasPrefix:@"ftp:"]
654               && ![o_url hasPrefix:@"mms"] )
655             o_mrl_string = [NSString stringWithFormat: @"http://%@", o_url];
656         else
657             o_mrl_string = o_url;
658     }
659
660     [o_mrl setStringValue: o_mrl_string];
661 }
662
663 - (IBAction)soutChanged:(id)sender;
664 {
665     if ([o_sout_cbox state] == NSOnState)
666     {
667         [o_sout_settings setEnabled:YES];
668     }
669     else
670     {
671         [o_sout_settings setEnabled:NO];
672     }
673 }
674
675 - (IBAction)soutSettings:(id)sender
676 {
677     [self soutModeChanged: nil];
678     [NSApp beginSheet: o_sout_sheet
679         modalForWindow: [sender window]
680         modalDelegate: self
681         didEndSelector: NULL
682         contextInfo: nil];
683 }
684
685 - (IBAction)soutFileBrowse:(id)sender
686 {
687     NSSavePanel *o_save_panel = [NSSavePanel savePanel];
688     NSString *o_mux_string;
689     if ( [[[o_sout_mux selectedCell] title] isEqualToString: _NS("MPEG PS")] )
690         o_mux_string = @"vob";
691     else if ( [[[o_sout_mux selectedCell] title] isEqualToString: _NS("AVI")] )
692         o_mux_string = @"avi";
693     else if ( [[[o_sout_mux selectedCell] title] isEqualToString: _NS("Ogg")] )
694         o_mux_string = @"ogm";
695     else
696         o_mux_string = @"ts";
697
698     NSString * o_name = [NSString stringWithFormat: @"vlc-output.%@",
699                          o_mux_string];
700
701     [o_save_panel setTitle: _NS("Save File")];
702     [o_save_panel setPrompt: _NS("Save")];
703
704     if( [o_save_panel runModalForDirectory: nil
705             file: o_name] == NSOKButton )
706     {
707         NSString *o_filename = [o_save_panel filename];
708         [o_sout_file_path setStringValue: o_filename];
709         [self soutInfoChanged: nil];
710     }
711 }
712
713 - (void)soutModeChanged:(NSNotification *)o_notification
714 {
715     NSString *o_mode;
716     BOOL b_file = FALSE;
717     BOOL b_net = FALSE;
718
719     o_mode = [[o_sout_access selectedCell] title];
720
721     if( [o_mode isEqualToString: _NS("File")] ) b_file = TRUE;   
722     else if( [o_mode isEqualToString: _NS("UDP")] ) b_net = TRUE;
723     else if( [o_mode isEqualToString: _NS("RTP")] ) b_net = TRUE;
724
725     [o_sout_file_path setEnabled: b_file];
726     [o_sout_file_btn_browse setEnabled: b_file];
727     [o_sout_udp_addr setEnabled: !b_file];
728     [o_sout_udp_port setEnabled: !b_file];
729     [o_sout_udp_port_stp setEnabled: !b_file ];
730     
731     [[o_sout_mux cellAtRow:0 column: 1] setEnabled: !b_net];
732     [[o_sout_mux cellAtRow:0 column: 2] setEnabled: !b_net];
733     [[o_sout_mux cellAtRow:0 column: 3] setEnabled: !b_net];
734     if ( b_net )
735     {
736         [o_sout_mux selectCellAtRow:0 column: 0];
737     }
738
739     [self soutInfoChanged: nil];
740 }
741
742 - (void)soutInfoChanged:(NSNotification *)o_notification
743 {
744     NSString *o_mode;
745     NSString *o_mux;
746     NSString *o_mrl_string;
747     NSString *o_mux_string;
748
749     o_mode = [[o_sout_access selectedCell] title];
750     o_mux = [[o_sout_mux selectedCell] title];
751
752     if ( [o_mux isEqualToString: _NS("AVI")] ) o_mux_string = @"avi";
753     else if ( [o_mux isEqualToString: _NS("Ogg")] ) o_mux_string = @"ogg";
754     else if ( [o_mux isEqualToString: _NS("MPEG PS")] ) o_mux_string = @"ps";
755     else o_mux_string = @"ts";
756
757     if ( [o_mode isEqualToString: _NS("File")] )
758     {
759         o_mrl_string = [NSString stringWithFormat: @"file/%@://%@",
760                         o_mux_string, [o_sout_file_path stringValue]];
761     }
762     else if ( [o_mode isEqualToString: _NS("HTTP")] )
763     {
764         o_mrl_string = [NSString stringWithFormat: @"http/%@://%@:%i",
765                         o_mux_string, [o_sout_udp_addr stringValue],
766                         [o_sout_udp_port intValue]];
767     }
768     else if ( [o_mode isEqualToString: _NS("UDP")] )
769     {
770         o_mrl_string = [NSString stringWithFormat: @"udp/%@://%@:%i",
771                         o_mux_string, [o_sout_udp_addr stringValue],
772                         [o_sout_udp_port intValue]];
773     }
774     else
775     {
776         o_mrl_string = [NSString stringWithFormat: @"rtp/%@://%@:%i",
777                         o_mux_string, [o_sout_udp_addr stringValue],
778                         [o_sout_udp_port intValue]];
779     }
780
781
782     [o_sout_mrl setStringValue: o_mrl_string];
783 }
784
785 - (IBAction)soutStepperChanged:(id)sender
786 {
787     [o_sout_udp_port setIntValue: [o_sout_udp_port_stp intValue]];
788     [self soutInfoChanged: nil];
789 }
790
791 - (IBAction)soutCloseSheet:(id)sender
792 {
793     [o_sout_sheet orderOut:sender];
794     [NSApp endSheet: o_sout_sheet];
795 }
796
797 - (IBAction)openFile:(id)sender
798 {
799     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
800     
801     [o_open_panel setAllowsMultipleSelection: YES];
802     [o_open_panel setCanChooseDirectories: YES];
803     [o_open_panel setTitle: _NS("Open File")];
804     [o_open_panel setPrompt: _NS("Open")];
805     
806     if( [o_open_panel runModalForDirectory: nil
807             file: nil types: nil] == NSOKButton )
808     {
809         intf_thread_t * p_intf = [NSApp getIntf];
810         config_PutPsz( p_intf, "sout", NULL );
811         
812         NSArray *o_values = [[o_open_panel filenames]
813                 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
814         
815         [o_playlist appendArray: o_values atPos: -1 enqueue:NO];
816     }
817 }
818
819 - (IBAction)subsChanged:(id)sender
820 {
821     if ([o_file_sub_ckbox state] == NSOnState)
822     {
823         [o_file_sub_btn_settings setEnabled:YES];
824     }
825     else
826     {
827         [o_file_sub_btn_settings setEnabled:NO];
828     }
829 }
830
831 - (IBAction)subSettings:(id)sender
832 {
833     [NSApp beginSheet: o_file_sub_sheet
834         modalForWindow: [sender window]
835         modalDelegate: self
836         didEndSelector: NULL
837         contextInfo: nil];
838 }
839
840 - (IBAction)subFileBrowse:(id)sender
841 {
842     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
843     
844     [o_open_panel setAllowsMultipleSelection: NO];
845     [o_open_panel setTitle: _NS("Open File")];
846     [o_open_panel setPrompt: _NS("Open")];
847
848     if( [o_open_panel runModalForDirectory: nil 
849             file: nil types: nil] == NSOKButton )
850     {
851         NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
852         [o_file_sub_path setStringValue: o_filename];
853     }
854 }
855
856 - (IBAction)subOverride:(id)sender
857 {
858     BOOL b_state = [o_file_sub_override state];
859     [o_file_sub_delay setEnabled: b_state];
860     [o_file_sub_delay_stp setEnabled: b_state];
861     [o_file_sub_fps setEnabled: b_state];
862     [o_file_sub_fps_stp setEnabled: b_state];
863 }
864
865 - (IBAction)subDelayStepperChanged:(id)sender
866 {
867     [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
868 }
869
870 - (IBAction)subFpsStepperChanged:(id)sender;
871 {
872     [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
873 }
874
875 - (IBAction)subCloseSheet:(id)sender
876 {
877     [o_file_sub_sheet orderOut:sender];
878     [NSApp endSheet: o_file_sub_sheet];
879 }
880
881 - (IBAction)panelCancel:(id)sender
882 {
883     [NSApp stopModalWithCode: 0];
884 }
885
886 - (IBAction)panelOk:(id)sender
887 {
888     if( [[o_mrl stringValue] length] )
889     {
890         [NSApp stopModalWithCode: 1];
891     }
892     else
893     {
894         NSBeep();
895     }
896 }
897
898 @end