externalcommandhelper: Make copy direction an enum.
This commit is contained in:
parent
d16d9e8019
commit
32d146eed3
|
@ -166,15 +166,26 @@ QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const
|
||||||
QVariantMap reply;
|
QVariantMap reply;
|
||||||
reply[QStringLiteral("success")] = true;
|
reply[QStringLiteral("success")] = true;
|
||||||
|
|
||||||
|
// This enum specified whether individual blocks are moved left or right
|
||||||
|
// When partition is moved to the left, we start with the leftmost block,
|
||||||
|
// and move it further left, then second leftmost block and so on.
|
||||||
|
// But when we move partition to the right, we start with rightmost block.
|
||||||
|
// To account for this difference, we introduce CopyDirection variable which takes
|
||||||
|
// care of some of the differences between these two cases.
|
||||||
|
enum CopyDirection : qint8 {
|
||||||
|
Left = 1,
|
||||||
|
Right = -1,
|
||||||
|
};
|
||||||
|
|
||||||
const qint64 blocksToCopy = sourceLength / blockSize;
|
const qint64 blocksToCopy = sourceLength / blockSize;
|
||||||
qint64 readOffset = sourceFirstByte;
|
qint64 readOffset = sourceFirstByte;
|
||||||
qint64 writeOffset = targetFirstByte;
|
qint64 writeOffset = targetFirstByte;
|
||||||
qint32 copyDirection = 1;
|
qint8 copyDirection = CopyDirection::Left;
|
||||||
|
|
||||||
if (targetFirstByte > sourceFirstByte) {
|
if (targetFirstByte > sourceFirstByte) {
|
||||||
readOffset = sourceFirstByte + sourceLength - blockSize;
|
readOffset = sourceFirstByte + sourceLength - blockSize;
|
||||||
writeOffset = targetFirstByte + sourceLength - blockSize;
|
writeOffset = targetFirstByte + sourceLength - blockSize;
|
||||||
copyDirection = -1;
|
copyDirection = CopyDirection::Right;
|
||||||
}
|
}
|
||||||
|
|
||||||
const qint64 lastBlock = sourceLength % blockSize;
|
const qint64 lastBlock = sourceLength % blockSize;
|
||||||
|
@ -189,7 +200,7 @@ QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
QString reportText = 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")
|
sourceLength, readOffset, writeOffset, copyDirection == CopyDirection::Left ? i18nc("direction: left", "left")
|
||||||
: i18nc("direction: right", "right"));
|
: i18nc("direction: right", "right"));
|
||||||
Q_EMIT report(reportText);
|
Q_EMIT report(reportText);
|
||||||
|
|
||||||
|
@ -221,8 +232,8 @@ QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const
|
||||||
if (rval && lastBlock > 0) {
|
if (rval && lastBlock > 0) {
|
||||||
Q_ASSERT(lastBlock < blockSize);
|
Q_ASSERT(lastBlock < blockSize);
|
||||||
|
|
||||||
const qint64 lastBlockReadOffset = copyDirection > 0 ? readOffset + blockSize * blocksCopied : sourceFirstByte;
|
const qint64 lastBlockReadOffset = copyDirection == CopyDirection::Left ? readOffset + blockSize * blocksCopied : sourceFirstByte;
|
||||||
const qint64 lastBlockWriteOffset = copyDirection > 0 ? writeOffset + blockSize * blocksCopied : targetFirstByte;
|
const qint64 lastBlockWriteOffset = copyDirection == CopyDirection::Left ? writeOffset + blockSize * blocksCopied : targetFirstByte;
|
||||||
reportText = xi18nc("@info:progress", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset);
|
reportText = xi18nc("@info:progress", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset);
|
||||||
Q_EMIT report(reportText);
|
Q_EMIT report(reportText);
|
||||||
rval = readData(sourceDevice, buffer, lastBlockReadOffset, lastBlock);
|
rval = readData(sourceDevice, buffer, lastBlockReadOffset, lastBlock);
|
||||||
|
|
|
@ -42,7 +42,6 @@ public Q_SLOTS:
|
||||||
Q_SCRIPTABLE bool CreateFile(const QString& filePath, const QByteArray& fileContents);
|
Q_SCRIPTABLE bool CreateFile(const QString& filePath, const QByteArray& fileContents);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool isCallerAuthorized();
|
bool isCallerAuthorized();
|
||||||
|
|
||||||
void onReadOutput();
|
void onReadOutput();
|
||||||
|
|
Loading…
Reference in New Issue