Warning, /plasma/plasma-workspace/applets/mediacontroller/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org> 0003 SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de> 0004 SPDX-FileCopyrightText: 2020 Ismael Asensio <isma.af@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 import QtQuick 0010 import QtQuick.Layouts 0011 import org.kde.plasma.plasmoid 2.0 0012 import org.kde.plasma.core as PlasmaCore 0013 import org.kde.plasma.private.mediacontroller 1.0 0014 import org.kde.plasma.private.mpris as Mpris 0015 import org.kde.kirigami 2 as Kirigami 0016 0017 PlasmoidItem { 0018 id: root 0019 0020 switchWidth: Kirigami.Units.gridUnit * 14 0021 switchHeight: Kirigami.Units.gridUnit * 10 0022 0023 readonly property int volumePercentStep: config.volumeStep 0024 0025 // BEGIN model properties 0026 readonly property string track: mpris2Model.currentPlayer?.track ?? "" 0027 readonly property string artist: mpris2Model.currentPlayer?.artist ?? "" 0028 readonly property string album: mpris2Model.currentPlayer?.album ?? "" 0029 readonly property string albumArt: mpris2Model.currentPlayer?.artUrl ?? "" 0030 readonly property string identity: mpris2Model.currentPlayer?.identity ?? "" 0031 readonly property bool canControl: mpris2Model.currentPlayer?.canControl ?? false 0032 readonly property bool canGoPrevious: mpris2Model.currentPlayer?.canGoPrevious ?? false 0033 readonly property bool canGoNext: mpris2Model.currentPlayer?.canGoNext ?? false 0034 readonly property bool canPlay: mpris2Model.currentPlayer?.canPlay ?? false 0035 readonly property bool canPause: mpris2Model.currentPlayer?.canPause ?? false 0036 readonly property bool canStop: mpris2Model.currentPlayer?.canStop ?? false 0037 readonly property int playbackStatus: mpris2Model.currentPlayer?.playbackStatus ?? 0 0038 readonly property bool isPlaying: root.playbackStatus === Mpris.PlaybackStatus.Playing 0039 readonly property bool canRaise: mpris2Model.currentPlayer?.canRaise ?? false 0040 readonly property bool canQuit: mpris2Model.currentPlayer?.canQuit ?? false 0041 readonly property int shuffle: mpris2Model.currentPlayer?.shuffle ?? 0 0042 readonly property int loopStatus: mpris2Model.currentPlayer?.loopStatus ?? 0 0043 // END model properties 0044 0045 Plasmoid.icon: switch (root.playbackStatus) { 0046 case Mpris.PlaybackStatus.Playing: 0047 return "media-playback-playing-symbolic"; 0048 case Mpris.PlaybackStatus.Paused: 0049 return "media-playback-paused-symbolic"; 0050 default: 0051 return "media-playback-stopped-symbolic"; 0052 } 0053 Plasmoid.status: PlasmaCore.Types.PassiveStatus 0054 toolTipMainText: root.playbackStatus > Mpris.PlaybackStatus.Stopped ? root.track : i18n("No media playing") 0055 toolTipSubText: switch (root.playbackStatus) { 0056 case Mpris.PlaybackStatus.Playing: 0057 return root.artist ? i18nc("@info:tooltip %1 is a musical artist and %2 is an app name", "by %1 (%2)\nMiddle-click to pause\nScroll to adjust volume", root.artist, root.identity) 0058 : i18nc("@info:tooltip %1 is an app name", "%1\nMiddle-click to pause\nScroll to adjust volume", root.identity) 0059 case Mpris.PlaybackStatus.Paused: 0060 return root.artist ? i18nc("@info:tooltip %1 is a musical artist and %2 is an app name", "by %1 (paused, %2)\nMiddle-click to play\nScroll to adjust volume", root.artist, root.identity) 0061 : i18nc("@info:tooltip %1 is an app name", "Paused (%1)\nMiddle-click to play\nScroll to adjust volume", root.identity) 0062 default: 0063 return ""; 0064 } 0065 toolTipTextFormat: Text.PlainText 0066 0067 compactRepresentation: CompactRepresentation {} 0068 fullRepresentation: ExpandedRepresentation {} 0069 0070 // HACK Some players like Amarok take quite a while to load the next track 0071 // this avoids having the plasmoid jump between popup and panel 0072 onPlaybackStatusChanged: { 0073 if (root.playbackStatus > Mpris.PlaybackStatus.Stopped) { 0074 Plasmoid.status = PlasmaCore.Types.ActiveStatus 0075 } else { 0076 updatePlasmoidStatusTimer.restart() 0077 } 0078 } 0079 0080 onExpandedChanged: { 0081 if (root.expanded) { 0082 mpris2Model.currentPlayer?.updatePosition(); 0083 } 0084 } 0085 0086 Timer { 0087 id: updatePlasmoidStatusTimer 0088 interval: Kirigami.Units.humanMoment 0089 onTriggered: { 0090 if (root.playbackStatus > Mpris.PlaybackStatus.Stopped) { 0091 Plasmoid.status = PlasmaCore.Types.ActiveStatus 0092 } else { 0093 Plasmoid.status = PlasmaCore.Types.PassiveStatus 0094 } 0095 } 0096 } 0097 0098 GlobalConfig { 0099 id: config 0100 } 0101 0102 Plasmoid.contextualActions: [ 0103 PlasmaCore.Action { 0104 text: i18nc("Open player window or bring it to the front if already open", "Open") 0105 icon.name: "go-up-symbolic" 0106 priority: PlasmaCore.Action.LowPriority 0107 visible: root.canRaise 0108 onTriggered: raise() 0109 }, 0110 PlasmaCore.Action { 0111 text: i18nc("Play previous track", "Previous Track") 0112 icon.name: Qt.application.layoutDirection === Qt.RightToLeft ? "media-skip-forward" : "media-skip-backward" 0113 priority: PlasmaCore.Action.LowPriority 0114 visible: root.canControl 0115 enabled: root.canGoPrevious 0116 onTriggered: previous() 0117 }, 0118 PlasmaCore.Action { 0119 text: i18nc("Pause playback", "Pause") 0120 icon.name: "media-playback-pause" 0121 priority: PlasmaCore.Action.LowPriority 0122 visible: root.isPlaying && root.canPause 0123 enabled: visible 0124 onTriggered: pause() 0125 }, 0126 PlasmaCore.Action { 0127 text: i18nc("Start playback", "Play") 0128 icon.name: "media-playback-start" 0129 priority: PlasmaCore.Action.LowPriority 0130 visible: root.canControl && !root.isPlaying 0131 enabled: root.canPlay 0132 onTriggered: play() 0133 }, 0134 PlasmaCore.Action { 0135 text: i18nc("Play next track", "Next Track") 0136 icon.name: Qt.application.layoutDirection === Qt.RightToLeft ? "media-skip-backward" : "media-skip-forward" 0137 priority: PlasmaCore.Action.LowPriority 0138 visible: root.canControl 0139 enabled: root.canGoNext 0140 onTriggered: next() 0141 }, 0142 PlasmaCore.Action { 0143 text: i18nc("Stop playback", "Stop") 0144 icon.name: "media-playback-stop" 0145 priority: PlasmaCore.Action.LowPriority 0146 visible: root.canControl 0147 enabled: root.canStop 0148 onTriggered: stop() 0149 }, 0150 PlasmaCore.Action { 0151 isSeparator: true 0152 priority: PlasmaCore.Action.LowPriority 0153 visible: root.canQuit 0154 }, 0155 PlasmaCore.Action { 0156 text: i18nc("Quit player", "Quit") 0157 icon.name: "application-exit" 0158 priority: PlasmaCore.Action.LowPriority 0159 visible: root.canQuit 0160 onTriggered: quit() 0161 } 0162 ] 0163 0164 function previous() { 0165 mpris2Model.currentPlayer.Previous(); 0166 } 0167 function next() { 0168 mpris2Model.currentPlayer.Next(); 0169 } 0170 function play() { 0171 mpris2Model.currentPlayer.Play(); 0172 } 0173 function pause() { 0174 mpris2Model.currentPlayer.Pause(); 0175 } 0176 function togglePlaying() { 0177 mpris2Model.currentPlayer.PlayPause(); 0178 } 0179 function stop() { 0180 mpris2Model.currentPlayer.Stop(); 0181 } 0182 function quit() { 0183 mpris2Model.currentPlayer.Quit(); 0184 } 0185 function raise() { 0186 mpris2Model.currentPlayer.Raise(); 0187 } 0188 0189 Mpris.Mpris2Model { 0190 id: mpris2Model 0191 } 0192 0193 Component.onCompleted: { 0194 Plasmoid.removeInternalAction("configure"); 0195 } 0196 }