lgsmarttv: Add Qt6 support

master
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 "integrations/thing.h"
#include "plugininfo.h"
#include "network/networkaccessmanager.h"
#include "network/upnp/upnpdiscovery.h"
#include "hardwaremanager.h"
#include "tvdevice.h"
#include <integrations/thing.h>
#include <network/networkaccessmanager.h>
#include <network/upnp/upnpdiscovery.h>
#include <hardwaremanager.h>
#include <QDebug>

View File

@ -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 <integrations/integrationplugin.h>
#include <network/upnp/upnpdevicedescriptor.h>
#include <plugintimer.h>
#include <QNetworkReply>
class TvDevice;
class IntegrationPluginLgSmartTv : public IntegrationPlugin
{

View File

@ -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 \

View File

@ -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<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";
QNetworkRequest request;
@ -171,7 +171,7 @@ QPair<QNetworkRequest, QByteArray> TvDevice::createDisplayKeyRequest(const QHost
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";
QNetworkRequest request;
@ -195,7 +195,7 @@ QPair<QNetworkRequest, QByteArray> TvDevice::createEndPairingRequest(const QUrl
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";
QNetworkRequest request;
@ -208,7 +208,7 @@ QPair<QNetworkRequest, QByteArray> TvDevice::createEndPairingRequest(const QHost
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";
QNetworkRequest request;
@ -243,7 +243,7 @@ QNetworkRequest TvDevice::createChannelInformationRequest()
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";
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();
}

View File

@ -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 <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>
#include <QXmlStreamReader>
#include <QXmlReader>
#include <QXmlStreamWriter>
#include <QXmlStreamAttributes>
#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<QNetworkRequest, QByteArray> createDisplayKeyRequest(const QHostAddress &host, const int &port);
static QPair<QNetworkRequest, QByteArray> createPairingRequest(const QHostAddress &host, const int &port, const QString &key);
static QPair<QNetworkRequest, QByteArray> createDisplayKeyRequest(const QHostAddress &host, int port);
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 QHostAddress &host, const int &port);
static QPair<QNetworkRequest, QByteArray> createEventRequest(const QHostAddress &host, const int &port);
static QPair<QNetworkRequest, QByteArray> createEndPairingRequest(const QHostAddress &host, 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 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;

View File

@ -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 <QDateTime>
#include <QRegularExpression>
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();
}

View File

@ -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 <QTcpServer>
#include <QTcpSocket>
#include <QDebug>
#include <QDateTime>
#include <QTextStream>
#include <QRegExp>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
class TvEventHandler : public QTcpServer
{