macosx: rename to VLCStringUtility
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Mon, 8 Aug 2016 16:47:05 +0000 (18:47 +0200)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Mon, 8 Aug 2016 16:47:29 +0000 (18:47 +0200)
13 files changed:
extras/package/macosx/vlc.xcodeproj/project.pbxproj
modules/gui/macosx/Makefile.am
modules/gui/macosx/StringUtility.h [deleted file]
modules/gui/macosx/StringUtility.m [deleted file]
modules/gui/macosx/VLCAddonListItem.m
modules/gui/macosx/VLCPLModel.m
modules/gui/macosx/VLCRendererItem.m
modules/gui/macosx/VLCResumeDialogController.m
modules/gui/macosx/VLCStatusBarIcon.m
modules/gui/macosx/VLCStringUtility.h [new file with mode: 0644]
modules/gui/macosx/VLCStringUtility.m [new file with mode: 0644]
modules/gui/macosx/VLCTimeSelectionPanelController.m
modules/gui/macosx/intf.h

index 8443ef0..b2e049c 100644 (file)
                1CCB5F861A62A724004C3E90 /* SharedDialogs.m in Sources */ = {isa = PBXBuildFile; fileRef = CC461F6D160078340022423C /* SharedDialogs.m */; };
                1CCB5F871A62A724004C3E90 /* simple_prefs.h in Sources */ = {isa = PBXBuildFile; fileRef = CCB24D5E0D54BBAE004D780C /* simple_prefs.h */; };
                1CCB5F881A62A724004C3E90 /* simple_prefs.m in Sources */ = {isa = PBXBuildFile; fileRef = CCB24D5D0D54BBAE004D780C /* simple_prefs.m */; };
-               1CCB5F891A62A724004C3E90 /* StringUtility.h in Sources */ = {isa = PBXBuildFile; fileRef = CC269A4615E7947F00F2FDC9 /* StringUtility.h */; };
-               1CCB5F8A1A62A724004C3E90 /* StringUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = CC269A4715E7947F00F2FDC9 /* StringUtility.m */; };
+               1CCB5F891A62A724004C3E90 /* VLCStringUtility.h in Sources */ = {isa = PBXBuildFile; fileRef = CC269A4615E7947F00F2FDC9 /* VLCStringUtility.h */; };
+               1CCB5F8A1A62A724004C3E90 /* VLCStringUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = CC269A4715E7947F00F2FDC9 /* VLCStringUtility.m */; };
                1CCB5F8B1A62A724004C3E90 /* VLCTrackSynchronizationWindowController.h in Sources */ = {isa = PBXBuildFile; fileRef = CC707EC3137464CD0003010A /* VLCTrackSynchronizationWindowController.h */; };
                1CCB5F8C1A62A724004C3E90 /* VLCTrackSynchronizationWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = CC707EC4137464CD0003010A /* VLCTrackSynchronizationWindowController.m */; };
                1CCB5F8D1A62A724004C3E90 /* VLCVideoEffectsWindowController.h in Sources */ = {isa = PBXBuildFile; fileRef = CCCE366D13817E4500694F2A /* VLCVideoEffectsWindowController.h */; };
                CC206B5F14ACFEB8007935C6 /* topbar-dark-right.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "topbar-dark-right.png"; path = "Resources/mainwindow_dark/topbar-dark-right.png"; sourceTree = SOURCE_ROOT; };
                CC206B6314AD044A007935C6 /* lion-window-minimize-over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "lion-window-minimize-over.png"; sourceTree = "<group>"; };
                CC206B6914AD0A52007935C6 /* window-resize.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "window-resize.png"; path = "Resources/mainwindow_dark/window-resize.png"; sourceTree = "<group>"; };
-               CC269A4615E7947F00F2FDC9 /* StringUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = StringUtility.h; path = ../../../modules/gui/macosx/StringUtility.h; sourceTree = SOURCE_ROOT; };
-               CC269A4715E7947F00F2FDC9 /* StringUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = StringUtility.m; path = ../../../modules/gui/macosx/StringUtility.m; sourceTree = SOURCE_ROOT; };
+               CC269A4615E7947F00F2FDC9 /* VLCStringUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = VLCStringUtility.h; path = ../../../modules/gui/macosx/VLCStringUtility.h; sourceTree = SOURCE_ROOT; };
+               CC269A4715E7947F00F2FDC9 /* VLCStringUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = VLCStringUtility.m; path = ../../../modules/gui/macosx/VLCStringUtility.m; sourceTree = SOURCE_ROOT; };
                CC3DC89B0A7CDB9600B53F32 /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = /System/Library/Frameworks/ApplicationServices.framework; sourceTree = "<absolute>"; };
                CC3F2E8815F5038F009D7F39 /* playlist-1btn-pressed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "playlist-1btn-pressed.png"; path = "Resources/mainwindow/playlist-1btn-pressed.png"; sourceTree = "<group>"; };
                CC3F2E8915F5038F009D7F39 /* playlist-1btn-pressed@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "playlist-1btn-pressed@2x.png"; path = "Resources/mainwindow/playlist-1btn-pressed@2x.png"; sourceTree = "<group>"; };
                                CC461F6D160078340022423C /* SharedDialogs.m */,
                                CCB24D5E0D54BBAE004D780C /* simple_prefs.h */,
                                CCB24D5D0D54BBAE004D780C /* simple_prefs.m */,
