Changeset View
Changeset View
Standalone View
Standalone View
app/qml/mpris.qml
Show All 22 Lines | |||||
23 | import QtQuick.Layouts 1.1 | 23 | import QtQuick.Layouts 1.1 | ||
24 | import org.kde.kirigami 2.0 as Kirigami | 24 | import org.kde.kirigami 2.0 as Kirigami | ||
25 | 25 | | |||
26 | Kirigami.Page | 26 | Kirigami.Page | ||
27 | { | 27 | { | ||
28 | id: root | 28 | id: root | ||
29 | property QtObject pluginInterface | 29 | property QtObject pluginInterface | ||
30 | property bool muted: false | 30 | property bool muted: false | ||
31 | property bool updatePositionSlider: true | ||||
31 | property int volumeUnmuted | 32 | property int volumeUnmuted | ||
32 | property var volume: pluginInterface.volume | 33 | property var volume: pluginInterface.volume | ||
34 | property var lastPosition: pluginInterface.position | ||||
35 | property date lastPositionTime: new Date() | ||||
33 | title: i18n("Multimedia Controls") | 36 | title: i18n("Multimedia Controls") | ||
34 | 37 | | |||
38 | onLastPositionChanged: { | ||||
39 | lastPositionTime = new Date(); | ||||
40 | } | ||||
41 | | ||||
35 | onVolumeChanged: { | 42 | onVolumeChanged: { | ||
36 | if (muted && volume != 0) { | 43 | if (muted && volume != 0) { | ||
37 | toggleMute() | 44 | toggleMute() | ||
38 | volumeUnmuted = volume | 45 | volumeUnmuted = volume | ||
39 | } else if (!muted) { | 46 | } else if (!muted) { | ||
40 | volumeUnmuted = volume | 47 | volumeUnmuted = volume | ||
41 | } | 48 | } | ||
42 | } | 49 | } | ||
43 | 50 | | |||
44 | function soundState(volume) | 51 | function soundState(volume) | ||
45 | { | 52 | { | ||
46 | if (volume <= 25) { | 53 | if (volume <= 25) { | ||
47 | return "audio-volume-low" | 54 | return "audio-volume-low" | ||
48 | } else if (volume <= 75) { | 55 | } else if (volume <= 75) { | ||
49 | return "audio-volume-medium" | 56 | return "audio-volume-medium" | ||
50 | } else { | 57 | } else { | ||
51 | return "audio-volume-high" | 58 | return "audio-volume-high" | ||
52 | } | 59 | } | ||
53 | } | 60 | } | ||
54 | 61 | | |||
55 | function toggleMute() { | 62 | function toggleMute() | ||
63 | { | ||||
56 | muted = !muted | 64 | muted = !muted | ||
57 | root.pluginInterface.volume = muted ? 0 : volumeUnmuted | 65 | root.pluginInterface.volume = muted ? 0 : volumeUnmuted | ||
58 | muteButton.icon.name = muted ? "audio-volume-muted" : soundState(root.pluginInterface.volume) | 66 | muteButton.icon.name = muted ? "audio-volume-muted" : soundState(root.pluginInterface.volume) | ||
59 | } | 67 | } | ||
60 | 68 | | |||
69 | function msToTime(currentTime, totalTime) | ||||
70 | { | ||||
71 | if (totalTime.getHours() == 2) { | ||||
72 | // Skip a day ahead as Date type's minimum is 1am on the 1st of January and can't go lower | ||||
73 | currentTime.setDate(2) | ||||
74 | currentTime.setHours(currentTime.getHours() - 1) | ||||
75 | return currentTime.toLocaleTimeString(Qt.locale(),"hh:mm:ss") | ||||
76 | } else { | ||||
77 | return currentTime.toLocaleTimeString(Qt.locale(),"mm:ss") | ||||
78 | } | ||||
79 | } | ||||
80 | | ||||
81 | Connections { | ||||
82 | target: root.pluginInterface | ||||
83 | onNowPlayingChanged: positionSlider.value = lastPosition | ||||
84 | } | ||||
85 | | ||||
61 | Label { | 86 | Label { | ||
62 | id: noPlayersText | 87 | id: noPlayersText | ||
63 | text: i18n("No players available") | 88 | text: i18n("No players available") | ||
64 | anchors.centerIn: parent | 89 | anchors.centerIn: parent | ||
65 | visible: pluginInterface.playerList.length == 0 | 90 | visible: pluginInterface.playerList.length == 0 | ||
66 | } | 91 | } | ||
67 | 92 | | |||
68 | ColumnLayout | 93 | ColumnLayout | ||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 140 | RowLayout { | |||
127 | Button { | 152 | Button { | ||
128 | Layout.fillWidth: true | 153 | Layout.fillWidth: true | ||
129 | icon.name: "media-skip-forward" | 154 | icon.name: "media-skip-forward" | ||
130 | onClicked: root.pluginInterface.sendAction("Next") | 155 | onClicked: root.pluginInterface.sendAction("Next") | ||
131 | } | 156 | } | ||
132 | } | 157 | } | ||
133 | RowLayout { | 158 | RowLayout { | ||
134 | Layout.fillWidth: true | 159 | Layout.fillWidth: true | ||
160 | Label { | ||||
161 | text: msToTime(new Date(positionSlider.value), new Date(root.pluginInterface.length)) | ||||
162 | } | ||||
163 | Slider { | ||||
164 | id: positionSlider | ||||
165 | to: root.pluginInterface.length | ||||
166 | Layout.fillWidth: true | ||||
167 | Timer { | ||||
168 | id: positionUpdateTimer | ||||
169 | interval: 1000 | ||||
170 | repeat: true | ||||
171 | running: updatePositionSlider && root.pluginInterface.isPlaying | ||||
172 | | ||||
173 | onTriggered: positionSlider.value = lastPosition + (new Date().getTime() - lastPositionTime.getTime()) | ||||
174 | } | ||||
175 | onPressedChanged: { | ||||
176 | if (pressed) { | ||||
177 | updatePositionSlider = false | ||||
178 | } else { | ||||
179 | updatePositionSlider = true | ||||
180 | root.pluginInterface.position = value | ||||
181 | } | ||||
182 | } | ||||
183 | } | ||||
184 | Label { | ||||
185 | text: msToTime(new Date(root.pluginInterface.length), new Date(root.pluginInterface.length)) | ||||
186 | } | ||||
187 | } | ||||
188 | RowLayout { | ||||
189 | Layout.fillWidth: true | ||||
135 | Button { | 190 | Button { | ||
136 | id: muteButton | 191 | id: muteButton | ||
137 | icon.name: soundState(root.pluginInterface.volume) | 192 | icon.name: soundState(root.pluginInterface.volume) | ||
138 | onClicked: toggleMute() | 193 | onClicked: toggleMute() | ||
139 | } | 194 | } | ||
140 | Slider { | 195 | Slider { | ||
141 | id: volumeSlider | 196 | id: volumeSlider | ||
142 | value: volumeUnmuted | 197 | value: volumeUnmuted | ||
Show All 15 Lines |