massive refactoring

This commit is contained in:
2017-05-05 17:55:52 +03:00
parent 6e62ceaac7
commit d0c96ce829
152 changed files with 3041 additions and 3219 deletions

View File

@ -28,13 +28,13 @@
#include "qcronscheduler.h"
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString &filePath)
: QDialog(parent)
, m_fileName(filePath)
AbstractExtItem::AbstractExtItem(QWidget *_parent, const QString &_filePath)
: QDialog(_parent)
, m_fileName(_filePath)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
qCDebug(LOG_LIB) << "Desktop name" << filePath;
qCDebug(LOG_LIB) << "Desktop name" << _filePath;
m_name = m_fileName;
}
@ -299,18 +299,15 @@ void AbstractExtItem::readConfiguration()
{
QSettings settings(m_fileName, QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setName(settings.value(QString("Name"), name()).toString());
setComment(settings.value(QString("Comment"), comment()).toString());
setApiVersion(
settings.value(QString("X-AW-ApiVersion"), apiVersion()).toInt());
setActive(
settings.value(QString("X-AW-Active"), QVariant(isActive())).toString()
== QString("true"));
setInterval(settings.value(QString("X-AW-Interval"), interval()).toInt());
setNumber(settings.value(QString("X-AW-Number"), number()).toInt());
setCron(settings.value(QString("X-AW-Schedule"), cron()).toString());
setSocket(settings.value(QString("X-AW-Socket"), socket()).toString());
settings.beginGroup("Desktop Entry");
setName(settings.value("Name", name()).toString());
setComment(settings.value("Comment", comment()).toString());
setApiVersion(settings.value("X-AW-ApiVersion", apiVersion()).toInt());
setActive(settings.value("X-AW-Active", isActive()).toBool());
setInterval(settings.value("X-AW-Interval", interval()).toInt());
setNumber(settings.value("X-AW-Number", number()).toInt());
setCron(settings.value("X-AW-Schedule", cron()).toString());
setSocket(settings.value("X-AW-Socket", socket()).toString());
settings.endGroup();
}
@ -329,18 +326,16 @@ void AbstractExtItem::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Encoding"), QString("UTF-8"));
settings.setValue(QString("Name"), name());
settings.setValue(QString("Comment"), comment());
settings.setValue(QString("X-AW-ApiVersion"), apiVersion());
settings.setValue(QString("X-AW-Active"), QVariant(isActive()).toString());
settings.setValue(QString("X-AW-Interval"),
cron().isEmpty() ? QVariant(interval())
: QVariant(cron()));
settings.setValue(QString("X-AW-Number"), number());
settings.setValue(QString("X-AW-Schedule"), cron());
settings.setValue(QString("X-AW-Socket"), socket());
settings.beginGroup("Desktop Entry");
settings.setValue("Encoding", "UTF-8");
settings.setValue("Name", name());
settings.setValue("Comment", comment());
settings.setValue("X-AW-ApiVersion", apiVersion());
settings.setValue("X-AW-Active", isActive());
settings.setValue("X-AW-Interval", interval());
settings.setValue("X-AW-Number", number());
settings.setValue("X-AW-Schedule", cron());
settings.setValue("X-AW-Socket", socket());
settings.endGroup();
settings.sync();

View File

@ -40,8 +40,8 @@ class AbstractExtItem : public QDialog
Q_PROPERTY(QString uniq READ uniq)
public:
explicit AbstractExtItem(QWidget *parent,
const QString &filePath = QString());
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)
@ -62,17 +62,17 @@ public:
QString tag(const QString &_type) const;
virtual QString uniq() const = 0;
// set methods
void setApiVersion(const int _apiVersion = 0);
void setActive(const bool _state = true);
void setComment(const QString &_comment = QString("empty"));
void setCron(const QString &_cron = "");
void setInterval(const int _interval = 1);
void setName(const QString &_name = QString("none"));
void setNumber(int _number = -1);
void setSocket(const QString &_socket = QString(""));
void setApiVersion(const int _apiVersion);
void setActive(const bool _state);
void setComment(const QString &_comment);
void setCron(const QString &_cron);
void setInterval(const int _interval);
void setName(const QString &_name);
void setNumber(int _number);
void setSocket(const QString &_socket);
signals:
void dataReceived(const QVariantHash &data);
void dataReceived(const QVariantHash &_data);
void requestDataUpdate();
public slots:
@ -80,7 +80,7 @@ public slots:
virtual void initSocket();
virtual void readConfiguration();
virtual QVariantHash run() = 0;
virtual int showConfiguration(const QVariant &args = QVariant()) = 0;
virtual int showConfiguration(const QVariant &_args) = 0;
virtual bool tryDelete() const;
virtual void writeConfiguration() const;
@ -89,19 +89,19 @@ private slots:
private:
QCronScheduler *m_scheduler = nullptr;
QString m_fileName = QString("/dev/null");
QString m_fileName = "/dev/null";
int m_times = 0;
virtual void translate() = 0;
// properties
int m_apiVersion = 0;
bool m_active = true;
QString m_comment = QString("empty");
QString m_comment = "empty";
QString m_cron = "";
int m_interval = 1;
QString m_name = QString("none");
QString m_name = "none";
int m_number = -1;
QLocalServer *m_socket = nullptr;
QString m_socketFile = QString("");
QString m_socketFile = "";
};

View File

@ -25,11 +25,11 @@
#include <QPushButton>
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent,
const QString &type)
: QDialog(parent)
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *_parent,
const QString &_type)
: QDialog(_parent)
, ui(new Ui::AbstractExtItemAggregator)
, m_type(type)
, m_type(_type)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
@ -113,13 +113,13 @@ void AbstractExtItemAggregator::editItem()
QString AbstractExtItemAggregator::getName()
{
bool ok;
QString name = QInputDialog::getText(this, i18n("Enter file name"),
i18n("File name"), QLineEdit::Normal,
QString(""), &ok);
QString name
= QInputDialog::getText(this, i18n("Enter file name"),
i18n("File name"), QLineEdit::Normal, "", &ok);
if ((!ok) || (name.isEmpty()))
return QString("");
if (!name.endsWith(QString(".desktop")))
name += QString(".desktop");
return "";
if (!name.endsWith(".desktop"))
name += ".desktop";
return name;
}
@ -157,7 +157,7 @@ void AbstractExtItemAggregator::repaintList()
tooltip.append(i18n("Name: %1", _item->name()));
tooltip.append(i18n("Comment: %1", _item->comment()));
tooltip.append(i18n("Identity: %1", _item->uniq()));
item->setToolTip(tooltip.join(QChar('\n')));
item->setToolTip(tooltip.join('\n'));
ui->listWidget->addItem(item);
}
}
@ -202,14 +202,14 @@ void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *)
}
void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button)
void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *_button)
{
if (static_cast<QPushButton *>(button) == copyButton)
if (static_cast<QPushButton *>(_button) == copyButton)
return copyItem();
else if (static_cast<QPushButton *>(button) == createButton)
else if (static_cast<QPushButton *>(_button) == createButton)
return doCreateItem();
else if (static_cast<QPushButton *>(button) == deleteButton)
else if (static_cast<QPushButton *>(_button) == deleteButton)
return deleteItem();
else if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
else if (ui->buttonBox->buttonRole(_button) == QDialogButtonBox::AcceptRole)
return editItem();
}

View File

@ -39,7 +39,7 @@ class AbstractExtItemAggregator : public QDialog
Q_PROPERTY(QVariant type READ type)
public:
explicit AbstractExtItemAggregator(QWidget *parent, const QString &type);
explicit AbstractExtItemAggregator(QWidget *_parent, const QString &_type);
virtual ~AbstractExtItemAggregator();
// methods
void copyItem();
@ -79,7 +79,7 @@ public:
private slots:
void editItemActivated(QListWidgetItem *);
void editItemButtonPressed(QAbstractButton *button);
void editItemButtonPressed(QAbstractButton *_button);
private:
// ui

View File

@ -28,14 +28,14 @@ class AbstractWeatherProvider : public QObject
Q_PROPERTY(int number READ number)
public:
explicit AbstractWeatherProvider(QObject *parent, const int number)
: QObject(parent)
, m_number(number){};
explicit AbstractWeatherProvider(QObject *_parent, const int _number)
: QObject(_parent)
, m_number(_number){};
virtual ~AbstractWeatherProvider(){};
virtual void initUrl(const QString &city, const QString &country,
const int ts)
virtual void initUrl(const QString &_city, const QString &_country,
const int _ts)
= 0;
virtual QVariantHash parse(const QVariantMap &json) const = 0;
virtual QVariantHash parse(const QVariantMap &_json) const = 0;
virtual QUrl url() const = 0;
int number() const { return m_number; };

View File

@ -22,9 +22,9 @@
#include "awdebug.h"
AWAbstractFormatter::AWAbstractFormatter(QWidget *parent,
const QString &filePath)
: AbstractExtItem(parent, filePath)
AWAbstractFormatter::AWAbstractFormatter(QWidget *_parent,
const QString &_filePath)
: AbstractExtItem(_parent, _filePath)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
}
@ -55,25 +55,25 @@ QString AWAbstractFormatter::strType() const
QString value;
switch (m_type) {
case FormatterClass::DateTime:
value = QString("DateTime");
value = "DateTime";
break;
case FormatterClass::Float:
value = QString("Float");
value = "Float";
break;
case FormatterClass::List:
value = QString("List");
value = "List";
break;
case FormatterClass::Script:
value = QString("Script");
value = "Script";
break;
case FormatterClass::String:
value = QString("String");
value = "String";
break;
case FormatterClass::Json:
value = QString("Json");
value = "Json";
break;
case FormatterClass::NoFormat:
value = QString("NoFormat");
value = "NoFormat";
break;
}
@ -91,17 +91,17 @@ void AWAbstractFormatter::setStrType(const QString &_type)
{
qCDebug(LOG_LIB) << "Type" << _type;
if (_type == QString("DateTime"))
if (_type == "DateTime")
m_type = FormatterClass::DateTime;
else if (_type == QString("Float"))
else if (_type == "Float")
m_type = FormatterClass::Float;
else if (_type == QString("List"))
else if (_type == "List")
m_type = FormatterClass::List;
else if (_type == QString("Script"))
else if (_type == "Script")
m_type = FormatterClass::Script;
else if (_type == QString("String"))
else if (_type == "String")
m_type = FormatterClass::String;
else if (_type == QString("Json"))
else if (_type == "Json")
m_type = FormatterClass::Json;
else
m_type = FormatterClass::NoFormat;
@ -123,8 +123,8 @@ void AWAbstractFormatter::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
settings.beginGroup("Desktop Entry");
setStrType(settings.value("X-AW-Type", strType()).toString());
settings.endGroup();
}
@ -136,8 +136,8 @@ void AWAbstractFormatter::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Type"), strType());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-Type", strType());
settings.endGroup();
settings.sync();

