/*****************************************************************************
* StringUtility.m: MacOS X interface module
*****************************************************************************
- * Copyright (C) 2002-2012 VLC authors and VideoLAN
+ * Copyright (C) 2002-2014 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-#import <vlc_input.h>
+#import "intf.h"
+#import "StringUtility.h"
+#import "CompatibilityFixes.h"
+
#import <vlc_keys.h>
#import <vlc_strings.h>
-#import "StringUtility.h"
-#import "intf.h"
-
@implementation VLCStringUtility
static VLCStringUtility *_o_sharedInstance = nil;
- (NSString *)localizedString:(const char *)psz
{
- NSString * o_str = nil;
+ NSString * stringObject = nil;
if (psz != NULL) {
- o_str = [NSString stringWithCString: _(psz) encoding:NSUTF8StringEncoding];
+ stringObject = [NSString stringWithCString: _(psz) encoding:NSUTF8StringEncoding];
- if (o_str == NULL) {
+ if (stringObject == NULL) {
msg_Err(VLCIntf, "could not translate: %s", psz);
- return(@"");
+ return @"";
}
- } else {
- msg_Warn(VLCIntf, "can't translate empty strings");
- return(@"");
- }
+ } else
+ return @"";
- return(o_str);
+ return stringObject;
}
/* i_width is in pixels */
-- (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
+- (NSString *)wrapString:(NSString *)o_in_string toWidth:(int)i_width
{
NSMutableString *o_wrapped;
NSString *o_out_string;
- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative
{
assert(p_input != nil);
-
+
vlc_value_t time;
char psz_time[MSTRTIME_MAX_SIZE];
-
+
var_Get(p_input, "time", &time);
-
+
mtime_t dur = input_item_GetDuration(input_GetItem(p_input));
if (b_negative && dur > 0) {
mtime_t remaining = 0;
return [NSString stringWithUTF8String:secstotimestr(psz_time, (time.i_time / 1000000))];
}
+- (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
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
return returnStr;
}
-
@end
+
+NSImage *imageFromRes(NSString *o_id)
+{
+ NSString *result = @"";
+ if (OSX_YOSEMITE) {
+ result = [result stringByAppendingString:@"ys-"];
+ }
+
+ result = [result stringByAppendingString:o_id];
+
+ return [NSImage imageNamed:result];
+}