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