lgsmarttv: Add Qt6 support

This commit is contained in:
Simon Stürz 2025-08-08 14:26:22 +02:00
parent c31980a4cd
commit 6e153628c1
7 changed files with 66 additions and 61 deletions

View File

@ -29,12 +29,13 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "integrationpluginlgsmarttv.h" #include "integrationpluginlgsmarttv.h"
#include "integrations/thing.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "network/networkaccessmanager.h" #include "tvdevice.h"
#include "network/upnp/upnpdiscovery.h"
#include "hardwaremanager.h" #include <integrations/thing.h>
#include <network/networkaccessmanager.h>
#include <network/upnp/upnpdiscovery.h>
#include <hardwaremanager.h>
#include <QDebug> #include <QDebug>

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -31,10 +31,14 @@
#ifndef INTEGRATIONPLUGINLGSMARTTV_H #ifndef INTEGRATIONPLUGINLGSMARTTV_H
#define INTEGRATIONPLUGINLGSMARTTV_H #define INTEGRATIONPLUGINLGSMARTTV_H
#include "tvdevice.h" #include <integrations/integrationplugin.h>
#include "plugintimer.h"
#include "integrations/integrationplugin.h" #include <network/upnp/upnpdevicedescriptor.h>
#include "network/upnp/upnpdevicedescriptor.h" #include <plugintimer.h>
#include <QNetworkReply>
class TvDevice;
class IntegrationPluginLgSmartTv : public IntegrationPlugin class IntegrationPluginLgSmartTv : public IntegrationPlugin
{ {

View File

@ -1,8 +1,12 @@
include(../plugins.pri) include(../plugins.pri)
TARGET = $$qtLibraryTarget(nymea_integrationpluginlgsmarttv) QT += network
QT+= network xml greaterThan(QT_MAJOR_VERSION, 5) {
QT += core5compat
} else {
QT += xml
}
SOURCES += \ SOURCES += \
integrationpluginlgsmarttv.cpp \ integrationpluginlgsmarttv.cpp \

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -67,7 +67,7 @@ QHostAddress TvDevice::hostAddress() const
return m_hostAddress; return m_hostAddress;
} }
void TvDevice::setPort(const int &port) void TvDevice::setPort(int port)
{ {
m_port = port; m_port = port;
} }
@ -87,11 +87,11 @@ QString TvDevice::uuid() const
return m_uuid; return m_uuid;
} }
void TvDevice::setPaired(const bool &paired) void TvDevice::setPaired(bool paired)
{ {
if (m_paired != paired) { if (m_paired != paired) {
m_paired = paired; m_paired = paired;
stateChanged(); emit stateChanged();
} }
} }
@ -100,7 +100,7 @@ bool TvDevice::paired() const
return m_paired; return m_paired;
} }
void TvDevice::setReachable(const bool &reachable) void TvDevice::setReachable(bool reachable)
{ {
if (m_reachable != reachable) { if (m_reachable != reachable) {
qCDebug(dcLgSmartTv()) << "TV Event handler" << (reachable ? "reachable" : "not reachable any more"); qCDebug(dcLgSmartTv()) << "TV Event handler" << (reachable ? "reachable" : "not reachable any more");
@ -159,7 +159,7 @@ QString TvDevice::inputSourceLabelName() const
return m_inputSourceLabel; return m_inputSourceLabel;
} }
QPair<QNetworkRequest, QByteArray> TvDevice::createDisplayKeyRequest(const QHostAddress &host, const int &port) QPair<QNetworkRequest, QByteArray> TvDevice::createDisplayKeyRequest(const QHostAddress &host, int port)
{ {
QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/pairing"; QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/pairing";
QNetworkRequest request; QNetworkRequest request;
@ -171,7 +171,7 @@ QPair<QNetworkRequest, QByteArray> TvDevice::createDisplayKeyRequest(const QHost
return QPair<QNetworkRequest, QByteArray>(request, data); return QPair<QNetworkRequest, QByteArray>(request, data);
} }
QPair<QNetworkRequest, QByteArray> TvDevice::createPairingRequest(const QHostAddress &host, const int &port, const QString &key) QPair<QNetworkRequest, QByteArray> TvDevice::createPairingRequest(const QHostAddress &host, int port, const QString &key)
{ {
QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/pairing"; QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/pairing";
QNetworkRequest request; QNetworkRequest request;
@ -195,7 +195,7 @@ QPair<QNetworkRequest, QByteArray> TvDevice::createEndPairingRequest(const QUrl
return QPair<QNetworkRequest, QByteArray>(request, data); return QPair<QNetworkRequest, QByteArray>(request, data);
} }
QPair<QNetworkRequest, QByteArray> TvDevice::createEndPairingRequest(const QHostAddress &host, const int &port) QPair<QNetworkRequest, QByteArray> TvDevice::createEndPairingRequest(const QHostAddress &host, int port)
{ {
QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/pairing"; QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/pairing";
QNetworkRequest request; QNetworkRequest request;
@ -208,7 +208,7 @@ QPair<QNetworkRequest, QByteArray> TvDevice::createEndPairingRequest(const QHost
return QPair<QNetworkRequest, QByteArray>(request, data); return QPair<QNetworkRequest, QByteArray>(request, data);
} }
QPair<QNetworkRequest, QByteArray> TvDevice::createEventRequest(const QHostAddress &host, const int &port) QPair<QNetworkRequest, QByteArray> TvDevice::createEventRequest(const QHostAddress &host, int port)
{ {
QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/event"; QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/event";
QNetworkRequest request; QNetworkRequest request;
@ -243,7 +243,7 @@ QNetworkRequest TvDevice::createChannelInformationRequest()
return request; return request;
} }
QPair<QNetworkRequest, QByteArray> TvDevice::createPressButtonRequest(const TvDevice::RemoteKey &key) QPair<QNetworkRequest, QByteArray> TvDevice::createPressButtonRequest(RemoteKey key)
{ {
QString urlString = "http://" + hostAddress().toString() + ":" + QString::number(port()) + "/udap/api/command"; QString urlString = "http://" + hostAddress().toString() + ":" + QString::number(port()) + "/udap/api/command";
QNetworkRequest request; QNetworkRequest request;
@ -265,10 +265,10 @@ void TvDevice::onVolumeInformationUpdate(const QByteArray &data)
while(!xml.atEnd() && !xml.hasError()) { while(!xml.atEnd() && !xml.hasError()) {
xml.readNext(); xml.readNext();
if(xml.name() == "mute") { if (xml.name() == QString("mute")) {
m_mute = QVariant(xml.readElementText()).toBool(); m_mute = QVariant(xml.readElementText()).toBool();
} }
if(xml.name() == "level") { if (xml.name() == QString("level")) {
m_volumeLevel = QVariant(xml.readElementText()).toInt(); m_volumeLevel = QVariant(xml.readElementText()).toInt();
} }
} }
@ -283,22 +283,22 @@ void TvDevice::onChannelInformationUpdate(const QByteArray &data)
while(!xml.atEnd() && !xml.hasError()) { while(!xml.atEnd() && !xml.hasError()) {
xml.readNext(); xml.readNext();
if(xml.name() == "chtype") { if (xml.name() == QString("chtype")) {
m_channelType = xml.readElementText(); m_channelType = xml.readElementText();
} }
if(xml.name() == "major") { if (xml.name() == QString("major")) {
m_channelNumber = QVariant(xml.readElementText()).toInt(); m_channelNumber = QVariant(xml.readElementText()).toInt();
} }
if(xml.name() == "chname") { if (xml.name() == QString("chname")) {
m_channelName = xml.readElementText(); m_channelName = xml.readElementText();
} }
if(xml.name() == "progName") { if (xml.name() == QString("progName")) {
m_programName = xml.readElementText(); m_programName = xml.readElementText();
} }
if(xml.name() == "inputSourceIdx") { if (xml.name() == QString("inputSourceIdx")) {
m_inputSourceIndex = QVariant(xml.readElementText()).toInt(); m_inputSourceIndex = QVariant(xml.readElementText()).toInt();
} }
if(xml.name() == "labelName") { if (xml.name() == QString("labelName")) {
m_inputSourceLabel = xml.readElementText(); m_inputSourceLabel = xml.readElementText();
} }
} }
@ -314,11 +314,12 @@ QString TvDevice::printXmlData(const QByteArray &data)
while (!reader.atEnd()) { while (!reader.atEnd()) {
reader.readNext(); reader.readNext();
if(!reader.isWhitespace()) { if (!reader.isWhitespace()) {
writer.writeCurrentToken(reader); writer.writeCurrentToken(reader);
} }
} }
if(reader.hasError()) {
if (reader.hasError()) {
qCWarning(dcLgSmartTv()) << "error reading XML thing information:" << reader.errorString(); qCWarning(dcLgSmartTv()) << "error reading XML thing information:" << reader.errorString();
} }
return xmlOut; return xmlOut;
@ -329,7 +330,7 @@ void TvDevice::eventOccured(const QByteArray &data)
qCDebug(dcLgSmartTv()) << "Event handler data received" << printXmlData(data); qCDebug(dcLgSmartTv()) << "Event handler data received" << printXmlData(data);
// if we got a channel changed event... // if we got a channel changed event...
if(data.contains("ChannelChanged")) { if (data.contains("ChannelChanged")) {
onChannelInformationUpdate(data); onChannelInformationUpdate(data);
return; return;
} }
@ -338,7 +339,7 @@ void TvDevice::eventOccured(const QByteArray &data)
// if the tv suspends, it will send a byebye message, which means // if the tv suspends, it will send a byebye message, which means
// the pairing will be closed. // the pairing will be closed.
if(data.contains("api type=\"pairing\"") && data.contains("byebye")) { if (data.contains("api type=\"pairing\"") && data.contains("byebye")) {
qCDebug(dcLgSmartTv()) << "Ended pairing (host)"; qCDebug(dcLgSmartTv()) << "Ended pairing (host)";
setPaired(false); setPaired(false);
setReachable(false); setReachable(false);
@ -351,14 +352,15 @@ void TvDevice::eventOccured(const QByteArray &data)
while(!xml.atEnd() && !xml.hasError()) { while(!xml.atEnd() && !xml.hasError()) {
xml.readNext(); xml.readNext();
if(xml.name() == "name") { if (xml.name() == QString("name")) {
if(xml.readElementText() == "3DMode") { if (xml.readElementText() == "3DMode") {
xml.readNext(); xml.readNext();
if(xml.name() == "value") { if (xml.name() == QString("value")) {
m_is3DMode = QVariant(xml.readElementText()).toBool(); m_is3DMode = QVariant(xml.readElementText()).toBool();
} }
} }
} }
} }
emit stateChanged(); emit stateChanged();
} }

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -37,13 +37,11 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QUrl>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlReader> #include <QXmlReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QXmlStreamAttributes> #include <QXmlStreamAttributes>
#include "integrations/integrationplugin.h"
#include "tveventhandler.h" #include "tveventhandler.h"
class TvDevice : public QObject class TvDevice : public QObject
@ -128,17 +126,17 @@ public:
void setHostAddress(const QHostAddress &hostAddress); void setHostAddress(const QHostAddress &hostAddress);
QHostAddress hostAddress() const; QHostAddress hostAddress() const;
void setPort(const int &port); void setPort(int port);
int port() const; int port() const;
void setUuid(const QString &uuid); void setUuid(const QString &uuid);
QString uuid() const; QString uuid() const;
// States // States
void setPaired(const bool &paired); void setPaired(bool paired);
bool paired() const; bool paired() const;
void setReachable(const bool &reachable); void setReachable(bool reachable);
bool reachable() const; bool reachable() const;
bool is3DMode() const; bool is3DMode() const;
@ -152,13 +150,13 @@ public:
QString inputSourceLabelName() const; QString inputSourceLabelName() const;
// other methods // other methods
static QPair<QNetworkRequest, QByteArray> createDisplayKeyRequest(const QHostAddress &host, const int &port); static QPair<QNetworkRequest, QByteArray> createDisplayKeyRequest(const QHostAddress &host, int port);
static QPair<QNetworkRequest, QByteArray> createPairingRequest(const QHostAddress &host, const int &port, const QString &key); static QPair<QNetworkRequest, QByteArray> createPairingRequest(const QHostAddress &host, int port, const QString &key);
static QPair<QNetworkRequest, QByteArray> createEndPairingRequest(const QUrl &url); static QPair<QNetworkRequest, QByteArray> createEndPairingRequest(const QUrl &url);
static QPair<QNetworkRequest, QByteArray> createEndPairingRequest(const QHostAddress &host, const int &port); static QPair<QNetworkRequest, QByteArray> createEndPairingRequest(const QHostAddress &host, int port);
static QPair<QNetworkRequest, QByteArray> createEventRequest(const QHostAddress &host, const int &port); static QPair<QNetworkRequest, QByteArray> createEventRequest(const QHostAddress &host, int port);
QPair<QNetworkRequest, QByteArray> createPressButtonRequest(const TvDevice::RemoteKey &key); QPair<QNetworkRequest, QByteArray> createPressButtonRequest(TvDevice::RemoteKey key);
QNetworkRequest createVolumeInformationRequest(); QNetworkRequest createVolumeInformationRequest();
QNetworkRequest createChannelInformationRequest(); QNetworkRequest createChannelInformationRequest();
@ -166,7 +164,7 @@ public:
void onChannelInformationUpdate(const QByteArray &data); void onChannelInformationUpdate(const QByteArray &data);
private: private:
TvEventHandler *m_eventHandler; TvEventHandler *m_eventHandler = nullptr;
QHostAddress m_hostAddress; QHostAddress m_hostAddress;
int m_port; int m_port;

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -31,6 +31,9 @@
#include "tveventhandler.h" #include "tveventhandler.h"
#include "extern-plugininfo.h" #include "extern-plugininfo.h"
#include <QDateTime>
#include <QRegularExpression>
TvEventHandler::TvEventHandler(const QHostAddress &host, const int &port, QObject *parent) : TvEventHandler::TvEventHandler(const QHostAddress &host, const int &port, QObject *parent) :
QTcpServer(parent), QTcpServer(parent),
m_host(host), m_host(host),
@ -85,8 +88,8 @@ void TvEventHandler::readClient()
// check if we got header // check if we got header
if (data.startsWith("POST") && !m_expectingData) { if (data.startsWith("POST") && !m_expectingData) {
m_expectingData = true; m_expectingData = true;
QStringList tokens = QString(data).split(QRegExp("[ \r\n][ \r\n]*")); QStringList tokens = QString(data).split(QRegularExpression("[ \r\n][ \r\n]*"));
qCDebug(dcLgSmartTv()) << "event handler -> event occured" << "http://" << m_host.toString() << ":" << m_port << tokens[1]; qCDebug(dcLgSmartTv()) << "Event handler -> event occured" << "http://" << m_host.toString() << ":" << m_port << tokens[1];
} }
} }
} }
@ -94,7 +97,7 @@ void TvEventHandler::readClient()
void TvEventHandler::onDisconnected() void TvEventHandler::onDisconnected()
{ {
QTcpSocket* socket = (QTcpSocket*)sender(); QTcpSocket* socket = (QTcpSocket*)sender();
qCDebug(dcLgSmartTv()) << "event handler -> client disconnected" << socket->peerAddress(); qCDebug(dcLgSmartTv()) << "Event handler -> client disconnected" << socket->peerAddress();
socket->deleteLater(); socket->deleteLater();
} }

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -33,13 +33,6 @@
#include <QTcpServer> #include <QTcpServer>
#include <QTcpSocket> #include <QTcpSocket>
#include <QDebug>
#include <QDateTime>
#include <QTextStream>
#include <QRegExp>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
class TvEventHandler : public QTcpServer class TvEventHandler : public QTcpServer
{ {