mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-10-14 00:29:59 +00:00
use m_ prefix for all internal variables, update CONTRIBUTING.md
accordingly
This commit is contained in:
@ -44,15 +44,15 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString filePath)
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
values[tag(QString("ask"))] = 0.0;
|
||||
values[tag(QString("askchg"))] = 0.0;
|
||||
values[tag(QString("percaskchg"))] = 0.0;
|
||||
values[tag(QString("bid"))] = 0.0;
|
||||
values[tag(QString("bidchg"))] = 0.0;
|
||||
values[tag(QString("percbidchg"))] = 0.0;
|
||||
values[tag(QString("price"))] = 0.0;
|
||||
values[tag(QString("pricechg"))] = 0.0;
|
||||
values[tag(QString("percpricechg"))] = 0.0;
|
||||
m_values[tag(QString("ask"))] = 0.0;
|
||||
m_values[tag(QString("askchg"))] = 0.0;
|
||||
m_values[tag(QString("percaskchg"))] = 0.0;
|
||||
m_values[tag(QString("bid"))] = 0.0;
|
||||
m_values[tag(QString("bidchg"))] = 0.0;
|
||||
m_values[tag(QString("percbidchg"))] = 0.0;
|
||||
m_values[tag(QString("price"))] = 0.0;
|
||||
m_values[tag(QString("pricechg"))] = 0.0;
|
||||
m_values[tag(QString("percpricechg"))] = 0.0;
|
||||
|
||||
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
||||
// in the destructor
|
||||
@ -133,22 +133,22 @@ void ExtQuotes::readConfiguration()
|
||||
|
||||
QVariantHash ExtQuotes::run()
|
||||
{
|
||||
if ((!isActive()) || (isRunning))
|
||||
return values;
|
||||
if ((!isActive()) || (m_isRunning))
|
||||
return m_values;
|
||||
|
||||
if (times == 1) {
|
||||
if (m_times == 1) {
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
isRunning = true;
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
// update value
|
||||
if (times >= interval())
|
||||
times = 0;
|
||||
times++;
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
|
||||
return values;
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
@ -199,7 +199,7 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
|
||||
<< reply->errorString();
|
||||
|
||||
isRunning = false;
|
||||
m_isRunning = false;
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
reply->deleteLater();
|
||||
@ -216,38 +216,38 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
|
||||
// ask
|
||||
value = jsonQuotes[QString("Ask")].toString().toDouble();
|
||||
values[tag(QString("askchg"))]
|
||||
= values[tag(QString("ask"))].toDouble() == 0.0
|
||||
m_values[tag(QString("askchg"))]
|
||||
= m_values[tag(QString("ask"))].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - values[tag(QString("ask"))].toDouble();
|
||||
values[tag(QString("percaskchg"))]
|
||||
= 100.0 * values[tag(QString("askchg"))].toDouble()
|
||||
/ values[tag(QString("ask"))].toDouble();
|
||||
values[tag(QString("ask"))] = value;
|
||||
: value - m_values[tag(QString("ask"))].toDouble();
|
||||
m_values[tag(QString("percaskchg"))]
|
||||
= 100.0 * m_values[tag(QString("askchg"))].toDouble()
|
||||
/ m_values[tag(QString("ask"))].toDouble();
|
||||
m_values[tag(QString("ask"))] = value;
|
||||
|
||||
// bid
|
||||
value = jsonQuotes[QString("Bid")].toString().toDouble();
|
||||
values[tag(QString("bidchg"))]
|
||||
= values[tag(QString("bid"))].toDouble() == 0.0
|
||||
m_values[tag(QString("bidchg"))]
|
||||
= m_values[tag(QString("bid"))].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - values[tag(QString("bid"))].toDouble();
|
||||
values[tag(QString("percbidchg"))]
|
||||
= 100.0 * values[tag(QString("bidchg"))].toDouble()
|
||||
/ values[tag(QString("bid"))].toDouble();
|
||||
values[tag(QString("bid"))] = value;
|
||||
: value - m_values[tag(QString("bid"))].toDouble();
|
||||
m_values[tag(QString("percbidchg"))]
|
||||
= 100.0 * m_values[tag(QString("bidchg"))].toDouble()
|
||||
/ m_values[tag(QString("bid"))].toDouble();
|
||||
m_values[tag(QString("bid"))] = value;
|
||||
|
||||
// last trade
|
||||
value = jsonQuotes[QString("LastTradePriceOnly")].toString().toDouble();
|
||||
values[tag(QString("pricechg"))]
|
||||
= values[tag(QString("price"))].toDouble() == 0.0
|
||||
m_values[tag(QString("pricechg"))]
|
||||
= m_values[tag(QString("price"))].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - values[tag(QString("price"))].toDouble();
|
||||
values[tag(QString("percpricechg"))]
|
||||
= 100.0 * values[tag(QString("pricechg"))].toDouble()
|
||||
/ values[tag(QString("price"))].toDouble();
|
||||
values[tag(QString("price"))] = value;
|
||||
: value - m_values[tag(QString("price"))].toDouble();
|
||||
m_values[tag(QString("percpricechg"))]
|
||||
= 100.0 * m_values[tag(QString("pricechg"))].toDouble()
|
||||
/ m_values[tag(QString("price"))].toDouble();
|
||||
m_values[tag(QString("price"))] = value;
|
||||
|
||||
emit(dataReceived(values));
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,15 +59,15 @@ private slots:
|
||||
private:
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
QUrl m_url;
|
||||
bool isRunning = false;
|
||||
bool m_isRunning = false;
|
||||
Ui::ExtQuotes *ui = nullptr;
|
||||
void initUrl();
|
||||
void translate();
|
||||
// properties
|
||||
QString m_ticker = QString("EURUSD=X");
|
||||
// values
|
||||
int times = 0;
|
||||
QVariantHash values;
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -42,12 +42,12 @@ ExtScript::ExtScript(QWidget *parent, const QString filePath)
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
value[tag(QString("custom"))] = QString("");
|
||||
m_values[tag(QString("custom"))] = QString("");
|
||||
|
||||
process = new QProcess(nullptr);
|
||||
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
||||
m_process = new QProcess(nullptr);
|
||||
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
||||
SLOT(updateValue()));
|
||||
process->waitForFinished(0);
|
||||
m_process->waitForFinished(0);
|
||||
}
|
||||
|
||||
|
||||
@ -55,8 +55,8 @@ ExtScript::~ExtScript()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
process->kill();
|
||||
process->deleteLater();
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
|
||||
for (auto filt : filters()) {
|
||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||
QVariantMap filter = jsonFilters[filt].toMap();
|
||||
QVariantMap filter = m_jsonFilters[filt].toMap();
|
||||
if (filter.isEmpty()) {
|
||||
qCWarning(LOG_LIB) << "Could not find filter" << _value
|
||||
<< "in the json";
|
||||
@ -254,35 +254,35 @@ void ExtScript::readJsonFilters()
|
||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
jsonFilters = jsonDoc.toVariant().toMap();
|
||||
m_jsonFilters = jsonDoc.toVariant().toMap();
|
||||
|
||||
qCInfo(LOG_LIB) << "Filters" << jsonFilters;
|
||||
qCInfo(LOG_LIB) << "Filters" << m_jsonFilters;
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtScript::run()
|
||||
{
|
||||
if (!isActive())
|
||||
return value;
|
||||
if (process->state() != QProcess::NotRunning)
|
||||
return m_values;
|
||||
if (m_process->state() != QProcess::NotRunning)
|
||||
qCWarning(LOG_LIB) << "Another process is already running"
|
||||
<< process->state();
|
||||
<< m_process->state();
|
||||
|
||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||
if ((m_times == 1) && (m_process->state() == QProcess::NotRunning)) {
|
||||
QStringList cmdList;
|
||||
if (!prefix().isEmpty())
|
||||
cmdList.append(prefix());
|
||||
cmdList.append(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' '));
|
||||
process->start(cmdList.join(QChar(' ')));
|
||||
m_process->start(cmdList.join(QChar(' ')));
|
||||
}
|
||||
|
||||
// update value
|
||||
if (times >= interval())
|
||||
times = 0;
|
||||
times++;
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
|
||||
return value;
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
@ -352,13 +352,13 @@ void ExtScript::writeConfiguration() const
|
||||
|
||||
void ExtScript::updateValue()
|
||||
{
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode();
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
|
||||
QString qdebug = QTextCodec::codecForMib(106)
|
||||
->toUnicode(process->readAllStandardError())
|
||||
->toUnicode(m_process->readAllStandardError())
|
||||
.trimmed();
|
||||
qCInfo(LOG_LIB) << "Error" << qdebug;
|
||||
QString qoutput = QTextCodec::codecForMib(106)
|
||||
->toUnicode(process->readAllStandardOutput())
|
||||
->toUnicode(m_process->readAllStandardOutput())
|
||||
.trimmed();
|
||||
qCInfo(LOG_LIB) << "Output" << qoutput;
|
||||
QString strValue;
|
||||
@ -378,8 +378,8 @@ void ExtScript::updateValue()
|
||||
}
|
||||
|
||||
// filters
|
||||
value[tag(QString("custom"))] = applyFilters(strValue);
|
||||
emit(dataReceived(value));
|
||||
m_values[tag(QString("custom"))] = applyFilters(strValue);
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,7 +76,7 @@ private slots:
|
||||
void updateValue();
|
||||
|
||||
private:
|
||||
QProcess *process = nullptr;
|
||||
QProcess *m_process = nullptr;
|
||||
Ui::ExtScript *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
@ -85,9 +85,9 @@ private:
|
||||
QString m_prefix = QString("");
|
||||
Redirect m_redirect = Redirect::nothing;
|
||||
// internal properties
|
||||
QVariantMap jsonFilters = QVariantMap();
|
||||
int times = 0;
|
||||
QVariantHash value;
|
||||
QVariantMap m_jsonFilters = QVariantMap();
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -39,11 +39,11 @@ ExtUpgrade::ExtUpgrade(QWidget *parent, const QString filePath)
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
value[tag(QString("pkgcount"))] = 0;
|
||||
m_values[tag(QString("pkgcount"))] = 0;
|
||||
|
||||
process = new QProcess(nullptr);
|
||||
connect(process, SIGNAL(finished(int)), this, SLOT(updateValue()));
|
||||
process->waitForFinished(0);
|
||||
m_process = new QProcess(nullptr);
|
||||
connect(m_process, SIGNAL(finished(int)), this, SLOT(updateValue()));
|
||||
m_process->waitForFinished(0);
|
||||
}
|
||||
|
||||
|
||||
@ -51,8 +51,8 @@ ExtUpgrade::~ExtUpgrade()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
process->kill();
|
||||
process->deleteLater();
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -143,20 +143,20 @@ void ExtUpgrade::readConfiguration()
|
||||
QVariantHash ExtUpgrade::run()
|
||||
{
|
||||
if (!isActive())
|
||||
return value;
|
||||
return m_values;
|
||||
|
||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||
if ((m_times == 1) && (m_process->state() == QProcess::NotRunning)) {
|
||||
QString cmd = QString("sh -c \"%1\"").arg(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmd;
|
||||
process->start(cmd);
|
||||
m_process->start(cmd);
|
||||
}
|
||||
|
||||
// update value
|
||||
if (times >= interval())
|
||||
times = 0;
|
||||
times++;
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
|
||||
return value;
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
@ -211,13 +211,13 @@ void ExtUpgrade::writeConfiguration() const
|
||||
|
||||
void ExtUpgrade::updateValue()
|
||||
{
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode();
|
||||
qCInfo(LOG_LIB) << "Error" << process->readAllStandardError();
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
|
||||
qCInfo(LOG_LIB) << "Error" << m_process->readAllStandardError();
|
||||
|
||||
QString qoutput = QTextCodec::codecForMib(106)
|
||||
->toUnicode(process->readAllStandardOutput())
|
||||
->toUnicode(m_process->readAllStandardOutput())
|
||||
.trimmed();
|
||||
value[tag(QString("pkgcount"))] = [this](QString output) {
|
||||
m_values[tag(QString("pkgcount"))] = [this](QString output) {
|
||||
return filter().isEmpty()
|
||||
? output.split(QChar('\n'), QString::SkipEmptyParts).count()
|
||||
- null()
|
||||
@ -226,7 +226,7 @@ void ExtUpgrade::updateValue()
|
||||
.count();
|
||||
}(qoutput);
|
||||
|
||||
emit(dataReceived(value));
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ private slots:
|
||||
void updateValue();
|
||||
|
||||
private:
|
||||
QProcess *process = nullptr;
|
||||
QProcess *m_process = nullptr;
|
||||
Ui::ExtUpgrade *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
@ -67,8 +67,8 @@ private:
|
||||
QString m_filter = QString("");
|
||||
int m_null = 0;
|
||||
// internal properties
|
||||
int times = 0;
|
||||
QVariantHash value;
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -47,11 +47,11 @@ ExtWeather::ExtWeather(QWidget *parent, const QString filePath)
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
values[tag(QString("weatherId"))] = 0;
|
||||
values[tag(QString("weather"))] = QString("");
|
||||
values[tag(QString("humidity"))] = 0;
|
||||
values[tag(QString("pressure"))] = 0.0;
|
||||
values[tag(QString("temperature"))] = 0.0;
|
||||
m_values[tag(QString("weatherId"))] = 0;
|
||||
m_values[tag(QString("weather"))] = QString("");
|
||||
m_values[tag(QString("humidity"))] = 0;
|
||||
m_values[tag(QString("pressure"))] = 0.0;
|
||||
m_values[tag(QString("temperature"))] = 0.0;
|
||||
|
||||
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
||||
// in the destructor
|
||||
@ -259,23 +259,23 @@ void ExtWeather::readJsonMap()
|
||||
|
||||
QVariantHash ExtWeather::run()
|
||||
{
|
||||
if ((!isActive()) || (isRunning))
|
||||
return values;
|
||||
if ((!isActive()) || (m_isRunning))
|
||||
return m_values;
|
||||
|
||||
if (times == 1) {
|
||||
if (m_times == 1) {
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
isRunning = true;
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply
|
||||
= m_manager->get(QNetworkRequest(m_providerObject->url()));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
// update value
|
||||
if (times >= interval())
|
||||
times = 0;
|
||||
times++;
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
|
||||
return values;
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
@ -339,7 +339,7 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
|
||||
<< reply->errorString();
|
||||
|
||||
isRunning = false;
|
||||
m_isRunning = false;
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
reply->deleteLater();
|
||||
@ -352,11 +352,11 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
QVariantHash data = m_providerObject->parse(jsonDoc.toVariant().toMap());
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
values = data;
|
||||
values[tag(QString("weather"))]
|
||||
= weatherFromInt(values[tag(QString("weatherId"))].toInt());
|
||||
m_values = data;
|
||||
m_values[tag(QString("weather"))]
|
||||
= weatherFromInt(m_values[tag(QString("weatherId"))].toInt());
|
||||
|
||||
emit(dataReceived(values));
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,7 +75,7 @@ private slots:
|
||||
private:
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
AbstractWeatherProvider *m_providerObject = nullptr;
|
||||
bool isRunning = false;
|
||||
bool m_isRunning = false;
|
||||
Ui::ExtWeather *ui = nullptr;
|
||||
void initProvider();
|
||||
void translate();
|
||||
@ -87,8 +87,8 @@ private:
|
||||
int m_ts = 0;
|
||||
QVariantMap m_jsonMap = QVariantMap();
|
||||
// values
|
||||
int times = 0;
|
||||
QVariantHash values;
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "abstractweatherprovider.h"
|
||||
|
||||
// we are using own server to pass requests to OpenWeatherMap because it
|
||||
// requires specific APPID which belongs to developer not user
|
||||
#define OWM_WEATHER_URL "http://arcanis.me/weather"
|
||||
#define OWM_FORECAST_URL "http://arcanis.me/forecast"
|
||||
|
||||
|
Reference in New Issue
Block a user