From 3be9de549a3da86407a05b2f9aa7392ba01ec348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 12 Jun 2015 14:44:30 +0200 Subject: [PATCH] remove typeutils.cpp and improve lgsmarttv --- libguh/libguh.pro | 1 - .../lgsmarttv/devicepluginlgsmarttv.cpp | 46 +++++++++---------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/libguh/libguh.pro b/libguh/libguh.pro index a9971643..f881fd38 100644 --- a/libguh/libguh.pro +++ b/libguh/libguh.pro @@ -37,7 +37,6 @@ SOURCES += plugin/device.cpp \ types/ruleaction.cpp \ types/ruleactionparam.cpp \ types/statedescriptor.cpp \ - typeutils.cpp \ HEADERS += plugin/device.h \ plugin/deviceclass.h \ diff --git a/plugins/deviceplugins/lgsmarttv/devicepluginlgsmarttv.cpp b/plugins/deviceplugins/lgsmarttv/devicepluginlgsmarttv.cpp index 3df06b87..d0c3d401 100644 --- a/plugins/deviceplugins/lgsmarttv/devicepluginlgsmarttv.cpp +++ b/plugins/deviceplugins/lgsmarttv/devicepluginlgsmarttv.cpp @@ -103,14 +103,6 @@ DeviceManager::DeviceError DevicePluginLgSmartTv::discoverDevices(const DeviceCl DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::setupDevice(Device *device) { - - qDebug() << "setup tv"; - qDebug() << device->params(); - - QString key = m_tvKeys.value(device->paramValue("uuid").toString()); - qDebug() << "key for this device" << key; - device->setParamValue("key", key); - UpnpDeviceDescriptor upnpDeviceDescriptor; upnpDeviceDescriptor.setFriendlyName(device->paramValue("name").toString()); upnpDeviceDescriptor.setUuid(device->paramValue("uuid").toString()); @@ -120,15 +112,34 @@ DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::setupDevice(Device *devi upnpDeviceDescriptor.setLocation(QUrl(device->paramValue("location").toString())); TvDevice *tvDevice = new TvDevice(this, upnpDeviceDescriptor); - tvDevice->setKey(key); + + // check if the key wasn't loaded + if (device->paramValue("key") == QString()) { + // check if we know the key from the pairing procedure + if (!m_tvKeys.contains(device->paramValue("uuid").toString())) { + qWarning() << "could not find any pairing key"; + return DeviceManager::DeviceSetupStatusFailure; + } + // use the key from the pairing procedure + tvDevice->endPairing(); + QString key = m_tvKeys.value(device->paramValue("uuid").toString()); + tvDevice->setKey(key); + device->setParamValue("key", key); + } else { + // add the key for editing + if (!m_tvKeys.contains(device->paramValue("uuid").toString())) { + m_tvKeys.insert(tvDevice->uuid(), tvDevice->key()); + } + } connect(tvDevice, &TvDevice::pairingFinished, this, &DevicePluginLgSmartTv::slotPairingFinished); connect(tvDevice, &TvDevice::sendCommandFinished, this, &DevicePluginLgSmartTv::sendingCommandFinished); connect(tvDevice, &TvDevice::statusChanged, this, &DevicePluginLgSmartTv::statusChanged); m_tvList.insert(tvDevice, device); + tvDevice->requestPairing(); - return DeviceManager::DeviceSetupStatusSuccess; + return DeviceManager::DeviceSetupStatusAsync; } DeviceManager::HardwareResources DevicePluginLgSmartTv::requiredHardware() const @@ -264,19 +275,8 @@ void DevicePluginLgSmartTv::networkManagerReplyReady(QNetworkReply *reply) qWarning() << "Could not pair: please check the key and retry"; emit pairingFinished(pairingTransactionId, DeviceManager::DeviceSetupStatusFailure); } else { - qWarning() << "Paired successfully"; - // now unpair the device, because setupdevice will try that again - QString urlString = "http://" + hostAddress().toString() + ":" + QString::number(port()) + "/udap/api/pairing"; - - QNetworkRequest request; - request.setUrl(QUrl(urlString)); - request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/xml; charset=utf-8")); - request.setHeader(QNetworkRequest::UserAgentHeader,QVariant("UDAP/2.0 guh")); - request.setRawHeader("Connection", "Close"); - - QByteArray data = "byebye8080"; - - m_finishingPairingReplay = m_manager->post(request,data); + qDebug() << "Paired tv successfully"; + emit pairingFinished(pairingTransactionId, DeviceManager::DeviceSetupStatusSuccess); } reply->deleteLater(); }