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