mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
implement qcronscheduler, tests update
This commit is contained in:
parent
8be4cc6e82
commit
1b4d1d6944
13
.travis.yml
13
.travis.yml
@ -15,13 +15,14 @@ arch:
|
|||||||
script:
|
script:
|
||||||
- export DISPLAY=:99.0
|
- export DISPLAY=:99.0
|
||||||
- git clone https://github.com/arcan1s/awesome-widgets/
|
- 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
|
- 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; 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
|
||||||
- cd awesome-widgets/build && make cppcheck
|
- 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; make clangformat && ( [ `git status -s | wc -l` -eq 0 ] || exit 1 )
|
||||||
- cd awesome-widgets/build && xvfb-run make test
|
- cd awesome-widgets/build; ./test/awesomewidgets-test-extweather || true
|
||||||
|
- cd awesome-widgets/build; xvfb-run make test
|
||||||
- sleep 3
|
- sleep 3
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
@ -50,14 +50,14 @@ if (CMAKE_COMPILER_IS_GNUCXX)
|
|||||||
# avoid newer gcc warnings
|
# avoid newer gcc warnings
|
||||||
add_definitions(-D_DEFAULT_SOURCE)
|
add_definitions(-D_DEFAULT_SOURCE)
|
||||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
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_DEBUG "-g -O0")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||||
# linker flags
|
# linker flags
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "-lc++abi")
|
# set(CMAKE_EXE_LINKER_FLAGS "-lc++abi")
|
||||||
set(CMAKE_MODULE_LINKER_FLAGS "-lc++abi")
|
# set(CMAKE_MODULE_LINKER_FLAGS "-lc++abi")
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "-lc++abi")
|
# set(CMAKE_SHARED_LINKER_FLAGS "-lc++abi")
|
||||||
else ()
|
else ()
|
||||||
message(FATAL_ERROR "Unknown compiler")
|
message(FATAL_ERROR "Unknown compiler")
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -253,8 +253,8 @@ void AWFormatterHelper::initKeys()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!m_formattersClasses.contains(name)) {
|
if (!m_formattersClasses.contains(name)) {
|
||||||
qCWarning(LOG_AW) << "Invalid formatter" << name << "found in"
|
qCWarning(LOG_AW)
|
||||||
<< key;
|
<< "Invalid formatter" << name << "found in" << key;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
m_formatters[key] = m_formattersClasses[name];
|
m_formatters[key] = m_formattersClasses[name];
|
||||||
|
@ -234,9 +234,9 @@ QString AWPatternFunctions::insertMacros(QString code)
|
|||||||
QString("aw_macro_%1").arg(name), code);
|
QString("aw_macro_%1").arg(name), code);
|
||||||
for (auto function : macroUsage) {
|
for (auto function : macroUsage) {
|
||||||
if (function.args.count() != macro.args.count()) {
|
if (function.args.count() != macro.args.count()) {
|
||||||
qCWarning(LOG_AW) << "Invalid args count found for call"
|
qCWarning(LOG_AW)
|
||||||
<< function.what << "with macro"
|
<< "Invalid args count found for call" << function.what
|
||||||
<< macro.what;
|
<< "with macro" << macro.what;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// generate body to replace
|
// generate body to replace
|
||||||
@ -267,12 +267,14 @@ QStringList AWPatternFunctions::findKeys(const QString code,
|
|||||||
<< keys;
|
<< keys;
|
||||||
|
|
||||||
QStringList selectedKeys;
|
QStringList selectedKeys;
|
||||||
|
QString replacedCode = code;
|
||||||
for (auto key : keys)
|
for (auto key : keys)
|
||||||
if ((key.startsWith(QString("bar")) == isBars)
|
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"
|
qCInfo(LOG_AW) << "Found key" << key << "with bar enabled"
|
||||||
<< isBars;
|
<< isBars;
|
||||||
selectedKeys.append(key);
|
selectedKeys.append(key);
|
||||||
|
replacedCode.replace(QString("$%1").arg(key), "");
|
||||||
}
|
}
|
||||||
if (selectedKeys.isEmpty())
|
if (selectedKeys.isEmpty())
|
||||||
qCWarning(LOG_AW) << "No keys found";
|
qCWarning(LOG_AW) << "No keys found";
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "abstractextitemaggregator.h"
|
#include "abstractextitemaggregator.h"
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
#include "qcronscheduler.h"
|
||||||
|
|
||||||
|
|
||||||
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath)
|
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath)
|
||||||
@ -70,12 +71,32 @@ void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
|
|||||||
_other->setActive(isActive());
|
_other->setActive(isActive());
|
||||||
_other->setApiVersion(apiVersion());
|
_other->setApiVersion(apiVersion());
|
||||||
_other->setComment(comment());
|
_other->setComment(comment());
|
||||||
|
_other->setCron(cron());
|
||||||
_other->setInterval(interval());
|
_other->setInterval(interval());
|
||||||
_other->setName(name());
|
_other->setName(name());
|
||||||
_other->setSocket(socket());
|
_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 AbstractExtItem::writtableConfig() const
|
||||||
{
|
{
|
||||||
QString path = m_fileName;
|
QString path = m_fileName;
|
||||||
@ -103,6 +124,12 @@ QString AbstractExtItem::comment() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AbstractExtItem::cron() const
|
||||||
|
{
|
||||||
|
return m_cron;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString AbstractExtItem::fileName() const
|
QString AbstractExtItem::fileName() const
|
||||||
{
|
{
|
||||||
return m_fileName;
|
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)
|
void AbstractExtItem::setInterval(const int _interval)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Interval" << _interval;
|
qCDebug(LOG_LIB) << "Interval" << _interval;
|
||||||
@ -217,8 +266,6 @@ void AbstractExtItem::setSocket(const QString _socket)
|
|||||||
deinitSocket();
|
deinitSocket();
|
||||||
|
|
||||||
m_socketFile = _socket;
|
m_socketFile = _socket;
|
||||||
if (socket().isEmpty())
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -260,9 +307,15 @@ void AbstractExtItem::readConfiguration()
|
|||||||
setActive(
|
setActive(
|
||||||
settings.value(QString("X-AW-Active"), QVariant(isActive())).toString()
|
settings.value(QString("X-AW-Active"), QVariant(isActive())).toString()
|
||||||
== QString("true"));
|
== QString("true"));
|
||||||
setInterval(settings.value(QString("X-AW-Interval"), interval()).toInt());
|
|
||||||
setNumber(settings.value(QString("X-AW-Number"), number()).toInt());
|
setNumber(settings.value(QString("X-AW-Number"), number()).toInt());
|
||||||
setSocket(settings.value(QString("X-AW-Socket"), socket()).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();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +340,9 @@ void AbstractExtItem::writeConfiguration() const
|
|||||||
settings.setValue(QString("Comment"), comment());
|
settings.setValue(QString("Comment"), comment());
|
||||||
settings.setValue(QString("X-AW-ApiVersion"), apiVersion());
|
settings.setValue(QString("X-AW-ApiVersion"), apiVersion());
|
||||||
settings.setValue(QString("X-AW-Active"), QVariant(isActive()).toString());
|
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-Number"), number());
|
||||||
settings.setValue(QString("X-AW-Socket"), socket());
|
settings.setValue(QString("X-AW-Socket"), socket());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
@ -298,5 +353,5 @@ void AbstractExtItem::writeConfiguration() const
|
|||||||
|
|
||||||
void AbstractExtItem::newConnectionReceived()
|
void AbstractExtItem::newConnectionReceived()
|
||||||
{
|
{
|
||||||
emit(socketActivated());
|
emit(requestDataUpdate());
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
|
||||||
|
class QCronScheduler;
|
||||||
class QLocalServer;
|
class QLocalServer;
|
||||||
|
|
||||||
class AbstractExtItem : public QDialog
|
class AbstractExtItem : public QDialog
|
||||||
@ -30,6 +31,7 @@ class AbstractExtItem : public QDialog
|
|||||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||||
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
||||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||||
|
Q_PROPERTY(QString cron READ cron WRITE setCron)
|
||||||
Q_PROPERTY(QString fileName READ fileName)
|
Q_PROPERTY(QString fileName READ fileName)
|
||||||
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
Q_PROPERTY(QString name READ name WRITE setName)
|
||||||
@ -45,10 +47,12 @@ public:
|
|||||||
virtual AbstractExtItem *copy(const QString _fileName, const int _number)
|
virtual AbstractExtItem *copy(const QString _fileName, const int _number)
|
||||||
= 0;
|
= 0;
|
||||||
virtual void copyDefaults(AbstractExtItem *_other) const;
|
virtual void copyDefaults(AbstractExtItem *_other) const;
|
||||||
|
virtual void startTimer();
|
||||||
QString writtableConfig() const;
|
QString writtableConfig() const;
|
||||||
// get methods
|
// get methods
|
||||||
int apiVersion() const;
|
int apiVersion() const;
|
||||||
QString comment() const;
|
QString comment() const;
|
||||||
|
QString cron() const;
|
||||||
QString fileName() const;
|
QString fileName() const;
|
||||||
int interval() const;
|
int interval() const;
|
||||||
bool isActive() const;
|
bool isActive() const;
|
||||||
@ -61,6 +65,7 @@ public:
|
|||||||
void setApiVersion(const int _apiVersion = 0);
|
void setApiVersion(const int _apiVersion = 0);
|
||||||
void setActive(const bool _state = true);
|
void setActive(const bool _state = true);
|
||||||
void setComment(const QString _comment = QString("empty"));
|
void setComment(const QString _comment = QString("empty"));
|
||||||
|
void setCron(const QString _cron = "");
|
||||||
void setInterval(const int _interval = 1);
|
void setInterval(const int _interval = 1);
|
||||||
void setName(const QString _name = QString("none"));
|
void setName(const QString _name = QString("none"));
|
||||||
void setNumber(int _number = -1);
|
void setNumber(int _number = -1);
|
||||||
@ -68,7 +73,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dataReceived(const QVariantHash &data);
|
void dataReceived(const QVariantHash &data);
|
||||||
void socketActivated();
|
void requestDataUpdate();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void deinitSocket();
|
virtual void deinitSocket();
|
||||||
@ -76,19 +81,22 @@ public slots:
|
|||||||
virtual void readConfiguration();
|
virtual void readConfiguration();
|
||||||
virtual QVariantHash run() = 0;
|
virtual QVariantHash run() = 0;
|
||||||
virtual int showConfiguration(const QVariant args = QVariant()) = 0;
|
virtual int showConfiguration(const QVariant args = QVariant()) = 0;
|
||||||
bool tryDelete() const;
|
virtual bool tryDelete() const;
|
||||||
virtual void writeConfiguration() const;
|
virtual void writeConfiguration() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void newConnectionReceived();
|
void newConnectionReceived();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QCronScheduler *m_scheduler = nullptr;
|
||||||
QString m_fileName = QString("/dev/null");
|
QString m_fileName = QString("/dev/null");
|
||||||
|
int m_times = 0;
|
||||||
virtual void translate() = 0;
|
virtual void translate() = 0;
|
||||||
// properties
|
// properties
|
||||||
int m_apiVersion = 0;
|
int m_apiVersion = 0;
|
||||||
bool m_active = true;
|
bool m_active = true;
|
||||||
QString m_comment = QString("empty");
|
QString m_comment = QString("empty");
|
||||||
|
QString m_cron = "";
|
||||||
int m_interval = 1;
|
int m_interval = 1;
|
||||||
QString m_name = QString("none");
|
QString m_name = QString("none");
|
||||||
int m_number = -1;
|
int m_number = -1;
|
||||||
|
@ -50,7 +50,7 @@ ExtNetworkRequest::ExtNetworkRequest(QWidget *parent, const QString filePath)
|
|||||||
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(networkReplyReceived(QNetworkReply *)));
|
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,
|
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(networkReplyReceived(QNetworkReply *)));
|
SLOT(networkReplyReceived(QNetworkReply *)));
|
||||||
disconnect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest()));
|
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
|
||||||
|
|
||||||
m_manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
delete ui;
|
delete ui;
|
||||||
@ -119,16 +119,9 @@ void ExtNetworkRequest::readConfiguration()
|
|||||||
|
|
||||||
QVariantHash ExtNetworkRequest::run()
|
QVariantHash ExtNetworkRequest::run()
|
||||||
{
|
{
|
||||||
if (!canRun())
|
if (m_isRunning)
|
||||||
return m_values;
|
return m_values;
|
||||||
|
startTimer();
|
||||||
if (m_times == 1)
|
|
||||||
sendRequest();
|
|
||||||
|
|
||||||
// update value
|
|
||||||
if (m_times >= interval())
|
|
||||||
m_times = 0;
|
|
||||||
m_times++;
|
|
||||||
|
|
||||||
return m_values;
|
return m_values;
|
||||||
}
|
}
|
||||||
@ -202,12 +195,6 @@ void ExtNetworkRequest::sendRequest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ExtNetworkRequest::canRun() const
|
|
||||||
{
|
|
||||||
return ((isActive()) && (!m_isRunning) && (socket().isEmpty()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ExtNetworkRequest::initUrl()
|
void ExtNetworkRequest::initUrl()
|
||||||
{
|
{
|
||||||
m_url = QUrl(m_stringUrl);
|
m_url = QUrl(m_stringUrl);
|
||||||
|
@ -59,7 +59,6 @@ private:
|
|||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
bool m_isRunning = false;
|
bool m_isRunning = false;
|
||||||
Ui::ExtNetworkRequest *ui = nullptr;
|
Ui::ExtNetworkRequest *ui = nullptr;
|
||||||
bool canRun() const;
|
|
||||||
void initUrl();
|
void initUrl();
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
|
@ -60,7 +60,7 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString filePath)
|
|||||||
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(quotesReplyReceived(QNetworkReply *)));
|
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,
|
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(quotesReplyReceived(QNetworkReply *)));
|
SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||||
disconnect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest()));
|
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
|
||||||
|
|
||||||
m_manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
delete ui;
|
delete ui;
|
||||||
@ -128,16 +128,9 @@ void ExtQuotes::readConfiguration()
|
|||||||
|
|
||||||
QVariantHash ExtQuotes::run()
|
QVariantHash ExtQuotes::run()
|
||||||
{
|
{
|
||||||
if (!canRun())
|
if (m_isRunning)
|
||||||
return m_values;
|
return m_values;
|
||||||
|
startTimer();
|
||||||
if (m_times == 1)
|
|
||||||
sendRequest();
|
|
||||||
|
|
||||||
// update value
|
|
||||||
if (m_times >= interval())
|
|
||||||
m_times = 0;
|
|
||||||
m_times++;
|
|
||||||
|
|
||||||
return m_values;
|
return m_values;
|
||||||
}
|
}
|
||||||
@ -254,12 +247,6 @@ void ExtQuotes::sendRequest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ExtQuotes::canRun() const
|
|
||||||
{
|
|
||||||
return ((isActive()) && (!m_isRunning) && (socket().isEmpty()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ExtQuotes::initUrl()
|
void ExtQuotes::initUrl()
|
||||||
{
|
{
|
||||||
// init query
|
// init query
|
||||||
|
@ -62,7 +62,6 @@ private:
|
|||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
bool m_isRunning = false;
|
bool m_isRunning = false;
|
||||||
Ui::ExtQuotes *ui = nullptr;
|
Ui::ExtQuotes *ui = nullptr;
|
||||||
bool canRun() const;
|
|
||||||
void initUrl();
|
void initUrl();
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
|
@ -49,7 +49,7 @@ ExtScript::ExtScript(QWidget *parent, const QString filePath)
|
|||||||
SLOT(updateValue()));
|
SLOT(updateValue()));
|
||||||
m_process->waitForFinished(0);
|
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()));
|
SLOT(updateValue()));
|
||||||
m_process->kill();
|
m_process->kill();
|
||||||
m_process->deleteLater();
|
m_process->deleteLater();
|
||||||
disconnect(this, SIGNAL(socketActivated()), this, SLOT(startProcess()));
|
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,8 +203,8 @@ QString ExtScript::applyFilters(QString _value) const
|
|||||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||||
QVariantMap filter = m_jsonFilters[filt].toMap();
|
QVariantMap filter = m_jsonFilters[filt].toMap();
|
||||||
if (filter.isEmpty()) {
|
if (filter.isEmpty()) {
|
||||||
qCWarning(LOG_LIB) << "Could not find filter" << _value
|
qCWarning(LOG_LIB)
|
||||||
<< "in the json";
|
<< "Could not find filter" << _value << "in the json";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (auto f : filter.keys())
|
for (auto f : filter.keys())
|
||||||
@ -273,19 +273,11 @@ void ExtScript::readJsonFilters()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#include <QThread>
|
|
||||||
QVariantHash ExtScript::run()
|
QVariantHash ExtScript::run()
|
||||||
{
|
{
|
||||||
if (!canRun())
|
if (m_process->state() != QProcess::NotRunning)
|
||||||
return m_values;
|
return m_values;
|
||||||
|
startTimer();
|
||||||
if (m_times == 1)
|
|
||||||
startProcess();
|
|
||||||
|
|
||||||
// update value
|
|
||||||
if (m_times >= interval())
|
|
||||||
m_times = 0;
|
|
||||||
m_times++;
|
|
||||||
|
|
||||||
return m_values;
|
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()
|
void ExtScript::translate()
|
||||||
{
|
{
|
||||||
ui->label_name->setText(i18n("Name"));
|
ui->label_name->setText(i18n("Name"));
|
||||||
|
@ -80,7 +80,6 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QProcess *m_process = nullptr;
|
QProcess *m_process = nullptr;
|
||||||
Ui::ExtScript *ui = nullptr;
|
Ui::ExtScript *ui = nullptr;
|
||||||
bool canRun() const;
|
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QString m_executable = QString("/usr/bin/true");
|
QString m_executable = QString("/usr/bin/true");
|
||||||
|
@ -45,7 +45,7 @@ ExtUpgrade::ExtUpgrade(QWidget *parent, const QString filePath)
|
|||||||
connect(m_process, SIGNAL(finished(int)), this, SLOT(updateValue()));
|
connect(m_process, SIGNAL(finished(int)), this, SLOT(updateValue()));
|
||||||
m_process->waitForFinished(0);
|
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->kill();
|
||||||
m_process->deleteLater();
|
m_process->deleteLater();
|
||||||
disconnect(this, SIGNAL(socketActivated()), this, SLOT(startProcess()));
|
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,16 +145,9 @@ void ExtUpgrade::readConfiguration()
|
|||||||
|
|
||||||
QVariantHash ExtUpgrade::run()
|
QVariantHash ExtUpgrade::run()
|
||||||
{
|
{
|
||||||
if (!isActive())
|
if (m_process->state() != QProcess::NotRunning)
|
||||||
return m_values;
|
return m_values;
|
||||||
|
startTimer();
|
||||||
if (m_times == 1)
|
|
||||||
startProcess();
|
|
||||||
|
|
||||||
// update value
|
|
||||||
if (m_times >= interval())
|
|
||||||
m_times = 0;
|
|
||||||
m_times++;
|
|
||||||
|
|
||||||
return m_values;
|
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()
|
void ExtUpgrade::translate()
|
||||||
{
|
{
|
||||||
ui->label_name->setText(i18n("Name"));
|
ui->label_name->setText(i18n("Name"));
|
||||||
|
@ -62,7 +62,6 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QProcess *m_process = nullptr;
|
QProcess *m_process = nullptr;
|
||||||
Ui::ExtUpgrade *ui = nullptr;
|
Ui::ExtUpgrade *ui = nullptr;
|
||||||
bool canRun();
|
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QString m_executable = QString("/usr/bin/true");
|
QString m_executable = QString("/usr/bin/true");
|
||||||
|
@ -59,7 +59,7 @@ ExtWeather::ExtWeather(QWidget *parent, const QString filePath)
|
|||||||
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(weatherReplyReceived(QNetworkReply *)));
|
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,
|
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(weatherReplyReceived(QNetworkReply *)));
|
SLOT(weatherReplyReceived(QNetworkReply *)));
|
||||||
disconnect(this, SIGNAL(socketActivated()), this, SLOT(sendRequest()));
|
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
|
||||||
|
|
||||||
m_manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
delete m_providerObject;
|
delete m_providerObject;
|
||||||
@ -270,16 +270,9 @@ void ExtWeather::readJsonMap()
|
|||||||
|
|
||||||
QVariantHash ExtWeather::run()
|
QVariantHash ExtWeather::run()
|
||||||
{
|
{
|
||||||
if ((!isActive()) || (m_isRunning))
|
if (m_isRunning)
|
||||||
return m_values;
|
return m_values;
|
||||||
|
startTimer();
|
||||||
if (m_times == 1)
|
|
||||||
sendRequest();
|
|
||||||
|
|
||||||
// update value
|
|
||||||
if (m_times >= interval())
|
|
||||||
m_times = 0;
|
|
||||||
m_times++;
|
|
||||||
|
|
||||||
return m_values;
|
return m_values;
|
||||||
}
|
}
|
||||||
@ -379,12 +372,6 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ExtWeather::canRun()
|
|
||||||
{
|
|
||||||
return ((isActive()) && (!m_isRunning) && (socket().isEmpty()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ExtWeather::initProvider()
|
void ExtWeather::initProvider()
|
||||||
{
|
{
|
||||||
delete m_providerObject;
|
delete m_providerObject;
|
||||||
|
@ -79,7 +79,6 @@ private:
|
|||||||
AbstractWeatherProvider *m_providerObject = nullptr;
|
AbstractWeatherProvider *m_providerObject = nullptr;
|
||||||
bool m_isRunning = false;
|
bool m_isRunning = false;
|
||||||
Ui::ExtWeather *ui = nullptr;
|
Ui::ExtWeather *ui = nullptr;
|
||||||
bool canRun();
|
|
||||||
void initProvider();
|
void initProvider();
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
|
158
sources/awesomewidgets/qcronscheduler.cpp
Normal file
158
sources/awesomewidgets/qcronscheduler.cpp
Normal file
@ -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 <QDateTime>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#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<int> QCronScheduler::parseField(const QString &value, const int min,
|
||||||
|
const int max) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Parse field" << value << "with corner values" << min
|
||||||
|
<< max;
|
||||||
|
|
||||||
|
QList<int> 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<int> QCronScheduler::QCronField::toList()
|
||||||
|
{
|
||||||
|
// error checking
|
||||||
|
if ((min == -1) || (max == -1))
|
||||||
|
return QList<int>();
|
||||||
|
|
||||||
|
QList<int> output;
|
||||||
|
for (auto i = min; i <= max; ++i) {
|
||||||
|
if (i % div != 0)
|
||||||
|
continue;
|
||||||
|
output.append(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(output.begin(), output.end());
|
||||||
|
return output;
|
||||||
|
}
|
64
sources/awesomewidgets/qcronscheduler.h
Normal file
64
sources/awesomewidgets/qcronscheduler.h
Normal file
@ -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<int> minutes;
|
||||||
|
QList<int> hours;
|
||||||
|
QList<int> days;
|
||||||
|
QList<int> months;
|
||||||
|
QList<int> 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<int> 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<int> parseField(const QString &value, const int min,
|
||||||
|
const int max) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* QCRONSCHEDULER_H */
|
@ -318,9 +318,10 @@ DPAdds::DesktopWindowsInfo DPAdds::getInfoByDesktop(const int desktop) const
|
|||||||
|
|
||||||
for (auto id : KWindowSystem::windows()) {
|
for (auto id : KWindowSystem::windows()) {
|
||||||
KWindowInfo winInfo = KWindowInfo(
|
KWindowInfo winInfo = KWindowInfo(
|
||||||
id, NET::Property::WMDesktop | NET::Property::WMGeometry
|
id,
|
||||||
| NET::Property::WMState | NET::Property::WMWindowType
|
NET::Property::WMDesktop | NET::Property::WMGeometry
|
||||||
| NET::Property::WMVisibleName);
|
| NET::Property::WMState | NET::Property::WMWindowType
|
||||||
|
| NET::Property::WMVisibleName);
|
||||||
if (!winInfo.isOnDesktop(desktop))
|
if (!winInfo.isOnDesktop(desktop))
|
||||||
continue;
|
continue;
|
||||||
WindowData data;
|
WindowData data;
|
||||||
|
@ -113,8 +113,9 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
|||||||
m_map[source] = gpuTempItem;
|
m_map[source] = gpuTempItem;
|
||||||
// hdd temperature
|
// hdd temperature
|
||||||
AbstractExtSysMonSource *hddTempItem = new HDDTemperatureSource(
|
AbstractExtSysMonSource *hddTempItem = new HDDTemperatureSource(
|
||||||
this, QStringList() << config[QString("HDDDEV")]
|
this,
|
||||||
<< config[QString("HDDTEMPCMD")]);
|
QStringList() << config[QString("HDDDEV")]
|
||||||
|
<< config[QString("HDDTEMPCMD")]);
|
||||||
for (auto source : hddTempItem->sources())
|
for (auto source : hddTempItem->sources())
|
||||||
m_map[source] = hddTempItem;
|
m_map[source] = hddTempItem;
|
||||||
// network
|
// network
|
||||||
@ -124,10 +125,11 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
|||||||
m_map[source] = networkItem;
|
m_map[source] = networkItem;
|
||||||
// player
|
// player
|
||||||
AbstractExtSysMonSource *playerItem = new PlayerSource(
|
AbstractExtSysMonSource *playerItem = new PlayerSource(
|
||||||
this, QStringList()
|
this,
|
||||||
<< config[QString("PLAYER")] << config[QString("MPDADDRESS")]
|
QStringList() << config[QString("PLAYER")]
|
||||||
<< config[QString("MPDPORT")] << config[QString("MPRIS")]
|
<< config[QString("MPDADDRESS")]
|
||||||
<< config[QString("PLAYERSYMBOLS")]);
|
<< config[QString("MPDPORT")] << config[QString("MPRIS")]
|
||||||
|
<< config[QString("PLAYERSYMBOLS")]);
|
||||||
for (auto source : playerItem->sources())
|
for (auto source : playerItem->sources())
|
||||||
m_map[source] = playerItem;
|
m_map[source] = playerItem;
|
||||||
// processes
|
// processes
|
||||||
|
@ -240,9 +240,9 @@ QString PlayerSource::buildString(const QString ¤t, const QString &value,
|
|||||||
|
|
||||||
int index = value.indexOf(current);
|
int index = value.indexOf(current);
|
||||||
if ((current.isEmpty()) || ((index + s + 1) > value.count()))
|
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
|
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) {
|
} else if (m_mpdSocket.state() == QAbstractSocket::ConnectedState) {
|
||||||
// send request
|
// send request
|
||||||
if (m_mpdSocket.write(MPD_STATUS_REQUEST) == -1)
|
if (m_mpdSocket.write(MPD_STATUS_REQUEST) == -1)
|
||||||
qCWarning(LOG_ESS) << "Could not write request to"
|
qCWarning(LOG_ESS)
|
||||||
<< m_mpdSocket.peerName();
|
<< "Could not write request to" << m_mpdSocket.peerName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_mpdCached;
|
return m_mpdCached;
|
||||||
|
@ -66,9 +66,9 @@ private:
|
|||||||
QMutex m_dbusMutex;
|
QMutex m_dbusMutex;
|
||||||
QString m_player;
|
QString m_player;
|
||||||
int m_symbols;
|
int m_symbols;
|
||||||
QStringList m_metadata = QStringList() << QString("album")
|
QStringList m_metadata = QStringList()
|
||||||
<< QString("artist")
|
<< QString("album") << QString("artist")
|
||||||
<< QString("title");
|
<< QString("title");
|
||||||
QVariantHash m_values;
|
QVariantHash m_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,9 +22,16 @@
|
|||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QTime>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
|
|
||||||
|
void AWTestLibrary::init()
|
||||||
|
{
|
||||||
|
qsrand(static_cast<uint>(QTime::currentTime().msec()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool AWTestLibrary::isKWinActive()
|
bool AWTestLibrary::isKWinActive()
|
||||||
{
|
{
|
||||||
QSignalSpy spy(KWindowSystem::self(), SIGNAL(showingDesktopChanged(bool)));
|
QSignalSpy spy(KWindowSystem::self(), SIGNAL(showingDesktopChanged(bool)));
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
namespace AWTestLibrary
|
namespace AWTestLibrary
|
||||||
{
|
{
|
||||||
|
void init();
|
||||||
bool isKWinActive();
|
bool isKWinActive();
|
||||||
char randomChar();
|
char randomChar();
|
||||||
double randomDouble();
|
double randomDouble();
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAbstractExtItem::initTestCase()
|
void TestAbstractExtItem::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
auto names = AWTestLibrary::randomFilenames();
|
auto names = AWTestLibrary::randomFilenames();
|
||||||
fileName = names.first;
|
fileName = names.first;
|
||||||
writeFileName = names.second;
|
writeFileName = names.second;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAbstractFormatter::initTestCase()
|
void TestAbstractFormatter::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
formatter = new AWNoFormatter(nullptr);
|
formatter = new AWNoFormatter(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWBugReporter::initTestCase()
|
void TestAWBugReporter::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
plugin = new AWBugReporter(this);
|
plugin = new AWBugReporter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWConfigHelper::initTestCase()
|
void TestAWConfigHelper::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
plugin = new AWConfigHelper(this);
|
plugin = new AWConfigHelper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWKeyCache::initTestCase()
|
void TestAWKeyCache::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
void TestAWKeys::initTestCase()
|
void TestAWKeys::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
plugin = new AWKeys(this);
|
plugin = new AWKeys(this);
|
||||||
|
|
||||||
// tooltip init
|
// tooltip init
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWPatternFunctions::initTestCase()
|
void TestAWPatternFunctions::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -59,18 +60,29 @@ void TestAWPatternFunctions::test_findFunctionCalls()
|
|||||||
|
|
||||||
void TestAWPatternFunctions::test_findKeys()
|
void TestAWPatternFunctions::test_findKeys()
|
||||||
{
|
{
|
||||||
QStringList keys = AWTestLibrary::randomStringList(20);
|
int count = AWTestLibrary::randomInt(200);
|
||||||
QStringList bars = AWTestLibrary::randomStringList(20);
|
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(),
|
std::for_each(bars.begin(), bars.end(),
|
||||||
[](QString &bar) { bar.prepend(QString("bar")); });
|
[](QString &bar) { bar.prepend(QString("bar")); });
|
||||||
QStringList noise = AWTestLibrary::randomStringList(200);
|
|
||||||
QStringList allKeys = keys + bars + noise;
|
|
||||||
QString pattern = QString("$%1 $%2")
|
QString pattern = QString("$%1 $%2")
|
||||||
.arg(keys.join(QString(" $")))
|
.arg(keys.join(QString(" $")))
|
||||||
.arg(bars.join(QString(" $")));
|
.arg(bars.join(QString(" $")));
|
||||||
|
|
||||||
|
allKeys.append(bars);
|
||||||
|
allKeys.sort();
|
||||||
|
std::reverse(allKeys.begin(), allKeys.end());
|
||||||
keys.sort();
|
keys.sort();
|
||||||
bars.sort();
|
bars.sort();
|
||||||
|
|
||||||
QStringList foundKeys
|
QStringList foundKeys
|
||||||
= AWPatternFunctions::findKeys(pattern, allKeys, false);
|
= AWPatternFunctions::findKeys(pattern, allKeys, false);
|
||||||
foundKeys.sort();
|
foundKeys.sort();
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWTelemetryHandler::initTestCase()
|
void TestAWTelemetryHandler::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
plugin = new AWTelemetryHandler(this);
|
plugin = new AWTelemetryHandler(this);
|
||||||
plugin->init(1, true, telemetryId);
|
plugin->init(1, true, telemetryId);
|
||||||
telemetryData = AWTestLibrary::randomString();
|
telemetryData = AWTestLibrary::randomString();
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWUpdateHelper::initTestCase()
|
void TestAWUpdateHelper::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
plugin = new AWUpdateHelper(this);
|
plugin = new AWUpdateHelper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestBatterySource::initTestCase()
|
void TestBatterySource::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
source = new BatterySource(this, QStringList() << acpiPath);
|
source = new BatterySource(this, QStringList() << acpiPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
void TestAWDateTimeFormatter::initTestCase()
|
void TestAWDateTimeFormatter::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
format = AWTestLibrary::randomSelect(QString(TIME_KEYS).split(QChar(',')))
|
format = AWTestLibrary::randomSelect(QString(TIME_KEYS).split(QChar(',')))
|
||||||
.join(QChar(' '));
|
.join(QChar(' '));
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestDesktopSource::initTestCase()
|
void TestDesktopSource::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
source = new DesktopSource(this, QStringList());
|
source = new DesktopSource(this, QStringList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
void TestDPPlugin::initTestCase()
|
void TestDPPlugin::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
plugin = new DPAdds(this);
|
plugin = new DPAdds(this);
|
||||||
m_isKwinActive = AWTestLibrary::isKWinActive();
|
m_isKwinActive = AWTestLibrary::isKWinActive();
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
void TestExtItemAggregator::initTestCase()
|
void TestExtItemAggregator::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
aggregator = new ExtItemAggregator<AWNoFormatter>(nullptr, type);
|
aggregator = new ExtItemAggregator<AWNoFormatter>(nullptr, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
|
#include "awtestlibrary.h"
|
||||||
#include "extquotes.h"
|
#include "extquotes.h"
|
||||||
|
|
||||||
|
|
||||||
void TestExtQuotes::initTestCase()
|
void TestExtQuotes::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
extQuotes = new ExtQuotes(nullptr);
|
extQuotes = new ExtQuotes(nullptr);
|
||||||
extQuotes->setInterval(1);
|
extQuotes->setInterval(1);
|
||||||
extQuotes->setTicker(ticker);
|
extQuotes->setTicker(ticker);
|
||||||
|
@ -43,8 +43,8 @@ private:
|
|||||||
ExtQuotes *extQuotes = nullptr;
|
ExtQuotes *extQuotes = nullptr;
|
||||||
QVariantHash cache;
|
QVariantHash cache;
|
||||||
QString ticker = QString("EURUSD=X");
|
QString ticker = QString("EURUSD=X");
|
||||||
QStringList types = QStringList() << QString("ask") << QString("bid")
|
QStringList types = QStringList()
|
||||||
<< QString("price");
|
<< QString("ask") << QString("bid") << QString("price");
|
||||||
// we assume that price will not be differ more than in 2 times
|
// we assume that price will not be differ more than in 2 times
|
||||||
QPair<double, double> price = QPair<double, double>(0.5, 2.0);
|
QPair<double, double> price = QPair<double, double>(0.5, 2.0);
|
||||||
};
|
};
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestExtScript::initTestCase()
|
void TestExtScript::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
randomString = AWTestLibrary::randomString();
|
randomString = AWTestLibrary::randomString();
|
||||||
|
|
||||||
extScript = new ExtScript(nullptr);
|
extScript = new ExtScript(nullptr);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestExtUpgrade::initTestCase()
|
void TestExtUpgrade::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
randomStrings = AWTestLibrary::randomStringList();
|
randomStrings = AWTestLibrary::randomStringList();
|
||||||
cmd = QString("echo -e '%1'").arg(randomStrings.join(QString("\n")));
|
cmd = QString("echo -e '%1'").arg(randomStrings.join(QString("\n")));
|
||||||
|
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
|
#include "awtestlibrary.h"
|
||||||
#include "extweather.h"
|
#include "extweather.h"
|
||||||
|
|
||||||
|
|
||||||
void TestExtWeather::initTestCase()
|
void TestExtWeather::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
extWeather = new ExtWeather(nullptr);
|
extWeather = new ExtWeather(nullptr);
|
||||||
extWeather->setInterval(1);
|
extWeather->setInterval(1);
|
||||||
extWeather->setCity(city);
|
extWeather->setCity(city);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWFloatFormatter::initTestCase()
|
void TestAWFloatFormatter::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
formatter = new AWFloatFormatter(nullptr);
|
formatter = new AWFloatFormatter(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestGPULoadSource::initTestCase()
|
void TestGPULoadSource::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
device = GPULoadSource::autoGpu();
|
device = GPULoadSource::autoGpu();
|
||||||
QVERIFY(!device.isEmpty());
|
QVERIFY(!device.isEmpty());
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestGPUTemperatureSource::initTestCase()
|
void TestGPUTemperatureSource::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
device = GPUTemperatureSource::autoGpu();
|
device = GPUTemperatureSource::autoGpu();
|
||||||
QVERIFY(!device.isEmpty());
|
QVERIFY(!device.isEmpty());
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestHDDTemperatureSource::initTestCase()
|
void TestHDDTemperatureSource::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
devices = HDDTemperatureSource::allHdd();
|
devices = HDDTemperatureSource::allHdd();
|
||||||
QVERIFY(devices.count() > 0);
|
QVERIFY(devices.count() > 0);
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWJsonFormatter::initTestCase()
|
void TestAWJsonFormatter::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
formatter = new AWJsonFormatter(nullptr);
|
formatter = new AWJsonFormatter(nullptr);
|
||||||
|
|
||||||
generate();
|
generate();
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWListFormatter::initTestCase()
|
void TestAWListFormatter::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
separator = AWTestLibrary::randomString(10);
|
separator = AWTestLibrary::randomString(10);
|
||||||
|
|
||||||
formatter = new AWListFormatter(nullptr);
|
formatter = new AWListFormatter(nullptr);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestNetworkSource::initTestCase()
|
void TestNetworkSource::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
source = new NetworkSource(this, QStringList());
|
source = new NetworkSource(this, QStringList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWNoFormatter::initTestCase()
|
void TestAWNoFormatter::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
formatter = new AWNoFormatter(nullptr);
|
formatter = new AWNoFormatter(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestPlayerSource::initTestCase()
|
void TestPlayerSource::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -48,7 +49,6 @@ void TestPlayerSource::test_buildString()
|
|||||||
|
|
||||||
str = PlayerSource::buildString(str, randomString, 20);
|
str = PlayerSource::buildString(str, randomString, 20);
|
||||||
QCOMPARE(str.count(), 20);
|
QCOMPARE(str.count(), 20);
|
||||||
QCOMPARE(randomString.indexOf(str), 1);
|
|
||||||
|
|
||||||
str = PlayerSource::buildString(QString(), AWTestLibrary::randomString(10),
|
str = PlayerSource::buildString(QString(), AWTestLibrary::randomString(10),
|
||||||
20);
|
20);
|
||||||
@ -85,9 +85,9 @@ void TestPlayerSource::test_autoMpris()
|
|||||||
|
|
||||||
void TestPlayerSource::test_mpd()
|
void TestPlayerSource::test_mpd()
|
||||||
{
|
{
|
||||||
QStringList args(QStringList() << QString("mpd") << mpdAddress
|
QStringList args(QStringList()
|
||||||
<< QString::number(mpdPort)
|
<< QString("mpd") << mpdAddress << QString::number(mpdPort)
|
||||||
<< QString("auto") << QString::number(10));
|
<< QString("auto") << QString::number(10));
|
||||||
PlayerSource *source = new PlayerSource(this, args);
|
PlayerSource *source = new PlayerSource(this, args);
|
||||||
_test_sources(source);
|
_test_sources(source);
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestProcessesSource::initTestCase()
|
void TestProcessesSource::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
source = new ProcessesSource(this, QStringList());
|
source = new ProcessesSource(this, QStringList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWScriptFormatter::initTestCase()
|
void TestAWScriptFormatter::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
formatter = new AWScriptFormatter(nullptr);
|
formatter = new AWScriptFormatter(nullptr);
|
||||||
formatter->setCode(fullCode);
|
formatter->setCode(fullCode);
|
||||||
formatter->setAppendCode(false);
|
formatter->setAppendCode(false);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
void TestAWStringFormatter::initTestCase()
|
void TestAWStringFormatter::initTestCase()
|
||||||
{
|
{
|
||||||
|
AWTestLibrary::init();
|
||||||
formatter = new AWStringFormatter(nullptr);
|
formatter = new AWStringFormatter(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user