From 56711827b790ea9b5472ea29cd8a00ec7ea6fbb9 Mon Sep 17 00:00:00 2001 From: Chupligin Sergey Date: Sun, 24 Sep 2017 17:20:41 +0300 Subject: [PATCH] [Statusbar] Add media controller panel --- rpm/lipstick-glacier-home-qt5.spec | 1 + src/qml/Statusbar.qml | 14 ++- src/qml/statusbar/CommonPanel.qml | 4 +- src/qml/statusbar/MediaController.qml | 136 ++++++++++++++++++++++++++ src/src.pro | 3 +- 5 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 src/qml/statusbar/MediaController.qml diff --git a/rpm/lipstick-glacier-home-qt5.spec b/rpm/lipstick-glacier-home-qt5.spec index 1c96dd96..e4134a93 100644 --- a/rpm/lipstick-glacier-home-qt5.spec +++ b/rpm/lipstick-glacier-home-qt5.spec @@ -21,6 +21,7 @@ Requires: connman-qt5 Requires: libqofono-qt5-declarative Requires: nemo-theme-glacier Requires: google-opensans-fonts +Requires: mpris-qt5-qml-plugin BuildRequires: pkgconfig(Qt5Core) BuildRequires: pkgconfig(Qt5Quick) diff --git a/src/qml/Statusbar.qml b/src/qml/Statusbar.qml index 7ebea728..d2d966d2 100644 --- a/src/qml/Statusbar.qml +++ b/src/qml/Statusbar.qml @@ -35,7 +35,9 @@ import QtQuick.Controls.Nemo 1.0 import QtQuick.Controls.Styles.Nemo 1.0 import org.freedesktop.contextkit 1.0 import MeeGo.Connman 0.2 + import org.nemomobile.lipstick 0.1 +import org.nemomobile.mpris 1.0 import "statusbar" @@ -289,9 +291,19 @@ Item { iconSize: Theme.itemHeightExtraSmall source: "image://theme/icon_gps_normal" } + StatusbarItem { + MprisManager { + id: mprisManager + } + property bool isPlaying: mprisManager.currentService && mprisManager.playbackStatus == Mpris.Playing + iconSize: Theme.itemHeightExtraSmall - source: "image://theme/icon_play_pause" + source: isPlaying ? + "image://theme/pause" + : "image://theme/play" + + panel: MediaController{} } StatusbarItem { iconSize: root.height diff --git a/src/qml/statusbar/CommonPanel.qml b/src/qml/statusbar/CommonPanel.qml index 86101b3d..bc31eaaa 100644 --- a/src/qml/statusbar/CommonPanel.qml +++ b/src/qml/statusbar/CommonPanel.qml @@ -40,6 +40,8 @@ Rectangle { id: commonPanel property alias switcherEnabled: columnCheckBox.enabled + property bool settingsIconEnabled: true + property alias switcherChecked: columnCheckBox.checked property string name: "" signal click @@ -120,7 +122,7 @@ Rectangle { id:settingsIcon fillMode: Image.PreserveAspectFit height: Theme.itemHeightMedium - visible: parent.height > Theme.itemSpacingMedium + visible: settingsIconEnabled && parent.height > Theme.itemSpacingMedium source: "image://theme/icon-app-settings" //maybe better icon? settings.png from statusbar spec anchors{ right: parent.right diff --git a/src/qml/statusbar/MediaController.qml b/src/qml/statusbar/MediaController.qml new file mode 100644 index 00000000..66ec8596 --- /dev/null +++ b/src/qml/statusbar/MediaController.qml @@ -0,0 +1,136 @@ +/**************************************************************************************** +** +** Copyright (C) 2017 Sergey Chupligin +** All rights reserved. +** +** You may use this file under the terms of BSD license as follows: +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the author nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR +** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +** +****************************************************************************************/ + + +import QtQuick 2.1 +import QtQuick.Controls 1.0 +import QtQuick.Controls.Nemo 1.0 +import QtQuick.Controls.Styles.Nemo 1.0 +import QtQuick.Layouts 1.0 + +import org.nemomobile.mpris 1.0 + +Component { + id: mediaPanelItem + CommonPanel { + id: mediaPanelcommon + switcherEnabled: false + settingsIconEnabled: false + + property bool isPlaying: mprisManager.currentService && mprisManager.playbackStatus == Mpris.Playing + + Item{ + width: parent.width + height: parent.height + + Label{ + id: trackName + width: parent.width + text: if (mprisManager.currentService) { + var artistTag = Mpris.metadataToString(Mpris.Artist) + var titleTag = Mpris.metadataToString(Mpris.Title) + + var artistLabel = (artistTag in mprisManager.metadata) ? mprisManager.metadata[artistTag].toString() : ""; + var titleLabel = (titleTag in mprisManager.metadata) ? mprisManager.metadata[titleTag].toString() : "" + + return artistLabel+"\n"+titleLabel + + }else{ + return qsTr("No music playing") + } + horizontalAlignment: Text.AlignHCenter + } + + + Image{ + id: backBtn + width: playPause.width*0.6 + height: width + visible: mprisManager.currentService + + anchors{ + right: playPause.left + rightMargin: width/2 + verticalCenter: playPause.verticalCenter + } + + MouseArea{ + anchors.fill: parent + onClicked: if (mprisManager.canGoPrevious) mprisManager.previous() + } + + source: "image://theme/backward" + } + + Image{ + id: playPause + width: Theme.itemHeightHuge + height: width + visible: mprisManager.currentService + + anchors{ + horizontalCenter: parent.horizontalCenter + top: trackName.bottom + topMargin: Theme.itemSpacingLarge + } + + source: isPlaying ? + "image://theme/pause" : + "image://theme/play" + + MouseArea{ + anchors.fill: parent + onClicked: (isPlaying)? mprisManager.pause() : mprisManager.play() + } + } + + Image{ + id: forwBtn + width: playPause.width*0.6 + height: width + visible: mprisManager.currentService + + anchors{ + left: playPause.right + leftMargin: width/2 + verticalCenter: playPause.verticalCenter + } + + source: "image://theme/forward" + + MouseArea{ + anchors.fill: parent + onClicked: if (mprisManager.canGoNext) mprisManager.next() + } + } + } + } +} diff --git a/src/src.pro b/src/src.pro index 962a8cc8..d0f45cc0 100644 --- a/src/src.pro +++ b/src/src.pro @@ -80,7 +80,8 @@ statusbar.files = qml/statusbar/BatteryPanel.qml\ qml/statusbar/SimPanel.qml\ qml/statusbar/WifiPanel.qml\ qml/statusbar/StatusbarItem.qml\ - qml/statusbar/NumButton.qml + qml/statusbar/NumButton.qml \ + qml/statusbar/MediaController.qml INSTALLS += styles \ images \