From 6cff70567b1907103a15193166132191a74d6063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sun, 11 Oct 2020 23:46:20 +0100 Subject: [PATCH] Fix signals between helper and client. --- src/jobs/job.cpp | 4 ++-- src/jobs/job.h | 2 +- src/util/externalcommand.cpp | 8 +++----- src/util/externalcommand.h | 7 +------ src/util/externalcommandhelper.cpp | 25 +++++++++++-------------- src/util/externalcommandhelper.h | 4 ++-- 6 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/jobs/job.cpp b/src/jobs/job.cpp index f46f409..4e2878b 100644 --- a/src/jobs/job.cpp +++ b/src/jobs/job.cpp @@ -94,9 +94,9 @@ void Job::emitProgress(int i) Q_EMIT progress(i); } -void Job::updateReport(const QVariantMap& reportString) +void Job::updateReport(const QString& report) { - m_Report->line() << reportString[QStringLiteral("report")].toString(); + m_Report->line() << report; } Report* Job::jobStarted(Report& parent) diff --git a/src/jobs/job.h b/src/jobs/job.h index 8e74128..cc32c4d 100644 --- a/src/jobs/job.h +++ b/src/jobs/job.h @@ -71,7 +71,7 @@ public: } void emitProgress(int i); - void updateReport(const QVariantMap& reportString); + void updateReport(const QString& report); protected: bool copyBlocks(Report& report, CopyTarget& target, CopySource& source); diff --git a/src/util/externalcommand.cpp b/src/util/externalcommand.cpp index 744af8d..75e9308 100644 --- a/src/util/externalcommand.cpp +++ b/src/util/externalcommand.cpp @@ -159,15 +159,13 @@ bool ExternalCommand::copyBlocks(const CopySource& source, CopyTarget& target) bool rval = true; const qint64 blockSize = 10 * 1024 * 1024; // number of bytes per block to copy - // TODO KF6:Use new signal-slot syntax - // FIXME: port and reenable these signals - //connect(m_job, SIGNAL(percent(KJob*, unsigned long)), this, SLOT(emitProgress(KJob*, unsigned long))); - //connect(m_job, &KAuth::ExecuteJob::newData, this, &ExternalCommand::emitReport); - auto interface = helperInterface(); if (!interface) return false; + connect(interface, &OrgKdeKpmcoreExternalcommandInterface::progress, this, &ExternalCommand::progress); + connect(interface, &OrgKdeKpmcoreExternalcommandInterface::report, this, &ExternalCommand::reportSignal); + QDBusPendingCall pcall = interface->CopyBlocks(source.path(), source.firstByte(), source.length(), target.path(), target.firstByte(), blockSize); diff --git a/src/util/externalcommand.h b/src/util/externalcommand.h index 05f7dc1..2b3d044 100644 --- a/src/util/externalcommand.h +++ b/src/util/externalcommand.h @@ -89,8 +89,6 @@ public: /**< @return pointer to the Report or nullptr */ Report* report(); - void emitReport(const QVariantMap& report) { Q_EMIT reportSignal(report); } - /**< Sets a parent widget for the authentication dialog. * @param p parent widget */ @@ -100,10 +98,7 @@ public: Q_SIGNALS: void progress(int); - void reportSignal(const QVariantMap&); - -public Q_SLOTS: - void emitProgress(KJob*, unsigned long percent) { Q_EMIT progress(percent); } + void reportSignal(const QString&); private: void setExitCode(int i); diff --git a/src/util/externalcommandhelper.cpp b/src/util/externalcommandhelper.cpp index 026a07d..9c68226 100644 --- a/src/util/externalcommandhelper.cpp +++ b/src/util/externalcommandhelper.cpp @@ -41,7 +41,7 @@ ExternalCommandHelper::ExternalCommandHelper() { - if (!QDBusConnection::systemBus().registerObject(QStringLiteral("/Helper"), this, QDBusConnection::ExportAllSlots)) { + if (!QDBusConnection::systemBus().registerObject(QStringLiteral("/Helper"), this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals)) { ::exit(-1); } @@ -183,13 +183,10 @@ QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const timer.start(); - QVariantMap report; - - report[QStringLiteral("report")] = xi18nc("@info:progress", "Copying %1 blocks (%2 bytes) from %3 to %4, direction: %5.", blocksToCopy, + QString reportText = xi18nc("@info:progress", "Copying %1 blocks (%2 bytes) from %3 to %4, direction: %5.", blocksToCopy, sourceLength, readOffset, writeOffset, copyDirection == 1 ? i18nc("direction: left", "left") : i18nc("direction: right", "right")); - - //HelperSupport::progressStep(report); + Q_EMIT report(reportText); bool rval = true; @@ -208,10 +205,10 @@ QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const if (percent % 5 == 0 && timer.elapsed() > 1000) { const qint64 mibsPerSec = (blocksCopied * blockSize / 1024 / 1024) / (timer.elapsed() / 1000); const qint64 estSecsLeft = (100 - percent) * timer.elapsed() / percent / 1000; - report[QStringLiteral("report")]= xi18nc("@info:progress", "Copying %1 MiB/second, estimated time left: %2", mibsPerSec, QTime(0, 0).addSecs(estSecsLeft).toString()); - //HelperSupport::progressStep(report); + reportText = xi18nc("@info:progress", "Copying %1 MiB/second, estimated time left: %2", mibsPerSec, QTime(0, 0).addSecs(estSecsLeft).toString()); + Q_EMIT report(reportText); } - //HelperSupport::progressStep(percent); + Q_EMIT progress(percent); } } @@ -221,8 +218,8 @@ QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const const qint64 lastBlockReadOffset = copyDirection > 0 ? readOffset + blockSize * blocksCopied : sourceFirstByte; const qint64 lastBlockWriteOffset = copyDirection > 0 ? writeOffset + blockSize * blocksCopied : targetFirstByte; - report[QStringLiteral("report")]= xi18nc("@info:progress", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset); - //HelperSupport::progressStep(report); + reportText = xi18nc("@info:progress", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset); + Q_EMIT report(reportText); rval = readData(sourceDevice, buffer, lastBlockReadOffset, lastBlock); if (rval) { @@ -233,13 +230,13 @@ QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const } if (rval) { - //HelperSupport::progressStep(100); + Q_EMIT progress(100); bytesWritten += buffer.size(); } } - report[QStringLiteral("report")] = xi18ncp("@info:progress argument 2 is a string such as 7 bytes (localized accordingly)", "Copying 1 block (%2) finished.", "Copying %1 blocks (%2) finished.", blocksCopied, i18np("1 byte", "%1 bytes", bytesWritten)); - //HelperSupport::progressStep(report); + reportText = xi18ncp("@info:progress argument 2 is a string such as 7 bytes (localized accordingly)", "Copying 1 block (%2) finished.", "Copying %1 blocks (%2) finished.", blocksCopied, i18np("1 byte", "%1 bytes", bytesWritten)); + Q_EMIT report(reportText); reply[QStringLiteral("success")] = rval; return reply; diff --git a/src/util/externalcommandhelper.h b/src/util/externalcommandhelper.h index a71923f..c86a8d6 100644 --- a/src/util/externalcommandhelper.h +++ b/src/util/externalcommandhelper.h @@ -27,8 +27,8 @@ class ExternalCommandHelper : public QObject, public QDBusContext Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand") Q_SIGNALS: - void progress(int); - void quit(); + Q_SCRIPTABLE void progress(int); + Q_SCRIPTABLE void report(QString); public: ExternalCommandHelper();