From 734cbe2f4c21b15eb39d5bdfab69ba99e15d9cae Mon Sep 17 00:00:00 2001 From: arcan1s Date: Mon, 9 May 2016 04:07:58 +0300 Subject: [PATCH 01/32] upload vertical alignment patch, fix code (#94) --- patches/fix-vertical-alignment.patch | 26 +++++++++++++++++++ .../package/contents/ui/main.qml | 2 +- .../package/contents/ui/main.qml | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 patches/fix-vertical-alignment.patch diff --git a/patches/fix-vertical-alignment.patch b/patches/fix-vertical-alignment.patch new file mode 100644 index 0000000..136087c --- /dev/null +++ b/patches/fix-vertical-alignment.patch @@ -0,0 +1,26 @@ +diff --git a/sources/awesome-widget/package/contents/ui/main.qml b/sources/awesome-widget/package/contents/ui/main.qml +index 79c6ddf..0e20bc9 100644 +--- a/sources/awesome-widget/package/contents/ui/main.qml ++++ b/sources/awesome-widget/package/contents/ui/main.qml +@@ -84,7 +84,7 @@ Item { + // ui + Text { + id: text +- anchors.fill: Plasmoid.Layout ++ anchors.fill: parent + renderType: Text.NativeRendering + textFormat: Text.RichText + wrapMode: plasmoid.configuration.wrapText ? Text.WordWrap : Text.NoWrap +diff --git a/sources/desktop-panel/package/contents/ui/main.qml b/sources/desktop-panel/package/contents/ui/main.qml +index 5a1e9b6..20f8732 100644 +--- a/sources/desktop-panel/package/contents/ui/main.qml ++++ b/sources/desktop-panel/package/contents/ui/main.qml +@@ -57,7 +57,7 @@ Item { + + // ui + GridLayout { +- anchors.fill: Plasmoid.Layout ++ anchors.fill: parent + columns: plasmoid.configuration.verticalLayout ? 1 : dpAdds.numberOfDesktops() + rows: plasmoid.configuration.verticalLayout ? dpAdds.numberOfDesktops() : 1 + diff --git a/sources/awesome-widget/package/contents/ui/main.qml b/sources/awesome-widget/package/contents/ui/main.qml index 79c6ddf..0e20bc9 100644 --- a/sources/awesome-widget/package/contents/ui/main.qml +++ b/sources/awesome-widget/package/contents/ui/main.qml @@ -84,7 +84,7 @@ Item { // ui Text { id: text - anchors.fill: Plasmoid.Layout + anchors.fill: parent renderType: Text.NativeRendering textFormat: Text.RichText wrapMode: plasmoid.configuration.wrapText ? Text.WordWrap : Text.NoWrap diff --git a/sources/desktop-panel/package/contents/ui/main.qml b/sources/desktop-panel/package/contents/ui/main.qml index 5a1e9b6..20f8732 100644 --- a/sources/desktop-panel/package/contents/ui/main.qml +++ b/sources/desktop-panel/package/contents/ui/main.qml @@ -57,7 +57,7 @@ Item { // ui GridLayout { - anchors.fill: Plasmoid.Layout + anchors.fill: parent columns: plasmoid.configuration.verticalLayout ? 1 : dpAdds.numberOfDesktops() rows: plasmoid.configuration.verticalLayout ? dpAdds.numberOfDesktops() : 1 From 7c37134aab03eb9f44ed61d6aa3ab9f9051e77da Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 10 May 2016 02:16:24 +0300 Subject: [PATCH 02/32] rewrite formatters according to rfc #91 --- sources/awesome-widget/plugin/CMakeLists.txt | 4 +- .../plugin/awabstractformatter.cpp | 151 +++++++++ .../plugin/awabstractformatter.h | 45 ++- .../plugin/awdatetimeformatter.cpp | 99 +++++- .../plugin/awdatetimeformatter.h | 23 +- .../plugin/awdatetimeformatter.ui | 167 +++++++++ .../plugin/awfloatformatter.cpp | 160 +++++++-- .../awesome-widget/plugin/awfloatformatter.h | 41 ++- .../awesome-widget/plugin/awfloatformatter.ui | 317 ++++++++++++++++++ .../plugin/awformatterhelper.cpp | 132 ++++++-- .../awesome-widget/plugin/awformatterhelper.h | 13 +- .../awesome-widget/plugin/awnoformatter.cpp | 66 +++- sources/awesome-widget/plugin/awnoformatter.h | 19 +- .../awesome-widget/plugin/awnoformatter.ui | 144 ++++++++ .../plugin/awscriptformatter.cpp | 119 ++++++- .../awesome-widget/plugin/awscriptformatter.h | 29 +- .../plugin/awscriptformatter.ui | 212 ++++++++++++ 17 files changed, 1586 insertions(+), 155 deletions(-) create mode 100644 sources/awesome-widget/plugin/awabstractformatter.cpp create mode 100644 sources/awesome-widget/plugin/awdatetimeformatter.ui create mode 100644 sources/awesome-widget/plugin/awfloatformatter.ui create mode 100644 sources/awesome-widget/plugin/awnoformatter.ui create mode 100644 sources/awesome-widget/plugin/awscriptformatter.ui diff --git a/sources/awesome-widget/plugin/CMakeLists.txt b/sources/awesome-widget/plugin/CMakeLists.txt index 381937f..4d90d57 100644 --- a/sources/awesome-widget/plugin/CMakeLists.txt +++ b/sources/awesome-widget/plugin/CMakeLists.txt @@ -11,9 +11,11 @@ include_directories( ) file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) +file(GLOB SUBPROJECT_UI *.ui) file(GLOB SUBPROJECT_NOTIFY *.notifyrc) -add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE}) +qt5_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI}) +add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER}) target_link_libraries(${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget) diff --git a/sources/awesome-widget/plugin/awabstractformatter.cpp b/sources/awesome-widget/plugin/awabstractformatter.cpp new file mode 100644 index 0000000..302a00a --- /dev/null +++ b/sources/awesome-widget/plugin/awabstractformatter.cpp @@ -0,0 +1,151 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awabstractformatter.h" + +#include +#include +#include + +#include "awdebug.h" + + +AWAbstractFormatter::AWAbstractFormatter(QWidget *parent, + const QString filePath) + : QDialog(parent) + , m_fileName(filePath) +{ + qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + qCDebug(LOG_AW) << "Desktop name" << filePath; + + m_name = m_fileName; +} + + +AWAbstractFormatter::~AWAbstractFormatter() +{ + qCDebug(LOG_AW) << __PRETTY_FUNCTION__; +} + + +void AWAbstractFormatter::copyDefaults(AWAbstractFormatter *_other) const +{ + _other->setComment(m_comment); + _other->setName(m_name); + _other->setType(m_type); +} + + +QString AWAbstractFormatter::writtableConfig() const +{ + QStringList paths = m_fileName.split(QChar('/')); + + QString name = paths.takeLast(); + QString dir = paths.takeLast(); + + return QString("%1/awesomewidgets/%2/%3") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)) + .arg(dir) + .arg(name); +} + + +QString AWAbstractFormatter::comment() const +{ + return m_comment; +} + + +QString AWAbstractFormatter::fileName() const +{ + return m_fileName; +} + + +QString AWAbstractFormatter::name() const +{ + return m_name; +} + + +QString AWAbstractFormatter::type() const +{ + return m_type; +} + + +void AWAbstractFormatter::setComment(const QString _comment) +{ + qCDebug(LOG_AW) << "Comment" << _comment; + + m_comment = _comment; +} + + +void AWAbstractFormatter::setName(const QString _name) +{ + qCDebug(LOG_AW) << "Name" << _name; + + m_name = _name; +} + + +void AWAbstractFormatter::setType(const QString _type) +{ + qCDebug(LOG_AW) << "Type" << _type; + + m_type = _type; +} + + +void AWAbstractFormatter::readConfiguration() +{ + QSettings settings(m_fileName, QSettings::IniFormat); + + settings.beginGroup(QString("Desktop Entry")); + setName(settings.value(QString("Name"), m_name).toString()); + setComment(settings.value(QString("Comment"), m_comment).toString()); + setType(settings.value(QString("Type"), m_type).toString()); + settings.endGroup(); +} + + +bool AWAbstractFormatter::tryDelete() const +{ + bool status = QFile::remove(m_fileName); + qCInfo(LOG_AW) << "Remove file" << m_fileName << status; + + return status; +} + + +void AWAbstractFormatter::writeConfiguration() const +{ + QSettings settings(writtableConfig(), QSettings::IniFormat); + qCInfo(LOG_AW) << "Configuration file" << settings.fileName(); + + settings.beginGroup(QString("Desktop Entry")); + settings.setValue(QString("Encoding"), QString("UTF-8")); + settings.setValue(QString("Name"), m_name); + settings.setValue(QString("Comment"), m_comment); + settings.setValue(QString("Type"), m_type); + settings.endGroup(); + + settings.sync(); +} diff --git a/sources/awesome-widget/plugin/awabstractformatter.h b/sources/awesome-widget/plugin/awabstractformatter.h index d873ef5..d953a25 100644 --- a/sources/awesome-widget/plugin/awabstractformatter.h +++ b/sources/awesome-widget/plugin/awabstractformatter.h @@ -18,19 +18,48 @@ #ifndef AWABSTRACTFORMATTER_H #define AWABSTRACTFORMATTER_H -#include +#include #include -class AWAbstractFormatter : public QObject +class AWAbstractFormatter : public QDialog { + Q_OBJECT + Q_PROPERTY(QString comment READ comment WRITE setComment) + Q_PROPERTY(QString fileName READ fileName) + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString type READ type WRITE setType) + public: - explicit AWAbstractFormatter(QObject *parent, const QString, const QString) - : QObject(parent){}; - explicit AWAbstractFormatter(QObject *parent) - : QObject(parent){}; - virtual ~AWAbstractFormatter(){}; - virtual QString convert(const QVariant &value) const = 0; + explicit AWAbstractFormatter(QWidget *parent = nullptr, + const QString filePath = QString()); + virtual ~AWAbstractFormatter(); + virtual AWAbstractFormatter *copy(const QString _fileName) = 0; + void copyDefaults(AWAbstractFormatter *_other) const; + virtual QString convert(const QVariant &_value) const = 0; + QString writtableConfig() const; + // properties + QString comment() const; + QString fileName() const; + QString name() const; + QString type() const; + void setComment(const QString _comment = QString("empty")); + void setName(const QString _name = QString("none")); + void setType(const QString _type = QString("NoFormat")); + +public slots: + virtual void readConfiguration(); + virtual int showConfiguration(const QVariant args = QVariant()) = 0; + bool tryDelete() const; + virtual void writeConfiguration() const; + +private: + QString m_fileName; + virtual void translate() = 0; + // properties + QString m_comment = QString("empty"); + QString m_name = QString("none"); + QString m_type = QString("NoFormat"); }; diff --git a/sources/awesome-widget/plugin/awdatetimeformatter.cpp b/sources/awesome-widget/plugin/awdatetimeformatter.cpp index 515dd42..6445fe3 100644 --- a/sources/awesome-widget/plugin/awdatetimeformatter.cpp +++ b/sources/awesome-widget/plugin/awdatetimeformatter.cpp @@ -17,44 +17,69 @@ #include "awdatetimeformatter.h" +#include "ui_awdatetimeformatter.h" + +#include #include +#include #include #include "awdebug.h" -AWDateTimeFormatter::AWDateTimeFormatter(QObject *parent, - const QString filename, - const QString section) - : AWAbstractFormatter(parent, filename, section) +AWDateTimeFormatter::AWDateTimeFormatter(QWidget *parent, + const QString filePath) + : AWAbstractFormatter(parent, filePath) + , ui(new Ui::AWDateTimeFormatter) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; - init(filename, section); + readConfiguration(); + ui->setupUi(this); + translate(); } -AWDateTimeFormatter::AWDateTimeFormatter(QObject *parent, const QString format) +AWDateTimeFormatter::AWDateTimeFormatter(const QString format, QWidget *parent) : AWAbstractFormatter(parent) + , ui(new Ui::AWDateTimeFormatter) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; setFormat(format); + + ui->setupUi(this); + translate(); } AWDateTimeFormatter::~AWDateTimeFormatter() { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + delete ui; } -QString AWDateTimeFormatter::convert(const QVariant &value) const +QString AWDateTimeFormatter::convert(const QVariant &_value) const { - qCDebug(LOG_AW) << "Convert value" << value; + qCDebug(LOG_AW) << "Convert value" << _value; - return value.toDateTime().toString(m_format); + return _value.toDateTime().toString(m_format); +} + + +AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString _fileName) +{ + qCDebug(LOG_LIB) << "File" << _fileName; + + AWDateTimeFormatter *item + = new AWDateTimeFormatter(static_cast(parent()), _fileName); + copyDefaults(item); + item->setFormat(format()); + + return item; } @@ -72,13 +97,59 @@ void AWDateTimeFormatter::setFormat(const QString _format) } -void AWDateTimeFormatter::init(const QString filename, const QString section) +void AWDateTimeFormatter::readConfiguration() { - qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename; + AWAbstractFormatter::readConfiguration(); - QSettings settings(filename, QSettings::IniFormat); + QSettings settings(fileName(), QSettings::IniFormat); - settings.beginGroup(section); - setFormat(settings.value(QString("Format"), QString()).toString()); + settings.beginGroup(QString("Desktop Entry")); + setFormat(settings.value(QString("Format"), m_format).toString()); settings.endGroup(); } + + +int AWDateTimeFormatter::showConfiguration(const QVariant args) +{ + Q_UNUSED(args) + + ui->lineEdit_name->setText(name()); + ui->lineEdit_comment->setText(comment()); + ui->label_typeValue->setText(QString("DateTime")); + ui->lineEdit_format->setText(m_format); + + int ret = exec(); + if (ret != 1) + return ret; + setName(ui->lineEdit_name->text()); + setComment(ui->lineEdit_comment->text()); + setType(ui->label_typeValue->text()); + setFormat(ui->lineEdit_format->text()); + + writeConfiguration(); + return ret; +} + + +void AWDateTimeFormatter::writeConfiguration() const +{ + AWAbstractFormatter::writeConfiguration(); + + QSettings settings(writtableConfig(), QSettings::IniFormat); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); + + settings.beginGroup(QString("Desktop Entry")); + settings.setValue(QString("Format"), m_format); + settings.endGroup(); + + settings.sync(); +} + + +void AWDateTimeFormatter::translate() +{ + ui->label_name->setText(i18n("Name")); + ui->label_comment->setText(i18n("Comment")); + ui->label_type->setText(i18n("Type")); + ui->label_format->setText(i18n("Format")); +} diff --git a/sources/awesome-widget/plugin/awdatetimeformatter.h b/sources/awesome-widget/plugin/awdatetimeformatter.h index df8e9d7..b0b1bbc 100644 --- a/sources/awesome-widget/plugin/awdatetimeformatter.h +++ b/sources/awesome-widget/plugin/awdatetimeformatter.h @@ -21,25 +21,36 @@ #include "awabstractformatter.h" +namespace Ui +{ +class AWDateTimeFormatter; +} + class AWDateTimeFormatter : public AWAbstractFormatter { Q_OBJECT Q_PROPERTY(QString format READ format WRITE setFormat) public: - explicit AWDateTimeFormatter(QObject *parent, const QString filename, - const QString section); - explicit AWDateTimeFormatter(QObject *parent, const QString format); + explicit AWDateTimeFormatter(QWidget *parent, const QString filePath); + explicit AWDateTimeFormatter(const QString format, QWidget *parent); virtual ~AWDateTimeFormatter(); - QString convert(const QVariant &value) const; + QString convert(const QVariant &_value) const; + AWDateTimeFormatter *copy(const QString _fileName); // properties QString format() const; void setFormat(const QString _format); +public slots: + void readConfiguration(); + int showConfiguration(const QVariant args = QVariant()); + void writeConfiguration() const; + private: - void init(const QString filename, const QString section); + Ui::AWDateTimeFormatter *ui; + void translate(); // properties - QString m_format; + QString m_format = QString(); }; diff --git a/sources/awesome-widget/plugin/awdatetimeformatter.ui b/sources/awesome-widget/plugin/awdatetimeformatter.ui new file mode 100644 index 0000000..f0f80dc --- /dev/null +++ b/sources/awesome-widget/plugin/awdatetimeformatter.ui @@ -0,0 +1,167 @@ + + + AWDateTimeFormatter + + + + 0 + 0 + 420 + 157 + + + + Configuration + + + + + + + + + 0 + 0 + + + + Name + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + 0 + 0 + + + + Comment + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + Type + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + + + + 0 + 0 + + + + Format + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AWDateTimeFormatter + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AWDateTimeFormatter + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/awesome-widget/plugin/awfloatformatter.cpp b/sources/awesome-widget/plugin/awfloatformatter.cpp index 7a6fe2c..ba2a18f 100644 --- a/sources/awesome-widget/plugin/awfloatformatter.cpp +++ b/sources/awesome-widget/plugin/awfloatformatter.cpp @@ -17,51 +17,87 @@ #include "awfloatformatter.h" +#include "ui_awfloatformatter.h" +#include + +#include #include #include "awdebug.h" -AWFloatFormatter::AWFloatFormatter(QObject *parent, const QString filename, - const QString section) - : AWAbstractFormatter(parent, filename, section) +AWFloatFormatter::AWFloatFormatter(QWidget *parent, const QString filePath) + : AWAbstractFormatter(parent, filePath) + , ui(new Ui::AWFloatFormatter) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; - init(filename, section); + readConfiguration(); + ui->setupUi(this); + translate(); } -AWFloatFormatter::AWFloatFormatter(QObject *parent, const QChar fillChar, +AWFloatFormatter::AWFloatFormatter(const int count, const QChar fillChar, const char format, const double multiplier, const int precision, const double summand, - const int width) + QWidget *parent) : AWAbstractFormatter(parent) + , ui(new Ui::AWFloatFormatter) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + setCount(count); setFillChar(fillChar); setFormat(format); setMultiplier(multiplier); setPrecision(precision); setSummand(summand); - setWidth(width); + + ui->setupUi(this); + translate(); } AWFloatFormatter::~AWFloatFormatter() { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + delete ui; } -QString AWFloatFormatter::convert(const QVariant &value) const +QString AWFloatFormatter::convert(const QVariant &_value) const { - qCDebug(LOG_AW) << "Convert value" << value; + qCDebug(LOG_AW) << "Convert value" << _value; - return QString("%1").arg(value.toDouble() * m_multiplier + m_summand, - m_width, m_format, m_precision, m_fillChar); + return QString("%1").arg(_value.toDouble() * m_multiplier + m_summand, + m_count, m_format, m_precision, m_fillChar); +} + + +AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName) +{ + qCDebug(LOG_LIB) << "File" << _fileName; + + AWFloatFormatter *item + = new AWFloatFormatter(static_cast(parent()), _fileName); + copyDefaults(item); + item->setCount(count()); + item->setFormat(format()); + item->setFillChar(fillChar()); + item->setMultiplier(multiplier()); + item->setPrecision(precision()); + item->setSummand(summand()); + + return item; +} + + +int AWFloatFormatter::count() const +{ + return m_count; } @@ -95,9 +131,11 @@ double AWFloatFormatter::summand() const } -int AWFloatFormatter::width() const +void AWFloatFormatter::setCount(const int _count) { - return m_width; + qCDebug(LOG_AW) << "Set width" << _count; + + m_count = _count; } @@ -147,30 +185,90 @@ void AWFloatFormatter::setSummand(const double _summand) } -void AWFloatFormatter::setWidth(const int _width) +void AWFloatFormatter::readConfiguration() { - qCDebug(LOG_AW) << "Set width" << _width; + AWAbstractFormatter::readConfiguration(); - m_width = _width; -} + QSettings settings(fileName(), QSettings::IniFormat); - -void AWFloatFormatter::init(const QString filename, const QString section) -{ - qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename; - - QSettings settings(filename, QSettings::IniFormat); - - settings.beginGroup(section); + settings.beginGroup(QString("Desktop Entry")); + setCount(settings.value(QString("Width"), m_count).toInt()); setFillChar( - settings.value(QString("FillChar"), QString()).toString().at(0)); - setFormat(settings.value(QString("Format"), QString("f")) + settings.value(QString("FillChar"), m_fillChar).toString().at(0)); + setFormat(settings.value(QString("Format"), QString(m_format)) .toString() .at(0) .toLatin1()); - setMultiplier(settings.value(QString("Multiplier"), 1.0).toDouble()); - setPrecision(settings.value(QString("Precision"), -1).toInt()); - setSummand(settings.value(QString("Summand"), 0.0).toDouble()); - setWidth(settings.value(QString("Width"), 0).toInt()); + setMultiplier( + settings.value(QString("Multiplier"), m_multiplier).toDouble()); + setPrecision(settings.value(QString("Precision"), m_precision).toInt()); + setSummand(settings.value(QString("Summand"), m_summand).toDouble()); settings.endGroup(); } + + +int AWFloatFormatter::showConfiguration(const QVariant args) +{ + Q_UNUSED(args) + + ui->lineEdit_name->setText(name()); + ui->lineEdit_comment->setText(comment()); + ui->label_typeValue->setText(QString("Float")); + ui->comboBox_format->setCurrentIndex( + ui->comboBox_format->findText(QString(m_format))); + ui->spinBox_precision->setValue(m_precision); + ui->spinBox_width->setValue(m_count); + ui->lineEdit_fill->setText(QString(m_fillChar)); + ui->doubleSpinBox_multiplier->setValue(m_multiplier); + ui->doubleSpinBox_summand->setValue(m_summand); + + int ret = exec(); + if (ret != 1) + return ret; + setName(ui->lineEdit_name->text()); + setComment(ui->lineEdit_comment->text()); + setType(ui->label_typeValue->text()); + setFormat(ui->comboBox_format->currentText().at(0).toLatin1()); + setPrecision(ui->spinBox_precision->value()); + setCount(ui->spinBox_width->value()); + setFillChar(ui->lineEdit_fill->text().at(0)); + setMultiplier(ui->doubleSpinBox_multiplier->value()); + setSummand(ui->doubleSpinBox_summand->value()); + + writeConfiguration(); + return ret; +} + + +void AWFloatFormatter::writeConfiguration() const +{ + AWAbstractFormatter::writeConfiguration(); + + QSettings settings(writtableConfig(), QSettings::IniFormat); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); + + settings.beginGroup(QString("Desktop Entry")); + settings.setValue(QString("Width"), m_count); + settings.setValue(QString("FillChar"), m_fillChar); + settings.setValue(QString("Format"), m_format); + settings.setValue(QString("Multiplier"), m_multiplier); + settings.setValue(QString("Precision"), m_precision); + settings.setValue(QString("Summand"), m_summand); + settings.endGroup(); + + settings.sync(); +} + + +void AWFloatFormatter::translate() +{ + ui->label_name->setText(i18n("Name")); + ui->label_comment->setText(i18n("Comment")); + ui->label_type->setText(i18n("Type")); + ui->label_format->setText(i18n("Format")); + ui->label_precision->setText(i18n("Precision")); + ui->label_width->setText(i18n("Width")); + ui->label_fill->setText(i18n("Fill char")); + ui->label_multiplier->setText(i18n("Multiplier")); + ui->label_summand->setText(i18n("Summand")); +} diff --git a/sources/awesome-widget/plugin/awfloatformatter.h b/sources/awesome-widget/plugin/awfloatformatter.h index 2ee36c8..1a9b28f 100644 --- a/sources/awesome-widget/plugin/awfloatformatter.h +++ b/sources/awesome-widget/plugin/awfloatformatter.h @@ -21,48 +21,59 @@ #include "awabstractformatter.h" +namespace Ui +{ +class AWFloatFormatter; +} + class AWFloatFormatter : public AWAbstractFormatter { Q_OBJECT + Q_PROPERTY(int count READ count WRITE setCount) Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar) Q_PROPERTY(char format READ format WRITE setFormat) Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier) Q_PROPERTY(int precision READ precision WRITE setPrecision) Q_PROPERTY(double summand READ summand WRITE setSummand) - Q_PROPERTY(int width READ width WRITE setWidth) public: - explicit AWFloatFormatter(QObject *parent, const QString filename, - const QString section); - explicit AWFloatFormatter(QObject *parent, const QChar fillChar, + explicit AWFloatFormatter(QWidget *parent, const QString filePath); + explicit AWFloatFormatter(const int count, const QChar fillChar, const char format, const double multiplier, const int precision, const double summand, - const int width); + QWidget *parent); virtual ~AWFloatFormatter(); - QString convert(const QVariant &value) const; + QString convert(const QVariant &_value) const; + AWFloatFormatter *copy(const QString _fileName); // properties + int count() const; QChar fillChar() const; char format() const; double multiplier() const; int precision() const; double summand() const; - int width() const; + void setCount(const int _count); void setFillChar(const QChar _fillChar); void setFormat(char _format); void setMultiplier(const double _multiplier); void setPrecision(const int _precision); void setSummand(const double _summand); - void setWidth(const int _width); + +public slots: + void readConfiguration(); + int showConfiguration(const QVariant args = QVariant()); + void writeConfiguration() const; private: - void init(const QString filename, const QString section); + Ui::AWFloatFormatter *ui; + void translate(); // properties - QChar m_fillChar; - char m_format; - double m_multiplier; - int m_precision; - double m_summand; - int m_width; + int m_count = 0; + QChar m_fillChar = QChar(); + char m_format = 'f'; + double m_multiplier = 1.0; + int m_precision = -1; + double m_summand = 0.0; }; diff --git a/sources/awesome-widget/plugin/awfloatformatter.ui b/sources/awesome-widget/plugin/awfloatformatter.ui new file mode 100644 index 0000000..8d6a1e6 --- /dev/null +++ b/sources/awesome-widget/plugin/awfloatformatter.ui @@ -0,0 +1,317 @@ + + + AWFloatFormatter + + + + 0 + 0 + 420 + 315 + + + + Configuration + + + + + + + + + 0 + 0 + + + + Name + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + 0 + 0 + + + + Comment + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + Type + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + + + Format + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + e + + + + + E + + + + + f + + + + + g + + + + + G + + + + + + + + + + + + Precision + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + -1 + + + 10000 + + + + + + + + + + + Width + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + -10000 + + + 10000 + + + + + + + + + + + + 0 + 0 + + + + Fill char + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 1 + + + + + + + + + Qt::Horizontal + + + + + + + + + Multiplier + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + -1000000000.000000000000000 + + + 1000000000.000000000000000 + + + + + + + + + + + Summand + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + -1000000000.000000000000000 + + + 1000000000.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AWFloatFormatter + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AWFloatFormatter + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index aa6cd4f..cac9759 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -17,6 +17,7 @@ #include "awformatterhelper.h" +#include #include #include @@ -32,11 +33,10 @@ AWFormatterHelper::AWFormatterHelper(QObject *parent) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; - m_genericConfig = QString("%1/awesomewidgets/general.ini") - .arg(QStandardPaths::writableLocation( - QStandardPaths::GenericDataLocation)); #ifdef BUILD_FUTURE - init(); + installDirectories(); + initFormatters(); + initKeys(); #endif /* BUILD_FUTURE */ } @@ -46,6 +46,7 @@ AWFormatterHelper::~AWFormatterHelper() qCDebug(LOG_AW) << __PRETTY_FUNCTION__; m_formatters.clear(); + m_formattersClasses.clear(); } @@ -65,17 +66,16 @@ QStringList AWFormatterHelper::definedFormatters() const } -AWFormatterHelper::FormatterClass -AWFormatterHelper::defineFormatterClass(const QString name) const +QStringList AWFormatterHelper::knownFormatters() const { - qCDebug(LOG_AW) << "Define formatter class for" << name; + return m_formattersClasses.keys(); +} - QSettings settings(m_genericConfig, QSettings::IniFormat); - settings.beginGroup(name); - QString stringType - = settings.value(QString("Type"), QString("NoFormat")).toString(); - settings.endGroup(); +AWFormatterHelper::FormatterClass +AWFormatterHelper::defineFormatterClass(const QString stringType) const +{ + qCDebug(LOG_AW) << "Define formatter class for" << stringType; FormatterClass formatter = FormatterClass::NoFormat; if (stringType == QString("DateTime")) @@ -91,35 +91,97 @@ AWFormatterHelper::defineFormatterClass(const QString name) const } -void AWFormatterHelper::init() +void AWFormatterHelper::initFormatters() { - QSettings settings(m_genericConfig, QSettings::IniFormat); + m_formattersClasses.clear(); + for (int i = m_directories.count() - 1; i >= 0; i--) { + QStringList files + = QDir(m_directories.at(i)).entryList(QDir::Files, QDir::Name); + for (auto file : files) { + if (!file.endsWith(QString(".desktop"))) + continue; + qCInfo(LOG_LIB) << "Found file" << file << "in" + << m_directories.at(i); + QString filePath + = QString("%1/%2").arg(m_directories.at(i)).arg(file); + auto metadata = readMetadata(filePath); + QString name = metadata.first; + if (m_formattersClasses.contains(name)) + continue; + + + switch (metadata.second) { + case FormatterClass::DateTime: + m_formattersClasses[name] + = new AWDateTimeFormatter(nullptr, filePath); + break; + case FormatterClass::Float: + m_formattersClasses[name] + = new AWFloatFormatter(nullptr, filePath); + break; + case FormatterClass::Script: + m_formattersClasses[name] + = new AWScriptFormatter(nullptr, filePath); + break; + case FormatterClass::NoFormat: + m_formattersClasses[name] + = new AWNoFormatter(nullptr, filePath); + break; + } + } + } +} + + +void AWFormatterHelper::initKeys() +{ + m_formatters.clear(); + + QSettings settings(m_formatterConfig, QSettings::IniFormat); settings.beginGroup(QString("Formatters")); QStringList keys = settings.childKeys(); for (auto key : keys) { QString name = settings.value(key).toString(); - FormatterClass formatter = defineFormatterClass(name); - qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key - << "defined as" << static_cast(formatter); - - switch (formatter) { - case FormatterClass::DateTime: - m_formatters[key] - = new AWDateTimeFormatter(this, m_genericConfig, name); - break; - case FormatterClass::Float: - m_formatters[key] - = new AWFloatFormatter(this, m_genericConfig, name); - break; - case FormatterClass::Script: - m_formatters[key] - = new AWScriptFormatter(this, m_genericConfig, name); - break; - case FormatterClass::NoFormat: - m_formatters[key] = new AWNoFormatter(this, m_genericConfig, name); - break; - } + qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key; + m_formatters[key] = m_formattersClasses[name]; } settings.endGroup(); } + + +void AWFormatterHelper::installDirectories() +{ + // create directory at $HOME + QString localDir = QString("%1/awesomewidgets/formatters") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)); + QDir localDirectory; + if (localDirectory.mkpath(localDir)) + qCInfo(LOG_LIB) << "Created directory" << localDir; + + m_directories = QStandardPaths::locateAll( + QStandardPaths::GenericDataLocation, + QString("awesomewidgets/formatters"), QStandardPaths::LocateDirectory); + + m_formatterConfig = QString("%1/awesomewidgets/formatters/formatters.ini") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)); +} + + +QPair +AWFormatterHelper::readMetadata(const QString filePath) const +{ + qCDebug(LOG_AW) << "Read initial parameters from" << filePath; + + QSettings settings(filePath, QSettings::IniFormat); + settings.beginGroup(QString("Desktop Entry")); + QString name = settings.value(QString("Name"), filePath).toString(); + QString type + = settings.value(QString("Type"), QString("NoFormat")).toString(); + FormatterClass formatter = defineFormatterClass(type); + settings.endGroup(); + + return QPair(name, formatter); +} diff --git a/sources/awesome-widget/plugin/awformatterhelper.h b/sources/awesome-widget/plugin/awformatterhelper.h index 784f5f9..779dd36 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.h +++ b/sources/awesome-widget/plugin/awformatterhelper.h @@ -35,14 +35,21 @@ public: virtual ~AWFormatterHelper(); QString convert(const QVariant &value, const QString name) const; QStringList definedFormatters() const; + QStringList knownFormatters() const; private: AWFormatterHelper::FormatterClass - defineFormatterClass(const QString name) const; - void init(); + defineFormatterClass(const QString stringType) const; + void initFormatters(); + void initKeys(); + void installDirectories(); + QPair + readMetadata(const QString filePath) const; // properties - QString m_genericConfig; + QStringList m_directories; + QString m_formatterConfig; QHash m_formatters; + QHash m_formattersClasses; }; diff --git a/sources/awesome-widget/plugin/awnoformatter.cpp b/sources/awesome-widget/plugin/awnoformatter.cpp index f36a2b5..a7903a2 100644 --- a/sources/awesome-widget/plugin/awnoformatter.cpp +++ b/sources/awesome-widget/plugin/awnoformatter.cpp @@ -17,43 +17,87 @@ #include "awnoformatter.h" +#include "ui_awnoformatter.h" + +#include #include "awdebug.h" -AWNoFormatter::AWNoFormatter(QObject *parent, const QString filename, - const QString section) - : AWAbstractFormatter(parent, filename, section) +AWNoFormatter::AWNoFormatter(QWidget *parent, const QString filePath) + : AWAbstractFormatter(parent, filePath) + , ui(new Ui::AWNoFormatter) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; - init(filename, section); + readConfiguration(); + ui->setupUi(this); + translate(); } -AWNoFormatter::AWNoFormatter(QObject *parent) +AWNoFormatter::AWNoFormatter(QWidget *parent) : AWAbstractFormatter(parent) + , ui(new Ui::AWNoFormatter) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + ui->setupUi(this); + translate(); } AWNoFormatter::~AWNoFormatter() { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + delete ui; } -QString AWNoFormatter::convert(const QVariant &value) const +QString AWNoFormatter::convert(const QVariant &_value) const { - qCDebug(LOG_AW) << "Convert value" << value; + qCDebug(LOG_AW) << "Convert value" << _value; - return value.toString(); + return _value.toString(); } -void AWNoFormatter::init(const QString filename, const QString section) +AWNoFormatter *AWNoFormatter::copy(const QString _fileName) { - qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename; - // dummy method for future references + qCDebug(LOG_LIB) << "File" << _fileName; + + AWNoFormatter *item + = new AWNoFormatter(static_cast(parent()), _fileName); + copyDefaults(item); + + return item; +} + + +int AWNoFormatter::showConfiguration(const QVariant args) +{ + Q_UNUSED(args) + + ui->lineEdit_name->setText(name()); + ui->lineEdit_comment->setText(comment()); + ui->label_typeValue->setText(QString("NoFormat")); + + int ret = exec(); + if (ret != 1) + return ret; + setName(ui->lineEdit_name->text()); + setComment(ui->lineEdit_comment->text()); + setType(ui->label_typeValue->text()); + + writeConfiguration(); + return ret; +} + + +void AWNoFormatter::translate() +{ + ui->label_name->setText(i18n("Name")); + ui->label_comment->setText(i18n("Comment")); + ui->label_type->setText(i18n("Type")); } diff --git a/sources/awesome-widget/plugin/awnoformatter.h b/sources/awesome-widget/plugin/awnoformatter.h index 0251b50..77b50c7 100644 --- a/sources/awesome-widget/plugin/awnoformatter.h +++ b/sources/awesome-widget/plugin/awnoformatter.h @@ -21,19 +21,28 @@ #include "awabstractformatter.h" +namespace Ui +{ +class AWNoFormatter; +} + class AWNoFormatter : public AWAbstractFormatter { Q_OBJECT public: - explicit AWNoFormatter(QObject *parent, const QString filename, - const QString section); - explicit AWNoFormatter(QObject *parent); + explicit AWNoFormatter(QWidget *parent, const QString filePath); + explicit AWNoFormatter(QWidget *parent); virtual ~AWNoFormatter(); - QString convert(const QVariant &value) const; + QString convert(const QVariant &_value) const; + AWNoFormatter *copy(const QString _fileName); + +public slots: + int showConfiguration(const QVariant args = QVariant()); private: - void init(const QString filename, const QString section); + Ui::AWNoFormatter *ui; + void translate(); // properties }; diff --git a/sources/awesome-widget/plugin/awnoformatter.ui b/sources/awesome-widget/plugin/awnoformatter.ui new file mode 100644 index 0000000..8112539 --- /dev/null +++ b/sources/awesome-widget/plugin/awnoformatter.ui @@ -0,0 +1,144 @@ + + + AWNoFormatter + + + + 0 + 0 + 420 + 128 + + + + Configuration + + + + + + + + + 0 + 0 + + + + Name + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + 0 + 0 + + + + Comment + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + Type + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AWNoFormatter + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AWNoFormatter + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/awesome-widget/plugin/awscriptformatter.cpp b/sources/awesome-widget/plugin/awscriptformatter.cpp index 0f056d2..d2b1eaa 100644 --- a/sources/awesome-widget/plugin/awscriptformatter.cpp +++ b/sources/awesome-widget/plugin/awscriptformatter.cpp @@ -17,27 +17,33 @@ #include "awscriptformatter.h" +#include "ui_awscriptformatter.h" +#include + +#include #include #include #include "awdebug.h" -AWScriptFormatter::AWScriptFormatter(QObject *parent, const QString filename, - const QString section) - : AWAbstractFormatter(parent, filename, section) +AWScriptFormatter::AWScriptFormatter(QWidget *parent, const QString filePath) + : AWAbstractFormatter(parent, filePath) + , ui(new Ui::AWScriptFormatter) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; - init(filename, section); - initProgram(); + readConfiguration(); + ui->setupUi(this); + translate(); } -AWScriptFormatter::AWScriptFormatter(QObject *parent, const bool appendCode, - const QString code, const bool hasReturn) +AWScriptFormatter::AWScriptFormatter(const bool appendCode, const QString code, + const bool hasReturn, QWidget *parent) : AWAbstractFormatter(parent) + , ui(new Ui::AWScriptFormatter) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; @@ -45,23 +51,28 @@ AWScriptFormatter::AWScriptFormatter(QObject *parent, const bool appendCode, setCode(code); setHasReturn(hasReturn); initProgram(); + + ui->setupUi(this); + translate(); } AWScriptFormatter::~AWScriptFormatter() { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + delete ui; } -QString AWScriptFormatter::convert(const QVariant &value) const +QString AWScriptFormatter::convert(const QVariant &_value) const { - qCDebug(LOG_AW) << "Convert value" << value; + qCDebug(LOG_AW) << "Convert value" << _value; // init engine QJSEngine engine; QJSValue fn = engine.evaluate(m_program); - QJSValueList args = QJSValueList() << value.toString(); + QJSValueList args = QJSValueList() << _value.toString(); QJSValue result = fn.call(args); if (result.isError()) { @@ -75,6 +86,21 @@ QString AWScriptFormatter::convert(const QVariant &value) const } +AWScriptFormatter *AWScriptFormatter::copy(const QString _fileName) +{ + qCDebug(LOG_LIB) << "File" << _fileName; + + AWScriptFormatter *item + = new AWScriptFormatter(static_cast(parent()), _fileName); + copyDefaults(item); + item->setAppendCode(appendCode()); + item->setCode(code()); + item->setHasReturn(hasReturn()); + + return item; +} + + bool AWScriptFormatter::appendCode() const { return m_appendCode; @@ -123,17 +149,65 @@ void AWScriptFormatter::setHasReturn(const bool _hasReturn) } -void AWScriptFormatter::init(const QString filename, const QString section) +void AWScriptFormatter::readConfiguration() { - qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename; + AWAbstractFormatter::readConfiguration(); - QSettings settings(filename, QSettings::IniFormat); + QSettings settings(fileName(), QSettings::IniFormat); - settings.beginGroup(section); - setAppendCode(settings.value(QString("AppendCode"), true).toBool()); - setCode(settings.value(QString("Code"), QString()).toString()); - setHasReturn(settings.value(QString("HasReturn"), false).toBool()); + settings.beginGroup(QString("Desktop Entry")); + setAppendCode(settings.value(QString("AppendCode"), m_appendCode).toBool()); + setCode(settings.value(QString("Code"), m_code).toString()); + setHasReturn(settings.value(QString("HasReturn"), m_hasReturn).toBool()); settings.endGroup(); + + initProgram(); +} + + +int AWScriptFormatter::showConfiguration(const QVariant args) +{ + Q_UNUSED(args) + + ui->lineEdit_name->setText(name()); + ui->lineEdit_comment->setText(comment()); + ui->label_typeValue->setText(QString("Script")); + ui->checkBox_appendCode->setCheckState(m_appendCode ? Qt::Checked + : Qt::Unchecked); + ui->checkBox_hasReturn->setCheckState(m_hasReturn ? Qt::Checked + : Qt::Unchecked); + ui->textEdit_code->setPlainText(m_code); + + int ret = exec(); + if (ret != 1) + return ret; + setName(ui->lineEdit_name->text()); + setComment(ui->lineEdit_comment->text()); + setType(ui->label_typeValue->text()); + setAppendCode(ui->checkBox_appendCode->checkState() == Qt::Checked); + setHasReturn(ui->checkBox_hasReturn->checkState() == Qt::Checked); + setCode(ui->textEdit_code->toPlainText()); + initProgram(); + + writeConfiguration(); + return ret; +} + + +void AWScriptFormatter::writeConfiguration() const +{ + AWAbstractFormatter::writeConfiguration(); + + QSettings settings(writtableConfig(), QSettings::IniFormat); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); + + settings.beginGroup(QString("Desktop Entry")); + settings.setValue(QString("AppendCode"), m_appendCode); + settings.setValue(QString("Code"), m_code); + settings.setValue(QString("HasReturn"), m_hasReturn); + settings.endGroup(); + + settings.sync(); } @@ -149,3 +223,14 @@ void AWScriptFormatter::initProgram() qCInfo(LOG_AW) << "Create JS engine with code" << m_program; } + + +void AWScriptFormatter::translate() +{ + ui->label_name->setText(i18n("Name")); + ui->label_comment->setText(i18n("Comment")); + ui->label_type->setText(i18n("Type")); + ui->checkBox_appendCode->setText(i18n("Append code")); + ui->checkBox_hasReturn->setText(i18n("Has return")); + ui->label_code->setText(i18n("Code")); +} diff --git a/sources/awesome-widget/plugin/awscriptformatter.h b/sources/awesome-widget/plugin/awscriptformatter.h index 1749e90..3939917 100644 --- a/sources/awesome-widget/plugin/awscriptformatter.h +++ b/sources/awesome-widget/plugin/awscriptformatter.h @@ -21,6 +21,11 @@ #include "awabstractformatter.h" +namespace Ui +{ +class AWScriptFormatter; +} + class AWScriptFormatter : public AWAbstractFormatter { Q_OBJECT @@ -30,12 +35,12 @@ class AWScriptFormatter : public AWAbstractFormatter Q_PROPERTY(QString program READ program) public: - explicit AWScriptFormatter(QObject *parent, const QString filename, - const QString section); - explicit AWScriptFormatter(QObject *parent, const bool appendCode, - const QString code, const bool hasReturn); + explicit AWScriptFormatter(QWidget *parent, const QString filePath); + explicit AWScriptFormatter(const bool appendCode, const QString code, + const bool hasReturn, QWidget *parent); virtual ~AWScriptFormatter(); - QString convert(const QVariant &value) const; + QString convert(const QVariant &_value) const; + AWScriptFormatter *copy(const QString _fileName); // properties bool appendCode() const; QString code() const; @@ -45,13 +50,19 @@ public: void setCode(const QString _code); void setHasReturn(const bool _hasReturn); +public slots: + void readConfiguration(); + int showConfiguration(const QVariant args = QVariant()); + void writeConfiguration() const; + private: - void init(const QString filename, const QString section); + Ui::AWScriptFormatter *ui; void initProgram(); + void translate(); // properties - bool m_appendCode; - QString m_code; - bool m_hasReturn; + bool m_appendCode = true; + QString m_code = QString(); + bool m_hasReturn = false; QString m_program; }; diff --git a/sources/awesome-widget/plugin/awscriptformatter.ui b/sources/awesome-widget/plugin/awscriptformatter.ui new file mode 100644 index 0000000..a752a0d --- /dev/null +++ b/sources/awesome-widget/plugin/awscriptformatter.ui @@ -0,0 +1,212 @@ + + + AWScriptFormatter + + + + 0 + 0 + 420 + 315 + + + + Configuration + + + + + + + + + 0 + 0 + + + + Name + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + 0 + 0 + + + + Comment + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + Type + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Append code + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Has return + + + + + + + + + Qt::Horizontal + + + + + + + + + Code + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AWScriptFormatter + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AWScriptFormatter + reject() + + + 316 + 260 + + + 286 + 274 + + + + + From 14aab3b7581155f08c2de91863dda0aad0705a8d Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 11 May 2016 14:02:15 +0300 Subject: [PATCH 03/32] rewrite extensions to new model --- sources/awesomewidgets/abstractextitem.cpp | 76 +++++++++----------- sources/awesomewidgets/abstractextitem.h | 9 +-- sources/awesomewidgets/extitemaggregator.h | 40 ++++++----- sources/awesomewidgets/extquotes.cpp | 32 +++------ sources/awesomewidgets/extquotes.h | 3 +- sources/awesomewidgets/extscript.cpp | 43 +++++------- sources/awesomewidgets/extscript.h | 3 +- sources/awesomewidgets/extupgrade.cpp | 35 ++++------ sources/awesomewidgets/extupgrade.h | 3 +- sources/awesomewidgets/extweather.cpp | 41 ++++------- sources/awesomewidgets/extweather.h | 3 +- sources/awesomewidgets/graphicalitem.cpp | 80 +++++++++------------- sources/awesomewidgets/graphicalitem.h | 3 +- 13 files changed, 151 insertions(+), 220 deletions(-) diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index fc6abde..7ec998f 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -26,16 +26,13 @@ #include "abstractextitemaggregator.h" -AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName, - const QStringList directories) +AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath) : QDialog(parent) - , m_fileName(desktopName) - , m_dirs(directories) + , m_fileName(filePath) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - qCDebug(LOG_LIB) << "Desktop name" << desktopName << "directories" - << directories; + qCDebug(LOG_LIB) << "Desktop name" << filePath; m_name = m_fileName; } @@ -57,6 +54,21 @@ void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const } +QString AbstractExtItem::writtableConfig() const +{ + QStringList paths = m_fileName.split(QChar('/')); + + QString name = paths.takeLast(); + QString dir = paths.takeLast(); + + return QString("%1/awesomewidgets/%2/%3") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)) + .arg(dir) + .arg(name); +} + + int AbstractExtItem::apiVersion() const { return m_apiVersion; @@ -69,12 +81,6 @@ QString AbstractExtItem::comment() const } -QStringList AbstractExtItem::directories() const -{ - return m_dirs; -} - - QString AbstractExtItem::fileName() const { return m_fileName; @@ -173,48 +179,34 @@ void AbstractExtItem::setNumber(int _number) void AbstractExtItem::readConfiguration() { - for (int i = m_dirs.count() - 1; i >= 0; i--) { - if (!QDir(m_dirs.at(i)).entryList(QDir::Files).contains(m_fileName)) - continue; - QSettings settings(QString("%1/%2").arg(m_dirs.at(i)).arg(m_fileName), - QSettings::IniFormat); + QSettings settings(m_fileName, QSettings::IniFormat); - settings.beginGroup(QString("Desktop Entry")); - setName(settings.value(QString("Name"), m_name).toString()); - setComment(settings.value(QString("Comment"), m_comment).toString()); - setApiVersion( - settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt()); - setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)) - .toString() - == QString("true")); - setInterval( - settings.value(QString("X-AW-Interval"), m_interval).toInt()); - setNumber(settings.value(QString("X-AW-Number"), m_number).toInt()); - settings.endGroup(); - } + settings.beginGroup(QString("Desktop Entry")); + setName(settings.value(QString("Name"), m_name).toString()); + setComment(settings.value(QString("Comment"), m_comment).toString()); + setApiVersion( + settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt()); + setActive( + settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() + == QString("true")); + setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt()); + setNumber(settings.value(QString("X-AW-Number"), m_number).toInt()); + settings.endGroup(); } bool AbstractExtItem::tryDelete() const { - for (auto dir : m_dirs) { - bool status = QFile::remove(QString("%1/%2").arg(dir).arg(m_fileName)); - qCInfo(LOG_LIB) << "Remove file" - << QString("%1/%2").arg(dir).arg(m_fileName) << status; - } + bool status = QFile::remove(m_fileName); + qCInfo(LOG_AW) << "Remove file" << m_fileName << status; - // check if exists - for (auto dir : m_dirs) - if (QFile::exists(QString("%1/%2").arg(dir).arg(m_fileName))) - return false; - return true; + return status; } void AbstractExtItem::writeConfiguration() const { - QSettings settings(QString("%1/%2").arg(m_dirs.first()).arg(m_fileName), - QSettings::IniFormat); + QSettings settings(writtableConfig(), QSettings::IniFormat); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index e2ec0b8..ff02013 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -28,7 +28,6 @@ class AbstractExtItem : public QDialog Q_PROPERTY(bool active READ isActive WRITE setActive) Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion) Q_PROPERTY(QString comment READ comment WRITE setComment) - Q_PROPERTY(QStringList directories READ directories) Q_PROPERTY(QString fileName READ fileName) Q_PROPERTY(int interval READ interval WRITE setInterval) Q_PROPERTY(QString name READ name WRITE setName) @@ -37,16 +36,15 @@ class AbstractExtItem : public QDialog public: explicit AbstractExtItem(QWidget *parent = nullptr, - const QString desktopName = QString(), - const QStringList directories = QStringList()); + const QString filePath = QString()); virtual ~AbstractExtItem(); virtual AbstractExtItem *copy(const QString _fileName, const int _number) = 0; - void copyDefaults(AbstractExtItem *_other) const; + virtual void copyDefaults(AbstractExtItem *_other) const; + QString writtableConfig() const; // get methods int apiVersion() const; QString comment() const; - QStringList directories() const; QString fileName() const; int interval() const; bool isActive() const; @@ -71,7 +69,6 @@ public slots: private: QString m_fileName; - QStringList m_dirs; virtual void translate() = 0; // properties int m_apiVersion = 0; diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h index df92a16..740d018 100644 --- a/sources/awesomewidgets/extitemaggregator.h +++ b/sources/awesomewidgets/extitemaggregator.h @@ -57,7 +57,7 @@ public: void editItems() { - repaint(); + repaintList(); int ret = dialog->exec(); qCInfo(LOG_LIB) << "Dialog returns" << ret; }; @@ -104,7 +104,8 @@ public: T *found = nullptr; for (auto item : m_items) { - if (item->fileName() != widgetItem->text()) + QString fileName = QFileInfo(item->fileName()).fileName(); + if (fileName != widgetItem->text()) continue; found = item; break; @@ -135,7 +136,6 @@ private: QList m_activeItems; QString m_type; - // init method QList getItems() { // create directory at $HOME @@ -161,7 +161,8 @@ private: continue; qCInfo(LOG_LIB) << "Found file" << file << "in" << dir; names.append(file); - items.append(new T(this, file, dirs)); + QString filePath = QString("%1/%2").arg(dir).arg(file); + items.append(new T(this, filePath)); } } @@ -185,12 +186,13 @@ private: } }; - void repaint() + void repaintList() { widgetDialog->clear(); for (auto _item : m_items) { + QString fileName = QFileInfo(_item->fileName()).fileName(); QListWidgetItem *item - = new QListWidgetItem(_item->fileName(), widgetDialog); + = new QListWidgetItem(fileName, widgetDialog); QStringList tooltip; tooltip.append(i18n("Name: %1", _item->name())); tooltip.append(i18n("Comment: %1", _item->comment())); @@ -206,15 +208,20 @@ private: T *source = itemFromWidget(); QString fileName = getName(); int number = uniqNumber(); + QString dir = QString("%1/awesomewidgets/%2") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)) + .arg(m_type); if ((source == nullptr) || (fileName.isEmpty())) { qCWarning(LOG_LIB) << "Nothing to copy"; return; } + QString filePath = QString("%1/%2").arg(dir).arg(fileName); - T *newItem = static_cast(source->copy(fileName, number)); + T *newItem = static_cast(source->copy(filePath, number)); if (newItem->showConfiguration(configArgs()) == 1) { initItems(); - repaint(); + repaintList(); } }; @@ -222,20 +229,21 @@ private: { QString fileName = getName(); int number = uniqNumber(); - QStringList dirs = QStandardPaths::locateAll( - QStandardPaths::GenericDataLocation, - QString("awesomewidgets/%1").arg(m_type), - QStandardPaths::LocateDirectory); + QString dir = QString("%1/awesomewidgets/%2") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)) + .arg(m_type); if (fileName.isEmpty()) { qCWarning(LOG_LIB) << "Nothing to create"; return; }; + QString filePath = QString("%1/%2").arg(dir).arg(fileName); - T *newItem = new T(this, fileName, dirs); + T *newItem = new T(this, filePath); newItem->setNumber(number); if (newItem->showConfiguration(configArgs()) == 1) { initItems(); - repaint(); + repaintList(); } }; @@ -249,7 +257,7 @@ private: if (source->tryDelete()) { initItems(); - repaint(); + repaintList(); } }; @@ -263,7 +271,7 @@ private: if (source->showConfiguration(configArgs()) == 1) { initItems(); - repaint(); + repaintList(); } }; }; diff --git a/sources/awesomewidgets/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp index 473b2a1..e115a35 100644 --- a/sources/awesomewidgets/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -33,9 +33,8 @@ #include "awdebug.h" -ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName, - const QStringList directories) - : AbstractExtItem(parent, quotesName, directories) +ExtQuotes::ExtQuotes(QWidget *parent, const QString filePath) + : AbstractExtItem(parent, filePath) , ui(new Ui::ExtQuotes) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; @@ -76,11 +75,10 @@ ExtQuotes::~ExtQuotes() ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number) { - qCDebug(LOG_LIB) << "File" << _fileName; - qCDebug(LOG_LIB) << "Number" << _number; + qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number; - ExtQuotes *item = new ExtQuotes(static_cast(parent()), _fileName, - directories()); + ExtQuotes *item + = new ExtQuotes(static_cast(parent()), _fileName); copyDefaults(item); item->setNumber(_number); item->setTicker(ticker()); @@ -113,19 +111,11 @@ void ExtQuotes::readConfiguration() { AbstractExtItem::readConfiguration(); - for (int i = directories().count() - 1; i >= 0; i--) { - if (!QDir(directories().at(i)) - .entryList(QDir::Files) - .contains(fileName())) - continue; - QSettings settings( - QString("%1/%2").arg(directories().at(i)).arg(fileName()), - QSettings::IniFormat); + QSettings settings(fileName(), QSettings::IniFormat); - settings.beginGroup(QString("Desktop Entry")); - setTicker(settings.value(QString("X-AW-Ticker"), m_ticker).toString()); - settings.endGroup(); - } + settings.beginGroup(QString("Desktop Entry")); + setTicker(settings.value(QString("X-AW-Ticker"), m_ticker).toString()); + settings.endGroup(); // update for current API if ((apiVersion() > 0) && (apiVersion() < AWEQAPI)) { @@ -200,9 +190,7 @@ void ExtQuotes::writeConfiguration() const { AbstractExtItem::writeConfiguration(); - QSettings settings( - QString("%1/%2").arg(directories().first()).arg(fileName()), - QSettings::IniFormat); + QSettings settings(writtableConfig(), QSettings::IniFormat); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); diff --git a/sources/awesomewidgets/extquotes.h b/sources/awesomewidgets/extquotes.h index 4ec2757..16c3fe7 100644 --- a/sources/awesomewidgets/extquotes.h +++ b/sources/awesomewidgets/extquotes.h @@ -39,8 +39,7 @@ class ExtQuotes : public AbstractExtItem public: explicit ExtQuotes(QWidget *parent = nullptr, - const QString quotesName = QString(), - const QStringList directories = QStringList()); + const QString filePath = QString()); virtual ~ExtQuotes(); ExtQuotes *copy(const QString _fileName, const int _number); // get methods diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index a674ff3..3e278c6 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -30,9 +30,8 @@ #include "awdebug.h" -ExtScript::ExtScript(QWidget *parent, const QString scriptName, - const QStringList directories) - : AbstractExtItem(parent, scriptName, directories) +ExtScript::ExtScript(QWidget *parent, const QString filePath) + : AbstractExtItem(parent, filePath) , ui(new Ui::ExtScript) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; @@ -65,8 +64,8 @@ ExtScript *ExtScript::copy(const QString _fileName, const int _number) { qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number; - ExtScript *item = new ExtScript(static_cast(parent()), _fileName, - directories()); + ExtScript *item + = new ExtScript(static_cast(parent()), _fileName); copyDefaults(item); item->setExecutable(executable()); item->setNumber(_number); @@ -215,26 +214,18 @@ void ExtScript::readConfiguration() { AbstractExtItem::readConfiguration(); - for (int i = directories().count() - 1; i >= 0; i--) { - if (!QDir(directories().at(i)) - .entryList(QDir::Files) - .contains(fileName())) - continue; - QSettings settings( - QString("%1/%2").arg(directories().at(i)).arg(fileName()), - QSettings::IniFormat); + QSettings settings(fileName(), QSettings::IniFormat); - settings.beginGroup(QString("Desktop Entry")); - setExecutable(settings.value(QString("Exec"), m_executable).toString()); - setPrefix(settings.value(QString("X-AW-Prefix"), m_prefix).toString()); - setStrRedirect( - settings.value(QString("X-AW-Redirect"), strRedirect()).toString()); - // api == 3 - setFilters(settings.value(QString("X-AW-Filters"), m_filters) - .toString() - .split(QChar(','), QString::SkipEmptyParts)); - settings.endGroup(); - } + settings.beginGroup(QString("Desktop Entry")); + setExecutable(settings.value(QString("Exec"), m_executable).toString()); + setPrefix(settings.value(QString("X-AW-Prefix"), m_prefix).toString()); + setStrRedirect( + settings.value(QString("X-AW-Redirect"), strRedirect()).toString()); + // api == 3 + setFilters(settings.value(QString("X-AW-Filters"), m_filters) + .toString() + .split(QChar(','), QString::SkipEmptyParts)); + settings.endGroup(); // update for current API if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) { @@ -344,9 +335,7 @@ void ExtScript::writeConfiguration() const { AbstractExtItem::writeConfiguration(); - QSettings settings( - QString("%1/%2").arg(directories().first()).arg(fileName()), - QSettings::IniFormat); + QSettings settings(writtableConfig(), QSettings::IniFormat); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); diff --git a/sources/awesomewidgets/extscript.h b/sources/awesomewidgets/extscript.h index 8d1e9b1..a6be0bd 100644 --- a/sources/awesomewidgets/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -40,8 +40,7 @@ public: enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap }; explicit ExtScript(QWidget *parent = nullptr, - const QString scriptName = QString(), - const QStringList directories = QStringList()); + const QString filePath = QString()); virtual ~ExtScript(); ExtScript *copy(const QString _fileName, const int _number); // get methods diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index 9c23963..fe5cd11 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -28,9 +28,8 @@ #include "awdebug.h" -ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName, - const QStringList directories) - : AbstractExtItem(parent, upgradeName, directories) +ExtUpgrade::ExtUpgrade(QWidget *parent, const QString filePath) + : AbstractExtItem(parent, filePath) , ui(new Ui::ExtUpgrade) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; @@ -61,8 +60,8 @@ ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number) { qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number; - ExtUpgrade *item = new ExtUpgrade(static_cast(parent()), - _fileName, directories()); + ExtUpgrade *item + = new ExtUpgrade(static_cast(parent()), _fileName); copyDefaults(item); item->setExecutable(executable()); item->setFilter(filter()); @@ -127,22 +126,14 @@ void ExtUpgrade::readConfiguration() { AbstractExtItem::readConfiguration(); - for (int i = directories().count() - 1; i >= 0; i--) { - if (!QDir(directories().at(i)) - .entryList(QDir::Files) - .contains(fileName())) - continue; - QSettings settings( - QString("%1/%2").arg(directories().at(i)).arg(fileName()), - QSettings::IniFormat); + QSettings settings(fileName(), QSettings::IniFormat); - settings.beginGroup(QString("Desktop Entry")); - setExecutable(settings.value(QString("Exec"), m_executable).toString()); - setNull(settings.value(QString("X-AW-Null"), m_null).toInt()); - // api == 3 - setFilter(settings.value(QString("X-AW-Filter"), m_filter).toString()); - settings.endGroup(); - } + settings.beginGroup(QString("Desktop Entry")); + setExecutable(settings.value(QString("Exec"), m_executable).toString()); + setNull(settings.value(QString("X-AW-Null"), m_null).toInt()); + // api == 3 + setFilter(settings.value(QString("X-AW-Filter"), m_filter).toString()); + settings.endGroup(); // update for current API if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) { @@ -208,9 +199,7 @@ void ExtUpgrade::writeConfiguration() const { AbstractExtItem::writeConfiguration(); - QSettings settings( - QString("%1/%2").arg(directories().first()).arg(fileName()), - QSettings::IniFormat); + QSettings settings(writtableConfig(), QSettings::IniFormat); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); diff --git a/sources/awesomewidgets/extupgrade.h b/sources/awesomewidgets/extupgrade.h index c5a3b8a..709d4d7 100644 --- a/sources/awesomewidgets/extupgrade.h +++ b/sources/awesomewidgets/extupgrade.h @@ -37,8 +37,7 @@ class ExtUpgrade : public AbstractExtItem public: explicit ExtUpgrade(QWidget *parent = nullptr, - const QString upgradeName = QString(), - const QStringList directories = QStringList()); + const QString filePath = QString()); virtual ~ExtUpgrade(); ExtUpgrade *copy(const QString _fileName, const int _number); // get methods diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 63f8c18..5e66da8 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -34,9 +34,8 @@ #include "awdebug.h" -ExtWeather::ExtWeather(QWidget *parent, const QString weatherName, - const QStringList directories) - : AbstractExtItem(parent, weatherName, directories) +ExtWeather::ExtWeather(QWidget *parent, const QString filePath) + : AbstractExtItem(parent, filePath) , ui(new Ui::ExtWeather) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; @@ -76,8 +75,8 @@ ExtWeather *ExtWeather::copy(const QString _fileName, const int _number) { qCDebug(LOG_LIB) << "File" << _fileName << "number" << _number; - ExtWeather *item = new ExtWeather(static_cast(parent()), - _fileName, directories()); + ExtWeather *item + = new ExtWeather(static_cast(parent()), _fileName); copyDefaults(item); item->setCity(city()); item->setCountry(country()); @@ -165,26 +164,16 @@ void ExtWeather::readConfiguration() { AbstractExtItem::readConfiguration(); - for (int i = directories().count() - 1; i >= 0; i--) { - if (!QDir(directories().at(i)) - .entryList(QDir::Files) - .contains(fileName())) - continue; - QSettings settings( - QString("%1/%2").arg(directories().at(i)).arg(fileName()), - QSettings::IniFormat); + QSettings settings(fileName(), QSettings::IniFormat); - settings.beginGroup(QString("Desktop Entry")); - setCity(settings.value(QString("X-AW-City"), m_city).toString()); - setCountry( - settings.value(QString("X-AW-Country"), m_country).toString()); - setTs(settings.value(QString("X-AW-TS"), m_ts).toInt()); - // api == 2 - setImage( - settings.value(QString("X-AW-Image"), QVariant(m_image)).toString() - == QString("true")); - settings.endGroup(); - } + settings.beginGroup(QString("Desktop Entry")); + setCity(settings.value(QString("X-AW-City"), m_city).toString()); + setCountry(settings.value(QString("X-AW-Country"), m_country).toString()); + setTs(settings.value(QString("X-AW-TS"), m_ts).toInt()); + // api == 2 + setImage(settings.value(QString("X-AW-Image"), QVariant(m_image)).toString() + == QString("true")); + settings.endGroup(); // update for current API if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) { @@ -291,9 +280,7 @@ void ExtWeather::writeConfiguration() const { AbstractExtItem::writeConfiguration(); - QSettings settings( - QString("%1/%2").arg(directories().first()).arg(fileName()), - QSettings::IniFormat); + QSettings settings(writtableConfig(), QSettings::IniFormat); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); diff --git a/sources/awesomewidgets/extweather.h b/sources/awesomewidgets/extweather.h index 1320a22..e4d91ee 100644 --- a/sources/awesomewidgets/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -43,8 +43,7 @@ class ExtWeather : public AbstractExtItem public: explicit ExtWeather(QWidget *parent = nullptr, - const QString weatherName = QString(), - const QStringList directories = QStringList()); + const QString filePath = QString()); virtual ~ExtWeather(); ExtWeather *copy(const QString _fileName, const int _number); QString weatherFromInt(const int _id) const; diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 4579a06..d31b2a6 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -32,9 +32,8 @@ #include "graphicalitemhelper.h" -GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, - const QStringList directories) - : AbstractExtItem(parent, desktopName, directories) +GraphicalItem::GraphicalItem(QWidget *parent, const QString filePath) + : AbstractExtItem(parent, filePath) , ui(new Ui::GraphicalItem) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; @@ -70,8 +69,8 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number) { qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number; - GraphicalItem *item = new GraphicalItem(static_cast(parent()), - _fileName, directories()); + GraphicalItem *item + = new GraphicalItem(static_cast(parent()), _fileName); copyDefaults(item); item->setActiveColor(m_activeColor); item->setBar(m_bar); @@ -401,47 +400,36 @@ void GraphicalItem::readConfiguration() { AbstractExtItem::readConfiguration(); - for (int i = directories().count() - 1; i >= 0; i--) { - if (!QDir(directories().at(i)) - .entryList(QDir::Files) - .contains(fileName())) - continue; - QSettings settings( - QString("%1/%2").arg(directories().at(i)).arg(fileName()), - QSettings::IniFormat); + QSettings settings(fileName(), QSettings::IniFormat); - settings.beginGroup(QString("Desktop Entry")); - setCount(settings.value(QString("X-AW-Count"), m_count).toInt()); - setCustom(settings.value(QString("X-AW-Custom"), m_custom).toBool()); - setBar(settings.value(QString("X-AW-Value"), m_bar).toString()); - setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat()); - setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat()); - setActiveColor( - settings.value(QString("X-AW-ActiveColor"), m_activeColor) - .toString()); - setInactiveColor( - settings.value(QString("X-AW-InactiveColor"), m_inactiveColor) - .toString()); - setStrType(settings.value(QString("X-AW-Type"), strType()).toString()); - setStrDirection( - settings.value(QString("X-AW-Direction"), strDirection()) - .toString()); - setHeight(settings.value(QString("X-AW-Height"), m_height).toInt()); - setWidth(settings.value(QString("X-AW-Width"), m_width).toInt()); - // api == 5 - if (apiVersion() < 5) { - QString prefix; - prefix = m_activeColor.startsWith(QString("/")) - ? QString("file://%1") - : QString("color://%1"); - m_activeColor = prefix.arg(m_activeColor); - prefix = m_inactiveColor.startsWith(QString("/")) - ? QString("file://%1") - : QString("color://%1"); - m_inactiveColor = prefix.arg(m_inactiveColor); - } - settings.endGroup(); + settings.beginGroup(QString("Desktop Entry")); + setCount(settings.value(QString("X-AW-Count"), m_count).toInt()); + setCustom(settings.value(QString("X-AW-Custom"), m_custom).toBool()); + setBar(settings.value(QString("X-AW-Value"), m_bar).toString()); + setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat()); + setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat()); + setActiveColor( + settings.value(QString("X-AW-ActiveColor"), m_activeColor).toString()); + setInactiveColor( + settings.value(QString("X-AW-InactiveColor"), m_inactiveColor) + .toString()); + setStrType(settings.value(QString("X-AW-Type"), strType()).toString()); + setStrDirection( + settings.value(QString("X-AW-Direction"), strDirection()).toString()); + setHeight(settings.value(QString("X-AW-Height"), m_height).toInt()); + setWidth(settings.value(QString("X-AW-Width"), m_width).toInt()); + // api == 5 + if (apiVersion() < 5) { + QString prefix; + prefix = m_activeColor.startsWith(QString("/")) ? QString("file://%1") + : QString("color://%1"); + m_activeColor = prefix.arg(m_activeColor); + prefix = m_inactiveColor.startsWith(QString("/")) + ? QString("file://%1") + : QString("color://%1"); + m_inactiveColor = prefix.arg(m_inactiveColor); } + settings.endGroup(); // update for current API if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) { @@ -520,9 +508,7 @@ void GraphicalItem::writeConfiguration() const { AbstractExtItem::writeConfiguration(); - QSettings settings( - QString("%1/%2").arg(directories().first()).arg(fileName()), - QSettings::IniFormat); + QSettings settings(writtableConfig(), QSettings::IniFormat); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index 24af844..3938c1a 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -53,8 +53,7 @@ public: enum class Type { Horizontal, Vertical, Circle, Graph, Bars }; explicit GraphicalItem(QWidget *parent = nullptr, - const QString desktopName = QString(), - const QStringList directories = QStringList()); + const QString filePath = QString()); virtual ~GraphicalItem(); GraphicalItem *copy(const QString _fileName, const int _number); QString image(const QVariant &value); From 326c65528dd9784370d89466c22c73516f3eb3f6 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 12 May 2016 20:51:21 +0300 Subject: [PATCH 04/32] rewrite formatters to ext classes --- .../awesome-widget/plugin/awesomewidget.cpp | 3 +- .../plugin/awformatterhelper.cpp | 72 +++++++-- .../awesome-widget/plugin/awformatterhelper.h | 20 ++- .../plugin/awkeysaggregator.cpp | 2 +- .../abstractextitemaggregator.cpp | 119 +++++++++++++- .../abstractextitemaggregator.h | 46 +++++- .../awabstractformatter.cpp | 84 ++-------- .../awabstractformatter.h | 25 +-- .../awdatetimeformatter.cpp | 8 +- .../awdatetimeformatter.h | 2 +- .../awdatetimeformatter.ui | 0 .../awfloatformatter.cpp | 8 +- .../awfloatformatter.h | 2 +- .../awfloatformatter.ui | 0 .../awnoformatter.cpp | 7 +- .../plugin => awesomewidgets}/awnoformatter.h | 2 +- .../awnoformatter.ui | 0 .../awscriptformatter.cpp | 8 +- .../awscriptformatter.h | 2 +- .../awscriptformatter.ui | 0 sources/awesomewidgets/extitemaggregator.h | 153 ++---------------- 21 files changed, 288 insertions(+), 275 deletions(-) rename sources/{awesome-widget/plugin => awesomewidgets}/awabstractformatter.cpp (57%) rename sources/{awesome-widget/plugin => awesomewidgets}/awabstractformatter.h (69%) rename sources/{awesome-widget/plugin => awesomewidgets}/awdatetimeformatter.cpp (94%) rename sources/{awesome-widget/plugin => awesomewidgets}/awdatetimeformatter.h (96%) rename sources/{awesome-widget/plugin => awesomewidgets}/awdatetimeformatter.ui (100%) rename sources/{awesome-widget/plugin => awesomewidgets}/awfloatformatter.cpp (97%) rename sources/{awesome-widget/plugin => awesomewidgets}/awfloatformatter.h (97%) rename sources/{awesome-widget/plugin => awesomewidgets}/awfloatformatter.ui (100%) rename sources/{awesome-widget/plugin => awesomewidgets}/awnoformatter.cpp (92%) rename sources/{awesome-widget/plugin => awesomewidgets}/awnoformatter.h (96%) rename sources/{awesome-widget/plugin => awesomewidgets}/awnoformatter.ui (100%) rename sources/{awesome-widget/plugin => awesomewidgets}/awscriptformatter.cpp (96%) rename sources/{awesome-widget/plugin => awesomewidgets}/awscriptformatter.h (97%) rename sources/{awesome-widget/plugin => awesomewidgets}/awscriptformatter.ui (100%) diff --git a/sources/awesome-widget/plugin/awesomewidget.cpp b/sources/awesome-widget/plugin/awesomewidget.cpp index 6d6233b..4235ed5 100644 --- a/sources/awesome-widget/plugin/awesomewidget.cpp +++ b/sources/awesome-widget/plugin/awesomewidget.cpp @@ -21,7 +21,7 @@ #include "awactions.h" #include "awconfighelper.h" -#include "awdataengineaggregator.h" +#include "awformatterhelper.h" #include "awkeys.h" @@ -31,5 +31,6 @@ void AWPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 1, 0, "AWActions"); qmlRegisterType(uri, 1, 0, "AWConfigHelper"); + qmlRegisterType(uri, 1, 0, "AWFormatterHelper"); qmlRegisterType(uri, 1, 0, "AWKeys"); } diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index cac9759..3a42a58 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -17,9 +17,11 @@ #include "awformatterhelper.h" +#include + #include +#include #include -#include #include "awdebug.h" #include "awdatetimeformatter.h" @@ -28,15 +30,13 @@ #include "awscriptformatter.h" -AWFormatterHelper::AWFormatterHelper(QObject *parent) - : QObject(parent) +AWFormatterHelper::AWFormatterHelper(QWidget *parent) + : AbstractExtItemAggregator(parent, QString("formatters")) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; #ifdef BUILD_FUTURE - installDirectories(); - initFormatters(); - initKeys(); + initItems(); #endif /* BUILD_FUTURE */ } @@ -66,12 +66,30 @@ QStringList AWFormatterHelper::definedFormatters() const } +QString AWFormatterHelper::formatterByTag(const QString tag) const +{ + qCDebug(LOG_AW) << "Looking for tag" << tag; + + return m_formatters.contains(tag) ? m_formatters[tag]->name() : QString(); +} + + QStringList AWFormatterHelper::knownFormatters() const { return m_formattersClasses.keys(); } +QList AWFormatterHelper::items() const +{ + QList converted; + for (auto item : m_formattersClasses.values()) + converted.append(item); + + return converted; +} + + AWFormatterHelper::FormatterClass AWFormatterHelper::defineFormatterClass(const QString stringType) const { @@ -114,19 +132,18 @@ void AWFormatterHelper::initFormatters() switch (metadata.second) { case FormatterClass::DateTime: m_formattersClasses[name] - = new AWDateTimeFormatter(nullptr, filePath); + = new AWDateTimeFormatter(this, filePath); break; case FormatterClass::Float: m_formattersClasses[name] - = new AWFloatFormatter(nullptr, filePath); + = new AWFloatFormatter(this, filePath); break; case FormatterClass::Script: m_formattersClasses[name] - = new AWScriptFormatter(nullptr, filePath); + = new AWScriptFormatter(this, filePath); break; case FormatterClass::NoFormat: - m_formattersClasses[name] - = new AWNoFormatter(nullptr, filePath); + m_formattersClasses[name] = new AWNoFormatter(this, filePath); break; } } @@ -185,3 +202,36 @@ AWFormatterHelper::readMetadata(const QString filePath) const return QPair(name, formatter); } + + +void AWFormatterHelper::doCreateItem() +{ + QStringList selection = QStringList() + << QString("NoFormat") << QString("DateTime") + << QString("Float") << QString("Script"); + bool ok; + QString select = QInputDialog::getItem( + this, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok); + if (!ok) + return; + + FormatterClass formatter = defineFormatterClass(select); + switch (formatter) { + case FormatterClass::DateTime: + return createItem(); + case FormatterClass::Float: + return createItem(); + case FormatterClass::Script: + return createItem(); + case FormatterClass::NoFormat: + return createItem(); + } +} + + +void AWFormatterHelper::initItems() +{ + installDirectories(); + initFormatters(); + initKeys(); +} diff --git a/sources/awesome-widget/plugin/awformatterhelper.h b/sources/awesome-widget/plugin/awformatterhelper.h index 779dd36..952452c 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.h +++ b/sources/awesome-widget/plugin/awformatterhelper.h @@ -19,25 +19,28 @@ #ifndef AWFORMATTERHELPER_H #define AWFORMATTERHELPER_H -#include - -#include "awabstractformatter.h" +#include "abstractextitemaggregator.h" -class AWFormatterHelper : public QObject +class AWAbstractFormatter; + +class AWFormatterHelper : public AbstractExtItemAggregator { Q_OBJECT public: enum class FormatterClass { DateTime, Float, Script, NoFormat }; - explicit AWFormatterHelper(QObject *parent = nullptr); + explicit AWFormatterHelper(QWidget *parent = nullptr); virtual ~AWFormatterHelper(); QString convert(const QVariant &value, const QString name) const; - QStringList definedFormatters() const; - QStringList knownFormatters() const; + Q_INVOKABLE QStringList definedFormatters() const; + Q_INVOKABLE QString formatterByTag(const QString tag) const; + Q_INVOKABLE QStringList knownFormatters() const; + QList items() const; private: + // methods AWFormatterHelper::FormatterClass defineFormatterClass(const QString stringType) const; void initFormatters(); @@ -45,6 +48,9 @@ private: void installDirectories(); QPair readMetadata(const QString filePath) const; + // parent methods + void doCreateItem(); + void initItems(); // properties QStringList m_directories; QString m_formatterConfig; diff --git a/sources/awesome-widget/plugin/awkeysaggregator.cpp b/sources/awesome-widget/plugin/awkeysaggregator.cpp index 0f5f0c0..735f716 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.cpp +++ b/sources/awesome-widget/plugin/awkeysaggregator.cpp @@ -49,7 +49,7 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent) m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat; m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat; - m_customFormatters = new AWFormatterHelper(this); + m_customFormatters = new AWFormatterHelper(nullptr); } diff --git a/sources/awesomewidgets/abstractextitemaggregator.cpp b/sources/awesomewidgets/abstractextitemaggregator.cpp index 69113c7..122ab07 100644 --- a/sources/awesomewidgets/abstractextitemaggregator.cpp +++ b/sources/awesomewidgets/abstractextitemaggregator.cpp @@ -19,15 +19,16 @@ #include +#include #include #include #include -#include "awdebug.h" - -AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent) +AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent, + const QString type) : QWidget(parent) + , m_type(type) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; @@ -62,6 +63,59 @@ AbstractExtItemAggregator::~AbstractExtItemAggregator() } +void AbstractExtItemAggregator::copyItem() +{ + AbstractExtItem *source = itemFromWidget(); + QString fileName = getName(); + int number = uniqNumber(); + QString dir = QString("%1/awesomewidgets/%2") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)) + .arg(m_type); + if ((source == nullptr) || (fileName.isEmpty())) { + qCWarning(LOG_LIB) << "Nothing to copy"; + return; + } + QString filePath = QString("%1/%2").arg(dir).arg(fileName); + + AbstractExtItem *newItem = source->copy(filePath, number); + if (newItem->showConfiguration(configArgs()) == 1) { + initItems(); + repaintList(); + } +} + + +void AbstractExtItemAggregator::deleteItem() +{ + AbstractExtItem *source = itemFromWidget(); + if (source == nullptr) { + qCWarning(LOG_LIB) << "Nothing to delete"; + return; + }; + + if (source->tryDelete()) { + initItems(); + repaintList(); + } +} + + +void AbstractExtItemAggregator::editItem() +{ + AbstractExtItem *source = itemFromWidget(); + if (source == nullptr) { + qCWarning(LOG_LIB) << "Nothing to edit"; + return; + }; + + if (source->showConfiguration(configArgs()) == 1) { + initItems(); + repaintList(); + } +} + + QString AbstractExtItemAggregator::getName() { bool ok; @@ -77,12 +131,69 @@ QString AbstractExtItemAggregator::getName() } +AbstractExtItem *AbstractExtItemAggregator::itemFromWidget() +{ + QListWidgetItem *widgetItem = widgetDialog->currentItem(); + if (widgetItem == nullptr) + return nullptr; + + AbstractExtItem *found = nullptr; + for (auto item : items()) { + QString fileName = QFileInfo(item->fileName()).fileName(); + if (fileName != widgetItem->text()) + continue; + found = item; + break; + } + if (found == nullptr) + qCWarning(LOG_LIB) << "Could not find item by name" + << widgetItem->text(); + + return found; +} + + +void AbstractExtItemAggregator::repaintList() +{ + widgetDialog->clear(); + for (auto _item : items()) { + QString fileName = QFileInfo(_item->fileName()).fileName(); + QListWidgetItem *item = new QListWidgetItem(fileName, widgetDialog); + QStringList tooltip; + 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'))); + widgetDialog->addItem(item); + } +} + + +int AbstractExtItemAggregator::uniqNumber() const +{ + QList tagList; + for (auto item : items()) + tagList.append(item->number()); + int number = 0; + while (tagList.contains(number)) + number++; + + return number; +} + + QVariant AbstractExtItemAggregator::configArgs() const { return m_configArgs; } +QString AbstractExtItemAggregator::type() const +{ + return m_type; +} + + void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs) { qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs; @@ -102,7 +213,7 @@ void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button) if (static_cast(button) == copyButton) return copyItem(); else if (static_cast(button) == createButton) - return createItem(); + return doCreateItem(); else if (static_cast(button) == deleteButton) return deleteItem(); else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole) diff --git a/sources/awesomewidgets/abstractextitemaggregator.h b/sources/awesomewidgets/abstractextitemaggregator.h index 54724a2..29d0cb8 100644 --- a/sources/awesomewidgets/abstractextitemaggregator.h +++ b/sources/awesomewidgets/abstractextitemaggregator.h @@ -22,19 +22,52 @@ #include #include #include +#include #include +#include "abstractextitem.h" +#include "awdebug.h" + // additional class since QObject macro does not allow class templates class AbstractExtItemAggregator : public QWidget { Q_OBJECT Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs) + Q_PROPERTY(QVariant type READ type) public: - explicit AbstractExtItemAggregator(QWidget *parent = nullptr); + explicit AbstractExtItemAggregator(QWidget *parent, const QString type); virtual ~AbstractExtItemAggregator(); + // methods + void copyItem(); + template void createItem() + { + QString fileName = getName(); + int number = uniqNumber(); + QString dir = QString("%1/awesomewidgets/%2") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)) + .arg(m_type); + if (fileName.isEmpty()) { + qCWarning(LOG_LIB) << "Nothing to create"; + return; + }; + QString filePath = QString("%1/%2").arg(dir).arg(fileName); + + T *newItem = new T(this, filePath); + newItem->setNumber(number); + if (newItem->showConfiguration(configArgs()) == 1) { + initItems(); + repaintList(); + }; + }; + void deleteItem(); + void editItem(); QString getName(); + AbstractExtItem *itemFromWidget(); + void repaintList(); + int uniqNumber() const; // ui QDialog *dialog = nullptr; QListWidget *widgetDialog = nullptr; @@ -44,6 +77,8 @@ public: QPushButton *deleteButton = nullptr; // get methods QVariant configArgs() const; + virtual QList items() const = 0; + QString type() const; // set methods void setConfigArgs(const QVariant _configArgs); @@ -53,11 +88,10 @@ private slots: private: QVariant m_configArgs; - // methods - virtual void copyItem() = 0; - virtual void createItem() = 0; - virtual void deleteItem() = 0; - virtual void editItem() = 0; + QString m_type; + // ui methods + virtual void doCreateItem() = 0; + virtual void initItems() = 0; }; diff --git a/sources/awesome-widget/plugin/awabstractformatter.cpp b/sources/awesomewidgets/awabstractformatter.cpp similarity index 57% rename from sources/awesome-widget/plugin/awabstractformatter.cpp rename to sources/awesomewidgets/awabstractformatter.cpp index 302a00a..e44c240 100644 --- a/sources/awesome-widget/plugin/awabstractformatter.cpp +++ b/sources/awesomewidgets/awabstractformatter.cpp @@ -17,23 +17,16 @@ #include "awabstractformatter.h" -#include #include -#include #include "awdebug.h" AWAbstractFormatter::AWAbstractFormatter(QWidget *parent, const QString filePath) - : QDialog(parent) - , m_fileName(filePath) + : AbstractExtItem(parent, filePath) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; - - qCDebug(LOG_AW) << "Desktop name" << filePath; - - m_name = m_fileName; } @@ -43,44 +36,17 @@ AWAbstractFormatter::~AWAbstractFormatter() } -void AWAbstractFormatter::copyDefaults(AWAbstractFormatter *_other) const +void AWAbstractFormatter::copyDefaults(AbstractExtItem *_other) const { - _other->setComment(m_comment); - _other->setName(m_name); - _other->setType(m_type); + AbstractExtItem::copyDefaults(_other); + + static_cast(_other)->setType(m_type); } -QString AWAbstractFormatter::writtableConfig() const +QString AWAbstractFormatter::uniq() const { - QStringList paths = m_fileName.split(QChar('/')); - - QString name = paths.takeLast(); - QString dir = paths.takeLast(); - - return QString("%1/awesomewidgets/%2/%3") - .arg(QStandardPaths::writableLocation( - QStandardPaths::GenericDataLocation)) - .arg(dir) - .arg(name); -} - - -QString AWAbstractFormatter::comment() const -{ - return m_comment; -} - - -QString AWAbstractFormatter::fileName() const -{ - return m_fileName; -} - - -QString AWAbstractFormatter::name() const -{ - return m_name; + return QString("%1(%2)").arg(name()).arg(m_type); } @@ -90,22 +56,6 @@ QString AWAbstractFormatter::type() const } -void AWAbstractFormatter::setComment(const QString _comment) -{ - qCDebug(LOG_AW) << "Comment" << _comment; - - m_comment = _comment; -} - - -void AWAbstractFormatter::setName(const QString _name) -{ - qCDebug(LOG_AW) << "Name" << _name; - - m_name = _name; -} - - void AWAbstractFormatter::setType(const QString _type) { qCDebug(LOG_AW) << "Type" << _type; @@ -116,34 +66,24 @@ void AWAbstractFormatter::setType(const QString _type) void AWAbstractFormatter::readConfiguration() { - QSettings settings(m_fileName, QSettings::IniFormat); + AbstractExtItem::readConfiguration(); + + QSettings settings(fileName(), QSettings::IniFormat); settings.beginGroup(QString("Desktop Entry")); - setName(settings.value(QString("Name"), m_name).toString()); - setComment(settings.value(QString("Comment"), m_comment).toString()); setType(settings.value(QString("Type"), m_type).toString()); settings.endGroup(); } -bool AWAbstractFormatter::tryDelete() const -{ - bool status = QFile::remove(m_fileName); - qCInfo(LOG_AW) << "Remove file" << m_fileName << status; - - return status; -} - - void AWAbstractFormatter::writeConfiguration() const { + AbstractExtItem::writeConfiguration(); + QSettings settings(writtableConfig(), QSettings::IniFormat); qCInfo(LOG_AW) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); - settings.setValue(QString("Encoding"), QString("UTF-8")); - settings.setValue(QString("Name"), m_name); - settings.setValue(QString("Comment"), m_comment); settings.setValue(QString("Type"), m_type); settings.endGroup(); diff --git a/sources/awesome-widget/plugin/awabstractformatter.h b/sources/awesomewidgets/awabstractformatter.h similarity index 69% rename from sources/awesome-widget/plugin/awabstractformatter.h rename to sources/awesomewidgets/awabstractformatter.h index d953a25..519d5fb 100644 --- a/sources/awesome-widget/plugin/awabstractformatter.h +++ b/sources/awesomewidgets/awabstractformatter.h @@ -18,47 +18,32 @@ #ifndef AWABSTRACTFORMATTER_H #define AWABSTRACTFORMATTER_H -#include -#include +#include "abstractextitem.h" -class AWAbstractFormatter : public QDialog +class AWAbstractFormatter : public AbstractExtItem { Q_OBJECT - Q_PROPERTY(QString comment READ comment WRITE setComment) - Q_PROPERTY(QString fileName READ fileName) - Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString type READ type WRITE setType) public: explicit AWAbstractFormatter(QWidget *parent = nullptr, const QString filePath = QString()); virtual ~AWAbstractFormatter(); - virtual AWAbstractFormatter *copy(const QString _fileName) = 0; - void copyDefaults(AWAbstractFormatter *_other) const; + void copyDefaults(AbstractExtItem *_other) const; virtual QString convert(const QVariant &_value) const = 0; - QString writtableConfig() const; + QString uniq() const; // properties - QString comment() const; - QString fileName() const; - QString name() const; QString type() const; - void setComment(const QString _comment = QString("empty")); - void setName(const QString _name = QString("none")); void setType(const QString _type = QString("NoFormat")); public slots: virtual void readConfiguration(); - virtual int showConfiguration(const QVariant args = QVariant()) = 0; - bool tryDelete() const; + QVariantHash run() { return QVariantHash(); }; virtual void writeConfiguration() const; private: - QString m_fileName; - virtual void translate() = 0; // properties - QString m_comment = QString("empty"); - QString m_name = QString("none"); QString m_type = QString("NoFormat"); }; diff --git a/sources/awesome-widget/plugin/awdatetimeformatter.cpp b/sources/awesomewidgets/awdatetimeformatter.cpp similarity index 94% rename from sources/awesome-widget/plugin/awdatetimeformatter.cpp rename to sources/awesomewidgets/awdatetimeformatter.cpp index 6445fe3..96e28dd 100644 --- a/sources/awesome-widget/plugin/awdatetimeformatter.cpp +++ b/sources/awesomewidgets/awdatetimeformatter.cpp @@ -70,14 +70,16 @@ QString AWDateTimeFormatter::convert(const QVariant &_value) const } -AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString _fileName) +AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString _fileName, + const int _number) { - qCDebug(LOG_LIB) << "File" << _fileName; + qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number; AWDateTimeFormatter *item = new AWDateTimeFormatter(static_cast(parent()), _fileName); - copyDefaults(item); + AWAbstractFormatter::copyDefaults(item); item->setFormat(format()); + item->setNumber(_number); return item; } diff --git a/sources/awesome-widget/plugin/awdatetimeformatter.h b/sources/awesomewidgets/awdatetimeformatter.h similarity index 96% rename from sources/awesome-widget/plugin/awdatetimeformatter.h rename to sources/awesomewidgets/awdatetimeformatter.h index b0b1bbc..29d2c82 100644 --- a/sources/awesome-widget/plugin/awdatetimeformatter.h +++ b/sources/awesomewidgets/awdatetimeformatter.h @@ -36,7 +36,7 @@ public: explicit AWDateTimeFormatter(const QString format, QWidget *parent); virtual ~AWDateTimeFormatter(); QString convert(const QVariant &_value) const; - AWDateTimeFormatter *copy(const QString _fileName); + AWDateTimeFormatter *copy(const QString _fileName, const int _number); // properties QString format() const; void setFormat(const QString _format); diff --git a/sources/awesome-widget/plugin/awdatetimeformatter.ui b/sources/awesomewidgets/awdatetimeformatter.ui similarity index 100% rename from sources/awesome-widget/plugin/awdatetimeformatter.ui rename to sources/awesomewidgets/awdatetimeformatter.ui diff --git a/sources/awesome-widget/plugin/awfloatformatter.cpp b/sources/awesomewidgets/awfloatformatter.cpp similarity index 97% rename from sources/awesome-widget/plugin/awfloatformatter.cpp rename to sources/awesomewidgets/awfloatformatter.cpp index ba2a18f..9b37d29 100644 --- a/sources/awesome-widget/plugin/awfloatformatter.cpp +++ b/sources/awesomewidgets/awfloatformatter.cpp @@ -77,17 +77,19 @@ QString AWFloatFormatter::convert(const QVariant &_value) const } -AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName) +AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName, + const int _number) { - qCDebug(LOG_LIB) << "File" << _fileName; + qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number; AWFloatFormatter *item = new AWFloatFormatter(static_cast(parent()), _fileName); - copyDefaults(item); + AWAbstractFormatter::copyDefaults(item); item->setCount(count()); item->setFormat(format()); item->setFillChar(fillChar()); item->setMultiplier(multiplier()); + item->setNumber(_number); item->setPrecision(precision()); item->setSummand(summand()); diff --git a/sources/awesome-widget/plugin/awfloatformatter.h b/sources/awesomewidgets/awfloatformatter.h similarity index 97% rename from sources/awesome-widget/plugin/awfloatformatter.h rename to sources/awesomewidgets/awfloatformatter.h index 1a9b28f..921ea70 100644 --- a/sources/awesome-widget/plugin/awfloatformatter.h +++ b/sources/awesomewidgets/awfloatformatter.h @@ -44,7 +44,7 @@ public: QWidget *parent); virtual ~AWFloatFormatter(); QString convert(const QVariant &_value) const; - AWFloatFormatter *copy(const QString _fileName); + AWFloatFormatter *copy(const QString _fileName, const int _number); // properties int count() const; QChar fillChar() const; diff --git a/sources/awesome-widget/plugin/awfloatformatter.ui b/sources/awesomewidgets/awfloatformatter.ui similarity index 100% rename from sources/awesome-widget/plugin/awfloatformatter.ui rename to sources/awesomewidgets/awfloatformatter.ui diff --git a/sources/awesome-widget/plugin/awnoformatter.cpp b/sources/awesomewidgets/awnoformatter.cpp similarity index 92% rename from sources/awesome-widget/plugin/awnoformatter.cpp rename to sources/awesomewidgets/awnoformatter.cpp index a7903a2..7f727ad 100644 --- a/sources/awesome-widget/plugin/awnoformatter.cpp +++ b/sources/awesomewidgets/awnoformatter.cpp @@ -63,13 +63,14 @@ QString AWNoFormatter::convert(const QVariant &_value) const } -AWNoFormatter *AWNoFormatter::copy(const QString _fileName) +AWNoFormatter *AWNoFormatter::copy(const QString _fileName, const int _number) { - qCDebug(LOG_LIB) << "File" << _fileName; + qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number; AWNoFormatter *item = new AWNoFormatter(static_cast(parent()), _fileName); - copyDefaults(item); + AWAbstractFormatter::copyDefaults(item); + item->setNumber(_number); return item; } diff --git a/sources/awesome-widget/plugin/awnoformatter.h b/sources/awesomewidgets/awnoformatter.h similarity index 96% rename from sources/awesome-widget/plugin/awnoformatter.h rename to sources/awesomewidgets/awnoformatter.h index 77b50c7..31121bc 100644 --- a/sources/awesome-widget/plugin/awnoformatter.h +++ b/sources/awesomewidgets/awnoformatter.h @@ -35,7 +35,7 @@ public: explicit AWNoFormatter(QWidget *parent); virtual ~AWNoFormatter(); QString convert(const QVariant &_value) const; - AWNoFormatter *copy(const QString _fileName); + AWNoFormatter *copy(const QString _fileName, const int _number); public slots: int showConfiguration(const QVariant args = QVariant()); diff --git a/sources/awesome-widget/plugin/awnoformatter.ui b/sources/awesomewidgets/awnoformatter.ui similarity index 100% rename from sources/awesome-widget/plugin/awnoformatter.ui rename to sources/awesomewidgets/awnoformatter.ui diff --git a/sources/awesome-widget/plugin/awscriptformatter.cpp b/sources/awesomewidgets/awscriptformatter.cpp similarity index 96% rename from sources/awesome-widget/plugin/awscriptformatter.cpp rename to sources/awesomewidgets/awscriptformatter.cpp index d2b1eaa..bc7909d 100644 --- a/sources/awesome-widget/plugin/awscriptformatter.cpp +++ b/sources/awesomewidgets/awscriptformatter.cpp @@ -86,16 +86,18 @@ QString AWScriptFormatter::convert(const QVariant &_value) const } -AWScriptFormatter *AWScriptFormatter::copy(const QString _fileName) +AWScriptFormatter *AWScriptFormatter::copy(const QString _fileName, + const int _number) { - qCDebug(LOG_LIB) << "File" << _fileName; + qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number; AWScriptFormatter *item = new AWScriptFormatter(static_cast(parent()), _fileName); - copyDefaults(item); + AWAbstractFormatter::copyDefaults(item); item->setAppendCode(appendCode()); item->setCode(code()); item->setHasReturn(hasReturn()); + item->setNumber(_number); return item; } diff --git a/sources/awesome-widget/plugin/awscriptformatter.h b/sources/awesomewidgets/awscriptformatter.h similarity index 97% rename from sources/awesome-widget/plugin/awscriptformatter.h rename to sources/awesomewidgets/awscriptformatter.h index 3939917..0b8d786 100644 --- a/sources/awesome-widget/plugin/awscriptformatter.h +++ b/sources/awesomewidgets/awscriptformatter.h @@ -40,7 +40,7 @@ public: const bool hasReturn, QWidget *parent); virtual ~AWScriptFormatter(); QString convert(const QVariant &_value) const; - AWScriptFormatter *copy(const QString _fileName); + AWScriptFormatter *copy(const QString _fileName, const int _number); // properties bool appendCode() const; QString code() const; diff --git a/sources/awesome-widget/plugin/awscriptformatter.ui b/sources/awesomewidgets/awscriptformatter.ui similarity index 100% rename from sources/awesome-widget/plugin/awscriptformatter.ui rename to sources/awesomewidgets/awscriptformatter.ui diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h index 740d018..5527d07 100644 --- a/sources/awesomewidgets/extitemaggregator.h +++ b/sources/awesomewidgets/extitemaggregator.h @@ -32,8 +32,7 @@ template class ExtItemAggregator : public AbstractExtItemAggregator { public: explicit ExtItemAggregator(QWidget *parent, const QString type) - : AbstractExtItemAggregator(parent) - , m_type(type) + : AbstractExtItemAggregator(parent, type) { qSetMessagePattern(LOG_FORMAT); qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; @@ -70,7 +69,7 @@ public: for (auto item : m_items) { if (item->tag(_type) != _tag) continue; - found = item; + found = static_cast(item); break; } if (found == nullptr) @@ -87,7 +86,7 @@ public: for (auto item : m_items) { if (item->number() != _number) continue; - found = item; + found = static_cast(item); break; } if (found == nullptr) @@ -96,63 +95,31 @@ public: return found; }; - T *itemFromWidget() const - { - QListWidgetItem *widgetItem = widgetDialog->currentItem(); - if (widgetItem == nullptr) - return nullptr; - - T *found = nullptr; - for (auto item : m_items) { - QString fileName = QFileInfo(item->fileName()).fileName(); - if (fileName != widgetItem->text()) - continue; - found = item; - break; - } - if (found == nullptr) - qCWarning(LOG_LIB) << "Could not find item by name" - << widgetItem->text(); - - return found; - }; - - QList items() const { return m_items; }; - - int uniqNumber() const - { - QList tagList; - for (auto item : m_items) - tagList.append(item->number()); - int number = 0; - while (tagList.contains(number)) - number++; - - return number; - }; + QList items() const { return m_items; }; private: - QList m_items; + QList m_items; QList m_activeItems; - QString m_type; - QList getItems() + void doCreateItem() { return createItem(); } + + QList getItems() { // create directory at $HOME QString localDir = QString("%1/awesomewidgets/%2") .arg(QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation)) - .arg(m_type); + .arg(type()); QDir localDirectory; if (localDirectory.mkpath(localDir)) qCInfo(LOG_LIB) << "Created directory" << localDir; QStringList dirs = QStandardPaths::locateAll( QStandardPaths::GenericDataLocation, - QString("awesomewidgets/%1").arg(m_type), + QString("awesomewidgets/%1").arg(type()), QStandardPaths::LocateDirectory); QStringList names; - QList items; + QList items; for (auto dir : dirs) { QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name); for (auto file : files) { @@ -167,9 +134,10 @@ private: } // sort items - std::sort(items.begin(), items.end(), [](const T *lhs, const T *rhs) { - return lhs->number() < rhs->number(); - }); + std::sort(items.begin(), items.end(), + [](const AbstractExtItem *lhs, const AbstractExtItem *rhs) { + return lhs->number() < rhs->number(); + }); return items; }; @@ -182,96 +150,7 @@ private: for (auto item : m_items) { if (!item->isActive()) continue; - m_activeItems.append(item); - } - }; - - void repaintList() - { - widgetDialog->clear(); - for (auto _item : m_items) { - QString fileName = QFileInfo(_item->fileName()).fileName(); - QListWidgetItem *item - = new QListWidgetItem(fileName, widgetDialog); - QStringList tooltip; - 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'))); - widgetDialog->addItem(item); - } - }; - - // methods - void copyItem() - { - T *source = itemFromWidget(); - QString fileName = getName(); - int number = uniqNumber(); - QString dir = QString("%1/awesomewidgets/%2") - .arg(QStandardPaths::writableLocation( - QStandardPaths::GenericDataLocation)) - .arg(m_type); - if ((source == nullptr) || (fileName.isEmpty())) { - qCWarning(LOG_LIB) << "Nothing to copy"; - return; - } - QString filePath = QString("%1/%2").arg(dir).arg(fileName); - - T *newItem = static_cast(source->copy(filePath, number)); - if (newItem->showConfiguration(configArgs()) == 1) { - initItems(); - repaintList(); - } - }; - - void createItem() - { - QString fileName = getName(); - int number = uniqNumber(); - QString dir = QString("%1/awesomewidgets/%2") - .arg(QStandardPaths::writableLocation( - QStandardPaths::GenericDataLocation)) - .arg(m_type); - if (fileName.isEmpty()) { - qCWarning(LOG_LIB) << "Nothing to create"; - return; - }; - QString filePath = QString("%1/%2").arg(dir).arg(fileName); - - T *newItem = new T(this, filePath); - newItem->setNumber(number); - if (newItem->showConfiguration(configArgs()) == 1) { - initItems(); - repaintList(); - } - }; - - void deleteItem() - { - T *source = itemFromWidget(); - if (source == nullptr) { - qCWarning(LOG_LIB) << "Nothing to delete"; - return; - }; - - if (source->tryDelete()) { - initItems(); - repaintList(); - } - }; - - void editItem() - { - T *source = itemFromWidget(); - if (source == nullptr) { - qCWarning(LOG_LIB) << "Nothing to edit"; - return; - }; - - if (source->showConfiguration(configArgs()) == 1) { - initItems(); - repaintList(); + m_activeItems.append(static_cast(item)); } }; }; From 51c7299ad04eb3147a30677a7c70e903ff7b2c0a Mon Sep 17 00:00:00 2001 From: arcan1s Date: Fri, 13 May 2016 13:23:25 +0300 Subject: [PATCH 05/32] changes in Extensions ABI * rewrite aggregator to normal qt ui * use X-AW prefix for formatters options * fix logging * use nullptr in headers --- .../awesome-widget/plugin/awconfighelper.cpp | 4 +- .../plugin/awformatterhelper.cpp | 17 +++-- sources/awesomewidgets/abstractextitem.cpp | 2 +- .../abstractextitemaggregator.cpp | 40 +++++------- .../abstractextitemaggregator.h | 27 ++++---- .../abstractextitemaggregator.ui | 64 +++++++++++++++++++ .../awesomewidgets/awabstractformatter.cpp | 12 ++-- .../awesomewidgets/awdatetimeformatter.cpp | 14 ++-- sources/awesomewidgets/awdatetimeformatter.h | 2 +- sources/awesomewidgets/awfloatformatter.cpp | 47 +++++++------- sources/awesomewidgets/awfloatformatter.h | 2 +- sources/awesomewidgets/awnoformatter.cpp | 8 +-- sources/awesomewidgets/awnoformatter.h | 2 +- sources/awesomewidgets/awscriptformatter.cpp | 36 ++++++----- sources/awesomewidgets/awscriptformatter.h | 2 +- sources/awesomewidgets/extitemaggregator.h | 2 +- sources/awesomewidgets/extquotes.h | 4 +- sources/awesomewidgets/extscript.h | 2 +- sources/awesomewidgets/extupgrade.h | 2 +- sources/awesomewidgets/extweather.h | 4 +- sources/awesomewidgets/graphicalitem.h | 2 +- sources/extsysmon/sources/customsource.h | 2 +- sources/extsysmon/sources/quotessource.h | 2 +- sources/extsysmon/sources/upgradesource.h | 2 +- sources/extsysmon/sources/weathersource.h | 2 +- 25 files changed, 186 insertions(+), 117 deletions(-) create mode 100644 sources/awesomewidgets/abstractextitemaggregator.ui diff --git a/sources/awesome-widget/plugin/awconfighelper.cpp b/sources/awesome-widget/plugin/awconfighelper.cpp index a7b26be..db8dbf4 100644 --- a/sources/awesome-widget/plugin/awconfighelper.cpp +++ b/sources/awesome-widget/plugin/awconfighelper.cpp @@ -295,7 +295,7 @@ void AWConfigHelper::readFile(QSettings &settings, const QString key, file.close(); settings.setValue(key, text); } else { - qCWarning(LOG_LIB) << "Could not open" << file.fileName(); + qCWarning(LOG_AW) << "Could not open" << file.fileName(); } } @@ -316,6 +316,6 @@ void AWConfigHelper::writeFile(QSettings &settings, const QString key, out.flush(); file.close(); } else { - qCWarning(LOG_LIB) << "Could not open" << file.fileName(); + qCWarning(LOG_AW) << "Could not open" << file.fileName(); } } diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index 3a42a58..168f092 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -119,8 +119,8 @@ void AWFormatterHelper::initFormatters() for (auto file : files) { if (!file.endsWith(QString(".desktop"))) continue; - qCInfo(LOG_LIB) << "Found file" << file << "in" - << m_directories.at(i); + qCInfo(LOG_AW) << "Found file" << file << "in" + << m_directories.at(i); QString filePath = QString("%1/%2").arg(m_directories.at(i)).arg(file); auto metadata = readMetadata(filePath); @@ -161,6 +161,10 @@ void AWFormatterHelper::initKeys() for (auto key : keys) { QString name = settings.value(key).toString(); qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key; + if (!m_formattersClasses.contains(name)) { + qCWarning(LOG_AW) << "Invalid formatter" << name << "found in" + << key; + } m_formatters[key] = m_formattersClasses[name]; } settings.endGroup(); @@ -175,7 +179,7 @@ void AWFormatterHelper::installDirectories() QStandardPaths::GenericDataLocation)); QDir localDirectory; if (localDirectory.mkpath(localDir)) - qCInfo(LOG_LIB) << "Created directory" << localDir; + qCInfo(LOG_AW) << "Created directory" << localDir; m_directories = QStandardPaths::locateAll( QStandardPaths::GenericDataLocation, @@ -196,7 +200,7 @@ AWFormatterHelper::readMetadata(const QString filePath) const settings.beginGroup(QString("Desktop Entry")); QString name = settings.value(QString("Name"), filePath).toString(); QString type - = settings.value(QString("Type"), QString("NoFormat")).toString(); + = settings.value(QString("X-AW-Type"), QString("NoFormat")).toString(); FormatterClass formatter = defineFormatterClass(type); settings.endGroup(); @@ -212,9 +216,12 @@ void AWFormatterHelper::doCreateItem() bool ok; QString select = QInputDialog::getItem( this, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok); - if (!ok) + if (!ok) { + qCWarning(LOG_AW) << "No type selected"; return; + } + qCInfo(LOG_AW) << "Selected type" << select; FormatterClass formatter = defineFormatterClass(select); switch (formatter) { case FormatterClass::DateTime: diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index 7ec998f..b4fa77d 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -198,7 +198,7 @@ void AbstractExtItem::readConfiguration() bool AbstractExtItem::tryDelete() const { bool status = QFile::remove(m_fileName); - qCInfo(LOG_AW) << "Remove file" << m_fileName << status; + qCInfo(LOG_LIB) << "Remove file" << m_fileName << status; return status; } diff --git a/sources/awesomewidgets/abstractextitemaggregator.cpp b/sources/awesomewidgets/abstractextitemaggregator.cpp index 122ab07..90704cf 100644 --- a/sources/awesomewidgets/abstractextitemaggregator.cpp +++ b/sources/awesomewidgets/abstractextitemaggregator.cpp @@ -16,41 +16,35 @@ ***************************************************************************/ #include "abstractextitemaggregator.h" +#include "ui_abstractextitemaggregator.h" #include #include -#include #include -#include +#include AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent, const QString type) - : QWidget(parent) + : QDialog(parent) + , ui(new Ui::AbstractExtItemAggregator) , m_type(type) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - dialog = new QDialog(this); - widgetDialog = new QListWidget(dialog); - dialogButtons = new QDialogButtonBox( - QDialogButtonBox::Open | QDialogButtonBox::Close, Qt::Vertical, dialog); + ui->setupUi(this); copyButton - = dialogButtons->addButton(i18n("Copy"), QDialogButtonBox::ActionRole); - createButton = dialogButtons->addButton(i18n("Create"), + = ui->buttonBox->addButton(i18n("Copy"), QDialogButtonBox::ActionRole); + createButton = ui->buttonBox->addButton(i18n("Create"), QDialogButtonBox::ActionRole); - deleteButton = dialogButtons->addButton(i18n("Remove"), + deleteButton = ui->buttonBox->addButton(i18n("Remove"), QDialogButtonBox::ActionRole); - QHBoxLayout *layout = new QHBoxLayout(dialog); - layout->addWidget(widgetDialog); - layout->addWidget(dialogButtons); - dialog->setLayout(layout); - connect(dialogButtons, SIGNAL(clicked(QAbstractButton *)), this, + connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(editItemButtonPressed(QAbstractButton *))); - connect(dialogButtons, SIGNAL(rejected()), dialog, SLOT(reject())); - connect(widgetDialog, SIGNAL(itemActivated(QListWidgetItem *)), this, + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(ui->listWidget, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(editItemActivated(QListWidgetItem *))); } @@ -59,7 +53,7 @@ AbstractExtItemAggregator::~AbstractExtItemAggregator() { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - delete dialog; + delete ui; } @@ -133,7 +127,7 @@ QString AbstractExtItemAggregator::getName() AbstractExtItem *AbstractExtItemAggregator::itemFromWidget() { - QListWidgetItem *widgetItem = widgetDialog->currentItem(); + QListWidgetItem *widgetItem = ui->listWidget->currentItem(); if (widgetItem == nullptr) return nullptr; @@ -155,16 +149,16 @@ AbstractExtItem *AbstractExtItemAggregator::itemFromWidget() void AbstractExtItemAggregator::repaintList() { - widgetDialog->clear(); + ui->listWidget->clear(); for (auto _item : items()) { QString fileName = QFileInfo(_item->fileName()).fileName(); - QListWidgetItem *item = new QListWidgetItem(fileName, widgetDialog); + QListWidgetItem *item = new QListWidgetItem(fileName, ui->listWidget); QStringList tooltip; 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'))); - widgetDialog->addItem(item); + ui->listWidget->addItem(item); } } @@ -216,6 +210,6 @@ void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button) return doCreateItem(); else if (static_cast(button) == deleteButton) return deleteItem(); - else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole) + else if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) return editItem(); } diff --git a/sources/awesomewidgets/abstractextitemaggregator.h b/sources/awesomewidgets/abstractextitemaggregator.h index 29d0cb8..cb1cb52 100644 --- a/sources/awesomewidgets/abstractextitemaggregator.h +++ b/sources/awesomewidgets/abstractextitemaggregator.h @@ -19,18 +19,20 @@ #define ABSTRACTEXTITEMAGGREGATOR_H #include -#include -#include -#include #include -#include #include "abstractextitem.h" #include "awdebug.h" -// additional class since QObject macro does not allow class templates -class AbstractExtItemAggregator : public QWidget +class QAbstractButton; +class QListWidgetItem; +namespace Ui +{ +class AbstractExtItemAggregator; +} + +class AbstractExtItemAggregator : public QDialog { Q_OBJECT Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs) @@ -68,13 +70,6 @@ public: AbstractExtItem *itemFromWidget(); void repaintList(); int uniqNumber() const; - // ui - QDialog *dialog = nullptr; - QListWidget *widgetDialog = nullptr; - QDialogButtonBox *dialogButtons = nullptr; - QPushButton *copyButton = nullptr; - QPushButton *createButton = nullptr; - QPushButton *deleteButton = nullptr; // get methods QVariant configArgs() const; virtual QList items() const = 0; @@ -87,6 +82,12 @@ private slots: void editItemButtonPressed(QAbstractButton *button); private: + // ui + Ui::AbstractExtItemAggregator *ui = nullptr; + QPushButton *copyButton = nullptr; + QPushButton *createButton = nullptr; + QPushButton *deleteButton = nullptr; + // properties QVariant m_configArgs; QString m_type; // ui methods diff --git a/sources/awesomewidgets/abstractextitemaggregator.ui b/sources/awesomewidgets/abstractextitemaggregator.ui new file mode 100644 index 0000000..f0c541d --- /dev/null +++ b/sources/awesomewidgets/abstractextitemaggregator.ui @@ -0,0 +1,64 @@ + + + AbstractExtItemAggregator + + + + 0 + 0 + 400 + 300 + + + + + + + + + + Qt::Vertical + + + QDialogButtonBox::Close|QDialogButtonBox::Open + + + + + + + + + buttonBox + accepted() + AbstractExtItemAggregator + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AbstractExtItemAggregator + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/awesomewidgets/awabstractformatter.cpp b/sources/awesomewidgets/awabstractformatter.cpp index e44c240..18e39ea 100644 --- a/sources/awesomewidgets/awabstractformatter.cpp +++ b/sources/awesomewidgets/awabstractformatter.cpp @@ -26,13 +26,13 @@ AWAbstractFormatter::AWAbstractFormatter(QWidget *parent, const QString filePath) : AbstractExtItem(parent, filePath) { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; } AWAbstractFormatter::~AWAbstractFormatter() { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; } @@ -58,7 +58,7 @@ QString AWAbstractFormatter::type() const void AWAbstractFormatter::setType(const QString _type) { - qCDebug(LOG_AW) << "Type" << _type; + qCDebug(LOG_LIB) << "Type" << _type; m_type = _type; } @@ -71,7 +71,7 @@ void AWAbstractFormatter::readConfiguration() QSettings settings(fileName(), QSettings::IniFormat); settings.beginGroup(QString("Desktop Entry")); - setType(settings.value(QString("Type"), m_type).toString()); + setType(settings.value(QString("X-AW-Type"), m_type).toString()); settings.endGroup(); } @@ -81,10 +81,10 @@ void AWAbstractFormatter::writeConfiguration() const AbstractExtItem::writeConfiguration(); QSettings settings(writtableConfig(), QSettings::IniFormat); - qCInfo(LOG_AW) << "Configuration file" << settings.fileName(); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); - settings.setValue(QString("Type"), m_type); + settings.setValue(QString("X-AW-Type"), m_type); settings.endGroup(); settings.sync(); diff --git a/sources/awesomewidgets/awdatetimeformatter.cpp b/sources/awesomewidgets/awdatetimeformatter.cpp index 96e28dd..24c1aa4 100644 --- a/sources/awesomewidgets/awdatetimeformatter.cpp +++ b/sources/awesomewidgets/awdatetimeformatter.cpp @@ -33,7 +33,7 @@ AWDateTimeFormatter::AWDateTimeFormatter(QWidget *parent, : AWAbstractFormatter(parent, filePath) , ui(new Ui::AWDateTimeFormatter) { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; readConfiguration(); ui->setupUi(this); @@ -45,7 +45,7 @@ AWDateTimeFormatter::AWDateTimeFormatter(const QString format, QWidget *parent) : AWAbstractFormatter(parent) , ui(new Ui::AWDateTimeFormatter) { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; setFormat(format); @@ -56,7 +56,7 @@ AWDateTimeFormatter::AWDateTimeFormatter(const QString format, QWidget *parent) AWDateTimeFormatter::~AWDateTimeFormatter() { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; delete ui; } @@ -64,7 +64,7 @@ AWDateTimeFormatter::~AWDateTimeFormatter() QString AWDateTimeFormatter::convert(const QVariant &_value) const { - qCDebug(LOG_AW) << "Convert value" << _value; + qCDebug(LOG_LIB) << "Convert value" << _value; return _value.toDateTime().toString(m_format); } @@ -93,7 +93,7 @@ QString AWDateTimeFormatter::format() const void AWDateTimeFormatter::setFormat(const QString _format) { - qCDebug(LOG_AW) << "Set format" << _format; + qCDebug(LOG_LIB) << "Set format" << _format; m_format = _format; } @@ -106,7 +106,7 @@ void AWDateTimeFormatter::readConfiguration() QSettings settings(fileName(), QSettings::IniFormat); settings.beginGroup(QString("Desktop Entry")); - setFormat(settings.value(QString("Format"), m_format).toString()); + setFormat(settings.value(QString("X-AW-Format"), m_format).toString()); settings.endGroup(); } @@ -141,7 +141,7 @@ void AWDateTimeFormatter::writeConfiguration() const qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); - settings.setValue(QString("Format"), m_format); + settings.setValue(QString("X-AW-Format"), m_format); settings.endGroup(); settings.sync(); diff --git a/sources/awesomewidgets/awdatetimeformatter.h b/sources/awesomewidgets/awdatetimeformatter.h index 29d2c82..d908a73 100644 --- a/sources/awesomewidgets/awdatetimeformatter.h +++ b/sources/awesomewidgets/awdatetimeformatter.h @@ -47,7 +47,7 @@ public slots: void writeConfiguration() const; private: - Ui::AWDateTimeFormatter *ui; + Ui::AWDateTimeFormatter *ui = nullptr; void translate(); // properties QString m_format = QString(); diff --git a/sources/awesomewidgets/awfloatformatter.cpp b/sources/awesomewidgets/awfloatformatter.cpp index 9b37d29..6bd3fb8 100644 --- a/sources/awesomewidgets/awfloatformatter.cpp +++ b/sources/awesomewidgets/awfloatformatter.cpp @@ -31,7 +31,7 @@ AWFloatFormatter::AWFloatFormatter(QWidget *parent, const QString filePath) : AWAbstractFormatter(parent, filePath) , ui(new Ui::AWFloatFormatter) { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; readConfiguration(); ui->setupUi(this); @@ -46,7 +46,7 @@ AWFloatFormatter::AWFloatFormatter(const int count, const QChar fillChar, : AWAbstractFormatter(parent) , ui(new Ui::AWFloatFormatter) { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; setCount(count); setFillChar(fillChar); @@ -62,7 +62,7 @@ AWFloatFormatter::AWFloatFormatter(const int count, const QChar fillChar, AWFloatFormatter::~AWFloatFormatter() { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; delete ui; } @@ -70,7 +70,7 @@ AWFloatFormatter::~AWFloatFormatter() QString AWFloatFormatter::convert(const QVariant &_value) const { - qCDebug(LOG_AW) << "Convert value" << _value; + qCDebug(LOG_LIB) << "Convert value" << _value; return QString("%1").arg(_value.toDouble() * m_multiplier + m_summand, m_count, m_format, m_precision, m_fillChar); @@ -135,7 +135,7 @@ double AWFloatFormatter::summand() const void AWFloatFormatter::setCount(const int _count) { - qCDebug(LOG_AW) << "Set width" << _count; + qCDebug(LOG_LIB) << "Set width" << _count; m_count = _count; } @@ -143,7 +143,7 @@ void AWFloatFormatter::setCount(const int _count) void AWFloatFormatter::setFillChar(const QChar _fillChar) { - qCDebug(LOG_AW) << "Set char" << _fillChar; + qCDebug(LOG_LIB) << "Set char" << _fillChar; m_fillChar = _fillChar; } @@ -151,11 +151,11 @@ void AWFloatFormatter::setFillChar(const QChar _fillChar) void AWFloatFormatter::setFormat(char _format) { - qCDebug(LOG_AW) << "Set format" << _format; + qCDebug(LOG_LIB) << "Set format" << _format; // http://doc.qt.io/qt-5/qstring.html#argument-formats if ((_format != 'e') && (_format != 'E') && (_format != 'f') && (_format != 'g') && (_format != 'G')) { - qCWarning(LOG_AW) << "Invalid format" << _format; + qCWarning(LOG_LIB) << "Invalid format" << _format; _format = 'f'; } @@ -165,7 +165,7 @@ void AWFloatFormatter::setFormat(char _format) void AWFloatFormatter::setMultiplier(const double _multiplier) { - qCDebug(LOG_AW) << "Set multiplier" << _multiplier; + qCDebug(LOG_LIB) << "Set multiplier" << _multiplier; m_multiplier = _multiplier; } @@ -173,7 +173,7 @@ void AWFloatFormatter::setMultiplier(const double _multiplier) void AWFloatFormatter::setPrecision(const int _precision) { - qCDebug(LOG_AW) << "Set precision" << _precision; + qCDebug(LOG_LIB) << "Set precision" << _precision; m_precision = _precision; } @@ -181,7 +181,7 @@ void AWFloatFormatter::setPrecision(const int _precision) void AWFloatFormatter::setSummand(const double _summand) { - qCDebug(LOG_AW) << "Set summand" << _summand; + qCDebug(LOG_LIB) << "Set summand" << _summand; m_summand = _summand; } @@ -194,17 +194,18 @@ void AWFloatFormatter::readConfiguration() QSettings settings(fileName(), QSettings::IniFormat); settings.beginGroup(QString("Desktop Entry")); - setCount(settings.value(QString("Width"), m_count).toInt()); + setCount(settings.value(QString("X-AW-Width"), m_count).toInt()); setFillChar( - settings.value(QString("FillChar"), m_fillChar).toString().at(0)); - setFormat(settings.value(QString("Format"), QString(m_format)) + settings.value(QString("X-AW-FillChar"), m_fillChar).toString().at(0)); + setFormat(settings.value(QString("X-AW-Format"), QString(m_format)) .toString() .at(0) .toLatin1()); setMultiplier( - settings.value(QString("Multiplier"), m_multiplier).toDouble()); - setPrecision(settings.value(QString("Precision"), m_precision).toInt()); - setSummand(settings.value(QString("Summand"), m_summand).toDouble()); + settings.value(QString("X-AW-Multiplier"), m_multiplier).toDouble()); + setPrecision( + settings.value(QString("X-AW-Precision"), m_precision).toInt()); + setSummand(settings.value(QString("X-AW-Summand"), m_summand).toDouble()); settings.endGroup(); } @@ -250,12 +251,12 @@ void AWFloatFormatter::writeConfiguration() const qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); - settings.setValue(QString("Width"), m_count); - settings.setValue(QString("FillChar"), m_fillChar); - settings.setValue(QString("Format"), m_format); - settings.setValue(QString("Multiplier"), m_multiplier); - settings.setValue(QString("Precision"), m_precision); - settings.setValue(QString("Summand"), m_summand); + settings.setValue(QString("X-AW-Width"), m_count); + settings.setValue(QString("X-AW-FillChar"), m_fillChar); + settings.setValue(QString("X-AW-Format"), m_format); + settings.setValue(QString("X-AW-Multiplier"), m_multiplier); + settings.setValue(QString("X-AW-Precision"), m_precision); + settings.setValue(QString("X-AW-Summand"), m_summand); settings.endGroup(); settings.sync(); diff --git a/sources/awesomewidgets/awfloatformatter.h b/sources/awesomewidgets/awfloatformatter.h index 921ea70..1087214 100644 --- a/sources/awesomewidgets/awfloatformatter.h +++ b/sources/awesomewidgets/awfloatformatter.h @@ -65,7 +65,7 @@ public slots: void writeConfiguration() const; private: - Ui::AWFloatFormatter *ui; + Ui::AWFloatFormatter *ui = nullptr; void translate(); // properties int m_count = 0; diff --git a/sources/awesomewidgets/awnoformatter.cpp b/sources/awesomewidgets/awnoformatter.cpp index 7f727ad..dd801d4 100644 --- a/sources/awesomewidgets/awnoformatter.cpp +++ b/sources/awesomewidgets/awnoformatter.cpp @@ -28,7 +28,7 @@ AWNoFormatter::AWNoFormatter(QWidget *parent, const QString filePath) : AWAbstractFormatter(parent, filePath) , ui(new Ui::AWNoFormatter) { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; readConfiguration(); ui->setupUi(this); @@ -40,7 +40,7 @@ AWNoFormatter::AWNoFormatter(QWidget *parent) : AWAbstractFormatter(parent) , ui(new Ui::AWNoFormatter) { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; ui->setupUi(this); translate(); @@ -49,7 +49,7 @@ AWNoFormatter::AWNoFormatter(QWidget *parent) AWNoFormatter::~AWNoFormatter() { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; delete ui; } @@ -57,7 +57,7 @@ AWNoFormatter::~AWNoFormatter() QString AWNoFormatter::convert(const QVariant &_value) const { - qCDebug(LOG_AW) << "Convert value" << _value; + qCDebug(LOG_LIB) << "Convert value" << _value; return _value.toString(); } diff --git a/sources/awesomewidgets/awnoformatter.h b/sources/awesomewidgets/awnoformatter.h index 31121bc..d8efab5 100644 --- a/sources/awesomewidgets/awnoformatter.h +++ b/sources/awesomewidgets/awnoformatter.h @@ -41,7 +41,7 @@ public slots: int showConfiguration(const QVariant args = QVariant()); private: - Ui::AWNoFormatter *ui; + Ui::AWNoFormatter *ui = nullptr; void translate(); // properties }; diff --git a/sources/awesomewidgets/awscriptformatter.cpp b/sources/awesomewidgets/awscriptformatter.cpp index bc7909d..a97ff41 100644 --- a/sources/awesomewidgets/awscriptformatter.cpp +++ b/sources/awesomewidgets/awscriptformatter.cpp @@ -32,7 +32,7 @@ AWScriptFormatter::AWScriptFormatter(QWidget *parent, const QString filePath) : AWAbstractFormatter(parent, filePath) , ui(new Ui::AWScriptFormatter) { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; readConfiguration(); ui->setupUi(this); @@ -45,7 +45,7 @@ AWScriptFormatter::AWScriptFormatter(const bool appendCode, const QString code, : AWAbstractFormatter(parent) , ui(new Ui::AWScriptFormatter) { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; setAppendCode(appendCode); setCode(code); @@ -59,7 +59,7 @@ AWScriptFormatter::AWScriptFormatter(const bool appendCode, const QString code, AWScriptFormatter::~AWScriptFormatter() { - qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; delete ui; } @@ -67,7 +67,7 @@ AWScriptFormatter::~AWScriptFormatter() QString AWScriptFormatter::convert(const QVariant &_value) const { - qCDebug(LOG_AW) << "Convert value" << _value; + qCDebug(LOG_LIB) << "Convert value" << _value; // init engine QJSEngine engine; @@ -76,9 +76,9 @@ QString AWScriptFormatter::convert(const QVariant &_value) const QJSValue result = fn.call(args); if (result.isError()) { - qCWarning(LOG_AW) << "Uncaught exception at line" - << result.property("lineNumber").toInt() << ":" - << result.toString(); + qCWarning(LOG_LIB) << "Uncaught exception at line" + << result.property("lineNumber").toInt() << ":" + << result.toString(); return QString(); } else { return result.toString(); @@ -129,7 +129,7 @@ QString AWScriptFormatter::program() const void AWScriptFormatter::setAppendCode(const bool _appendCode) { - qCDebug(LOG_AW) << "Set append code" << _appendCode; + qCDebug(LOG_LIB) << "Set append code" << _appendCode; m_appendCode = _appendCode; } @@ -137,7 +137,7 @@ void AWScriptFormatter::setAppendCode(const bool _appendCode) void AWScriptFormatter::setCode(const QString _code) { - qCDebug(LOG_AW) << "Set code" << _code; + qCDebug(LOG_LIB) << "Set code" << _code; m_code = _code; } @@ -145,7 +145,7 @@ void AWScriptFormatter::setCode(const QString _code) void AWScriptFormatter::setHasReturn(const bool _hasReturn) { - qCDebug(LOG_AW) << "Set has return" << _hasReturn; + qCDebug(LOG_LIB) << "Set has return" << _hasReturn; m_hasReturn = _hasReturn; } @@ -158,9 +158,11 @@ void AWScriptFormatter::readConfiguration() QSettings settings(fileName(), QSettings::IniFormat); settings.beginGroup(QString("Desktop Entry")); - setAppendCode(settings.value(QString("AppendCode"), m_appendCode).toBool()); - setCode(settings.value(QString("Code"), m_code).toString()); - setHasReturn(settings.value(QString("HasReturn"), m_hasReturn).toBool()); + setAppendCode( + settings.value(QString("X-AW-AppendCode"), m_appendCode).toBool()); + setCode(settings.value(QString("X-AW-Code"), m_code).toString()); + setHasReturn( + settings.value(QString("X-AW-HasReturn"), m_hasReturn).toBool()); settings.endGroup(); initProgram(); @@ -204,9 +206,9 @@ void AWScriptFormatter::writeConfiguration() const qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); - settings.setValue(QString("AppendCode"), m_appendCode); - settings.setValue(QString("Code"), m_code); - settings.setValue(QString("HasReturn"), m_hasReturn); + settings.setValue(QString("X-AW-AppendCode"), m_appendCode); + settings.setValue(QString("X-AW-Code"), m_code); + settings.setValue(QString("X-AW-HasReturn"), m_hasReturn); settings.endGroup(); settings.sync(); @@ -223,7 +225,7 @@ void AWScriptFormatter::initProgram() else m_program = m_code; - qCInfo(LOG_AW) << "Create JS engine with code" << m_program; + qCInfo(LOG_LIB) << "Create JS engine with code" << m_program; } diff --git a/sources/awesomewidgets/awscriptformatter.h b/sources/awesomewidgets/awscriptformatter.h index 0b8d786..3af8ade 100644 --- a/sources/awesomewidgets/awscriptformatter.h +++ b/sources/awesomewidgets/awscriptformatter.h @@ -56,7 +56,7 @@ public slots: void writeConfiguration() const; private: - Ui::AWScriptFormatter *ui; + Ui::AWScriptFormatter *ui = nullptr; void initProgram(); void translate(); // properties diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h index 5527d07..7549383 100644 --- a/sources/awesomewidgets/extitemaggregator.h +++ b/sources/awesomewidgets/extitemaggregator.h @@ -57,7 +57,7 @@ public: void editItems() { repaintList(); - int ret = dialog->exec(); + int ret = exec(); qCInfo(LOG_LIB) << "Dialog returns" << ret; }; diff --git a/sources/awesomewidgets/extquotes.h b/sources/awesomewidgets/extquotes.h index 16c3fe7..38e0057 100644 --- a/sources/awesomewidgets/extquotes.h +++ b/sources/awesomewidgets/extquotes.h @@ -58,10 +58,10 @@ private slots: void quotesReplyReceived(QNetworkReply *reply); private: - QNetworkAccessManager *m_manager; + QNetworkAccessManager *m_manager = nullptr; QUrl m_url; bool isRunning = false; - Ui::ExtQuotes *ui; + Ui::ExtQuotes *ui = nullptr; void translate(); // properties QString m_ticker = QString("EURUSD=X"); diff --git a/sources/awesomewidgets/extscript.h b/sources/awesomewidgets/extscript.h index a6be0bd..e4e8a45 100644 --- a/sources/awesomewidgets/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -73,7 +73,7 @@ private slots: private: QProcess *process = nullptr; - Ui::ExtScript *ui; + Ui::ExtScript *ui = nullptr; void translate(); // properties QString m_executable = QString("/usr/bin/true"); diff --git a/sources/awesomewidgets/extupgrade.h b/sources/awesomewidgets/extupgrade.h index 709d4d7..ad981a9 100644 --- a/sources/awesomewidgets/extupgrade.h +++ b/sources/awesomewidgets/extupgrade.h @@ -61,7 +61,7 @@ private slots: private: QProcess *process = nullptr; - Ui::ExtUpgrade *ui; + Ui::ExtUpgrade *ui = nullptr; void translate(); // properties QString m_executable = QString("/usr/bin/true"); diff --git a/sources/awesomewidgets/extweather.h b/sources/awesomewidgets/extweather.h index e4d91ee..0f4d87d 100644 --- a/sources/awesomewidgets/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -70,10 +70,10 @@ private slots: void weatherReplyReceived(QNetworkReply *reply); private: - QNetworkAccessManager *m_manager; + QNetworkAccessManager *m_manager = nullptr; QUrl m_url; bool isRunning = false; - Ui::ExtWeather *ui; + Ui::ExtWeather *ui = nullptr; void translate(); // properties QString m_city = QString("London"); diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index 3938c1a..c504996 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -105,7 +105,7 @@ private: GraphicalItemHelper *m_helper = nullptr; QGraphicsScene *m_scene = nullptr; QGraphicsView *m_view = nullptr; - Ui::GraphicalItem *ui; + Ui::GraphicalItem *ui = nullptr; void initScene(); void translate(); // properties diff --git a/sources/extsysmon/sources/customsource.h b/sources/extsysmon/sources/customsource.h index 91ee081..3230de2 100644 --- a/sources/extsysmon/sources/customsource.h +++ b/sources/extsysmon/sources/customsource.h @@ -39,7 +39,7 @@ public: private: QStringList getSources(); // configuration and values - ExtItemAggregator *extScripts; + ExtItemAggregator *extScripts = nullptr; QStringList m_sources; }; diff --git a/sources/extsysmon/sources/quotessource.h b/sources/extsysmon/sources/quotessource.h index ae09f0b..edb3490 100644 --- a/sources/extsysmon/sources/quotessource.h +++ b/sources/extsysmon/sources/quotessource.h @@ -39,7 +39,7 @@ public: private: QStringList getSources(); // configuration and values - ExtItemAggregator *extQuotes; + ExtItemAggregator *extQuotes = nullptr; QStringList m_sources; QVariantHash m_values; }; diff --git a/sources/extsysmon/sources/upgradesource.h b/sources/extsysmon/sources/upgradesource.h index d020151..8bf6a81 100644 --- a/sources/extsysmon/sources/upgradesource.h +++ b/sources/extsysmon/sources/upgradesource.h @@ -39,7 +39,7 @@ public: private: QStringList getSources(); // configuration and values - ExtItemAggregator *extUpgrade; + ExtItemAggregator *extUpgrade = nullptr; QStringList m_sources; }; diff --git a/sources/extsysmon/sources/weathersource.h b/sources/extsysmon/sources/weathersource.h index 50b9f83..88520f6 100644 --- a/sources/extsysmon/sources/weathersource.h +++ b/sources/extsysmon/sources/weathersource.h @@ -39,7 +39,7 @@ public: private: QStringList getSources(); // configuration and values - ExtItemAggregator *extWeather; + ExtItemAggregator *extWeather = nullptr; QStringList m_sources; QVariantHash m_values; }; From 6bd7788aa96c4185075dc96163f825ee0f795204 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sat, 14 May 2016 04:08:22 +0300 Subject: [PATCH 06/32] More consistent formatters --- sources/awdebug.cpp | 1 + .../awesome-widget/plugin/awconfighelper.cpp | 4 +- .../awesome-widget/plugin/awconfighelper.h | 2 +- .../plugin/awdataaggregator.cpp | 2 +- .../plugin/awformatterhelper.cpp | 64 +++++++++++++------ .../awesome-widget/plugin/awformatterhelper.h | 4 +- .../awesome-widget/plugin/awkeyoperations.cpp | 15 +++-- sources/awesome-widget/plugin/awkeys.cpp | 2 +- .../awesome-widget/plugin/awupdatehelper.cpp | 4 +- sources/awesomewidgets/abstractextitem.cpp | 16 ++++- sources/awesomewidgets/abstractextitem.h | 1 + .../awesomewidgets/awdatetimeformatter.cpp | 2 + sources/awesomewidgets/awfloatformatter.cpp | 2 + sources/awesomewidgets/awscriptformatter.cpp | 3 + sources/awesomewidgets/extquotes.cpp | 2 + sources/awesomewidgets/extscript.cpp | 8 +-- sources/awesomewidgets/extupgrade.cpp | 8 +-- sources/awesomewidgets/extweather.cpp | 2 + sources/awesomewidgets/graphicalitem.cpp | 8 +-- sources/desktop-panel/plugin/dpadds.cpp | 16 ++--- sources/extsysmon/extsysmon.cpp | 4 +- sources/version.h.in | 2 + 22 files changed, 107 insertions(+), 65 deletions(-) diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp index 2b9ccc7..2b7ad34 100644 --- a/sources/awdebug.cpp +++ b/sources/awdebug.cpp @@ -44,6 +44,7 @@ const QStringList getBuildData() metadata.append(QString(" AWESAPI: %1").arg(AWESAPI)); metadata.append(QString(" AWEUAPI: %1").arg(AWEUAPI)); metadata.append(QString(" AWEWAPI: %1").arg(AWEWAPI)); + metadata.append(QString(" AWEFAPI: %1").arg(AWEFAPI)); metadata.append(QString(" TIME_KEYS: %1").arg(TIME_KEYS)); metadata.append(QString(" STATIC_KEYS: %1").arg(STATIC_KEYS)); // cmake properties diff --git a/sources/awesome-widget/plugin/awconfighelper.cpp b/sources/awesome-widget/plugin/awconfighelper.cpp index db8dbf4..4bb06c7 100644 --- a/sources/awesome-widget/plugin/awconfighelper.cpp +++ b/sources/awesome-widget/plugin/awconfighelper.cpp @@ -201,7 +201,7 @@ QVariantMap AWConfigHelper::readDataEngineConfiguration() const } -void AWConfigHelper::writeDataEngineConfiguration( +bool AWConfigHelper::writeDataEngineConfiguration( const QVariantMap configuration) const { qCDebug(LOG_AW) << "Configuration" << configuration; @@ -228,6 +228,8 @@ void AWConfigHelper::writeDataEngineConfiguration( settings.endGroup(); settings.sync(); + + return (settings.status() == QSettings::NoError); } diff --git a/sources/awesome-widget/plugin/awconfighelper.h b/sources/awesome-widget/plugin/awconfighelper.h index d16e297..fdca421 100644 --- a/sources/awesome-widget/plugin/awconfighelper.h +++ b/sources/awesome-widget/plugin/awconfighelper.h @@ -42,7 +42,7 @@ public: const bool importAdds) const; // dataengine Q_INVOKABLE QVariantMap readDataEngineConfiguration() const; - Q_INVOKABLE void + Q_INVOKABLE bool writeDataEngineConfiguration(const QVariantMap configuration) const; private: diff --git a/sources/awesome-widget/plugin/awdataaggregator.cpp b/sources/awesome-widget/plugin/awdataaggregator.cpp index 7f26fe4..4b22862 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.cpp +++ b/sources/awesome-widget/plugin/awdataaggregator.cpp @@ -19,11 +19,11 @@ #include -#include #include #include #include #include +#include #include diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index 168f092..f6c9e10 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -23,8 +23,8 @@ #include #include -#include "awdebug.h" #include "awdatetimeformatter.h" +#include "awdebug.h" #include "awfloatformatter.h" #include "awnoformatter.h" #include "awscriptformatter.h" @@ -66,11 +66,13 @@ QStringList AWFormatterHelper::definedFormatters() const } -QString AWFormatterHelper::formatterByTag(const QString tag) const +QVariantMap AWFormatterHelper::getFormatters() const { - qCDebug(LOG_AW) << "Looking for tag" << tag; + QVariantMap map; + for (auto tag : m_formatters.keys()) + map[tag] = m_formatters[tag]->name(); - return m_formatters.contains(tag) ? m_formatters[tag]->name() : QString(); + return map; } @@ -80,6 +82,25 @@ QStringList AWFormatterHelper::knownFormatters() const } +bool AWFormatterHelper::writeFormatters(const QVariantMap configuration) const +{ + QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)); + QSettings settings(fileName, QSettings::IniFormat); + qCInfo(LOG_AW) << "Configuration file" << fileName; + + settings.beginGroup(QString("Formatters")); + for (auto key : configuration.keys()) + settings.setValue(key, configuration[key]); + settings.endGroup(); + + settings.sync(); + + return (settings.status() == QSettings::NoError); +} + + QList AWFormatterHelper::items() const { QList converted; @@ -155,19 +176,28 @@ void AWFormatterHelper::initKeys() { m_formatters.clear(); - QSettings settings(m_formatterConfig, QSettings::IniFormat); - settings.beginGroup(QString("Formatters")); - QStringList keys = settings.childKeys(); - for (auto key : keys) { - QString name = settings.value(key).toString(); - qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key; - if (!m_formattersClasses.contains(name)) { - qCWarning(LOG_AW) << "Invalid formatter" << name << "found in" - << key; + QStringList configs = QStandardPaths::locateAll( + QStandardPaths::GenericDataLocation, + QString("awesomewidgets/formatters/formatters.ini")); + + for (auto fileName : configs) { + QSettings settings(fileName, QSettings::IniFormat); + qCInfo(LOG_AW) << "Configuration file" << settings.fileName(); + + settings.beginGroup(QString("Formatters")); + QStringList keys = settings.childKeys(); + for (auto key : keys) { + QString name = settings.value(key).toString(); + qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key + << "in" << settings.fileName(); + if (!m_formattersClasses.contains(name)) { + qCWarning(LOG_AW) << "Invalid formatter" << name << "found in" + << key; + } + m_formatters[key] = m_formattersClasses[name]; } - m_formatters[key] = m_formattersClasses[name]; + settings.endGroup(); } - settings.endGroup(); } @@ -184,10 +214,6 @@ void AWFormatterHelper::installDirectories() m_directories = QStandardPaths::locateAll( QStandardPaths::GenericDataLocation, QString("awesomewidgets/formatters"), QStandardPaths::LocateDirectory); - - m_formatterConfig = QString("%1/awesomewidgets/formatters/formatters.ini") - .arg(QStandardPaths::writableLocation( - QStandardPaths::GenericDataLocation)); } diff --git a/sources/awesome-widget/plugin/awformatterhelper.h b/sources/awesome-widget/plugin/awformatterhelper.h index 952452c..36cddcb 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.h +++ b/sources/awesome-widget/plugin/awformatterhelper.h @@ -35,8 +35,9 @@ public: virtual ~AWFormatterHelper(); QString convert(const QVariant &value, const QString name) const; Q_INVOKABLE QStringList definedFormatters() const; - Q_INVOKABLE QString formatterByTag(const QString tag) const; + Q_INVOKABLE QVariantMap getFormatters() const; Q_INVOKABLE QStringList knownFormatters() const; + Q_INVOKABLE bool writeFormatters(const QVariantMap configuration) const; QList items() const; private: @@ -53,7 +54,6 @@ private: void initItems(); // properties QStringList m_directories; - QString m_formatterConfig; QHash m_formatters; QHash m_formattersClasses; }; diff --git a/sources/awesome-widget/plugin/awkeyoperations.cpp b/sources/awesome-widget/plugin/awkeyoperations.cpp index abab46c..1e23e18 100644 --- a/sources/awesome-widget/plugin/awkeyoperations.cpp +++ b/sources/awesome-widget/plugin/awkeyoperations.cpp @@ -194,12 +194,14 @@ QString AWKeyOperations::infoByKey(QString key) const else if (key.startsWith(QString("custom"))) return extScripts->itemByTag(key, QString("custom"))->uniq(); else if (key.contains(QRegExp(QString("^hdd[rw]")))) - return QString("%1").arg(m_devices[QString( - "disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); + return QString("%1").arg( + m_devices[QString("disk")] + [key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); else if (key.contains(QRegExp( QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))) - return QString("%1").arg(m_devices[QString( - "mount")][key + return QString("%1").arg( + m_devices[QString("mount")] + [key .remove(QRegExp(QString( "^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))) .toInt()]); @@ -207,8 +209,9 @@ QString AWKeyOperations::infoByKey(QString key) const return QString("%1").arg( m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]); else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) - return QString("%1").arg(m_devices[QString( - "net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]); + return QString("%1").arg( + m_devices[QString("net")] + [key.remove(QRegExp(QString("^(down|up)"))).toInt()]); else if (key.startsWith(QString("pkgcount"))) return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq(); else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index fd1c829..1744fb7 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -17,11 +17,11 @@ #include "awkeys.h" -#include #include #include #include #include +#include #include "awdataaggregator.h" #include "awdataengineaggregator.h" diff --git a/sources/awesome-widget/plugin/awupdatehelper.cpp b/sources/awesome-widget/plugin/awupdatehelper.cpp index 9ccd636..bd9c59a 100644 --- a/sources/awesome-widget/plugin/awupdatehelper.cpp +++ b/sources/awesome-widget/plugin/awupdatehelper.cpp @@ -19,14 +19,14 @@ #include -#include #include #include #include #include -#include #include +#include #include +#include #include "awdebug.h" diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index b4fa77d..18b5639 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -22,8 +22,8 @@ #include #include -#include "awdebug.h" #include "abstractextitemaggregator.h" +#include "awdebug.h" AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath) @@ -44,6 +44,20 @@ AbstractExtItem::~AbstractExtItem() } +void AbstractExtItem::bumpApi(const int _newVer) +{ + qCDebug(LOG_LIB) << "Bump API using new version" << _newVer; + + // update for current API + if ((apiVersion() > 0) && (apiVersion() < _newVer)) { + qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" + << _newVer; + setApiVersion(_newVer); + writeConfiguration(); + } +} + + void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const { _other->setActive(m_active); diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index ff02013..4a19168 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -38,6 +38,7 @@ public: explicit AbstractExtItem(QWidget *parent = nullptr, const QString filePath = QString()); virtual ~AbstractExtItem(); + virtual void bumpApi(const int _newVer); virtual AbstractExtItem *copy(const QString _fileName, const int _number) = 0; virtual void copyDefaults(AbstractExtItem *_other) const; diff --git a/sources/awesomewidgets/awdatetimeformatter.cpp b/sources/awesomewidgets/awdatetimeformatter.cpp index 24c1aa4..fbc220c 100644 --- a/sources/awesomewidgets/awdatetimeformatter.cpp +++ b/sources/awesomewidgets/awdatetimeformatter.cpp @@ -108,6 +108,8 @@ void AWDateTimeFormatter::readConfiguration() settings.beginGroup(QString("Desktop Entry")); setFormat(settings.value(QString("X-AW-Format"), m_format).toString()); settings.endGroup(); + + bumpApi(AWEFAPI); } diff --git a/sources/awesomewidgets/awfloatformatter.cpp b/sources/awesomewidgets/awfloatformatter.cpp index 6bd3fb8..af69075 100644 --- a/sources/awesomewidgets/awfloatformatter.cpp +++ b/sources/awesomewidgets/awfloatformatter.cpp @@ -207,6 +207,8 @@ void AWFloatFormatter::readConfiguration() settings.value(QString("X-AW-Precision"), m_precision).toInt()); setSummand(settings.value(QString("X-AW-Summand"), m_summand).toDouble()); settings.endGroup(); + + bumpApi(AWEFAPI); } diff --git a/sources/awesomewidgets/awscriptformatter.cpp b/sources/awesomewidgets/awscriptformatter.cpp index a97ff41..f01cbc6 100644 --- a/sources/awesomewidgets/awscriptformatter.cpp +++ b/sources/awesomewidgets/awscriptformatter.cpp @@ -165,6 +165,9 @@ void AWScriptFormatter::readConfiguration() settings.value(QString("X-AW-HasReturn"), m_hasReturn).toBool()); settings.endGroup(); + bumpApi(AWEFAPI); + + // init JS code initProgram(); } diff --git a/sources/awesomewidgets/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp index e115a35..785f0f4 100644 --- a/sources/awesomewidgets/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -125,6 +125,8 @@ void ExtQuotes::readConfiguration() writeConfiguration(); } + bumpApi(AWEQAPI); + // init query m_url = QUrl(YAHOO_QUOTES_URL); QUrlQuery params; diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 3e278c6..683e9d1 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -227,13 +227,7 @@ void ExtScript::readConfiguration() .split(QChar(','), QString::SkipEmptyParts)); settings.endGroup(); - // update for current API - if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) { - qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" - << AWESAPI; - setApiVersion(AWESAPI); - writeConfiguration(); - } + bumpApi(AWESAPI); } diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index fe5cd11..e996dbd 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -135,13 +135,7 @@ void ExtUpgrade::readConfiguration() setFilter(settings.value(QString("X-AW-Filter"), m_filter).toString()); settings.endGroup(); - // update for current API - if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) { - qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" - << AWEUAPI; - setApiVersion(AWEUAPI); - writeConfiguration(); - } + bumpApi(AWEUAPI); } diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 5e66da8..0f82ba5 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -183,6 +183,8 @@ void ExtWeather::readConfiguration() writeConfiguration(); } + bumpApi(AWEWAPI); + // init query m_url = QUrl(YAHOO_WEATHER_URL); QUrlQuery params; diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index d31b2a6..1095932 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -431,13 +431,7 @@ void GraphicalItem::readConfiguration() } settings.endGroup(); - // update for current API - if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) { - qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" - << AWGIAPI; - setApiVersion(AWGIAPI); - writeConfiguration(); - } + bumpApi(AWGIAPI); } diff --git a/sources/desktop-panel/plugin/dpadds.cpp b/sources/desktop-panel/plugin/dpadds.cpp index 21a551c..ee25dae 100644 --- a/sources/desktop-panel/plugin/dpadds.cpp +++ b/sources/desktop-panel/plugin/dpadds.cpp @@ -156,22 +156,22 @@ QString DPAdds::toolTipImage(const int desktop) const std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(), [&toolTipScene, &screen](WindowData data) { QPixmap desktop = screen->grabWindow(data.id); - toolTipScene->addPixmap(desktop) - ->setOffset(data.rect.left(), data.rect.top()); + toolTipScene->addPixmap(desktop)->setOffset( + data.rect.left(), data.rect.top()); }); } else if (m_tooltipType == QString("windows")) { QScreen *screen = QGuiApplication::primaryScreen(); std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(), [&toolTipScene, &screen](WindowData data) { QPixmap desktop = screen->grabWindow(data.id); - toolTipScene->addPixmap(desktop) - ->setOffset(data.rect.left(), data.rect.top()); + toolTipScene->addPixmap(desktop)->setOffset( + data.rect.left(), data.rect.top()); }); std::for_each(info.windowsData.cbegin(), info.windowsData.cend(), [&toolTipScene, &screen](WindowData data) { QPixmap window = screen->grabWindow(data.id); - toolTipScene->addPixmap(window) - ->setOffset(data.rect.left(), data.rect.top()); + toolTipScene->addPixmap(window)->setOffset( + data.rect.left(), data.rect.top()); }); } @@ -232,8 +232,8 @@ QString DPAdds::valueByKey(const QString key, int desktop) const .arg(currentMark, m_mark.count(), QLatin1Char(' ')) .replace(QString(" "), QString(" ")); else if (key == QString("name")) - return KWindowSystem::desktopName(desktop) - .replace(QString(" "), QString(" ")); + return KWindowSystem::desktopName(desktop).replace(QString(" "), + QString(" ")); else if (key == QString("number")) return QString::number(desktop); else if (key == QString("total")) diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 8727df8..6b61d34 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -125,8 +125,8 @@ void ExtendedSysMon::readConfiguration() settings.beginGroup(QString("Configuration")); rawConfig[QString("ACPIPATH")] - = settings.value(QString("ACPIPATH"), - QString("/sys/class/power_supply/")) + = settings + .value(QString("ACPIPATH"), QString("/sys/class/power_supply/")) .toString(); rawConfig[QString("GPUDEV")] = settings.value(QString("GPUDEV"), QString("auto")).toString(); diff --git a/sources/version.h.in b/sources/version.h.in index eed78e8..5803bec 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -33,6 +33,8 @@ #define AWEUAPI 3 // extweather api version #define AWEWAPI 2 +// formatter api version +#define AWEFAPI 1 // network requests timeout, ms #define REQUEST_TIMEOUT 5000 // available time keys From 301a908aed18b5078de4659d22d8cace1339337f Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sun, 15 May 2016 01:18:18 +0300 Subject: [PATCH 07/32] add formatter configuration to ui --- .../package/contents/ui/widget.qml | 10 +- .../plugin/awabstractselector.cpp | 76 +++++++++ .../plugin/awabstractselector.h | 49 ++++++ .../plugin/awabstractselector.ui | 36 ++++ .../awesome-widget/plugin/awesomewidget.cpp | 5 +- .../plugin/awformatterconfig.cpp | 159 ++++++++++++++++++ .../awesome-widget/plugin/awformatterconfig.h | 61 +++++++ .../plugin/awformatterconfig.ui | 93 ++++++++++ .../plugin/awformatterconfigfactory.cpp | 42 +++++ .../plugin/awformatterconfigfactory.h | 38 +++++ .../plugin/awformatterhelper.cpp | 31 ++-- .../awesome-widget/plugin/awformatterhelper.h | 8 +- .../awesome-widget/plugin/awkeyoperations.cpp | 15 +- sources/desktop-panel/plugin/dpadds.cpp | 16 +- sources/extsysmon/extsysmon.cpp | 4 +- 15 files changed, 604 insertions(+), 39 deletions(-) create mode 100644 sources/awesome-widget/plugin/awabstractselector.cpp create mode 100644 sources/awesome-widget/plugin/awabstractselector.h create mode 100644 sources/awesome-widget/plugin/awabstractselector.ui create mode 100644 sources/awesome-widget/plugin/awformatterconfig.cpp create mode 100644 sources/awesome-widget/plugin/awformatterconfig.h create mode 100644 sources/awesome-widget/plugin/awformatterconfig.ui create mode 100644 sources/awesome-widget/plugin/awformatterconfigfactory.cpp create mode 100644 sources/awesome-widget/plugin/awformatterconfigfactory.h diff --git a/sources/awesome-widget/package/contents/ui/widget.qml b/sources/awesome-widget/package/contents/ui/widget.qml index 86da37c..62c4900 100644 --- a/sources/awesome-widget/package/contents/ui/widget.qml +++ b/sources/awesome-widget/package/contents/ui/widget.qml @@ -31,6 +31,9 @@ Item { AWActions { id: awActions } + AWFormatterConfigFactory { + id: awFormatter + } width: childrenRect.width height: childrenRect.height @@ -320,10 +323,15 @@ Item { height: implicitHeight width: parent.width QtControls.Button { - width: parent.width * 3 / 5 + width: parent.width * 3 / 10 text: i18n("Edit bars") onClicked: awKeys.editItem("graphicalitem") } + QtControls.Button { + width: parent.width * 3 / 10 + text: i18n("Formatters") + onClicked: awFormatter.showDialog(awKeys.dictKeys(true)) + } QtControls.Button { width: parent.width * 2 / 5 text: i18n("Preview") diff --git a/sources/awesome-widget/plugin/awabstractselector.cpp b/sources/awesome-widget/plugin/awabstractselector.cpp new file mode 100644 index 0000000..46215ac --- /dev/null +++ b/sources/awesome-widget/plugin/awabstractselector.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awabstractselector.h" +#include "ui_awabstractselector.h" + +#include "awdebug.h" + + +AWAbstractSelector::AWAbstractSelector(QWidget *parent) + : QWidget(parent) + , ui(new Ui::AWAbstractSelector) +{ + qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + ui->setupUi(this); + + connect(ui->comboBox_key, SIGNAL(currentIndexChanged(int)), this, + SIGNAL(selectionChanged())); + connect(ui->comboBox_value, SIGNAL(currentIndexChanged(int)), this, + SIGNAL(selectionChanged())); +} + + +AWAbstractSelector::~AWAbstractSelector() +{ + qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + delete ui; +} + + +QPair AWAbstractSelector::current() const +{ + QString key = ui->comboBox_key->currentText(); + QString value = ui->comboBox_value->currentText(); + + return QPair(key, value); +} + + +void AWAbstractSelector::init(const QStringList keys, const QStringList values, + const QPair current) +{ + if ((!keys.contains(current.first)) || (!values.contains(current.second))) { + qCWarning(LOG_AW) << "Invalid current value" << current + << "not found in default ones"; + return; + } + qCDebug(LOG_AW) << "Init selector with keys" << keys << "and values" + << values << "and current ones are" << current; + + // set data + ui->comboBox_key->clear(); + ui->comboBox_key->addItems(keys); + ui->comboBox_value->clear(); + ui->comboBox_value->addItems(values); + + // set current values + ui->comboBox_key->setCurrentText(current.first); + ui->comboBox_value->setCurrentText(current.second); +} diff --git a/sources/awesome-widget/plugin/awabstractselector.h b/sources/awesome-widget/plugin/awabstractselector.h new file mode 100644 index 0000000..2dbc926 --- /dev/null +++ b/sources/awesome-widget/plugin/awabstractselector.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef AWABSTRACTSELECTOR_H +#define AWABSTRACTSELECTOR_H + +#include + + +namespace Ui +{ +class AWAbstractSelector; +} + +class AWAbstractSelector : public QWidget +{ + Q_OBJECT + +public: + explicit AWAbstractSelector(QWidget *parent = nullptr); + virtual ~AWAbstractSelector(); + QPair current() const; + void init(const QStringList keys, const QStringList values, + const QPair current); + +signals: + void selectionChanged(); + +private: + Ui::AWAbstractSelector *ui = nullptr; +}; + + +#endif /* AWABSTRACTSELECTOR_H */ diff --git a/sources/awesome-widget/plugin/awabstractselector.ui b/sources/awesome-widget/plugin/awabstractselector.ui new file mode 100644 index 0000000..a871fa1 --- /dev/null +++ b/sources/awesome-widget/plugin/awabstractselector.ui @@ -0,0 +1,36 @@ + + + AWAbstractSelector + + + + 0 + 0 + 400 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + diff --git a/sources/awesome-widget/plugin/awesomewidget.cpp b/sources/awesome-widget/plugin/awesomewidget.cpp index 4235ed5..e327c47 100644 --- a/sources/awesome-widget/plugin/awesomewidget.cpp +++ b/sources/awesome-widget/plugin/awesomewidget.cpp @@ -21,7 +21,7 @@ #include "awactions.h" #include "awconfighelper.h" -#include "awformatterhelper.h" +#include "awformatterconfigfactory.h" #include "awkeys.h" @@ -31,6 +31,7 @@ void AWPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 1, 0, "AWActions"); qmlRegisterType(uri, 1, 0, "AWConfigHelper"); - qmlRegisterType(uri, 1, 0, "AWFormatterHelper"); + qmlRegisterType(uri, 1, 0, + "AWFormatterConfigFactory"); qmlRegisterType(uri, 1, 0, "AWKeys"); } diff --git a/sources/awesome-widget/plugin/awformatterconfig.cpp b/sources/awesome-widget/plugin/awformatterconfig.cpp new file mode 100644 index 0000000..d4dd856 --- /dev/null +++ b/sources/awesome-widget/plugin/awformatterconfig.cpp @@ -0,0 +1,159 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awformatterconfig.h" +#include "ui_awformatterconfig.h" + +#include + +#include "awabstractselector.h" +#include "awdebug.h" +#include "awformatterhelper.h" + + +AWFormatterConfig::AWFormatterConfig(QWidget *parent, const QStringList keys) + : QDialog(parent) + , ui(new Ui::AWFormatterConfig) + , m_keys(keys) +{ + qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + ui->setupUi(this); + init(); + + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); +} + + +AWFormatterConfig::~AWFormatterConfig() +{ + qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + clearSelectors(); + + delete m_helper; + delete ui; +} + + +void AWFormatterConfig::showDialog() +{ + clearSelectors(); + QHash appliedFormatters = m_helper->getFormatters(); + auto keys = initKeys(); + + for (auto key : appliedFormatters.keys()) + addSelector(keys.first, keys.second, + QPair(key, appliedFormatters[key])); + // empty one + addSelector(keys.first, keys.second, QPair()); + + // exec dialog + return execDialog(); +} + + +void AWFormatterConfig::updateUi() +{ + QPair current + = static_cast(sender())->current(); + int index + = m_selectors.indexOf(static_cast(sender())); + + if ((current.first.isEmpty()) && (current.second.isEmpty())) { + if (sender() == m_selectors.last()) + return; + AWAbstractSelector *selector = m_selectors.takeAt(index); + ui->verticalLayout->removeWidget(selector); + selector->deleteLater(); + } else { + if (sender() != m_selectors.last()) + return; + auto keys = initKeys(); + addSelector(keys.first, keys.second, QPair()); + } +} + + +void AWFormatterConfig::addSelector(const QStringList &keys, + const QStringList &values, + const QPair ¤t) +{ + qCDebug(LOG_AW) << "Add selector with keys" << keys << "values" << values + << "and current ones" << current; + + AWAbstractSelector *selector + = new AWAbstractSelector(ui->scrollAreaWidgetContents); + selector->init(keys, values, current); + ui->verticalLayout->insertWidget(ui->verticalLayout->count() - 1, selector); + connect(selector, SIGNAL(selectionChanged()), this, SLOT(updateUi())); + m_selectors.append(selector); +} + + +void AWFormatterConfig::clearSelectors() +{ + for (auto selector : m_selectors) + disconnect(selector, SIGNAL(selectionChanged()), this, + SLOT(updateUi())); + m_selectors.clear(); +} + + +void AWFormatterConfig::execDialog() +{ + int ret = exec(); + QHash data; + for (auto selector : m_selectors) { + QPair select = selector->current(); + if ((select.first.isEmpty()) || (select.second.isEmpty())) + continue; + data[select.first] = select.second; + } + + // save configuration if required + switch (ret) { + case 0: + break; + case 1: + default: + m_helper->writeFormatters(data); + break; + } +} + + +void AWFormatterConfig::init() +{ + delete m_helper; + m_helper = new AWFormatterHelper(this); +} + + +QPair AWFormatterConfig::initKeys() const +{ + // we are adding empty string at the start + QStringList keys = QStringList() << QString(""); + keys.append(m_keys); + keys.sort(); + QStringList knownFormatters = QStringList() << QString(""); + knownFormatters.append(m_helper->knownFormatters()); + knownFormatters.sort(); + + return QPair(keys, knownFormatters); +} diff --git a/sources/awesome-widget/plugin/awformatterconfig.h b/sources/awesome-widget/plugin/awformatterconfig.h new file mode 100644 index 0000000..b04cbaa --- /dev/null +++ b/sources/awesome-widget/plugin/awformatterconfig.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef AWFORMATTERCONFIG_H +#define AWFORMATTERCONFIG_H + +#include + + +class AWAbstractSelector; +class AWFormatterHelper; +namespace Ui +{ +class AWFormatterConfig; +} + +class AWFormatterConfig : public QDialog +{ + Q_OBJECT + +public: + explicit AWFormatterConfig(QWidget *parent = nullptr, + const QStringList keys = QStringList()); + virtual ~AWFormatterConfig(); + Q_INVOKABLE void showDialog(); + +private slots: + void updateUi(); + +private: + Ui::AWFormatterConfig *ui = nullptr; + AWFormatterHelper *m_helper = nullptr; + QList m_selectors; + // properties + QStringList m_keys; + // methods + void addSelector(const QStringList &keys, const QStringList &values, + const QPair ¤t); + void clearSelectors(); + void execDialog(); + void init(); + QPair initKeys() const; +}; + + +#endif /* AWFORMATTERCONFIG_H */ diff --git a/sources/awesome-widget/plugin/awformatterconfig.ui b/sources/awesome-widget/plugin/awformatterconfig.ui new file mode 100644 index 0000000..4f0fff2 --- /dev/null +++ b/sources/awesome-widget/plugin/awformatterconfig.ui @@ -0,0 +1,93 @@ + + + AWFormatterConfig + + + + 0 + 0 + 400 + 300 + + + + + + + true + + + + + 0 + 0 + 384 + 249 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AWFormatterConfig + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AWFormatterConfig + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/awesome-widget/plugin/awformatterconfigfactory.cpp b/sources/awesome-widget/plugin/awformatterconfigfactory.cpp new file mode 100644 index 0000000..d7da52d --- /dev/null +++ b/sources/awesome-widget/plugin/awformatterconfigfactory.cpp @@ -0,0 +1,42 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awformatterconfigfactory.h" + +#include "awdebug.h" +#include "awformatterconfig.h" + + +AWFormatterConfigFactory::AWFormatterConfigFactory(QObject *parent) + : QObject(parent) +{ + qCDebug(LOG_AW) << __PRETTY_FUNCTION__; +} + + +AWFormatterConfigFactory::~AWFormatterConfigFactory() +{ + qCDebug(LOG_AW) << __PRETTY_FUNCTION__; +} + + +void AWFormatterConfigFactory::showDialog(const QStringList keys) +{ + AWFormatterConfig *config = new AWFormatterConfig(nullptr, keys); + config->showDialog(); + config->deleteLater(); +} diff --git a/sources/awesome-widget/plugin/awformatterconfigfactory.h b/sources/awesome-widget/plugin/awformatterconfigfactory.h new file mode 100644 index 0000000..edfd49f --- /dev/null +++ b/sources/awesome-widget/plugin/awformatterconfigfactory.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef AWFORMATTERCONFIGFACTORY_H +#define AWFORMATTERCONFIGFACTORY_H + +#include + + +class AWFormatterConfigFactory : public QObject +{ + Q_OBJECT + +public: + explicit AWFormatterConfigFactory(QObject *parent = nullptr); + virtual ~AWFormatterConfigFactory(); + Q_INVOKABLE void showDialog(const QStringList keys); + +private: +}; + + +#endif /* AWFORMATTERCONFIGFACTORY_H */ diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index f6c9e10..7dccc84 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -66,9 +66,9 @@ QStringList AWFormatterHelper::definedFormatters() const } -QVariantMap AWFormatterHelper::getFormatters() const +QHash AWFormatterHelper::getFormatters() const { - QVariantMap map; + QHash map; for (auto tag : m_formatters.keys()) map[tag] = m_formatters[tag]->name(); @@ -76,14 +76,27 @@ QVariantMap AWFormatterHelper::getFormatters() const } +QList AWFormatterHelper::items() const +{ + QList converted; + for (auto item : m_formattersClasses.values()) + converted.append(item); + + return converted; +} + + QStringList AWFormatterHelper::knownFormatters() const { return m_formattersClasses.keys(); } -bool AWFormatterHelper::writeFormatters(const QVariantMap configuration) const +bool AWFormatterHelper::writeFormatters( + const QHash configuration) const { + qCDebug(LOG_AW) << "Write configuration" << configuration; + QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini") .arg(QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation)); @@ -101,16 +114,6 @@ bool AWFormatterHelper::writeFormatters(const QVariantMap configuration) const } -QList AWFormatterHelper::items() const -{ - QList converted; - for (auto item : m_formattersClasses.values()) - converted.append(item); - - return converted; -} - - AWFormatterHelper::FormatterClass AWFormatterHelper::defineFormatterClass(const QString stringType) const { @@ -121,6 +124,8 @@ AWFormatterHelper::defineFormatterClass(const QString stringType) const formatter = FormatterClass::DateTime; else if (stringType == QString("Float")) formatter = FormatterClass::Float; + else if (stringType == QString("NoFormat")) + ; else if (stringType == QString("Script")) formatter = FormatterClass::Script; else diff --git a/sources/awesome-widget/plugin/awformatterhelper.h b/sources/awesome-widget/plugin/awformatterhelper.h index 36cddcb..81eb324 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.h +++ b/sources/awesome-widget/plugin/awformatterhelper.h @@ -34,11 +34,11 @@ public: explicit AWFormatterHelper(QWidget *parent = nullptr); virtual ~AWFormatterHelper(); QString convert(const QVariant &value, const QString name) const; - Q_INVOKABLE QStringList definedFormatters() const; - Q_INVOKABLE QVariantMap getFormatters() const; - Q_INVOKABLE QStringList knownFormatters() const; - Q_INVOKABLE bool writeFormatters(const QVariantMap configuration) const; + QStringList definedFormatters() const; + QHash getFormatters() const; QList items() const; + QStringList knownFormatters() const; + bool writeFormatters(const QHash configuration) const; private: // methods diff --git a/sources/awesome-widget/plugin/awkeyoperations.cpp b/sources/awesome-widget/plugin/awkeyoperations.cpp index 1e23e18..abab46c 100644 --- a/sources/awesome-widget/plugin/awkeyoperations.cpp +++ b/sources/awesome-widget/plugin/awkeyoperations.cpp @@ -194,14 +194,12 @@ QString AWKeyOperations::infoByKey(QString key) const else if (key.startsWith(QString("custom"))) return extScripts->itemByTag(key, QString("custom"))->uniq(); else if (key.contains(QRegExp(QString("^hdd[rw]")))) - return QString("%1").arg( - m_devices[QString("disk")] - [key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); + return QString("%1").arg(m_devices[QString( + "disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); else if (key.contains(QRegExp( QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))) - return QString("%1").arg( - m_devices[QString("mount")] - [key + return QString("%1").arg(m_devices[QString( + "mount")][key .remove(QRegExp(QString( "^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))) .toInt()]); @@ -209,9 +207,8 @@ QString AWKeyOperations::infoByKey(QString key) const return QString("%1").arg( m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]); else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) - return QString("%1").arg( - m_devices[QString("net")] - [key.remove(QRegExp(QString("^(down|up)"))).toInt()]); + return QString("%1").arg(m_devices[QString( + "net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]); else if (key.startsWith(QString("pkgcount"))) return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq(); else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) diff --git a/sources/desktop-panel/plugin/dpadds.cpp b/sources/desktop-panel/plugin/dpadds.cpp index ee25dae..21a551c 100644 --- a/sources/desktop-panel/plugin/dpadds.cpp +++ b/sources/desktop-panel/plugin/dpadds.cpp @@ -156,22 +156,22 @@ QString DPAdds::toolTipImage(const int desktop) const std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(), [&toolTipScene, &screen](WindowData data) { QPixmap desktop = screen->grabWindow(data.id); - toolTipScene->addPixmap(desktop)->setOffset( - data.rect.left(), data.rect.top()); + toolTipScene->addPixmap(desktop) + ->setOffset(data.rect.left(), data.rect.top()); }); } else if (m_tooltipType == QString("windows")) { QScreen *screen = QGuiApplication::primaryScreen(); std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(), [&toolTipScene, &screen](WindowData data) { QPixmap desktop = screen->grabWindow(data.id); - toolTipScene->addPixmap(desktop)->setOffset( - data.rect.left(), data.rect.top()); + toolTipScene->addPixmap(desktop) + ->setOffset(data.rect.left(), data.rect.top()); }); std::for_each(info.windowsData.cbegin(), info.windowsData.cend(), [&toolTipScene, &screen](WindowData data) { QPixmap window = screen->grabWindow(data.id); - toolTipScene->addPixmap(window)->setOffset( - data.rect.left(), data.rect.top()); + toolTipScene->addPixmap(window) + ->setOffset(data.rect.left(), data.rect.top()); }); } @@ -232,8 +232,8 @@ QString DPAdds::valueByKey(const QString key, int desktop) const .arg(currentMark, m_mark.count(), QLatin1Char(' ')) .replace(QString(" "), QString(" ")); else if (key == QString("name")) - return KWindowSystem::desktopName(desktop).replace(QString(" "), - QString(" ")); + return KWindowSystem::desktopName(desktop) + .replace(QString(" "), QString(" ")); else if (key == QString("number")) return QString::number(desktop); else if (key == QString("total")) diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 6b61d34..8727df8 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -125,8 +125,8 @@ void ExtendedSysMon::readConfiguration() settings.beginGroup(QString("Configuration")); rawConfig[QString("ACPIPATH")] - = settings - .value(QString("ACPIPATH"), QString("/sys/class/power_supply/")) + = settings.value(QString("ACPIPATH"), + QString("/sys/class/power_supply/")) .toString(); rawConfig[QString("GPUDEV")] = settings.value(QString("GPUDEV"), QString("auto")).toString(); From 906ad56c46192d80d0f137cd11382a7ddadd8c06 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 17 May 2016 14:22:12 +0300 Subject: [PATCH 08/32] Rename some properties in GI. Actually properties height and width are QDialog ones, just rename them to ones with `item` prefix. No configuration keys were changed. Update translations as well. --- .../plugin/awformatterhelper.cpp | 4 +- .../awesome-widget/plugin/awformatterhelper.h | 2 +- sources/awesomewidgets/awabstractformatter.h | 2 +- sources/awesomewidgets/graphicalitem.cpp | 88 +++++++++---------- sources/awesomewidgets/graphicalitem.h | 14 +-- sources/translations/awesome-widgets.pot | 47 ++++++++-- sources/translations/en.po | 55 +++++++++--- sources/translations/es.po | 82 +++++++++++++---- sources/translations/fr.po | 54 +++++++++--- sources/translations/nl_NL.po | 52 +++++++++-- sources/translations/pl.po | 52 +++++++++-- sources/translations/pt_BR.po | 55 +++++++++--- sources/translations/ru.po | 55 +++++++++--- sources/translations/uk.po | 55 +++++++++--- sources/translations/zh.po | 52 +++++++++-- 15 files changed, 510 insertions(+), 159 deletions(-) diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index 7dccc84..a0349b8 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -35,9 +35,7 @@ AWFormatterHelper::AWFormatterHelper(QWidget *parent) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; -#ifdef BUILD_FUTURE initItems(); -#endif /* BUILD_FUTURE */ } @@ -51,7 +49,7 @@ AWFormatterHelper::~AWFormatterHelper() QString AWFormatterHelper::convert(const QVariant &value, - const QString name) const + const QString &name) const { qCDebug(LOG_AW) << "Convert value" << value << "for" << name; diff --git a/sources/awesome-widget/plugin/awformatterhelper.h b/sources/awesome-widget/plugin/awformatterhelper.h index 81eb324..657871e 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.h +++ b/sources/awesome-widget/plugin/awformatterhelper.h @@ -33,7 +33,7 @@ public: explicit AWFormatterHelper(QWidget *parent = nullptr); virtual ~AWFormatterHelper(); - QString convert(const QVariant &value, const QString name) const; + QString convert(const QVariant &value, const QString &name) const; QStringList definedFormatters() const; QHash getFormatters() const; QList items() const; diff --git a/sources/awesomewidgets/awabstractformatter.h b/sources/awesomewidgets/awabstractformatter.h index 519d5fb..b91bef6 100644 --- a/sources/awesomewidgets/awabstractformatter.h +++ b/sources/awesomewidgets/awabstractformatter.h @@ -30,8 +30,8 @@ public: explicit AWAbstractFormatter(QWidget *parent = nullptr, const QString filePath = QString()); virtual ~AWAbstractFormatter(); - void copyDefaults(AbstractExtItem *_other) const; virtual QString convert(const QVariant &_value) const = 0; + void copyDefaults(AbstractExtItem *_other) const; QString uniq() const; // properties QString type() const; diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 1095932..886e495 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -77,13 +77,13 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number) item->setCount(m_count); item->setCustom(m_custom); item->setDirection(m_direction); - item->setHeight(m_height); + item->setItemHeight(m_height); item->setInactiveColor(m_inactiveColor); item->setMaxValue(m_maxValue); item->setMinValue(m_minValue); item->setNumber(_number); item->setType(m_type); - item->setWidth(m_width); + item->setItemWidth(m_width); return item; } @@ -152,24 +152,36 @@ QString GraphicalItem::activeColor() const } -QString GraphicalItem::inactiveColor() const -{ - return m_inactiveColor; -} - - int GraphicalItem::count() const { return m_count; } +QString GraphicalItem::inactiveColor() const +{ + return m_inactiveColor; +} + + bool GraphicalItem::isCustom() const { return m_custom; } +int GraphicalItem::itemHeight() const +{ + return m_height; +} + + +int GraphicalItem::itemWidth() const +{ + return m_width; +} + + float GraphicalItem::maxValue() const { return m_maxValue; @@ -235,24 +247,12 @@ QString GraphicalItem::strDirection() const } -int GraphicalItem::height() const -{ - return m_height; -} - - QStringList GraphicalItem::usedKeys() const { return m_usedKeys; } -int GraphicalItem::width() const -{ - return m_width; -} - - QString GraphicalItem::uniq() const { return m_bar; @@ -301,6 +301,26 @@ void GraphicalItem::setInactiveColor(const QString _color) } +void GraphicalItem::setItemHeight(const int _height) +{ + qCDebug(LOG_LIB) << "Height" << _height; + if (_height <= 0) + return; + + m_height = _height; +} + + +void GraphicalItem::setItemWidth(const int _width) +{ + qCDebug(LOG_LIB) << "Width" << _width; + if (_width <= 0) + return; + + m_width = _width; +} + + void GraphicalItem::setMaxValue(const float _value) { qCDebug(LOG_LIB) << "Max value" << _value; @@ -361,16 +381,6 @@ void GraphicalItem::setStrDirection(const QString _direction) } -void GraphicalItem::setHeight(const int _height) -{ - qCDebug(LOG_LIB) << "Height" << _height; - if (_height <= 0) - return; - - m_height = _height; -} - - void GraphicalItem::setUsedKeys(const QStringList _usedKeys) { qCDebug(LOG_LIB) << "Used keys" << _usedKeys; @@ -386,16 +396,6 @@ void GraphicalItem::setUsedKeys(const QStringList _usedKeys) } -void GraphicalItem::setWidth(const int _width) -{ - qCDebug(LOG_LIB) << "Width" << _width; - if (_width <= 0) - return; - - m_width = _width; -} - - void GraphicalItem::readConfiguration() { AbstractExtItem::readConfiguration(); @@ -416,8 +416,8 @@ void GraphicalItem::readConfiguration() setStrType(settings.value(QString("X-AW-Type"), strType()).toString()); setStrDirection( settings.value(QString("X-AW-Direction"), strDirection()).toString()); - setHeight(settings.value(QString("X-AW-Height"), m_height).toInt()); - setWidth(settings.value(QString("X-AW-Width"), m_width).toInt()); + setItemHeight(settings.value(QString("X-AW-Height"), m_height).toInt()); + setItemWidth(settings.value(QString("X-AW-Width"), m_width).toInt()); // api == 5 if (apiVersion() < 5) { QString prefix; @@ -490,8 +490,8 @@ int GraphicalItem::showConfiguration(const QVariant args) setInactiveColor(ui->lineEdit_inactiveColor->text()); setStrType(ui->comboBox_type->currentText()); setStrDirection(ui->comboBox_direction->currentText()); - setHeight(ui->spinBox_height->value()); - setWidth(ui->spinBox_width->value()); + setItemHeight(ui->spinBox_height->value()); + setItemWidth(ui->spinBox_width->value()); writeConfiguration(); return ret; diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index c504996..89afaba 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -40,13 +40,13 @@ class GraphicalItem : public AbstractExtItem Q_PROPERTY(int count READ count WRITE setCount) Q_PROPERTY(bool custom READ isCustom WRITE setCustom) Q_PROPERTY(QString inactiveColor READ inactiveColor WRITE setInactiveColor) + Q_PROPERTY(int itemHeight READ itemHeight WRITE setItemHeight) + Q_PROPERTY(int itemWidth READ itemWidth WRITE setItemWidth) Q_PROPERTY(Type type READ type WRITE setType) Q_PROPERTY(Direction direction READ direction WRITE setDirection) - Q_PROPERTY(int height READ height WRITE setHeight) Q_PROPERTY(float maxValue READ maxValue WRITE setMaxValue) Q_PROPERTY(float minValue READ minValue WRITE setMinValue) Q_PROPERTY(QStringList usedKeys READ usedKeys WRITE setUsedKeys) - Q_PROPERTY(int width READ width WRITE setWidth) public: enum class Direction { LeftToRight = 0, RightToLeft = 1 }; @@ -60,18 +60,18 @@ public: // get methods QString bar() const; QString activeColor() const; - QString inactiveColor() const; int count() const; + QString inactiveColor() const; bool isCustom() const; + int itemHeight() const; + int itemWidth() const; float minValue() const; float maxValue() const; Type type() const; QString strType() const; Direction direction() const; QString strDirection() const; - int height() const; QStringList usedKeys() const; - int width() const; QString uniq() const; // set methods void setBar(const QString _bar = QString("cpu")); @@ -80,15 +80,15 @@ public: 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 setHeight(const int _height = 100); void setUsedKeys(const QStringList _usedKeys = QStringList()); - void setWidth(const int _width = 100); public slots: void readConfiguration(); diff --git a/sources/translations/awesome-widgets.pot b/sources/translations/awesome-widgets.pot index fb8cc48..d2da3a6 100644 --- a/sources/translations/awesome-widgets.pot +++ b/sources/translations/awesome-widgets.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -369,6 +369,9 @@ msgstr "" msgid "Edit bars" msgstr "" +msgid "Formatters" +msgstr "" + msgid "Preview" msgstr "" @@ -438,6 +441,12 @@ msgstr "" msgid "Network device has been changed to %1" msgstr "" +msgid "Select type" +msgstr "" + +msgid "Type:" +msgstr "" + msgid "MB/s" msgstr "" @@ -495,6 +504,36 @@ msgstr "" msgid "Comment" msgstr "" +msgid "Type" +msgstr "" + +msgid "Format" +msgstr "" + +msgid "Precision" +msgstr "" + +msgid "Width" +msgstr "" + +msgid "Fill char" +msgstr "" + +msgid "Multiplier" +msgstr "" + +msgid "Summand" +msgstr "" + +msgid "Append code" +msgstr "" + +msgid "Has return" +msgstr "" + +msgid "Code" +msgstr "" + msgid "Tag" msgstr "" @@ -568,9 +607,6 @@ msgstr "" msgid "Inctive filling type" msgstr "" -msgid "Type" -msgstr "" - msgid "Points count" msgstr "" @@ -580,9 +616,6 @@ msgstr "" msgid "Height" msgstr "" -msgid "Width" -msgstr "" - msgid "color" msgstr "" diff --git a/sources/translations/en.po b/sources/translations/en.po index 6b43fff..4d8602a 100644 --- a/sources/translations/en.po +++ b/sources/translations/en.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" -"PO-Revision-Date: 2016-04-29 12:21+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"PO-Revision-Date: 2016-05-16 14:14+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: English \n" "Language: ru\n" @@ -374,6 +374,9 @@ msgstr "Show value" msgid "Edit bars" msgstr "Edit bars" +msgid "Formatters" +msgstr "Formatters" + msgid "Preview" msgstr "Preview" @@ -443,6 +446,12 @@ msgstr "High GPU load" msgid "Network device has been changed to %1" msgstr "Network device has been changed to %1" +msgid "Select type" +msgstr "Select type" + +msgid "Type:" +msgstr "Type:" + msgid "MB/s" msgstr "MB/s" @@ -500,6 +509,36 @@ msgstr "Name" msgid "Comment" msgstr "Comment" +msgid "Type" +msgstr "Type" + +msgid "Format" +msgstr "Format" + +msgid "Precision" +msgstr "Precision" + +msgid "Width" +msgstr "Width" + +msgid "Fill char" +msgstr "Fill char" + +msgid "Multiplier" +msgstr "Multiplier" + +msgid "Summand" +msgstr "Summand" + +msgid "Append code" +msgstr "Append code" + +msgid "Has return" +msgstr "Has return" + +msgid "Code" +msgstr "Code" + msgid "Tag" msgstr "Tag" @@ -577,9 +616,6 @@ msgstr "Active filling type" msgid "Inctive filling type" msgstr "Inctive filling type" -msgid "Type" -msgstr "Type" - msgid "Points count" msgstr "Points count" @@ -589,9 +625,6 @@ msgstr "Direction" msgid "Height" msgstr "Height" -msgid "Width" -msgstr "Width" - msgid "color" msgstr "color" @@ -657,9 +690,6 @@ msgstr "esalexeev@gmail.com" #~ msgid "Free space on %1 less than 10%" #~ msgstr "Free space on %1 less than 10%" -#~ msgid "Has output" -#~ msgstr "Has output" - #~ msgid "Top Edge" #~ msgstr "Top Edge" @@ -828,9 +858,6 @@ msgstr "esalexeev@gmail.com" #~ msgid "Widget configuration" #~ msgstr "Widget configuration" -#~ msgid "Form" -#~ msgstr "Form" - #~ msgid "Network directory" #~ msgstr "Network directory" diff --git a/sources/translations/es.po b/sources/translations/es.po index c0686ff..3a43ac6 100644 --- a/sources/translations/es.po +++ b/sources/translations/es.po @@ -1,7 +1,7 @@ # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# +# # Translators: # Ernesto Avilés Vázquez , 2014-2016 # Evgeniy Alekseev , 2014-2015 @@ -9,14 +9,15 @@ msgid "" msgstr "" "Project-Id-Version: Awesome widgets\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" "PO-Revision-Date: 2016-05-03 06:47+0000\n" "Last-Translator: Ernesto Avilés Vázquez \n" -"Language-Team: Spanish (http://www.transifex.com/arcanis/awesome-widgets/language/es/)\n" +"Language-Team: Spanish (http://www.transifex.com/arcanis/awesome-widgets/" +"language/es/)\n" +"Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Language: es\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" msgid "Widget" @@ -274,7 +275,10 @@ msgstr "Comprobar actualizaciones" msgid "" "CPU, CPU clock, memory, swap and network labels support graphical tooltip. " "To enable them just make needed checkbox checked." -msgstr "Las etiquetas para CPU, reloj de CPU, memoria, swap y red soportan ventanas emergentes. Para habilitarlas, simplemente marca las casillas correspondientes." +msgstr "" +"Las etiquetas para CPU, reloj de CPU, memoria, swap y red soportan ventanas " +"emergentes. Para habilitarlas, simplemente marca las casillas " +"correspondientes." msgid "Number of values for tooltips" msgstr "Número de valores para las ventanas emergentes" @@ -328,9 +332,11 @@ msgid "Battery inactive color" msgstr "Color de la batería inactiva" msgid "" -"Detailed information may be found on project homepage" -msgstr "Puedes encontrar información detallada en el sitio del proyecto" +"Detailed information may be found on project homepage" +msgstr "" +"Puedes encontrar información detallada en el sitio del proyecto" msgid "Bgcolor" msgstr "Color de fondo" @@ -371,6 +377,9 @@ msgstr "Mostrar valor" msgid "Edit bars" msgstr "Editar barras" +msgid "Formatters" +msgstr "" + msgid "Preview" msgstr "Vista previa" @@ -440,6 +449,14 @@ msgstr "Carga alta de GPU" msgid "Network device has been changed to %1" msgstr "El dispositivo de red ha sido cambiado a %1" +#, fuzzy +msgid "Select type" +msgstr "Elegir etiqueta" + +#, fuzzy +msgid "Type:" +msgstr "Tipo" + msgid "MB/s" msgstr "MB/s" @@ -497,15 +514,52 @@ msgstr "Nombre" msgid "Comment" msgstr "Comentario" +msgid "Type" +msgstr "Tipo" + +#, fuzzy +msgid "Format" +msgstr "normal" + +msgid "Precision" +msgstr "" + +msgid "Width" +msgstr "Ancho" + +msgid "Fill char" +msgstr "" + +msgid "Multiplier" +msgstr "" + +#, fuzzy +msgid "Summand" +msgstr "Orden" + +#, fuzzy +msgid "Append code" +msgstr "Apariencia" + +msgid "Has return" +msgstr "" + +msgid "Code" +msgstr "" + msgid "Tag" msgstr "Etiqueta" msgid "" "

Use YAHOO! finance ticker to get quotes for the " "instrument. Refer to http://finance.yahoo.com/

" -msgstr "

Usa el tablero electrónico de YAHOO! para obtener la cotización del medio. Dirígete a http://finance.yahoo.com/

" +"text-decoration: underline; color:#0057ae;\">http://finance.yahoo.com/

" +msgstr "" +"

Usa el tablero electrónico de YAHOO! para obtener la " +"cotización del medio. Dirígete a http://finance.yahoo." +"com/

" msgid "Ticker" msgstr "Tablero" @@ -570,9 +624,6 @@ msgstr "Activar tipo de relleno" msgid "Inctive filling type" msgstr "Inhabilitar tipo de relleno" -msgid "Type" -msgstr "Tipo" - msgid "Points count" msgstr "Conteo de puntos" @@ -582,9 +633,6 @@ msgstr "Dirección" msgid "Height" msgstr "Alto" -msgid "Width" -msgstr "Ancho" - msgid "color" msgstr "color" diff --git a/sources/translations/fr.po b/sources/translations/fr.po index 4652220..8e53115 100644 --- a/sources/translations/fr.po +++ b/sources/translations/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" "PO-Revision-Date: 2015-07-31 22:16+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: French \n" @@ -390,6 +390,9 @@ msgstr "Afficher la valeur" msgid "Edit bars" msgstr "Modifier les barres" +msgid "Formatters" +msgstr "" + msgid "Preview" msgstr "" @@ -459,6 +462,13 @@ msgstr "Haute charge GPU" msgid "Network device has been changed to %1" msgstr "L'interface réseau à été changée en %1" +#, fuzzy +msgid "Select type" +msgstr "Sélectionner l'étiquette" + +msgid "Type:" +msgstr "" + msgid "MB/s" msgstr "" @@ -522,6 +532,39 @@ msgstr "Nom: %1" msgid "Comment" msgstr "Commentaire: %1" +msgid "Type" +msgstr "" + +#, fuzzy +msgid "Format" +msgstr "Entrées" + +msgid "Precision" +msgstr "" + +msgid "Width" +msgstr "" + +msgid "Fill char" +msgstr "" + +msgid "Multiplier" +msgstr "" + +#, fuzzy +msgid "Summand" +msgstr "Commande personnalisée" + +#, fuzzy +msgid "Append code" +msgstr "Apparence" + +msgid "Has return" +msgstr "" + +msgid "Code" +msgstr "" + msgid "Tag" msgstr "Étiquette" @@ -607,9 +650,6 @@ msgstr "Batterie" msgid "Inctive filling type" msgstr "Bureau inactif" -msgid "Type" -msgstr "" - msgid "Points count" msgstr "" @@ -620,9 +660,6 @@ msgstr "" msgid "Height" msgstr "léger" -msgid "Width" -msgstr "" - #, fuzzy msgid "color" msgstr "Couleur processeur" @@ -834,9 +871,6 @@ msgstr "esalexeev@gmail.com mermouy@gmail.com" #~ msgid "Add stretch to right/bottom of the layout" #~ msgstr "Étirer le positionnement vers bas/droite" -#~ msgid "Form" -#~ msgstr "Entrées" - #~ msgid "Network directory" #~ msgstr "Voisinage réseau" diff --git a/sources/translations/nl_NL.po b/sources/translations/nl_NL.po index 60e8781..eef4dba 100644 --- a/sources/translations/nl_NL.po +++ b/sources/translations/nl_NL.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Awesome widgets\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" "PO-Revision-Date: 2015-08-20 22:52+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Dutch \n" @@ -392,6 +392,9 @@ msgstr "Waarde weergeven" msgid "Edit bars" msgstr "Balken bewerken" +msgid "Formatters" +msgstr "" + msgid "Preview" msgstr "" @@ -465,6 +468,14 @@ msgstr "Hoog CPU-verbruik" msgid "Network device has been changed to %1" msgstr "Het netwerkapparaat is gewijzigd naar %1" +#, fuzzy +msgid "Select type" +msgstr "Sleutelwoord selecteren" + +#, fuzzy +msgid "Type:" +msgstr "Type" + msgid "MB/s" msgstr "" @@ -524,6 +535,39 @@ msgstr "Naam" msgid "Comment" msgstr "Commentaar" +msgid "Type" +msgstr "Type" + +#, fuzzy +msgid "Format" +msgstr "normaal" + +msgid "Precision" +msgstr "" + +msgid "Width" +msgstr "Breedte" + +msgid "Fill char" +msgstr "" + +msgid "Multiplier" +msgstr "" + +#, fuzzy +msgid "Summand" +msgstr "Commentaar" + +#, fuzzy +msgid "Append code" +msgstr "Uiterlijk" + +msgid "Has return" +msgstr "" + +msgid "Code" +msgstr "" + msgid "Tag" msgstr "Sleutelwoord" @@ -606,9 +650,6 @@ msgstr "Actieve kleur" msgid "Inctive filling type" msgstr "Inactieve kleur" -msgid "Type" -msgstr "Type" - msgid "Points count" msgstr "" @@ -618,9 +659,6 @@ msgstr "Richting" msgid "Height" msgstr "Hoogte" -msgid "Width" -msgstr "Breedte" - #, fuzzy msgid "color" msgstr "CPU-kleur" diff --git a/sources/translations/pl.po b/sources/translations/pl.po index 8562705..ad911ee 100644 --- a/sources/translations/pl.po +++ b/sources/translations/pl.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -375,6 +375,9 @@ msgstr "Pokaż wartość" msgid "Edit bars" msgstr "Edytuj paski postępu" +msgid "Formatters" +msgstr "" + msgid "Preview" msgstr "Przegląd" @@ -444,6 +447,14 @@ msgstr "Wysokie obciążenie procesora graficznego" msgid "Network device has been changed to %1" msgstr "Urządznie sieciowe zamienione na %1" +#, fuzzy +msgid "Select type" +msgstr "Wybierz znacznik" + +#, fuzzy +msgid "Type:" +msgstr "Typ" + msgid "MB/s" msgstr "MB/s" @@ -501,6 +512,39 @@ msgstr "Nazwa" msgid "Comment" msgstr "Komentarz" +msgid "Type" +msgstr "Typ" + +#, fuzzy +msgid "Format" +msgstr "normalna" + +msgid "Precision" +msgstr "" + +msgid "Width" +msgstr "Szerokość" + +msgid "Fill char" +msgstr "" + +msgid "Multiplier" +msgstr "" + +#, fuzzy +msgid "Summand" +msgstr "Polecenie" + +#, fuzzy +msgid "Append code" +msgstr "Wygląd" + +msgid "Has return" +msgstr "" + +msgid "Code" +msgstr "" + msgid "Tag" msgstr "Znacznik" @@ -582,9 +626,6 @@ msgstr "Aktywny" msgid "Inctive filling type" msgstr "Nie aktywny pulpit" -msgid "Type" -msgstr "Typ" - msgid "Points count" msgstr "" @@ -594,9 +635,6 @@ msgstr "Kierunek" msgid "Height" msgstr "Wysokość" -msgid "Width" -msgstr "Szerokość" - #, fuzzy msgid "color" msgstr "Kolor procesora" diff --git a/sources/translations/pt_BR.po b/sources/translations/pt_BR.po index 61fb011..b84f23e 100644 --- a/sources/translations/pt_BR.po +++ b/sources/translations/pt_BR.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" "PO-Revision-Date: 2015-07-31 22:21+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -391,6 +391,9 @@ msgstr "Mostrar valor" msgid "Edit bars" msgstr "Editar barras" +msgid "Formatters" +msgstr "" + msgid "Preview" msgstr "" @@ -460,6 +463,14 @@ msgstr "Alta carga da GPU" msgid "Network device has been changed to %1" msgstr "O dispositivo de rede mudou para %1" +#, fuzzy +msgid "Select type" +msgstr "Selecionar tag" + +#, fuzzy +msgid "Type:" +msgstr "Tipo" + msgid "MB/s" msgstr "" @@ -518,6 +529,39 @@ msgstr "NOme" msgid "Comment" msgstr "Comentário" +msgid "Type" +msgstr "Tipo" + +#, fuzzy +msgid "Format" +msgstr "Forma" + +msgid "Precision" +msgstr "" + +msgid "Width" +msgstr "Largura" + +msgid "Fill char" +msgstr "" + +msgid "Multiplier" +msgstr "" + +#, fuzzy +msgid "Summand" +msgstr "Comentário" + +#, fuzzy +msgid "Append code" +msgstr "Aparência" + +msgid "Has return" +msgstr "" + +msgid "Code" +msgstr "" + msgid "Tag" msgstr "Tag" @@ -597,9 +641,6 @@ msgstr "Cor ativa" msgid "Inctive filling type" msgstr "Desktop inativo" -msgid "Type" -msgstr "Tipo" - msgid "Points count" msgstr "" @@ -609,9 +650,6 @@ msgstr "Direção" msgid "Height" msgstr "Altura" -msgid "Width" -msgstr "Largura" - #, fuzzy msgid "color" msgstr "Cor da CPU" @@ -822,9 +860,6 @@ msgstr "under@insicuri.net" #~ msgid "Add stretch to right/bottom of the layout" #~ msgstr "Adicionar esticamento à direita/inferior do layout" -#~ msgid "Form" -#~ msgstr "Forma" - #~ msgid "Network directory" #~ msgstr "Diretório de rede" diff --git a/sources/translations/ru.po b/sources/translations/ru.po index d762281..7b72394 100644 --- a/sources/translations/ru.po +++ b/sources/translations/ru.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" -"PO-Revision-Date: 2016-04-29 12:22+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"PO-Revision-Date: 2016-05-16 14:15+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" "Language: ru\n" @@ -374,6 +374,9 @@ msgstr "Показать значение" msgid "Edit bars" msgstr "Редактировать бары" +msgid "Formatters" +msgstr "Форматеры" + msgid "Preview" msgstr "Предварительный просмотр" @@ -443,6 +446,12 @@ msgstr "Высокая загрузка GPU" msgid "Network device has been changed to %1" msgstr "Сетевое устройство было изменено на %1" +msgid "Select type" +msgstr "Выберете тип" + +msgid "Type:" +msgstr "Тип:" + msgid "MB/s" msgstr "МБ/с" @@ -500,6 +509,36 @@ msgstr "Имя" msgid "Comment" msgstr "Комментарий" +msgid "Type" +msgstr "Тип" + +msgid "Format" +msgstr "Формат" + +msgid "Precision" +msgstr "Точность" + +msgid "Width" +msgstr "Ширина" + +msgid "Fill char" +msgstr "Заполнение" + +msgid "Multiplier" +msgstr "Множитель" + +msgid "Summand" +msgstr "Слагаемое" + +msgid "Append code" +msgstr "Дополнить код" + +msgid "Has return" +msgstr "Имеет return" + +msgid "Code" +msgstr "Код" + msgid "Tag" msgstr "Тег" @@ -577,9 +616,6 @@ msgstr "Тип активного наполнения" msgid "Inctive filling type" msgstr "Тип неактивного наполнения" -msgid "Type" -msgstr "Тип" - msgid "Points count" msgstr "Количество точек" @@ -589,9 +625,6 @@ msgstr "Направление" msgid "Height" msgstr "Высота" -msgid "Width" -msgstr "Ширина" - msgid "color" msgstr "цвет" @@ -657,9 +690,6 @@ msgstr "esalexeev@gmail.com" #~ msgid "Free space on %1 less than 10%" #~ msgstr "Свободное место на диске %1 меньше 10%" -#~ msgid "Has output" -#~ msgstr "Имеет сообщения" - #~ msgid "Top Edge" #~ msgstr "Верхняя грань" @@ -828,9 +858,6 @@ msgstr "esalexeev@gmail.com" #~ msgid "Widget configuration" #~ msgstr "Настройка виджета" -#~ msgid "Form" -#~ msgstr "Form" - #~ msgid "Network directory" #~ msgstr "Путь к интерфейсам" diff --git a/sources/translations/uk.po b/sources/translations/uk.po index ce87bfe..5f53381 100644 --- a/sources/translations/uk.po +++ b/sources/translations/uk.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" "PO-Revision-Date: 2016-05-05 17:18+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Ukrainian \n" @@ -375,6 +375,9 @@ msgstr "Показати значення" msgid "Edit bars" msgstr "Редагувати бари" +msgid "Formatters" +msgstr "" + msgid "Preview" msgstr "Попередній перегляд" @@ -444,6 +447,14 @@ msgstr "Високе завантаження GPU" msgid "Network device has been changed to %1" msgstr "Мережевий пристрій було змінено на %1" +#, fuzzy +msgid "Select type" +msgstr "Оберіть тег" + +#, fuzzy +msgid "Type:" +msgstr "Тип" + msgid "MB/s" msgstr "МБ/с" @@ -501,6 +512,39 @@ msgstr "Ім’я" msgid "Comment" msgstr "Коментар" +msgid "Type" +msgstr "Тип" + +#, fuzzy +msgid "Format" +msgstr "Form" + +msgid "Precision" +msgstr "" + +msgid "Width" +msgstr "Ширина" + +msgid "Fill char" +msgstr "" + +msgid "Multiplier" +msgstr "" + +#, fuzzy +msgid "Summand" +msgstr "Команда" + +#, fuzzy +msgid "Append code" +msgstr "Зовнішній вигляд" + +msgid "Has return" +msgstr "" + +msgid "Code" +msgstr "" + msgid "Tag" msgstr "Тег" @@ -578,9 +622,6 @@ msgstr "Тип активного заповнення" msgid "Inctive filling type" msgstr "Тип неактивного заповнення" -msgid "Type" -msgstr "Тип" - msgid "Points count" msgstr "Кількість точок" @@ -590,9 +631,6 @@ msgstr "Напрямок" msgid "Height" msgstr "Висота" -msgid "Width" -msgstr "Ширина" - msgid "color" msgstr "колір" @@ -814,9 +852,6 @@ msgstr "sarumyan@i.ua" #~ msgid "Add stretch to right/bottom of the layout" #~ msgstr "Додати порожнє місце праворуч/внизу віджету" -#~ msgid "Form" -#~ msgstr "Form" - #~ msgid "Network directory" #~ msgstr "Шлях до інтерфейсів" diff --git a/sources/translations/zh.po b/sources/translations/zh.po index 5d0e961..08a45e8 100644 --- a/sources/translations/zh.po +++ b/sources/translations/zh.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-04-29 12:21+0300\n" +"POT-Creation-Date: 2016-05-16 14:13+0300\n" "PO-Revision-Date: 2015-07-31 22:24+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -376,6 +376,9 @@ msgstr "显示值" msgid "Edit bars" msgstr "编辑工具栏" +msgid "Formatters" +msgstr "" + msgid "Preview" msgstr "预览" @@ -445,6 +448,14 @@ msgstr "高 GPU 使用" msgid "Network device has been changed to %1" msgstr "网络设备变更为 %1" +#, fuzzy +msgid "Select type" +msgstr "选择标签" + +#, fuzzy +msgid "Type:" +msgstr "类型" + msgid "MB/s" msgstr "MB/s" @@ -502,6 +513,39 @@ msgstr "命名" msgid "Comment" msgstr "评论" +msgid "Type" +msgstr "类型" + +#, fuzzy +msgid "Format" +msgstr "正常" + +msgid "Precision" +msgstr "" + +msgid "Width" +msgstr "宽度" + +msgid "Fill char" +msgstr "" + +msgid "Multiplier" +msgstr "" + +#, fuzzy +msgid "Summand" +msgstr "命令" + +#, fuzzy +msgid "Append code" +msgstr "外观" + +msgid "Has return" +msgstr "" + +msgid "Code" +msgstr "" + msgid "Tag" msgstr "标签" @@ -584,9 +628,6 @@ msgstr "使用" msgid "Inctive filling type" msgstr "未激活桌面" -msgid "Type" -msgstr "类型" - msgid "Points count" msgstr "" @@ -596,9 +637,6 @@ msgstr "方向" msgid "Height" msgstr "高度" -msgid "Width" -msgstr "宽度" - #, fuzzy msgid "color" msgstr "CPU 颜色" From f717c984b77481cdaac834238d879dca33e80ed7 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 18 May 2016 12:46:50 +0300 Subject: [PATCH 09/32] add formatters configuration to ui --- .../plugin/awformatterconfig.cpp | 46 ++++++++++++++----- .../awesome-widget/plugin/awformatterconfig.h | 3 ++ .../plugin/awformatterhelper.cpp | 38 +++++++++++++++ .../awesome-widget/plugin/awformatterhelper.h | 4 ++ sources/translations/awesome-widgets.pot | 5 +- sources/translations/en.po | 12 ++--- sources/translations/es.po | 6 ++- sources/translations/fr.po | 10 ++-- sources/translations/nl_NL.po | 8 ++-- sources/translations/pl.po | 6 ++- sources/translations/pt_BR.po | 8 ++-- sources/translations/ru.po | 12 ++--- sources/translations/uk.po | 10 ++-- sources/translations/zh.po | 10 ++-- 14 files changed, 128 insertions(+), 50 deletions(-) diff --git a/sources/awesome-widget/plugin/awformatterconfig.cpp b/sources/awesome-widget/plugin/awformatterconfig.cpp index d4dd856..f2f1471 100644 --- a/sources/awesome-widget/plugin/awformatterconfig.cpp +++ b/sources/awesome-widget/plugin/awformatterconfig.cpp @@ -20,6 +20,8 @@ #include +#include + #include "awabstractselector.h" #include "awdebug.h" #include "awformatterhelper.h" @@ -33,10 +35,13 @@ AWFormatterConfig::AWFormatterConfig(QWidget *parent, const QStringList keys) qCDebug(LOG_AW) << __PRETTY_FUNCTION__; ui->setupUi(this); + editButton = ui->buttonBox->addButton(i18n("Edit"), + QDialogButtonBox::ActionRole); init(); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(editButton, SIGNAL(clicked(bool)), this, SLOT(editFormatters())); } @@ -53,21 +58,20 @@ AWFormatterConfig::~AWFormatterConfig() void AWFormatterConfig::showDialog() { - clearSelectors(); - QHash appliedFormatters = m_helper->getFormatters(); - auto keys = initKeys(); - - for (auto key : appliedFormatters.keys()) - addSelector(keys.first, keys.second, - QPair(key, appliedFormatters[key])); - // empty one - addSelector(keys.first, keys.second, QPair()); - + // update dialog + updateDialog(); // exec dialog return execDialog(); } +void AWFormatterConfig::editFormatters() +{ + m_helper->editItems(); + updateDialog(); +} + + void AWFormatterConfig::updateUi() { QPair current @@ -108,9 +112,12 @@ void AWFormatterConfig::addSelector(const QStringList &keys, void AWFormatterConfig::clearSelectors() { - for (auto selector : m_selectors) + for (auto selector : m_selectors) { disconnect(selector, SIGNAL(selectionChanged()), this, SLOT(updateUi())); + ui->verticalLayout->removeWidget(selector); + selector->deleteLater(); + } m_selectors.clear(); } @@ -121,7 +128,7 @@ void AWFormatterConfig::execDialog() QHash data; for (auto selector : m_selectors) { QPair select = selector->current(); - if ((select.first.isEmpty()) || (select.second.isEmpty())) + if (select.first.isEmpty()) continue; data[select.first] = select.second; } @@ -133,6 +140,7 @@ void AWFormatterConfig::execDialog() case 1: default: m_helper->writeFormatters(data); + m_helper->writeFormatters(data.keys()); break; } } @@ -157,3 +165,17 @@ QPair AWFormatterConfig::initKeys() const return QPair(keys, knownFormatters); } + + +void AWFormatterConfig::updateDialog() +{ + clearSelectors(); + QHash appliedFormatters = m_helper->getFormatters(); + auto keys = initKeys(); + + for (auto key : appliedFormatters.keys()) + addSelector(keys.first, keys.second, + QPair(key, appliedFormatters[key])); + // empty one + addSelector(keys.first, keys.second, QPair()); +} diff --git a/sources/awesome-widget/plugin/awformatterconfig.h b/sources/awesome-widget/plugin/awformatterconfig.h index b04cbaa..65a6382 100644 --- a/sources/awesome-widget/plugin/awformatterconfig.h +++ b/sources/awesome-widget/plugin/awformatterconfig.h @@ -40,9 +40,11 @@ public: Q_INVOKABLE void showDialog(); private slots: + void editFormatters(); void updateUi(); private: + QPushButton *editButton = nullptr; Ui::AWFormatterConfig *ui = nullptr; AWFormatterHelper *m_helper = nullptr; QList m_selectors; @@ -55,6 +57,7 @@ private: void execDialog(); void init(); QPair initKeys() const; + void updateDialog(); }; diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index a0349b8..37f3426 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -90,6 +90,31 @@ QStringList AWFormatterHelper::knownFormatters() const } +bool AWFormatterHelper::writeFormatters(const QStringList keys) const +{ + qCDebug(LOG_AW) << "Remove formatters" << keys; + + QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)); + QSettings settings(fileName, QSettings::IniFormat); + qCInfo(LOG_AW) << "Configuration file" << fileName; + + settings.beginGroup(QString("Formatters")); + QStringList foundKeys = settings.childKeys(); + for (auto key : foundKeys) { + if (keys.contains(key)) + continue; + settings.remove(key); + } + settings.endGroup(); + + settings.sync(); + + return (settings.status() == QSettings::NoError); +} + + bool AWFormatterHelper::writeFormatters( const QHash configuration) const { @@ -112,6 +137,14 @@ bool AWFormatterHelper::writeFormatters( } +void AWFormatterHelper::editItems() +{ + repaintList(); + int ret = exec(); + qCInfo(LOG_AW) << "Dialog returns" << ret; +} + + AWFormatterHelper::FormatterClass AWFormatterHelper::defineFormatterClass(const QString stringType) const { @@ -193,9 +226,14 @@ void AWFormatterHelper::initKeys() QString name = settings.value(key).toString(); qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key << "in" << settings.fileName(); + if (name.isEmpty()) { + qCInfo(LOG_AW) << "Skip empty formatter for" << key; + continue; + } if (!m_formattersClasses.contains(name)) { qCWarning(LOG_AW) << "Invalid formatter" << name << "found in" << key; + continue; } m_formatters[key] = m_formattersClasses[name]; } diff --git a/sources/awesome-widget/plugin/awformatterhelper.h b/sources/awesome-widget/plugin/awformatterhelper.h index 657871e..5b9f349 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.h +++ b/sources/awesome-widget/plugin/awformatterhelper.h @@ -38,8 +38,12 @@ public: QHash getFormatters() const; QList items() const; QStringList knownFormatters() const; + bool writeFormatters(const QStringList keys) const; bool writeFormatters(const QHash configuration) const; +public slots: + void editItems(); + private: // methods AWFormatterHelper::FormatterClass diff --git a/sources/translations/awesome-widgets.pot b/sources/translations/awesome-widgets.pot index d2da3a6..ca0a5dc 100644 --- a/sources/translations/awesome-widgets.pot +++ b/sources/translations/awesome-widgets.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -441,6 +441,9 @@ msgstr "" msgid "Network device has been changed to %1" msgstr "" +msgid "Edit" +msgstr "" + msgid "Select type" msgstr "" diff --git a/sources/translations/en.po b/sources/translations/en.po index 4d8602a..82b3a59 100644 --- a/sources/translations/en.po +++ b/sources/translations/en.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2016-05-16 14:14+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: English \n" @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<" -"=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Generator: Lokalize 2.0\n" msgid "Widget" @@ -446,6 +446,9 @@ msgstr "High GPU load" msgid "Network device has been changed to %1" msgstr "Network device has been changed to %1" +msgid "Edit" +msgstr "Edit" + msgid "Select type" msgstr "Select type" @@ -723,9 +726,6 @@ msgstr "esalexeev@gmail.com" #~ msgid "Check for updates" #~ msgstr "Check for updates" -#~ msgid "Edit" -#~ msgstr "Edit" - #~ msgid "Enable popup on mouse click" #~ msgstr "Enable popup on mouse click" diff --git a/sources/translations/es.po b/sources/translations/es.po index 3a43ac6..af5d59b 100644 --- a/sources/translations/es.po +++ b/sources/translations/es.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Awesome widgets\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2016-05-03 06:47+0000\n" "Last-Translator: Ernesto Avilés Vázquez \n" "Language-Team: Spanish (http://www.transifex.com/arcanis/awesome-widgets/" @@ -449,6 +449,10 @@ msgstr "Carga alta de GPU" msgid "Network device has been changed to %1" msgstr "El dispositivo de red ha sido cambiado a %1" +#, fuzzy +msgid "Edit" +msgstr "Editar barras" + #, fuzzy msgid "Select type" msgstr "Elegir etiqueta" diff --git a/sources/translations/fr.po b/sources/translations/fr.po index 8e53115..7635fce 100644 --- a/sources/translations/fr.po +++ b/sources/translations/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2015-07-31 22:16+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: French \n" @@ -462,6 +462,10 @@ msgstr "Haute charge GPU" msgid "Network device has been changed to %1" msgstr "L'interface réseau à été changée en %1" +#, fuzzy +msgid "Edit" +msgstr "Modifiable" + #, fuzzy msgid "Select type" msgstr "Sélectionner l'étiquette" @@ -746,10 +750,6 @@ msgstr "esalexeev@gmail.com mermouy@gmail.com" #~ msgid "Update text" #~ msgstr "Mettre à jour le texte" -#, fuzzy -#~ msgid "Edit" -#~ msgstr "Modifiable" - #~ msgid "Enable popup on mouse click" #~ msgstr "Popup lors d'un click souris" diff --git a/sources/translations/nl_NL.po b/sources/translations/nl_NL.po index eef4dba..ca5f9ec 100644 --- a/sources/translations/nl_NL.po +++ b/sources/translations/nl_NL.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Awesome widgets\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2015-08-20 22:52+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Dutch \n" @@ -468,6 +468,9 @@ msgstr "Hoog CPU-verbruik" msgid "Network device has been changed to %1" msgstr "Het netwerkapparaat is gewijzigd naar %1" +msgid "Edit" +msgstr "Bewerken" + #, fuzzy msgid "Select type" msgstr "Sleutelwoord selecteren" @@ -746,9 +749,6 @@ msgstr "vistausss@outlook.com" #~ msgid "Exec: %1" #~ msgstr "Uitvoeren: %1" -#~ msgid "Edit" -#~ msgstr "Bewerken" - #~ msgid "Select color" #~ msgstr "Kleur selecteren" diff --git a/sources/translations/pl.po b/sources/translations/pl.po index ad911ee..8e17d6c 100644 --- a/sources/translations/pl.po +++ b/sources/translations/pl.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -447,6 +447,10 @@ msgstr "Wysokie obciążenie procesora graficznego" msgid "Network device has been changed to %1" msgstr "Urządznie sieciowe zamienione na %1" +#, fuzzy +msgid "Edit" +msgstr "Edytuj paski postępu" + #, fuzzy msgid "Select type" msgstr "Wybierz znacznik" diff --git a/sources/translations/pt_BR.po b/sources/translations/pt_BR.po index b84f23e..e22880f 100644 --- a/sources/translations/pt_BR.po +++ b/sources/translations/pt_BR.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2015-07-31 22:21+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -463,6 +463,9 @@ msgstr "Alta carga da GPU" msgid "Network device has been changed to %1" msgstr "O dispositivo de rede mudou para %1" +msgid "Edit" +msgstr "Editar" + #, fuzzy msgid "Select type" msgstr "Selecionar tag" @@ -737,9 +740,6 @@ msgstr "under@insicuri.net" #~ msgid "Check for updates" #~ msgstr "Checar por atualizações" -#~ msgid "Edit" -#~ msgstr "Editar" - #~ msgid "Enable popup on mouse click" #~ msgstr "Ativar popup no clique do mouse" diff --git a/sources/translations/ru.po b/sources/translations/ru.po index 7b72394..bf6c14c 100644 --- a/sources/translations/ru.po +++ b/sources/translations/ru.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2016-05-16 14:15+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<" -"=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Generator: Lokalize 2.0\n" msgid "Widget" @@ -446,6 +446,9 @@ msgstr "Высокая загрузка GPU" msgid "Network device has been changed to %1" msgstr "Сетевое устройство было изменено на %1" +msgid "Edit" +msgstr "Править" + msgid "Select type" msgstr "Выберете тип" @@ -723,9 +726,6 @@ msgstr "esalexeev@gmail.com" #~ msgid "Check for updates" #~ msgstr "Проверить обновления" -#~ msgid "Edit" -#~ msgstr "Править" - #~ msgid "Enable popup on mouse click" #~ msgstr "Включить сообщения по клику мыши" diff --git a/sources/translations/uk.po b/sources/translations/uk.po index 5f53381..be53776 100644 --- a/sources/translations/uk.po +++ b/sources/translations/uk.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2016-05-05 17:18+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Ukrainian \n" @@ -447,6 +447,10 @@ msgstr "Високе завантаження GPU" msgid "Network device has been changed to %1" msgstr "Мережевий пристрій було змінено на %1" +#, fuzzy +msgid "Edit" +msgstr "Редагувати" + #, fuzzy msgid "Select type" msgstr "Оберіть тег" @@ -726,10 +730,6 @@ msgstr "sarumyan@i.ua" #~ msgid "Check for updates" #~ msgstr "Шукати оновлення" -#, fuzzy -#~ msgid "Edit" -#~ msgstr "Редагувати" - #~ msgid "Enable popup on mouse click" #~ msgstr "Включити спливаючі підказки при натисканні клавіші миші" diff --git a/sources/translations/zh.po b/sources/translations/zh.po index 08a45e8..894fec4 100644 --- a/sources/translations/zh.po +++ b/sources/translations/zh.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2015-07-31 22:24+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -448,6 +448,10 @@ msgstr "高 GPU 使用" msgid "Network device has been changed to %1" msgstr "网络设备变更为 %1" +#, fuzzy +msgid "Edit" +msgstr "可编辑的" + #, fuzzy msgid "Select type" msgstr "选择标签" @@ -722,10 +726,6 @@ msgstr "用户邮箱" #~ msgid "Update text" #~ msgstr "刷新文本" -#, fuzzy -#~ msgid "Edit" -#~ msgstr "可编辑的" - #~ msgid "Enable popup on mouse click" #~ msgstr "鼠标点击时弹出对话框" From e71da9bdfb8c807823f711a6a9740b2adb82a257 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 19 May 2016 16:28:19 +0300 Subject: [PATCH 10/32] use overloaded constructors to create tests --- sources/awesomewidgets/abstractextitem.h | 2 +- sources/awesomewidgets/awabstractformatter.h | 2 +- .../awesomewidgets/awdatetimeformatter.cpp | 16 ++----------- sources/awesomewidgets/awdatetimeformatter.h | 3 +-- sources/awesomewidgets/awfloatformatter.cpp | 24 ++----------------- sources/awesomewidgets/awfloatformatter.h | 6 +---- sources/awesomewidgets/awnoformatter.cpp | 14 ++--------- sources/awesomewidgets/awnoformatter.h | 3 +-- sources/awesomewidgets/awscriptformatter.cpp | 20 ++-------------- sources/awesomewidgets/awscriptformatter.h | 4 +--- sources/awesomewidgets/extquotes.cpp | 3 ++- sources/awesomewidgets/extquotes.h | 2 +- sources/awesomewidgets/extscript.cpp | 3 ++- sources/awesomewidgets/extscript.h | 2 +- sources/awesomewidgets/extupgrade.cpp | 3 ++- sources/awesomewidgets/extupgrade.h | 2 +- sources/awesomewidgets/extweather.cpp | 3 ++- sources/awesomewidgets/extweather.h | 2 +- sources/awesomewidgets/graphicalitem.cpp | 3 ++- sources/awesomewidgets/graphicalitem.h | 2 +- 20 files changed, 29 insertions(+), 90 deletions(-) diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index 4a19168..7c27fae 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -35,7 +35,7 @@ class AbstractExtItem : public QDialog Q_PROPERTY(QString uniq READ uniq) public: - explicit AbstractExtItem(QWidget *parent = nullptr, + explicit AbstractExtItem(QWidget *parent, const QString filePath = QString()); virtual ~AbstractExtItem(); virtual void bumpApi(const int _newVer); diff --git a/sources/awesomewidgets/awabstractformatter.h b/sources/awesomewidgets/awabstractformatter.h index b91bef6..3fcd8e4 100644 --- a/sources/awesomewidgets/awabstractformatter.h +++ b/sources/awesomewidgets/awabstractformatter.h @@ -27,7 +27,7 @@ class AWAbstractFormatter : public AbstractExtItem Q_PROPERTY(QString type READ type WRITE setType) public: - explicit AWAbstractFormatter(QWidget *parent = nullptr, + explicit AWAbstractFormatter(QWidget *parent, const QString filePath = QString()); virtual ~AWAbstractFormatter(); virtual QString convert(const QVariant &_value) const = 0; diff --git a/sources/awesomewidgets/awdatetimeformatter.cpp b/sources/awesomewidgets/awdatetimeformatter.cpp index fbc220c..0a99eb2 100644 --- a/sources/awesomewidgets/awdatetimeformatter.cpp +++ b/sources/awesomewidgets/awdatetimeformatter.cpp @@ -35,20 +35,8 @@ AWDateTimeFormatter::AWDateTimeFormatter(QWidget *parent, { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - readConfiguration(); - ui->setupUi(this); - translate(); -} - - -AWDateTimeFormatter::AWDateTimeFormatter(const QString format, QWidget *parent) - : AWAbstractFormatter(parent) - , ui(new Ui::AWDateTimeFormatter) -{ - qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - - setFormat(format); - + if (!filePath.isEmpty()) + readConfiguration(); ui->setupUi(this); translate(); } diff --git a/sources/awesomewidgets/awdatetimeformatter.h b/sources/awesomewidgets/awdatetimeformatter.h index d908a73..0605fcf 100644 --- a/sources/awesomewidgets/awdatetimeformatter.h +++ b/sources/awesomewidgets/awdatetimeformatter.h @@ -32,8 +32,7 @@ class AWDateTimeFormatter : public AWAbstractFormatter Q_PROPERTY(QString format READ format WRITE setFormat) public: - explicit AWDateTimeFormatter(QWidget *parent, const QString filePath); - explicit AWDateTimeFormatter(const QString format, QWidget *parent); + explicit AWDateTimeFormatter(QWidget *parent, const QString filePath = QString()); virtual ~AWDateTimeFormatter(); QString convert(const QVariant &_value) const; AWDateTimeFormatter *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/awfloatformatter.cpp b/sources/awesomewidgets/awfloatformatter.cpp index af69075..088bd51 100644 --- a/sources/awesomewidgets/awfloatformatter.cpp +++ b/sources/awesomewidgets/awfloatformatter.cpp @@ -33,28 +33,8 @@ AWFloatFormatter::AWFloatFormatter(QWidget *parent, const QString filePath) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - readConfiguration(); - ui->setupUi(this); - translate(); -} - - -AWFloatFormatter::AWFloatFormatter(const int count, const QChar fillChar, - const char format, const double multiplier, - const int precision, const double summand, - QWidget *parent) - : AWAbstractFormatter(parent) - , ui(new Ui::AWFloatFormatter) -{ - qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - - setCount(count); - setFillChar(fillChar); - setFormat(format); - setMultiplier(multiplier); - setPrecision(precision); - setSummand(summand); - + if (!filePath.isEmpty()) + readConfiguration(); ui->setupUi(this); translate(); } diff --git a/sources/awesomewidgets/awfloatformatter.h b/sources/awesomewidgets/awfloatformatter.h index 1087214..310cae9 100644 --- a/sources/awesomewidgets/awfloatformatter.h +++ b/sources/awesomewidgets/awfloatformatter.h @@ -37,11 +37,7 @@ class AWFloatFormatter : public AWAbstractFormatter Q_PROPERTY(double summand READ summand WRITE setSummand) public: - explicit AWFloatFormatter(QWidget *parent, const QString filePath); - explicit AWFloatFormatter(const int count, const QChar fillChar, - const char format, const double multiplier, - const int precision, const double summand, - QWidget *parent); + explicit AWFloatFormatter(QWidget *parent, const QString filePath = QString()); virtual ~AWFloatFormatter(); QString convert(const QVariant &_value) const; AWFloatFormatter *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/awnoformatter.cpp b/sources/awesomewidgets/awnoformatter.cpp index dd801d4..1a6aa81 100644 --- a/sources/awesomewidgets/awnoformatter.cpp +++ b/sources/awesomewidgets/awnoformatter.cpp @@ -30,18 +30,8 @@ AWNoFormatter::AWNoFormatter(QWidget *parent, const QString filePath) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - readConfiguration(); - ui->setupUi(this); - translate(); -} - - -AWNoFormatter::AWNoFormatter(QWidget *parent) - : AWAbstractFormatter(parent) - , ui(new Ui::AWNoFormatter) -{ - qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - + if (!filePath.isEmpty()) + readConfiguration(); ui->setupUi(this); translate(); } diff --git a/sources/awesomewidgets/awnoformatter.h b/sources/awesomewidgets/awnoformatter.h index d8efab5..de79817 100644 --- a/sources/awesomewidgets/awnoformatter.h +++ b/sources/awesomewidgets/awnoformatter.h @@ -31,8 +31,7 @@ class AWNoFormatter : public AWAbstractFormatter Q_OBJECT public: - explicit AWNoFormatter(QWidget *parent, const QString filePath); - explicit AWNoFormatter(QWidget *parent); + explicit AWNoFormatter(QWidget *parent, const QString filePath = QString()); virtual ~AWNoFormatter(); QString convert(const QVariant &_value) const; AWNoFormatter *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/awscriptformatter.cpp b/sources/awesomewidgets/awscriptformatter.cpp index f01cbc6..89c404d 100644 --- a/sources/awesomewidgets/awscriptformatter.cpp +++ b/sources/awesomewidgets/awscriptformatter.cpp @@ -34,24 +34,8 @@ AWScriptFormatter::AWScriptFormatter(QWidget *parent, const QString filePath) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - readConfiguration(); - ui->setupUi(this); - translate(); -} - - -AWScriptFormatter::AWScriptFormatter(const bool appendCode, const QString code, - const bool hasReturn, QWidget *parent) - : AWAbstractFormatter(parent) - , ui(new Ui::AWScriptFormatter) -{ - qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - - setAppendCode(appendCode); - setCode(code); - setHasReturn(hasReturn); - initProgram(); - + if (!filePath.isEmpty()) + readConfiguration(); ui->setupUi(this); translate(); } diff --git a/sources/awesomewidgets/awscriptformatter.h b/sources/awesomewidgets/awscriptformatter.h index 3af8ade..f950990 100644 --- a/sources/awesomewidgets/awscriptformatter.h +++ b/sources/awesomewidgets/awscriptformatter.h @@ -35,9 +35,7 @@ class AWScriptFormatter : public AWAbstractFormatter Q_PROPERTY(QString program READ program) public: - explicit AWScriptFormatter(QWidget *parent, const QString filePath); - explicit AWScriptFormatter(const bool appendCode, const QString code, - const bool hasReturn, QWidget *parent); + explicit AWScriptFormatter(QWidget *parent, const QString filePath = QString()); virtual ~AWScriptFormatter(); QString convert(const QVariant &_value) const; AWScriptFormatter *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp index 785f0f4..8cab854 100644 --- a/sources/awesomewidgets/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -39,7 +39,8 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString filePath) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - readConfiguration(); + if (!filePath.isEmpty()) + readConfiguration(); ui->setupUi(this); translate(); diff --git a/sources/awesomewidgets/extquotes.h b/sources/awesomewidgets/extquotes.h index 38e0057..3001bad 100644 --- a/sources/awesomewidgets/extquotes.h +++ b/sources/awesomewidgets/extquotes.h @@ -38,7 +38,7 @@ class ExtQuotes : public AbstractExtItem Q_PROPERTY(QString ticker READ ticker WRITE setTicker) public: - explicit ExtQuotes(QWidget *parent = nullptr, + explicit ExtQuotes(QWidget *parent, const QString filePath = QString()); virtual ~ExtQuotes(); ExtQuotes *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 683e9d1..39a3045 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -36,7 +36,8 @@ ExtScript::ExtScript(QWidget *parent, const QString filePath) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - readConfiguration(); + if (!filePath.isEmpty()) + readConfiguration(); readJsonFilters(); ui->setupUi(this); translate(); diff --git a/sources/awesomewidgets/extscript.h b/sources/awesomewidgets/extscript.h index e4e8a45..283289b 100644 --- a/sources/awesomewidgets/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -39,7 +39,7 @@ class ExtScript : public AbstractExtItem public: enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap }; - explicit ExtScript(QWidget *parent = nullptr, + explicit ExtScript(QWidget *parent, const QString filePath = QString()); virtual ~ExtScript(); ExtScript *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index e996dbd..41bb731 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -34,7 +34,8 @@ ExtUpgrade::ExtUpgrade(QWidget *parent, const QString filePath) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - readConfiguration(); + if (!filePath.isEmpty()) + readConfiguration(); ui->setupUi(this); translate(); diff --git a/sources/awesomewidgets/extupgrade.h b/sources/awesomewidgets/extupgrade.h index ad981a9..9a5a63b 100644 --- a/sources/awesomewidgets/extupgrade.h +++ b/sources/awesomewidgets/extupgrade.h @@ -36,7 +36,7 @@ class ExtUpgrade : public AbstractExtItem Q_PROPERTY(int null READ null WRITE setNull) public: - explicit ExtUpgrade(QWidget *parent = nullptr, + explicit ExtUpgrade(QWidget *parent, const QString filePath = QString()); virtual ~ExtUpgrade(); ExtUpgrade *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 0f82ba5..6fda40b 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -40,7 +40,8 @@ ExtWeather::ExtWeather(QWidget *parent, const QString filePath) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - readConfiguration(); + if (!filePath.isEmpty()) + readConfiguration(); readJsonMap(); ui->setupUi(this); translate(); diff --git a/sources/awesomewidgets/extweather.h b/sources/awesomewidgets/extweather.h index 0f4d87d..825ae41 100644 --- a/sources/awesomewidgets/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -42,7 +42,7 @@ class ExtWeather : public AbstractExtItem Q_PROPERTY(int ts READ ts WRITE setTs) public: - explicit ExtWeather(QWidget *parent = nullptr, + explicit ExtWeather(QWidget *parent, const QString filePath = QString()); virtual ~ExtWeather(); ExtWeather *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 886e495..52354ef 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -38,7 +38,8 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString filePath) { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - readConfiguration(); + if (!filePath.isEmpty()) + readConfiguration(); ui->setupUi(this); translate(); diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index 89afaba..de512c9 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -52,7 +52,7 @@ public: enum class Direction { LeftToRight = 0, RightToLeft = 1 }; enum class Type { Horizontal, Vertical, Circle, Graph, Bars }; - explicit GraphicalItem(QWidget *parent = nullptr, + explicit GraphicalItem(QWidget *parent, const QString filePath = QString()); virtual ~GraphicalItem(); GraphicalItem *copy(const QString _fileName, const int _number); From 2dccc92933d09d823bbf046f5ddde6ba7905b753 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sat, 21 May 2016 14:36:24 +0300 Subject: [PATCH 11/32] fix error in extscript and extupgrade with invalid updates interval if X-AW-Interval=1 --- sources/awesomewidgets/extscript.cpp | 6 ++++-- sources/awesomewidgets/extupgrade.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 39a3045..d319459 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -271,9 +271,11 @@ QVariantHash ExtScript::run() cmdList.append(m_executable); qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' ')); process->start(cmdList.join(QChar(' '))); - } else if (times >= interval()) { - times = 0; } + + // update value + if (times >= interval()) + times = 0; times++; return value; diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index 41bb731..ed54fc5 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -149,9 +149,11 @@ QVariantHash ExtUpgrade::run() QString cmd = QString("sh -c \"%1\"").arg(m_executable); qCInfo(LOG_LIB) << "Run cmd" << cmd; process->start(cmd); - } else if (times >= interval()) { - times = 0; } + + // update value + if (times >= interval()) + times = 0; times++; return value; From ea7c15d8651b766d81b750ebd616dc49c2b0a562 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sun, 22 May 2016 15:14:56 +0300 Subject: [PATCH 12/32] initial commit with test modules --- sources/CMakeLists.txt | 4 ++ sources/libraries.cmake | 8 ++-- sources/test/CMakeLists.txt | 23 +++++++++++ sources/test/testextscript.cpp | 72 ++++++++++++++++++++++++++++++++++ sources/test/testextscript.h | 46 ++++++++++++++++++++++ 5 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 sources/test/CMakeLists.txt create mode 100644 sources/test/testextscript.cpp create mode 100644 sources/test/testextscript.h diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 0d23497..e628d3d 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -80,5 +80,9 @@ if (BUILD_PLASMOIDS) add_subdirectory(desktop-panel) add_subdirectory(translations) endif () +if (BUILD_TESTING) + enable_testing() + add_subdirectory(test) +endif () include(packages-recipe.cmake) diff --git a/sources/libraries.cmake b/sources/libraries.cmake index 339bb58..9a9a052 100644 --- a/sources/libraries.cmake +++ b/sources/libraries.cmake @@ -2,18 +2,18 @@ find_package(Gettext REQUIRED) # main qt libraries -find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets) +find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets) add_definitions( ${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS} - ${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} + ${Qt5Qml_DEFINITIONS} ${Qt5Test_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ) set(Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} - ${Qt5Qml_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} + ${Qt5Qml_INCLUDE_DIRS} ${Qt5Test_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ) set(Qt_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES} - ${Qt5Qml_LIBRARIES} ${Qt5Widgets_LIBRARIES} + ${Qt5Qml_LIBRARIES} ${Qt5Test_LIBRARIES} ${Qt5Widgets_LIBRARIES} ) # kf5 libraries diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt new file mode 100644 index 0000000..e70c070 --- /dev/null +++ b/sources/test/CMakeLists.txt @@ -0,0 +1,23 @@ +set(SUBPROJECT awesomewidgets-test) +message(STATUS "Subproject ${SUBPROJECT}") + +# find qt test package +include_directories( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/ + ${PROJECT_TRDPARTY_DIR} + ${Qt_INCLUDE} + ${Kf5_INCLUDE} + ${Qt5Test_INCLUDE_DIRS} +) + +# extscript +set (EXTSCRIPT_HEADERS testextscript.h) +set (EXTSCRIPT_SOURCES testextscript.cpp) +# qt5_wrap_cpp(EXTSCRIPT_MOC_SOURCES ${EXTSCRIPT_HEADERS}) +add_executable (${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES} ${EXTSCRIPT_MOC_SOURCES}) +target_link_libraries (${SUBPROJECT}-extscript ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +add_test (NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript + "-o" "../Testing/output-extscript.log") + diff --git a/sources/test/testextscript.cpp b/sources/test/testextscript.cpp new file mode 100644 index 0000000..c6fe839 --- /dev/null +++ b/sources/test/testextscript.cpp @@ -0,0 +1,72 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testextscript.h" + +#include + +#include "extscript.h" +#include "version.h" + + +void TestExtScript::initTestCase() +{ + extScript = new ExtScript(nullptr); + extScript->setInterval(1); + extScript->setExecutable(QString("hello world")); + extScript->setRedirect(ExtScript::Redirect::stderr2stdout); + extScript->setPrefix(QString("echo")); + + while (true) + qDebug() <run(); +} + + +void TestExtScript::cleanupTestCase() +{ + delete extScript; +} + + +void TestExtScript::test_values() +{ + QCOMPARE(extScript->interval(), 1); + QCOMPARE(extScript->executable(), QString("hello world")); + QCOMPARE(extScript->prefix(), QString("echo")); +} + + +void TestExtScript::test_firstRun() +{ + QVariantHash firstValue = extScript->run(); + qDebug() << firstValue; + QTest::qSleep(20000); + QCOMPARE(firstValue[extScript->tag(QString("custom"))].toString(), QString("")); + QTest::qSleep(20000); +} + + +void TestExtScript::test_secondRun() +{ + QVariantHash secondValue = extScript->run(); + qDebug() << secondValue; + QCOMPARE(secondValue[extScript->tag(QString("custom"))].toString(), QString("hello world")); +} + + +QTEST_MAIN(TestExtScript); diff --git a/sources/test/testextscript.h b/sources/test/testextscript.h new file mode 100644 index 0000000..5422d76 --- /dev/null +++ b/sources/test/testextscript.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTEXTSCRIPT_H +#define TESTEXTSCRIPT_H + +#include +#include + + +class ExtScript; + +class TestExtScript : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_firstRun(); + void test_secondRun(); + +private: + ExtScript *extScript = nullptr; +}; + + +#endif /* TESTEXTSCRIPT_H */ From 72f0d4587bdbd8ade94f7f0b4888f89fb7e0e2ed Mon Sep 17 00:00:00 2001 From: arcan1s Date: Mon, 23 May 2016 11:04:12 +0300 Subject: [PATCH 13/32] more correct test class for extscripts --- .../plugin/awformatterconfig.cpp | 4 +- .../plugin/awformatterhelper.cpp | 4 +- .../awesome-widget/plugin/awkeyoperations.cpp | 15 ++++--- sources/awesomewidgets/abstractextitem.h | 3 ++ sources/awesomewidgets/awdatetimeformatter.h | 3 +- sources/awesomewidgets/awfloatformatter.h | 3 +- sources/awesomewidgets/awscriptformatter.h | 3 +- sources/awesomewidgets/extquotes.h | 3 +- sources/awesomewidgets/extscript.cpp | 4 ++ sources/awesomewidgets/extscript.h | 3 +- sources/awesomewidgets/extupgrade.h | 3 +- sources/awesomewidgets/extweather.h | 3 +- sources/awesomewidgets/graphicalitem.h | 3 +- sources/desktop-panel/plugin/dpadds.cpp | 16 ++++---- sources/extsysmon/extsysmon.cpp | 4 +- sources/test/testextscript.cpp | 40 ++++++++++++++----- sources/test/testextscript.h | 5 ++- 17 files changed, 73 insertions(+), 46 deletions(-) diff --git a/sources/awesome-widget/plugin/awformatterconfig.cpp b/sources/awesome-widget/plugin/awformatterconfig.cpp index f2f1471..e1f3d54 100644 --- a/sources/awesome-widget/plugin/awformatterconfig.cpp +++ b/sources/awesome-widget/plugin/awformatterconfig.cpp @@ -35,8 +35,8 @@ AWFormatterConfig::AWFormatterConfig(QWidget *parent, const QStringList keys) qCDebug(LOG_AW) << __PRETTY_FUNCTION__; ui->setupUi(this); - editButton = ui->buttonBox->addButton(i18n("Edit"), - QDialogButtonBox::ActionRole); + editButton + = ui->buttonBox->addButton(i18n("Edit"), QDialogButtonBox::ActionRole); init(); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index 37f3426..649cd0b 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -95,8 +95,8 @@ bool AWFormatterHelper::writeFormatters(const QStringList keys) const qCDebug(LOG_AW) << "Remove formatters" << keys; QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini") - .arg(QStandardPaths::writableLocation( - QStandardPaths::GenericDataLocation)); + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)); QSettings settings(fileName, QSettings::IniFormat); qCInfo(LOG_AW) << "Configuration file" << fileName; diff --git a/sources/awesome-widget/plugin/awkeyoperations.cpp b/sources/awesome-widget/plugin/awkeyoperations.cpp index abab46c..1e23e18 100644 --- a/sources/awesome-widget/plugin/awkeyoperations.cpp +++ b/sources/awesome-widget/plugin/awkeyoperations.cpp @@ -194,12 +194,14 @@ QString AWKeyOperations::infoByKey(QString key) const else if (key.startsWith(QString("custom"))) return extScripts->itemByTag(key, QString("custom"))->uniq(); else if (key.contains(QRegExp(QString("^hdd[rw]")))) - return QString("%1").arg(m_devices[QString( - "disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); + return QString("%1").arg( + m_devices[QString("disk")] + [key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); else if (key.contains(QRegExp( QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))) - return QString("%1").arg(m_devices[QString( - "mount")][key + return QString("%1").arg( + m_devices[QString("mount")] + [key .remove(QRegExp(QString( "^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))) .toInt()]); @@ -207,8 +209,9 @@ QString AWKeyOperations::infoByKey(QString key) const return QString("%1").arg( m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]); else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) - return QString("%1").arg(m_devices[QString( - "net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]); + return QString("%1").arg( + m_devices[QString("net")] + [key.remove(QRegExp(QString("^(down|up)"))).toInt()]); else if (key.startsWith(QString("pkgcount"))) return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq(); else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index 7c27fae..72ea07c 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -61,6 +61,9 @@ public: void setName(const QString _name = QString("none")); void setNumber(int _number = -1); +signals: + void dataReceived(const QVariantHash &data); + public slots: virtual void readConfiguration(); virtual QVariantHash run() = 0; diff --git a/sources/awesomewidgets/awdatetimeformatter.h b/sources/awesomewidgets/awdatetimeformatter.h index 0605fcf..30f328b 100644 --- a/sources/awesomewidgets/awdatetimeformatter.h +++ b/sources/awesomewidgets/awdatetimeformatter.h @@ -32,7 +32,8 @@ class AWDateTimeFormatter : public AWAbstractFormatter Q_PROPERTY(QString format READ format WRITE setFormat) public: - explicit AWDateTimeFormatter(QWidget *parent, const QString filePath = QString()); + explicit AWDateTimeFormatter(QWidget *parent, + const QString filePath = QString()); virtual ~AWDateTimeFormatter(); QString convert(const QVariant &_value) const; AWDateTimeFormatter *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/awfloatformatter.h b/sources/awesomewidgets/awfloatformatter.h index 310cae9..7fcb6ef 100644 --- a/sources/awesomewidgets/awfloatformatter.h +++ b/sources/awesomewidgets/awfloatformatter.h @@ -37,7 +37,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, + const QString filePath = QString()); virtual ~AWFloatFormatter(); QString convert(const QVariant &_value) const; AWFloatFormatter *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/awscriptformatter.h b/sources/awesomewidgets/awscriptformatter.h index f950990..ec9fdbf 100644 --- a/sources/awesomewidgets/awscriptformatter.h +++ b/sources/awesomewidgets/awscriptformatter.h @@ -35,7 +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, + const QString filePath = QString()); virtual ~AWScriptFormatter(); QString convert(const QVariant &_value) const; AWScriptFormatter *copy(const QString _fileName, const int _number); diff --git a/sources/awesomewidgets/extquotes.h b/sources/awesomewidgets/extquotes.h index 3001bad..27cc49c 100644 --- a/sources/awesomewidgets/extquotes.h +++ b/sources/awesomewidgets/extquotes.h @@ -38,8 +38,7 @@ class ExtQuotes : public AbstractExtItem Q_PROPERTY(QString ticker READ ticker WRITE setTicker) public: - explicit ExtQuotes(QWidget *parent, - const QString filePath = QString()); + explicit ExtQuotes(QWidget *parent, const QString filePath = QString()); virtual ~ExtQuotes(); ExtQuotes *copy(const QString _fileName, const int _number); // get methods diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index d319459..9c06c85 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -263,6 +263,9 @@ QVariantHash ExtScript::run() { if (!isActive()) return value; + if (process->state() != QProcess::NotRunning) + qCWarning(LOG_LIB) << "Another process is already running" + << process->state(); if ((times == 1) && (process->state() == QProcess::NotRunning)) { QStringList cmdList; @@ -375,6 +378,7 @@ void ExtScript::updateValue() // filters value[tag(QString("custom"))] = applyFilters(strValue); + emit(dataReceived(value)); } diff --git a/sources/awesomewidgets/extscript.h b/sources/awesomewidgets/extscript.h index 283289b..a5fb1b7 100644 --- a/sources/awesomewidgets/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -39,8 +39,7 @@ class ExtScript : public AbstractExtItem public: enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap }; - explicit ExtScript(QWidget *parent, - const QString filePath = QString()); + explicit ExtScript(QWidget *parent, const QString filePath = QString()); virtual ~ExtScript(); ExtScript *copy(const QString _fileName, const int _number); // get methods diff --git a/sources/awesomewidgets/extupgrade.h b/sources/awesomewidgets/extupgrade.h index 9a5a63b..0c94b45 100644 --- a/sources/awesomewidgets/extupgrade.h +++ b/sources/awesomewidgets/extupgrade.h @@ -36,8 +36,7 @@ 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, const QString filePath = QString()); virtual ~ExtUpgrade(); ExtUpgrade *copy(const QString _fileName, const int _number); // get methods diff --git a/sources/awesomewidgets/extweather.h b/sources/awesomewidgets/extweather.h index 825ae41..f02cebb 100644 --- a/sources/awesomewidgets/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -42,8 +42,7 @@ class ExtWeather : public AbstractExtItem Q_PROPERTY(int ts READ ts WRITE setTs) public: - explicit ExtWeather(QWidget *parent, - const QString filePath = QString()); + explicit ExtWeather(QWidget *parent, const QString filePath = QString()); virtual ~ExtWeather(); ExtWeather *copy(const QString _fileName, const int _number); QString weatherFromInt(const int _id) const; diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index de512c9..b5a6c30 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -52,8 +52,7 @@ public: enum class Direction { LeftToRight = 0, RightToLeft = 1 }; enum class Type { Horizontal, Vertical, Circle, Graph, Bars }; - explicit GraphicalItem(QWidget *parent, - const QString filePath = QString()); + explicit GraphicalItem(QWidget *parent, const QString filePath = QString()); virtual ~GraphicalItem(); GraphicalItem *copy(const QString _fileName, const int _number); QString image(const QVariant &value); diff --git a/sources/desktop-panel/plugin/dpadds.cpp b/sources/desktop-panel/plugin/dpadds.cpp index 21a551c..ee25dae 100644 --- a/sources/desktop-panel/plugin/dpadds.cpp +++ b/sources/desktop-panel/plugin/dpadds.cpp @@ -156,22 +156,22 @@ QString DPAdds::toolTipImage(const int desktop) const std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(), [&toolTipScene, &screen](WindowData data) { QPixmap desktop = screen->grabWindow(data.id); - toolTipScene->addPixmap(desktop) - ->setOffset(data.rect.left(), data.rect.top()); + toolTipScene->addPixmap(desktop)->setOffset( + data.rect.left(), data.rect.top()); }); } else if (m_tooltipType == QString("windows")) { QScreen *screen = QGuiApplication::primaryScreen(); std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(), [&toolTipScene, &screen](WindowData data) { QPixmap desktop = screen->grabWindow(data.id); - toolTipScene->addPixmap(desktop) - ->setOffset(data.rect.left(), data.rect.top()); + toolTipScene->addPixmap(desktop)->setOffset( + data.rect.left(), data.rect.top()); }); std::for_each(info.windowsData.cbegin(), info.windowsData.cend(), [&toolTipScene, &screen](WindowData data) { QPixmap window = screen->grabWindow(data.id); - toolTipScene->addPixmap(window) - ->setOffset(data.rect.left(), data.rect.top()); + toolTipScene->addPixmap(window)->setOffset( + data.rect.left(), data.rect.top()); }); } @@ -232,8 +232,8 @@ QString DPAdds::valueByKey(const QString key, int desktop) const .arg(currentMark, m_mark.count(), QLatin1Char(' ')) .replace(QString(" "), QString(" ")); else if (key == QString("name")) - return KWindowSystem::desktopName(desktop) - .replace(QString(" "), QString(" ")); + return KWindowSystem::desktopName(desktop).replace(QString(" "), + QString(" ")); else if (key == QString("number")) return QString::number(desktop); else if (key == QString("total")) diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 8727df8..6b61d34 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -125,8 +125,8 @@ void ExtendedSysMon::readConfiguration() settings.beginGroup(QString("Configuration")); rawConfig[QString("ACPIPATH")] - = settings.value(QString("ACPIPATH"), - QString("/sys/class/power_supply/")) + = settings + .value(QString("ACPIPATH"), QString("/sys/class/power_supply/")) .toString(); rawConfig[QString("GPUDEV")] = settings.value(QString("GPUDEV"), QString("auto")).toString(); diff --git a/sources/test/testextscript.cpp b/sources/test/testextscript.cpp index c6fe839..d397550 100644 --- a/sources/test/testextscript.cpp +++ b/sources/test/testextscript.cpp @@ -29,11 +29,12 @@ void TestExtScript::initTestCase() extScript = new ExtScript(nullptr); extScript->setInterval(1); extScript->setExecutable(QString("hello world")); + extScript->setNumber(0); extScript->setRedirect(ExtScript::Redirect::stderr2stdout); extScript->setPrefix(QString("echo")); - while (true) - qDebug() <run(); + QVariantHash value = extScript->run(); + qDebug() << "Init values in first run" << value; } @@ -46,26 +47,43 @@ void TestExtScript::cleanupTestCase() void TestExtScript::test_values() { QCOMPARE(extScript->interval(), 1); + QCOMPARE(extScript->number(), 0); QCOMPARE(extScript->executable(), QString("hello world")); + QCOMPARE(extScript->strRedirect(), QString("stderr2stdout")); QCOMPARE(extScript->prefix(), QString("echo")); } -void TestExtScript::test_firstRun() +void TestExtScript::test_run() { + // init spy + QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &))); QVariantHash firstValue = extScript->run(); - qDebug() << firstValue; - QTest::qSleep(20000); - QCOMPARE(firstValue[extScript->tag(QString("custom"))].toString(), QString("")); - QTest::qSleep(20000); + QCOMPARE(firstValue[extScript->tag(QString("custom"))].toString(), + QString("")); + + // check values + QVERIFY(spy.wait(5000)); + QList arguments = spy.takeFirst(); + QCOMPARE( + arguments.at(0).toHash()[extScript->tag(QString("custom"))].toString(), + QString("\nhello world")); } -void TestExtScript::test_secondRun() +void TestExtScript::test_filters() { - QVariantHash secondValue = extScript->run(); - qDebug() << secondValue; - QCOMPARE(secondValue[extScript->tag(QString("custom"))].toString(), QString("hello world")); + extScript->setFilters(QStringList() << QString("newline")); + // init spy + QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &))); + extScript->run(); + + // check values + QVERIFY(spy.wait(5000)); + QList arguments = spy.takeFirst(); + QCOMPARE( + arguments.at(0).toHash()[extScript->tag(QString("custom"))].toString(), + QString("
hello world")); } diff --git a/sources/test/testextscript.h b/sources/test/testextscript.h index 5422d76..b9cc3b5 100644 --- a/sources/test/testextscript.h +++ b/sources/test/testextscript.h @@ -24,6 +24,7 @@ class ExtScript; +class QSignalSpy; class TestExtScript : public QObject { @@ -35,8 +36,8 @@ private slots: void cleanupTestCase(); // test void test_values(); - void test_firstRun(); - void test_secondRun(); + void test_run(); + void test_filters(); private: ExtScript *extScript = nullptr; From c57a92b6870ca12fb68b8deb6af7bea63b9ec19a Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 24 May 2016 11:53:00 +0300 Subject: [PATCH 14/32] more consistent tests for extscripts (fix missed filters copying found by tests btw) --- sources/awesomewidgets/extscript.cpp | 1 + sources/test/testextscript.cpp | 19 ++++++++++++++++++- sources/test/testextscript.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 9c06c85..c7823f2 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -72,6 +72,7 @@ ExtScript *ExtScript::copy(const QString _fileName, const int _number) item->setNumber(_number); item->setPrefix(prefix()); item->setRedirect(redirect()); + item->setFilters(filters()); return item; } diff --git a/sources/test/testextscript.cpp b/sources/test/testextscript.cpp index d397550..ded0da1 100644 --- a/sources/test/testextscript.cpp +++ b/sources/test/testextscript.cpp @@ -21,7 +21,6 @@ #include #include "extscript.h" -#include "version.h" void TestExtScript::initTestCase() @@ -44,6 +43,9 @@ void TestExtScript::cleanupTestCase() } + + + void TestExtScript::test_values() { QCOMPARE(extScript->interval(), 1); @@ -87,4 +89,19 @@ void TestExtScript::test_filters() } +void TestExtScript::test_copy() +{ + ExtScript *newExtScript = extScript->copy(QString("/dev/null"), 1); + + QCOMPARE(newExtScript->interval(), extScript->interval()); + QCOMPARE(newExtScript->executable(), extScript->executable()); + QCOMPARE(newExtScript->strRedirect(), extScript->strRedirect()); + QCOMPARE(newExtScript->prefix(), extScript->prefix()); + QCOMPARE(newExtScript->filters(), extScript->filters()); + QCOMPARE(newExtScript->number(), 1); + + delete newExtScript; +} + + QTEST_MAIN(TestExtScript); diff --git a/sources/test/testextscript.h b/sources/test/testextscript.h index b9cc3b5..2f5688d 100644 --- a/sources/test/testextscript.h +++ b/sources/test/testextscript.h @@ -38,6 +38,7 @@ private slots: void test_values(); void test_run(); void test_filters(); + void test_copy(); private: ExtScript *extScript = nullptr; From b73fb194097ae50201a1f6e31906c901188b190b Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 25 May 2016 12:35:34 +0300 Subject: [PATCH 15/32] add tests for extupgrade --- sources/awesomewidgets/extupgrade.cpp | 2 + sources/libraries.cmake | 2 +- sources/test/CMakeLists.txt | 19 ++-- sources/test/testextscript.cpp | 29 +++-- sources/test/testextscript.h | 3 +- sources/test/testextupgrade.cpp | 148 ++++++++++++++++++++++++++ sources/test/testextupgrade.h | 52 +++++++++ 7 files changed, 236 insertions(+), 19 deletions(-) create mode 100644 sources/test/testextupgrade.cpp create mode 100644 sources/test/testextupgrade.h diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index ed54fc5..951d4d1 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -225,6 +225,8 @@ void ExtUpgrade::updateValue() .filter(QRegExp(m_filter)) .count(); }(qoutput); + + emit(dataReceived(value)); } diff --git a/sources/libraries.cmake b/sources/libraries.cmake index 9a9a052..0c29760 100644 --- a/sources/libraries.cmake +++ b/sources/libraries.cmake @@ -13,7 +13,7 @@ set(Qt_INCLUDE ) set(Qt_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES} - ${Qt5Qml_LIBRARIES} ${Qt5Test_LIBRARIES} ${Qt5Widgets_LIBRARIES} + ${Qt5Qml_LIBRARIES} ${Qt5Widgets_LIBRARIES} ) # kf5 libraries diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index e70c070..27f96e1 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -9,15 +9,18 @@ include_directories( ${PROJECT_TRDPARTY_DIR} ${Qt_INCLUDE} ${Kf5_INCLUDE} - ${Qt5Test_INCLUDE_DIRS} ) # extscript -set (EXTSCRIPT_HEADERS testextscript.h) -set (EXTSCRIPT_SOURCES testextscript.cpp) -# qt5_wrap_cpp(EXTSCRIPT_MOC_SOURCES ${EXTSCRIPT_HEADERS}) -add_executable (${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES} ${EXTSCRIPT_MOC_SOURCES}) -target_link_libraries (${SUBPROJECT}-extscript ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) -add_test (NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript - "-o" "../Testing/output-extscript.log") +set(EXTSCRIPT_HEADERS testextscript.h) +set(EXTSCRIPT_SOURCES testextscript.cpp) +add_executable(${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES}) +target_link_libraries(${SUBPROJECT}-extscript ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +add_test(NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript) +# extupgrade +set(EXTUPGRADE_HEADERS testextupgrade.h) +set(EXTUPGRADE_SOURCES testextupgrade.cpp) +add_executable(${SUBPROJECT}-extupgrade ${EXTUPGRADE_HEADERS} ${EXTUPGRADE_SOURCES}) +target_link_libraries(${SUBPROJECT}-extupgrade ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +add_test(NAME "ExtUpgrade" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extupgrade) diff --git a/sources/test/testextscript.cpp b/sources/test/testextscript.cpp index ded0da1..e5c8619 100644 --- a/sources/test/testextscript.cpp +++ b/sources/test/testextscript.cpp @@ -25,15 +25,16 @@ void TestExtScript::initTestCase() { + generateRandomString(); + extScript = new ExtScript(nullptr); extScript->setInterval(1); - extScript->setExecutable(QString("hello world")); + extScript->setExecutable(randomString); extScript->setNumber(0); extScript->setRedirect(ExtScript::Redirect::stderr2stdout); extScript->setPrefix(QString("echo")); - QVariantHash value = extScript->run(); - qDebug() << "Init values in first run" << value; + extScript->run(); } @@ -43,14 +44,11 @@ void TestExtScript::cleanupTestCase() } - - - void TestExtScript::test_values() { QCOMPARE(extScript->interval(), 1); QCOMPARE(extScript->number(), 0); - QCOMPARE(extScript->executable(), QString("hello world")); + QCOMPARE(extScript->executable(), randomString); QCOMPARE(extScript->strRedirect(), QString("stderr2stdout")); QCOMPARE(extScript->prefix(), QString("echo")); } @@ -69,7 +67,7 @@ void TestExtScript::test_run() QList arguments = spy.takeFirst(); QCOMPARE( arguments.at(0).toHash()[extScript->tag(QString("custom"))].toString(), - QString("\nhello world")); + QString("\n%1").arg(randomString)); } @@ -85,7 +83,7 @@ void TestExtScript::test_filters() QList arguments = spy.takeFirst(); QCOMPARE( arguments.at(0).toHash()[extScript->tag(QString("custom"))].toString(), - QString("
hello world")); + QString("
%1").arg(randomString)); } @@ -104,4 +102,17 @@ void TestExtScript::test_copy() } +void TestExtScript::generateRandomString() +{ + randomString.clear(); + + int diff = 'Z' - 'A'; + int count = rand() % 100 + 1; + for (int i = 0; i < count; i++) { + char c = 'A' + (rand() % diff); + randomString += QChar(c); + } +} + + QTEST_MAIN(TestExtScript); diff --git a/sources/test/testextscript.h b/sources/test/testextscript.h index 2f5688d..16cbb2d 100644 --- a/sources/test/testextscript.h +++ b/sources/test/testextscript.h @@ -24,7 +24,6 @@ class ExtScript; -class QSignalSpy; class TestExtScript : public QObject { @@ -41,7 +40,9 @@ private slots: void test_copy(); private: + void generateRandomString(); ExtScript *extScript = nullptr; + QString randomString; }; diff --git a/sources/test/testextupgrade.cpp b/sources/test/testextupgrade.cpp new file mode 100644 index 0000000..3e4f44c --- /dev/null +++ b/sources/test/testextupgrade.cpp @@ -0,0 +1,148 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testextupgrade.h" + +#include + +#include "extupgrade.h" + + +void TestExtUpgrade::initTestCase() +{ + generateRandomStrings(); + + extUpgrade = new ExtUpgrade(nullptr); + extUpgrade->setInterval(1); + extUpgrade->setExecutable(cmd); + extUpgrade->setNumber(0); + + extUpgrade->run(); +} + + +void TestExtUpgrade::cleanupTestCase() +{ + delete extUpgrade; +} + + +void TestExtUpgrade::test_values() +{ + QCOMPARE(extUpgrade->interval(), 1); + QCOMPARE(extUpgrade->number(), 0); + QCOMPARE(extUpgrade->executable(), cmd); +} + + +void TestExtUpgrade::test_run() +{ + // init spy + QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &))); + QVariantHash firstValue = extUpgrade->run(); + QCOMPARE(firstValue[extUpgrade->tag(QString("pkgcount"))].toInt(), 0); + + // check values + QVERIFY(spy.wait(5000)); + QList arguments = spy.takeFirst(); + QCOMPARE( + arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(), + randomStrings.count()); +} + + +void TestExtUpgrade::test_null() +{ + int null = rand() % randomStrings.count(); + extUpgrade->setNull(null); + QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &))); + extUpgrade->run(); + + // check values + QVERIFY(spy.wait(5000)); + QList arguments = spy.takeFirst(); + QCOMPARE( + arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(), + randomStrings.count() - null); +} + + +void TestExtUpgrade::test_filter() +{ + QSet filters; + int count = rand() % randomStrings.count(); + for (int i = 0; i < count; i++) { + int index = rand() % randomStrings.count(); + filters << randomStrings.at(index); + } + + extUpgrade->setFilter( + QString("(^%1$)").arg(filters.toList().join(QString("$|^")))); + // init spy + QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &))); + extUpgrade->run(); + + // check values + QVERIFY(spy.wait(5000)); + QList arguments = spy.takeFirst(); + QCOMPARE( + arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(), + filters.count()); +} + + +void TestExtUpgrade::test_copy() +{ + ExtUpgrade *newExtUpgrade = extUpgrade->copy(QString("/dev/null"), 1); + + QCOMPARE(newExtUpgrade->interval(), extUpgrade->interval()); + QCOMPARE(newExtUpgrade->executable(), extUpgrade->executable()); + QCOMPARE(newExtUpgrade->filter(), extUpgrade->filter()); + QCOMPARE(newExtUpgrade->null(), extUpgrade->null()); + QCOMPARE(newExtUpgrade->number(), 1); + + delete newExtUpgrade; +} + + +QString TestExtUpgrade::generateRandomString() const +{ + QString string; + int diff = 'Z' - 'A'; + int count = rand() % 100 + 1; + for (int i = 0; i < count; i++) { + char c = 'A' + (rand() % diff); + string += QChar(c); + } + + return string; +} + + +void TestExtUpgrade::generateRandomStrings() +{ + randomStrings.clear(); + + int count = rand() % 100 + 1; + for (int i = 0; i < count; i++) + randomStrings.append(generateRandomString()); + cmd = QString("echo -e '%1'").arg(randomStrings.join(QString("\n"))); +} + + +QTEST_MAIN(TestExtUpgrade); diff --git a/sources/test/testextupgrade.h b/sources/test/testextupgrade.h new file mode 100644 index 0000000..e20b3a5 --- /dev/null +++ b/sources/test/testextupgrade.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTEXTUPGRADE_H +#define TESTEXTUPGRADE_H + +#include +#include + + +class ExtUpgrade; + +class TestExtUpgrade : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_run(); + void test_null(); + void test_filter(); + void test_copy(); + +private: + QString generateRandomString() const; + void generateRandomStrings(); + ExtUpgrade *extUpgrade = nullptr; + QString cmd; + QStringList randomStrings; +}; + + +#endif /* TESTEXTUPGRADE_H */ From 6f09737f0f9797d5664cd3d1b4b65ade5b2cb97c Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 26 May 2016 16:10:23 +0300 Subject: [PATCH 16/32] add test for extquotes * change url generation in extquotes * fix bug with missing derivate values --- sources/awesomewidgets/extquotes.cpp | 55 ++++++------ sources/awesomewidgets/extquotes.h | 1 + sources/test/CMakeLists.txt | 6 ++ sources/test/testextquotes.cpp | 123 +++++++++++++++++++++++++++ sources/test/testextquotes.h | 53 ++++++++++++ 5 files changed, 214 insertions(+), 24 deletions(-) create mode 100644 sources/test/testextquotes.cpp create mode 100644 sources/test/testextquotes.h diff --git a/sources/awesomewidgets/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp index 8cab854..525d45c 100644 --- a/sources/awesomewidgets/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -105,6 +105,7 @@ void ExtQuotes::setTicker(const QString _ticker) qCDebug(LOG_LIB) << "Ticker" << _ticker; m_ticker = _ticker; + initUrl(); } @@ -127,16 +128,6 @@ void ExtQuotes::readConfiguration() } bumpApi(AWEQAPI); - - // init query - m_url = QUrl(YAHOO_QUOTES_URL); - QUrlQuery params; - params.addQueryItem(QString("format"), QString("json")); - params.addQueryItem(QString("env"), - QString("store://datatables.org/alltableswithkeys")); - params.addQueryItem(QString("q"), - QString(YAHOO_QUOTES_QUERY).arg(m_ticker)); - m_url.setQuery(params); } @@ -226,35 +217,51 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply) // ask value = jsonQuotes[QString("Ask")].toString().toDouble(); values[tag(QString("askchg"))] - = values[QString("ask")].toDouble() == 0.0 + = values[tag(QString("ask"))].toDouble() == 0.0 ? 0.0 - : value - values[QString("ask")].toDouble(); - values[tag(QString("percaskchg"))] = 100.0 - * values[QString("askchg")].toDouble() - / values[QString("ask")].toDouble(); + : value - values[tag(QString("ask"))].toDouble(); + values[tag(QString("percaskchg"))] + = 100.0 * values[tag(QString("askchg"))].toDouble() + / values[tag(QString("ask"))].toDouble(); values[tag(QString("ask"))] = value; // bid value = jsonQuotes[QString("Bid")].toString().toDouble(); values[tag(QString("bidchg"))] - = values[QString("bid")].toDouble() == 0.0 + = values[tag(QString("bid"))].toDouble() == 0.0 ? 0.0 - : value - values[QString("bid")].toDouble(); - values[tag(QString("percbidchg"))] = 100.0 - * values[QString("bidchg")].toDouble() - / values[QString("bid")].toDouble(); + : value - values[tag(QString("bid"))].toDouble(); + values[tag(QString("percbidchg"))] + = 100.0 * values[tag(QString("bidchg"))].toDouble() + / values[tag(QString("bid"))].toDouble(); values[tag(QString("bid"))] = value; // last trade value = jsonQuotes[QString("LastTradePriceOnly")].toString().toDouble(); values[tag(QString("pricechg"))] - = values[QString("price")].toDouble() == 0.0 + = values[tag(QString("price"))].toDouble() == 0.0 ? 0.0 - : value - values[QString("price")].toDouble(); + : value - values[tag(QString("price"))].toDouble(); values[tag(QString("percpricechg"))] - = 100.0 * values[QString("pricechg")].toDouble() - / values[QString("price")].toDouble(); + = 100.0 * values[tag(QString("pricechg"))].toDouble() + / values[tag(QString("price"))].toDouble(); values[tag(QString("price"))] = value; + + emit(dataReceived(values)); +} + + +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(m_ticker)); + m_url.setQuery(params); } diff --git a/sources/awesomewidgets/extquotes.h b/sources/awesomewidgets/extquotes.h index 27cc49c..d5e2256 100644 --- a/sources/awesomewidgets/extquotes.h +++ b/sources/awesomewidgets/extquotes.h @@ -61,6 +61,7 @@ private: QUrl m_url; bool isRunning = false; Ui::ExtQuotes *ui = nullptr; + void initUrl(); void translate(); // properties QString m_ticker = QString("EURUSD=X"); diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 27f96e1..5a0bace 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -17,6 +17,12 @@ set(EXTSCRIPT_SOURCES testextscript.cpp) add_executable(${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES}) target_link_libraries(${SUBPROJECT}-extscript ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) add_test(NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript) +# extquotes +set(EXTQUOTES_HEADERS testextquotes.h) +set(EXTQUOTES_SOURCES testextquotes.cpp) +add_executable(${SUBPROJECT}-extquotes ${EXTQUOTES_HEADERS} ${EXTQUOTES_SOURCES}) +target_link_libraries(${SUBPROJECT}-extquotes ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +add_test(NAME "ExtQuotes" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extquotes) # extupgrade set(EXTUPGRADE_HEADERS testextupgrade.h) set(EXTUPGRADE_SOURCES testextupgrade.cpp) diff --git a/sources/test/testextquotes.cpp b/sources/test/testextquotes.cpp new file mode 100644 index 0000000..67aa9e4 --- /dev/null +++ b/sources/test/testextquotes.cpp @@ -0,0 +1,123 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testextquotes.h" + +#include + +#include "extquotes.h" + + +void TestExtQuotes::initTestCase() +{ + extQuotes = new ExtQuotes(nullptr); + extQuotes->setInterval(1); + extQuotes->setTicker(ticker); + extQuotes->setNumber(0); + + extQuotes->run(); +} + + +void TestExtQuotes::cleanupTestCase() +{ + delete extQuotes; +} + + +void TestExtQuotes::test_values() +{ + QCOMPARE(extQuotes->interval(), 1); + QCOMPARE(extQuotes->number(), 0); + QCOMPARE(extQuotes->ticker(), ticker); +} + + +void TestExtQuotes::test_run() +{ + // init spy + QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &))); + QVariantHash firstValue = extQuotes->run(); + QCOMPARE(firstValue[extQuotes->tag(QString("ask"))].toDouble(), 0.0); + QCOMPARE(firstValue[extQuotes->tag(QString("bid"))].toDouble(), 0.0); + QCOMPARE(firstValue[extQuotes->tag(QString("price"))].toDouble(), 0.0); + + // check values + QVERIFY(spy.wait(5000)); + QList arguments = spy.takeFirst(); + cache[QString("ask")] + = arguments.at(0).toHash()[extQuotes->tag(QString("ask"))]; + cache[QString("bid")] + = arguments.at(0).toHash()[extQuotes->tag(QString("bid"))]; + cache[QString("price")] + = arguments.at(0).toHash()[extQuotes->tag(QString("price"))]; + + for (auto type : types) { + qDebug() << "Test type" << type; + QVERIFY((cache[type].toDouble() > price.first) + && (cache[type].toDouble() < price.second)); + } +} + + +void TestExtQuotes::test_derivatives() +{ + // init spy + QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &))); + QVariantHash firstValue = extQuotes->run(); + + // check values + QVERIFY(spy.wait(5000)); + QList arguments = spy.takeFirst(); + QVariantHash values; + values[QString("ask")] + = arguments.at(0).toHash()[extQuotes->tag(QString("ask"))]; + values[QString("bid")] + = arguments.at(0).toHash()[extQuotes->tag(QString("bid"))]; + values[QString("price")] + = arguments.at(0).toHash()[extQuotes->tag(QString("price"))]; + + for (auto type : types) { + qDebug() << "Test type" << type; + QCOMPARE(arguments.at(0) + .toHash()[extQuotes->tag(QString("%1chg").arg(type))] + .toDouble(), + (values[type].toDouble() - cache[type].toDouble())); + QWARN("Possible round error"); + QCOMPARE(arguments.at(0) + .toHash()[extQuotes->tag(QString("perc%1chg").arg(type))] + .toDouble(), + 100.0 * (values[type].toDouble() - cache[type].toDouble()) + / values[type].toDouble()); + } +} + + +void TestExtQuotes::test_copy() +{ + ExtQuotes *newExtQuotes = extQuotes->copy(QString("/dev/null"), 1); + + QCOMPARE(newExtQuotes->interval(), extQuotes->interval()); + QCOMPARE(newExtQuotes->ticker(), extQuotes->ticker()); + QCOMPARE(newExtQuotes->number(), 1); + + delete newExtQuotes; +} + + +QTEST_MAIN(TestExtQuotes); diff --git a/sources/test/testextquotes.h b/sources/test/testextquotes.h new file mode 100644 index 0000000..1b07163 --- /dev/null +++ b/sources/test/testextquotes.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTEXTQUOTES_H +#define TESTEXTQUOTES_H + +#include +#include + + +class ExtQuotes; + +class TestExtQuotes : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_run(); + void test_derivatives(); + void test_copy(); + +private: + ExtQuotes *extQuotes = nullptr; + QVariantHash cache; + QString ticker = QString("EURUSD=X"); + QStringList types = QStringList() << QString("ask") << QString("bid") + << QString("price"); + // we assume that price will not be differ more than in 2 times + QPair price = QPair(0.5, 2.0); +}; + + +#endif /* TESTEXTQUOTES_H */ From 2a257de1e64eadf47893a5ba1c6d1999846a60c7 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Fri, 27 May 2016 15:53:12 +0300 Subject: [PATCH 17/32] add tests for extweather --- sources/awesomewidgets/extweather.cpp | 28 ++++-- sources/awesomewidgets/extweather.h | 1 + sources/test/CMakeLists.txt | 7 +- sources/test/testextweather.cpp | 140 ++++++++++++++++++++++++++ sources/test/testextweather.h | 56 +++++++++++ 5 files changed, 221 insertions(+), 11 deletions(-) create mode 100644 sources/test/testextweather.cpp create mode 100644 sources/test/testextweather.h diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 6fda40b..0aabd44 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -134,6 +134,7 @@ void ExtWeather::setCity(const QString _city) qCDebug(LOG_LIB) << "City" << _city; m_city = _city; + initUrl(); } @@ -142,6 +143,7 @@ void ExtWeather::setCountry(const QString _country) qCDebug(LOG_LIB) << "Country" << _country; m_country = _country; + initUrl(); } @@ -185,16 +187,6 @@ void ExtWeather::readConfiguration() } bumpApi(AWEWAPI); - - // init query - m_url = QUrl(YAHOO_WEATHER_URL); - QUrlQuery params; - params.addQueryItem(QString("format"), QString("json")); - params.addQueryItem(QString("env"), - QString("store://datatables.org/alltableswithkeys")); - params.addQueryItem(QString("q"), - QString(YAHOO_WEATHER_QUERY).arg(m_city, m_country)); - m_url.setQuery(params); } @@ -359,6 +351,22 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply) values[tag(QString("humidity"))] = 0; values[tag(QString("pressure"))] = 0.0; } + + emit(dataReceived(values)); +} + + +void ExtWeather::initUrl() +{ + // init query + m_url = QUrl(YAHOO_WEATHER_URL); + QUrlQuery params; + params.addQueryItem(QString("format"), QString("json")); + params.addQueryItem(QString("env"), + QString("store://datatables.org/alltableswithkeys")); + params.addQueryItem(QString("q"), + QString(YAHOO_WEATHER_QUERY).arg(m_city, m_country)); + m_url.setQuery(params); } diff --git a/sources/awesomewidgets/extweather.h b/sources/awesomewidgets/extweather.h index f02cebb..6b60583 100644 --- a/sources/awesomewidgets/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -73,6 +73,7 @@ private: QUrl m_url; bool isRunning = false; Ui::ExtWeather *ui = nullptr; + void initUrl(); void translate(); // properties QString m_city = QString("London"); diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 5a0bace..9e0c2f6 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -29,4 +29,9 @@ set(EXTUPGRADE_SOURCES testextupgrade.cpp) add_executable(${SUBPROJECT}-extupgrade ${EXTUPGRADE_HEADERS} ${EXTUPGRADE_SOURCES}) target_link_libraries(${SUBPROJECT}-extupgrade ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) add_test(NAME "ExtUpgrade" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extupgrade) - +# extweather +set(EXTWEATHER_HEADERS testextweather.h) +set(EXTWEATHER_SOURCES testextweather.cpp) +add_executable(${SUBPROJECT}-extweather ${EXTWEATHER_HEADERS} ${EXTWEATHER_SOURCES}) +target_link_libraries(${SUBPROJECT}-extweather ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +add_test(NAME "ExtWeather" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extweather) diff --git a/sources/test/testextweather.cpp b/sources/test/testextweather.cpp new file mode 100644 index 0000000..97f8a7f --- /dev/null +++ b/sources/test/testextweather.cpp @@ -0,0 +1,140 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testextweather.h" + +#include + +#include "extweather.h" + + +void TestExtWeather::initTestCase() +{ + extWeather = new ExtWeather(nullptr); + extWeather->setInterval(1); + extWeather->setCity(city); + extWeather->setCountry(country); + extWeather->setNumber(0); + + extWeather->run(); +} + + +void TestExtWeather::cleanupTestCase() +{ + delete extWeather; +} + + +void TestExtWeather::test_values() +{ + QCOMPARE(extWeather->interval(), 1); + QCOMPARE(extWeather->number(), 0); + QCOMPARE(extWeather->city(), city); + QCOMPARE(extWeather->country(), country); +} + + +void TestExtWeather::test_run() +{ + // init spy + QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &))); + QVariantHash firstValue = extWeather->run(); + + // check values + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + QEXPECT_FAIL("", "WeatherID should not be 0", Continue); + QCOMPARE(arguments[extWeather->tag(QString("weatherId"))].toInt(), 0); + QVERIFY((arguments[extWeather->tag(QString("humidity"))].toInt() + > humidity.first) + && (arguments[extWeather->tag(QString("humidity"))].toInt() + < humidity.second)); + QEXPECT_FAIL("", "https://yahoo.uservoice.com/forums/207813-us-weather/" + "suggestions/14209233-invalid-pressure-calculation", + Continue); + QVERIFY((arguments[extWeather->tag(QString("pressure"))].toFloat() + > pressure.first) + && (arguments[extWeather->tag(QString("pressure"))].toInt() + < pressure.second)); + QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat() + > temp.first) + && (arguments[extWeather->tag(QString("temperature"))].toInt() + < temp.second)); + // image should be only one symbol here + QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(), + 1); +} + + +void TestExtWeather::test_ts() +{ + extWeather->setTs(1); + // init spy + QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &))); + QVariantHash firstValue = extWeather->run(); + + // check values + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + QEXPECT_FAIL("", "WeatherID should not be 0", Continue); + QCOMPARE(arguments[extWeather->tag(QString("weatherId"))].toInt(), 0); + QCOMPARE(arguments[extWeather->tag(QString("humidity"))].toInt(), 0); + QCOMPARE(arguments[extWeather->tag(QString("pressure"))].toFloat(), 0.0f); + QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat() + > temp.first) + && (arguments[extWeather->tag(QString("temperature"))].toInt() + < temp.second)); + // image should be only one symbol here + QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(), + 1); +} + + +void TestExtWeather::test_image() +{ + extWeather->setImage(true); + // init spy + QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &))); + QVariantHash firstValue = extWeather->run(); + + // check values + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + QVERIFY( + arguments[extWeather->tag(QString("weather"))].toString().startsWith( + QString("copy(QString("/dev/null"), 1); + + QCOMPARE(newExtWeather->interval(), extWeather->interval()); + QCOMPARE(newExtWeather->city(), extWeather->city()); + QCOMPARE(newExtWeather->country(), extWeather->country()); + QCOMPARE(newExtWeather->ts(), extWeather->ts()); + QCOMPARE(newExtWeather->image(), extWeather->image()); + QCOMPARE(newExtWeather->number(), 1); + + delete newExtWeather; +} + + +QTEST_MAIN(TestExtWeather); diff --git a/sources/test/testextweather.h b/sources/test/testextweather.h new file mode 100644 index 0000000..1b1638a --- /dev/null +++ b/sources/test/testextweather.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTEXTWEATHER_H +#define TESTEXTWEATHER_H + +#include +#include + + +class ExtWeather; + +class TestExtWeather : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_run(); + void test_ts(); + void test_image(); + void test_copy(); + +private: + ExtWeather *extWeather = nullptr; + QString city = QString("London"); + QString country = QString("uk"); + // humidity is in percents + QPair humidity = QPair(0, 100); + // pressure should be about 1 atm + QPair pressure = QPair(500.0f, 1500.0f); + // dont know about temperature, but I suppose it will be between -40 and 40 + QPair temp = QPair(-40.0f, 40.0f); +}; + + +#endif /* TESTEXTWEATHER_H */ From fd3ed61191aa3979f29ae444dc0ae9938dbd7975 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sat, 28 May 2016 00:30:02 +0300 Subject: [PATCH 18/32] add test for abstractextitem --- sources/awesomewidgets/abstractextitem.cpp | 8 +- sources/awesomewidgets/abstractextitem.h | 2 +- sources/test/CMakeLists.txt | 18 ++- sources/test/testabstractextitem.cpp | 127 +++++++++++++++++++++ sources/test/testabstractextitem.h | 54 +++++++++ sources/test/testextweather.cpp | 4 +- 6 files changed, 200 insertions(+), 13 deletions(-) create mode 100644 sources/test/testabstractextitem.cpp create mode 100644 sources/test/testabstractextitem.h diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index 18b5639..62e0e09 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -70,10 +70,10 @@ void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const QString AbstractExtItem::writtableConfig() const { - QStringList paths = m_fileName.split(QChar('/')); - - QString name = paths.takeLast(); - QString dir = paths.takeLast(); + QString path = m_fileName; + QString name = QFileInfo(path).fileName(); + path.remove(path.count() - name.count() - 1, name.count() + 1); + QString dir = QFileInfo(path).fileName(); return QString("%1/awesomewidgets/%2/%3") .arg(QStandardPaths::writableLocation( diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index 72ea07c..7bdb3a1 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -72,7 +72,7 @@ public slots: virtual void writeConfiguration() const; private: - QString m_fileName; + QString m_fileName = QString("/dev/null"); virtual void translate() = 0; // properties int m_apiVersion = 0; diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 9e0c2f6..2542dc0 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -11,18 +11,24 @@ include_directories( ${Kf5_INCLUDE} ) -# extscript -set(EXTSCRIPT_HEADERS testextscript.h) -set(EXTSCRIPT_SOURCES testextscript.cpp) -add_executable(${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES}) -target_link_libraries(${SUBPROJECT}-extscript ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) -add_test(NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript) +# abstractextitem +set(ABSTRACTEXTITEM_HEADERS testabstractextitem.h) +set(ABSTRACTEXTITEM_SOURCES testabstractextitem.cpp) +add_executable(${SUBPROJECT}-abstractextitem ${ABSTRACTEXTITEM_HEADERS} ${ABSTRACTEXTITEM_SOURCES}) +target_link_libraries(${SUBPROJECT}-abstractextitem ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +add_test(NAME "AbstractExtItem" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-abstractextitem) # extquotes set(EXTQUOTES_HEADERS testextquotes.h) set(EXTQUOTES_SOURCES testextquotes.cpp) add_executable(${SUBPROJECT}-extquotes ${EXTQUOTES_HEADERS} ${EXTQUOTES_SOURCES}) target_link_libraries(${SUBPROJECT}-extquotes ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) add_test(NAME "ExtQuotes" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extquotes) +# extscript +set(EXTSCRIPT_HEADERS testextscript.h) +set(EXTSCRIPT_SOURCES testextscript.cpp) +add_executable(${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES}) +target_link_libraries(${SUBPROJECT}-extscript ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +add_test(NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript) # extupgrade set(EXTUPGRADE_HEADERS testextupgrade.h) set(EXTUPGRADE_SOURCES testextupgrade.cpp) diff --git a/sources/test/testabstractextitem.cpp b/sources/test/testabstractextitem.cpp new file mode 100644 index 0000000..dcb48d5 --- /dev/null +++ b/sources/test/testabstractextitem.cpp @@ -0,0 +1,127 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testabstractextitem.h" + +#include + +#include "extupgrade.h" + + +void TestAbstractExtItem::initTestCase() +{ + generateFilename(); + + extItem = new ExtUpgrade(nullptr, fileName); + extItem->setActive(false); + extItem->setApiVersion(1); + extItem->setComment(comment); + extItem->setName(name); + extItem->setNumber(-1); +} + + +void TestAbstractExtItem::cleanupTestCase() +{ + QFile::remove(fileName); + delete extItem; +} + + +void TestAbstractExtItem::test_values() +{ + QCOMPARE(extItem->isActive(), false); + QCOMPARE(extItem->apiVersion(), 1); + QCOMPARE(extItem->comment(), comment); + QCOMPARE(extItem->fileName(), fileName); + QCOMPARE(extItem->name(), name); + QVERIFY((extItem->number() > 0) && (extItem->number() < 1000)); +} + + +void TestAbstractExtItem::test_writtableFile() +{ + QCOMPARE(extItem->writtableConfig(), writeFileName); +} + + +void TestAbstractExtItem::test_configuration() +{ + extItem->writeConfiguration(); + + ExtUpgrade *newExtItem = new ExtUpgrade(nullptr, writeFileName); + QCOMPARE(newExtItem->isActive(), extItem->isActive()); + QCOMPARE(newExtItem->comment(), extItem->comment()); + QCOMPARE(newExtItem->fileName(), writeFileName); + QCOMPARE(newExtItem->name(), extItem->name()); + QCOMPARE(newExtItem->number(), extItem->number()); + + delete newExtItem; +} + + +void TestAbstractExtItem::test_bumpApi() +{ + extItem->bumpApi(100500); + + QCOMPARE(extItem->apiVersion(), 100500); +} + + +void TestAbstractExtItem::test_delete() +{ + ExtUpgrade *newExtItem = new ExtUpgrade(nullptr, writeFileName); + + QVERIFY(newExtItem->tryDelete()); + QVERIFY(!QFile::exists(writeFileName)); + + delete newExtItem; +} + + +void TestAbstractExtItem::test_copy() +{ + ExtUpgrade *newExtItem = extItem->copy(QString("/dev/null"), 1); + + QCOMPARE(newExtItem->isActive(), extItem->isActive()); + QCOMPARE(newExtItem->apiVersion(), extItem->apiVersion()); + QCOMPARE(newExtItem->comment(), extItem->comment()); + QCOMPARE(newExtItem->name(), extItem->name()); + + delete newExtItem; +} + + +void TestAbstractExtItem::generateFilename() +{ + fileName = QString("%1/").arg( + QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + writeFileName = QString("%1/awesomewidgets/tmp/") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)); + int diff = 'Z' - 'A'; + int count = rand() % 20 + 1; + for (int i = 0; i < count; i++) { + char c = 'A' + (rand() % diff); + fileName += QChar(c); + writeFileName += QChar(c); + } +} + + +QTEST_MAIN(TestAbstractExtItem); diff --git a/sources/test/testabstractextitem.h b/sources/test/testabstractextitem.h new file mode 100644 index 0000000..4d672ed --- /dev/null +++ b/sources/test/testabstractextitem.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTABSTRACTEXTITEM_H +#define TESTABSTRACTEXTITEM_H + +#include +#include + + +class ExtUpgrade; + +class TestAbstractExtItem : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_writtableFile(); + void test_configuration(); + void test_bumpApi(); + void test_delete(); + void test_copy(); + +private: + void generateFilename(); + ExtUpgrade *extItem = nullptr; + QString comment = QString("A comment"); + QString name = QString("A name"); + QString fileName; + QString writeFileName; +}; + + +#endif /* TESTABSTRACTEXTITEM_H */ diff --git a/sources/test/testextweather.cpp b/sources/test/testextweather.cpp index 97f8a7f..bf41746 100644 --- a/sources/test/testextweather.cpp +++ b/sources/test/testextweather.cpp @@ -117,8 +117,8 @@ void TestExtWeather::test_image() QVERIFY(spy.wait(5000)); QVariantHash arguments = spy.takeFirst().at(0).toHash(); QVERIFY( - arguments[extWeather->tag(QString("weather"))].toString().startsWith( - QString("tag(QString("weather"))].toString().startsWith( + QString(" Date: Sun, 29 May 2016 02:45:57 +0300 Subject: [PATCH 19/32] add test cases for float and no formatters --- sources/test/CMakeLists.txt | 14 +++ sources/test/testfloatformatter.cpp | 184 ++++++++++++++++++++++++++++ sources/test/testfloatformatter.h | 53 ++++++++ sources/test/testnoformatter.cpp | 81 ++++++++++++ sources/test/testnoformatter.h | 47 +++++++ 5 files changed, 379 insertions(+) create mode 100644 sources/test/testfloatformatter.cpp create mode 100644 sources/test/testfloatformatter.h create mode 100644 sources/test/testnoformatter.cpp create mode 100644 sources/test/testnoformatter.h diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 2542dc0..f28898a 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -11,6 +11,7 @@ include_directories( ${Kf5_INCLUDE} ) +## extensions # abstractextitem set(ABSTRACTEXTITEM_HEADERS testabstractextitem.h) set(ABSTRACTEXTITEM_SOURCES testabstractextitem.cpp) @@ -41,3 +42,16 @@ set(EXTWEATHER_SOURCES testextweather.cpp) add_executable(${SUBPROJECT}-extweather ${EXTWEATHER_HEADERS} ${EXTWEATHER_SOURCES}) target_link_libraries(${SUBPROJECT}-extweather ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) add_test(NAME "ExtWeather" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extweather) +## formatters +# float formatter +set(FLOATFORMATTER_HEADERS testfloatformatter.h) +set(FLOATFORMATTER_SOURCES testfloatformatter.cpp) +add_executable(${SUBPROJECT}-floatformatter ${FLOATFORMATTER_HEADERS} ${FLOATFORMATTER_SOURCES}) +target_link_libraries(${SUBPROJECT}-floatformatter ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +add_test(NAME "FloatFormatter" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-floatformatter) +# no formatter +set(NOFORMATTER_HEADERS testnoformatter.h) +set(NOFORMATTER_SOURCES testnoformatter.cpp) +add_executable(${SUBPROJECT}-noformatter ${NOFORMATTER_HEADERS} ${NOFORMATTER_SOURCES}) +target_link_libraries(${SUBPROJECT}-noformatter ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +add_test(NAME "NoFormatter" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-noformatter) diff --git a/sources/test/testfloatformatter.cpp b/sources/test/testfloatformatter.cpp new file mode 100644 index 0000000..c035880 --- /dev/null +++ b/sources/test/testfloatformatter.cpp @@ -0,0 +1,184 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testfloatformatter.h" + +#include + +#include "awfloatformatter.h" + + +void TestAWFloatFormatter::initTestCase() +{ + formatter = new AWFloatFormatter(nullptr); +} + + +void TestAWFloatFormatter::cleanupTestCase() +{ + delete formatter; +} + + +void TestAWFloatFormatter::test_values() +{ +} + + +void TestAWFloatFormatter::test_count() +{ + // assign + int count = 10 + rand() % 200; + formatter->setCount(count); + QCOMPARE(formatter->count(), count); + + // test + float value = getValue(); + QString output = formatter->convert(value); + QCOMPARE(output.count(), count); + + // reset + formatter->setCount(0); +} + + +void TestAWFloatFormatter::test_fillChar() +{ + // assign + char c = 'A' + (rand() % static_cast('Z' - 'A')); + formatter->setFillChar(QChar(c)); + QCOMPARE(formatter->fillChar(), QChar(c)); + formatter->setCount(101); + + // test + int value = rand() % 100; + QString output = formatter->convert(value); + QVERIFY(output.startsWith(QChar(c))); + + // reset + formatter->setFillChar(QChar()); + formatter->setCount(0); +} + + +void TestAWFloatFormatter::test_format() +{ + // assign + QWARN("Lets assing 'z' formatter, it should cause a warning"); + formatter->setFormat('z'); + QCOMPARE(formatter->format(), 'f'); + formatter->setFormat('e'); + QCOMPARE(formatter->format(), 'e'); + + // test + float value = getValue(); + QString output = formatter->convert(value); + QVERIFY(output.contains('e')); + + // reset + formatter->setFormat('f'); +} + + +void TestAWFloatFormatter::test_precision() +{ + // assign + int precision = 1 + rand() % 5; + formatter->setPrecision(precision); + QCOMPARE(formatter->precision(), precision); + + // test + float value = getValue(); + QString output = formatter->convert(value); + output.remove(QString("0.")); + QCOMPARE(output.count(), precision); + + // reset + formatter->setPrecision(-1); +} + + +void TestAWFloatFormatter::test_multiplier() +{ + formatter->setPrecision(6); + + // assign + double multiplier = getValue(); + formatter->setMultiplier(multiplier); + QCOMPARE(formatter->multiplier(), multiplier); + + // test + double value = getValue(); + QCOMPARE(formatter->convert(value), QString::number(value * multiplier, 'f', 6)); + + // reset + formatter->setMultiplier(1.0); +} + + +void TestAWFloatFormatter::test_summand() +{ + // assign + double summand = getValue(); + formatter->setSummand(summand); + QCOMPARE(formatter->summand(), summand); + + // test + double value = getValue(); + QCOMPARE(formatter->convert(value), QString::number(value + summand, 'f', 6)); + + // reset + formatter->setSummand(1.0); +} + + +void TestAWFloatFormatter::test_copy() +{ + doRandom(); + AWFloatFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1); + + QCOMPARE(newFormatter->count(), formatter->count()); + QCOMPARE(newFormatter->fillChar(), formatter->fillChar()); + QCOMPARE(newFormatter->format(), formatter->format()); + QCOMPARE(newFormatter->multiplier(), formatter->multiplier()); + QCOMPARE(newFormatter->precision(), formatter->precision()); + QCOMPARE(newFormatter->summand(), formatter->summand()); + QCOMPARE(newFormatter->number(), 1); + + delete newFormatter; +} + + +void TestAWFloatFormatter::doRandom() +{ + formatter->setCount(rand() % 100); + formatter->setFillChar(QChar('A' + (rand() % static_cast('Z' - 'A')))); + formatter->setFormat('A' + (rand() % static_cast('Z' - 'A'))); + formatter->setMultiplier(getValue()); + formatter->setPrecision(rand() % 100); + formatter->setSummand(getValue()); +} + + +float TestAWFloatFormatter::getValue() const +{ + return static_cast(rand()) / static_cast(RAND_MAX); +} + + +QTEST_MAIN(TestAWFloatFormatter); diff --git a/sources/test/testfloatformatter.h b/sources/test/testfloatformatter.h new file mode 100644 index 0000000..ea88f53 --- /dev/null +++ b/sources/test/testfloatformatter.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTFLOATFORMATTER_H +#define TESTFLOATFORMATTER_H + +#include +#include + + +class AWFloatFormatter; + +class TestAWFloatFormatter : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_count(); + void test_fillChar(); + void test_format(); + void test_precision(); + void test_multiplier(); + void test_summand(); + void test_copy(); + +private: + void doRandom(); + float getValue() const; + AWFloatFormatter *formatter = nullptr; +}; + + +#endif /* TESTFLOATFORMATTER_H */ diff --git a/sources/test/testnoformatter.cpp b/sources/test/testnoformatter.cpp new file mode 100644 index 0000000..b4db641 --- /dev/null +++ b/sources/test/testnoformatter.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testnoformatter.h" + +#include + +#include "awnoformatter.h" + + +void TestAWNoFormatter::initTestCase() +{ + formatter = new AWNoFormatter(nullptr); +} + + +void TestAWNoFormatter::cleanupTestCase() +{ + delete formatter; +} + + +void TestAWNoFormatter::test_values() +{ +} + + +void TestAWNoFormatter::test_conversion() +{ + // integer + int randomInt = rand(); + QCOMPARE(formatter->convert(randomInt), QString::number(randomInt)); + // float + QWARN("Float conversion isn't tested here due to possible rounding errors"); + // string + QString randomString = generateRandomString(); + QCOMPARE(formatter->convert(randomString), randomString); +} + + +void TestAWNoFormatter::test_copy() +{ + AWNoFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1); + + QCOMPARE(newFormatter->number(), 1); + + delete newFormatter; +} + + +QString TestAWNoFormatter::generateRandomString() +{ + QString string; + + int diff = 'Z' - 'A'; + int count = rand() % 100 + 1; + for (int i = 0; i < count; i++) { + char c = 'A' + (rand() % diff); + string += QChar(c); + } + + return string; +} + + +QTEST_MAIN(TestAWNoFormatter); diff --git a/sources/test/testnoformatter.h b/sources/test/testnoformatter.h new file mode 100644 index 0000000..26c01aa --- /dev/null +++ b/sources/test/testnoformatter.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTNOFORMATTER_H +#define TESTNOFORMATTER_H + +#include +#include + + +class AWNoFormatter; + +class TestAWNoFormatter : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_conversion(); + void test_copy(); + +private: + QString generateRandomString(); + AWNoFormatter *formatter = nullptr; +}; + + +#endif /* TESTNOFORMATTER_H */ From cae9e0d2e32a9ca7b7002f789e9857baba611088 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sun, 29 May 2016 03:33:41 +0300 Subject: [PATCH 20/32] add test library for random values generation --- sources/test/CMakeLists.txt | 22 ++++++---- sources/test/awtestlibrary.cpp | 61 ++++++++++++++++++++++++++++ sources/test/awtestlibrary.h | 35 ++++++++++++++++ sources/test/testabstractextitem.cpp | 12 +++--- sources/test/testextscript.cpp | 16 +------- sources/test/testextscript.h | 1 - sources/test/testextupgrade.cpp | 35 +++------------- sources/test/testextupgrade.h | 2 - sources/test/testfloatformatter.cpp | 47 ++++++++++----------- sources/test/testfloatformatter.h | 1 - sources/test/testnoformatter.cpp | 20 ++------- sources/test/testnoformatter.h | 1 - 12 files changed, 148 insertions(+), 105 deletions(-) create mode 100644 sources/test/awtestlibrary.cpp create mode 100644 sources/test/awtestlibrary.h diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index f28898a..0ed3817 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -11,47 +11,53 @@ include_directories( ${Kf5_INCLUDE} ) +## library +set(AWTESTLIBRARY_HEADERS awtestlibrary.h) +set(AWTESTLIBRARY_SOURCES awtestlibrary.cpp) +add_library(${SUBPROJECT}-awtest STATIC ${AWTESTLIBRARY_SOURCES} ${AWTESTLIBRARY_HEADERS}) +target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) ## extensions # abstractextitem set(ABSTRACTEXTITEM_HEADERS testabstractextitem.h) set(ABSTRACTEXTITEM_SOURCES testabstractextitem.cpp) add_executable(${SUBPROJECT}-abstractextitem ${ABSTRACTEXTITEM_HEADERS} ${ABSTRACTEXTITEM_SOURCES}) -target_link_libraries(${SUBPROJECT}-abstractextitem ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +target_link_libraries(${SUBPROJECT}-abstractextitem ${LIBRARY_TEST_SET}) add_test(NAME "AbstractExtItem" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-abstractextitem) # extquotes set(EXTQUOTES_HEADERS testextquotes.h) set(EXTQUOTES_SOURCES testextquotes.cpp) add_executable(${SUBPROJECT}-extquotes ${EXTQUOTES_HEADERS} ${EXTQUOTES_SOURCES}) -target_link_libraries(${SUBPROJECT}-extquotes ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +target_link_libraries(${SUBPROJECT}-extquotes ${LIBRARY_TEST_SET}) add_test(NAME "ExtQuotes" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extquotes) # extscript set(EXTSCRIPT_HEADERS testextscript.h) set(EXTSCRIPT_SOURCES testextscript.cpp) add_executable(${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES}) -target_link_libraries(${SUBPROJECT}-extscript ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +target_link_libraries(${SUBPROJECT}-extscript ${LIBRARY_TEST_SET}) add_test(NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript) # extupgrade set(EXTUPGRADE_HEADERS testextupgrade.h) set(EXTUPGRADE_SOURCES testextupgrade.cpp) add_executable(${SUBPROJECT}-extupgrade ${EXTUPGRADE_HEADERS} ${EXTUPGRADE_SOURCES}) -target_link_libraries(${SUBPROJECT}-extupgrade ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +target_link_libraries(${SUBPROJECT}-extupgrade ${LIBRARY_TEST_SET}) add_test(NAME "ExtUpgrade" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extupgrade) # extweather set(EXTWEATHER_HEADERS testextweather.h) set(EXTWEATHER_SOURCES testextweather.cpp) add_executable(${SUBPROJECT}-extweather ${EXTWEATHER_HEADERS} ${EXTWEATHER_SOURCES}) -target_link_libraries(${SUBPROJECT}-extweather ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +target_link_libraries(${SUBPROJECT}-extweather ${LIBRARY_TEST_SET}) add_test(NAME "ExtWeather" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extweather) ## formatters # float formatter set(FLOATFORMATTER_HEADERS testfloatformatter.h) set(FLOATFORMATTER_SOURCES testfloatformatter.cpp) add_executable(${SUBPROJECT}-floatformatter ${FLOATFORMATTER_HEADERS} ${FLOATFORMATTER_SOURCES}) -target_link_libraries(${SUBPROJECT}-floatformatter ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) -add_test(NAME "FloatFormatter" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-floatformatter) +target_link_libraries(${SUBPROJECT}-floatformatter ${LIBRARY_TEST_SET}) +add_test(NAME "Float4Formatter" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-floatformatter) # no formatter set(NOFORMATTER_HEADERS testnoformatter.h) set(NOFORMATTER_SOURCES testnoformatter.cpp) add_executable(${SUBPROJECT}-noformatter ${NOFORMATTER_HEADERS} ${NOFORMATTER_SOURCES}) -target_link_libraries(${SUBPROJECT}-noformatter ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +target_link_libraries(${SUBPROJECT}-noformatter ${LIBRARY_TEST_SET}) add_test(NAME "NoFormatter" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-noformatter) diff --git a/sources/test/awtestlibrary.cpp b/sources/test/awtestlibrary.cpp new file mode 100644 index 0000000..f1eb1db --- /dev/null +++ b/sources/test/awtestlibrary.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "awtestlibrary.h" + + +char AWTestLibrary::randomChar() +{ + return 'A' + (rand() % static_cast('Z' - 'A')); +} + + +double AWTestLibrary::randomDouble() +{ + return static_cast(rand()) / static_cast(RAND_MAX); +} + + +int AWTestLibrary::randomInt(const int max) +{ + return rand() % max; +} + + +QString AWTestLibrary::randomString(const int max) +{ + QString output; + + int count = 1 + randomInt(max); + for (int i = 0; i < count; i++) + output += QChar(randomChar()); + + return output; +} + + +QStringList AWTestLibrary::randomStringList(const int max) +{ + QStringList output; + + int count = 1 + randomInt(max); + for (int i = 0; i < count; i++) + output.append(randomString()); + + return output; +} diff --git a/sources/test/awtestlibrary.h b/sources/test/awtestlibrary.h new file mode 100644 index 0000000..a4d1096 --- /dev/null +++ b/sources/test/awtestlibrary.h @@ -0,0 +1,35 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef AWTESTLIBRARY_H +#define AWTESTLIBRARY_H + +#include + + +namespace AWTestLibrary +{ + char randomChar(); + double randomDouble(); + int randomInt(const int max = 100); + QString randomString(const int max = 100); + QStringList randomStringList(const int max = 100); +}; + + +#endif /* AWTESTLIBRARY_H */ diff --git a/sources/test/testabstractextitem.cpp b/sources/test/testabstractextitem.cpp index dcb48d5..ffb9068 100644 --- a/sources/test/testabstractextitem.cpp +++ b/sources/test/testabstractextitem.cpp @@ -20,6 +20,7 @@ #include +#include "awtestlibrary.h" #include "extupgrade.h" @@ -114,13 +115,10 @@ void TestAbstractExtItem::generateFilename() writeFileName = QString("%1/awesomewidgets/tmp/") .arg(QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation)); - int diff = 'Z' - 'A'; - int count = rand() % 20 + 1; - for (int i = 0; i < count; i++) { - char c = 'A' + (rand() % diff); - fileName += QChar(c); - writeFileName += QChar(c); - } + + QString name = AWTestLibrary::randomString(20); + fileName += name; + writeFileName += name; } diff --git a/sources/test/testextscript.cpp b/sources/test/testextscript.cpp index e5c8619..4ecc050 100644 --- a/sources/test/testextscript.cpp +++ b/sources/test/testextscript.cpp @@ -20,12 +20,13 @@ #include +#include "awtestlibrary.h" #include "extscript.h" void TestExtScript::initTestCase() { - generateRandomString(); + randomString = AWTestLibrary::randomString(); extScript = new ExtScript(nullptr); extScript->setInterval(1); @@ -102,17 +103,4 @@ void TestExtScript::test_copy() } -void TestExtScript::generateRandomString() -{ - randomString.clear(); - - int diff = 'Z' - 'A'; - int count = rand() % 100 + 1; - for (int i = 0; i < count; i++) { - char c = 'A' + (rand() % diff); - randomString += QChar(c); - } -} - - QTEST_MAIN(TestExtScript); diff --git a/sources/test/testextscript.h b/sources/test/testextscript.h index 16cbb2d..01bed73 100644 --- a/sources/test/testextscript.h +++ b/sources/test/testextscript.h @@ -40,7 +40,6 @@ private slots: void test_copy(); private: - void generateRandomString(); ExtScript *extScript = nullptr; QString randomString; }; diff --git a/sources/test/testextupgrade.cpp b/sources/test/testextupgrade.cpp index 3e4f44c..9b149a0 100644 --- a/sources/test/testextupgrade.cpp +++ b/sources/test/testextupgrade.cpp @@ -20,12 +20,14 @@ #include +#include "awtestlibrary.h" #include "extupgrade.h" void TestExtUpgrade::initTestCase() { - generateRandomStrings(); + randomStrings = AWTestLibrary::randomStringList(); + cmd = QString("echo -e '%1'").arg(randomStrings.join(QString("\n"))); extUpgrade = new ExtUpgrade(nullptr); extUpgrade->setInterval(1); @@ -68,7 +70,7 @@ void TestExtUpgrade::test_run() void TestExtUpgrade::test_null() { - int null = rand() % randomStrings.count(); + int null = AWTestLibrary::randomInt(randomStrings.count()); extUpgrade->setNull(null); QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &))); extUpgrade->run(); @@ -85,9 +87,9 @@ void TestExtUpgrade::test_null() void TestExtUpgrade::test_filter() { QSet filters; - int count = rand() % randomStrings.count(); + int count = AWTestLibrary::randomInt(randomStrings.count()); for (int i = 0; i < count; i++) { - int index = rand() % randomStrings.count(); + int index = AWTestLibrary::randomInt(randomStrings.count()); filters << randomStrings.at(index); } @@ -120,29 +122,4 @@ void TestExtUpgrade::test_copy() } -QString TestExtUpgrade::generateRandomString() const -{ - QString string; - int diff = 'Z' - 'A'; - int count = rand() % 100 + 1; - for (int i = 0; i < count; i++) { - char c = 'A' + (rand() % diff); - string += QChar(c); - } - - return string; -} - - -void TestExtUpgrade::generateRandomStrings() -{ - randomStrings.clear(); - - int count = rand() % 100 + 1; - for (int i = 0; i < count; i++) - randomStrings.append(generateRandomString()); - cmd = QString("echo -e '%1'").arg(randomStrings.join(QString("\n"))); -} - - QTEST_MAIN(TestExtUpgrade); diff --git a/sources/test/testextupgrade.h b/sources/test/testextupgrade.h index e20b3a5..99f8a0b 100644 --- a/sources/test/testextupgrade.h +++ b/sources/test/testextupgrade.h @@ -41,8 +41,6 @@ private slots: void test_copy(); private: - QString generateRandomString() const; - void generateRandomStrings(); ExtUpgrade *extUpgrade = nullptr; QString cmd; QStringList randomStrings; diff --git a/sources/test/testfloatformatter.cpp b/sources/test/testfloatformatter.cpp index c035880..711e6c6 100644 --- a/sources/test/testfloatformatter.cpp +++ b/sources/test/testfloatformatter.cpp @@ -20,6 +20,7 @@ #include +#include "awtestlibrary.h" #include "awfloatformatter.h" @@ -43,12 +44,12 @@ void TestAWFloatFormatter::test_values() void TestAWFloatFormatter::test_count() { // assign - int count = 10 + rand() % 200; + int count = 10 + AWTestLibrary::randomInt(); formatter->setCount(count); QCOMPARE(formatter->count(), count); // test - float value = getValue(); + double value = AWTestLibrary::randomDouble(); QString output = formatter->convert(value); QCOMPARE(output.count(), count); @@ -60,13 +61,13 @@ void TestAWFloatFormatter::test_count() void TestAWFloatFormatter::test_fillChar() { // assign - char c = 'A' + (rand() % static_cast('Z' - 'A')); + char c = AWTestLibrary::randomChar(); formatter->setFillChar(QChar(c)); QCOMPARE(formatter->fillChar(), QChar(c)); formatter->setCount(101); // test - int value = rand() % 100; + int value = AWTestLibrary::randomInt(); QString output = formatter->convert(value); QVERIFY(output.startsWith(QChar(c))); @@ -86,7 +87,7 @@ void TestAWFloatFormatter::test_format() QCOMPARE(formatter->format(), 'e'); // test - float value = getValue(); + double value = AWTestLibrary::randomDouble(); QString output = formatter->convert(value); QVERIFY(output.contains('e')); @@ -98,12 +99,12 @@ void TestAWFloatFormatter::test_format() void TestAWFloatFormatter::test_precision() { // assign - int precision = 1 + rand() % 5; + int precision = 1 + AWTestLibrary::randomInt(5); formatter->setPrecision(precision); QCOMPARE(formatter->precision(), precision); // test - float value = getValue(); + double value = AWTestLibrary::randomDouble(); QString output = formatter->convert(value); output.remove(QString("0.")); QCOMPARE(output.count(), precision); @@ -118,13 +119,14 @@ void TestAWFloatFormatter::test_multiplier() formatter->setPrecision(6); // assign - double multiplier = getValue(); + double multiplier = AWTestLibrary::randomDouble(); formatter->setMultiplier(multiplier); QCOMPARE(formatter->multiplier(), multiplier); // test - double value = getValue(); - QCOMPARE(formatter->convert(value), QString::number(value * multiplier, 'f', 6)); + double value = AWTestLibrary::randomDouble(); + QCOMPARE(formatter->convert(value), + QString::number(value * multiplier, 'f', 6)); // reset formatter->setMultiplier(1.0); @@ -134,13 +136,14 @@ void TestAWFloatFormatter::test_multiplier() void TestAWFloatFormatter::test_summand() { // assign - double summand = getValue(); + double summand = AWTestLibrary::randomDouble(); formatter->setSummand(summand); QCOMPARE(formatter->summand(), summand); // test - double value = getValue(); - QCOMPARE(formatter->convert(value), QString::number(value + summand, 'f', 6)); + double value = AWTestLibrary::randomDouble(); + QCOMPARE(formatter->convert(value), + QString::number(value + summand, 'f', 6)); // reset formatter->setSummand(1.0); @@ -166,18 +169,12 @@ void TestAWFloatFormatter::test_copy() void TestAWFloatFormatter::doRandom() { - formatter->setCount(rand() % 100); - formatter->setFillChar(QChar('A' + (rand() % static_cast('Z' - 'A')))); - formatter->setFormat('A' + (rand() % static_cast('Z' - 'A'))); - formatter->setMultiplier(getValue()); - formatter->setPrecision(rand() % 100); - formatter->setSummand(getValue()); -} - - -float TestAWFloatFormatter::getValue() const -{ - return static_cast(rand()) / static_cast(RAND_MAX); + formatter->setCount(AWTestLibrary::randomInt()); + formatter->setFillChar(QChar(AWTestLibrary::randomChar())); + formatter->setFormat(AWTestLibrary::randomChar()); + formatter->setMultiplier(AWTestLibrary::randomDouble()); + formatter->setPrecision(AWTestLibrary::randomInt()); + formatter->setSummand(AWTestLibrary::randomDouble()); } diff --git a/sources/test/testfloatformatter.h b/sources/test/testfloatformatter.h index ea88f53..8ee99f7 100644 --- a/sources/test/testfloatformatter.h +++ b/sources/test/testfloatformatter.h @@ -45,7 +45,6 @@ private slots: private: void doRandom(); - float getValue() const; AWFloatFormatter *formatter = nullptr; }; diff --git a/sources/test/testnoformatter.cpp b/sources/test/testnoformatter.cpp index b4db641..dc5a937 100644 --- a/sources/test/testnoformatter.cpp +++ b/sources/test/testnoformatter.cpp @@ -20,6 +20,7 @@ #include +#include "awtestlibrary.h" #include "awnoformatter.h" @@ -43,12 +44,12 @@ void TestAWNoFormatter::test_values() void TestAWNoFormatter::test_conversion() { // integer - int randomInt = rand(); + int randomInt = AWTestLibrary::randomInt(); QCOMPARE(formatter->convert(randomInt), QString::number(randomInt)); // float QWARN("Float conversion isn't tested here due to possible rounding errors"); // string - QString randomString = generateRandomString(); + QString randomString = AWTestLibrary::randomString(); QCOMPARE(formatter->convert(randomString), randomString); } @@ -63,19 +64,4 @@ void TestAWNoFormatter::test_copy() } -QString TestAWNoFormatter::generateRandomString() -{ - QString string; - - int diff = 'Z' - 'A'; - int count = rand() % 100 + 1; - for (int i = 0; i < count; i++) { - char c = 'A' + (rand() % diff); - string += QChar(c); - } - - return string; -} - - QTEST_MAIN(TestAWNoFormatter); diff --git a/sources/test/testnoformatter.h b/sources/test/testnoformatter.h index 26c01aa..1b43309 100644 --- a/sources/test/testnoformatter.h +++ b/sources/test/testnoformatter.h @@ -39,7 +39,6 @@ private slots: void test_copy(); private: - QString generateRandomString(); AWNoFormatter *formatter = nullptr; }; From 69c09d9ff8b121900a4017c8294beddd4e6458e4 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Mon, 30 May 2016 01:47:06 +0300 Subject: [PATCH 21/32] more tests for formatters --- sources/awesomewidgets/awscriptformatter.cpp | 7 +- sources/test/CMakeLists.txt | 56 +++------- sources/test/awtestlibrary.cpp | 16 +++ sources/test/awtestlibrary.h | 11 +- sources/test/testabstractextitem.h | 1 - sources/test/testdatetimeformatter.cpp | 68 ++++++++++++ sources/test/testdatetimeformatter.h | 46 ++++++++ sources/test/testextscript.h | 1 - sources/test/testextupgrade.cpp | 11 +- sources/test/testextupgrade.h | 1 - sources/test/testextweather.h | 1 - sources/test/testfloatformatter.cpp | 2 +- sources/test/testfloatformatter.h | 1 - sources/test/testnoformatter.cpp | 2 +- sources/test/testnoformatter.h | 1 - sources/test/testscriptformatter.cpp | 107 +++++++++++++++++++ sources/test/testscriptformatter.h | 50 +++++++++ 17 files changed, 313 insertions(+), 69 deletions(-) create mode 100644 sources/test/testdatetimeformatter.cpp create mode 100644 sources/test/testdatetimeformatter.h create mode 100644 sources/test/testscriptformatter.cpp create mode 100644 sources/test/testscriptformatter.h diff --git a/sources/awesomewidgets/awscriptformatter.cpp b/sources/awesomewidgets/awscriptformatter.cpp index 89c404d..3bc23cd 100644 --- a/sources/awesomewidgets/awscriptformatter.cpp +++ b/sources/awesomewidgets/awscriptformatter.cpp @@ -116,6 +116,7 @@ void AWScriptFormatter::setAppendCode(const bool _appendCode) qCDebug(LOG_LIB) << "Set append code" << _appendCode; m_appendCode = _appendCode; + initProgram(); } @@ -124,6 +125,7 @@ void AWScriptFormatter::setCode(const QString _code) qCDebug(LOG_LIB) << "Set code" << _code; m_code = _code; + initProgram(); } @@ -132,6 +134,7 @@ void AWScriptFormatter::setHasReturn(const bool _hasReturn) qCDebug(LOG_LIB) << "Set has return" << _hasReturn; m_hasReturn = _hasReturn; + initProgram(); } @@ -150,9 +153,6 @@ void AWScriptFormatter::readConfiguration() settings.endGroup(); bumpApi(AWEFAPI); - - // init JS code - initProgram(); } @@ -204,6 +204,7 @@ void AWScriptFormatter::writeConfiguration() const void AWScriptFormatter::initProgram() { + // init JS code if (m_appendCode) m_program = QString("(function(value) { %1%2 })") diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 0ed3817..fd94701 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -17,47 +17,15 @@ set(AWTESTLIBRARY_SOURCES awtestlibrary.cpp) add_library(${SUBPROJECT}-awtest STATIC ${AWTESTLIBRARY_SOURCES} ${AWTESTLIBRARY_HEADERS}) target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) -## extensions -# abstractextitem -set(ABSTRACTEXTITEM_HEADERS testabstractextitem.h) -set(ABSTRACTEXTITEM_SOURCES testabstractextitem.cpp) -add_executable(${SUBPROJECT}-abstractextitem ${ABSTRACTEXTITEM_HEADERS} ${ABSTRACTEXTITEM_SOURCES}) -target_link_libraries(${SUBPROJECT}-abstractextitem ${LIBRARY_TEST_SET}) -add_test(NAME "AbstractExtItem" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-abstractextitem) -# extquotes -set(EXTQUOTES_HEADERS testextquotes.h) -set(EXTQUOTES_SOURCES testextquotes.cpp) -add_executable(${SUBPROJECT}-extquotes ${EXTQUOTES_HEADERS} ${EXTQUOTES_SOURCES}) -target_link_libraries(${SUBPROJECT}-extquotes ${LIBRARY_TEST_SET}) -add_test(NAME "ExtQuotes" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extquotes) -# extscript -set(EXTSCRIPT_HEADERS testextscript.h) -set(EXTSCRIPT_SOURCES testextscript.cpp) -add_executable(${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES}) -target_link_libraries(${SUBPROJECT}-extscript ${LIBRARY_TEST_SET}) -add_test(NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript) -# extupgrade -set(EXTUPGRADE_HEADERS testextupgrade.h) -set(EXTUPGRADE_SOURCES testextupgrade.cpp) -add_executable(${SUBPROJECT}-extupgrade ${EXTUPGRADE_HEADERS} ${EXTUPGRADE_SOURCES}) -target_link_libraries(${SUBPROJECT}-extupgrade ${LIBRARY_TEST_SET}) -add_test(NAME "ExtUpgrade" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extupgrade) -# extweather -set(EXTWEATHER_HEADERS testextweather.h) -set(EXTWEATHER_SOURCES testextweather.cpp) -add_executable(${SUBPROJECT}-extweather ${EXTWEATHER_HEADERS} ${EXTWEATHER_SOURCES}) -target_link_libraries(${SUBPROJECT}-extweather ${LIBRARY_TEST_SET}) -add_test(NAME "ExtWeather" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extweather) -## formatters -# float formatter -set(FLOATFORMATTER_HEADERS testfloatformatter.h) -set(FLOATFORMATTER_SOURCES testfloatformatter.cpp) -add_executable(${SUBPROJECT}-floatformatter ${FLOATFORMATTER_HEADERS} ${FLOATFORMATTER_SOURCES}) -target_link_libraries(${SUBPROJECT}-floatformatter ${LIBRARY_TEST_SET}) -add_test(NAME "Float4Formatter" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-floatformatter) -# no formatter -set(NOFORMATTER_HEADERS testnoformatter.h) -set(NOFORMATTER_SOURCES testnoformatter.cpp) -add_executable(${SUBPROJECT}-noformatter ${NOFORMATTER_HEADERS} ${NOFORMATTER_SOURCES}) -target_link_libraries(${SUBPROJECT}-noformatter ${LIBRARY_TEST_SET}) -add_test(NAME "NoFormatter" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-noformatter) + +## modules +set(TEST_MODULES + abstractextitem extquotes extscript extupgrade extweather + datetimeformatter floatformatter noformatter scriptformatter) +foreach (TEST_MODULE ${TEST_MODULES}) + set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h) + set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp) + add_executable(${SUBPROJECT}-${TEST_MODULE} ${${TEST_MODULE}_HEADERS} ${${TEST_MODULE}_SOURCES}) + target_link_libraries(${SUBPROJECT}-${TEST_MODULE} ${LIBRARY_TEST_SET}) + add_test(NAME ${TEST_MODULE} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-${TEST_MODULE}) +endforeach (TEST_MODULE) diff --git a/sources/test/awtestlibrary.cpp b/sources/test/awtestlibrary.cpp index f1eb1db..6883972 100644 --- a/sources/test/awtestlibrary.cpp +++ b/sources/test/awtestlibrary.cpp @@ -18,6 +18,8 @@ #include "awtestlibrary.h" +#include + char AWTestLibrary::randomChar() { @@ -59,3 +61,17 @@ QStringList AWTestLibrary::randomStringList(const int max) return output; } + + +QStringList AWTestLibrary::randomSelect(const QStringList available) +{ + QSet output; + + int count = 1 + randomInt(available.count()); + for (int i = 0; i < count; i++) { + int index = randomInt(available.count()); + output << available.at(index); + } + + return output.toList(); +} diff --git a/sources/test/awtestlibrary.h b/sources/test/awtestlibrary.h index a4d1096..355d8a0 100644 --- a/sources/test/awtestlibrary.h +++ b/sources/test/awtestlibrary.h @@ -24,11 +24,12 @@ namespace AWTestLibrary { - char randomChar(); - double randomDouble(); - int randomInt(const int max = 100); - QString randomString(const int max = 100); - QStringList randomStringList(const int max = 100); +char randomChar(); +double randomDouble(); +int randomInt(const int max = 100); +QString randomString(const int max = 100); +QStringList randomStringList(const int max = 100); +QStringList randomSelect(const QStringList available); }; diff --git a/sources/test/testabstractextitem.h b/sources/test/testabstractextitem.h index 4d672ed..805fe5a 100644 --- a/sources/test/testabstractextitem.h +++ b/sources/test/testabstractextitem.h @@ -20,7 +20,6 @@ #define TESTABSTRACTEXTITEM_H #include -#include class ExtUpgrade; diff --git a/sources/test/testdatetimeformatter.cpp b/sources/test/testdatetimeformatter.cpp new file mode 100644 index 0000000..c785338 --- /dev/null +++ b/sources/test/testdatetimeformatter.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testdatetimeformatter.h" + +#include + +#include "awdatetimeformatter.h" +#include "awtestlibrary.h" +#include "version.h" + + +void TestAWDateTimeFormatter::initTestCase() +{ + format = AWTestLibrary::randomSelect(QString(TIME_KEYS).split(QChar(','))).join(QChar(' ')); + + formatter = new AWDateTimeFormatter(nullptr); + formatter->setFormat(format); +} + + +void TestAWDateTimeFormatter::cleanupTestCase() +{ + delete formatter; +} + + +void TestAWDateTimeFormatter::test_values() +{ + QCOMPARE(formatter->format(), format); +} + + +void TestAWDateTimeFormatter::test_conversion() +{ + QDateTime now = QDateTime::currentDateTime(); + QCOMPARE(formatter->convert(now), now.toString(format)); +} + + +void TestAWDateTimeFormatter::test_copy() +{ + AWDateTimeFormatter *newFormatter + = formatter->copy(QString("/dev/null"), 1); + + QCOMPARE(newFormatter->format(), formatter->format()); + QCOMPARE(newFormatter->number(), 1); + + delete newFormatter; +} + + +QTEST_MAIN(TestAWDateTimeFormatter); diff --git a/sources/test/testdatetimeformatter.h b/sources/test/testdatetimeformatter.h new file mode 100644 index 0000000..6386458 --- /dev/null +++ b/sources/test/testdatetimeformatter.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTDATETIMEFORMATTER_H +#define TESTDATETIMEFORMATTER_H + +#include + + +class AWDateTimeFormatter; + +class TestAWDateTimeFormatter : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_conversion(); + void test_copy(); + +private: + AWDateTimeFormatter *formatter = nullptr; + QString format; +}; + + +#endif /* TESTDATETIMEFORMATTER_H */ diff --git a/sources/test/testextscript.h b/sources/test/testextscript.h index 01bed73..4c1d195 100644 --- a/sources/test/testextscript.h +++ b/sources/test/testextscript.h @@ -20,7 +20,6 @@ #define TESTEXTSCRIPT_H #include -#include class ExtScript; diff --git a/sources/test/testextupgrade.cpp b/sources/test/testextupgrade.cpp index 9b149a0..64cbc10 100644 --- a/sources/test/testextupgrade.cpp +++ b/sources/test/testextupgrade.cpp @@ -86,15 +86,8 @@ void TestExtUpgrade::test_null() void TestExtUpgrade::test_filter() { - QSet filters; - int count = AWTestLibrary::randomInt(randomStrings.count()); - for (int i = 0; i < count; i++) { - int index = AWTestLibrary::randomInt(randomStrings.count()); - filters << randomStrings.at(index); - } - - extUpgrade->setFilter( - QString("(^%1$)").arg(filters.toList().join(QString("$|^")))); + QStringList filters = AWTestLibrary::randomSelect(randomStrings); + extUpgrade->setFilter(QString("(^%1$)").arg(filters.join(QString("$|^")))); // init spy QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &))); extUpgrade->run(); diff --git a/sources/test/testextupgrade.h b/sources/test/testextupgrade.h index 99f8a0b..7db8bcb 100644 --- a/sources/test/testextupgrade.h +++ b/sources/test/testextupgrade.h @@ -20,7 +20,6 @@ #define TESTEXTUPGRADE_H #include -#include class ExtUpgrade; diff --git a/sources/test/testextweather.h b/sources/test/testextweather.h index 1b1638a..8e28e05 100644 --- a/sources/test/testextweather.h +++ b/sources/test/testextweather.h @@ -20,7 +20,6 @@ #define TESTEXTWEATHER_H #include -#include class ExtWeather; diff --git a/sources/test/testfloatformatter.cpp b/sources/test/testfloatformatter.cpp index 711e6c6..46ef23e 100644 --- a/sources/test/testfloatformatter.cpp +++ b/sources/test/testfloatformatter.cpp @@ -20,8 +20,8 @@ #include -#include "awtestlibrary.h" #include "awfloatformatter.h" +#include "awtestlibrary.h" void TestAWFloatFormatter::initTestCase() diff --git a/sources/test/testfloatformatter.h b/sources/test/testfloatformatter.h index 8ee99f7..77746c9 100644 --- a/sources/test/testfloatformatter.h +++ b/sources/test/testfloatformatter.h @@ -20,7 +20,6 @@ #define TESTFLOATFORMATTER_H #include -#include class AWFloatFormatter; diff --git a/sources/test/testnoformatter.cpp b/sources/test/testnoformatter.cpp index dc5a937..a1ed6ce 100644 --- a/sources/test/testnoformatter.cpp +++ b/sources/test/testnoformatter.cpp @@ -20,8 +20,8 @@ #include -#include "awtestlibrary.h" #include "awnoformatter.h" +#include "awtestlibrary.h" void TestAWNoFormatter::initTestCase() diff --git a/sources/test/testnoformatter.h b/sources/test/testnoformatter.h index 1b43309..b9cf531 100644 --- a/sources/test/testnoformatter.h +++ b/sources/test/testnoformatter.h @@ -20,7 +20,6 @@ #define TESTNOFORMATTER_H #include -#include class AWNoFormatter; diff --git a/sources/test/testscriptformatter.cpp b/sources/test/testscriptformatter.cpp new file mode 100644 index 0000000..d2e0adc --- /dev/null +++ b/sources/test/testscriptformatter.cpp @@ -0,0 +1,107 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testscriptformatter.h" + +#include + +#include "awscriptformatter.h" +#include "awtestlibrary.h" + + +void TestAWScriptFormatter::initTestCase() +{ + formatter = new AWScriptFormatter(nullptr); + formatter->setCode(fullCode); + formatter->setAppendCode(false); + formatter->setHasReturn(true); +} + + +void TestAWScriptFormatter::cleanupTestCase() +{ + delete formatter; +} + + +void TestAWScriptFormatter::test_values() +{ + QCOMPARE(formatter->code(), fullCode); + QCOMPARE(formatter->appendCode(), false); + QCOMPARE(formatter->hasReturn(), true); + + QCOMPARE(formatter->program(), fullCode); +} + + +void TestAWScriptFormatter::test_conversion() +{ + QString string = AWTestLibrary::randomString(); + QCOMPARE(formatter->convert(string), string); +} + + +void TestAWScriptFormatter::test_appendCode() +{ + // set + formatter->setAppendCode(true); + QCOMPARE(formatter->appendCode(), true); + formatter->setCode(codeWithReturn); + + // test + QCOMPARE(formatter->program(), fullCode); + test_conversion(); + + // reset + formatter->setAppendCode(false); +} + + +void TestAWScriptFormatter::test_hasReturn() +{ + // set + formatter->setHasReturn(false); + QCOMPARE(formatter->hasReturn(), false); + formatter->setCode(code); + + // test 1 + QEXPECT_FAIL("", "Should fail because appendCode set to false", Continue); + QCOMPARE(formatter->program(), fullCode); + + // test 2 + formatter->setAppendCode(true); + QCOMPARE(formatter->program(), fullCode); + test_conversion(); +} + + +void TestAWScriptFormatter::test_copy() +{ + AWScriptFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1); + + QCOMPARE(newFormatter->appendCode(), formatter->appendCode()); + QCOMPARE(newFormatter->code(), formatter->code()); + QCOMPARE(newFormatter->hasReturn(), formatter->hasReturn()); + QCOMPARE(newFormatter->program(), formatter->program()); + QCOMPARE(newFormatter->number(), 1); + + delete newFormatter; +} + + +QTEST_MAIN(TestAWScriptFormatter); diff --git a/sources/test/testscriptformatter.h b/sources/test/testscriptformatter.h new file mode 100644 index 0000000..ed81823 --- /dev/null +++ b/sources/test/testscriptformatter.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTSCRIPTFORMATTER_H +#define TESTSCRIPTFORMATTER_H + +#include + + +class AWScriptFormatter; + +class TestAWScriptFormatter : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_conversion(); + void test_appendCode(); + void test_hasReturn(); + void test_copy(); + +private: + AWScriptFormatter *formatter = nullptr; + QString code = QString("output = value"); + QString codeWithReturn = QString("%1; return output;").arg(code); + QString fullCode = QString("(function(value) { %1 })").arg(codeWithReturn); +}; + + +#endif /* TESTNOFORMATTER_H */ From 4337379177431e47862b091cf41e878c3e10afdb Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 1 Jun 2016 10:55:51 +0300 Subject: [PATCH 22/32] add tests for abstract formatter --- .../plugin/awformatterhelper.cpp | 36 +++++----- .../awesome-widget/plugin/awformatterhelper.h | 8 +-- .../awesomewidgets/awabstractformatter.cpp | 48 +++++++++++-- sources/awesomewidgets/awabstractformatter.h | 13 ++-- .../awesomewidgets/awdatetimeformatter.cpp | 2 +- sources/awesomewidgets/awfloatformatter.cpp | 2 +- sources/awesomewidgets/awnoformatter.cpp | 2 +- sources/awesomewidgets/awscriptformatter.cpp | 2 +- sources/awesomewidgets/extscript.cpp | 10 +-- sources/awesomewidgets/extscript.h | 2 +- sources/awesomewidgets/graphicalitem.cpp | 53 ++++++++------- sources/awesomewidgets/graphicalitem.h | 4 +- sources/test/CMakeLists.txt | 2 +- sources/test/testabstractformatter.cpp | 67 +++++++++++++++++++ sources/test/testabstractformatter.h | 45 +++++++++++++ sources/test/testdatetimeformatter.cpp | 3 +- 16 files changed, 230 insertions(+), 69 deletions(-) create mode 100644 sources/test/testabstractformatter.cpp create mode 100644 sources/test/testabstractformatter.h diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index 649cd0b..2dc9598 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -145,20 +145,21 @@ void AWFormatterHelper::editItems() } -AWFormatterHelper::FormatterClass +AWAbstractFormatter::FormatterClass AWFormatterHelper::defineFormatterClass(const QString stringType) const { qCDebug(LOG_AW) << "Define formatter class for" << stringType; - FormatterClass formatter = FormatterClass::NoFormat; + AWAbstractFormatter::FormatterClass formatter + = AWAbstractFormatter::FormatterClass::NoFormat; if (stringType == QString("DateTime")) - formatter = FormatterClass::DateTime; + formatter = AWAbstractFormatter::FormatterClass::DateTime; else if (stringType == QString("Float")) - formatter = FormatterClass::Float; + formatter = AWAbstractFormatter::FormatterClass::Float; else if (stringType == QString("NoFormat")) ; else if (stringType == QString("Script")) - formatter = FormatterClass::Script; + formatter = AWAbstractFormatter::FormatterClass::Script; else qCWarning(LOG_AW) << "Unknown formatter" << stringType; @@ -187,19 +188,19 @@ void AWFormatterHelper::initFormatters() switch (metadata.second) { - case FormatterClass::DateTime: + case AWAbstractFormatter::FormatterClass::DateTime: m_formattersClasses[name] = new AWDateTimeFormatter(this, filePath); break; - case FormatterClass::Float: + case AWAbstractFormatter::FormatterClass::Float: m_formattersClasses[name] = new AWFloatFormatter(this, filePath); break; - case FormatterClass::Script: + case AWAbstractFormatter::FormatterClass::Script: m_formattersClasses[name] = new AWScriptFormatter(this, filePath); break; - case FormatterClass::NoFormat: + case AWAbstractFormatter::FormatterClass::NoFormat: m_formattersClasses[name] = new AWNoFormatter(this, filePath); break; } @@ -258,7 +259,7 @@ void AWFormatterHelper::installDirectories() } -QPair +QPair AWFormatterHelper::readMetadata(const QString filePath) const { qCDebug(LOG_AW) << "Read initial parameters from" << filePath; @@ -268,10 +269,10 @@ AWFormatterHelper::readMetadata(const QString filePath) const QString name = settings.value(QString("Name"), filePath).toString(); QString type = settings.value(QString("X-AW-Type"), QString("NoFormat")).toString(); - FormatterClass formatter = defineFormatterClass(type); + AWAbstractFormatter::FormatterClass formatter = defineFormatterClass(type); settings.endGroup(); - return QPair(name, formatter); + return QPair(name, formatter); } @@ -289,15 +290,16 @@ void AWFormatterHelper::doCreateItem() } qCInfo(LOG_AW) << "Selected type" << select; - FormatterClass formatter = defineFormatterClass(select); + AWAbstractFormatter::FormatterClass formatter + = defineFormatterClass(select); switch (formatter) { - case FormatterClass::DateTime: + case AWAbstractFormatter::FormatterClass::DateTime: return createItem(); - case FormatterClass::Float: + case AWAbstractFormatter::FormatterClass::Float: return createItem(); - case FormatterClass::Script: + case AWAbstractFormatter::FormatterClass::Script: return createItem(); - case FormatterClass::NoFormat: + case AWAbstractFormatter::FormatterClass::NoFormat: return createItem(); } } diff --git a/sources/awesome-widget/plugin/awformatterhelper.h b/sources/awesome-widget/plugin/awformatterhelper.h index 5b9f349..5ba16d6 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.h +++ b/sources/awesome-widget/plugin/awformatterhelper.h @@ -21,6 +21,8 @@ #include "abstractextitemaggregator.h" +#include "awabstractformatter.h" + class AWAbstractFormatter; @@ -29,8 +31,6 @@ class AWFormatterHelper : public AbstractExtItemAggregator Q_OBJECT public: - enum class FormatterClass { DateTime, Float, Script, NoFormat }; - explicit AWFormatterHelper(QWidget *parent = nullptr); virtual ~AWFormatterHelper(); QString convert(const QVariant &value, const QString &name) const; @@ -46,12 +46,12 @@ public slots: private: // methods - AWFormatterHelper::FormatterClass + AWAbstractFormatter::FormatterClass defineFormatterClass(const QString stringType) const; void initFormatters(); void initKeys(); void installDirectories(); - QPair + QPair readMetadata(const QString filePath) const; // parent methods void doCreateItem(); diff --git a/sources/awesomewidgets/awabstractformatter.cpp b/sources/awesomewidgets/awabstractformatter.cpp index 18e39ea..123a245 100644 --- a/sources/awesomewidgets/awabstractformatter.cpp +++ b/sources/awesomewidgets/awabstractformatter.cpp @@ -46,20 +46,58 @@ void AWAbstractFormatter::copyDefaults(AbstractExtItem *_other) const QString AWAbstractFormatter::uniq() const { - return QString("%1(%2)").arg(name()).arg(m_type); + return QString("%1(%2)").arg(name()).arg(strType()); } -QString AWAbstractFormatter::type() const +QString AWAbstractFormatter::strType() const +{ + QString value; + switch (m_type) { + case FormatterClass::DateTime: + value = QString("DateTime"); + break; + case FormatterClass::Float: + value = QString("Float"); + break; + case FormatterClass::Script: + value = QString("Script"); + break; + case FormatterClass::NoFormat: + value = QString("NoFormat"); + break; + } + + return value; +} + + +AWAbstractFormatter::FormatterClass AWAbstractFormatter::type() const { return m_type; } -void AWAbstractFormatter::setType(const QString _type) +void AWAbstractFormatter::setStrType(const QString _type) { qCDebug(LOG_LIB) << "Type" << _type; + if (_type == QString("DateTime")) + m_type = FormatterClass::DateTime; + else if (_type == QString("Float")) + m_type = FormatterClass::Float; + else if (_type == QString("Script")) + m_type = FormatterClass::Script; + else + m_type = FormatterClass::NoFormat; +} + + +void AWAbstractFormatter::setType( + const AWAbstractFormatter::FormatterClass _type) +{ + qCDebug(LOG_LIB) << "Type" << static_cast(_type); + m_type = _type; } @@ -71,7 +109,7 @@ void AWAbstractFormatter::readConfiguration() QSettings settings(fileName(), QSettings::IniFormat); settings.beginGroup(QString("Desktop Entry")); - setType(settings.value(QString("X-AW-Type"), m_type).toString()); + setStrType(settings.value(QString("X-AW-Type"), strType()).toString()); settings.endGroup(); } @@ -84,7 +122,7 @@ void AWAbstractFormatter::writeConfiguration() const qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); - settings.setValue(QString("X-AW-Type"), m_type); + settings.setValue(QString("X-AW-Type"), strType()); settings.endGroup(); settings.sync(); diff --git a/sources/awesomewidgets/awabstractformatter.h b/sources/awesomewidgets/awabstractformatter.h index 3fcd8e4..9bb5315 100644 --- a/sources/awesomewidgets/awabstractformatter.h +++ b/sources/awesomewidgets/awabstractformatter.h @@ -24,9 +24,12 @@ class AWAbstractFormatter : public AbstractExtItem { Q_OBJECT - Q_PROPERTY(QString type READ type WRITE setType) + Q_PROPERTY(FormatterClass type READ type WRITE setType) + Q_PROPERTY(QString strType READ strType WRITE setStrType) public: + enum class FormatterClass { DateTime, Float, Script, NoFormat }; + explicit AWAbstractFormatter(QWidget *parent, const QString filePath = QString()); virtual ~AWAbstractFormatter(); @@ -34,8 +37,10 @@ public: void copyDefaults(AbstractExtItem *_other) const; QString uniq() const; // properties - QString type() const; - void setType(const QString _type = QString("NoFormat")); + QString strType() const; + FormatterClass type() const; + void setStrType(const QString type); + void setType(const FormatterClass _type = FormatterClass::NoFormat); public slots: virtual void readConfiguration(); @@ -44,7 +49,7 @@ public slots: private: // properties - QString m_type = QString("NoFormat"); + FormatterClass m_type = FormatterClass::NoFormat; }; diff --git a/sources/awesomewidgets/awdatetimeformatter.cpp b/sources/awesomewidgets/awdatetimeformatter.cpp index 0a99eb2..dfaa437 100644 --- a/sources/awesomewidgets/awdatetimeformatter.cpp +++ b/sources/awesomewidgets/awdatetimeformatter.cpp @@ -115,7 +115,7 @@ int AWDateTimeFormatter::showConfiguration(const QVariant args) return ret; setName(ui->lineEdit_name->text()); setComment(ui->lineEdit_comment->text()); - setType(ui->label_typeValue->text()); + setStrType(ui->label_typeValue->text()); setFormat(ui->lineEdit_format->text()); writeConfiguration(); diff --git a/sources/awesomewidgets/awfloatformatter.cpp b/sources/awesomewidgets/awfloatformatter.cpp index 088bd51..53a0f5a 100644 --- a/sources/awesomewidgets/awfloatformatter.cpp +++ b/sources/awesomewidgets/awfloatformatter.cpp @@ -212,7 +212,7 @@ int AWFloatFormatter::showConfiguration(const QVariant args) return ret; setName(ui->lineEdit_name->text()); setComment(ui->lineEdit_comment->text()); - setType(ui->label_typeValue->text()); + setStrType(ui->label_typeValue->text()); setFormat(ui->comboBox_format->currentText().at(0).toLatin1()); setPrecision(ui->spinBox_precision->value()); setCount(ui->spinBox_width->value()); diff --git a/sources/awesomewidgets/awnoformatter.cpp b/sources/awesomewidgets/awnoformatter.cpp index 1a6aa81..e1e3ddb 100644 --- a/sources/awesomewidgets/awnoformatter.cpp +++ b/sources/awesomewidgets/awnoformatter.cpp @@ -79,7 +79,7 @@ int AWNoFormatter::showConfiguration(const QVariant args) return ret; setName(ui->lineEdit_name->text()); setComment(ui->lineEdit_comment->text()); - setType(ui->label_typeValue->text()); + setStrType(ui->label_typeValue->text()); writeConfiguration(); return ret; diff --git a/sources/awesomewidgets/awscriptformatter.cpp b/sources/awesomewidgets/awscriptformatter.cpp index 3bc23cd..e06ef23 100644 --- a/sources/awesomewidgets/awscriptformatter.cpp +++ b/sources/awesomewidgets/awscriptformatter.cpp @@ -174,7 +174,7 @@ int AWScriptFormatter::showConfiguration(const QVariant args) return ret; setName(ui->lineEdit_name->text()); setComment(ui->lineEdit_comment->text()); - setType(ui->label_typeValue->text()); + setStrType(ui->label_typeValue->text()); setAppendCode(ui->checkBox_appendCode->checkState() == Qt::Checked); setHasReturn(ui->checkBox_hasReturn->checkState() == Qt::Checked); setCode(ui->textEdit_code->toPlainText()); diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index c7823f2..fd5179a 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -168,13 +168,13 @@ void ExtScript::setStrRedirect(const QString _redirect) qCDebug(LOG_LIB) << "Redirect" << _redirect; if (_redirect == QString("stdout2sdterr")) - m_redirect = Redirect::stdout2stderr; + setRedirect(Redirect::stdout2stderr); else if (_redirect == QString("stderr2sdtout")) - m_redirect = Redirect::stderr2stdout; + setRedirect(Redirect::stderr2stdout); else if (_redirect == QString("swap")) - m_redirect = Redirect::swap; + setRedirect(Redirect::swap); else - m_redirect = Redirect::nothing; + setRedirect(Redirect::nothing); } @@ -317,7 +317,7 @@ int ExtScript::showConfiguration(const QVariant args) setExecutable(ui->lineEdit_command->text()); setPrefix(ui->lineEdit_prefix->text()); setActive(ui->checkBox_active->checkState() == Qt::Checked); - setStrRedirect(ui->comboBox_redirect->currentText()); + setRedirect(static_cast(ui->comboBox_redirect->currentIndex())); setInterval(ui->spinBox_interval->value()); // filters updateFilter(QString("color"), diff --git a/sources/awesomewidgets/extscript.h b/sources/awesomewidgets/extscript.h index a5fb1b7..1dca548 100644 --- a/sources/awesomewidgets/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -37,7 +37,7 @@ class ExtScript : public AbstractExtItem Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect) public: - enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap }; + enum class Redirect { stdout2stderr = 0, nothing = 1, stderr2stdout = 2, swap = 3 }; explicit ExtScript(QWidget *parent, const QString filePath = QString()); virtual ~ExtScript(); diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 52354ef..313f022 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -43,8 +43,6 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString filePath) ui->setupUi(this); translate(); - initScene(); - connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this, SLOT(changeValue(int))); connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this, @@ -141,6 +139,31 @@ QString GraphicalItem::image(const QVariant &value) } +void GraphicalItem::initScene() +{ + // cleanup + delete m_helper; + delete m_scene; + + // init scene + m_scene = new QGraphicsScene(); + m_scene->setBackgroundBrush(QBrush(Qt::NoBrush)); + // init view + m_view = new QGraphicsView(m_scene); + m_view->setStyleSheet(QString("background: transparent")); + m_view->setContentsMargins(0, 0, 0, 0); + m_view->setFrameShape(QFrame::NoFrame); + m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_view->resize(m_width + 5, m_height + 5); + + // init helper + m_helper = new GraphicalItemHelper(this, m_scene); + m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height, + m_count); +} + + QString GraphicalItem::bar() const { return m_bar; @@ -433,6 +456,7 @@ void GraphicalItem::readConfiguration() settings.endGroup(); bumpApi(AWGIAPI); + initScene(); } @@ -489,8 +513,8 @@ int GraphicalItem::showConfiguration(const QVariant args) setMinValue(ui->doubleSpinBox_min->value()); setActiveColor(ui->lineEdit_activeColor->text()); setInactiveColor(ui->lineEdit_inactiveColor->text()); - setStrType(ui->comboBox_type->currentText()); - setStrDirection(ui->comboBox_direction->currentText()); + setType(static_cast(ui->comboBox_type->currentIndex())); + setDirection(static_cast(ui->comboBox_direction->currentIndex())); setItemHeight(ui->spinBox_height->value()); setItemWidth(ui->spinBox_width->value()); @@ -590,27 +614,6 @@ void GraphicalItem::changeValue(const int state) } -void GraphicalItem::initScene() -{ - // init scene - m_scene = new QGraphicsScene(); - m_scene->setBackgroundBrush(QBrush(Qt::NoBrush)); - // init view - m_view = new QGraphicsView(m_scene); - m_view->setStyleSheet(QString("background: transparent")); - m_view->setContentsMargins(0, 0, 0, 0); - m_view->setFrameShape(QFrame::NoFrame); - m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_view->resize(m_width + 5, m_height + 5); - - // init helper - m_helper = new GraphicalItemHelper(this, m_scene); - m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height, - m_count); -} - - void GraphicalItem::translate() { ui->label_name->setText(i18n("Name")); diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index b5a6c30..b7bc656 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -50,12 +50,13 @@ class GraphicalItem : public AbstractExtItem public: enum class Direction { LeftToRight = 0, RightToLeft = 1 }; - enum class Type { Horizontal, Vertical, Circle, Graph, Bars }; + enum class Type { Horizontal = 0, Vertical = 1, Circle = 2, Graph = 3, Bars = 4 }; explicit GraphicalItem(QWidget *parent, const QString filePath = QString()); virtual ~GraphicalItem(); GraphicalItem *copy(const QString _fileName, const int _number); QString image(const QVariant &value); + void initScene(); // get methods QString bar() const; QString activeColor() const; @@ -105,7 +106,6 @@ private: QGraphicsScene *m_scene = nullptr; QGraphicsView *m_view = nullptr; Ui::GraphicalItem *ui = nullptr; - void initScene(); void translate(); // properties QString m_bar = QString("cpu"); diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index fd94701..45f5831 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -21,7 +21,7 @@ set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Q ## modules set(TEST_MODULES abstractextitem extquotes extscript extupgrade extweather - datetimeformatter floatformatter noformatter scriptformatter) + abstractformatter datetimeformatter floatformatter noformatter scriptformatter) foreach (TEST_MODULE ${TEST_MODULES}) set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h) set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp) diff --git a/sources/test/testabstractformatter.cpp b/sources/test/testabstractformatter.cpp new file mode 100644 index 0000000..a8c6905 --- /dev/null +++ b/sources/test/testabstractformatter.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testabstractformatter.h" + +#include + +#include "awnoformatter.h" +#include "awtestlibrary.h" + + +void TestAbstractFormatter::initTestCase() +{ + formatter = new AWNoFormatter(nullptr); +} + + +void TestAbstractFormatter::cleanupTestCase() +{ + delete formatter; +} + + +void TestAbstractFormatter::test_values() +{ +} + + +void TestAbstractFormatter::test_type() +{ + QString type = AWTestLibrary::randomString(); + QEXPECT_FAIL("", "Will fail because of invalid format", Continue); + formatter->setStrType(type); + QCOMPARE(formatter->strType(), type); + + formatter->setStrType(QString("NoFormat")); + QCOMPARE(formatter->strType(), QString("NoFormat")); +} + + +void TestAbstractFormatter::test_copy() +{ + AWNoFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1); + + QCOMPARE(newFormatter->type(), formatter->type()); + QCOMPARE(newFormatter->name(), formatter->name()); + + delete newFormatter; +} + + +QTEST_MAIN(TestAbstractFormatter); diff --git a/sources/test/testabstractformatter.h b/sources/test/testabstractformatter.h new file mode 100644 index 0000000..ec94f93 --- /dev/null +++ b/sources/test/testabstractformatter.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTABSTRACTFORMATTER_H +#define TESTABSTRACTFORMATTER_H + +#include + + +class AWNoFormatter; + +class TestAbstractFormatter : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + void test_type(); + void test_copy(); + +private: + AWNoFormatter *formatter = nullptr; +}; + + +#endif /* TESTABSTRACTFORMATTER_H */ diff --git a/sources/test/testdatetimeformatter.cpp b/sources/test/testdatetimeformatter.cpp index c785338..41a1554 100644 --- a/sources/test/testdatetimeformatter.cpp +++ b/sources/test/testdatetimeformatter.cpp @@ -27,7 +27,8 @@ void TestAWDateTimeFormatter::initTestCase() { - format = AWTestLibrary::randomSelect(QString(TIME_KEYS).split(QChar(','))).join(QChar(' ')); + format = AWTestLibrary::randomSelect(QString(TIME_KEYS).split(QChar(','))) + .join(QChar(' ')); formatter = new AWDateTimeFormatter(nullptr); formatter->setFormat(format); From 620c4bd1e3a98c008b269cfde68dd0e0363a6092 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 2 Jun 2016 11:09:02 +0300 Subject: [PATCH 23/32] Return to owm weather provider Since yahoo support already exists, so I've added new option X-AW-Provider (apiver 3). Added tests for these cases --- sources/awesomewidgets/abstractextitem.cpp | 4 +- .../awesomewidgets/abstractweatherprovider.h | 47 ++++++ .../awesomewidgets-extweather-ids.json | 131 +++++++++++++++- sources/awesomewidgets/extscript.h | 7 +- sources/awesomewidgets/extweather.cpp | 144 +++++++++--------- sources/awesomewidgets/extweather.h | 19 ++- sources/awesomewidgets/extweather.ui | 42 ++++- sources/awesomewidgets/graphicalitem.cpp | 3 +- sources/awesomewidgets/graphicalitem.h | 8 +- sources/awesomewidgets/owmweatherprovider.cpp | 112 ++++++++++++++ sources/awesomewidgets/owmweatherprovider.h | 43 ++++++ sources/awesomewidgets/weather/01d.png | Bin 0 -> 2859 bytes sources/awesomewidgets/weather/02d.png | Bin 0 -> 2969 bytes sources/awesomewidgets/weather/03d.png | Bin 0 -> 2565 bytes sources/awesomewidgets/weather/04d.png | Bin 0 -> 2773 bytes sources/awesomewidgets/weather/09d.png | Bin 0 -> 3818 bytes sources/awesomewidgets/weather/10d.png | Bin 0 -> 3793 bytes sources/awesomewidgets/weather/11d.png | Bin 0 -> 3777 bytes sources/awesomewidgets/weather/13d.png | Bin 0 -> 3901 bytes sources/awesomewidgets/weather/50d.png | Bin 0 -> 3328 bytes sources/awesomewidgets/weather/london.desktop | 3 +- .../awesomewidgets/yahooweatherprovider.cpp | 126 +++++++++++++++ sources/awesomewidgets/yahooweatherprovider.h | 47 ++++++ sources/test/testextweather.cpp | 90 +++++------ sources/test/testextweather.h | 4 +- sources/version.h.in | 5 +- 26 files changed, 704 insertions(+), 131 deletions(-) create mode 100644 sources/awesomewidgets/abstractweatherprovider.h create mode 100644 sources/awesomewidgets/owmweatherprovider.cpp create mode 100644 sources/awesomewidgets/owmweatherprovider.h create mode 100644 sources/awesomewidgets/weather/01d.png create mode 100644 sources/awesomewidgets/weather/02d.png create mode 100644 sources/awesomewidgets/weather/03d.png create mode 100644 sources/awesomewidgets/weather/04d.png create mode 100644 sources/awesomewidgets/weather/09d.png create mode 100644 sources/awesomewidgets/weather/10d.png create mode 100644 sources/awesomewidgets/weather/11d.png create mode 100644 sources/awesomewidgets/weather/13d.png create mode 100644 sources/awesomewidgets/weather/50d.png create mode 100644 sources/awesomewidgets/yahooweatherprovider.cpp create mode 100644 sources/awesomewidgets/yahooweatherprovider.h diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index 62e0e09..787acc0 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -178,7 +178,7 @@ void AbstractExtItem::setName(const QString _name) void AbstractExtItem::setNumber(int _number) { qCDebug(LOG_LIB) << "Number" << _number; - if (_number == -1) + if (_number == -1) { _number = []() { qCWarning(LOG_LIB) << "Number is empty, generate new one"; qsrand(QTime::currentTime().msec()); @@ -186,6 +186,8 @@ void AbstractExtItem::setNumber(int _number) qCInfo(LOG_LIB) << "Generated number is" << n; return n; }(); + writeConfiguration(); + } m_number = _number; } diff --git a/sources/awesomewidgets/abstractweatherprovider.h b/sources/awesomewidgets/abstractweatherprovider.h new file mode 100644 index 0000000..9582cac --- /dev/null +++ b/sources/awesomewidgets/abstractweatherprovider.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef ABSTRACTWEATHERPROVIDER_H +#define ABSTRACTWEATHERPROVIDER_H + +#include +#include + + +class AbstractWeatherProvider : public QObject +{ + Q_OBJECT + Q_PROPERTY(int number READ number) + +public: + explicit AbstractWeatherProvider(QObject *parent, const int number) + : QObject(parent) + , m_number(number){}; + virtual ~AbstractWeatherProvider(){}; + virtual void initUrl(const QString city, const QString country, + const int ts) + = 0; + virtual QVariantHash parse(const QVariantMap &json) const = 0; + virtual QUrl url() const = 0; + int number() const { return m_number; }; + +private: + int m_number; +}; + + +#endif /* ABSTRACTWEATHERPROVIDER_H */ diff --git a/sources/awesomewidgets/awesomewidgets-extweather-ids.json b/sources/awesomewidgets/awesomewidgets-extweather-ids.json index 69f9085..e8ec649 100644 --- a/sources/awesomewidgets/awesomewidgets-extweather-ids.json +++ b/sources/awesomewidgets/awesomewidgets-extweather-ids.json @@ -1,11 +1,75 @@ { - "__url": "https://developer.yahoo.com/weather/documentation.html", + "__url-yahoo": "https://developer.yahoo.com/weather/documentation.html", + "__url-owm": "http://openweathermap.org/weather-conditions", "image": { "__comment": "should be described as html image with full path inside", "default": "", + "800": "", + + "801": "", + + "802": "", + "803": "", + + "804": "", + + "300": "", + "301": "", + "302": "", + "310": "", + "311": "", + "312": "", + "313": "", + "314": "", + "321": "", + "520": "", + "521": "", + "522": "", + "531": "", + + "500": "", + "501": "", + "502": "", + "503": "", + "504": "", + + "200": "", + "201": "", + "202": "", + "210": "", + "211": "", + "212": "", + "221": "", + "230": "", + "231": "", + "232": "", + + "511": "", + "600": "", + "601": "", + "602": "", + "611": "", + "612": "", + "615": "", + "616": "", + "620": "", + "621": "", + "622": "", + + "701": "", + "711": "", + "721": "", + "731": "", + "741": "", + "751": "", + "761": "", + "762": "", + "771": "", + "781": "", + "0": "", "1": "", "2": "", @@ -59,8 +123,71 @@ "text": { "default": "\u2604", - "3200": "\u2604", + "800": "\u2600", + + "801": "\u26C5", + + "802": "\u2601", + "803": "\u2601", + + "804": "\u2601", + + "300": "\u2602", + "301": "\u2602", + "302": "\u2602", + "310": "\u2602", + "311": "\u2602", + "312": "\u2602", + "313": "\u2602", + "314": "\u2602", + "321": "\u2602", + "520": "\u2602", + "521": "\u2602", + "522": "\u2602", + "531": "\u2602", + + "500": "\u2614", + "501": "\u2614", + "502": "\u2614", + "503": "\u2614", + "504": "\u2614", + + "200": "\u2608", + "201": "\u2608", + "202": "\u2608", + "210": "\u2608", + "211": "\u2608", + "212": "\u2608", + "221": "\u2608", + "230": "\u2608", + "231": "\u2608", + "232": "\u2608", + + "511": "\u2603", + "600": "\u2603", + "601": "\u2603", + "602": "\u2603", + "611": "\u2603", + "612": "\u2603", + "615": "\u2603", + "616": "\u2603", + "620": "\u2603", + "621": "\u2603", + "622": "\u2603", + + "701": "\u26C5", + "711": "\u26C5", + "721": "\u26C5", + "731": "\u26C5", + "741": "\u26C5", + "751": "\u26C5", + "761": "\u26C5", + "762": "\u26C5", + "771": "\u26C5", + "781": "\u26C5", + + "3200": "\u2604", "0": "\u2604", "1": "\u2604", "2": "\u2604", diff --git a/sources/awesomewidgets/extscript.h b/sources/awesomewidgets/extscript.h index 1dca548..5189a63 100644 --- a/sources/awesomewidgets/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -37,7 +37,12 @@ class ExtScript : public AbstractExtItem Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect) public: - enum class Redirect { stdout2stderr = 0, nothing = 1, stderr2stdout = 2, swap = 3 }; + enum class Redirect { + stdout2stderr = 0, + nothing = 1, + stderr2stdout = 2, + swap = 3 + }; explicit ExtScript(QWidget *parent, const QString filePath = QString()); virtual ~ExtScript(); diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 0aabd44..456d893 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -27,11 +27,12 @@ #include #include #include -#include #include #include "awdebug.h" +#include "owmweatherprovider.h" +#include "yahooweatherprovider.h" ExtWeather::ExtWeather(QWidget *parent, const QString filePath) @@ -68,6 +69,7 @@ ExtWeather::~ExtWeather() SLOT(weatherReplyReceived(QNetworkReply *))); m_manager->deleteLater(); + delete m_providerObject; delete ui; } @@ -83,6 +85,7 @@ ExtWeather *ExtWeather::copy(const QString _fileName, const int _number) item->setCountry(country()); item->setImage(image()); item->setNumber(_number); + item->setProvider(provider()); item->setTs(ts()); return item; @@ -117,6 +120,28 @@ bool ExtWeather::image() const } +ExtWeather::Provider ExtWeather::provider() const +{ + return m_provider; +} + + +QString ExtWeather::strProvider() const +{ + QString value; + switch (m_provider) { + case Provider::OWM: + value = QString("OWM"); + break; + case Provider::Yahoo: + value = QString("Yahoo"); + break; + } + + return value; +} + + int ExtWeather::ts() const { return m_ts; @@ -134,7 +159,7 @@ void ExtWeather::setCity(const QString _city) qCDebug(LOG_LIB) << "City" << _city; m_city = _city; - initUrl(); + initProvider(); } @@ -143,7 +168,7 @@ void ExtWeather::setCountry(const QString _country) qCDebug(LOG_LIB) << "Country" << _country; m_country = _country; - initUrl(); + initProvider(); } @@ -155,11 +180,32 @@ void ExtWeather::setImage(const bool _image) } +void ExtWeather::setProvider(const Provider _provider) +{ + qCDebug(LOG_LIB) << "Provider" << static_cast(_provider); + + m_provider = _provider; + initProvider(); +} + + +void ExtWeather::setStrProvider(const QString _provider) +{ + qCDebug(LOG_LIB) << "Provider" << _provider; + + if (_provider == QString("Yahoo")) + setProvider(Provider::Yahoo); + else + setProvider(Provider::OWM); +} + + void ExtWeather::setTs(const int _ts) { qCDebug(LOG_LIB) << "Timestamp" << _ts; m_ts = _ts; + initProvider(); } @@ -176,16 +222,11 @@ void ExtWeather::readConfiguration() // api == 2 setImage(settings.value(QString("X-AW-Image"), QVariant(m_image)).toString() == QString("true")); + // api == 3 + setStrProvider( + settings.value(QString("X-AW-Provider"), strProvider()).toString()); settings.endGroup(); - // update for current API - if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) { - qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" - << AWEWAPI; - setApiVersion(AWEWAPI); - writeConfiguration(); - } - bumpApi(AWEWAPI); } @@ -224,7 +265,8 @@ QVariantHash ExtWeather::run() if (times == 1) { qCInfo(LOG_LIB) << "Send request"; isRunning = true; - QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url)); + QNetworkReply *reply + = m_manager->get(QNetworkRequest(m_providerObject->url())); new QReplyTimeout(reply, REQUEST_TIMEOUT); } @@ -244,6 +286,7 @@ int ExtWeather::showConfiguration(const QVariant args) ui->lineEdit_name->setText(name()); ui->lineEdit_comment->setText(comment()); ui->label_numberValue->setText(QString("%1").arg(number())); + ui->comboBox_provider->setCurrentIndex(static_cast(m_provider)); ui->lineEdit_city->setText(m_city); ui->lineEdit_country->setText(m_country); ui->spinBox_timestamp->setValue(m_ts); @@ -261,6 +304,7 @@ int ExtWeather::showConfiguration(const QVariant args) setApiVersion(AWEWAPI); setCity(ui->lineEdit_city->text()); setCountry(ui->lineEdit_country->text()); + setProvider(static_cast(ui->comboBox_provider->currentIndex())); setTs(ui->spinBox_timestamp->value()); setImage(ui->checkBox_image->checkState() == Qt::Checked); setActive(ui->checkBox_active->checkState() == Qt::Checked); @@ -282,6 +326,7 @@ void ExtWeather::writeConfiguration() const settings.setValue(QString("X-AW-City"), m_city); settings.setValue(QString("X-AW-Country"), m_country); settings.setValue(QString("X-AW-Image"), m_image); + settings.setValue(QString("X-AW-Provider"), strProvider()); settings.setValue(QString("X-AW-TS"), m_ts); settings.endGroup(); @@ -304,69 +349,31 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply) return; } - // convert to map - QVariantMap json = jsonDoc.toVariant().toMap()[QString("query")].toMap(); - if (json[QString("count")].toInt() != 1) { - qCWarning(LOG_LIB) << "Found data count" - << json[QString("count")].toInt() << "is not 1"; + QVariantHash data = m_providerObject->parse(jsonDoc.toVariant().toMap()); + if (data.isEmpty()) return; - } - QVariantMap results - = json[QString("results")].toMap()[QString("channel")].toMap(); - QVariantMap item = results[QString("item")].toMap(); - - if (m_ts == 0) { - // current weather - int id = item[QString("condition")].toMap()[QString("code")].toInt(); - values[tag(QString("weatherId"))] = id; - values[tag(QString("weather"))] = weatherFromInt(id); - values[tag(QString("temperature"))] - = item[QString("condition")].toMap()[QString("temp")].toInt(); - values[tag(QString("timestamp"))] - = item[QString("condition")].toMap()[QString("date")].toString(); - values[tag(QString("humidity"))] = results[QString("atmosphere")] - .toMap()[QString("humidity")] - .toInt(); - values[tag(QString("pressure"))] - = static_cast(results[QString("atmosphere")] - .toMap()[QString("pressure")] - .toFloat()); - } else { - // forecast weather - QVariantList weatherList = item[QString("forecast")].toList(); - QVariantMap weatherMap = weatherList.count() < m_ts - ? weatherList.last().toMap() - : weatherList.at(m_ts).toMap(); - int id = weatherMap[QString("code")].toInt(); - values[tag(QString("weatherId"))] = id; - values[tag(QString("weather"))] = weatherFromInt(id); - values[tag(QString("timestamp"))] - = weatherMap[QString("date")].toString(); - // yahoo provides high and low temperatures. Lets calculate average one - values[tag(QString("temperature"))] - = (weatherMap[QString("high")].toFloat() - + weatherMap[QString("low")].toFloat()) - / 2.0; - // ... and no forecast data for humidity and pressure - values[tag(QString("humidity"))] = 0; - values[tag(QString("pressure"))] = 0.0; - } + values = data; + values[tag(QString("weather"))] + = weatherFromInt(values[tag(QString("weatherId"))].toInt()); emit(dataReceived(values)); } -void ExtWeather::initUrl() +void ExtWeather::initProvider() { - // init query - m_url = QUrl(YAHOO_WEATHER_URL); - QUrlQuery params; - params.addQueryItem(QString("format"), QString("json")); - params.addQueryItem(QString("env"), - QString("store://datatables.org/alltableswithkeys")); - params.addQueryItem(QString("q"), - QString(YAHOO_WEATHER_QUERY).arg(m_city, m_country)); - m_url.setQuery(params); + delete m_providerObject; + + switch (m_provider) { + case Provider::OWM: + m_providerObject = new OWMWeatherProvider(this, number()); + break; + case Provider::Yahoo: + m_providerObject = new YahooWeatherProvider(this, number()); + break; + } + + return m_providerObject->initUrl(m_city, m_country, m_ts); } @@ -375,6 +382,7 @@ void ExtWeather::translate() ui->label_name->setText(i18n("Name")); ui->label_comment->setText(i18n("Comment")); ui->label_number->setText(i18n("Tag")); + ui->label_provider->setText(i18n("Provider")); ui->label_city->setText(i18n("City")); ui->label_country->setText(i18n("Country")); ui->label_timestamp->setText(i18n("Timestamp")); diff --git a/sources/awesomewidgets/extweather.h b/sources/awesomewidgets/extweather.h index 6b60583..8ee174c 100644 --- a/sources/awesomewidgets/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -22,12 +22,8 @@ #include "abstractextitem.h" -#define YAHOO_WEATHER_URL "https://query.yahooapis.com/v1/public/yql" -#define YAHOO_WEATHER_QUERY \ - "select * from weather.forecast where u='c' and woeid in (select woeid " \ - "from geo.places(1) where text='%1, %2')" - +class AbstractWeatherProvider; namespace Ui { class ExtWeather; @@ -39,9 +35,13 @@ class ExtWeather : public AbstractExtItem Q_PROPERTY(QString city READ city WRITE setCity) Q_PROPERTY(QString country READ country WRITE setCountry) Q_PROPERTY(bool image READ image WRITE setImage) + Q_PROPERTY(Provider povider READ provider WRITE setProvider) + Q_PROPERTY(QString strPovider READ strProvider WRITE setStrProvider) Q_PROPERTY(int ts READ ts WRITE setTs) public: + enum class Provider { OWM = 0, Yahoo = 1 }; + explicit ExtWeather(QWidget *parent, const QString filePath = QString()); virtual ~ExtWeather(); ExtWeather *copy(const QString _fileName, const int _number); @@ -50,12 +50,16 @@ public: QString city() const; QString country() const; bool image() const; + Provider provider() const; + QString strProvider() const; 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); public slots: @@ -70,15 +74,16 @@ private slots: private: QNetworkAccessManager *m_manager = nullptr; - QUrl m_url; + AbstractWeatherProvider *m_providerObject = nullptr; bool isRunning = false; Ui::ExtWeather *ui = nullptr; - void initUrl(); + void initProvider(); void translate(); // properties QString m_city = QString("London"); QString m_country = QString("uk"); bool m_image = false; + Provider m_provider = Provider::OWM; int m_ts = 0; QVariantMap m_jsonMap = QVariantMap(); // values diff --git a/sources/awesomewidgets/extweather.ui b/sources/awesomewidgets/extweather.ui index 5015643..0b5bb43 100644 --- a/sources/awesomewidgets/extweather.ui +++ b/sources/awesomewidgets/extweather.ui @@ -7,7 +7,7 @@ 0 0 420 - 301 + 333 @@ -81,6 +81,46 @@ + + + + + + + 0 + 0 + + + + Provider + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + OWM + + + + + Yahoo + + + + + + diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 313f022..d236cdc 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -514,7 +514,8 @@ int GraphicalItem::showConfiguration(const QVariant args) setActiveColor(ui->lineEdit_activeColor->text()); setInactiveColor(ui->lineEdit_inactiveColor->text()); setType(static_cast(ui->comboBox_type->currentIndex())); - setDirection(static_cast(ui->comboBox_direction->currentIndex())); + setDirection( + static_cast(ui->comboBox_direction->currentIndex())); setItemHeight(ui->spinBox_height->value()); setItemWidth(ui->spinBox_width->value()); diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index b7bc656..cbfe3a2 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -50,7 +50,13 @@ class GraphicalItem : public AbstractExtItem public: enum class Direction { LeftToRight = 0, RightToLeft = 1 }; - enum class Type { Horizontal = 0, Vertical = 1, Circle = 2, Graph = 3, Bars = 4 }; + enum class Type { + Horizontal = 0, + Vertical = 1, + Circle = 2, + Graph = 3, + Bars = 4 + }; explicit GraphicalItem(QWidget *parent, const QString filePath = QString()); virtual ~GraphicalItem(); diff --git a/sources/awesomewidgets/owmweatherprovider.cpp b/sources/awesomewidgets/owmweatherprovider.cpp new file mode 100644 index 0000000..f3057b9 --- /dev/null +++ b/sources/awesomewidgets/owmweatherprovider.cpp @@ -0,0 +1,112 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "owmweatherprovider.h" + +#include +#include + +#include "awdebug.h" + + +OWMWeatherProvider::OWMWeatherProvider(QObject *parent, const int number) + : AbstractWeatherProvider(parent, number) +{ + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; +} + + +OWMWeatherProvider::~OWMWeatherProvider() +{ + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; +} + + +void OWMWeatherProvider::initUrl(const QString city, const QString country, + const int ts) +{ + qCDebug(LOG_LIB) << "Init query for" << city << country << "with ts" << ts; + + m_ts = ts; + + if (m_ts == 0) + m_url = QUrl(OWM_WEATHER_URL); + 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")); + m_url.setQuery(params); +} + + +QVariantHash OWMWeatherProvider::parse(const QVariantMap &json) const +{ + qCDebug(LOG_LIB) << "Parse json" << json; + + if (json[QString("cod")].toInt() != 200) { + qCWarning(LOG_LIB) << "Invalid OpenWeatherMap return code" + << json[QString("cod")].toInt(); + return QVariantHash(); + } + + if (m_ts == 0) { + return parseSingleJson(json); + } else { + QVariantList list = json[QString("list")].toList(); + return parseSingleJson(list.count() <= m_ts ? list.at(m_ts - 1).toMap() + : list.last().toMap()); + } +} + + +QUrl OWMWeatherProvider::url() const +{ + return m_url; +} + + +QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &json) const +{ + qCDebug(LOG_LIB) << "Single json data" << json; + + QVariantHash output; + + // weather status + QVariantList weather = json[QString("weather")].toList(); + if (!weather.isEmpty()) { + int id = weather.first().toMap()[QString("id")].toInt(); + output[QString("weatherId%1").arg(number())] = id; + } + + // main data + QVariantMap mainWeather = json[QString("main")].toMap(); + if (!weather.isEmpty()) { + output[QString("humidity%1").arg(number())] + = mainWeather[QString("humidity")].toFloat(); + output[QString("pressure%1").arg(number())] + = mainWeather[QString("pressure")].toFloat(); + output[QString("temperature%1").arg(number())] + = mainWeather[QString("temp")].toFloat(); + } + + // timestamp + output[QString("timestamp%1").arg(number())] + = QDateTime::fromTime_t(json[QString("dt")].toUInt()).toUTC(); + + return output; +} diff --git a/sources/awesomewidgets/owmweatherprovider.h b/sources/awesomewidgets/owmweatherprovider.h new file mode 100644 index 0000000..6f8b639 --- /dev/null +++ b/sources/awesomewidgets/owmweatherprovider.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef OWMWEATHERPROVIDER_H +#define OWMWEATHERPROVIDER_H + +#include "abstractweatherprovider.h" + +#define OWM_WEATHER_URL "http://arcanis.me/weather" +#define OWM_FORECAST_URL "http://arcanis.me/forecast" + + +class OWMWeatherProvider : public AbstractWeatherProvider +{ +public: + 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; + QUrl url() const; + +private: + QVariantHash parseSingleJson(const QVariantMap &json) const; + int m_ts = 0; + QUrl m_url; +}; + + +#endif /* OWMWEATHERPROVIDER_H */ diff --git a/sources/awesomewidgets/weather/01d.png b/sources/awesomewidgets/weather/01d.png new file mode 100644 index 0000000000000000000000000000000000000000..7d2f792c324408eaccb8a13e0cd16fd502dd51cf GIT binary patch literal 2859 zcmb_ed00~U8YWZAt;dpF$c#`cHx7$LGC-QB>A2;BQrU!n$i!lRikgku&1G85Cew0B zN6Tifg$#_-(Q^xeUB%gl(sZAP_A*#kB--Hro&aQFG_`1&RYb+zAW; z4@qYVf>}rjFAVgCK!_3o_{d|4>2L{;%NG$OB!tp~06r^V00CFJi1(2Yfgav)M}d$9 z$05;341%l)hr@|NW(dKD;yf1)zL5~2VsRJ&03stJk&#%WK*$Erc6N3E3Ikv;HlT-% zD2gwpOKkWe)7c~+^H5kKhL95`<_P$3MP7QaAY4pBAQXk>KXZNZ!sZL{MRTk`et?7? z2B48BU_LV#NCY_&JOoTmNEC%GW|1){G{y#nx5423&{zTrPuPMZ0*ib;)l^113R!fq zK5m2yLz)C5ZqM=3j|6?oWgnZKVGr9`PmwXi{ z!ArWVp@(zD2=XR| z1>6VRT|%({ZHLFh55OtlO!7oxP;(?W`Ln-2m-BhnS@iQ_MBt0Y{`&CDqTqHTYl8dX zSy|YJ1eYKeOxVU$LKRQ2h z4{pfLD(wk*f9^Z$HFfRnj*Sfs)CwEXuA3WvK4YkQr{&QkB&XE8Q$^(t91gV{y(VM7 zC^4lD{HvqSL%;cl?A&Lf2jdg5sUtZeqb_5wZOudtxS6&CdYa_lj?i?#GPw;Zub0E(0B?=Ve%sL@oahpEhEsV`)DvKKK2m z7|vxbgSHBgUGyR6Xk43Ur;Zkfm1Nmyr^n&+Elg&bNeFN_rb#fHZ)u&BL{(T^lrWMkXh{Ood*do-_}7-XM<~HrQYB&g; zBzvg*)=RI7!(%;H^Rlk@UocEIqY*Q!D89b*L%Qlrfr@&nS}!lIYqM^!neiU^*U^c! z5J!V0RlV^`twMj+=}bO~d)j~K+(Re-CV&5^EYgGZWX_2RrZ(4$MlO@h}YaLme*yb-Z5Qe`eAG!BGc#Hj?q;o9N$ab z)RBHm`SFDlRPWZN?UG;30UKah1tv5w8Bh;q6R@0+R;Wg21hPi$x;&RR{ts8)D z=E;Ho=xtGHvY*;vHW_VmEI|5=P{pY)j*ew`SJt`_p)J@plQhUsak@ruV-pL;Yh9CB zUYAgbjX%0eZcupXQ8a1)_zT%LX(nSU<&o!Adu1z{`X=hI!m~Eqo7aDWhLnGQfe6PP zX58)#s;9a9Zu}(ns}(8G@!H4ojHp65rzQs~D=lun^=r(@|LyGkD#E*Zby`M5!kWev zXiF)@J$vfRVB461NnZCzDKR6WwGqaS)mCNO-Y85ALcDUu=p&C?4z6 zDRDw&m~ML()ltYhlH7m9`e96zU2x@E_K}@h#DWnaYRe?#I!sMlW7%NlcBy@^N`uj+ zKD~>1k+`TDy9>sy7ByV^dTS=tSnJC5w-(ZJtDbd!LRrjr(bqR!-Tg`}D%%SY0qcbl zQ~Np6Y%N|uM>sFHM{woDgZe1y zV46$jeNpHiN7mz}t*WbBen~81nvUPicd-r_y$7sWJ*=_)!)a-^HlC7!KJ*&@ihm-Y zTSa(K;`4mvYdU!en@g>h4d`7CjNH@wVq zVZuCd<#{fC*b?_zht#{a+21l9QZI(=JahDrNg8L%mYo-^m1&-eQI%0{hr!EWu0{}pm z>O~2H?s&zesSbUcIPWflZdwAbFcAP~8z?R%ASVwF0BSz0;7~Bs*M~&sbI~*gKZ1!C za|Mt$062~Sc(3=w~8UzI-3?@E49vyFk<_n`RI3kgV!QwG^yfx%uElS{lG_f^L zWHy=PQyvOaL>ICIAdAmKD)Q1I__3f93Z*DC{h8{ME0`|C6HT##_+i8}0S1T0Vx}`g zfsPPIk}sdZicFx;KqeWF#o?{71ZzAY7-vJm5=aDsBW9M*=b97I?m{LF-q&5@kj+n2o84M?EVL?n0pA$RbPry$F%mil#xbwLJAyXt$6o5pSNHP38LTU!tGJg2Phm5)y~Ti*iDVtr^TnS}X@dk(bh!A%mdZ zB?S36B7uP1iljg@$rXW+=4fd0Cx3qq>&vW@=$FMDF<&+I?ZY#PLfefDgJ%5GrX<6P zboDi$z51F;aSe`E8(5R*lN(~_{I~$)-9#@1;!^i|aqKn7dTnisu{u7un4Iw|sdsO| zZT$$owmGHN2c+5k)1I$qOXz2oeG zpylA1bNggnYt^X%_G@rt;<>7!pw!1db3F`Y&2sl&s= zhFu?F)D%zi#=}0ES4x-blr7)3v!^O4JNvnA%i0?I_0G>~@BA|Syz6++$PHC`b6U+I z8Mpk9$@YHt1Io$8-8%9t>CSWiH77hIN~^r>Vmh^`hogJEa~^vnWt7z9ZwKSzEa$?VVZmN< zztSqUX{r5pmUSn}l>5%6HTe6Vbldhj?6(*s{2njl^k}D9wF&>|+qn7f?pXf(hvkNf zxP2)aQR&Jjg0@@2{j*RA|BX8g%5Y`5%gv-kot?LPeJnDY*q)(p#M)!*5xva3a`;($ zqt1pU9sx)Iji`G$N78&6h!rk03|6uo07~;}BmI{-_?&r{nGeV1YIr9caXKAjNlfdN zcn;BB0#SvMfFQVk0rESla&hbXt=`_==RWBDFa1)f2 zOL{Rpq8ebIPX<3;;a7Fh@4VBtIwh)4ZE0a{_2(pd|7XX{1Qu+=q48@v_kB=|geC}E58l#^nVNcTa)4Clyjus07unxPfdZAT!w0c{l znM%6hZ}*%^<2 z^=DgK)~3o8nihEdmHL%84IQygBVaDEKZ+6(T;rj+OCI>%RxQn7I3xV(MpOho^kLMA#4yR0lr(qL zz6{BRY>k^eR^_eCM{@-69=jZ*zy73cK-q=P1xw5k8Q3A$mjMDm|bvOXgK> z-O;{4=#Ox@yBTRERiQ6ZE7Y=TYpqr45bK-EkM3XZIF4igdB}zJq7cBTonJiPwFTP-OV_T#A=Hi!8@o|!|(+zn`*U+<% zBeC1-2jUVxF3bPPzQyWS3n0mOw}C;X^#ee5e6F7LIB>5%@$eGM#czlm!&s!AYU#me zDoly;%R}wW4|(U4?-=`BG78r-c2E^CYu&F$WEP#>5WY+P!U(1$y2`7pY}VFw*Ut0n z1*0F8&hId};vnhFfO~dqKXXdP6|Z=INJ4b8nvahOFS#%8ysXsS-E9*0p;&u-EkX-E zkGH3}r_e&4m)+#%;-RB{<=WujAmZl!wM7|PsgM6!6`deov2W)vQ+jU1Rd_S6P(``^ z@KugIU#@3!tO2F83TvnL>Qqnf?iO`jw(9Gcu&{;XJ-t%Nv7SfaAtCdk${$#kab2)l zwlA0E3$)H;Xx9B`dRfCPB8tl$*w%6BwR)G6AR!?^o!qDmwWa;?xDN#zigjPIx;60X zlDjc2;g8$e+Uyn&XshEFpQw!RtxJ5m#@G^`tBLm?c m4wsEm2Q|&UVeCz#J>575!#p{#e6!+@H$YwKN0GU0`tfgi34I*^ literal 0 HcmV?d00001 diff --git a/sources/awesomewidgets/weather/03d.png b/sources/awesomewidgets/weather/03d.png new file mode 100644 index 0000000000000000000000000000000000000000..8a4a8e9fa75b5b860ff33f84cd6bf65a9ad04e54 GIT binary patch literal 2565 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nC-&H|6fVg?3oVGw3ym^DX&fq~U0 zGbExU!q>+tIX_n~F(p4KRj(qq0H~UQ!KT6r$jnVGNmQuF&B-gas<2f8tFQvHLBje< z3ScEA*|tg%z5xo(`9-M;rh0~YMoM;E3JMA~MJZ`kK`w4k?LeNbQbtKhft9{~d3m{B zxv^e;QM$gNrKP35fswwEkuFe$ZgFK^Nn(X=Ua>O75STeGsl~}fnFS@8`FRQ;a}$&D zOG|8(lt3220o0wj1#pYv;5=hU{aFdS+1b8CnV*`x_BM_jXmG!D8x zRw`Az%UZayTWQM$*YHIwE*yEH7h^R&7Oqp7-Ozo>EAy?B$R$2Eb=9LsQWl;~ne#pE z-u~w{dp*S-SLeSwb6DtJ>&)_<_V;b?|2${;y{PZ;gufSl{B>ZmbaDBY@8#Cz($(^$ zQDci!k&bcB5{}KUoo?;O7ZKe3Kq0TR^lNa%=D8bnt8bNch;(=EmuxGZE%3R2;zYr< z-044@3g+5K&A0jaJVWVNyqL?wB`ThUr?+)JzR~iWHEGter#H^kCRvJmA6|ODR`+EA zqw&P4Q>VV1A+mq&xi4ZD+4>&eo5j?hDSaYhnrlU$`l?lV=3AeIA3l88zBFU?^D;Fh z0WbN^JwLkVO!Yp{(6Q)&kfYHGgMT>z#|?PO_bfE~XRQ1A$b$zDlKr!-W~7{*nE!N6 zjMHJoB^?THgdC$Mu>32KQR;c}X=lvdxc}=mMOdoKiP^Jl^>PSmSo-?$ZN_j%WrUkDLhHDTTB^`*Z5xjAZ-x{_pyIyAbHBDa;M zW@o>?_T)Q+wFX7{8-Q8`odn%YJUTv83SPWmAQ!`Hx;$?AkEN z>C=shMs=nyroQU6wLg>BpIBXNP;+%|$`9@(CoWwIGP^nXkK?&i|F2(EVnj3Iwp6RB zwuJIN;yP{OV6kLj=K0rKZ;6C#fBrV<(JzOt6PZ7Q_UYGiy}IbqD(YtzLmaT&YHJ}=F!w>LHWw(IJ@y~+DrR$aYi{&7bMufBN> zn@Z;PjsWKg9C3>#H0LP>NNWkS7;^02wJ0QO>)V^1ot^F_wX4^^Uo3df*WG|;!<9#g zb)5HJ3G6rQdma;WMw};JrDeL#wh%4TB87=N0wZI3svrJ%#-Z{wnB_qCd4m#j$Gr^J za~D5sJIe6eYD%`I*#Df}{~vfB*!SD6CSK`k)>pZfAltcq%Qu7^QhiqSzP4d*-({so z`}j7jVpM$NJ?X-iL*G=5OiV)J;^Ou(Z<_C_P{Fcm-Y2HF$7F;K&1cZhJZy43^lId% zLtj;yX20FKbt|_+0#C#84~iappRwNQwLIf~Mx5hywz0AC>$n;FLc8yu4fI#zZBZIPPNqB_1>Gr5@}PN&FZ!qgu)J&=)=KZ~FqD@Jdej{z~6x Rf*Poy=IQF^vd$@?2>@Ou)Or8_ literal 0 HcmV?d00001 diff --git a/sources/awesomewidgets/weather/04d.png b/sources/awesomewidgets/weather/04d.png new file mode 100644 index 0000000000000000000000000000000000000000..4677b8596acb4bed4fc8c62633e673567e8af6db GIT binary patch literal 2773 zcmb_eX;f2Z8jb}aEDC~#O&|tlSZo#|5V?e~1tBPsrhr654M~77*}S=s(6WSvR%8<> zSV61`)@9tPELs#5XDmWtPzGeF3L-lKg;q(AsB;q#0oyZwnsaXMz0bRS&+~ond+q`H zcK=nn=DG+3Vihfb%7E`g)rHi8|E)YTF2gq+aR5_-K*XqkX7lmIdhjM@W$pH(m(gI2ph|M0+s2hq{K zB9M!A!8zfG7>X_$jV6PfXn;Z8G9M1Vd0=88NDScdQmGUt-Gmc?F?c68H#aD1=xttWaVzm*ia@Dp$e=d18ns5~5XkSy7^R$OD5>6=y9ND6V<1Q1Aon+qAg%;$Ygb+j+Y zWkDh^L?q%<=sX#hFHpUri8umoK6bIkd@vcWVzG#oS~Aswmf`=8EyRm{uj>-JD$9p_ zRVWY)^0=_hDm5uiWc&x%B8F-klfjjU`0;9g5^+9YF}OUyS0oUFT!}YArD$u(=vE@RQP*4Wno#1!TEr{Ol+=<_a|bjEFX%kLIL%e2&eJ{T;ZG^1Ty{) z4U6ch?Y<(u2>evcVsk03E-ss39hbw)Bh;mse^zRd;jb2k!(M1PaXiRZcQ%KO=kmEQ zYe)hsN4`C?w zYzH(0o?Rd$a&jY)&`D@2+>-(c1Z$3iJAZEf`MjlB=g_6a$oLNy_Q!{34uz*1MHikA z?-v$- z+IpXNMvi@XVaIM-VI7X;oKfOw=54~PF?rzQu)$*E38NFJxB`+{Zm#FE;mxV1hdjnv z2CgxKP0WK9AVsPCPwC|ACo{?4&J4M;dlSDsx}QZhKqD2a``@By9+=Ol&QV^$*qn^e z3tzWQjzcay7PUOedR z>MFikRTaO{&Ti;MUtgb|>yez_lPJ|UZ@#IYn3(vywzjrB@Mx~xOn_HHLc;nqFWdU) zO`2CKDoA~1$E5;+z~ptxTT*CfXvaU#o$H#OCPpxstOv1$W;t7`tE*8f507bRXdG)8 z33$1Co#Ca9SGsF&t;?Dk$ev;*WqW2$%^o9LANl1~*O{L}zsI^fdh{r%;>L~HFgDx9 z!rVM6D=X_Ggre?tUUYVu@d4@^5IEW*6p11X3=EFlcE42rjCp93_FJiu;mJFGrZ)wy zM|uV~pVP_Jt7+H}<%-I>tWex8b&3}qf4?uv|jeYUpt^$*3xX0C2-4bKx^ zr6!gAipm<;foSxt*>gwanLYuomsZ@mwa2x)tSqDkrL9d~y}$f!TvdscX*7Yl8rjrZ zQdE@KUhre`_^+0Qd28fnw3U70%}s+tLuLVnjLgz9&sHaJ=j3Q`TgIBvYQwR0j4Fz@E5@?m|_o!>t)rYDoE0N9K zJMF+01b?OB>UiJ$gbmI9@P6UGrtGuT{6c}VFP2XkkJnT28xp8EtfQj2e#9|K|98eH03neh6n|(qdI} z>eBJ!y}1xxc)9#vH#E^b8X3iF8J$(8O8y#*{5lPt2}DSxq_L3^8b@gSKxT6G<(DD$ zxV*gtrGroE(L2GlrKeB|2K79tHTY$(?bz7Z^^Wdt0D%cIx~|3XLlQkF$Hy-OJkdJ{ zdY#(WyOOcZFQMBZzEx*rQaj!!mvZojzdhdi+xn|p@&YR~(+e>`jBfh#x(RM&S8G#K zleMuM{&AL`=80EERZq9Xj-NbS28Jo(jBKX^t`p?;t`;W9n~b5Yfq{RgTjW5rPyA_Z zerqGPVgektF%d_`zMqLmNl7U%Hn{riAyN<=6tr$)a8UfIuat^Hhp-|yr1&-e3qe6Hu~dOx3^_v`i8A}!7L2>>O5002P1$PjDIz9Uvn z9&YwkMkk_xedF~rbfN+Pd>dEJb%1211OUKgO0adLIhvWGJjf&{&Xeqphtf%YY;OPn zO-HdGNq8C#L?;n_sVF)Iyy}5sKd-x<_kIg!zhS@!X*53+3>Fv|2n|$)k}2LWxTdBiOa%c$ARufH2$kVW!_gtW)E!@w ze9wc$Q#~jIKN^AT3tGvGb0-JTFktXXp&!S$b&~vk6!N8hW5wnNqvQNwaHtCGM`m^) zn#~bqM)o9lF|arqUK^nTM?h4N5CqZ|u8LAYqSRH;u-|-s)?AI&r{HlkGR2lmCTd#} z=y)P&M+#-{9Y)9Dmxie=KV)_$}Z+6B|z_{EOHtmOsT_K~bxF!Vya#;eEgA!QN5-XjnsU z)viw_k|{QRI1jw`Zgq84wvNBUzelW=a{9MYYYhLjFrFSiTFx(kLR{@^PY)QLh-b5= zQQ6ACe{DNY4-|#qeUL`|zVE*_@#^l^CDMLHzqbXEurfgFI z-a`Ro&7NHp8X2yMM1qcjuTPrb*8> z+}d}#f#X5CI`;IjgHLd==;G1ShL)PxJ4-eBu9c{!QCdq>RMfmKdnzY1do9$yrlhts zHwR2BiPfHb_l42peDCO-^m*eMb9eW_&!0cj;~PC~9UOLb_4I`BT8|x`=ywr4*%Eva zEgILH){eavHv#lsdTD&X-NB3gY>w#I9qFLy}*fn*|PoS zg5hCJELM*0o1mcCcM4-d9#5XLA<=Br(N=n{tO~YuNfrN~-ZEsvJ#Pf;YFPq_i zq+#;W?aa(f0V$-f*nGm6x=D!Ak@~pxTX48?Vg}r}Fs8j?gHB?Z309VSS_2J>Y^n11}7;if1tR!x~hh7mLEE`8;Kp%y>|!1wIa#w+J^yQVApeBr2jtr z(6Fa%ktr`Agu6)uBAC1XRtvVm)^^!ei;$X;{no+?jg?yXi<+JLmTd7&V;_)JSOE_>s?O*6mbns=q!pxgzjujI(6z4 z7!7vU5t##zKPyWh^Afp4n&#iDoQ;rY=@&A)rX)yu?)%id1W>oPua=z&P@WPiY(q=tjH+b*fz?6k>L-wkru8B^catp+GbY$S=Orwt5Ft8sIZqy=xlL$ zI0_4IZTsYHk)AljSs2iJBl`n4C{2Hxfm!s!k)uXiFh0*PRoNWim6U-NFdf<=~HpSBUGOTfKIPWth+LzApbM0Cw zvD=AVNygaWglBs+gQ~JFjT)&f&9xT~FEz?n%XARBZCx1~&KvE0lV*Lk?wF*5aw)4@ z`mNymDe9Hhs|(tTqLIofbyyW$Xrx*4bII!Bd&!xh`GFX+o={E zEw!%q#H(Q&mW_-eohu&X2;Zs>x_fwOtM~CJ`+UQFG3XHzl%?{fJ+WA9w2RyE{+o+D zCT7WMgfIP-LCx6*QU*3bg6jLQ6>jAn#vAKn&xt8k`p8}nqjmuBnz;|+VwfAb6=8Rc zyj#=s8zO7PnN5mPTNUK%*2!mxaBIodhHtN}Xov`)ueTdjN@$!OD=seXj|7l|SvPO; z2U}De&$(|boE*h*#ZD2A$g%T99V<7PTr5>jdlE;xUSMUpX;ZWs1KkLU4;2L0sNYX) z%eKPD+^|W7$V+QziOt(wubC#1n2TTo?Cy?0SK5=vXL-W$C$L)PW3TS?ke(KJJalox za8z#CIml&bVS(Jfm*NC{cUY8EE&kD8iwdcL)tIsZlRQWE(_Op>9RB-nZS zNXJ_r!bde+K=@4C zKn8Q04OQu-3|YMxS#0RN;%utMp-;+;EflZlE?x>3F9OP?Y2luZ-y(EiWYqoo$T15S zgjG3Y?7eS-p}BB#X-<>5laxG)|$-r4~EmXh{fd#KE#V+ zcV6F>h`kq5W|STur%?SUnTr^rRdTS$MAd?x&%Aj=#Lh%}p78woF6h1a;p3sz$}bNY zepvEpIN9}_vHh)(Fp%r2;*dT(_+8M3j|T9abpHO>p*gSu_b%02X^uO>@&RLs6< z=jxt`xdHcjUG-u=(&I}7e*#1zL*R9??#3;~cp0w0mgQ?=6W*!BJ#3W9WwC#vU=Y~N l5`uZ#5%2ULXv1aZgbEWjQWJ+`&#wF%H8L>A=Ib2@{U5PWS9kyb literal 0 HcmV?d00001 diff --git a/sources/awesomewidgets/weather/10d.png b/sources/awesomewidgets/weather/10d.png new file mode 100644 index 0000000000000000000000000000000000000000..b1e1f8305ef7558bad0ab12e5298db59229d69a3 GIT binary patch literal 3793 zcmb_fc|6nqAD{b5j*1*<=4xRx%rQ)kY3qv#{YW8f7-MT2M&-znPL*;bIg&HEa)iiL zEJu_m-`qk)h!F7`UDEga`2F+S9%XRh=>?lc-10fqYc`9b{DAS8+#6sE1M4OLNvs;Vk8J(Q{b-ZUq= zvNu)cTaq7njPX<#3V}=`ki3Cwd7Yd|J~TZLXsyuC&-ZH3Zu0q6b3NLKf_I{k zDAptr5otl7f%huc?WI=|ca&HZWYb9k#?%NkpG@e@&(!e}J02UE{@=pjTzu6S<|RYWnjOz9nJ+oA-K8Is6WpAwgzcK)~bPbB=F^&9$oFW-nw8?w`M56=Cgf>$NWFv;UK8nj&e5G+ z4wN)fp;Ym-s`TT-=Tz7j>(Vjlrf0{s)Z9Lvntwx`TufSuF)}XO9bCQp+A+i|cxLr& z6EbSne^{b$pQHOJqlgJu4|Cm33*n~jx9g7v_l;=vvp(GFn%kvU8)oC7q#s^*HP^>y zzj6)tF88*sl*ss<0@HNeQ1=(?i29(5>?Eq|siqi}-s3}}{grSAMf#I=P+tB+K1gtD zl7m<4+-yhpix=v*hRXb}%H9!-T2U7zC>agw3$nLe3Sr}VS)y;vh`-Lzbil@%wy(~< z3Zy;Wp5z@{WEGTt+?vFN;c_oH3cj#VQ>JgqaPOtegd68rAda+$&7Y9bJmF-*iJn+2 z_IEu;+cw9~&red<&?slm3qB1@Z5uU09gO5JxnQ1A^vF9;qVHB-DLtIOui)j73ESYM zF<~X0d?^X2NXl1W>Q}*mgU&-L-*$%oU;*>FqfW8 z3N8a16OpS4m=)a@Z~X)g_Viaz`c_n9_rL_$*@hoTvR?giOO?LRE;{}0K>f0&5OqjU zUq+}`W?5q3B@}l4CP6=hQ9$4jEnvKe=uL|4JK7`PiU@ipSQjoIo%J-#8}Fi#pdc?N z*OHl)1#W*ohh-qOJGAELIQIs8*m9F(*b$aXf;ye0oG+A;9$`I54BE`WnG= zBooP*_+k6rx?(#oB-k*6O8}Wx_nM682vy#`$Gaw1r%Ijvqbv}Q_l1|6kC0`{uRNz%j2v@|RX4>2WuWSLuY)_%fbD{R{I>+BRwlt>2sJ4r=r30oL zU2L)n!WQ}NYSN;*cOn;$xz&t@9ibB>_5?0(>}}*YQTp|vN2dx?qHFUljI-$#Hg7N3U<2_H!4QKNO*@bYQdpy6;k2FG9?pe3Y5$LMhSyli7f-(+}) z#2k6xD0rDLVsQB^($_-Eb}4?W%*0T%o7kRwn>CYRGZid}6tCYO3%EHY>##F7LzCgx?daik+^GGVAF zVv2^NoB~ou$)w^>@!6mY#1GvCuX;+nPQ-f`@5OVUX6<}7li`qmtftN(Z(i=pO*1+C-GI=D>NyT1dFAGr)n4l&_hJV8 z&Yjo!m6a(XDE~-Vaid`zzWlalaqO|$FxCCIv=1-e-H#Y_u3BBBeg#*7+_7x33SCVa z3D%0|?h-@JKw=lu>Tj4OXpAg9eb!lN6?I>j)LXfzcB2i8!SJZtTyDcJi>9hM{@h%m zm>ri}do4Yp*@}q88Wcxm!cG!eXE3b@S-FVz7~@(kG8{7wj<$K?(EJtO>glO~l-kud z+nuaMdY9Vil3u*GW&!oY1TCI>>u3Y3^fe1E@$w6gFOB5|is8a)f`bwST%|OouJ5M) z{c#UG>R?m3xr@lmGN|pD(D}!{sOr%vQK14On-R+2=BZ1fg)rB~Y_%NZLKyOOMb%E< zl8hcH%);k>N@B>BgW4w8r|tze!e5Lx?OItOkQztb>fznO&bQ!45*3@T+*y^0v&nE6J;7Kh;;eI?vmQ4U$n38tT_|s*+7z`h;g_r6k7|N-Xe6V$8h=( z295}&j4KkRGJ?qX)eXVF(2qD!JfD-vZA zr`~nioH{p~y~rlnJ9-6RGTwQI`2%F*a_OP`?7X&wX(%nmjA4wKm~7cTB8E^1Gs7@u#>~h}*2r3<_$-AM=?yKG z6opWsge)OKwD6XF3E94(O?uz!`{zB^IdjgrpY3_;Cw!xhBzA(825rVe<`1I>P3g`r^3nhV2Q2W)R)1u~$}@F0Y$nkpQO z0fImvZ5ob%wl*~S7S4Xt0ednSR5TRo@9(ebudYg=c|g@rC=?V1hr;0ywg-gHA~Rf> z5HelyYm)DI4Dob#8j;E%QpljyysmB(KZXt%yjtkT@ok+x)E|Y&^lz-#{Gd!%DpXAs z2K|wl9jMLbh_;~Mhy<3QD+7;#!_?pq7!m?UV%5~qFeLlbhHmirS#vGgfQENvP-s{R zg@mypGVvsz)mIQ)6{d>#8oS=(Td+2CmBl(%Ym%)lXaoNL*fNNOpSu1+ch&Mc-&GWC zNh9LfI8l0UBCI7@k8Sk- znctR7Wc*mu26$tX{ZBjQ$FkOg-va(MvGGjeKZw0*`CaT)6uq`5>@K2@I8UAfyaPB`^j_OAvt#vle9f~L6 z*{m6KwlZqJwjItLO(S}EGU(s;{nsX5+x>bZ#;@r2wjdE#X9=3*O7_qJGa)!U!PSq% z0AqH#?*dt~XBUk@Q9~h-pg@ozyC;3<47TQ~?9TuC{Yk`MvwlT?Ev60qZDD`EdA_3T z>4pKad;I&P!~iE3>mu2+R@T%|59`T2V$W}t)FFXc8C}ljzcCzUtt%?>nD>MdTv0;I zSe#^jJxeCCoy%PVy*st7ossV79ihaNsAV&(q`5_-6;#}L6%lvd>v<=(JNk^{r3C4N zhdD&grf@Fwc8@L3Q9jEY<3r0u?WGT5mg!BXK330zJ+PV~XV2IG4z5}l=ew1LL`8X- zi8{H$N)ykXZI6V~Ms(hazD%%yoeYnNh&V_nVv(^}tbC1ZPfyQS9yYh>*l=g_KCWY` z#wQ=l7&;Vty|gjQE>zmS9Y0Xw`!>4XhfF36)!wxGbic5$&`YX;^GKj9$T6!~Ys+M+ zt9Eb97<_;0hQq64d)T=rIQj85?tAQ)91wW z^zP0y#O}L3Qd`dp!6#%l>+6Qw34D4eA|{qw(Cx!@LMWnS zYgRL(-c9Xc?n^J1+Lp%I$>wX87b~DhWXfIAD=$#4ygX~A-go1Bs0bV_x#)3#!?wDg_q^78TvC6)O4WQ)-3i*fPs z$<;ZxZ(BYSls_=q<5mzo-uB07ubq}dqT|zM%#Z+6Q_}<}V6wu+Hm|5i9jc^+E7s@W z3f5qfonH3tMl>!R?YcwcBNB;>xpCKzV+tmUnaax=%%}kEmBsm~hdfJzeGI~j7hay8 zn`7f*baGoi$uI9P8tr51yOh!*J~Ul~Mz~m52u?UVIa$!8kgTZDA z7hYaxMDz5wW$FZ+@A->|yQQ@?k&EE*Ml>^YbTH@^ixpvYX6%jf_QlHvQA#j*E@w?E z0hRIiy7|j1yz)z?wze;WJzA&?C+untOEZ5U1#wLJpwjA*Kky=aX{iQ&>eVzg)sDZMYuCXHVPU^Uod?u@ zeRS|*NfNR`cVXbn=H^W=66c(iTjw~>@l*@@?th$v@M>cnyfT<98($-FCN6G!xwGZW z%uI_;_59?*$-%~>ak5}7t&)zkMp=>Ks-ttZ3DSSm=J9(x=NPA<(&P4oBc&QHAkSFa z*kp53$KUAjNhc*u)-TN~1qdBS^ruZ3O9g2a&}&B)%5U9LmDNAh*C{aZ6!1I%nU=~C zRer4K)k0c#nN_UJGxhMnsuOC`vBh`pKRH&Qz`nFz&~42>Kt zzBDZ_B1J_SM7KF5)bl%69lvj?6$Au3t;mWeB&qlT3r^y~_PiIDSA19UPHq-+D8H;M zu%oNkdv@FOR^P}V4k<5a?0z|C8M)Et+M$)=%DPDnpOCrXr$Du?k;_W`UAER^!5weKPqo=JbyE@{nwdj{Ggp<4CeDqa#RQC^TEYb1 zGd^Mq&$J{~R;Yp(Sz*aMlqYXEzPJc;U^KNu-(=j8DxJtW=vhXdniUo17_2#paC+%% z?M$Zi?f?p1`FzOiI&vmhtZTkr{vdDo^(L$ht_m#nMNmwns_}XVLDFxTz^lfMrRGMK zRbGUz#rN%y*PTnNsi_eI zNDIT}wfkAa&l-UIe=fe|%4tGAJKWLg}C1)seFmj8G@Z;My7U*VG%b& zNHWmviRH<}@wzYUnV3nPAE>QX7MWM+HALHc0V{{lruZPA)Ax7IRyK13Kj}K)eVdWb z2)Gr7lkr$KvoN<>fJcq%(n14aVPN4L0n)dUGLv=xlb-g!~<7rBBF^eLe2 z0J26`7jP$(v$eUa%aPt+&7G*S_tM$JjeWuK8Lb7=e8uAe!kRVHjs(Yr;f3MLNn4YV z-iZ2uX}`PurOK#%fwqOpg(3Axz{;?48r<7r!6oAvPzsk{tq|PdlD6D3FUWZ^Y`)e~ zsu0!?dj4Fl6-=q~nPEf*cV4OvB&TojLyfuW>#`*e84^jU$)g4f5MRl_NNx#?+aD76h4v{C7I4(Yr8!PQ)OhV^6u@)yl6qo5*`-A1#P-yVAhO*>%B77NKF}jeyiS zTxKn2+mH}e!44M;vyv3fO7{}t+WhyJ2AY+$Bv+1JoO^n)x4R^*S)lJw1(KVmdy4m_ zxs6M@f}PEj(GbQ?A-Un{1rWJE`kI8;HH4_HOc2W8#j^5)J;Dn~jUSm~~M{`f#>%c7KOys%sv8tSuW-P0-asD^nFZC;A zcM3h;0r7+0ei7XsAN_Q@0vB!cKr7D{NByY=URie1mf57mT{?V}i0kmE-S^xk5 literal 0 HcmV?d00001 diff --git a/sources/awesomewidgets/weather/13d.png b/sources/awesomewidgets/weather/13d.png new file mode 100644 index 0000000000000000000000000000000000000000..7b64a6cfd080465634c92f56e1eba8a5a3166c4f GIT binary patch literal 3901 zcmb_fdpOhkAD?SlF00A4V{~DuuVTbO#?M0I&|ca)|)W<|+XI5>6CPZS6N*R+H6V~^ z`^g5JP`c0?06=q4!pBfDivZ<>Qp1=i4n||u10{T3fngfZRTowWM#J0L4QfMUkfFu~ z2m_=B76^qx(F{@m${lC-Ib8UL(FkI(=qMPB&1M_04Gn0FKp4Wz%nSxc!jMRPp@%** zGK@vw=!Y>iKPCA)501Vhq81pkLAwL+0 zK!+g=;IJ>5g@I@xN0c*-L^ZBRdYP1c5 zOkmL%o-`U2>qg;_si7;cP^1Ce!1z<_*B+mP(XbU3U$I)1Y^9;^@c+k_MG5#v*Kg>q zSbpTYf}&g*6tYm~6*aL4H0%fLD~78!A9pg7MvYkYHxUZ*1NeP_4K0+;ATyaO1%x83 z`hSgm@BdGJuP_ShOHbdy-$!}>W5<4J>ud0Hz`rIonM3&>Vy{?!6nh0lt)2;Q93_+- z_DK&o8unieU(s8&+t8>qh6kNMBxAQ58ygCB{2u;3Vzrdd|0?yB;ola9MEo*x^auuZ zb+SoB7@0~IvSu-b${@ZSI}#Dapacf7n17%9PeZ(V`mLy}Z_&TUf=XH0B`7K(ED)o? z(I=4u2oY4423Ci-73wbBT?`ftVP;|ije_EYGa1Tc2{ktmPX4FgpGx^Q>nHTvVrbY8 zjs5q-^9dDhH!M&%<9}~TEU^9zRJe23{_2Rc@(hxg-o1|M@p2<}o?zZ|WHUZuTS1U@z{(#!{%1Wi3NX<$F zUh0t2imi~|(4MLup4%!IXlgRQk(u)=wY@-8H_N|%Nzk~w(1RIWxMQ}A(3TQK%f%j1 zvjjenSoH@-0t`loU#e2Sd1i4F|Nlu9-_q+SmmL>x#!(1qBCh=nnXkT>fye zD z4<1O?LeiB>%FAm&MRU`S*@hXZL4rhy)-ihbCCWh=$den6cRkT8lipnkWZm?!kHGl- z(Fp#-a#x%tjXG3|=nt;GdBG+TpbWUb{+hFHwrCxwce1;?8=|fwX1mk({#$@gy`oHX z?Od(pQ4iYASnZH{K?}QO+9v@9SUMGRM zqYhRlD*dG^VrhUhP4(z{KI``rEaF1~nz+x&5?=-egKfsfSqJPPYm0e`DtcB$(xzQA zqS6m{N{w%ssGUzvPA0Q>#_2qW`GKi8 z9mSthTM1|U5^}1a7J0vPklcTsS0BNLT3A3T&c@#XGm3BxaCU)Kx5MivXod2_UBAM5 zHiRnc+7~_hgWbDkVPe>Ad;5lmxJdSEk7l9@eApbZrM2hjQL5gCZM&{SZ`*wpaBXXT;p0n_UnNlyyLZL9HP+GLrgRwl9A?wx)Ai)C}Jl z=%98xZY~)wwWp(_BRWy*{(}di3K_j9Ggk+7rC^XfKE5iML1269DP)a}+zpba6yP$_ zlB$wbHE)ZzT9l)nj7yknmH3pDGh5n=56|>Iji0u4%+E3eOJ{f5|WOK}_!g=7uCdFx~oGC7sn@qk|i!5}H8NKL$QGA}5>vQUu>z&8>q`b8m z?Ql@L$eahdps-_%%bmj$szC`aOpEotgM6Q$BbsmM5->U zZ5yClH;9 z#Anf&SUt^&LLe^J^_9tG-B@sLZAWs#(Svv7yo^P=&${sD{ZBB#byV<(XBT9cSEmys)kl%(A*+L``uwrU3OCCD|zt2T97j|QvNtp_PpCI5( z?A+8jb1QwFcaf??w49DhpLn5hJ7C5RMX10xV@MK2(r5P@SBU8!#k;v3i<6-Nv+&HHFMB5T6)E+ zSF_Pzudv5sZOb5068UcWX{XpXB1m_c^lX_KYm`LM=I92tc<-dhf!9ebL(pQlj7Y|? zCn)MPsPgQTYXN z#ocX;(Hu5Jy1<)uk5hj#w9%cl#hrGsw{@efZP7g~g620{p(F;O>bC z94Stxxm4Z0&7y5&qFs%K-|Kho)N?WEdn2iKkCl!LabV9XnE4NCFH~B|s&FAW4ZEyv z0(r;5+<~$ATBQiTW#l@&0E|vQ*6s41yHB81*uJr4MTI|{IY|IMyxUvOj&~z#$Md=2 z2DX37M)8x$K%8e4o+nqu%RgLtdvigNi+4KLoxF7O`4!9v)uqcA>sFYWL!vo2BX{-n zT`r&Dy=U`-dq&(k4xgJCI=?=@`vn?B`Ea8DTq@@Z?|Pe&O+%40M8G)Y%Ma1D*ygD0 z(Pns}N^G${$Jp2y;ibFN{0vdlT6}b1Fn8`&5IVS$RRJ3RO|Vp~ZyIu-Z?4{#KWGYErL*fvwY<3?fA8pbDF!j zJfQ2589(-$yiSuDmxaR2ybtqEbDp}xuSN6xXKqoiZ*Qo6@t}W^d;hueZ(xggx2d~n zBROgI#8K1PrHhhL!2=c3PLle6Mm=g?M!xpDxObS4-nJ z!VJ910(AMZ(N_MDH6Q8)od_Ck7=ChG{}%Ri5z V(K#=GDl30*9c^83SFQ2K{sUPJTaN$$ literal 0 HcmV?d00001 diff --git a/sources/awesomewidgets/weather/50d.png b/sources/awesomewidgets/weather/50d.png new file mode 100644 index 0000000000000000000000000000000000000000..18afb341e1f8f91119d249434cf170be5e686715 GIT binary patch literal 3328 zcmb_fc|6p4A0IMUN6v_>ogEUJnK5J0%ri&KxQ~!q#hCex8Rjzcn+$o1bP&7cC=xo* zVUx%aX&r64R7&N@vs8MD$i3E)o*6o%-PiNa{$8)&_5NJn_xtzxeCIXEo*s^>O8QC= z2t?J{iQ+A}W2C2|yyR*~N-C4wzTrCs3Ly|>E$Jx($;n*}fk53@J^^5WyBm(i;~=SY zUKoHBbNCW(2m~+2Ngg=>NQH?xY_1R|CcqawaFS;!jDo`!T);>IJiy%(M&=0sm=zL@ z#K4J4Fc=IkpfhmZ6o(Jtk~adJ34(ka3Kbn4jf}QL@&w^1G!~0RSzu5Y3_{|85XNvp zsu;l)8Z9RIn1=!gX#y4>WbwE#XEXKQjZV8c$AdI5>^Y6Nf)#X|9@;j7UQ$7U(l6WzUC`Mahn7z zK%%o$O(GhP`U+dZaKRSn4G4K`(SpB?gw$8y@&GcA!xsQTp|pV22mhtma{tfyeYq^~ z)0&pS%cBB5+lil+wG{ji@Q;ZNh*^Ilw$$>q*isa?&=Ua^76;%i>S2LL{iR_Ey#+g& z$L0w(^Qkm|Xl-R>DbaB`ygXu|RN&v0T4MO8g`v|vjT~PjU@uHIorVI~fP^(DlqiG# za_s0doPZV11ce{_esPEwy5E)!eu;h@3pPu-m*Ch`Za4uhM$iEURm2A2L{pj>%v-W| z2|ykiYhwe8gHa?i$q|AQ&5@GHU;O@T)|Xiq(JzbPQC}_WubXEPmF#XrCCQ9`+$o7l z$qqq@5QsvMGsV`22_4FIb$co@XlU1QasAHIuld*!yLf^nJxX|L&9QavN0=C7dTNS- z8eO*_Ig7JStvT_iW1d$*^0h>-gYwp#>@8`bI+L`TJ zk0=T?Zl%+X=M4Rv?DYHlsKz4KER~p;n4+MPD$O~iJP-enfB>;EiPTe8SBEdJs@g6T zi6;MOZr*nzqH?D8$`zW+uLJ^NW^{B^z#ljfDIer+vf0&GvqmfB`aXX@zqd_2cWSDO ziwC^?{r!Dz8MOr!{E_N-kt-Ho)@Tk7<*V=$f*YAorTDFOzdT^lyXh*jZKg)@HIuRL zM5&Vq1mbWRQO0G>tGg|c*}CX<#eA`LvxA+N-k6D5XNvdb zl6L*NhVdQzG9+oeyRlz_=^J$oeS22V%uH>f$mp^Oyg(P)n7qam?EQ^}O<51ws*-78 zaeI!q0m!x59iEUSbMuwChr;ny_j<0zO^@ARRc`9^aWCO-*s`g^KNP2Y?O%%Tl&NHK zOv6ioyEzis+!ju!Q`%ZvJux;m(VA<2P78DNJiqeV0U5NL*u3Ey8K=tMUU2s8>#n}O zzPb5#voGogoNmZI@t_;pj_UANHn^5kZN>&RPx$5)I}~2J)OLWsPGv=(;6!;jCiYp= zUR7TY0}upXySTdk^ynvqw$iHcKph>OBO8=tWkRP19{-}(wkP&c?A2}LAN4D#NqIA) z8;vIPNWSEUUX|6=ubx#Z;kPCnA~+P3sTb)6-tVo6s(y-a37_lg>N2Nv*=PQ6qT22| z>UTmDv2+c6;t)dyNdU94E@1q`T@F26Iz&^F}Wv{YS@@Uz1Na^)Nnil9zuK1OVww*rEPPL zBtU-O231R@BoT}%Oq%=hE8eGQ$}%#ZBb` zG^c|HuYF!9basf)QhYw-g-st1_naff%tHG`nTmnPZFOgTpRau~lJyo4Z7>*OT$+yb zrfbHMUTDAJy#`Bf*7UArW)_T`3CvELs=FRmBm2%+G*PRG`VX!|!z`)T4!XZ7)4>0w zZS{k2@3{4`;_%GlKLl4gcpEwCGnw@c-Y4;^RjM+^OJ(*qn8ATL?LSeJw@Up{cZR22 zeZFZm>Gj8oD2_RlRWJl$KEcMZg4C3)rnw`67Ia?`5BIwxSEA3Yts3dws{HuliZW{=?rt*)^5%t(zTfuI`U zcJIfMl9HJ5@$tPQ9s3{h(zo3}pI0F=PQ3{2o*{d7h1qu)%GJBPVzMG4%FjMCn?e@{ zF!$&jtpDEV!M`t5RXsWVn{RLmp7|VaQRk+L5`|b*W+EG+()DAx({>L}Ce4)f+N;XH zsGEe%${g_VcAhlRF$4g>!7$fa#r*V6kP@9?YEGSl>xQh>LyPeb%rj?9+a*JC@nSi`$$#iaCXw%id=~IK;#68C;gA&Z0|w2U>Cake{1PD AO#lD@ literal 0 HcmV?d00001 diff --git a/sources/awesomewidgets/weather/london.desktop b/sources/awesomewidgets/weather/london.desktop index c89d790..cddbedc 100644 --- a/sources/awesomewidgets/weather/london.desktop +++ b/sources/awesomewidgets/weather/london.desktop @@ -3,10 +3,11 @@ Comment=London current weather Encoding=UTF-8 Name=London current X-AW-Active=false -X-AW-ApiVersion=2 +X-AW-ApiVersion=3 X-AW-City=London X-AW-Country=uk X-AW-Image=false X-AW-Interval=3600 X-AW-Number=0 +X-AW-Provider=OWM X-AW-TS=0 diff --git a/sources/awesomewidgets/yahooweatherprovider.cpp b/sources/awesomewidgets/yahooweatherprovider.cpp new file mode 100644 index 0000000..569a269 --- /dev/null +++ b/sources/awesomewidgets/yahooweatherprovider.cpp @@ -0,0 +1,126 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "yahooweatherprovider.h" + +#include + +#include "awdebug.h" + + +YahooWeatherProvider::YahooWeatherProvider(QObject *parent, const int number) + : AbstractWeatherProvider(parent, number) +{ + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; +} + + +YahooWeatherProvider::~YahooWeatherProvider() +{ + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; +} + + +void YahooWeatherProvider::initUrl(const QString city, const QString country, + const int 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)); + m_url.setQuery(params); +} + + +QVariantHash YahooWeatherProvider::parse(const QVariantMap &json) const +{ + 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"; + return QVariantHash(); + } + QVariantMap results + = jsonMap[QString("results")].toMap()[QString("channel")].toMap(); + QVariantMap item = results[QString("item")].toMap(); + QVariantMap atmosphere = results[QString("atmosphere")].toMap(); + + return m_ts == 0 ? parseCurrent(item, atmosphere) : parseForecast(item); +} + + +QUrl YahooWeatherProvider::url() const +{ + return m_url; +} + + +QVariantHash +YahooWeatherProvider::parseCurrent(const QVariantMap &json, + const QVariantMap &atmosphere) const +{ + qCDebug(LOG_LIB) << "Parse current weather from" << json; + + QVariantHash values; + int id = json[QString("condition")].toMap()[QString("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("humidity%1").arg(number())] + = atmosphere[QString("humidity")].toInt(); + values[QString("pressure%1").arg(number())] + = static_cast(atmosphere[QString("pressure")].toFloat()); + + return values; +} + + +QVariantHash YahooWeatherProvider::parseForecast(const QVariantMap &json) const +{ + qCDebug(LOG_LIB) << "Parse forecast from" << json; + + QVariantHash values; + QVariantList weatherList = json[QString("forecast")].toList(); + QVariantMap weatherMap = weatherList.count() < m_ts + ? weatherList.last().toMap() + : weatherList.at(m_ts).toMap(); + int id = weatherMap[QString("code")].toInt(); + values[QString("weatherId%1").arg(number())] = id; + values[QString("timestamp%1").arg(number())] + = weatherMap[QString("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; + // ... and no forecast data for humidity and pressure + values[QString("humidity%1").arg(number())] = 0; + values[QString("pressure%1").arg(number())] = 0.0; + + return values; +} diff --git a/sources/awesomewidgets/yahooweatherprovider.h b/sources/awesomewidgets/yahooweatherprovider.h new file mode 100644 index 0000000..d5c997f --- /dev/null +++ b/sources/awesomewidgets/yahooweatherprovider.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef YAHOOWEATHERPROVIDER_H +#define YAHOOWEATHERPROVIDER_H + +#include "abstractweatherprovider.h" + +#define YAHOO_WEATHER_URL "https://query.yahooapis.com/v1/public/yql" +#define YAHOO_WEATHER_QUERY \ + "select * from weather.forecast where u='c' and woeid in (select woeid " \ + "from geo.places(1) where text='%1, %2')" + + +class YahooWeatherProvider : public AbstractWeatherProvider +{ +public: + 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; + QUrl url() const; + +private: + QVariantHash parseCurrent(const QVariantMap &json, + const QVariantMap &atmosphere) const; + QVariantHash parseForecast(const QVariantMap &json) const; + int m_ts = 0; + QUrl m_url; +}; + + +#endif /* YAHOOWEATHERPROVIDER_H */ diff --git a/sources/test/testextweather.cpp b/sources/test/testextweather.cpp index bf41746..d1d38d9 100644 --- a/sources/test/testextweather.cpp +++ b/sources/test/testextweather.cpp @@ -30,6 +30,7 @@ void TestExtWeather::initTestCase() extWeather->setCity(city); extWeather->setCountry(country); extWeather->setNumber(0); + extWeather->setProvider(ExtWeather::Provider::OWM); extWeather->run(); } @@ -47,62 +48,28 @@ void TestExtWeather::test_values() QCOMPARE(extWeather->number(), 0); QCOMPARE(extWeather->city(), city); QCOMPARE(extWeather->country(), country); + QCOMPARE(extWeather->provider(), ExtWeather::Provider::OWM); } -void TestExtWeather::test_run() +void TestExtWeather::test_runOWM() { - // init spy - QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &))); - QVariantHash firstValue = extWeather->run(); + run(); +} - // check values - QVERIFY(spy.wait(5000)); - QVariantHash arguments = spy.takeFirst().at(0).toHash(); - QEXPECT_FAIL("", "WeatherID should not be 0", Continue); - QCOMPARE(arguments[extWeather->tag(QString("weatherId"))].toInt(), 0); - QVERIFY((arguments[extWeather->tag(QString("humidity"))].toInt() - > humidity.first) - && (arguments[extWeather->tag(QString("humidity"))].toInt() - < humidity.second)); - QEXPECT_FAIL("", "https://yahoo.uservoice.com/forums/207813-us-weather/" - "suggestions/14209233-invalid-pressure-calculation", - Continue); - QVERIFY((arguments[extWeather->tag(QString("pressure"))].toFloat() - > pressure.first) - && (arguments[extWeather->tag(QString("pressure"))].toInt() - < pressure.second)); - QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat() - > temp.first) - && (arguments[extWeather->tag(QString("temperature"))].toInt() - < temp.second)); - // image should be only one symbol here - QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(), - 1); + +void TestExtWeather::test_runYahoo() +{ + extWeather->setProvider(ExtWeather::Provider::Yahoo); + run(); + extWeather->setProvider(ExtWeather::Provider::OWM); } void TestExtWeather::test_ts() { extWeather->setTs(1); - // init spy - QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &))); - QVariantHash firstValue = extWeather->run(); - - // check values - QVERIFY(spy.wait(5000)); - QVariantHash arguments = spy.takeFirst().at(0).toHash(); - QEXPECT_FAIL("", "WeatherID should not be 0", Continue); - QCOMPARE(arguments[extWeather->tag(QString("weatherId"))].toInt(), 0); - QCOMPARE(arguments[extWeather->tag(QString("humidity"))].toInt(), 0); - QCOMPARE(arguments[extWeather->tag(QString("pressure"))].toFloat(), 0.0f); - QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat() - > temp.first) - && (arguments[extWeather->tag(QString("temperature"))].toInt() - < temp.second)); - // image should be only one symbol here - QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(), - 1); + run(); } @@ -131,10 +98,43 @@ void TestExtWeather::test_copy() QCOMPARE(newExtWeather->country(), extWeather->country()); QCOMPARE(newExtWeather->ts(), extWeather->ts()); QCOMPARE(newExtWeather->image(), extWeather->image()); + QCOMPARE(newExtWeather->provider(), extWeather->provider()); QCOMPARE(newExtWeather->number(), 1); delete newExtWeather; } +void TestExtWeather::run() +{ + // init spy + QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &))); + QVariantHash firstValue = extWeather->run(); + + // check values + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + QEXPECT_FAIL("", "WeatherID should not be 0", Continue); + QCOMPARE(arguments[extWeather->tag(QString("weatherId"))].toInt(), 0); + QVERIFY((arguments[extWeather->tag(QString("humidity"))].toInt() + >= humidity.first) + && (arguments[extWeather->tag(QString("humidity"))].toInt() + <= humidity.second)); + QWARN("May fail here for Yahoo! Weather, see " + "https://yahoo.uservoice.com/forums/207813-us-weather/suggestions/" + "14209233-invalid-pressure-calculation"); + QVERIFY((arguments[extWeather->tag(QString("pressure"))].toFloat() + > pressure.first) + && (arguments[extWeather->tag(QString("pressure"))].toInt() + < pressure.second)); + QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat() + > temp.first) + && (arguments[extWeather->tag(QString("temperature"))].toInt() + < temp.second)); + // image should be only one symbol here + QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(), + 1); +} + + QTEST_MAIN(TestExtWeather); diff --git a/sources/test/testextweather.h b/sources/test/testextweather.h index 8e28e05..e06cae2 100644 --- a/sources/test/testextweather.h +++ b/sources/test/testextweather.h @@ -34,12 +34,14 @@ private slots: void cleanupTestCase(); // test void test_values(); - void test_run(); + void test_runOWM(); + void test_runYahoo(); void test_ts(); void test_image(); void test_copy(); private: + void run(); ExtWeather *extWeather = nullptr; QString city = QString("London"); QString country = QString("uk"); diff --git a/sources/version.h.in b/sources/version.h.in index 5803bec..4c89f7b 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -19,7 +19,8 @@ "qnetworkreply-network-reply-timeout-helper" #define SPECIAL_THANKS \ "Yahoo! Finance,https://finance.yahoo.com/;Yahoo! " \ - "Weather,https://weather.yahoo.com/;JetBrains,https://www.jetbrains.com/" + "Weather,https://weather.yahoo.com/;JetBrains,https://www.jetbrains.com/" \ + ";OpenWeatherMap,http://openweathermap.org/" #define CHANGELOG "@PROJECT_CHANGELOG@" // configuraion @@ -32,7 +33,7 @@ // extupgrade api version #define AWEUAPI 3 // extweather api version -#define AWEWAPI 2 +#define AWEWAPI 3 // formatter api version #define AWEFAPI 1 // network requests timeout, ms From ab01c9fa08dcfbbbe9c08a05e7f4e2ea06fc4558 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Fri, 3 Jun 2016 01:37:23 +0300 Subject: [PATCH 24/32] Some test improvements --- sources/awesomewidgets/abstractextitem.cpp | 6 ++++-- sources/libraries.cmake | 4 ++-- sources/test/CMakeLists.txt | 2 ++ sources/test/awtestlibrary.cpp | 17 +++++++++++++++++ sources/test/awtestlibrary.h | 1 + sources/test/testabstractextitem.cpp | 18 +++--------------- sources/test/testabstractextitem.h | 1 - 7 files changed, 29 insertions(+), 20 deletions(-) diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index 787acc0..cfed6cb 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -178,7 +178,8 @@ void AbstractExtItem::setName(const QString _name) void AbstractExtItem::setNumber(int _number) { qCDebug(LOG_LIB) << "Number" << _number; - if (_number == -1) { + bool generateNumber = (_number == -1); + if (generateNumber) { _number = []() { qCWarning(LOG_LIB) << "Number is empty, generate new one"; qsrand(QTime::currentTime().msec()); @@ -186,10 +187,11 @@ void AbstractExtItem::setNumber(int _number) qCInfo(LOG_LIB) << "Generated number is" << n; return n; }(); - writeConfiguration(); } m_number = _number; + if (generateNumber) + writeConfiguration(); } diff --git a/sources/libraries.cmake b/sources/libraries.cmake index 0c29760..6f171a6 100644 --- a/sources/libraries.cmake +++ b/sources/libraries.cmake @@ -5,11 +5,11 @@ find_package(Gettext REQUIRED) find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets) add_definitions( ${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS} - ${Qt5Qml_DEFINITIONS} ${Qt5Test_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} + ${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ) set(Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} - ${Qt5Qml_INCLUDE_DIRS} ${Qt5Test_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} + ${Qt5Qml_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ) set(Qt_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES} diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 45f5831..e8a2804 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -2,12 +2,14 @@ set(SUBPROJECT awesomewidgets-test) message(STATUS "Subproject ${SUBPROJECT}") # find qt test package +add_definitions(${Qt5Test_DEFINITIONS}) include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/ ${PROJECT_TRDPARTY_DIR} ${Qt_INCLUDE} + ${Qt5Test_INCLUDE_DIRS} ${Kf5_INCLUDE} ) diff --git a/sources/test/awtestlibrary.cpp b/sources/test/awtestlibrary.cpp index 6883972..a36c589 100644 --- a/sources/test/awtestlibrary.cpp +++ b/sources/test/awtestlibrary.cpp @@ -19,6 +19,7 @@ #include "awtestlibrary.h" #include +#include char AWTestLibrary::randomChar() @@ -33,6 +34,22 @@ double AWTestLibrary::randomDouble() } +QPair AWTestLibrary::randomFilenames() +{ + QString fileName = QString("%1/").arg( + QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + QString writeFileName = QString("%1/awesomewidgets/tmp/") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)); + + QString name = randomString(20); + fileName += name; + writeFileName += name; + + return QPair(fileName, writeFileName); +} + + int AWTestLibrary::randomInt(const int max) { return rand() % max; diff --git a/sources/test/awtestlibrary.h b/sources/test/awtestlibrary.h index 355d8a0..44d4dc0 100644 --- a/sources/test/awtestlibrary.h +++ b/sources/test/awtestlibrary.h @@ -26,6 +26,7 @@ namespace AWTestLibrary { char randomChar(); double randomDouble(); +QPair randomFilenames(); int randomInt(const int max = 100); QString randomString(const int max = 100); QStringList randomStringList(const int max = 100); diff --git a/sources/test/testabstractextitem.cpp b/sources/test/testabstractextitem.cpp index ffb9068..379b186 100644 --- a/sources/test/testabstractextitem.cpp +++ b/sources/test/testabstractextitem.cpp @@ -26,7 +26,9 @@ void TestAbstractExtItem::initTestCase() { - generateFilename(); + auto names = AWTestLibrary::randomFilenames(); + fileName = names.first; + writeFileName = names.second; extItem = new ExtUpgrade(nullptr, fileName); extItem->setActive(false); @@ -108,18 +110,4 @@ void TestAbstractExtItem::test_copy() } -void TestAbstractExtItem::generateFilename() -{ - fileName = QString("%1/").arg( - QStandardPaths::writableLocation(QStandardPaths::TempLocation)); - writeFileName = QString("%1/awesomewidgets/tmp/") - .arg(QStandardPaths::writableLocation( - QStandardPaths::GenericDataLocation)); - - QString name = AWTestLibrary::randomString(20); - fileName += name; - writeFileName += name; -} - - QTEST_MAIN(TestAbstractExtItem); diff --git a/sources/test/testabstractextitem.h b/sources/test/testabstractextitem.h index 805fe5a..43f1ea0 100644 --- a/sources/test/testabstractextitem.h +++ b/sources/test/testabstractextitem.h @@ -41,7 +41,6 @@ private slots: void test_copy(); private: - void generateFilename(); ExtUpgrade *extItem = nullptr; QString comment = QString("A comment"); QString name = QString("A name"); From 18789f78b38f7acdc75edea8be79bf9c0f08fca3 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sun, 5 Jun 2016 03:57:08 +0300 Subject: [PATCH 25/32] add small test for aggregators --- sources/test/CMakeLists.txt | 3 +- sources/test/testextitemaggregator.cpp | 48 ++++++++++++++++++++++++++ sources/test/testextitemaggregator.h | 44 +++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 sources/test/testextitemaggregator.cpp create mode 100644 sources/test/testextitemaggregator.h diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index e8a2804..b6032f0 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -23,7 +23,8 @@ set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Q ## modules set(TEST_MODULES abstractextitem extquotes extscript extupgrade extweather - abstractformatter datetimeformatter floatformatter noformatter scriptformatter) + abstractformatter datetimeformatter floatformatter noformatter scriptformatter + extitemaggregator) foreach (TEST_MODULE ${TEST_MODULES}) set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h) set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp) diff --git a/sources/test/testextitemaggregator.cpp b/sources/test/testextitemaggregator.cpp new file mode 100644 index 0000000..ddd681f --- /dev/null +++ b/sources/test/testextitemaggregator.cpp @@ -0,0 +1,48 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testextitemaggregator.h" + +#include + +#include "awnoformatter.h" +#include "awtestlibrary.h" +#include "extitemaggregator.h" + + +void TestExtItemAggregator::initTestCase() +{ + aggregator = new ExtItemAggregator(nullptr, type); +} + + +void TestExtItemAggregator::cleanupTestCase() +{ + delete aggregator; +} + + +void TestExtItemAggregator::test_values() +{ + QCOMPARE(aggregator->type(), type); + QCOMPARE(aggregator->uniqNumber(), 0); + QCOMPARE(aggregator->items().count(), 0); +} + + +QTEST_MAIN(TestExtItemAggregator); diff --git a/sources/test/testextitemaggregator.h b/sources/test/testextitemaggregator.h new file mode 100644 index 0000000..e5fc449 --- /dev/null +++ b/sources/test/testextitemaggregator.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTEXTITEMAGGREGATOR_H +#define TESTEXTITEMAGGREGATOR_H + +#include + +class AWNoFormatter; +template class ExtItemAggregator; + +class TestExtItemAggregator : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_values(); + +private: + ExtItemAggregator *aggregator = nullptr; + QString type = QString("tmp"); +}; + + +#endif /* TESTEXTITEMAGGREGATOR_H */ From 5a0541d06d1643d4db5f59049ba19a7e03ab94ee Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 7 Jun 2016 14:16:48 +0300 Subject: [PATCH 26/32] Add test for hddsource, move sources to own library --- sources/CMakeLists.txt | 2 + sources/awdebug.cpp | 3 +- sources/awdebug.h | 1 + sources/extsysmon/CMakeLists.txt | 10 +- sources/extsysmon/extsysmon.cpp | 40 +------- sources/extsysmon/extsysmon.h | 2 - sources/extsysmon/extsysmonaggregator.cpp | 26 +++--- sources/extsysmon/extsysmonaggregator.h | 2 +- sources/extsysmonsources/CMakeLists.txt | 18 ++++ .../abstractextsysmonsource.h | 5 + .../batterysource.cpp | 12 +-- .../batterysource.h | 0 .../customsource.cpp | 8 +- .../customsource.h | 0 .../desktopsource.cpp | 8 +- .../desktopsource.h | 0 .../gpuloadsource.cpp | 35 +++++-- .../gpuloadsource.h | 1 + .../gputempsource.cpp | 35 +++++-- .../gputempsource.h | 1 + .../hddtempsource.cpp | 43 ++++++--- .../hddtempsource.h | 1 + .../loadsource.cpp | 8 +- .../sources => extsysmonsources}/loadsource.h | 0 .../networksource.cpp | 10 +- .../networksource.h | 0 .../playersource.cpp | 30 +++--- .../playersource.h | 0 .../processessource.cpp | 8 +- .../processessource.h | 0 .../quotessource.cpp | 8 +- .../quotessource.h | 0 .../upgradesource.cpp | 8 +- .../upgradesource.h | 0 .../weathersource.cpp | 8 +- .../weathersource.h | 0 sources/test/CMakeLists.txt | 6 +- sources/test/testextitemaggregator.h | 3 +- sources/test/testextweather.cpp | 4 +- sources/test/testhddtempsource.cpp | 91 +++++++++++++++++++ sources/test/testhddtempsource.h | 50 ++++++++++ 41 files changed, 344 insertions(+), 143 deletions(-) create mode 100644 sources/extsysmonsources/CMakeLists.txt rename sources/{extsysmon/sources => extsysmonsources}/abstractextsysmonsource.h (96%) rename sources/{extsysmon/sources => extsysmonsources}/batterysource.cpp (93%) rename sources/{extsysmon/sources => extsysmonsources}/batterysource.h (100%) rename sources/{extsysmon/sources => extsysmonsources}/customsource.cpp (93%) rename sources/{extsysmon/sources => extsysmonsources}/customsource.h (100%) rename sources/{extsysmon/sources => extsysmonsources}/desktopsource.cpp (95%) rename sources/{extsysmon/sources => extsysmonsources}/desktopsource.h (100%) rename sources/{extsysmon/sources => extsysmonsources}/gpuloadsource.cpp (83%) rename sources/{extsysmon/sources => extsysmonsources}/gpuloadsource.h (98%) rename sources/{extsysmon/sources => extsysmonsources}/gputempsource.cpp (82%) rename sources/{extsysmon/sources => extsysmonsources}/gputempsource.h (98%) rename sources/{extsysmon/sources => extsysmonsources}/hddtempsource.cpp (78%) rename sources/{extsysmon/sources => extsysmonsources}/hddtempsource.h (98%) rename sources/{extsysmon/sources => extsysmonsources}/loadsource.cpp (92%) rename sources/{extsysmon/sources => extsysmonsources}/loadsource.h (100%) rename sources/{extsysmon/sources => extsysmonsources}/networksource.cpp (92%) rename sources/{extsysmon/sources => extsysmonsources}/networksource.h (100%) rename sources/{extsysmon/sources => extsysmonsources}/playersource.cpp (95%) rename sources/{extsysmon/sources => extsysmonsources}/playersource.h (100%) rename sources/{extsysmon/sources => extsysmonsources}/processessource.cpp (95%) rename sources/{extsysmon/sources => extsysmonsources}/processessource.h (100%) rename sources/{extsysmon/sources => extsysmonsources}/quotessource.cpp (97%) rename sources/{extsysmon/sources => extsysmonsources}/quotessource.h (100%) rename sources/{extsysmon/sources => extsysmonsources}/upgradesource.cpp (93%) rename sources/{extsysmon/sources => extsysmonsources}/upgradesource.h (100%) rename sources/{extsysmon/sources => extsysmonsources}/weathersource.cpp (96%) rename sources/{extsysmon/sources => extsysmonsources}/weathersource.h (100%) create mode 100644 sources/test/testhddtempsource.cpp create mode 100644 sources/test/testhddtempsource.h diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index e628d3d..fa0dc2c 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -66,6 +66,7 @@ endif () set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty) set(PROJECT_LIBRARY awesomewidgets) +set(PROJECT_MONITORSOURCES extsysmonsources) include(libraries.cmake) include(clang-format.cmake) include(cppcheck.cmake) @@ -74,6 +75,7 @@ include(coverity.cmake) get_directory_property(CMAKE_DEFINITIONS COMPILE_DEFINITIONS) configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h) add_subdirectory(awesomewidgets) +add_subdirectory(extsysmonsources) add_subdirectory(extsysmon) if (BUILD_PLASMOIDS) add_subdirectory(awesome-widget) diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp index 2b7ad34..6397383 100644 --- a/sources/awdebug.cpp +++ b/sources/awdebug.cpp @@ -24,6 +24,8 @@ Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget", Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel", QtMsgType::QtWarningMsg) Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg) +Q_LOGGING_CATEGORY(LOG_ESS, "org.kde.plasma.extsysmonsources", + QtMsgType::QtWarningMsg) Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets", QtMsgType::QtWarningMsg) @@ -69,7 +71,6 @@ const QStringList getBuildData() .arg(CMAKE_SHARED_LINKER_FLAGS)); // components metadata.append(QString("Components data:")); - metadata.append(QString(" BUILD_COVERAGE: %1").arg(BUILD_COVERAGE)); metadata.append(QString(" BUILD_PLASMOIDS: %1").arg(BUILD_PLASMOIDS)); metadata.append( QString(" BUILD_DEB_PACKAGE: %1").arg(BUILD_DEB_PACKAGE)); diff --git a/sources/awdebug.h b/sources/awdebug.h index 6a3b2dd..bae3ba4 100644 --- a/sources/awdebug.h +++ b/sources/awdebug.h @@ -34,6 +34,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_AW) Q_DECLARE_LOGGING_CATEGORY(LOG_DP) Q_DECLARE_LOGGING_CATEGORY(LOG_ESM) +Q_DECLARE_LOGGING_CATEGORY(LOG_ESS) Q_DECLARE_LOGGING_CATEGORY(LOG_LIB) const QStringList getBuildData(); diff --git a/sources/extsysmon/CMakeLists.txt b/sources/extsysmon/CMakeLists.txt index 7e9857a..f078f0b 100644 --- a/sources/extsysmon/CMakeLists.txt +++ b/sources/extsysmon/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/ + ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/ ${PROJECT_TRDPARTY_DIR} ${Qt_INCLUDE} ${Kf5_INCLUDE} @@ -13,15 +14,18 @@ include_directories( file(GLOB SUBPROJECT_DESKTOP_IN *.desktop) file(RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN}) -file(GLOB SUBPROJECT_SOURCE *.cpp sources/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) +file(GLOB SUBPROJECT_SOURCE *.cpp ${CMAKE_SOURCE_DIR}/*.cpp) +file(GLOB SUBPROJECT_HEADER *.h) file(GLOB SUBPROJECT_CONF *.conf) # prepare configure_file(${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}) # make -add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE}) -target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) +add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER}) +target_link_libraries(${SUBPROJECT} + ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES} + ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) kcoreaddons_desktop_to_json(${SUBPROJECT} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} SERVICE_TYPES plasma-dataengine.desktop) diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 6b61d34..69934c4 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -17,7 +17,6 @@ #include "extsysmon.h" -#include #include #include #include @@ -25,6 +24,8 @@ #include "awdebug.h" #include "extsysmonaggregator.h" +#include "gputempsource.h" +#include "hddtempsource.h" ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args) @@ -83,37 +84,6 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) } -QStringList ExtendedSysMon::getAllHdd() const -{ - QStringList allDevices - = QDir(QString("/dev")).entryList(QDir::System, QDir::Name); - QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$"))); - for (int i = 0; i < devices.count(); i++) - devices[i] = QString("/dev/%1").arg(devices.at(i)); - - qCInfo(LOG_ESM) << "Device list" << devices; - return devices; -} - - -QString ExtendedSysMon::getAutoGpu() const -{ - QString gpu = QString("disable"); - QFile moduleFile(QString("/proc/modules")); - if (!moduleFile.open(QIODevice::ReadOnly)) - return gpu; - - QString output = moduleFile.readAll(); - if (output.contains(QString("fglrx"))) - gpu = QString("ati"); - else if (output.contains(QString("nvidia"))) - gpu = QString("nvidia"); - - qCInfo(LOG_ESM) << "Device" << gpu; - return gpu; -} - - void ExtendedSysMon::readConfiguration() { QString fileName @@ -161,12 +131,12 @@ ExtendedSysMon::updateConfiguration(QHash rawConfig) const if (rawConfig[QString("GPUDEV")] == QString("disable")) rawConfig[QString("GPUDEV")] = QString("disable"); else if (rawConfig[QString("GPUDEV")] == QString("auto")) - rawConfig[QString("GPUDEV")] = getAutoGpu(); + rawConfig[QString("GPUDEV")] = GPUTemperatureSource::autoGpu(); else if ((rawConfig[QString("GPUDEV")] != QString("ati")) && (rawConfig[QString("GPUDEV")] != QString("nvidia"))) - rawConfig[QString("GPUDEV")] = getAutoGpu(); + rawConfig[QString("GPUDEV")] = GPUTemperatureSource::autoGpu(); // hdddev - QStringList allHddDevices = getAllHdd(); + QStringList allHddDevices = HDDTemperatureSource::allHdd(); if (rawConfig[QString("HDDDEV")] == QString("all")) { rawConfig[QString("HDDDEV")] = allHddDevices.join(QChar(',')); } else if (rawConfig[QString("HDDDEV")] == QString("disable")) { diff --git a/sources/extsysmon/extsysmon.h b/sources/extsysmon/extsysmon.h index 72dc025..7ec57df 100644 --- a/sources/extsysmon/extsysmon.h +++ b/sources/extsysmon/extsysmon.h @@ -41,8 +41,6 @@ private: ExtSysMonAggregator *aggregator = nullptr; QHash configuration; // methods - QStringList getAllHdd() const; - QString getAutoGpu() const; void readConfiguration(); QHash updateConfiguration(QHash rawConfig) const; diff --git a/sources/extsysmon/extsysmonaggregator.cpp b/sources/extsysmon/extsysmonaggregator.cpp index e137548..18a7130 100644 --- a/sources/extsysmon/extsysmonaggregator.cpp +++ b/sources/extsysmon/extsysmonaggregator.cpp @@ -18,19 +18,19 @@ #include "extsysmonaggregator.h" #include "awdebug.h" -#include "sources/batterysource.h" -#include "sources/customsource.h" -#include "sources/desktopsource.h" -#include "sources/gpuloadsource.h" -#include "sources/gputempsource.h" -#include "sources/hddtempsource.h" -#include "sources/loadsource.h" -#include "sources/networksource.h" -#include "sources/playersource.h" -#include "sources/processessource.h" -#include "sources/quotessource.h" -#include "sources/upgradesource.h" -#include "sources/weathersource.h" +#include "batterysource.h" +#include "customsource.h" +#include "desktopsource.h" +#include "gpuloadsource.h" +#include "gputempsource.h" +#include "hddtempsource.h" +#include "loadsource.h" +#include "networksource.h" +#include "playersource.h" +#include "processessource.h" +#include "quotessource.h" +#include "upgradesource.h" +#include "weathersource.h" ExtSysMonAggregator::ExtSysMonAggregator(QObject *parent, diff --git a/sources/extsysmon/extsysmonaggregator.h b/sources/extsysmon/extsysmonaggregator.h index 6918a24..ff7cad9 100644 --- a/sources/extsysmon/extsysmonaggregator.h +++ b/sources/extsysmon/extsysmonaggregator.h @@ -20,7 +20,7 @@ #include -#include "sources/abstractextsysmonsource.h" +#include "abstractextsysmonsource.h" class ExtSysMonAggregator : public QObject diff --git a/sources/extsysmonsources/CMakeLists.txt b/sources/extsysmonsources/CMakeLists.txt new file mode 100644 index 0000000..b5940f7 --- /dev/null +++ b/sources/extsysmonsources/CMakeLists.txt @@ -0,0 +1,18 @@ +set(SUBPROJECT ${PROJECT_MONITORSOURCES}) +message(STATUS "Subproject ${SUBPROJECT}") +add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\") + +include_directories( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/ + ${PROJECT_TRDPARTY_DIR} + ${Qt_INCLUDE} + ${Kf5_INCLUDE} +) + +file(GLOB SUBPROJECT_SOURCE *.cpp) +file(GLOB SUBPROJECT_HEADER *.h) + +add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER}) +target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) diff --git a/sources/extsysmon/sources/abstractextsysmonsource.h b/sources/extsysmonsources/abstractextsysmonsource.h similarity index 96% rename from sources/extsysmon/sources/abstractextsysmonsource.h rename to sources/extsysmonsources/abstractextsysmonsource.h index 23526cf..00d82fb 100644 --- a/sources/extsysmon/sources/abstractextsysmonsource.h +++ b/sources/extsysmonsources/abstractextsysmonsource.h @@ -25,6 +25,8 @@ class AbstractExtSysMonSource : public QObject { + Q_OBJECT + public: explicit AbstractExtSysMonSource(QObject *parent, const QStringList) : QObject(parent){}; @@ -40,6 +42,9 @@ public: rx.indexIn(source); return rx.cap().toInt(); } + +signals: + void dataReceived(const QVariantHash &); }; diff --git a/sources/extsysmon/sources/batterysource.cpp b/sources/extsysmonsources/batterysource.cpp similarity index 93% rename from sources/extsysmon/sources/batterysource.cpp rename to sources/extsysmonsources/batterysource.cpp index 96dfae2..985f044 100644 --- a/sources/extsysmon/sources/batterysource.cpp +++ b/sources/extsysmonsources/batterysource.cpp @@ -27,7 +27,7 @@ BatterySource::BatterySource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 1); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_acpiPath = args.at(0); m_sources = getSources(); @@ -36,13 +36,13 @@ BatterySource::BatterySource(QObject *parent, const QStringList args) BatterySource::~BatterySource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant BatterySource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (!m_values.contains(source)) run(); @@ -53,7 +53,7 @@ QVariant BatterySource::data(QString source) QVariantMap BatterySource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("battery/ac")) { @@ -132,10 +132,10 @@ QStringList BatterySource::getSources() .entryList(QStringList() << QString("BAT*"), QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name) .count(); - qCInfo(LOG_ESM) << "Init batteries count as" << m_batteriesCount; + qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount; for (int i = 0; i < m_batteriesCount; i++) sources.append(QString("battery/bat%1").arg(i)); - qCInfo(LOG_ESM) << "Sources list" << sources; + qCInfo(LOG_ESS) << "Sources list" << sources; return sources; } diff --git a/sources/extsysmon/sources/batterysource.h b/sources/extsysmonsources/batterysource.h similarity index 100% rename from sources/extsysmon/sources/batterysource.h rename to sources/extsysmonsources/batterysource.h diff --git a/sources/extsysmon/sources/customsource.cpp b/sources/extsysmonsources/customsource.cpp similarity index 93% rename from sources/extsysmon/sources/customsource.cpp rename to sources/extsysmonsources/customsource.cpp index 26ad6e8..54763f1 100644 --- a/sources/extsysmon/sources/customsource.cpp +++ b/sources/extsysmonsources/customsource.cpp @@ -26,7 +26,7 @@ CustomSource::CustomSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; extScripts = new ExtItemAggregator(nullptr, QString("scripts")); m_sources = getSources(); @@ -35,7 +35,7 @@ CustomSource::CustomSource(QObject *parent, const QStringList args) CustomSource::~CustomSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; delete extScripts; } @@ -43,7 +43,7 @@ CustomSource::~CustomSource() QVariant CustomSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; // there are only one value return extScripts->itemByTagNumber(index(source))->run().values().first(); @@ -52,7 +52,7 @@ QVariant CustomSource::data(QString source) QVariantMap CustomSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; data[QString("min")] = QString(""); diff --git a/sources/extsysmon/sources/customsource.h b/sources/extsysmonsources/customsource.h similarity index 100% rename from sources/extsysmon/sources/customsource.h rename to sources/extsysmonsources/customsource.h diff --git a/sources/extsysmon/sources/desktopsource.cpp b/sources/extsysmonsources/desktopsource.cpp similarity index 95% rename from sources/extsysmon/sources/desktopsource.cpp rename to sources/extsysmonsources/desktopsource.cpp index 3c3ec1d..5723557 100644 --- a/sources/extsysmon/sources/desktopsource.cpp +++ b/sources/extsysmonsources/desktopsource.cpp @@ -27,19 +27,19 @@ DesktopSource::DesktopSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } DesktopSource::~DesktopSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant DesktopSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int current = KWindowSystem::currentDesktop(); int total = KWindowSystem::numberOfDesktops(); @@ -63,7 +63,7 @@ QVariant DesktopSource::data(QString source) QVariantMap DesktopSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("desktop/current/name")) { diff --git a/sources/extsysmon/sources/desktopsource.h b/sources/extsysmonsources/desktopsource.h similarity index 100% rename from sources/extsysmon/sources/desktopsource.h rename to sources/extsysmonsources/desktopsource.h diff --git a/sources/extsysmon/sources/gpuloadsource.cpp b/sources/extsysmonsources/gpuloadsource.cpp similarity index 83% rename from sources/extsysmon/sources/gpuloadsource.cpp rename to sources/extsysmonsources/gpuloadsource.cpp index c7d1396..1a4738d 100644 --- a/sources/extsysmon/sources/gpuloadsource.cpp +++ b/sources/extsysmonsources/gpuloadsource.cpp @@ -18,6 +18,7 @@ #include "gpuloadsource.h" +#include #include #include @@ -28,7 +29,7 @@ GPULoadSource::GPULoadSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 1); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_device = args.at(0); @@ -44,16 +45,34 @@ GPULoadSource::GPULoadSource(QObject *parent, const QStringList args) GPULoadSource::~GPULoadSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_process->kill(); m_process->deleteLater(); } +QString GPULoadSource::autoGpu() +{ + QString gpu = QString("disable"); + QFile moduleFile(QString("/proc/modules")); + if (!moduleFile.open(QIODevice::ReadOnly)) + return gpu; + + QString output = moduleFile.readAll(); + if (output.contains(QString("fglrx"))) + gpu = QString("ati"); + else if (output.contains(QString("nvidia"))) + gpu = QString("nvidia"); + + qCInfo(LOG_ESM) << "Device" << gpu; + return gpu; +} + + QVariant GPULoadSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (source == QString("gpu/load")) run(); @@ -64,7 +83,7 @@ QVariant GPULoadSource::data(QString source) QVariantMap GPULoadSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("gpu/load")) { @@ -87,7 +106,7 @@ void GPULoadSource::run() QString cmd = m_device == QString("nvidia") ? QString("nvidia-smi -q -x") : QString("aticonfig --od-getclocks"); - qCInfo(LOG_ESM) << "cmd" << cmd; + qCInfo(LOG_ESS) << "cmd" << cmd; m_process->start(cmd); } @@ -104,15 +123,15 @@ QStringList GPULoadSource::sources() const void GPULoadSource::updateValue() { - qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode(); + qCInfo(LOG_ESS) << "Cmd returns" << m_process->exitCode(); QString qdebug = QTextCodec::codecForMib(106) ->toUnicode(m_process->readAllStandardError()) .trimmed(); - qCInfo(LOG_LIB) << "Error" << qdebug; + qCInfo(LOG_ESS) << "Error" << qdebug; QString qoutput = QTextCodec::codecForMib(106) ->toUnicode(m_process->readAllStandardOutput()) .trimmed(); - qCInfo(LOG_LIB) << "Output" << qoutput; + qCInfo(LOG_ESS) << "Output" << qoutput; if (m_device == QString("nvidia")) { for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { diff --git a/sources/extsysmon/sources/gpuloadsource.h b/sources/extsysmonsources/gpuloadsource.h similarity index 98% rename from sources/extsysmon/sources/gpuloadsource.h rename to sources/extsysmonsources/gpuloadsource.h index 38e611b..c213309 100644 --- a/sources/extsysmon/sources/gpuloadsource.h +++ b/sources/extsysmonsources/gpuloadsource.h @@ -30,6 +30,7 @@ class GPULoadSource : public AbstractExtSysMonSource public: explicit GPULoadSource(QObject *parent, const QStringList args); virtual ~GPULoadSource(); + static QString autoGpu(); QVariant data(QString source); QVariantMap initialData(QString source) const; void run(); diff --git a/sources/extsysmon/sources/gputempsource.cpp b/sources/extsysmonsources/gputempsource.cpp similarity index 82% rename from sources/extsysmon/sources/gputempsource.cpp rename to sources/extsysmonsources/gputempsource.cpp index 45cdc4b..e69ff7c 100644 --- a/sources/extsysmon/sources/gputempsource.cpp +++ b/sources/extsysmonsources/gputempsource.cpp @@ -18,6 +18,7 @@ #include "gputempsource.h" +#include #include #include @@ -29,7 +30,7 @@ GPUTemperatureSource::GPUTemperatureSource(QObject *parent, : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 1); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_device = args.at(0); @@ -45,16 +46,34 @@ GPUTemperatureSource::GPUTemperatureSource(QObject *parent, GPUTemperatureSource::~GPUTemperatureSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_process->kill(); m_process->deleteLater(); } +QString GPUTemperatureSource::autoGpu() +{ + QString gpu = QString("disable"); + QFile moduleFile(QString("/proc/modules")); + if (!moduleFile.open(QIODevice::ReadOnly)) + return gpu; + + QString output = moduleFile.readAll(); + if (output.contains(QString("fglrx"))) + gpu = QString("ati"); + else if (output.contains(QString("nvidia"))) + gpu = QString("nvidia"); + + qCInfo(LOG_ESM) << "Device" << gpu; + return gpu; +} + + QVariant GPUTemperatureSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (source == QString("gpu/temperature")) run(); @@ -65,7 +84,7 @@ QVariant GPUTemperatureSource::data(QString source) QVariantMap GPUTemperatureSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("gpu/temperature")) { @@ -88,7 +107,7 @@ void GPUTemperatureSource::run() QString cmd = m_device == QString("nvidia") ? QString("nvidia-smi -q -x") : QString("aticonfig --od-gettemperature"); - qCInfo(LOG_ESM) << "cmd" << cmd; + qCInfo(LOG_ESS) << "cmd" << cmd; m_process->start(cmd); } @@ -105,15 +124,15 @@ QStringList GPUTemperatureSource::sources() const void GPUTemperatureSource::updateValue() { - qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode(); + qCInfo(LOG_ESS) << "Cmd returns" << m_process->exitCode(); QString qdebug = QTextCodec::codecForMib(106) ->toUnicode(m_process->readAllStandardError()) .trimmed(); - qCInfo(LOG_LIB) << "Error" << qdebug; + qCInfo(LOG_ESS) << "Error" << qdebug; QString qoutput = QTextCodec::codecForMib(106) ->toUnicode(m_process->readAllStandardOutput()) .trimmed(); - qCInfo(LOG_LIB) << "Output" << qoutput; + qCInfo(LOG_ESS) << "Output" << qoutput; if (m_device == QString("nvidia")) { for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { diff --git a/sources/extsysmon/sources/gputempsource.h b/sources/extsysmonsources/gputempsource.h similarity index 98% rename from sources/extsysmon/sources/gputempsource.h rename to sources/extsysmonsources/gputempsource.h index fc2d7a0..62332c2 100644 --- a/sources/extsysmon/sources/gputempsource.h +++ b/sources/extsysmonsources/gputempsource.h @@ -30,6 +30,7 @@ class GPUTemperatureSource : public AbstractExtSysMonSource public: explicit GPUTemperatureSource(QObject *parent, const QStringList args); virtual ~GPUTemperatureSource(); + static QString autoGpu(); QVariant data(QString source); QVariantMap initialData(QString source) const; void run(); diff --git a/sources/extsysmon/sources/hddtempsource.cpp b/sources/extsysmonsources/hddtempsource.cpp similarity index 78% rename from sources/extsysmon/sources/hddtempsource.cpp rename to sources/extsysmonsources/hddtempsource.cpp index b0774e1..3fffff2 100644 --- a/sources/extsysmon/sources/hddtempsource.cpp +++ b/sources/extsysmonsources/hddtempsource.cpp @@ -18,6 +18,7 @@ #include "hddtempsource.h" +#include #include #include @@ -29,13 +30,13 @@ HDDTemperatureSource::HDDTemperatureSource(QObject *parent, : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 2); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_devices = args.at(0).split(QChar(','), QString::SkipEmptyParts); m_cmd = args.at(1); m_smartctl = m_cmd.contains(QString("smartctl")); - qCInfo(LOG_ESM) << "Parse as smartctl" << m_smartctl; + qCInfo(LOG_ESS) << "Parse as smartctl" << m_smartctl; for (auto device : m_devices) { m_processes[device] = new QProcess(nullptr); @@ -53,7 +54,7 @@ HDDTemperatureSource::HDDTemperatureSource(QObject *parent, HDDTemperatureSource::~HDDTemperatureSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; for (auto device : m_devices) { m_processes[device]->kill(); @@ -62,9 +63,22 @@ HDDTemperatureSource::~HDDTemperatureSource() } +QStringList HDDTemperatureSource::allHdd() +{ + QStringList allDevices + = QDir(QString("/dev")).entryList(QDir::System, QDir::Name); + QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$"))); + for (int i = 0; i < devices.count(); i++) + devices[i] = QString("/dev/%1").arg(devices.at(i)); + + qCInfo(LOG_ESS) << "Device list" << devices; + return devices; +} + + QVariant HDDTemperatureSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QString device = source.remove(QString("hdd/temperature")); // run cmd @@ -77,7 +91,7 @@ QVariant HDDTemperatureSource::data(QString source) QVariantMap HDDTemperatureSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QString device = source.remove(QString("hdd/temperature")); QVariantMap data; @@ -103,23 +117,24 @@ QStringList HDDTemperatureSource::sources() const void HDDTemperatureSource::updateValue(const QString &device) { - qCDebug(LOG_LIB) << "Called with device" << device; + qCDebug(LOG_ESS) << "Called with device" << device; - qCInfo(LOG_LIB) << "Cmd returns" << m_processes[device]->exitCode(); + qCInfo(LOG_ESS) << "Cmd returns" << m_processes[device]->exitCode(); QString qdebug = QTextCodec::codecForMib(106) ->toUnicode(m_processes[device]->readAllStandardError()) .trimmed(); - qCInfo(LOG_LIB) << "Error" << qdebug; + qCInfo(LOG_ESS) << "Error" << qdebug; QString qoutput = QTextCodec::codecForMib(106) ->toUnicode(m_processes[device]->readAllStandardOutput()) .trimmed(); - qCInfo(LOG_LIB) << "Output" << qoutput; + qCInfo(LOG_ESS) << "Output" << qoutput; // parse if (m_smartctl) { - for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { + QStringList lines = qoutput.split(QChar('\n'), QString::SkipEmptyParts); + for (auto str : lines) { if (!str.startsWith(QString("194"))) continue; if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9) @@ -130,11 +145,13 @@ void HDDTemperatureSource::updateValue(const QString &device) break; } } else { - if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) { - QString temp - = qoutput.split(QChar(':'), QString::SkipEmptyParts).at(2); + QStringList lines = qoutput.split(QChar(':'), QString::SkipEmptyParts); + if (lines.count() >= 3) { + QString temp = lines.at(2); temp.remove(QChar(0260)).remove(QChar('C')); m_values[device] = temp.toFloat(); } } + + emit(dataReceived(m_values)); } diff --git a/sources/extsysmon/sources/hddtempsource.h b/sources/extsysmonsources/hddtempsource.h similarity index 98% rename from sources/extsysmon/sources/hddtempsource.h rename to sources/extsysmonsources/hddtempsource.h index ffc37b4..2daf711 100644 --- a/sources/extsysmon/sources/hddtempsource.h +++ b/sources/extsysmonsources/hddtempsource.h @@ -30,6 +30,7 @@ class HDDTemperatureSource : public AbstractExtSysMonSource public: explicit HDDTemperatureSource(QObject *parent, const QStringList args); virtual ~HDDTemperatureSource(); + static QStringList allHdd(); QVariant data(QString source); QVariantMap initialData(QString source) const; void run(){}; diff --git a/sources/extsysmon/sources/loadsource.cpp b/sources/extsysmonsources/loadsource.cpp similarity index 92% rename from sources/extsysmon/sources/loadsource.cpp rename to sources/extsysmonsources/loadsource.cpp index e5eff33..7b9d008 100644 --- a/sources/extsysmon/sources/loadsource.cpp +++ b/sources/extsysmonsources/loadsource.cpp @@ -25,19 +25,19 @@ LoadSource::LoadSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } LoadSource::~LoadSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant LoadSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; source.remove(QString("load/load")); return source.toInt(); @@ -46,7 +46,7 @@ QVariant LoadSource::data(QString source) QVariantMap LoadSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source.startsWith(QString("load/load"))) { diff --git a/sources/extsysmon/sources/loadsource.h b/sources/extsysmonsources/loadsource.h similarity index 100% rename from sources/extsysmon/sources/loadsource.h rename to sources/extsysmonsources/loadsource.h diff --git a/sources/extsysmon/sources/networksource.cpp b/sources/extsysmonsources/networksource.cpp similarity index 92% rename from sources/extsysmon/sources/networksource.cpp rename to sources/extsysmonsources/networksource.cpp index 45a27ef..249601d 100644 --- a/sources/extsysmon/sources/networksource.cpp +++ b/sources/extsysmonsources/networksource.cpp @@ -27,25 +27,25 @@ NetworkSource::NetworkSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } NetworkSource::~NetworkSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant NetworkSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (source == QString("network/current/name")) { QString device = QString("lo"); QList rawInterfaceList = QNetworkInterface::allInterfaces(); - qCInfo(LOG_ESM) << "Devices" << rawInterfaceList; + qCInfo(LOG_ESS) << "Devices" << rawInterfaceList; for (auto interface : rawInterfaceList) { if ((interface.flags().testFlag(QNetworkInterface::IsLoopBack)) || (interface.flags().testFlag( @@ -65,7 +65,7 @@ QVariant NetworkSource::data(QString source) QVariantMap NetworkSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("network/current/name")) { diff --git a/sources/extsysmon/sources/networksource.h b/sources/extsysmonsources/networksource.h similarity index 100% rename from sources/extsysmon/sources/networksource.h rename to sources/extsysmonsources/networksource.h diff --git a/sources/extsysmon/sources/playersource.cpp b/sources/extsysmonsources/playersource.cpp similarity index 95% rename from sources/extsysmon/sources/playersource.cpp rename to sources/extsysmonsources/playersource.cpp index df832e1..80c159b 100644 --- a/sources/extsysmon/sources/playersource.cpp +++ b/sources/extsysmonsources/playersource.cpp @@ -32,7 +32,7 @@ PlayerSource::PlayerSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 5); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_player = args.at(0); m_mpdAddress = QString("%1:%2").arg(args.at(1)).arg(args.at(2)); @@ -52,7 +52,7 @@ PlayerSource::PlayerSource(QObject *parent, const QStringList args) PlayerSource::~PlayerSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_mpdProcess->kill(); m_mpdProcess->deleteLater(); @@ -61,7 +61,7 @@ PlayerSource::~PlayerSource() QVariant PlayerSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (!m_values.contains(source)) run(); @@ -72,7 +72,7 @@ QVariant PlayerSource::data(QString source) QVariantMap PlayerSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("player/album")) { @@ -214,15 +214,15 @@ QStringList PlayerSource::sources() const void PlayerSource::updateValue() { - qCInfo(LOG_LIB) << "Cmd returns" << m_mpdProcess->exitCode(); + qCInfo(LOG_ESS) << "Cmd returns" << m_mpdProcess->exitCode(); QString qdebug = QTextCodec::codecForMib(106) ->toUnicode(m_mpdProcess->readAllStandardError()) .trimmed(); - qCInfo(LOG_LIB) << "Error" << qdebug; + qCInfo(LOG_ESS) << "Error" << qdebug; QString qoutput = QTextCodec::codecForMib(106) ->toUnicode(m_mpdProcess->readAllStandardOutput()) .trimmed(); - qCInfo(LOG_LIB) << "Output" << qoutput; + qCInfo(LOG_ESS) << "Output" << qoutput; for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { if (str.split(QString(": "), QString::SkipEmptyParts).count() == 2) { @@ -270,7 +270,7 @@ QString PlayerSource::getAutoMpris() const for (auto arg : arguments) { if (!arg.startsWith(QString("org.mpris.MediaPlayer2."))) continue; - qCInfo(LOG_ESM) << "Service found" << arg; + qCInfo(LOG_ESS) << "Service found" << arg; QString service = arg; service.remove(QString("org.mpris.MediaPlayer2.")); return service; @@ -282,13 +282,13 @@ QString PlayerSource::getAutoMpris() const QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const { - qCDebug(LOG_ESM) << "MPD" << mpdAddress; + qCDebug(LOG_ESS) << "MPD" << mpdAddress; // build cmd QString cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl " "--connect-timeout 1 -fsm 3 telnet://%1\"") .arg(mpdAddress); - qCInfo(LOG_ESM) << "cmd" << cmd; + qCInfo(LOG_ESS) << "cmd" << cmd; m_mpdProcess->start(cmd); return m_mpdCached; @@ -297,7 +297,7 @@ QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const { - qCDebug(LOG_ESM) << "MPRIS" << mpris; + qCDebug(LOG_ESS) << "MPRIS" << mpris; QVariantHash info = defaultInfo(); if (mpris.isEmpty()) @@ -322,7 +322,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const QDBusMessage response = bus.call(request, QDBus::BlockWithGui); if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { - qCWarning(LOG_ESM) << "Error message" << response.errorMessage(); + qCWarning(LOG_ESS) << "Error message" << response.errorMessage(); } else { // another portion of dirty magic QVariantHash map @@ -348,7 +348,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const response = bus.call(request, QDBus::BlockWithGui); if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { - qCWarning(LOG_ESM) << "Error message" << response.errorMessage(); + qCWarning(LOG_ESS) << "Error message" << response.errorMessage(); } else { // this cast is simpler than the previous one ;) info[QString("player/progress")] = response.arguments() @@ -366,7 +366,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const QString PlayerSource::buildString(const QString current, const QString value, const int s) const { - qCDebug(LOG_ESM) << "Current value" << current << "received" << value + qCDebug(LOG_ESS) << "Current value" << current << "received" << value << "will be stripped after" << s; int index = value.indexOf(current); @@ -379,7 +379,7 @@ QString PlayerSource::buildString(const QString current, const QString value, QString PlayerSource::stripString(const QString value, const int s) const { - qCDebug(LOG_ESM) << "New value" << value << "will be stripped after" << s; + qCDebug(LOG_ESS) << "New value" << value << "will be stripped after" << s; return value.count() > s ? QString("%1\u2026").arg(value.left(s - 1)) : value.leftJustified(s, QLatin1Char(' ')); diff --git a/sources/extsysmon/sources/playersource.h b/sources/extsysmonsources/playersource.h similarity index 100% rename from sources/extsysmon/sources/playersource.h rename to sources/extsysmonsources/playersource.h diff --git a/sources/extsysmon/sources/processessource.cpp b/sources/extsysmonsources/processessource.cpp similarity index 95% rename from sources/extsysmon/sources/processessource.cpp rename to sources/extsysmonsources/processessource.cpp index 6054909..7cdcdf3 100644 --- a/sources/extsysmon/sources/processessource.cpp +++ b/sources/extsysmonsources/processessource.cpp @@ -27,19 +27,19 @@ ProcessesSource::ProcessesSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } ProcessesSource::~ProcessesSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant ProcessesSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (!m_values.contains(source)) run(); @@ -50,7 +50,7 @@ QVariant ProcessesSource::data(QString source) QVariantMap ProcessesSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("ps/running/count")) { diff --git a/sources/extsysmon/sources/processessource.h b/sources/extsysmonsources/processessource.h similarity index 100% rename from sources/extsysmon/sources/processessource.h rename to sources/extsysmonsources/processessource.h diff --git a/sources/extsysmon/sources/quotessource.cpp b/sources/extsysmonsources/quotessource.cpp similarity index 97% rename from sources/extsysmon/sources/quotessource.cpp rename to sources/extsysmonsources/quotessource.cpp index 4a44b09..238136f 100644 --- a/sources/extsysmon/sources/quotessource.cpp +++ b/sources/extsysmonsources/quotessource.cpp @@ -26,7 +26,7 @@ QuotesSource::QuotesSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; extQuotes = new ExtItemAggregator(nullptr, QString("quotes")); m_sources = getSources(); @@ -35,7 +35,7 @@ QuotesSource::QuotesSource(QObject *parent, const QStringList args) QuotesSource::~QuotesSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; delete extQuotes; } @@ -43,7 +43,7 @@ QuotesSource::~QuotesSource() QVariant QuotesSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int ind = index(source); source.remove(QString("quotes/")); @@ -59,7 +59,7 @@ QVariant QuotesSource::data(QString source) QVariantMap QuotesSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int ind = index(source); QVariantMap data; diff --git a/sources/extsysmon/sources/quotessource.h b/sources/extsysmonsources/quotessource.h similarity index 100% rename from sources/extsysmon/sources/quotessource.h rename to sources/extsysmonsources/quotessource.h diff --git a/sources/extsysmon/sources/upgradesource.cpp b/sources/extsysmonsources/upgradesource.cpp similarity index 93% rename from sources/extsysmon/sources/upgradesource.cpp rename to sources/extsysmonsources/upgradesource.cpp index 243c0bd..0103da8 100644 --- a/sources/extsysmon/sources/upgradesource.cpp +++ b/sources/extsysmonsources/upgradesource.cpp @@ -26,7 +26,7 @@ UpgradeSource::UpgradeSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; extUpgrade = new ExtItemAggregator(nullptr, QString("upgrade")); m_sources = getSources(); @@ -35,7 +35,7 @@ UpgradeSource::UpgradeSource(QObject *parent, const QStringList args) UpgradeSource::~UpgradeSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; delete extUpgrade; } @@ -43,7 +43,7 @@ UpgradeSource::~UpgradeSource() QVariant UpgradeSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; // there are only one value return extUpgrade->itemByTagNumber(index(source))->run().values().first(); @@ -52,7 +52,7 @@ QVariant UpgradeSource::data(QString source) QVariantMap UpgradeSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; data[QString("min")] = QString(""); diff --git a/sources/extsysmon/sources/upgradesource.h b/sources/extsysmonsources/upgradesource.h similarity index 100% rename from sources/extsysmon/sources/upgradesource.h rename to sources/extsysmonsources/upgradesource.h diff --git a/sources/extsysmon/sources/weathersource.cpp b/sources/extsysmonsources/weathersource.cpp similarity index 96% rename from sources/extsysmon/sources/weathersource.cpp rename to sources/extsysmonsources/weathersource.cpp index 910ad31..1f95a90 100644 --- a/sources/extsysmon/sources/weathersource.cpp +++ b/sources/extsysmonsources/weathersource.cpp @@ -26,7 +26,7 @@ WeatherSource::WeatherSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; extWeather = new ExtItemAggregator(nullptr, QString("weather")); m_sources = getSources(); @@ -35,7 +35,7 @@ WeatherSource::WeatherSource(QObject *parent, const QStringList args) WeatherSource::~WeatherSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; delete extWeather; } @@ -43,7 +43,7 @@ WeatherSource::~WeatherSource() QVariant WeatherSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int ind = index(source); source.remove(QString("weather/")); @@ -59,7 +59,7 @@ QVariant WeatherSource::data(QString source) QVariantMap WeatherSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int ind = index(source); QVariantMap data; diff --git a/sources/extsysmon/sources/weathersource.h b/sources/extsysmonsources/weathersource.h similarity index 100% rename from sources/extsysmon/sources/weathersource.h rename to sources/extsysmonsources/weathersource.h diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index b6032f0..eb944a1 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/ + ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/ ${PROJECT_TRDPARTY_DIR} ${Qt_INCLUDE} ${Qt5Test_INCLUDE_DIRS} @@ -18,13 +19,14 @@ set(AWTESTLIBRARY_HEADERS awtestlibrary.h) set(AWTESTLIBRARY_SOURCES awtestlibrary.cpp) add_library(${SUBPROJECT}-awtest STATIC ${AWTESTLIBRARY_SOURCES} ${AWTESTLIBRARY_HEADERS}) target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) -set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) ## modules set(TEST_MODULES abstractextitem extquotes extscript extupgrade extweather abstractformatter datetimeformatter floatformatter noformatter scriptformatter - extitemaggregator) + extitemaggregator + hddtempsource) foreach (TEST_MODULE ${TEST_MODULES}) set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h) set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp) diff --git a/sources/test/testextitemaggregator.h b/sources/test/testextitemaggregator.h index e5fc449..022e501 100644 --- a/sources/test/testextitemaggregator.h +++ b/sources/test/testextitemaggregator.h @@ -21,8 +21,9 @@ #include + class AWNoFormatter; -template class ExtItemAggregator; +template class ExtItemAggregator; class TestExtItemAggregator : public QObject { diff --git a/sources/test/testextweather.cpp b/sources/test/testextweather.cpp index d1d38d9..825ee26 100644 --- a/sources/test/testextweather.cpp +++ b/sources/test/testextweather.cpp @@ -123,13 +123,13 @@ void TestExtWeather::run() QWARN("May fail here for Yahoo! Weather, see " "https://yahoo.uservoice.com/forums/207813-us-weather/suggestions/" "14209233-invalid-pressure-calculation"); - QVERIFY((arguments[extWeather->tag(QString("pressure"))].toFloat() + QVERIFY((arguments[extWeather->tag(QString("pressure"))].toInt() > pressure.first) && (arguments[extWeather->tag(QString("pressure"))].toInt() < pressure.second)); QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat() > temp.first) - && (arguments[extWeather->tag(QString("temperature"))].toInt() + && (arguments[extWeather->tag(QString("temperature"))].toFloat() < temp.second)); // image should be only one symbol here QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(), diff --git a/sources/test/testhddtempsource.cpp b/sources/test/testhddtempsource.cpp new file mode 100644 index 0000000..de4914b --- /dev/null +++ b/sources/test/testhddtempsource.cpp @@ -0,0 +1,91 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testhddtempsource.h" + +#include + +#include "awtestlibrary.h" +#include "hddtempsource.h" + + +void TestHDDTemperatureSource::initTestCase() +{ + devices = HDDTemperatureSource::allHdd(); + QVERIFY(devices.count() > 0); + + hddtempSource = new HDDTemperatureSource( + this, QStringList() << devices.join(QChar(',')) << hddtempCmd); + smartctlSource = new HDDTemperatureSource( + this, QStringList() << devices.join(QChar(',')) << smartctlCmd); +} + + +void TestHDDTemperatureSource::cleanupTestCase() +{ + delete hddtempSource; + delete smartctlSource; +} + + +void TestHDDTemperatureSource::test_sources() +{ + std::for_each(devices.begin(), devices.end(), [](QString &device) { + device.prepend(QString("hdd/temperature")); + }); + + QCOMPARE(hddtempSource->sources(), devices); + QCOMPARE(smartctlSource->sources(), devices); +} + + +void TestHDDTemperatureSource::test_hddtemp() +{ + std::for_each(devices.begin(), devices.end(), [this](QString device) { + QSignalSpy spy(hddtempSource, + SIGNAL(dataReceived(const QVariantHash &))); + float firstValue = hddtempSource->data(device).toFloat(); + QCOMPARE(firstValue, 0.0f); + + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + device.remove(QString("hdd/temperature")); + float secondValue = arguments[device].toFloat(); + QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second)); + }); +} + + +void TestHDDTemperatureSource::test_smartctl() +{ + std::for_each(devices.begin(), devices.end(), [this](QString &device) { + QSignalSpy spy(smartctlSource, + SIGNAL(dataReceived(const QVariantHash &))); + float firstValue = smartctlSource->data(device).toFloat(); + QCOMPARE(firstValue, 0.0f); + + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + device.remove(QString("hdd/temperature")); + float secondValue = arguments[device].toFloat(); + QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second)); + }); +} + + +QTEST_MAIN(TestHDDTemperatureSource); diff --git a/sources/test/testhddtempsource.h b/sources/test/testhddtempsource.h new file mode 100644 index 0000000..b558692 --- /dev/null +++ b/sources/test/testhddtempsource.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTHDDTEMPSOURCE_H +#define TESTHDDTEMPSOURCE_H + +#include + + +class HDDTemperatureSource; + +class TestHDDTemperatureSource : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_sources(); + void test_hddtemp(); + void test_smartctl(); + +private: + HDDTemperatureSource *hddtempSource = nullptr; + HDDTemperatureSource *smartctlSource = nullptr; + QStringList devices; + QString hddtempCmd = QString("sudo hddtemp"); + QString smartctlCmd = QString("sudo smartctl -a"); + QPair temp = QPair(0.0f, 40.0f); +}; + + +#endif /* TESTHDDTEMPSOURCE_H */ From bc2071a49345d7664f71d7c532cc1d157883dbce Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 8 Jun 2016 12:33:55 +0300 Subject: [PATCH 27/32] add gputemperature tests --- sources/extsysmonsources/gputempsource.cpp | 32 ++++++----- sources/extsysmonsources/gputempsource.h | 2 +- sources/test/testgputempsource.cpp | 64 ++++++++++++++++++++++ sources/test/testgputempsource.h | 47 ++++++++++++++++ 4 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 sources/test/testgputempsource.cpp create mode 100644 sources/test/testgputempsource.h diff --git a/sources/extsysmonsources/gputempsource.cpp b/sources/extsysmonsources/gputempsource.cpp index e69ff7c..437c143 100644 --- a/sources/extsysmonsources/gputempsource.cpp +++ b/sources/extsysmonsources/gputempsource.cpp @@ -55,19 +55,19 @@ GPUTemperatureSource::~GPUTemperatureSource() QString GPUTemperatureSource::autoGpu() { - QString gpu = QString("disable"); - QFile moduleFile(QString("/proc/modules")); - if (!moduleFile.open(QIODevice::ReadOnly)) - return gpu; - - QString output = moduleFile.readAll(); - if (output.contains(QString("fglrx"))) - gpu = QString("ati"); - else if (output.contains(QString("nvidia"))) - gpu = QString("nvidia"); - - qCInfo(LOG_ESM) << "Device" << gpu; + QString gpu = QString("disable"); + QFile moduleFile(QString("/proc/modules")); + if (!moduleFile.open(QIODevice::ReadOnly)) return gpu; + + QString output = moduleFile.readAll(); + if (output.contains(QString("fglrx"))) + gpu = QString("ati"); + else if (output.contains(QString("nvidia"))) + gpu = QString("nvidia"); + + qCInfo(LOG_ESM) << "Device" << gpu; + return gpu; } @@ -78,7 +78,7 @@ QVariant GPUTemperatureSource::data(QString source) if (source == QString("gpu/temperature")) run(); - return m_value; + return m_values[source]; } @@ -140,7 +140,7 @@ void GPUTemperatureSource::updateValue() continue; QString temp = str.remove(QString("")) .remove(QString("C")); - m_value = temp.toFloat(); + m_values[QString("gpu/temperature")] = temp.toFloat(); break; } } else if (m_device == QString("ati")) { @@ -148,8 +148,10 @@ void GPUTemperatureSource::updateValue() if (!str.contains(QString("Temperature"))) continue; QString temp = str.split(QChar(' '), QString::SkipEmptyParts).at(4); - m_value = temp.toFloat(); + m_values[QString("gpu/temperature")] = temp.toFloat(); break; } } + + emit(dataReceived(m_values)); } diff --git a/sources/extsysmonsources/gputempsource.h b/sources/extsysmonsources/gputempsource.h index 62332c2..0ebfc62 100644 --- a/sources/extsysmonsources/gputempsource.h +++ b/sources/extsysmonsources/gputempsource.h @@ -43,7 +43,7 @@ private: // configuration and values QString m_device; QProcess *m_process = nullptr; - QVariant m_value; + QVariantHash m_values; }; diff --git a/sources/test/testgputempsource.cpp b/sources/test/testgputempsource.cpp new file mode 100644 index 0000000..29a8f36 --- /dev/null +++ b/sources/test/testgputempsource.cpp @@ -0,0 +1,64 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testgputempsource.h" + +#include + +#include "awtestlibrary.h" +#include "gputempsource.h" + + +void TestGPUTemperatureSource::initTestCase() +{ + device = GPUTemperatureSource::autoGpu(); + QVERIFY(!device.isEmpty()); + + gputempSource = new GPUTemperatureSource(this, QStringList() << device); +} + + +void TestGPUTemperatureSource::cleanupTestCase() +{ + delete gputempSource; +} + + +void TestGPUTemperatureSource::test_sources() +{ + QCOMPARE(gputempSource->sources(), QStringList() << source); +} + + +void TestGPUTemperatureSource::test_gputemp() +{ + if (device == QString("disable")) + QSKIP("Not supported device, test will be skipped"); + + QSignalSpy spy(gputempSource, SIGNAL(dataReceived(const QVariantHash &))); + float firstValue = gputempSource->data(source).toFloat(); + QCOMPARE(firstValue, 0.0f); + + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + float secondValue = arguments[source].toFloat(); + QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second)); +} + + +QTEST_MAIN(TestGPUTemperatureSource); diff --git a/sources/test/testgputempsource.h b/sources/test/testgputempsource.h new file mode 100644 index 0000000..f095066 --- /dev/null +++ b/sources/test/testgputempsource.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTGPUTEMPSOURCE_H +#define TESTGPUTEMPSOURCE_H + +#include + + +class GPUTemperatureSource; + +class TestGPUTemperatureSource : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_sources(); + void test_gputemp(); + +private: + GPUTemperatureSource *gputempSource = nullptr; + QString device; + QString source = QString("gpu/temperature"); + QPair temp = QPair(0.0f, 40.0f); +}; + + +#endif /* TESTGPUTEMPSOURCE_H */ From 78b7a87c29450da1238190ce74da6bf03fc1898a Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 9 Jun 2016 12:45:21 +0300 Subject: [PATCH 28/32] add tests for battery and gpuload sources + some tests refactoring --- sources/extsysmonsources/batterysource.cpp | 39 ++++++------- sources/extsysmonsources/batterysource.h | 2 +- sources/extsysmonsources/gpuloadsource.cpp | 6 +- sources/extsysmonsources/gpuloadsource.h | 2 +- sources/test/CMakeLists.txt | 2 +- sources/test/testbatterysource.cpp | 61 ++++++++++++++++++++ sources/test/testbatterysource.h | 46 +++++++++++++++ sources/test/testextquotes.cpp | 6 +- sources/test/testextscript.cpp | 5 +- sources/test/testextupgrade.cpp | 3 +- sources/test/testgpuloadsource.cpp | 65 ++++++++++++++++++++++ sources/test/testgpuloadsource.h | 47 ++++++++++++++++ sources/test/testgputempsource.cpp | 15 ++--- sources/test/testgputempsource.h | 6 +- sources/test/testhddtempsource.cpp | 6 +- sources/test/testhddtempsource.h | 2 +- 16 files changed, 269 insertions(+), 44 deletions(-) create mode 100644 sources/test/testbatterysource.cpp create mode 100644 sources/test/testbatterysource.h create mode 100644 sources/test/testgpuloadsource.cpp create mode 100644 sources/test/testgpuloadsource.h diff --git a/sources/extsysmonsources/batterysource.cpp b/sources/extsysmonsources/batterysource.cpp index 985f044..fa1d161 100644 --- a/sources/extsysmonsources/batterysource.cpp +++ b/sources/extsysmonsources/batterysource.cpp @@ -40,6 +40,26 @@ BatterySource::~BatterySource() } + +QStringList BatterySource::getSources() +{ + QStringList sources; + sources.append(QString("battery/ac")); + sources.append(QString("battery/bat")); + m_batteriesCount + = QDir(m_acpiPath) + .entryList(QStringList() << QString("BAT*"), + QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name) + .count(); + qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount; + for (int i = 0; i < m_batteriesCount; i++) + sources.append(QString("battery/bat%1").arg(i)); + + qCInfo(LOG_ESS) << "Sources list" << sources; + return sources; +} + + QVariant BatterySource::data(QString source) { qCDebug(LOG_ESS) << "Source" << source; @@ -120,22 +140,3 @@ QStringList BatterySource::sources() const { return m_sources; } - - -QStringList BatterySource::getSources() -{ - QStringList sources; - sources.append(QString("battery/ac")); - sources.append(QString("battery/bat")); - m_batteriesCount - = QDir(m_acpiPath) - .entryList(QStringList() << QString("BAT*"), - QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name) - .count(); - qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount; - for (int i = 0; i < m_batteriesCount; i++) - sources.append(QString("battery/bat%1").arg(i)); - - qCInfo(LOG_ESS) << "Sources list" << sources; - return sources; -} diff --git a/sources/extsysmonsources/batterysource.h b/sources/extsysmonsources/batterysource.h index 09403c7..4779641 100644 --- a/sources/extsysmonsources/batterysource.h +++ b/sources/extsysmonsources/batterysource.h @@ -28,13 +28,13 @@ class BatterySource : public AbstractExtSysMonSource public: explicit BatterySource(QObject *parent, const QStringList args); virtual ~BatterySource(); + QStringList getSources(); QVariant data(QString source); QVariantMap initialData(QString source) const; void run(); QStringList sources() const; private: - QStringList getSources(); // configuration and values int m_batteriesCount = 0; QString m_acpiPath; diff --git a/sources/extsysmonsources/gpuloadsource.cpp b/sources/extsysmonsources/gpuloadsource.cpp index 1a4738d..b85db70 100644 --- a/sources/extsysmonsources/gpuloadsource.cpp +++ b/sources/extsysmonsources/gpuloadsource.cpp @@ -77,7 +77,7 @@ QVariant GPULoadSource::data(QString source) if (source == QString("gpu/load")) run(); - return m_value; + return m_values[source]; } @@ -140,7 +140,7 @@ void GPULoadSource::updateValue() QString load = str.remove(QString("")) .remove(QString("")) .remove(QChar('%')); - m_value = load.toFloat(); + m_values[QString("gpu/load")] = load.toFloat(); break; } } else if (m_device == QString("ati")) { @@ -150,7 +150,7 @@ void GPULoadSource::updateValue() QString load = str.split(QChar(' '), QString::SkipEmptyParts)[3].remove( QChar('%')); - m_value = load.toFloat(); + m_values[QString("gpu/load")] = load.toFloat(); break; } } diff --git a/sources/extsysmonsources/gpuloadsource.h b/sources/extsysmonsources/gpuloadsource.h index c213309..4caa8fa 100644 --- a/sources/extsysmonsources/gpuloadsource.h +++ b/sources/extsysmonsources/gpuloadsource.h @@ -43,7 +43,7 @@ private: // configuration and values QString m_device; QProcess *m_process = nullptr; - QVariant m_value; + QVariantHash m_values; }; diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index eb944a1..6703c72 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -26,7 +26,7 @@ set(TEST_MODULES abstractextitem extquotes extscript extupgrade extweather abstractformatter datetimeformatter floatformatter noformatter scriptformatter extitemaggregator - hddtempsource) + batterysource gpuloadsource gputempsource hddtempsource) foreach (TEST_MODULE ${TEST_MODULES}) set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h) set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp) diff --git a/sources/test/testbatterysource.cpp b/sources/test/testbatterysource.cpp new file mode 100644 index 0000000..636df6a --- /dev/null +++ b/sources/test/testbatterysource.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testbatterysource.h" + +#include + +#include "awtestlibrary.h" +#include "batterysource.h" + + +void TestBatterySource::initTestCase() +{ + source = new BatterySource(this, QStringList() << acpiPath); +} + + +void TestBatterySource::cleanupTestCase() +{ + delete source; +} + + +void TestBatterySource::test_sources() +{ + QVERIFY(source->sources().count() >= 2); +} + + +void TestBatterySource::test_battery() +{ + if (source->sources().count() == 2) + QSKIP("No battery found, test will be skipped"); + + QStringList batteries = source->sources(); + std::for_each(batteries.begin(), batteries.end(), [this](const QString bat) { + QVariant value = source->data(bat); + if (bat == QString("battery/ac")) + QCOMPARE(value.type(), QVariant::Bool); + else + QVERIFY((value.toFloat() >= battery.first) && (value.toFloat() <= battery.second)); + }); +} + + +QTEST_MAIN(TestBatterySource); diff --git a/sources/test/testbatterysource.h b/sources/test/testbatterysource.h new file mode 100644 index 0000000..c51dfc9 --- /dev/null +++ b/sources/test/testbatterysource.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTBATTERYSOURCE_H +#define TESTBATTERYSOURCE_H + +#include + + +class BatterySource; + +class TestBatterySource : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_sources(); + void test_battery(); + +private: + BatterySource *source = nullptr; + QString acpiPath = QString("/sys/class/power_supply/"); + QPair battery = QPair(0, 100); +}; + + +#endif /* TESTBATTERYSOURCE_H */ diff --git a/sources/test/testextquotes.cpp b/sources/test/testextquotes.cpp index 67aa9e4..095f5d4 100644 --- a/sources/test/testextquotes.cpp +++ b/sources/test/testextquotes.cpp @@ -53,9 +53,6 @@ void TestExtQuotes::test_run() // init spy QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &))); QVariantHash firstValue = extQuotes->run(); - QCOMPARE(firstValue[extQuotes->tag(QString("ask"))].toDouble(), 0.0); - QCOMPARE(firstValue[extQuotes->tag(QString("bid"))].toDouble(), 0.0); - QCOMPARE(firstValue[extQuotes->tag(QString("price"))].toDouble(), 0.0); // check values QVERIFY(spy.wait(5000)); @@ -67,6 +64,9 @@ void TestExtQuotes::test_run() cache[QString("price")] = arguments.at(0).toHash()[extQuotes->tag(QString("price"))]; + QCOMPARE(firstValue[extQuotes->tag(QString("ask"))].toDouble(), 0.0); + QCOMPARE(firstValue[extQuotes->tag(QString("bid"))].toDouble(), 0.0); + QCOMPARE(firstValue[extQuotes->tag(QString("price"))].toDouble(), 0.0); for (auto type : types) { qDebug() << "Test type" << type; QVERIFY((cache[type].toDouble() > price.first) diff --git a/sources/test/testextscript.cpp b/sources/test/testextscript.cpp index 4ecc050..959593f 100644 --- a/sources/test/testextscript.cpp +++ b/sources/test/testextscript.cpp @@ -60,12 +60,13 @@ void TestExtScript::test_run() // init spy QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &))); QVariantHash firstValue = extScript->run(); - QCOMPARE(firstValue[extScript->tag(QString("custom"))].toString(), - QString("")); // check values QVERIFY(spy.wait(5000)); QList arguments = spy.takeFirst(); + + QCOMPARE(firstValue[extScript->tag(QString("custom"))].toString(), + QString("")); QCOMPARE( arguments.at(0).toHash()[extScript->tag(QString("custom"))].toString(), QString("\n%1").arg(randomString)); diff --git a/sources/test/testextupgrade.cpp b/sources/test/testextupgrade.cpp index 64cbc10..fb0e0d3 100644 --- a/sources/test/testextupgrade.cpp +++ b/sources/test/testextupgrade.cpp @@ -57,11 +57,12 @@ void TestExtUpgrade::test_run() // init spy QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &))); QVariantHash firstValue = extUpgrade->run(); - QCOMPARE(firstValue[extUpgrade->tag(QString("pkgcount"))].toInt(), 0); // check values QVERIFY(spy.wait(5000)); QList arguments = spy.takeFirst(); + + QCOMPARE(firstValue[extUpgrade->tag(QString("pkgcount"))].toInt(), 0); QCOMPARE( arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(), randomStrings.count()); diff --git a/sources/test/testgpuloadsource.cpp b/sources/test/testgpuloadsource.cpp new file mode 100644 index 0000000..0bdc1ec --- /dev/null +++ b/sources/test/testgpuloadsource.cpp @@ -0,0 +1,65 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testgpuloadsource.h" + +#include + +#include "awtestlibrary.h" +#include "gpuloadsource.h" + + +void TestGPULoadSource::initTestCase() +{ + device = GPULoadSource::autoGpu(); + QVERIFY(!device.isEmpty()); + + source = new GPULoadSource(this, QStringList() << device); +} + + +void TestGPULoadSource::cleanupTestCase() +{ + delete source; +} + + +void TestGPULoadSource::test_sources() +{ + QCOMPARE(source->sources(), QStringList() << src); +} + + +void TestGPULoadSource::test_gpuload() +{ + if (device == QString("disable")) + QSKIP("Not supported device, test will be skipped"); + + QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &))); + float firstValue = source->data(src).toFloat(); + + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + float secondValue = arguments[src].toFloat(); + + QCOMPARE(firstValue, 0.0f); + QVERIFY((secondValue >= load.first) && (secondValue <= load.second)); +} + + +QTEST_MAIN(TestGPULoadSource); diff --git a/sources/test/testgpuloadsource.h b/sources/test/testgpuloadsource.h new file mode 100644 index 0000000..5e32433 --- /dev/null +++ b/sources/test/testgpuloadsource.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTGPULOADSOURCE_H +#define TESTGPULOADSOURCE_H + +#include + + +class GPULoadSource; + +class TestGPULoadSource : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_sources(); + void test_gpuload(); + +private: + GPULoadSource *source = nullptr; + QString device; + QString src = QString("gpu/load"); + QPair load = QPair(0.0f, 100.0f); +}; + + +#endif /* TESTGPULOADSOURCE_H */ diff --git a/sources/test/testgputempsource.cpp b/sources/test/testgputempsource.cpp index 29a8f36..a73546c 100644 --- a/sources/test/testgputempsource.cpp +++ b/sources/test/testgputempsource.cpp @@ -29,19 +29,19 @@ void TestGPUTemperatureSource::initTestCase() device = GPUTemperatureSource::autoGpu(); QVERIFY(!device.isEmpty()); - gputempSource = new GPUTemperatureSource(this, QStringList() << device); + source = new GPUTemperatureSource(this, QStringList() << device); } void TestGPUTemperatureSource::cleanupTestCase() { - delete gputempSource; + delete source; } void TestGPUTemperatureSource::test_sources() { - QCOMPARE(gputempSource->sources(), QStringList() << source); + QCOMPARE(source->sources(), QStringList() << src); } @@ -50,13 +50,14 @@ void TestGPUTemperatureSource::test_gputemp() if (device == QString("disable")) QSKIP("Not supported device, test will be skipped"); - QSignalSpy spy(gputempSource, SIGNAL(dataReceived(const QVariantHash &))); - float firstValue = gputempSource->data(source).toFloat(); - QCOMPARE(firstValue, 0.0f); + QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &))); + float firstValue = source->data(src).toFloat(); QVERIFY(spy.wait(5000)); QVariantHash arguments = spy.takeFirst().at(0).toHash(); - float secondValue = arguments[source].toFloat(); + float secondValue = arguments[src].toFloat(); + + QCOMPARE(firstValue, 0.0f); QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second)); } diff --git a/sources/test/testgputempsource.h b/sources/test/testgputempsource.h index f095066..74458e0 100644 --- a/sources/test/testgputempsource.h +++ b/sources/test/testgputempsource.h @@ -37,10 +37,10 @@ private slots: void test_gputemp(); private: - GPUTemperatureSource *gputempSource = nullptr; + GPUTemperatureSource *source = nullptr; QString device; - QString source = QString("gpu/temperature"); - QPair temp = QPair(0.0f, 40.0f); + QString src = QString("gpu/temperature"); + QPair temp = QPair(0.0f, 120.0f); }; diff --git a/sources/test/testhddtempsource.cpp b/sources/test/testhddtempsource.cpp index de4914b..bccd587 100644 --- a/sources/test/testhddtempsource.cpp +++ b/sources/test/testhddtempsource.cpp @@ -60,12 +60,13 @@ void TestHDDTemperatureSource::test_hddtemp() QSignalSpy spy(hddtempSource, SIGNAL(dataReceived(const QVariantHash &))); float firstValue = hddtempSource->data(device).toFloat(); - QCOMPARE(firstValue, 0.0f); QVERIFY(spy.wait(5000)); QVariantHash arguments = spy.takeFirst().at(0).toHash(); device.remove(QString("hdd/temperature")); float secondValue = arguments[device].toFloat(); + + QCOMPARE(firstValue, 0.0f); QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second)); }); } @@ -77,12 +78,13 @@ void TestHDDTemperatureSource::test_smartctl() QSignalSpy spy(smartctlSource, SIGNAL(dataReceived(const QVariantHash &))); float firstValue = smartctlSource->data(device).toFloat(); - QCOMPARE(firstValue, 0.0f); QVERIFY(spy.wait(5000)); QVariantHash arguments = spy.takeFirst().at(0).toHash(); device.remove(QString("hdd/temperature")); float secondValue = arguments[device].toFloat(); + + QCOMPARE(firstValue, 0.0f); QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second)); }); } diff --git a/sources/test/testhddtempsource.h b/sources/test/testhddtempsource.h index b558692..b790938 100644 --- a/sources/test/testhddtempsource.h +++ b/sources/test/testhddtempsource.h @@ -43,7 +43,7 @@ private: QStringList devices; QString hddtempCmd = QString("sudo hddtemp"); QString smartctlCmd = QString("sudo smartctl -a"); - QPair temp = QPair(0.0f, 40.0f); + QPair temp = QPair(0.0f, 120.0f); }; From 5d9d551afe78fcafb64247ed6eb709cd1424b0d2 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Mon, 13 Jun 2016 05:15:08 +0300 Subject: [PATCH 29/32] some fixes inside sources --- sources/extsysmonsources/gpuloadsource.cpp | 2 ++ sources/extsysmonsources/playersource.cpp | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sources/extsysmonsources/gpuloadsource.cpp b/sources/extsysmonsources/gpuloadsource.cpp index b85db70..482c468 100644 --- a/sources/extsysmonsources/gpuloadsource.cpp +++ b/sources/extsysmonsources/gpuloadsource.cpp @@ -154,4 +154,6 @@ void GPULoadSource::updateValue() break; } } + + emit(dataReceived(m_values)); } diff --git a/sources/extsysmonsources/playersource.cpp b/sources/extsysmonsources/playersource.cpp index 80c159b..769ed9d 100644 --- a/sources/extsysmonsources/playersource.cpp +++ b/sources/extsysmonsources/playersource.cpp @@ -161,15 +161,11 @@ void PlayerSource::run() // initial data if (m_player == QString("mpd")) { // mpd - QHash data = getPlayerMpdInfo(m_mpdAddress); - for (auto key : data.keys()) - m_values[key] = data[key]; + m_values = getPlayerMpdInfo(m_mpdAddress); } else if (m_player == QString("mpris")) { // players which supports mpris QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris; - QHash data = getPlayerMprisInfo(mpris); - for (auto key : data.keys()) - m_values[key] = data[key]; + m_values = getPlayerMprisInfo(mpris); } // dymanic properties From 75d101cc8b736580b810e64121c8a19e673ec156 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 15 Jun 2016 15:10:41 +0300 Subject: [PATCH 30/32] add tests for dekstop, network and processes sources --- sources/extsysmonsources/batterysource.cpp | 9 ++-- sources/test/CMakeLists.txt | 2 +- sources/test/testbatterysource.cpp | 16 +++--- sources/test/testdesktopsource.cpp | 60 ++++++++++++++++++++++ sources/test/testdesktopsource.h | 44 ++++++++++++++++ sources/test/testnetworksource.cpp | 51 ++++++++++++++++++ sources/test/testnetworksource.h | 45 ++++++++++++++++ sources/test/testprocessessource.cpp | 57 ++++++++++++++++++++ sources/test/testprocessessource.h | 44 ++++++++++++++++ 9 files changed, 315 insertions(+), 13 deletions(-) create mode 100644 sources/test/testdesktopsource.cpp create mode 100644 sources/test/testdesktopsource.h create mode 100644 sources/test/testnetworksource.cpp create mode 100644 sources/test/testnetworksource.h create mode 100644 sources/test/testprocessessource.cpp create mode 100644 sources/test/testprocessessource.h diff --git a/sources/extsysmonsources/batterysource.cpp b/sources/extsysmonsources/batterysource.cpp index fa1d161..1f2e337 100644 --- a/sources/extsysmonsources/batterysource.cpp +++ b/sources/extsysmonsources/batterysource.cpp @@ -40,17 +40,16 @@ BatterySource::~BatterySource() } - QStringList BatterySource::getSources() { QStringList sources; sources.append(QString("battery/ac")); sources.append(QString("battery/bat")); m_batteriesCount - = QDir(m_acpiPath) - .entryList(QStringList() << QString("BAT*"), - QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name) - .count(); + = QDir(m_acpiPath) + .entryList(QStringList() << QString("BAT*"), + QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name) + .count(); qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount; for (int i = 0; i < m_batteriesCount; i++) sources.append(QString("battery/bat%1").arg(i)); diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 6703c72..d7aabaa 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -26,7 +26,7 @@ set(TEST_MODULES abstractextitem extquotes extscript extupgrade extweather abstractformatter datetimeformatter floatformatter noformatter scriptformatter extitemaggregator - batterysource gpuloadsource gputempsource hddtempsource) + batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource processessource) foreach (TEST_MODULE ${TEST_MODULES}) set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h) set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp) diff --git a/sources/test/testbatterysource.cpp b/sources/test/testbatterysource.cpp index 636df6a..74f1f9f 100644 --- a/sources/test/testbatterysource.cpp +++ b/sources/test/testbatterysource.cpp @@ -48,13 +48,15 @@ void TestBatterySource::test_battery() QSKIP("No battery found, test will be skipped"); QStringList batteries = source->sources(); - std::for_each(batteries.begin(), batteries.end(), [this](const QString bat) { - QVariant value = source->data(bat); - if (bat == QString("battery/ac")) - QCOMPARE(value.type(), QVariant::Bool); - else - QVERIFY((value.toFloat() >= battery.first) && (value.toFloat() <= battery.second)); - }); + std::for_each(batteries.begin(), batteries.end(), + [this](const QString bat) { + QVariant value = source->data(bat); + if (bat == QString("battery/ac")) + QCOMPARE(value.type(), QVariant::Bool); + else + QVERIFY((value.toFloat() >= battery.first) + && (value.toFloat() <= battery.second)); + }); } diff --git a/sources/test/testdesktopsource.cpp b/sources/test/testdesktopsource.cpp new file mode 100644 index 0000000..602efd8 --- /dev/null +++ b/sources/test/testdesktopsource.cpp @@ -0,0 +1,60 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testdesktopsource.h" + +#include + +#include "awtestlibrary.h" +#include "desktopsource.h" + + +void TestDesktopSource::initTestCase() +{ + source = new DesktopSource(this, QStringList()); +} + + +void TestDesktopSource::cleanupTestCase() +{ + delete source; +} + + +void TestDesktopSource::test_sources() +{ + QCOMPARE(source->sources().count(), 4); + // FIXME there is segfault here sometimes o_0 +// QVERIFY(std::all_of( +// source->sources().cbegin(), source->sources().cend(), +// [](const QString &src) { return src.startsWith(QString("desktop/")); })); +} + + +void TestDesktopSource::test_values() +{ + QVERIFY(source->data(QString("desktop/current/name")).toString().count() + > 0); + QVERIFY(source->data(QString("desktop/current/number")).toInt() >= 0); + QVERIFY(source->data(QString("desktop/total/name")).toStringList().count() + > 0); + QVERIFY(source->data(QString("desktop/total/number")).toInt() > 0); +} + + +QTEST_MAIN(TestDesktopSource); diff --git a/sources/test/testdesktopsource.h b/sources/test/testdesktopsource.h new file mode 100644 index 0000000..7fd0a60 --- /dev/null +++ b/sources/test/testdesktopsource.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTDESKTOPSOURCE_H +#define TESTDESKTOPSOURCE_H + +#include + + +class DesktopSource; + +class TestDesktopSource : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_sources(); + void test_values(); + +private: + DesktopSource *source = nullptr; +}; + + +#endif /* TESTDESKTOPSOURCE_H */ diff --git a/sources/test/testnetworksource.cpp b/sources/test/testnetworksource.cpp new file mode 100644 index 0000000..9f2994b --- /dev/null +++ b/sources/test/testnetworksource.cpp @@ -0,0 +1,51 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testnetworksource.h" + +#include + +#include "awtestlibrary.h" +#include "networksource.h" + + +void TestNetworkSource::initTestCase() +{ + source = new NetworkSource(this, QStringList()); +} + + +void TestNetworkSource::cleanupTestCase() +{ + delete source; +} + + +void TestNetworkSource::test_sources() +{ + QCOMPARE(source->sources(), QStringList() << src); +} + + +void TestNetworkSource::test_values() +{ + QVERIFY(source->data(src).toString().count() > 0); +} + + +QTEST_MAIN(TestNetworkSource); diff --git a/sources/test/testnetworksource.h b/sources/test/testnetworksource.h new file mode 100644 index 0000000..e69334c --- /dev/null +++ b/sources/test/testnetworksource.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTNETWORKSOURCE_H +#define TESTNETWORKSOURCE_H + +#include + + +class NetworkSource; + +class TestNetworkSource : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_sources(); + void test_values(); + +private: + NetworkSource *source = nullptr; + QString src = QString("network/current/name"); +}; + + +#endif /* TESTNETWORKSOURCE_H */ diff --git a/sources/test/testprocessessource.cpp b/sources/test/testprocessessource.cpp new file mode 100644 index 0000000..11280b5 --- /dev/null +++ b/sources/test/testprocessessource.cpp @@ -0,0 +1,57 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testprocessessource.h" + +#include + +#include "awtestlibrary.h" +#include "processessource.h" + + +void TestProcessesSource::initTestCase() +{ + source = new ProcessesSource(this, QStringList()); +} + + +void TestProcessesSource::cleanupTestCase() +{ + delete source; +} + + +void TestProcessesSource::test_sources() +{ + QCOMPARE(source->sources().count(), 3); + // FIXME there is segfault here sometimes o_0 +// QVERIFY(std::all_of( +// source->sources().cbegin(), source->sources().cend(), +// [](const QString &src) { return src.startsWith(QString("ps/")); })); +} + + +void TestProcessesSource::test_values() +{ + QVERIFY(source->data(QString("ps/running/count")).toInt() > 0); + QVERIFY(source->data(QString("ps/running/list")).toStringList().count() > 0); + QVERIFY(source->data(QString("ps/total/count")).toInt() > 0); +} + + +QTEST_MAIN(TestProcessesSource); diff --git a/sources/test/testprocessessource.h b/sources/test/testprocessessource.h new file mode 100644 index 0000000..c81b871 --- /dev/null +++ b/sources/test/testprocessessource.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTPROCESSESSOURCE_H +#define TESTPROCESSESSOURCE_H + +#include + + +class ProcessesSource; + +class TestProcessesSource : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_sources(); + void test_values(); + +private: + ProcessesSource *source = nullptr; +}; + + +#endif /* TESTPROCESSESSOURCE_H */ From b20a96d32fdee24ce354080f6b5349abf77ab1f7 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 16 Jun 2016 15:17:06 +0300 Subject: [PATCH 31/32] add fix for possible race condition (#96) --- patches/fix-race-condition.patch | 15 +++++++++++++++ sources/awesome-widget/plugin/awkeys.cpp | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 patches/fix-race-condition.patch diff --git a/patches/fix-race-condition.patch b/patches/fix-race-condition.patch new file mode 100644 index 0000000..14d79ea --- /dev/null +++ b/patches/fix-race-condition.patch @@ -0,0 +1,15 @@ +diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp +index 1744fb7..f483209 100644 +--- a/sources/awesome-widget/plugin/awkeys.cpp ++++ b/sources/awesome-widget/plugin/awkeys.cpp +@@ -234,8 +234,10 @@ void AWKeys::reinitKeys(const QStringList currentKeys) + void AWKeys::updateTextData() + { + // do not do it in parallel to avoid race condition ++ m_mutex.lock(); + calculateValues(); + QString text = parsePattern(keyOperator->pattern()); ++ m_mutex.unlock(); + + emit(needTextToBeUpdated(text)); + emit(dataAggregator->updateData(values)); diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 1744fb7..f483209 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -234,8 +234,10 @@ void AWKeys::reinitKeys(const QStringList currentKeys) void AWKeys::updateTextData() { // do not do it in parallel to avoid race condition + m_mutex.lock(); calculateValues(); QString text = parsePattern(keyOperator->pattern()); + m_mutex.unlock(); emit(needTextToBeUpdated(text)); emit(dataAggregator->updateData(values)); From 0f1763cb8137e05b43379775ac3f412274ef7b47 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Fri, 17 Jun 2016 15:19:00 +0300 Subject: [PATCH 32/32] add one more workaround for possible freezes (#96) First of all it seems that freezes were caused by stuck dbus calls. I've enabled dbus call timeout (build-configured, default to 3000 msec). And moreover I've added one more thread lock for dbus calls. --- patches/fix-dbus-calls.patch | 89 +++++++++++++++++++++++ sources/extsysmon/extsysmon.cpp | 5 +- sources/extsysmonsources/playersource.cpp | 13 +++- sources/extsysmonsources/playersource.h | 6 ++ 4 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 patches/fix-dbus-calls.patch diff --git a/patches/fix-dbus-calls.patch b/patches/fix-dbus-calls.patch new file mode 100644 index 0000000..8ffe473 --- /dev/null +++ b/patches/fix-dbus-calls.patch @@ -0,0 +1,89 @@ +diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp +index 69934c4..a48b8e7 100644 +--- a/sources/extsysmon/extsysmon.cpp ++++ b/sources/extsysmon/extsysmon.cpp +@@ -74,7 +74,10 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) + qCDebug(LOG_ESM) << "Source" << source; + + if (aggregator->hasSource(source)) { +- setData(source, QString("value"), aggregator->data(source)); ++ QVariant data = aggregator->data(source); ++ if (data.isNull()) ++ return false; ++ setData(source, QString("value"), data); + } else { + qCWarning(LOG_ESM) << "Unknown source" << source; + return false; +diff --git a/sources/extsysmon/sources/playersource.cpp b/sources/extsysmon/sources/playersource.cpp +index 769ed9d..c51511c 100644 +--- a/sources/extsysmon/sources/playersource.cpp ++++ b/sources/extsysmon/sources/playersource.cpp +@@ -164,12 +164,16 @@ void PlayerSource::run() + QHash data = getPlayerMpdInfo(m_mpdAddress); + for (auto key : data.keys()) + m_values[key] = data[key]; + } else if (m_player == QString("mpris")) { + // players which supports mpris +- QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris; +- QHash data = getPlayerMprisInfo(mpris); +- for (auto key : data.keys()) +- m_values[key] = data[key]; ++ if (m_dbusMutex.tryLock()) { ++ QString mpris ++ = m_mpris == QString("auto") ? getAutoMpris() : m_mpris; ++ QHash data = getPlayerMprisInfo(mpris); ++ for (auto key : data.keys()) ++ m_values[key] = data[key]; ++ m_dbusMutex.unlock(); ++ } + } + + // dymanic properties +@@ -258,7 +262,7 @@ QVariantHash PlayerSource::defaultInfo() const + QString PlayerSource::getAutoMpris() const + { + QDBusMessage listServices = QDBusConnection::sessionBus().interface()->call( +- QDBus::BlockWithGui, QString("ListNames")); ++ QDBus::BlockWithGui, QString("ListNames"), DBUS_CALL_TIMEOUT); + if (listServices.arguments().isEmpty()) + return QString(); + QStringList arguments = listServices.arguments().first().toStringList(); +@@ -315,7 +319,8 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const + QString("org.mpris.MediaPlayer2.%1").arg(mpris), + QString("/org/mpris/MediaPlayer2"), QString(""), QString("Get")); + request.setArguments(args); +- QDBusMessage response = bus.call(request, QDBus::BlockWithGui); ++ QDBusMessage response ++ = bus.call(request, QDBus::BlockWithGui, DBUS_CALL_TIMEOUT); + if ((response.type() != QDBusMessage::ReplyMessage) + || (response.arguments().isEmpty())) { + qCWarning(LOG_ESS) << "Error message" << response.errorMessage(); +diff --git a/sources/extsysmon/sources/playersource.h b/sources/extsysmon/sources/playersource.h +index 0d8bbfc..2164354 100644 +--- a/sources/extsysmon/sources/playersource.h ++++ b/sources/extsysmon/sources/playersource.h +@@ -18,11 +18,16 @@ + #ifndef PLAYERSOURCE_H + #define PLAYERSOURCE_H + ++#include + #include + + #include "abstractextsysmonsource.h" + + ++#ifndef DBUS_CALL_TIMEOUT ++#define DBUS_CALL_TIMEOUT 3000 ++#endif /* DBUS_CALL_TIMEOUT */ ++ + class QProcess; + + class PlayerSource : public AbstractExtSysMonSource +@@ -52,6 +57,7 @@ private: + QVariantHash m_mpdCached; + QProcess *m_mpdProcess = nullptr; + QString m_mpris; ++ QMutex m_dbusMutex; + QString m_player; + int m_symbols; + QStringList m_metadata = QStringList() << QString("album") diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 69934c4..a48b8e7 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -74,7 +74,10 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) qCDebug(LOG_ESM) << "Source" << source; if (aggregator->hasSource(source)) { - setData(source, QString("value"), aggregator->data(source)); + QVariant data = aggregator->data(source); + if (data.isNull()) + return false; + setData(source, QString("value"), data); } else { qCWarning(LOG_ESM) << "Unknown source" << source; return false; diff --git a/sources/extsysmonsources/playersource.cpp b/sources/extsysmonsources/playersource.cpp index 769ed9d..c51511c 100644 --- a/sources/extsysmonsources/playersource.cpp +++ b/sources/extsysmonsources/playersource.cpp @@ -164,8 +164,12 @@ void PlayerSource::run() m_values = getPlayerMpdInfo(m_mpdAddress); } else if (m_player == QString("mpris")) { // players which supports mpris - QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris; - m_values = getPlayerMprisInfo(mpris); + if (m_dbusMutex.tryLock()) { + QString mpris + = m_mpris == QString("auto") ? getAutoMpris() : m_mpris; + m_values = getPlayerMprisInfo(mpris); + m_dbusMutex.unlock(); + } } // dymanic properties @@ -258,7 +262,7 @@ QVariantHash PlayerSource::defaultInfo() const QString PlayerSource::getAutoMpris() const { QDBusMessage listServices = QDBusConnection::sessionBus().interface()->call( - QDBus::BlockWithGui, QString("ListNames")); + QDBus::BlockWithGui, QString("ListNames"), DBUS_CALL_TIMEOUT); if (listServices.arguments().isEmpty()) return QString(); QStringList arguments = listServices.arguments().first().toStringList(); @@ -315,7 +319,8 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const QString("org.mpris.MediaPlayer2.%1").arg(mpris), QString("/org/mpris/MediaPlayer2"), QString(""), QString("Get")); request.setArguments(args); - QDBusMessage response = bus.call(request, QDBus::BlockWithGui); + QDBusMessage response + = bus.call(request, QDBus::BlockWithGui, DBUS_CALL_TIMEOUT); if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { qCWarning(LOG_ESS) << "Error message" << response.errorMessage(); diff --git a/sources/extsysmonsources/playersource.h b/sources/extsysmonsources/playersource.h index 0d8bbfc..baf93fb 100644 --- a/sources/extsysmonsources/playersource.h +++ b/sources/extsysmonsources/playersource.h @@ -18,11 +18,16 @@ #ifndef PLAYERSOURCE_H #define PLAYERSOURCE_H +#include #include #include "abstractextsysmonsource.h" +#ifndef DBUS_CALL_TIMEOUT +#define DBUS_CALL_TIMEOUT 3000 +#endif /* DBUS_CALL_TIMEOUT */ + class QProcess; class PlayerSource : public AbstractExtSysMonSource @@ -52,6 +57,7 @@ private: QVariantHash m_mpdCached; QProcess *m_mpdProcess = nullptr; QString m_mpris; + QMutex m_dbusMutex; QString m_player; int m_symbols; QStringList m_metadata = QStringList() << QString("album")