From e7a726733b45edad9b23a3a362114b26b2cd5416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Mon, 14 Apr 2014 00:02:30 +0200 Subject: [PATCH] search emit discovered devices --- .../devicepluginopenweathermap.cpp | 21 ++++++++++++++++++- .../devicepluginopenweathermap.h | 1 + .../openweathermap/openweathermap.cpp | 16 +++++++++----- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.cpp b/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.cpp index ebd01b51..3736630d 100644 --- a/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.cpp +++ b/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.cpp @@ -151,10 +151,11 @@ VendorId openweathermapVendorId = VendorId("bf1e96f0-9650-4e7c-a56c-916d54d18e7a"); - +DeviceClassId deviceClassId = DeviceClassId("985195aa-17ad-4530-88a4-cdd753d747d7"); DevicePluginOpenweathermap::DevicePluginOpenweathermap() { m_openweaher = new OpenWeatherMap(this); + connect(m_openweaher, SIGNAL(searchResultReady(QList)), this, SLOT(searchResultsReady(QList))); } QList DevicePluginOpenweathermap::supportedVendors() const @@ -292,6 +293,10 @@ QList DevicePluginOpenweathermap::supportedDevices() const DeviceManager::DeviceError DevicePluginOpenweathermap::discoverDevices(const DeviceClassId &deviceClassId, const QVariantMap ¶ms) const { qDebug() << "should discover divces for" << deviceClassId << params; + if(params.value("location").toString() == ""){ + m_openweaher->update(); + return DeviceManager::DeviceErrorNoError; + } m_openweaher->search(params.value("location").toString()); return DeviceManager::DeviceErrorNoError; } @@ -315,4 +320,18 @@ void DevicePluginOpenweathermap::guhTimer() { } +void DevicePluginOpenweathermap::searchResultsReady(const QList &cityList) +{ + QList retList; + foreach (QVariantMap elemant, cityList) { + QVariantMap params; + params.insert("location", elemant.value("name")); + params.insert("country", elemant.value("country")); + params.insert("id", elemant.value("id")); + retList.append(DeviceDescriptor(deviceClassId, params)); + } + + emit discoverDevices(deviceClassId,retList); +} + diff --git a/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.h b/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.h index 9a54cf6c..3ac48993 100644 --- a/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.h +++ b/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.h @@ -48,6 +48,7 @@ public: void guhTimer() override; private slots: + void searchResultsReady(const QList &cityList); public slots: diff --git a/plugins/deviceplugins/openweathermap/openweathermap.cpp b/plugins/deviceplugins/openweathermap/openweathermap.cpp index 6585cdab..c5a77a84 100644 --- a/plugins/deviceplugins/openweathermap/openweathermap.cpp +++ b/plugins/deviceplugins/openweathermap/openweathermap.cpp @@ -124,16 +124,22 @@ void OpenWeatherMap::processSearchLocationResponse(QByteArray data) } //qDebug() << jsonDoc.toJson(); + QList cityList; QVariantMap dataMap = jsonDoc.toVariant().toMap(); if(dataMap.contains("list")){ QVariantList list = dataMap.value("list").toList(); foreach (QVariant key, list) { QVariantMap elemant = key.toMap(); - if(elemant.contains("id")){ - m_cityId = elemant.value("id").toString(); - updateWeatherData(); - return; - } + + QVariantMap city; + city.insert("name",elemant.value("name").toString()); + city.insert("country", elemant.value("sys").toMap().value("country").toString()); + city.insert("id",elemant.value("id").toString()); + cityList.append(city); + + m_cityId = elemant.value("id").toString(); + updateWeatherData(); + return; } } }