From 6e153628c123edd4783820dc15c3b816f7c8c94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 8 Aug 2025 14:26:22 +0200 Subject: [PATCH] lgsmarttv: Add Qt6 support --- lgsmarttv/integrationpluginlgsmarttv.cpp | 11 ++--- lgsmarttv/integrationpluginlgsmarttv.h | 14 ++++--- lgsmarttv/lgsmarttv.pro | 8 +++- lgsmarttv/tvdevice.cpp | 52 ++++++++++++------------ lgsmarttv/tvdevice.h | 22 +++++----- lgsmarttv/tveventhandler.cpp | 11 +++-- lgsmarttv/tveventhandler.h | 9 +--- 7 files changed, 66 insertions(+), 61 deletions(-) diff --git a/lgsmarttv/integrationpluginlgsmarttv.cpp b/lgsmarttv/integrationpluginlgsmarttv.cpp index 9562961e..10c8d950 100644 --- a/lgsmarttv/integrationpluginlgsmarttv.cpp +++ b/lgsmarttv/integrationpluginlgsmarttv.cpp @@ -29,12 +29,13 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "integrationpluginlgsmarttv.h" - -#include "integrations/thing.h" #include "plugininfo.h" -#include "network/networkaccessmanager.h" -#include "network/upnp/upnpdiscovery.h" -#include "hardwaremanager.h" +#include "tvdevice.h" + +#include +#include +#include +#include #include diff --git a/lgsmarttv/integrationpluginlgsmarttv.h b/lgsmarttv/integrationpluginlgsmarttv.h index fe127b78..6bd78026 100644 --- a/lgsmarttv/integrationpluginlgsmarttv.h +++ b/lgsmarttv/integrationpluginlgsmarttv.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -31,10 +31,14 @@ #ifndef INTEGRATIONPLUGINLGSMARTTV_H #define INTEGRATIONPLUGINLGSMARTTV_H -#include "tvdevice.h" -#include "plugintimer.h" -#include "integrations/integrationplugin.h" -#include "network/upnp/upnpdevicedescriptor.h" +#include + +#include +#include + +#include + +class TvDevice; class IntegrationPluginLgSmartTv : public IntegrationPlugin { diff --git a/lgsmarttv/lgsmarttv.pro b/lgsmarttv/lgsmarttv.pro index 1b8349c5..36c5e987 100644 --- a/lgsmarttv/lgsmarttv.pro +++ b/lgsmarttv/lgsmarttv.pro @@ -1,8 +1,12 @@ include(../plugins.pri) -TARGET = $$qtLibraryTarget(nymea_integrationpluginlgsmarttv) +QT += network -QT+= network xml +greaterThan(QT_MAJOR_VERSION, 5) { + QT += core5compat +} else { + QT += xml +} SOURCES += \ integrationpluginlgsmarttv.cpp \ diff --git a/lgsmarttv/tvdevice.cpp b/lgsmarttv/tvdevice.cpp index 13c8c76b..a3a98532 100644 --- a/lgsmarttv/tvdevice.cpp +++ b/lgsmarttv/tvdevice.cpp @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -67,7 +67,7 @@ QHostAddress TvDevice::hostAddress() const return m_hostAddress; } -void TvDevice::setPort(const int &port) +void TvDevice::setPort(int port) { m_port = port; } @@ -87,11 +87,11 @@ QString TvDevice::uuid() const return m_uuid; } -void TvDevice::setPaired(const bool &paired) +void TvDevice::setPaired(bool paired) { if (m_paired != paired) { m_paired = paired; - stateChanged(); + emit stateChanged(); } } @@ -100,7 +100,7 @@ bool TvDevice::paired() const return m_paired; } -void TvDevice::setReachable(const bool &reachable) +void TvDevice::setReachable(bool reachable) { if (m_reachable != reachable) { qCDebug(dcLgSmartTv()) << "TV Event handler" << (reachable ? "reachable" : "not reachable any more"); @@ -159,7 +159,7 @@ QString TvDevice::inputSourceLabelName() const return m_inputSourceLabel; } -QPair TvDevice::createDisplayKeyRequest(const QHostAddress &host, const int &port) +QPair TvDevice::createDisplayKeyRequest(const QHostAddress &host, int port) { QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/pairing"; QNetworkRequest request; @@ -171,7 +171,7 @@ QPair TvDevice::createDisplayKeyRequest(const QHost return QPair(request, data); } -QPair TvDevice::createPairingRequest(const QHostAddress &host, const int &port, const QString &key) +QPair TvDevice::createPairingRequest(const QHostAddress &host, int port, const QString &key) { QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/pairing"; QNetworkRequest request; @@ -195,7 +195,7 @@ QPair TvDevice::createEndPairingRequest(const QUrl return QPair(request, data); } -QPair TvDevice::createEndPairingRequest(const QHostAddress &host, const int &port) +QPair TvDevice::createEndPairingRequest(const QHostAddress &host, int port) { QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/pairing"; QNetworkRequest request; @@ -208,7 +208,7 @@ QPair TvDevice::createEndPairingRequest(const QHost return QPair(request, data); } -QPair TvDevice::createEventRequest(const QHostAddress &host, const int &port) +QPair TvDevice::createEventRequest(const QHostAddress &host, int port) { QString urlString = "http://" + host.toString() + ":" + QString::number(port) + "/udap/api/event"; QNetworkRequest request; @@ -243,7 +243,7 @@ QNetworkRequest TvDevice::createChannelInformationRequest() return request; } -QPair TvDevice::createPressButtonRequest(const TvDevice::RemoteKey &key) +QPair TvDevice::createPressButtonRequest(RemoteKey key) { QString urlString = "http://" + hostAddress().toString() + ":" + QString::number(port()) + "/udap/api/command"; QNetworkRequest request; @@ -265,10 +265,10 @@ void TvDevice::onVolumeInformationUpdate(const QByteArray &data) while(!xml.atEnd() && !xml.hasError()) { xml.readNext(); - if(xml.name() == "mute") { + if (xml.name() == QString("mute")) { m_mute = QVariant(xml.readElementText()).toBool(); } - if(xml.name() == "level") { + if (xml.name() == QString("level")) { m_volumeLevel = QVariant(xml.readElementText()).toInt(); } } @@ -283,22 +283,22 @@ void TvDevice::onChannelInformationUpdate(const QByteArray &data) while(!xml.atEnd() && !xml.hasError()) { xml.readNext(); - if(xml.name() == "chtype") { + if (xml.name() == QString("chtype")) { m_channelType = xml.readElementText(); } - if(xml.name() == "major") { + if (xml.name() == QString("major")) { m_channelNumber = QVariant(xml.readElementText()).toInt(); } - if(xml.name() == "chname") { + if (xml.name() == QString("chname")) { m_channelName = xml.readElementText(); } - if(xml.name() == "progName") { + if (xml.name() == QString("progName")) { m_programName = xml.readElementText(); } - if(xml.name() == "inputSourceIdx") { + if (xml.name() == QString("inputSourceIdx")) { m_inputSourceIndex = QVariant(xml.readElementText()).toInt(); } - if(xml.name() == "labelName") { + if (xml.name() == QString("labelName")) { m_inputSourceLabel = xml.readElementText(); } } @@ -314,11 +314,12 @@ QString TvDevice::printXmlData(const QByteArray &data) while (!reader.atEnd()) { reader.readNext(); - if(!reader.isWhitespace()) { + if (!reader.isWhitespace()) { writer.writeCurrentToken(reader); } } - if(reader.hasError()) { + + if (reader.hasError()) { qCWarning(dcLgSmartTv()) << "error reading XML thing information:" << reader.errorString(); } return xmlOut; @@ -329,7 +330,7 @@ void TvDevice::eventOccured(const QByteArray &data) qCDebug(dcLgSmartTv()) << "Event handler data received" << printXmlData(data); // if we got a channel changed event... - if(data.contains("ChannelChanged")) { + if (data.contains("ChannelChanged")) { onChannelInformationUpdate(data); return; } @@ -338,7 +339,7 @@ void TvDevice::eventOccured(const QByteArray &data) // if the tv suspends, it will send a byebye message, which means // 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)"; setPaired(false); setReachable(false); @@ -351,14 +352,15 @@ void TvDevice::eventOccured(const QByteArray &data) while(!xml.atEnd() && !xml.hasError()) { xml.readNext(); - if(xml.name() == "name") { - if(xml.readElementText() == "3DMode") { + if (xml.name() == QString("name")) { + if (xml.readElementText() == "3DMode") { xml.readNext(); - if(xml.name() == "value") { + if (xml.name() == QString("value")) { m_is3DMode = QVariant(xml.readElementText()).toBool(); } } } } + emit stateChanged(); } diff --git a/lgsmarttv/tvdevice.h b/lgsmarttv/tvdevice.h index c1fb917a..4a72567c 100644 --- a/lgsmarttv/tvdevice.h +++ b/lgsmarttv/tvdevice.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -37,13 +37,11 @@ #include #include #include -#include #include #include #include #include -#include "integrations/integrationplugin.h" #include "tveventhandler.h" class TvDevice : public QObject @@ -128,17 +126,17 @@ public: void setHostAddress(const QHostAddress &hostAddress); QHostAddress hostAddress() const; - void setPort(const int &port); + void setPort(int port); int port() const; void setUuid(const QString &uuid); QString uuid() const; // States - void setPaired(const bool &paired); + void setPaired(bool paired); bool paired() const; - void setReachable(const bool &reachable); + void setReachable(bool reachable); bool reachable() const; bool is3DMode() const; @@ -152,13 +150,13 @@ public: QString inputSourceLabelName() const; // other methods - static QPair createDisplayKeyRequest(const QHostAddress &host, const int &port); - static QPair createPairingRequest(const QHostAddress &host, const int &port, const QString &key); + static QPair createDisplayKeyRequest(const QHostAddress &host, int port); + static QPair createPairingRequest(const QHostAddress &host, int port, const QString &key); static QPair createEndPairingRequest(const QUrl &url); - static QPair createEndPairingRequest(const QHostAddress &host, const int &port); - static QPair createEventRequest(const QHostAddress &host, const int &port); + static QPair createEndPairingRequest(const QHostAddress &host, int port); + static QPair createEventRequest(const QHostAddress &host, int port); - QPair createPressButtonRequest(const TvDevice::RemoteKey &key); + QPair createPressButtonRequest(TvDevice::RemoteKey key); QNetworkRequest createVolumeInformationRequest(); QNetworkRequest createChannelInformationRequest(); @@ -166,7 +164,7 @@ public: void onChannelInformationUpdate(const QByteArray &data); private: - TvEventHandler *m_eventHandler; + TvEventHandler *m_eventHandler = nullptr; QHostAddress m_hostAddress; int m_port; diff --git a/lgsmarttv/tveventhandler.cpp b/lgsmarttv/tveventhandler.cpp index 6ce827f2..b3f7e1de 100644 --- a/lgsmarttv/tveventhandler.cpp +++ b/lgsmarttv/tveventhandler.cpp @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -31,6 +31,9 @@ #include "tveventhandler.h" #include "extern-plugininfo.h" +#include +#include + TvEventHandler::TvEventHandler(const QHostAddress &host, const int &port, QObject *parent) : QTcpServer(parent), m_host(host), @@ -85,8 +88,8 @@ void TvEventHandler::readClient() // check if we got header if (data.startsWith("POST") && !m_expectingData) { m_expectingData = true; - QStringList tokens = QString(data).split(QRegExp("[ \r\n][ \r\n]*")); - qCDebug(dcLgSmartTv()) << "event handler -> event occured" << "http://" << m_host.toString() << ":" << m_port << tokens[1]; + QStringList tokens = QString(data).split(QRegularExpression("[ \r\n][ \r\n]*")); + qCDebug(dcLgSmartTv()) << "Event handler -> event occured" << "http://" << m_host.toString() << ":" << m_port << tokens[1]; } } } @@ -94,7 +97,7 @@ void TvEventHandler::readClient() void TvEventHandler::onDisconnected() { QTcpSocket* socket = (QTcpSocket*)sender(); - qCDebug(dcLgSmartTv()) << "event handler -> client disconnected" << socket->peerAddress(); + qCDebug(dcLgSmartTv()) << "Event handler -> client disconnected" << socket->peerAddress(); socket->deleteLater(); } diff --git a/lgsmarttv/tveventhandler.h b/lgsmarttv/tveventhandler.h index 188ef74e..67050d2d 100644 --- a/lgsmarttv/tveventhandler.h +++ b/lgsmarttv/tveventhandler.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -33,13 +33,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include class TvEventHandler : public QTcpServer {