Commit c835a204 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx/open: further clean-up

trim exposed class API, remove code which does not belong in a view object, remove macro abuse
parent aff23ff5
......@@ -36,6 +36,15 @@
#define B64DecNSStr(s) [[VLCStringUtility sharedInstance] b64Decode: s]
#define B64EncAndFree(s) [[VLCStringUtility sharedInstance] b64EncodeAndFree: s]
extern NSString *const kVLCMediaAudioCD;
extern NSString *const kVLCMediaDVD;
extern NSString *const kVLCMediaVCD;
extern NSString *const kVLCMediaSVCD;
extern NSString *const kVLCMediaBD;
extern NSString *const kVLCMediaVideoTSFolder;
extern NSString *const kVLCMediaBDMVFolder;
extern NSString *const kVLCMediaUnknown;
NSString *toNSStr(const char *str);
unsigned int CocoaKeyToVLC(unichar i_key);
......@@ -61,4 +70,7 @@ NSImage *imageFromRes(NSString *o_id);
- (NSString *)b64Decode:(NSString *)string;
- (NSString *)b64EncodeAndFree:(char *)psz_string;
- (NSString *)getVolumeTypeFromMountPath:(NSString *)mountPath;
- (NSString *)getBSDNodeFromMountPath:(NSString *)mountPath;
@end
......@@ -28,6 +28,20 @@
#import "StringUtility.h"
#import "CompatibilityFixes.h"
#import <IOKit/storage/IOMedia.h>
#import <IOKit/storage/IOCDMedia.h>
#import <IOKit/storage/IODVDMedia.h>
#import <IOKit/storage/IOBDMedia.h>
NSString *const kVLCMediaAudioCD = @"AudioCD";
NSString *const kVLCMediaDVD = @"DVD";
NSString *const kVLCMediaVCD = @"VCD";
NSString *const kVLCMediaSVCD = @"SVCD";
NSString *const kVLCMediaBD = @"Blu-ray";
NSString *const kVLCMediaVideoTSFolder = @"VIDEO_TS";
NSString *const kVLCMediaBDMVFolder = @"BDMV";
NSString *const kVLCMediaUnknown = @"Unknown";
#import <vlc_keys.h>
#import <vlc_strings.h>
......@@ -383,6 +397,136 @@ NSString *toNSStr(const char *str) {
return returnStr;
}
- (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
{
OSStatus err;
FSRef ref;
FSVolumeRefNum actualVolume;
err = FSPathMakeRef ((const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL);
// get a FSVolumeRefNum from mountPath
if (noErr == err) {
FSCatalogInfo catalogInfo;
err = FSGetCatalogInfo (&ref,
kFSCatInfoVolume,
&catalogInfo,
NULL,
NULL,
NULL
);
if (noErr == err)
actualVolume = catalogInfo.volume;
else
return @"";
}
else
return @"";
GetVolParmsInfoBuffer volumeParms;
err = FSGetVolumeParms(actualVolume, &volumeParms, sizeof(volumeParms));
if (noErr == err) {
NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
return [NSString stringWithFormat:@"/dev/r%@", bsdName];
}
return @"";
}
- (NSString *)getVolumeTypeFromMountPath:(NSString *)mountPath
{
OSStatus err;
FSRef ref;
FSVolumeRefNum actualVolume;
NSString *returnValue;
err = FSPathMakeRef ((const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL);
// get a FSVolumeRefNum from mountPath
if (noErr == err) {
FSCatalogInfo catalogInfo;
err = FSGetCatalogInfo (&ref,
kFSCatInfoVolume,
&catalogInfo,
NULL,
NULL,
NULL
);
if (noErr == err)
actualVolume = catalogInfo.volume;
else
goto out;
}
else
goto out;
GetVolParmsInfoBuffer volumeParms;
err = FSGetVolumeParms(actualVolume, &volumeParms, sizeof(volumeParms));
CFMutableDictionaryRef matchingDict;
io_service_t service;
if (!volumeParms.vMDeviceID) {
goto out;
}
matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
if (IO_OBJECT_NULL != service) {
if (IOObjectConformsTo(service, kIOCDMediaClass))
returnValue = kVLCMediaAudioCD;
else if (IOObjectConformsTo(service, kIODVDMediaClass))
returnValue = kVLCMediaDVD;
else if (IOObjectConformsTo(service, kIOBDMediaClass))
returnValue = kVLCMediaBD;
IOObjectRelease(service);
if (returnValue)
return returnValue;
}
out:
if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
returnValue = kVLCMediaVideoTSFolder;
else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
returnValue = kVLCMediaBDMVFolder;
else {
// NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
NSFileManager * fm = [[NSFileManager alloc] init];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
for (int i = 0; i < [dirContents count]; i++) {
NSString *currentFile = [dirContents objectAtIndex:i];
NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
BOOL isDir;
if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
{
if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame) {
returnValue = kVLCMediaSVCD;
break;
}
if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame) {
returnValue = kVLCMediaVCD;
break;
}
if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame) {
returnValue = kVLCMediaBDMVFolder;
break;
}
if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame) {
returnValue = kVLCMediaVideoTSFolder;
break;
}
}
}
if (!returnValue)
returnValue = kVLCMediaVideoTSFolder;
}
return returnValue;
}
@end
NSImage *imageFromRes(NSString *o_id)
......
......@@ -233,3 +233,9 @@ typedef NSInteger NSByteCountFormatterCountStyle;
+ (NSString *)stringFromByteCount:(long long)byteCount countStyle:(NSByteCountFormatterCountStyle)countStyle;
@end
extern NSString *const VLCOpenTextFieldWasClicked;
@interface VLCOpenTextField : NSTextField
- (void)mouseDown:(NSEvent *)theEvent;
@end
......@@ -32,6 +32,7 @@
#import <CoreAudio/CoreAudio.h>
#import <vlc_keys.h>
NSString *const VLCOpenTextFieldWasClicked = @"VLCOpenTextFieldWasClicked";
/*****************************************************************************
* NSSound (VLCAdditions)
......@@ -999,3 +1000,14 @@ end:
}
@end
@implementation VLCOpenTextField
- (void)mouseDown:(NSEvent *)theEvent
{
[[NSNotificationCenter defaultCenter] postNotificationName: VLCOpenTextFieldWasClicked
object: self];
[super mouseDown: theEvent];
}
@end
/*****************************************************************************
* open.h: Open dialogues for VLC's MacOS X port
*****************************************************************************
* Copyright (C) 2002-2012 VLC authors and VideoLAN
* Copyright (C) 2002-2015 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
......@@ -24,15 +24,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#define kVLCMediaAudioCD @"AudioCD"
#define kVLCMediaDVD @"DVD"
#define kVLCMediaVCD @"VCD"
#define kVLCMediaSVCD @"SVCD"
#define kVLCMediaBD @"Blu-ray"
#define kVLCMediaVideoTSFolder @"VIDEO_TS"
#define kVLCMediaBDMVFolder @"BDMV"
#define kVLCMediaUnknown @"Unknown"
/*****************************************************************************
* Intf_Open interface
*****************************************************************************/
......@@ -221,22 +212,11 @@
IBOutlet id o_capture_height_stp;
}
+ (VLCOpen *)sharedInstance;
@property (readwrite, assign) NSString *MRL;
@property (readonly) NSArray *qtkvideoDevices;
@property (readonly) NSArray *qtkaudioDevices;
/* text field / stepper binding values - subs panel */
@property (nonatomic) float fileSubDelay;
@property (nonatomic) float fileSubFps;
- (void)qtkrefreshVideoDevices;
- (void)qtkrefreshAudioDevices;
- (void)setSubPanel;
- (void)openTarget:(int)i_type;
- (void)tabView:(NSTabView *)o_tv didSelectTabViewItem:(NSTabViewItem *)o_tvi;
- (void)textFieldWasClicked:(NSNotification *)o_notification;
- (IBAction)expandMRLfieldAction:(id)sender;
......@@ -244,21 +224,15 @@
- (IBAction)fileTimeCustomization:(id)sender;
- (void)openFileGeneric;
- (void)openFilePathChanged:(NSNotification *)o_notification;
- (IBAction)openFileBrowse:(id)sender;
- (IBAction)openFileStreamChanged:(id)sender;
- (void)openDisc;
- (void)scanOpticalMedia:(NSNotification *)o_notification;
- (IBAction)discSelectorChanged:(id)sender;
- (IBAction)openSpecialMediaFolder:(id)sender;
- (IBAction)dvdreadOptionChanged:(id)sender;
- (IBAction)vcdOptionChanged:(id)sender;
// static helper functions
+ (NSString *)getVolumeTypeFromMountPath:(NSString *)mountPath;
+ (NSString *)getBSDNodeFromMountPath:(NSString *)mountPath;
- (void)openNet;
- (IBAction)openNetModeChanged:(id)sender;
- (IBAction)openNetStepperChanged:(id)sender;
......@@ -266,7 +240,6 @@
- (IBAction)openNetUDPButtonAction:(id)sender;
- (void)openCapture;
- (void)showCaptureView: theView;
- (IBAction)openCaptureModeChanged:(id)sender;
- (IBAction)qtkChanged:(id)sender;
- (IBAction)qtkAudioChanged:(id)sender;
......@@ -275,9 +248,6 @@
- (IBAction)eyetvSwitchChannel:(id)sender;
- (IBAction)eyetvLaunch:(id)sender;
- (IBAction)eyetvGetPlugin:(id)sender;
- (void)eyetvChanged:(NSNotification *)o_notification;
- (void)setupChannelInfo;
- (void)screenFPSfieldChanged:(NSNotification *)o_notification;
- (IBAction)subsChanged:(id)sender;
- (IBAction)subSettings:(id)sender;
......@@ -291,7 +261,3 @@
- (void)openFile;
@end
@interface VLCOpenTextField : NSTextField
- (void)mouseDown:(NSEvent *)theEvent;
@end
This diff is collapsed.
......@@ -613,19 +613,19 @@
[[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:o_path isRemovable: &b_rem
isWritable:&b_writable isUnmountable:NULL description:NULL type:NULL] && b_rem && !b_writable && [o_nsurl isFileURL]) {
NSString *diskType = [VLCOpen getVolumeTypeFromMountPath: o_path];
NSString *diskType = [[VLCStringUtility sharedInstance] getVolumeTypeFromMountPath: o_path];
msg_Dbg(p_intf, "detected optical media of type %s in the file input", [diskType UTF8String]);
if ([diskType isEqualToString: kVLCMediaDVD])
o_uri = [NSString stringWithFormat: @"dvdnav://%@", [VLCOpen getBSDNodeFromMountPath: o_path]];
o_uri = [NSString stringWithFormat: @"dvdnav://%@", [[VLCStringUtility sharedInstance] getBSDNodeFromMountPath: o_path]];
else if ([diskType isEqualToString: kVLCMediaVideoTSFolder])
o_uri = [NSString stringWithFormat: @"dvdnav://%@", o_path];
else if ([diskType isEqualToString: kVLCMediaAudioCD])
o_uri = [NSString stringWithFormat: @"cdda://%@", [VLCOpen getBSDNodeFromMountPath: o_path]];
o_uri = [NSString stringWithFormat: @"cdda://%@", [[VLCStringUtility sharedInstance] getBSDNodeFromMountPath: o_path]];
else if ([diskType isEqualToString: kVLCMediaVCD])
o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [VLCOpen getBSDNodeFromMountPath: o_path]];
o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [[VLCStringUtility sharedInstance] getBSDNodeFromMountPath: o_path]];
else if ([diskType isEqualToString: kVLCMediaSVCD])
o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [VLCOpen getBSDNodeFromMountPath: o_path]];
o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [[VLCStringUtility sharedInstance] getBSDNodeFromMountPath: o_path]];
else if ([diskType isEqualToString: kVLCMediaBD] || [diskType isEqualToString: kVLCMediaBDMVFolder])
o_uri = [NSString stringWithFormat: @"bluray://%@", o_path];
else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment