]> git.sesse.net Git - vlc/blob - modules/gui/macosx/open.m
macosx: drop the potential BDMV folder from a bluray path (fixes #10928)
[vlc] / modules / gui / macosx / open.m
1 /*****************************************************************************
2  * open.m: Open dialogues for VLC's MacOS X port
3  *****************************************************************************
4  * Copyright (C) 2002-2012 VLC authors and VideoLAN
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 "CompatibilityFixes.h"
35
36 #import <paths.h>
37 #import <IOKit/IOBSD.h>
38 #import <IOKit/storage/IOMedia.h>
39 #import <IOKit/storage/IOCDMedia.h>
40 #import <IOKit/storage/IODVDMedia.h>
41 #import <IOKit/storage/IOBDMedia.h>
42 #import <Cocoa/Cocoa.h>
43 #import <QTKit/QTKit.h>
44
45 #import "intf.h"
46 #import "playlist.h"
47 #import "open.h"
48 #import "output.h"
49 #import "eyetv.h"
50 #import "misc.h"
51
52 #import <vlc_url.h>
53
54 NSArray *qtkvideoDevices;
55 NSArray *qtkaudioDevices;
56 #define setEyeTVUnconnected \
57 [o_capture_lbl setStringValue: _NS("No device is selected")]; \
58 [o_capture_long_lbl setStringValue: _NS("No device is selected.\n\nChoose available device in above pull-down menu.\n")]; \
59 [o_capture_lbl displayIfNeeded]; \
60 [o_capture_long_lbl displayIfNeeded]; \
61 [self showCaptureView: o_capture_label_view]
62
63 struct display_info_t
64 {
65     CGRect rect;
66     CGDirectDisplayID id;
67 };
68
69 /*****************************************************************************
70  * VLCOpen implementation
71  *****************************************************************************/
72 @implementation VLCOpen
73
74 @synthesize fileSubDelay, fileSubFps;
75
76 #pragma mark -
77 #pragma mark Init
78
79 static VLCOpen *_o_sharedMainInstance = nil;
80
81 + (VLCOpen *)sharedInstance
82 {
83     return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
84 }
85
86 - (id)init
87 {
88     if (_o_sharedMainInstance)
89         [self dealloc];
90     else
91         _o_sharedMainInstance = [super init];
92
93     return _o_sharedMainInstance;
94 }
95
96 - (void)dealloc
97 {
98     [o_allMediaDevices release];
99     [o_specialMediaFolders release];
100     if (o_opticalDevices)
101         [o_opticalDevices release];
102     if (o_file_slave_path)
103         [o_file_slave_path release];
104     [o_mrl release];
105     if (o_sub_path)
106         [o_sub_path release];
107     [o_currentOpticalMediaIconView release];
108     [o_currentOpticalMediaView release];
109     for (int i = 0; i < [o_displayInfos count]; i ++) {
110         NSValue *v = [o_displayInfos objectAtIndex:i];
111         free([v pointerValue]);
112     }
113     [o_displayInfos removeAllObjects];
114     [o_displayInfos release];
115
116     [super dealloc];
117 }
118
119 - (void)awakeFromNib
120 {
121     if (!OSX_SNOW_LEOPARD)
122         [o_panel setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
123
124     [o_panel setTitle: _NS("Open Source")];
125     [o_mrl_lbl setStringValue: _NS("Media Resource Locator (MRL)")];
126
127     [o_btn_ok setTitle: _NS("Open")];
128     [o_btn_cancel setTitle: _NS("Cancel")];
129
130     [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
131     [o_tabview accessibilitySetOverrideValue:_NS("4 Tabs to choose between media input. Select 'File' for files, 'Disc' for optical media such as DVDs, Audio CDs or BRs, 'Network' for network streams or 'Capture' for Input Devices such as microphones or cameras, the current screen or TV streams if the EyeTV application is installed.") forAttribute:NSAccessibilityDescriptionAttribute];
132     [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
133     [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
134     [[o_tabview tabViewItemAtIndex: 3] setLabel: _NS("Capture")];
135     [o_file_name setStringValue: @""];
136     [o_file_name_stub setStringValue: _NS("Choose a file")];
137     [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
138     [o_file_btn_browse setTitle: _NS("Browse...")];
139     [[o_file_btn_browse cell] accessibilitySetOverrideValue:_NS("Click to select a file for playback") forAttribute:NSAccessibilityDescriptionAttribute];
140     [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
141     [o_file_stream setHidden: NO];
142     [o_file_slave_ckbox setTitle: _NS("Play another media synchronously")];
143     [o_file_slave_select_btn setTitle: _NS("Choose...")];
144     [[o_file_btn_browse cell] accessibilitySetOverrideValue:_NS("Click to select a another file to play it in sync with the previously selected file.") forAttribute:NSAccessibilityDescriptionAttribute];
145     [o_file_slave_filename_lbl setStringValue: @""];
146     [o_file_slave_icon_well setImage: NULL];
147     [o_file_subtitles_filename_lbl setStringValue: @""];
148     [o_file_subtitles_icon_well setImage: NULL];
149     [o_file_custom_timing_ckb setTitle: _NS("Custom playback")];
150     [o_file_starttime_lbl setStringValue: _NS("Start time")];
151     [o_file_starttime_fld setStringValue: @""];
152     [o_file_stoptime_lbl setStringValue: _NS("Stop time")];
153     [o_file_stoptime_fld setStringValue: @""];
154
155     [o_disc_selector_pop removeAllItems];
156     [o_disc_selector_pop setHidden: NO];
157     NSString *o_videots = _NS("Open VIDEO_TS / BDMV folder");
158     [o_disc_nodisc_lbl setStringValue: _NS("Insert Disc")];
159     [o_disc_nodisc_videots_btn setTitle: o_videots];
160     [o_disc_audiocd_lbl setStringValue: _NS("Audio CD")];
161     [o_disc_audiocd_trackcount_lbl setStringValue: @""];
162     [o_disc_audiocd_videots_btn setTitle: o_videots];
163     [o_disc_dvd_lbl setStringValue: @""];
164     [o_disc_dvd_disablemenus_btn setTitle: _NS("Disable DVD menus")];
165     [o_disc_dvd_videots_btn setTitle: o_videots];
166     [o_disc_dvdwomenus_lbl setStringValue: @""];
167     [o_disc_dvdwomenus_enablemenus_btn setTitle: _NS("Enable DVD menus")];
168     [o_disc_dvdwomenus_videots_btn setTitle: o_videots];
169     [o_disc_dvdwomenus_title_lbl setStringValue: _NS("Title")];
170     [o_disc_dvdwomenus_chapter_lbl setStringValue: _NS("Chapter")];
171     [o_disc_vcd_title_lbl setStringValue: _NS("Title")];
172     [o_disc_vcd_chapter_lbl setStringValue: _NS("Chapter")];
173     [o_disc_vcd_videots_btn setTitle: o_videots];
174     [o_disc_bd_videots_btn setTitle: o_videots];
175
176     [o_net_udp_port_lbl setStringValue: _NS("Port")];
177     [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
178     [o_net_udpm_port_lbl setStringValue: _NS("Port")];
179     [o_net_http_url_lbl setStringValue: _NS("URL")];
180     [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.")];
181     [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.")];
182     [[o_net_http_url cell] accessibilitySetOverrideValue:_NS("Enter a URL here to open the network stream. To open RTP or UDP streams, click on the respective button below.") forAttribute:NSAccessibilityDescriptionAttribute];
183     [o_net_udp_cancel_btn setTitle: _NS("Cancel")];
184     [o_net_udp_ok_btn setTitle: _NS("Open")];
185     [o_net_openUDP_btn setTitle: _NS("Open RTP/UDP Stream")];
186     [o_net_udp_mode_lbl setStringValue: _NS("Mode")];
187     [o_net_udp_protocol_lbl setStringValue: _NS("Protocol")];
188     [o_net_udp_address_lbl setStringValue: _NS("Address")];
189
190     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
191     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
192
193     [o_net_udp_port setIntValue: config_GetInt(VLCIntf, "server-port")];
194     [o_net_udp_port_stp setIntValue: config_GetInt(VLCIntf, "server-port")];
195
196     [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
197
198     [o_capture_mode_pop removeAllItems];
199     [o_capture_mode_pop addItemWithTitle: _NS("Input Devices")];
200     [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
201     [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
202     [o_screen_long_lbl setStringValue: _NS("This input allows you to save, stream or display your current screen contents.")];
203     [o_screen_fps_lbl setStringValue: [NSString stringWithFormat:@"%@:",_NS("Frames per Second")]];
204     [o_screen_screen_lbl setStringValue: [NSString stringWithFormat:@"%@:",_NS("Screen")]];
205     [o_screen_left_lbl setStringValue: [NSString stringWithFormat:@"%@:",_NS("Subscreen left")]];
206     [o_screen_top_lbl setStringValue: [NSString stringWithFormat:@"%@:",_NS("Subscreen top")]];
207     [o_screen_width_lbl setStringValue: [NSString stringWithFormat:@"%@:",_NS("Subscreen width")]];
208     [o_screen_height_lbl setStringValue: [NSString stringWithFormat:@"%@:",_NS("Subscreen height")]];
209     [o_screen_follow_mouse_ckb setTitle: _NS("Follow the mouse")];
210     [o_screen_qtk_audio_ckb setTitle: _NS("Capture Audio")];
211     [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
212     [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
213     [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
214     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
215     [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
216     [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
217     [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
218     [o_eyetv_getPlugin_btn setTitle: _NS("Download Plugin")];
219     [o_capture_width_lbl setStringValue: [NSString stringWithFormat:@"%@:",_NS("Image width")]];
220     [o_capture_height_lbl setStringValue: [NSString stringWithFormat:@"%@:",_NS("Image height")]];
221
222     // setup start / stop time fields
223     [o_file_starttime_fld setFormatter:[[[PositionFormatter alloc] init] autorelease]];
224     [o_file_stoptime_fld setFormatter:[[[PositionFormatter alloc] init] autorelease]];
225
226     [self qtkvideoDevices];
227     [o_qtk_video_device_pop removeAllItems];
228     msg_Dbg(VLCIntf, "Found %lu video capture devices", [qtkvideoDevices count]);
229
230     if ([qtkvideoDevices count] >= 1) {
231         if (!qtk_currdevice_uid)
232             qtk_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo] uniqueID]
233                                                                 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
234
235         NSUInteger deviceCount = [qtkvideoDevices count];
236         for (int ivideo = 0; ivideo < deviceCount; ivideo++) {
237             QTCaptureDevice *qtk_device;
238             qtk_device = [qtkvideoDevices objectAtIndex:ivideo];
239             [o_qtk_video_device_pop addItemWithTitle: [qtk_device localizedDisplayName]];
240
241             if ([[[qtk_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid])
242                 [o_qtk_video_device_pop selectItemAtIndex:ivideo];
243         }
244     } else {
245         [o_qtk_video_device_pop addItemWithTitle: _NS("None")];
246         [qtk_currdevice_uid release];
247     }
248
249     [self qtkaudioDevices];
250     [o_qtk_audio_device_pop removeAllItems];
251     [o_screen_qtk_audio_pop removeAllItems];
252     msg_Dbg(VLCIntf, "Found %lu audio capture devices", [qtkaudioDevices count]);
253
254     if ([qtkaudioDevices count] >= 1) {
255         if (!qtkaudio_currdevice_uid)
256             qtkaudio_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound] uniqueID]
257                                   stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
258
259         NSUInteger deviceCount = [qtkaudioDevices count];
260         for (int iaudio = 0; iaudio < deviceCount; iaudio++) {
261             QTCaptureDevice *qtkaudio_device;
262             qtkaudio_device = [qtkaudioDevices objectAtIndex:iaudio];
263             [o_qtk_audio_device_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
264             [o_screen_qtk_audio_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
265             if ([[[qtkaudio_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtkaudio_currdevice_uid]) {
266                 [o_qtk_audio_device_pop selectItemAtIndex:iaudio];
267                 [o_screen_qtk_audio_pop selectItemAtIndex:iaudio];
268             }
269         }
270     } else {
271         [o_qtk_audio_device_pop addItemWithTitle: _NS("None")];
272         [o_screen_qtk_audio_pop addItemWithTitle: _NS("None")];
273         [qtkaudio_currdevice_uid release];
274     }
275
276     [self setSubPanel];
277
278     [[NSNotificationCenter defaultCenter] addObserver: self
279         selector: @selector(openNetInfoChanged:)
280         name: NSControlTextDidChangeNotification
281         object: o_net_udp_port];
282     [[NSNotificationCenter defaultCenter] addObserver: self
283         selector: @selector(openNetInfoChanged:)
284         name: NSControlTextDidChangeNotification
285         object: o_net_udpm_addr];
286     [[NSNotificationCenter defaultCenter] addObserver: self
287         selector: @selector(openNetInfoChanged:)
288         name: NSControlTextDidChangeNotification
289         object: o_net_udpm_port];
290     [[NSNotificationCenter defaultCenter] addObserver: self
291         selector: @selector(openNetInfoChanged:)
292         name: NSControlTextDidChangeNotification
293         object: o_net_http_url];
294
295     [[NSDistributedNotificationCenter defaultCenter] addObserver: self
296                                                         selector: @selector(eyetvChanged:)
297                                                             name: NULL
298                                                           object: @"VLCEyeTVSupport"
299                                               suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
300
301     [[NSNotificationCenter defaultCenter] addObserver: self
302                                              selector: @selector(screenFPSfieldChanged:)
303                                                  name: NSControlTextDidChangeNotification
304                                                object: o_screen_fps_fld];
305
306     /* register clicks on text fields */
307     [[NSNotificationCenter defaultCenter] addObserver: self
308                                              selector: @selector(textFieldWasClicked:)
309                                                  name: @"VLCOpenTextFieldWasClicked"
310                                                object: nil];
311
312     /* we want to be notified about removed or added media */
313     o_allMediaDevices = [[NSMutableArray alloc] init];
314     o_specialMediaFolders = [[NSMutableArray alloc] init];
315     o_displayInfos = [[NSMutableArray alloc] init];
316     NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
317
318     [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidMountNotification object:nil];
319     [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidUnmountNotification object:nil];
320     [self performSelector:@selector(qtkToggleUIElements:) withObject:nil afterDelay:.3];
321     [self performSelector:@selector(scanOpticalMedia:) withObject:nil afterDelay:.5];
322
323     [self setMRL: @""];
324 }
325
326 - (void)setMRL:(NSString *)newMRL
327 {
328     if (!newMRL)
329         newMRL = @"";
330
331     if (o_mrl)
332         [o_mrl release];
333
334     o_mrl = newMRL;
335     [o_mrl retain];
336     [o_mrl_fld performSelectorOnMainThread:@selector(setStringValue:) withObject:o_mrl waitUntilDone:NO];
337     if ([o_mrl length] > 0)
338         [o_btn_ok setEnabled: YES];
339     else
340         [o_btn_ok setEnabled: NO];
341 }
342
343 - (NSString *)MRL
344 {
345     return o_mrl;
346 }
347
348 - (void)setSubPanel
349 {
350     int i_index;
351     module_config_t * p_item;
352     intf_thread_t * p_intf = VLCIntf;
353
354     [o_file_sub_ckbox setTitle: _NS("Add Subtitle File:")];
355     [o_file_sub_path_lbl setStringValue: _NS("Choose a file")];
356     [o_file_sub_path_lbl setHidden: NO];
357     [o_file_sub_path_fld setStringValue: @""];
358     [o_file_sub_btn_settings setTitle: _NS("Choose...")];
359     [[o_file_btn_browse cell] accessibilitySetOverrideValue:_NS("Click to setup subtitle playback in full detail.") forAttribute:NSAccessibilityDescriptionAttribute];
360     [o_file_sub_btn_browse setTitle: _NS("Browse...")];
361     [[o_file_sub_btn_browse cell] accessibilitySetOverrideValue:_NS("Click to select a subtitle file.") forAttribute:NSAccessibilityDescriptionAttribute];
362     [o_file_sub_override setTitle: _NS("Override parameters")];
363     [o_file_sub_delay_lbl setStringValue: _NS("Delay")];
364     [o_file_sub_delay_stp setEnabled: NO];
365     [o_file_sub_fps_lbl setStringValue: _NS("FPS")];
366     [o_file_sub_fps_stp setEnabled: NO];
367     [o_file_sub_encoding_lbl setStringValue: _NS("Subtitle encoding")];
368     [o_file_sub_encoding_pop removeAllItems];
369     [o_file_sub_size_lbl setStringValue: _NS("Font size")];
370     [o_file_sub_size_pop removeAllItems];
371     [o_file_sub_align_lbl setStringValue: _NS("Subtitle alignment")];
372     [o_file_sub_align_pop removeAllItems];
373     [o_file_sub_ok_btn setStringValue: _NS("OK")];
374     [[o_file_sub_ok_btn cell] accessibilitySetOverrideValue:_NS("Click to dismiss the subtitle setup dialog.") forAttribute:NSAccessibilityDescriptionAttribute];
375     [o_file_sub_font_box setTitle: _NS("Font Properties")];
376     [o_file_sub_file_box setTitle: _NS("Subtitle File")];
377
378     p_item = config_FindConfig(VLC_OBJECT(p_intf), "subsdec-encoding");
379
380     if (p_item) {
381         for (int i = 0; i < p_item->list_count; i++) {
382             [o_file_sub_encoding_pop addItemWithTitle: _NS(p_item->list_text[i])];
383             [[o_file_sub_encoding_pop lastItem] setRepresentedObject:[NSString stringWithFormat:@"%s", p_item->list.psz[i]]];
384             if (p_item->value.psz && !strcmp(p_item->value.psz, p_item->list.psz[i]))
385                 [o_file_sub_encoding_pop selectItem: [o_file_sub_encoding_pop lastItem]];
386         }
387
388         if ([o_file_sub_encoding_pop indexOfSelectedItem] < 0)
389             [o_file_sub_encoding_pop selectItemAtIndex:0];
390     }
391
392     p_item = config_FindConfig(VLC_OBJECT(p_intf), "subsdec-align");
393
394     if (p_item) {
395         for (i_index = 0; i_index < p_item->list_count; i_index++)
396             [o_file_sub_align_pop addItemWithTitle: _NS(p_item->list_text[i_index])];
397
398         [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
399     }
400
401     p_item = config_FindConfig(VLC_OBJECT(p_intf), "freetype-rel-fontsize");
402
403     if (p_item) {
404         for (i_index = 0; i_index < p_item->list_count; i_index++) {
405             [o_file_sub_size_pop addItemWithTitle: _NS(p_item->list_text[i_index])];
406
407             if (p_item->value.i == p_item->list.i[i_index])
408                 [o_file_sub_size_pop selectItemAtIndex: i_index];
409         }
410     }
411 }
412
413 - (void)openTarget:(int)i_type
414 {
415     /* check whether we already run a modal dialog */
416     if ([NSApp modalWindow] != nil)
417         return;
418
419     int i_result;
420
421     b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
422
423     [o_tabview selectTabViewItemAtIndex: i_type];
424     [o_file_sub_ckbox setState: NSOffState];
425
426     i_result = [NSApp runModalForWindow: o_panel];
427     [o_panel close];
428
429     if (i_result) {
430         NSMutableDictionary *o_dic;
431         NSMutableArray *o_options = [NSMutableArray array];
432
433         o_dic = [NSMutableDictionary dictionaryWithObject: [self MRL] forKey: @"ITEM_URL"];
434         if ([o_file_sub_ckbox state] == NSOnState) {
435             module_config_t * p_item;
436
437             [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", o_sub_path]];
438             if ([o_file_sub_override state] == NSOnState) {
439                 [o_options addObject: [NSString stringWithFormat: @"sub-delay=%f", ([self fileSubDelay] * 10)]];
440                 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [self fileSubFps]]];
441             }
442             [o_options addObject: [NSString stringWithFormat:
443                     @"subsdec-encoding=%@", [[o_file_sub_encoding_pop selectedItem] representedObject]]];
444             [o_options addObject: [NSString stringWithFormat:
445                     @"subsdec-align=%li", [o_file_sub_align_pop indexOfSelectedItem]]];
446
447             p_item = config_FindConfig(VLC_OBJECT(VLCIntf),
448                                             "freetype-rel-fontsize");
449
450             if (p_item) {
451                 [o_options addObject: [NSString stringWithFormat:
452                     @"freetype-rel-fontsize=%i",
453                     p_item->list.i[[o_file_sub_size_pop indexOfSelectedItem]]]];
454             }
455         }
456         if ([o_file_custom_timing_ckb state] == NSOnState) {
457             NSArray * components = [[o_file_starttime_fld stringValue] componentsSeparatedByString:@":"];
458             NSUInteger componentCount = [components count];
459             NSInteger tempValue = 0;
460             if (componentCount == 1)
461                 tempValue = [[components objectAtIndex:0] intValue];
462             else if (componentCount == 2)
463                 tempValue = [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue];
464             else if (componentCount == 3)
465                 tempValue = [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue];
466             if (tempValue > 0)
467                 [o_options addObject: [NSString stringWithFormat:@"start-time=%li", tempValue]];
468             components = [[o_file_stoptime_fld stringValue] componentsSeparatedByString:@":"];
469             componentCount = [components count];
470             if (componentCount == 1)
471                 tempValue = [[components objectAtIndex:0] intValue];
472             else if (componentCount == 2)
473                 tempValue = [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue];
474             else if (componentCount == 3)
475                 tempValue = [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue];
476             if (tempValue > 0)
477                 [o_options addObject: [NSString stringWithFormat:@"stop-time=%li", tempValue]];
478         }
479         if ([o_output_ckbox state] == NSOnState) {
480             NSArray * soutMRL = [o_sout_options soutMRL];
481             NSUInteger count = [soutMRL count];
482             for (NSUInteger i = 0 ; i < count ; i++)
483                 [o_options addObject: [NSString stringWithString: [soutMRL objectAtIndex:i]]];
484         }
485         if ([o_file_slave_ckbox state] && o_file_slave_path)
486            [o_options addObject: [NSString stringWithFormat: @"input-slave=%@", o_file_slave_path]];
487         if ([[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")]) {
488             if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")]) {
489                 int selected_index = [o_screen_screen_pop indexOfSelectedItem];
490                 NSValue *v = [o_displayInfos objectAtIndex:selected_index];
491                 struct display_info_t *item = (struct display_info_t *)[v pointerValue];
492
493                 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
494                 [o_options addObject: [NSString stringWithFormat: @"screen-display-id=%i", item->id]];
495                 [o_options addObject: [NSString stringWithFormat: @"screen-left=%i", [o_screen_left_fld intValue]]];
496                 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
497                 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
498                 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
499                 if ([o_screen_follow_mouse_ckb intValue] == YES)
500                     [o_options addObject: @"screen-follow-mouse"];
501                 else
502                     [o_options addObject: @"no-screen-follow-mouse"];
503                 if ([o_screen_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
504                    [o_options addObject: [NSString stringWithFormat: @"input-slave=qtsound://%@", qtkaudio_currdevice_uid]];
505             }
506             else if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")]) {
507                 if ([o_qtk_video_ckb state]) {
508                     [o_options addObject: [NSString stringWithFormat: @"qtcapture-width=%i", [o_capture_width_fld intValue]]];
509                     [o_options addObject: [NSString stringWithFormat: @"qtcapture-height=%i", [o_capture_height_fld intValue]]];
510                     if ([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
511                        [o_options addObject: [NSString stringWithFormat: @"input-slave=qtsound://%@", qtkaudio_currdevice_uid]];
512                 }
513             }
514         }
515
516         /* apply the options to our item(s) */
517         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
518         if (b_autoplay)
519             [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject:o_dic] atPos: -1 enqueue:NO];
520         else
521             [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject:o_dic] atPos: -1 enqueue:YES];
522     }
523 }
524
525 - (IBAction)screenChanged:(id)sender
526 {
527     int selected_index = [o_screen_screen_pop indexOfSelectedItem];
528     if (selected_index >= [o_displayInfos count]) return;
529
530     NSValue *v = [o_displayInfos objectAtIndex:selected_index];
531     struct display_info_t *item = (struct display_info_t *)[v pointerValue];
532
533     [o_screen_left_stp setMaxValue: item->rect.size.width];
534     [o_screen_top_stp setMaxValue: item->rect.size.height];
535     [o_screen_width_stp setMaxValue: item->rect.size.width];
536     [o_screen_height_stp setMaxValue: item->rect.size.height];
537
538     [o_screen_qtk_audio_pop setEnabled: [o_screen_qtk_audio_ckb state]];
539 }
540
541 - (IBAction)qtkChanged:(id)sender
542 {
543     NSInteger i_selectedDevice = [o_qtk_video_device_pop indexOfSelectedItem];
544     if ([qtkvideoDevices count] >= 1) {
545         NSValue *sizes = [[[[qtkvideoDevices objectAtIndex:i_selectedDevice] formatDescriptions] objectAtIndex:0] attributeForKey: QTFormatDescriptionVideoEncodedPixelsSizeAttribute];
546
547         [o_capture_width_fld setIntValue: [sizes sizeValue].width];
548         [o_capture_height_fld setIntValue: [sizes sizeValue].height];
549         [o_capture_width_stp setIntValue: [o_capture_width_fld intValue]];
550         [o_capture_height_stp setIntValue: [o_capture_height_fld intValue]];
551         qtk_currdevice_uid = [[(QTCaptureDevice *)[qtkvideoDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
552     }
553 }
554
555 - (IBAction)qtkAudioChanged:(id)sender
556 {
557     NSInteger i_selectedDevice = [o_qtk_audio_device_pop indexOfSelectedItem];
558     if ([qtkaudioDevices count] >= 1) {
559         qtkaudio_currdevice_uid = [[(QTCaptureDevice *)[qtkaudioDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
560     }
561     [o_screen_qtk_audio_pop selectItemAtIndex: i_selectedDevice];
562     [o_qtk_audio_device_pop selectItemAtIndex: i_selectedDevice];
563 }
564
565 - (IBAction)qtkToggleUIElements:(id)sender
566 {
567     [o_qtk_audio_device_pop setEnabled:[o_qtk_audio_ckb state]];
568     BOOL b_state = [o_qtk_video_ckb state];
569     [o_qtk_video_device_pop setEnabled:b_state];
570     [o_capture_width_fld setEnabled:b_state];
571     [o_capture_width_stp setEnabled:b_state];
572     [o_capture_height_fld setEnabled:b_state];
573     [o_capture_height_stp setEnabled:b_state];
574     [self qtkAudioChanged:sender];
575     [self qtkChanged:sender];
576     [self openCaptureModeChanged:sender];
577 }
578
579 #pragma mark -
580 #pragma mark Main Actions
581
582 - (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi
583 {
584     NSString *o_label = [o_tvi label];
585
586     if ([o_label isEqualToString: _NS("File")])
587         [self openFilePathChanged: nil];
588     else if ([o_label isEqualToString: _NS("Disc")])
589         [self scanOpticalMedia: nil];
590     else if ([o_label isEqualToString: _NS("Network")])
591         [self openNetInfoChanged: nil];
592     else if ([o_label isEqualToString: _NS("Capture")])
593         [self openCaptureModeChanged: nil];
594 }
595
596 - (IBAction)expandMRLfieldAction:(id)sender
597 {
598     NSRect o_win_rect, o_view_rect;
599     o_win_rect = [o_panel frame];
600     o_view_rect = [o_mrl_view frame];
601
602     if ([o_mrl_btn state] == NSOffState) {
603         /* we need to collaps, restore the panel size */
604         o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
605         o_win_rect.origin.y = (o_win_rect.origin.y + o_view_rect.size.height) - o_view_rect.size.height;
606
607         /* remove the MRL view */
608         [o_mrl_view removeFromSuperview];
609     } else {
610         /* we need to expand */
611         [o_mrl_view setFrame: NSMakeRect(0,
612                                          [o_mrl_btn frame].origin.y,
613                                          o_view_rect.size.width,
614                                          o_view_rect.size.height)];
615         [o_mrl_view setNeedsDisplay: NO];
616         [o_mrl_view setAutoresizesSubviews: YES];
617
618         /* enlarge panel size for MRL view */
619         o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
620     }
621
622     [[o_panel animator] setFrame: o_win_rect display:YES];
623
624     if ([o_mrl_btn state] == NSOnState)
625         [[o_panel contentView] addSubview: o_mrl_view];
626 }
627
628 - (void)openFileGeneric
629 {
630     [self openFilePathChanged: nil];
631     [self openTarget: 0];
632 }
633
634 - (void)openDisc
635 {
636     @synchronized (self) {
637         [o_specialMediaFolders removeAllObjects];
638     }
639
640     [self scanOpticalMedia: nil];
641     [self openTarget: 1];
642 }
643
644 - (void)openNet
645 {
646     [self openNetInfoChanged: nil];
647     [self openTarget: 2];
648 }
649
650 - (void)openCapture
651 {
652     [self openCaptureModeChanged: nil];
653     [self openTarget: 3];
654 }
655
656 - (void)openFile
657 {
658     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
659     b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
660
661     [o_open_panel setAllowsMultipleSelection: YES];
662     [o_open_panel setCanChooseDirectories: YES];
663     [o_open_panel setTitle: _NS("Open File")];
664     [o_open_panel setPrompt: _NS("Open")];
665
666     if ([o_open_panel runModal] == NSOKButton) {
667         NSArray * o_urls = [o_open_panel URLs];
668         NSUInteger count = [o_urls count];
669         NSMutableArray *o_values = [NSMutableArray arrayWithCapacity:count];
670         NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
671         for (NSUInteger i = 0; i < count; i++)
672             [o_values addObject: [[o_urls objectAtIndex:i] path]];
673         [o_values sortUsingSelector:@selector(caseInsensitiveCompare:)];
674
675         for (NSUInteger i = 0; i < count; i++) {
676             NSDictionary *o_dic;
677             char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], "file");
678             if (!psz_uri)
679                 continue;
680
681             o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
682
683             free(psz_uri);
684
685             [o_array addObject: o_dic];
686         }
687         if (b_autoplay)
688             [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
689         else
690             [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
691     }
692 }
693
694 #pragma mark -
695 #pragma mark File Panel
696
697 - (void)openFilePathChanged:(NSNotification *)o_notification
698 {
699     if (o_file_path && [o_file_path length] > 0) {
700         bool b_stream = [o_file_stream state];
701         BOOL b_dir = NO;
702
703         [[NSFileManager defaultManager] fileExistsAtPath:o_file_path isDirectory:&b_dir];
704
705         char *psz_uri = vlc_path2uri([o_file_path UTF8String], "file");
706         if (!psz_uri) return;
707
708         NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
709         NSRange offile = [o_mrl_string rangeOfString:@"file"];
710         free(psz_uri);
711
712         if (b_dir)
713             [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
714         else if (b_stream)
715             [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
716
717         [o_file_name setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_path]];
718         [o_file_name_stub setHidden: YES];
719         [o_file_stream setHidden: NO];
720         [o_file_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_path]];
721         [o_file_icon_well setHidden: NO];
722         [self setMRL: o_mrl_string];
723     } else {
724         [o_file_name setStringValue: @""];
725         [o_file_name_stub setHidden: NO];
726         [o_file_stream setHidden: YES];
727         [o_file_icon_well setImage: [NSImage imageNamed:@"generic"]];
728         [self setMRL: @""];
729     }
730 }
731
732 - (IBAction)openFileBrowse:(id)sender
733 {
734     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
735
736     [o_open_panel setAllowsMultipleSelection: NO];
737     [o_open_panel setCanChooseDirectories: YES];
738     [o_open_panel setTitle: _NS("Open File")];
739     [o_open_panel setPrompt: _NS("Open")];
740     [o_open_panel beginSheetModalForWindow:[sender window] completionHandler:^(NSInteger returnCode) {
741         if (returnCode == NSFileHandlingPanelOKButton) {
742             if (o_file_path)
743                 [o_file_path release];
744             o_file_path = [[[o_open_panel URLs] objectAtIndex:0] path];
745             [o_file_path retain];
746             [self openFilePathChanged: nil];
747         }
748     }];
749 }
750
751 - (IBAction)openFileStreamChanged:(id)sender
752 {
753     [self openFilePathChanged: nil];
754 }
755
756 - (IBAction)inputSlaveAction:(id)sender
757 {
758     if (sender == o_file_slave_ckbox)
759         [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
760     else {
761         NSOpenPanel *o_open_panel;
762         o_open_panel = [NSOpenPanel openPanel];
763         [o_open_panel setCanChooseFiles: YES];
764         [o_open_panel setCanChooseDirectories: NO];
765         if ([o_open_panel runModal] == NSOKButton) {
766             if (o_file_slave_path)
767                 [o_file_slave_path release];
768             o_file_slave_path = [[[o_open_panel URLs] objectAtIndex:0] path];
769             [o_file_slave_path retain];
770         }
771     }
772     if (o_file_slave_path && [o_file_slave_ckbox state] == NSOnState) {
773         [o_file_slave_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_slave_path]];
774         [o_file_slave_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_slave_path]];
775     } else {
776         [o_file_slave_filename_lbl setStringValue: @""];
777         [o_file_slave_icon_well setImage: NULL];
778     }
779 }
780
781 - (IBAction)fileTimeCustomization:(id)sender
782 {
783     BOOL b_value = [o_file_custom_timing_ckb state];
784     [o_file_starttime_fld setEnabled: b_value];
785     [o_file_starttime_lbl setEnabled: b_value];
786     [o_file_stoptime_fld setEnabled: b_value];
787     [o_file_stoptime_lbl setEnabled: b_value];
788 }
789
790 #pragma mark -
791 #pragma mark Optical Media Panel
792
793 - (void)showOpticalMediaView: theView withIcon:(NSImage *)icon
794 {
795     NSRect o_view_rect;
796     o_view_rect = [theView frame];
797     [theView setFrame: NSMakeRect(233, 0, o_view_rect.size.width, o_view_rect.size.height)];
798     [theView setAutoresizesSubviews: YES];
799     if (o_currentOpticalMediaView) {
800         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaView with: theView];
801         [o_currentOpticalMediaView release];
802     }
803     else
804         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: theView];
805     o_currentOpticalMediaView = theView;
806     [o_currentOpticalMediaView retain];
807
808     NSImageView *imageView;
809     imageView = [[NSImageView alloc] init];
810     [imageView setFrame: NSMakeRect(53, 61, 128, 128)];
811     [icon setSize: NSMakeSize(128,128)];
812     [imageView setImage: icon];
813     if (o_currentOpticalMediaIconView) {
814         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaIconView with: imageView];
815         [o_currentOpticalMediaIconView release];
816     }
817     else
818          [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] addSubview: imageView];
819     o_currentOpticalMediaIconView = imageView;
820     [o_currentOpticalMediaIconView retain];
821     [o_currentOpticalMediaView setNeedsDisplay: YES];
822     [o_currentOpticalMediaIconView setNeedsDisplay: YES];
823     [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] setNeedsDisplay: YES];
824     [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] displayIfNeeded];
825 }
826
827 - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
828 {
829     OSStatus err;
830     FSRef ref;
831     FSVolumeRefNum actualVolume;
832     err = FSPathMakeRef ((const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL);
833
834     // get a FSVolumeRefNum from mountPath
835     if (noErr == err) {
836         FSCatalogInfo   catalogInfo;
837         err = FSGetCatalogInfo (&ref,
838                                 kFSCatInfoVolume,
839                                 &catalogInfo,
840                                 NULL,
841                                 NULL,
842                                 NULL
843                                );
844         if (noErr == err)
845             actualVolume = catalogInfo.volume;
846         else
847             return @"";
848     }
849     else
850         return @"";
851
852     GetVolParmsInfoBuffer volumeParms;
853     err = FSGetVolumeParms(actualVolume, &volumeParms, sizeof(volumeParms));
854     if (noErr == err) {
855         NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
856         return [NSString stringWithFormat:@"/dev/r%@", bsdName];
857     }
858
859     return @"";
860 }
861
862 - (NSString *)getVolumeTypeFromMountPath:(NSString *)mountPath
863 {
864     OSStatus err;
865     FSRef ref;
866     FSVolumeRefNum actualVolume;
867     err = FSPathMakeRef ((const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL);
868
869     // get a FSVolumeRefNum from mountPath
870     if (noErr == err) {
871         FSCatalogInfo   catalogInfo;
872         err = FSGetCatalogInfo (&ref,
873                                 kFSCatInfoVolume,
874                                 &catalogInfo,
875                                 NULL,
876                                 NULL,
877                                 NULL
878                                );
879         if (noErr == err)
880             actualVolume = catalogInfo.volume;
881         else
882             goto out;
883     }
884     else
885         goto out;
886
887     GetVolParmsInfoBuffer volumeParms;
888     err = FSGetVolumeParms(actualVolume, &volumeParms, sizeof(volumeParms));
889
890     CFMutableDictionaryRef matchingDict;
891     io_service_t service;
892
893     if (!volumeParms.vMDeviceID) {
894         goto out;
895     }
896
897     matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
898     service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
899
900
901     NSString *returnValue = nil;
902     if (IO_OBJECT_NULL != service) {
903         if (IOObjectConformsTo(service, kIOCDMediaClass))
904             returnValue = kVLCMediaAudioCD;
905         else if (IOObjectConformsTo(service, kIODVDMediaClass))
906             returnValue = kVLCMediaDVD;
907         else if (IOObjectConformsTo(service, kIOBDMediaClass))
908             returnValue = kVLCMediaBD;
909         IOObjectRelease(service);
910
911         if (returnValue)
912             return returnValue;
913     }
914
915 out:
916     if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
917         returnValue = kVLCMediaVideoTSFolder;
918     else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
919         returnValue = kVLCMediaBDMVFolder;
920     else {
921         // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
922         NSFileManager * fm = [[NSFileManager alloc] init];
923
924         NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
925         for (int i = 0; i < [dirContents count]; i++) {
926             NSString *currentFile = [dirContents objectAtIndex:i];
927             NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
928
929             BOOL isDir;
930             if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
931             {
932                 if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame) {
933                     returnValue = kVLCMediaSVCD;
934                     break;
935                 }
936                 if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame) {
937                     returnValue = kVLCMediaVCD;
938                     break;
939                 }
940                 if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame) {
941                     returnValue = kVLCMediaBDMVFolder;
942                     break;
943                 }
944                 if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame) {
945                     returnValue = kVLCMediaVideoTSFolder;
946                     break;
947                 }
948             }
949         }
950
951         [fm release];
952
953         if (!returnValue)
954             returnValue = kVLCMediaVideoTSFolder;
955     }
956
957     return returnValue;
958 }
959
960 - (void)showOpticalAtPath: (NSDictionary *)o_dict
961 {
962     NSString *diskType = [o_dict objectForKey:@"mediaType"];
963     NSString *o_opticalDevicePath = [o_dict objectForKey:@"path"];
964     NSString *o_device_path = [o_dict objectForKey:@"devicePath"];
965     NSImage *o_image = [o_dict objectForKey:@"image"];
966
967     if ([diskType isEqualToString: kVLCMediaDVD] || [diskType isEqualToString: kVLCMediaVideoTSFolder]) {
968         [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_opticalDevicePath]];
969         [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
970
971         if (!b_nodvdmenus) {
972             [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", o_device_path]];
973             [self showOpticalMediaView: o_disc_dvd_view withIcon:o_image];
974         } else {
975             [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", o_device_path, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
976             [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: o_image];
977         }
978     } else if ([diskType isEqualToString: kVLCMediaAudioCD]) {
979         [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
980         [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_opticalDevicePath error:NULL] count] - 1]]; // minus .TOC.plist
981         [self showOpticalMediaView: o_disc_audiocd_view withIcon: o_image];
982         [self setMRL: [NSString stringWithFormat: @"cdda://%@", o_device_path]];
983     } else if ([diskType isEqualToString: kVLCMediaVCD]) {
984         [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
985         [self showOpticalMediaView: o_disc_vcd_view withIcon: o_image];
986         [self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", o_device_path, [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
987     } else if ([diskType isEqualToString: kVLCMediaSVCD]) {
988         [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
989         [self showOpticalMediaView: o_disc_vcd_view withIcon: o_image];
990         [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", o_device_path, [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
991     } else if ([diskType isEqualToString: kVLCMediaBD] || [diskType isEqualToString: kVLCMediaBDMVFolder]) {
992         [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
993         [self showOpticalMediaView: o_disc_bd_view withIcon: o_image];
994         [self setMRL: [NSString stringWithFormat: @"bluray://%@", o_opticalDevicePath]];
995     } else {
996         if (VLCIntf)
997             msg_Warn(VLCIntf, "unknown disk type, no idea what to display");
998
999         [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
1000     }
1001 }
1002
1003 - (NSDictionary *)scanPath:(NSString *)o_path
1004 {
1005     NSString *o_type = [self getVolumeTypeFromMountPath:o_path];
1006     NSImage *o_image = [[NSWorkspace sharedWorkspace] iconForFile: o_path];
1007     NSString *o_device_path;
1008
1009     // BDMV path must not end with BDMV directory
1010     if([o_type isEqualToString: kVLCMediaBDMVFolder]) {
1011         if([[o_path lastPathComponent] isEqualToString: @"BDMV"]) {
1012             o_path = [o_path stringByDeletingLastPathComponent];
1013         }
1014     }
1015
1016     if ([o_type isEqualToString: kVLCMediaVideoTSFolder] ||
1017         [o_type isEqualToString: kVLCMediaBD] ||
1018         [o_type isEqualToString: kVLCMediaBDMVFolder] ||
1019         [o_type isEqualToString: kVLCMediaUnknown])
1020         o_device_path = o_path;
1021     else
1022         o_device_path = [self getBSDNodeFromMountPath:o_path];
1023
1024     return [NSDictionary dictionaryWithObjectsAndKeys: o_path, @"path",
1025                                                 o_device_path, @"devicePath",
1026                                                        o_type, @"mediaType",
1027                                                       o_image, @"image", nil];
1028 }
1029
1030 - (void)scanDevicesWithPaths:(NSArray *)o_paths
1031 {
1032     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1033
1034     NSUInteger count = [o_paths count];
1035     NSMutableArray *o_result = [NSMutableArray arrayWithCapacity:count];
1036     for (NSUInteger i = 0; i < count; i++)
1037         [o_result addObject: [self scanPath:[o_paths objectAtIndex:i]]];
1038
1039     @synchronized (self) {
1040         if (o_opticalDevices)
1041             [o_opticalDevices release];
1042         o_opticalDevices = [[NSArray alloc] initWithArray: o_result];
1043     }
1044
1045     [self performSelectorOnMainThread:@selector(updateMediaSelector:) withObject:nil waitUntilDone:NO];
1046     [o_pool release];
1047 }
1048
1049 - (void)scanSpecialPath:(NSString *)o_path
1050 {
1051     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1052
1053     NSDictionary *o_dict = [self scanPath:o_path];
1054
1055     @synchronized (self) {
1056         [o_specialMediaFolders addObject:o_dict];
1057     }
1058
1059     [self performSelectorOnMainThread:@selector(updateMediaSelector:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:NO];
1060     [o_pool release];
1061 }
1062
1063 - (void)scanOpticalMedia:(NSNotification *)o_notification
1064 {
1065     [NSThread detachNewThreadSelector:@selector(scanDevicesWithPaths:) toTarget:self withObject:[NSArray arrayWithArray:[[NSWorkspace sharedWorkspace] mountedRemovableMedia]]];
1066 }
1067
1068 - (void)updateMediaSelector:(NSNumber *)o_selection
1069 {
1070     [o_allMediaDevices removeAllObjects];
1071     [o_disc_selector_pop removeAllItems];
1072
1073     @synchronized (self) {
1074         [o_allMediaDevices addObjectsFromArray:o_opticalDevices];
1075         [o_allMediaDevices addObjectsFromArray:o_specialMediaFolders];
1076     }
1077
1078     NSUInteger count = [o_allMediaDevices count];
1079     if (count > 0) {
1080         for (NSUInteger i = 0; i < count ; i++) {
1081             NSDictionary *o_dict = [o_allMediaDevices objectAtIndex:i];
1082             [o_disc_selector_pop addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:[o_dict objectForKey:@"path"]]];
1083         }
1084
1085         if ([o_disc_selector_pop numberOfItems] <= 1)
1086             [o_disc_selector_pop setHidden: YES];
1087         else
1088             [o_disc_selector_pop setHidden: NO];
1089
1090         // select newly added media folder
1091         if (o_selection && [o_selection boolValue])
1092             [o_disc_selector_pop selectItemAtIndex: [[o_disc_selector_pop itemArray] count] - 1];
1093
1094         [self discSelectorChanged:nil];
1095     } else {
1096         msg_Dbg(VLCIntf, "no optical media found");
1097         [o_disc_selector_pop setHidden: YES];
1098         [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed: @"NSApplicationIcon"]];
1099     }
1100
1101 }
1102
1103 - (IBAction)discSelectorChanged:(id)sender
1104 {
1105     NSDictionary *o_dict = [o_allMediaDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];    
1106     [self showOpticalAtPath:o_dict];
1107 }
1108
1109 - (IBAction)openSpecialMediaFolder:(id)sender
1110 {
1111     /* this is currently for VIDEO_TS and BDMV folders */
1112     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1113
1114     [o_open_panel setAllowsMultipleSelection: NO];
1115     [o_open_panel setCanChooseDirectories: YES];
1116     [o_open_panel setTitle: [sender title]];
1117     [o_open_panel setPrompt: _NS("Open")];
1118
1119     /* work-around for Mountain Lion, which treats folders called "BDMV" including an item named "INDEX.BDM"
1120      * as a _FILE_. Don't ask, move on. There is nothing to see here */
1121     [o_open_panel setCanChooseFiles: YES];
1122     [o_open_panel setAllowedFileTypes:[NSArray arrayWithObject:@"public.directory"]];
1123
1124     if ([o_open_panel runModal] == NSOKButton) {
1125         NSString *o_path = [[[o_open_panel URLs] objectAtIndex:0] path];
1126         if ([o_path length] > 0) {
1127             [NSThread detachNewThreadSelector:@selector(scanSpecialPath:) toTarget:self withObject:o_path];
1128         }
1129     }
1130 }
1131
1132 - (IBAction)dvdreadOptionChanged:(id)sender
1133 {
1134     NSDictionary *o_dict = [o_allMediaDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];
1135     NSString *o_device_path = [o_dict objectForKey:@"devicePath"];
1136
1137     if (sender == o_disc_dvdwomenus_enablemenus_btn) {
1138         b_nodvdmenus = NO;
1139         [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", o_device_path]];
1140         [self showOpticalMediaView: o_disc_dvd_view withIcon: [o_currentOpticalMediaIconView image]];
1141         return;
1142     }
1143     if (sender == o_disc_dvd_disablemenus_btn) {
1144         b_nodvdmenus = YES;
1145         [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [o_currentOpticalMediaIconView image]];
1146     }
1147
1148     if (sender == o_disc_dvdwomenus_title)
1149         [o_disc_dvdwomenus_title_stp setIntValue: [o_disc_dvdwomenus_title intValue]];
1150     if (sender == o_disc_dvdwomenus_title_stp)
1151         [o_disc_dvdwomenus_title setIntValue: [o_disc_dvdwomenus_title_stp intValue]];
1152     if (sender == o_disc_dvdwomenus_chapter)
1153         [o_disc_dvdwomenus_chapter_stp setIntValue: [o_disc_dvdwomenus_chapter intValue]];
1154     if (sender == o_disc_dvdwomenus_chapter_stp)
1155         [o_disc_dvdwomenus_chapter setIntValue: [o_disc_dvdwomenus_chapter_stp intValue]];
1156
1157     [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", o_device_path, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
1158 }
1159
1160 - (IBAction)vcdOptionChanged:(id)sender
1161 {
1162     if (sender == o_disc_vcd_title)
1163         [o_disc_vcd_title_stp setIntValue: [o_disc_vcd_title intValue]];
1164     if (sender == o_disc_vcd_title_stp)
1165         [o_disc_vcd_title setIntValue: [o_disc_vcd_title_stp intValue]];
1166     if (sender == o_disc_vcd_chapter)
1167         [o_disc_vcd_chapter_stp setIntValue: [o_disc_vcd_chapter intValue]];
1168     if (sender == o_disc_vcd_chapter_stp)
1169         [o_disc_vcd_chapter setIntValue: [o_disc_vcd_chapter_stp intValue]];
1170
1171     NSString *o_device_path = [[o_allMediaDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]] objectForKey:@"devicePath"];
1172     [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", o_device_path, [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
1173 }
1174
1175 #pragma mark -
1176 #pragma mark Network Panel
1177
1178 - (void)textFieldWasClicked:(NSNotification *)o_notification
1179 {
1180     if ([o_notification object] == o_net_udp_port)
1181         [o_net_mode selectCellAtRow: 0 column: 0];
1182     else if ([o_notification object] == o_net_udpm_addr ||
1183              [o_notification object] == o_net_udpm_port)
1184         [o_net_mode selectCellAtRow: 1 column: 0];
1185     else
1186         [o_net_mode selectCellAtRow: 2 column: 0];
1187
1188     [self openNetInfoChanged: nil];
1189 }
1190
1191 - (IBAction)openNetModeChanged:(id)sender
1192 {
1193     if (sender == o_net_mode) {
1194         if ([[sender selectedCell] tag] == 0)
1195             [o_panel makeFirstResponder: o_net_udp_port];
1196         else if ([[sender selectedCell] tag] == 1)
1197             [o_panel makeFirstResponder: o_net_udpm_addr];
1198         else
1199             msg_Warn(VLCIntf, "Unknown sender tried to change UDP/RTP mode");
1200     }
1201
1202     [self openNetInfoChanged: nil];
1203 }
1204
1205 - (IBAction)openNetStepperChanged:(id)sender
1206 {
1207     int i_tag = [sender tag];
1208
1209     if (i_tag == 0) {
1210         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
1211         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1212                                                             object: o_net_udp_port];
1213         [o_panel makeFirstResponder: o_net_udp_port];
1214     }
1215     else if (i_tag == 1) {
1216         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
1217         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1218                                                             object: o_net_udpm_port];
1219         [o_panel makeFirstResponder: o_net_udpm_port];
1220     }
1221
1222     [self openNetInfoChanged: nil];
1223 }
1224
1225 - (void)openNetInfoChanged:(NSNotification *)o_notification
1226 {
1227     NSString *o_mrl_string = [NSString string];
1228
1229     if ([o_net_udp_panel isVisible]) {
1230         NSString *o_mode;
1231         o_mode = [[o_net_mode selectedCell] title];
1232
1233         if ([o_mode isEqualToString: _NS("Unicast")]) {
1234             int i_port = [o_net_udp_port intValue];
1235
1236             if ([[o_net_udp_protocol_mat selectedCell] tag] == 0)
1237                 o_mrl_string = @"udp://";
1238             else
1239                 o_mrl_string = @"rtp://";
1240
1241             if (i_port != config_GetInt(VLCIntf, "server-port")) {
1242                 o_mrl_string =
1243                     [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1244             }
1245         }
1246         else if ([o_mode isEqualToString: _NS("Multicast")]) {
1247             NSString *o_addr = [o_net_udpm_addr stringValue];
1248             int i_port = [o_net_udpm_port intValue];
1249
1250             if ([[o_net_udp_protocol_mat selectedCell] tag] == 0)
1251                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1252             else
1253                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1254
1255             if (i_port != config_GetInt(VLCIntf, "server-port")) {
1256                 o_mrl_string =
1257                     [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1258             }
1259         }
1260     } else
1261         o_mrl_string = [o_net_http_url stringValue];
1262
1263     [self setMRL: o_mrl_string];
1264 }
1265
1266 - (IBAction)openNetUDPButtonAction:(id)sender
1267 {
1268     if (sender == o_net_openUDP_btn) {
1269         [NSApp beginSheet: o_net_udp_panel
1270            modalForWindow: o_panel
1271             modalDelegate: self
1272            didEndSelector: NULL
1273               contextInfo: nil];
1274         [self openNetInfoChanged: nil];
1275     }
1276     else if (sender == o_net_udp_cancel_btn) {
1277         [o_net_udp_panel orderOut: sender];
1278         [NSApp endSheet: o_net_udp_panel];
1279     }
1280     else if (sender == o_net_udp_ok_btn) {
1281         NSString *o_mrl_string = [NSString string];
1282         if ([[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")]) {
1283             int i_port = [o_net_udp_port intValue];
1284
1285             if ([[o_net_udp_protocol_mat selectedCell] tag] == 0)
1286                 o_mrl_string = @"udp://";
1287             else
1288                 o_mrl_string = @"rtp://";
1289
1290             if (i_port != config_GetInt(VLCIntf, "server-port")) {
1291                 o_mrl_string =
1292                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
1293             }
1294         }
1295         else if ([[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")]) {
1296             NSString *o_addr = [o_net_udpm_addr stringValue];
1297             int i_port = [o_net_udpm_port intValue];
1298
1299             if ([[o_net_udp_protocol_mat selectedCell] tag] == 0)
1300                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
1301             else
1302                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
1303
1304             if (i_port != config_GetInt(VLCIntf, "server-port")) {
1305                 o_mrl_string =
1306                 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
1307             }
1308         }
1309         [self setMRL: o_mrl_string];
1310         [o_net_http_url setStringValue: o_mrl_string];
1311         [o_net_udp_panel orderOut: sender];
1312         [NSApp endSheet: o_net_udp_panel];
1313     }
1314 }
1315
1316 #pragma mark -
1317 #pragma mark Capture Panel
1318
1319 - (void)showCaptureView: theView
1320 {
1321     NSRect o_view_rect;
1322     o_view_rect = [theView frame];
1323     [theView setFrame: NSMakeRect(0, -10, o_view_rect.size.width, o_view_rect.size.height)];
1324     [theView setAutoresizesSubviews: YES];
1325     if (o_currentCaptureView) {
1326         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] replaceSubview: o_currentCaptureView with: theView];
1327         [o_currentCaptureView release];
1328     } else {
1329         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] addSubview: theView];
1330     }
1331     o_currentCaptureView = theView;
1332     [o_currentCaptureView retain];
1333 }
1334
1335 - (IBAction)openCaptureModeChanged:(id)sender
1336 {
1337     intf_thread_t * p_intf = VLCIntf;
1338
1339     if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"]) {
1340         if ([[[VLCMain sharedInstance] eyeTVController] eyeTVRunning] == YES) {
1341             if ([[[VLCMain sharedInstance] eyeTVController] deviceConnected] == YES) {
1342                 [self showCaptureView: o_eyetv_running_view];
1343                 [self setupChannelInfo];
1344             }
1345             else
1346                 setEyeTVUnconnected;
1347         }
1348         else
1349             [self showCaptureView: o_eyetv_notLaunched_view];
1350         [self setMRL: @""];
1351     }
1352     else if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")]) {
1353         [self showCaptureView: o_screen_view];
1354         [self setMRL: @"screen://"];
1355         [o_screen_height_fld setIntValue: config_GetInt(p_intf, "screen-height")];
1356         [o_screen_width_fld setIntValue: config_GetInt(p_intf, "screen-width")];
1357         [o_screen_fps_fld setFloatValue: config_GetFloat(p_intf, "screen-fps")];
1358         [o_screen_left_fld setIntValue: config_GetInt(p_intf, "screen-left")];
1359         [o_screen_top_fld setIntValue: config_GetInt(p_intf, "screen-top")];
1360         [o_screen_follow_mouse_ckb setIntValue: config_GetInt(p_intf, "screen-follow-mouse")];
1361
1362         int screen_index = config_GetInt(p_intf, "screen-index");
1363         int display_id = config_GetInt(p_intf, "screen-display-id");
1364         unsigned int i, displayCount = 0;
1365         CGLError returnedError;
1366         struct display_info_t *item;
1367         NSValue *v;
1368
1369         returnedError = CGGetOnlineDisplayList(0, NULL, &displayCount);
1370         if (!returnedError) {
1371             CGDirectDisplayID *ids;
1372             ids = (CGDirectDisplayID *)malloc(displayCount * sizeof(CGDirectDisplayID));
1373             returnedError = CGGetOnlineDisplayList(displayCount, ids, &displayCount);
1374             if (!returnedError) {
1375                 for (i = 0; i < [o_displayInfos count]; i ++) {
1376                     v = [o_displayInfos objectAtIndex:i];
1377                     free([v pointerValue]);
1378                 }
1379                 [o_displayInfos removeAllObjects];
1380                 [o_screen_screen_pop removeAllItems];
1381                 for (i = 0; i < displayCount; i ++) {
1382                     item = (struct display_info_t *)malloc(sizeof(struct display_info_t));
1383                     item->id = ids[i];
1384                     item->rect = CGDisplayBounds(item->id);
1385                     [o_screen_screen_pop addItemWithTitle: [NSString stringWithFormat:@"Screen %d (%dx%d)", i + 1, (int)item->rect.size.width, (int)item->rect.size.height]];
1386                     v = [NSValue valueWithPointer:item];
1387                     [o_displayInfos addObject:v];
1388                     if (i == 0 || display_id == item->id || screen_index - 1 == i) {
1389                         [o_screen_screen_pop selectItemAtIndex: i];
1390                         [o_screen_left_stp setMaxValue: item->rect.size.width];
1391                         [o_screen_top_stp setMaxValue: item->rect.size.height];
1392                         [o_screen_width_stp setMaxValue: item->rect.size.width];
1393                         [o_screen_height_stp setMaxValue: item->rect.size.height];
1394                     }
1395                 }
1396             }
1397             free(ids);
1398         }
1399     }
1400     else if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")]) {
1401         [self showCaptureView: o_qtk_view];
1402         if ([o_capture_width_fld intValue] <= 0)
1403             [self qtkChanged:nil];
1404
1405         [self qtkAudioChanged:nil];
1406
1407         [self setMRL: @""];
1408
1409         if ([o_qtk_video_ckb state] && qtk_currdevice_uid)
1410             [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
1411         else if ([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
1412             [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
1413     }
1414 }
1415
1416 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
1417 {
1418     [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
1419     if ([[o_screen_fps_fld stringValue] isEqualToString: @""])
1420         [o_screen_fps_fld setFloatValue: 1.0];
1421     [self setMRL: @"screen://"];
1422 }
1423
1424 - (IBAction)eyetvSwitchChannel:(id)sender
1425 {
1426     if (sender == o_eyetv_nextProgram_btn) {
1427         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
1428         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1429         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1430     } else if (sender == o_eyetv_previousProgram_btn) {
1431         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
1432         [o_eyetv_channels_pop selectItemWithTag:chanNum];
1433         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1434     } else if (sender == o_eyetv_channels_pop) {
1435         int chanNum = [[sender selectedItem] tag];
1436         [[[VLCMain sharedInstance] eyeTVController] setChannel:chanNum];
1437         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
1438     } else
1439         msg_Err(VLCIntf, "eyetvSwitchChannel sent by unknown object");
1440 }
1441
1442 - (IBAction)eyetvLaunch:(id)sender
1443 {
1444     [[[VLCMain sharedInstance] eyeTVController] launchEyeTV];
1445 }
1446
1447 - (IBAction)eyetvGetPlugin:(id)sender
1448 {
1449     [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.videolan.org/vlc/eyetv"]];
1450 }
1451
1452 - (void)eyetvChanged:(NSNotification *)o_notification
1453 {
1454     if ([[o_notification name] isEqualToString: @"DeviceAdded"]) {
1455         msg_Dbg(VLCIntf, "eyetv device was added");
1456         [self showCaptureView: o_eyetv_running_view];
1457         [self setupChannelInfo];
1458     } else if ([[o_notification name] isEqualToString: @"DeviceRemoved"]) {
1459         /* leave the channel selection like that,
1460          * switch to our "no device" tab */
1461         msg_Dbg(VLCIntf, "eyetv device was removed");
1462         setEyeTVUnconnected;
1463     } else if ([[o_notification name] isEqualToString: @"PluginQuit"]) {
1464         /* switch to the "launch eyetv" tab */
1465         msg_Dbg(VLCIntf, "eyetv was terminated");
1466         [self showCaptureView: o_eyetv_notLaunched_view];
1467     } else if ([[o_notification name] isEqualToString: @"PluginInit"]) {
1468         /* we got no device yet */
1469         msg_Dbg(VLCIntf, "eyetv was launched, no device yet");
1470         setEyeTVUnconnected;
1471     }
1472 }
1473
1474 /* little helper method, since this code needs to be run by multiple objects */
1475 - (void)setupChannelInfo
1476 {
1477     /* set up channel selection */
1478     [o_eyetv_channels_pop removeAllItems];
1479     [o_eyetv_chn_bgbar setHidden: NO];
1480     [o_eyetv_chn_bgbar animate: self];
1481     [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
1482     [o_eyetv_chn_status_txt setHidden: NO];
1483
1484     /* retrieve info */
1485     NSEnumerator *channels = [[[VLCMain sharedInstance] eyeTVController] allChannels];
1486     int x = -2;
1487     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
1488                                                action: nil
1489                                         keyEquivalent: @""] setTag:x++];
1490     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
1491                                                action: nil
1492                                         keyEquivalent: @""] setTag:x++];
1493     if (channels) {
1494         NSString *channel;
1495         [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
1496         while ((channel = [channels nextObject]) != nil)
1497             /* we have to add items this way, because we accept duplicates
1498              * additionally, we save a bit of time */
1499             [[[o_eyetv_channels_pop menu] addItemWithTitle: channel action: nil keyEquivalent: @""] setTag:++x];
1500
1501         /* make Tuner the default */
1502         [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] channel]];
1503     }
1504
1505     /* clean up GUI */
1506     [o_eyetv_chn_bgbar setHidden: YES];
1507     [o_eyetv_chn_status_txt setHidden: YES];
1508 }
1509
1510 #pragma mark -
1511 #pragma mark Subtitle Settings
1512
1513 - (IBAction)subsChanged:(id)sender
1514 {
1515     if ([o_file_sub_ckbox state] == NSOnState) {
1516         [o_file_sub_btn_settings setEnabled:YES];
1517         if (o_sub_path) {
1518             [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1519             [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1520         }
1521     } else {
1522         [o_file_sub_btn_settings setEnabled:NO];
1523         [o_file_subtitles_filename_lbl setStringValue: @""];
1524         [o_file_subtitles_icon_well setImage: NULL];
1525     }
1526 }
1527
1528 - (IBAction)subSettings:(id)sender
1529 {
1530     [NSApp beginSheet: o_file_sub_sheet
1531         modalForWindow: [sender window]
1532         modalDelegate: self
1533         didEndSelector: NULL
1534         contextInfo: nil];
1535 }
1536
1537 - (IBAction)subCloseSheet:(id)sender
1538 {
1539     [self subsChanged: nil];
1540     [o_file_sub_sheet orderOut:sender];
1541     [NSApp endSheet: o_file_sub_sheet];
1542 }
1543
1544 - (IBAction)subFileBrowse:(id)sender
1545 {
1546     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1547
1548     [o_open_panel setAllowsMultipleSelection: NO];
1549     [o_open_panel setTitle: _NS("Open File")];
1550     [o_open_panel setPrompt: _NS("Open")];
1551
1552     if ([o_open_panel runModal] == NSOKButton) {
1553         o_sub_path = [[[o_open_panel URLs] objectAtIndex:0] path];
1554         [o_sub_path retain];
1555         [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
1556         [o_file_sub_path_fld setStringValue: [o_file_subtitles_filename_lbl stringValue]];
1557         [o_file_sub_path_lbl setHidden: YES];
1558         [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
1559         [o_file_sub_icon_view setImage: [o_file_subtitles_icon_well image]];
1560     } else {
1561         [o_file_sub_path_lbl setHidden: NO];
1562         [o_file_sub_path_fld setStringValue:@""];
1563         [o_file_subtitles_filename_lbl setStringValue:@""];
1564         [o_file_subtitles_icon_well setImage: nil];
1565         [o_file_sub_icon_view setImage: nil];
1566     }
1567 }
1568
1569 - (IBAction)subOverride:(id)sender
1570 {
1571     BOOL b_state = [o_file_sub_override state];
1572     [o_file_sub_delay setEnabled: b_state];
1573     [o_file_sub_delay_stp setEnabled: b_state];
1574     [o_file_sub_fps setEnabled: b_state];
1575     [o_file_sub_fps_stp setEnabled: b_state];
1576 }
1577
1578 #pragma mark -
1579 #pragma mark Miscellaneous
1580
1581 - (IBAction)panelCancel:(id)sender
1582 {
1583     [NSApp stopModalWithCode: 0];
1584 }
1585
1586 - (IBAction)panelOk:(id)sender
1587 {
1588     if ([[self MRL] length])
1589         [NSApp stopModalWithCode: 1];
1590     else
1591         NSBeep();
1592 }
1593
1594 - (NSArray *)qtkvideoDevices
1595 {
1596     if (!qtkvideoDevices)
1597         [self qtkrefreshVideoDevices];
1598     return qtkvideoDevices;
1599 }
1600
1601 - (void)qtkrefreshVideoDevices
1602 {
1603     [qtkvideoDevices release];
1604     qtkvideoDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1605 }
1606
1607 - (NSArray *)qtkaudioDevices
1608 {
1609     if (!qtkaudioDevices)
1610         [self qtkrefreshAudioDevices];
1611     return qtkaudioDevices;
1612 }
1613
1614 - (void)qtkrefreshAudioDevices
1615 {
1616     [qtkaudioDevices release];
1617     qtkaudioDevices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeSound] arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain];
1618 }
1619
1620 @end
1621
1622 @implementation VLCOpenTextField
1623
1624 - (void)mouseDown:(NSEvent *)theEvent
1625 {
1626     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
1627                                                         object: self];
1628     [super mouseDown: theEvent];
1629 }
1630
1631 @end