1 /*****************************************************************************
2 * intf_open.c: MacOS X plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: intf_open.m,v 1.3.2.1 2002/06/02 22:32:46 massiot Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <IOKit/IOKitLib.h>
29 #include <IOKit/IOBSD.h>
30 #include <IOKit/storage/IOMedia.h>
31 #include <IOKit/storage/IOCDMedia.h>
32 #include <IOKit/storage/IODVDMedia.h>
35 #import "intf_vlc_wrapper.h"
37 /*****************************************************************************
38 * GetEjectableMediaOfClass
39 *****************************************************************************/
40 NSArray *GetEjectableMediaOfClass( const char *psz_class )
42 io_object_t next_media;
43 mach_port_t master_port;
44 kern_return_t kern_result;
45 NSArray *o_devices = nil;
46 NSMutableArray *p_list = nil;
47 io_iterator_t media_iterator;
48 CFMutableDictionaryRef classes_to_match;
50 kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
51 if( kern_result != KERN_SUCCESS )
56 classes_to_match = IOServiceMatching( psz_class );
57 if( classes_to_match == NULL )
62 CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectable ),
65 kern_result = IOServiceGetMatchingServices( master_port, classes_to_match,
67 if( kern_result != KERN_SUCCESS )
72 p_list = [NSMutableArray arrayWithCapacity: 1];
74 next_media = IOIteratorNext( media_iterator );
75 if( next_media != NULL )
78 size_t dev_path_length;
79 CFTypeRef str_bsd_path;
83 str_bsd_path = IORegistryEntryCreateCFProperty( next_media,
87 if( str_bsd_path == NULL )
89 IOObjectRelease( next_media );
93 snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' );
94 dev_path_length = strlen( psz_buf );
96 if( CFStringGetCString( str_bsd_path,
97 (char*)&psz_buf + dev_path_length,
98 sizeof(psz_buf) - dev_path_length,
99 kCFStringEncodingASCII ) )
101 [p_list addObject: [NSString stringWithCString: psz_buf]];
104 CFRelease( str_bsd_path );
106 IOObjectRelease( next_media );
108 } while( ( next_media = IOIteratorNext( media_iterator ) ) != NULL );
111 IOObjectRelease( media_iterator );
113 o_devices = [NSArray arrayWithArray: p_list];
118 /*****************************************************************************
119 * Intf_Open implementation
120 *****************************************************************************/
121 @implementation Intf_Open
123 static Intf_Open *o_open = nil;
129 o_open = [super init];
135 + (Intf_Open *)instance
142 [o_net_server_addr setEnabled: NSOffState];
143 [o_net_server_addr_label setStringValue: @"Address"];
144 [o_net_server_port setEnabled: NSOnState];
145 [o_net_server_port setIntValue: 1234];
146 [o_net_server_pstepper setEnabled: NSOnState];
147 [o_net_server_pstepper setIntValue: [o_net_server_port intValue]];
150 - (IBAction)openDisc:(id)sender
154 [self openDiscTypeChanged: nil];
156 [o_disc_panel makeKeyAndOrderFront: self];
157 i_result = [NSApp runModalForWindow: o_disc_panel];
158 [o_disc_panel close];
162 NSString *o_type = [[o_disc_type selectedCell] title];
163 NSString *o_device = [o_disc_device stringValue];
164 int i_title = [o_disc_title intValue];
165 int i_chapter = [o_disc_chapter intValue];
167 [[Intf_VLCWrapper instance] openDisc: [o_type lowercaseString]
168 device: o_device title: i_title chapter: i_chapter];
172 - (IBAction)openDiscTypeChanged:(id)sender
176 const char *psz_class = NULL;
178 [o_disc_device removeAllItems];
180 o_type = [[o_disc_type selectedCell] title];
182 if( [o_type isEqualToString: @"DVD"] )
184 psz_class = kIODVDMediaClass;
188 psz_class = kIOCDMediaClass;
191 o_devices = GetEjectableMediaOfClass( psz_class );
192 if( o_devices != nil )
194 int i_devices = [o_devices count];
200 for( i = 0; i < i_devices; i++ )
203 addItemWithObjectValue: [o_devices objectAtIndex: i]];
206 [o_disc_device selectItemAtIndex: 0];
210 [o_disc_device setStringValue:
211 [NSString stringWithFormat: @"No %@s found", o_type]];
216 - (IBAction)openFile:(id)sender
218 NSOpenPanel *o_panel = [NSOpenPanel openPanel];
220 [o_panel setAllowsMultipleSelection: YES];
222 if( [o_panel runModalForDirectory: nil
223 file: nil types: nil] == NSOKButton )
225 [[Intf_VLCWrapper instance] openFiles: [o_panel filenames]];
229 - (IBAction)openNet:(id)sender
233 [o_net_panel makeKeyAndOrderFront: self];
234 i_result = [NSApp runModalForWindow: o_net_panel];
239 NSString *o_protocol;
240 int i_port = [o_net_server_port intValue];
241 NSString *o_addr = [o_net_server_addr stringValue];
243 o_protocol = [[o_net_protocol selectedCell] title];
245 if( [o_protocol isEqualToString: @"UDP"] )
247 [[Intf_VLCWrapper instance] openNet: @"" port: i_port];
249 else if( [o_protocol isEqualToString: @"UDP - multicast"] )
251 [[Intf_VLCWrapper instance] openNet: o_addr port: i_port];
253 else if( [o_protocol isEqualToString: @"Channel server"] )
255 [[Intf_VLCWrapper instance] openNetChannel: o_addr port: i_port];
257 else if( [o_protocol isEqualToString: @"HTTP"] )
259 [[Intf_VLCWrapper instance] openNetHTTP: o_addr];
264 - (IBAction)openNetProtocol:(id)sender
266 NSString *o_protocol;
268 o_protocol = [[o_net_protocol selectedCell] title];
270 if( [o_protocol isEqualToString: @"UDP"] )
272 [o_net_server_addr setEnabled: NSOffState];
273 [o_net_server_port setEnabled: NSOnState];
274 [o_net_server_port setIntValue: 1234];
275 [o_net_server_pstepper setEnabled: NSOnState];
277 else if( [o_protocol isEqualToString: @"UDP - multicast"] )
279 [o_net_server_addr setEnabled: NSOnState];
280 [o_net_server_addr_label setStringValue: @"Mult. addr."];
281 [o_net_server_port setEnabled: NSOnState];
282 [o_net_server_port setIntValue: 1234];
283 [o_net_server_pstepper setEnabled: NSOnState];
285 else if( [o_protocol isEqualToString: @"Channel server"] )
287 [o_net_server_addr setEnabled: NSOnState];
288 [o_net_server_addr_label setStringValue: @"Server"];
289 [o_net_server_addr setStringValue: @"vlcs"];
290 [o_net_server_port setEnabled: NSOnState];
291 [o_net_server_port setIntValue: 6010];
292 [o_net_server_pstepper setEnabled: NSOnState];
294 else if( [o_protocol isEqualToString: @"HTTP"] )
296 [o_net_server_addr setEnabled: NSOnState];
297 [o_net_server_addr_label setStringValue: @"URL"];
298 [o_net_server_addr setStringValue: @"http://"];
299 [o_net_server_port setEnabled: NSOffState];
300 [o_net_server_pstepper setEnabled: NSOffState];
302 [o_net_server_pstepper setIntValue: [o_net_server_port intValue]];
305 - (IBAction)panelCancel:(id)sender
307 [NSApp stopModalWithCode: 0];
310 - (IBAction)panelOk:(id)sender
312 [NSApp stopModalWithCode: 1];