-                               CC269A4615E7947F00F2FDC9 /* StringUtility.h */,
-                               CC269A4715E7947F00F2FDC9 /* StringUtility.m */,
+                               CC269A4615E7947F00F2FDC9 /* VLCStringUtility.h */,
+                               CC269A4715E7947F00F2FDC9 /* VLCStringUtility.m */,
                                CC707EC3137464CD0003010A /* VLCTrackSynchronizationWindowController.h */,
                                CC707EC4137464CD0003010A /* VLCTrackSynchronizationWindowController.m */,
                                CCCE366D13817E4500694F2A /* VLCVideoEffectsWindowController.h */,
                                1CCB5F861A62A724004C3E90 /* SharedDialogs.m in Sources */,
                                1CCB5F871A62A724004C3E90 /* simple_prefs.h in Sources */,
                                1CCB5F881A62A724004C3E90 /* simple_prefs.m in Sources */,
-                               1CCB5F891A62A724004C3E90 /* StringUtility.h in Sources */,
-                               1CCB5F8A1A62A724004C3E90 /* StringUtility.m in Sources */,
+                               1CCB5F891A62A724004C3E90 /* VLCStringUtility.h in Sources */,
+                               1CCB5F8A1A62A724004C3E90 /* VLCStringUtility.m in Sources */,
                                1CCB5F8B1A62A724004C3E90 /* VLCTrackSynchronizationWindowController.h in Sources */,
                                1CCB5F8C1A62A724004C3E90 /* VLCTrackSynchronizationWindowController.m in Sources */,
                                6BBBB8B71D114628001BD9BA /* VLCRendererDiscovery.m in Sources */,
index 3ef5958..ff8af4f 100644 (file)
@@ -60,7 +60,7 @@ libmacosx_plugin_la_SOURCES = \
        SPInvocationGrabbing.h SPInvocationGrabbing.m \
        SPMediaKeyTap.h SPMediaKeyTap.m \
        Spotify.h \
-       StringUtility.h StringUtility.m \
+       VLCStringUtility.h VLCStringUtility.m \
        VideoView.h VideoView.m \
        VLCTimeSelectionPanelController.h VLCTimeSelectionPanelController.m \
        VLCUIWidgets.h VLCUIWidgets.m \
