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());
|
QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"), QStringLiteral("/Helper"), QStringLiteral("org.kde.kpmcore.externalcommand"), QDBusConnection::systemBus());
|
||||||
iface.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
iface.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
||||||
if (iface.isValid()) {
|
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);
|
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);
|
||||||
if (reply.isValid()) {
|
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
|
||||||
rval = reply.value()[QStringLiteral("success")].toInt();
|
QEventLoop loop;
|
||||||
}
|
|
||||||
else {
|
auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) {
|
||||||
qWarning() << reply.error().message();
|
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;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,10 +109,9 @@ bool ExternalCommandHelper::writeData(const QString &targetDevice, const QByteAr
|
||||||
return true;
|
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);
|
isCallerAuthorized(Uuid);
|
||||||
QVariantMap reply;
|
|
||||||
|
|
||||||
const qint64 blocksToCopy = sourceLength / blockSize;
|
const qint64 blocksToCopy = sourceLength / blockSize;
|
||||||
qint64 readOffset = sourceFirstByte;
|
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));
|
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);
|
HelperSupport::progressStep(report);
|
||||||
|
|
||||||
reply[QStringLiteral("success")] = rval;
|
return rval;
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap ExternalCommandHelper::start(const QString& Uuid, const QString& command, const QStringList& arguments, const QByteArray& input, const QStringList& environment)
|
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:
|
public Q_SLOTS:
|
||||||
ActionReply init(const QVariantMap& args);
|
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 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);
|
Q_SCRIPTABLE void exit(const QString& Uuid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue