{
}
+ComputeChecksum::~ComputeChecksum()
+{
+}
+
void ComputeChecksum::setChecksumType(const QByteArray &type)
{
_checksumType = type;
void ComputeChecksum::start(const QString &filePath)
{
qCInfo(lcChecksums) << "Computing" << checksumType() << "checksum of" << filePath << "in a thread";
- _file = new QFile(filePath, this);
+ _file.reset(new QFile(filePath));
if (!_file->open(QIODevice::ReadOnly)) {
qCWarning(lcChecksums) << "Could not open file" << filePath << "for reading to compute a checksum" << _file->errorString();
emit done(QByteArray(), QByteArray());
return;
}
- start(_file);
+ start(_file.get());
}
void ComputeChecksum::start(QIODevice *device)
void ComputeChecksum::slotCalculationDone()
{
// Close the file and delete the instance
- if (_file)
- delete _file;
+ _file.reset(nullptr);
QByteArray checksum = _watcher.future().result();
if (!checksum.isNull()) {
#include <QByteArray>
#include <QFutureWatcher>
+#include <memory>
+
class QFile;
namespace OCC {
Q_OBJECT
public:
explicit ComputeChecksum(QObject *parent = nullptr);
+ ~ComputeChecksum();
/**
* Sets the checksum type to be used. The default is empty.
QByteArray _checksumType;
// The convenience wrapper may open a file and must close it too
- QFile *_file = nullptr;
+ std::unique_ptr<QFile> _file;
// watcher for the checksum calculation thread
QFutureWatcher<QByteArray> _watcher;