mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
drop pornography with requests
Actually it has been introduced as temporary solution but I totally forgot about it
This commit is contained in:
parent
15abe54290
commit
354fd3cd0c
@ -26,6 +26,7 @@
|
|||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QUrlQuery>
|
||||||
|
|
||||||
#include <qreplytimeout/qreplytimeout.h>
|
#include <qreplytimeout/qreplytimeout.h>
|
||||||
|
|
||||||
@ -56,8 +57,8 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
|
|||||||
|
|
||||||
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
||||||
// in the destructor
|
// in the destructor
|
||||||
manager = new QNetworkAccessManager(nullptr);
|
m_manager = new QNetworkAccessManager(nullptr);
|
||||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
|
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(quotesReplyReceived(QNetworkReply *)));
|
SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,10 +67,10 @@ ExtQuotes::~ExtQuotes()
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
disconnect(manager, SIGNAL(finished(QNetworkReply *)), this,
|
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(quotesReplyReceived(QNetworkReply *)));
|
SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||||
|
|
||||||
manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +135,16 @@ void ExtQuotes::readConfiguration()
|
|||||||
setApiVersion(AWEQAPI);
|
setApiVersion(AWEQAPI);
|
||||||
writeConfiguration();
|
writeConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// init query
|
||||||
|
m_url = QUrl(YAHOO_QUOTES_URL);
|
||||||
|
QUrlQuery params;
|
||||||
|
params.addQueryItem(QString("format"), QString("json"));
|
||||||
|
params.addQueryItem(QString("env"),
|
||||||
|
QString("store://datatables.org/alltableswithkeys"));
|
||||||
|
params.addQueryItem(QString("q"),
|
||||||
|
QString(YAHOO_QUOTES_QUERY).arg(m_ticker));
|
||||||
|
m_url.setQuery(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,7 +156,7 @@ QVariantHash ExtQuotes::run()
|
|||||||
if (times == 1) {
|
if (times == 1) {
|
||||||
qCInfo(LOG_LIB) << "Send request";
|
qCInfo(LOG_LIB) << "Send request";
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
|
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,12 +282,3 @@ get quotes for the instrument. Refer to <a href=\"http://finance.yahoo.com/\">\
|
|||||||
ui->checkBox_active->setText(i18n("Active"));
|
ui->checkBox_active->setText(i18n("Active"));
|
||||||
ui->label_interval->setText(i18n("Interval"));
|
ui->label_interval->setText(i18n("Interval"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString ExtQuotes::url() const
|
|
||||||
{
|
|
||||||
QString apiUrl = QString(YAHOO_QUOTES_URL).arg(m_ticker);
|
|
||||||
qCInfo(LOG_LIB) << "API url" << apiUrl;
|
|
||||||
|
|
||||||
return apiUrl;
|
|
||||||
}
|
|
||||||
|
@ -22,11 +22,9 @@
|
|||||||
|
|
||||||
#include "abstractextitem.h"
|
#include "abstractextitem.h"
|
||||||
|
|
||||||
#define YAHOO_QUOTES_URL \
|
#define YAHOO_QUOTES_URL "https://query.yahooapis.com/v1/public/yql"
|
||||||
"https://query.yahooapis.com/v1/public/yql?q=select * from " \
|
#define YAHOO_QUOTES_QUERY \
|
||||||
"yahoo.finance.quotes where " \
|
"select * from yahoo.finance.quotes where symbol='%1'"
|
||||||
"symbol=\"%1\"&env=store://datatables.org/" \
|
|
||||||
"alltableswithkeys&format=json"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
@ -61,11 +59,11 @@ private slots:
|
|||||||
void quotesReplyReceived(QNetworkReply *reply);
|
void quotesReplyReceived(QNetworkReply *reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *manager;
|
QNetworkAccessManager *m_manager;
|
||||||
|
QUrl m_url;
|
||||||
bool isRunning = false;
|
bool isRunning = false;
|
||||||
Ui::ExtQuotes *ui;
|
Ui::ExtQuotes *ui;
|
||||||
void translate();
|
void translate();
|
||||||
QString url() const;
|
|
||||||
// properties
|
// properties
|
||||||
QString m_ticker = QString("EURUSD=X");
|
QString m_ticker = QString("EURUSD=X");
|
||||||
// values
|
// values
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QUrlQuery>
|
||||||
|
|
||||||
#include <qreplytimeout/qreplytimeout.h>
|
#include <qreplytimeout/qreplytimeout.h>
|
||||||
|
|
||||||
@ -54,8 +55,8 @@ ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
|
|||||||
|
|
||||||
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
||||||
// in the destructor
|
// in the destructor
|
||||||
manager = new QNetworkAccessManager(nullptr);
|
m_manager = new QNetworkAccessManager(nullptr);
|
||||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
|
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(weatherReplyReceived(QNetworkReply *)));
|
SLOT(weatherReplyReceived(QNetworkReply *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,10 +65,10 @@ ExtWeather::~ExtWeather()
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
disconnect(manager, SIGNAL(finished(QNetworkReply *)), this,
|
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(weatherReplyReceived(QNetworkReply *)));
|
SLOT(weatherReplyReceived(QNetworkReply *)));
|
||||||
|
|
||||||
manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ QString ExtWeather::weatherFromInt(const int _id) const
|
|||||||
qCDebug(LOG_LIB) << "Weather ID" << _id;
|
qCDebug(LOG_LIB) << "Weather ID" << _id;
|
||||||
|
|
||||||
QVariantMap map
|
QVariantMap map
|
||||||
= jsonMap[m_image ? QString("image") : QString("text")].toMap();
|
= m_jsonMap[m_image ? QString("image") : QString("text")].toMap();
|
||||||
return map.value(QString::number(_id), map[QString("default")]).toString();
|
return map.value(QString::number(_id), map[QString("default")]).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +194,16 @@ void ExtWeather::readConfiguration()
|
|||||||
setApiVersion(AWEWAPI);
|
setApiVersion(AWEWAPI);
|
||||||
writeConfiguration();
|
writeConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// init query
|
||||||
|
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(m_city, m_country));
|
||||||
|
m_url.setQuery(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -216,9 +227,9 @@ void ExtWeather::readJsonMap()
|
|||||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
jsonMap = jsonDoc.toVariant().toMap();
|
m_jsonMap = jsonDoc.toVariant().toMap();
|
||||||
|
|
||||||
qCInfo(LOG_LIB) << "Weather map" << jsonMap;
|
qCInfo(LOG_LIB) << "Weather map" << m_jsonMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -230,7 +241,7 @@ 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 = manager->get(QNetworkRequest(QUrl(url())));
|
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,13 +385,3 @@ void ExtWeather::translate()
|
|||||||
ui->checkBox_active->setText(i18n("Active"));
|
ui->checkBox_active->setText(i18n("Active"));
|
||||||
ui->label_interval->setText(i18n("Interval"));
|
ui->label_interval->setText(i18n("Interval"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString ExtWeather::url() const
|
|
||||||
{
|
|
||||||
|
|
||||||
QString apiUrl = QString(YAHOO_WEATHER_URL).arg(m_city).arg(m_country);
|
|
||||||
qCInfo(LOG_LIB) << "API url" << apiUrl;
|
|
||||||
|
|
||||||
return apiUrl;
|
|
||||||
}
|
|
||||||
|
@ -22,10 +22,10 @@
|
|||||||
|
|
||||||
#include "abstractextitem.h"
|
#include "abstractextitem.h"
|
||||||
|
|
||||||
#define YAHOO_WEATHER_URL \
|
#define YAHOO_WEATHER_URL "https://query.yahooapis.com/v1/public/yql"
|
||||||
"https://query.yahooapis.com/v1/public/yql?format=json&env=store://" \
|
#define YAHOO_WEATHER_QUERY \
|
||||||
"datatables.org/alltableswithkeys&q=select * from weather.forecast where " \
|
"select * from weather.forecast where u='c' and woeid in (select woeid " \
|
||||||
"u='c' and woeid in (select woeid from geo.places(1) where text='%1, %2')"
|
"from geo.places(1) where text='%1, %2')"
|
||||||
|
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
@ -71,17 +71,17 @@ private slots:
|
|||||||
void weatherReplyReceived(QNetworkReply *reply);
|
void weatherReplyReceived(QNetworkReply *reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *manager;
|
QNetworkAccessManager *m_manager;
|
||||||
|
QUrl m_url;
|
||||||
bool isRunning = false;
|
bool isRunning = false;
|
||||||
Ui::ExtWeather *ui;
|
Ui::ExtWeather *ui;
|
||||||
void translate();
|
void translate();
|
||||||
QString url() const;
|
|
||||||
// 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;
|
||||||
int m_ts = 0;
|
int m_ts = 0;
|
||||||
QVariantMap jsonMap = QVariantMap();
|
QVariantMap m_jsonMap = QVariantMap();
|
||||||
// values
|
// values
|
||||||
int times = 0;
|
int times = 0;
|
||||||
QVariantHash values;
|
QVariantHash values;
|
||||||
|
Loading…
Reference in New Issue
Block a user