mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-12 21:35:49 +00:00
Replace yahoo finance to stooq (#131)
Old code is dropped to separated provider
This commit is contained in:
@ -57,8 +57,7 @@ void AbstractExtItem::bumpApi(const int _newVer)
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < _newVer)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< _newVer;
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << _newVer;
|
||||
setApiVersion(_newVer);
|
||||
writeConfiguration();
|
||||
}
|
||||
@ -104,8 +103,7 @@ QString AbstractExtItem::writtableConfig() const
|
||||
QString dir = QFileInfo(path).fileName();
|
||||
|
||||
return QString("%1/awesomewidgets/%2/%3")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation))
|
||||
.arg(dir)
|
||||
.arg(name);
|
||||
}
|
||||
@ -202,8 +200,7 @@ void AbstractExtItem::setCron(const QString &_cron)
|
||||
qCDebug(LOG_LIB) << "Cron string" << _cron;
|
||||
// deinit module first
|
||||
if (m_scheduler) {
|
||||
disconnect(m_scheduler, SIGNAL(activated()), this,
|
||||
SIGNAL(requestDataUpdate()));
|
||||
disconnect(m_scheduler, SIGNAL(activated()), this, SIGNAL(requestDataUpdate()));
|
||||
delete m_scheduler;
|
||||
}
|
||||
|
||||
@ -214,8 +211,7 @@ void AbstractExtItem::setCron(const QString &_cron)
|
||||
// init scheduler
|
||||
m_scheduler = new QCronScheduler(this);
|
||||
m_scheduler->parse(cron());
|
||||
connect(m_scheduler, SIGNAL(activated()), this,
|
||||
SIGNAL(requestDataUpdate()));
|
||||
connect(m_scheduler, SIGNAL(activated()), this, SIGNAL(requestDataUpdate()));
|
||||
}
|
||||
|
||||
|
||||
@ -276,8 +272,7 @@ void AbstractExtItem::deinitSocket()
|
||||
m_socket->close();
|
||||
m_socket->removeServer(socket());
|
||||
delete m_socket;
|
||||
disconnect(m_socket, SIGNAL(newConnection()), this,
|
||||
SLOT(newConnectionReceived()));
|
||||
disconnect(m_socket, SIGNAL(newConnection()), this, SLOT(newConnectionReceived()));
|
||||
}
|
||||
|
||||
|
||||
@ -289,8 +284,7 @@ void AbstractExtItem::initSocket()
|
||||
m_socket = new QLocalServer(this);
|
||||
bool listening = m_socket->listen(socket());
|
||||
qCInfo(LOG_LIB) << "Server listening on" << socket() << listening;
|
||||
connect(m_socket, SIGNAL(newConnection()), this,
|
||||
SLOT(newConnectionReceived()));
|
||||
connect(m_socket, SIGNAL(newConnection()), this, SLOT(newConnectionReceived()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,12 +40,10 @@ class AbstractExtItem : public QDialog
|
||||
Q_PROPERTY(QString uniq READ uniq)
|
||||
|
||||
public:
|
||||
explicit AbstractExtItem(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit AbstractExtItem(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~AbstractExtItem();
|
||||
virtual void bumpApi(const int _newVer);
|
||||
virtual AbstractExtItem *copy(const QString &_fileName, const int _number)
|
||||
= 0;
|
||||
virtual AbstractExtItem *copy(const QString &_fileName, const int _number) = 0;
|
||||
virtual void copyDefaults(AbstractExtItem *_other) const;
|
||||
virtual void startTimer();
|
||||
QString writtableConfig() const;
|
||||
|
@ -25,8 +25,7 @@
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *_parent,
|
||||
const QString &_type)
|
||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *_parent, const QString &_type)
|
||||
: QDialog(_parent)
|
||||
, ui(new Ui::AbstractExtItemAggregator)
|
||||
, m_type(_type)
|
||||
@ -34,21 +33,18 @@ AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *_parent,
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
// create directory at $HOME
|
||||
QString localDir = QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(type());
|
||||
QString localDir
|
||||
= QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation))
|
||||
.arg(type());
|
||||
QDir localDirectory;
|
||||
if (localDirectory.mkpath(localDir))
|
||||
qCInfo(LOG_LIB) << "Created directory" << localDir;
|
||||
|
||||
ui->setupUi(this);
|
||||
copyButton
|
||||
= ui->buttonBox->addButton(i18n("Copy"), QDialogButtonBox::ActionRole);
|
||||
createButton = ui->buttonBox->addButton(i18n("Create"),
|
||||
QDialogButtonBox::ActionRole);
|
||||
deleteButton = ui->buttonBox->addButton(i18n("Remove"),
|
||||
QDialogButtonBox::ActionRole);
|
||||
copyButton = ui->buttonBox->addButton(i18n("Copy"), QDialogButtonBox::ActionRole);
|
||||
createButton = ui->buttonBox->addButton(i18n("Create"), QDialogButtonBox::ActionRole);
|
||||
deleteButton = ui->buttonBox->addButton(i18n("Remove"), QDialogButtonBox::ActionRole);
|
||||
|
||||
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton *)), this,
|
||||
SLOT(editItemButtonPressed(QAbstractButton *)));
|
||||
@ -72,8 +68,7 @@ void AbstractExtItemAggregator::copyItem()
|
||||
QString fileName = getName();
|
||||
int number = uniqNumber();
|
||||
QString dir = QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation))
|
||||
.arg(m_type);
|
||||
if ((!source) || (fileName.isEmpty())) {
|
||||
qCWarning(LOG_LIB) << "Nothing to copy";
|
||||
@ -122,9 +117,8 @@ void AbstractExtItemAggregator::editItem()
|
||||
QString AbstractExtItemAggregator::getName()
|
||||
{
|
||||
bool ok;
|
||||
QString name
|
||||
= QInputDialog::getText(this, i18n("Enter file name"),
|
||||
i18n("File name"), QLineEdit::Normal, "", &ok);
|
||||
QString name = QInputDialog::getText(this, i18n("Enter file name"), i18n("File name"),
|
||||
QLineEdit::Normal, "", &ok);
|
||||
if ((!ok) || (name.isEmpty()))
|
||||
return "";
|
||||
if (!name.endsWith(".desktop"))
|
||||
@ -149,8 +143,7 @@ AbstractExtItem *AbstractExtItemAggregator::itemFromWidget()
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
qCWarning(LOG_LIB) << "Could not find item by name"
|
||||
<< widgetItem->text();
|
||||
qCWarning(LOG_LIB) << "Could not find item by name" << widgetItem->text();
|
||||
|
||||
return found;
|
||||
}
|
||||
@ -193,10 +186,9 @@ QVariant AbstractExtItemAggregator::configArgs() const
|
||||
|
||||
QStringList AbstractExtItemAggregator::directories() const
|
||||
{
|
||||
auto dirs
|
||||
= QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/%1").arg(type()),
|
||||
QStandardPaths::LocateDirectory);
|
||||
auto dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/%1").arg(type()),
|
||||
QStandardPaths::LocateDirectory);
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
@ -47,10 +47,10 @@ public:
|
||||
{
|
||||
QString fileName = getName();
|
||||
int number = uniqNumber();
|
||||
QString dir = QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(m_type);
|
||||
QString dir
|
||||
= QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation))
|
||||
.arg(m_type);
|
||||
if (fileName.isEmpty()) {
|
||||
qCWarning(LOG_LIB) << "Nothing to create";
|
||||
return;
|
||||
|
45
sources/awesomewidgets/abstractquotesprovider.h
Normal file
45
sources/awesomewidgets/abstractquotesprovider.h
Normal file
@ -0,0 +1,45 @@
|
||||
/***************************************************************************
|
||||
* 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 ABSTRACTQUOTESPROVIDER_H
|
||||
#define ABSTRACTQUOTESPROVIDER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
|
||||
class AbstractQuotesProvider : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AbstractQuotesProvider(QObject *_parent)
|
||||
: QObject(_parent){};
|
||||
virtual ~AbstractQuotesProvider(){};
|
||||
virtual void initUrl(const QString &_asset) = 0;
|
||||
virtual QVariantHash parse(const QByteArray &_source, const QVariantHash &_oldValues) const = 0;
|
||||
QString tag(const QString &_type) const
|
||||
{
|
||||
return static_cast<AbstractExtItem *>(parent())->tag(_type);
|
||||
};
|
||||
virtual QUrl url() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* ABSTRACTQUOTESPROVIDER_H */
|
@ -21,26 +21,24 @@
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
|
||||
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){};
|
||||
explicit AbstractWeatherProvider(QObject *_parent)
|
||||
: QObject(_parent){};
|
||||
virtual ~AbstractWeatherProvider(){};
|
||||
virtual void initUrl(const QString &_city, const QString &_country,
|
||||
const int _ts)
|
||||
= 0;
|
||||
virtual void initUrl(const QString &_city, const QString &_country, const int _ts) = 0;
|
||||
virtual QVariantHash parse(const QVariantMap &_json) const = 0;
|
||||
QString tag(const QString &_type) const
|
||||
{
|
||||
return static_cast<AbstractExtItem *>(parent())->tag(_type);
|
||||
};
|
||||
virtual QUrl url() const = 0;
|
||||
int number() const { return m_number; };
|
||||
|
||||
private:
|
||||
int m_number;
|
||||
};
|
||||
|
||||
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWAbstractFormatter::AWAbstractFormatter(QWidget *_parent,
|
||||
const QString &_filePath)
|
||||
AWAbstractFormatter::AWAbstractFormatter(QWidget *_parent, const QString &_filePath)
|
||||
: AbstractExtItem(_parent, _filePath)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
@ -108,8 +107,7 @@ void AWAbstractFormatter::setStrType(const QString &_type)
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractFormatter::setType(
|
||||
const AWAbstractFormatter::FormatterClass _type)
|
||||
void AWAbstractFormatter::setType(const AWAbstractFormatter::FormatterClass _type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Type" << static_cast<int>(_type);
|
||||
|
||||
|
@ -28,18 +28,9 @@ class AWAbstractFormatter : public AbstractExtItem
|
||||
Q_PROPERTY(QString strType READ strType WRITE setStrType)
|
||||
|
||||
public:
|
||||
enum class FormatterClass {
|
||||
DateTime,
|
||||
Float,
|
||||
List,
|
||||
Script,
|
||||
String,
|
||||
NoFormat,
|
||||
Json
|
||||
};
|
||||
enum class FormatterClass { DateTime, Float, List, Script, String, NoFormat, Json };
|
||||
|
||||
explicit AWAbstractFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit AWAbstractFormatter(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~AWAbstractFormatter();
|
||||
virtual QString convert(const QVariant &_value) const = 0;
|
||||
void copyDefaults(AbstractExtItem *_other) const;
|
||||
|
@ -27,8 +27,7 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWDateTimeFormatter::AWDateTimeFormatter(QWidget *_parent,
|
||||
const QString &_filePath)
|
||||
AWDateTimeFormatter::AWDateTimeFormatter(QWidget *_parent, const QString &_filePath)
|
||||
: AWAbstractFormatter(_parent, _filePath)
|
||||
, ui(new Ui::AWDateTimeFormatter)
|
||||
{
|
||||
@ -57,8 +56,7 @@ QString AWDateTimeFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
@ -110,8 +108,7 @@ void AWDateTimeFormatter::readConfiguration()
|
||||
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setFormat(settings.value("X-AW-Format", format()).toString());
|
||||
setTranslateString(
|
||||
settings.value("X-AW-Translate", translateString()).toBool());
|
||||
setTranslateString(settings.value("X-AW-Translate", translateString()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AW_FORMATTER_API);
|
||||
@ -126,8 +123,7 @@ int AWDateTimeFormatter::showConfiguration(const QVariant &_args)
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText("DateTime");
|
||||
ui->lineEdit_format->setText(format());
|
||||
ui->checkBox_translate->setCheckState(translateString() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_translate->setCheckState(translateString() ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
|
@ -32,12 +32,10 @@ class AWDateTimeFormatter : public AWAbstractFormatter
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString format READ format WRITE setFormat)
|
||||
Q_PROPERTY(
|
||||
bool translateString READ translateString WRITE setTranslateString)
|
||||
Q_PROPERTY(bool translateString READ translateString WRITE setTranslateString)
|
||||
|
||||
public:
|
||||
explicit AWDateTimeFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit AWDateTimeFormatter(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~AWDateTimeFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWDateTimeFormatter *copy(const QString &_fileName, const int _number);
|
||||
|
@ -51,9 +51,8 @@ QString AWFloatFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
QString output
|
||||
= QString("%1").arg(_value.toDouble() * multiplier() + summand(),
|
||||
count(), format(), precision(), fillChar());
|
||||
QString output = QString("%1").arg(_value.toDouble() * multiplier() + summand(), count(),
|
||||
format(), precision(), fillChar());
|
||||
if (forceWidth())
|
||||
output = output.left(count());
|
||||
|
||||
@ -61,13 +60,11 @@ QString AWFloatFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWFloatFormatter *AWFloatFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
AWFloatFormatter *AWFloatFormatter::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWFloatFormatter *item
|
||||
= new AWFloatFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWFloatFormatter *item = new AWFloatFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setCount(count());
|
||||
item->setFormat(format());
|
||||
@ -152,8 +149,8 @@ void AWFloatFormatter::setFormat(char _format)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set format" << _format;
|
||||
// http://doc.qt.io/qt-5/qstring.html#argument-formats
|
||||
if ((_format != 'e') && (_format != 'E') && (_format != 'f')
|
||||
&& (_format != 'g') && (_format != 'G')) {
|
||||
if ((_format != 'e') && (_format != 'E') && (_format != 'f') && (_format != 'g')
|
||||
&& (_format != 'G')) {
|
||||
qCWarning(LOG_LIB) << "Invalid format" << _format;
|
||||
_format = 'f';
|
||||
}
|
||||
@ -196,10 +193,7 @@ void AWFloatFormatter::readConfiguration()
|
||||
setCount(settings.value("X-AW-Width", count()).toInt());
|
||||
setFillChar(settings.value("X-AW-FillChar", fillChar()).toString().at(0));
|
||||
setForceWidth(settings.value("X-AW-ForceWidth", forceWidth()).toBool());
|
||||
setFormat(settings.value("X-AW-Format", QString(format()))
|
||||
.toString()
|
||||
.at(0)
|
||||
.toLatin1());
|
||||
setFormat(settings.value("X-AW-Format", QString(format())).toString().at(0).toLatin1());
|
||||
setMultiplier(settings.value("X-AW-Multiplier", multiplier()).toDouble());
|
||||
setPrecision(settings.value("X-AW-Precision", precision()).toInt());
|
||||
setSummand(settings.value("X-AW-Summand", summand()).toDouble());
|
||||
@ -216,13 +210,11 @@ int AWFloatFormatter::showConfiguration(const QVariant &_args)
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText("Float");
|
||||
ui->comboBox_format->setCurrentIndex(
|
||||
ui->comboBox_format->findText(QString(format())));
|
||||
ui->comboBox_format->setCurrentIndex(ui->comboBox_format->findText(QString(format())));
|
||||
ui->spinBox_precision->setValue(precision());
|
||||
ui->spinBox_width->setValue(count());
|
||||
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->doubleSpinBox_multiplier->setValue(multiplier());
|
||||
ui->doubleSpinBox_summand->setValue(summand());
|
||||
|
||||
|
@ -38,8 +38,7 @@ class AWFloatFormatter : public AWAbstractFormatter
|
||||
Q_PROPERTY(double summand READ summand WRITE setSummand)
|
||||
|
||||
public:
|
||||
explicit AWFloatFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit AWFloatFormatter(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~AWFloatFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWFloatFormatter *copy(const QString &_fileName, const int _number);
|
||||
|
@ -53,10 +53,9 @@ QString AWJsonFormatter::convert(const QVariant &_value) const
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
// check if _value is string and parse first if required
|
||||
QJsonDocument json
|
||||
= _value.type() == QVariant::String
|
||||
? QJsonDocument::fromJson(_value.toString().toUtf8())
|
||||
: QJsonDocument::fromVariant(_value);
|
||||
QJsonDocument json = _value.type() == QVariant::String
|
||||
? QJsonDocument::fromJson(_value.toString().toUtf8())
|
||||
: QJsonDocument::fromVariant(_value);
|
||||
QVariant converted = json.toVariant();
|
||||
for (auto &element : m_splittedPath)
|
||||
converted = getFromJson(converted, element);
|
||||
@ -65,13 +64,11 @@ QString AWJsonFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWJsonFormatter *AWJsonFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
AWJsonFormatter *AWJsonFormatter::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWJsonFormatter *item
|
||||
= new AWJsonFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWJsonFormatter *item = new AWJsonFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
item->setPath(path());
|
||||
@ -147,8 +144,7 @@ void AWJsonFormatter::writeConfiguration() const
|
||||
}
|
||||
|
||||
|
||||
QVariant AWJsonFormatter::getFromJson(const QVariant &_value,
|
||||
const QVariant &_element) const
|
||||
QVariant AWJsonFormatter::getFromJson(const QVariant &_value, const QVariant &_element) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for element" << _element << "in" << _value;
|
||||
|
||||
@ -163,8 +159,7 @@ QVariant AWJsonFormatter::getFromJson(const QVariant &_value,
|
||||
}
|
||||
|
||||
|
||||
QVariant AWJsonFormatter::getFromList(const QVariant &_value,
|
||||
const int _index) const
|
||||
QVariant AWJsonFormatter::getFromList(const QVariant &_value, const int _index) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for index" << _index << "in" << _value;
|
||||
|
||||
@ -172,8 +167,7 @@ QVariant AWJsonFormatter::getFromList(const QVariant &_value,
|
||||
}
|
||||
|
||||
|
||||
QVariant AWJsonFormatter::getFromMap(const QVariant &_value,
|
||||
const QString &_key) const
|
||||
QVariant AWJsonFormatter::getFromMap(const QVariant &_value, const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for key" << _key << "in" << _value;
|
||||
|
||||
|
@ -32,8 +32,7 @@ class AWJsonFormatter : public AWAbstractFormatter
|
||||
Q_PROPERTY(QString path READ path WRITE setPath)
|
||||
|
||||
public:
|
||||
explicit AWJsonFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit AWJsonFormatter(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~AWJsonFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWJsonFormatter *copy(const QString &_fileName, const int _number);
|
||||
@ -48,8 +47,7 @@ public slots:
|
||||
|
||||
private:
|
||||
Ui::AWJsonFormatter *ui = nullptr;
|
||||
QVariant getFromJson(const QVariant &_value,
|
||||
const QVariant &_element) const;
|
||||
QVariant getFromJson(const QVariant &_value, const QVariant &_element) const;
|
||||
QVariant getFromList(const QVariant &_value, const int _index) const;
|
||||
QVariant getFromMap(const QVariant &_value, const QString &_key) const;
|
||||
void initPath();
|
||||
|
@ -59,13 +59,11 @@ QString AWListFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWListFormatter *AWListFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
AWListFormatter *AWListFormatter::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWListFormatter *item
|
||||
= new AWListFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWListFormatter *item = new AWListFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setFilter(filter());
|
||||
item->setSeparator(separator());
|
||||
@ -144,8 +142,7 @@ int AWListFormatter::showConfiguration(const QVariant &_args)
|
||||
ui->label_typeValue->setText("List");
|
||||
ui->lineEdit_filter->setText(filter());
|
||||
ui->lineEdit_separator->setText(separator());
|
||||
ui->checkBox_sorted->setCheckState(isSorted() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_sorted->setCheckState(isSorted() ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
|
@ -34,8 +34,7 @@ class AWListFormatter : public AWAbstractFormatter
|
||||
Q_PROPERTY(bool sorted READ isSorted WRITE setSorted)
|
||||
|
||||
public:
|
||||
explicit AWListFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit AWListFormatter(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~AWListFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWListFormatter *copy(const QString &_fileName, const int _number);
|
||||
|
@ -57,8 +57,7 @@ AWNoFormatter *AWNoFormatter::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWNoFormatter *item
|
||||
= new AWNoFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWNoFormatter *item = new AWNoFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
|
||||
|
@ -31,8 +31,7 @@ class AWNoFormatter : public AWAbstractFormatter
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWNoFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit AWNoFormatter(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~AWNoFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWNoFormatter *copy(const QString &_fileName, const int _number);
|
||||
|
@ -59,9 +59,8 @@ QString AWScriptFormatter::convert(const QVariant &_value) const
|
||||
QJSValue result = fn.call(args);
|
||||
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_LIB) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt() << ":"
|
||||
<< result.toString();
|
||||
qCWarning(LOG_LIB) << "Uncaught exception at line" << result.property("lineNumber").toInt()
|
||||
<< ":" << result.toString();
|
||||
return "";
|
||||
} else {
|
||||
return result.toString();
|
||||
@ -69,13 +68,11 @@ QString AWScriptFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWScriptFormatter *AWScriptFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
AWScriptFormatter *AWScriptFormatter::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWScriptFormatter *item
|
||||
= new AWScriptFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWScriptFormatter *item = new AWScriptFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setAppendCode(appendCode());
|
||||
item->setCode(code());
|
||||
@ -160,10 +157,8 @@ int AWScriptFormatter::showConfiguration(const QVariant &_args)
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText("Script");
|
||||
ui->checkBox_appendCode->setCheckState(appendCode() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_hasReturn->setCheckState(hasReturn() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_appendCode->setCheckState(appendCode() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_hasReturn->setCheckState(hasReturn() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->textEdit_code->setPlainText(code());
|
||||
|
||||
int ret = exec();
|
||||
|
@ -35,8 +35,7 @@ class AWScriptFormatter : public AWAbstractFormatter
|
||||
Q_PROPERTY(QString program READ program)
|
||||
|
||||
public:
|
||||
explicit AWScriptFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit AWScriptFormatter(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~AWScriptFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWScriptFormatter *copy(const QString &_fileName, const int _number);
|
||||
|
@ -59,13 +59,11 @@ QString AWStringFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWStringFormatter *AWStringFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
AWStringFormatter *AWStringFormatter::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWStringFormatter *item
|
||||
= new AWStringFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWStringFormatter *item = new AWStringFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setCount(count());
|
||||
item->setFillChar(fillChar());
|
||||
@ -143,8 +141,7 @@ int AWStringFormatter::showConfiguration(const QVariant &_args)
|
||||
ui->label_typeValue->setText("String");
|
||||
ui->spinBox_width->setValue(count());
|
||||
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
|
@ -34,8 +34,7 @@ class AWStringFormatter : public AWAbstractFormatter
|
||||
Q_PROPERTY(bool forceWidth READ forceWidth WRITE setForceWidth)
|
||||
|
||||
public:
|
||||
explicit AWStringFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit AWStringFormatter(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~AWStringFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWStringFormatter *copy(const QString &_fileName, const int _number);
|
||||
|
@ -139,10 +139,9 @@ private:
|
||||
qCInfo(LOG_LIB) << "Found file" << file << "in" << dir;
|
||||
QString filePath = QString("%1/%2").arg(dir).arg(file);
|
||||
// check if already exists
|
||||
if (std::any_of(items.cbegin(), items.cend(),
|
||||
[&filePath](AbstractExtItem *item) {
|
||||
return (item->fileName() == filePath);
|
||||
}))
|
||||
if (std::any_of(items.cbegin(), items.cend(), [&filePath](AbstractExtItem *item) {
|
||||
return (item->fileName() == filePath);
|
||||
}))
|
||||
continue;
|
||||
items.append(new T(this, filePath));
|
||||
}
|
||||
|
@ -65,13 +65,11 @@ ExtNetworkRequest::~ExtNetworkRequest()
|
||||
}
|
||||
|
||||
|
||||
ExtNetworkRequest *ExtNetworkRequest::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
ExtNetworkRequest *ExtNetworkRequest::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
ExtNetworkRequest *item
|
||||
= new ExtNetworkRequest(static_cast<QWidget *>(parent()), _fileName);
|
||||
ExtNetworkRequest *item = new ExtNetworkRequest(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
item->setStringUrl(stringUrl());
|
||||
@ -133,8 +131,7 @@ int ExtNetworkRequest::showConfiguration(const QVariant &_args)
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_url->setText(stringUrl());
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
@ -174,8 +171,8 @@ void ExtNetworkRequest::writeConfiguration() const
|
||||
void ExtNetworkRequest::networkReplyReceived(QNetworkReply *_reply)
|
||||
{
|
||||
if (_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
|
||||
<< "with message" << _reply->errorString();
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error() << "with message"
|
||||
<< _reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,7 @@ class ExtNetworkRequest : public AbstractExtItem
|
||||
Q_PROPERTY(QString stringUrl READ stringUrl WRITE setStringUrl)
|
||||
|
||||
public:
|
||||
explicit ExtNetworkRequest(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit ExtNetworkRequest(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~ExtNetworkRequest();
|
||||
ExtNetworkRequest *copy(const QString &_fileName, const int _number);
|
||||
// get methods
|
||||
|
@ -21,13 +21,13 @@
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDir>
|
||||
#include <QJsonDocument>
|
||||
#include <QSettings>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include <qreplytimeout/qreplytimeout.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "stooqquotesprovider.h"
|
||||
#include "yahooquotesprovider.h"
|
||||
|
||||
|
||||
ExtQuotes::ExtQuotes(QWidget *_parent, const QString &_filePath)
|
||||
@ -41,15 +41,12 @@ ExtQuotes::ExtQuotes(QWidget *_parent, const QString &_filePath)
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
m_values[tag("ask")] = 0.0;
|
||||
m_values[tag("askchg")] = 0.0;
|
||||
m_values[tag("percaskchg")] = 0.0;
|
||||
m_values[tag("bid")] = 0.0;
|
||||
m_values[tag("bidchg")] = 0.0;
|
||||
m_values[tag("percbidchg")] = 0.0;
|
||||
m_values[tag("price")] = 0.0;
|
||||
m_values[tag("pricechg")] = 0.0;
|
||||
m_values[tag("percpricechg")] = 0.0;
|
||||
m_values[tag("volume")] = 0;
|
||||
m_values[tag("volumechg")] = 0;
|
||||
m_values[tag("percvolumechg")] = 0.0;
|
||||
|
||||
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
||||
// in the destructor
|
||||
@ -78,8 +75,7 @@ ExtQuotes *ExtQuotes::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
ExtQuotes *item
|
||||
= new ExtQuotes(static_cast<QWidget *>(parent()), _fileName);
|
||||
ExtQuotes *item = new ExtQuotes(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
item->setTicker(ticker());
|
||||
@ -105,7 +101,7 @@ void ExtQuotes::setTicker(const QString &_ticker)
|
||||
qCDebug(LOG_LIB) << "Ticker" << _ticker;
|
||||
|
||||
m_ticker = _ticker;
|
||||
initUrl();
|
||||
initProvider();
|
||||
}
|
||||
|
||||
|
||||
@ -141,8 +137,7 @@ int ExtQuotes::showConfiguration(const QVariant &_args)
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_ticker->setText(ticker());
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
@ -182,49 +177,19 @@ void ExtQuotes::writeConfiguration() const
|
||||
void ExtQuotes::quotesReplyReceived(QNetworkReply *_reply)
|
||||
{
|
||||
if (_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
|
||||
<< "with message" << _reply->errorString();
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error() << "with message"
|
||||
<< _reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
m_isRunning = false;
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
|
||||
auto text = _reply->readAll();
|
||||
_reply->deleteLater();
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||
|
||||
QVariantHash data = m_providerObject->parse(text, m_values);
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
}
|
||||
QVariantMap jsonQuotes = jsonDoc.toVariant().toMap()["query"].toMap();
|
||||
jsonQuotes = jsonQuotes["results"].toMap()["quote"].toMap();
|
||||
double value;
|
||||
|
||||
// ask
|
||||
value = jsonQuotes["Ask"].toString().toDouble();
|
||||
m_values[tag("askchg")] = m_values[tag("ask")].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - m_values[tag("ask")].toDouble();
|
||||
m_values[tag("percaskchg")] = 100.0 * m_values[tag("askchg")].toDouble()
|
||||
/ m_values[tag("ask")].toDouble();
|
||||
m_values[tag("ask")] = value;
|
||||
|
||||
// bid
|
||||
value = jsonQuotes["Bid"].toString().toDouble();
|
||||
m_values[tag("bidchg")] = m_values[tag("bid")].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - m_values[tag("bid")].toDouble();
|
||||
m_values[tag("percbidchg")] = 100.0 * m_values[tag("bidchg")].toDouble()
|
||||
/ m_values[tag("bid")].toDouble();
|
||||
m_values[tag("bid")] = value;
|
||||
|
||||
// last trade
|
||||
value = jsonQuotes["LastTradePriceOnly"].toString().toDouble();
|
||||
m_values[tag("pricechg")] = m_values[tag("price")].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - m_values[tag("price")].toDouble();
|
||||
m_values[tag("percpricechg")] = 100.0 * m_values[tag("pricechg")].toDouble()
|
||||
/ m_values[tag("price")].toDouble();
|
||||
m_values[tag("price")] = value;
|
||||
m_values = data;
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
@ -233,20 +198,19 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *_reply)
|
||||
void ExtQuotes::sendRequest()
|
||||
{
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_providerObject->url()));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::initUrl()
|
||||
void ExtQuotes::initProvider()
|
||||
{
|
||||
// init query
|
||||
m_url = QUrl(YAHOO_QUOTES_URL);
|
||||
QUrlQuery params;
|
||||
params.addQueryItem("format", "json");
|
||||
params.addQueryItem("env", "store://datatables.org/alltableswithkeys");
|
||||
params.addQueryItem("q", QString(YAHOO_QUOTES_QUERY).arg(ticker()));
|
||||
m_url.setQuery(params);
|
||||
delete m_providerObject;
|
||||
|
||||
// in the future release it is possible to change provider here
|
||||
m_providerObject = new StooqQuotesProvider(this);
|
||||
|
||||
return m_providerObject->initUrl(ticker());
|
||||
}
|
||||
|
||||
|
||||
@ -256,10 +220,9 @@ void ExtQuotes::translate()
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_number->setText(i18n("Tag"));
|
||||
ui->label->setText(
|
||||
i18n("<html><head/><body><p>Use YAHOO! finance ticker to \
|
||||
get quotes for the instrument. Refer to <a href=\"http://finance.yahoo.com/\">\
|
||||
<span style=\" text-decoration: underline; color:#0057ae;\">http://finance.yahoo.com/\
|
||||
</span></a></p></body></html>"));
|
||||
i18n("<html><head/><body><p>Use Stooq ticker to get quotes for the instrument. Refer to <a "
|
||||
"href=\"https://stooq.com/\"><span style=\" text-decoration: underline; "
|
||||
"color:#0057ae;\">https://stooq.com/</span></a></p></body></html>"));
|
||||
ui->label_ticker->setText(i18n("Ticker"));
|
||||
ui->checkBox_active->setText(i18n("Active"));
|
||||
ui->label_schedule->setText(i18n("Schedule"));
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "abstractextitem.h"
|
||||
|
||||
|
||||
class AbstractQuotesProvider;
|
||||
namespace Ui
|
||||
{
|
||||
class ExtQuotes;
|
||||
@ -34,12 +35,7 @@ class ExtQuotes : public AbstractExtItem
|
||||
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
|
||||
|
||||
public:
|
||||
const char *YAHOO_QUOTES_URL = "https://query.yahooapis.com/v1/public/yql";
|
||||
const char *YAHOO_QUOTES_QUERY
|
||||
= "select * from yahoo.finance.quotes where symbol='%1'";
|
||||
|
||||
explicit ExtQuotes(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit ExtQuotes(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~ExtQuotes();
|
||||
ExtQuotes *copy(const QString &_fileName, const int _number);
|
||||
// get methods
|
||||
@ -59,11 +55,11 @@ private slots:
|
||||
void sendRequest();
|
||||
|
||||
private:
|
||||
AbstractQuotesProvider *m_providerObject = nullptr;
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
QUrl m_url;
|
||||
bool m_isRunning = false;
|
||||
Ui::ExtQuotes *ui = nullptr;
|
||||
void initUrl();
|
||||
void initProvider();
|
||||
void translate();
|
||||
// properties
|
||||
QString m_ticker = "EURUSD=X";
|
||||
|
@ -84,7 +84,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>Use YAHOO! finance ticker to get quotes for the instrument. Refer to <a href="http://finance.yahoo.com/"><span style=" text-decoration: underline; color:#0057ae;">http://finance.yahoo.com/</span></a></p></body></html></string>
|
||||
<string><html><head/><body><p>Use Stooq ticker to get quotes for the instrument. Refer to <a href="https://stooq.com/"><span style=" text-decoration: underline; color:#0057ae;">https://stooq.com/</span></a></p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
|
@ -44,8 +44,7 @@ ExtScript::ExtScript(QWidget *_parent, const QString &_filePath)
|
||||
m_values[tag("custom")] = "";
|
||||
|
||||
m_process = new QProcess(nullptr);
|
||||
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
||||
SLOT(updateValue()));
|
||||
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateValue()));
|
||||
m_process->waitForFinished(0);
|
||||
|
||||
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
|
||||
@ -56,8 +55,7 @@ ExtScript::~ExtScript()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
disconnect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
||||
SLOT(updateValue()));
|
||||
disconnect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateValue()));
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
|
||||
@ -69,8 +67,7 @@ ExtScript *ExtScript::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
ExtScript *item
|
||||
= new ExtScript(static_cast<QWidget *>(parent()), _fileName);
|
||||
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setExecutable(executable());
|
||||
item->setNumber(_number);
|
||||
@ -84,9 +81,9 @@ ExtScript *ExtScript::copy(const QString &_fileName, const int _number)
|
||||
|
||||
QString ExtScript::jsonFiltersFile() const
|
||||
{
|
||||
QString fileName = QStandardPaths::locate(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
"awesomewidgets/scripts/awesomewidgets-extscripts-filters.json");
|
||||
QString fileName
|
||||
= QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
||||
"awesomewidgets/scripts/awesomewidgets-extscripts-filters.json");
|
||||
qCInfo(LOG_LIB) << "Filters file" << fileName;
|
||||
|
||||
return fileName;
|
||||
@ -157,9 +154,8 @@ void ExtScript::setFilters(const QStringList &_filters)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Filters" << _filters;
|
||||
|
||||
std::for_each(
|
||||
_filters.cbegin(), _filters.cend(),
|
||||
[this](const QString &filter) { return updateFilter(filter, true); });
|
||||
std::for_each(_filters.cbegin(), _filters.cend(),
|
||||
[this](const QString &filter) { return updateFilter(filter, true); });
|
||||
}
|
||||
|
||||
|
||||
@ -202,8 +198,7 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||
QVariantMap filter = m_jsonFilters[filt].toMap();
|
||||
if (filter.isEmpty()) {
|
||||
qCWarning(LOG_LIB)
|
||||
<< "Could not find filter" << _value << "in the json";
|
||||
qCWarning(LOG_LIB) << "Could not find filter" << _value << "in the json";
|
||||
continue;
|
||||
}
|
||||
for (auto &f : filter.keys())
|
||||
@ -239,9 +234,8 @@ void ExtScript::readConfiguration()
|
||||
setPrefix(settings.value("X-AW-Prefix", prefix()).toString());
|
||||
setStrRedirect(settings.value("X-AW-Redirect", strRedirect()).toString());
|
||||
// api == 3
|
||||
setFilters(settings.value("X-AW-Filters", filters())
|
||||
.toString()
|
||||
.split(',', QString::SkipEmptyParts));
|
||||
setFilters(
|
||||
settings.value("X-AW-Filters", filters()).toString().split(',', QString::SkipEmptyParts));
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AW_EXTSCRIPT_API);
|
||||
@ -290,19 +284,18 @@ int ExtScript::showConfiguration(const QVariant &_args)
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_command->setText(executable());
|
||||
ui->lineEdit_prefix->setText(prefix());
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(redirect()));
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
// filters
|
||||
ui->checkBox_colorFilter->setCheckState(
|
||||
filters().contains("color") ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_linesFilter->setCheckState(
|
||||
filters().contains("newline") ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_spaceFilter->setCheckState(
|
||||
filters().contains("space") ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_colorFilter->setCheckState(filters().contains("color") ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_linesFilter->setCheckState(filters().contains("newline") ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_spaceFilter->setCheckState(filters().contains("space") ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
@ -319,12 +312,9 @@ int ExtScript::showConfiguration(const QVariant &_args)
|
||||
setSocket(ui->lineEdit_socket->text());
|
||||
setInterval(ui->spinBox_interval->value());
|
||||
// filters
|
||||
updateFilter("color",
|
||||
ui->checkBox_colorFilter->checkState() == Qt::Checked);
|
||||
updateFilter("newline",
|
||||
ui->checkBox_linesFilter->checkState() == Qt::Checked);
|
||||
updateFilter("space",
|
||||
ui->checkBox_spaceFilter->checkState() == Qt::Checked);
|
||||
updateFilter("color", ui->checkBox_colorFilter->checkState() == Qt::Checked);
|
||||
updateFilter("newline", ui->checkBox_linesFilter->checkState() == Qt::Checked);
|
||||
updateFilter("space", ui->checkBox_spaceFilter->checkState() == Qt::Checked);
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
@ -363,13 +353,11 @@ void ExtScript::startProcess()
|
||||
void ExtScript::updateValue()
|
||||
{
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
|
||||
QString qdebug = QTextCodec::codecForMib(106)
|
||||
->toUnicode(m_process->readAllStandardError())
|
||||
.trimmed();
|
||||
QString qdebug
|
||||
= QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardError()).trimmed();
|
||||
qCInfo(LOG_LIB) << "Error" << qdebug;
|
||||
QString qoutput = QTextCodec::codecForMib(106)
|
||||
->toUnicode(m_process->readAllStandardOutput())
|
||||
.trimmed();
|
||||
QString qoutput
|
||||
= QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardOutput()).trimmed();
|
||||
qCInfo(LOG_LIB) << "Output" << qoutput;
|
||||
QString strValue;
|
||||
|
||||
|
@ -37,15 +37,9 @@ class ExtScript : public AbstractExtItem
|
||||
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
||||
|
||||
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 = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit ExtScript(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~ExtScript();
|
||||
ExtScript *copy(const QString &_fileName, const int _number);
|
||||
QString jsonFiltersFile() const;
|
||||
|
@ -63,8 +63,7 @@ ExtUpgrade *ExtUpgrade::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
ExtUpgrade *item
|
||||
= new ExtUpgrade(static_cast<QWidget *>(parent()), _fileName);
|
||||
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setExecutable(executable());
|
||||
item->setFilter(filter());
|
||||
@ -161,8 +160,7 @@ int ExtUpgrade::showConfiguration(const QVariant &_args)
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_command->setText(executable());
|
||||
ui->lineEdit_filter->setText(filter());
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->spinBox_null->setValue(null());
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
@ -218,16 +216,12 @@ void ExtUpgrade::updateValue()
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
|
||||
qCInfo(LOG_LIB) << "Error" << m_process->readAllStandardError();
|
||||
|
||||
QString qoutput = QTextCodec::codecForMib(106)
|
||||
->toUnicode(m_process->readAllStandardOutput())
|
||||
.trimmed();
|
||||
QString qoutput
|
||||
= QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardOutput()).trimmed();
|
||||
m_values[tag("pkgcount")] = [this](QString output) {
|
||||
return filter().isEmpty()
|
||||
? output.split('\n', QString::SkipEmptyParts).count()
|
||||
- null()
|
||||
: output.split('\n', QString::SkipEmptyParts)
|
||||
.filter(QRegExp(filter()))
|
||||
.count();
|
||||
? output.split('\n', QString::SkipEmptyParts).count() - null()
|
||||
: output.split('\n', QString::SkipEmptyParts).filter(QRegExp(filter())).count();
|
||||
}(qoutput);
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
|
@ -36,8 +36,7 @@ class ExtUpgrade : public AbstractExtItem
|
||||
Q_PROPERTY(int null READ null WRITE setNull)
|
||||
|
||||
public:
|
||||
explicit ExtUpgrade(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit ExtUpgrade(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~ExtUpgrade();
|
||||
ExtUpgrade *copy(const QString &_fileName, const int _number);
|
||||
// get methods
|
||||
|
@ -77,8 +77,7 @@ ExtWeather *ExtWeather::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "number" << _number;
|
||||
|
||||
ExtWeather *item
|
||||
= new ExtWeather(static_cast<QWidget *>(parent()), _fileName);
|
||||
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setCity(city());
|
||||
item->setCountry(country());
|
||||
@ -93,9 +92,9 @@ ExtWeather *ExtWeather::copy(const QString &_fileName, const int _number)
|
||||
|
||||
QString ExtWeather::jsonMapFile() const
|
||||
{
|
||||
QString fileName = QStandardPaths::locate(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
"awesomewidgets/weather/awesomewidgets-extweather-ids.json");
|
||||
QString fileName
|
||||
= QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
||||
"awesomewidgets/weather/awesomewidgets-extweather-ids.json");
|
||||
qCInfo(LOG_LIB) << "Map file" << fileName;
|
||||
|
||||
return fileName;
|
||||
@ -283,8 +282,7 @@ int ExtWeather::showConfiguration(const QVariant &_args)
|
||||
ui->lineEdit_country->setText(country());
|
||||
ui->spinBox_timestamp->setValue(ts());
|
||||
ui->checkBox_image->setCheckState(image() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
@ -333,8 +331,7 @@ void ExtWeather::writeConfiguration() const
|
||||
void ExtWeather::sendRequest()
|
||||
{
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply
|
||||
= m_manager->get(QNetworkRequest(m_providerObject->url()));
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_providerObject->url()));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
@ -342,8 +339,8 @@ void ExtWeather::sendRequest()
|
||||
void ExtWeather::weatherReplyReceived(QNetworkReply *_reply)
|
||||
{
|
||||
if (_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
|
||||
<< "with message" << _reply->errorString();
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error() << "with message"
|
||||
<< _reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -360,8 +357,7 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *_reply)
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
m_values = data;
|
||||
m_values[tag("weather")]
|
||||
= weatherFromInt(m_values[tag("weatherId")].toInt());
|
||||
m_values[tag("weather")] = weatherFromInt(m_values[tag("weatherId")].toInt());
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
@ -373,10 +369,10 @@ void ExtWeather::initProvider()
|
||||
|
||||
switch (m_provider) {
|
||||
case Provider::OWM:
|
||||
m_providerObject = new OWMWeatherProvider(this, number());
|
||||
m_providerObject = new OWMWeatherProvider(this);
|
||||
break;
|
||||
case Provider::Yahoo:
|
||||
m_providerObject = new YahooWeatherProvider(this, number());
|
||||
m_providerObject = new YahooWeatherProvider(this);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,7 @@ class ExtWeather : public AbstractExtItem
|
||||
public:
|
||||
enum class Provider { OWM = 0, Yahoo = 1 };
|
||||
|
||||
explicit ExtWeather(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit ExtWeather(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~ExtWeather();
|
||||
ExtWeather *copy(const QString &_fileName, const int _number);
|
||||
QString jsonMapFile() const;
|
||||
@ -76,8 +75,8 @@ private slots:
|
||||
void weatherReplyReceived(QNetworkReply *_reply);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
AbstractWeatherProvider *m_providerObject = nullptr;
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
bool m_isRunning = false;
|
||||
Ui::ExtWeather *ui = nullptr;
|
||||
void initProvider();
|
||||
|
@ -56,14 +56,10 @@ GraphicalItem::GraphicalItem(QWidget *_parent, const QString &_filePath)
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(changeValue(int)));
|
||||
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(changeCountState(int)));
|
||||
connect(ui->toolButton_activeColor, SIGNAL(clicked()), this,
|
||||
SLOT(changeColor()));
|
||||
connect(ui->toolButton_inactiveColor, SIGNAL(clicked()), this,
|
||||
SLOT(changeColor()));
|
||||
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this, SLOT(changeValue(int)));
|
||||
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCountState(int)));
|
||||
connect(ui->toolButton_activeColor, SIGNAL(clicked()), this, SLOT(changeColor()));
|
||||
connect(ui->toolButton_inactiveColor, SIGNAL(clicked()), this, SLOT(changeColor()));
|
||||
}
|
||||
|
||||
|
||||
@ -79,8 +75,7 @@ GraphicalItem *GraphicalItem::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
GraphicalItem *item
|
||||
= new GraphicalItem(static_cast<QWidget *>(parent()), _fileName);
|
||||
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setActiveColor(activeColor());
|
||||
item->setBar(bar());
|
||||
@ -105,8 +100,7 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
|
||||
m_scene->clear();
|
||||
int scale[2] = {1, 1};
|
||||
float converted
|
||||
= m_helper->getPercents(value.toFloat(), minValue(), maxValue());
|
||||
float converted = m_helper->getPercents(value.toFloat(), minValue(), maxValue());
|
||||
|
||||
// paint
|
||||
switch (m_type) {
|
||||
@ -138,13 +132,12 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
}
|
||||
|
||||
// convert
|
||||
QPixmap pixmap
|
||||
= m_view->grab().transformed(QTransform().scale(scale[0], scale[1]));
|
||||
QPixmap pixmap = m_view->grab().transformed(QTransform().scale(scale[0], scale[1]));
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
pixmap.save(&buffer, "PNG");
|
||||
QString url = QString("<img src=\"data:image/png;base64,%1\"/>")
|
||||
.arg(QString(byteArray.toBase64()));
|
||||
QString url
|
||||
= QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
|
||||
|
||||
return url;
|
||||
}
|
||||
@ -153,8 +146,7 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
void GraphicalItem::initScene()
|
||||
{
|
||||
m_view->resize(m_width + 5, m_height + 5);
|
||||
m_helper->setParameters(activeColor(), inactiveColor(), itemWidth(),
|
||||
itemHeight(), count());
|
||||
m_helper->setParameters(activeColor(), inactiveColor(), itemWidth(), itemHeight(), count());
|
||||
}
|
||||
|
||||
|
||||
@ -426,23 +418,18 @@ void GraphicalItem::readConfiguration()
|
||||
setBar(settings.value("X-AW-Value", bar()).toString());
|
||||
setMaxValue(settings.value("X-AW-Max", maxValue()).toFloat());
|
||||
setMinValue(settings.value("X-AW-Min", minValue()).toFloat());
|
||||
setActiveColor(
|
||||
settings.value("X-AW-ActiveColor", activeColor()).toString());
|
||||
setInactiveColor(
|
||||
settings.value("X-AW-InactiveColor", inactiveColor()).toString());
|
||||
setActiveColor(settings.value("X-AW-ActiveColor", activeColor()).toString());
|
||||
setInactiveColor(settings.value("X-AW-InactiveColor", inactiveColor()).toString());
|
||||
setStrType(settings.value("X-AW-Type", strType()).toString());
|
||||
setStrDirection(
|
||||
settings.value("X-AW-Direction", strDirection()).toString());
|
||||
setStrDirection(settings.value("X-AW-Direction", strDirection()).toString());
|
||||
setItemHeight(settings.value("X-AW-Height", itemHeight()).toInt());
|
||||
setItemWidth(settings.value("X-AW-Width", itemWidth()).toInt());
|
||||
// api == 5
|
||||
if (apiVersion() < 5) {
|
||||
QString prefix;
|
||||
prefix = activeColor().startsWith("/") ? QString("file://%1")
|
||||
: QString("color://%1");
|
||||
prefix = activeColor().startsWith("/") ? QString("file://%1") : QString("color://%1");
|
||||
m_activeColor = prefix.arg(activeColor());
|
||||
prefix = inactiveColor().startsWith("/") ? QString("file://%1")
|
||||
: QString("color://%1");
|
||||
prefix = inactiveColor().startsWith("/") ? QString("file://%1") : QString("color://%1");
|
||||
m_inactiveColor = prefix.arg(inactiveColor());
|
||||
}
|
||||
settings.endGroup();
|
||||
@ -487,8 +474,7 @@ int GraphicalItem::showConfiguration(const QVariant &_args)
|
||||
ui->spinBox_width->setValue(itemWidth());
|
||||
|
||||
// update UI
|
||||
emit(ui->comboBox_type->currentIndexChanged(
|
||||
ui->comboBox_type->currentIndex()));
|
||||
emit(ui->comboBox_type->currentIndexChanged(ui->comboBox_type->currentIndex()));
|
||||
emit(ui->checkBox_custom->stateChanged(ui->checkBox_custom->checkState()));
|
||||
|
||||
int ret = exec();
|
||||
@ -499,15 +485,13 @@ int GraphicalItem::showConfiguration(const QVariant &_args)
|
||||
setApiVersion(AW_GRAPHITEM_API);
|
||||
setCount(ui->spinBox_count->value());
|
||||
setCustom(ui->checkBox_custom->isChecked());
|
||||
setBar(m_custom ? ui->lineEdit_customValue->text()
|
||||
: ui->comboBox_value->currentText());
|
||||
setBar(m_custom ? ui->lineEdit_customValue->text() : ui->comboBox_value->currentText());
|
||||
setMaxValue(ui->doubleSpinBox_max->value());
|
||||
setMinValue(ui->doubleSpinBox_min->value());
|
||||
setActiveColor(ui->lineEdit_activeColor->text());
|
||||
setInactiveColor(ui->lineEdit_inactiveColor->text());
|
||||
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());
|
||||
setItemWidth(ui->spinBox_width->value());
|
||||
|
||||
@ -557,8 +541,8 @@ void GraphicalItem::changeColor()
|
||||
QString outputColor;
|
||||
if (state == 0) {
|
||||
QColor color = m_helper->stringToColor(lineEdit->text());
|
||||
QColor newColor = QColorDialog::getColor(
|
||||
color, this, i18n("Select color"), QColorDialog::ShowAlphaChannel);
|
||||
QColor newColor = QColorDialog::getColor(color, this, i18n("Select color"),
|
||||
QColorDialog::ShowAlphaChannel);
|
||||
if (!newColor.isValid())
|
||||
return;
|
||||
qCInfo(LOG_LIB) << "Selected color" << newColor;
|
||||
@ -573,10 +557,10 @@ void GraphicalItem::changeColor()
|
||||
} else if (state == 1) {
|
||||
QString path = lineEdit->text();
|
||||
QString directory = QFileInfo(path).absolutePath();
|
||||
outputColor = QFileDialog::getOpenFileUrl(
|
||||
this, i18n("Select path"), directory,
|
||||
i18n("Images (*.png *.bpm *.jpg);;All files (*.*)"))
|
||||
.toString();
|
||||
outputColor
|
||||
= QFileDialog::getOpenFileUrl(this, i18n("Select path"), directory,
|
||||
i18n("Images (*.png *.bpm *.jpg);;All files (*.*)"))
|
||||
.toString();
|
||||
|
||||
qCInfo(LOG_LIB) << "Selected path" << outputColor;
|
||||
}
|
||||
|
@ -50,16 +50,9 @@ class GraphicalItem : public AbstractExtItem
|
||||
|
||||
public:
|
||||
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 = nullptr,
|
||||
const QString &_filePath = "");
|
||||
explicit GraphicalItem(QWidget *_parent = nullptr, const QString &_filePath = "");
|
||||
virtual ~GraphicalItem();
|
||||
GraphicalItem *copy(const QString &_fileName, const int _number);
|
||||
QString image(const QVariant &value);
|
||||
|
@ -26,8 +26,7 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
GraphicalItemHelper::GraphicalItemHelper(QObject *_parent,
|
||||
QGraphicsScene *_scene)
|
||||
GraphicalItemHelper::GraphicalItemHelper(QObject *_parent, QGraphicsScene *_scene)
|
||||
: QObject(_parent)
|
||||
, m_scene(_scene)
|
||||
{
|
||||
@ -41,14 +40,11 @@ GraphicalItemHelper::~GraphicalItemHelper()
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItemHelper::setParameters(const QString &_active,
|
||||
const QString &_inactive,
|
||||
const int _width, const int _height,
|
||||
const int _count)
|
||||
void GraphicalItemHelper::setParameters(const QString &_active, const QString &_inactive,
|
||||
const int _width, const int _height, const int _count)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Use active color" << _active << ", inactive"
|
||||
<< _inactive << ", width" << _width << ", height"
|
||||
<< _height << ", count" << _count;
|
||||
qCDebug(LOG_LIB) << "Use active color" << _active << ", inactive" << _inactive << ", width"
|
||||
<< _width << ", height" << _height << ", count" << _count;
|
||||
|
||||
// put images to pens if any otherwise set pen colors
|
||||
// Images resize to content here as well
|
||||
@ -67,8 +63,7 @@ void GraphicalItemHelper::setParameters(const QString &_active,
|
||||
if (isColor(_inactive)) {
|
||||
m_inactivePen.setBrush(QBrush(stringToColor(_inactive)));
|
||||
} else {
|
||||
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from"
|
||||
<< _inactive;
|
||||
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << _inactive;
|
||||
QPixmap pixmap = QPixmap(QUrl(_inactive).toLocalFile());
|
||||
if (pixmap.isNull()) {
|
||||
qCWarning(LOG_LIB) << "Invalid pixmap found" << _inactive;
|
||||
@ -93,8 +88,7 @@ void GraphicalItemHelper::paintBars(const float _value)
|
||||
storeValue(_value);
|
||||
|
||||
// default norms
|
||||
float normX
|
||||
= static_cast<float>(m_width) / static_cast<float>(m_values.count());
|
||||
float normX = static_cast<float>(m_width) / static_cast<float>(m_values.count());
|
||||
float normY = static_cast<float>(m_height - 1);
|
||||
// paint graph
|
||||
for (int i = 0; i < m_values.count(); i++) {
|
||||
@ -118,13 +112,11 @@ void GraphicalItemHelper::paintCircle(const float _percent)
|
||||
// Returns the start angle for an ellipse segment in 16ths of a degree
|
||||
|
||||
// inactive
|
||||
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, m_inactivePen,
|
||||
m_inactivePen.brush());
|
||||
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, m_inactivePen, m_inactivePen.brush());
|
||||
circle->setSpanAngle(-(1.0f - _percent) * 360.0f * 16.0f);
|
||||
circle->setStartAngle(90.0f * 16.0f - _percent * 360.0f * 16.0f);
|
||||
// active
|
||||
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, m_activePen,
|
||||
m_activePen.brush());
|
||||
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, m_activePen, m_activePen.brush());
|
||||
circle->setSpanAngle(-_percent * 360.0f * 16.0f);
|
||||
circle->setStartAngle(90 * 16);
|
||||
}
|
||||
@ -140,8 +132,7 @@ void GraphicalItemHelper::paintGraph(const float _value)
|
||||
storeValue(_value);
|
||||
|
||||
// default norms
|
||||
float normX
|
||||
= static_cast<float>(m_width) / static_cast<float>(m_values.count());
|
||||
float normX = static_cast<float>(m_width) / static_cast<float>(m_values.count());
|
||||
float normY = static_cast<float>(m_height - 1);
|
||||
// paint graph
|
||||
for (int i = 0; i < m_values.count() - 1; i++) {
|
||||
@ -162,12 +153,11 @@ void GraphicalItemHelper::paintHorizontal(const float _percent)
|
||||
m_activePen.setWidth(m_height);
|
||||
m_inactivePen.setWidth(m_height);
|
||||
// inactive
|
||||
m_scene->addLine(_percent * m_width + 0.5 * m_height, 0.5 * m_height,
|
||||
m_width + 0.5 * m_height, 0.5 * m_height, m_inactivePen);
|
||||
m_scene->addLine(_percent * m_width + 0.5 * m_height, 0.5 * m_height, m_width + 0.5 * m_height,
|
||||
0.5 * m_height, m_inactivePen);
|
||||
// active
|
||||
m_scene->addLine(-0.5 * m_height, 0.5 * m_height,
|
||||
_percent * m_width - 0.5 * m_height, 0.5 * m_height,
|
||||
m_activePen);
|
||||
m_scene->addLine(-0.5 * m_height, 0.5 * m_height, _percent * m_width - 0.5 * m_height,
|
||||
0.5 * m_height, m_activePen);
|
||||
}
|
||||
|
||||
|
||||
@ -179,16 +169,14 @@ void GraphicalItemHelper::paintVertical(const float _percent)
|
||||
m_inactivePen.setWidth(m_height);
|
||||
// inactive
|
||||
m_scene->addLine(0.5 * m_width, -0.5 * m_width, 0.5 * m_width,
|
||||
(1.0 - _percent) * m_height - 0.5 * m_width,
|
||||
m_inactivePen);
|
||||
(1.0 - _percent) * m_height - 0.5 * m_width, m_inactivePen);
|
||||
// active
|
||||
m_scene->addLine(0.5 * m_width, (1.0 - _percent) * m_height + 0.5 * m_width,
|
||||
0.5 * m_width, m_height + 0.5 * m_width, m_activePen);
|
||||
m_scene->addLine(0.5 * m_width, (1.0 - _percent) * m_height + 0.5 * m_width, 0.5 * m_width,
|
||||
m_height + 0.5 * m_width, m_activePen);
|
||||
}
|
||||
|
||||
|
||||
float GraphicalItemHelper::getPercents(const float _value, const float _min,
|
||||
const float _max)
|
||||
float GraphicalItemHelper::getPercents(const float _value, const float _min, const float _max)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Get percent value from" << _value;
|
||||
// newest Qt crashes here if value is nan
|
||||
|
@ -30,12 +30,11 @@ class GraphicalItemHelper : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GraphicalItemHelper(QObject *_parent = nullptr,
|
||||
QGraphicsScene *_scene = nullptr);
|
||||
explicit GraphicalItemHelper(QObject *_parent = nullptr, QGraphicsScene *_scene = nullptr);
|
||||
virtual ~GraphicalItemHelper();
|
||||
// parameters
|
||||
void setParameters(const QString &_active, const QString &_inactive,
|
||||
const int _width, const int _height, const int _count);
|
||||
void setParameters(const QString &_active, const QString &_inactive, const int _width,
|
||||
const int _height, const int _count);
|
||||
// paint methods
|
||||
void paintBars(const float _value);
|
||||
void paintCircle(const float _percent);
|
||||
|
@ -23,8 +23,8 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
OWMWeatherProvider::OWMWeatherProvider(QObject *_parent, const int _number)
|
||||
: AbstractWeatherProvider(_parent, _number)
|
||||
OWMWeatherProvider::OWMWeatherProvider(QObject *_parent)
|
||||
: AbstractWeatherProvider(_parent)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
@ -36,11 +36,9 @@ OWMWeatherProvider::~OWMWeatherProvider()
|
||||
}
|
||||
|
||||
|
||||
void OWMWeatherProvider::initUrl(const QString &_city, const QString &_country,
|
||||
const int ts)
|
||||
void OWMWeatherProvider::initUrl(const QString &_city, const QString &_country, const int ts)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Init query for" << _city << _country << "with ts"
|
||||
<< ts;
|
||||
qCDebug(LOG_LIB) << "Init query for" << _city << _country << "with ts" << ts;
|
||||
|
||||
m_ts = ts;
|
||||
|
||||
@ -60,8 +58,7 @@ QVariantHash OWMWeatherProvider::parse(const QVariantMap &_json) const
|
||||
qCDebug(LOG_LIB) << "Parse json" << _json;
|
||||
|
||||
if (_json["cod"].toInt() != 200) {
|
||||
qCWarning(LOG_LIB) << "Invalid OpenWeatherMap return code"
|
||||
<< _json["cod"].toInt();
|
||||
qCWarning(LOG_LIB) << "Invalid OpenWeatherMap return code" << _json["cod"].toInt();
|
||||
return QVariantHash();
|
||||
}
|
||||
|
||||
@ -91,23 +88,19 @@ QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &_json) const
|
||||
QVariantList weather = _json["weather"].toList();
|
||||
if (!weather.isEmpty()) {
|
||||
int id = weather.first().toMap()["id"].toInt();
|
||||
output[QString("weatherId%1").arg(number())] = id;
|
||||
output[tag("weatherId")] = id;
|
||||
}
|
||||
|
||||
// main data
|
||||
QVariantMap mainWeather = _json["main"].toMap();
|
||||
if (!weather.isEmpty()) {
|
||||
output[QString("humidity%1").arg(number())]
|
||||
= mainWeather["humidity"].toFloat();
|
||||
output[QString("pressure%1").arg(number())]
|
||||
= mainWeather["pressure"].toFloat();
|
||||
output[QString("temperature%1").arg(number())]
|
||||
= mainWeather["temp"].toFloat();
|
||||
output[tag("humidity")] = mainWeather["humidity"].toFloat();
|
||||
output[tag("pressure")] = mainWeather["pressure"].toFloat();
|
||||
output[tag("temperature")] = mainWeather["temp"].toFloat();
|
||||
}
|
||||
|
||||
// timestamp
|
||||
output[QString("timestamp%1").arg(number())]
|
||||
= QDateTime::fromTime_t(_json["dt"].toUInt()).toUTC();
|
||||
output[tag("timestamp")] = QDateTime::fromTime_t(_json["dt"].toUInt()).toUTC();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
const char *OWM_WEATHER_URL = "https://arcanis.me/weather";
|
||||
const char *OWM_FORECAST_URL = "https://arcanis.me/forecast";
|
||||
|
||||
explicit OWMWeatherProvider(QObject *_parent, const int _number);
|
||||
explicit OWMWeatherProvider(QObject *_parent);
|
||||
virtual ~OWMWeatherProvider();
|
||||
void initUrl(const QString &_city, const QString &_country, const int);
|
||||
QVariantHash parse(const QVariantMap &_json) const;
|
||||
|
@ -76,11 +76,9 @@ void QCronScheduler::expired()
|
||||
}
|
||||
|
||||
|
||||
QList<int> QCronScheduler::parseField(const QString &_value, const int _min,
|
||||
const int _max) const
|
||||
QList<int> QCronScheduler::parseField(const QString &_value, const int _min, const int _max) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Parse field" << _value << "with corner values" << _min
|
||||
<< _max;
|
||||
qCDebug(LOG_LIB) << "Parse field" << _value << "with corner values" << _min << _max;
|
||||
|
||||
QList<int> parsed;
|
||||
auto fields = _value.split(',');
|
||||
@ -89,9 +87,7 @@ QList<int> QCronScheduler::parseField(const QString &_value, const int _min,
|
||||
parsedField.fromRange(field.split('/').first(), _min, _max);
|
||||
if (field.contains('/')) {
|
||||
bool status;
|
||||
parsedField.div = field.split('/', QString::SkipEmptyParts)
|
||||
.at(1)
|
||||
.toInt(&status);
|
||||
parsedField.div = field.split('/', QString::SkipEmptyParts).at(1).toInt(&status);
|
||||
if (!status)
|
||||
parsedField.div = 1;
|
||||
}
|
||||
@ -103,11 +99,9 @@ QList<int> QCronScheduler::parseField(const QString &_value, const int _min,
|
||||
}
|
||||
|
||||
|
||||
void QCronScheduler::QCronField::fromRange(const QString &_range,
|
||||
const int _min, const int _max)
|
||||
void QCronScheduler::QCronField::fromRange(const QString &_range, const int _min, const int _max)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Parse field from range" << _range
|
||||
<< "with corner values" << _min << _max;
|
||||
qCDebug(LOG_LIB) << "Parse field from range" << _range << "with corner values" << _min << _max;
|
||||
|
||||
if (_range == "*") {
|
||||
minValue = _min;
|
||||
|
@ -56,8 +56,7 @@ private slots:
|
||||
private:
|
||||
QCronRunSchedule m_schedule;
|
||||
QTimer *m_timer = nullptr;
|
||||
QList<int> parseField(const QString &_value, const int _min,
|
||||
const int _max) const;
|
||||
QList<int> parseField(const QString &_value, const int _min, const int _max) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@ Name=AAPL.NASDAQ
|
||||
Comment=Apple Inc
|
||||
X-AW-Ticker="AAPL"
|
||||
X-AW-Active=false
|
||||
X-AW-ApiVersion=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Interval=60
|
||||
X-AW-Number=0
|
||||
X-AW-Schedule=
|
||||
|
@ -2,9 +2,9 @@
|
||||
Encoding=UTF-8
|
||||
Name=EUR/RUB
|
||||
Comment=EUR/RUB
|
||||
X-AW-Ticker="EURRUB=X"
|
||||
X-AW-Ticker="EURRUB"
|
||||
X-AW-Active=false
|
||||
X-AW-ApiVersion=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Interval=60
|
||||
X-AW-Number=1
|
||||
X-AW-Schedule=
|
||||
|
@ -2,9 +2,9 @@
|
||||
Encoding=UTF-8
|
||||
Name=EUR/USD
|
||||
Comment=EUR/USD
|
||||
X-AW-Ticker="EURUSD=X"
|
||||
X-AW-Ticker="EURUSD"
|
||||
X-AW-Active=false
|
||||
X-AW-ApiVersion=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Interval=60
|
||||
X-AW-Number=2
|
||||
X-AW-Schedule=
|
||||
|
@ -4,7 +4,7 @@ Name=GOOG.NASDAQ
|
||||
Comment=Google Inc
|
||||
X-AW-Ticker="GOOG"
|
||||
X-AW-Active=false
|
||||
X-AW-ApiVersion=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Interval=60
|
||||
X-AW-Number=3
|
||||
X-AW-Schedule=
|
||||
|
@ -4,7 +4,7 @@ Name=MSFT.NASDAQ
|
||||
Comment=Microsoft Corp
|
||||
X-AW-Ticker="MSFT"
|
||||
X-AW-Active=false
|
||||
X-AW-ApiVersion=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Interval=60
|
||||
X-AW-Number=4
|
||||
X-AW-Schedule=
|
||||
|
@ -2,10 +2,10 @@
|
||||
Encoding=UTF-8
|
||||
Name=RTS
|
||||
Comment=RTS Index
|
||||
X-AW-Ticker="RTS.RS"
|
||||
X-AW-Ticker="^RTS"
|
||||
X-AW-Active=false
|
||||
X-AW-ApiVersion=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Interval=60
|
||||
X-AW-Number=5
|
||||
X-AW-Number=4
|
||||
X-AW-Schedule=
|
||||
X-AW-Socket=
|
||||
|
@ -1,11 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
Name=S&P
|
||||
Comment=S&P 500 Index
|
||||
X-AW-Ticker="^GSPC"
|
||||
X-AW-Active=false
|
||||
X-AW-ApiVersion=4
|
||||
X-AW-Interval=60
|
||||
X-AW-Number=6
|
||||
X-AW-Schedule=
|
||||
X-AW-Socket=
|
@ -2,9 +2,9 @@
|
||||
Encoding=UTF-8
|
||||
Name=USD/RUB
|
||||
Comment=USD/RUB
|
||||
X-AW-Ticker="USDRUB=X"
|
||||
X-AW-Ticker="USDRUB"
|
||||
X-AW-Active=false
|
||||
X-AW-ApiVersion=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Interval=60
|
||||
X-AW-Number=8
|
||||
X-AW-Schedule=
|
||||
|
@ -1,11 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
Name=VIX
|
||||
Comment=Volatility S&P 500
|
||||
X-AW-Ticker="^VIX"
|
||||
X-AW-Active=false
|
||||
X-AW-ApiVersion=4
|
||||
X-AW-Interval=60
|
||||
X-AW-Number=7
|
||||
X-AW-Schedule=
|
||||
X-AW-Socket=
|
88
sources/awesomewidgets/stooqquotesprovider.cpp
Normal file
88
sources/awesomewidgets/stooqquotesprovider.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/***************************************************************************
|
||||
* 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 "stooqquotesprovider.h"
|
||||
|
||||
#include <QTextCodec>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
StooqQuotesProvider::StooqQuotesProvider(QObject *_parent)
|
||||
: AbstractQuotesProvider(_parent)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
StooqQuotesProvider::~StooqQuotesProvider()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void StooqQuotesProvider::initUrl(const QString &_asset)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Init query for" << _asset;
|
||||
|
||||
m_url = QUrl(STOOQ_QUOTES_URL);
|
||||
QUrlQuery params;
|
||||
params.addQueryItem("s", _asset);
|
||||
params.addQueryItem("f", "pv");
|
||||
params.addQueryItem("e", "csv");
|
||||
m_url.setQuery(params);
|
||||
}
|
||||
|
||||
|
||||
QVariantHash StooqQuotesProvider::parse(const QByteArray &_source,
|
||||
const QVariantHash &_oldValues) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Parse csv" << _source;
|
||||
|
||||
QVariantHash values;
|
||||
|
||||
QStringList sourceValues
|
||||
= QTextCodec::codecForMib(106)->toUnicode(_source).trimmed().split(',');
|
||||
if (sourceValues.count() != 2) {
|
||||
qCWarning(LOG_LIB) << "Parse error" << sourceValues;
|
||||
return values;
|
||||
}
|
||||
|
||||
// extract old data
|
||||
auto oldPrice = _oldValues[tag("price")].toDouble();
|
||||
auto oldVolume = _oldValues[tag("volume")].toInt();
|
||||
|
||||
// last trade
|
||||
auto price = sourceValues.at(0).toDouble();
|
||||
values[tag("pricechg")] = oldPrice == 0.0 ? 0.0 : price - oldPrice;
|
||||
values[tag("percpricechg")] = 100.0 * values[tag("pricechg")].toDouble() / price;
|
||||
values[tag("price")] = price;
|
||||
// volume
|
||||
auto volume = sourceValues.at(1).toInt();
|
||||
values[tag("volumechg")] = oldVolume == 0 ? 0 : volume - oldVolume;
|
||||
values[tag("percvolumechg")] = 100.0 * values[tag("volumechg")].toDouble() / volume;
|
||||
values[tag("volume")] = volume;
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
QUrl StooqQuotesProvider::url() const
|
||||
{
|
||||
return m_url;
|
||||
}
|
42
sources/awesomewidgets/stooqquotesprovider.h
Normal file
42
sources/awesomewidgets/stooqquotesprovider.h
Normal file
@ -0,0 +1,42 @@
|
||||
/***************************************************************************
|
||||
* 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 STOOQQUOTESPROVIDER_H
|
||||
#define STOOQQUOTESPROVIDER_H
|
||||
|
||||
#include "abstractquotesprovider.h"
|
||||
|
||||
|
||||
class StooqQuotesProvider : public AbstractQuotesProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
const char *STOOQ_QUOTES_URL = "https://stooq.com/q/l/";
|
||||
|
||||
explicit StooqQuotesProvider(QObject *_parent);
|
||||
virtual ~StooqQuotesProvider();
|
||||
void initUrl(const QString &_asset);
|
||||
QVariantHash parse(const QByteArray &_source, const QVariantHash &_oldValues) const;
|
||||
QUrl url() const;
|
||||
|
||||
private:
|
||||
QUrl m_url;
|
||||
};
|
||||
|
||||
|
||||
#endif /* STOOQQUOTESPROVIDER_H */
|
88
sources/awesomewidgets/yahooquotesprovider.cpp
Normal file
88
sources/awesomewidgets/yahooquotesprovider.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/***************************************************************************
|
||||
* 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 "yahooquotesprovider.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
YahooQuotesProvider::YahooQuotesProvider(QObject *_parent)
|
||||
: AbstractQuotesProvider(_parent)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
YahooQuotesProvider::~YahooQuotesProvider()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void YahooQuotesProvider::initUrl(const QString &_asset)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Init query for" << _asset;
|
||||
|
||||
m_url = QUrl(YAHOO_QUOTES_URL);
|
||||
QUrlQuery params;
|
||||
params.addQueryItem("format", "json");
|
||||
params.addQueryItem("env", "store://datatables.org/alltableswithkeys");
|
||||
params.addQueryItem("q", QString(YAHOO_QUOTES_QUERY).arg(_asset));
|
||||
m_url.setQuery(params);
|
||||
}
|
||||
|
||||
|
||||
QVariantHash YahooQuotesProvider::parse(const QByteArray &_source,
|
||||
const QVariantHash &_oldValues) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Parse json" << _source;
|
||||
|
||||
QVariantHash values;
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(_source, &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||
return values;
|
||||
}
|
||||
QVariantMap jsonQuotes = jsonDoc.toVariant().toMap()["query"].toMap();
|
||||
jsonQuotes = jsonQuotes["results"].toMap()["quote"].toMap();
|
||||
|
||||
// extract old data
|
||||
auto oldPrice = _oldValues[tag("price")].toDouble();
|
||||
|
||||
// last trade
|
||||
auto value = jsonQuotes["LastTradePriceOnly"].toString().toDouble();
|
||||
values[tag("pricechg")] = oldPrice == 0.0 ? 0.0 : value - oldPrice;
|
||||
values[tag("percpricechg")] = 100.0 * values[tag("pricechg")].toDouble() / value;
|
||||
values[tag("price")] = value;
|
||||
// volume
|
||||
values[tag("volume")] = 0;
|
||||
values[tag("volumechg")] = 0;
|
||||
values[tag("percvolumechg")] = 0.0;
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
QUrl YahooQuotesProvider::url() const
|
||||
{
|
||||
return m_url;
|
||||
}
|
43
sources/awesomewidgets/yahooquotesprovider.h
Normal file
43
sources/awesomewidgets/yahooquotesprovider.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 YAHOOQUOTESPROVIDER_H
|
||||
#define YAHOOQUOTESPROVIDER_H
|
||||
|
||||
#include "abstractquotesprovider.h"
|
||||
|
||||
|
||||
class YahooQuotesProvider : public AbstractQuotesProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
const char *YAHOO_QUOTES_URL = "https://query.yahooapis.com/v1/public/yql";
|
||||
const char *YAHOO_QUOTES_QUERY = "select * from yahoo.finance.quotes where symbol='%1'";
|
||||
|
||||
explicit YahooQuotesProvider(QObject *_parent);
|
||||
virtual ~YahooQuotesProvider();
|
||||
void initUrl(const QString &_asset);
|
||||
QVariantHash parse(const QByteArray &_source, const QVariantHash &_oldValues) const;
|
||||
QUrl url() const;
|
||||
|
||||
private:
|
||||
QUrl m_url;
|
||||
};
|
||||
|
||||
|
||||
#endif /* YAHOOQUOTESPROVIDER_H */
|
@ -22,8 +22,8 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
YahooWeatherProvider::YahooWeatherProvider(QObject *_parent, const int _number)
|
||||
: AbstractWeatherProvider(_parent, _number)
|
||||
YahooWeatherProvider::YahooWeatherProvider(QObject *_parent)
|
||||
: AbstractWeatherProvider(_parent)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
@ -35,11 +35,9 @@ YahooWeatherProvider::~YahooWeatherProvider()
|
||||
}
|
||||
|
||||
|
||||
void YahooWeatherProvider::initUrl(const QString &_city,
|
||||
const QString &_country, const int ts)
|
||||
void YahooWeatherProvider::initUrl(const QString &_city, const QString &_country, const int ts)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Init query for" << _city << _country << "with ts"
|
||||
<< ts;
|
||||
qCDebug(LOG_LIB) << "Init query for" << _city << _country << "with ts" << ts;
|
||||
|
||||
m_ts = ts;
|
||||
|
||||
@ -58,8 +56,7 @@ QVariantHash YahooWeatherProvider::parse(const QVariantMap &_json) const
|
||||
|
||||
QVariantMap jsonMap = _json["query"].toMap();
|
||||
if (jsonMap["count"].toInt() != 1) {
|
||||
qCWarning(LOG_LIB) << "Found data count" << _json["count"].toInt()
|
||||
<< "is not 1";
|
||||
qCWarning(LOG_LIB) << "Found data count" << _json["count"].toInt() << "is not 1";
|
||||
return QVariantHash();
|
||||
}
|
||||
QVariantMap results = jsonMap["results"].toMap()["channel"].toMap();
|
||||
@ -76,9 +73,8 @@ QUrl YahooWeatherProvider::url() const
|
||||
}
|
||||
|
||||
|
||||
QVariantHash
|
||||
YahooWeatherProvider::parseCurrent(const QVariantMap &_json,
|
||||
const QVariantMap &_atmosphere) const
|
||||
QVariantHash YahooWeatherProvider::parseCurrent(const QVariantMap &_json,
|
||||
const QVariantMap &_atmosphere) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Parse current weather from" << _json;
|
||||
|
||||
@ -86,14 +82,12 @@ YahooWeatherProvider::parseCurrent(const QVariantMap &_json,
|
||||
|
||||
QVariantHash values;
|
||||
int id = _json["condition"].toMap()["code"].toInt();
|
||||
values[QString("weatherId%1").arg(number())] = id;
|
||||
values[QString("temperature%1").arg(number())] = condition["temp"].toInt();
|
||||
values[QString("timestamp%1").arg(number())] = condition["date"].toString();
|
||||
values[QString("humidity%1").arg(number())]
|
||||
= _atmosphere["humidity"].toInt();
|
||||
values[tag("weatherId")] = id;
|
||||
values[tag("temperature")] = condition["temp"].toInt();
|
||||
values[tag("timestamp")] = condition["date"].toString();
|
||||
values[tag("humidity")] = _atmosphere["humidity"].toInt();
|
||||
// HACK temporary fix of invalid values on Yahoo! side
|
||||
values[QString("pressure%1").arg(number())]
|
||||
= static_cast<int>(_atmosphere["pressure"].toFloat() / 33.863753);
|
||||
values[tag("pressure")] = static_cast<int>(_atmosphere["pressure"].toFloat() / 33.863753);
|
||||
|
||||
return values;
|
||||
}
|
||||
@ -105,19 +99,16 @@ QVariantHash YahooWeatherProvider::parseForecast(const QVariantMap &_json) const
|
||||
|
||||
QVariantHash values;
|
||||
QVariantList weatherList = _json["forecast"].toList();
|
||||
QVariantMap weatherMap = weatherList.count() < m_ts
|
||||
? weatherList.last().toMap()
|
||||
: weatherList.at(m_ts).toMap();
|
||||
QVariantMap weatherMap
|
||||
= weatherList.count() < m_ts ? weatherList.last().toMap() : weatherList.at(m_ts).toMap();
|
||||
int id = weatherMap["code"].toInt();
|
||||
values[QString("weatherId%1").arg(number())] = id;
|
||||
values[QString("timestamp%1").arg(number())]
|
||||
= weatherMap["date"].toString();
|
||||
values[tag("weatherId")] = id;
|
||||
values[tag("timestamp")] = weatherMap["date"].toString();
|
||||
// yahoo provides high and low temperatures. Lets calculate average one
|
||||
values[QString("temperature%1").arg(number())]
|
||||
= (weatherMap["high"].toFloat() + weatherMap["low"].toFloat()) / 2.0;
|
||||
values[tag("temperature")] = (weatherMap["high"].toFloat() + weatherMap["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;
|
||||
values[tag("humidity")] = 0;
|
||||
values[tag("pressure")] = 0.0;
|
||||
|
||||
return values;
|
||||
}
|
||||
|
@ -31,15 +31,14 @@ public:
|
||||
"u='c' and woeid in (select woeid from "
|
||||
"geo.places(1) where text='%1, %2')";
|
||||
|
||||
explicit YahooWeatherProvider(QObject *_parent, const int _number);
|
||||
explicit YahooWeatherProvider(QObject *_parent);
|
||||
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 parseCurrent(const QVariantMap &_json, const QVariantMap &_atmosphere) const;
|
||||
QVariantHash parseForecast(const QVariantMap &_json) const;
|
||||
int m_ts = 0;
|
||||
QUrl m_url;
|
||||
|
Reference in New Issue
Block a user