]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
macosx: restored 10.5 SDK compatiblity
[vlc] / modules / gui / macosx / open.m
1 /*****************************************************************************
2  * open.m: Open dialogues for VLC's MacOS X port
3  *****************************************************************************
4  * Copyright (C) 2002-2011 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 Paul 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 #import <stdlib.h>                                      /* malloc(), free() */
32 #import <sys/param.h>                                    /* for MAXPATHLEN */
33
34 #import <paths.h>
35 #import <IOKit/IOBSD.h>
36 #import <IOKit/storage/IOMedia.h>
37 #import <IOKit/storage/IOCDMedia.h>
38 #import <IOKit/storage/IODVDMedia.h>
39 #import <IOKit/storage/IOBDMedia.h>
40 #import <Cocoa/Cocoa.h>
41 #import <QTKit/QTKit.h>
42
43 #import "intf.h"
44 #import "playlist.h"
45 #import "open.h"
46 #import "output.h"
47 #import "eyetv.h"
48
49 #import <vlc_url.h>
50
51 NSArray               *qtkvideoDevices;
52 #define setEyeTVUnconnected \
53 [o_capture_lbl setStringValue: _NS("No device is selected")]; \
54 [o_capture_long_lbl setStringValue: _NS("Any device is not selected.\n\nChose abailable device in above pull-down menu\n.")]; \
55 [o_capture_lbl displayIfNeeded]; \
56 [o_capture_long_lbl displayIfNeeded]; \
57 [self showCaptureView: o_capture_label_view]
58
59 #define kVLCMediaAudioCD "AudioCD"
60 #define kVLCMediaDVD "DVD"
61 #define kVLCMediaVCD "VCD"
62 #define kVLCMediaSVCD "SVCD"
63 #define kVLCMediaBD "Bluray"
64 #define kVLCMediaVideoTSFolder "VIDEO_TS"
65 #define kVLCMediaBDMVFolder "BDMV"
66 #define kVLCMediaUnknown "Unknown"
67
68
69 /*****************************************************************************
70  * VLCOpen implementation
71  *****************************************************************************/
72 @implementation VLCOpen
73
74 static VLCOpen *_o_sharedMainInstance = nil;
75
76 + (VLCOpen *)sharedInstance
77 {
78     return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
79 }
80
81 - (id)init
82 {
83     if( _o_sharedMainInstance) {
84         [self dealloc];
85     } else {
86         _o_sharedMainInstance = [super init];
87         p_intf = VLCIntf;
88     }
89  
90     return _o_sharedMainInstance;
91 }
92
93 - (void)dealloc
94 {
95     [o_specialMediaFolders release];
96     [o_opticalDevices release];
97     if( o_file_slave_path )
98         [o_file_slave_path release];
99     [o_mrl release];
100     [super dealloc];
101 }
102
103 - (void)awakeFromNib
104 {
105     [o_panel setTitle: _NS("Open Source")];
106     [o_mrl_lbl setStringValue: _NS("Media Resource Locator (MRL)")];
107
108     [o_btn_ok setTitle: _NS("Open")];
109     [o_btn_cancel setTitle: _NS("Cancel")];
110
111     [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
112     [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
113     [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
114     [[o_tabview tabViewItemAtIndex: 3] setLabel: _NS("Capture")];
115
116     [o_file_name setStringValue: @""];
117     [o_file_name_stub setStringValue: _NS("Choose a file")];
118     [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
119     [o_file_btn_browse setTitle: _NS("Browse...")];
120     [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
121     [o_file_stream setHidden: NO];
122     [o_file_slave_ckbox setTitle: _NS("Play another media synchronously")];
123     [o_file_slave_select_btn setTitle: _NS("Choose...")];
124     [o_file_slave_filename_lbl setStringValue: @""];
125     [o_file_slave_icon_well setImage: NULL];
126     [o_file_subtitles_filename_lbl setStringValue: @""];
127     [o_file_subtitles_icon_well setImage: NULL];
128
129     [o_disc_selector_pop removeAllItems];
130     [o_disc_selector_pop setHidden: NO];
131     NSString *o_videots = _NS("Open VIDEO_TS folder");
132     NSString *o_bdmv = _NS("Open BDMV folder");
133     [o_disc_nodisc_lbl setStringValue: _NS("Insert Disc")];
134     [o_disc_nodisc_videots_btn setTitle: o_videots];
135     [o_disc_nodisc_bdmv_btn setTitle: o_bdmv];
136     [o_disc_audiocd_lbl setStringValue: _NS("Audio CD")];
137     [o_disc_audiocd_trackcount_lbl setStringValue: @""];
138     [o_disc_audiocd_videots_btn setTitle: o_videots];
139     [o_disc_audiocd_bdmv_btn setTitle: o_bdmv];
140     [o_disc_dvd_lbl setStringValue: @""];
141     [o_disc_dvd_disablemenus_btn setTitle: _NS("Disable DVD menus")];
142     [o_disc_dvd_videots_btn setTitle: o_videots];
143     [o_disc_dvd_bdmv_btn setTitle: o_bdmv];
144     [o_disc_dvdwomenus_lbl setStringValue: @""];
145     [o_disc_dvdwomenus_enablemenus_btn setTitle: _NS("Enable DVD menus")];
146     [o_disc_dvdwomenus_videots_btn setTitle: o_videots];
147     [o_disc_dvdwomenus_bdmv_btn setTitle: o_bdmv];
148     [o_disc_dvdwomenus_title_lbl setStringValue: _NS("Title")];
149     [o_disc_dvdwomenus_chapter_lbl setStringValue: _NS("Chapter")];
150     [o_disc_vcd_title_lbl setStringValue: _NS("Title")];
151     [o_disc_vcd_chapter_lbl setStringValue: _NS("Chapter")];
152     [o_disc_vcd_videots_btn setTitle: o_videots];
153     [o_disc_vcd_bdmv_btn setTitle: o_bdmv];
154     [o_disc_bd_videots_btn setTitle: o_videots];
155     [o_disc_bd_bdmv_btn setTitle: o_bdmv];
156
157     [o_net_udp_port_lbl setStringValue: _NS("Port")];
158     [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
159     [o_net_udpm_port_lbl setStringValue: _NS("Port")];
160     [o_net_http_url_lbl setStringValue: _NS("URL")];
161     [o_net_help_lbl setStringValue: _NS("To Open a usual network stream (HTTP, RTSP, RTMP, MMS, FTP, etc.), just enter the URL in the field above. If you want to open a RTP or UDP stream, press the button below.")];
162     [o_net_help_udp_lbl setStringValue: _NS("If you want to open a multicast stream, enter the respective IP address given by the stream provider. In unicast mode, VLC will use your machine's IP automatically.\n\nTo open a stream using a different protocol, just press Cancel to close this sheet.")];
163     [o_net_udp_cancel_btn setTitle: _NS("Cancel")];
164     [o_net_udp_ok_btn setTitle: _NS("Open")];
165     [o_net_openUDP_btn setTitle: _NS("Open RTP/UDP Stream")];
166     [o_net_udp_mode_lbl setStringValue: _NS("Mode")];
167     [o_net_udp_protocol_lbl setStringValue: _NS("Protocol")];
168     [o_net_udp_address_lbl setStringValue: _NS("Address")];
169
170     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
171     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
172
173     [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
174     [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
175
176     [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
177
178     [o_capture_mode_pop removeAllItems];
179     [o_capture_mode_pop addItemWithTitle: _NS("Capture Device")];
180     [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
181     [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
182     [o_screen_long_lbl setStringValue: _NS("This input allows you to save, stream or display your current screen contents.")];
183     [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
184     [o_screen_left_lbl setStringValue: _NS("Subscreen left:")];
185     [o_screen_top_lbl setStringValue: _NS("Subscreen top:")];
186     [o_screen_width_lbl setStringValue: _NS("Subscreen width:")];
187     [o_screen_height_lbl setStringValue: _NS("Subscreen height:")];
188     [o_screen_follow_mouse_ckb setTitle: _NS("Follow the mouse")];
189     [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
190     [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
191     [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
192     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
193     [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
194     [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
195     [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
196     [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
197     [o_qtk_long_lbl setStringValue: _NS("This input allows you to process input signals from QuickTime-compatible video devices.\nLive Audio input is not supported.")];
198     [o_capture_width_lbl setStringValue: _NS("Image width:")];
199     [o_capture_height_lbl setStringValue: _NS("Image height:")];
200
201     [self qtkvideoDevices];
202     [o_qtk_device_pop removeAllItems];
203     msg_Dbg( VLCIntf, "Found %lu capture devices", [qtkvideoDevices count] );
204     if([qtkvideoDevices count] == 0){
205         [o_qtk_device_pop addItemWithTitle: _NS("None")];
206         [qtk_currdevice_uid release];
207     }else {
208         if (!qtk_currdevice_uid) {
209             qtk_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo] uniqueID]
210                                                                 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
211         }
212         for(int ivideo = 0; ivideo < [qtkvideoDevices count]; ivideo++){
213             QTCaptureDevice *qtk_device;
214             qtk_device = [qtkvideoDevices objectAtIndex:ivideo];
215             [o_qtk_device_pop addItemWithTitle: [qtk_device localizedDisplayName]];
216             if([[[qtk_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid]){
217                 [o_qtk_device_pop selectItemAtIndex:ivideo];
218             }
219         }
220     }
221
222     [self setSubPanel];
223
224     [[NSNotificationCenter defaultCenter] addObserver: self
225         selector: @selector(openNetInfoChanged:)
226         name: NSControlTextDidChangeNotification
227         object: o_net_udp_port];
228     [[NSNotificationCenter defaultCenter] addObserver: self
229         selector: @selector(openNetInfoChanged:)
230         name: NSControlTextDidChangeNotification
231         object: o_net_udpm_addr];
232     [[NSNotificationCenter defaultCenter] addObserver: self
233         selector: @selector(openNetInfoChanged:)
234         name: NSControlTextDidChangeNotification
235         object: o_net_udpm_port];
236     [[NSNotificationCenter defaultCenter] addObserver: self
237         selector: @selector(openNetInfoChanged:)
238         name: NSControlTextDidChangeNotification
239         object: o_net_http_url];
240
241     [[NSDistributedNotificationCenter defaultCenter] addObserver: self
242                                                         selector: @selector(eyetvChanged:)
243                                                             name: NULL
244                                                           object: @"VLCEyeTVSupport"
245                                               suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
246
247     [[NSNotificationCenter defaultCenter] addObserver: self
248                                              selector: @selector(screenFPSfieldChanged:)
249                                                  name: NSControlTextDidChangeNotification
250                                                object: o_screen_fps_fld];
251
252     /* register clicks on text fields */
253     [[NSNotificationCenter defaultCenter] addObserver: self
254                                              selector: @selector(textFieldWasClicked:)
255                                                  name: @"VLCOpenTextFieldWasClicked"
256                                                object: nil];
257
258     /* we want to be notified about removed or added media */
259     o_specialMediaFolders = [[NSMutableArray alloc] init];
260     o_opticalDevices = [[NSMutableArray alloc] init];
261     NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
262         [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidMountNotification object:nil];
263         [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidUnmountNotification object:nil];
264     [self scanOpticalMedia:nil];
265
266     [self setMRL: @""];
267 }
268
269 - (void)setMRL:(NSString *)newMRL
270 {
271     [o_mrl release];
272     o_mrl = newMRL;
273     [o_mrl retain];
274     [o_mrl_fld setStringValue: newMRL];
275     if ([o_mrl length] > 0)
276         [o_btn_ok setEnabled: YES];
277     else
278         [o_btn_ok setEnabled: NO];
279 }
280
281 - (NSString *)MRL
282 {
283     return o_mrl;
284 }
285
286 - (void)setSubPanel
287 {
288     int i_index;
289     module_config_t * p_item;
290
291     [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
292     [o_file_sub_btn_settings setTitle: _NS("Settings...")];
293     [o_file_sub_btn_browse setTitle: _NS("Browse...")];
294     [o_file_sub_override setTitle: _NS("Override parametters")];
295     [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
296     [o_file_sub_delay_stp setEnabled: NO];
297     [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
298     [o_file_sub_fps_stp setEnabled: NO];
299     [o_file_sub_encoding_lbl setStringValue: _NS("Subtitles encoding")];
300     [o_file_sub_encoding_pop removeAllItems];
301     [o_file_sub_size_lbl setStringValue: _NS("Font size")];
302     [o_file_sub_size_pop removeAllItems];
303     [o_file_sub_align_lbl setStringValue: _NS("Subtitles alignment")];
304     [o_file_sub_align_pop removeAllItems];
305     [o_file_sub_ok_btn setStringValue: _NS("OK")];
306     [o_file_sub_font_box setTitle: _NS("Font Properties")];
307     [o_file_sub_file_box setTitle: _NS("Subtitle File")];
308
309     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
310
311     if( p_item )
312     {
313         for( i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
314              i_index++ )
315         {
316             [o_file_sub_encoding_pop addItemWithTitle:
317                 [NSString stringWithUTF8String: p_item->ppsz_list[i_index]]];
318         }
319         [o_file_sub_encoding_pop selectItemWithTitle:
320                 [NSString stringWithUTF8String: p_item->value.psz]];
321     }
322
323     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
324
325     if ( p_item )
326     {
327         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
328         {
329             [o_file_sub_align_pop addItemWithTitle:
330                 [NSString stringWithUTF8String:
331                 p_item->ppsz_list_text[i_index]]];
332         }
333         [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
334     }
335
336     p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
337
338     if ( p_item )
339     {
340         for ( i_index = 0; i_index < p_item->i_list; i_index++ )
341         {
342             [o_file_sub_size_pop addItemWithTitle:
343                 [NSString stringWithUTF8String:
344                 p_item->ppsz_list_text[i_index]]];
345             if ( p_item->value.i == p_item->pi_list[i_index] )
346             {
347                 [o_file_sub_size_pop selectItemAtIndex: i_index];
348             }
349         }
350     }
351 }
352
353 - (void)openTarget:(int)i_type
354 {
355     int i_result;
356
357     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
358
359     [o_tabview selectTabViewItemAtIndex: i_type];
360     [o_file_sub_ckbox setState: NSOffState];
361  
362     i_result = [NSApp runModalForWindow: o_panel];
363     [o_panel close];
364
365     if( i_result )
366     {
367         NSMutableDictionary *o_dic;
368         NSMutableArray *o_options = [NSMutableArray array];
369         unsigned int i;
370
371         o_dic = [NSMutableDictionary dictionaryWithObject: [self MRL] forKey: @"ITEM_URL"];
372         if( [o_file_sub_ckbox state] == NSOnState )
373         {
374             module_config_t * p_item;
375
376             [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", [o_file_sub_path stringValue]]];
377             if( [o_file_sub_override state] == NSOnState )
378             {
379                 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
380                 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
381             }
382             [o_options addObject: [NSString stringWithFormat:
383                     @"subsdec-encoding=%@",
384                     [o_file_sub_encoding_pop titleOfSelectedItem]]];
385             [o_options addObject: [NSString stringWithFormat:
386                     @"subsdec-align=%i",
387                     [o_file_sub_align_pop indexOfSelectedItem]]];
388
389             p_item = config_FindConfig( VLC_OBJECT(p_intf),
390                                             "freetype-rel-fontsize" );
391
392             if ( p_item )
393             {
394                 [o_options addObject: [NSString stringWithFormat:
395                     @"freetype-rel-fontsize=%i",
396                     p_item->pi_list[[o_file_sub_size_pop indexOfSelectedItem]]]];
397             }
398         }
399         if( [o_output_ckbox state] == NSOnState )
400         {
401             for (i = 0 ; i < [[o_sout_options mrl] count] ; i++)
402             {
403                 [o_options addObject: [NSString stringWithString:
404                       [[(VLCOutput *)o_sout_options mrl] objectAtIndex: i]]];
405             }
406         }
407         if( [o_file_slave_ckbox state] && o_file_slave_path )
408            [o_options addObject: [NSString stringWithFormat: @"input-slave=%@", o_file_slave_path]];
409         if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
410         {
411             if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
412             {
413                 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
414                 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
415                 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
416                 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
417                 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
418                 if( [o_screen_follow_mouse_ckb intValue] == YES )
419                     [o_options addObject: @"screen-follow-mouse"];
420                 else
421                     [o_options addObject: @"no-screen-follow-mouse"];
422             }
423             else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Capture Device")] )
424             {
425                 [o_options addObject: [NSString stringWithFormat: @"qtcapture-width=%i", [o_capture_width_fld intValue]]];
426                 [o_options addObject: [NSString stringWithFormat: @"qtcapture-height=%i", [o_capture_height_fld intValue]]];
427             }
428         }
429
430         /* apply the options to our item(s) */
431         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
432         if( b_autoplay )
433             [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
434         else
435             [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
436     }
437 }
438
439 - (IBAction)qtkChanged:(id)sender
440 {
441     NSValue *sizes = [[[[qtkvideoDevices objectAtIndex:[o_qtk_device_pop indexOfSelectedItem]] formatDescriptions] objectAtIndex: 0] attributeForKey: QTFormatDescriptionVideoEncodedPixelsSizeAttribute];
442
443     [o_capture_width_fld setIntValue: [sizes sizeValue].width];
444     [o_capture_height_fld setIntValue: [sizes sizeValue].height];
445     [o_capture_width_stp setIntValue: [o_capture_width_fld intValue]];
446     [o_capture_height_stp setIntValue: [o_capture_height_fld intValue]];
447     qtk_currdevice_uid = [[[qtkvideoDevices objectAtIndex:[o_qtk_device_pop indexOfSelectedItem]] uniqueID]
448                           stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
449     [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
450 }
451
452 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
453 {
454     NSString *o_label = [o_tvi label];
455
456     if( [o_label isEqualToString: _NS("File")] )
457     {
458         [self openFilePathChanged: nil];
459     }
460     else if( [o_label isEqualToString: _NS("Disc")] )
461     {
462         [self scanOpticalMedia: nil];
463     }
464     else if( [o_label isEqualToString: _NS("Network")] )
465     {
466         [self openNetInfoChanged: nil];
467     }
468     else if( [o_label isEqualToString: _NS("Capture")] )
469     {
470         [self openCaptureModeChanged: nil];
471     }
472 }
473
474 - (IBAction)expandMRLfieldAction:(id)sender
475 {
476     NSRect o_win_rect, o_view_rect;
477     o_win_rect = [o_panel frame];
478     o_view_rect = [o_mrl_view frame];
479
480     if( [o_mrl_btn state] == NSOffState )
481     {
482         /* we need to collaps, restore the panel size */
483         o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
484         o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
485
486         /* remove the MRL view */
487         [o_mrl_view removeFromSuperview];
488     } else {
489         /* we need to expand */
490         [o_mrl_view setFrame: NSMakeRect( 0,
491                                          [o_mrl_btn frame].origin.y,
492                                          o_view_rect.size.width,
493                                          o_view_rect.size.height )];
494         [o_mrl_view setNeedsDisplay: NO];
495         [o_mrl_view setAutoresizesSubviews: YES];
496
497         /* enlarge panel size for MRL view */
498         o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
499     }
500
501     [o_panel setFrame: o_win_rect display:YES animate: YES];
502     [o_panel displayIfNeeded];
503     if( [o_mrl_btn state] == NSOnState )
504         [[o_panel contentView] addSubview: o_mrl_view];
505 }
506
507 - (IBAction)inputSlaveAction:(id)sender
508 {
509     if( sender == o_file_slave_ckbox )
510         [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
511     else
512     {
513         NSOpenPanel *o_open_panel;
514         o_open_panel = [NSOpenPanel openPanel];
515         [o_open_panel setCanChooseFiles: YES];
516         [o_open_panel setCanChooseDirectories: NO];
517         if( [o_open_panel runModal] == NSOKButton )
518         {
519             if( o_file_slave_path )
520                 [o_file_slave_path release];
521             o_file_slave_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
522             [o_file_slave_path retain];
523         }
524     }
525     if( o_file_slave_path && [o_file_slave_ckbox state] == NSOnState)
526     {
527         [o_file_slave_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_slave_path]];
528         [o_file_slave_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_slave_path]];
529     }
530     else
531     {
532         [o_file_slave_filename_lbl setStringValue: @""];
533         [o_file_slave_icon_well setImage: NULL];
534     }
535 }
536
537 - (void)openFileGeneric
538 {
539     [self openFilePathChanged: nil];
540     [self openTarget: 0];
541 }
542
543 - (void)openDisc
544 {
545     [o_specialMediaFolders removeAllObjects];
546     [o_opticalDevices removeAllObjects];
547     [self scanOpticalMedia: nil];
548     [self openTarget: 1];
549 }
550
551 - (void)openNet
552 {
553     [self openNetInfoChanged: nil];
554     [self openTarget: 2];
555 }
556
557 - (void)openCapture
558 {
559     [self openCaptureModeChanged: nil];
560     [self openTarget: 3];
561 }
562
563 - (void)openFilePathChanged:(NSNotification *)o_notification
564 {
565     if ( o_file_path && [o_file_path length] > 0 )
566     {
567         bool b_stream = [o_file_stream state];
568         BOOL b_dir = NO;
569
570         [[NSFileManager defaultManager] fileExistsAtPath:o_file_path isDirectory:&b_dir];
571
572         char *psz_uri = make_URI([o_file_path UTF8String], "file");
573         if( !psz_uri ) return;
574
575         NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
576         NSRange offile = [o_mrl_string rangeOfString:@"file"];
577         free( psz_uri );
578
579         if( b_dir )
580             [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
581         else if( b_stream )
582             [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
583
584         [o_file_name setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_path]];
585         [o_file_name_stub setHidden: YES];
586         [o_file_stream setHidden: NO];
587         [o_file_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_path]];
588         [o_file_icon_well setHidden: NO];
589         [self setMRL: o_mrl_string];
590     }
591     else
592     {
593         [o_file_name setStringValue: @""];
594         [o_file_name_stub setHidden: NO];
595         [o_file_stream setHidden: YES];
596         [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
597         [self setMRL: @""];
598     }
599 }
600
601 - (IBAction)openFileBrowse:(id)sender
602 {
603     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
604  
605     [o_open_panel setAllowsMultipleSelection: NO];
606     [o_open_panel setCanChooseDirectories: YES];
607     [o_open_panel setTitle: _NS("Open File")];
608     [o_open_panel setPrompt: _NS("Open")];
609
610     [o_open_panel beginSheetForDirectory:nil
611         file:nil
612         types:nil
613         modalForWindow:[sender window]
614         modalDelegate: self
615         didEndSelector: @selector(pathChosenInPanel:
616                         withReturn:
617                         contextInfo:)
618         contextInfo: nil];
619 }
620
621 - (void)pathChosenInPanel: (NSOpenPanel *) sheet withReturn:(int)returnCode contextInfo:(void  *)contextInfo
622 {
623     if (returnCode == NSFileHandlingPanelOKButton)
624     {
625         if( o_file_path )
626             [o_file_path release];
627         o_file_path = [[[sheet URLs] objectAtIndex: 0] path];
628         [o_file_path retain];
629         [self openFilePathChanged: nil];
630     }
631 }
632
633 - (IBAction)openFileStreamChanged:(id)sender
634 {
635     [self openFilePathChanged: nil];
636 }
637
638 - (void)showOpticalMediaView: theView
639 {
640     NSRect o_view_rect;
641     o_view_rect = [theView frame];
642     if( o_currentOpticalMediaView )
643     {
644         [o_currentOpticalMediaView removeFromSuperviewWithoutNeedingDisplay];
645         [o_currentOpticalMediaView release];
646     }
647     [theView setFrame: NSMakeRect( 233, 0, o_view_rect.size.width, o_view_rect.size.height)];
648     [theView setNeedsDisplay: YES];
649     [theView setAutoresizesSubviews: YES];
650     [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] addSubview: theView];
651     [theView displayIfNeeded];
652     o_currentOpticalMediaView = theView;
653     [o_currentOpticalMediaView retain];
654 }
655
656 - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
657 {
658     OSStatus err;
659     FSRef ref;
660     FSVolumeRefNum actualVolume;
661     err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
662
663     // get a FSVolumeRefNum from mountPath
664     if ( noErr == err ) {
665         FSCatalogInfo   catalogInfo;
666         err = FSGetCatalogInfo ( &ref,
667                                 kFSCatInfoVolume,
668                                 &catalogInfo,
669                                 NULL,
670                                 NULL,
671                                 NULL
672                                 );
673         if ( noErr == err ) {
674             actualVolume = catalogInfo.volume;
675         }
676     }
677
678     GetVolParmsInfoBuffer volumeParms;
679     err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
680     if ( noErr != err ) {
681         msg_Err( p_intf, "error retrieving volume params, bailing out" );
682         return @"";
683     }
684
685     NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
686     return [NSString stringWithFormat:@"/dev/r%@", bsdName];
687 }
688
689 - (char *)getVolumeTypeFromMountPath:(NSString *)mountPath
690 {
691     OSStatus err;
692     FSRef ref;
693     FSVolumeRefNum actualVolume;
694     err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
695
696     // get a FSVolumeRefNum from mountPath
697     if ( noErr == err ) {
698         FSCatalogInfo   catalogInfo;
699         err = FSGetCatalogInfo ( &ref,
700                                 kFSCatInfoVolume,
701                                 &catalogInfo,
702                                 NULL,
703                                 NULL,
704                                 NULL
705                                 );
706         if ( noErr == err ) {
707             actualVolume = catalogInfo.volume;
708         }
709     }
710
711     GetVolParmsInfoBuffer volumeParms;
712     err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
713
714     CFMutableDictionaryRef      matchingDict;
715     io_service_t                        service;
716
717     matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
718     service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
719
720     char *returnValue;
721     if (IO_OBJECT_NULL != service) {
722         if (IOObjectConformsTo(service, kIOCDMediaClass)) {
723             returnValue = kVLCMediaAudioCD;
724         }
725         else if(IOObjectConformsTo(service, kIODVDMediaClass))
726             returnValue = kVLCMediaDVD;
727         else if(IOObjectConformsTo(service, kIOBDMediaClass))
728             returnValue = kVLCMediaBD;
729         else
730         {
731             if ([mountPath rangeOfString:@"VIDEO_TS"].location != NSNotFound)
732                 returnValue = kVLCMediaVideoTSFolder;
733             else if ([mountPath rangeOfString:@"BDMV"].location != NSNotFound)
734                 returnValue = kVLCMediaBDMVFolder;
735             else
736             {
737                 NSArray * topLevelItems;
738                 topLevelItems = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath: mountPath error: NULL];
739                 for (int i = 0; i < [topLevelItems count]; i++) {
740                     if([[topLevelItems objectAtIndex:i] rangeOfString:@"SVCD"].location != NSNotFound) {
741                         returnValue = kVLCMediaSVCD;
742                         break;
743                     }
744                     if([[topLevelItems objectAtIndex:i] rangeOfString:@"VCD"].location != NSNotFound) {
745                         returnValue = kVLCMediaVCD;
746                         break;
747                     }
748                 }
749                 if(!returnValue)
750                     returnValue = kVLCMediaUnknown;
751             }
752         }
753
754         IOObjectRelease(service);
755     }
756     return returnValue;
757 }
758
759 - (void)showOpticalAtIndex: (NSNumber *)n_index
760 {
761     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
762
763     unsigned int index = [n_index intValue];
764     char *diskType = [self getVolumeTypeFromMountPath:[o_opticalDevices objectAtIndex: index]];
765
766     if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder)
767     {
768         [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: index]]];
769         [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
770         [o_disc_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: [o_opticalDevices objectAtIndex: index]]];
771         NSString *pathToOpen;
772         if (diskType == kVLCMediaVideoTSFolder)
773             pathToOpen = [o_opticalDevices objectAtIndex: index];
774         else
775             pathToOpen = [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: index]];
776         if (!b_nodvdmenus) {
777             [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
778             [self showOpticalMediaView: o_disc_dvd_view];
779         } else {
780             [self setMRL: [NSString stringWithFormat: @"dvdread://%@@%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
781             [self showOpticalMediaView: o_disc_dvdwomenus_view];
782         }
783     }
784     else if (diskType == kVLCMediaAudioCD)
785     {
786         [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: index]]];
787         [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: [o_opticalDevices objectAtIndex: index] error:NULL] count] - 1]]; // minus .TOC.plist
788         [self showOpticalMediaView: o_disc_audiocd_view];
789         [o_disc_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: [o_opticalDevices objectAtIndex: index]]];
790         [self setMRL: [NSString stringWithFormat: @"cdda://%@", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: index]]]];
791     }
792     else if (diskType == kVLCMediaVCD || diskType == kVLCMediaSVCD)
793     {
794         [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: index]]];
795         [self showOpticalMediaView: o_disc_vcd_view];
796         [o_disc_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: [o_opticalDevices objectAtIndex: index]]];
797         [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: index]], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
798     }
799     else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
800     {
801         [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: index]]];
802         [self showOpticalMediaView: o_disc_bd_view];
803         [o_disc_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: [o_opticalDevices objectAtIndex: index]]];
804         if (diskType == kVLCMediaBD)
805             [self setMRL: [NSString stringWithFormat: @"bluray://%@", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: index]]]];
806         else
807             [self setMRL: [NSString stringWithFormat: @"bluray://%@", [o_opticalDevices objectAtIndex: index]]];
808     }
809     else
810     {
811         msg_Warn( VLCIntf, "unknown disk type, no idea what to display" );
812         [o_disc_icon_well setImage: [NSImage imageNamed:@"NSApplicationIcon"]];
813         [self showOpticalMediaView: o_disc_nodisc_view];
814     }
815
816     [[o_disc_icon_well image] setSize: NSMakeSize(128,128)];
817     [o_pool release];
818 }
819
820 - (void)scanOpticalMedia:(NSNotification *)o_notification
821 {
822     [o_opticalDevices removeAllObjects];
823     [o_disc_selector_pop removeAllItems];
824     [o_opticalDevices addObjectsFromArray: [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
825     if ([o_specialMediaFolders count] > 0)
826         [o_opticalDevices addObjectsFromArray: o_specialMediaFolders];
827     if ([o_opticalDevices count] > 0) {
828         for (int i = 0; i < [o_opticalDevices count] ; i++)
829             [o_disc_selector_pop addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:[o_opticalDevices objectAtIndex: i]]];
830
831         if ([o_disc_selector_pop numberOfItems] <= 1)
832             [o_disc_selector_pop setHidden: YES];
833         else
834             [o_disc_selector_pop setHidden: NO];
835
836         [NSThread detachNewThreadSelector:@selector(showOpticalAtIndex:) toTarget:self withObject:[NSNumber numberWithInt:[o_disc_selector_pop indexOfSelectedItem]]];
837     }
838     else
839     {
840         msg_Dbg( VLCIntf, "no optical media found" );
841         [o_disc_selector_pop setHidden: YES];
842         [o_disc_icon_well setImage: [NSImage imageNamed: @"NSApplicationIcon"]];
843         [self showOpticalMediaView: o_disc_nodisc_view];
844     }
845 }
846
847 - (IBAction)discSelectorChanged:(id)sender
848 {
849     [NSThread detachNewThreadSelector:@selector(showOpticalAtIndex:) toTarget:self withObject:[NSNumber numberWithInt:[o_disc_selector_pop indexOfSelectedItem]]];
850 }
851
852 - (IBAction)openSpecialMediaFolder:(id)sender
853 {
854     /* this is currently for VIDEO_TS and BDMV folders */
855     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
856
857     [o_open_panel setAllowsMultipleSelection: NO];
858     [o_open_panel setCanChooseFiles: NO];
859     [o_open_panel setCanChooseDirectories: YES];
860     [o_open_panel setTitle: [sender title]];
861     [o_open_panel setPrompt: _NS("Open")];
862
863     if ([o_open_panel runModal] == NSOKButton)
864     {
865         NSString *o_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
866         if ([o_path length] > 0 )
867         {
868             if ([o_path rangeOfString:@"VIDEO_TS"].location != NSNotFound || [o_path rangeOfString:@"BDMV"].location != NSNotFound)
869             {
870                 [o_specialMediaFolders addObject: o_path];
871                 [self scanOpticalMedia: nil];
872             }
873             else
874                 msg_Dbg( VLCIntf, "chosen directory is no suitable special media folder" );
875         }
876     }
877 }
878
879 - (IBAction)dvdreadOptionChanged:(id)sender
880 {
881     if (sender == o_disc_dvdwomenus_enablemenus_btn) {
882         b_nodvdmenus = NO;
883         [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]]]]];
884         [self showOpticalMediaView: o_disc_dvd_view];
885         return;
886     }
887     if (sender == o_disc_dvd_disablemenus_btn) {
888         b_nodvdmenus = YES;
889         [self showOpticalMediaView: o_disc_dvdwomenus_view];
890     }
891
892     if (sender == o_disc_dvdwomenus_title)
893         [o_disc_dvdwomenus_title_stp setIntValue: [o_disc_dvdwomenus_title intValue]];
894     if (sender == o_disc_dvdwomenus_title_stp)
895         [o_disc_dvdwomenus_title setIntValue: [o_disc_dvdwomenus_title_stp intValue]];
896     if (sender == o_disc_dvdwomenus_chapter)
897         [o_disc_dvdwomenus_chapter_stp setIntValue: [o_disc_dvdwomenus_chapter intValue]];
898     if (sender == o_disc_dvdwomenus_chapter_stp)
899         [o_disc_dvdwomenus_chapter setIntValue: [o_disc_dvdwomenus_chapter_stp intValue]];
900
901     [self setMRL: [NSString stringWithFormat: @"dvdread://%@@%i:%i-", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]]], [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
902 }
903
904 - (IBAction)vcdOptionChanged:(id)sender
905 {
906     if (sender == o_disc_vcd_title)
907         [o_disc_vcd_title_stp setIntValue: [o_disc_vcd_title intValue]];
908     if (sender == o_disc_vcd_title_stp)
909         [o_disc_vcd_title setIntValue: [o_disc_vcd_title_stp intValue]];
910     if (sender == o_disc_vcd_chapter)
911         [o_disc_vcd_chapter_stp setIntValue: [o_disc_vcd_chapter intValue]];
912     if (sender == o_disc_vcd_chapter_stp)
913         [o_disc_vcd_chapter setIntValue: [o_disc_vcd_chapter_stp intValue]];
914
915     [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath:[o_opticalDevices objectAtIndex: [o_disc_selector_pop indexOfSelectedItem]]], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
916 }
917
918 - (void)textFieldWasClicked:(NSNotification *)o_notification
919 {
920     if( [o_notification object] == o_net_udp_port )
921         [o_net_mode selectCellAtRow: 0 column: 0];
922     else if( [o_notification object] == o_net_udpm_addr ||
923              [o_notification object] == o_net_udpm_port )
924         [o_net_mode selectCellAtRow: 1 column: 0];
925     else
926         [o_net_mode selectCellAtRow: 2 column: 0];
927
928     [self openNetInfoChanged: nil];
929 }
930
931 - (IBAction)openNetModeChanged:(id)sender
932 {
933     if( sender == o_net_mode )
934     {
935         if( [[sender selectedCell] tag] == 0 )
936             [o_panel makeFirstResponder: o_net_udp_port];
937         else if ( [[sender selectedCell] tag] == 1 )
938             [o_panel makeFirstResponder: o_net_udpm_addr];
939         else
940             msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
941     }
942
943     [self openNetInfoChanged: nil];
944 }
945
946 - (IBAction)openNetStepperChanged:(id)sender
947 {
948     int i_tag = [sender tag];
949
950     if( i_tag == 0 )
951     {
952         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
953         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
954                                                             object: o_net_udp_port];
955         [o_panel makeFirstResponder: o_net_udp_port];
956     }
957     else if( i_tag == 1 )
958     {
959         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
960         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
961                                                             object: o_net_udpm_port];
962         [o_panel makeFirstResponder: o_net_udpm_port];
963     }
964
965     [self openNetInfoChanged: nil];
966 }
967
968 - (void)openNetInfoChanged:(NSNotification *)o_notification
969 {
970     NSString *o_mrl_string = [NSString string];
971
972     if( [o_net_udp_panel isVisible] )
973     {
974         NSString *o_mode;
975         o_mode = [[o_net_mode selectedCell] title];
976
977         if( [o_mode isEqualToString: _NS("Unicast")] )
978         {
979             int i_port = [o_net_udp_port intValue];
980
981             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
982                 o_mrl_string = [NSString stringWithString: @"udp://"];
983             else
984                 o_mrl_string = [NSString stringWithString: @"rtp://"];
985
986             if( i_port != config_GetInt( p_intf, "server-port" ) )
987             {
988                 o_mrl_string =
989                     [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
990             }
991         }
992         else if( [o_mode isEqualToString: _NS("Multicast")] )
993         {
994             NSString *o_addr = [o_net_udpm_addr stringValue];
995             int i_port = [o_net_udpm_port intValue];
996
997             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
998                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
999             else
1000                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1001
1002             if( i_port != config_GetInt( p_intf, "server-port" ) )
1003             {
1004                 o_mrl_string =
1005                     [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1006             }
1007         }
1008     }
1009     else
1010     {
1011         o_mrl_string = [o_net_http_url stringValue];
1012     }
1013     [self setMRL: o_mrl_string];
1014 }
1015
1016 - (IBAction)openNetUDPButtonAction:(id)sender
1017 {
1018     if( sender == o_net_openUDP_btn )
1019     {
1020         [NSApp beginSheet: o_net_udp_panel
1021            modalForWindow: o_panel
1022             modalDelegate: self
1023            didEndSelector: NULL
1024               contextInfo: nil];
1025         [self openNetInfoChanged: nil];
1026     }
1027     else if( sender == o_net_udp_cancel_btn )
1028     {
1029         [o_net_udp_panel orderOut: sender];
1030         [NSApp endSheet: o_net_udp_panel];
1031     }
1032     else if( sender == o_net_udp_ok_btn )
1033     {
1034         NSString *o_mrl_string = [NSString string];
1035         if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
1036         {
1037             int i_port = [o_net_udp_port intValue];
1038             
1039             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1040                 o_mrl_string = [NSString stringWithString: @"udp://"];
1041             else
1042                 o_mrl_string = [NSString stringWithString: @"rtp://"];
1043
1044             if( i_port != config_GetInt( p_intf, "server-port" ) )
1045             {
1046                 o_mrl_string =
1047                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1048             }
1049         }
1050         else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
1051         {
1052             NSString *o_addr = [o_net_udpm_addr stringValue];
1053             int i_port = [o_net_udpm_port intValue];
1054             
1055             if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
1056                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1057             else
1058                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1059
1060             if( i_port != config_GetInt( p_intf, "server-port" ) )
1061             {
1062                 o_mrl_string =
1063                 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1064             }
1065         }
1066         [self setMRL: o_mrl_string];
1067         [o_net_http_url setStringValue: o_mrl_string];
1068         [o_net_udp_panel orderOut: sender];
1069         [NSApp endSheet: o_net_udp_panel];
1070     }
1071 }
1072     
1073 - (void)openFile
1074 {
1075     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1076     int i;
1077     b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
1078  
1079     [o_open_panel setAllowsMultipleSelection: YES];
1080     [o_open_panel setCanChooseDirectories: YES];
1081     [o_open_panel setTitle: _NS("Open File")];
1082     [o_open_panel setPrompt: _NS("Open")];
1083  
1084     if( [o_open_panel runModal] == NSOKButton )
1085     {
1086         NSArray *o_array = [NSArray array];
1087         NSArray *o_values = [[o_open_panel URLs]
1088                 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
1089
1090         for( i = 0; i < (int)[o_values count]; i++)
1091         {
1092             NSDictionary *o_dic;
1093             char *psz_uri = make_URI([[[o_values objectAtIndex:i] path] UTF8String], "file");
1094             if( !psz_uri )
1095                 continue;
1096
1097             o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1098
1099             free( psz_uri );
1100
1101             o_array = [o_array arrayByAddingObject: o_dic];
1102         }
1103         if( b_autoplay )
1104             [o_playlist appendArray: o_array atPos: -1 enqueue:NO];
1105         else
1106             [o_playlist appendArray: o_array atPos: -1 enqueue:YES];
1107     }
1108 }
1109
1110 - (void)showCaptureView: theView
1111 {
1112     NSRect o_view_rect;
1113     o_view_rect = [theView frame];
1114     if( o_currentCaptureView )
1115     {
1116         [o_currentCaptureView removeFromSuperviewWithoutNeedingDisplay];
1117         [o_currentCaptureView release];
1118     }
1119     [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
1120     [theView setNeedsDisplay: YES];
1121     [theView setAutoresizesSubviews: YES];
1122     [[[o_tabview tabViewItemAtIndex: 3] view] addSubview: theView];
1123     [theView displayIfNeeded];
1124     o_currentCaptureView = theView;
1125     [o_currentCaptureView retain];
1126 }
1127
1128 - (IBAction)openCaptureModeChanged:(id)sender
1129 {
1130     if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
1131     {
1132         if( [[[VLCMain sharedInstance] eyeTVController] isEyeTVrunning] == YES )
1133         {
1134             if( [[[VLCMain sharedInstance] eyeTVController] isDeviceConnected] == YES )
1135             {
1136                 [self showCaptureView: o_eyetv_running_view];
1137                 [self setupChannelInfo];
1138             }
1139             else
1140             {
1141                 setEyeTVUnconnected;
1142             }
1143         }
1144         else
1145             [self showCaptureView: o_eyetv_notLaunched_view];
1146         [self setMRL: @""];
1147     } 
1148     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
1149     {
1150         [self showCaptureView: o_screen_view];
1151         [self setMRL: @"screen://"];
1152         [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
1153         [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
1154         [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
1155         [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
1156         [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
1157         [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
1158     }
1159     else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Capture Device")] )
1160     {
1161         [self showCaptureView: o_qtk_view];
1162         if ([o_capture_width_fld intValue] <= 0)
1163             [self qtkChanged:nil];
1164
1165         if(!qtk_currdevice_uid)
1166             [self setMRL: @""];
1167         else
1168             [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
1169     }
1170 }
1171
1172 - (IBAction)screenStepperChanged:(id)sender
1173 {
1174     [o_screen_fps_fld setFloatValue: [o_screen_fps_stp floatValue]];
1175     [o_panel makeFirstResponder: o_screen_fps_fld];
1176     [self setMRL: @"screen://"];
1177 }
1178
1179 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1180 {
1181     [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1182     if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
1183         [o_screen_fps_fld setFloatValue: 1.0];
1184     [self setMRL: @"screen://"];
1185 }
1186
1187 - (IBAction)eyetvSwitchChannel:(id)sender
1188 {
1189     if( sender == o_eyetv_nextProgram_btn )
1190     {
1191         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1192         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1193         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1194     }
1195     else if( sender == o_eyetv_previousProgram_btn )
1196     {
1197         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1198         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1199         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1200     }
1201     else if( sender == o_eyetv_channels_pop )
1202     {
1203         int chanNum = [[sender selectedItem] tag];
1204         [[[VLCMain sharedInstance] eyeTVController] selectChannel:chanNum];
1205         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1206     }
1207     else
1208         msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
1209 }
1210
1211 - (IBAction)eyetvLaunch:(id)sender
1212 {
1213     [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1214 }
1215
1216 - (IBAction)eyetvGetPlugin:(id)sender
1217 {
1218     [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1219 }
1220
1221 - (void)eyetvChanged:(NSNotification *)o_notification
1222 {
1223     if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
1224     {
1225         msg_Dbg( VLCIntf, "eyetv device was added" );
1226         [self showCaptureView: o_eyetv_running_view];
1227         [self setupChannelInfo];
1228     }
1229     else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
1230     {
1231         /* leave the channel selection like that,
1232          * switch to our "no device" tab */
1233         msg_Dbg( VLCIntf, "eyetv device was removed" );
1234         setEyeTVUnconnected;
1235     }
1236     else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
1237     {
1238         /* switch to the "launch eyetv" tab */
1239         msg_Dbg( VLCIntf, "eyetv was terminated" );
1240         [self showCaptureView: o_eyetv_notLaunched_view];
1241     }
1242     else if( [[o_notification name] isEqualToString: @"PluginInit"] )
1243     {
1244         /* we got no device yet */
1245         msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
1246         setEyeTVUnconnected;
1247     }
1248 }    
1249
1250 /* little helper method, since this code needs to be run by multiple objects */
1251 - (void)setupChannelInfo
1252 {
1253     /* set up channel selection */
1254     [o_eyetv_channels_pop removeAllItems];
1255     [o_eyetv_chn_bgbar setHidden: NO];
1256     [o_eyetv_chn_bgbar animate: self];
1257     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1258     [o_eyetv_chn_status_txt setHidden: NO];
1259  
1260     /* retrieve info */
1261     NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1262     int x = -2;
1263     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1264                                                action: nil
1265                                         keyEquivalent: @""] setTag:x++];
1266     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1267                                                action: nil
1268                                         keyEquivalent: @""] setTag:x++];
1269     if( channels ) 
1270     {
1271         NSString *channel;
1272         [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1273         while( channel = [channels nextObject] )
1274         {
1275             /* we have to add items this way, because we accept duplicates
1276              * additionally, we save a bit of time */
1277             [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
1278                                                    action: nil
1279                                             keyEquivalent: @""] setTag:++x];
1280         }
1281         /* make Tuner the default */
1282         [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] currentChannel]];
1283     }
1284  
1285     /* clean up GUI */
1286     [o_eyetv_chn_bgbar setHidden: YES];
1287     [o_eyetv_chn_status_txt setHidden: YES];
1288 }
1289
1290 - (IBAction)subsChanged:(id)sender
1291 {
1292     if ([o_file_sub_ckbox state] == NSOnState)
1293     {
1294         [o_file_sub_btn_settings setEnabled:YES];
1295         if ([[o_file_sub_path stringValue] length] > 0) {
1296             [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:[o_file_sub_path stringValue]]];
1297             [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: [o_file_sub_path stringValue]]];
1298         }
1299     }
1300     else
1301     {
1302         [o_file_sub_btn_settings setEnabled:NO];
1303         [o_file_subtitles_filename_lbl setStringValue: @""];
1304         [o_file_subtitles_icon_well setImage: NULL];
1305     }
1306 }
1307
1308 - (IBAction)subSettings:(id)sender
1309 {
1310     [NSApp beginSheet: o_file_sub_sheet
1311         modalForWindow: [sender window]
1312         modalDelegate: self
1313         didEndSelector: NULL
1314         contextInfo: nil];
1315 }
1316
1317 - (IBAction)subCloseSheet:(id)sender
1318 {
1319     [self subsChanged: nil];
1320     [o_file_sub_sheet orderOut:sender];
1321     [NSApp endSheet: o_file_sub_sheet];
1322 }
1323     
1324 - (IBAction)subFileBrowse:(id)sender
1325 {
1326     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1327  
1328     [o_open_panel setAllowsMultipleSelection: NO];
1329     [o_open_panel setTitle: _NS("Open File")];
1330     [o_open_panel setPrompt: _NS("Open")];
1331
1332     if( [o_open_panel runModal] == NSOKButton )
1333     {
1334         NSString *o_filename = [[[o_open_panel URLs] objectAtIndex: 0] path];
1335         [o_file_sub_path setStringValue: o_filename];
1336         [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_filename]];
1337         [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_filename]];
1338     }
1339 }
1340
1341 - (IBAction)subOverride:(id)sender
1342 {
1343     BOOL b_state = [o_file_sub_override state];
1344     [o_file_sub_delay setEnabled: b_state];
1345     [o_file_sub_delay_stp setEnabled: b_state];
1346     [o_file_sub_fps setEnabled: b_state];
1347     [o_file_sub_fps_stp setEnabled: b_state];
1348 }
1349
1350 - (IBAction)subDelayStepperChanged:(id)sender
1351 {
1352     [o_file_sub_delay setIntValue: [o_file_sub_delay_stp intValue]];
1353 }
1354
1355 - (IBAction)subFpsStepperChanged:(id)sender;
1356 {
1357     [o_file_sub_fps setFloatValue: [o_file_sub_fps_stp floatValue]];
1358 }
1359
1360 - (IBAction)panelCancel:(id)sender
1361 {
1362     [NSApp stopModalWithCode: 0];
1363 }
1364
1365 - (IBAction)panelOk:(id)sender
1366 {
1367     if( [[self MRL] length] )
1368         [NSApp stopModalWithCode: 1];
1369     else
1370         NSBeep();
1371 }
1372
1373 - (NSArray *)qtkvideoDevices
1374 {
1375     if (!qtkvideoDevices)
1376         [self qtkrefreshDevices];
1377     return qtkvideoDevices;
1378 }
1379
1380 - (void)qtkrefreshDevices
1381 {
1382     [qtkvideoDevices release];
1383     qtkvideoDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1384 }
1385
1386 @end
1387
1388 @implementation VLCOpenTextField
1389
1390 - (void)mouseDown:(NSEvent *)theEvent
1391 {
1392     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1393                                                         object: self];
1394     [super mouseDown: theEvent];
1395 }
1396
1397 @end