View File

@ -38,8 +38,8 @@ public:
Json
};
explicit AWAbstractFormatter(QWidget *parent,
const QString &filePath = QString());
explicit AWAbstractFormatter(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~AWAbstractFormatter();
virtual QString convert(const QVariant &_value) const = 0;
void copyDefaults(AbstractExtItem *_other) const;
@ -47,8 +47,8 @@ public:
// properties
QString strType() const;
FormatterClass type() const;
void setStrType(const QString &type);
void setType(const FormatterClass _type = FormatterClass::NoFormat);
void setStrType(const QString &_type);
void setType(const FormatterClass _type);
public slots:
virtual void readConfiguration();

View File

@ -28,14 +28,14 @@
#include "awdebug.h"
AWDateTimeFormatter::AWDateTimeFormatter(QWidget *parent,
const QString &filePath)
: AWAbstractFormatter(parent, filePath)
AWDateTimeFormatter::AWDateTimeFormatter(QWidget *_parent,
const QString &_filePath)
: AWAbstractFormatter(_parent, _filePath)
, ui(new Ui::AWDateTimeFormatter)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
@ -109,23 +109,23 @@ void AWDateTimeFormatter::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setFormat(settings.value(QString("X-AW-Format"), format()).toString());
settings.beginGroup("Desktop Entry");
setFormat(settings.value("X-AW-Format", format()).toString());
setTranslateString(
settings.value(QString("X-AW-Translate"), translateString()).toBool());
settings.value("X-AW-Translate", translateString()).toBool());
settings.endGroup();
bumpApi(AW_FORMATTER_API);
}
int AWDateTimeFormatter::showConfiguration(const QVariant &args)
int AWDateTimeFormatter::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("DateTime"));
ui->label_typeValue->setText("DateTime");
ui->lineEdit_format->setText(format());
ui->checkBox_translate->setCheckState(translateString() ? Qt::Checked
: Qt::Unchecked);
@ -152,9 +152,9 @@ void AWDateTimeFormatter::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Format"), format());
settings.setValue(QString("X-AW-Translate"), translateString());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-Format", format());
settings.setValue("X-AW-Translate", translateString());
settings.endGroup();
settings.sync();

View File

@ -35,8 +35,8 @@ class AWDateTimeFormatter : public AWAbstractFormatter
bool translateString READ translateString WRITE setTranslateString)
public:
explicit AWDateTimeFormatter(QWidget *parent,
const QString &filePath = QString());
explicit AWDateTimeFormatter(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~AWDateTimeFormatter();
QString convert(const QVariant &_value) const;
AWDateTimeFormatter *copy(const QString &_fileName, const int _number);
@ -48,7 +48,7 @@ public:
public slots:
void readConfiguration();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private:
@ -57,7 +57,7 @@ private:
void translate();
// properties
QLocale m_locale;
QString m_format = QString();
QString m_format = "";
bool m_translate = true;
};

View File

@ -27,13 +27,13 @@
#include "awdebug.h"
AWFloatFormatter::AWFloatFormatter(QWidget *parent, const QString &filePath)
: AWAbstractFormatter(parent, filePath)
AWFloatFormatter::AWFloatFormatter(QWidget *_parent, const QString &_filePath)
: AWAbstractFormatter(_parent, _filePath)
, ui(new Ui::AWFloatFormatter)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
@ -193,34 +193,30 @@ void AWFloatFormatter::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setCount(settings.value(QString("X-AW-Width"), count()).toInt());
setFillChar(
settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
setForceWidth(
settings.value(QString("X-AW-ForceWidth"), forceWidth()).toBool());
setFormat(settings.value(QString("X-AW-Format"), QString(format()))
settings.beginGroup("Desktop Entry");
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());
setMultiplier(
settings.value(QString("X-AW-Multiplier"), multiplier()).toDouble());
setPrecision(
settings.value(QString("X-AW-Precision"), precision()).toInt());
setSummand(settings.value(QString("X-AW-Summand"), summand()).toDouble());
setMultiplier(settings.value("X-AW-Multiplier", multiplier()).toDouble());
setPrecision(settings.value("X-AW-Precision", precision()).toInt());
setSummand(settings.value("X-AW-Summand", summand()).toDouble());
settings.endGroup();
bumpApi(AW_FORMATTER_API);
}
int AWFloatFormatter::showConfiguration(const QVariant &args)
int AWFloatFormatter::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("Float"));
ui->label_typeValue->setText("Float");
ui->comboBox_format->setCurrentIndex(
ui->comboBox_format->findText(QString(format())));
ui->spinBox_precision->setValue(precision());
@ -258,14 +254,14 @@ void AWFloatFormatter::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Width"), count());
settings.setValue(QString("X-AW-FillChar"), fillChar());
settings.setValue(QString("X-AW-Format"), QString(format()));
settings.setValue(QString("X-AW-ForceWidth"), forceWidth());
settings.setValue(QString("X-AW-Multiplier"), multiplier());
settings.setValue(QString("X-AW-Precision"), precision());
settings.setValue(QString("X-AW-Summand"), summand());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-Width", count());
settings.setValue("X-AW-FillChar", fillChar());
settings.setValue("X-AW-Format", QString(format()));
settings.setValue("X-AW-ForceWidth", forceWidth());
settings.setValue("X-AW-Multiplier", multiplier());
settings.setValue("X-AW-Precision", precision());
settings.setValue("X-AW-Summand", summand());
settings.endGroup();
settings.sync();

View File

@ -38,8 +38,8 @@ class AWFloatFormatter : public AWAbstractFormatter
Q_PROPERTY(double summand READ summand WRITE setSummand)
public:
explicit AWFloatFormatter(QWidget *parent,
const QString &filePath = QString());
explicit AWFloatFormatter(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~AWFloatFormatter();
QString convert(const QVariant &_value) const;
AWFloatFormatter *copy(const QString &_fileName, const int _number);
@ -61,7 +61,7 @@ public:
public slots:
void readConfiguration();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private:

View File

@ -27,13 +27,13 @@
#include "awdebug.h"
AWJsonFormatter::AWJsonFormatter(QWidget *parent, const QString &filePath)
: AWAbstractFormatter(parent, filePath)
AWJsonFormatter::AWJsonFormatter(QWidget *_parent, const QString &_filePath)
: AWAbstractFormatter(_parent, _filePath)
, ui(new Ui::AWJsonFormatter)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
@ -101,8 +101,8 @@ void AWJsonFormatter::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setPath(settings.value(QString("X-AW-Path"), path()).toString());
settings.beginGroup("Desktop Entry");
setPath(settings.value("X-AW-Path", path()).toString());
settings.endGroup();
bumpApi(AW_FORMATTER_API);
@ -115,7 +115,7 @@ int AWJsonFormatter::showConfiguration(const QVariant &args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("Json"));
ui->label_typeValue->setText("Json");
ui->lineEdit_path->setText(path());
int ret = exec();
@ -139,53 +139,52 @@ void AWJsonFormatter::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Path"), path());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-Path", path());
settings.endGroup();
settings.sync();
}
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;
qCDebug(LOG_LIB) << "Looking for element" << _element << "in" << _value;
if (element.type() == QVariant::String) {
return getFromMap(value, element.toString());
} else if (element.type() == QVariant::Int) {
return getFromList(value, element.toInt());
if (_element.type() == QVariant::String) {
return getFromMap(_value, _element.toString());
} else if (_element.type() == QVariant::Int) {
return getFromList(_value, _element.toInt());
} else {
qCWarning(LOG_LIB) << "Unknown type" << element.typeName();
return value;
qCWarning(LOG_LIB) << "Unknown type" << _element.typeName();
return _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;
qCDebug(LOG_LIB) << "Looking for index" << _index << "in" << _value;
return value.toList()[index];
return _value.toList()[_index];
}
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;
qCDebug(LOG_LIB) << "Looking for key" << _key << "in" << _value;
return value.toMap()[key];
return _value.toMap()[_key];
}
void AWJsonFormatter::initPath()
{
m_splittedPath.clear();
QStringList splittedByDot
= m_path.split(QChar('.'), QString::SkipEmptyParts);
QStringList splittedByDot = m_path.split('.', QString::SkipEmptyParts);
for (auto &element : splittedByDot) {
bool ok;

View File

@ -32,8 +32,8 @@ class AWJsonFormatter : public AWAbstractFormatter
Q_PROPERTY(QString path READ path WRITE setPath)
public:
explicit AWJsonFormatter(QWidget *parent,
const QString &filePath = QString());
explicit AWJsonFormatter(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~AWJsonFormatter();
QString convert(const QVariant &_value) const;
AWJsonFormatter *copy(const QString &_fileName, const int _number);
@ -43,14 +43,15 @@ public:
public slots:
void readConfiguration();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private:
Ui::AWJsonFormatter *ui = nullptr;
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;
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();
void translate();
// properties

View File

@ -26,13 +26,13 @@
#include "awdebug.h"
AWListFormatter::AWListFormatter(QWidget *parent, const QString &filePath)
: AWAbstractFormatter(parent, filePath)
AWListFormatter::AWListFormatter(QWidget *_parent, const QString &_filePath)
: AWAbstractFormatter(_parent, _filePath)
, ui(new Ui::AWListFormatter)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
@ -125,24 +125,23 @@ void AWListFormatter::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setFilter(settings.value(QString("X-AW-Filter"), filter()).toString());
setSeparator(
settings.value(QString("X-AW-Separator"), separator()).toString());
setSorted(settings.value(QString("X-AW-Sort"), isSorted()).toBool());
settings.beginGroup("Desktop Entry");
setFilter(settings.value("X-AW-Filter", filter()).toString());
setSeparator(settings.value("X-AW-Separator", separator()).toString());
setSorted(settings.value("X-AW-Sort", isSorted()).toBool());
settings.endGroup();
bumpApi(AW_FORMATTER_API);
}
int AWListFormatter::showConfiguration(const QVariant &args)
int AWListFormatter::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("NoFormat"));
ui->label_typeValue->setText("List");
ui->lineEdit_filter->setText(filter());
ui->lineEdit_separator->setText(separator());
ui->checkBox_sorted->setCheckState(isSorted() ? Qt::Checked
@ -171,10 +170,10 @@ void AWListFormatter::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Filter"), filter());
settings.setValue(QString("X-AW-Separator"), separator());
settings.setValue(QString("X-AW-Sort"), isSorted());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-Filter", filter());
settings.setValue("X-AW-Separator", separator());
settings.setValue("X-AW-Sort", isSorted());
settings.endGroup();
settings.sync();

View File

@ -34,8 +34,8 @@ class AWListFormatter : public AWAbstractFormatter
Q_PROPERTY(bool sorted READ isSorted WRITE setSorted)
public:
explicit AWListFormatter(QWidget *parent,
const QString &filePath = QString());
explicit AWListFormatter(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~AWListFormatter();
QString convert(const QVariant &_value) const;
AWListFormatter *copy(const QString &_fileName, const int _number);
@ -49,15 +49,15 @@ public:
public slots:
void readConfiguration();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private:
Ui::AWListFormatter *ui = nullptr;
void translate();
// properties
QString m_filter = QString();
QString m_separator = QString();
QString m_filter = "";
QString m_separator = "";
bool m_sorted = false;
QRegExp m_regex;
};

View File

@ -24,13 +24,13 @@
#include "awdebug.h"
AWNoFormatter::AWNoFormatter(QWidget *parent, const QString &filePath)
: AWAbstractFormatter(parent, filePath)
AWNoFormatter::AWNoFormatter(QWidget *_parent, const QString &_filePath)
: AWAbstractFormatter(_parent, _filePath)
, ui(new Ui::AWNoFormatter)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
@ -66,13 +66,13 @@ AWNoFormatter *AWNoFormatter::copy(const QString &_fileName, const int _number)
}
int AWNoFormatter::showConfiguration(const QVariant &args)
int AWNoFormatter::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("NoFormat"));
ui->label_typeValue->setText("NoFormat");
int ret = exec();
if (ret != 1)

