Commit 8be8fe5b authored by Elvis Angelaccio's avatar Elvis Angelaccio

Fix preview of nested archives

The assumption that a PreviewJob can remove its temp dir when it's done (commit 41b25127)
was wrong, at least with nested archives.
If we remove the extracted file too soon, there is no way to preview a nested archive or,
worse, a "double-nested" archive.

This patch just delays the cleanup to the Part destructor.

Differential Revision: D2265
parent 57854537
......@@ -341,9 +341,9 @@ TempExtractJob::TempExtractJob(const QString &file, bool passwordProtectedHint,
, m_file(file)
, m_passwordProtectedHint(passwordProtectedHint)
{
m_tmpExtractDir = new QTemporaryDir();
}
QString TempExtractJob::validatedFilePath() const
{
QString path = extractionDir() + QLatin1Char('/') + m_file;
......@@ -368,6 +368,11 @@ ExtractionOptions TempExtractJob::extractionOptions() const
return options;
}
QTemporaryDir *TempExtractJob::tempDir() const
{
return m_tmpExtractDir;
}
void TempExtractJob::doWork()
{
emit description(this, i18n("Extracting one file"));
......@@ -383,33 +388,21 @@ void TempExtractJob::doWork()
}
}
PreviewJob::PreviewJob(const QString& file, bool passwordProtectedHint, ReadOnlyArchiveInterface *interface)
: TempExtractJob(file, passwordProtectedHint, interface)
QString TempExtractJob::extractionDir() const
{
qCDebug(ARK) << "PreviewJob started";
return m_tmpExtractDir->path();
}
QString PreviewJob::extractionDir() const
PreviewJob::PreviewJob(const QString& file, bool passwordProtectedHint, ReadOnlyArchiveInterface *interface)
: TempExtractJob(file, passwordProtectedHint, interface)
{
return m_tmpExtractDir.path();
qCDebug(ARK) << "PreviewJob started";
}
OpenJob::OpenJob(const QString& file, bool passwordProtectedHint, ReadOnlyArchiveInterface *interface)
: TempExtractJob(file, passwordProtectedHint, interface)
{
qCDebug(ARK) << "OpenJob started";
m_tmpExtractDir = new QTemporaryDir();
}
QTemporaryDir *OpenJob::tempDir() const
{
return m_tmpExtractDir;
}
QString OpenJob::extractionDir() const
{
return m_tmpExtractDir->path();
}
OpenWithJob::OpenWithJob(const QString& file, bool passwordProtectedHint, ReadOnlyArchiveInterface *interface)
......
......@@ -159,13 +159,20 @@ public:
ExtractionOptions extractionOptions() const;
/**
* @return The temporary dir used for the extraction.
* It is safe to delete this pointer in order to remove the directory.
*/
QTemporaryDir *tempDir() const;
public slots:
virtual void doWork() Q_DECL_OVERRIDE;
private:
virtual QString extractionDir() const = 0;
QString extractionDir() const;
QString m_file;
QTemporaryDir *m_tmpExtractDir;
bool m_passwordProtectedHint;
};
......@@ -179,11 +186,6 @@ class KERFUFFLE_EXPORT PreviewJob : public TempExtractJob
public:
PreviewJob(const QString& file, bool passwordProtectedHint, ReadOnlyArchiveInterface *interface);
private:
QString extractionDir() const Q_DECL_OVERRIDE;
QTemporaryDir m_tmpExtractDir;
};
/**
......@@ -196,17 +198,6 @@ class KERFUFFLE_EXPORT OpenJob : public TempExtractJob
public:
OpenJob(const QString& file, bool passwordProtectedHint, ReadOnlyArchiveInterface *interface);
/**
* @return The temporary dir used for the extraction.
* It is safe to delete this pointer in order to remove the directory.
*/
QTemporaryDir *tempDir() const;
private:
QString extractionDir() const Q_DECL_OVERRIDE;
QTemporaryDir *m_tmpExtractDir;
};
class KERFUFFLE_EXPORT OpenWithJob : public OpenJob
......
......@@ -186,7 +186,7 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList& args)
Part::~Part()
{
qDeleteAll(m_tmpOpenDirList);
qDeleteAll(m_tmpExtractDirList);
// Only save splitterSizes if infopanel is visible,
// because we don't want to store zero size for infopanel.
......@@ -919,7 +919,7 @@ void Part::slotOpenExtractedEntry(KJob *job)
// Since the user could modify the file (unlike the Preview case),
// we'll need to manually delete the temp dir in the Part destructor.
m_tmpOpenDirList << openJob->tempDir();
m_tmpExtractDirList << openJob->tempDir();
const QString fullName = openJob->validatedFilePath();
......@@ -957,6 +957,7 @@ void Part::slotPreviewExtractedEntry(KJob *job)
PreviewJob *previewJob = qobject_cast<PreviewJob*>(job);
Q_ASSERT(previewJob);
m_tmpExtractDirList << previewJob->tempDir();
ArkViewer::view(previewJob->validatedFilePath());
} else if (job->error() != KJob::KilledJobError) {
......@@ -971,7 +972,7 @@ void Part::slotWatchedFileModified(const QString& file)
// Find the relative path of the file within the archive.
QString relPath = file;
foreach (QTemporaryDir *tmpDir, m_tmpOpenDirList) {
foreach (QTemporaryDir *tmpDir, m_tmpExtractDirList) {
relPath.remove(tmpDir->path()); //Remove tmpDir.
}
relPath = relPath.mid(1); //Remove leading slash.
......
......@@ -160,7 +160,7 @@ private:
KToggleAction *m_showInfoPanelAction;
InfoPanel *m_infoPanel;
QSplitter *m_splitter;
QList<QTemporaryDir*> m_tmpOpenDirList;
QList<QTemporaryDir*> m_tmpExtractDirList;
bool m_busy;
OpenFileMode m_openFileMode;
QUrl m_lastUsedAddPath;
......
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