Changeset View
Changeset View
Standalone View
Standalone View
applets/mediacontroller/contents/ui/main.qml
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright 2013 Sebastian Kügler <sebas@kde.org> * | 2 | * Copyright 2013 Sebastian Kügler <sebas@kde.org> * | ||
3 | * Copyright 2014 Kai Uwe Broulik <kde@privat.broulik.de> * | 3 | * Copyright 2014 Kai Uwe Broulik <kde@privat.broulik.de> * | ||
4 | * Copyright 2020 Ismael Asensio <isma.af@gmail.com> * | ||||
4 | * * | 5 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * | ||
6 | * it under the terms of the GNU Library General Public License as * | 7 | * it under the terms of the GNU Library General Public License as * | ||
7 | * published by the Free Software Foundation; either version 2 of the * | 8 | * published by the Free Software Foundation; either version 2 of the * | ||
8 | * License, or (at your option) any later version. * | 9 | * License, or (at your option) any later version. * | ||
9 | * * | 10 | * * | ||
10 | * This program is distributed in the hope that it will be useful, * | 11 | * This program is distributed in the hope that it will be useful, * | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 53 | property string artist: { | |||
65 | } | 66 | } | ||
66 | } | 67 | } | ||
67 | property string albumArt: currentMetadata ? currentMetadata["mpris:artUrl"] || "" : "" | 68 | property string albumArt: currentMetadata ? currentMetadata["mpris:artUrl"] || "" : "" | ||
68 | 69 | | |||
69 | readonly property string identity: !root.noPlayer ? mpris2Source.currentData.Identity || mpris2Source.current : "" | 70 | readonly property string identity: !root.noPlayer ? mpris2Source.currentData.Identity || mpris2Source.current : "" | ||
70 | 71 | | |||
71 | property bool noPlayer: mpris2Source.sources.length <= 1 | 72 | property bool noPlayer: mpris2Source.sources.length <= 1 | ||
72 | 73 | | |||
74 | property var mprisSourcesModel: [] | ||||
75 | | ||||
73 | readonly property bool canControl: (!root.noPlayer && mpris2Source.currentData.CanControl) || false | 76 | readonly property bool canControl: (!root.noPlayer && mpris2Source.currentData.CanControl) || false | ||
74 | readonly property bool canGoPrevious: (canControl && mpris2Source.currentData.CanGoPrevious) || false | 77 | readonly property bool canGoPrevious: (canControl && mpris2Source.currentData.CanGoPrevious) || false | ||
75 | readonly property bool canGoNext: (canControl && mpris2Source.currentData.CanGoNext) || false | 78 | readonly property bool canGoNext: (canControl && mpris2Source.currentData.CanGoNext) || false | ||
76 | readonly property bool canPlay: (canControl && mpris2Source.currentData.CanPlay) || false | 79 | readonly property bool canPlay: (canControl && mpris2Source.currentData.CanPlay) || false | ||
77 | readonly property bool canPause: (canControl && mpris2Source.currentData.CanPause) || false | 80 | readonly property bool canPause: (canControl && mpris2Source.currentData.CanPause) || false | ||
78 | 81 | | |||
79 | Plasmoid.switchWidth: units.gridUnit * 14 | 82 | Plasmoid.switchWidth: units.gridUnit * 14 | ||
80 | Plasmoid.switchHeight: units.gridUnit * 10 | 83 | Plasmoid.switchHeight: units.gridUnit * 10 | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 202 | PlasmaCore.DataSource { | |||
200 | id: mpris2Source | 203 | id: mpris2Source | ||
201 | 204 | | |||
202 | readonly property string multiplexSource: "@multiplex" | 205 | readonly property string multiplexSource: "@multiplex" | ||
203 | property string current: multiplexSource | 206 | property string current: multiplexSource | ||
204 | 207 | | |||
205 | readonly property var currentData: data[current] | 208 | readonly property var currentData: data[current] | ||
206 | 209 | | |||
207 | engine: "mpris2" | 210 | engine: "mpris2" | ||
208 | connectedSources: current | 211 | connectedSources: sources | ||
212 | | ||||
213 | onSourceAdded: { | ||||
214 | updateMprisSourcesModel() | ||||
215 | } | ||||
209 | 216 | | |||
210 | onSourceRemoved: { | 217 | onSourceRemoved: { | ||
211 | // if player is closed, reset to multiplex source | 218 | // if player is closed, reset to multiplex source | ||
212 | if (source === current) { | 219 | if (source === current) { | ||
213 | current = multiplexSource | 220 | current = multiplexSource | ||
214 | } | 221 | } | ||
222 | updateMprisSourcesModel() | ||||
215 | } | 223 | } | ||
216 | } | 224 | } | ||
217 | 225 | | |||
218 | Component.onCompleted: { | 226 | Component.onCompleted: { | ||
219 | mpris2Source.serviceForSource("@multiplex").enableGlobalShortcuts(); | 227 | mpris2Source.serviceForSource("@multiplex").enableGlobalShortcuts() | ||
228 | updateMprisSourcesModel() | ||||
220 | } | 229 | } | ||
221 | 230 | | |||
222 | function togglePlaying() { | 231 | function togglePlaying() { | ||
223 | if (root.state === "playing") { | 232 | if (root.state === "playing") { | ||
224 | if (root.canPause) { | 233 | if (root.canPause) { | ||
225 | root.action_pause(); | 234 | root.action_pause(); | ||
226 | } | 235 | } | ||
227 | } else { | 236 | } else { | ||
Show All 35 Lines | |||||
263 | } | 272 | } | ||
264 | 273 | | |||
265 | function serviceOp(src, op) { | 274 | function serviceOp(src, op) { | ||
266 | var service = mpris2Source.serviceForSource(src); | 275 | var service = mpris2Source.serviceForSource(src); | ||
267 | var operation = service.operationDescription(op); | 276 | var operation = service.operationDescription(op); | ||
268 | return service.startOperationCall(operation); | 277 | return service.startOperationCall(operation); | ||
269 | } | 278 | } | ||
270 | 279 | | |||
280 | function updateMprisSourcesModel () { | ||||
281 | | ||||
282 | var model = [{ | ||||
283 | 'text': i18n("Choose player automatically"), | ||||
284 | 'icon': 'emblem-favorite', | ||||
285 | 'source': mpris2Source.multiplexSource | ||||
286 | }] | ||||
287 | | ||||
288 | var sources = mpris2Source.sources | ||||
289 | for (var i = 0, length = sources.length; i < length; ++i) { | ||||
290 | var source = sources[i] | ||||
291 | if (source === mpris2Source.multiplexSource) { | ||||
292 | continue | ||||
293 | } | ||||
294 | | ||||
295 | model.push({ | ||||
296 | 'text': mpris2Source.data[source]["Identity"], | ||||
297 | 'icon': mpris2Source.data[source]["Desktop Icon Name"] || mpris2Source.data[source]["Desktop Entry"] || source, | ||||
298 | 'source': source | ||||
299 | }); | ||||
300 | } | ||||
301 | | ||||
302 | root.mprisSourcesModel = model; | ||||
303 | } | ||||
304 | | ||||
271 | states: [ | 305 | states: [ | ||
272 | State { | 306 | State { | ||
273 | name: "playing" | 307 | name: "playing" | ||
274 | when: !root.noPlayer && mpris2Source.currentData.PlaybackStatus === "Playing" | 308 | when: !root.noPlayer && mpris2Source.currentData.PlaybackStatus === "Playing" | ||
275 | 309 | | |||
276 | PropertyChanges { | 310 | PropertyChanges { | ||
277 | target: plasmoid | 311 | target: plasmoid | ||
278 | icon: albumArt ? albumArt : "media-playback-playing" | 312 | icon: albumArt ? albumArt : "media-playback-playing" | ||
Show All 17 Lines |