From 6e99e262d4f19ef296ea46d0b246d1631e72b0db Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Wed, 3 May 2017 00:27:09 +0300 Subject: [PATCH] add configuration for cron --- .travis.yml | 1 - sources/awesomewidgets/abstractextitem.cpp | 10 ++---- sources/awesomewidgets/extnetworkrequest.cpp | 3 ++ sources/awesomewidgets/extnetworkrequest.ui | 23 +++++++++++++ sources/awesomewidgets/extquotes.cpp | 3 ++ sources/awesomewidgets/extquotes.ui | 25 +++++++++++++- sources/awesomewidgets/extscript.cpp | 3 ++ sources/awesomewidgets/extscript.ui | 25 +++++++++++++- sources/awesomewidgets/extupgrade.cpp | 5 ++- sources/awesomewidgets/extupgrade.ui | 25 +++++++++++++- sources/awesomewidgets/extweather.cpp | 3 ++ sources/awesomewidgets/extweather.ui | 25 +++++++++++++- sources/awesomewidgets/qcronscheduler.cpp | 34 ++++++++++---------- sources/awesomewidgets/qcronscheduler.h | 4 +-- sources/test/awtestlibrary.cpp | 6 ++-- sources/test/awtestlibrary.h | 2 +- sources/test/testabstractextitem.cpp | 3 ++ sources/test/testabstractextitem.h | 1 + sources/test/testawpatternfunctions.cpp | 8 ++--- sources/test/testlistformatter.cpp | 2 +- sources/test/testplayersource.cpp | 12 +++---- sources/test/teststringformatter.cpp | 5 ++- 22 files changed, 180 insertions(+), 48 deletions(-) diff --git a/.travis.yml b/.travis.yml index a88bb4b..f3292aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,6 @@ arch: - cd awesome-widgets/build; make - cd awesome-widgets/build; make cppcheck - cd awesome-widgets/build; make clangformat && ( [ `git status -s | wc -l` -eq 0 ] || exit 1 ) - - cd awesome-widgets/build; ./test/awesomewidgets-test-extweather || true - cd awesome-widgets/build; xvfb-run make test - sleep 3 diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index 79b9fb1..b0468f6 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -307,15 +307,10 @@ void AbstractExtItem::readConfiguration() setActive( settings.value(QString("X-AW-Active"), QVariant(isActive())).toString() == QString("true")); + setInterval(settings.value(QString("X-AW-Interval"), interval()).toInt()); setNumber(settings.value(QString("X-AW-Number"), number()).toInt()); + setCron(settings.value(QString("X-AW-Schedule"), cron()).toString()); setSocket(settings.value(QString("X-AW-Socket"), socket()).toString()); - - // interval definition - QVariant value = settings.value(QString("X-AW-Interval"), interval()); - if (value.type() == QVariant::Int) - setInterval(value.toInt()); - else - setCron(value.toString()); settings.endGroup(); } @@ -344,6 +339,7 @@ void AbstractExtItem::writeConfiguration() const cron().isEmpty() ? QVariant(interval()) : QVariant(cron())); settings.setValue(QString("X-AW-Number"), number()); + settings.setValue(QString("X-AW-Schedule"), cron()); settings.setValue(QString("X-AW-Socket"), socket()); settings.endGroup(); diff --git a/sources/awesomewidgets/extnetworkrequest.cpp b/sources/awesomewidgets/extnetworkrequest.cpp index b5a803f..92e3203 100644 --- a/sources/awesomewidgets/extnetworkrequest.cpp +++ b/sources/awesomewidgets/extnetworkrequest.cpp @@ -137,6 +137,7 @@ int ExtNetworkRequest::showConfiguration(const QVariant args) ui->lineEdit_url->setText(stringUrl()); ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked); + ui->lineEdit_schedule->setText(cron()); ui->lineEdit_socket->setText(socket()); ui->spinBox_interval->setValue(interval()); @@ -149,6 +150,7 @@ int ExtNetworkRequest::showConfiguration(const QVariant args) setApiVersion(AW_EXTNETREQUEST_API); setStringUrl(ui->lineEdit_url->text()); setActive(ui->checkBox_active->checkState() == Qt::Checked); + setCron(ui->lineEdit_schedule->text()); setSocket(ui->lineEdit_socket->text()); setInterval(ui->spinBox_interval->value()); @@ -208,6 +210,7 @@ void ExtNetworkRequest::translate() ui->label_number->setText(i18n("Tag")); ui->label_url->setText(i18n("URL")); ui->checkBox_active->setText(i18n("Active")); + ui->label_schedule->setText(i18n("Schedule")); ui->label_socket->setText(i18n("Socket")); ui->label_interval->setText(i18n("Interval")); } diff --git a/sources/awesomewidgets/extnetworkrequest.ui b/sources/awesomewidgets/extnetworkrequest.ui index 9b49355..d4dea4d 100644 --- a/sources/awesomewidgets/extnetworkrequest.ui +++ b/sources/awesomewidgets/extnetworkrequest.ui @@ -134,6 +134,29 @@ + + + + + + + 0 + 0 + + + + Schedule + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + diff --git a/sources/awesomewidgets/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp index d75c4cd..4f8096a 100644 --- a/sources/awesomewidgets/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -146,6 +146,7 @@ int ExtQuotes::showConfiguration(const QVariant args) ui->lineEdit_ticker->setText(ticker()); ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked); + ui->lineEdit_schedule->setText(cron()); ui->lineEdit_socket->setText(socket()); ui->spinBox_interval->setValue(interval()); @@ -158,6 +159,7 @@ int ExtQuotes::showConfiguration(const QVariant args) setApiVersion(AW_EXTQUOTES_API); setTicker(ui->lineEdit_ticker->text()); setActive(ui->checkBox_active->checkState() == Qt::Checked); + setCron(ui->lineEdit_schedule->text()); setSocket(ui->lineEdit_socket->text()); setInterval(ui->spinBox_interval->value()); @@ -273,6 +275,7 @@ get quotes for the instrument. Refer to \

