]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
499b32e78bb8340aa2a740c89c35478e0c996095
[vlc] / modules / gui / macosx / open.m
1 /*****************************************************************************
2  * open.m: MacOS X module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002-2007 the VideoLAN team
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  *          Felix K\9fhne <fkuehne at videolan dot org>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include <stdlib.h>                                      /* malloc(), free() */
32 #include <sys/param.h>                                    /* for MAXPATHLEN */
33 #include <string.h>
34
35 #include <paths.h>
36 #include <IOKit/IOKitLib.h>
37 #include <IOKit/IOBSD.h>
38 #include <IOKit/storage/IOMedia.h>
39 #include <IOKit/storage/IOCDMedia.h>
40 #include <IOKit/storage/IODVDMedia.h>
41
42 #import "intf.h"
43 #import "playlist.h"
44 #import "open.h"
45 #import "output.h"
46 #import "eyetv.h"
47
48 /*****************************************************************************
49  * GetEjectableMediaOfClass 
50  *****************************************************************************/
51 NSArray *GetEjectableMediaOfClass( const char *psz_class )
52 {
53     io_object_t next_media;
54     mach_port_t master_port;
55     kern_return_t kern_result;
56     NSArray *o_devices = nil;
57     NSMutableArray *p_list = nil;
58     io_iterator_t media_iterator;
59     CFMutableDictionaryRef classes_to_match;
60
61     kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
62     if( kern_result != KERN_SUCCESS )
63     {
64         return( nil );
65     }
66     
67     classes_to_match = IOServiceMatching( psz_class );
68     if( classes_to_match == NULL )
69     {
70         return( nil );
71     }
72     
73     CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectableKey ), 
74                           kCFBooleanTrue );
75     
76     kern_result = IOServiceGetMatchingServices( master_port, classes_to_match, 
77                                                 &media_iterator );
78     if( kern_result != KERN_SUCCESS )
79     {
80         return( nil );
81     }
82
83     p_list = [NSMutableArray arrayWithCapacity: 1];
84     
85     next_media = IOIteratorNext( media_iterator );
86     if( next_media != nil )
87     {
88         char psz_buf[0x32];
89         size_t dev_path_length;
90         CFTypeRef str_bsd_path;
91     
92         do
93         {
94             str_bsd_path = IORegistryEntryCreateCFProperty( next_media,
95                                                             CFSTR( kIOBSDNameKey ),
96                                                             kCFAllocatorDefault,
97                                                             0 );
98             if( str_bsd_path == NULL )
99             {
100                 IOObjectRelease( next_media );
101                 continue;
102             }
103             
104             snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' );
105             dev_path_length = strlen( psz_buf );
106             
107             if( CFStringGetCString( str_bsd_path,
108                                     (char*)&psz_buf + dev_path_length,
109                                     sizeof(psz_buf) - dev_path_length,
110                                     kCFStringEncodingASCII ) )
111             {
112                 [p_list addObject: [NSString stringWithCString: psz_buf]];
113             }
114             
115             CFRelease( str_bsd_path );
116             
117             IOObjectRelease( next_media );
118         
119         } while( ( next_media = IOIteratorNext( media_iterator ) ) != nil );
120     }
121     
122     IOObjectRelease( media_iterator );
123
124     o_devices = [NSArray arrayWithArray: p_list];
125
126     return( o_devices );
127 }
128
129 /*****************************************************************************
130  * VLCOpen implementation 
131  *****************************************************************************/
132 @implementation VLCOpen
133
134 static VLCOpen *_o_sharedMainInstance = nil;
135
136 + (VLCOpen *)sharedInstance
137 {
138     return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
139 }
140
141 - (id)init
142 {
143     if( _o_sharedMainInstance) {
144         [self dealloc];
145     } else {
146         _o_sharedMainInstance = [super init];
147     }
148     
149     return _o_sharedMainInstance;
150 }
151
152 - (void)awakeFromNib
153 {
154     intf_thread_t * p_intf = VLCIntf;
155
156     [o_panel setTitle: _NS("Open Source")];
157     [o_mrl_lbl setTitle: _NS("Media Resource Locator (MRL)")];
158
159     [o_btn_ok setTitle: _NS("OK")];
160     [o_btn_cancel setTitle: _NS("Cancel")];
161
162     [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
163     [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
164     [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
165
166     [o_file_btn_browse setTitle: _NS("Browse...")];
167     [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
168
169     [o_disc_device_lbl setStringValue: _NS("Device name")];
170     [o_disc_title_lbl setStringValue: _NS("Title")];
171     [o_disc_chapter_lbl setStringValue: _NS("Chapter")];
172     [o_disc_videots_btn_browse setTitle: _NS("Browse...")];
173     [o_disc_dvd_menus setTitle: _NS("Use DVD menus")];
174
175     [[o_disc_type cellAtRow:0 column:0] setTitle: _NS("VIDEO_TS directory")];
176     [[o_disc_type cellAtRow:1 column:0] setTitle: _NS("DVD")];
177     [[o_disc_type cellAtRow:2 column:0] setTitle: _NS("VCD")];
178     [[o_disc_type cellAtRow:3 column:0] setTitle: _NS("Audio CD")];
179
180     [o_net_udp_port_lbl setStringValue: _NS("Port")];
181     [o_net_udpm_addr_lbl setStringValue: _NS("Address")];
182     [o_net_udpm_port_lbl setStringValue: _NS("Port")];
183     [o_net_http_url_lbl setStringValue: _NS("URL")];
184
185     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("UDP/RTP")];
186     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("UDP/RTP Multicast")];
187     [[o_net_mode cellAtRow:2 column:0] setTitle: _NS("HTTP/FTP/MMS/RTSP")];
188     [o_net_timeshift_ckbox setTitle: _NS("Allow timeshifting")];
189
190     [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
191     [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
192     
193     [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
194     /* FIXME: implement EyeTV l10n here */
195     
196     [self setSubPanel];
197
198
199     [[NSNotificationCenter defaultCenter] addObserver: self
200         selector: @selector(openFilePathChanged:)
201         name: NSControlTextDidChangeNotification
202         object: o_file_path];
203
204     [[NSNotificationCenter defaultCenter] addObserver: self
205         selector: @selector(openDiscInfoChanged:)
206         name: NSControlTextDidChangeNotification
207         object: o_disc_device];
208     [[NSNotificationCenter defaultCenter] addObserver: self
209         selector: @selector(openDiscInfoChanged:)
210         name: NSControlTextDidChangeNotification
211         object: o_disc_title];
212     [[NSNotificationCenter defaultCenter] addObserver: self
213         selector: @selector(openDiscInfoChanged:)
214         name: NSControlTextDidChangeNotification
215         object: o_disc_chapter];
216     [[NSNotificationCenter defaultCenter] addObserver: self
217         selector: @selector(openDiscInfoChanged:)
218         name: NSControlTextDidChangeNotification
219         object: o_disc_videots_folder];
220
221     [[NSNotificationCenter defaultCenter] addObserver: self
222         selector: @selector(openNetInfoChanged:)
223         name: NSControlTextDidChangeNotification
224         object: o_net_udp_port];
225     [[NSNotificationCenter defaultCenter] addObserver: self
226         selector: @selector(openNetInfoChanged:)
227         name: NSControlTextDidChangeNotification
228         object: o_net_udpm_addr];
229     [[NSNotificationCenter defaultCenter] addObserver: self
230         selector: @selector(openNetInfoChanged:)
231         name: NSControlTextDidChangeNotification
232         object: o_net_udpm_port];
233     [[NSNotificationCenter defaultCenter] addObserver: self
234         selector: @selector(openNetInfoChanged:)
235         name: NSControlTextDidChangeNotification
236         object: o_net_http_url];
237
238     /* wake up with the correct GUI */
239     if( [[[VLCMain sharedInstance] getEyeTVController] isEyeTVrunning] == YES )
240         [o_eyetv_tabView selectTabViewItemWithIdentifier:@"nodevice"];
241     if( [[[VLCMain sharedInstance] getEyeTVController] isDeviceConnected] == YES )
242     {
243         [o_eyetv_tabView selectTabViewItemWithIdentifier:@"eyetvup"];
244         [self setupChannelInfo];
245     }
246     
247     [[NSDistributedNotificationCenter defaultCenter] addObserver: self
248                                                         selector: @selector(eyetvChanged:)
249                                                             name: NULL
250                                                           object: @"VLCEyeTVSupport"
251                                               suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
252     
253     /* register clicks on text fields */
254     [[NSNotificationCenter defaultCenter] addObserver: self
255                                              selector: @selector(textFieldWasClicked:)
256                                                  name: @"VLCOpenTextFieldWasClicked"
257                                                object: nil];
258 }
259
260 - (void)setSubPanel
261 {
262     intf_thread_t * p_intf = VLCIntf;
263     int i_index;
264     module_config_t * p_item;
265
266     [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
267     [o_file_sub_btn_settings setTitle: _NS("Settings...")];
268     [o_file_sub_btn_browse setTitle: _NS("Browse...")];
269     [o_file_sub_override setTitle: _NS("Override parametters")];
270     [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
271     [o_file_sub_delay_stp setEnabled: NO];
272     [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
273     [o_file_sub_fps_stp setEnabled: NO];
274     [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
275     [o_file_sub_encoding_pop removeAllItems];
276     [o_file_sub_size_lbl setStringValue: _NS("Font size")];
277     [o_file_sub_size_pop removeAllItems];
278     [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
279     [o_file_sub_align_pop removeAllItems];
280     [o_file_sub_ok_btn setStringValue: _NS("OK")];
281     [o_file_sub_font_box setTitle: _NS("Font Properties")];
282     [o_file_sub_file_box setTitle: _NS("Subtitle File")];
283
284     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
285
286     if( p_item )
287     {
288         for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
289              i_index++ )
290         {
291             [o_file_sub_encoding_pop addItemWithTitle:
292                 [NSString stringWithCString:
293                 p_item->ppsz_list[i_index]]];
294         }
295         [o_file_sub_encoding_pop selectItemWithTitle:
296                 [NSString stringWithCString:
297                 p_item->value.psz]];
298     }
299
300     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
301
302     if ( p_item )
303     {
304         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
305         {
306             [o_file_sub_align_pop addItemWithTitle:
307                 [NSString stringWithUTF8String:
308                 p_item->ppsz_list_text[i_index]]];
309         }
310         [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
311     }
312
313     p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
314
315     if ( p_item )
316     {
317         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
318         {
319             [o_file_sub_size_pop addItemWithTitle:
320                 [NSString stringWithUTF8String:
321                 p_item->ppsz_list_text[i_index]]];
322             if ( p_item->value.i == p_item->pi_list[i_index] )
323             {
324                 [o_file_sub_size_pop selectItemAtIndex: i_index];
325             }
326         }
327     }
328 }
329
330 - (void)openTarget:(int)i_type
331 {
332     int i_result;
333     intf_thread_t * p_intf = VLCIntf;
334
335     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
336
337     [o_tabview selectTabViewItemAtIndex: i_type];
338     [o_file_sub_ckbox setState: NSOffState];
339     
340     i_result = [NSApp runModalForWindow: o_panel];
341     [o_panel close];
342
343     if( i_result )
344     {
345         NSMutableDictionary *o_dic;
346         NSMutableArray *o_options = [NSMutableArray array];
347         unsigned int i;
348
349         o_dic = [NSMutableDictionary dictionaryWithObject: [o_mrl stringValue] forKey: @"ITEM_URL"];
350         if( [o_file_sub_ckbox state] == NSOnState )
351         {
352             module_config_t * p_item;
353
354             [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", [o_file_sub_path stringValue]]];
355             if( [o_file_sub_override state] == NSOnState )
356             {
357                 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
358                 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
359             }
360             [o_options addObject: [NSString stringWithFormat:
361                     @"subsdec-encoding=%@",
362                     [o_file_sub_encoding_pop titleOfSelectedItem]]];
363             [o_options addObject: [NSString stringWithFormat:
364                     @"subsdec-align=%i",
365                     [o_file_sub_align_pop indexOfSelectedItem]]];
366
367             p_item = config_FindConfig( VLC_OBJECT(p_intf),
368                                             "freetype-rel-fontsize" );
369
370             if ( p_item )
371             {
372                 [o_options addObject: [NSString stringWithFormat:
373                     @"freetype-rel-fontsize=%i",
374                     p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
375             }
376         }
377         if( [o_output_ckbox state] == NSOnState )
378         {
379             for (i = 0 ; i < [[o_sout_options getMRL] count] ; i++)
380             {
381                 [o_options addObject: [NSString stringWithString:
382                       [[(VLCOutput *)o_sout_options getMRL] objectAtIndex: i]]];
383             }
384         }
385         if( [o_net_timeshift_ckbox state] == NSOnState )
386         {
387             [o_options addObject: [NSString stringWithString:
388                                                 @"access-filter=timeshift"]];
389         }
390         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
391         if( b_autoplay )
392             [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
393         else
394             [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
395     }
396 }
397
398 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
399 {
400     NSString *o_label = [o_tvi label];
401
402     if( [o_label isEqualToString: _NS("File")] )
403     {
404         [self openFilePathChanged: nil];
405     }
406     else if( [o_label isEqualToString: _NS("Disc")] )
407     {
408         [self openDiscTypeChanged: nil];
409     }
410     else if( [o_label isEqualToString: _NS("Network")] )
411     {
412         [self openNetInfoChanged: nil];
413     }  
414 }
415
416 - (void)openFileGeneric
417 {
418     [self openFilePathChanged: nil];
419     [self openTarget: 0];
420 }
421
422 - (void)openDisc
423 {
424     [self openDiscTypeChanged: nil];
425     [self openTarget: 1];
426 }
427
428 - (void)openNet
429 {
430     [self openNetInfoChanged: nil];
431     [self openTarget: 2];
432 }
433
434 - (void)openFilePathChanged:(NSNotification *)o_notification
435 {
436     NSString *o_mrl_string;
437     NSString *o_filename = [o_file_path stringValue];
438     NSString *o_ext = [o_filename pathExtension];
439     vlc_bool_t b_stream = [o_file_stream state];
440     BOOL b_dir = NO;
441     
442     [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
443
444     if( b_dir )
445     {
446         o_mrl_string = [NSString stringWithFormat: @"dir:%@", o_filename];
447     }
448     else if( [o_ext isEqualToString: @"bin"] ||
449         [o_ext isEqualToString: @"cue"] ||
450         [o_ext isEqualToString: @"vob"] ||
451         [o_ext isEqualToString: @"iso"] )
452     {
453         o_mrl_string = o_filename;
454     }
455     else
456     {
457         o_mrl_string = [NSString stringWithFormat: @"%s://%@",
458                         b_stream ? "stream" : "file",
459                         o_filename];
460     }
461     [o_mrl setStringValue: o_mrl_string]; 
462 }
463
464 - (IBAction)openFileBrowse:(id)sender
465 {
466     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
467     
468     [o_open_panel setAllowsMultipleSelection: NO];
469     [o_open_panel setCanChooseDirectories: YES];
470     [o_open_panel setTitle: _NS("Open File")];
471     [o_open_panel setPrompt: _NS("Open")];
472
473     [o_open_panel beginSheetForDirectory:nil
474         file:nil
475         types:nil
476         modalForWindow:[sender window]
477         modalDelegate: self
478         didEndSelector: @selector(pathChosenInPanel: 
479                         withReturn:
480                         contextInfo:)
481         contextInfo: nil];
482 }
483
484 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void  *)contextInfo
485 {
486     if (returnCode == NSFileHandlingPanelOKButton)
487     {
488         NSString *o_filename = [[sheet filenames] objectAtIndex: 0];
489         [o_file_path setStringValue: o_filename];
490         [self openFilePathChanged: nil];
491     }
492 }
493
494 - (IBAction)openFileStreamChanged:(id)sender
495 {
496     [self openFilePathChanged: nil];
497 }
498
499 - (IBAction)openDiscTypeChanged:(id)sender
500 {
501     NSString *o_type;
502     vlc_bool_t b_device, b_menus, b_title_chapter;
503     
504     [o_disc_device removeAllItems];
505     b_title_chapter = ![o_disc_dvd_menus state];
506     
507     o_type = [[o_disc_type selectedCell] title];
508
509     if ( [o_type isEqualToString: _NS("VIDEO_TS directory")] )
510     {
511         b_device = 0; b_menus = 1;
512     }
513     else
514     {
515         NSArray *o_devices;
516         NSString *o_disc;
517         const char *psz_class = NULL;
518         b_device = 1;
519
520         if ( [o_type isEqualToString: _NS("VCD")] )
521         {
522             psz_class = kIOCDMediaClass;
523             o_disc = o_type;
524             b_menus = 0; b_title_chapter = 1;
525             [o_disc_dvd_menus setState: FALSE];
526         }
527         else if ( [o_type isEqualToString: _NS("Audio CD")])
528         {
529             psz_class = kIOCDMediaClass;
530             o_disc = o_type;
531             b_menus = 0; b_title_chapter = 0;
532             [o_disc_dvd_menus setState: FALSE];
533         }
534         else
535         {
536             psz_class = kIODVDMediaClass;
537             o_disc = o_type;
538             b_menus = 1;
539         }
540     
541         o_devices = GetEjectableMediaOfClass( psz_class );
542         if ( o_devices != nil )
543         {
544             int i_devices = [o_devices count];
545         
546             if ( i_devices )
547             {
548                 int i;
549         
550                 for( i = 0; i < i_devices; i++ )
551                 {
552                     [o_disc_device 
553                         addItemWithObjectValue: [o_devices objectAtIndex: i]];
554                 }
555
556                 [o_disc_device selectItemAtIndex: 0];
557             }
558             else
559             {
560                 [o_disc_device setStringValue: 
561                     [NSString stringWithFormat: _NS("No %@s found"), o_disc]];
562             }
563         }
564     }
565
566     [o_disc_device setEnabled: b_device];
567     [o_disc_title setEnabled: b_title_chapter];
568     [o_disc_title_stp setEnabled: b_title_chapter];
569     [o_disc_chapter setEnabled: b_title_chapter];
570     [o_disc_chapter_stp setEnabled: b_title_chapter];
571     [o_disc_videots_folder setEnabled: !b_device];
572     [o_disc_videots_btn_browse setEnabled: !b_device];
573     [o_disc_dvd_menus setEnabled: b_menus];
574
575     [self openDiscInfoChanged: nil];
576 }
577
578 - (IBAction)openDiscStepperChanged:(id)sender
579 {
580     int i_tag = [sender tag];
581
582     if( i_tag == 0 )
583     {
584         [o_disc_title setIntValue: [o_disc_title_stp intValue]];
585     }
586     else if( i_tag == 1 )
587     {
588         [o_disc_chapter setIntValue: [o_disc_chapter_stp intValue]];
589     }
590
591     [self openDiscInfoChanged: nil];
592 }
593
594 - (void)openDiscInfoChanged:(NSNotification *)o_notification
595 {
596     NSString *o_type;
597     NSString *o_device;
598     NSString *o_videots;
599     NSString *o_mrl_string;
600     int i_title, i_chapter;
601     vlc_bool_t b_menus;
602
603     o_type = [[o_disc_type selectedCell] title];
604     o_device = [o_disc_device stringValue];
605     i_title = [o_disc_title intValue];
606     i_chapter = [o_disc_chapter intValue];
607     o_videots = [o_disc_videots_folder stringValue];
608     b_menus = [o_disc_dvd_menus state];
609
610     if ( [o_type isEqualToString: _NS("VCD")] )
611     {
612         if ( [o_device isEqualToString:
613                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
614             o_device = @"";
615         o_mrl_string = [NSString stringWithFormat: @"vcd://%@@%i:%i",
616                         o_device, i_title, i_chapter]; 
617     }
618     else if ( [o_type isEqualToString: _NS("Audio CD")] )
619     {
620         if ( [o_device isEqualToString:
621                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
622             o_device = @"";
623         o_mrl_string = [NSString stringWithFormat: @"cdda://%@",
624                         o_device]; 
625     }
626     else if ( [o_type isEqualToString: _NS("DVD")] )
627     {
628         if ( [o_device isEqualToString:
629                 [NSString stringWithFormat: _NS("No %@s found"), o_type]] )
630             o_device = @"";
631         if ( b_menus )
632             o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
633                             o_device]; 
634         else
635             o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i-",
636                             o_device, i_title, i_chapter]; 
637     }
638     else /* VIDEO_TS folder */
639     {
640         if ( b_menus )
641             o_mrl_string = [NSString stringWithFormat: @"dvdnav://%@",
642                             o_videots]; 
643         else
644             o_mrl_string = [NSString stringWithFormat: @"dvdread://%@@%i:%i",
645                             o_videots, i_title, i_chapter]; 
646     }
647
648     [o_mrl setStringValue: o_mrl_string]; 
649 }
650
651 - (IBAction)openDiscMenusChanged:(id)sender
652 {
653     [self openDiscInfoChanged: nil];
654     [self openDiscTypeChanged: nil];
655 }
656
657 - (IBAction)openVTSBrowse:(id)sender
658 {
659     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
660
661     [o_open_panel setAllowsMultipleSelection: NO];
662     [o_open_panel setCanChooseFiles: NO];
663     [o_open_panel setCanChooseDirectories: YES];
664     [o_open_panel setTitle: _NS("Open VIDEO_TS Directory")];
665     [o_open_panel setPrompt: _NS("Open")];
666
667     if( [o_open_panel runModalForDirectory: nil
668             file: nil types: nil] == NSOKButton )
669     {
670         NSString *o_dirname = [[o_open_panel filenames] objectAtIndex: 0];
671         [o_disc_videots_folder setStringValue: o_dirname];
672         [self openDiscInfoChanged: nil];
673     }
674 }
675
676 - (void)textFieldWasClicked:(NSNotification *)o_notification
677 {
678     if( [o_notification object] == o_net_udp_port )
679         [o_net_mode selectCellAtRow: 0 column: 0];
680     else if( [o_notification object] == o_net_udpm_addr ||
681              [o_notification object] == o_net_udpm_port )
682         [o_net_mode selectCellAtRow: 1 column: 0];
683     else
684         [o_net_mode selectCellAtRow: 2 column: 0];
685
686     [self openNetInfoChanged: nil];
687 }
688
689 - (IBAction)openNetModeChanged:(id)sender
690 {
691     if( [[sender selectedCell] tag] == 0 )
692         [o_panel makeFirstResponder: o_net_udp_port];
693     else if ( [[sender selectedCell] tag] == 1 )
694         [o_panel makeFirstResponder: o_net_udpm_addr];
695     else
696         [o_panel makeFirstResponder: o_net_http_url];
697
698     [self openNetInfoChanged: nil];
699 }
700
701 - (IBAction)openNetStepperChanged:(id)sender
702 {
703     int i_tag = [sender tag];
704
705     if( i_tag == 0 )
706     {
707         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
708         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked" 
709                                                             object: o_net_udp_port];
710         [o_panel makeFirstResponder: o_net_udp_port];
711     }
712     else if( i_tag == 1 )
713     {
714         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
715         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked" 
716                                                             object: o_net_udpm_port];
717         [o_panel makeFirstResponder: o_net_udpm_port];
718     }
719
720     [self openNetInfoChanged: nil];
721 }
722
723 - (void)openNetInfoChanged:(NSNotification *)o_notification
724 {
725     NSString *o_mode;
726     NSString *o_mrl_string = [NSString string];
727     intf_thread_t * p_intf = VLCIntf;
728
729     o_mode = [[o_net_mode selectedCell] title];
730
731     if( [o_mode isEqualToString: _NS("UDP/RTP")] )
732     {
733         int i_port = [o_net_udp_port intValue];
734
735         o_mrl_string = [NSString stringWithString: @"udp://"]; 
736
737         if( i_port != config_GetInt( p_intf, "server-port" ) )
738         {
739             o_mrl_string = 
740                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port]; 
741         } 
742     }
743     else if( [o_mode isEqualToString: _NS("UDP/RTP Multicast")] ) 
744     {
745         NSString *o_addr = [o_net_udpm_addr stringValue];
746         int i_port = [o_net_udpm_port intValue];
747
748         o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr]; 
749
750         if( i_port != config_GetInt( p_intf, "server-port" ) )
751         {
752             o_mrl_string = 
753                 [o_mrl_string stringByAppendingFormat: @":%i", i_port]; 
754         } 
755     }
756     else if( [o_mode isEqualToString: _NS("HTTP/FTP/MMS/RTSP")] )
757     {
758         NSString *o_url = [o_net_http_url stringValue];
759
760         if ( ![o_url hasPrefix:@"http:"] && ![o_url hasPrefix:@"ftp:"]
761               && ![o_url hasPrefix:@"mms"] && ![o_url hasPrefix:@"rtsp"] )
762             o_mrl_string = [NSString stringWithFormat: @"http://%@", o_url];
763         else
764             o_mrl_string = o_url;
765     }
766     [o_mrl setStringValue: o_mrl_string];
767 }
768
769 - (void)openFile
770 {
771     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
772     int i;
773     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
774     
775     [o_open_panel setAllowsMultipleSelection: YES];
776     [o_open_panel setCanChooseDirectories: YES];
777     [o_open_panel setTitle: _NS("Open File")];
778     [o_open_panel setPrompt: _NS("Open")];
779     
780     if( [o_open_panel runModalForDirectory: nil
781             file: nil types: nil] == NSOKButton )
782     {
783         NSArray *o_array = [NSArray array];
784         NSArray *o_values = [[o_open_panel filenames]
785                 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
786
787         for( i = 0; i < (int)[o_values count]; i++)
788         {
789             NSDictionary *o_dic;
790             o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
791             o_array = [o_array arrayByAddingObject: o_dic];
792         }
793         if( b_autoplay )
794             [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
795         else
796             [o_playlist appendArray: o_array atPos: -1 enqueue:YES];
797     }
798 }
799
800 - (IBAction)eyetvSwitchChannel:(id)sender
801 {
802     if( sender == o_eyetv_nextProgram_btn )
803         [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: YES];
804     else if( sender == o_eyetv_previousProgram_btn )
805         [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: NO];
806     else if( sender == o_eyetv_channels_pop )
807         [[[VLCMain sharedInstance] getEyeTVController] selectChannel: 
808             [sender indexOfSelectedItem]];
809     else
810         msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
811 }
812
813 - (IBAction)eyetvLaunch:(id)sender
814 {
815     [[[VLCMain sharedInstance] getEyeTVController] launchEyeTV];
816 }
817
818 - (void)eyetvChanged:(NSNotification *)o_notification
819 {
820     if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
821     {
822         msg_Dbg( VLCIntf, "eyetv device was added" );
823         [o_eyetv_tabView selectTabViewItemWithIdentifier:@"eyetvup"];
824         [self setupChannelInfo];
825     }
826     else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
827     {
828         /* leave the channel selection like that,
829          * switch to our "no device" tab */
830         msg_Dbg( VLCIntf, "eyetv device was removed" );
831         [o_eyetv_tabView selectTabViewItemWithIdentifier:@"nodevice"];
832     }
833     else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
834     {
835         /* switch to the "launch eyetv" tab */
836         msg_Dbg( VLCIntf, "eyetv was terminated" );
837         [o_eyetv_tabView selectTabViewItemWithIdentifier:@"noeyetv"];
838     }
839     else if( [[o_notification name] isEqualToString: @"PluginInit"] )
840     {
841         /* we got no device yet */
842         msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
843         [o_eyetv_tabView selectTabViewItemWithIdentifier:@"nodevice"];
844     }
845     else
846         msg_Warn( VLCIntf, "unknown external notify '%s' received", [[o_notification name] UTF8String] );
847 }
848
849 /* little helper method, since this code needs to be run by multiple objects */
850 - (void)setupChannelInfo
851 {
852     /* set up channel selection */
853     [o_eyetv_channels_pop removeAllItems];
854     [o_eyetv_chn_bgbar setHidden: NO];
855     [o_eyetv_chn_bgbar animate: self];
856     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
857     [o_eyetv_chn_status_txt setHidden: NO];
858     
859     /* retrieve info */
860     int x = 0;
861     int channelCount = ( [[[VLCMain sharedInstance] getEyeTVController] getNumberOfChannels] + 1 );
862     while( x != channelCount )
863     {
864         /* we have to add items this way, because we accept duplicates 
865          * additionally, we save a bit of time */
866         [[o_eyetv_channels_pop menu] addItemWithTitle: [[[VLCMain sharedInstance] getEyeTVController] getNameOfChannel: x]
867                                                action: nil
868                                         keyEquivalent: @""];
869         x += 1;
870     }
871     
872     /* clean up GUI */
873     [o_eyetv_chn_bgbar setHidden: YES];
874     [o_eyetv_chn_status_txt setHidden: YES];
875 }
876
877 - (IBAction)subsChanged:(id)sender
878 {
879     if ([o_file_sub_ckbox state] == NSOnState)
880     {
881         [o_file_sub_btn_settings setEnabled:YES];
882     }
883     else
884     {
885         [o_file_sub_btn_settings setEnabled:NO];
886     }
887 }
888
889 - (IBAction)subSettings:(id)sender
890 {
891     [NSApp beginSheet: o_file_sub_sheet
892         modalForWindow: [sender window]
893         modalDelegate: self
894         didEndSelector: NULL
895         contextInfo: nil];
896 }
897
898 - (IBAction)subFileBrowse:(id)sender
899 {
900     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
901     
902     [o_open_panel setAllowsMultipleSelection: NO];
903     [o_open_panel setTitle: _NS("Open File")];
904     [o_open_panel setPrompt: _NS("Open")];
905
906     if( [o_open_panel runModalForDirectory: nil 
907             file: nil types: nil] == NSOKButton )
908     {
909         NSString *o_filename = [[o_open_panel filenames] objectAtIndex: 0];
910         [o_file_sub_path setStringValue: o_filename];
911     }
912 }
913
914 - (IBAction)subOverride:(id)sender
915 {
916     BOOL b_state = [o_file_sub_override state];
917     [o_file_sub_delay setEnabled: b_state];
918     [o_file_sub_delay_stp setEnabled: b_state];
919     [o_file_sub_fps setEnabled: b_state];
920     [o_file_sub_fps_stp setEnabled: b_state];
921 }
922
923 - (IBAction)subDelayStepperChanged:(id)sender
924 {
925     [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
926 }
927
928 - (IBAction)subFpsStepperChanged:(id)sender;
929 {
930     [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
931 }
932
933 - (IBAction)subCloseSheet:(id)sender
934 {
935     [o_file_sub_sheet orderOut:sender];
936     [NSApp endSheet: o_file_sub_sheet];
937 }
938
939 - (IBAction)panelCancel:(id)sender
940 {
941     [NSApp stopModalWithCode: 0];
942 }
943
944 - (IBAction)panelOk:(id)sender
945 {
946     if( [[o_mrl stringValue] length] )
947     {
948         [NSApp stopModalWithCode: 1];
949     }
950     else
951     {
952         NSBeep();
953     }
954 }
955
956 @end
957
958 @implementation VLCOpenTextField
959
960 - (void)mouseDown:(NSEvent *)theEvent
961 {
962     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
963                                                         object: self];
964     [super mouseDown: theEvent];
965 }
966
967 @end
968