Verified Commit 30d6726f authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applets/mediacontroller: add `isPlaying` property

This reduces unnecessary string comparisons in the applet.
parent 53b86a50
Pipeline #208127 passed with stage
in 6 minutes and 37 seconds
......@@ -573,7 +573,7 @@ PlasmaExtras.Representation {
id: seekTimer
interval: 1000 / expandedRepresentation.rate
repeat: true
running: root.state === "playing" && Plasmoid.expanded && !keyPressed && interval > 0 && seekSlider.to >= 1000000
running: root.isPlaying && Plasmoid.expanded && !keyPressed && interval > 0 && seekSlider.to >= 1000000
onTriggered: {
// some players don't continuously update the seek slider position via mpris
// add one second; value in microseconds
......@@ -666,8 +666,8 @@ PlasmaExtras.Representation {
icon.width: expandedRepresentation.controlSize
icon.height: expandedRepresentation.controlSize
Layout.alignment: Qt.AlignVCenter
enabled: root.state == "playing" ? root.canPause : root.canPlay
icon.name: root.state == "playing" ? "media-playback-pause" : "media-playback-start"
enabled: root.isPlaying ? root.canPause : root.canPlay
icon.name: root.isPlaying ? "media-playback-pause" : "media-playback-start"
onClicked: root.togglePlaying()
}
......
......@@ -64,6 +64,7 @@ Item {
readonly property bool canGoNext: (canControl && mpris2Source.currentData.CanGoNext) || false
readonly property bool canPlay: (canControl && mpris2Source.currentData.CanPlay) || false
readonly property bool canPause: (canControl && mpris2Source.currentData.CanPause) || false
readonly property bool isPlaying: root.state === "playing"
// var instead of bool so we can use "undefined" for "shuffle not supported"
readonly property var shuffle: !root.noPlayer && typeof mpris2Source.currentData.Shuffle === "boolean"
......@@ -101,15 +102,15 @@ Item {
})
// if CanPause, toggle the menu entry between Play & Pause, otherwise always use Play
if (root.state == "playing" && root.canPause) {
if (root.isPlaying && root.canPause) {
Plasmoid.setAction("pause", i18nc("Pause playback", "Pause"), "media-playback-pause")
Plasmoid.action("pause").enabled = Qt.binding(function() {
return root.state === "playing" && root.canPause;
return root.isPlaying && root.canPause;
});
} else {
Plasmoid.setAction("play", i18nc("Start playback", "Play"), "media-playback-start")
Plasmoid.action("play").enabled = Qt.binding(function() {
return root.state !== "playing" && root.canPlay;
return !root.isPlaying && root.canPlay;
});
}
......@@ -121,7 +122,7 @@ Item {
Plasmoid.setAction("stop", i18nc("Stop playback", "Stop"), "media-playback-stop")
Plasmoid.action("stop").enabled = Qt.binding(function() {
return root.state === "playing" || root.state === "paused";
return root.isPlaying || root.state === "paused";
})
}
......@@ -157,7 +158,7 @@ Item {
Plasmoid.compactRepresentation: PlasmaCore.IconItem {
source: {
if (root.state === "playing") {
if (root.isPlaying) {
return "media-playback-playing";
} else if (root.state === "paused") {
return "media-playback-paused";
......@@ -229,7 +230,7 @@ Item {
}
function togglePlaying() {
if (root.state === "playing") {
if (root.isPlaying) {
if (root.canPause) {
root.action_pause();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment