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