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