diff --git a/app/qml/mpris.qml b/app/qml/mpris.qml --- a/app/qml/mpris.qml +++ b/app/qml/mpris.qml @@ -28,10 +28,18 @@ id: root property QtObject pluginInterface property bool muted: false + property bool updatePositionSlider: true property int volumeUnmuted property var volume: pluginInterface.volume + property var songPosition: pluginInterface.position title: i18n("Multimedia Controls") + onSongPositionChanged: { + if (updatePositionSlider) { + positionSlider.value = songPosition + } + } + onVolumeChanged: { if (muted && volume != 0) { toggleMute() @@ -52,12 +60,25 @@ } } - function toggleMute() { + function toggleMute() + { muted = !muted root.pluginInterface.volume = muted ? 0 : volumeUnmuted muteButton.icon.name = muted ? "audio-volume-muted" : soundState(root.pluginInterface.volume) } + function msToTime(currentTime, totalTime) + { + if (totalTime.getHours() == 2) { + // Skip a day ahead as Date type's minimum is 1am on the 1st of January and can't go lower + currentTime.setDate(2) + currentTime.setHours(currentTime.getHours() - 1) + return currentTime.toLocaleTimeString(Qt.locale(),"hh:mm:ss") + } else { + return currentTime.toLocaleTimeString(Qt.locale(),"mm:ss") + } + } + Label { id: noPlayersText text: i18n("No players available") @@ -80,6 +101,28 @@ model: root.pluginInterface.playerList onCurrentTextChanged: root.pluginInterface.player = currentText } + RowLayout { + Layout.fillWidth: true + Label { + text: msToTime(new Date(positionSlider.value), new Date(root.pluginInterface.length)) + } + Slider { + id: positionSlider + to: root.pluginInterface.length + Layout.fillWidth: true + onPressedChanged: { + if (pressed) { + updatePositionSlider = false + } else { + root.pluginInterface.position = valueAt(position) + updatePositionSlider = true + } + } + } + Label { + text: msToTime(new Date(root.pluginInterface.length), new Date(root.pluginInterface.length)) + } + } Label { id: nowPlaying Layout.fillWidth: true