mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-28 09:27:18 +00:00
refactor: review delete and new operators
This commit is contained in:
parent
397b523180
commit
95d5bb99c0
@ -183,10 +183,8 @@ PlasmoidItem {
|
|||||||
plasmoid.configuration.telemetryId = generateUuid()
|
plasmoid.configuration.telemetryId = generateUuid()
|
||||||
// save telemetry
|
// save telemetry
|
||||||
awTelemetryHandler.init(plasmoid.configuration.telemetryCount,
|
awTelemetryHandler.init(plasmoid.configuration.telemetryCount,
|
||||||
plasmoid.configuration.telemetryRemote,
|
|
||||||
plasmoid.configuration.telemetryId)
|
plasmoid.configuration.telemetryId)
|
||||||
if (awTelemetryHandler.put("awwidgetconfig", plasmoid.configuration.text))
|
awTelemetryHandler.put("awwidgetconfig", plasmoid.configuration.text)
|
||||||
awTelemetryHandler.uploadTelemetry("awwidgetconfig", plasmoid.configuration.text)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// code from http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
// code from http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
||||||
|
@ -58,6 +58,12 @@ AWAbstractPairConfig::~AWAbstractPairConfig()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWAbstractPairConfig::setHelper(std::unique_ptr<AWAbstractPairHelper> _helper)
|
||||||
|
{
|
||||||
|
m_helper = std::move(_helper);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWAbstractPairConfig::showDialog()
|
void AWAbstractPairConfig::showDialog()
|
||||||
{
|
{
|
||||||
// update dialog
|
// update dialog
|
||||||
@ -133,7 +139,7 @@ void AWAbstractPairConfig::execDialog()
|
|||||||
auto ret = exec();
|
auto ret = exec();
|
||||||
QHash<QString, QString> data;
|
QHash<QString, QString> data;
|
||||||
for (auto selector : m_selectors) {
|
for (auto selector : m_selectors) {
|
||||||
QPair<QString, QString> select = selector->current();
|
auto select = selector->current();
|
||||||
if (select.first.isEmpty())
|
if (select.first.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
data[select.first] = select.second;
|
data[select.first] = select.second;
|
||||||
|
@ -35,12 +35,7 @@ class AWAbstractPairConfig : public QDialog
|
|||||||
public:
|
public:
|
||||||
explicit AWAbstractPairConfig(QWidget *_parent = nullptr, bool _hasEdit = false, QStringList _keys = {});
|
explicit AWAbstractPairConfig(QWidget *_parent = nullptr, bool _hasEdit = false, QStringList _keys = {});
|
||||||
~AWAbstractPairConfig() override;
|
~AWAbstractPairConfig() override;
|
||||||
template <class T> void initHelper()
|
void setHelper(std::unique_ptr<AWAbstractPairHelper> _helper);
|
||||||
{
|
|
||||||
|
|
||||||
delete m_helper;
|
|
||||||
m_helper = new T(this);
|
|
||||||
}
|
|
||||||
void showDialog();
|
void showDialog();
|
||||||
// properties
|
// properties
|
||||||
void setEditable(bool _first, bool _second);
|
void setEditable(bool _first, bool _second);
|
||||||
@ -52,7 +47,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QPushButton *m_editButton = nullptr;
|
QPushButton *m_editButton = nullptr;
|
||||||
Ui::AWAbstractPairConfig *ui = nullptr;
|
Ui::AWAbstractPairConfig *ui = nullptr;
|
||||||
AWAbstractPairHelper *m_helper = nullptr;
|
std::unique_ptr<AWAbstractPairHelper> m_helper;
|
||||||
QList<AWAbstractSelector *> m_selectors;
|
QList<AWAbstractSelector *> m_selectors;
|
||||||
// properties
|
// properties
|
||||||
QPair<bool, bool> m_editable = {false, false};
|
QPair<bool, bool> m_editable = {false, false};
|
||||||
|
@ -33,12 +33,17 @@ AWBugReporter::AWBugReporter(QObject *_parent)
|
|||||||
: QObject(_parent)
|
: QObject(_parent)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
m_manager = new QNetworkAccessManager(nullptr);
|
||||||
|
connect(m_manager, &QNetworkAccessManager::finished, this, &AWBugReporter::issueReplyReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AWBugReporter::~AWBugReporter()
|
AWBugReporter::~AWBugReporter()
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
m_manager->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -72,8 +77,6 @@ void AWBugReporter::sendBugReport(const QString &_title, const QString &_body)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Send bug report with title" << _title << "and body" << _body;
|
qCDebug(LOG_AW) << "Send bug report with title" << _title << "and body" << _body;
|
||||||
|
|
||||||
auto manager = new QNetworkAccessManager(nullptr);
|
|
||||||
connect(manager, &QNetworkAccessManager::finished, this, &AWBugReporter::issueReplyReceived);
|
|
||||||
|
|
||||||
auto request = QNetworkRequest(QUrl(BUGTRACKER_API));
|
auto request = QNetworkRequest(QUrl(BUGTRACKER_API));
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
@ -87,7 +90,7 @@ void AWBugReporter::sendBugReport(const QString &_title, const QString &_body)
|
|||||||
auto data = QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
|
auto data = QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
|
||||||
qCInfo(LOG_AW) << "Send request with _body" << data.data() << "and size" << data.size();
|
qCInfo(LOG_AW) << "Send request with _body" << data.data() << "and size" << data.size();
|
||||||
|
|
||||||
manager->post(request, data);
|
m_manager->post(request, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
class QNetworkAccessManager;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
|
||||||
class AWBugReporter : public QObject
|
class AWBugReporter : public QObject
|
||||||
@ -44,4 +45,5 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_lastBugUrl;
|
QString m_lastBugUrl;
|
||||||
|
QNetworkAccessManager *m_manager = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -27,5 +27,5 @@ AWCustomKeysConfig::AWCustomKeysConfig(QWidget *_parent, const QStringList &_key
|
|||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
setEditable(true, false);
|
setEditable(true, false);
|
||||||
initHelper<AWCustomKeysHelper>();
|
setHelper(std::make_unique<AWCustomKeysHelper>());
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,8 @@ AWDataAggregator::~AWDataAggregator()
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
delete m_toolTipScene;
|
m_toolTipView->deleteLater();
|
||||||
|
m_toolTipScene->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,5 +27,5 @@ AWFormatterConfig::AWFormatterConfig(QWidget *_parent, const QStringList &_keys)
|
|||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
setEditable(false, false);
|
setEditable(false, false);
|
||||||
initHelper<AWFormatterHelper>();
|
setHelper(std::make_unique<AWFormatterHelper>());
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#include "awstringformatter.h"
|
#include "awstringformatter.h"
|
||||||
|
|
||||||
|
|
||||||
AWFormatterHelper::AWFormatterHelper(QWidget *_parent)
|
AWFormatterHelper::AWFormatterHelper(QObject *_parent)
|
||||||
: AbstractExtItemAggregator(_parent, "formatters")
|
: AbstractExtItemAggregator(_parent, "formatters")
|
||||||
, AWAbstractPairHelper("awesomewidgets/formatters/formatters.ini", "Formatters")
|
, AWAbstractPairHelper("awesomewidgets/formatters/formatters.ini", "Formatters")
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ class AWFormatterHelper : public AbstractExtItemAggregator, public AWAbstractPai
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWFormatterHelper(QWidget *_parent = nullptr);
|
explicit AWFormatterHelper(QObject *_parent = nullptr);
|
||||||
~AWFormatterHelper() override;
|
~AWFormatterHelper() override;
|
||||||
// read-write methods
|
// read-write methods
|
||||||
void initItems() override;
|
void initItems() override;
|
||||||
|
@ -40,12 +40,12 @@ AWKeyOperations::AWKeyOperations(QObject *_parent)
|
|||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_customKeys = new AWCustomKeysHelper(this);
|
m_customKeys = new AWCustomKeysHelper(this);
|
||||||
m_graphicalItems = new ExtItemAggregator<GraphicalItem>(nullptr, "desktops");
|
m_graphicalItems = new ExtItemAggregator<GraphicalItem>(this, "desktops");
|
||||||
m_extNetRequest = new ExtItemAggregator<ExtNetworkRequest>(nullptr, "requests");
|
m_extNetRequest = new ExtItemAggregator<ExtNetworkRequest>(this, "requests");
|
||||||
m_extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, "quotes");
|
m_extQuotes = new ExtItemAggregator<ExtQuotes>(this, "quotes");
|
||||||
m_extScripts = new ExtItemAggregator<ExtScript>(nullptr, "scripts");
|
m_extScripts = new ExtItemAggregator<ExtScript>(this, "scripts");
|
||||||
m_extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, "upgrade");
|
m_extUpgrade = new ExtItemAggregator<ExtUpgrade>(this, "upgrade");
|
||||||
m_extWeather = new ExtItemAggregator<ExtWeather>(nullptr, "weather");
|
m_extWeather = new ExtItemAggregator<ExtWeather>(this, "weather");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,8 +189,10 @@ void AWKeys::dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors,
|
|||||||
if (!_sensors.contains(data.sensorProperty))
|
if (!_sensors.contains(data.sensorProperty))
|
||||||
continue;
|
continue;
|
||||||
auto sensor = _sensors[data.sensorProperty];
|
auto sensor = _sensors[data.sensorProperty];
|
||||||
std::ignore = QtConcurrent::run(m_threadPool, &AWKeys::setDataBySource, this, data.sensorProperty, sensor,
|
setDataBySource(data.sensorProperty, sensor, data.payload);
|
||||||
data.payload);
|
// std::ignore = QtConcurrent::run(m_threadPool, &AWKeys::setDataBySource, this, data.sensorProperty,
|
||||||
|
// sensor,
|
||||||
|
// data.payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ AWKeysAggregator::AWKeysAggregator(QObject *_parent)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_customFormatters = new AWFormatterHelper(nullptr);
|
m_customFormatters = new AWFormatterHelper(this);
|
||||||
m_mapper = new AWDataEngineMapper(this, m_customFormatters);
|
m_mapper = new AWDataEngineMapper(this, m_customFormatters);
|
||||||
|
|
||||||
// sort time keys
|
// sort time keys
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
#include "awtelemetryhandler.h"
|
#include "awtelemetryhandler.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
@ -65,13 +63,11 @@ QString AWTelemetryHandler::getLast(const QString &_group) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWTelemetryHandler::init(const int _count, const bool _enableRemote, const QString &_clientId)
|
void AWTelemetryHandler::init(const int _count, const QString &_clientId)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Init telemetry with count" << _count << "enable remote" << _enableRemote << "client ID"
|
qCDebug(LOG_AW) << "Init telemetry with count" << _count << "client ID" << _clientId;
|
||||||
<< _clientId;
|
|
||||||
|
|
||||||
m_storeCount = _count;
|
m_storeCount = _count;
|
||||||
m_uploadEnabled = _enableRemote;
|
|
||||||
m_clientId = _clientId;
|
m_clientId = _clientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,59 +108,6 @@ bool AWTelemetryHandler::put(const QString &_group, const QString &_value) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWTelemetryHandler::uploadTelemetry(const QString &_group, const QString &_value)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Upload data with group" << _group << "and value" << _value;
|
|
||||||
if (!m_uploadEnabled) {
|
|
||||||
qCInfo(LOG_AW) << "Upload disabled by configuration";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto manager = new QNetworkAccessManager(nullptr);
|
|
||||||
connect(manager, &QNetworkAccessManager::finished, this, &AWTelemetryHandler::telemetryReplyReceived);
|
|
||||||
|
|
||||||
QUrl url(REMOTE_TELEMETRY_URL);
|
|
||||||
QNetworkRequest request(url);
|
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
||||||
|
|
||||||
// generate payload
|
|
||||||
QVariantMap payload;
|
|
||||||
payload["api"] = AW_TELEMETRY_API;
|
|
||||||
payload["client_id"] = m_clientId;
|
|
||||||
payload["metadata"] = _value;
|
|
||||||
payload["type"] = _group;
|
|
||||||
// convert to QByteArray to send request
|
|
||||||
auto data = QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
|
|
||||||
qCInfo(LOG_AW) << "Send request with body" << data.data() << "and size" << data.size();
|
|
||||||
|
|
||||||
manager->post(request, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWTelemetryHandler::telemetryReplyReceived(QNetworkReply *_reply)
|
|
||||||
{
|
|
||||||
if (_reply->error() != QNetworkReply::NoError) {
|
|
||||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error() << "with message" << _reply->errorString();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonParseError error{};
|
|
||||||
auto jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
|
|
||||||
if (error.error != QJsonParseError::NoError) {
|
|
||||||
qCWarning(LOG_AW) << "Parse error" << error.errorString();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_reply->deleteLater();
|
|
||||||
|
|
||||||
// convert to map
|
|
||||||
auto response = jsonDoc.toVariant().toMap();
|
|
||||||
auto message = response["message"].toString();
|
|
||||||
qCInfo(LOG_AW) << "Server reply on telemetry" << message;
|
|
||||||
|
|
||||||
return emit(replyReceived(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWTelemetryHandler::getKey(const int _count)
|
QString AWTelemetryHandler::getKey(const int _count)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Get key for keys count" << _count;
|
qCDebug(LOG_AW) << "Get key for keys count" << _count;
|
||||||
|
@ -20,33 +20,21 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
class QNetworkReply;
|
|
||||||
|
|
||||||
class AWTelemetryHandler : public QObject
|
class AWTelemetryHandler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const char *REMOTE_TELEMETRY_URL = "https://arcanis.me/telemetry";
|
|
||||||
|
|
||||||
explicit AWTelemetryHandler(QObject *_parent = nullptr, const QString &_clientId = "");
|
explicit AWTelemetryHandler(QObject *_parent = nullptr, const QString &_clientId = "");
|
||||||
~AWTelemetryHandler() override = default;
|
~AWTelemetryHandler() override = default;
|
||||||
Q_INVOKABLE [[nodiscard]] QStringList get(const QString &_group) const;
|
Q_INVOKABLE [[nodiscard]] QStringList get(const QString &_group) const;
|
||||||
Q_INVOKABLE [[nodiscard]] QString getLast(const QString &_group) const;
|
Q_INVOKABLE [[nodiscard]] QString getLast(const QString &_group) const;
|
||||||
Q_INVOKABLE void init(int _count, bool _enableRemote, const QString &_clientId);
|
Q_INVOKABLE void init(int _count, const QString &_clientId);
|
||||||
Q_INVOKABLE [[nodiscard]] bool put(const QString &_group, const QString &_value) const;
|
Q_INVOKABLE [[nodiscard]] bool put(const QString &_group, const QString &_value) const;
|
||||||
Q_INVOKABLE void uploadTelemetry(const QString &_group, const QString &_value);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void replyReceived(const QString &_message);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void telemetryReplyReceived(QNetworkReply *_reply);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QString getKey(int _count);
|
static QString getKey(int _count);
|
||||||
QString m_clientId;
|
QString m_clientId;
|
||||||
QString m_localFile;
|
QString m_localFile;
|
||||||
int m_storeCount = 0;
|
int m_storeCount = 0;
|
||||||
bool m_uploadEnabled = false;
|
|
||||||
};
|
};
|
||||||
|
@ -45,7 +45,7 @@ void AWUpdateHelper::checkUpdates(const bool _showAnyway)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Show anyway" << _showAnyway;
|
qCDebug(LOG_AW) << "Show anyway" << _showAnyway;
|
||||||
|
|
||||||
// showAnyway options requires to show message if no updates found on direct
|
// showAnyway options required to show message if no updates found on direct
|
||||||
// request. In case of automatic check no message will be shown
|
// request. In case of automatic check no message will be shown
|
||||||
auto manager = new QNetworkAccessManager(nullptr);
|
auto manager = new QNetworkAccessManager(nullptr);
|
||||||
connect(manager, &QNetworkAccessManager::finished,
|
connect(manager, &QNetworkAccessManager::finished,
|
||||||
@ -126,6 +126,7 @@ void AWUpdateHelper::versionReplyReceived(QNetworkReply *_reply, const bool _sho
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_reply->deleteLater();
|
_reply->deleteLater();
|
||||||
|
_reply->manager()->deleteLater(); // remember to delete manager too
|
||||||
|
|
||||||
// convert to map
|
// convert to map
|
||||||
auto firstRelease = jsonDoc.toVariant().toList().first().toMap();
|
auto firstRelease = jsonDoc.toVariant().toList().first().toMap();
|
||||||
|
@ -36,6 +36,12 @@ AbstractExtItem::AbstractExtItem(QObject *_parent, const QString &_filePath)
|
|||||||
qCDebug(LOG_LIB) << "Desktop name" << _filePath;
|
qCDebug(LOG_LIB) << "Desktop name" << _filePath;
|
||||||
|
|
||||||
m_name = m_filePath;
|
m_name = m_filePath;
|
||||||
|
|
||||||
|
m_scheduler = new QCronScheduler(this);
|
||||||
|
connect(m_scheduler, &QCronScheduler::activated, this, &AbstractExtItem::requestDataUpdate);
|
||||||
|
|
||||||
|
m_socket = new QLocalServer(this);
|
||||||
|
connect(m_socket, &QLocalServer::newConnection, this, &AbstractExtItem::requestDataUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,11 +49,11 @@ AbstractExtItem::~AbstractExtItem()
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
if (m_socket) {
|
m_scheduler->stop();
|
||||||
m_socket->close();
|
m_scheduler->deleteLater();
|
||||||
QLocalServer::removeServer(socket());
|
|
||||||
m_socket->deleteLater();
|
m_socket->close();
|
||||||
}
|
m_socket->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -203,20 +209,14 @@ void AbstractExtItem::setComment(const QString &_comment)
|
|||||||
void AbstractExtItem::setCron(const QString &_cron)
|
void AbstractExtItem::setCron(const QString &_cron)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Cron string" << _cron;
|
qCDebug(LOG_LIB) << "Cron string" << _cron;
|
||||||
// deinit module first
|
|
||||||
if (m_scheduler) {
|
|
||||||
disconnect(m_scheduler, &QCronScheduler::activated, this, &AbstractExtItem::requestDataUpdate);
|
|
||||||
delete m_scheduler;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_cron = _cron;
|
m_cron = _cron;
|
||||||
if (cron().isEmpty())
|
if (m_cron.isEmpty()) { // disable cron timer
|
||||||
return;
|
m_scheduler->stop();
|
||||||
|
} else {
|
||||||
// init scheduler
|
m_scheduler->parse(m_cron);
|
||||||
m_scheduler = new QCronScheduler(this);
|
m_scheduler->start();
|
||||||
m_scheduler->parse(cron());
|
}
|
||||||
connect(m_scheduler, &QCronScheduler::activated, this, &AbstractExtItem::requestDataUpdate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -260,34 +260,18 @@ void AbstractExtItem::setNumber(int _number)
|
|||||||
void AbstractExtItem::setSocket(const QString &_socket)
|
void AbstractExtItem::setSocket(const QString &_socket)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Socket" << _socket;
|
qCDebug(LOG_LIB) << "Socket" << _socket;
|
||||||
// remove old socket first
|
|
||||||
deinitSocket();
|
|
||||||
|
|
||||||
m_socketFile = _socket;
|
m_socketFile = _socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AbstractExtItem::deinitSocket()
|
|
||||||
{
|
|
||||||
if (!m_socket)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_socket->close();
|
|
||||||
QLocalServer::removeServer(socket());
|
|
||||||
disconnect(m_socket, &QLocalServer::newConnection, this, &AbstractExtItem::requestDataUpdate);
|
|
||||||
delete m_socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AbstractExtItem::initSocket()
|
void AbstractExtItem::initSocket()
|
||||||
{
|
{
|
||||||
// remove old socket first
|
// reload local socket
|
||||||
deinitSocket();
|
m_socket->close();
|
||||||
|
|
||||||
m_socket = new QLocalServer(this);
|
auto listening = m_socket->listen(m_socketFile);
|
||||||
auto listening = m_socket->listen(socket());
|
qCInfo(LOG_LIB) << "Server listening on" << m_socketFile << listening;
|
||||||
qCInfo(LOG_LIB) << "Server listening on" << socket() << listening;
|
|
||||||
connect(m_socket, &QLocalServer::newConnection, this, &AbstractExtItem::requestDataUpdate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ signals:
|
|||||||
void requestDataUpdate();
|
void requestDataUpdate();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void deinitSocket();
|
|
||||||
virtual void initSocket();
|
virtual void initSocket();
|
||||||
virtual void readConfiguration();
|
virtual void readConfiguration();
|
||||||
virtual QVariantHash run() = 0;
|
virtual QVariantHash run() = 0;
|
||||||
|
@ -17,25 +17,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QVariant>
|
||||||
#include "abstractextitem.h"
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractQuotesProvider : public QObject
|
class AbstractQuotesProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AbstractQuotesProvider(QObject *_parent)
|
virtual ~AbstractQuotesProvider() = default;
|
||||||
: QObject(_parent){};
|
|
||||||
~AbstractQuotesProvider() override = default;
|
|
||||||
virtual void initUrl(const QString &_asset) = 0;
|
virtual void initUrl(const QString &_asset) = 0;
|
||||||
[[nodiscard]] virtual QVariantHash parse(const QByteArray &_source, const QVariantHash &_oldValues) const = 0;
|
[[nodiscard]] virtual QVariantHash parse(const QByteArray &_source) = 0;
|
||||||
[[nodiscard]] QString tag(const QString &_type) const
|
|
||||||
{
|
|
||||||
return dynamic_cast<AbstractExtItem *>(parent())->tag(_type);
|
|
||||||
};
|
|
||||||
[[nodiscard]] virtual QUrl url() const = 0;
|
[[nodiscard]] virtual QUrl url() const = 0;
|
||||||
};
|
};
|
||||||
|
@ -17,25 +17,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QVariant>
|
||||||
#include "abstractextitem.h"
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractWeatherProvider : public QObject
|
class AbstractWeatherProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AbstractWeatherProvider(QObject *_parent)
|
virtual ~AbstractWeatherProvider() = default;
|
||||||
: QObject(_parent){};
|
|
||||||
~AbstractWeatherProvider() override = default;
|
|
||||||
virtual void initUrl(const QString &_city, const QString &_country, int _ts) = 0;
|
virtual void initUrl(const QString &_city, const QString &_country, int _ts) = 0;
|
||||||
[[nodiscard]] virtual QVariantHash parse(const QVariantMap &_json) const = 0;
|
[[nodiscard]] virtual QVariantHash parse(const QVariantMap &_json) const = 0;
|
||||||
[[nodiscard]] QString tag(const QString &_type) const
|
|
||||||
{
|
|
||||||
return dynamic_cast<AbstractExtItem *>(parent())->tag(_type);
|
|
||||||
};
|
|
||||||
[[nodiscard]] virtual QUrl url() const = 0;
|
[[nodiscard]] virtual QUrl url() const = 0;
|
||||||
};
|
};
|
||||||
|
@ -49,9 +49,6 @@ ExtNetworkRequest::~ExtNetworkRequest()
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
disconnect(m_manager, &QNetworkAccessManager::finished, this, &ExtNetworkRequest::networkReplyReceived);
|
|
||||||
disconnect(this, &ExtNetworkRequest::requestDataUpdate, this, &ExtNetworkRequest::sendRequest);
|
|
||||||
|
|
||||||
m_manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,9 +55,6 @@ ExtQuotes::~ExtQuotes()
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
disconnect(m_manager, &QNetworkAccessManager::finished, this, &ExtQuotes::quotesReplyReceived);
|
|
||||||
disconnect(this, &ExtQuotes::requestDataUpdate, this, &ExtQuotes::sendRequest);
|
|
||||||
|
|
||||||
m_manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,10 +183,9 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *_reply)
|
|||||||
auto text = _reply->readAll();
|
auto text = _reply->readAll();
|
||||||
_reply->deleteLater();
|
_reply->deleteLater();
|
||||||
|
|
||||||
auto data = m_providerObject->parse(text, m_values);
|
auto data = m_providerObject->parse(text);
|
||||||
if (data.isEmpty())
|
for (auto [key, value] : data.asKeyValueRange())
|
||||||
return;
|
m_values[tag(key)] = value;
|
||||||
m_values = data;
|
|
||||||
|
|
||||||
emit(dataReceived(m_values));
|
emit(dataReceived(m_values));
|
||||||
}
|
}
|
||||||
@ -205,10 +201,8 @@ void ExtQuotes::sendRequest()
|
|||||||
|
|
||||||
void ExtQuotes::initProvider()
|
void ExtQuotes::initProvider()
|
||||||
{
|
{
|
||||||
delete m_providerObject;
|
|
||||||
|
|
||||||
// in the future release it is possible to change provider here
|
// in the future release it is possible to change provider here
|
||||||
m_providerObject = new StooqQuotesProvider(this);
|
m_providerObject = std::make_unique<StooqQuotesProvider>();
|
||||||
|
|
||||||
return m_providerObject->initUrl(ticker());
|
return m_providerObject->initUrl(ticker());
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ private slots:
|
|||||||
void sendRequest();
|
void sendRequest();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AbstractQuotesProvider *m_providerObject = nullptr;
|
std::unique_ptr<AbstractQuotesProvider> m_providerObject;
|
||||||
QNetworkAccessManager *m_manager = nullptr;
|
QNetworkAccessManager *m_manager = nullptr;
|
||||||
bool m_isRunning = false;
|
bool m_isRunning = false;
|
||||||
void initProvider();
|
void initProvider();
|
||||||
|
@ -53,7 +53,6 @@ ExtScript::~ExtScript()
|
|||||||
|
|
||||||
m_process->kill();
|
m_process->kill();
|
||||||
m_process->deleteLater();
|
m_process->deleteLater();
|
||||||
disconnect(this, &ExtScript::requestDataUpdate, this, &ExtScript::startProcess);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ ExtUpgrade::ExtUpgrade(QObject *_parent, const QString &_filePath)
|
|||||||
m_values[tag("pkgcount")] = 0;
|
m_values[tag("pkgcount")] = 0;
|
||||||
|
|
||||||
m_process = new QProcess(nullptr);
|
m_process = new QProcess(nullptr);
|
||||||
connect(m_process, &QProcess::finished, [this]() { return updateValue(); });
|
connect(m_process, &QProcess::finished, this, &ExtUpgrade::updateValue);
|
||||||
m_process->waitForFinished(0);
|
m_process->waitForFinished(0);
|
||||||
|
|
||||||
connect(this, &ExtUpgrade::requestDataUpdate, this, &ExtUpgrade::startProcess);
|
connect(this, &ExtUpgrade::requestDataUpdate, this, &ExtUpgrade::startProcess);
|
||||||
@ -49,7 +49,6 @@ ExtUpgrade::~ExtUpgrade()
|
|||||||
|
|
||||||
m_process->kill();
|
m_process->kill();
|
||||||
m_process->deleteLater();
|
m_process->deleteLater();
|
||||||
disconnect(this, &ExtUpgrade::requestDataUpdate, this, &ExtUpgrade::startProcess);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,9 +58,6 @@ ExtWeather::~ExtWeather()
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
disconnect(m_manager, &QNetworkAccessManager::finished, this, &ExtWeather::weatherReplyReceived);
|
|
||||||
disconnect(this, &ExtWeather::requestDataUpdate, this, &ExtWeather::sendRequest);
|
|
||||||
|
|
||||||
m_manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,9 +351,8 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *_reply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto data = m_providerObject->parse(jsonDoc.toVariant().toMap());
|
auto data = m_providerObject->parse(jsonDoc.toVariant().toMap());
|
||||||
if (data.isEmpty())
|
for (auto [key, value] : data.asKeyValueRange())
|
||||||
return;
|
m_values[tag(key)] = value;
|
||||||
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));
|
emit(dataReceived(m_values));
|
||||||
@ -365,10 +361,8 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *_reply)
|
|||||||
|
|
||||||
void ExtWeather::initProvider()
|
void ExtWeather::initProvider()
|
||||||
{
|
{
|
||||||
delete m_providerObject;
|
|
||||||
|
|
||||||
// in the future release it is possible to change provider here
|
// in the future release it is possible to change provider here
|
||||||
m_providerObject = new OWMWeatherProvider(this);
|
m_providerObject = std::make_unique<OWMWeatherProvider>();
|
||||||
|
|
||||||
return m_providerObject->initUrl(city(), country(), ts());
|
return m_providerObject->initUrl(city(), country(), ts());
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ private slots:
|
|||||||
void weatherReplyReceived(QNetworkReply *_reply);
|
void weatherReplyReceived(QNetworkReply *_reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AbstractWeatherProvider *m_providerObject = nullptr;
|
std::unique_ptr<AbstractWeatherProvider> m_providerObject;
|
||||||
QNetworkAccessManager *m_manager = nullptr;
|
QNetworkAccessManager *m_manager = nullptr;
|
||||||
bool m_isRunning = false;
|
bool m_isRunning = false;
|
||||||
void initProvider();
|
void initProvider();
|
||||||
|
@ -55,6 +55,15 @@ GraphicalItem::GraphicalItem(QObject *_parent, const QString &_filePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GraphicalItem::~GraphicalItem()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
m_view->deleteLater();
|
||||||
|
m_scene->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GraphicalItem *GraphicalItem::copy(const QString &_fileName, const int _number)
|
GraphicalItem *GraphicalItem::copy(const QString &_fileName, const int _number)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
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(QObject *_parent = nullptr, const QString &_filePath = "");
|
explicit GraphicalItem(QObject *_parent = nullptr, const QString &_filePath = "");
|
||||||
|
~GraphicalItem() override;
|
||||||
GraphicalItem *copy(const QString &_fileName, int _number) override;
|
GraphicalItem *copy(const QString &_fileName, int _number) override;
|
||||||
QString image(const QVariant &value);
|
QString image(const QVariant &value);
|
||||||
void initScene();
|
void initScene();
|
||||||
|
@ -23,14 +23,8 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
OWMWeatherProvider::OWMWeatherProvider(QObject *_parent)
|
OWMWeatherProvider::OWMWeatherProvider()
|
||||||
: AbstractWeatherProvider(_parent)
|
: AbstractWeatherProvider()
|
||||||
{
|
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
OWMWeatherProvider::~OWMWeatherProvider()
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
@ -66,7 +60,7 @@ QVariantHash OWMWeatherProvider::parse(const QVariantMap &_json) const
|
|||||||
if (m_ts == 0) {
|
if (m_ts == 0) {
|
||||||
return parseSingleJson(_json);
|
return parseSingleJson(_json);
|
||||||
} else {
|
} else {
|
||||||
QVariantList list = _json["list"].toList();
|
auto list = _json["list"].toList();
|
||||||
return parseSingleJson(list.count() <= m_ts ? list.at(m_ts - 1).toMap() : list.last().toMap());
|
return parseSingleJson(list.count() <= m_ts ? list.at(m_ts - 1).toMap() : list.last().toMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,7 +72,7 @@ QUrl OWMWeatherProvider::url() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &_json) const
|
QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &_json)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Single json data" << _json;
|
qCDebug(LOG_LIB) << "Single json data" << _json;
|
||||||
|
|
||||||
@ -88,19 +82,19 @@ QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &_json) const
|
|||||||
auto weather = _json["weather"].toList();
|
auto weather = _json["weather"].toList();
|
||||||
if (!weather.isEmpty()) {
|
if (!weather.isEmpty()) {
|
||||||
int id = weather.first().toMap()["id"].toInt();
|
int id = weather.first().toMap()["id"].toInt();
|
||||||
output[tag("weatherId")] = id;
|
output["weatherId"] = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// main data
|
// main data
|
||||||
auto mainWeather = _json["main"].toMap();
|
auto mainWeather = _json["main"].toMap();
|
||||||
if (!weather.isEmpty()) {
|
if (!weather.isEmpty()) {
|
||||||
output[tag("humidity")] = mainWeather["humidity"].toDouble();
|
output["humidity"] = mainWeather["humidity"].toDouble();
|
||||||
output[tag("pressure")] = mainWeather["pressure"].toDouble();
|
output["pressure"] = mainWeather["pressure"].toDouble();
|
||||||
output[tag("temperature")] = mainWeather["temp"].toDouble();
|
output["temperature"] = mainWeather["temp"].toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
// timestamp
|
// timestamp
|
||||||
output[tag("timestamp")] = QDateTime::fromSecsSinceEpoch(_json["dt"].toUInt()).toUTC();
|
output["timestamp"] = QDateTime::fromSecsSinceEpoch(_json["dt"].toUInt()).toUTC();
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -22,22 +22,20 @@
|
|||||||
|
|
||||||
class OWMWeatherProvider : public AbstractWeatherProvider
|
class OWMWeatherProvider : public AbstractWeatherProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// we are using own server to pass requests to OpenWeatherMap because it
|
// we are using own server to pass requests to OpenWeatherMap because it
|
||||||
// requires specific APPID which belongs to developer not user
|
// requires specific APPID which belongs to developer not user
|
||||||
const char *OWM_WEATHER_URL = "https://arcanis.me/weather";
|
const char *OWM_WEATHER_URL = "https://arcanis.me/weather";
|
||||||
const char *OWM_FORECAST_URL = "https://arcanis.me/forecast";
|
const char *OWM_FORECAST_URL = "https://arcanis.me/forecast";
|
||||||
|
|
||||||
explicit OWMWeatherProvider(QObject *_parent);
|
explicit OWMWeatherProvider();
|
||||||
~OWMWeatherProvider() override;
|
~OWMWeatherProvider() override = default;
|
||||||
void initUrl(const QString &_city, const QString &_country, int) override;
|
void initUrl(const QString &_city, const QString &_country, int) override;
|
||||||
[[nodiscard]] QVariantHash parse(const QVariantMap &_json) const override;
|
[[nodiscard]] QVariantHash parse(const QVariantMap &_json) const override;
|
||||||
[[nodiscard]] QUrl url() const override;
|
[[nodiscard]] QUrl url() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] QVariantHash parseSingleJson(const QVariantMap &_json) const;
|
[[nodiscard]] static QVariantHash parseSingleJson(const QVariantMap &_json);
|
||||||
int m_ts = 0;
|
int m_ts = 0;
|
||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
};
|
};
|
||||||
|
@ -34,8 +34,6 @@ QCronScheduler::QCronScheduler(QObject *_parent)
|
|||||||
m_timer->setInterval(60 * 1000);
|
m_timer->setInterval(60 * 1000);
|
||||||
|
|
||||||
connect(m_timer, &QTimer::timeout, this, &QCronScheduler::expired);
|
connect(m_timer, &QTimer::timeout, this, &QCronScheduler::expired);
|
||||||
|
|
||||||
m_timer->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -44,6 +42,7 @@ QCronScheduler::~QCronScheduler()
|
|||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
|
m_timer->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -63,6 +62,22 @@ void QCronScheduler::parse(const QString &_timer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QCronScheduler::start()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Start cron timer";
|
||||||
|
|
||||||
|
m_timer->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QCronScheduler::stop()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Stop cron timer";
|
||||||
|
|
||||||
|
m_timer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void QCronScheduler::expired()
|
void QCronScheduler::expired()
|
||||||
{
|
{
|
||||||
auto now = QDateTime::currentDateTime();
|
auto now = QDateTime::currentDateTime();
|
||||||
|
@ -39,12 +39,14 @@ public:
|
|||||||
int maxValue = -1;
|
int maxValue = -1;
|
||||||
int div = 1;
|
int div = 1;
|
||||||
void fromRange(const QString &_range, int _min, int _max);
|
void fromRange(const QString &_range, int _min, int _max);
|
||||||
QList<int> toList() const;
|
[[nodiscard]] QList<int> toList() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit QCronScheduler(QObject *_parent = nullptr);
|
explicit QCronScheduler(QObject *_parent = nullptr);
|
||||||
~QCronScheduler() override;
|
~QCronScheduler() override;
|
||||||
void parse(const QString &_timer);
|
void parse(const QString &_timer);
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void activated();
|
void activated();
|
||||||
|
@ -22,14 +22,8 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
StooqQuotesProvider::StooqQuotesProvider(QObject *_parent)
|
StooqQuotesProvider::StooqQuotesProvider()
|
||||||
: AbstractQuotesProvider(_parent)
|
: AbstractQuotesProvider()
|
||||||
{
|
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
StooqQuotesProvider::~StooqQuotesProvider()
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
@ -49,7 +43,7 @@ void StooqQuotesProvider::initUrl(const QString &_asset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash StooqQuotesProvider::parse(const QByteArray &_source, const QVariantHash &_oldValues) const
|
QVariantHash StooqQuotesProvider::parse(const QByteArray &_source)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Parse csv" << _source;
|
qCDebug(LOG_LIB) << "Parse csv" << _source;
|
||||||
|
|
||||||
@ -61,20 +55,18 @@ QVariantHash StooqQuotesProvider::parse(const QByteArray &_source, const QVarian
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract old data
|
|
||||||
auto oldPrice = _oldValues[tag("price")].toDouble();
|
|
||||||
auto oldVolume = _oldValues[tag("volume")].toInt();
|
|
||||||
|
|
||||||
// last trade
|
// last trade
|
||||||
auto price = sourceValues.at(0).toDouble();
|
auto price = sourceValues.at(0).toDouble();
|
||||||
values[tag("pricechg")] = oldPrice == 0.0 ? 0.0 : price - oldPrice;
|
values["pricechg"] = m_price == 0.0 ? 0.0 : price - m_price;
|
||||||
values[tag("percpricechg")] = 100.0 * values[tag("pricechg")].toDouble() / oldPrice;
|
values["percpricechg"] = 100.0 * values["pricechg"].toDouble() / m_price;
|
||||||
values[tag("price")] = price;
|
values["price"] = price;
|
||||||
|
m_price = price;
|
||||||
// volume
|
// volume
|
||||||
auto volume = sourceValues.at(1).toInt();
|
auto volume = sourceValues.at(1).toInt();
|
||||||
values[tag("volumechg")] = oldVolume == 0 ? 0 : volume - oldVolume;
|
values["volumechg"] = m_volume == 0 ? 0 : volume - m_volume;
|
||||||
values[tag("percvolumechg")] = 100.0 * values[tag("volumechg")].toDouble() / oldVolume;
|
values["percvolumechg"] = 100.0 * values["volumechg"].toDouble() / m_volume;
|
||||||
values[tag("volume")] = volume;
|
values["volume"] = volume;
|
||||||
|
m_volume = volume;
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -22,17 +22,17 @@
|
|||||||
|
|
||||||
class StooqQuotesProvider : public AbstractQuotesProvider
|
class StooqQuotesProvider : public AbstractQuotesProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const char *STOOQ_QUOTES_URL = "https://stooq.com/q/l/";
|
const char *STOOQ_QUOTES_URL = "https://stooq.com/q/l/";
|
||||||
|
|
||||||
explicit StooqQuotesProvider(QObject *_parent);
|
explicit StooqQuotesProvider();
|
||||||
~StooqQuotesProvider() override;
|
~StooqQuotesProvider() override = default;
|
||||||
void initUrl(const QString &_asset) override;
|
void initUrl(const QString &_asset) override;
|
||||||
[[nodiscard]] QVariantHash parse(const QByteArray &_source, const QVariantHash &_oldValues) const override;
|
[[nodiscard]] QVariantHash parse(const QByteArray &_source) override;
|
||||||
[[nodiscard]] QUrl url() const override;
|
[[nodiscard]] QUrl url() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
double m_price = 0.0;
|
||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
|
int m_volume = 0;
|
||||||
};
|
};
|
||||||
|
@ -23,14 +23,8 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
YahooQuotesProvider::YahooQuotesProvider(QObject *_parent)
|
YahooQuotesProvider::YahooQuotesProvider()
|
||||||
: AbstractQuotesProvider(_parent)
|
: AbstractQuotesProvider()
|
||||||
{
|
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
YahooQuotesProvider::~YahooQuotesProvider()
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
@ -50,7 +44,7 @@ void YahooQuotesProvider::initUrl(const QString &_asset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash YahooQuotesProvider::parse(const QByteArray &_source, const QVariantHash &_oldValues) const
|
QVariantHash YahooQuotesProvider::parse(const QByteArray &_source)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Parse json" << _source;
|
qCDebug(LOG_LIB) << "Parse json" << _source;
|
||||||
|
|
||||||
@ -65,18 +59,16 @@ QVariantHash YahooQuotesProvider::parse(const QByteArray &_source, const QVarian
|
|||||||
auto jsonQuotes = jsonDoc.toVariant().toMap()["query"].toMap();
|
auto jsonQuotes = jsonDoc.toVariant().toMap()["query"].toMap();
|
||||||
jsonQuotes = jsonQuotes["results"].toMap()["quote"].toMap();
|
jsonQuotes = jsonQuotes["results"].toMap()["quote"].toMap();
|
||||||
|
|
||||||
// extract old data
|
|
||||||
auto oldPrice = _oldValues[tag("price")].toDouble();
|
|
||||||
|
|
||||||
// last trade
|
// last trade
|
||||||
auto value = jsonQuotes["LastTradePriceOnly"].toString().toDouble();
|
auto price = jsonQuotes["LastTradePriceOnly"].toString().toDouble();
|
||||||
values[tag("pricechg")] = oldPrice == 0.0 ? 0.0 : value - oldPrice;
|
values["pricechg"] = m_price == 0.0 ? 0.0 : price - m_price;
|
||||||
values[tag("percpricechg")] = 100.0 * values[tag("pricechg")].toDouble() / value;
|
values["percpricechg"] = 100.0 * values["pricechg"].toDouble() / price;
|
||||||
values[tag("price")] = value;
|
values["price"] = price;
|
||||||
|
m_price = price;
|
||||||
// volume
|
// volume
|
||||||
values[tag("volume")] = 0;
|
values["volume"] = 0;
|
||||||
values[tag("volumechg")] = 0;
|
values["volumechg"] = 0;
|
||||||
values[tag("percvolumechg")] = 0.0;
|
values["percvolumechg"] = 0.0;
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -22,18 +22,17 @@
|
|||||||
|
|
||||||
class YahooQuotesProvider : public AbstractQuotesProvider
|
class YahooQuotesProvider : public AbstractQuotesProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const char *YAHOO_QUOTES_URL = "https://query.yahooapis.com/v1/public/yql";
|
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'";
|
const char *YAHOO_QUOTES_QUERY = "select * from yahoo.finance.quotes where symbol='%1'";
|
||||||
|
|
||||||
explicit YahooQuotesProvider(QObject *_parent);
|
explicit YahooQuotesProvider();
|
||||||
~YahooQuotesProvider() override;
|
~YahooQuotesProvider() override = default;
|
||||||
void initUrl(const QString &_asset) override;
|
void initUrl(const QString &_asset) override;
|
||||||
[[nodiscard]] QVariantHash parse(const QByteArray &_source, const QVariantHash &_oldValues) const override;
|
[[nodiscard]] QVariantHash parse(const QByteArray &_source) override;
|
||||||
[[nodiscard]] QUrl url() const override;
|
[[nodiscard]] QUrl url() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
double m_price = 0.0;
|
||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
};
|
};
|
||||||
|
@ -22,14 +22,8 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
YahooWeatherProvider::YahooWeatherProvider(QObject *_parent)
|
YahooWeatherProvider::YahooWeatherProvider()
|
||||||
: AbstractWeatherProvider(_parent)
|
: AbstractWeatherProvider()
|
||||||
{
|
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
YahooWeatherProvider::~YahooWeatherProvider()
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
@ -74,7 +68,7 @@ QUrl YahooWeatherProvider::url() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash YahooWeatherProvider::parseCurrent(const QVariantMap &_json, const QVariantMap &_atmosphere) const
|
QVariantHash YahooWeatherProvider::parseCurrent(const QVariantMap &_json, const QVariantMap &_atmosphere)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Parse current weather from" << _json;
|
qCDebug(LOG_LIB) << "Parse current weather from" << _json;
|
||||||
|
|
||||||
@ -82,12 +76,12 @@ QVariantHash YahooWeatherProvider::parseCurrent(const QVariantMap &_json, const
|
|||||||
|
|
||||||
QVariantHash values;
|
QVariantHash values;
|
||||||
auto id = _json["condition"].toMap()["code"].toInt();
|
auto id = _json["condition"].toMap()["code"].toInt();
|
||||||
values[tag("weatherId")] = id;
|
values["weatherId"] = id;
|
||||||
values[tag("temperature")] = condition["temp"].toInt();
|
values["temperature"] = condition["temp"].toInt();
|
||||||
values[tag("timestamp")] = condition["date"].toString();
|
values["timestamp"] = condition["date"].toString();
|
||||||
values[tag("humidity")] = _atmosphere["humidity"].toInt();
|
values["humidity"] = _atmosphere["humidity"].toInt();
|
||||||
// HACK temporary fix of invalid values on Yahoo! side
|
// HACK temporary fix of invalid values on Yahoo! side
|
||||||
values[tag("pressure")] = static_cast<int>(_atmosphere["pressure"].toDouble() / 33.863753);
|
values["pressure"] = static_cast<int>(_atmosphere["pressure"].toDouble() / 33.863753);
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
@ -101,13 +95,13 @@ QVariantHash YahooWeatherProvider::parseForecast(const QVariantMap &_json) const
|
|||||||
auto weatherList = _json["forecast"].toList();
|
auto weatherList = _json["forecast"].toList();
|
||||||
auto weatherMap = weatherList.count() < m_ts ? weatherList.last().toMap() : weatherList.at(m_ts).toMap();
|
auto weatherMap = weatherList.count() < m_ts ? weatherList.last().toMap() : weatherList.at(m_ts).toMap();
|
||||||
auto id = weatherMap["code"].toInt();
|
auto id = weatherMap["code"].toInt();
|
||||||
values[tag("weatherId")] = id;
|
values["weatherId"] = id;
|
||||||
values[tag("timestamp")] = weatherMap["date"].toString();
|
values["timestamp"] = weatherMap["date"].toString();
|
||||||
// yahoo provides high and low temperatures. Lets calculate average one
|
// yahoo provides high and low temperatures. Lets calculate average one
|
||||||
values[tag("temperature")] = (weatherMap["high"].toDouble() + weatherMap["low"].toDouble()) / 2.0;
|
values["temperature"] = (weatherMap["high"].toDouble() + weatherMap["low"].toDouble()) / 2.0;
|
||||||
// ... and no forecast data for humidity and pressure
|
// ... and no forecast data for humidity and pressure
|
||||||
values[tag("humidity")] = 0;
|
values["humidity"] = 0;
|
||||||
values[tag("pressure")] = 0.0;
|
values["pressure"] = 0.0;
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -22,22 +22,20 @@
|
|||||||
|
|
||||||
class YahooWeatherProvider : public AbstractWeatherProvider
|
class YahooWeatherProvider : public AbstractWeatherProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const char *YAHOO_WEATHER_URL = "https://query.yahooapis.com/v1/public/yql";
|
const char *YAHOO_WEATHER_URL = "https://query.yahooapis.com/v1/public/yql";
|
||||||
const char *YAHOO_WEATHER_QUERY = "select * from weather.forecast where "
|
const char *YAHOO_WEATHER_QUERY = "select * from weather.forecast where "
|
||||||
"u='c' and woeid in (select woeid from "
|
"u='c' and woeid in (select woeid from "
|
||||||
"geo.places(1) where text='%1, %2')";
|
"geo.places(1) where text='%1, %2')";
|
||||||
|
|
||||||
explicit YahooWeatherProvider(QObject *_parent);
|
explicit YahooWeatherProvider();
|
||||||
~YahooWeatherProvider() override;
|
~YahooWeatherProvider() override = default;
|
||||||
void initUrl(const QString &_city, const QString &_country, int) override;
|
void initUrl(const QString &_city, const QString &_country, int) override;
|
||||||
[[nodiscard]] QVariantHash parse(const QVariantMap &_json) const override;
|
[[nodiscard]] QVariantHash parse(const QVariantMap &_json) const override;
|
||||||
[[nodiscard]] QUrl url() const override;
|
[[nodiscard]] QUrl url() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] QVariantHash parseCurrent(const QVariantMap &_json, const QVariantMap &_atmosphere) const;
|
[[nodiscard]] static QVariantHash parseCurrent(const QVariantMap &_json, const QVariantMap &_atmosphere);
|
||||||
[[nodiscard]] QVariantHash parseForecast(const QVariantMap &_json) const;
|
[[nodiscard]] QVariantHash parseForecast(const QVariantMap &_json) const;
|
||||||
int m_ts = 0;
|
int m_ts = 0;
|
||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
|
@ -136,7 +136,7 @@ QString DPAdds::toolTipImage(const int _desktop) const
|
|||||||
toolTipScene->addLine(width + 2.0 * margin, height + 2.0 * margin, width + 2.0 * margin, 0);
|
toolTipScene->addLine(width + 2.0 * margin, height + 2.0 * margin, width + 2.0 * margin, 0);
|
||||||
toolTipScene->addLine(width + 2.0 * margin, 0, 0, 0);
|
toolTipScene->addLine(width + 2.0 * margin, 0, 0, 0);
|
||||||
|
|
||||||
// with wayland countours only are supported
|
// with wayland contours only are supported
|
||||||
auto pen = QPen();
|
auto pen = QPen();
|
||||||
pen.setWidthF(2.0 * width / 400.0);
|
pen.setWidthF(2.0 * width / 400.0);
|
||||||
pen.setColor(QColor(m_tooltipColor));
|
pen.setColor(QColor(m_tooltipColor));
|
||||||
@ -159,8 +159,8 @@ QString DPAdds::toolTipImage(const int _desktop) const
|
|||||||
QBuffer buffer(&byteArray);
|
QBuffer buffer(&byteArray);
|
||||||
image.save(&buffer, "PNG");
|
image.save(&buffer, "PNG");
|
||||||
|
|
||||||
delete toolTipView;
|
toolTipView->deleteLater();
|
||||||
delete toolTipScene;
|
toolTipScene->deleteLater();
|
||||||
|
|
||||||
return QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
|
return QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ QuotesSource::QuotesSource(QObject *_parent)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, "quotes");
|
m_extQuotes = new ExtItemAggregator<ExtQuotes>(this, "quotes");
|
||||||
m_extQuotes->initSockets();
|
m_extQuotes->initSockets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ RequestSource::RequestSource(QObject *_parent)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_extNetRequest = new ExtItemAggregator<ExtNetworkRequest>(nullptr, "requests");
|
m_extNetRequest = new ExtItemAggregator<ExtNetworkRequest>(this, "requests");
|
||||||
m_extNetRequest->initSockets();
|
m_extNetRequest->initSockets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ UpgradeSource::UpgradeSource(QObject *_parent)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, "upgrade");
|
m_extUpgrade = new ExtItemAggregator<ExtUpgrade>(this, "upgrade");
|
||||||
m_extUpgrade->initSockets();
|
m_extUpgrade->initSockets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ WeatherSource::WeatherSource(QObject *_parent)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_extWeather = new ExtItemAggregator<ExtWeather>(nullptr, "weather");
|
m_extWeather = new ExtItemAggregator<ExtWeather>(this, "weather");
|
||||||
m_extWeather->initSockets();
|
m_extWeather->initSockets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ void TestAWTelemetryHandler::initTestCase()
|
|||||||
{
|
{
|
||||||
AWTestLibrary::init();
|
AWTestLibrary::init();
|
||||||
plugin = new AWTelemetryHandler(this);
|
plugin = new AWTelemetryHandler(this);
|
||||||
plugin->init(1, true, telemetryId);
|
plugin->init(1, telemetryId);
|
||||||
telemetryData = AWTestLibrary::randomString();
|
telemetryData = AWTestLibrary::randomString();
|
||||||
telemetryGroup = AWTestLibrary::randomString();
|
telemetryGroup = AWTestLibrary::randomString();
|
||||||
}
|
}
|
||||||
@ -61,18 +61,4 @@ void TestAWTelemetryHandler::test_getLast()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestAWTelemetryHandler::test_uploadTelemetry()
|
|
||||||
{
|
|
||||||
QSKIP("Remote telemetry is disabled at the moment");
|
|
||||||
|
|
||||||
QSignalSpy spy(plugin, SIGNAL(replyReceived(const QString &)));
|
|
||||||
plugin->uploadTelemetry(telemetryValidGroup, telemetryData);
|
|
||||||
|
|
||||||
QVERIFY(spy.wait(5000));
|
|
||||||
auto arguments = spy.takeFirst();
|
|
||||||
|
|
||||||
QCOMPARE(arguments.at(0).toString(), telemetryStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(TestAWTelemetryHandler);
|
QTEST_MAIN(TestAWTelemetryHandler);
|
||||||
|
@ -34,7 +34,6 @@ private slots:
|
|||||||
void test_put();
|
void test_put();
|
||||||
void test_get();
|
void test_get();
|
||||||
void test_getLast();
|
void test_getLast();
|
||||||
void test_uploadTelemetry();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AWTelemetryHandler *plugin = nullptr;
|
AWTelemetryHandler *plugin = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user