summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/Radio.qml105
-rw-r--r--app/api/Binding.qml196
-rw-r--r--app/app.pro2
-rw-r--r--app/main.cpp5
-rw-r--r--app/radio.qrc1
-rw-r--r--package/config.xml1
6 files changed, 72 insertions, 238 deletions
diff --git a/app/Radio.qml b/app/Radio.qml
index 894b9a3..448958d 100644
--- a/app/Radio.qml
+++ b/app/Radio.qml
@@ -19,7 +19,6 @@ import QtQuick 2.6
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0
import AGL.Demo.Controls 1.0
-import 'api' as API
ApplicationWindow {
id: root
@@ -27,16 +26,13 @@ ApplicationWindow {
width: container.width * container.scale
height: container.height * container.scale
- API.Binding {
- id: radio
+ property string title
- property string title
-
- onBandChanged: frequency = minimumFrequency
- onStationFound: title = stationId
- onFrequencyChanged: {
- title = ''
- slider.value = frequency
+ function freq2str(freq) {
+ if (freq > 5000000) {
+ return '%1 MHz'.arg((freq / 1000000).toFixed(1))
+ } else {
+ return '%1 kHz'.arg((freq / 1000).toFixed(0))
}
}
@@ -88,7 +84,7 @@ ApplicationWindow {
// onImage: './images/FM_Icons_AM.svg'
// onCheckedChanged: {
// radio.band = checked ? radio.amBand : radio.fmBand
-// radio.frequency = radio.minimumFrequency
+// radio.frequency = radio.minFrequency
// }
// }
}
@@ -97,14 +93,14 @@ ApplicationWindow {
Label {
id: label
Layout.alignment: Layout.Center
- text: radio.freq2str(radio.frequency)
+ text: freq2str(radio.frequency)
horizontalAlignment: Label.AlignHCenter
verticalAlignment: Label.AlignVCenter
}
Label {
id: artist
Layout.alignment: Layout.Center
- text: radio.title
+ text: root.title
horizontalAlignment: Label.AlignHCenter
verticalAlignment: Label.AlignVCenter
font.pixelSize: label.font.pixelSize * 0.6
@@ -114,22 +110,26 @@ ApplicationWindow {
Slider {
id: slider
Layout.fillWidth: true
- from: radio.minimumFrequency
- to: radio.maximumFrequency
+ from: radio.minFrequency
+ to: radio.maxFrequency
stepSize: radio.frequencyStep
snapMode: Slider.SnapOnRelease
- onValueChanged: radio.frequency = value
+ value: radio.frequency
+ onPressedChanged: {
+ radio.frequency = value
+ root.title = ''
+ }
Label {
anchors.left: parent.left
anchors.bottom: parent.top
font.pixelSize: 32
- text: radio.freq2str(radio.minimumFrequency)
+ text: freq2str(radio.minFrequency)
}
Label {
anchors.right: parent.right
anchors.bottom: parent.top
font.pixelSize: 32
- text: radio.freq2str(radio.maximumFrequency)
+ text: freq2str(radio.maxFrequency)
}
}
RowLayout {
@@ -146,7 +146,12 @@ ApplicationWindow {
triggeredOnStart: true
interval: 100
repeat: true
- onTriggered: radio.tuneDown()
+ onTriggered: {
+ if(radio.frequency > radio.minFrequency) {
+ radio.frequency -= radio.frequencyStep
+ root.title = ''
+ }
+ }
}
}
@@ -157,7 +162,12 @@ ApplicationWindow {
triggeredOnStart: true
interval: 100
repeat: true
- onTriggered: radio.tuneUp()
+ onTriggered: {
+ if(radio.frequency < radio.maxFrequency) {
+ radio.frequency += radio.frequencyStep
+ root.title = ''
+ }
+ }
}
}
@@ -166,10 +176,13 @@ ApplicationWindow {
ImageButton {
id: play
offImage: './images/AGL_MediaPlayer_Player_Play.svg'
- onClicked: radio.start()
+ onClicked: {
+ mediaplayer.pause()
+ radio.start()
+ }
states: [
State {
- when: radio.state === radio.activeState
+ when: radio.playing
PropertyChanges {
target: play
offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
@@ -182,32 +195,44 @@ ApplicationWindow {
Item { Layout.fillWidth: true }
Label {
- //Layout.fillWidth: true
+ id: scanLabel
text: 'SCAN'
+ color: radio.scanning ? '#59FF7F' : '#FFFFFF'
}
ImageButton {
+ id: scanBackwardBtn
offImage: './images/AGL_MediaPlayer_BackArrow.svg'
- Timer {
- running: parent.pressed
- triggeredOnStart: true
- interval: 100
- repeat: true
- onTriggered: radio.scanDown()
- }
+ states: [
+ State {
+ when: radio.playing
+ PropertyChanges {
+ target: scanBackwardBtn
+ onClicked: {
+ radio.scanBackward()
+ root.title = ''
+ }
+ }
+ }
+ ]
}
ImageButton {
+ id: scanForwardBtn
offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
- Timer {
- running: parent.pressed
- triggeredOnStart: true
- interval: 100
- repeat: true
- onTriggered: radio.scanUp()
- }
+ states: [
+ State {
+ when: radio.playing
+ PropertyChanges {
+ target: scanForwardBtn
+ onClicked: {
+ radio.scanForward()
+ root.title = ''
+ }
+ }
+ }
+ ]
}
-
}
}
}
@@ -231,7 +256,7 @@ ApplicationWindow {
onClicked: {
radio.band = model.modelData.band
radio.frequency = model.modelData.frequency
- radio.title = model.modelData.title
+ root.title = model.modelData.title
}
RowLayout {
@@ -247,7 +272,7 @@ ApplicationWindow {
}
Label {
Layout.fillWidth: true
- text: radio.freq2str(model.frequency)
+ text: freq2str(model.frequency)
color: '#59FF7F'
font.pixelSize: 32
}
diff --git a/app/api/Binding.qml b/app/api/Binding.qml
deleted file mode 100644
index 3b43510..0000000
--- a/app/api/Binding.qml
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (C) 2016 The Qt Company Ltd.
- * Copyright (C) 2017 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import QtQuick 2.6
-import QtWebSockets 1.0
-
-WebSocket {
- id: root
- active: true
- url: bindingAddress
-
- property string apiString: "radio"
- property var verbs: []
- property string payloadLength: "9999"
-
- readonly property var msgid: {
- "call": 2,
- "retok": 3,
- "reterr": 4,
- "event": 5
- }
-
- readonly property int amBand: 0
- readonly property int fmBand: 1
-
- readonly property int stoppedState: 0
- readonly property int activeState: 1
-
- property int band: fmBand
- property int frequency
- property int frequencyStep
- property int minimumFrequency
- property int maximumFrequency
- property int state: stoppedState
- property int scanningState: stoppedState
- property bool scanningFreqUpdate: false
- property string stationId: ""
-
- signal stationFound
-
- property Connections c : Connections {
- target: root
-
- onFrequencyChanged: {
- if(scanningState != activeState) {
- // Not scanning, push update
- sendSocketMessage("frequency", { value: frequency })
- } else if(!scanningFreqUpdate) {
- // External change, stop scanning
- sendSocketMessage("scan_stop", 'None')
- scanningState = stoppedState
- sendSocketMessage("frequency", { value: frequency })
- } else {
- // This update was from scanning, clear state
- scanningFreqUpdate = false
- }
- }
-
- onBandChanged: {
- sendSocketMessage("band", { value: band })
- updateFrequencyRange(band)
- updateFrequencyStep(band)
- frequency = minimumFrequency
- }
- }
-
- onTextMessageReceived: {
- var json = JSON.parse(message)
- //console.debug("Raw response: " + message)
- var request = json[2].request
- var response = json[2].response
-
- switch (json[0]) {
- case msgid.call:
- break
- case msgid.retok:
- var verb = verbs.shift()
- if (verb == "frequency_range") {
- minimumFrequency = response.min
- maximumFrequency = response.max
- } else if (verb == "frequency_step") {
- frequencyStep = response.step
- }
- break
- case msgid.event:
- var event = JSON.parse(JSON.stringify(json[2]))
- if (event.event === "radio/frequency") {
- if(scanningState == activeState) {
- scanningFreqUpdate = true
- frequency = event.data.value
- }
- } else if (event.event === "radio/station_found") {
- if(scanningState == activeState) {
- scanningState = stoppedState
- stationId = freq2str(event.data.value)
- root.stationFound()
- }
- }
- break
- case msg.reterr:
- console.debug("Bad return value, binding probably not installed")
- break
- case MessageId.event:
- break
- }
- }
-
- onStatusChanged: {
- switch (status) {
- case WebSocket.Open:
- // Initialize band values now that we're connected to the
- // binding
- updateFrequencyRange(band)
- updateFrequencyStep(band)
- frequency = minimumFrequency
- sendSocketMessage("subscribe", { value: "frequency" })
- sendSocketMessage("subscribe", { value: "station_found" })
- break
- case WebSocket.Error:
- console.debug("WebSocket error: " + root.errorString)
- break
- }
- }
-
- function freq2str(freq) {
- if (freq > 5000000) {
- return '%1 MHz'.arg((freq / 1000000).toFixed(1))
- } else {
- return '%1 kHz'.arg((freq / 1000).toFixed(0))
- }
- }
-
- function sendSocketMessage(verb, parameter) {
- var requestJson = [ msgid.call, payloadLength, apiString + '/'
- + verb, parameter ]
- //console.debug("sendSocketMessage: " + JSON.stringify(requestJson))
- verbs.push(verb)
- sendTextMessage(JSON.stringify(requestJson))
- }
-
- function start() {
- sendSocketMessage("start", 'None')
- state = activeState
- }
-
- function stop() {
- sendSocketMessage("stop", 'None')
- state = stoppedState
- }
-
- function tuneUp() {
- frequency += frequencyStep
- if(frequency > maximumFrequency) {
- frequency = minimumFrequency
- }
- }
-
- function tuneDown() {
- frequency -= frequencyStep
- if(frequency < minimumFrequency) {
- frequency = maximumFrequency
- }
- }
-
- function scanUp() {
- scanningState = activeState
- sendSocketMessage("scan_start", { direction: "forward" })
- }
-
- function scanDown() {
- scanningState = activeState
- sendSocketMessage("scan_start", { direction: "backward" })
- }
-
- function updateFrequencyRange(band) {
- sendSocketMessage("frequency_range", { band: band })
- }
-
- function updateFrequencyStep(band) {
- sendSocketMessage("frequency_step", { band: band })
- }
-}
diff --git a/app/app.pro b/app/app.pro
index d1e8274..c6e5c5a 100644
--- a/app/app.pro
+++ b/app/app.pro
@@ -5,7 +5,7 @@ HEADERS = PresetDataObject.h
SOURCES = main.cpp PresetDataObject.cpp
CONFIG += link_pkgconfig
-PKGCONFIG += libhomescreen qlibwindowmanager
+PKGCONFIG += libhomescreen qlibwindowmanager qtappfw
RESOURCES += \
radio.qrc \
diff --git a/app/main.cpp b/app/main.cpp
index 0fb066c..9471a63 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -27,6 +27,8 @@
#include <libhomescreen.hpp>
#include <qlibwindowmanager.h>
#include <stdlib.h>
+#include <mediaplayer.h>
+#include <radio.h>
#include "PresetDataObject.h"
int main(int argc, char *argv[])
@@ -126,6 +128,9 @@ int main(int argc, char *argv[])
}
});
+ context->setContextProperty("mediaplayer", new Mediaplayer(bindingAddress, context));
+ context->setContextProperty("radio", new Radio(bindingAddress, context));
+
engine.load(QUrl(QStringLiteral("qrc:/Radio.qml")));
QObject *root = engine.rootObjects().first();
QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
diff --git a/app/radio.qrc b/app/radio.qrc
index 38ce4f8..347894c 100644
--- a/app/radio.qrc
+++ b/app/radio.qrc
@@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/">
<file>Radio.qml</file>
- <file>api/Binding.qml</file>
</qresource>
</RCC>
diff --git a/package/config.xml b/package/config.xml
index bc50257..77cbaa1 100644
--- a/package/config.xml
+++ b/package/config.xml
@@ -10,6 +10,7 @@
<param name="windowmanager" value="ws" />
<param name="homescreen" value="ws" />
<param name="radio" value="ws" />
+ <param name="mediaplayer" value="ws" />
</feature>
<feature name="urn:AGL:widget:required-permission">
<param name="urn:AGL:permission::public:no-htdocs" value="required" />