some experiments
This commit is contained in:
parent
1f35f78238
commit
5daf3023b9
@ -79,6 +79,18 @@ void DevicePluginKodi::deviceRemoved(Device *device)
|
||||
kodiConnection->deleteLater();
|
||||
}
|
||||
|
||||
void DevicePluginKodi::guhTimer()
|
||||
{
|
||||
foreach (KodiConnection *kodi, m_kodiConnections.keys()) {
|
||||
if (!kodi->connected()) {
|
||||
kodi->connectToKodi();
|
||||
continue;
|
||||
} else {
|
||||
// update.. ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeviceManager::DeviceError DevicePluginKodi::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
@ -94,6 +106,18 @@ void DevicePluginKodi::upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &
|
||||
QList<DeviceDescriptor> deviceDescriptors;
|
||||
foreach (const UpnpDeviceDescriptor &upnpDescriptor, upnpDeviceDescriptorList) {
|
||||
if (upnpDescriptor.modelName().contains("Kodi")) {
|
||||
|
||||
// check if we allready found the kodi on this ip
|
||||
bool alreadyAdded = false;
|
||||
foreach (const DeviceDescriptor dDescriptor, deviceDescriptors) {
|
||||
if (dDescriptor.params().paramValue("ip").toString() == upnpDescriptor.hostAddress().toString()) {
|
||||
alreadyAdded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (alreadyAdded)
|
||||
continue;
|
||||
|
||||
qCDebug(dcKodi) << upnpDescriptor;
|
||||
DeviceDescriptor deviceDescriptor(kodiDeviceClassId, "Kodi - Media Center", upnpDescriptor.hostAddress().toString());
|
||||
ParamList params;
|
||||
|
||||
@ -40,6 +40,7 @@ public:
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||
void deviceRemoved(Device *device) override;
|
||||
void guhTimer() override;
|
||||
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
void upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &upnpDeviceDescriptorList) override;
|
||||
|
||||
@ -38,7 +38,8 @@
|
||||
"id": "bc98cdb0-4d0e-48ca-afc7-922e49bb7813",
|
||||
"idName": "mute",
|
||||
"name": "mute",
|
||||
"type": "bool"
|
||||
"type": "bool",
|
||||
"writable": {}
|
||||
},
|
||||
{
|
||||
"id": "9dfe5d78-4c3f-497c-bab1-bb9fdf7e93a9",
|
||||
@ -46,9 +47,10 @@
|
||||
"name": "volume",
|
||||
"unit": "Percentage",
|
||||
"type": "int",
|
||||
"writable": true,
|
||||
"minValue": 0,
|
||||
"maxValue": 100
|
||||
"writable": {
|
||||
"minValue": 0,
|
||||
"maxValue": 100
|
||||
}
|
||||
}
|
||||
],
|
||||
"actionTypes": [
|
||||
|
||||
@ -1,6 +1,42 @@
|
||||
#include "jsonhandler.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QBuffer>
|
||||
|
||||
JsonHandler::JsonHandler(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
//QByteArray JsonHandler::createHelloMessage(QString title, QString message)
|
||||
//{
|
||||
// QByteArray payload;
|
||||
|
||||
// QByteArray iconData;
|
||||
// QBuffer buffer(&iconData);
|
||||
// buffer.open(QIODevice::WriteOnly);
|
||||
// icon.save(&buffer, "PNG");
|
||||
// // payload.clear();
|
||||
|
||||
// // // titel
|
||||
// // payload.push_back(QByteArray::fromStdString(title.toStdString()));
|
||||
// // payload.push_back('\0');
|
||||
|
||||
// // // message
|
||||
// // payload.push_back(QByteArray::fromStdString(message.toStdString()));
|
||||
// // payload.push_back('\0');
|
||||
|
||||
// // // icontype ( 0=>NOICON, 1=>JPEG , 2=>PNG , 3=>GIF )
|
||||
// // payload.push_back(2);
|
||||
|
||||
// // payload.push_back("0000");
|
||||
|
||||
// // // image data
|
||||
// // payload.push_back(iconData);
|
||||
// // payload.push_back('\0');
|
||||
|
||||
// // qCDebug(dcKodi) << payload;
|
||||
|
||||
// return payload;
|
||||
//}
|
||||
|
||||
@ -9,6 +9,8 @@ class JsonHandler : public QObject
|
||||
public:
|
||||
explicit JsonHandler(QObject *parent = 0);
|
||||
|
||||
//static QByteArray createHelloMessage(QString title, QString message);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
@ -2,6 +2,8 @@ include(../../plugins.pri)
|
||||
|
||||
TARGET = $$qtLibraryTarget(guh_devicepluginkodi)
|
||||
|
||||
RESOURCES += images.qrc \
|
||||
|
||||
SOURCES += \
|
||||
devicepluginkodi.cpp \
|
||||
kodiconnection.cpp \
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
#include "kodiconnection.h"
|
||||
#include "loggingcategories.h"
|
||||
#include "jsonhandler.h"
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
KodiConnection::KodiConnection(const QHostAddress &hostAddress, const int &port, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_hostAddress(hostAddress),
|
||||
m_port(port)
|
||||
m_port(port),
|
||||
m_connected(false)
|
||||
{
|
||||
m_socket = new QTcpSocket(this);
|
||||
|
||||
@ -16,6 +20,9 @@ KodiConnection::KodiConnection(const QHostAddress &hostAddress, const int &port,
|
||||
|
||||
void KodiConnection::connectToKodi()
|
||||
{
|
||||
if (m_socket->state() == QAbstractSocket::ConnectingState) {
|
||||
return;
|
||||
}
|
||||
m_socket->connectToHost(m_hostAddress, m_port);
|
||||
}
|
||||
|
||||
@ -34,15 +41,24 @@ int KodiConnection::port() const
|
||||
return m_port;
|
||||
}
|
||||
|
||||
bool KodiConnection::connected()
|
||||
{
|
||||
return m_connected;
|
||||
}
|
||||
|
||||
void KodiConnection::onConnected()
|
||||
{
|
||||
qCDebug(dcKodi) << "connected successfully to" << hostAddress().toString() << port();
|
||||
m_connected = true;
|
||||
// QPixmap logo = QPixmap(":/images/guh-logo.png");
|
||||
// qCDebug(dcKodi) << "image size" << logo.size();
|
||||
emit connectionStateChanged(true);
|
||||
}
|
||||
|
||||
void KodiConnection::onDisconnected()
|
||||
{
|
||||
qCDebug(dcKodi) << "disconnected from" << hostAddress().toString() << port();
|
||||
m_connected = false;
|
||||
emit connectionStateChanged(false);
|
||||
}
|
||||
|
||||
@ -64,7 +80,6 @@ void KodiConnection::readData()
|
||||
}
|
||||
qCDebug(dcKodi) << "data received:" << jsonDoc.toJson();
|
||||
|
||||
unsigned short m_IconSize;
|
||||
emit dataReady(data);
|
||||
}
|
||||
|
||||
|
||||
@ -18,11 +18,13 @@ public:
|
||||
QHostAddress hostAddress() const;
|
||||
int port() const;
|
||||
|
||||
bool connected();
|
||||
|
||||
private:
|
||||
QHostAddress m_hostAddress;
|
||||
int m_port;
|
||||
int m_id;
|
||||
|
||||
bool m_connected;
|
||||
|
||||
|
||||
QTcpSocket *m_socket;
|
||||
|
||||
Reference in New Issue
Block a user