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