]> git.sesse.net Git - vlc/blobdiff - projects/macosx/framework/Sources/VLCTime.m
macosx/framework: Activate our dialog provider.
[vlc] / projects / macosx / framework / Sources / VLCTime.m
index de36bd14f3ab2648a75aa58b8e671d94dd9089d0..fa4dc4e3058c0a51a48fb5dde06e390c605457c7 100644 (file)
     return [[[VLCTime alloc] initWithNumber:aNumber] autorelease];
 }
 
++ (VLCTime *)timeWithInt:(NSInteger)aInt
+{
+    return [[[VLCTime alloc] initWithInt:aInt] autorelease];
+}
+
 /* Initializers */
 - (id)initWithNumber:(NSNumber *)aNumber
 {
     if (self = [super init])
     {
         if (aNumber)
-            value = [[aNumber copy] retain];
+            value = [aNumber copy];
+        else
+            value = nil;
+    }
+    return self;
+}
+
+- (id)initWithInt:(int)aInt
+{
+    if (self = [super init])
+    {
+        if (aInt)
+            value = [[NSNumber numberWithInt: aInt] retain];
         else
             value = nil;
     }
     }
 }
 
+- (NSString *)verboseStringValue
+{
+    if (value)
+    {
+        long long duration = [value longLongValue] / 1000000;
+        long long positiveDuration = llabs(duration);
+        long hours = positiveDuration / 3600;
+        long mins = (positiveDuration / 60) % 60;
+        long seconds = positiveDuration % 60;
+        const char * remaining = duration < 0 ? " remaining" : "";
+        if (hours > 0)
+            return [NSString stringWithFormat:@"%d hours %d minutes%s", hours, mins, remaining];
+        else if (mins > 5)
+            return [NSString stringWithFormat:@"%d minutes%s", mins, remaining];
+        else if (mins > 0)
+            return [NSString stringWithFormat:@"%d minutes %d seconds%s", mins, seconds, remaining];
+        else
+            return [NSString stringWithFormat:@"%d seconds%s", seconds, remaining];
+    }
+    else
+    {
+        // Return a string that represents an undefined time.
+        return @"";
+    }
+}
+
+- (int)intValue
+{
+    if( value )
+        return [value intValue];
+    return 0;
+}
+
 - (NSComparisonResult)compare:(VLCTime *)aTime
 {
     if (!aTime && !value)