View File

@ -31,13 +31,14 @@ class AWNoFormatter : public AWAbstractFormatter
Q_OBJECT
public:
explicit AWNoFormatter(QWidget *parent, const QString &filePath = QString());
explicit AWNoFormatter(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~AWNoFormatter();
QString convert(const QVariant &_value) const;
AWNoFormatter *copy(const QString &_fileName, const int _number);
public slots:
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
private:
Ui::AWNoFormatter *ui = nullptr;

View File

@ -28,13 +28,13 @@
#include "awdebug.h"
AWScriptFormatter::AWScriptFormatter(QWidget *parent, const QString &filePath)
: AWAbstractFormatter(parent, filePath)
AWScriptFormatter::AWScriptFormatter(QWidget *_parent, const QString &_filePath)
: AWAbstractFormatter(_parent, _filePath)
, ui(new Ui::AWScriptFormatter)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
@ -63,7 +63,7 @@ QString AWScriptFormatter::convert(const QVariant &_value) const
qCWarning(LOG_LIB) << "Uncaught exception at line"
<< result.property("lineNumber").toInt() << ":"
<< result.toString();
return QString();
return "";
} else {
return result.toString();
}
@ -144,25 +144,23 @@ void AWScriptFormatter::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setAppendCode(
settings.value(QString("X-AW-AppendCode"), appendCode()).toBool());
setCode(settings.value(QString("X-AW-Code"), code()).toString());
setHasReturn(
settings.value(QString("X-AW-HasReturn"), hasReturn()).toBool());
settings.beginGroup("Desktop Entry");
setAppendCode(settings.value("X-AW-AppendCode", appendCode()).toBool());
setCode(settings.value("X-AW-Code", code()).toString());
setHasReturn(settings.value("X-AW-HasReturn", hasReturn()).toBool());
settings.endGroup();
bumpApi(AW_FORMATTER_API);
}
int AWScriptFormatter::showConfiguration(const QVariant &args)
int AWScriptFormatter::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("Script"));
ui->label_typeValue->setText("Script");
ui->checkBox_appendCode->setCheckState(appendCode() ? Qt::Checked
: Qt::Unchecked);
ui->checkBox_hasReturn->setCheckState(hasReturn() ? Qt::Checked
@ -193,10 +191,10 @@ void AWScriptFormatter::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-AppendCode"), appendCode());
settings.setValue(QString("X-AW-Code"), code());
settings.setValue(QString("X-AW-HasReturn"), hasReturn());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-AppendCode", appendCode());
settings.setValue("X-AW-Code", code());
settings.setValue("X-AW-HasReturn", hasReturn());
settings.endGroup();
settings.sync();
@ -207,10 +205,9 @@ void AWScriptFormatter::initProgram()
{
// init JS code
if (appendCode())
m_program
= QString("(function(value) { %1%2 })")
.arg(code())
.arg(hasReturn() ? QString("") : QString("; return output;"));
m_program = QString("(function(value) { %1%2 })")
.arg(code())
.arg(hasReturn() ? "" : "; return output;");
else
m_program = code();

View File

@ -35,8 +35,8 @@ class AWScriptFormatter : public AWAbstractFormatter
Q_PROPERTY(QString program READ program)
public:
explicit AWScriptFormatter(QWidget *parent,
const QString &filePath = QString());
explicit AWScriptFormatter(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~AWScriptFormatter();
QString convert(const QVariant &_value) const;
AWScriptFormatter *copy(const QString &_fileName, const int _number);
@ -51,7 +51,7 @@ public:
public slots:
void readConfiguration();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private:
@ -60,7 +60,7 @@ private:
void translate();
// properties
bool m_appendCode = true;
QString m_code = QString();
QString m_code = "";
bool m_hasReturn = false;
QString m_program;
};

View File

@ -27,13 +27,13 @@
#include "awdebug.h"
AWStringFormatter::AWStringFormatter(QWidget *parent, const QString &filePath)
: AWAbstractFormatter(parent, filePath)
AWStringFormatter::AWStringFormatter(QWidget *_parent, const QString &_filePath)
: AWAbstractFormatter(_parent, _filePath)
, ui(new Ui::AWStringFormatter)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
@ -125,25 +125,23 @@ void AWStringFormatter::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setCount(settings.value(QString("X-AW-Width"), count()).toInt());
setFillChar(
settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
setForceWidth(
settings.value(QString("X-AW-ForceWidth"), forceWidth()).toBool());
settings.beginGroup("Desktop Entry");
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());
settings.endGroup();
bumpApi(AW_FORMATTER_API);
}
int AWStringFormatter::showConfiguration(const QVariant &args)
int AWStringFormatter::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("String"));
ui->label_typeValue->setText("String");
ui->spinBox_width->setValue(count());
ui->lineEdit_fill->setText(QString(fillChar()));
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
@ -172,10 +170,10 @@ void AWStringFormatter::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Width"), count());
settings.setValue(QString("X-AW-FillChar"), fillChar());
settings.setValue(QString("X-AW-ForceWidth"), forceWidth());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-Width", count());
settings.setValue("X-AW-FillChar", fillChar());
settings.setValue("X-AW-ForceWidth", forceWidth());
settings.endGroup();
settings.sync();

View File

