mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-19 00:29:57 +00:00
implement qcronscheduler, tests update
This commit is contained in:
@ -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());
|
||||
}
|
||||
|
Reference in New Issue
Block a user