From 1b4d1d69448bc0c09bfb70e5d4ff8894f158dec5 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Fri, 28 Apr 2017 01:47:42 +0300 Subject: [PATCH] implement qcronscheduler, tests update --- .travis.yml | 13 +- sources/CMakeLists.txt | 8 +- .../plugin/awformatterhelper.cpp | 4 +- .../plugin/awpatternfunctions.cpp | 10 +- sources/awesomewidgets/abstractextitem.cpp | 65 ++++++- sources/awesomewidgets/abstractextitem.h | 12 +- sources/awesomewidgets/extnetworkrequest.cpp | 21 +-- sources/awesomewidgets/extnetworkrequest.h | 1 - sources/awesomewidgets/extquotes.cpp | 21 +-- sources/awesomewidgets/extquotes.h | 1 - sources/awesomewidgets/extscript.cpp | 27 +-- sources/awesomewidgets/extscript.h | 1 - sources/awesomewidgets/extupgrade.cpp | 22 +-- sources/awesomewidgets/extupgrade.h | 1 - sources/awesomewidgets/extweather.cpp | 21 +-- sources/awesomewidgets/extweather.h | 1 - sources/awesomewidgets/qcronscheduler.cpp | 158 ++++++++++++++++++ sources/awesomewidgets/qcronscheduler.h | 64 +++++++ sources/desktop-panel/plugin/dpadds.cpp | 7 +- sources/extsysmon/extsysmonaggregator.cpp | 14 +- sources/extsysmonsources/playersource.cpp | 8 +- sources/extsysmonsources/playersource.h | 6 +- sources/test/awtestlibrary.cpp | 7 + sources/test/awtestlibrary.h | 1 + sources/test/testabstractextitem.cpp | 1 + sources/test/testabstractformatter.cpp | 1 + sources/test/testawbugreporter.cpp | 1 + sources/test/testawconfighelper.cpp | 1 + sources/test/testawkeycache.cpp | 1 + sources/test/testawkeys.cpp | 1 + sources/test/testawpatternfunctions.cpp | 20 ++- sources/test/testawtelemetryhandler.cpp | 1 + sources/test/testawupdatehelper.cpp | 1 + sources/test/testbatterysource.cpp | 1 + sources/test/testdatetimeformatter.cpp | 1 + sources/test/testdesktopsource.cpp | 1 + sources/test/testdpplugin.cpp | 1 + sources/test/testextitemaggregator.cpp | 1 + sources/test/testextquotes.cpp | 2 + sources/test/testextquotes.h | 4 +- sources/test/testextscript.cpp | 1 + sources/test/testextupgrade.cpp | 1 + sources/test/testextweather.cpp | 2 + sources/test/testfloatformatter.cpp | 1 + sources/test/testgpuloadsource.cpp | 1 + sources/test/testgputempsource.cpp | 1 + sources/test/testhddtempsource.cpp | 1 + sources/test/testjsonformatter.cpp | 1 + sources/test/testlistformatter.cpp | 1 + sources/test/testnetworksource.cpp | 1 + sources/test/testnoformatter.cpp | 1 + sources/test/testplayersource.cpp | 8 +- sources/test/testprocessessource.cpp | 1 + sources/test/testscriptformatter.cpp | 1 + sources/test/teststringformatter.cpp | 1 + 55 files changed, 412 insertions(+), 144 deletions(-) create mode 100644 sources/awesomewidgets/qcronscheduler.cpp create mode 100644 sources/awesomewidgets/qcronscheduler.h diff --git a/.travis.yml b/.travis.yml index c8cd8e4..a88bb4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,13 +15,14 @@ arch: script: - export DISPLAY=:99.0 - git clone https://github.com/arcan1s/awesome-widgets/ - - cd awesome-widgets && git submodule update --init --recursive + - cd awesome-widgets; git submodule update --init --recursive - mkdir awesome-widgets/build - - cd awesome-widgets/build && cmake -DKDE_INSTALL_USE_QT_SYS_PATHS=ON -DCMAKE_BUILD_TYPE=Optimization -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_FUTURE=ON -DBUILD_TESTING=ON ../sources - - 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 && xvfb-run make test + - cd awesome-widgets/build; cmake -DKDE_INSTALL_USE_QT_SYS_PATHS=ON -DCMAKE_BUILD_TYPE=Optimization -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_FUTURE=ON -DBUILD_TESTING=ON ../sources + - 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 script: diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 8a7bce1..343d534 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -50,14 +50,14 @@ if (CMAKE_COMPILER_IS_GNUCXX) # avoid newer gcc warnings add_definitions(-D_DEFAULT_SOURCE) elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -stdlib=libc++") + set(CMAKE_CXX_FLAGS "-Wall -std=c++11") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG") # linker flags - set(CMAKE_EXE_LINKER_FLAGS "-lc++abi") - set(CMAKE_MODULE_LINKER_FLAGS "-lc++abi") - set(CMAKE_SHARED_LINKER_FLAGS "-lc++abi") +# set(CMAKE_EXE_LINKER_FLAGS "-lc++abi") +# set(CMAKE_MODULE_LINKER_FLAGS "-lc++abi") +# set(CMAKE_SHARED_LINKER_FLAGS "-lc++abi") else () message(FATAL_ERROR "Unknown compiler") endif () diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index d94bf39..4ec9596 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -253,8 +253,8 @@ void AWFormatterHelper::initKeys() continue; } if (!m_formattersClasses.contains(name)) { - qCWarning(LOG_AW) << "Invalid formatter" << name << "found in" - << key; + qCWarning(LOG_AW) + << "Invalid formatter" << name << "found in" << key; continue; } m_formatters[key] = m_formattersClasses[name]; diff --git a/sources/awesome-widget/plugin/awpatternfunctions.cpp b/sources/awesome-widget/plugin/awpatternfunctions.cpp index 70bd96c..0f76f49 100644 --- a/sources/awesome-widget/plugin/awpatternfunctions.cpp +++ b/sources/awesome-widget/plugin/awpatternfunctions.cpp @@ -234,9 +234,9 @@ QString AWPatternFunctions::insertMacros(QString code) QString("aw_macro_%1").arg(name), code); for (auto function : macroUsage) { if (function.args.count() != macro.args.count()) { - qCWarning(LOG_AW) << "Invalid args count found for call" - << function.what << "with macro" - << macro.what; + qCWarning(LOG_AW) + << "Invalid args count found for call" << function.what + << "with macro" << macro.what; continue; } // generate body to replace @@ -267,12 +267,14 @@ QStringList AWPatternFunctions::findKeys(const QString code, << keys; QStringList selectedKeys; + QString replacedCode = code; for (auto key : keys) if ((key.startsWith(QString("bar")) == isBars) - && (code.contains(QString("$%1").arg(key)))) { + && (replacedCode.contains(QString("$%1").arg(key)))) { qCInfo(LOG_AW) << "Found key" << key << "with bar enabled" << isBars; selectedKeys.append(key); + replacedCode.replace(QString("$%1").arg(key), ""); } if (selectedKeys.isEmpty()) qCWarning(LOG_AW) << "No keys found"; diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index 9758f32..79b9fb1 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -25,6 +25,7 @@ #include "abstractextitemaggregator.h" #include "awdebug.h" +#include "qcronscheduler.h" AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath) @@ -70,12 +71,32 @@ void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const _other->setActive(isActive()); _other->setApiVersion(apiVersion()); _other->setComment(comment()); + _other->setCron(cron()); _other->setInterval(interval()); _other->setName(name()); _other->setSocket(socket()); } +void AbstractExtItem::startTimer() +{ + if (!socket().isEmpty()) + // check if there is active socket setup + return; + else if (!cron().isEmpty()) + // check if there is active scheduler + return; + else if (m_times == 1) + // check if it is time to update + emit(requestDataUpdate()); + + // update counter value + if (m_times >= interval()) + m_times = 0; + m_times++; +} + + QString AbstractExtItem::writtableConfig() const { QString path = m_fileName; @@ -103,6 +124,12 @@ QString AbstractExtItem::comment() const } +QString AbstractExtItem::cron() const +{ + return m_cron; +} + + QString AbstractExtItem::fileName() const { return m_fileName; @@ -171,6 +198,28 @@ void AbstractExtItem::setComment(const QString _comment) } +void AbstractExtItem::setCron(const QString _cron) +{ + qCDebug(LOG_LIB) << "Cron string" << _cron; + // deinit module first + if (m_scheduler) { + disconnect(m_scheduler, SIGNAL(activated()), this, + SIGNAL(requestDataUpdate())); + delete m_scheduler; + } + + m_cron = _cron; + if (cron().isEmpty()) + return; + + // init scheduler + m_scheduler = new QCronScheduler(this); + m_scheduler->parse(cron()); + connect(m_scheduler, SIGNAL(activated()), this, + SIGNAL(requestDataUpdate())); +} + + void AbstractExtItem::setInterval(const int _interval) { qCDebug(LOG_LIB) << "Interval" << _interval; @@ -217,8 +266,6 @@ void AbstractExtItem::setSocket(const QString _socket) deinitSocket(); m_socketFile = _socket; - if (socket().isEmpty()) - return; } @@ -260,9 +307,15 @@ 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()); 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(); } @@ -287,7 +340,9 @@ void AbstractExtItem::writeConfiguration() const settings.setValue(QString("Comment"), comment()); settings.setValue(QString("X-AW-ApiVersion"), apiVersion()); settings.setValue(QString("X-AW-Active"), QVariant(isActive()).toString()); - settings.setValue(QString("X-AW-Interval"), interval()); + settings.setValue(QString("X-AW-Interval"), + cron().isEmpty() ? QVariant(interval()) + : QVariant(cron())); settings.setValue(QString("X-AW-Number"), number()); settings.setValue(QString("X-AW-Socket"), socket()); settings.endGroup(); @@ -298,5 +353,5 @@ void AbstractExtItem::writeConfiguration() const void AbstractExtItem::newConnectionReceived() { - emit(socketActivated()); + emit(requestDataUpdate()); } diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index 5debcec..05bc6c4 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -22,6 +22,7 @@ #include +class QCronScheduler; class QLocalServer; class AbstractExtItem : public QDialog @@ -30,6 +31,7 @@ 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(QString cron READ cron WRITE setCron) Q_PROPERTY(QString fileName READ fileName) Q_PROPERTY(int interval READ interval WRITE setInterval) Q_PROPERTY(QString name READ name WRITE setName) @@ -45,10 +47,12 @@ public: virtual AbstractExtItem *copy(const QString _fileName, const int _number) = 0; virtual void copyDefaults(AbstractExtItem *_other) const; + virtual void startTimer(); QString writtableConfig() const; // get methods int apiVersion() const; QString comment() const; + QString cron() const; QString fileName() const; int interval() const; bool isActive() const; @@ -61,6 +65,7 @@ public: void setApiVersion(const int _apiVersion = 0); void setActive(const bool _state = true); void setComment(const QString _comment = QString("empty")); + void setCron(const QString _cron = ""); void setInterval(const int _interval = 1); void setName(const QString _name = QString("none")); void setNumber(int _number = -1); @@ -68,7 +73,7 @@ public: signals: void dataReceived(const QVariantHash &data); - void socketActivated(); + void requestDataUpdate(); public slots: virtual void deinitSocket(); @@ -76,19 +81,22 @@ public slots: virtual void readConfiguration(); virtual QVariantHash run() = 0; virtual int showConfiguration(const QVariant args = QVariant()) = 0; - bool tryDelete() const; + virtual bool tryDelete() const; virtual void writeConfiguration() const; private slots: void newConnectionReceived(); private: + QCronScheduler *m_scheduler = nullptr; QString m_fileName = QString("/dev/null"); + int m_times = 0; virtual void translate() = 0; // properties int m_apiVersion = 0; bool m_active = true; QString m_comment = QString("empty"); + QString m_cron = ""; int m_interval = 1; QString m_name = QString("none"); int m_number = -1; diff --git a/sources/awesomewidgets/extnetworkrequest.cpp b/sources/awesomewidgets/extnetworkrequest.cpp index d62e965..b5a803f 100644 --- a/sources/awesomewidgets/extnetworkrequest.cpp +++ b/sources/awesomewidgets/extnetworkrequest.cpp @@ -50,7 +50,7 @@ ExtNetworkRequest::ExtNetworkRequest(QWidget *parent, const QString filePath) connect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkReplyReceived(QNetworkReply *))); - connect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest())); + connect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest())); } @@ -60,7 +60,7 @@ ExtNetworkRequest::~ExtNetworkRequest() disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkReplyReceived(QNetworkReply *))); - disconnect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest())); + disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest())); m_manager->deleteLater(); delete ui; @@ -119,16 +119,9 @@ void ExtNetworkRequest::readConfiguration() QVariantHash ExtNetworkRequest::run() { - if (!canRun()) + if (m_isRunning) return m_values; - - if (m_times == 1) - sendRequest(); - - // update value - if (m_times >= interval()) - m_times = 0; - m_times++; + startTimer(); return m_values; } @@ -202,12 +195,6 @@ void ExtNetworkRequest::sendRequest() } -bool ExtNetworkRequest::canRun() const -{ - return ((isActive()) && (!m_isRunning) && (socket().isEmpty())); -} - - void ExtNetworkRequest::initUrl() { m_url = QUrl(m_stringUrl); diff --git a/sources/awesomewidgets/extnetworkrequest.h b/sources/awesomewidgets/extnetworkrequest.h index c32ea5f..fb979c0 100644 --- a/sources/awesomewidgets/extnetworkrequest.h +++ b/sources/awesomewidgets/extnetworkrequest.h @@ -59,7 +59,6 @@ private: QUrl m_url; bool m_isRunning = false; Ui::ExtNetworkRequest *ui = nullptr; - bool canRun() const; void initUrl(); void translate(); // properties diff --git a/sources/awesomewidgets/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp index 908957d..d75c4cd 100644 --- a/sources/awesomewidgets/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -60,7 +60,7 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString filePath) connect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(quotesReplyReceived(QNetworkReply *))); - connect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest())); + connect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest())); } @@ -70,7 +70,7 @@ ExtQuotes::~ExtQuotes() disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(quotesReplyReceived(QNetworkReply *))); - disconnect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest())); + disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest())); m_manager->deleteLater(); delete ui; @@ -128,16 +128,9 @@ void ExtQuotes::readConfiguration() QVariantHash ExtQuotes::run() { - if (!canRun()) + if (m_isRunning) return m_values; - - if (m_times == 1) - sendRequest(); - - // update value - if (m_times >= interval()) - m_times = 0; - m_times++; + startTimer(); return m_values; } @@ -254,12 +247,6 @@ void ExtQuotes::sendRequest() } -bool ExtQuotes::canRun() const -{ - return ((isActive()) && (!m_isRunning) && (socket().isEmpty())); -} - - void ExtQuotes::initUrl() { // init query diff --git a/sources/awesomewidgets/extquotes.h b/sources/awesomewidgets/extquotes.h index d9561ac..ac1fc42 100644 --- a/sources/awesomewidgets/extquotes.h +++ b/sources/awesomewidgets/extquotes.h @@ -62,7 +62,6 @@ private: QUrl m_url; bool m_isRunning = false; Ui::ExtQuotes *ui = nullptr; - bool canRun() const; void initUrl(); void translate(); // properties diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 3d52778..0fb0197 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -49,7 +49,7 @@ ExtScript::ExtScript(QWidget *parent, const QString filePath) SLOT(updateValue())); m_process->waitForFinished(0); - connect(this, SIGNAL(socketActivated()), this, SLOT(startProcess())); + connect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess())); } @@ -61,7 +61,7 @@ ExtScript::~ExtScript() SLOT(updateValue())); m_process->kill(); m_process->deleteLater(); - disconnect(this, SIGNAL(socketActivated()), this, SLOT(startProcess())); + disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess())); delete ui; } @@ -203,8 +203,8 @@ QString ExtScript::applyFilters(QString _value) const qCInfo(LOG_LIB) << "Found filter" << filt; QVariantMap filter = m_jsonFilters[filt].toMap(); if (filter.isEmpty()) { - qCWarning(LOG_LIB) << "Could not find filter" << _value - << "in the json"; + qCWarning(LOG_LIB) + << "Could not find filter" << _value << "in the json"; continue; } for (auto f : filter.keys()) @@ -273,19 +273,11 @@ void ExtScript::readJsonFilters() } -#include QVariantHash ExtScript::run() { - if (!canRun()) + if (m_process->state() != QProcess::NotRunning) return m_values; - - if (m_times == 1) - startProcess(); - - // update value - if (m_times >= interval()) - m_times = 0; - m_times++; + startTimer(); return m_values; } @@ -401,13 +393,6 @@ void ExtScript::updateValue() } -bool ExtScript::canRun() const -{ - return ((isActive()) && (m_process->state() == QProcess::NotRunning) - && (socket().isEmpty())); -} - - void ExtScript::translate() { ui->label_name->setText(i18n("Name")); diff --git a/sources/awesomewidgets/extscript.h b/sources/awesomewidgets/extscript.h index 42bdf4b..002b716 100644 --- a/sources/awesomewidgets/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -80,7 +80,6 @@ private slots: private: QProcess *m_process = nullptr; Ui::ExtScript *ui = nullptr; - bool canRun() const; void translate(); // properties QString m_executable = QString("/usr/bin/true"); diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index d901072..6f103aa 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -45,7 +45,7 @@ ExtUpgrade::ExtUpgrade(QWidget *parent, const QString filePath) connect(m_process, SIGNAL(finished(int)), this, SLOT(updateValue())); m_process->waitForFinished(0); - connect(this, SIGNAL(socketActivated()), this, SLOT(startProcess())); + connect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess())); } @@ -55,7 +55,7 @@ ExtUpgrade::~ExtUpgrade() m_process->kill(); m_process->deleteLater(); - disconnect(this, SIGNAL(socketActivated()), this, SLOT(startProcess())); + disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess())); delete ui; } @@ -145,16 +145,9 @@ void ExtUpgrade::readConfiguration() QVariantHash ExtUpgrade::run() { - if (!isActive()) + if (m_process->state() != QProcess::NotRunning) return m_values; - - if (m_times == 1) - startProcess(); - - // update value - if (m_times >= interval()) - m_times = 0; - m_times++; + startTimer(); return m_values; } @@ -240,13 +233,6 @@ void ExtUpgrade::updateValue() } -bool ExtUpgrade::canRun() -{ - return ((isActive()) && (m_process->state() == QProcess::NotRunning) - && (socket().isEmpty())); -} - - void ExtUpgrade::translate() { ui->label_name->setText(i18n("Name")); diff --git a/sources/awesomewidgets/extupgrade.h b/sources/awesomewidgets/extupgrade.h index 0e27c60..d4c7c55 100644 --- a/sources/awesomewidgets/extupgrade.h +++ b/sources/awesomewidgets/extupgrade.h @@ -62,7 +62,6 @@ private slots: private: QProcess *m_process = nullptr; Ui::ExtUpgrade *ui = nullptr; - bool canRun(); void translate(); // properties QString m_executable = QString("/usr/bin/true"); diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 2facad2..9f1fe23 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -59,7 +59,7 @@ ExtWeather::ExtWeather(QWidget *parent, const QString filePath) connect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(weatherReplyReceived(QNetworkReply *))); - connect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest())); + connect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest())); } @@ -69,7 +69,7 @@ ExtWeather::~ExtWeather() disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(weatherReplyReceived(QNetworkReply *))); - disconnect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest())); + disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest())); m_manager->deleteLater(); delete m_providerObject; @@ -270,16 +270,9 @@ void ExtWeather::readJsonMap() QVariantHash ExtWeather::run() { - if ((!isActive()) || (m_isRunning)) + if (m_isRunning) return m_values; - - if (m_times == 1) - sendRequest(); - - // update value - if (m_times >= interval()) - m_times = 0; - m_times++; + startTimer(); return m_values; } @@ -379,12 +372,6 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply) } -bool ExtWeather::canRun() -{ - return ((isActive()) && (!m_isRunning) && (socket().isEmpty())); -} - - void ExtWeather::initProvider() { delete m_providerObject; diff --git a/sources/awesomewidgets/extweather.h b/sources/awesomewidgets/extweather.h index 873632c..201758c 100644 --- a/sources/awesomewidgets/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -79,7 +79,6 @@ private: AbstractWeatherProvider *m_providerObject = nullptr; bool m_isRunning = false; Ui::ExtWeather *ui = nullptr; - bool canRun(); void initProvider(); void translate(); // properties diff --git a/sources/awesomewidgets/qcronscheduler.cpp b/sources/awesomewidgets/qcronscheduler.cpp new file mode 100644 index 0000000..97126c5 --- /dev/null +++ b/sources/awesomewidgets/qcronscheduler.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + * 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 "qcronscheduler.h" + +#include +#include + +#include "awdebug.h" + + +QCronScheduler::QCronScheduler(QObject *parent) + : QObject(parent) +{ + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; + + m_timer = new QTimer(this); + m_timer->setSingleShot(false); + m_timer->setInterval(60 * 1000); + + connect(m_timer, SIGNAL(timeout()), this, SLOT(expired())); + + m_timer->start(); +} + + +QCronScheduler::~QCronScheduler() +{ + qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; + + m_timer->stop(); + delete m_timer; +} + + +void QCronScheduler::parse(const QString &timer) +{ + qCDebug(LOG_LIB) << "Parse timer string" << timer; + + QStringList fields = timer.split(' '); + 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); +} + + +void QCronScheduler::expired() +{ + QDateTime now = QDateTime::currentDateTime(); + + if (m_schedule.minutes.contains(now.time().minute()) + && m_schedule.hours.contains(now.time().hour()) + && m_schedule.days.contains(now.date().day()) + && m_schedule.months.contains(now.date().month()) + && m_schedule.weekdays.contains(now.date().dayOfWeek())) + emit(activated()); +} + + +QList QCronScheduler::parseField(const QString &value, const int min, + const int max) const +{ + qCDebug(LOG_LIB) << "Parse field" << value << "with corner values" << min + << max; + + QList parsed; + auto fields = value.split(','); + for (auto &field : fields) { + QCronField parsedField; + parsedField.fromRange(field.split('/').first(), min, max); + if (field.contains('/')) { + bool status; + parsedField.div = field.split('/', QString::SkipEmptyParts) + .at(1) + .toInt(&status); + if (!status) + parsedField.div = 1; + } + // append + parsed.append(parsedField.toList()); + } + + return parsed; +} + + +void QCronScheduler::QCronField::fromRange(const QString &range, const int min, + const int max) +{ + qCDebug(LOG_LIB) << "Parse field from range" << range + << "with corner values" << min << max; + + if (range == '*') { + this->min = min; + this->max = 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)); + if (!status) + this->min = -1; + // maximal value + this->max = std::min(max, interval.at(1).toInt(&status)); + if (!status) + this->max = -1; + // error check + if (this->min > this->max) + std::swap(this->min, this->max); + } else { + bool status; + int value = range.toInt(&status); + if (!status || (value < min) || (value > max)) + value = -1; + this->min = value; + this->max = value; + } +} + + +QList QCronScheduler::QCronField::toList() +{ + // error checking + if ((min == -1) || (max == -1)) + return QList(); + + QList output; + for (auto i = min; i <= max; ++i) { + if (i % div != 0) + continue; + output.append(i); + } + + std::sort(output.begin(), output.end()); + return output; +} diff --git a/sources/awesomewidgets/qcronscheduler.h b/sources/awesomewidgets/qcronscheduler.h new file mode 100644 index 0000000..f8e0aef --- /dev/null +++ b/sources/awesomewidgets/qcronscheduler.h @@ -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/ * + ***************************************************************************/ + +#ifndef QCRONSCHEDULER_H +#define QCRONSCHEDULER_H + +#include "QObject" + + +class QTimer; + +class QCronScheduler : public QObject +{ + Q_OBJECT + +public: + typedef struct { + QList minutes; + QList hours; + QList days; + QList months; + QList weekdays; + } QCronRunSchedule; + typedef struct { + int min = -1; + int max = -1; + int div = 1; + void fromRange(const QString &range, const int min, const int max); + QList toList(); + } QCronField; + + explicit QCronScheduler(QObject *parent); + virtual ~QCronScheduler(); + void parse(const QString &timer); + +signals: + void activated(); + +private slots: + void expired(); + +private: + QCronRunSchedule m_schedule; + QTimer *m_timer = nullptr; + QList parseField(const QString &value, const int min, + const int max) const; +}; + + +#endif /* QCRONSCHEDULER_H */ diff --git a/sources/desktop-panel/plugin/dpadds.cpp b/sources/desktop-panel/plugin/dpadds.cpp index 791c825..d2a953a 100644 --- a/sources/desktop-panel/plugin/dpadds.cpp +++ b/sources/desktop-panel/plugin/dpadds.cpp @@ -318,9 +318,10 @@ DPAdds::DesktopWindowsInfo DPAdds::getInfoByDesktop(const int desktop) const for (auto id : KWindowSystem::windows()) { KWindowInfo winInfo = KWindowInfo( - id, NET::Property::WMDesktop | NET::Property::WMGeometry - | NET::Property::WMState | NET::Property::WMWindowType - | NET::Property::WMVisibleName); + id, + NET::Property::WMDesktop | NET::Property::WMGeometry + | NET::Property::WMState | NET::Property::WMWindowType + | NET::Property::WMVisibleName); if (!winInfo.isOnDesktop(desktop)) continue; WindowData data; diff --git a/sources/extsysmon/extsysmonaggregator.cpp b/sources/extsysmon/extsysmonaggregator.cpp index f750e61..3c7a130 100644 --- a/sources/extsysmon/extsysmonaggregator.cpp +++ b/sources/extsysmon/extsysmonaggregator.cpp @@ -113,8 +113,9 @@ void ExtSysMonAggregator::init(const QHash config) m_map[source] = gpuTempItem; // hdd temperature AbstractExtSysMonSource *hddTempItem = new HDDTemperatureSource( - this, QStringList() << config[QString("HDDDEV")] - << config[QString("HDDTEMPCMD")]); + this, + QStringList() << config[QString("HDDDEV")] + << config[QString("HDDTEMPCMD")]); for (auto source : hddTempItem->sources()) m_map[source] = hddTempItem; // network @@ -124,10 +125,11 @@ void ExtSysMonAggregator::init(const QHash config) m_map[source] = networkItem; // player AbstractExtSysMonSource *playerItem = new PlayerSource( - this, QStringList() - << config[QString("PLAYER")] << config[QString("MPDADDRESS")] - << config[QString("MPDPORT")] << config[QString("MPRIS")] - << config[QString("PLAYERSYMBOLS")]); + this, + QStringList() << config[QString("PLAYER")] + << config[QString("MPDADDRESS")] + << config[QString("MPDPORT")] << config[QString("MPRIS")] + << config[QString("PLAYERSYMBOLS")]); for (auto source : playerItem->sources()) m_map[source] = playerItem; // processes diff --git a/sources/extsysmonsources/playersource.cpp b/sources/extsysmonsources/playersource.cpp index 9fc3c86..b5d4320 100644 --- a/sources/extsysmonsources/playersource.cpp +++ b/sources/extsysmonsources/playersource.cpp @@ -240,9 +240,9 @@ QString PlayerSource::buildString(const QString ¤t, const QString &value, int index = value.indexOf(current); if ((current.isEmpty()) || ((index + s + 1) > value.count())) - return QString("%1").arg(value.left(s), s, QLatin1Char(' ')); + return QString("%1").arg(value.left(s), -s, QLatin1Char(' ')); else - return QString("%1").arg(value.mid(index + 1, s), s, QLatin1Char(' ')); + return QString("%1").arg(value.mid(index + 1, s), -s, QLatin1Char(' ')); } @@ -329,8 +329,8 @@ QVariantHash PlayerSource::getPlayerMpdInfo() } else if (m_mpdSocket.state() == QAbstractSocket::ConnectedState) { // send request if (m_mpdSocket.write(MPD_STATUS_REQUEST) == -1) - qCWarning(LOG_ESS) << "Could not write request to" - << m_mpdSocket.peerName(); + qCWarning(LOG_ESS) + << "Could not write request to" << m_mpdSocket.peerName(); } return m_mpdCached; diff --git a/sources/extsysmonsources/playersource.h b/sources/extsysmonsources/playersource.h index 8fd6f99..b7b80a7 100644 --- a/sources/extsysmonsources/playersource.h +++ b/sources/extsysmonsources/playersource.h @@ -66,9 +66,9 @@ private: QMutex m_dbusMutex; QString m_player; int m_symbols; - QStringList m_metadata = QStringList() << QString("album") - << QString("artist") - << QString("title"); + QStringList m_metadata = QStringList() + << QString("album") << QString("artist") + << QString("title"); QVariantHash m_values; }; diff --git a/sources/test/awtestlibrary.cpp b/sources/test/awtestlibrary.cpp index d699c30..815f319 100644 --- a/sources/test/awtestlibrary.cpp +++ b/sources/test/awtestlibrary.cpp @@ -22,9 +22,16 @@ #include #include #include +#include #include +void AWTestLibrary::init() +{ + qsrand(static_cast(QTime::currentTime().msec())); +} + + bool AWTestLibrary::isKWinActive() { QSignalSpy spy(KWindowSystem::self(), SIGNAL(showingDesktopChanged(bool))); diff --git a/sources/test/awtestlibrary.h b/sources/test/awtestlibrary.h index 7595d86..0aab568 100644 --- a/sources/test/awtestlibrary.h +++ b/sources/test/awtestlibrary.h @@ -25,6 +25,7 @@ namespace AWTestLibrary { +void init(); bool isKWinActive(); char randomChar(); double randomDouble(); diff --git a/sources/test/testabstractextitem.cpp b/sources/test/testabstractextitem.cpp index dcfd1e6..8771c54 100644 --- a/sources/test/testabstractextitem.cpp +++ b/sources/test/testabstractextitem.cpp @@ -26,6 +26,7 @@ void TestAbstractExtItem::initTestCase() { + AWTestLibrary::init(); auto names = AWTestLibrary::randomFilenames(); fileName = names.first; writeFileName = names.second; diff --git a/sources/test/testabstractformatter.cpp b/sources/test/testabstractformatter.cpp index a8c6905..ba27ed9 100644 --- a/sources/test/testabstractformatter.cpp +++ b/sources/test/testabstractformatter.cpp @@ -26,6 +26,7 @@ void TestAbstractFormatter::initTestCase() { + AWTestLibrary::init(); formatter = new AWNoFormatter(nullptr); } diff --git a/sources/test/testawbugreporter.cpp b/sources/test/testawbugreporter.cpp index 1ccf9ee..071b20d 100644 --- a/sources/test/testawbugreporter.cpp +++ b/sources/test/testawbugreporter.cpp @@ -26,6 +26,7 @@ void TestAWBugReporter::initTestCase() { + AWTestLibrary::init(); plugin = new AWBugReporter(this); } diff --git a/sources/test/testawconfighelper.cpp b/sources/test/testawconfighelper.cpp index ac9716e..daa9525 100644 --- a/sources/test/testawconfighelper.cpp +++ b/sources/test/testawconfighelper.cpp @@ -26,6 +26,7 @@ void TestAWConfigHelper::initTestCase() { + AWTestLibrary::init(); plugin = new AWConfigHelper(this); } diff --git a/sources/test/testawkeycache.cpp b/sources/test/testawkeycache.cpp index df8ac05..2be9b0e 100644 --- a/sources/test/testawkeycache.cpp +++ b/sources/test/testawkeycache.cpp @@ -26,6 +26,7 @@ void TestAWKeyCache::initTestCase() { + AWTestLibrary::init(); } diff --git a/sources/test/testawkeys.cpp b/sources/test/testawkeys.cpp index 9754102..d4c597d 100644 --- a/sources/test/testawkeys.cpp +++ b/sources/test/testawkeys.cpp @@ -29,6 +29,7 @@ void TestAWKeys::initTestCase() { + AWTestLibrary::init(); plugin = new AWKeys(this); // tooltip init diff --git a/sources/test/testawpatternfunctions.cpp b/sources/test/testawpatternfunctions.cpp index 7e6a0d6..937956e 100644 --- a/sources/test/testawpatternfunctions.cpp +++ b/sources/test/testawpatternfunctions.cpp @@ -26,6 +26,7 @@ void TestAWPatternFunctions::initTestCase() { + AWTestLibrary::init(); } @@ -59,18 +60,29 @@ void TestAWPatternFunctions::test_findFunctionCalls() void TestAWPatternFunctions::test_findKeys() { - QStringList keys = AWTestLibrary::randomStringList(20); - QStringList bars = AWTestLibrary::randomStringList(20); + int count = AWTestLibrary::randomInt(200); + QStringList allKeys; + for (int i = 0; i < count; i++) { + auto key = AWTestLibrary::randomString(20); + while (allKeys.indexOf(QRegExp(QString("^%1.*").arg(key))) != -1) + key = AWTestLibrary::randomString(20); + allKeys.append(key); + } + + auto keys = AWTestLibrary::randomSelect(allKeys); + auto bars = AWTestLibrary::randomSelect(allKeys); std::for_each(bars.begin(), bars.end(), [](QString &bar) { bar.prepend(QString("bar")); }); - QStringList noise = AWTestLibrary::randomStringList(200); - QStringList allKeys = keys + bars + noise; QString pattern = QString("$%1 $%2") .arg(keys.join(QString(" $"))) .arg(bars.join(QString(" $"))); + allKeys.append(bars); + allKeys.sort(); + std::reverse(allKeys.begin(), allKeys.end()); keys.sort(); bars.sort(); + QStringList foundKeys = AWPatternFunctions::findKeys(pattern, allKeys, false); foundKeys.sort(); diff --git a/sources/test/testawtelemetryhandler.cpp b/sources/test/testawtelemetryhandler.cpp index d13e180..6c914c0 100644 --- a/sources/test/testawtelemetryhandler.cpp +++ b/sources/test/testawtelemetryhandler.cpp @@ -26,6 +26,7 @@ void TestAWTelemetryHandler::initTestCase() { + AWTestLibrary::init(); plugin = new AWTelemetryHandler(this); plugin->init(1, true, telemetryId); telemetryData = AWTestLibrary::randomString(); diff --git a/sources/test/testawupdatehelper.cpp b/sources/test/testawupdatehelper.cpp index 4b96b56..2585b83 100644 --- a/sources/test/testawupdatehelper.cpp +++ b/sources/test/testawupdatehelper.cpp @@ -26,6 +26,7 @@ void TestAWUpdateHelper::initTestCase() { + AWTestLibrary::init(); plugin = new AWUpdateHelper(this); } diff --git a/sources/test/testbatterysource.cpp b/sources/test/testbatterysource.cpp index 74f1f9f..8e1640a 100644 --- a/sources/test/testbatterysource.cpp +++ b/sources/test/testbatterysource.cpp @@ -26,6 +26,7 @@ void TestBatterySource::initTestCase() { + AWTestLibrary::init(); source = new BatterySource(this, QStringList() << acpiPath); } diff --git a/sources/test/testdatetimeformatter.cpp b/sources/test/testdatetimeformatter.cpp index c97b570..62050f2 100644 --- a/sources/test/testdatetimeformatter.cpp +++ b/sources/test/testdatetimeformatter.cpp @@ -27,6 +27,7 @@ void TestAWDateTimeFormatter::initTestCase() { + AWTestLibrary::init(); format = AWTestLibrary::randomSelect(QString(TIME_KEYS).split(QChar(','))) .join(QChar(' ')); diff --git a/sources/test/testdesktopsource.cpp b/sources/test/testdesktopsource.cpp index 36831e6..2471ca5 100644 --- a/sources/test/testdesktopsource.cpp +++ b/sources/test/testdesktopsource.cpp @@ -26,6 +26,7 @@ void TestDesktopSource::initTestCase() { + AWTestLibrary::init(); source = new DesktopSource(this, QStringList()); } diff --git a/sources/test/testdpplugin.cpp b/sources/test/testdpplugin.cpp index 8be71f0..0db977f 100644 --- a/sources/test/testdpplugin.cpp +++ b/sources/test/testdpplugin.cpp @@ -27,6 +27,7 @@ void TestDPPlugin::initTestCase() { + AWTestLibrary::init(); plugin = new DPAdds(this); m_isKwinActive = AWTestLibrary::isKWinActive(); } diff --git a/sources/test/testextitemaggregator.cpp b/sources/test/testextitemaggregator.cpp index ddd681f..631e169 100644 --- a/sources/test/testextitemaggregator.cpp +++ b/sources/test/testextitemaggregator.cpp @@ -27,6 +27,7 @@ void TestExtItemAggregator::initTestCase() { + AWTestLibrary::init(); aggregator = new ExtItemAggregator(nullptr, type); } diff --git a/sources/test/testextquotes.cpp b/sources/test/testextquotes.cpp index 5f5d48f..71fa3ed 100644 --- a/sources/test/testextquotes.cpp +++ b/sources/test/testextquotes.cpp @@ -20,11 +20,13 @@ #include +#include "awtestlibrary.h" #include "extquotes.h" void TestExtQuotes::initTestCase() { + AWTestLibrary::init(); extQuotes = new ExtQuotes(nullptr); extQuotes->setInterval(1); extQuotes->setTicker(ticker); diff --git a/sources/test/testextquotes.h b/sources/test/testextquotes.h index 1b07163..5eed05d 100644 --- a/sources/test/testextquotes.h +++ b/sources/test/testextquotes.h @@ -43,8 +43,8 @@ private: ExtQuotes *extQuotes = nullptr; QVariantHash cache; QString ticker = QString("EURUSD=X"); - QStringList types = QStringList() << QString("ask") << QString("bid") - << QString("price"); + 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); }; diff --git a/sources/test/testextscript.cpp b/sources/test/testextscript.cpp index d482eba..5198946 100644 --- a/sources/test/testextscript.cpp +++ b/sources/test/testextscript.cpp @@ -26,6 +26,7 @@ void TestExtScript::initTestCase() { + AWTestLibrary::init(); randomString = AWTestLibrary::randomString(); extScript = new ExtScript(nullptr); diff --git a/sources/test/testextupgrade.cpp b/sources/test/testextupgrade.cpp index fb0e0d3..b87ca0f 100644 --- a/sources/test/testextupgrade.cpp +++ b/sources/test/testextupgrade.cpp @@ -26,6 +26,7 @@ void TestExtUpgrade::initTestCase() { + AWTestLibrary::init(); randomStrings = AWTestLibrary::randomStringList(); cmd = QString("echo -e '%1'").arg(randomStrings.join(QString("\n"))); diff --git a/sources/test/testextweather.cpp b/sources/test/testextweather.cpp index 90a108c..0ffa2b1 100644 --- a/sources/test/testextweather.cpp +++ b/sources/test/testextweather.cpp @@ -20,11 +20,13 @@ #include +#include "awtestlibrary.h" #include "extweather.h" void TestExtWeather::initTestCase() { + AWTestLibrary::init(); extWeather = new ExtWeather(nullptr); extWeather->setInterval(1); extWeather->setCity(city); diff --git a/sources/test/testfloatformatter.cpp b/sources/test/testfloatformatter.cpp index dbe75c7..2a8993d 100644 --- a/sources/test/testfloatformatter.cpp +++ b/sources/test/testfloatformatter.cpp @@ -26,6 +26,7 @@ void TestAWFloatFormatter::initTestCase() { + AWTestLibrary::init(); formatter = new AWFloatFormatter(nullptr); } diff --git a/sources/test/testgpuloadsource.cpp b/sources/test/testgpuloadsource.cpp index 0bdc1ec..311428e 100644 --- a/sources/test/testgpuloadsource.cpp +++ b/sources/test/testgpuloadsource.cpp @@ -26,6 +26,7 @@ void TestGPULoadSource::initTestCase() { + AWTestLibrary::init(); device = GPULoadSource::autoGpu(); QVERIFY(!device.isEmpty()); diff --git a/sources/test/testgputempsource.cpp b/sources/test/testgputempsource.cpp index a73546c..aaa08c9 100644 --- a/sources/test/testgputempsource.cpp +++ b/sources/test/testgputempsource.cpp @@ -26,6 +26,7 @@ void TestGPUTemperatureSource::initTestCase() { + AWTestLibrary::init(); device = GPUTemperatureSource::autoGpu(); QVERIFY(!device.isEmpty()); diff --git a/sources/test/testhddtempsource.cpp b/sources/test/testhddtempsource.cpp index bccd587..0be6c7a 100644 --- a/sources/test/testhddtempsource.cpp +++ b/sources/test/testhddtempsource.cpp @@ -26,6 +26,7 @@ void TestHDDTemperatureSource::initTestCase() { + AWTestLibrary::init(); devices = HDDTemperatureSource::allHdd(); QVERIFY(devices.count() > 0); diff --git a/sources/test/testjsonformatter.cpp b/sources/test/testjsonformatter.cpp index c5b9c0d..c1611ff 100644 --- a/sources/test/testjsonformatter.cpp +++ b/sources/test/testjsonformatter.cpp @@ -26,6 +26,7 @@ void TestAWJsonFormatter::initTestCase() { + AWTestLibrary::init(); formatter = new AWJsonFormatter(nullptr); generate(); diff --git a/sources/test/testlistformatter.cpp b/sources/test/testlistformatter.cpp index 9522dae..2d58391 100644 --- a/sources/test/testlistformatter.cpp +++ b/sources/test/testlistformatter.cpp @@ -26,6 +26,7 @@ void TestAWListFormatter::initTestCase() { + AWTestLibrary::init(); separator = AWTestLibrary::randomString(10); formatter = new AWListFormatter(nullptr); diff --git a/sources/test/testnetworksource.cpp b/sources/test/testnetworksource.cpp index 9f2994b..878e258 100644 --- a/sources/test/testnetworksource.cpp +++ b/sources/test/testnetworksource.cpp @@ -26,6 +26,7 @@ void TestNetworkSource::initTestCase() { + AWTestLibrary::init(); source = new NetworkSource(this, QStringList()); } diff --git a/sources/test/testnoformatter.cpp b/sources/test/testnoformatter.cpp index a1ed6ce..7eda3c0 100644 --- a/sources/test/testnoformatter.cpp +++ b/sources/test/testnoformatter.cpp @@ -26,6 +26,7 @@ void TestAWNoFormatter::initTestCase() { + AWTestLibrary::init(); formatter = new AWNoFormatter(nullptr); } diff --git a/sources/test/testplayersource.cpp b/sources/test/testplayersource.cpp index e4b41cf..6d88bf7 100644 --- a/sources/test/testplayersource.cpp +++ b/sources/test/testplayersource.cpp @@ -26,6 +26,7 @@ void TestPlayerSource::initTestCase() { + AWTestLibrary::init(); } @@ -48,7 +49,6 @@ void TestPlayerSource::test_buildString() str = PlayerSource::buildString(str, randomString, 20); QCOMPARE(str.count(), 20); - QCOMPARE(randomString.indexOf(str), 1); str = PlayerSource::buildString(QString(), AWTestLibrary::randomString(10), 20); @@ -85,9 +85,9 @@ void TestPlayerSource::test_autoMpris() void TestPlayerSource::test_mpd() { - QStringList args(QStringList() << QString("mpd") << mpdAddress - << QString::number(mpdPort) - << QString("auto") << QString::number(10)); + QStringList args(QStringList() + << QString("mpd") << mpdAddress << QString::number(mpdPort) + << QString("auto") << QString::number(10)); PlayerSource *source = new PlayerSource(this, args); _test_sources(source); diff --git a/sources/test/testprocessessource.cpp b/sources/test/testprocessessource.cpp index fef1bf1..a6a3180 100644 --- a/sources/test/testprocessessource.cpp +++ b/sources/test/testprocessessource.cpp @@ -26,6 +26,7 @@ void TestProcessesSource::initTestCase() { + AWTestLibrary::init(); source = new ProcessesSource(this, QStringList()); } diff --git a/sources/test/testscriptformatter.cpp b/sources/test/testscriptformatter.cpp index d2e0adc..22b02ae 100644 --- a/sources/test/testscriptformatter.cpp +++ b/sources/test/testscriptformatter.cpp @@ -26,6 +26,7 @@ void TestAWScriptFormatter::initTestCase() { + AWTestLibrary::init(); formatter = new AWScriptFormatter(nullptr); formatter->setCode(fullCode); formatter->setAppendCode(false); diff --git a/sources/test/teststringformatter.cpp b/sources/test/teststringformatter.cpp index a7f98b6..1a1d78c 100644 --- a/sources/test/teststringformatter.cpp +++ b/sources/test/teststringformatter.cpp @@ -26,6 +26,7 @@ void TestAWStringFormatter::initTestCase() { + AWTestLibrary::init(); formatter = new AWStringFormatter(nullptr); }