Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- * Copyright (C) 2019 by Dr_i-glu4IT <dr@i-glu4it.ru> *
- ***************************************************************************/
- import QtQuick 2.5
- import QtQuick.Layouts 1.1
- import QtQuick.Controls 1.4 as QtControls
- import QtMultimedia 5.8
- import org.kde.plasma.core 2.0 as PlasmaCore
- import org.kde.plasma.extras 2.0 as PlasmaExtras
- import org.kde.plasma.plasmoid 2.0
- import org.kde.plasma.components 2.0 as PlasmaComponents
- Item {
- id: root
- Layout.fillWidth: true
- Layout.fillHeight: true
- width: 200
- height: 300
- ServersModel {
- id: serversModel
- }
- Component.onCompleted: {
- reloadServerModel();
- }
- Connections {
- target: plasmoid.configuration
- onServersChanged: {
- reloadServerModel();
- }
- }
- MediaPlayer
- {
- id: playMusic
- onError: {
- playMusic.stop();
- reloadServerModel();
- }
- onStopped: {
- }
- onStatusChanged:
- {
- }
- volume: 0.8
- }
- Plasmoid.compactRepresentation: Item {
- id: comp
- width: parent.width
- height: parent.width
- PlasmaCore.IconItem {
- anchors.fill: parent
- source: "radio"
- width: parent.width
- height: parent.width
- }
- Timer {
- id: elapsedTimer
- interval: 3000;
- running: true;
- repeat: true;
- onTriggered: toolTip.mainText = i18n("Advanced Radio Player"), toolTip.subText = (isPlaying()) ? playMusic.metaData.title : i18n("Choose station")
- }
- MouseArea {
- id: mouseArea
- width: parent.width
- height: parent.width
- anchors.fill: parent
- hoverEnabled: true
- onClicked: {
- plasmoid.expanded = !plasmoid.expanded
- }
- onWheel: {
- elapsedTimer.stop()
- if (wheel.angleDelta.y > 0 && playMusic.volume < 1) {
- playMusic.volume += 0.05
- } else if (wheel.angleDelta.y < 0 && playMusic.volume > 0){
- playMusic.volume -= 0.05
- }
- toolTip.mainText = Math.round(playMusic.volume * 100) + '%'
- toolTip.subText = i18n('Volume')
- elapsedTimer.restart()
- }
- }
- PlasmaCore.ToolTipArea {
- id: toolTip
- width: parent.width
- height: parent.width
- anchors.fill: parent
- mainText: i18n("Advanced Radio Player")
- subText: (playMusic.metaData.title === undefined) ? i18n("Unknown") : playMusic.metaData.title
- icon: "radio"
- }
- }
- Plasmoid.fullRepresentation: Item {
- Layout.preferredWidth: 200
- Layout.preferredHeight: 300
- clip:true
- Rectangle {
- id: square
- color: "transparent"
- width: 200
- height: 20
- PlasmaComponents.Label {
- id: nameText2
- height: parent.height
- text: isPlaying() ? playMusic.metaData.title : "Advanced Radio Player"
- verticalAlignment: Text.AlignVCenter
- onTextChanged: {
- anim.restart()
- }
- }
- NumberAnimation {
- property: "x"
- id: anim
- target: nameText2
- from: (isPlaying()) ? square.width : square.width + 100
- to: (isPlaying()) ? -nameText2.width : -nameText2.width / 2 + square.width / 2;
- duration: 20 * Math.abs(to - from);
- loops: (isPlaying()) ? Animation.Infinite : 1
- }
- MouseArea {
- id: mouseArea2
- width: parent.width
- height: parent.width
- anchors.fill: parent
- hoverEnabled: true
- onEntered: {
- (isPlaying()) ? anim.pause() : anim.resume()
- }
- onExited: {
- anim.resume()
- }
- }
- }
- ListView {
- id: serversListView
- anchors.fill: parent
- anchors.topMargin:25
- anchors.bottomMargin:25
- model: serversModel
- clip:true
- delegate: Item {
- height: nameText.paintedHeight * 1.3
- width: parent.width
- PlasmaComponents.Label {
- id: icon
- height: parent.height
- text: model.status == 1 ? "▶" : model.index + 1
- width: 15
- verticalAlignment: Text.AlignVCenter
- horizontalAlignment: Text.AlignHCenter
- }
- PlasmaComponents.Label {
- id: nameText
- anchors.left: icon.right
- anchors.leftMargin: 5
- height: parent.height
- text: model.name.length == 0 ? model.hostname : model.name
- verticalAlignment: Text.AlignVCenter
- elide: Text.ElideRight
- }
- MouseArea {
- id: mouseArea
- anchors.top: icon.top
- anchors.bottom: icon.bottom
- anchors.left: icon.left
- width: serversListView.width
- hoverEnabled: true
- onEntered: {
- icon.text = model.status == 1 ? '■' : '▶'
- }
- onExited: {
- icon.text = model.status == 1 ? '▶' : model.index + 1
- }
- onClicked: {
- refreshServer(model.index)
- }
- }
- }
- }
- Rectangle {
- id: square2
- color: "transparent"
- width: 200
- height: 30
- anchors.top: serversListView.bottom
- PlasmaComponents.Label {
- id: nameText3
- font.pixelSize : 10
- height: parent.height
- width: parent.width
- text: isPlaying() ? 'Bitrate: ' + Math.round(playMusic.metaData.audioBitRate / 1000) + 'Kb/s Genre: ' + playMusic.metaData.genre : "Choose station and enjoy..."
- verticalAlignment: Text.AlignVCenter
- horizontalAlignment: Text.AlignHCenter
- elide: Text.ElideRight
- }
- }
- PlasmaComponents.Button {
- anchors.centerIn: parent
- text: i18n("Add stations")
- visible: serversModel.count == 0
- onClicked: plasmoid.action("configure").trigger();
- }
- }
- function reloadServerModel() {
- serversModel.clear();
- playMusic.stop()
- var servers = JSON.parse(plasmoid.configuration.servers);
- for(var i = 0; i < servers.length; i++) {
- if(servers[i].active) {
- serversModel.append(servers[i]);
- }
- }
- }
- function refreshServer(index) {
- serversModel.setProperty(index, "status", 0);
- if( isPlaying() && playMusic.source == serversModel.get(index).hostname) {
- playMusic.stop()
- serversModel.setProperty(index, "status", 0)
- }
- else
- {
- //reloadServerModel()
- playMusic.source = serversModel.get(index).hostname
- serversModel.setProperty(index, "status", 1);
- playMusic.play()
- }
- }
- function isPlaying()
- {
- return playMusic.playbackState == MediaPlayer.PlayingState
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement