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