Convert copyblocks dbus call to asynchronous call.
This commit is contained in:
parent
97d7076481
commit
4b91f2c07e
|
@ -77,17 +77,27 @@ bool ExternalCommand::copyBlocks()
|
|||
QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"), QStringLiteral("/Helper"), QStringLiteral("org.kde.kpmcore.externalcommand"), QDBusConnection::systemBus());
|
||||
iface.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
||||
if (iface.isValid()) {
|
||||
QDBusReply<QVariantMap> reply = iface.call(QStringLiteral("copyblocks"), CoreBackendManager::self()->Uuid(), m_Source->path(), m_Source->firstByte(), m_Source->length(), m_Target->path(), m_Target->firstByte(), blockSize);
|
||||
if (reply.isValid()) {
|
||||
rval = reply.value()[QStringLiteral("success")].toInt();
|
||||
}
|
||||
else {
|
||||
qWarning() << reply.error().message();
|
||||
}
|
||||
QDBusPendingCall pcall= iface.asyncCall(QStringLiteral("copyblocks"), CoreBackendManager::self()->Uuid(), m_Source->path(), m_Source->firstByte(), m_Source->length(), m_Target->path(), m_Target->firstByte(), blockSize);
|
||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
|
||||
QEventLoop loop;
|
||||
|
||||
auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) {
|
||||
loop.exit();
|
||||
if (watcher->isError()) {
|
||||
qWarning() << watcher->error();
|
||||
}
|
||||
else {
|
||||
QDBusPendingReply<bool> reply = *watcher;
|
||||
rval = reply.argumentAt<0>();
|
||||
}
|
||||
emit finished();
|
||||
setExitCode(!rval);
|
||||
};
|
||||
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop);
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
emit finished();
|
||||
setExitCode(!rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,10 +109,9 @@ bool ExternalCommandHelper::writeData(const QString &targetDevice, const QByteAr
|
|||
return true;
|
||||
}
|
||||
|
||||
QVariantMap ExternalCommandHelper::copyblocks(const QString& Uuid, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize)
|
||||
bool ExternalCommandHelper::copyblocks(const QString& Uuid, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize)
|
||||
{
|
||||
isCallerAuthorized(Uuid);
|
||||
QVariantMap reply;
|
||||
|
||||
const qint64 blocksToCopy = sourceLength / blockSize;
|
||||
qint64 readOffset = sourceFirstByte;
|
||||
|
@ -190,9 +189,7 @@ QVariantMap ExternalCommandHelper::copyblocks(const QString& Uuid, const QString
|
|||
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);
|
||||
|
||||
reply[QStringLiteral("success")] = rval;
|
||||
|
||||
return reply;
|
||||
return rval;
|
||||
}
|
||||
|
||||
QVariantMap ExternalCommandHelper::start(const QString& Uuid, const QString& command, const QStringList& arguments, const QByteArray& input, const QStringList& environment)
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
public Q_SLOTS:
|
||||
ActionReply init(const QVariantMap& args);
|
||||
Q_SCRIPTABLE QVariantMap start(const QString& Uuid, const QString& command, const QStringList& arguments, const QByteArray& input, const QStringList& environment);
|
||||
Q_SCRIPTABLE QVariantMap copyblocks(const QString& Uuid, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize);
|
||||
Q_SCRIPTABLE bool copyblocks(const QString& Uuid, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize);
|
||||
Q_SCRIPTABLE void exit(const QString& Uuid);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue