Return to owm weather provider
Since yahoo support already exists, so I've added new option X-AW-Provider (apiver 3). Added tests for these cases
@ -178,7 +178,7 @@ void AbstractExtItem::setName(const QString _name)
|
|||||||
void AbstractExtItem::setNumber(int _number)
|
void AbstractExtItem::setNumber(int _number)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Number" << _number;
|
qCDebug(LOG_LIB) << "Number" << _number;
|
||||||
if (_number == -1)
|
if (_number == -1) {
|
||||||
_number = []() {
|
_number = []() {
|
||||||
qCWarning(LOG_LIB) << "Number is empty, generate new one";
|
qCWarning(LOG_LIB) << "Number is empty, generate new one";
|
||||||
qsrand(QTime::currentTime().msec());
|
qsrand(QTime::currentTime().msec());
|
||||||
@ -186,6 +186,8 @@ void AbstractExtItem::setNumber(int _number)
|
|||||||
qCInfo(LOG_LIB) << "Generated number is" << n;
|
qCInfo(LOG_LIB) << "Generated number is" << n;
|
||||||
return n;
|
return n;
|
||||||
}();
|
}();
|
||||||
|
writeConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
m_number = _number;
|
m_number = _number;
|
||||||
}
|
}
|
||||||
|
47
sources/awesomewidgets/abstractweatherprovider.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of awesome-widgets *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef ABSTRACTWEATHERPROVIDER_H
|
||||||
|
#define ABSTRACTWEATHERPROVIDER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractWeatherProvider : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int number READ number)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AbstractWeatherProvider(QObject *parent, const int number)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_number(number){};
|
||||||
|
virtual ~AbstractWeatherProvider(){};
|
||||||
|
virtual void initUrl(const QString city, const QString country,
|
||||||
|
const int ts)
|
||||||
|
= 0;
|
||||||
|
virtual QVariantHash parse(const QVariantMap &json) const = 0;
|
||||||
|
virtual QUrl url() const = 0;
|
||||||
|
int number() const { return m_number; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_number;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* ABSTRACTWEATHERPROVIDER_H */
|
@ -1,11 +1,75 @@
|
|||||||
{
|
{
|
||||||
"__url": "https://developer.yahoo.com/weather/documentation.html",
|
"__url-yahoo": "https://developer.yahoo.com/weather/documentation.html",
|
||||||
|
"__url-owm": "http://openweathermap.org/weather-conditions",
|
||||||
|
|
||||||
"image": {
|
"image": {
|
||||||
"__comment": "should be described as html image with full path inside",
|
"__comment": "should be described as html image with full path inside",
|
||||||
|
|
||||||
"default": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3200.gif\">",
|
"default": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3200.gif\">",
|
||||||
|
|
||||||
|
"800": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/01d.png\">",
|
||||||
|
|
||||||
|
"801": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/02d.png\">",
|
||||||
|
|
||||||
|
"802": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/03d.png\">",
|
||||||
|
"803": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/03d.png\">",
|
||||||
|
|
||||||
|
"804": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/04d.png\">",
|
||||||
|
|
||||||
|
"300": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"301": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"302": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"310": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"311": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"312": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"313": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"314": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"321": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"520": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"521": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"522": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"531": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
|
||||||
|
"500": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
"501": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
"502": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
"503": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
"504": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
|
||||||
|
"200": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"201": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"202": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"210": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"211": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"212": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"221": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"230": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"231": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"232": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
|
||||||
|
"511": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"600": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"601": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"602": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"611": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"612": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"615": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"616": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"620": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"621": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"622": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
|
||||||
|
"701": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"711": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"721": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"731": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"741": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"751": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"761": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"762": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"771": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"781": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
|
||||||
"0": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/0.gif\">",
|
"0": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/0.gif\">",
|
||||||
"1": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/1.gif\">",
|
"1": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/1.gif\">",
|
||||||
"2": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/2.gif\">",
|
"2": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/2.gif\">",
|
||||||
@ -59,8 +123,71 @@
|
|||||||
|
|
||||||
"text": {
|
"text": {
|
||||||
"default": "\u2604",
|
"default": "\u2604",
|
||||||
"3200": "\u2604",
|
|
||||||
|
|
||||||
|
"800": "\u2600",
|
||||||
|
|
||||||
|
"801": "\u26C5",
|
||||||
|
|
||||||
|
"802": "\u2601",
|
||||||
|
"803": "\u2601",
|
||||||
|
|
||||||
|
"804": "\u2601",
|
||||||
|
|
||||||
|
"300": "\u2602",
|
||||||
|
"301": "\u2602",
|
||||||
|
"302": "\u2602",
|
||||||
|
"310": "\u2602",
|
||||||
|
"311": "\u2602",
|
||||||
|
"312": "\u2602",
|
||||||
|
"313": "\u2602",
|
||||||
|
"314": "\u2602",
|
||||||
|
"321": "\u2602",
|
||||||
|
"520": "\u2602",
|
||||||
|
"521": "\u2602",
|
||||||
|
"522": "\u2602",
|
||||||
|
"531": "\u2602",
|
||||||
|
|
||||||
|
"500": "\u2614",
|
||||||
|
"501": "\u2614",
|
||||||
|
"502": "\u2614",
|
||||||
|
"503": "\u2614",
|
||||||
|
"504": "\u2614",
|
||||||
|
|
||||||
|
"200": "\u2608",
|
||||||
|
"201": "\u2608",
|
||||||
|
"202": "\u2608",
|
||||||
|
"210": "\u2608",
|
||||||
|
"211": "\u2608",
|
||||||
|
"212": "\u2608",
|
||||||
|
"221": "\u2608",
|
||||||
|
"230": "\u2608",
|
||||||
|
"231": "\u2608",
|
||||||
|
"232": "\u2608",
|
||||||
|
|
||||||
|
"511": "\u2603",
|
||||||
|
"600": "\u2603",
|
||||||
|
"601": "\u2603",
|
||||||
|
"602": "\u2603",
|
||||||
|
"611": "\u2603",
|
||||||
|
"612": "\u2603",
|
||||||
|
"615": "\u2603",
|
||||||
|
"616": "\u2603",
|
||||||
|
"620": "\u2603",
|
||||||
|
"621": "\u2603",
|
||||||
|
"622": "\u2603",
|
||||||
|
|
||||||
|
"701": "\u26C5",
|
||||||
|
"711": "\u26C5",
|
||||||
|
"721": "\u26C5",
|
||||||
|
"731": "\u26C5",
|
||||||
|
"741": "\u26C5",
|
||||||
|
"751": "\u26C5",
|
||||||
|
"761": "\u26C5",
|
||||||
|
"762": "\u26C5",
|
||||||
|
"771": "\u26C5",
|
||||||
|
"781": "\u26C5",
|
||||||
|
|
||||||
|
"3200": "\u2604",
|
||||||
"0": "\u2604",
|
"0": "\u2604",
|
||||||
"1": "\u2604",
|
"1": "\u2604",
|
||||||
"2": "\u2604",
|
"2": "\u2604",
|
||||||
|
@ -37,7 +37,12 @@ class ExtScript : public AbstractExtItem
|
|||||||
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class Redirect { stdout2stderr = 0, nothing = 1, stderr2stdout = 2, swap = 3 };
|
enum class Redirect {
|
||||||
|
stdout2stderr = 0,
|
||||||
|
nothing = 1,
|
||||||
|
stderr2stdout = 2,
|
||||||
|
swap = 3
|
||||||
|
};
|
||||||
|
|
||||||
explicit ExtScript(QWidget *parent, const QString filePath = QString());
|
explicit ExtScript(QWidget *parent, const QString filePath = QString());
|
||||||
virtual ~ExtScript();
|
virtual ~ExtScript();
|
||||||
|
@ -27,11 +27,12 @@
|
|||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QUrlQuery>
|
|
||||||
|
|
||||||
#include <qreplytimeout/qreplytimeout.h>
|
#include <qreplytimeout/qreplytimeout.h>
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
#include "owmweatherprovider.h"
|
||||||
|
#include "yahooweatherprovider.h"
|
||||||
|
|
||||||
|
|
||||||
ExtWeather::ExtWeather(QWidget *parent, const QString filePath)
|
ExtWeather::ExtWeather(QWidget *parent, const QString filePath)
|
||||||
@ -68,6 +69,7 @@ ExtWeather::~ExtWeather()
|
|||||||
SLOT(weatherReplyReceived(QNetworkReply *)));
|
SLOT(weatherReplyReceived(QNetworkReply *)));
|
||||||
|
|
||||||
m_manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
|
delete m_providerObject;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +85,7 @@ ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
|
|||||||
item->setCountry(country());
|
item->setCountry(country());
|
||||||
item->setImage(image());
|
item->setImage(image());
|
||||||
item->setNumber(_number);
|
item->setNumber(_number);
|
||||||
|
item->setProvider(provider());
|
||||||
item->setTs(ts());
|
item->setTs(ts());
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
@ -117,6 +120,28 @@ bool ExtWeather::image() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExtWeather::Provider ExtWeather::provider() const
|
||||||
|
{
|
||||||
|
return m_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString ExtWeather::strProvider() const
|
||||||
|
{
|
||||||
|
QString value;
|
||||||
|
switch (m_provider) {
|
||||||
|
case Provider::OWM:
|
||||||
|
value = QString("OWM");
|
||||||
|
break;
|
||||||
|
case Provider::Yahoo:
|
||||||
|
value = QString("Yahoo");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int ExtWeather::ts() const
|
int ExtWeather::ts() const
|
||||||
{
|
{
|
||||||
return m_ts;
|
return m_ts;
|
||||||
@ -134,7 +159,7 @@ void ExtWeather::setCity(const QString _city)
|
|||||||
qCDebug(LOG_LIB) << "City" << _city;
|
qCDebug(LOG_LIB) << "City" << _city;
|
||||||
|
|
||||||
m_city = _city;
|
m_city = _city;
|
||||||
initUrl();
|
initProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -143,7 +168,7 @@ void ExtWeather::setCountry(const QString _country)
|
|||||||
qCDebug(LOG_LIB) << "Country" << _country;
|
qCDebug(LOG_LIB) << "Country" << _country;
|
||||||
|
|
||||||
m_country = _country;
|
m_country = _country;
|
||||||
initUrl();
|
initProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -155,11 +180,32 @@ void ExtWeather::setImage(const bool _image)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExtWeather::setProvider(const Provider _provider)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Provider" << static_cast<int>(_provider);
|
||||||
|
|
||||||
|
m_provider = _provider;
|
||||||
|
initProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExtWeather::setStrProvider(const QString _provider)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Provider" << _provider;
|
||||||
|
|
||||||
|
if (_provider == QString("Yahoo"))
|
||||||
|
setProvider(Provider::Yahoo);
|
||||||
|
else
|
||||||
|
setProvider(Provider::OWM);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ExtWeather::setTs(const int _ts)
|
void ExtWeather::setTs(const int _ts)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Timestamp" << _ts;
|
qCDebug(LOG_LIB) << "Timestamp" << _ts;
|
||||||
|
|
||||||
m_ts = _ts;
|
m_ts = _ts;
|
||||||
|
initProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -176,16 +222,11 @@ void ExtWeather::readConfiguration()
|
|||||||
// api == 2
|
// api == 2
|
||||||
setImage(settings.value(QString("X-AW-Image"), QVariant(m_image)).toString()
|
setImage(settings.value(QString("X-AW-Image"), QVariant(m_image)).toString()
|
||||||
== QString("true"));
|
== QString("true"));
|
||||||
|
// api == 3
|
||||||
|
setStrProvider(
|
||||||
|
settings.value(QString("X-AW-Provider"), strProvider()).toString());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
// update for current API
|
|
||||||
if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) {
|
|
||||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
|
||||||
<< AWEWAPI;
|
|
||||||
setApiVersion(AWEWAPI);
|
|
||||||
writeConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
bumpApi(AWEWAPI);
|
bumpApi(AWEWAPI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +265,8 @@ QVariantHash ExtWeather::run()
|
|||||||
if (times == 1) {
|
if (times == 1) {
|
||||||
qCInfo(LOG_LIB) << "Send request";
|
qCInfo(LOG_LIB) << "Send request";
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
QNetworkReply *reply
|
||||||
|
= m_manager->get(QNetworkRequest(m_providerObject->url()));
|
||||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,6 +286,7 @@ int ExtWeather::showConfiguration(const QVariant args)
|
|||||||
ui->lineEdit_name->setText(name());
|
ui->lineEdit_name->setText(name());
|
||||||
ui->lineEdit_comment->setText(comment());
|
ui->lineEdit_comment->setText(comment());
|
||||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||||
|
ui->comboBox_provider->setCurrentIndex(static_cast<int>(m_provider));
|
||||||
ui->lineEdit_city->setText(m_city);
|
ui->lineEdit_city->setText(m_city);
|
||||||
ui->lineEdit_country->setText(m_country);
|
ui->lineEdit_country->setText(m_country);
|
||||||
ui->spinBox_timestamp->setValue(m_ts);
|
ui->spinBox_timestamp->setValue(m_ts);
|
||||||
@ -261,6 +304,7 @@ int ExtWeather::showConfiguration(const QVariant args)
|
|||||||
setApiVersion(AWEWAPI);
|
setApiVersion(AWEWAPI);
|
||||||
setCity(ui->lineEdit_city->text());
|
setCity(ui->lineEdit_city->text());
|
||||||
setCountry(ui->lineEdit_country->text());
|
setCountry(ui->lineEdit_country->text());
|
||||||
|
setProvider(static_cast<Provider>(ui->comboBox_provider->currentIndex()));
|
||||||
setTs(ui->spinBox_timestamp->value());
|
setTs(ui->spinBox_timestamp->value());
|
||||||
setImage(ui->checkBox_image->checkState() == Qt::Checked);
|
setImage(ui->checkBox_image->checkState() == Qt::Checked);
|
||||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||||
@ -282,6 +326,7 @@ void ExtWeather::writeConfiguration() const
|
|||||||
settings.setValue(QString("X-AW-City"), m_city);
|
settings.setValue(QString("X-AW-City"), m_city);
|
||||||
settings.setValue(QString("X-AW-Country"), m_country);
|
settings.setValue(QString("X-AW-Country"), m_country);
|
||||||
settings.setValue(QString("X-AW-Image"), m_image);
|
settings.setValue(QString("X-AW-Image"), m_image);
|
||||||
|
settings.setValue(QString("X-AW-Provider"), strProvider());
|
||||||
settings.setValue(QString("X-AW-TS"), m_ts);
|
settings.setValue(QString("X-AW-TS"), m_ts);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
@ -304,69 +349,31 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert to map
|
QVariantHash data = m_providerObject->parse(jsonDoc.toVariant().toMap());
|
||||||
QVariantMap json = jsonDoc.toVariant().toMap()[QString("query")].toMap();
|
if (data.isEmpty())
|
||||||
if (json[QString("count")].toInt() != 1) {
|
|
||||||
qCWarning(LOG_LIB) << "Found data count"
|
|
||||||
<< json[QString("count")].toInt() << "is not 1";
|
|
||||||
return;
|
return;
|
||||||
}
|
values = data;
|
||||||
QVariantMap results
|
values[tag(QString("weather"))]
|
||||||
= json[QString("results")].toMap()[QString("channel")].toMap();
|
= weatherFromInt(values[tag(QString("weatherId"))].toInt());
|
||||||
QVariantMap item = results[QString("item")].toMap();
|
|
||||||
|
|
||||||
if (m_ts == 0) {
|
|
||||||
// current weather
|
|
||||||
int id = item[QString("condition")].toMap()[QString("code")].toInt();
|
|
||||||
values[tag(QString("weatherId"))] = id;
|
|
||||||
values[tag(QString("weather"))] = weatherFromInt(id);
|
|
||||||
values[tag(QString("temperature"))]
|
|
||||||
= item[QString("condition")].toMap()[QString("temp")].toInt();
|
|
||||||
values[tag(QString("timestamp"))]
|
|
||||||
= item[QString("condition")].toMap()[QString("date")].toString();
|
|
||||||
values[tag(QString("humidity"))] = results[QString("atmosphere")]
|
|
||||||
.toMap()[QString("humidity")]
|
|
||||||
.toInt();
|
|
||||||
values[tag(QString("pressure"))]
|
|
||||||
= static_cast<int>(results[QString("atmosphere")]
|
|
||||||
.toMap()[QString("pressure")]
|
|
||||||
.toFloat());
|
|
||||||
} else {
|
|
||||||
// forecast weather
|
|
||||||
QVariantList weatherList = item[QString("forecast")].toList();
|
|
||||||
QVariantMap weatherMap = weatherList.count() < m_ts
|
|
||||||
? weatherList.last().toMap()
|
|
||||||
: weatherList.at(m_ts).toMap();
|
|
||||||
int id = weatherMap[QString("code")].toInt();
|
|
||||||
values[tag(QString("weatherId"))] = id;
|
|
||||||
values[tag(QString("weather"))] = weatherFromInt(id);
|
|
||||||
values[tag(QString("timestamp"))]
|
|
||||||
= weatherMap[QString("date")].toString();
|
|
||||||
// yahoo provides high and low temperatures. Lets calculate average one
|
|
||||||
values[tag(QString("temperature"))]
|
|
||||||
= (weatherMap[QString("high")].toFloat()
|
|
||||||
+ weatherMap[QString("low")].toFloat())
|
|
||||||
/ 2.0;
|
|
||||||
// ... and no forecast data for humidity and pressure
|
|
||||||
values[tag(QString("humidity"))] = 0;
|
|
||||||
values[tag(QString("pressure"))] = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
emit(dataReceived(values));
|
emit(dataReceived(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ExtWeather::initUrl()
|
void ExtWeather::initProvider()
|
||||||
{
|
{
|
||||||
// init query
|
delete m_providerObject;
|
||||||
m_url = QUrl(YAHOO_WEATHER_URL);
|
|
||||||
QUrlQuery params;
|
switch (m_provider) {
|
||||||
params.addQueryItem(QString("format"), QString("json"));
|
case Provider::OWM:
|
||||||
params.addQueryItem(QString("env"),
|
m_providerObject = new OWMWeatherProvider(this, number());
|
||||||
QString("store://datatables.org/alltableswithkeys"));
|
break;
|
||||||
params.addQueryItem(QString("q"),
|
case Provider::Yahoo:
|
||||||
QString(YAHOO_WEATHER_QUERY).arg(m_city, m_country));
|
m_providerObject = new YahooWeatherProvider(this, number());
|
||||||
m_url.setQuery(params);
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_providerObject->initUrl(m_city, m_country, m_ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -375,6 +382,7 @@ void ExtWeather::translate()
|
|||||||
ui->label_name->setText(i18n("Name"));
|
ui->label_name->setText(i18n("Name"));
|
||||||
ui->label_comment->setText(i18n("Comment"));
|
ui->label_comment->setText(i18n("Comment"));
|
||||||
ui->label_number->setText(i18n("Tag"));
|
ui->label_number->setText(i18n("Tag"));
|
||||||
|
ui->label_provider->setText(i18n("Provider"));
|
||||||
ui->label_city->setText(i18n("City"));
|
ui->label_city->setText(i18n("City"));
|
||||||
ui->label_country->setText(i18n("Country"));
|
ui->label_country->setText(i18n("Country"));
|
||||||
ui->label_timestamp->setText(i18n("Timestamp"));
|
ui->label_timestamp->setText(i18n("Timestamp"));
|
||||||
|
@ -22,12 +22,8 @@
|
|||||||
|
|
||||||
#include "abstractextitem.h"
|
#include "abstractextitem.h"
|
||||||
|
|
||||||
#define YAHOO_WEATHER_URL "https://query.yahooapis.com/v1/public/yql"
|
|
||||||
#define YAHOO_WEATHER_QUERY \
|
|
||||||
"select * from weather.forecast where u='c' and woeid in (select woeid " \
|
|
||||||
"from geo.places(1) where text='%1, %2')"
|
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractWeatherProvider;
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class ExtWeather;
|
class ExtWeather;
|
||||||
@ -39,9 +35,13 @@ class ExtWeather : public AbstractExtItem
|
|||||||
Q_PROPERTY(QString city READ city WRITE setCity)
|
Q_PROPERTY(QString city READ city WRITE setCity)
|
||||||
Q_PROPERTY(QString country READ country WRITE setCountry)
|
Q_PROPERTY(QString country READ country WRITE setCountry)
|
||||||
Q_PROPERTY(bool image READ image WRITE setImage)
|
Q_PROPERTY(bool image READ image WRITE setImage)
|
||||||
|
Q_PROPERTY(Provider povider READ provider WRITE setProvider)
|
||||||
|
Q_PROPERTY(QString strPovider READ strProvider WRITE setStrProvider)
|
||||||
Q_PROPERTY(int ts READ ts WRITE setTs)
|
Q_PROPERTY(int ts READ ts WRITE setTs)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum class Provider { OWM = 0, Yahoo = 1 };
|
||||||
|
|
||||||
explicit ExtWeather(QWidget *parent, const QString filePath = QString());
|
explicit ExtWeather(QWidget *parent, const QString filePath = QString());
|
||||||
virtual ~ExtWeather();
|
virtual ~ExtWeather();
|
||||||
ExtWeather *copy(const QString _fileName, const int _number);
|
ExtWeather *copy(const QString _fileName, const int _number);
|
||||||
@ -50,12 +50,16 @@ public:
|
|||||||
QString city() const;
|
QString city() const;
|
||||||
QString country() const;
|
QString country() const;
|
||||||
bool image() const;
|
bool image() const;
|
||||||
|
Provider provider() const;
|
||||||
|
QString strProvider() const;
|
||||||
int ts() const;
|
int ts() const;
|
||||||
QString uniq() const;
|
QString uniq() const;
|
||||||
// set methods
|
// set methods
|
||||||
void setCity(const QString _city = QString("London"));
|
void setCity(const QString _city = QString("London"));
|
||||||
void setCountry(const QString _country = QString("uk"));
|
void setCountry(const QString _country = QString("uk"));
|
||||||
void setImage(const bool _image = false);
|
void setImage(const bool _image = false);
|
||||||
|
void setProvider(const Provider _provider = Provider::OWM);
|
||||||
|
void setStrProvider(const QString _provider = QString("OWM"));
|
||||||
void setTs(const int _ts = 0);
|
void setTs(const int _ts = 0);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@ -70,15 +74,16 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *m_manager = nullptr;
|
QNetworkAccessManager *m_manager = nullptr;
|
||||||
QUrl m_url;
|
AbstractWeatherProvider *m_providerObject = nullptr;
|
||||||
bool isRunning = false;
|
bool isRunning = false;
|
||||||
Ui::ExtWeather *ui = nullptr;
|
Ui::ExtWeather *ui = nullptr;
|
||||||
void initUrl();
|
void initProvider();
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QString m_city = QString("London");
|
QString m_city = QString("London");
|
||||||
QString m_country = QString("uk");
|
QString m_country = QString("uk");
|
||||||
bool m_image = false;
|
bool m_image = false;
|
||||||
|
Provider m_provider = Provider::OWM;
|
||||||
int m_ts = 0;
|
int m_ts = 0;
|
||||||
QVariantMap m_jsonMap = QVariantMap();
|
QVariantMap m_jsonMap = QVariantMap();
|
||||||
// values
|
// values
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>420</width>
|
<width>420</width>
|
||||||
<height>301</height>
|
<height>333</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -81,6 +81,46 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_provider">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_provider">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Provider</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBox_provider">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">OWM</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">Yahoo</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="layout_city">
|
<layout class="QHBoxLayout" name="layout_city">
|
||||||
<item>
|
<item>
|
||||||
|
@ -514,7 +514,8 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
|||||||
setActiveColor(ui->lineEdit_activeColor->text());
|
setActiveColor(ui->lineEdit_activeColor->text());
|
||||||
setInactiveColor(ui->lineEdit_inactiveColor->text());
|
setInactiveColor(ui->lineEdit_inactiveColor->text());
|
||||||
setType(static_cast<Type>(ui->comboBox_type->currentIndex()));
|
setType(static_cast<Type>(ui->comboBox_type->currentIndex()));
|
||||||
setDirection(static_cast<Direction>(ui->comboBox_direction->currentIndex()));
|
setDirection(
|
||||||
|
static_cast<Direction>(ui->comboBox_direction->currentIndex()));
|
||||||
setItemHeight(ui->spinBox_height->value());
|
setItemHeight(ui->spinBox_height->value());
|
||||||
setItemWidth(ui->spinBox_width->value());
|
setItemWidth(ui->spinBox_width->value());
|
||||||
|
|
||||||
|
@ -50,7 +50,13 @@ class GraphicalItem : public AbstractExtItem
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
||||||
enum class Type { Horizontal = 0, Vertical = 1, Circle = 2, Graph = 3, Bars = 4 };
|
enum class Type {
|
||||||
|
Horizontal = 0,
|
||||||
|
Vertical = 1,
|
||||||
|
Circle = 2,
|
||||||
|
Graph = 3,
|
||||||
|
Bars = 4
|
||||||
|
};
|
||||||
|
|
||||||
explicit GraphicalItem(QWidget *parent, const QString filePath = QString());
|
explicit GraphicalItem(QWidget *parent, const QString filePath = QString());
|
||||||
virtual ~GraphicalItem();
|
virtual ~GraphicalItem();
|
||||||
|
112
sources/awesomewidgets/owmweatherprovider.cpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of awesome-widgets *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "owmweatherprovider.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QUrlQuery>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
OWMWeatherProvider::OWMWeatherProvider(QObject *parent, const int number)
|
||||||
|
: AbstractWeatherProvider(parent, number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OWMWeatherProvider::~OWMWeatherProvider()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OWMWeatherProvider::initUrl(const QString city, const QString country,
|
||||||
|
const int ts)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Init query for" << city << country << "with ts" << ts;
|
||||||
|
|
||||||
|
m_ts = ts;
|
||||||
|
|
||||||
|
if (m_ts == 0)
|
||||||
|
m_url = QUrl(OWM_WEATHER_URL);
|
||||||
|
else
|
||||||
|
m_url = QUrl(OWM_FORECAST_URL);
|
||||||
|
QUrlQuery params;
|
||||||
|
params.addQueryItem(QString("q"), QString("%1,%2").arg(city, country));
|
||||||
|
params.addQueryItem(QString("units"), QString("metric"));
|
||||||
|
m_url.setQuery(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash OWMWeatherProvider::parse(const QVariantMap &json) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Parse json" << json;
|
||||||
|
|
||||||
|
if (json[QString("cod")].toInt() != 200) {
|
||||||
|
qCWarning(LOG_LIB) << "Invalid OpenWeatherMap return code"
|
||||||
|
<< json[QString("cod")].toInt();
|
||||||
|
return QVariantHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_ts == 0) {
|
||||||
|
return parseSingleJson(json);
|
||||||
|
} else {
|
||||||
|
QVariantList list = json[QString("list")].toList();
|
||||||
|
return parseSingleJson(list.count() <= m_ts ? list.at(m_ts - 1).toMap()
|
||||||
|
: list.last().toMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QUrl OWMWeatherProvider::url() const
|
||||||
|
{
|
||||||
|
return m_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &json) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Single json data" << json;
|
||||||
|
|
||||||
|
QVariantHash output;
|
||||||
|
|
||||||
|
// weather status
|
||||||
|
QVariantList weather = json[QString("weather")].toList();
|
||||||
|
if (!weather.isEmpty()) {
|
||||||
|
int id = weather.first().toMap()[QString("id")].toInt();
|
||||||
|
output[QString("weatherId%1").arg(number())] = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// main data
|
||||||
|
QVariantMap mainWeather = json[QString("main")].toMap();
|
||||||
|
if (!weather.isEmpty()) {
|
||||||
|
output[QString("humidity%1").arg(number())]
|
||||||
|
= mainWeather[QString("humidity")].toFloat();
|
||||||
|
output[QString("pressure%1").arg(number())]
|
||||||
|
= mainWeather[QString("pressure")].toFloat();
|
||||||
|
output[QString("temperature%1").arg(number())]
|
||||||
|
= mainWeather[QString("temp")].toFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
// timestamp
|
||||||
|
output[QString("timestamp%1").arg(number())]
|
||||||
|
= QDateTime::fromTime_t(json[QString("dt")].toUInt()).toUTC();
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
43
sources/awesomewidgets/owmweatherprovider.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of awesome-widgets *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef OWMWEATHERPROVIDER_H
|
||||||
|
#define OWMWEATHERPROVIDER_H
|
||||||
|
|
||||||
|
#include "abstractweatherprovider.h"
|
||||||
|
|
||||||
|
#define OWM_WEATHER_URL "http://arcanis.me/weather"
|
||||||
|
#define OWM_FORECAST_URL "http://arcanis.me/forecast"
|
||||||
|
|
||||||
|
|
||||||
|
class OWMWeatherProvider : public AbstractWeatherProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit OWMWeatherProvider(QObject *parent, const int number);
|
||||||
|
virtual ~OWMWeatherProvider();
|
||||||
|
void initUrl(const QString city, const QString country, const int);
|
||||||
|
QVariantHash parse(const QVariantMap &json) const;
|
||||||
|
QUrl url() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVariantHash parseSingleJson(const QVariantMap &json) const;
|
||||||
|
int m_ts = 0;
|
||||||
|
QUrl m_url;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* OWMWEATHERPROVIDER_H */
|
BIN
sources/awesomewidgets/weather/01d.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
sources/awesomewidgets/weather/02d.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
sources/awesomewidgets/weather/03d.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sources/awesomewidgets/weather/04d.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sources/awesomewidgets/weather/09d.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
sources/awesomewidgets/weather/10d.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
sources/awesomewidgets/weather/11d.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
sources/awesomewidgets/weather/13d.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
sources/awesomewidgets/weather/50d.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
@ -3,10 +3,11 @@ Comment=London current weather
|
|||||||
Encoding=UTF-8
|
Encoding=UTF-8
|
||||||
Name=London current
|
Name=London current
|
||||||
X-AW-Active=false
|
X-AW-Active=false
|
||||||
X-AW-ApiVersion=2
|
X-AW-ApiVersion=3
|
||||||
X-AW-City=London
|
X-AW-City=London
|
||||||
X-AW-Country=uk
|
X-AW-Country=uk
|
||||||
X-AW-Image=false
|
X-AW-Image=false
|
||||||
X-AW-Interval=3600
|
X-AW-Interval=3600
|
||||||
X-AW-Number=0
|
X-AW-Number=0
|
||||||
|
X-AW-Provider=OWM
|
||||||
X-AW-TS=0
|
X-AW-TS=0
|
||||||
|
126
sources/awesomewidgets/yahooweatherprovider.cpp
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of awesome-widgets *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "yahooweatherprovider.h"
|
||||||
|
|
||||||
|
#include <QUrlQuery>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
YahooWeatherProvider::YahooWeatherProvider(QObject *parent, const int number)
|
||||||
|
: AbstractWeatherProvider(parent, number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
YahooWeatherProvider::~YahooWeatherProvider()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void YahooWeatherProvider::initUrl(const QString city, const QString country,
|
||||||
|
const int ts)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Init query for" << city << country << "with ts" << ts;
|
||||||
|
|
||||||
|
m_ts = ts;
|
||||||
|
|
||||||
|
m_url = QUrl(YAHOO_WEATHER_URL);
|
||||||
|
QUrlQuery params;
|
||||||
|
params.addQueryItem(QString("format"), QString("json"));
|
||||||
|
params.addQueryItem(QString("env"),
|
||||||
|
QString("store://datatables.org/alltableswithkeys"));
|
||||||
|
params.addQueryItem(QString("q"),
|
||||||
|
QString(YAHOO_WEATHER_QUERY).arg(city, country));
|
||||||
|
m_url.setQuery(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash YahooWeatherProvider::parse(const QVariantMap &json) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Parse json" << json;
|
||||||
|
|
||||||
|
QVariantMap jsonMap = json[QString("query")].toMap();
|
||||||
|
if (jsonMap[QString("count")].toInt() != 1) {
|
||||||
|
qCWarning(LOG_LIB) << "Found data count"
|
||||||
|
<< json[QString("count")].toInt() << "is not 1";
|
||||||
|
return QVariantHash();
|
||||||
|
}
|
||||||
|
QVariantMap results
|
||||||
|
= jsonMap[QString("results")].toMap()[QString("channel")].toMap();
|
||||||
|
QVariantMap item = results[QString("item")].toMap();
|
||||||
|
QVariantMap atmosphere = results[QString("atmosphere")].toMap();
|
||||||
|
|
||||||
|
return m_ts == 0 ? parseCurrent(item, atmosphere) : parseForecast(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QUrl YahooWeatherProvider::url() const
|
||||||
|
{
|
||||||
|
return m_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash
|
||||||
|
YahooWeatherProvider::parseCurrent(const QVariantMap &json,
|
||||||
|
const QVariantMap &atmosphere) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Parse current weather from" << json;
|
||||||
|
|
||||||
|
QVariantHash values;
|
||||||
|
int id = json[QString("condition")].toMap()[QString("code")].toInt();
|
||||||
|
values[QString("weatherId%1").arg(number())] = id;
|
||||||
|
values[QString("temperature%1").arg(number())]
|
||||||
|
= json[QString("condition")].toMap()[QString("temp")].toInt();
|
||||||
|
values[QString("timestamp%1").arg(number())]
|
||||||
|
= json[QString("condition")].toMap()[QString("date")].toString();
|
||||||
|
values[QString("humidity%1").arg(number())]
|
||||||
|
= atmosphere[QString("humidity")].toInt();
|
||||||
|
values[QString("pressure%1").arg(number())]
|
||||||
|
= static_cast<int>(atmosphere[QString("pressure")].toFloat());
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash YahooWeatherProvider::parseForecast(const QVariantMap &json) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Parse forecast from" << json;
|
||||||
|
|
||||||
|
QVariantHash values;
|
||||||
|
QVariantList weatherList = json[QString("forecast")].toList();
|
||||||
|
QVariantMap weatherMap = weatherList.count() < m_ts
|
||||||
|
? weatherList.last().toMap()
|
||||||
|
: weatherList.at(m_ts).toMap();
|
||||||
|
int id = weatherMap[QString("code")].toInt();
|
||||||
|
values[QString("weatherId%1").arg(number())] = id;
|
||||||
|
values[QString("timestamp%1").arg(number())]
|
||||||
|
= weatherMap[QString("date")].toString();
|
||||||
|
// yahoo provides high and low temperatures. Lets calculate average one
|
||||||
|
values[QString("temperature%1").arg(number())]
|
||||||
|
= (weatherMap[QString("high")].toFloat()
|
||||||
|
+ weatherMap[QString("low")].toFloat())
|
||||||
|
/ 2.0;
|
||||||
|
// ... and no forecast data for humidity and pressure
|
||||||
|
values[QString("humidity%1").arg(number())] = 0;
|
||||||
|
values[QString("pressure%1").arg(number())] = 0.0;
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
47
sources/awesomewidgets/yahooweatherprovider.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of awesome-widgets *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef YAHOOWEATHERPROVIDER_H
|
||||||
|
#define YAHOOWEATHERPROVIDER_H
|
||||||
|
|
||||||
|
#include "abstractweatherprovider.h"
|
||||||
|
|
||||||
|
#define YAHOO_WEATHER_URL "https://query.yahooapis.com/v1/public/yql"
|
||||||
|
#define YAHOO_WEATHER_QUERY \
|
||||||
|
"select * from weather.forecast where u='c' and woeid in (select woeid " \
|
||||||
|
"from geo.places(1) where text='%1, %2')"
|
||||||
|
|
||||||
|
|
||||||
|
class YahooWeatherProvider : public AbstractWeatherProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit YahooWeatherProvider(QObject *parent, const int number);
|
||||||
|
virtual ~YahooWeatherProvider();
|
||||||
|
void initUrl(const QString city, const QString country, const int);
|
||||||
|
QVariantHash parse(const QVariantMap &json) const;
|
||||||
|
QUrl url() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVariantHash parseCurrent(const QVariantMap &json,
|
||||||
|
const QVariantMap &atmosphere) const;
|
||||||
|
QVariantHash parseForecast(const QVariantMap &json) const;
|
||||||
|
int m_ts = 0;
|
||||||
|
QUrl m_url;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* YAHOOWEATHERPROVIDER_H */
|
@ -30,6 +30,7 @@ void TestExtWeather::initTestCase()
|
|||||||
extWeather->setCity(city);
|
extWeather->setCity(city);
|
||||||
extWeather->setCountry(country);
|
extWeather->setCountry(country);
|
||||||
extWeather->setNumber(0);
|
extWeather->setNumber(0);
|
||||||
|
extWeather->setProvider(ExtWeather::Provider::OWM);
|
||||||
|
|
||||||
extWeather->run();
|
extWeather->run();
|
||||||
}
|
}
|
||||||
@ -47,62 +48,28 @@ void TestExtWeather::test_values()
|
|||||||
QCOMPARE(extWeather->number(), 0);
|
QCOMPARE(extWeather->number(), 0);
|
||||||
QCOMPARE(extWeather->city(), city);
|
QCOMPARE(extWeather->city(), city);
|
||||||
QCOMPARE(extWeather->country(), country);
|
QCOMPARE(extWeather->country(), country);
|
||||||
|
QCOMPARE(extWeather->provider(), ExtWeather::Provider::OWM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestExtWeather::test_run()
|
void TestExtWeather::test_runOWM()
|
||||||
{
|
{
|
||||||
// init spy
|
run();
|
||||||
QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &)));
|
}
|
||||||
QVariantHash firstValue = extWeather->run();
|
|
||||||
|
|
||||||
// check values
|
|
||||||
QVERIFY(spy.wait(5000));
|
void TestExtWeather::test_runYahoo()
|
||||||
QVariantHash arguments = spy.takeFirst().at(0).toHash();
|
{
|
||||||
QEXPECT_FAIL("", "WeatherID should not be 0", Continue);
|
extWeather->setProvider(ExtWeather::Provider::Yahoo);
|
||||||
QCOMPARE(arguments[extWeather->tag(QString("weatherId"))].toInt(), 0);
|
run();
|
||||||
QVERIFY((arguments[extWeather->tag(QString("humidity"))].toInt()
|
extWeather->setProvider(ExtWeather::Provider::OWM);
|
||||||
> humidity.first)
|
|
||||||
&& (arguments[extWeather->tag(QString("humidity"))].toInt()
|
|
||||||
< humidity.second));
|
|
||||||
QEXPECT_FAIL("", "https://yahoo.uservoice.com/forums/207813-us-weather/"
|
|
||||||
"suggestions/14209233-invalid-pressure-calculation",
|
|
||||||
Continue);
|
|
||||||
QVERIFY((arguments[extWeather->tag(QString("pressure"))].toFloat()
|
|
||||||
> pressure.first)
|
|
||||||
&& (arguments[extWeather->tag(QString("pressure"))].toInt()
|
|
||||||
< pressure.second));
|
|
||||||
QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat()
|
|
||||||
> temp.first)
|
|
||||||
&& (arguments[extWeather->tag(QString("temperature"))].toInt()
|
|
||||||
< temp.second));
|
|
||||||
// image should be only one symbol here
|
|
||||||
QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(),
|
|
||||||
1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestExtWeather::test_ts()
|
void TestExtWeather::test_ts()
|
||||||
{
|
{
|
||||||
extWeather->setTs(1);
|
extWeather->setTs(1);
|
||||||
// init spy
|
run();
|
||||||
QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &)));
|
|
||||||
QVariantHash firstValue = extWeather->run();
|
|
||||||
|
|
||||||
// check values
|
|
||||||
QVERIFY(spy.wait(5000));
|
|
||||||
QVariantHash arguments = spy.takeFirst().at(0).toHash();
|
|
||||||
QEXPECT_FAIL("", "WeatherID should not be 0", Continue);
|
|
||||||
QCOMPARE(arguments[extWeather->tag(QString("weatherId"))].toInt(), 0);
|
|
||||||
QCOMPARE(arguments[extWeather->tag(QString("humidity"))].toInt(), 0);
|
|
||||||
QCOMPARE(arguments[extWeather->tag(QString("pressure"))].toFloat(), 0.0f);
|
|
||||||
QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat()
|
|
||||||
> temp.first)
|
|
||||||
&& (arguments[extWeather->tag(QString("temperature"))].toInt()
|
|
||||||
< temp.second));
|
|
||||||
// image should be only one symbol here
|
|
||||||
QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(),
|
|
||||||
1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -131,10 +98,43 @@ void TestExtWeather::test_copy()
|
|||||||
QCOMPARE(newExtWeather->country(), extWeather->country());
|
QCOMPARE(newExtWeather->country(), extWeather->country());
|
||||||
QCOMPARE(newExtWeather->ts(), extWeather->ts());
|
QCOMPARE(newExtWeather->ts(), extWeather->ts());
|
||||||
QCOMPARE(newExtWeather->image(), extWeather->image());
|
QCOMPARE(newExtWeather->image(), extWeather->image());
|
||||||
|
QCOMPARE(newExtWeather->provider(), extWeather->provider());
|
||||||
QCOMPARE(newExtWeather->number(), 1);
|
QCOMPARE(newExtWeather->number(), 1);
|
||||||
|
|
||||||
delete newExtWeather;
|
delete newExtWeather;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestExtWeather::run()
|
||||||
|
{
|
||||||
|
// init spy
|
||||||
|
QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
|
QVariantHash firstValue = extWeather->run();
|
||||||
|
|
||||||
|
// check values
|
||||||
|
QVERIFY(spy.wait(5000));
|
||||||
|
QVariantHash arguments = spy.takeFirst().at(0).toHash();
|
||||||
|
QEXPECT_FAIL("", "WeatherID should not be 0", Continue);
|
||||||
|
QCOMPARE(arguments[extWeather->tag(QString("weatherId"))].toInt(), 0);
|
||||||
|
QVERIFY((arguments[extWeather->tag(QString("humidity"))].toInt()
|
||||||
|
>= humidity.first)
|
||||||
|
&& (arguments[extWeather->tag(QString("humidity"))].toInt()
|
||||||
|
<= humidity.second));
|
||||||
|
QWARN("May fail here for Yahoo! Weather, see "
|
||||||
|
"https://yahoo.uservoice.com/forums/207813-us-weather/suggestions/"
|
||||||
|
"14209233-invalid-pressure-calculation");
|
||||||
|
QVERIFY((arguments[extWeather->tag(QString("pressure"))].toFloat()
|
||||||
|
> pressure.first)
|
||||||
|
&& (arguments[extWeather->tag(QString("pressure"))].toInt()
|
||||||
|
< pressure.second));
|
||||||
|
QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat()
|
||||||
|
> temp.first)
|
||||||
|
&& (arguments[extWeather->tag(QString("temperature"))].toInt()
|
||||||
|
< temp.second));
|
||||||
|
// image should be only one symbol here
|
||||||
|
QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(),
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(TestExtWeather);
|
QTEST_MAIN(TestExtWeather);
|
||||||
|
@ -34,12 +34,14 @@ private slots:
|
|||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
// test
|
// test
|
||||||
void test_values();
|
void test_values();
|
||||||
void test_run();
|
void test_runOWM();
|
||||||
|
void test_runYahoo();
|
||||||
void test_ts();
|
void test_ts();
|
||||||
void test_image();
|
void test_image();
|
||||||
void test_copy();
|
void test_copy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void run();
|
||||||
ExtWeather *extWeather = nullptr;
|
ExtWeather *extWeather = nullptr;
|
||||||
QString city = QString("London");
|
QString city = QString("London");
|
||||||
QString country = QString("uk");
|
QString country = QString("uk");
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
"qnetworkreply-network-reply-timeout-helper"
|
"qnetworkreply-network-reply-timeout-helper"
|
||||||
#define SPECIAL_THANKS \
|
#define SPECIAL_THANKS \
|
||||||
"Yahoo! Finance,https://finance.yahoo.com/;Yahoo! " \
|
"Yahoo! Finance,https://finance.yahoo.com/;Yahoo! " \
|
||||||
"Weather,https://weather.yahoo.com/;JetBrains,https://www.jetbrains.com/"
|
"Weather,https://weather.yahoo.com/;JetBrains,https://www.jetbrains.com/" \
|
||||||
|
";OpenWeatherMap,http://openweathermap.org/"
|
||||||
#define CHANGELOG "@PROJECT_CHANGELOG@"
|
#define CHANGELOG "@PROJECT_CHANGELOG@"
|
||||||
|
|
||||||
// configuraion
|
// configuraion
|
||||||
@ -32,7 +33,7 @@
|
|||||||
// extupgrade api version
|
// extupgrade api version
|
||||||
#define AWEUAPI 3
|
#define AWEUAPI 3
|
||||||
// extweather api version
|
// extweather api version
|
||||||
#define AWEWAPI 2
|
#define AWEWAPI 3
|
||||||
// formatter api version
|
// formatter api version
|
||||||
#define AWEFAPI 1
|
#define AWEFAPI 1
|
||||||
// network requests timeout, ms
|
// network requests timeout, ms
|
||||||
|