diff --git a/src/util/externalcommandhelper.cpp b/src/util/externalcommandhelper.cpp index a877dd7..4591307 100644 --- a/src/util/externalcommandhelper.cpp +++ b/src/util/externalcommandhelper.cpp @@ -17,9 +17,7 @@ #include "externalcommandhelper.h" -#include #include -#include #include #include #include @@ -28,6 +26,9 @@ #include +// exit helper if no ping for 42s +#define TIMEOUT 42000 + /** Initialize ExternalCommandHelper Daemon and prepare DBus interface */ ActionReply ExternalCommandHelper::init(const QVariantMap& args) @@ -47,11 +48,9 @@ ActionReply ExternalCommandHelper::init(const QVariantMap& args) } QDBusConnection::systemBus().registerObject(QStringLiteral("/Helper"), this, QDBusConnection::ExportAllSlots); - m_pingTime = new QDateTime(QDateTime::currentDateTime()); - - QTimer *timer = new QTimer(this); - connect(timer, &QTimer::timeout, this, &ExternalCommandHelper::checkPing); - timer->start(20000); // check ping every 20 secs + timer = new QTimer(this); + connect(timer, &QTimer::timeout, this, [=] () { exit(m_callerUuid); }); + timer->start(TIMEOUT); HelperSupport::progressStep(QVariantMap()); m_loop.exec(); @@ -250,20 +249,7 @@ void ExternalCommandHelper::ping(const QString &Uuid) if (!isCallerAuthorized(Uuid)) return; - // update ping - m_pingTime->setDate(QDate::currentDate()); - m_pingTime->setTime(QTime::currentTime()); -} - -void ExternalCommandHelper::checkPing() -{ - qint64 mSecsSinceLastPing = m_pingTime->msecsTo(QDateTime::currentDateTime()); - - qDebug() << mSecsSinceLastPing / 1000.0 << " seconds since the last ping."; - - if (mSecsSinceLastPing >= 42000) { // more than 42 seconds since the last ping - exit(m_callerUuid); - } + timer->setInterval(TIMEOUT); } void ExternalCommandHelper::onReadOutput() diff --git a/src/util/externalcommandhelper.h b/src/util/externalcommandhelper.h index 4aea8d4..aba456a 100644 --- a/src/util/externalcommandhelper.h +++ b/src/util/externalcommandhelper.h @@ -20,11 +20,12 @@ #include -#include #include #include #include +class QTimer; + using namespace KAuth; class ExternalCommandHelper : public QObject @@ -47,9 +48,6 @@ public Q_SLOTS: Q_SCRIPTABLE void exit(const QString& Uuid); Q_SCRIPTABLE void ping(const QString& Uuid); -private Q_SLOTS: - void checkPing(); - private: void onReadOutput(); bool isCallerAuthorized(const QString& Uuid); @@ -60,7 +58,7 @@ private: QString m_sourceDevice; QProcess m_cmd; - QDateTime *m_pingTime; + QTimer *timer; // QByteArray output; };