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