diff --git a/applets/mediacontroller/contents/ui/ExpandedRepresentation.qml b/applets/mediacontroller/contents/ui/ExpandedRepresentation.qml --- a/applets/mediacontroller/contents/ui/ExpandedRepresentation.qml +++ b/applets/mediacontroller/contents/ui/ExpandedRepresentation.qml @@ -92,7 +92,7 @@ if (event.key === Qt.Key_Space || event.key === Qt.Key_K) { // K is YouTube's key for "play/pause" :) - root.action_playPause() + root.togglePlaying() } else if (event.key === Qt.Key_P) { root.action_previous() } else if (event.key === Qt.Key_N) { @@ -376,9 +376,9 @@ PlasmaComponents.ToolButton { width: Math.round(expandedRepresentation.controlSize * 1.5) height: width - enabled: root.state == "playing" ? root.canPause : root.canPlay - iconSource: root.state == "playing" ? "media-playback-pause" : "media-playback-start" - onClicked: root.action_playPause() + enabled: root.state === "playing" || root.canPlay + iconSource: root.state !== "playing" ? "media-playback-start" : root.canPause ? "media-playback-pause" : "media-playback-stop" + onClicked: root.togglePlaying(); } PlasmaComponents.ToolButton { diff --git a/applets/mediacontroller/contents/ui/main.qml b/applets/mediacontroller/contents/ui/main.qml --- a/applets/mediacontroller/contents/ui/main.qml +++ b/applets/mediacontroller/contents/ui/main.qml @@ -66,7 +66,7 @@ Plasmoid.toolTipMainText: i18n("No media playing") Plasmoid.toolTipSubText: "" Plasmoid.toolTipTextFormat: Text.PlainText - Plasmoid.status: PlasmaCore.Types.ActiveStatus + Plasmoid.status: PlasmaCore.Types.PassiveStatus Plasmoid.onContextualActionsAboutToShow: { plasmoid.clearActions() @@ -88,15 +88,24 @@ }) if (root.state == "playing") { - plasmoid.setAction("playPause", i18nc("Pause playback", "Pause"), "media-playback-pause") - plasmoid.action("playPause").enabled = Qt.binding(function() { - return root.canPause; - }); + if (canPause) { + plasmoid.setAction("playPause", i18nc("Pause playback", "Pause"), "media-playback-pause") + plasmoid.action("playPause").enabled = Qt.binding(function() { + return root.canPause; + }); + } } else { - plasmoid.setAction("playPause", i18nc("Start playback", "Play"), "media-playback-start") - plasmoid.action("playPause").enabled = Qt.binding(function() { - return root.canPlay; - }); + if (canPause) { + plasmoid.setAction("playPause", i18nc("Start playback", "Play"), "media-playback-start") + plasmoid.action("playPause").enabled = Qt.binding(function() { + return root.canPlay; + }); + } else { + plasmoid.setAction("play", i18nc("Start playback", "Play"), "media-playback-start") + plasmoid.action("play").enabled = Qt.binding(function() { + return root.canPlay; + }); + } } plasmoid.setAction("next", i18nc("Play next track", "Next Track"), @@ -106,6 +115,9 @@ }) plasmoid.setAction("stop", i18nc("Stop playback", "Stop"), "media-playback-stop") + plasmoid.action("stop").enabled = Qt.binding(function() { + return root.state === "playing" || root.state === "paused"; + }) } if (mpris2Source.currentData.CanQuit) { @@ -117,7 +129,7 @@ // HACK Some players like Amarok take quite a while to load the next track // this avoids having the plasmoid jump between popup and panel onStateChanged: { - if (state != "") { + if (state != "" && state != "stopped") { plasmoid.status = PlasmaCore.Types.ActiveStatus } else { updatePlasmoidStatusTimer.restart() @@ -128,7 +140,7 @@ id: updatePlasmoidStatusTimer interval: 3000 onTriggered: { - if (state != "") { + if (state != "" && state != "stopped") { plasmoid.status = PlasmaCore.Types.ActiveStatus } else { plasmoid.status = PlasmaCore.Types.PassiveStatus @@ -139,7 +151,9 @@ Plasmoid.fullRepresentation: ExpandedRepresentation {} Plasmoid.compactRepresentation: PlasmaCore.IconItem { - source: root.state === "playing" ? "media-playback-start" : "media-playback-pause" + source: root.state === "playing" ? "media-playback-start" : + root.state === "paused" ? "media-playback-pause" : + "media-playback-stop" active: compactMouse.containsMouse MouseArea { @@ -188,6 +202,18 @@ mpris2Source.serviceForSource("@multiplex").enableGlobalShortcuts(); } + function togglePlaying() { + if (root.canPause) { + root.action_playPause(); + } else { + if (root.state !== "playing") { + root.action_play(); + } else { + root.action_stop(); + } + } + } + function action_open() { serviceOp(mpris2Source.current, "Raise"); } @@ -247,6 +273,17 @@ toolTipMainText: track toolTipSubText: artist ? i18nc("Artist of the song", "by %1 (paused)", artist) : i18n("Paused") } + }, + State { + name: "stopped" + when: !root.noPlayer && mpris2Source.currentData.PlaybackStatus === "Stopped" + + PropertyChanges { + target: plasmoid + icon: albumArt ? albumArt : "media-playback-stop" + toolTipMainText: track + toolTipSubText: artist ? i18nc("Artist of the song", "by %1 (stopped)", artist) : i18n("Stopped") + } } ] }