@ -34,8 +34,8 @@ class AWStringFormatter : public AWAbstractFormatter
Q_PROPERTY(bool forceWidth READ forceWidth WRITE setForceWidth)
public:
explicit AWStringFormatter(QWidget *parent,
const QString &filePath = QString());
explicit AWStringFormatter(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~AWStringFormatter();
QString convert(const QVariant &_value) const;
AWStringFormatter *copy(const QString &_fileName, const int _number);
@ -49,7 +49,7 @@ public:
public slots:
void readConfiguration();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private:

View File

@ -31,15 +31,15 @@
template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
{
public:
explicit ExtItemAggregator(QWidget *parent, const QString &type)
: AbstractExtItemAggregator(parent, type)
explicit ExtItemAggregator(QWidget *_parent, const QString &_type)
: AbstractExtItemAggregator(_parent, _type)
{
qSetMessagePattern(AWDebug::LOG_FORMAT);
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
for (auto &metadata : AWDebug::getBuildData())
qCDebug(LOG_LIB) << metadata;
qCDebug(LOG_LIB) << "Type" << type;
qCDebug(LOG_LIB) << "Type" << _type;
initItems();
};
@ -132,8 +132,7 @@ private:
for (auto &dir : dirs) {
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
for (auto &file : files) {
if ((!file.endsWith(QString(".desktop")))
|| (names.contains(file)))
if ((!file.endsWith(".desktop")) || (names.contains(file)))
continue;
qCInfo(LOG_LIB) << "Found file" << file << "in" << dir;
names.append(file);

View File

@ -31,18 +31,18 @@
#include "awdebug.h"
ExtNetworkRequest::ExtNetworkRequest(QWidget *parent, const QString &filePath)
: AbstractExtItem(parent, filePath)
ExtNetworkRequest::ExtNetworkRequest(QWidget *_parent, const QString &_filePath)
: AbstractExtItem(_parent, _filePath)
, ui(new Ui::ExtNetworkRequest)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
m_values[tag(QString("response"))] = QString();
m_values[tag("response")] = "";
// HACK declare as child of nullptr to avoid crash with plasmawindowed
// in the destructor
@ -109,8 +109,8 @@ void ExtNetworkRequest::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setStringUrl(settings.value(QString("X-AW-Url"), stringUrl()).toString());
settings.beginGroup("Desktop Entry");
setStringUrl(settings.value("X-AW-Url", stringUrl()).toString());
settings.endGroup();
bumpApi(AW_EXTNETREQUEST_API);
@ -127,9 +127,9 @@ QVariantHash ExtNetworkRequest::run()
}
int ExtNetworkRequest::showConfiguration(const QVariant &args)
int ExtNetworkRequest::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
@ -166,24 +166,24 @@ void ExtNetworkRequest::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Url"), stringUrl());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-Url", stringUrl());
settings.endGroup();
settings.sync();
}
void ExtNetworkRequest::networkReplyReceived(QNetworkReply *reply)
void ExtNetworkRequest::networkReplyReceived(QNetworkReply *_reply)
{
if (reply->error() != QNetworkReply::NoError) {
qCWarning(LOG_AW) << "An error occurs" << reply->error()
<< "with message" << reply->errorString();
if (_reply->error() != QNetworkReply::NoError) {
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
<< "with message" << _reply->errorString();
return;
}
m_isRunning = false;
m_values[tag(QString("response"))]
= QTextCodec::codecForMib(106)->toUnicode(reply->readAll()).trimmed();
m_values[tag("response")]
= QTextCodec::codecForMib(106)->toUnicode(_reply->readAll()).trimmed();
emit(dataReceived(m_values));
}

View File

@ -34,24 +34,24 @@ class ExtNetworkRequest : public AbstractExtItem
Q_PROPERTY(QString stringUrl READ stringUrl WRITE setStringUrl)
public:
explicit ExtNetworkRequest(QWidget *parent,
const QString &filePath = QString());
explicit ExtNetworkRequest(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~ExtNetworkRequest();
ExtNetworkRequest *copy(const QString &_fileName, const int _number);
// get methods
QString stringUrl() const;
QString uniq() const;
// set methods
void setStringUrl(const QString &_url = QString("https://httpbin.org/get"));
void setStringUrl(const QString &_url);
public slots:
void readConfiguration();
QVariantHash run();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private slots:
void networkReplyReceived(QNetworkReply *reply);
void networkReplyReceived(QNetworkReply *_reply);
void sendRequest();
private:
@ -62,9 +62,8 @@ private:
void initUrl();
void translate();
// properties
QString m_stringUrl = QString("https://httpbin.org/get");
QString m_stringUrl = "https://httpbin.org/get";
// values
int m_times = 0;
QVariantHash m_values;
};

View File

@ -33,26 +33,26 @@
#include "awdebug.h"
ExtQuotes::ExtQuotes(QWidget *parent, const QString &filePath)
: AbstractExtItem(parent, filePath)
ExtQuotes::ExtQuotes(QWidget *_parent, const QString &_filePath)
: AbstractExtItem(_parent, _filePath)
, ui(new Ui::ExtQuotes)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
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;
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;
// HACK declare as child of nullptr to avoid crash with plasmawindowed
// in the destructor
@ -118,8 +118,8 @@ void ExtQuotes::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setTicker(settings.value(QString("X-AW-Ticker"), ticker()).toString());
settings.beginGroup("Desktop Entry");
setTicker(settings.value("X-AW-Ticker", ticker()).toString());
settings.endGroup();
bumpApi(AW_EXTQUOTES_API);
@ -136,9 +136,9 @@ QVariantHash ExtQuotes::run()
}
int ExtQuotes::showConfiguration(const QVariant &args)
int ExtQuotes::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
@ -175,67 +175,59 @@ void ExtQuotes::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Ticker"), ticker());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-Ticker", ticker());
settings.endGroup();
settings.sync();
}
void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
void ExtQuotes::quotesReplyReceived(QNetworkReply *_reply)
{
if (reply->error() != QNetworkReply::NoError) {
qCWarning(LOG_AW) << "An error occurs" << reply->error()
<< "with message" << reply->errorString();
if (_reply->error() != QNetworkReply::NoError) {
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);
reply->deleteLater();
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
_reply->deleteLater();
if (error.error != QJsonParseError::NoError) {
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
return;
}
QVariantMap jsonQuotes
= jsonDoc.toVariant().toMap()[QString("query")].toMap();
jsonQuotes
= jsonQuotes[QString("results")].toMap()[QString("quote")].toMap();
QVariantMap jsonQuotes = jsonDoc.toVariant().toMap()["query"].toMap();
jsonQuotes = jsonQuotes["results"].toMap()["quote"].toMap();
double value;
// ask
value = jsonQuotes[QString("Ask")].toString().toDouble();
m_values[tag(QString("askchg"))]
= m_values[tag(QString("ask"))].toDouble() == 0.0
? 0.0
: 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;
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[QString("Bid")].toString().toDouble();
m_values[tag(QString("bidchg"))]
= m_values[tag(QString("bid"))].toDouble() == 0.0
? 0.0
: 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;
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[QString("LastTradePriceOnly")].toString().toDouble();
m_values[tag(QString("pricechg"))]
= m_values[tag(QString("price"))].toDouble() == 0.0
? 0.0
: 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;
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;
emit(dataReceived(m_values));
}
@ -254,11 +246,9 @@ void ExtQuotes::initUrl()
// init query
m_url = QUrl(YAHOO_QUOTES_URL);
QUrlQuery params;
params.addQueryItem(QString("format"), QString("json"));
params.addQueryItem(QString("env"),
QString("store://datatables.org/alltableswithkeys"));
params.addQueryItem(QString("q"),
QString(YAHOO_QUOTES_QUERY).arg(ticker()));
params.addQueryItem("format", "json");
params.addQueryItem("env", "store://datatables.org/alltableswithkeys");
params.addQueryItem("q", QString(YAHOO_QUOTES_QUERY).arg(ticker()));
m_url.setQuery(params);
}

View File

@ -38,23 +38,24 @@ public:
const char *YAHOO_QUOTES_QUERY
= "select * from yahoo.finance.quotes where symbol='%1'";
explicit ExtQuotes(QWidget *parent, const QString &filePath = QString());
explicit ExtQuotes(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~ExtQuotes();
ExtQuotes *copy(const QString &_fileName, const int _number);
// get methods
QString ticker() const;
QString uniq() const;
// set methods
void setTicker(const QString &_ticker = QString("EURUSD=X"));
void setTicker(const QString &_ticker);
public slots:
void readConfiguration();
QVariantHash run();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private slots:
void quotesReplyReceived(QNetworkReply *reply);
void quotesReplyReceived(QNetworkReply *_reply);
void sendRequest();
private:
@ -65,9 +66,8 @@ private:
void initUrl();
void translate();
// properties
QString m_ticker = QString("EURUSD=X");
QString m_ticker = "EURUSD=X";
// values
int m_times = 0;
QVariantHash m_values;
};

View File

@ -30,19 +30,19 @@
#include "awdebug.h"
ExtScript::ExtScript(QWidget *parent, const QString &filePath)
: AbstractExtItem(parent, filePath)
ExtScript::ExtScript(QWidget *_parent, const QString &_filePath)
: AbstractExtItem(_parent, _filePath)
, ui(new Ui::ExtScript)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
readJsonFilters();
ui->setupUi(this);
translate();
m_values[tag(QString("custom"))] = QString("");
m_values[tag("custom")] = "";
m_process = new QProcess(nullptr);
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
@ -87,8 +87,7 @@ QString ExtScript::jsonFiltersFile() const
{
QString fileName = QStandardPaths::locate(
QStandardPaths::GenericDataLocation,
QString(
"awesomewidgets/scripts/awesomewidgets-extscripts-filters.json"));
"awesomewidgets/scripts/awesomewidgets-extscripts-filters.json");
qCInfo(LOG_LIB) << "Filters file" << fileName;
return fileName;
@ -130,16 +129,16 @@ QString ExtScript::strRedirect() const
QString value;
switch (redirect()) {
case Redirect::stdout2stderr:
value = QString("stdout2stderr");
value = "stdout2stderr";
break;
case Redirect::stderr2stdout:
value = QString("stderr2stdout");
value = "stderr2stdout";
break;
case Redirect::swap:
value = QString("swap");
value = "swap";
break;
case Redirect::nothing:
value = QString("nothing");
value = "nothing";
break;
}
@ -159,8 +158,9 @@ void ExtScript::setFilters(const QStringList &_filters)
{
qCDebug(LOG_LIB) << "Filters" << _filters;
std::for_each(_filters.cbegin(), _filters.cend(),
[this](QString filter) { return updateFilter(filter); });
std::for_each(
_filters.cbegin(), _filters.cend(),
[this](const QString &filter) { return updateFilter(filter, true); });
}
@ -184,11 +184,11 @@ void ExtScript::setStrRedirect(const QString &_redirect)
{
qCDebug(LOG_LIB) << "Redirect" << _redirect;
if (_redirect == QString("stdout2sdterr"))
if (_redirect == "stdout2sdterr")
setRedirect(Redirect::stdout2stderr);
else if (_redirect == QString("stderr2sdtout"))
else if (_redirect == "stderr2sdtout")
setRedirect(Redirect::stderr2stdout);
else if (_redirect == QString("swap"))
else if (_redirect == "swap")
setRedirect(Redirect::swap);
else
setRedirect(Redirect::nothing);
@ -235,15 +235,14 @@ void ExtScript::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setExecutable(settings.value(QString("Exec"), executable()).toString());
setPrefix(settings.value(QString("X-AW-Prefix"), prefix()).toString());
setStrRedirect(
settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
settings.beginGroup("Desktop Entry");
setExecutable(settings.value("Exec", executable()).toString());
setPrefix(settings.value("X-AW-Prefix", prefix()).toString());
setStrRedirect(settings.value("X-AW-Redirect", strRedirect()).toString());
// api == 3
setFilters(settings.value(QString("X-AW-Filters"), filters())
setFilters(settings.value("X-AW-Filters", filters())
.toString()
.split(QChar(','), QString::SkipEmptyParts));
.split(',', QString::SkipEmptyParts));
settings.endGroup();
bumpApi(AW_EXTSCRIPT_API);
@ -283,9 +282,9 @@ QVariantHash ExtScript::run()
}
int ExtScript::showConfiguration(const QVariant &args)
int ExtScript::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
@ -300,11 +299,11 @@ int ExtScript::showConfiguration(const QVariant &args)
ui->spinBox_interval->setValue(interval());
// filters
ui->checkBox_colorFilter->setCheckState(
filters().contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
filters().contains("color") ? Qt::Checked : Qt::Unchecked);
ui->checkBox_linesFilter->setCheckState(
filters().contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
filters().contains("newline") ? Qt::Checked : Qt::Unchecked);
ui->checkBox_spaceFilter->setCheckState(
filters().contains(QString("space")) ? Qt::Checked : Qt::Unchecked);
filters().contains("space") ? Qt::Checked : Qt::Unchecked);
int ret = exec();
if (ret != 1)
@ -321,11 +320,11 @@ int ExtScript::showConfiguration(const QVariant &args)
setSocket(ui->lineEdit_socket->text());
setInterval(ui->spinBox_interval->value());
// filters
updateFilter(QString("color"),
updateFilter("color",
ui->checkBox_colorFilter->checkState() == Qt::Checked);
updateFilter(QString("newline"),
updateFilter("newline",
ui->checkBox_linesFilter->checkState() == Qt::Checked);
updateFilter(QString("space"),
updateFilter("space",
ui->checkBox_spaceFilter->checkState() == Qt::Checked);
writeConfiguration();
@ -340,11 +339,11 @@ void ExtScript::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Exec"), executable());
settings.setValue(QString("X-AW-Prefix"), prefix());
settings.setValue(QString("X-AW-Redirect"), strRedirect());
settings.setValue(QString("X-AW-Filters"), filters().join(QChar(',')));
settings.beginGroup("Desktop Entry");
settings.setValue("Exec", executable());
settings.setValue("X-AW-Prefix", prefix());
settings.setValue("X-AW-Redirect", strRedirect());
settings.setValue("X-AW-Filters", filters().join(','));
settings.endGroup();
settings.sync();
@ -357,8 +356,8 @@ void ExtScript::startProcess()
if (!prefix().isEmpty())
cmdList.append(prefix());
cmdList.append(executable());
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' '));
m_process->start(cmdList.join(QChar(' ')));
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(' ');
m_process->start(cmdList.join(' '));
}
@ -390,7 +389,7 @@ void ExtScript::updateValue()
}
// filters
m_values[tag(QString("custom"))] = applyFilters(strValue);
m_values[tag("custom")] = applyFilters(strValue);
emit(dataReceived(m_values));
}

