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