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