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