Fix notification handling
parent
ae883cd0a4
commit
c2ca4038da
|
|
@ -72,8 +72,6 @@ void DevicePluginKodi::setupDevice(DeviceSetupInfo *info)
|
|||
connect(kodi, &Kodi::connectionStatusChanged, this, &DevicePluginKodi::onConnectionChanged);
|
||||
connect(kodi, &Kodi::stateChanged, this, &DevicePluginKodi::onStateChanged);
|
||||
connect(kodi, &Kodi::actionExecuted, this, &DevicePluginKodi::onActionExecuted);
|
||||
connect(kodi, &Kodi::versionDataReceived, this, &DevicePluginKodi::versionDataReceived);
|
||||
connect(kodi, &Kodi::updateDataReceived, this, &DevicePluginKodi::onSetupFinished);
|
||||
connect(kodi, &Kodi::playbackStatusChanged, this, &DevicePluginKodi::onPlaybackStatusChanged);
|
||||
connect(kodi, &Kodi::browserItemExecuted, this, &DevicePluginKodi::onBrowserItemExecuted);
|
||||
connect(kodi, &Kodi::browserItemActionExecuted, this, &DevicePluginKodi::onBrowserItemActionExecuted);
|
||||
|
|
@ -343,18 +341,24 @@ void DevicePluginKodi::onPluginTimer()
|
|||
}
|
||||
}
|
||||
|
||||
void DevicePluginKodi::onConnectionChanged()
|
||||
void DevicePluginKodi::onConnectionChanged(bool connected)
|
||||
{
|
||||
Kodi *kodi = static_cast<Kodi *>(sender());
|
||||
Device *device = m_kodis.value(kodi);
|
||||
|
||||
if (kodi->connected()) {
|
||||
// if this is the first setup, check version
|
||||
if (m_asyncSetups.contains(kodi)) {
|
||||
kodi->checkVersion();
|
||||
// Finish setup
|
||||
DeviceSetupInfo *info = m_asyncSetups.value(kodi);
|
||||
if (info) {
|
||||
if (connected) {
|
||||
info->finish(Device::DeviceErrorNoError);
|
||||
} else {
|
||||
//: Error setting up device
|
||||
m_asyncSetups.take(kodi)->finish(Device::DeviceErrorHardwareFailure, QT_TR_NOOP("This installation of Kodi is too old. Please upgrade your Kodi system."));
|
||||
}
|
||||
}
|
||||
|
||||
kodi->showNotification("nymea", tr("Connected"), 2000, "info");
|
||||
|
||||
device->setStateValue(kodiConnectedStateTypeId, kodi->connected());
|
||||
}
|
||||
|
||||
|
|
@ -392,40 +396,6 @@ void DevicePluginKodi::onBrowserItemActionExecuted(int actionId, bool success)
|
|||
m_pendingBrowserItemActions.take(actionId)->finish(success ? Device::DeviceErrorNoError : Device::DeviceErrorHardwareFailure);
|
||||
}
|
||||
|
||||
void DevicePluginKodi::versionDataReceived(const QVariantMap &data)
|
||||
{
|
||||
Kodi *kodi = static_cast<Kodi *>(sender());
|
||||
|
||||
QVariantMap version = data.value("version").toMap();
|
||||
QString apiVersion = QString("%1.%2.%3").arg(version.value("major").toString()).arg(version.value("minor").toString()).arg(version.value("patch").toString());
|
||||
qCDebug(dcKodi) << "API Version:" << apiVersion;
|
||||
|
||||
if (version.value("major").toInt() < 6) {
|
||||
qCWarning(dcKodi) << "incompatible api version:" << apiVersion;
|
||||
if (m_asyncSetups.contains(kodi)) {
|
||||
//: Error setting up device
|
||||
m_asyncSetups.take(kodi)->finish(Device::DeviceErrorHardwareFailure, QT_TR_NOOP("This installation of Kodi is too old. Please upgrade your Kodi system."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
kodi->update();
|
||||
}
|
||||
|
||||
void DevicePluginKodi::onSetupFinished(const QVariantMap &data)
|
||||
{
|
||||
Kodi *kodi = static_cast<Kodi *>(sender());
|
||||
|
||||
QVariantMap version = data.value("version").toMap();
|
||||
QString kodiVersion = QString("%1.%2 (%3)").arg(version.value("major").toString()).arg(version.value("minor").toString()).arg(version.value("tag").toString());
|
||||
qCDebug(dcKodi) << "Version:" << kodiVersion;
|
||||
|
||||
if (m_asyncSetups.contains(kodi)) {
|
||||
m_asyncSetups.take(kodi)->finish(Device::DeviceErrorNoError);
|
||||
}
|
||||
|
||||
kodi->showNotification("nymea", tr("Connected"), 2000, "info");
|
||||
}
|
||||
|
||||
void DevicePluginKodi::onPlaybackStatusChanged(const QString &playbackStatus)
|
||||
{
|
||||
Kodi *kodi = static_cast<Kodi *>(sender());
|
||||
|
|
|
|||
|
|
@ -63,13 +63,11 @@ private:
|
|||
|
||||
private slots:
|
||||
void onPluginTimer();
|
||||
void onConnectionChanged();
|
||||
void onConnectionChanged(bool connected);
|
||||
void onStateChanged();
|
||||
void onActionExecuted(int actionId, bool success);
|
||||
void onBrowserItemExecuted(int actionId, bool success);
|
||||
void onBrowserItemActionExecuted(int actionId, bool success);
|
||||
void versionDataReceived(const QVariantMap &data);
|
||||
void onSetupFinished(const QVariantMap &data);
|
||||
|
||||
void onPlaybackStatusChanged(const QString &playbackStatus);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ Kodi::Kodi(const QHostAddress &hostAddress, int port, int httpPort, QObject *par
|
|||
m_volume(-1)
|
||||
{
|
||||
m_connection = new KodiConnection(hostAddress, port, this);
|
||||
connect (m_connection, &KodiConnection::connectionStatusChanged, this, &Kodi::connectionStatusChanged);
|
||||
connect (m_connection, &KodiConnection::connectionStatusChanged, this, &Kodi::onConnectionStatusChanged);
|
||||
|
||||
m_jsonHandler = new KodiJsonHandler(m_connection, this);
|
||||
connect(m_jsonHandler, &KodiJsonHandler::notificationReceived, this, &Kodi::processNotification);
|
||||
|
|
@ -532,6 +532,15 @@ int Kodi::executeBrowserItemAction(const QString &itemId, const ActionTypeId &ac
|
|||
return m_jsonHandler->sendData(scope + "." + method, QVariantMap());
|
||||
}
|
||||
|
||||
void Kodi::onConnectionStatusChanged()
|
||||
{
|
||||
if (m_connection->connected()) {
|
||||
checkVersion();
|
||||
} else {
|
||||
emit connectionStatusChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Kodi::onVolumeChanged(const int &volume, const bool &muted)
|
||||
{
|
||||
if (m_volume != volume || m_muted != muted) {
|
||||
|
|
@ -636,14 +645,14 @@ void Kodi::processNotification(const QString &method, const QVariantMap ¶ms)
|
|||
if (method == "Application.OnVolumeChanged") {
|
||||
QVariantMap data = params.value("data").toMap();
|
||||
onVolumeChanged(data.value("volume").toInt(), data.value("muted").toBool());
|
||||
} else if (method == "Player.OnPlay" || method == "Player.OnResume" || method == "Player.OnAVStart") {
|
||||
onPlaybackStatusChanged("Playing");
|
||||
update();
|
||||
} else if (method == "Player.OnPause") {
|
||||
onPlaybackStatusChanged("Paused");
|
||||
update();
|
||||
} else if (method == "Player.OnStop") {
|
||||
onPlaybackStatusChanged("Stopped");
|
||||
return;
|
||||
}
|
||||
|
||||
if (method == "Player.OnPlay" ||
|
||||
method == "Player.OnResume" ||
|
||||
method == "Player.OnPause" ||
|
||||
method == "Player.OnStop" ||
|
||||
method == "Player.OnAVChange") {
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
|
@ -657,27 +666,43 @@ void Kodi::processResponse(int id, const QString &method, const QVariantMap &res
|
|||
qCWarning(dcKodi) << "got error response for request " << method << ":" << response.value("error").toMap().value("message").toString();
|
||||
}
|
||||
|
||||
if (method == "JSONRPC.Version") {
|
||||
qCDebug(dcKodi) << "got version response" << method;
|
||||
QVariantMap data = response.value("result").toMap();
|
||||
QVariantMap version = data.value("version").toMap();
|
||||
QString apiVersion = QString("%1.%2.%3").arg(version.value("major").toString()).arg(version.value("minor").toString()).arg(version.value("patch").toString());
|
||||
qCDebug(dcKodi) << "API Version:" << apiVersion;
|
||||
|
||||
if (version.value("major").toInt() < 6) {
|
||||
qCWarning(dcKodi) << "incompatible api version:" << apiVersion;
|
||||
m_connection->disconnectKodi();
|
||||
emit connectionStatusChanged(false);
|
||||
return;
|
||||
}
|
||||
emit connectionStatusChanged(true);
|
||||
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
if (method == "Application.GetProperties") {
|
||||
//qCDebug(dcKodi) << "got update response" << reply.method();
|
||||
emit updateDataReceived(response.value("result").toMap());
|
||||
return;
|
||||
}
|
||||
|
||||
if (method == "JSONRPC.Version") {
|
||||
qCDebug(dcKodi) << "got version response" << method;
|
||||
emit versionDataReceived(response.value("result").toMap());
|
||||
return;
|
||||
}
|
||||
|
||||
if (method == "Player.GetActivePlayers") {
|
||||
qCDebug(dcKodi) << "Active players changed" << response;
|
||||
activePlayersChanged(response.value("result").toList());
|
||||
updatePlayerProperties();
|
||||
return;
|
||||
}
|
||||
|
||||
if (method == "Player.GetProperties") {
|
||||
qCDebug(dcKodi) << "Player properties received" << response;
|
||||
playerPropertiesReceived(response.value("result").toMap());
|
||||
updateMetadata();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,20 +74,20 @@ public:
|
|||
int executeBrowserItemAction(const QString &itemId, const ActionTypeId &actionTypeId);
|
||||
|
||||
signals:
|
||||
void connectionStatusChanged();
|
||||
void connectionStatusChanged(bool connected);
|
||||
void stateChanged();
|
||||
void activePlayerChanged(const QString &playerType);
|
||||
void actionExecuted(int actionId, bool success);
|
||||
void browserItemExecuted(int actionId, bool success);
|
||||
void browserItemActionExecuted(int actionId, bool success);
|
||||
void updateDataReceived(const QVariantMap &data);
|
||||
void versionDataReceived(const QVariantMap &data);
|
||||
void playbackStatusChanged(const QString &playbackState);
|
||||
void mediaMetadataChanged(const QString &title, const QString &artist, const QString &collection, const QString &artwork);
|
||||
void shuffleChanged(bool shuffle);
|
||||
void repeatChanged(const QString &repeat);
|
||||
|
||||
private slots:
|
||||
void onConnectionStatusChanged();
|
||||
void onVolumeChanged(const int &volume, const bool &muted);
|
||||
void onUpdateFinished(const QVariantMap &data);
|
||||
void activePlayersChanged(const QVariantList &data);
|
||||
|
|
|
|||
Loading…
Reference in New Issue