Fix signals between helper and client.

This commit is contained in:
Andrius Štikonas 2020-10-11 23:46:20 +01:00
parent cd4d9b1985
commit 6cff70567b
6 changed files with 20 additions and 30 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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();