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