From 0162e49ef44906e15579debd083e06329aaa9651 Mon Sep 17 00:00:00 2001 From: Victor Tran Date: Sun, 15 Sep 2024 19:22:56 +1000 Subject: [PATCH] Fix durations --- application/CMakeLists.txt | 1 + application/ControlStrip.qml | 30 +++++++++++++++++------------- application/LibraryListing.qml | 31 ++++++++++++++++--------------- application/common.js | 15 +++++++++++++++ application/translations/ar_SA.ts | 4 ++-- application/translations/cs.ts | 4 ++-- application/translations/da_DK.ts | 4 ++-- application/translations/de_DE.ts | 4 ++-- application/translations/en_GB.ts | 4 ++-- application/translations/en_US.ts | 4 ++-- application/translations/fr_CA.ts | 4 ++-- application/translations/id_ID.ts | 4 ++-- application/translations/nl_NL.ts | 4 ++-- application/translations/tr_TR.ts | 4 ++-- application/translations/ur_PK.ts | 4 ++-- application/translations/vi_VN.ts | 4 ++-- 16 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 application/common.js diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index c51f71d..43c7553 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -104,6 +104,7 @@ qt_add_qml_module(thebeat QueuePane.qml ArtistsAlbumsPane.qml LibraryHeader.qml + common.js SOURCES playlistmodel.h playlistmodel.cpp NO_CACHEGEN diff --git a/application/ControlStrip.qml b/application/ControlStrip.qml index 2fb34e7..968bda3 100644 --- a/application/ControlStrip.qml +++ b/application/ControlStrip.qml @@ -4,6 +4,7 @@ import QtQuick.Layouts import com.vicr123.Contemporary import com.vicr123.thebeat import Contemporary +import "common.js" as Common Layer { id: root @@ -44,10 +45,12 @@ Layer { Component.onCompleted: () => { currentItemMeta.text = Qt.binding(() => { const list = []; - if (PlaylistManager.currentItem.authors.length !== 0) list.push(Contemporary.createSeparatedList(PlaylistManager.currentItem.authors)) - if (PlaylistManager.currentItem.album !== "") list.push(PlaylistManager.currentItem.album) - return list.join(" · ") - }) + if (PlaylistManager.currentItem.authors.length !== 0) + list.push(Contemporary.createSeparatedList(PlaylistManager.currentItem.authors)); + if (PlaylistManager.currentItem.album !== "") + list.push(PlaylistManager.currentItem.album); + return list.join(" · "); + }); } } } @@ -57,27 +60,27 @@ Layer { } Button { - Layout.alignment: Qt.AlignCenter id: shuffleButton + Layout.alignment: Qt.AlignCenter flat: true icon.name: "media-playlist-shuffle" implicitWidth: height checked: PlaylistManager.shuffle checkable: true onCheckedChanged: () => { - PlaylistManager.shuffle = shuffleButton.checked + PlaylistManager.shuffle = shuffleButton.checked; } } Button { - Layout.alignment: Qt.AlignCenter id: repeatOneButton + Layout.alignment: Qt.AlignCenter flat: true icon.name: "media-repeat-single" implicitWidth: height checked: PlaylistManager.repeatOne checkable: true onCheckedChanged: () => { - PlaylistManager.repeatOne = repeatOneButton.checked + PlaylistManager.repeatOne = repeatOneButton.checked; } } Button { @@ -90,8 +93,8 @@ Layer { } } Button { - Layout.alignment: Qt.AlignCenter id: playPauseButton + Layout.alignment: Qt.AlignCenter flat: true icon.name: PlaylistManager.state === PlaylistManager.Playing ? "media-playback-pause" : "media-playback-start" icon.height: 40 @@ -116,23 +119,24 @@ Layer { Layout.fillWidth: true Label { - text: "elapsed" + id: elapsedText + text: Common.durationToString(PlaylistManager.currentItem.elapsed) } Slider { - Layout.fillWidth: true id: progressSlider + Layout.fillWidth: true from: 0 to: PlaylistManager.currentItem.duration value: PlaylistManager.currentItem.elapsed onMoved: () => { - PlaylistManager.currentItem.seek(progressSlider.value) + PlaylistManager.currentItem.seek(progressSlider.value); } } Label { - text: "total" + text: Common.durationToString(PlaylistManager.currentItem.duration, true) } } } diff --git a/application/LibraryListing.qml b/application/LibraryListing.qml index ec870eb..68878b6 100644 --- a/application/LibraryListing.qml +++ b/application/LibraryListing.qml @@ -2,6 +2,7 @@ import QtQuick import QtQuick.Layouts import QtQuick.Controls import Contemporary +import "common.js" as Common ListView { id: root @@ -41,14 +42,13 @@ ListView { rowSpacing: 3 Label { + id: trackNumberLabel Layout.row: 0 Layout.column: 0 Layout.rowSpan: 2 Layout.fillHeight: true Layout.preferredWidth: implicitHeight - - id: trackNumberLabel text: trackItem.track === 0 ? "-" : trackItem.track color: Contemporary.disabled(Contemporary.foreground) verticalAlignment: Qt.AlignVCenter @@ -69,30 +69,31 @@ ListView { Label { id: trackDurationLabel - text: trackItem.duration + text: Common.durationToString(trackItem.duration) color: Contemporary.disabled(Contemporary.foreground) } } Label { + id: trackMetaLabel Layout.row: 1 Layout.column: 1 Layout.fillWidth: true Layout.fillHeight: true - - id: trackMetaLabel text: "." color: Contemporary.disabled(Contemporary.foreground) Component.onCompleted: () => { trackMetaLabel.text = Qt.binding(() => { const list = []; - if (trackItem.artist !== "") list.push(qsTr("by %1").arg(trackItem.artist)); - if (trackItem.album !== "") list.push(qsTr("on %1").arg(trackItem.album)); - - if (list.length == 0) return qsTr("Track"); - return list.join(" · ") - }) + if (trackItem.artist !== "") + list.push(qsTr("by %1").arg(trackItem.artist)); + if (trackItem.album !== "") + list.push(qsTr("on %1").arg(trackItem.album)); + if (list.length == 0) + return qsTr("Track"); + return list.join(" · "); + }); } } } @@ -104,10 +105,10 @@ ListView { hoverEnabled: true onClicked: () => { - const mediaItem = UrlManager.itemForUrl(Qt.url(`file://${trackItem.path}`)); - PlaylistManager.addItem(mediaItem) - PlaylistManager.currentItem = mediaItem; - } + const mediaItem = UrlManager.itemForUrl(Qt.url(`file://${trackItem.path}`)); + PlaylistManager.addItem(mediaItem); + PlaylistManager.currentItem = mediaItem; + } } } } diff --git a/application/common.js b/application/common.js new file mode 100644 index 0000000..1ab702f --- /dev/null +++ b/application/common.js @@ -0,0 +1,15 @@ +function durationToString(ms, zeroIsInfinity) { + if (zeroIsInfinity && ms === 0) return "∞"; + + let parts = []; + + const seconds = Math.floor(ms / 1000) % 60; + const minutes = Math.floor(ms / 1000 / 60) % 60; + const hours = Math.floor(ms / 1000 / 60 / 60); + + if (hours > 0) parts.push(`${hours}`); + parts.push(`${minutes}`.padStart(2, '0')); + parts.push(`${seconds}`.padStart(2, '0')); + + return parts.join(":"); +} diff --git a/application/translations/ar_SA.ts b/application/translations/ar_SA.ts index 8a0677c..936864d 100644 --- a/application/translations/ar_SA.ts +++ b/application/translations/ar_SA.ts @@ -365,8 +365,8 @@ من %1 - - + + on %1 على %1 diff --git a/application/translations/cs.ts b/application/translations/cs.ts index 8fd3c0a..843c7c3 100644 --- a/application/translations/cs.ts +++ b/application/translations/cs.ts @@ -337,8 +337,8 @@ od %1 - - + + on %1 na %1 diff --git a/application/translations/da_DK.ts b/application/translations/da_DK.ts index af396a6..c51dc50 100644 --- a/application/translations/da_DK.ts +++ b/application/translations/da_DK.ts @@ -349,8 +349,8 @@ af %1 - - + + on %1 i %1 diff --git a/application/translations/de_DE.ts b/application/translations/de_DE.ts index 78f92e0..f902de9 100644 --- a/application/translations/de_DE.ts +++ b/application/translations/de_DE.ts @@ -353,8 +353,8 @@ von %1 - - + + on %1 auf %1 diff --git a/application/translations/en_GB.ts b/application/translations/en_GB.ts index 554672e..eff3f0f 100644 --- a/application/translations/en_GB.ts +++ b/application/translations/en_GB.ts @@ -349,8 +349,8 @@ by %1 - - + + on %1 on %1 diff --git a/application/translations/en_US.ts b/application/translations/en_US.ts index 7b8a04a..e7e903f 100644 --- a/application/translations/en_US.ts +++ b/application/translations/en_US.ts @@ -312,8 +312,8 @@ - - + + on %1 diff --git a/application/translations/fr_CA.ts b/application/translations/fr_CA.ts index 1477399..12dd8df 100644 --- a/application/translations/fr_CA.ts +++ b/application/translations/fr_CA.ts @@ -330,8 +330,8 @@ - - + + on %1 diff --git a/application/translations/id_ID.ts b/application/translations/id_ID.ts index ea3f3a0..b815dfc 100644 --- a/application/translations/id_ID.ts +++ b/application/translations/id_ID.ts @@ -346,8 +346,8 @@ oleh %1 - - + + on %1 dalam %1 diff --git a/application/translations/nl_NL.ts b/application/translations/nl_NL.ts index 80205b7..fd244ed 100644 --- a/application/translations/nl_NL.ts +++ b/application/translations/nl_NL.ts @@ -345,8 +345,8 @@ door %1 - - + + on %1 op %1 diff --git a/application/translations/tr_TR.ts b/application/translations/tr_TR.ts index c59cbe9..ae66504 100644 --- a/application/translations/tr_TR.ts +++ b/application/translations/tr_TR.ts @@ -350,8 +350,8 @@ %1 tarafından - - + + on %1 %1'de diff --git a/application/translations/ur_PK.ts b/application/translations/ur_PK.ts index be25e77..14bf4d7 100644 --- a/application/translations/ur_PK.ts +++ b/application/translations/ur_PK.ts @@ -330,8 +330,8 @@ - - + + on %1 diff --git a/application/translations/vi_VN.ts b/application/translations/vi_VN.ts index b95f035..466a4b7 100644 --- a/application/translations/vi_VN.ts +++ b/application/translations/vi_VN.ts @@ -350,8 +350,8 @@ bởi %1 - - + + on %1 trên %1