[vlc-commits] macosx: Move time helper to string category

Marvin Scholz git at videolan.org
Tue Oct 9 13:06:48 CEST 2018


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Tue Oct  9 13:04:36 2018 +0200| [8afe989a4d2e85ab8d66bd0c2f088b9ba506d3db] | committer: Marvin Scholz

macosx: Move time helper to string category

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8afe989a4d2e85ab8d66bd0c2f088b9ba506d3db
---

 modules/gui/macosx/NSString+Helpers.h          | 10 ++++++++++
 modules/gui/macosx/NSString+Helpers.m          | 21 +++++++++++++++++++++
 modules/gui/macosx/VLCResumeDialogController.m |  3 ++-
 modules/gui/macosx/VLCStatusBarIcon.m          |  2 +-
 modules/gui/macosx/VLCStringUtility.h          |  2 --
 modules/gui/macosx/VLCStringUtility.m          | 25 -------------------------
 6 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/modules/gui/macosx/NSString+Helpers.h b/modules/gui/macosx/NSString+Helpers.h
index 35ea1165cb..b0935a8c2b 100644
--- a/modules/gui/macosx/NSString+Helpers.h
+++ b/modules/gui/macosx/NSString+Helpers.h
@@ -42,6 +42,16 @@
                                negative:(BOOL)negative;
 
 /**
+ Creates an NSString with the given time in seconds
+
+ This method allocates and initializes an NSString with the given
+ time formatted as playback time.
+
+ \param time   Time in seconds
+ */
++ (instancetype)stringWithTime:(long long int)time;
+
+/**
  Creates an NSString from the given null-terminated C string
  buffer encoded as base64
 
diff --git a/modules/gui/macosx/NSString+Helpers.m b/modules/gui/macosx/NSString+Helpers.m
index 36773ec235..9623afd7ad 100644
--- a/modules/gui/macosx/NSString+Helpers.m
+++ b/modules/gui/macosx/NSString+Helpers.m
@@ -53,6 +53,27 @@
     }
 }
 
++ (instancetype)stringWithTime:(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 @"--:--";
+    }
+}
+
 + (instancetype)base64StringWithCString:(const char *)cstring
 {
     if (cstring == NULL)
diff --git a/modules/gui/macosx/VLCResumeDialogController.m b/modules/gui/macosx/VLCResumeDialogController.m
index be4208e9de..4ddc2e0f6a 100644
--- a/modules/gui/macosx/VLCResumeDialogController.m
+++ b/modules/gui/macosx/VLCResumeDialogController.m
@@ -26,6 +26,7 @@
 
 #import "VLCMain.h"
 #import "VLCStringUtility.h"
+#import "NSString+Helpers.h"
 
 @interface VLCResumeDialogController()
 {
@@ -66,7 +67,7 @@
     char *psz_title_name = input_item_GetTitleFbName(p_item);
     NSString *o_title = toNSStr(psz_title_name);
     free(psz_title_name);
-    NSString *labelString = [NSString stringWithFormat:_NS("Playback of \"%@\" will continue at %@"), o_title, [[VLCStringUtility sharedInstance] stringForTime:pos]];
+    NSString *labelString = [NSString stringWithFormat:_NS("Playback of \"%@\" will continue at %@"), o_title, [NSString stringWithTime:pos]];
     [o_text_lbl setStringValue:labelString];
     [o_always_resume_chk setState: NSOffState];
 
diff --git a/modules/gui/macosx/VLCStatusBarIcon.m b/modules/gui/macosx/VLCStatusBarIcon.m
index f6f61e50b5..2b23ae6c88 100644
--- a/modules/gui/macosx/VLCStatusBarIcon.m
+++ b/modules/gui/macosx/VLCStatusBarIcon.m
@@ -260,7 +260,7 @@
             [totalField setStringValue:@"∞"];
         } else {
             /* Not unknown, update displayed duration */
-            totalTime = [[VLCStringUtility sharedInstance] stringForTime:(dur/1000000)];
+            totalTime = [NSString stringWithTime:SEC_FROM_VLC_TICK(dur)];
             [progressField setStringValue:(showTimeElapsed) ? elapsedTime : remainingTime];
             [totalField setStringValue:totalTime];
         }
diff --git a/modules/gui/macosx/VLCStringUtility.h b/modules/gui/macosx/VLCStringUtility.h
index f7f241954c..2321f6fb6b 100644
--- a/modules/gui/macosx/VLCStringUtility.h
+++ b/modules/gui/macosx/VLCStringUtility.h
@@ -58,8 +58,6 @@ NSImage *imageFromRes(NSString *name);
 
 + (VLCStringUtility *)sharedInstance;
 
-- (NSString *)stringForTime:(long long int)time;
-
 - (NSString *)OSXStringKeyToString:(NSString *)theString;
 - (NSString *)VLCKeyToString:(NSString *)theString;
 - (unsigned int)VLCModifiersToCocoa:(NSString *)theString;
diff --git a/modules/gui/macosx/VLCStringUtility.m b/modules/gui/macosx/VLCStringUtility.m
index bcba2110a6..82a20e944a 100644
--- a/modules/gui/macosx/VLCStringUtility.m
+++ b/modules/gui/macosx/VLCStringUtility.m
@@ -65,31 +65,6 @@ NSString *const kVLCMediaUnknown = @"Unknown";
 }
 
 #pragma mark -
-#pragma mark String utility
-
-
-- (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



More information about the vlc-commits mailing list