Checksums: Use the first supported type if nothing is preferred

This commit is contained in:
Christian Kamm 2016-04-26 13:10:53 +02:00
parent 043350f49d
commit 09eea7f5f2
3 changed files with 19 additions and 1 deletions

View file

@ -95,4 +95,15 @@ QByteArray Capabilities::preferredUploadChecksumType() const
return _capabilities["checksums"].toMap()["preferredUploadType"].toByteArray();
}
QByteArray Capabilities::uploadChecksumType() const
{
QByteArray preferred = preferredUploadChecksumType();
if (!preferred.isEmpty())
return preferred;
QList<QByteArray> supported = supportedChecksumTypes();
if (!supported.isEmpty())
return supported.first();
return QByteArray();
}
}

View file

@ -69,6 +69,13 @@ public:
*/
QByteArray preferredUploadChecksumType() const;
/**
* Helper that returns the preferredUploadChecksumType() if set, or one
* of the supportedChecksumTypes() if it isn't. May return an empty
* QByteArray if no checksum types are supported.
*/
QByteArray uploadChecksumType() const;
private:
QVariantMap _capabilities;
};

View file

@ -261,7 +261,7 @@ void PropagateUploadFileQNAM::slotComputeTransmissionChecksum(const QByteArray&
// Compute the transmission checksum.
auto computeChecksum = new ComputeChecksum(this);
if (uploadChecksumEnabled()) {
computeChecksum->setChecksumType(_propagator->account()->capabilities().preferredUploadChecksumType());
computeChecksum->setChecksumType(_propagator->account()->capabilities().uploadChecksumType());
} else {
computeChecksum->setChecksumType(QByteArray());
}