fixed shuffle and repeat state
parent
5d9b6c55e1
commit
e95ff04808
|
|
@ -220,6 +220,19 @@ QUuid BluOS::setShuffle(bool shuffle)
|
|||
}
|
||||
emit connectionChanged(true);
|
||||
emit actionExecuted(requestId, true);
|
||||
|
||||
QXmlStreamReader xml;
|
||||
xml.addData(reply->readAll());
|
||||
if (xml.hasError()) {
|
||||
qCDebug(dcBluOS()) << "XML Error:" << xml.errorString();
|
||||
return;
|
||||
}
|
||||
if (xml.readNextStartElement()) {
|
||||
if (xml.attributes().hasAttribute("shuffle")) {
|
||||
bool shuffle = RepeatMode(xml.attributes().value("shuffle").toInt());
|
||||
emit shuffleStateReceived(shuffle);
|
||||
}
|
||||
}
|
||||
});
|
||||
return requestId;
|
||||
}
|
||||
|
|
@ -254,6 +267,21 @@ QUuid BluOS::setRepeat(RepeatMode repeatMode)
|
|||
}
|
||||
emit connectionChanged(true);
|
||||
emit actionExecuted(requestId, true);
|
||||
|
||||
QXmlStreamReader xml;
|
||||
xml.addData(reply->readAll());
|
||||
if (xml.hasError()) {
|
||||
qCDebug(dcBluOS()) << "XML Error:" << xml.errorString();
|
||||
return;
|
||||
}
|
||||
if (xml.readNextStartElement()) {
|
||||
if (xml.name() == "playlist") {
|
||||
if (xml.attributes().hasAttribute("repeat")) {
|
||||
RepeatMode mode = RepeatMode(xml.attributes().value("repeat").toInt());
|
||||
emit repeatModeReceived(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return requestId;
|
||||
}
|
||||
|
|
@ -652,6 +680,8 @@ bool BluOS::parseState(const QByteArray &state)
|
|||
statusResponse.Image = xml.readElementText();
|
||||
} else if(xml.name() == "title1") {
|
||||
statusResponse.Title = xml.readElementText();
|
||||
} else if(xml.name() == "group") {
|
||||
statusResponse.Group = xml.readElementText();
|
||||
} else {
|
||||
xml.skipCurrentElement();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ public:
|
|||
RepeatMode Repeat;
|
||||
bool Shuffle;
|
||||
QUrl Image;
|
||||
QString Group;
|
||||
};
|
||||
|
||||
struct Preset {
|
||||
|
|
@ -142,6 +143,8 @@ signals:
|
|||
|
||||
void statusReceived(const StatusResponse &status);
|
||||
void volumeReceived(int volume, bool mute);
|
||||
void shuffleStateReceived(bool state);
|
||||
void repeatModeReceived(RepeatMode mode);
|
||||
|
||||
void presetsReceived(QUuid requestId, const QList<Preset> &presets);
|
||||
void sourcesReceived(QUuid requestId, const QList<Source> &sources);
|
||||
|
|
|
|||
|
|
@ -47,11 +47,6 @@ IntegrationPluginBluOS::IntegrationPluginBluOS()
|
|||
|
||||
}
|
||||
|
||||
IntegrationPluginBluOS::~IntegrationPluginBluOS()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IntegrationPluginBluOS::init()
|
||||
{
|
||||
m_serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser("_musc._tcp");
|
||||
|
|
@ -99,13 +94,14 @@ void IntegrationPluginBluOS::setupThing(ThingSetupInfo *info)
|
|||
connect(bluos, &BluOS::volumeReceived, this, &IntegrationPluginBluOS::onVolumeReceived);
|
||||
connect(bluos, &BluOS::presetsReceived, this, &IntegrationPluginBluOS::onPresetsReceived);
|
||||
connect(bluos, &BluOS::sourcesReceived, this, &IntegrationPluginBluOS::onSourcesReceived);
|
||||
connect(bluos, &BluOS::shuffleStateReceived, this, &IntegrationPluginBluOS::onShuffleStateReceived);
|
||||
connect(bluos, &BluOS::repeatModeReceived, this, &IntegrationPluginBluOS::onRepeatModeReceived);
|
||||
|
||||
m_asyncSetup.insert(bluos, info);
|
||||
bluos->getStatus();
|
||||
// In case the setup is cancelled before we finish it...
|
||||
connect(info, &QObject::destroyed, this, [this, bluos]() {
|
||||
m_asyncSetup.remove(bluos);
|
||||
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
|
|
@ -242,10 +238,10 @@ void IntegrationPluginBluOS::browseThing(BrowseResult *result)
|
|||
presetItem.setMediaIcon(MediaBrowserItem::MediaBrowserIconMusicLibrary);
|
||||
result->addItem(presetItem);
|
||||
|
||||
MediaBrowserItem groupingItem("grouping", "Grouping", true, false);
|
||||
groupingItem.setIcon(BrowserItem::BrowserIcon::BrowserIconApplication);
|
||||
groupingItem.setMediaIcon(MediaBrowserItem::MediaBrowserIconNetwork);
|
||||
result->addItem(groupingItem);
|
||||
// MediaBrowserItem groupingItem("grouping", "Grouping", true, false);
|
||||
// groupingItem.setIcon(BrowserItem::BrowserIcon::BrowserIconApplication);
|
||||
// groupingItem.setMediaIcon(MediaBrowserItem::MediaBrowserIconNetwork);
|
||||
// result->addItem(groupingItem);
|
||||
|
||||
QUuid requestId = bluos->getSources();
|
||||
m_asyncBrowseResults.insert(requestId, result);
|
||||
|
|
@ -364,6 +360,7 @@ void IntegrationPluginBluOS::onStatusResponseReceived(const BluOS::StatusRespons
|
|||
thing->setStateValue(bluosPlayerRepeatStateTypeId, "None");
|
||||
break;
|
||||
}
|
||||
thing->setStateValue(bluosPlayerGroupStateTypeId, status.Group);
|
||||
}
|
||||
|
||||
void IntegrationPluginBluOS::onActionExecuted(QUuid requestId, bool success)
|
||||
|
|
@ -397,6 +394,35 @@ void IntegrationPluginBluOS::onVolumeReceived(int volume, bool mute)
|
|||
thing->setStateValue(bluosPlayerVolumeStateTypeId, volume);
|
||||
}
|
||||
|
||||
void IntegrationPluginBluOS::onShuffleStateReceived(bool state)
|
||||
{
|
||||
BluOS *bluos = static_cast<BluOS*>(sender());
|
||||
Thing *thing = myThings().findById(m_bluos.key(bluos));
|
||||
if (!thing)
|
||||
return;
|
||||
thing->setStateValue(bluosPlayerShuffleStateTypeId, state);
|
||||
}
|
||||
|
||||
void IntegrationPluginBluOS::onRepeatModeReceived(BluOS::RepeatMode mode)
|
||||
{
|
||||
BluOS *bluos = static_cast<BluOS*>(sender());
|
||||
Thing *thing = myThings().findById(m_bluos.key(bluos));
|
||||
if (!thing)
|
||||
return;
|
||||
switch (mode) {
|
||||
case BluOS::RepeatMode::All:
|
||||
thing->setStateValue(bluosPlayerRepeatStateTypeId, "All");
|
||||
break;
|
||||
case BluOS::RepeatMode::One:
|
||||
thing->setStateValue(bluosPlayerRepeatStateTypeId, "One");
|
||||
break;
|
||||
case BluOS::RepeatMode::None:
|
||||
thing->setStateValue(bluosPlayerRepeatStateTypeId, "None");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void IntegrationPluginBluOS::onPresetsReceived(QUuid requestId, const QList<BluOS::Preset> &presets)
|
||||
{
|
||||
BluOS *bluos = static_cast<BluOS*>(sender());
|
||||
|
|
@ -444,6 +470,7 @@ void IntegrationPluginBluOS::onSourcesReceived(QUuid requestId, const QList<BluO
|
|||
if (source.Text == "Bluetooth") {
|
||||
item.setMediaIcon(MediaBrowserItem::MediaBrowserIconBluetooth);
|
||||
} else if (source.Text == "Spotify") {
|
||||
item.setExecutable(false);
|
||||
item.setMediaIcon(MediaBrowserItem::MediaBrowserIconSpotify);
|
||||
item.setDescription("Open the Spotify App for browsing");
|
||||
} else if (source.Text == "TuneIn") {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ class IntegrationPluginBluOS: public IntegrationPlugin
|
|||
|
||||
public:
|
||||
explicit IntegrationPluginBluOS();
|
||||
~IntegrationPluginBluOS();
|
||||
|
||||
void init() override;
|
||||
void discoverThings(ThingDiscoveryInfo *info) override;
|
||||
|
|
@ -83,6 +82,8 @@ private slots:
|
|||
void onStatusResponseReceived(const BluOS::StatusResponse &status);
|
||||
void onActionExecuted(QUuid actionId, bool success);
|
||||
void onVolumeReceived(int volume, bool mute);
|
||||
void onShuffleStateReceived(bool state);
|
||||
void onRepeatModeReceived(BluOS::RepeatMode mode);
|
||||
|
||||
void onPresetsReceived(QUuid requestId, const QList<BluOS::Preset> &presets);
|
||||
void onSourcesReceived(QUuid requestId, const QList<BluOS::Source> &sources);
|
||||
|
|
|
|||
|
|
@ -142,6 +142,14 @@
|
|||
"displayNameEvent": "Artwork changed",
|
||||
"type": "QString",
|
||||
"defaultValue": ""
|
||||
},
|
||||
{
|
||||
"id": "69757ef3-173f-499c-9304-4252de3588c6",
|
||||
"name": "group",
|
||||
"displayName": "Group",
|
||||
"displayNameEvent": "Group changed",
|
||||
"type": "QString",
|
||||
"defaultValue": ""
|
||||
}
|
||||
],
|
||||
"actionTypes": [
|
||||
|
|
|
|||
Loading…
Reference in New Issue