Make TransmissionChecksumValidator child of the job for auto delete.
authorKlaas Freitag <freitag@owncloud.com>
Wed, 20 May 2015 14:54:04 +0000 (16:54 +0200)
committerKlaas Freitag <freitag@owncloud.com>
Wed, 20 May 2015 14:54:04 +0000 (16:54 +0200)
That way no explicit memory management is needed as the allocation
is freed when the job (parent) is deleted automatically.

src/libsync/propagatedownload.cpp
src/libsync/propagatedownload.h
src/libsync/propagateupload.cpp
src/libsync/propagateupload.h

index fc943d0fc09bd7e3f4168c122a0f508ae497ebe5..aa30a3ac5738e9a5779d2625aa03c7dc48f1a98d 100644 (file)
@@ -489,16 +489,15 @@ void PropagateDownloadFileQNAM::slotGetFinished()
     // do whatever is needed to add a checksum to the http upload request.
     // in any case, the validator will emit signal startUpload to let the flow
     // continue in slotStartUpload here.
-    _validator = new TransmissionChecksumValidator( _tmpFile.fileName() );
-    connect(_validator, SIGNAL(validated()), this, SLOT(downloadFinished()));
-    connect(_validator, SIGNAL(validationFailed(QString)), this, SLOT(slotChecksumFail(QString)));
-    _validator->downloadValidation(job->reply()->rawHeader(checkSumHeaderC));
+    TransmissionChecksumValidator *validator = new TransmissionChecksumValidator(_tmpFile.fileName(), this);
+    connect(validator, SIGNAL(validated()), this, SLOT(downloadFinished()));
+    connect(validator, SIGNAL(validationFailed(QString)), this, SLOT(slotChecksumFail(QString)));
+    validator->downloadValidation(job->reply()->rawHeader(checkSumHeaderC));
 
 }
 
 void PropagateDownloadFileQNAM::slotChecksumFail( const QString& errMsg )
 {
-    _validator->deleteLater();
     _tmpFile.remove();
     _propagator->_anotherSyncNeeded = true;
     done(SyncFileItem::SoftError, errMsg ); // tr("The file downloaded with a broken checksum, will be redownloaded."));
@@ -527,8 +526,6 @@ QString makeConflictFileName(const QString &fn, const QDateTime &dt)
 
 void PropagateDownloadFileQNAM::downloadFinished()
 {
-    _validator->deleteLater();
-
     QString fn = _propagator->getFilePath(_item._file);
 
     // In case of file name clash, report an error
index 7ec9bd3dbf850cf6eadeb705545e1cf2d6df5bdf..b2cf18c262b4ac1ce703ed41d28f8fdf7619e55b 100644 (file)
@@ -21,8 +21,6 @@
 
 namespace OCC {
 
-class TransmissionChecksumValidator;
-
 class GETFileJob : public AbstractNetworkJob {
     Q_OBJECT
     QFile* _device;
@@ -119,8 +117,6 @@ private:
     // Utility::StopWatch _stopWatch;
     QPointer<GETFileJob> _job;
     QFile _tmpFile;
-    TransmissionChecksumValidator *_validator;
-
 };
 
 }
index 6707b173a5517c5250b1c317b657e6b6354a71ca..f602132a8510ed73ff9a53eca487c42267aadd14 100644 (file)
@@ -211,15 +211,13 @@ void PropagateUploadFileQNAM::start()
     // do whatever is needed to add a checksum to the http upload request.
     // in any case, the validator will emit signal startUpload to let the flow
     // continue in slotStartUpload here.
-    _validator = new TransmissionChecksumValidator(filePath);
-    connect(_validator, SIGNAL(validated()), this, SLOT(slotStartUpload()));
-    _validator->uploadValidation( &_item );
+    TransmissionChecksumValidator *validator = new TransmissionChecksumValidator(filePath, this);
+    connect(validator, SIGNAL(validated()), this, SLOT(slotStartUpload()));
+    validator->uploadValidation( &_item );
 }
 
 void PropagateUploadFileQNAM::slotStartUpload()
 {
-    _validator->deleteLater();
-
     const QString fullFilePath(_propagator->getFilePath(_item._file));
 
     if (!FileSystem::fileExists(fullFilePath)) {
index 7b5e11fd1baab141721e0802c8d82fca33dc714b..3746ff4084ae1ddae52078bf1036e127c318a525 100644 (file)
@@ -23,7 +23,6 @@
 
 namespace OCC {
 class BandwidthManager;
-class TransmissionChecksumValidator;
 
 class UploadDevice : public QIODevice {
     Q_OBJECT
@@ -172,8 +171,6 @@ private:
     // measure the performance of checksum calc and upload
     Utility::StopWatch _stopWatch;
 
-    TransmissionChecksumValidator *_validator;
-
 public:
     PropagateUploadFileQNAM(OwncloudPropagator* propagator,const SyncFileItem& item)
         : PropagateItemJob(propagator, item), _startChunk(0), _currentChunk(0), _chunkCount(0), _transferId(0), _finished(false) {}