View File

@ -44,7 +44,8 @@ public:
swap = 3
};
explicit ExtScript(QWidget *parent, const QString &filePath = QString());
explicit ExtScript(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~ExtScript();
ExtScript *copy(const QString &_fileName, const int _number);
QString jsonFiltersFile() const;
@ -57,20 +58,20 @@ public:
// derivatives
QString strRedirect() const;
// set methods
void setExecutable(const QString &_executable = QString("/usr/bin/true"));
void setFilters(const QStringList &_filters = QStringList());
void setPrefix(const QString &_prefix = QString(""));
void setRedirect(const Redirect _redirect = Redirect::nothing);
void setStrRedirect(const QString &_redirect = QString("nothing"));
void setExecutable(const QString &_executable);
void setFilters(const QStringList &_filters);
void setPrefix(const QString &_prefix);
void setRedirect(const Redirect _redirect);
void setStrRedirect(const QString &_redirect);
// filters
QString applyFilters(QString _value) const;
void updateFilter(const QString &_filter, const bool _add = true);
void updateFilter(const QString &_filter, const bool _add);
public slots:
void readConfiguration();
void readJsonFilters();
QVariantHash run();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private slots:
@ -82,13 +83,12 @@ private:
Ui::ExtScript *ui = nullptr;
void translate();
// properties
QString m_executable = QString("/usr/bin/true");
QString m_executable = "/usr/bin/true";
QStringList m_filters = QStringList();
QString m_prefix = QString("");
QString m_prefix = "";
Redirect m_redirect = Redirect::nothing;
// internal properties
QVariantMap m_jsonFilters = QVariantMap();
int m_times = 0;
QVariantMap m_jsonFilters;
QVariantHash m_values;
};

View File

