void TransmissionChecksumValidator::uploadValidation() { const QString csType = checksumType(); if( csType.isEmpty() ) { // if there is no checksum defined, continue to upload emit validated(QByteArray()); } else { // Calculate the checksum in a different thread first. connect( &_watcher, SIGNAL(finished()), this, SLOT(slotUploadChecksumCalculated())); if( csType == checkSumMD5C ) { _checksumHeader = checkSumMD5C; _checksumHeader += ":"; _watcher.setFuture(QtConcurrent::run(FileSystem::calcMd5, _filePath)); } else if( csType == checkSumSHA1C ) { _checksumHeader = checkSumSHA1C; _checksumHeader += ":"; _watcher.setFuture(QtConcurrent::run( FileSystem::calcSha1, _filePath)); } #ifdef ZLIB_FOUND else if( csType == checkSumAdlerC) { _checksumHeader = checkSumAdlerC; _checksumHeader += ":"; _watcher.setFuture(QtConcurrent::run(FileSystem::calcAdler32, _filePath)); } #endif else { // for an unknown checksum, continue to upload emit validated(QByteArray()); } } }
void ComputeChecksum::start(const QString& filePath) { const QString csType = checksumType(); // Calculate the checksum in a different thread first. connect( &_watcher, SIGNAL(finished()), this, SLOT(slotCalculationDone()), Qt::UniqueConnection ); if( csType == checkSumMD5C ) { _watcher.setFuture(QtConcurrent::run(FileSystem::calcMd5, filePath)); } else if( csType == checkSumSHA1C ) { _watcher.setFuture(QtConcurrent::run( FileSystem::calcSha1, filePath)); } #ifdef ZLIB_FOUND else if( csType == checkSumAdlerC) { _watcher.setFuture(QtConcurrent::run(FileSystem::calcAdler32, filePath)); } #endif else { // for an unknown checksum or no checksum, we're done right now if( !csType.isEmpty() ) { qDebug() << "Unknown checksum type:" << csType; } emit done(QByteArray(), QByteArray()); } }
void ComputeChecksum::start(const QString& filePath) { // Calculate the checksum in a different thread first. connect( &_watcher, SIGNAL(finished()), this, SLOT(slotCalculationDone()), Qt::UniqueConnection ); _watcher.setFuture(QtConcurrent::run(ComputeChecksum::computeNow, filePath, checksumType())); }
void TransmissionChecksumValidator::downloadValidation( const QByteArray& checksumHeader ) { // if the incoming header is empty, there was no checksum header, and // no validation can happen. Just continue. const QString csType = checksumType(); // for empty checksum type, everything is valid. if( csType.isEmpty() ) { emit validated(QByteArray()); return; } int indx = checksumHeader.indexOf(':'); if( indx < 0 ) { qDebug() << "Checksum header malformed:" << checksumHeader; emit validationFailed(tr("The checksum header is malformed.")); // show must go on - even not validated. return; } const QByteArray type = checksumHeader.left(indx).toUpper(); _expectedHash = checksumHeader.mid(indx+1); connect( &_watcher, SIGNAL(finished()), this, SLOT(slotDownloadChecksumCalculated()) ); // start the calculation in different thread if( type == checkSumMD5C ) { _watcher.setFuture(QtConcurrent::run(FileSystem::calcMd5, _filePath)); } else if( type == checkSumSHA1C ) { _watcher.setFuture(QtConcurrent::run(FileSystem::calcSha1, _filePath)); } #ifdef ZLIB_FOUND else if( type == checkSumAdlerUpperC ) { _watcher.setFuture(QtConcurrent::run(FileSystem::calcAdler32, _filePath)); } #endif else { qDebug() << "Unknown checksum type" << type; emit validationFailed(tr("The checksum header is malformed.")); return; } }