Commit 268ad34f authored by Elvis Angelaccio's avatar Elvis Angelaccio

Make jobs parent-less

KJobs autodelete themselves using deleteLater(), when they are done.
So there is no reason to have them as children of Archive.

This fixes a crash when canceling a ListJob with header-encrypted archives
(see task T2225).

Differential Revision: D1525
parent a8425817
......@@ -103,7 +103,7 @@ QList<ArchiveEntry> JobsTest::listEntries(JSONArchiveInterface *iface)
{
m_entries.clear();
ListJob *listJob = new ListJob(iface, this);
ListJob *listJob = new ListJob(iface);
connect(listJob, &Job::newEntry,
this, &JobsTest::slotNewEntry);
......@@ -189,7 +189,7 @@ void JobsTest::testListJob()
JSONArchiveInterface *iface = createArchiveInterface(jsonArchive);
QVERIFY(iface);
ListJob *listJob = new ListJob(iface, this);
ListJob *listJob = new ListJob(iface);
listJob->setAutoDelete(false);
startAndWaitForResult(listJob);
......@@ -217,7 +217,7 @@ void JobsTest::testListJob()
void JobsTest::testExtractJobAccessors()
{
JSONArchiveInterface *iface = createArchiveInterface(QFINDTESTDATA("data/archive001.json"));
ExtractJob *job = new ExtractJob(QVariantList(), QStringLiteral("/tmp/some-dir"), ExtractionOptions(), iface, this);
ExtractJob *job = new ExtractJob(QVariantList(), QStringLiteral("/tmp/some-dir"), ExtractionOptions(), iface);
ExtractionOptions defaultOptions;
defaultOptions[QStringLiteral("PreservePaths")] = false;
......@@ -229,13 +229,14 @@ void JobsTest::testExtractJobAccessors()
QCOMPARE(job->destinationDirectory(), QLatin1String("/tmp/some-dir"));
QCOMPARE(job->extractionOptions(), defaultOptions);
delete job;
ExtractionOptions options;
options[QStringLiteral("PreservePaths")] = true;
options[QStringLiteral("foo")] = QLatin1String("bar");
options[QStringLiteral("pi")] = 3.14f;
job = new ExtractJob(QVariantList(), QStringLiteral("/root"), options, iface, this);
job = new ExtractJob(QVariantList(), QStringLiteral("/root"), options, iface);
QCOMPARE(job->destinationDirectory(), QLatin1String("/root"));
QCOMPARE(job->extractionOptions(), options);
......@@ -245,6 +246,7 @@ void JobsTest::testExtractJobAccessors()
QCOMPARE(job->destinationDirectory(), QLatin1String("/root"));
QCOMPARE(job->extractionOptions(), options);
delete job;
}
void JobsTest::testRemoveEntries_data()
......@@ -283,7 +285,7 @@ void JobsTest::testRemoveEntries()
}
}
DeleteJob *deleteJob = new DeleteJob(entriesToDelete, iface, this);
DeleteJob *deleteJob = new DeleteJob(entriesToDelete, iface);
startAndWaitForResult(deleteJob);
auto remainingEntries = listEntries(iface);
......@@ -327,7 +329,7 @@ void JobsTest::testAddEntries()
QCOMPARE(currentEntries.size(), originalEntries.size());
QFETCH(QStringList, entriesToAdd);
AddJob *addJob = new AddJob(entriesToAdd, CompressionOptions(), iface, this);
AddJob *addJob = new AddJob(entriesToAdd, CompressionOptions(), iface);
startAndWaitForResult(addJob);
currentEntries = listEntries(iface);
......
......@@ -177,7 +177,7 @@ CommentJob* Archive::addComment(const QString &comment)
qCDebug(ARK) << "Going to add comment:" << comment;
Q_ASSERT(!isReadOnly());
CommentJob *job = new CommentJob(comment, static_cast<ReadWriteArchiveInterface*>(m_iface), this);
CommentJob *job = new CommentJob(comment, static_cast<ReadWriteArchiveInterface*>(m_iface));
return job;
}
......@@ -189,7 +189,7 @@ TestJob* Archive::testArchive()
qCDebug(ARK) << "Going to test archive";
TestJob *job = new TestJob(m_iface, this);
TestJob *job = new TestJob(m_iface);
return job;
}
......@@ -298,7 +298,7 @@ ListJob* Archive::list()
qCDebug(ARK) << "Going to list files";
ListJob *job = new ListJob(m_iface, this);
ListJob *job = new ListJob(m_iface);
//if this job has not been listed before, we grab the opportunity to
//collect some information about the archive
......@@ -319,7 +319,7 @@ DeleteJob* Archive::deleteFiles(const QList<QVariant> & files)
if (m_iface->isReadOnly()) {
return 0;
}
DeleteJob *newJob = new DeleteJob(files, static_cast<ReadWriteArchiveInterface*>(m_iface), this);
DeleteJob *newJob = new DeleteJob(files, static_cast<ReadWriteArchiveInterface*>(m_iface));
return newJob;
}
......@@ -337,7 +337,8 @@ AddJob* Archive::addFiles(const QStringList & files, const CompressionOptions& o
qCDebug(ARK) << "Going to add files" << files << "with options" << newOptions;
Q_ASSERT(!m_iface->isReadOnly());
AddJob *newJob = new AddJob(files, newOptions, static_cast<ReadWriteArchiveInterface*>(m_iface), this);
AddJob *newJob = new AddJob(files, newOptions, static_cast<ReadWriteArchiveInterface*>(m_iface));
connect(newJob, &AddJob::result, this, &Archive::onAddFinished);
return newJob;
}
......@@ -353,7 +354,7 @@ ExtractJob* Archive::copyFiles(const QList<QVariant>& files, const QString& dest
newOptions[QStringLiteral( "PasswordProtectedHint" )] = true;
}
ExtractJob *newJob = new ExtractJob(files, destinationDir, newOptions, m_iface, this);
ExtractJob *newJob = new ExtractJob(files, destinationDir, newOptions, m_iface);
return newJob;
}
......
......@@ -70,8 +70,8 @@ void Job::Private::run()
#endif
}
Job::Job(ReadOnlyArchiveInterface *interface, QObject *parent)
: KJob(parent)
Job::Job(ReadOnlyArchiveInterface *interface)
: KJob()
, m_archiveInterface(interface)
, m_isRunning(false)
, d(new Private(this))
......@@ -192,8 +192,8 @@ bool Job::doKill()
return ret;
}
ListJob::ListJob(ReadOnlyArchiveInterface *interface, QObject *parent)
: Job(interface, parent)
ListJob::ListJob(ReadOnlyArchiveInterface *interface)
: Job(interface)
, m_isSingleFolderArchive(true)
, m_isPasswordProtected(false)
, m_extractedFilesSize(0)
......@@ -271,8 +271,8 @@ QString ListJob::subfolderName() const
return m_subfolderName;
}
ExtractJob::ExtractJob(const QVariantList& files, const QString& destinationDir, const ExtractionOptions& options, ReadOnlyArchiveInterface *interface, QObject *parent)
: Job(interface, parent)
ExtractJob::ExtractJob(const QVariantList& files, const QString& destinationDir, const ExtractionOptions& options, ReadOnlyArchiveInterface *interface)
: Job(interface)
, m_files(files)
, m_destinationDir(destinationDir)
, m_options(options)
......@@ -336,8 +336,8 @@ ExtractionOptions ExtractJob::extractionOptions() const
return m_options;
}
AddJob::AddJob(const QStringList& files, const CompressionOptions& options , ReadWriteArchiveInterface *interface, QObject *parent)
: Job(interface, parent)
AddJob::AddJob(const QStringList& files, const CompressionOptions& options , ReadWriteArchiveInterface *interface)
: Job(interface)
, m_files(files)
, m_options(options)
{
......@@ -394,8 +394,8 @@ void AddJob::onFinished(bool result)
Job::onFinished(result);
}
DeleteJob::DeleteJob(const QVariantList& files, ReadWriteArchiveInterface *interface, QObject *parent)
: Job(interface, parent)
DeleteJob::DeleteJob(const QVariantList& files, ReadWriteArchiveInterface *interface)
: Job(interface)
, m_files(files)
{
}
......@@ -417,8 +417,8 @@ void DeleteJob::doWork()
}
}
CommentJob::CommentJob(const QString& comment, ReadWriteArchiveInterface *interface, QObject *parent)
: Job(interface, parent)
CommentJob::CommentJob(const QString& comment, ReadWriteArchiveInterface *interface)
: Job(interface)
, m_comment(comment)
{
}
......@@ -440,8 +440,8 @@ void CommentJob::doWork()
}
}
TestJob::TestJob(ReadOnlyArchiveInterface *interface, QObject *parent)
: Job(interface, parent)
TestJob::TestJob(ReadOnlyArchiveInterface *interface)
: Job(interface)
{
m_testSuccess = false;
}
......
......@@ -52,7 +52,7 @@ public:
bool isRunning() const;
protected:
Job(ReadOnlyArchiveInterface *interface, QObject *parent = 0);
Job(ReadOnlyArchiveInterface *interface);
virtual ~Job();
virtual bool doKill();
virtual void emitResult();
......@@ -95,7 +95,7 @@ class KERFUFFLE_EXPORT ListJob : public Job
Q_OBJECT
public:
explicit ListJob(ReadOnlyArchiveInterface *interface, QObject *parent = 0);
explicit ListJob(ReadOnlyArchiveInterface *interface);
qlonglong extractedFilesSize() const;
bool isPasswordProtected() const;
......@@ -123,7 +123,7 @@ class KERFUFFLE_EXPORT ExtractJob : public Job
Q_OBJECT
public:
ExtractJob(const QVariantList& files, const QString& destinationDir, const ExtractionOptions& options, ReadOnlyArchiveInterface *interface, QObject *parent = 0);
ExtractJob(const QVariantList& files, const QString& destinationDir, const ExtractionOptions& options, ReadOnlyArchiveInterface *interface);
QString destinationDirectory() const;
ExtractionOptions extractionOptions() const;
......@@ -145,7 +145,7 @@ class KERFUFFLE_EXPORT AddJob : public Job
Q_OBJECT
public:
AddJob(const QStringList& files, const CompressionOptions& options, ReadWriteArchiveInterface *interface, QObject *parent = 0);
AddJob(const QStringList& files, const CompressionOptions& options, ReadWriteArchiveInterface *interface);
public slots:
virtual void doWork() Q_DECL_OVERRIDE;
......@@ -164,7 +164,7 @@ class KERFUFFLE_EXPORT DeleteJob : public Job
Q_OBJECT
public:
DeleteJob(const QVariantList& files, ReadWriteArchiveInterface *interface, QObject *parent = 0);
DeleteJob(const QVariantList& files, ReadWriteArchiveInterface *interface);
public slots:
virtual void doWork() Q_DECL_OVERRIDE;
......@@ -178,7 +178,7 @@ class KERFUFFLE_EXPORT CommentJob : public Job
Q_OBJECT
public:
CommentJob(const QString& comment, ReadWriteArchiveInterface *interface, QObject *parent = 0);
CommentJob(const QString& comment, ReadWriteArchiveInterface *interface);
public slots:
virtual void doWork() Q_DECL_OVERRIDE;
......@@ -192,7 +192,7 @@ class KERFUFFLE_EXPORT TestJob : public Job
Q_OBJECT
public:
TestJob(ReadOnlyArchiveInterface *interface, QObject *parent = 0);
TestJob(ReadOnlyArchiveInterface *interface);
bool testSucceeded();
public slots:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment