1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/*
* Copyright (C) 2018-2020,2022 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.
*/
#include <QDebug>
#include "RadioClient.h"
#include "RadioGrpcClient.h"
RadioClient::RadioClient(QQmlContext *context, QObject * parent) :
QObject(parent),
m_band(1),
m_frequency(0),
m_minFrequency(0),
m_maxFrequency(0),
m_playing(false),
m_scanning(false)
{
m_radio = new RadioGrpcClient(this);
if (m_radio) {
m_radio->GetBandParameters(m_band, m_minFrequency, m_maxFrequency, m_frequencyStep);
emit minFrequencyChanged(m_minFrequency);
emit maxFrequencyChanged(m_maxFrequency);
emit frequencyStepChanged(m_frequencyStep);
// Handle start up
if (!m_frequency) {
m_frequency = m_minFrequency;
emit frequencyChanged(m_frequency);
}
}
}
RadioClient::~RadioClient()
{
delete m_radio;
}
void RadioClient::setBand(int band)
{
if (m_radio)
m_radio->SetBand(band);
}
void RadioClient::setFrequency(int frequency)
{
if (!m_radio)
return;
m_radio->SetFrequency(frequency);
// To improve UI responsiveness, signal the change here immediately
// This fixes visual glitchiness in the slider caused by the frequency
// update event taking long enough that the QML engine gets a chance
// to update the slider with the current value before the event with
// the new value comes.
m_frequency = frequency;
emit frequencyChanged(m_frequency);
}
// control related methods
void RadioClient::start()
{
if (m_radio)
m_radio->Start();
}
void RadioClient::stop()
{
if (m_radio)
m_radio->Stop();
}
void RadioClient::scanForward()
{
if (!m_radio || m_scanning)
return;
m_radio->ScanForward();
m_scanning = true;
emit scanningChanged(m_scanning);
}
void RadioClient::scanBackward()
{
if (!m_radio || m_scanning)
return;
m_radio->ScanBackward();
m_scanning = true;
emit scanningChanged(m_scanning);
}
void RadioClient::scanStop()
{
if (m_radio)
m_radio->ScanStop();
m_scanning = false;
emit scanningChanged(m_scanning);
}
void RadioClient::updateBand(int band)
{
m_band = band;
emit bandChanged(m_band);
}
void RadioClient::updateFrequency(int frequency)
{
m_frequency = frequency;
emit frequencyChanged(m_frequency);
}
void RadioClient::updatePlaying(bool status)
{
m_playing = status;
emit playingChanged(m_playing);
}
void RadioClient::updateScanning(int station_found)
{
if (station_found && m_scanning) {
m_scanning = false;
emit scanningChanged(m_scanning);
}
}
|