Changeset View
Changeset View
Standalone View
Standalone View
lookandfeel/contents/lockscreen/MediaControls.qml
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | This file is part of the KDE project. | ||||
3 | | ||||
4 | Copyright (C) 2016 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
5 | | ||||
6 | This program is free software; you can redistribute it and/or modify | ||||
7 | it under the terms of the GNU General Public License as published by | ||||
8 | the Free Software Foundation; either version 2 of the License, or | ||||
9 | (at your option) any later version. | ||||
10 | | ||||
11 | This program is distributed in the hope that it will be useful, | ||||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
14 | GNU General Public License for more details. | ||||
15 | | ||||
16 | You should have received a copy of the GNU General Public License | ||||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
18 | *********************************************************************/ | ||||
19 | | ||||
20 | import QtQuick 2.5 | ||||
21 | import QtQuick.Layouts 1.1 | ||||
22 | | ||||
23 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
24 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||||
25 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||||
26 | | ||||
27 | Item { | ||||
28 | visible: mpris2Source.hasPlayer | ||||
29 | implicitHeight: controlsRow.height + controlsRow.y | ||||
30 | | ||||
31 | RowLayout { | ||||
32 | id: controlsRow | ||||
33 | anchors.bottom: parent.bottom | ||||
34 | y: units.smallSpacing // some distance to the password field | ||||
35 | width: parent.width | ||||
36 | height: units.gridUnit * 3 | ||||
37 | spacing: 0 | ||||
38 | | ||||
39 | enabled: mpris2Source.canControl | ||||
40 | | ||||
41 | PlasmaCore.DataSource { | ||||
42 | id: mpris2Source | ||||
43 | | ||||
44 | readonly property string source: "@multiplex" | ||||
45 | readonly property var playerData: data[source] | ||||
46 | | ||||
47 | readonly property bool hasPlayer: sources.length > 1 && !!playerData | ||||
48 | readonly property string identity: hasPlayer ? playerData.Identity : "" | ||||
49 | readonly property bool playing: hasPlayer && playerData.PlaybackStatus === "Playing" | ||||
50 | readonly property bool canControl: hasPlayer && playerData.CanControl | ||||
51 | readonly property bool canGoBack: hasPlayer && playerData.CanGoPrevious | ||||
52 | readonly property bool canGoNext: hasPlayer && playerData.CanGoNext | ||||
53 | | ||||
54 | readonly property var currentMetadata: hasPlayer ? playerData.Metadata : ({}) | ||||
55 | | ||||
56 | readonly property string track: { | ||||
57 | var xesamTitle = currentMetadata["xesam:title"] | ||||
58 | if (xesamTitle) { | ||||
59 | return xesamTitle | ||||
60 | } | ||||
61 | // if no track title is given, print out the file name | ||||
62 | var xesamUrl = currentMetadata["xesam:url"] ? currentMetadata["xesam:url"].toString() : "" | ||||
63 | if (!xesamUrl) { | ||||
64 | return "" | ||||
65 | } | ||||
66 | var lastSlashPos = xesamUrl.lastIndexOf('/') | ||||
67 | if (lastSlashPos < 0) { | ||||
68 | return "" | ||||
69 | } | ||||
70 | var lastUrlPart = xesamUrl.substring(lastSlashPos + 1) | ||||
71 | return decodeURIComponent(lastUrlPart) | ||||
72 | } | ||||
73 | readonly property string artist: currentMetadata["xesam:artist"] || "" | ||||
74 | readonly property string albumArt: currentMetadata["mpris:artUrl"] || "" | ||||
75 | | ||||
76 | engine: "mpris2" | ||||
77 | connectedSources: [source] | ||||
78 | | ||||
79 | function startOperation(op) { | ||||
80 | var service = serviceForSource(source) | ||||
81 | var operation = service.operationDescription(op) | ||||
82 | return service.startOperationCall(operation) | ||||
83 | } | ||||
84 | | ||||
85 | function goPrevious() { | ||||
86 | startOperation("Previous"); | ||||
87 | } | ||||
88 | function goNext() { | ||||
89 | startOperation("Next"); | ||||
90 | } | ||||
91 | function playPause(source) { | ||||
92 | startOperation("PlayPause"); | ||||
93 | } | ||||
94 | } | ||||
95 | | ||||
96 | Image { | ||||
97 | id: albumArt | ||||
98 | Layout.preferredWidth: height | ||||
99 | Layout.fillHeight: true | ||||
100 | asynchronous: true | ||||
101 | source: mpris2Source.albumArt | ||||
102 | sourceSize: Qt.size(width, height) | ||||
103 | visible: status === Image.Loading || status === Image.Ready | ||||
104 | } | ||||
105 | | ||||
106 | Item { // spacer | ||||
107 | width: units.smallSpacing | ||||
108 | height: 1 | ||||
109 | } | ||||
110 | | ||||
111 | ColumnLayout { | ||||
112 | Layout.fillWidth: true | ||||
113 | spacing: 0 | ||||
114 | | ||||
115 | PlasmaExtras.Heading { | ||||
116 | Layout.fillWidth: true | ||||
117 | level: 4 | ||||
118 | wrapMode: Text.NoWrap | ||||
119 | elide: Text.ElideRight | ||||
120 | text: mpris2Source.track || i18n("No media playing") | ||||
121 | } | ||||
122 | | ||||
123 | PlasmaExtras.Heading { | ||||
124 | Layout.fillWidth: true | ||||
125 | level: 5 | ||||
126 | wrapMode: Text.NoWrap | ||||
127 | elide: Text.ElideRight | ||||
128 | // if no artist is given, show player name instead | ||||
129 | text: mpris2Source.artist || mpris2Source.identity || "" | ||||
130 | } | ||||
131 | } | ||||
132 | | ||||
133 | PlasmaComponents.ToolButton { | ||||
134 | enabled: mpris2Source.canGoBack | ||||
135 | iconName: LayoutMirroring.enabled ? "media-skip-forward" : "media-skip-backward" | ||||
136 | onClicked: mpris2Source.goPrevious() | ||||
137 | } | ||||
138 | | ||||
139 | PlasmaComponents.ToolButton { | ||||
140 | Layout.fillHeight: true | ||||
141 | Layout.preferredWidth: height // make this button bigger | ||||
142 | iconName: mpris2Source.playing ? "media-playback-pause" : "media-playback-start" | ||||
143 | onClicked: mpris2Source.playPause() | ||||
144 | } | ||||
145 | | ||||
146 | PlasmaComponents.ToolButton { | ||||
147 | enabled: mpris2Source.canGoNext | ||||
148 | iconName: LayoutMirroring.enabled ? "media-skip-backward" : "media-skip-forward" | ||||
149 | onClicked: mpris2Source.goNext() | ||||
150 | } | ||||
151 | } | ||||
152 | } |