diff --git a/plasmoid/contents/ui/CoverArt.qml b/plasmoid/contents/ui/CoverArt.qml index 2d6d0d6..a833da8 100644 --- a/plasmoid/contents/ui/CoverArt.qml +++ b/plasmoid/contents/ui/CoverArt.qml @@ -18,7 +18,9 @@ */ import QtQuick 2.4 import QtQuick.Layouts 1.2 +import QtQuick.Controls 1.4 import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents import QtGraphicalEffects 1.0 Item { @@ -98,6 +100,7 @@ Item { to: 1.0 duration: units.longDuration * 1.5 } + } MouseArea { @@ -105,5 +108,109 @@ Item { anchors.fill: parent acceptedButtons: Qt.LeftButton onClicked: action_raise() + hoverEnabled: true + } + + PlasmaComponents.ToolButton { + id: mediaSelector + anchors { + left: cover.left + top: cover.top + leftMargin: units.smallSpacing + topMargin: units.smallSpacing + } + + opacity: (toggleWindow.containsMouse || hovered) ? 1 : 0 + visible: repeater.count >= 2 + + Behavior on opacity { + NumberAnimation { duration: units.largeDuration } + } + + iconName: mpris2.icon(mpris2.currentSource) + onClicked: menu.open() + + PlasmaComponents.ContextMenu { + id: menu + visualParent: mediaSelector + + function caption(source) { + var text = 'None' + + if (source === "@multiplex") { + text = i18n("Select automatically") + } else if (source && mpris2.currentSource === source) { + text = mpris2.capitalize(source) + } else { + var e = mpris2.recentSources.find(function (e) { + return e.source === source + }); + + if (!e) + text = source[0].toUpperCase() + source.substr(1) + else + text = e.identity + } + + return text + } + + function changeSource(source) { + if (mpris2.currentSource !== source) { + if (mpris2.sourceActive) + mpris2.disconnectSource(mpris2.currentSource) + + mpris2.connectSource(source) + } + } + + + PlasmaComponents.MenuItem { + id: menuItemAuto + readonly property string source: '@multiplex' + text: menu.caption(source) + onClicked: { + sourceChanged() + menu.changeSource(source) + } + checkable: true + Binding { + target: menuItemAuto + property: 'checked' + value: mpris2.currentSource === menuItemAuto.source + } + } + + //!BEGIN: Media players menu items + readonly property Item _items: Item { + Repeater { + id: repeater + readonly property var sources: mpris2.sources.filter(function(e){ return e !== '@multiplex' }) + + model: sources.length + onItemAdded: menu.addMenuItem(item) + onItemRemoved: menu.removeMenuItem(item) + + delegate: PlasmaComponents.MenuItem { + id: menuItem + readonly property string source: repeater.sources[index] + text: menu.caption(source) + onClicked: { + sourceChanged() + menu.changeSource(source) + } + checkable: true + + Binding { + target: menuItem + property: 'checked' + value: mpris2.currentSource === menuItem.source + } + } + } + } + //!END: Media players menu items + } + } } diff --git a/plasmoid/contents/ui/Mpris2.qml b/plasmoid/contents/ui/Mpris2.qml index aec44f0..ff9d66b 100644 --- a/plasmoid/contents/ui/Mpris2.qml +++ b/plasmoid/contents/ui/Mpris2.qml @@ -39,7 +39,7 @@ PlasmaCore.DataSource { readonly property var metadata: currentSource ? data[currentSource].Metadata : undefined - readonly property string identity: currentSource ? capitalize(source) : '' + readonly property string identity: currentSource ? capitalize(currentSource) : '' readonly property string playbackStatus: currentSource && sourceActive ? data[currentSource].PlaybackStatus : 'Stopped' @@ -150,10 +150,11 @@ PlasmaCore.DataSource { onSourcesChanged: { if (connectedSources.length === 0) nextSource() + + console.log("sources availables:", sources) } onSourceAdded: { - // debug( 'Source added', source ) // debug( 'sources', sources ) if (source !== '@multiplex' && connectedSources.length === 0) { @@ -247,29 +248,40 @@ PlasmaCore.DataSource { } function capitalize(source) { - var i = data[source]['Identity'] - return i[0].toUpperCase() + i.substr(1) + if (source !== '') { + var i = (data[source] || { Identity: source }).Identity + return i[0].toUpperCase() + i.substr(1) + } + + return source } function icon(source) { - var icon = source + var iconName = source - if (icon.match('vlc')) - icon = 'vlc' + if (iconName.match('vlc')) + iconName = 'vlc' - switch (icon) { + switch (iconName) { case 'spotify': - icon = 'spotify-client' + iconName = 'spotify-client' break case 'clementine': - icon = 'application-x-clementine' + iconName = 'application-x-clementine' break case 'yarock': - icon = 'application-x-yarock' + iconName = 'application-x-yarock' + break + case '@multiplex': + if (sourceActive && currentSource == '@multiplex') + iconName = icon(data[source]['Source Name']) + else + iconName = 'emblem-music-symbolic' + break } - return icon + return iconName } function addRecentSource(source) {