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