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