@ -28,18 +28,18 @@
#include "awdebug.h"
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString &filePath)
: AbstractExtItem(parent, filePath)
ExtUpgrade::ExtUpgrade(QWidget *_parent, const QString &_filePath)
: AbstractExtItem(_parent, _filePath)
, ui(new Ui::ExtUpgrade)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
m_values[tag(QString("pkgcount"))] = 0;
m_values[tag("pkgcount")] = 0;
m_process = new QProcess(nullptr);
connect(m_process, SIGNAL(finished(int)), this, SLOT(updateValue()));
@ -132,11 +132,11 @@ void ExtUpgrade::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setExecutable(settings.value(QString("Exec"), executable()).toString());
setNull(settings.value(QString("X-AW-Null"), null()).toInt());
settings.beginGroup("Desktop Entry");
setExecutable(settings.value("Exec", executable()).toString());
setNull(settings.value("X-AW-Null", null()).toInt());
// api == 3
setFilter(settings.value(QString("X-AW-Filter"), filter()).toString());
setFilter(settings.value("X-AW-Filter", filter()).toString());
settings.endGroup();
bumpApi(AW_EXTUPGRADE_API);
@ -153,9 +153,9 @@ QVariantHash ExtUpgrade::run()
}
int ExtUpgrade::showConfiguration(const QVariant &args)
int ExtUpgrade::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
@ -196,10 +196,10 @@ void ExtUpgrade::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Exec"), executable());
settings.setValue(QString("X-AW-Filter"), filter());
settings.setValue(QString("X-AW-Null"), null());
settings.beginGroup("Desktop Entry");
settings.setValue("Exec", executable());
settings.setValue("X-AW-Filter", filter());
settings.setValue("X-AW-Null", null());
settings.endGroup();
settings.sync();
@ -222,11 +222,11 @@ void ExtUpgrade::updateValue()
QString qoutput = QTextCodec::codecForMib(106)
->toUnicode(m_process->readAllStandardOutput())
.trimmed();
m_values[tag(QString("pkgcount"))] = [this](QString output) {
m_values[tag("pkgcount")] = [this](QString output) {
return filter().isEmpty()
? output.split(QChar('\n'), QString::SkipEmptyParts).count()
? output.split('\n', QString::SkipEmptyParts).count()
- null()
: output.split(QChar('\n'), QString::SkipEmptyParts)
: output.split('\n', QString::SkipEmptyParts)
.filter(QRegExp(filter()))
.count();
}(qoutput);

View File

@ -36,7 +36,8 @@ class ExtUpgrade : public AbstractExtItem
Q_PROPERTY(int null READ null WRITE setNull)
public:
explicit ExtUpgrade(QWidget *parent, const QString &filePath = QString());
explicit ExtUpgrade(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~ExtUpgrade();
ExtUpgrade *copy(const QString &_fileName, const int _number);
// get methods
@ -45,14 +46,14 @@ public:
int null() const;
QString uniq() const;
// set methods
void setExecutable(const QString &_executable = QString("/usr/bin/true"));
void setFilter(const QString &_filter = QString());
void setNull(const int _null = 0);
void setExecutable(const QString &_executable);
void setFilter(const QString &_filter);
void setNull(const int _null);
public slots:
void readConfiguration();
QVariantHash run();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private slots:
@ -64,11 +65,10 @@ private:
Ui::ExtUpgrade *ui = nullptr;
void translate();
// properties
QString m_executable = QString("/usr/bin/true");
QString m_filter = QString("");
QString m_executable = "/usr/bin/true";
QString m_filter = "";
int m_null = 0;
// internal properties
int m_times = 0;
QVariantHash m_values;
};

View File

@ -35,23 +35,23 @@
#include "yahooweatherprovider.h"
ExtWeather::ExtWeather(QWidget *parent, const QString &filePath)
: AbstractExtItem(parent, filePath)
ExtWeather::ExtWeather(QWidget *_parent, const QString &_filePath)
: AbstractExtItem(_parent, _filePath)
, ui(new Ui::ExtWeather)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
readJsonMap();
ui->setupUi(this);
translate();
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;
m_values[tag("weatherId")] = 0;
m_values[tag("weather")] = "";
m_values[tag("humidity")] = 0;
m_values[tag("pressure")] = 0.0;
m_values[tag("temperature")] = 0.0;
// HACK declare as child of nullptr to avoid crash with plasmawindowed
// in the destructor
@ -99,7 +99,7 @@ QString ExtWeather::jsonMapFile() const
{
QString fileName = QStandardPaths::locate(
QStandardPaths::GenericDataLocation,
QString("awesomewidgets/weather/awesomewidgets-extweather-ids.json"));
"awesomewidgets/weather/awesomewidgets-extweather-ids.json");
qCInfo(LOG_LIB) << "Map file" << fileName;
return fileName;
@ -110,9 +110,8 @@ QString ExtWeather::weatherFromInt(const int _id) const
{
qCDebug(LOG_LIB) << "Weather ID" << _id;
QVariantMap map
= m_jsonMap[m_image ? QString("image") : QString("text")].toMap();
return map.value(QString::number(_id), map[QString("default")]).toString();
QVariantMap map = m_jsonMap[m_image ? "image" : "text"].toMap();
return map.value(QString::number(_id), map["default"]).toString();
}
@ -145,10 +144,10 @@ QString ExtWeather::strProvider() const
QString value;
switch (m_provider) {
case Provider::OWM:
value = QString("OWM");
value = "OWM";
break;
case Provider::Yahoo:
value = QString("Yahoo");
value = "Yahoo";
break;
}
@ -207,7 +206,7 @@ void ExtWeather::setStrProvider(const QString &_provider)
{
qCDebug(LOG_LIB) << "Provider" << _provider;
if (_provider == QString("Yahoo"))
if (_provider == "Yahoo")
setProvider(Provider::Yahoo);
else
setProvider(Provider::OWM);
@ -229,16 +228,14 @@ void ExtWeather::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setCity(settings.value(QString("X-AW-City"), city()).toString());
setCountry(settings.value(QString("X-AW-Country"), country()).toString());
setTs(settings.value(QString("X-AW-TS"), ts()).toInt());
settings.beginGroup("Desktop Entry");
setCity(settings.value("X-AW-City", city()).toString());
setCountry(settings.value("X-AW-Country", country()).toString());
setTs(settings.value("X-AW-TS", ts()).toInt());
// api == 2
setImage(settings.value(QString("X-AW-Image"), QVariant(image())).toString()
== QString("true"));
setImage(settings.value("X-AW-Image", image()).toBool());
// api == 3
setStrProvider(
settings.value(QString("X-AW-Provider"), strProvider()).toString());
setStrProvider(settings.value("X-AW-Provider", strProvider()).toString());
settings.endGroup();
bumpApi(AW_EXTWEATHER_API);
@ -278,9 +275,9 @@ QVariantHash ExtWeather::run()
}
int ExtWeather::showConfiguration(const QVariant &args)
int ExtWeather::showConfiguration(const QVariant &_args)
{
Q_UNUSED(args)
Q_UNUSED(_args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
@ -325,12 +322,12 @@ void ExtWeather::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-City"), city());
settings.setValue(QString("X-AW-Country"), country());
settings.setValue(QString("X-AW-Image"), image());
settings.setValue(QString("X-AW-Provider"), strProvider());
settings.setValue(QString("X-AW-TS"), ts());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-City", city());
settings.setValue("X-AW-Country", country());
settings.setValue("X-AW-Image", image());
settings.setValue("X-AW-Provider", strProvider());
settings.setValue("X-AW-TS", ts());
settings.endGroup();
settings.sync();
@ -346,18 +343,18 @@ void ExtWeather::sendRequest()
}
void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
void ExtWeather::weatherReplyReceived(QNetworkReply *_reply)
{
if (reply->error() != QNetworkReply::NoError) {
qCWarning(LOG_AW) << "An error occurs" << reply->error()
<< "with message" << reply->errorString();
if (_reply->error() != QNetworkReply::NoError) {
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);
reply->deleteLater();
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
_reply->deleteLater();
if (error.error != QJsonParseError::NoError) {
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
return;
@ -367,8 +364,8 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
if (data.isEmpty())
return;
m_values = data;
m_values[tag(QString("weather"))]
= weatherFromInt(m_values[tag(QString("weatherId"))].toInt());
m_values[tag("weather")]
= weatherFromInt(m_values[tag("weatherId")].toInt());
emit(dataReceived(m_values));
}

View File

@ -42,7 +42,8 @@ class ExtWeather : public AbstractExtItem
public:
enum class Provider { OWM = 0, Yahoo = 1 };
explicit ExtWeather(QWidget *parent, const QString &filePath = QString());
explicit ExtWeather(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~ExtWeather();
ExtWeather *copy(const QString &_fileName, const int _number);
QString jsonMapFile() const;
@ -56,23 +57,23 @@ public:
int ts() const;
QString uniq() const;
// set methods
void setCity(const QString &_city = QString("London"));
void setCountry(const QString &_country = QString("uk"));
void setImage(const bool _image = false);
void setProvider(const Provider _provider = Provider::OWM);
void setStrProvider(const QString &_provider = QString("OWM"));
void setTs(const int _ts = 0);
void setCity(const QString &_city);
void setCountry(const QString &_country);
void setImage(const bool _image);
void setProvider(const Provider _provider);
void setStrProvider(const QString &_provider);
void setTs(const int _ts);
public slots:
void readConfiguration();
void readJsonMap();
QVariantHash run();
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private slots:
void sendRequest();
void weatherReplyReceived(QNetworkReply *reply);
void weatherReplyReceived(QNetworkReply *_reply);
private:
QNetworkAccessManager *m_manager = nullptr;
@ -82,14 +83,13 @@ private:
void initProvider();
void translate();
// properties
QString m_city = QString("London");
QString m_country = QString("uk");
QString m_city = "London";
QString m_country = "uk";
bool m_image = false;
Provider m_provider = Provider::OWM;
int m_ts = 0;
QVariantMap m_jsonMap = QVariantMap();
QVariantMap m_jsonMap;
// values
int m_times = 0;
QVariantHash m_values;
};

View File

@ -32,13 +32,13 @@
#include "graphicalitemhelper.h"
GraphicalItem::GraphicalItem(QWidget *parent, const QString &filePath)
: AbstractExtItem(parent, filePath)
GraphicalItem::GraphicalItem(QWidget *_parent, const QString &_filePath)
: AbstractExtItem(_parent, _filePath)
, ui(new Ui::GraphicalItem)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
if (!filePath.isEmpty())
if (!_filePath.isEmpty())
readConfiguration();
ui->setupUi(this);
translate();
@ -150,7 +150,7 @@ void GraphicalItem::initScene()
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
// init view
m_view = new QGraphicsView(m_scene);
m_view->setStyleSheet(QString("background: transparent"));
m_view->setStyleSheet("background: transparent");
m_view->setContentsMargins(0, 0, 0, 0);
m_view->setFrameShape(QFrame::NoFrame);
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@ -229,19 +229,19 @@ QString GraphicalItem::strType() const
QString value;
switch (type()) {
case Type::Vertical:
value = QString("Vertical");
value = "Vertical";
break;
case Type::Circle:
value = QString("Circle");
value = "Circle";
break;
case Type::Graph:
value = QString("Graph");
value = "Graph";
break;
case Type::Bars:
value = QString("Bars");
value = "Bars";
break;
case Type::Horizontal:
value = QString("Horizontal");
value = "Horizontal";
break;
}
@ -260,10 +260,10 @@ QString GraphicalItem::strDirection() const
QString value;
switch (direction()) {
case Direction::RightToLeft:
value = QString("RightToLeft");
value = "RightToLeft";
break;
case Direction::LeftToRight:
value = QString("LeftToRight");
value = "LeftToRight";
break;
}
@ -373,13 +373,13 @@ void GraphicalItem::setStrType(const QString &_type)
{
qCDebug(LOG_LIB) << "Type" << _type;
if (_type == QString("Vertical"))
if (_type == "Vertical")
setType(Type::Vertical);
else if (_type == QString("Circle"))
else if (_type == "Circle")
setType(Type::Circle);
else if (_type == QString("Graph"))
else if (_type == "Graph")
setType(Type::Graph);
else if (_type == QString("Bars"))
else if (_type == "Bars")
setType(Type::Bars);
else
setType(Type::Horizontal);
@ -398,7 +398,7 @@ void GraphicalItem::setStrDirection(const QString &_direction)
{
qCDebug(LOG_LIB) << "Direction" << _direction;
if (_direction == QString("RightToLeft"))
if (_direction == "RightToLeft")
setDirection(Direction::RightToLeft);
else
setDirection(Direction::LeftToRight);
@ -426,31 +426,29 @@ void GraphicalItem::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setCount(settings.value(QString("X-AW-Count"), count()).toInt());
setCustom(settings.value(QString("X-AW-Custom"), isCustom()).toBool());
setBar(settings.value(QString("X-AW-Value"), bar()).toString());
setMaxValue(settings.value(QString("X-AW-Max"), maxValue()).toFloat());
setMinValue(settings.value(QString("X-AW-Min"), minValue()).toFloat());
settings.beginGroup("Desktop Entry");
setCount(settings.value("X-AW-Count", count()).toInt());
setCustom(settings.value("X-AW-Custom", isCustom()).toBool());
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(QString("X-AW-ActiveColor"), activeColor()).toString());
settings.value("X-AW-ActiveColor", activeColor()).toString());
setInactiveColor(
settings.value(QString("X-AW-InactiveColor"), inactiveColor())
.toString());
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
settings.value("X-AW-InactiveColor", inactiveColor()).toString());
setStrType(settings.value("X-AW-Type", strType()).toString());
setStrDirection(
settings.value(QString("X-AW-Direction"), strDirection()).toString());
setItemHeight(settings.value(QString("X-AW-Height"), itemHeight()).toInt());
setItemWidth(settings.value(QString("X-AW-Width"), itemWidth()).toInt());
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("/")) ? QString("file://%1")
: QString("color://%1");
prefix = activeColor().startsWith("/") ? QString("file://%1")
: QString("color://%1");
m_activeColor = prefix.arg(activeColor());
prefix = inactiveColor().startsWith(QString("/"))
? QString("file://%1")
: QString("color://%1");
prefix = inactiveColor().startsWith("/") ? QString("file://%1")
: QString("color://%1");
m_inactiveColor = prefix.arg(inactiveColor());
}
settings.endGroup();
@ -460,10 +458,10 @@ void GraphicalItem::readConfiguration()
}
int GraphicalItem::showConfiguration(const QVariant &args)
int GraphicalItem::showConfiguration(const QVariant &_args)
{
qCDebug(LOG_LIB) << "Combobox arguments" << args;
QStringList tags = args.toStringList();
qCDebug(LOG_LIB) << "Combobox arguments" << _args;
QStringList tags = _args.toStringList();
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
@ -531,18 +529,18 @@ void GraphicalItem::writeConfiguration() const
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Value"), bar());
settings.setValue(QString("X-AW-Count"), count());
settings.setValue(QString("X-AW-Custom"), isCustom());
settings.setValue(QString("X-AW-Max"), maxValue());
settings.setValue(QString("X-AW-Min"), minValue());
settings.setValue(QString("X-AW-ActiveColor"), activeColor());
settings.setValue(QString("X-AW-InactiveColor"), inactiveColor());
settings.setValue(QString("X-AW-Type"), strType());
settings.setValue(QString("X-AW-Direction"), strDirection());
settings.setValue(QString("X-AW-Height"), itemHeight());
settings.setValue(QString("X-AW-Width"), itemWidth());
settings.beginGroup("Desktop Entry");
settings.setValue("X-AW-Value", bar());
settings.setValue("X-AW-Count", count());
settings.setValue("X-AW-Custom", isCustom());
settings.setValue("X-AW-Max", maxValue());
settings.setValue("X-AW-Min", minValue());
settings.setValue("X-AW-ActiveColor", activeColor());
settings.setValue("X-AW-InactiveColor", inactiveColor());
settings.setValue("X-AW-Type", strType());
settings.setValue("X-AW-Direction", strDirection());
settings.setValue("X-AW-Height", itemHeight());
settings.setValue("X-AW-Width", itemWidth());
settings.endGroup();
settings.sync();
@ -566,7 +564,7 @@ void GraphicalItem::changeColor()
if (state == 0) {
QColor color = m_helper->stringToColor(lineEdit->text());
QColor newColor = QColorDialog::getColor(
color, this, tr("Select color"), QColorDialog::ShowAlphaChannel);
color, this, i18n("Select color"), QColorDialog::ShowAlphaChannel);
if (!newColor.isValid())
return;
qCInfo(LOG_LIB) << "Selected color" << newColor;
@ -577,13 +575,13 @@ void GraphicalItem::changeColor()
colorText.append(QString("%1").arg(newColor.blue()));
colorText.append(QString("%1").arg(newColor.alpha()));
outputColor = QString("color://%1").arg(colorText.join(QChar(',')));
outputColor = QString("color://%1").arg(colorText.join(','));
} else if (state == 1) {
QString path = lineEdit->text();
QString directory = QFileInfo(path).absolutePath();
outputColor = QFileDialog::getOpenFileUrl(
this, tr("Select path"), directory,
tr("Images (*.png *.bpm *.jpg);;All files (*.*)"))
this, i18n("Select path"), directory,
i18n("Images (*.png *.bpm *.jpg);;All files (*.*)"))
.toString();
qCInfo(LOG_LIB) << "Selected path" << outputColor;
@ -597,21 +595,21 @@ void GraphicalItem::changeColor()
}
void GraphicalItem::changeCountState(const int state)
void GraphicalItem::changeCountState(const int _state)
{
qCDebug(LOG_LIB) << "Current state is" << state;
qCDebug(LOG_LIB) << "Current state is" << _state;
// 3 is magic number. Actually 3 is Graph mode
ui->widget_count->setHidden(state != 3);
ui->widget_count->setHidden(_state != 3);
}
void GraphicalItem::changeValue(const int state)
void GraphicalItem::changeValue(const int _state)
{
qCDebug(LOG_LIB) << "Current state is" << state;
qCDebug(LOG_LIB) << "Current state is" << _state;
ui->widget_value->setHidden(state != Qt::Unchecked);
ui->widget_customValue->setHidden(state == Qt::Unchecked);
ui->widget_value->setHidden(_state != Qt::Unchecked);
ui->widget_customValue->setHidden(_state == Qt::Unchecked);
}

View File

