Skip to content

Commit

Permalink
Fix durations
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Sep 15, 2024
1 parent 520da78 commit 0162e49
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 52 deletions.
1 change: 1 addition & 0 deletions application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ qt_add_qml_module(thebeat
QueuePane.qml
ArtistsAlbumsPane.qml
LibraryHeader.qml
common.js
SOURCES
playlistmodel.h playlistmodel.cpp
NO_CACHEGEN
Expand Down
30 changes: 17 additions & 13 deletions application/ControlStrip.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(" · ");
});
}
}
}
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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)
}
}
}
Expand Down
31 changes: 16 additions & 15 deletions application/LibraryListing.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import Contemporary
import "common.js" as Common

ListView {
id: root
Expand Down Expand Up @@ -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
Expand All @@ -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(" · ");
});
}
}
}
Expand All @@ -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;
}
}
}
}
15 changes: 15 additions & 0 deletions application/common.js
Original file line number Diff line number Diff line change
@@ -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(":");
}
4 changes: 2 additions & 2 deletions application/translations/ar_SA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@
<translation type="unfinished">من %1</translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished">على %1</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@
<translation type="unfinished">od %1</translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished">na %1</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/da_DK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@
<translation type="unfinished">af %1</translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished">i %1</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/de_DE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@
<translation type="unfinished">von %1</translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished">auf %1</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/en_GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@
<translation type="unfinished">by %1</translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished">on %1</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/fr_CA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/id_ID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@
<translation type="unfinished">oleh %1</translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished">dalam %1</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/nl_NL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@
<translation type="unfinished">door %1</translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished">op %1</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/tr_TR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@
<translation type="unfinished">%1 tarafından</translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished">%1&apos;de</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/ur_PK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/vi_VN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@
<translation type="unfinished">bởi %1</translation>
</message>
<message>
<location line="+1"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+1"/>
<location line="+2"/>
<location filename="../../../build-theBeat-Desktop_ARM-Debug/application/com/vicr123/thebeat/LibraryListing.qml" line="+2"/>
<source>on %1</source>
<translation type="unfinished">trên %1</translation>
</message>
Expand Down

0 comments on commit 0162e49

Please sign in to comment.