fixed denon plug-in

This commit is contained in:
Boernsman 2016-04-21 11:01:42 +02:00 committed by Michael Zanetti
parent 9d2ab92d42
commit 7f3a373e3c
4 changed files with 6 additions and 295 deletions

View File

@ -1,194 +0,0 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015 Simon Stuerz <simon.stuerz@guh.guru> *
* Copyright (C) 2016 Bernhard Trinnes <bernhard.trinnes@guh.guru> *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
d
#include "denon.h"
Kodi::Kodi(const QHostAddress &hostAddress, const int &port, QObject *parent) :
QObject(parent),
m_muted(false),
m_volume(-1)
{
m_connection = new KodiConnection(hostAddress, port, this);
connect (m_connection, &KodiConnection::connectionStatusChanged, this, &Kodi::connectionStatusChanged);
m_jsonHandler = new KodiJsonHandler(m_connection, this);
connect(m_jsonHandler, &KodiJsonHandler::volumeChanged, this, &Kodi::onVolumeChanged);
connect(m_jsonHandler, &KodiJsonHandler::actionExecuted, this, &Kodi::actionExecuted);
connect(m_jsonHandler, &KodiJsonHandler::versionDataReceived, this, &Kodi::versionDataReceived);
connect(m_jsonHandler, &KodiJsonHandler::updateDataReceived, this, &Kodi::updateDataReceived);
connect(m_jsonHandler, &KodiJsonHandler::updateDataReceived, this, &Kodi::onUpdateFinished);
connect(m_jsonHandler, &KodiJsonHandler::onPlayerPlay, this, &Kodi::onPlayerPlay);
connect(m_jsonHandler, &KodiJsonHandler::onPlayerPause, this, &Kodi::onPlayerPause);
connect(m_jsonHandler, &KodiJsonHandler::onPlayerStop, this, &Kodi::onPlayerStop);
}
QHostAddress Kodi::hostAddress() const
{
return m_connection->hostAddress();
}
int Kodi::port() const
{
return m_connection->port();
}
bool Kodi::connected() const
{
return m_connection->connected();
}
void Kodi::setMuted(const bool &muted, const ActionId &actionId)
{
QVariantMap params;
params.insert("mute", muted);
m_jsonHandler->sendData("Application.SetMute", params, actionId);
}
bool Kodi::muted() const
{
return m_muted;
}
void Kodi::setVolume(const int &volume, const ActionId &actionId)
{
QVariantMap params;
params.insert("volume", volume);
m_jsonHandler->sendData("Application.SetVolume", params, actionId);
}
int Kodi::volume() const
{
return m_volume;
}
void Kodi::showNotification(const QString &message, const int &displayTime, const QString &notificationType, const ActionId &actionId)
{
QVariantMap params;
params.insert("title", "guh notification");
params.insert("message", message);
params.insert("displaytime", displayTime);
params.insert("image", notificationType);
m_jsonHandler->sendData("GUI.ShowNotification", params, actionId);
}
void Kodi::pressButton(const QString &button, const ActionId &actionId)
{
QVariantMap params;
params.insert("action", button);
m_jsonHandler->sendData("Input.ExecuteAction", params, actionId);
}
void Kodi::systemCommand(const QString &command, const ActionId &actionId)
{
QString method;
if (command == "hibernate") {
method = "Hibernate";
} else if (command == "reboot") {
method = "Reboot";
} else if (command == "shutdown") {
method = "Shutdown";
} else if (command == "suspend") {
method = "Suspend";
} else {
// already checkt with allowed values
}
m_jsonHandler->sendData("System." + method, QVariantMap(), actionId);
}
void Kodi::videoLibrary(const QString &command, const ActionId &actionId)
{
QString method;
if (command == "scan") {
method = "Scan";
} else if (command == "clean") {
method = "Clean";
} else {
// already checkt with allowed values
}
m_jsonHandler->sendData("VideoLibrary." + method, QVariantMap(), actionId);
}
void Kodi::audioLibrary(const QString &command, const ActionId &actionId)
{
QString method;
if (command == "scan") {
method = "Scan";
} else if (command == "clean") {
method = "Clean";
} else {
// already checkt with allowed values
}
m_jsonHandler->sendData("AudioLibrary." + method, QVariantMap(), actionId);
}
void Kodi::update()
{
QVariantMap params;
QVariantList properties;
properties.append("volume");
properties.append("muted");
properties.append("name");
properties.append("version");
params.insert("properties", properties);
m_jsonHandler->sendData("Application.GetProperties", params, ActionId());
}
void Kodi::checkVersion()
{
m_jsonHandler->sendData("JSONRPC.Version", QVariantMap(), ActionId());
}
void Kodi::connectKodi()
{
m_connection->connectKodi();
}
void Kodi::disconnectKodi()
{
m_connection->disconnectKodi();
}
void Kodi::onVolumeChanged(const int &volume, const bool &muted)
{
if (m_volume != volume || m_muted != muted) {
m_volume = volume;
m_muted = muted;
emit stateChanged();
}
}
void Kodi::onUpdateFinished(const QVariantMap &data)
{
if (data.contains("volume")) {
m_volume = data.value("volume").toInt();
}
if (data.contains("muted")) {
m_muted = data.value("muted").toBool();
}
emit stateChanged();
}