@ -58,7 +58,8 @@ public:
Bars = 4
};
explicit GraphicalItem(QWidget *parent, const QString &filePath = QString());
explicit GraphicalItem(QWidget *_parent = nullptr,
const QString &_filePath = "");
virtual ~GraphicalItem();
GraphicalItem *copy(const QString &_fileName, const int _number);
QString image(const QVariant &value);
@ -80,32 +81,31 @@ public:
QStringList usedKeys() const;
QString uniq() const;
// set methods
void setBar(const QString &_bar = QString("cpu"));
void setActiveColor(const QString &_color = QString("color://0,0,0,130"));
void setCount(const int _count = 100);
void setCustom(const bool _custom = false);
void setInactiveColor(const QString &_color
= QString("color://255,255,255,130"));
void setItemHeight(const int _height = 100);
void setItemWidth(const int _width = 100);
void setMinValue(const float _value = 0.0);
void setMaxValue(const float _value = 100.0);
void setType(const Type _type = Type::Horizontal);
void setStrType(const QString &_type = QString("Horizontal"));
void setDirection(const Direction _direction = Direction::LeftToRight);
void setStrDirection(const QString &_direction = QString("LeftToRight"));
void setUsedKeys(const QStringList &_usedKeys = QStringList());
void setBar(const QString &_bar);
void setActiveColor(const QString &_color);
void setCount(const int _count);
void setCustom(const bool _custom);
void setInactiveColor(const QString &_color);
void setItemHeight(const int _height);
void setItemWidth(const int _width);
void setMinValue(const float _value);
void setMaxValue(const float _value);
void setType(const Type _type);
void setStrType(const QString &_type);
void setDirection(const Direction _direction);
void setStrDirection(const QString &_direction);
void setUsedKeys(const QStringList &_usedKeys);
public slots:
void readConfiguration();
QVariantHash run() { return QVariantHash(); };
int showConfiguration(const QVariant &args = QVariant());
int showConfiguration(const QVariant &_args);
void writeConfiguration() const;
private slots:
void changeColor();
void changeCountState(const int state);
void changeValue(const int state);
void changeCountState(const int _state);
void changeValue(const int _state);
private:
GraphicalItemHelper *m_helper = nullptr;
@ -114,11 +114,11 @@ private:
Ui::GraphicalItem *ui = nullptr;
void translate();
// properties
QString m_bar = QString("cpu");
QString m_bar = "cpu";
int m_count = 100;
bool m_custom = false;
QString m_activeColor = QString("color://0,0,0,130");
QString m_inactiveColor = QString("color://255,255,255,130");
QString m_activeColor = "color://0,0,0,130";
QString m_inactiveColor = "color://255,255,255,130";
float m_minValue = 0.0f;
float m_maxValue = 100.0f;
Type m_type = Type::Horizontal;

View File

@ -27,9 +27,10 @@
#include "awdebug.h"
GraphicalItemHelper::GraphicalItemHelper(QObject *parent, QGraphicsScene *scene)
: QObject(parent)
, m_scene(scene)
GraphicalItemHelper::GraphicalItemHelper(QObject *_parent,
QGraphicsScene *_scene)
: QObject(_parent)
, m_scene(_scene)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
}
@ -41,54 +42,56 @@ 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
if (isColor(active)) {
m_activePen.setBrush(QBrush(stringToColor(active)));
if (isColor(_active)) {
m_activePen.setBrush(QBrush(stringToColor(_active)));
} else {
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << active;
QPixmap pixmap = QPixmap(QUrl(active).toLocalFile());
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << _active;
QPixmap pixmap = QPixmap(QUrl(_active).toLocalFile());
if (pixmap.isNull()) {
qCWarning(LOG_LIB) << "Invalid pixmap found" << active;
qCWarning(LOG_LIB) << "Invalid pixmap found" << _active;
m_activePen.setBrush(QBrush(QColor(0, 0, 0, 130)));
} else {
m_activePen.setBrush(QBrush(pixmap.scaled(width, height)));
m_activePen.setBrush(QBrush(pixmap.scaled(_width, _height)));
}
}
if (isColor(inactive)) {
m_inactivePen.setBrush(QBrush(stringToColor(inactive)));
if (isColor(_inactive)) {
m_inactivePen.setBrush(QBrush(stringToColor(_inactive)));
} else {
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << inactive;
QPixmap pixmap = QPixmap(QUrl(inactive).toLocalFile());
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;
qCWarning(LOG_LIB) << "Invalid pixmap found" << _inactive;
m_inactivePen.setBrush(QBrush(QColor(255, 255, 255, 130)));
} else {
m_inactivePen.setBrush(QBrush(pixmap.scaled(width, height)));
m_inactivePen.setBrush(QBrush(pixmap.scaled(_width, _height)));
}
}
m_width = width;
m_height = height;
m_count = count;
m_width = _width;
m_height = _height;
m_count = _count;
}
void GraphicalItemHelper::paintBars(const float value)
void GraphicalItemHelper::paintBars(const float _value)
{
qCDebug(LOG_LIB) << "Paint with value" << value;
qCDebug(LOG_LIB) << "Paint with value" << _value;
// refresh background image
m_scene->setBackgroundBrush(m_inactivePen.brush());
storeValue(value);
storeValue(_value);
// default norms
float normX
@ -105,9 +108,9 @@ void GraphicalItemHelper::paintBars(const float value)
}
void GraphicalItemHelper::paintCircle(const float percent)
void GraphicalItemHelper::paintCircle(const float _percent)
{
qCDebug(LOG_LIB) << "Paint with percent" << percent;
qCDebug(LOG_LIB) << "Paint with percent" << _percent;
m_activePen.setWidth(1);
m_inactivePen.setWidth(1);
@ -118,24 +121,24 @@ void GraphicalItemHelper::paintCircle(const float percent)
// inactive
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);
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->setSpanAngle(-percent * 360.0f * 16.0f);
circle->setSpanAngle(-_percent * 360.0f * 16.0f);
circle->setStartAngle(90 * 16);
}
void GraphicalItemHelper::paintGraph(const float value)
void GraphicalItemHelper::paintGraph(const float _value)
{
qCDebug(LOG_LIB) << "Paint with value" << value;
qCDebug(LOG_LIB) << "Paint with value" << _value;
// refresh background image
m_scene->setBackgroundBrush(m_inactivePen.brush());
storeValue(value);
storeValue(_value);
// default norms
float normX
@ -153,66 +156,67 @@ void GraphicalItemHelper::paintGraph(const float value)
}
void GraphicalItemHelper::paintHorizontal(const float percent)
void GraphicalItemHelper::paintHorizontal(const float _percent)
{
qCDebug(LOG_LIB) << "Paint with percent" << percent;
qCDebug(LOG_LIB) << "Paint with percent" << _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_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,
_percent * m_width - 0.5 * m_height, 0.5 * m_height,
m_activePen);
}
void GraphicalItemHelper::paintVertical(const float percent)
void GraphicalItemHelper::paintVertical(const float _percent)
{
qCDebug(LOG_LIB) << "Paint with percent" << percent;
qCDebug(LOG_LIB) << "Paint with percent" << _percent;
m_activePen.setWidth(m_height);
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,
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;
qCDebug(LOG_LIB) << "Get percent value from" << _value;
// newest Qt crashes here if value is nan
if (std::isnan(value))
if (std::isnan(_value))
return 0.0;
return (value - min) / (max - min);
return (_value - _min) / (_max - _min);
}
bool GraphicalItemHelper::isColor(const QString &input)
bool GraphicalItemHelper::isColor(const QString &_input)
{
qCDebug(LOG_LIB) << "Define input type in" << input;
qCDebug(LOG_LIB) << "Define input type in" << _input;
return input.startsWith(QString("color://"));
return _input.startsWith("color://");
}
QColor GraphicalItemHelper::stringToColor(const QString &color)
QColor GraphicalItemHelper::stringToColor(const QString &_color)
{
qCDebug(LOG_LIB) << "Color" << color;
qCDebug(LOG_LIB) << "Color" << _color;
QStringList listColor = color.split(QChar(','));
QStringList listColor = _color.split(',');
while (listColor.count() < 4)
listColor.append(QString("0"));
listColor.append("0");
// remove prefix
listColor[0].remove(QString("color://"));
listColor[0].remove("color://");
// init color
QColor qColor;
qColor.setRed(listColor.at(0).toInt());
@ -224,14 +228,14 @@ QColor GraphicalItemHelper::stringToColor(const QString &color)
}
void GraphicalItemHelper::storeValue(const float value)
void GraphicalItemHelper::storeValue(const float _value)
{
qCDebug(LOG_LIB) << "Save value to array" << value;
qCDebug(LOG_LIB) << "Save value to array" << _value;
if (m_values.count() == 0)
m_values.append(1.0);
else if (m_values.count() > m_count)
m_values.removeFirst();
m_values.append(value);
m_values.append(_value);
}

View File

@ -30,25 +30,25 @@ 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);
void paintGraph(const float value);
void paintHorizontal(const float percent);
void paintVertical(const float percent);
void paintBars(const float _value);
void paintCircle(const float _percent);
void paintGraph(const float _value);
void paintHorizontal(const float _percent);
void paintVertical(const float _percent);
// additional conversion methods
float getPercents(const float value, const float min, const float max);
bool isColor(const QString &input);
QColor stringToColor(const QString &color);
float getPercents(const float _value, const float _min, const float _max);
bool isColor(const QString &_input);
QColor stringToColor(const QString &_color);
private:
void storeValue(const float value);
void storeValue(const float _value);
QGraphicsScene *m_scene = nullptr;
int m_count = 100;
QPen m_activePen;

View File