diff --git a/modules/gui/macosx/StringUtility.h b/modules/gui/macosx/StringUtility.h
deleted file mode 100644 (file)
index 47edb94..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*****************************************************************************
- * StringUtility.h: MacOS X interface module
- *****************************************************************************
- * Copyright (C) 2002-2014 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
- *          Christophe Massiot <massiot@via.ecp.fr>
- *          Derk-Jan Hartman <hartman at videolan dot org>
- *          Felix Paul Kühne <fkuehne at videolan dot org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#import <Cocoa/Cocoa.h>
-#import <vlc_input.h>
-
-#define _NS(s) [[VLCStringUtility sharedInstance] localizedString: s]
-/* Get an alternate version of the string.
- * This string is stored as '1:string' but when displayed it only displays
- * the translated string. the translation should be '1:translatedstring' though */
-#define _ANS(s) [[[VLCStringUtility sharedInstance] localizedString: _(s)] substringFromIndex:2]
-
-#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);
-
-/**
- * Gets the proper variant for an image ressource,
- * depending on the os version.
- */
-NSImage *imageFromRes(NSString *o_id);
-
-@interface VLCStringUtility : NSObject
-
-+ (VLCStringUtility *)sharedInstance;
-
-- (NSString *)localizedString:(const char *)psz NS_FORMAT_ARGUMENT(1);
-- (NSString *)wrapString: (NSString *)o_in_string toWidth: (int)i_width;
-- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative;
-- (NSString *)stringForTime:(long long int)time;
-
-- (NSString *)OSXStringKeyToString:(NSString *)theString;
-- (NSString *)VLCKeyToString:(NSString *)theString;
-- (unsigned int)VLCModifiersToCocoa:(NSString *)theString;
-
-- (NSString *)b64Decode:(NSString *)string;
-- (NSString *)b64EncodeAndFree:(char *)psz_string;
-
-- (NSString *)getVolumeTypeFromMountPath:(NSString *)mountPath;
-- (NSString *)getBSDNodeFromMountPath:(NSString *)mountPath;
-
-@end
diff --git a/modules/gui/macosx/StringUtility.m b/modules/gui/macosx/StringUtility.m
deleted file mode 100644 (file)
index 19783f0..0000000
+++ /dev/null
@@ -1,542 +0,0 @@
-/*****************************************************************************
- * StringUtility.m: MacOS X interface module
- *****************************************************************************
- * Copyright (C) 2002-2014 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
- *          Christophe Massiot <massiot@via.ecp.fr>
- *          Derk-Jan Hartman <hartman at videolan dot org>
- *          Felix Paul Kühne <fkuehne at videolan dot org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#import "intf.h"
-#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>
-
-@implementation VLCStringUtility
-
-
-+ (VLCStringUtility *)sharedInstance
-{
-    static VLCStringUtility *sharedInstance = nil;
-    static dispatch_once_t pred;
-
-    dispatch_once(&pred, ^{
-        sharedInstance = [VLCStringUtility new];
-    });
-
-    return sharedInstance;
-}
-
-#pragma mark -
-#pragma mark String utility
-
-- (NSString *)localizedString:(const char *)psz
-{
-    NSString * stringObject = nil;
-
-    if (psz != NULL) {
-        stringObject = toNSStr(_(psz));
-
-        if (stringObject == NULL) {
-            msg_Err(getIntf(), "could not translate: %s", psz);
-            return @"";
-        }
-    } else
-        return @"";
-
-    return stringObject;
-}
-
-/* i_width is in pixels */
-- (NSString *)wrapString:(NSString *)o_in_string toWidth:(int)i_width
-{
-    NSMutableString *o_wrapped;
-    NSString *o_out_string;
-    NSRange glyphRange, effectiveRange, charRange;
-    NSRect lineFragmentRect;
-    unsigned glyphIndex, breaksInserted = 0;
-
-    NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
-                                                          attributes: [NSDictionary dictionaryWithObjectsAndKeys:
-                                                                       [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
-    NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
-    NSTextContainer *o_container = [[NSTextContainer alloc]
-                                    initWithContainerSize: NSMakeSize(i_width, 2000)];
-
-    [o_layout_manager addTextContainer: o_container];
-    [o_storage addLayoutManager: o_layout_manager];
-
-    o_wrapped = [o_in_string mutableCopy];
-    glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
-
-    for (glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
-        glyphIndex += effectiveRange.length) {
-        lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
-                                                              effectiveRange: &effectiveRange];
-        charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
-                                                 actualGlyphRange: &effectiveRange];
-        if ([o_wrapped lineRangeForRange:
-            NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
-            [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
-            breaksInserted++;
-        }
-    }
-    o_out_string = [NSString stringWithString: o_wrapped];
-
-    return o_out_string;
-}
-
-- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative
-{
-    assert(p_input != nil);
-
-    char psz_time[MSTRTIME_MAX_SIZE];
-    int64_t t = var_GetInteger(p_input, "time");
-
-    mtime_t dur = input_item_GetDuration(input_GetItem(p_input));
-    if (b_negative && dur > 0) {
-        mtime_t remaining = 0;
-        if (dur > t)
-            remaining = dur - t;
-        return [NSString stringWithFormat: @"-%s", secstotimestr(psz_time, (remaining / 1000000))];
-    } else
-        return toNSStr(secstotimestr(psz_time, t / CLOCK_FREQ ));
-}
-
-- (NSString *)stringForTime:(long long int)time
-{
-    if (time > 0) {
-        long long positiveDuration = llabs(time);
-        if (positiveDuration > 3600)
-            return [NSString stringWithFormat:@"%s%01ld:%02ld:%02ld",
-                    time < 0 ? "-" : "",
-                    (long) (positiveDuration / 3600),
-                    (long)((positiveDuration / 60) % 60),
-                    (long) (positiveDuration % 60)];
-        else
-            return [NSString stringWithFormat:@"%s%02ld:%02ld",
-                    time < 0 ? "-" : "",
-                    (long)((positiveDuration / 60) % 60),
-                    (long) (positiveDuration % 60)];
-    } else {
-        // Return a string that represents an undefined time.
-        return @"--:--";
-    }
-}
-
-#pragma mark -
-#pragma mark Key Shortcuts
-
-static struct
-{
-    unichar i_nskey;
-    unsigned int i_vlckey;
-} nskeys_to_vlckeys[] =
-{
-    { NSUpArrowFunctionKey, KEY_UP },
-    { NSDownArrowFunctionKey, KEY_DOWN },
-    { NSLeftArrowFunctionKey, KEY_LEFT },
-    { NSRightArrowFunctionKey, KEY_RIGHT },
-    { NSF1FunctionKey, KEY_F1 },
-    { NSF2FunctionKey, KEY_F2 },
-    { NSF3FunctionKey, KEY_F3 },
-    { NSF4FunctionKey, KEY_F4 },
-    { NSF5FunctionKey, KEY_F5 },
-    { NSF6FunctionKey, KEY_F6 },
-    { NSF7FunctionKey, KEY_F7 },
-    { NSF8FunctionKey, KEY_F8 },
-    { NSF9FunctionKey, KEY_F9 },
-    { NSF10FunctionKey, KEY_F10 },
-    { NSF11FunctionKey, KEY_F11 },
-    { NSF12FunctionKey, KEY_F12 },
-    { NSInsertFunctionKey, KEY_INSERT },
-    { NSHomeFunctionKey, KEY_HOME },
-    { NSEndFunctionKey, KEY_END },
-    { NSPageUpFunctionKey, KEY_PAGEUP },
-    { NSPageDownFunctionKey, KEY_PAGEDOWN },
-    { NSMenuFunctionKey, KEY_MENU },
-    { NSTabCharacter, KEY_TAB },
-    { NSCarriageReturnCharacter, KEY_ENTER },
-    { NSEnterCharacter, KEY_ENTER },
-    { NSBackspaceCharacter, KEY_BACKSPACE },
-    { NSDeleteCharacter, KEY_DELETE },
-    {0,0}
-};
-
-/*
- * Takes the first value of an cocoa key string, and converts it to VLCs int representation.
- */
-unsigned int CocoaKeyToVLC(unichar i_key)
-{
-    unsigned int i;
-
-    for (i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++) {
-        if (nskeys_to_vlckeys[i].i_nskey == i_key) {
-            return nskeys_to_vlckeys[i].i_vlckey;
-        }
-    }
-    return (unsigned int)i_key;
-}
-
-/* takes a good old const c string and converts it to NSString without UTF8 loss */
-
-NSString *toNSStr(const char *str) {
-    return str != NULL ? [NSString stringWithUTF8String:str] : @"";
-}
-
-/*
- * Converts VLC key string to a prettified version, for hotkey settings.
- * The returned string adapts similar how its done within the cocoa framework when setting this
- * key to menu items.
- */
-- (NSString *)OSXStringKeyToString:(NSString *)theString
-{
-    if (![theString isEqualToString:@""]) {
-        /* remove cruft */
-        if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
-            theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
-        else {
-            theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
-            theString = [NSString stringWithFormat:@"%@+", theString];
-        }
-        if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
-            theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
-        else {
-            theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
-            theString = [NSString stringWithFormat:@"%@-", theString];
-        }
-        /* modifiers */
-        theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString: [NSString stringWithUTF8String:"\xE2\x8C\x98"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString: [NSString stringWithUTF8String:"\xE2\x8C\xA5"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString: [NSString stringWithUTF8String:"\xE2\x87\xA7"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString: [NSString stringWithUTF8String:"\xE2\x8C\x83"]];
-        /* show non-character keys correctly */
-        theString = [theString stringByReplacingOccurrencesOfString:@"Right" withString:[NSString stringWithUTF8String:"\xE2\x86\x92"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Left" withString:[NSString stringWithUTF8String:"\xE2\x86\x90"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Page Up" withString:[NSString stringWithUTF8String:"\xE2\x87\x9E"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Page Down" withString:[NSString stringWithUTF8String:"\xE2\x87\x9F"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Up" withString:[NSString stringWithUTF8String:"\xE2\x86\x91"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Down" withString:[NSString stringWithUTF8String:"\xE2\x86\x93"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Enter" withString:[NSString stringWithUTF8String:"\xe2\x86\xb5"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Tab" withString:[NSString stringWithUTF8String:"\xe2\x87\xa5"]];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Delete" withString:[NSString stringWithUTF8String:"\xe2\x8c\xab"]];        /* capitalize plain characters to suit the menubar's look */
-        theString = [theString capitalizedString];
-    }
-    else
-        theString = [NSString stringWithString:_NS("Not Set")];
-    return theString;
-}
-
-/*
- * Converts VLC key string to cocoa modifiers which can be used as setKeyEquivalent for menu items
- */
-- (unsigned int)VLCModifiersToCocoa:(NSString *)theString
-{
-    unsigned int new = 0;
-
-    if ([theString rangeOfString:@"Command"].location != NSNotFound)
-        new |= NSCommandKeyMask;
-    if ([theString rangeOfString:@"Alt"].location != NSNotFound)
-        new |= NSAlternateKeyMask;
-    if ([theString rangeOfString:@"Shift"].location != NSNotFound)
-        new |= NSShiftKeyMask;
-    if ([theString rangeOfString:@"Ctrl"].location != NSNotFound)
-        new |= NSControlKeyMask;
-    return new;
-}
-
-/*
- * Converts VLC key to cocoa string which can be used as setKeyEquivalentModifierMask for menu items
- */
-- (NSString *)VLCKeyToString:(NSString *)theString
-{
-    if (![theString isEqualToString:@""]) {
-        if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
-            theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
-        else {
-            theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
-            theString = [NSString stringWithFormat:@"%@+", theString];
-        }
-        if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
-            theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
-        else {
-            theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
-            theString = [NSString stringWithFormat:@"%@-", theString];
-        }
-        theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString:@""];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString:@""];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString:@""];
-        theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString:@""];
-    }
-
-#ifdef __clang__
-#pragma GCC diagnostic ignored "-Wformat"
-#endif
-    if ([theString length] > 1) {
-        if ([theString rangeOfString:@"Page Up"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSPageUpFunctionKey];
-        else if ([theString rangeOfString:@"Page Down"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSPageDownFunctionKey];
-        else if ([theString rangeOfString:@"Up"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSUpArrowFunctionKey];
-        else if ([theString rangeOfString:@"Down"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSDownArrowFunctionKey];
-        else if ([theString rangeOfString:@"Right"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSRightArrowFunctionKey];
-        else if ([theString rangeOfString:@"Left"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSLeftArrowFunctionKey];
-        else if ([theString rangeOfString:@"Enter"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSEnterCharacter]; // we treat NSCarriageReturnCharacter as aquivalent
-        else if ([theString rangeOfString:@"Insert"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSInsertFunctionKey];
-        else if ([theString rangeOfString:@"Home"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSHomeFunctionKey];
-        else if ([theString rangeOfString:@"End"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSEndFunctionKey];
-        else if ([theString rangeOfString:@"Menu"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSMenuFunctionKey];
-        else if ([theString rangeOfString:@"Tab"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSTabCharacter];
-        else if ([theString rangeOfString:@"Backspace"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSBackspaceCharacter];
-        else if ([theString rangeOfString:@"Delete"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSDeleteCharacter];
-        else if ([theString rangeOfString:@"F12"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF12FunctionKey];
-        else if ([theString rangeOfString:@"F11"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF11FunctionKey];
-        else if ([theString rangeOfString:@"F10"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF10FunctionKey];
-        else if ([theString rangeOfString:@"F9"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF9FunctionKey];
-        else if ([theString rangeOfString:@"F8"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF8FunctionKey];
-        else if ([theString rangeOfString:@"F7"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF7FunctionKey];
-        else if ([theString rangeOfString:@"F6"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF6FunctionKey];
-        else if ([theString rangeOfString:@"F5"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF5FunctionKey];
-        else if ([theString rangeOfString:@"F4"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF4FunctionKey];
-        else if ([theString rangeOfString:@"F3"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF3FunctionKey];
-        else if ([theString rangeOfString:@"F2"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF2FunctionKey];
-        else if ([theString rangeOfString:@"F1"].location != NSNotFound)
-            return [NSString stringWithFormat:@"%C", NSF1FunctionKey];
-        else if ([theString rangeOfString:@"Space"].location != NSNotFound)
-            return @" ";
-        /* note that we don't support esc here, since it is reserved for leaving fullscreen */
-    }
-#ifdef __clang__
-#pragma GCC diagnostic warning "-Wformat"
-#endif
-
-    return theString;
-}
-
-#pragma mark -
-#pragma mark base64 helpers
-
-- (NSString *)b64Decode:(NSString *)string
-{
-    char *psz_decoded_string = vlc_b64_decode([string UTF8String]);
-    if(!psz_decoded_string)
-        return @"";
-
-    NSString *returnStr = [NSString stringWithFormat:@"%s", psz_decoded_string];
-    free(psz_decoded_string);
-
-    return returnStr;
-}
-
-- (NSString *)b64EncodeAndFree:(char *)psz_string
-{
-    char *psz_encoded_string = vlc_b64_encode(psz_string);
-    free(psz_string);
-    if(!psz_encoded_string)
-        return @"";
-
-    NSString *returnStr = [NSString stringWithFormat:@"%s", psz_encoded_string];
-    free(psz_encoded_string);
-
-    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)
-{
-    NSString *result = @"";
-    if (OSX_YOSEMITE || OSX_EL_CAPITAN || OSX_SIERRA) {
-        result = [result stringByAppendingString:@"ys-"];
-    }
-
-    result = [result stringByAppendingString:o_id];
-
-    return [NSImage imageNamed:result];
-}
index e5faa9a..6cc1811 100644 (file)
@@ -22,7 +22,7 @@
 
 #import "intf.h"
 #import "VLCAddonListItem.h"
-#import "StringUtility.h"
+#import "VLCStringUtility.h"
 
 @interface VLCAddonListItem ()
 {
index 55beed0..ef4b4b4 100644 (file)
@@ -24,7 +24,7 @@
 #import "misc.h"    /* VLCByteCountFormatter */
 
 #import "VLCPlaylist.h"
-#import "StringUtility.h"
+#import "VLCStringUtility.h"
 #import "intf.h"
 #import "ControlsBar.h"
 #import "VLCMainMenu.h"
index 8d4f894..d8efcfd 100644 (file)
@@ -22,7 +22,7 @@
  *****************************************************************************/
 
 #import "VLCRendererItem.h"
-#import "StringUtility.h"
+#import "VLCStringUtility.h"
 
 #include <vlc_common.h>
 #include <vlc_renderer_discovery.h>
index 97617f6..d19a322 100644 (file)
@@ -25,7 +25,7 @@
 #import "VLCResumeDialogController.h"
 
 #import "intf.h"
-#import "StringUtility.h"
+#import "VLCStringUtility.h"
 
 @interface VLCResumeDialogController()
 {
index 1144d92..0b04afa 100644 (file)
@@ -31,7 +31,7 @@
 #import <vlc_input.h>
 
 #import "VLCCoreInteraction.h"
-#import "StringUtility.h"
+#import "VLCStringUtility.h"
 
 @interface VLCStatusBarIcon ()
 {
diff --git a/modules/gui/macosx/VLCStringUtility.h b/modules/gui/macosx/VLCStringUtility.h
new file mode 100644 (file)
index 0000000..659900e
--- /dev/null
@@ -0,0 +1,76 @@
+/*****************************************************************************
+ * VLCStringUtility.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2002-2014 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
+ *          Christophe Massiot <massiot@via.ecp.fr>
+ *          Derk-Jan Hartman <hartman at videolan dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+#import <vlc_input.h>
+
+#define _NS(s) [[VLCStringUtility sharedInstance] localizedString: s]
+/* Get an alternate version of the string.
+ * This string is stored as '1:string' but when displayed it only displays
+ * the translated string. the translation should be '1:translatedstring' though */
+#define _ANS(s) [[[VLCStringUtility sharedInstance] localizedString: _(s)] substringFromIndex:2]
+
+#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);
+
+/**
+ * Gets the proper variant for an image ressource,
+ * depending on the os version.
+ */
+NSImage *imageFromRes(NSString *o_id);
+
+@interface VLCStringUtility : NSObject
+
++ (VLCStringUtility *)sharedInstance;
+
+- (NSString *)localizedString:(const char *)psz NS_FORMAT_ARGUMENT(1);
+- (NSString *)wrapString: (NSString *)o_in_string toWidth: (int)i_width;
+- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative;
+- (NSString *)stringForTime:(long long int)time;
+
+- (NSString *)OSXStringKeyToString:(NSString *)theString;
+- (NSString *)VLCKeyToString:(NSString *)theString;
+- (unsigned int)VLCModifiersToCocoa:(NSString *)theString;
+
+- (NSString *)b64Decode:(NSString *)string;
+- (NSString *)b64EncodeAndFree:(char *)psz_string;
+
+- (NSString *)getVolumeTypeFromMountPath:(NSString *)mountPath;
+- (NSString *)getBSDNodeFromMountPath:(NSString *)mountPath;
+
+@end
diff --git a/modules/gui/macosx/VLCStringUtility.m b/modules/gui/macosx/VLCStringUtility.m
new file mode 100644 (file)
index 0000000..b26923e
--- /dev/null
@@ -0,0 +1,543 @@
+/*****************************************************************************
+ * VLCStringUtility.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2002-2014 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
+ *          Christophe Massiot <massiot@via.ecp.fr>
+ *          Derk-Jan Hartman <hartman at videolan dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCStringUtility.h"
+
+#import "intf.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>
+
+@implementation VLCStringUtility
+
+
++ (VLCStringUtility *)sharedInstance
+{
+    static VLCStringUtility *sharedInstance = nil;
+    static dispatch_once_t pred;
+
+    dispatch_once(&pred, ^{
+        sharedInstance = [VLCStringUtility new];
+    });
+
+    return sharedInstance;
+}
+
+#pragma mark -
+#pragma mark String utility
+
+- (NSString *)localizedString:(const char *)psz
+{
+    NSString * stringObject = nil;
+
+    if (psz != NULL) {
+        stringObject = toNSStr(_(psz));
+
+        if (stringObject == NULL) {
+            msg_Err(getIntf(), "could not translate: %s", psz);
+            return @"";
+        }
+    } else
+        return @"";
+
+    return stringObject;
+}
+
+/* i_width is in pixels */
+- (NSString *)wrapString:(NSString *)o_in_string toWidth:(int)i_width
+{
+    NSMutableString *o_wrapped;
+    NSString *o_out_string;
+    NSRange glyphRange, effectiveRange, charRange;
+    NSRect lineFragmentRect;
+    unsigned glyphIndex, breaksInserted = 0;
+
+    NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
+                                                          attributes: [NSDictionary dictionaryWithObjectsAndKeys:
+                                                                       [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
+    NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
+    NSTextContainer *o_container = [[NSTextContainer alloc]
+                                    initWithContainerSize: NSMakeSize(i_width, 2000)];
+
+    [o_layout_manager addTextContainer: o_container];
+    [o_storage addLayoutManager: o_layout_manager];
+
+    o_wrapped = [o_in_string mutableCopy];
+    glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
+
+    for (glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
+        glyphIndex += effectiveRange.length) {
+        lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
+                                                              effectiveRange: &effectiveRange];
+        charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
+                                                 actualGlyphRange: &effectiveRange];
+        if ([o_wrapped lineRangeForRange:
+            NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
+            [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
+            breaksInserted++;
+        }
+    }
+    o_out_string = [NSString stringWithString: o_wrapped];
+
+    return o_out_string;
+}
+
+- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative
+{
+    assert(p_input != nil);
+
+    char psz_time[MSTRTIME_MAX_SIZE];
+    int64_t t = var_GetInteger(p_input, "time");
+
+    mtime_t dur = input_item_GetDuration(input_GetItem(p_input));
+    if (b_negative && dur > 0) {
+        mtime_t remaining = 0;
+        if (dur > t)
+            remaining = dur - t;
+        return [NSString stringWithFormat: @"-%s", secstotimestr(psz_time, (remaining / 1000000))];
+    } else
+        return toNSStr(secstotimestr(psz_time, t / CLOCK_FREQ ));
+}
+
+- (NSString *)stringForTime:(long long int)time
+{
+    if (time > 0) {
+        long long positiveDuration = llabs(time);
+        if (positiveDuration > 3600)
+            return [NSString stringWithFormat:@"%s%01ld:%02ld:%02ld",
+                    time < 0 ? "-" : "",
+                    (long) (positiveDuration / 3600),
+                    (long)((positiveDuration / 60) % 60),
+                    (long) (positiveDuration % 60)];
+        else
+            return [NSString stringWithFormat:@"%s%02ld:%02ld",
+                    time < 0 ? "-" : "",
+                    (long)((positiveDuration / 60) % 60),
+                    (long) (positiveDuration % 60)];
+    } else {
+        // Return a string that represents an undefined time.
+        return @"--:--";
+    }
+}
+
+#pragma mark -
+#pragma mark Key Shortcuts
+
+static struct
+{
+    unichar i_nskey;
+    unsigned int i_vlckey;
+} nskeys_to_vlckeys[] =
+{
+    { NSUpArrowFunctionKey, KEY_UP },
+    { NSDownArrowFunctionKey, KEY_DOWN },
+    { NSLeftArrowFunctionKey, KEY_LEFT },
+    { NSRightArrowFunctionKey, KEY_RIGHT },
+    { NSF1FunctionKey, KEY_F1 },
+    { NSF2FunctionKey, KEY_F2 },
+    { NSF3FunctionKey, KEY_F3 },
+    { NSF4FunctionKey, KEY_F4 },
+    { NSF5FunctionKey, KEY_F5 },
+    { NSF6FunctionKey, KEY_F6 },
+    { NSF7FunctionKey, KEY_F7 },
+    { NSF8FunctionKey, KEY_F8 },
+    { NSF9FunctionKey, KEY_F9 },
+    { NSF10FunctionKey, KEY_F10 },
+    { NSF11FunctionKey, KEY_F11 },
+    { NSF12FunctionKey, KEY_F12 },
+    { NSInsertFunctionKey, KEY_INSERT },
+    { NSHomeFunctionKey, KEY_HOME },
+    { NSEndFunctionKey, KEY_END },
+    { NSPageUpFunctionKey, KEY_PAGEUP },
+    { NSPageDownFunctionKey, KEY_PAGEDOWN },
+    { NSMenuFunctionKey, KEY_MENU },
+    { NSTabCharacter, KEY_TAB },
+    { NSCarriageReturnCharacter, KEY_ENTER },
+    { NSEnterCharacter, KEY_ENTER },
+    { NSBackspaceCharacter, KEY_BACKSPACE },
+    { NSDeleteCharacter, KEY_DELETE },
+    {0,0}
+};
+
+/*
+ * Takes the first value of an cocoa key string, and converts it to VLCs int representation.
+ */
+unsigned int CocoaKeyToVLC(unichar i_key)
+{
+    unsigned int i;
+
+    for (i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++) {
+        if (nskeys_to_vlckeys[i].i_nskey == i_key) {
+            return nskeys_to_vlckeys[i].i_vlckey;
+        }
+    }
+    return (unsigned int)i_key;
+}
+
+/* takes a good old const c string and converts it to NSString without UTF8 loss */
+
+NSString *toNSStr(const char *str) {
+    return str != NULL ? [NSString stringWithUTF8String:str] : @"";
+}
+
+/*
+ * Converts VLC key string to a prettified version, for hotkey settings.
+ * The returned string adapts similar how its done within the cocoa framework when setting this
+ * key to menu items.
+ */
+- (NSString *)OSXStringKeyToString:(NSString *)theString
+{
+    if (![theString isEqualToString:@""]) {
+        /* remove cruft */
+        if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
+            theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
+        else {
+            theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
+            theString = [NSString stringWithFormat:@"%@+", theString];
+        }
+        if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
+            theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
+        else {
+            theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
+            theString = [NSString stringWithFormat:@"%@-", theString];
+        }
+        /* modifiers */
+        theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString: [NSString stringWithUTF8String:"\xE2\x8C\x98"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString: [NSString stringWithUTF8String:"\xE2\x8C\xA5"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString: [NSString stringWithUTF8String:"\xE2\x87\xA7"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString: [NSString stringWithUTF8String:"\xE2\x8C\x83"]];
+        /* show non-character keys correctly */
+        theString = [theString stringByReplacingOccurrencesOfString:@"Right" withString:[NSString stringWithUTF8String:"\xE2\x86\x92"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Left" withString:[NSString stringWithUTF8String:"\xE2\x86\x90"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Page Up" withString:[NSString stringWithUTF8String:"\xE2\x87\x9E"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Page Down" withString:[NSString stringWithUTF8String:"\xE2\x87\x9F"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Up" withString:[NSString stringWithUTF8String:"\xE2\x86\x91"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Down" withString:[NSString stringWithUTF8String:"\xE2\x86\x93"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Enter" withString:[NSString stringWithUTF8String:"\xe2\x86\xb5"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Tab" withString:[NSString stringWithUTF8String:"\xe2\x87\xa5"]];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Delete" withString:[NSString stringWithUTF8String:"\xe2\x8c\xab"]];        /* capitalize plain characters to suit the menubar's look */
+        theString = [theString capitalizedString];
+    }
+    else
+        theString = [NSString stringWithString:_NS("Not Set")];
+    return theString;
+}
+
+/*
+ * Converts VLC key string to cocoa modifiers which can be used as setKeyEquivalent for menu items
+ */
+- (unsigned int)VLCModifiersToCocoa:(NSString *)theString
+{
+    unsigned int new = 0;
+
+    if ([theString rangeOfString:@"Command"].location != NSNotFound)
+        new |= NSCommandKeyMask;
+    if ([theString rangeOfString:@"Alt"].location != NSNotFound)
+        new |= NSAlternateKeyMask;
+    if ([theString rangeOfString:@"Shift"].location != NSNotFound)
+        new |= NSShiftKeyMask;
+    if ([theString rangeOfString:@"Ctrl"].location != NSNotFound)
+        new |= NSControlKeyMask;
+    return new;
+}
+
+/*
+ * Converts VLC key to cocoa string which can be used as setKeyEquivalentModifierMask for menu items
+ */
+- (NSString *)VLCKeyToString:(NSString *)theString
+{
+    if (![theString isEqualToString:@""]) {
+        if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
+            theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
+        else {
+            theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
+            theString = [NSString stringWithFormat:@"%@+", theString];
+        }
+        if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
+            theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
+        else {
+            theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
+            theString = [NSString stringWithFormat:@"%@-", theString];
+        }
+        theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString:@""];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString:@""];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString:@""];
+        theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString:@""];
+    }
+
+#ifdef __clang__
+#pragma GCC diagnostic ignored "-Wformat"
+#endif
+    if ([theString length] > 1) {
+        if ([theString rangeOfString:@"Page Up"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSPageUpFunctionKey];
+        else if ([theString rangeOfString:@"Page Down"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSPageDownFunctionKey];
+        else if ([theString rangeOfString:@"Up"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSUpArrowFunctionKey];
+        else if ([theString rangeOfString:@"Down"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSDownArrowFunctionKey];
+        else if ([theString rangeOfString:@"Right"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSRightArrowFunctionKey];
+        else if ([theString rangeOfString:@"Left"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSLeftArrowFunctionKey];
+        else if ([theString rangeOfString:@"Enter"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSEnterCharacter]; // we treat NSCarriageReturnCharacter as aquivalent
+        else if ([theString rangeOfString:@"Insert"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSInsertFunctionKey];
+        else if ([theString rangeOfString:@"Home"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSHomeFunctionKey];
+        else if ([theString rangeOfString:@"End"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSEndFunctionKey];
+        else if ([theString rangeOfString:@"Menu"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSMenuFunctionKey];
+        else if ([theString rangeOfString:@"Tab"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSTabCharacter];
+        else if ([theString rangeOfString:@"Backspace"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSBackspaceCharacter];
+        else if ([theString rangeOfString:@"Delete"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSDeleteCharacter];
+        else if ([theString rangeOfString:@"F12"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF12FunctionKey];
+        else if ([theString rangeOfString:@"F11"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF11FunctionKey];
+        else if ([theString rangeOfString:@"F10"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF10FunctionKey];
+        else if ([theString rangeOfString:@"F9"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF9FunctionKey];
+        else if ([theString rangeOfString:@"F8"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF8FunctionKey];
+        else if ([theString rangeOfString:@"F7"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF7FunctionKey];
+        else if ([theString rangeOfString:@"F6"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF6FunctionKey];
+        else if ([theString rangeOfString:@"F5"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF5FunctionKey];
+        else if ([theString rangeOfString:@"F4"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF4FunctionKey];
+        else if ([theString rangeOfString:@"F3"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF3FunctionKey];
+        else if ([theString rangeOfString:@"F2"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF2FunctionKey];
+        else if ([theString rangeOfString:@"F1"].location != NSNotFound)
+            return [NSString stringWithFormat:@"%C", NSF1FunctionKey];
+        else if ([theString rangeOfString:@"Space"].location != NSNotFound)
+            return @" ";
+        /* note that we don't support esc here, since it is reserved for leaving fullscreen */
+    }
+#ifdef __clang__
+#pragma GCC diagnostic warning "-Wformat"
+#endif
+
+    return theString;
+}
+
+#pragma mark -
+#pragma mark base64 helpers
+
+- (NSString *)b64Decode:(NSString *)string
+{
+    char *psz_decoded_string = vlc_b64_decode([string UTF8String]);
+    if(!psz_decoded_string)
+        return @"";
+
+    NSString *returnStr = [NSString stringWithFormat:@"%s", psz_decoded_string];
+    free(psz_decoded_string);
+
+    return returnStr;
+}
+
+- (NSString *)b64EncodeAndFree:(char *)psz_string
+{
+    char *psz_encoded_string = vlc_b64_encode(psz_string);
+    free(psz_string);
+    if(!psz_encoded_string)
+        return @"";
+
+    NSString *returnStr = [NSString stringWithFormat:@"%s", psz_encoded_string];
+    free(psz_encoded_string);
+
+    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)
+{
+    NSString *result = @"";
+    if (OSX_YOSEMITE || OSX_EL_CAPITAN || OSX_SIERRA) {
+        result = [result stringByAppendingString:@"ys-"];
+    }
+
+    result = [result stringByAppendingString:o_id];
+
+    return [NSImage imageNamed:result];
+}
index 5beb204..82ca6a4 100644 (file)
@@ -22,7 +22,7 @@
 #import "VLCTimeSelectionPanelController.h"
 
 #import "misc.h"
-#import "StringUtility.h"
+#import "VLCStringUtility.h"
 
 @interface VLCTimeSelectionPanelController()
 {
index 171915c..6469d5d 100644 (file)
@@ -42,7 +42,7 @@
 #import "VLCMainWindow.h"
 #import "VLCVoutWindowController.h"
 #import "VLCStatusBarIcon.h"
-#import "StringUtility.h"
+#import "VLCStringUtility.h"
 
 /*****************************************************************************
  * Local prototypes.