View File

@ -1,86 +0,0 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015 Simon Stuerz <simon.stuerz@guh.guru> *
* Copyright (C) 2015 Bernhard Trinnes <bernhard.trinnes@guh.guru> *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DENON_H
#define DENON_H
#include <QObject>
#include <QHostAddress>
#include "denonconnection.h"
class Denon : public QObject
{
Q_OBJECT
public:
explicit Denon(const QHostAddress &hostAddress, const int &port = 9090, QObject *parent = 0);
QHostAddress hostAddress() const;
int port() const;
bool connected() const;
// propertys
void setMuted(const bool &muted, const ActionId &actionId);
bool muted() const;
void setVolume(const int &volume, const ActionId &actionId);
int volume() const;
// actions
void showNotification(const QString &message, const int &displayTime, const QString &notificationType, const ActionId &actionId);
void pressButton(const QString &button, const ActionId &actionId);
void systemCommand(const QString &command, const ActionId &actionId);
void videoLibrary(const QString &command, const ActionId &actionId);
void audioLibrary(const QString &command, const ActionId &actionId);
void update();
void checkVersion();
void connectKodi();
void disconnectKodi();
private:
DenonConnection *m_connection;
bool m_muted;
int m_volume;
signals:
void connectionStatusChanged();
void stateChanged();
void actionExecuted(const ActionId &actionId, const bool &success);
void updateDataReceived(const QVariantMap &data);
void versionDataReceived(const QVariantMap &data);
void onPlayerPlay();
void onPlayerPause();
void onPlayerStop();
private slots:
void onVolumeChanged(const int &volume, const bool &muted);
void onUpdateFinished(const QVariantMap &data);
};
#endif // DENON_H

View File

@ -96,21 +96,7 @@ void DenonConnection::onError(QAbstractSocket::SocketError socketError)
void DenonConnection::readData()
{
QByteArray data = m_socket->readAll();
QStringList commandList = QString(data).split("}{");
for(int i = 0; i < commandList.count(); ++i) {
QString command = commandList.at(i);
if(command.isEmpty()) {
continue;
}
if(i < commandList.count() - 1) {
command.append("}");
}
if(i > 0) {
command.prepend("{");
}
emit dataReady(command.toUtf8());
}
emit dataReady(QString(data).toUtf8());
}
void DenonConnection::setConnected(const bool &connected)

View File

@ -89,6 +89,8 @@ void DevicePluginDenon::deviceRemoved(Device *device)
qCWarning(dcDenon) << "Invalid connection pointer" << device->id().toString();
return;
}
m_device.clear();
m_denonConnection->disconnectDenon();
m_denonConnection->deleteLater();
}
@ -161,6 +163,9 @@ DeviceManager::DeviceError DevicePluginDenon::executeAction(Device *device, cons
void DevicePluginDenon::onConnectionChanged()
{
if (!m_device)
return;
// if the device is connected
if (m_denonConnection->connected()) {
// and from the first setup