split packages containing multiple messages
This commit is contained in:
parent
053ea0a770
commit
d5c6836de5
@ -71,19 +71,19 @@
|
|||||||
|
|
||||||
DevicePluginKodi::DevicePluginKodi()
|
DevicePluginKodi::DevicePluginKodi()
|
||||||
{
|
{
|
||||||
Q_INIT_RESOURCE(images);
|
// Q_INIT_RESOURCE(images);
|
||||||
QFile file(":/images/guh-logo.png");
|
// QFile file(":/images/guh-logo.png");
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
// if (!file.open(QIODevice::ReadOnly)) {
|
||||||
qCWarning(dcKodi) << "could not open" << file.fileName();
|
// qCWarning(dcKodi) << "could not open" << file.fileName();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
QByteArray guhLogoByteArray = file.readAll();
|
// QByteArray guhLogoByteArray = file.readAll();
|
||||||
if (guhLogoByteArray.isEmpty()) {
|
// if (guhLogoByteArray.isEmpty()) {
|
||||||
qCWarning(dcKodi) << "could not read" << file.fileName();
|
// qCWarning(dcKodi) << "could not read" << file.fileName();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
m_logo = guhLogoByteArray;
|
// m_logo = guhLogoByteArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::HardwareResources DevicePluginKodi::requiredHardware() const
|
DeviceManager::HardwareResources DevicePluginKodi::requiredHardware() const
|
||||||
@ -93,7 +93,8 @@ DeviceManager::HardwareResources DevicePluginKodi::requiredHardware() const
|
|||||||
|
|
||||||
DeviceManager::DeviceSetupStatus DevicePluginKodi::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginKodi::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
Kodi *kodi= new Kodi(m_logo, QHostAddress(device->paramValue("ip").toString()), 9090, this);
|
qCDebug(dcKodi) << "Setup Kodi device" << device->paramValue("ip").toString();
|
||||||
|
Kodi *kodi= new Kodi(QHostAddress(device->paramValue("ip").toString()), 9090, this);
|
||||||
|
|
||||||
connect(kodi, &Kodi::connectionStatusChanged, this, &DevicePluginKodi::onConnectionChanged);
|
connect(kodi, &Kodi::connectionStatusChanged, this, &DevicePluginKodi::onConnectionChanged);
|
||||||
connect(kodi, &Kodi::stateChanged, this, &DevicePluginKodi::onStateChanged);
|
connect(kodi, &Kodi::stateChanged, this, &DevicePluginKodi::onStateChanged);
|
||||||
@ -104,10 +105,11 @@ DeviceManager::DeviceSetupStatus DevicePluginKodi::setupDevice(Device *device)
|
|||||||
connect(kodi, &Kodi::onPlayerPause, this, &DevicePluginKodi::onPlayerPause);
|
connect(kodi, &Kodi::onPlayerPause, this, &DevicePluginKodi::onPlayerPause);
|
||||||
connect(kodi, &Kodi::onPlayerStop, this, &DevicePluginKodi::onPlayerStop);
|
connect(kodi, &Kodi::onPlayerStop, this, &DevicePluginKodi::onPlayerStop);
|
||||||
|
|
||||||
kodi->connectKodi();
|
|
||||||
|
|
||||||
m_kodis.insert(kodi, device);
|
m_kodis.insert(kodi, device);
|
||||||
m_asyncSetups.append(kodi);
|
m_asyncSetups.append(kodi);
|
||||||
|
|
||||||
|
kodi->connectKodi();
|
||||||
|
|
||||||
return DeviceManager::DeviceSetupStatusAsync;
|
return DeviceManager::DeviceSetupStatusAsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,9 +27,6 @@
|
|||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QPixmap>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QImage>
|
|
||||||
|
|
||||||
class DevicePluginKodi : public DevicePlugin
|
class DevicePluginKodi : public DevicePlugin
|
||||||
{
|
{
|
||||||
@ -53,7 +50,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
QHash<Kodi *, Device *> m_kodis;
|
QHash<Kodi *, Device *> m_kodis;
|
||||||
QList<Kodi *> m_asyncSetups;
|
QList<Kodi *> m_asyncSetups;
|
||||||
QByteArray m_logo;
|
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|||||||
@ -20,9 +20,8 @@
|
|||||||
|
|
||||||
#include "kodi.h"
|
#include "kodi.h"
|
||||||
|
|
||||||
Kodi::Kodi(const QByteArray &logo, const QHostAddress &hostAddress, const int &port, QObject *parent) :
|
Kodi::Kodi(const QHostAddress &hostAddress, const int &port, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_logo(logo),
|
|
||||||
m_muted(false),
|
m_muted(false),
|
||||||
m_volume(-1)
|
m_volume(-1)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -23,8 +23,6 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
#include <QImage>
|
|
||||||
#include <QPixmap>
|
|
||||||
|
|
||||||
#include "kodiconnection.h"
|
#include "kodiconnection.h"
|
||||||
#include "kodijsonhandler.h"
|
#include "kodijsonhandler.h"
|
||||||
@ -34,7 +32,7 @@ class Kodi : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit Kodi(const QByteArray &logo, const QHostAddress &hostAddress, const int &port = 9090, QObject *parent = 0);
|
explicit Kodi(const QHostAddress &hostAddress, const int &port = 9090, QObject *parent = 0);
|
||||||
|
|
||||||
QHostAddress hostAddress() const;
|
QHostAddress hostAddress() const;
|
||||||
int port() const;
|
int port() const;
|
||||||
@ -64,7 +62,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
KodiConnection *m_connection;
|
KodiConnection *m_connection;
|
||||||
KodiJsonHandler *m_jsonHandler;
|
KodiJsonHandler *m_jsonHandler;
|
||||||
QByteArray m_logo;
|
|
||||||
bool m_muted;
|
bool m_muted;
|
||||||
int m_volume;
|
int m_volume;
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ include(../../plugins.pri)
|
|||||||
|
|
||||||
TARGET = $$qtLibraryTarget(guh_devicepluginkodi)
|
TARGET = $$qtLibraryTarget(guh_devicepluginkodi)
|
||||||
|
|
||||||
RESOURCES += images.qrc
|
#RESOURCES += images.qrc
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
devicepluginkodi.cpp \
|
devicepluginkodi.cpp \
|
||||||
|
|||||||
@ -90,7 +90,21 @@ void KodiConnection::onError(QAbstractSocket::SocketError socketError)
|
|||||||
void KodiConnection::readData()
|
void KodiConnection::readData()
|
||||||
{
|
{
|
||||||
QByteArray data = m_socket->readAll();
|
QByteArray data = m_socket->readAll();
|
||||||
emit dataReady(data);
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KodiConnection::sendData(const QByteArray &message)
|
void KodiConnection::sendData(const QByteArray &message)
|
||||||
|
|||||||
@ -47,7 +47,6 @@ private:
|
|||||||
int m_port;
|
int m_port;
|
||||||
bool m_connected;
|
bool m_connected;
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onConnected();
|
void onConnected();
|
||||||
void onDisconnected();
|
void onDisconnected();
|
||||||
|
|||||||
Reference in New Issue
Block a user