@ -23,8 +23,8 @@
#include "awdebug.h"
OWMWeatherProvider::OWMWeatherProvider(QObject *parent, const int number)
: AbstractWeatherProvider(parent, number)
OWMWeatherProvider::OWMWeatherProvider(QObject *_parent, const int _number)
: AbstractWeatherProvider(_parent, _number)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
}
@ -36,10 +36,11 @@ OWMWeatherProvider::~OWMWeatherProvider()
}
void OWMWeatherProvider::initUrl(const QString &city, const QString &country,
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;
@ -48,26 +49,26 @@ void OWMWeatherProvider::initUrl(const QString &city, const QString &country,
else
m_url = QUrl(OWM_FORECAST_URL);
QUrlQuery params;
params.addQueryItem(QString("q"), QString("%1,%2").arg(city, country));
params.addQueryItem(QString("units"), QString("metric"));
params.addQueryItem("q", QString("%1,%2").arg(_city, _country));
params.addQueryItem("units", "metric");
m_url.setQuery(params);
}
QVariantHash OWMWeatherProvider::parse(const QVariantMap &json) const
QVariantHash OWMWeatherProvider::parse(const QVariantMap &_json) const
{
qCDebug(LOG_LIB) << "Parse json" << json;
qCDebug(LOG_LIB) << "Parse json" << _json;
if (json[QString("cod")].toInt() != 200) {
if (_json["cod"].toInt() != 200) {
qCWarning(LOG_LIB) << "Invalid OpenWeatherMap return code"
<< json[QString("cod")].toInt();
<< _json["cod"].toInt();
return QVariantHash();
}
if (m_ts == 0) {
return parseSingleJson(json);
return parseSingleJson(_json);
} else {
QVariantList list = json[QString("list")].toList();
QVariantList list = _json["list"].toList();
return parseSingleJson(list.count() <= m_ts ? list.at(m_ts - 1).toMap()
: list.last().toMap());
}
@ -80,33 +81,33 @@ QUrl OWMWeatherProvider::url() const
}
QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &json) const
QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &_json) const
{
qCDebug(LOG_LIB) << "Single json data" << json;
qCDebug(LOG_LIB) << "Single json data" << _json;
QVariantHash output;
// weather status
QVariantList weather = json[QString("weather")].toList();
QVariantList weather = _json["weather"].toList();
if (!weather.isEmpty()) {
int id = weather.first().toMap()[QString("id")].toInt();
int id = weather.first().toMap()["id"].toInt();
output[QString("weatherId%1").arg(number())] = id;
}
// main data
QVariantMap mainWeather = json[QString("main")].toMap();
QVariantMap mainWeather = _json["main"].toMap();
if (!weather.isEmpty()) {
output[QString("humidity%1").arg(number())]
= mainWeather[QString("humidity")].toFloat();
= mainWeather["humidity"].toFloat();
output[QString("pressure%1").arg(number())]
= mainWeather[QString("pressure")].toFloat();
= mainWeather["pressure"].toFloat();
output[QString("temperature%1").arg(number())]
= mainWeather[QString("temp")].toFloat();
= mainWeather["temp"].toFloat();
}
// timestamp
output[QString("timestamp%1").arg(number())]
= QDateTime::fromTime_t(json[QString("dt")].toUInt()).toUTC();
= QDateTime::fromTime_t(_json["dt"].toUInt()).toUTC();
return output;
}

View File

@ -31,14 +31,14 @@ 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, const int _number);
virtual ~OWMWeatherProvider();
void initUrl(const QString &city, const QString &country, const int);
QVariantHash parse(const QVariantMap &json) const;
void initUrl(const QString &_city, const QString &_country, const int);
QVariantHash parse(const QVariantMap &_json) const;
QUrl url() const;
private:
QVariantHash parseSingleJson(const QVariantMap &json) const;
QVariantHash parseSingleJson(const QVariantMap &_json) const;
int m_ts = 0;
QUrl m_url;
};

View File

@ -24,8 +24,8 @@
#include "awdebug.h"
QCronScheduler::QCronScheduler(QObject *parent)
: QObject(parent)
QCronScheduler::QCronScheduler(QObject *_parent)
: QObject(_parent)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
@ -48,11 +48,11 @@ QCronScheduler::~QCronScheduler()
}
void QCronScheduler::parse(const QString &timer)
void QCronScheduler::parse(const QString &_timer)
{
qCDebug(LOG_LIB) << "Parse timer string" << timer;
qCDebug(LOG_LIB) << "Parse timer string" << _timer;
QStringList fields = timer.split(' ');
QStringList fields = _timer.split(' ');
if (fields.count() != 5)
return;
@ -77,17 +77,17 @@ 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(',');
auto fields = _value.split(',');
for (auto &field : fields) {
QCronField parsedField;
parsedField.fromRange(field.split('/').first(), min, max);
parsedField.fromRange(field.split('/').first(), _min, _max);
if (field.contains('/')) {
bool status;
parsedField.div = field.split('/', QString::SkipEmptyParts)
@ -104,26 +104,26 @@ 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;
maxValue = max;
} else if (range.contains('-')) {
auto interval = range.split('-', QString::SkipEmptyParts);
if (_range == '*') {
minValue = _min;
maxValue = _max;
} else if (_range.contains('-')) {
auto interval = _range.split('-', QString::SkipEmptyParts);
if (interval.count() != 2)
return;
bool status;
// minimal value
minValue = std::max(min, interval.at(0).toInt(&status));
minValue = std::max(_min, interval.at(0).toInt(&status));
if (!status)
minValue = -1;
// maximal value
maxValue = std::min(max, interval.at(1).toInt(&status));
maxValue = std::min(_max, interval.at(1).toInt(&status));
if (!status)
maxValue = -1;
// error check
@ -131,8 +131,8 @@ void QCronScheduler::QCronField::fromRange(const QString &range, const int min,
std::swap(minValue, maxValue);
} else {
bool status;
int value = range.toInt(&status);
if (!status || (value < min) || (value > max))
int value = _range.toInt(&status);
if (!status || (value < _min) || (value > _max))
value = -1;
minValue = value;
maxValue = value;

View File

@ -39,13 +39,13 @@ public:
int minValue = -1;
int maxValue = -1;
int div = 1;
void fromRange(const QString &range, const int min, const int max);
void fromRange(const QString &_range, const int _min, const int _max);
QList<int> toList();
} QCronField;
explicit QCronScheduler(QObject *parent);
explicit QCronScheduler(QObject *_parent = nullptr);
virtual ~QCronScheduler();
void parse(const QString &timer);
void parse(const QString &_timer);
signals:
void activated();
@ -56,8 +56,8 @@ 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;
};

View File

@ -22,8 +22,8 @@
#include "awdebug.h"
YahooWeatherProvider::YahooWeatherProvider(QObject *parent, const int number)
: AbstractWeatherProvider(parent, number)
YahooWeatherProvider::YahooWeatherProvider(QObject *_parent, const int _number)
: AbstractWeatherProvider(_parent, _number)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
}
@ -35,38 +35,36 @@ 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;
m_url = QUrl(YAHOO_WEATHER_URL);
QUrlQuery params;
params.addQueryItem(QString("format"), QString("json"));
params.addQueryItem(QString("env"),
QString("store://datatables.org/alltableswithkeys"));
params.addQueryItem(QString("q"),
QString(YAHOO_WEATHER_QUERY).arg(city, country));
params.addQueryItem("format", "json");
params.addQueryItem("env", "store://datatables.org/alltableswithkeys");
params.addQueryItem("q", QString(YAHOO_WEATHER_QUERY).arg(_city, _country));
m_url.setQuery(params);
}
QVariantHash YahooWeatherProvider::parse(const QVariantMap &json) const
QVariantHash YahooWeatherProvider::parse(const QVariantMap &_json) const
{
qCDebug(LOG_LIB) << "Parse json" << json;
qCDebug(LOG_LIB) << "Parse json" << _json;
QVariantMap jsonMap = json[QString("query")].toMap();
if (jsonMap[QString("count")].toInt() != 1) {
qCWarning(LOG_LIB) << "Found data count"
<< json[QString("count")].toInt() << "is not 1";
QVariantMap jsonMap = _json["query"].toMap();
if (jsonMap["count"].toInt() != 1) {
qCWarning(LOG_LIB) << "Found data count" << _json["count"].toInt()
<< "is not 1";
return QVariantHash();
}
QVariantMap results
= jsonMap[QString("results")].toMap()[QString("channel")].toMap();
QVariantMap item = results[QString("item")].toMap();
QVariantMap atmosphere = results[QString("atmosphere")].toMap();
QVariantMap results = jsonMap["results"].toMap()["channel"].toMap();
QVariantMap item = results["item"].toMap();
QVariantMap atmosphere = results["atmosphere"].toMap();
return m_ts == 0 ? parseCurrent(item, atmosphere) : parseForecast(item);
}
@ -79,46 +77,44 @@ QUrl YahooWeatherProvider::url() const
QVariantHash
YahooWeatherProvider::parseCurrent(const QVariantMap &json,
const QVariantMap &atmosphere) const
YahooWeatherProvider::parseCurrent(const QVariantMap &_json,
const QVariantMap &_atmosphere) const
{
qCDebug(LOG_LIB) << "Parse current weather from" << json;
qCDebug(LOG_LIB) << "Parse current weather from" << _json;
auto condition = _json["condition"].toMap();
QVariantHash values;
int id = json[QString("condition")].toMap()[QString("code")].toInt();
int id = _json["condition"].toMap()["code"].toInt();
values[QString("weatherId%1").arg(number())] = id;
values[QString("temperature%1").arg(number())]
= json[QString("condition")].toMap()[QString("temp")].toInt();
values[QString("timestamp%1").arg(number())]
= json[QString("condition")].toMap()[QString("date")].toString();
values[QString("temperature%1").arg(number())] = condition["temp"].toInt();
values[QString("timestamp%1").arg(number())] = condition["date"].toString();
values[QString("humidity%1").arg(number())]
= atmosphere[QString("humidity")].toInt();
= _atmosphere["humidity"].toInt();
// HACK temporary fix of invalid values on Yahoo! side
values[QString("pressure%1").arg(number())] = static_cast<int>(
atmosphere[QString("pressure")].toFloat() / 33.863753);
values[QString("pressure%1").arg(number())]
= static_cast<int>(_atmosphere["pressure"].toFloat() / 33.863753);
return values;
}
QVariantHash YahooWeatherProvider::parseForecast(const QVariantMap &json) const
QVariantHash YahooWeatherProvider::parseForecast(const QVariantMap &_json) const
{
qCDebug(LOG_LIB) << "Parse forecast from" << json;
qCDebug(LOG_LIB) << "Parse forecast from" << _json;
QVariantHash values;
QVariantList weatherList = json[QString("forecast")].toList();
QVariantList weatherList = _json["forecast"].toList();
QVariantMap weatherMap = weatherList.count() < m_ts
? weatherList.last().toMap()
: weatherList.at(m_ts).toMap();
int id = weatherMap[QString("code")].toInt();
int id = weatherMap["code"].toInt();
values[QString("weatherId%1").arg(number())] = id;
values[QString("timestamp%1").arg(number())]
= weatherMap[QString("date")].toString();
= weatherMap["date"].toString();
// yahoo provides high and low temperatures. Lets calculate average one
values[QString("temperature%1").arg(number())]
= (weatherMap[QString("high")].toFloat()
+ weatherMap[QString("low")].toFloat())
/ 2.0;
= (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;

View File

@ -31,16 +31,16 @@ 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, const int _number);
virtual ~YahooWeatherProvider();
void initUrl(const QString &city, const QString &country, const int);
QVariantHash parse(const QVariantMap &json) const;
void initUrl(const QString &_city, const QString &_country, const int);
QVariantHash parse(const QVariantMap &_json) const;
QUrl url() const;
private:
QVariantHash parseCurrent(const QVariantMap &json,
const QVariantMap &atmosphere) const;
QVariantHash parseForecast(const QVariantMap &json) const;
QVariantHash parseCurrent(const QVariantMap &_json,
const QVariantMap &_atmosphere) const;
QVariantHash parseForecast(const QVariantMap &_json) const;
int m_ts = 0;
QUrl m_url;
};