[vlc-devel] [PATCH 02/18] qml: add msToString helper function

Prince Gupta guptaprince8832 at gmail.com
Thu Apr 1 14:29:37 UTC 2021


---
 modules/gui/qt/Makefile.am         |  1 +
 modules/gui/qt/util/qml/Helpers.js | 38 ++++++++++++++++++++++++++++++
 modules/gui/qt/vlc.qrc             |  1 +
 3 files changed, 40 insertions(+)
 create mode 100644 modules/gui/qt/util/qml/Helpers.js

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 7857c8390a..8146de9019 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -723,6 +723,7 @@ libqt_plugin_la_QML = \
 	gui/qt/style/VLCIcons.qml \
 	gui/qt/style/VLCStyle.qml \
 	gui/qt/style/qmldir \
+	gui/qt/util/qml/Helpers.js \
 	gui/qt/util/qml/KeyHelper.js \
 	gui/qt/util/qml/SelectableDelegateModel.qml \
 	gui/qt/widgets/qml/BannerTabButton.qml \
diff --git a/modules/gui/qt/util/qml/Helpers.js b/modules/gui/qt/util/qml/Helpers.js
new file mode 100644
index 0000000000..761d13a4c6
--- /dev/null
+++ b/modules/gui/qt/util/qml/Helpers.js
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (C) 2021 VLC authors and VideoLAN
+ *
+ * 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.
+ *****************************************************************************/
+
+.pragma library
+
+function msToString(time, short) {
+    if (time < 0) return "--:--"
+
+    var t_sec = Math.floor(time / 1000)
+    var sec = t_sec % 60
+    var min = Math.floor(t_sec / 60) % 60
+    var hour = Math.floor(t_sec / 3600)
+
+    function prefixZero(number) {
+        return number < 10 ? "0" + number : number;
+    }
+
+    if (hour === 0)
+        return "%1:%2".arg(prefixZero(min)).arg(prefixZero(sec))
+    if (!!short)
+        return "%1h%2".arg(hour.toFixed()).arg(prefixZero(min))
+    return "%1:%2:%3".arg(prefixZero(hour)).arg(prefixZero(min)).arg(prefixZero(sec))
+}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 3cda8faf6c..5c19b8d393 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -26,6 +26,7 @@
         <file alias="wait4.svg">pixmaps/util/wait4.svg</file>
         <file alias="SelectableDelegateModel.qml">util/qml/SelectableDelegateModel.qml</file>
         <file alias="KeyHelper.js">util/qml/KeyHelper.js</file>
+        <file alias="Helpers.js">util/qml/Helpers.js</file>
     </qresource>
     <qresource prefix="/toolbar">
         <file alias="faster.svg">pixmaps/faster.svg</file>
-- 
2.27.0



More information about the vlc-devel mailing list