diff --git a/plugins/deviceplugins/denon/denon.cpp b/plugins/deviceplugins/denon/denon.cpp deleted file mode 100644 index 2001842b..00000000 --- a/plugins/deviceplugins/denon/denon.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * - * Copyright (C) 2015 Simon Stuerz * - * Copyright (C) 2016 Bernhard Trinnes * - * * - * 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 . * - * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -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 ¬ificationType, 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(); -} diff --git a/plugins/deviceplugins/denon/denon.h b/plugins/deviceplugins/denon/denon.h deleted file mode 100644 index aa83e739..00000000 --- a/plugins/deviceplugins/denon/denon.h +++ /dev/null @@ -1,86 +0,0 @@ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * - * Copyright (C) 2015 Simon Stuerz * - * Copyright (C) 2015 Bernhard Trinnes * - * * - * 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 . * - * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef DENON_H -#define DENON_H - -#include -#include - -#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 ¬ificationType, 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 diff --git a/plugins/deviceplugins/denon/denonconnection.cpp b/plugins/deviceplugins/denon/denonconnection.cpp index 7effd95d..bfae9e76 100644 --- a/plugins/deviceplugins/denon/denonconnection.cpp +++ b/plugins/deviceplugins/denon/denonconnection.cpp @@ -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) diff --git a/plugins/deviceplugins/denon/deviceplugindenon.cpp b/plugins/deviceplugins/denon/deviceplugindenon.cpp index 8a1fb982..d2ecf696 100644 --- a/plugins/deviceplugins/denon/deviceplugindenon.cpp +++ b/plugins/deviceplugins/denon/deviceplugindenon.cpp @@ -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