")); ui->label_ticker->setText(i18n("Ticker")); ui->checkBox_active->setText(i18n("Active")); + ui->label_schedule->setText(i18n("Schedule")); ui->label_socket->setText(i18n("Socket")); ui->label_interval->setText(i18n("Interval")); } diff --git a/sources/awesomewidgets/extquotes.ui b/sources/awesomewidgets/extquotes.ui index 3f8ad61..620e914 100644 --- a/sources/awesomewidgets/extquotes.ui +++ b/sources/awesomewidgets/extquotes.ui @@ -7,7 +7,7 @@ 0 0 420 - 301 + 339 @@ -150,6 +150,29 @@
+ + + + + + + 0 + 0 + + + + Schedule + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 0fb0197..acab312 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -295,6 +295,7 @@ int ExtScript::showConfiguration(const QVariant args) ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked); ui->comboBox_redirect->setCurrentIndex(static_cast(redirect())); + ui->lineEdit_schedule->setText(cron()); ui->lineEdit_socket->setText(socket()); ui->spinBox_interval->setValue(interval()); // filters @@ -316,6 +317,7 @@ int ExtScript::showConfiguration(const QVariant args) setPrefix(ui->lineEdit_prefix->text()); setActive(ui->checkBox_active->checkState() == Qt::Checked); setRedirect(static_cast(ui->comboBox_redirect->currentIndex())); + setCron(ui->lineEdit_schedule->text()); setSocket(ui->lineEdit_socket->text()); setInterval(ui->spinBox_interval->value()); // filters @@ -402,6 +404,7 @@ void ExtScript::translate() ui->label_prefix->setText(i18n("Prefix")); ui->checkBox_active->setText(i18n("Active")); ui->label_redirect->setText(i18n("Redirect")); + ui->label_schedule->setText(i18n("Schedule")); ui->label_socket->setText(i18n("Socket")); ui->label_interval->setText(i18n("Interval")); ui->groupBox_filters->setTitle(i18n("Additional filters")); diff --git a/sources/awesomewidgets/extscript.ui b/sources/awesomewidgets/extscript.ui index f40e30b..2445f9e 100644 --- a/sources/awesomewidgets/extscript.ui +++ b/sources/awesomewidgets/extscript.ui @@ -7,7 +7,7 @@ 0 0 420 - 442 + 473 @@ -195,6 +195,29 @@ + + + + + + + 0 + 0 + + + + Schedule + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index 6f103aa..c87da54 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -165,6 +165,7 @@ int ExtUpgrade::showConfiguration(const QVariant args) ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked); ui->spinBox_null->setValue(null()); + ui->lineEdit_schedule->setText(cron()); ui->lineEdit_socket->setText(socket()); ui->spinBox_interval->setValue(interval()); @@ -179,6 +180,7 @@ int ExtUpgrade::showConfiguration(const QVariant args) setFilter(ui->lineEdit_filter->text()); setActive(ui->checkBox_active->checkState() == Qt::Checked); setNull(ui->spinBox_null->value()); + setCron(ui->lineEdit_schedule->text()); setSocket(ui->lineEdit_socket->text()); setInterval(ui->spinBox_interval->value()); @@ -242,6 +244,7 @@ void ExtUpgrade::translate() ui->label_filter->setText(i18n("Filter")); ui->checkBox_active->setText(i18n("Active")); ui->label_null->setText(i18n("Null")); - ui->label_interval->setText(i18n("Interval")); ui->label_socket->setText(i18n("Socket")); + ui->label_schedule->setText(i18n("Schedule")); + ui->label_interval->setText(i18n("Interval")); } diff --git a/sources/awesomewidgets/extupgrade.ui b/sources/awesomewidgets/extupgrade.ui index 0443248..edf3517 100644 --- a/sources/awesomewidgets/extupgrade.ui +++ b/sources/awesomewidgets/extupgrade.ui @@ -7,7 +7,7 @@ 0 0 420 - 321 + 349 @@ -181,6 +181,29 @@ + + + + + + + 0 + 0 + + + + Schedule + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 9f1fe23..0791edc 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -292,6 +292,7 @@ int ExtWeather::showConfiguration(const QVariant args) ui->checkBox_image->setCheckState(image() ? Qt::Checked : Qt::Unchecked); ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked); + ui->lineEdit_schedule->setText(cron()); ui->lineEdit_socket->setText(socket()); ui->spinBox_interval->setValue(interval()); @@ -308,6 +309,7 @@ int ExtWeather::showConfiguration(const QVariant args) setTs(ui->spinBox_timestamp->value()); setImage(ui->checkBox_image->checkState() == Qt::Checked); setActive(ui->checkBox_active->checkState() == Qt::Checked); + setCron(ui->lineEdit_schedule->text()); setSocket(ui->lineEdit_socket->text()); setInterval(ui->spinBox_interval->value()); @@ -400,6 +402,7 @@ void ExtWeather::translate() ui->label_timestamp->setText(i18n("Timestamp")); ui->checkBox_image->setText(i18n("Use images")); ui->checkBox_active->setText(i18n("Active")); + ui->label_schedule->setText(i18n("Schedule")); ui->label_socket->setText(i18n("Socket")); ui->label_interval->setText(i18n("Interval")); } diff --git a/sources/awesomewidgets/extweather.ui b/sources/awesomewidgets/extweather.ui index 3201aaa..19010d3 100644 --- a/sources/awesomewidgets/extweather.ui +++ b/sources/awesomewidgets/extweather.ui @@ -7,7 +7,7 @@ 0 0 420 - 382 + 413 @@ -248,6 +248,29 @@ + + + + + + + 0 + 0 + + + + Schedule + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + diff --git a/sources/awesomewidgets/qcronscheduler.cpp b/sources/awesomewidgets/qcronscheduler.cpp index 97126c5..09275d6 100644 --- a/sources/awesomewidgets/qcronscheduler.cpp +++ b/sources/awesomewidgets/qcronscheduler.cpp @@ -56,11 +56,11 @@ void QCronScheduler::parse(const QString &timer) if (fields.count() != 5) return; - m_schedule.minutes = parseField(fields.at(1), 0, 59); - m_schedule.hours = parseField(fields.at(2), 0, 23); - m_schedule.days = parseField(fields.at(3), 1, 31); - m_schedule.months = parseField(fields.at(4), 1, 12); - m_schedule.weekdays = parseField(fields.at(5), 1, 7); + m_schedule.minutes = parseField(fields.at(0), 0, 59); + m_schedule.hours = parseField(fields.at(1), 0, 23); + m_schedule.days = parseField(fields.at(2), 1, 31); + m_schedule.months = parseField(fields.at(3), 1, 12); + m_schedule.weekdays = parseField(fields.at(4), 1, 7); } @@ -111,31 +111,31 @@ void QCronScheduler::QCronField::fromRange(const QString &range, const int min, << "with corner values" << min << max; if (range == '*') { - this->min = min; - this->max = max; + minValue = min; + maxValue = max; } else if (range.contains('-')) { auto interval = range.split('-', QString::SkipEmptyParts); if (interval.count() != 2) return; bool status; // minimal value - this->min = std::max(min, interval.at(0).toInt(&status)); + minValue = std::max(min, interval.at(0).toInt(&status)); if (!status) - this->min = -1; + minValue = -1; // maximal value - this->max = std::min(max, interval.at(1).toInt(&status)); + maxValue = std::min(max, interval.at(1).toInt(&status)); if (!status) - this->max = -1; + maxValue = -1; // error check - if (this->min > this->max) - std::swap(this->min, this->max); + if (minValue > maxValue) + std::swap(minValue, maxValue); } else { bool status; int value = range.toInt(&status); if (!status || (value < min) || (value > max)) value = -1; - this->min = value; - this->max = value; + minValue = value; + maxValue = value; } } @@ -143,11 +143,11 @@ void QCronScheduler::QCronField::fromRange(const QString &range, const int min, QList QCronScheduler::QCronField::toList() { // error checking - if ((min == -1) || (max == -1)) + if ((minValue == -1) || (maxValue == -1)) return QList(); QList output; - for (auto i = min; i <= max; ++i) { + for (auto i = minValue; i <= maxValue; ++i) { if (i % div != 0) continue; output.append(i); diff --git a/sources/awesomewidgets/qcronscheduler.h b/sources/awesomewidgets/qcronscheduler.h index f8e0aef..e03d34c 100644 --- a/sources/awesomewidgets/qcronscheduler.h +++ b/sources/awesomewidgets/qcronscheduler.h @@ -36,8 +36,8 @@ public: QList weekdays; } QCronRunSchedule; typedef struct { - int min = -1; - int max = -1; + int minValue = -1; + int maxValue = -1; int div = 1; void fromRange(const QString &range, const int min, const int max); QList toList(); diff --git a/sources/test/awtestlibrary.cpp b/sources/test/awtestlibrary.cpp index 815f319..d602173 100644 --- a/sources/test/awtestlibrary.cpp +++ b/sources/test/awtestlibrary.cpp @@ -65,7 +65,7 @@ QPair AWTestLibrary::randomFilenames() .arg(QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation)); - QString name = randomString(20); + QString name = randomString(1, 20); fileName += name; writeFileName += name; @@ -79,11 +79,11 @@ int AWTestLibrary::randomInt(const int max) } -QString AWTestLibrary::randomString(const int max) +QString AWTestLibrary::randomString(const int min, const int max) { QString output; - int count = 1 + randomInt(max); + int count = min + randomInt(max - min); for (int i = 0; i < count; i++) output += QChar(randomChar()); diff --git a/sources/test/awtestlibrary.h b/sources/test/awtestlibrary.h index 0aab568..d422344 100644 --- a/sources/test/awtestlibrary.h +++ b/sources/test/awtestlibrary.h @@ -31,7 +31,7 @@ char randomChar(); double randomDouble(); QPair randomFilenames(); int randomInt(const int max = 100); -QString randomString(const int max = 100); +QString randomString(const int min = 1, const int max = 100); QStringList randomStringList(const int max = 100); QStringList randomSelect(const QStringList available); }; diff --git a/sources/test/testabstractextitem.cpp b/sources/test/testabstractextitem.cpp index 8771c54..e4bc093 100644 --- a/sources/test/testabstractextitem.cpp +++ b/sources/test/testabstractextitem.cpp @@ -39,6 +39,7 @@ void TestAbstractExtItem::initTestCase() extItem->setActive(false); extItem->setApiVersion(1); extItem->setComment(comment); + extItem->setCron(cron); extItem->setName(name); extItem->setNumber(-1); extItem->setSocket(socket); @@ -81,6 +82,7 @@ void TestAbstractExtItem::test_configuration() QCOMPARE(newExtItem->name(), extItem->name()); QCOMPARE(newExtItem->number(), extItem->number()); QCOMPARE(newExtItem->socket(), extItem->socket()); + QCOMPARE(newExtItem->cron(), extItem->cron()); delete newExtItem; } @@ -114,6 +116,7 @@ void TestAbstractExtItem::test_copy() QCOMPARE(newExtItem->comment(), extItem->comment()); QCOMPARE(newExtItem->name(), extItem->name()); QCOMPARE(newExtItem->socket(), extItem->socket()); + QCOMPARE(newExtItem->cron(), extItem->cron()); delete newExtItem; } diff --git a/sources/test/testabstractextitem.h b/sources/test/testabstractextitem.h index af5ca68..a6be4a8 100644 --- a/sources/test/testabstractextitem.h +++ b/sources/test/testabstractextitem.h @@ -43,6 +43,7 @@ private slots: private: ExtUpgrade *extItem = nullptr; QString comment; + QString cron = "* * * * *"; QString name; QString socket; QString fileName; diff --git a/sources/test/testawpatternfunctions.cpp b/sources/test/testawpatternfunctions.cpp index 937956e..0a47d43 100644 --- a/sources/test/testawpatternfunctions.cpp +++ b/sources/test/testawpatternfunctions.cpp @@ -37,8 +37,8 @@ void TestAWPatternFunctions::cleanupTestCase() void TestAWPatternFunctions::test_findFunctionCalls() { - QString name = QString("aw_%1").arg(AWTestLibrary::randomString(10)); - QString code = AWTestLibrary::randomString(20); + QString name = QString("aw_%1").arg(AWTestLibrary::randomString(1, 10)); + QString code = AWTestLibrary::randomString(1, 20); QStringList args = AWTestLibrary::randomStringList(20); QString function = QString("$%1<%2>{{%3}}") .arg(name) @@ -63,9 +63,9 @@ void TestAWPatternFunctions::test_findKeys() int count = AWTestLibrary::randomInt(200); QStringList allKeys; for (int i = 0; i < count; i++) { - auto key = AWTestLibrary::randomString(20); + auto key = AWTestLibrary::randomString(1, 20); while (allKeys.indexOf(QRegExp(QString("^%1.*").arg(key))) != -1) - key = AWTestLibrary::randomString(20); + key = AWTestLibrary::randomString(1, 20); allKeys.append(key); } diff --git a/sources/test/testlistformatter.cpp b/sources/test/testlistformatter.cpp index 2d58391..e85a3fa 100644 --- a/sources/test/testlistformatter.cpp +++ b/sources/test/testlistformatter.cpp @@ -27,7 +27,7 @@ void TestAWListFormatter::initTestCase() { AWTestLibrary::init(); - separator = AWTestLibrary::randomString(10); + separator = AWTestLibrary::randomString(9, 10); formatter = new AWListFormatter(nullptr); formatter->setSeparator(separator); diff --git a/sources/test/testplayersource.cpp b/sources/test/testplayersource.cpp index 6d88bf7..e932941 100644 --- a/sources/test/testplayersource.cpp +++ b/sources/test/testplayersource.cpp @@ -43,15 +43,15 @@ void TestPlayerSource::_test_sources(const PlayerSource *source) void TestPlayerSource::test_buildString() { - QString randomString = AWTestLibrary::randomString(40); + QString randomString = AWTestLibrary::randomString(1, 40); QString str = PlayerSource::buildString(QString(), randomString, 20); QCOMPARE(str.count(), 20); str = PlayerSource::buildString(str, randomString, 20); QCOMPARE(str.count(), 20); - str = PlayerSource::buildString(QString(), AWTestLibrary::randomString(10), - 20); + str = PlayerSource::buildString(QString(), + AWTestLibrary::randomString(1, 10), 20); QCOMPARE(str.count(), 20); } @@ -59,11 +59,11 @@ void TestPlayerSource::test_buildString() void TestPlayerSource::test_stripString() { QString str = PlayerSource::buildString( - QString(), AWTestLibrary::randomString(40), 20); + QString(), AWTestLibrary::randomString(1, 40), 20); QCOMPARE(str.count(), 20); - str = PlayerSource::buildString(QString(), AWTestLibrary::randomString(10), - 20); + str = PlayerSource::buildString(QString(), + AWTestLibrary::randomString(1, 10), 20); QCOMPARE(str.count(), 20); } diff --git a/sources/test/teststringformatter.cpp b/sources/test/teststringformatter.cpp index 1a1d78c..1619cba 100644 --- a/sources/test/teststringformatter.cpp +++ b/sources/test/teststringformatter.cpp @@ -50,7 +50,10 @@ void TestAWStringFormatter::test_count() QCOMPARE(formatter->count(), count); // test - QString output = formatter->convert(AWTestLibrary::randomString()); + auto testString = AWTestLibrary::randomString(); + while (testString.count() > count) + testString = AWTestLibrary::randomString(); + QString output = formatter->convert(testString); QCOMPARE(output.count(), count); // reset