summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-15 17:06:46 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-15 17:11:37 (GMT)
commit89a7b5bbb52ee6acac620b50efea419446795e82 (patch)
tree42123d734ad502daab742889c1e05170c1060ca3
parent377dfcfebdd6bd3cafcc1497182efd0660273503 (diff)
Turn extraction/compression options into classes
Currently CompressionOptions and ExtractionOprions are both QHash typedefs, which means they are the same thing for the compiler. Currently we even pass CompressionOptions objects where ExtractionOptions objects are expected. Both types are changed into proper classes, so that the compiler can detect this class of bugs. While at it: - The default value for the `PreservePaths` option was false, now is true because it's the more common case. - The `RemoveRootNode` option was redundant, it was only used together with the `DragAndDrop` one. - The `FollowExtractionDialogSettings` was only set but never read, so we can drop it. Differential Revision: D3039 Task: T2137
-rw-r--r--autotests/kerfuffle/adddialogtest.cpp4
-rw-r--r--autotests/kerfuffle/addtest.cpp4
-rw-r--r--autotests/kerfuffle/copytest.cpp4
-rw-r--r--autotests/kerfuffle/extracttest.cpp33
-rw-r--r--autotests/kerfuffle/jobstest.cpp17
-rw-r--r--autotests/kerfuffle/jsonarchiveinterface.cpp2
-rw-r--r--autotests/kerfuffle/movetest.cpp2
-rw-r--r--autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp22
-rw-r--r--kerfuffle/CMakeLists.txt1
-rw-r--r--kerfuffle/adddialog.h2
-rw-r--r--kerfuffle/addtoarchive.cpp2
-rw-r--r--kerfuffle/archive_kerfuffle.cpp18
-rw-r--r--kerfuffle/archive_kerfuffle.h12
-rw-r--r--kerfuffle/archiveinterface.h2
-rw-r--r--kerfuffle/cliinterface.cpp36
-rw-r--r--kerfuffle/cliinterface.h2
-rw-r--r--kerfuffle/compressionoptionswidget.cpp21
-rw-r--r--kerfuffle/compressionoptionswidget.h2
-rw-r--r--kerfuffle/jobs.cpp27
-rw-r--r--kerfuffle/jobs.h2
-rw-r--r--kerfuffle/options.cpp148
-rw-r--r--kerfuffle/options.h110
-rw-r--r--part/part.cpp70
-rw-r--r--part/part.h1
-rw-r--r--plugins/cliunarchiverplugin/cliplugin.cpp2
-rw-r--r--plugins/clizipplugin/cliplugin.cpp2
-rw-r--r--plugins/libarchive/libarchiveplugin.cpp4
-rw-r--r--plugins/libarchive/readwritelibarchiveplugin.cpp6
28 files changed, 371 insertions, 187 deletions
diff --git a/autotests/kerfuffle/adddialogtest.cpp b/autotests/kerfuffle/adddialogtest.cpp
index 16681c5..bb09862 100644
--- a/autotests/kerfuffle/adddialogtest.cpp
+++ b/autotests/kerfuffle/adddialogtest.cpp
@@ -144,12 +144,12 @@ void AddDialogTest::testBasicWidgets()
if (supportsCompLevel) {
// Test that the value set by slider is exported from AddDialog.
- QCOMPARE(dialog->compressionOptions()[QStringLiteral("CompressionLevel")].toInt(), changeToCompLevel);
+ QCOMPARE(dialog->compressionOptions().compressionLevel(), changeToCompLevel);
}
// Test that passing a compression level in ctor works.
CompressionOptions opts;
- opts[QStringLiteral("CompressionLevel")] = initialCompLevel;
+ opts.setCompressionLevel(initialCompLevel);
dialog = new AddDialog(Q_NULLPTR, QString(), QUrl(), mime, opts);
dialog->slotOpenOptions();
diff --git a/autotests/kerfuffle/addtest.cpp b/autotests/kerfuffle/addtest.cpp
index 0dad849..7c4c949 100644
--- a/autotests/kerfuffle/addtest.cpp
+++ b/autotests/kerfuffle/addtest.cpp
@@ -124,8 +124,8 @@ void AddTest::testAdding()
QVector<Archive::Entry*> oldEntries = TestHelper::getEntryList(archive);
- CompressionOptions options = CompressionOptions();
- options.insert(QStringLiteral("GlobalWorkDir"), QFINDTESTDATA("data"));
+ CompressionOptions options;
+ options.setGlobalWorkDir(QFINDTESTDATA("data"));
AddJob *addJob = archive->addFiles(files, destination, options);
TestHelper::startAndWaitForResult(addJob);
diff --git a/autotests/kerfuffle/copytest.cpp b/autotests/kerfuffle/copytest.cpp
index 103c375..f9a8a7b 100644
--- a/autotests/kerfuffle/copytest.cpp
+++ b/autotests/kerfuffle/copytest.cpp
@@ -193,8 +193,8 @@ void CopyTest::testCopying()
const QVector<Archive::Entry*> oldEntries = TestHelper::getEntryList(archive);
- CompressionOptions options = CompressionOptions();
- options.insert(QStringLiteral("GlobalWorkDir"), QFINDTESTDATA("data"));
+ CompressionOptions options;
+ options.setGlobalWorkDir(QFINDTESTDATA("data"));
CopyJob *copyJob = archive->copyFiles(files, destination, options);
TestHelper::startAndWaitForResult(copyJob);
diff --git a/autotests/kerfuffle/extracttest.cpp b/autotests/kerfuffle/extracttest.cpp
index 0827fc0..4469bfb 100644
--- a/autotests/kerfuffle/extracttest.cpp
+++ b/autotests/kerfuffle/extracttest.cpp
@@ -249,11 +249,12 @@ void ExtractTest::testExtraction_data()
QTest::addColumn<int>("expectedExtractedEntriesCount");
ExtractionOptions optionsPreservePaths;
- optionsPreservePaths[QStringLiteral("PreservePaths")] = true;
- ExtractionOptions dragAndDropOptions = optionsPreservePaths;
- dragAndDropOptions[QStringLiteral("DragAndDrop")] = true;
- dragAndDropOptions[QStringLiteral("RemoveRootNode")] = true;
+ ExtractionOptions optionsNoPaths;
+ optionsNoPaths.setPreservePaths(false);
+
+ ExtractionOptions dragAndDropOptions;
+ dragAndDropOptions.setDragAndDropEnabled(true);
QString archivePath = QFINDTESTDATA("data/simplearchive.tar.gz");
QTest::newRow("extract the whole simplearchive.tar.gz")
@@ -269,7 +270,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("aDir/b.txt"), QStringLiteral("aDir")),
new Archive::Entry(this, QStringLiteral("c.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.tar.gz");
@@ -306,7 +307,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("A/test2.txt"), QStringLiteral("A")),
new Archive::Entry(this, QStringLiteral("A/B/test1.txt"), QStringLiteral("A/B"))
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/one_toplevel_folder.zip");
@@ -345,7 +346,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("A/test2.txt"), QStringLiteral("A")),
new Archive::Entry(this, QStringLiteral("A/B/test1.txt"), QStringLiteral("A/B"))
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/one_toplevel_folder.7z");
@@ -386,7 +387,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("file3.txt"), QString()),
new Archive::Entry(this, QStringLiteral("dir2/file22.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.tar.bz2");
@@ -403,7 +404,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("file3.txt"), QString()),
new Archive::Entry(this, QStringLiteral("dir2/file22.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.tar.xz");
@@ -420,7 +421,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("file3.txt"), QString()),
new Archive::Entry(this, QStringLiteral("dir2/file22.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.tar.lzma");
@@ -437,7 +438,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("file3.txt"), QString()),
new Archive::Entry(this, QStringLiteral("dir2/file22.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.tar.Z");
@@ -454,7 +455,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("file3.txt"), QString()),
new Archive::Entry(this, QStringLiteral("dir2/file22.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.tar.lz");
@@ -471,7 +472,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("file3.txt"), QString()),
new Archive::Entry(this, QStringLiteral("dir2/file22.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.tar.lzo");
@@ -490,7 +491,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("file3.txt"), QString()),
new Archive::Entry(this, QStringLiteral("dir2/file22.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.tar.lrz");
@@ -512,7 +513,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("file3.txt"), QString()),
new Archive::Entry(this, QStringLiteral("dir2/file22.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.tar.lz4");
@@ -532,7 +533,7 @@ void ExtractTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("dir1/file11.txt"), QString()),
new Archive::Entry(this, QStringLiteral("file4.txt"), QString())
}
- << ExtractionOptions()
+ << optionsNoPaths
<< 2;
archivePath = QFINDTESTDATA("data/simplearchive.xar");
diff --git a/autotests/kerfuffle/jobstest.cpp b/autotests/kerfuffle/jobstest.cpp
index bee53ab..7a748c0 100644
--- a/autotests/kerfuffle/jobstest.cpp
+++ b/autotests/kerfuffle/jobstest.cpp
@@ -219,34 +219,29 @@ void JobsTest::testExtractJobAccessors()
{
JSONArchiveInterface *iface = createArchiveInterface(QFINDTESTDATA("data/archive001.json"));
ExtractJob *job = new ExtractJob(QVector<Archive::Entry*>(), QStringLiteral("/tmp/some-dir"), ExtractionOptions(), iface);
- ExtractionOptions defaultOptions;
- defaultOptions[QStringLiteral("PreservePaths")] = false;
QCOMPARE(job->destinationDirectory(), QLatin1String("/tmp/some-dir"));
- QCOMPARE(job->extractionOptions(), defaultOptions);
+ QVERIFY(job->extractionOptions().preservePaths());
job->setAutoDelete(false);
startAndWaitForResult(job);
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;
+ options.setPreservePaths(false);
job = new ExtractJob(QVector<Archive::Entry*>(), QStringLiteral("/root"), options, iface);
QCOMPARE(job->destinationDirectory(), QLatin1String("/root"));
- QCOMPARE(job->extractionOptions(), options);
+ QVERIFY(!job->extractionOptions().preservePaths());
job->setAutoDelete(false);
startAndWaitForResult(job);
QCOMPARE(job->destinationDirectory(), QLatin1String("/root"));
- QCOMPARE(job->extractionOptions(), options);
+ QVERIFY(!job->extractionOptions().preservePaths());
delete job;
}
@@ -258,13 +253,13 @@ void JobsTest::testTempExtractJob()
const QString tempDirPath = job->tempDir()->path();
QVERIFY(QFileInfo::exists(tempDirPath));
QVERIFY(job->validatedFilePath().endsWith(QLatin1String("anotherDir/file.txt")));
- QVERIFY(job->extractionOptions()[QStringLiteral("PreservePaths")].toBool());
+ QVERIFY(job->extractionOptions().preservePaths());
job->setAutoDelete(false);
startAndWaitForResult(job);
QVERIFY(job->validatedFilePath().endsWith(QLatin1String("anotherDir/file.txt")));
- QVERIFY(job->extractionOptions()[QStringLiteral("PreservePaths")].toBool());
+ QVERIFY(job->extractionOptions().preservePaths());
delete job->tempDir();
QVERIFY(!QFileInfo::exists(tempDirPath));
diff --git a/autotests/kerfuffle/jsonarchiveinterface.cpp b/autotests/kerfuffle/jsonarchiveinterface.cpp
index 89ae6da..4543892 100644
--- a/autotests/kerfuffle/jsonarchiveinterface.cpp
+++ b/autotests/kerfuffle/jsonarchiveinterface.cpp
@@ -83,7 +83,7 @@ bool JSONArchiveInterface::addFiles(const QVector<Kerfuffle::Archive::Entry*>& f
return true;
}
-bool JSONArchiveInterface::moveFiles(const QVector<Kerfuffle::Archive::Entry*>& files, Kerfuffle::Archive::Entry *destination, const Kerfuffle::ExtractionOptions& options)
+bool JSONArchiveInterface::moveFiles(const QVector<Kerfuffle::Archive::Entry*>& files, Kerfuffle::Archive::Entry *destination, const Kerfuffle::CompressionOptions& options)
{
Q_UNUSED(files)
Q_UNUSED(destination)
diff --git a/autotests/kerfuffle/movetest.cpp b/autotests/kerfuffle/movetest.cpp
index 676409a..bd290d0 100644
--- a/autotests/kerfuffle/movetest.cpp
+++ b/autotests/kerfuffle/movetest.cpp
@@ -170,7 +170,7 @@ void MoveTest::testMoving()
QVector<Archive::Entry*> oldEntries = TestHelper::getEntryList(archive);
CompressionOptions options = CompressionOptions();
- options.insert(QStringLiteral("GlobalWorkDir"), QFINDTESTDATA("data"));
+ options.setGlobalWorkDir(QFINDTESTDATA("data"));
MoveJob *moveJob = archive->moveFiles(files, destination, options);
TestHelper::startAndWaitForResult(moveJob);
diff --git a/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp b/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp
index 2d6ed56..de65636 100644
--- a/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp
+++ b/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp
@@ -230,19 +230,19 @@ void CliUnarchiverTest::testExtraction_data()
QTest::addColumn<ExtractionOptions>("extractionOptions");
QTest::addColumn<int>("expectedExtractedEntriesCount");
- ExtractionOptions options;
- options[QStringLiteral("AlwaysUseTmpDir")] = true;
+ ExtractionOptions defaultOptions;
+ defaultOptions.setAlwaysUseTempDir(true);
- ExtractionOptions optionsPreservePaths = options;
- optionsPreservePaths[QStringLiteral("PreservePaths")] = true;
+ ExtractionOptions optionsNoPaths = defaultOptions;
+ optionsNoPaths.setPreservePaths(false);
- ExtractionOptions dragAndDropOptions = optionsPreservePaths;
- dragAndDropOptions[QStringLiteral("DragAndDrop")] = true;
+ ExtractionOptions dragAndDropOptions = defaultOptions;
+ dragAndDropOptions.setDragAndDropEnabled(true);
QTest::newRow("extract the whole multiple_toplevel_entries.rar")
<< QFINDTESTDATA("data/multiple_toplevel_entries.rar")
<< QVector<Archive::Entry*>()
- << optionsPreservePaths
+ << defaultOptions
<< 12;
QTest::newRow("extract selected entries from a rar, without paths")
@@ -251,7 +251,7 @@ void CliUnarchiverTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("A/test2.txt"), QStringLiteral("A")),
new Archive::Entry(this, QStringLiteral("A/B/test1.txt"), QStringLiteral("A/B"))
}
- << options
+ << optionsNoPaths
<< 2;
QTest::newRow("extract selected entries from a rar, preserve paths")
@@ -260,7 +260,7 @@ void CliUnarchiverTest::testExtraction_data()
new Archive::Entry(this, QStringLiteral("A/test2.txt"), QStringLiteral("A")),
new Archive::Entry(this, QStringLiteral("A/B/test1.txt"), QStringLiteral("A/B"))
}
- << optionsPreservePaths
+ << defaultOptions
<< 4;
QTest::newRow("extract selected entries from a rar, drag-and-drop")
@@ -277,13 +277,13 @@ void CliUnarchiverTest::testExtraction_data()
QTest::newRow("rar with empty folders")
<< QFINDTESTDATA("data/empty_folders.rar")
<< QVector<Archive::Entry*>()
- << optionsPreservePaths
+ << defaultOptions
<< 5;
QTest::newRow("rar with hidden folder and files")
<< QFINDTESTDATA("data/hidden_files.rar")
<< QVector<Archive::Entry*>()
- << optionsPreservePaths
+ << defaultOptions
<< 4;
}
diff --git a/kerfuffle/CMakeLists.txt b/kerfuffle/CMakeLists.txt
index f4e83f6..7b3b4e7 100644
--- a/kerfuffle/CMakeLists.txt
+++ b/kerfuffle/CMakeLists.txt
@@ -20,6 +20,7 @@ set(kerfuffle_SRCS
plugin.cpp
pluginmanager.cpp
archiveentry.cpp
+ options.cpp
)
kconfig_add_kcfg_files(kerfuffle_SRCS settings.kcfgc)
diff --git a/kerfuffle/adddialog.h b/kerfuffle/adddialog.h
index 013b93d..d63811d 100644
--- a/kerfuffle/adddialog.h
+++ b/kerfuffle/adddialog.h
@@ -49,7 +49,7 @@ public:
const QString &title,
const QUrl &startDir,
const QMimeType &mimeType,
- const CompressionOptions &opts = QHash<QString, QVariant>());
+ const CompressionOptions &opts = {});
virtual ~AddDialog();
QStringList selectedFiles() const;
CompressionOptions compressionOptions() const;
diff --git a/kerfuffle/addtoarchive.cpp b/kerfuffle/addtoarchive.cpp
index cb724dc..a4c3620 100644
--- a/kerfuffle/addtoarchive.cpp
+++ b/kerfuffle/addtoarchive.cpp
@@ -186,8 +186,8 @@ void AddToArchive::slotStartJob()
entry->setFullPath(stripDir.absoluteFilePath(entry->fullPath()));
}
- options[QStringLiteral( "GlobalWorkDir" )] = stripDir.path();
qCDebug(ARK) << "Setting GlobalWorkDir to " << stripDir.path();
+ options.setGlobalWorkDir(stripDir.path());
}
auto createJob = Archive::create(m_filename, m_mimeType, m_entries, options, this);
diff --git a/kerfuffle/archive_kerfuffle.cpp b/kerfuffle/archive_kerfuffle.cpp
index 31ef831..2d92ae3 100644
--- a/kerfuffle/archive_kerfuffle.cpp
+++ b/kerfuffle/archive_kerfuffle.cpp
@@ -400,7 +400,7 @@ AddJob* Archive::addFiles(const QVector<Archive::Entry*> &files, const Archive::
CompressionOptions newOptions = options;
if (encryptionType() != Unencrypted) {
- newOptions[QStringLiteral("PasswordProtectedHint")] = true;
+ newOptions.setEncryptedArchiveHint(true);
}
qCDebug(ARK) << "Going to add files" << files << "with options" << newOptions;
@@ -419,7 +419,7 @@ MoveJob* Archive::moveFiles(const QVector<Archive::Entry*> &files, Archive::Entr
CompressionOptions newOptions = options;
if (encryptionType() != Unencrypted) {
- newOptions[QStringLiteral("PasswordProtectedHint")] = true;
+ newOptions.setEncryptedArchiveHint(true);
}
qCDebug(ARK) << "Going to move files" << files << "with options" << newOptions;
@@ -437,7 +437,7 @@ CopyJob* Archive::copyFiles(const QVector<Archive::Entry*> &files, Archive::Entr
CompressionOptions newOptions = options;
if (encryptionType() != Unencrypted) {
- newOptions[QStringLiteral("PasswordProtectedHint")] = true;
+ newOptions.setEncryptedArchiveHint(true);
}
qCDebug(ARK) << "Going to copy files" << files << "with options" << newOptions;
@@ -455,7 +455,7 @@ ExtractJob* Archive::extractFiles(const QVector<Archive::Entry*> &files, const Q
ExtractionOptions newOptions = options;
if (encryptionType() != Unencrypted) {
- newOptions[QStringLiteral( "PasswordProtectedHint" )] = true;
+ newOptions.setEncryptedArchiveHint(true);
}
ExtractJob *newJob = new ExtractJob(files, destinationDir, newOptions, m_iface);
@@ -521,16 +521,6 @@ void Archive::onUserQuery(Query* query)
query->execute();
}
-void Archive::setCompressionOptions(const CompressionOptions &opts)
-{
- m_compOptions = opts;
-}
-
-CompressionOptions Archive::compressionOptions() const
-{
- return m_compOptions;
-}
-
QString Archive::multiVolumeName() const
{
return m_iface->multiVolumeName();
diff --git a/kerfuffle/archive_kerfuffle.h b/kerfuffle/archive_kerfuffle.h
index dd2816c..e3c6197 100644
--- a/kerfuffle/archive_kerfuffle.h
+++ b/kerfuffle/archive_kerfuffle.h
@@ -29,6 +29,7 @@
#define ARCHIVE_H
#include "kerfuffle_export.h"
+#include "options.h"
#include <KJob>
#include <KPluginMetaData>
@@ -62,14 +63,6 @@ enum ArchiveError {
FailedPlugin
};
-/**
-These are the extra options for doing the compression. Naming convention
-is CamelCase with either Global, or the compression type (such as Zip,
-Rar, etc), followed by the property name used
- */
-typedef QHash<QString, QVariant> CompressionOptions;
-typedef QHash<QString, QVariant> ExtractionOptions;
-
class KERFUFFLE_EXPORT Archive : public QObject
{
Q_OBJECT
@@ -125,8 +118,6 @@ public:
qulonglong unpackedSize() const;
qulonglong packedSize() const;
QString subfolderName() const;
- void setCompressionOptions(const CompressionOptions &opts);
- CompressionOptions compressionOptions() const;
QString multiVolumeName() const;
ReadOnlyArchiveInterface *interface();
@@ -248,7 +239,6 @@ private:
EncryptionType m_encryptionType;
qulonglong m_numberOfFiles;
qulonglong m_numberOfFolders;
- CompressionOptions m_compOptions;
QMimeType m_mimeType;
QStringList m_compressionMethods;
};
diff --git a/kerfuffle/archiveinterface.h b/kerfuffle/archiveinterface.h
index 8a8a6d7..a98daa9 100644
--- a/kerfuffle/archiveinterface.h
+++ b/kerfuffle/archiveinterface.h
@@ -204,8 +204,6 @@ public:
bool isReadOnly() const Q_DECL_OVERRIDE;
- //see archive.h for a list of what the compressionoptions might
- //contain
virtual bool addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions& options) = 0;
virtual bool moveFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions& options) = 0;
virtual bool copyFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions& options) = 0;
diff --git a/kerfuffle/cliinterface.cpp b/kerfuffle/cliinterface.cpp
index 05fef36..84fae96 100644
--- a/kerfuffle/cliinterface.cpp
+++ b/kerfuffle/cliinterface.cpp
@@ -122,14 +122,12 @@ bool CliInterface::extractFiles(const QVector<Archive::Entry*> &files, const QSt
cacheParameterList();
m_operationMode = Extract;
- m_compressionOptions = options;
+ m_extractionOptions = options;
m_extractedFiles = files;
m_extractDestDir = destinationDirectory;
const QStringList extractArgs = m_param.value(ExtractArgs).toStringList();
- if (extractArgs.contains(QStringLiteral("$PasswordSwitch")) &&
- options.value(QStringLiteral("PasswordProtectedHint")).toBool() &&
- password().isEmpty()) {
+ if (extractArgs.contains(QStringLiteral("$PasswordSwitch")) && options.encryptedArchiveHint() && password().isEmpty()) {
qCDebug(ARK) << "Password hint enabled, querying user";
if (!passwordQuery()) {
return false;
@@ -139,14 +137,13 @@ bool CliInterface::extractFiles(const QVector<Archive::Entry*> &files, const QSt
// Populate the argument list.
const QStringList args = substituteExtractVariables(extractArgs,
files,
- options.value(QStringLiteral("PreservePaths")).toBool(),
+ options.preservePaths(),
password());
QUrl destDir = QUrl(destinationDirectory);
QDir::setCurrent(destDir.adjusted(QUrl::RemoveScheme).url());
- bool useTmpExtractDir = options.value(QStringLiteral("DragAndDrop")).toBool() ||
- options.value(QStringLiteral("AlwaysUseTmpDir")).toBool();
+ const bool useTmpExtractDir = options.isDragAndDropEnabled() || options.alwaysUseTempDir();
if (useTmpExtractDir) {
@@ -220,26 +217,20 @@ bool CliInterface::addFiles(const QVector<Archive::Entry*> &files, const Archive
filesToPass = files;
}
- if (addArgs.contains(QStringLiteral("$PasswordSwitch")) &&
- options.value(QStringLiteral("PasswordProtectedHint")).toBool() &&
- password().isEmpty()) {
+ if (addArgs.contains(QStringLiteral("$PasswordSwitch")) && options.encryptedArchiveHint() && password().isEmpty()) {
qCDebug(ARK) << "Password hint enabled, querying user";
if (!passwordQuery()) {
return false;
}
}
- int compLevel = options.value(QStringLiteral("CompressionLevel"), -1).toInt();
- ulong volumeSize = options.value(QStringLiteral("VolumeSize"), 0).toULongLong();
- QString compMethod = options.value(QStringLiteral("CompressionMethod")).toString();
-
const auto args = substituteAddVariables(m_param.value(AddArgs).toStringList(),
filesToPass,
password(),
isHeaderEncryptionEnabled(),
- compLevel,
- volumeSize,
- compMethod);
+ options.compressionLevel(),
+ options.volumeSize(),
+ options.compressionMethod());
return runProcess(m_param.value(AddProgram).toStringList(), args);
}
@@ -271,12 +262,11 @@ bool CliInterface::copyFiles(const QVector<Archive::Entry*> &files, Archive::Ent
m_passedFiles = files;
m_passedDestination = destination;
m_passedOptions = options;
- m_passedOptions[QStringLiteral("PreservePaths")] = true;
m_subOperation = Extract;
connect(this, &CliInterface::finished, this, &CliInterface::continueCopying);
- return extractFiles(files, QDir::currentPath(), m_passedOptions);
+ return extractFiles(files, QDir::currentPath(), ExtractionOptions());
}
bool CliInterface::deleteFiles(const QVector<Archive::Entry*> &files)
@@ -423,7 +413,7 @@ void CliInterface::extractProcessFinished(int exitCode, QProcess::ExitStatus exi
m_process = Q_NULLPTR;
}
- if (m_compressionOptions.value(QStringLiteral("AlwaysUseTmpDir")).toBool()) {
+ if (m_extractionOptions.alwaysUseTempDir()) {
// unar exits with code 1 if extraction fails.
// This happens at least with wrong passwords or not enough space in the destination folder.
if (m_exitCode == 1) {
@@ -440,8 +430,8 @@ void CliInterface::extractProcessFinished(int exitCode, QProcess::ExitStatus exi
return;
}
- if (!m_compressionOptions.value(QStringLiteral("DragAndDrop")).toBool()) {
- if (!moveToDestination(QDir::current(), QDir(m_extractDestDir), m_compressionOptions[QStringLiteral("PreservePaths")].toBool())) {
+ if (!m_extractionOptions.isDragAndDropEnabled()) {
+ if (!moveToDestination(QDir::current(), QDir(m_extractDestDir), m_extractionOptions.preservePaths())) {
emit error(i18ncp("@info",
"Could not move the extracted file to the destination directory.",
"Could not move the extracted files to the destination directory.",
@@ -455,7 +445,7 @@ void CliInterface::extractProcessFinished(int exitCode, QProcess::ExitStatus exi
}
}
- if (m_compressionOptions.value(QStringLiteral("DragAndDrop")).toBool()) {
+ if (m_extractionOptions.isDragAndDropEnabled()) {
if (!moveDroppedFilesToDest(m_extractedFiles, m_extractDestDir)) {
emit error(i18ncp("@info",
"Could not move the extracted file to the destination directory.",
diff --git a/kerfuffle/cliinterface.h b/kerfuffle/cliinterface.h
index e207968..88b713b 100644
--- a/kerfuffle/cliinterface.h
+++ b/kerfuffle/cliinterface.h
@@ -503,7 +503,7 @@ private:
bool m_listEmptyLines;
QString m_storedFileName;
- CompressionOptions m_compressionOptions;
+ ExtractionOptions m_extractionOptions;
QString m_extractDestDir;
QTemporaryDir *m_extractTempDir;
QTemporaryFile *m_commentTempFile;
diff --git a/kerfuffle/compressionoptionswidget.cpp b/kerfuffle/compressionoptionswidget.cpp
index b5dc25b..29b5b49 100644
--- a/kerfuffle/compressionoptionswidget.cpp
+++ b/kerfuffle/compressionoptionswidget.cpp
@@ -50,23 +50,22 @@ CompressionOptionsWidget::CompressionOptionsWidget(QWidget *parent,
connect(multiVolumeCheckbox, &QCheckBox::stateChanged, this, &CompressionOptionsWidget::slotMultiVolumeChecked);
- if (m_opts.contains(QStringLiteral("VolumeSize"))) {
+ if (m_opts.isVolumeSizeSet()) {
multiVolumeCheckbox->setChecked(true);
// Convert from kilobytes.
- volumeSizeSpinbox->setValue(m_opts.value(QStringLiteral("VolumeSize")).toDouble() / 1024);
+ volumeSizeSpinbox->setValue(static_cast<double>(m_opts.volumeSize()) / 1024);
}
}
CompressionOptions CompressionOptionsWidget::commpressionOptions() const
{
CompressionOptions opts;
- opts[QStringLiteral("CompressionLevel")] = compLevelSlider->value();
+ opts.setCompressionLevel(compLevelSlider->value());
if (multiVolumeCheckbox->isChecked()) {
- // Convert to kilobytes.
- opts[QStringLiteral("VolumeSize")] = QString::number(volumeSize());
+ opts.setVolumeSize(volumeSize());
}
if (!compMethodComboBox->currentText().isEmpty()) {
- opts[QStringLiteral("CompressionMethod")] = compMethodComboBox->currentText();
+ opts.setCompressionMethod(compMethodComboBox->currentText());
}
return opts;
@@ -156,8 +155,8 @@ void CompressionOptionsWidget::updateWidgets()
compLevelSlider->setToolTip(QString());
compLevelSlider->setMinimum(archiveFormat.minCompressionLevel());
compLevelSlider->setMaximum(archiveFormat.maxCompressionLevel());
- if (m_opts.contains(QStringLiteral("CompressionLevel"))) {
- compLevelSlider->setValue(m_opts.value(QStringLiteral("CompressionLevel")).toInt());
+ if (m_opts.isCompressionLevelSet()) {
+ compLevelSlider->setValue(m_opts.compressionLevel());
} else {
compLevelSlider->setValue(archiveFormat.defaultCompressionLevel());
}
@@ -175,9 +174,9 @@ void CompressionOptionsWidget::updateWidgets()
compMethodComboBox->setToolTip(QString());
compMethodComboBox->clear();
compMethodComboBox->insertItems(0, archiveFormat.compressionMethods());
- if (m_opts.contains(QStringLiteral("CompressionMethod")) &&
- compMethodComboBox->findText(m_opts.value(QStringLiteral("CompressionMethod")).toString()) > -1) {
- compMethodComboBox->setCurrentText(m_opts.value(QStringLiteral("CompressionMethod")).toString());
+ if (!m_opts.compressionMethod().isEmpty() &&
+ compMethodComboBox->findText(m_opts.compressionMethod()) > -1) {
+ compMethodComboBox->setCurrentText(m_opts.compressionMethod());
} else {
compMethodComboBox->setCurrentText(archiveFormat.defaultCompressionMethod());
}
diff --git a/kerfuffle/compressionoptionswidget.h b/kerfuffle/compressionoptionswidget.h
index 9d120df..24d3335 100644
--- a/kerfuffle/compressionoptionswidget.h
+++ b/kerfuffle/compressionoptionswidget.h
@@ -43,7 +43,7 @@ class KERFUFFLE_EXPORT CompressionOptionsWidget : public QWidget, public Ui::Com
public:
explicit CompressionOptionsWidget(QWidget *parent = Q_NULLPTR,
- const CompressionOptions &opts = QHash<QString, QVariant>());
+ const CompressionOptions &opts = {});
int compressionLevel() const;
QString compressionMethod() const;
ulong volumeSize() const;
diff --git a/kerfuffle/jobs.cpp b/kerfuffle/jobs.cpp
index 6734b71..4349d1e 100644
--- a/kerfuffle/jobs.cpp
+++ b/kerfuffle/jobs.cpp
@@ -362,7 +362,7 @@ void BatchExtractJob::slotLoadingFinished(KJob *job)
setupDestination();
Kerfuffle::ExtractionOptions options;
- options[QStringLiteral("PreservePaths")] = m_preservePaths;
+ options.setPreservePaths(m_preservePaths);
auto extractJob = archive()->extractFiles({}, m_destination, options);
if (extractJob) {
@@ -437,7 +437,6 @@ ExtractJob::ExtractJob(const QVector<Archive::Entry*> &entries, const QString &d
, m_options(options)
{
qCDebug(ARK) << "ExtractJob created";
- setDefaultOptions();
}
void ExtractJob::doWork()
@@ -471,20 +470,6 @@ void ExtractJob::doWork()
}
}
-void ExtractJob::setDefaultOptions()
-{
- ExtractionOptions defaultOptions;
-
- defaultOptions[QStringLiteral("PreservePaths")] = false;
-
- ExtractionOptions::const_iterator it = defaultOptions.constBegin();
- for (; it != defaultOptions.constEnd(); ++it) {
- if (!m_options.contains(it.key())) {
- m_options[it.key()] = it.value();
- }
- }
-}
-
QString ExtractJob::destinationDirectory() const
{
return m_destinationDir;
@@ -518,10 +503,9 @@ QString TempExtractJob::validatedFilePath() const
ExtractionOptions TempExtractJob::extractionOptions() const
{
ExtractionOptions options;
- options[QStringLiteral("PreservePaths")] = true;
if (m_passwordProtectedHint) {
- options[QStringLiteral("PasswordProtectedHint")] = true;
+ options.setEncryptedArchiveHint(true);
}
return options;
@@ -582,7 +566,7 @@ AddJob::AddJob(const QVector<Archive::Entry*> &entries, const Archive::Entry *de
void AddJob::doWork()
{
// Set current dir.
- const QString globalWorkDir = m_options.value(QStringLiteral("GlobalWorkDir")).toString();
+ const QString globalWorkDir = m_options.globalWorkDir();
const QDir workDir = globalWorkDir.isEmpty() ? QDir::current() : QDir(globalWorkDir);
if (!globalWorkDir.isEmpty()) {
qCDebug(ARK) << "GlobalWorkDir is set, changing dir to " << globalWorkDir;
@@ -604,11 +588,8 @@ void AddJob::doWork()
}
}
}
- qCDebug(ARK) << "Counted" << totalCount << "entries in" << timer.elapsed() << "ms";
-
- m_options[QStringLiteral("NumberOfEntries")] = totalCount;
- qCDebug(ARK) << "AddJob: going to add" << totalCount << "entries";
+ qCDebug(ARK) << "AddJob: going to add" << totalCount << "entries, counted in" << timer.elapsed() << "ms";
QString desc = i18np("Adding a file", "Adding %1 files", totalCount);
emit description(this, desc, qMakePair(i18n("Archive"), archiveInterface()->filename()));
diff --git a/kerfuffle/jobs.h b/kerfuffle/jobs.h
index 11ab026..f6a492b 100644
--- a/kerfuffle/jobs.h
+++ b/kerfuffle/jobs.h
@@ -221,8 +221,6 @@ public slots:
virtual void doWork() Q_DECL_OVERRIDE;
private:
- // TODO: Maybe this should be a method if ExtractionOptions were a class?
- void setDefaultOptions();
QVector<Archive::Entry*> m_entries;
QString m_destinationDir;
diff --git a/kerfuffle/options.cpp b/kerfuffle/options.cpp
new file mode 100644
index 0000000..08c6bec
--- /dev/null
+++ b/kerfuffle/options.cpp
@@ -0,0 +1,148 @@
+/*
+ * ark -- archiver for the KDE project
+ *
+ * Copyright (C) 2016 Elvis Angelaccio <elvis.angelaccio@kde.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "options.h"
+
+namespace Kerfuffle
+{
+
+bool Options::encryptedArchiveHint() const
+{
+ return m_encryptedArchiveHint;
+}
+
+void Options::setEncryptedArchiveHint(bool encrypted)
+{
+ m_encryptedArchiveHint = encrypted;
+}
+
+bool ExtractionOptions::preservePaths() const
+{
+ return m_preservePaths;
+}
+
+void ExtractionOptions::setPreservePaths(bool preservePaths)
+{
+ m_preservePaths = preservePaths;
+}
+
+bool ExtractionOptions::isDragAndDropEnabled() const
+{
+ return m_dragAndDrop;
+}
+
+void ExtractionOptions::setDragAndDropEnabled(bool enabled)
+{
+ m_dragAndDrop = enabled;
+}
+
+bool ExtractionOptions::alwaysUseTempDir() const
+{
+ return m_alwaysUseTempDir;
+}
+
+void ExtractionOptions::setAlwaysUseTempDir(bool alwaysUseTempDir)
+{
+ m_alwaysUseTempDir = alwaysUseTempDir;
+}
+
+bool CompressionOptions::isCompressionLevelSet() const
+{
+ return compressionLevel() != -1;
+}
+
+bool CompressionOptions::isVolumeSizeSet() const
+{
+ return volumeSize() > 0;
+}
+
+int CompressionOptions::compressionLevel() const
+{
+ return m_compressionLevel;
+}
+
+void CompressionOptions::setCompressionLevel(int level)
+{
+ m_compressionLevel = level;
+}
+
+int CompressionOptions::volumeSize() const
+{
+ return m_volumeSize;
+}
+
+void CompressionOptions::setVolumeSize(int size)
+{
+ m_volumeSize = size;
+}
+
+QString CompressionOptions::compressionMethod() const
+{
+ return m_compressionMethod;
+}
+
+void CompressionOptions::setCompressionMethod(const QString &method)
+{
+ m_compressionMethod = method;
+}
+
+QString CompressionOptions::globalWorkDir() const
+{
+ return m_globalWorkDir;
+}
+
+void CompressionOptions::setGlobalWorkDir(const QString &workDir)
+{
+ m_globalWorkDir = workDir;
+}
+
+QDebug operator<<(QDebug d, const CompressionOptions &options)
+{
+ d.nospace() << "(encryption hint: " << options.encryptedArchiveHint();
+ if (!options.compressionMethod().isEmpty()) {
+ d.nospace() << ", compression method: " << options.compressionMethod();
+ }
+ if (!options.globalWorkDir().isEmpty()) {
+ d.nospace() << ", global work dir: " << options.globalWorkDir();
+ }
+ d.nospace() << ", compression level: " << options.compressionLevel();
+ d.nospace() << ", volume size: " << options.volumeSize();
+ d.nospace() << ")";
+ return d.space();
+}
+
+QDebug operator<<(QDebug d, const ExtractionOptions &options)
+{
+ d.nospace() << "(encryption hint: " << options.encryptedArchiveHint();
+ d.nospace() << ", preserve paths: " << options.preservePaths();
+ d.nospace() << ", drag and drop: " << options.isDragAndDropEnabled();
+ d.nospace() << ", always temp dir: " << options.alwaysUseTempDir();
+ d.nospace() << ")";
+ return d.space();
+}
+
+}
diff --git a/kerfuffle/options.h b/kerfuffle/options.h
new file mode 100644
index 0000000..a6ee073
--- /dev/null
+++ b/kerfuffle/options.h
@@ -0,0 +1,110 @@
+/*
+ * ark -- archiver for the KDE project
+ *
+ * Copyright (C) 2016 Elvis Angelaccio <elvis.angelaccio@kde.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OPTIONS_H
+#define OPTIONS_H
+
+#include "kerfuffle_export.h"
+
+#include <QDebug>
+
+namespace Kerfuffle
+{
+
+class KERFUFFLE_EXPORT Options
+{
+public:
+
+ bool encryptedArchiveHint() const;
+ void setEncryptedArchiveHint(bool encrypted);
+
+private:
+
+ bool m_encryptedArchiveHint = false;
+};
+
+class KERFUFFLE_EXPORT CompressionOptions : public Options
+{
+public:
+
+ /**
+ * @return Whether a custom compression level has been set in the options.
+ * If false, the default level from the ArchiveFormat should be used instead.
+ * @see compressionLevel()
+ */
+ bool isCompressionLevelSet() const;
+
+ /**
+ * @return Whether a custom volume size has been set in the options.
+ * If false, the default size from the ArchiveFormat should be used instead.
+ * @see compressionLevel()
+ */
+ bool isVolumeSizeSet() const;
+
+ int compressionLevel() const;
+ void setCompressionLevel(int level);
+ int volumeSize() const;
+ void setVolumeSize(int size);
+ QString compressionMethod() const;
+ void setCompressionMethod(const QString &method);
+ QString globalWorkDir() const;
+ void setGlobalWorkDir(const QString &workDir);
+
+private:
+ int m_compressionLevel = -1;
+ int m_volumeSize = 0;
+ QString m_compressionMethod;
+ QString m_globalWorkDir;
+};
+
+class KERFUFFLE_EXPORT ExtractionOptions : public Options
+{
+public:
+
+ bool preservePaths() const;
+ void setPreservePaths(bool preservePaths);
+ bool isDragAndDropEnabled() const;
+ void setDragAndDropEnabled(bool enabled);
+ bool alwaysUseTempDir() const;
+ void setAlwaysUseTempDir(bool alwaysUseTempDir);
+
+private:
+
+ bool m_preservePaths = true;
+ bool m_dragAndDrop = false;
+ bool m_alwaysUseTempDir = false;
+};
+
+QDebug KERFUFFLE_EXPORT operator<<(QDebug d, const CompressionOptions &options);
+QDebug KERFUFFLE_EXPORT operator<<(QDebug d, const ExtractionOptions &options);
+
+}
+
+Q_DECLARE_METATYPE(Kerfuffle::CompressionOptions)
+Q_DECLARE_METATYPE(Kerfuffle::ExtractionOptions)
+
+#endif
diff --git a/part/part.cpp b/part/part.cpp
index 23f17cb..c1f7dbf 100644
--- a/part/part.cpp
+++ b/part/part.cpp
@@ -273,9 +273,7 @@ void Part::extractSelectedFilesTo(const QString& localPath)
qCDebug(ARK) << "Extract to" << destination;
Kerfuffle::ExtractionOptions options;
- options[QStringLiteral("PreservePaths")] = true;
- options[QStringLiteral("RemoveRootNode")] = true;
- options[QStringLiteral("DragAndDrop")] = true;
+ options.setDragAndDropEnabled(true);
// Create and start the ExtractJob.
ExtractJob *job = m_model->extractFiles(filesAndRootNodesForIndexes(addChildren(m_view->selectionModel()->selectedRows())), destination, options);
@@ -606,6 +604,8 @@ void Part::resetGui()
m_commentView->clear();
m_commentBox->hide();
m_infoPanel->setIndex(QModelIndex());
+ // Also reset format-specific compression options.
+ m_compressionOptions = CompressionOptions();
}
void Part::slotTestingDone(KJob* job)
@@ -693,9 +693,7 @@ void Part::slotQuickExtractFiles(QAction *triggeredAction)
qCDebug(ARK) << "Extracting to:" << finalDestinationDirectory;
- Kerfuffle::ExtractionOptions options;
- options[QStringLiteral("PreservePaths")] = true;
- ExtractJob *job = m_model->extractFiles(filesAndRootNodesForIndexes(addChildren(m_view->selectionModel()->selectedRows())), finalDestinationDirectory, options);
+ ExtractJob *job = m_model->extractFiles(filesAndRootNodesForIndexes(addChildren(m_view->selectionModel()->selectedRows())), finalDestinationDirectory, ExtractionOptions());
registerJob(job);
connect(job, &KJob::result,
@@ -1120,11 +1118,7 @@ void Part::slotShowExtractionDialog()
qCDebug(ARK) << "Selected " << files;
Kerfuffle::ExtractionOptions options;
-
- if (dialog.data()->preservePaths()) {
- options[QStringLiteral("PreservePaths")] = true;
- }
- options[QStringLiteral("FollowExtractionDialogSettings")] = true;
+ options.setPreservePaths(dialog->preservePaths());
const QString destinationDirectory = dialog.data()->destinationDirectory().toLocalFile();
ExtractJob *job = m_model->extractFiles(files, destinationDirectory, options);
@@ -1217,12 +1211,6 @@ void Part::slotExtractionDone(KJob* job)
ExtractJob *extractJob = qobject_cast<ExtractJob*>(job);
Q_ASSERT(extractJob);
- const bool followExtractionDialogSettings =
- extractJob->extractionOptions().value(QStringLiteral("FollowExtractionDialogSettings"), false).toBool();
- if (!followExtractionDialogSettings) {
- return;
- }
-
if (ArkSettings::openDestinationFolderAfterExtraction()) {
qCDebug(ARK) << "Shall open" << extractJob->destinationDirectory();
QUrl destinationDirectory = QUrl::fromLocalFile(extractJob->destinationDirectory()).adjusted(QUrl::NormalizePathSegments);
@@ -1304,15 +1292,16 @@ void Part::slotAddFiles(const QStringList& filesToAdd, const Archive::Entry *des
globalWorkDir.chop(1);
}
- CompressionOptions options(m_model->archive()->compressionOptions());
+ // We need to override the global options with a working directory.
+ CompressionOptions compOptions = m_compressionOptions;
// Now take the absolute path of the parent directory.
globalWorkDir = QFileInfo(globalWorkDir).dir().absolutePath();
qCDebug(ARK) << "Detected GlobalWorkDir to be " << globalWorkDir;
- options[QStringLiteral("GlobalWorkDir")] = globalWorkDir;
+ compOptions.setGlobalWorkDir(globalWorkDir);
- AddJob *job = m_model->addFiles(m_jobTempEntries, destination, options);
+ AddJob *job = m_model->addFiles(m_jobTempEntries, destination, compOptions);
if (!job) {
qDeleteAll(m_jobTempEntries);
m_jobTempEntries.clear();
@@ -1327,25 +1316,20 @@ void Part::slotAddFiles(const QStringList& filesToAdd, const Archive::Entry *des
void Part::slotAddFiles()
{
- // If compression options are already set, we don't use the values from CreateDialog.
- CompressionOptions opts;
- if (m_model->archive()->compressionOptions().isEmpty()) {
- if (arguments().metaData().contains(QStringLiteral("compressionLevel"))) {
- opts[QStringLiteral("CompressionLevel")] = arguments().metaData()[QStringLiteral("compressionLevel")];
- }
- if (arguments().metaData().contains(QStringLiteral("compressionMethod"))) {
- opts[QStringLiteral("CompressionMethod")] = arguments().metaData()[QStringLiteral("compressionMethod")];
- }
- if (arguments().metaData().contains(QStringLiteral("volumeSize"))) {
- opts[QStringLiteral("VolumeSize")] = arguments().metaData()[QStringLiteral("volumeSize")];
- }
- m_model->archive()->setCompressionOptions(opts);
- } else {
- opts = m_model->archive()->compressionOptions();
+ // Store options from CreateDialog if they are set.
+ if (!m_compressionOptions.isCompressionLevelSet() && arguments().metaData().contains(QStringLiteral("compressionLevel"))) {
+ m_compressionOptions.setCompressionLevel(arguments().metaData()[QStringLiteral("compressionLevel")].toInt());
+ }
+ if (m_compressionOptions.compressionMethod().isEmpty() && arguments().metaData().contains(QStringLiteral("compressionMethod"))) {
+ m_compressionOptions.setCompressionMethod(arguments().metaData()[QStringLiteral("compressionMethod")]);
+ }
+ if (!m_compressionOptions.isVolumeSizeSet() && arguments().metaData().contains(QStringLiteral("volumeSize"))) {
+ m_compressionOptions.setVolumeSize(arguments().metaData()[QStringLiteral("volumeSize")].toInt());
}
- if (m_model->archive()->property("compressionMethods").toStringList().size() == 1) {
- opts[QStringLiteral("CompressionMethod")] = m_model->archive()->property("compressionMethods").toStringList().first();
+ const auto compressionMethods = m_model->archive()->property("compressionMethods").toStringList();
+ if (compressionMethods.size() == 1) {
+ m_compressionOptions.setCompressionMethod(compressionMethods.first());
}
QString dialogTitle = i18nc("@title:window", "Add Files");
@@ -1359,7 +1343,7 @@ void Part::slotAddFiles()
}
}
- qCDebug(ARK) << "Opening AddDialog with opts:" << opts;
+ qCDebug(ARK) << "Opening AddDialog with opts:" << m_compressionOptions;
// #264819: passing widget() as the parent will not work as expected.
// KFileDialog will create a KFileWidget, which runs an internal
@@ -1375,12 +1359,12 @@ void Part::slotAddFiles()
dialogTitle,
m_lastUsedAddPath,
m_model->archive()->mimeType(),
- opts);
+ m_compressionOptions);
if (dlg->exec() == QDialog::Accepted) {
qCDebug(ARK) << "Selected files:" << dlg->selectedFiles();
qCDebug(ARK) << "Options:" << dlg->compressionOptions();
- m_model->archive()->setCompressionOptions(dlg->compressionOptions());
+ m_compressionOptions = dlg->compressionOptions();
slotAddFiles(dlg->selectedFiles(), destination, QString());
}
delete dlg;
@@ -1533,13 +1517,11 @@ void Part::slotPasteFiles(QVector<Kerfuffle::Archive::Entry*> &files, Kerfuffle:
qCDebug(ARK) << "Copying " << files << "to" << destination;
}
- CompressionOptions options(m_model->archive()->compressionOptions());
-
KJob *job;
if (entriesWithoutChildren != 0) {
- job = m_model->moveFiles(files, destination, options);
+ job = m_model->moveFiles(files, destination, CompressionOptions());
} else {
- job = m_model->copyFiles(files, destination, options);
+ job = m_model->copyFiles(files, destination, CompressionOptions());
}
if (job) {
diff --git a/part/part.h b/part/part.h
index 4a7e8f5..97b7877 100644
--- a/part/part.h
+++ b/part/part.h
@@ -215,6 +215,7 @@ private:
QPlainTextEdit *m_commentView;
KMessageWidget *m_commentMsgWidget;
KMessageWidget *m_messageWidget;
+ Kerfuffle::CompressionOptions m_compressionOptions;
};
} // namespace Ark
diff --git a/plugins/cliunarchiverplugin/cliplugin.cpp b/plugins/cliunarchiverplugin/cliplugin.cpp
index b7d2482..7451255 100644
--- a/plugins/cliunarchiverplugin/cliplugin.cpp
+++ b/plugins/cliunarchiverplugin/cliplugin.cpp
@@ -66,7 +66,7 @@ bool CliPlugin::extractFiles(const QVector<Archive::Entry*> &files, const QStrin
// and then we move the files to the intended destination.
qCDebug(ARK) << "Enabling extraction to temporary directory.";
- newOptions[QStringLiteral("AlwaysUseTmpDir")] = true;
+ newOptions.setAlwaysUseTempDir(true);
return CliInterface::extractFiles(files, destinationDirectory, newOptions);
}
diff --git a/plugins/clizipplugin/cliplugin.cpp b/plugins/clizipplugin/cliplugin.cpp
index b5d7f8c..c98e786 100644
--- a/plugins/clizipplugin/cliplugin.cpp
+++ b/plugins/clizipplugin/cliplugin.cpp
@@ -213,7 +213,7 @@ bool CliPlugin::moveFiles(const QVector<Archive::Entry*> &files, Archive::Entry
m_subOperation = Extract;
connect(this, &CliPlugin::finished, this, &CliPlugin::continueMoving);
- return extractFiles(files, QDir::currentPath(), options);
+ return extractFiles(files, QDir::currentPath(), ExtractionOptions());
}
int CliPlugin::moveRequiredSignals() const {
diff --git a/plugins/libarchive/libarchiveplugin.cpp b/plugins/libarchive/libarchiveplugin.cpp
index 51ddaef..d4e5238 100644
--- a/plugins/libarchive/libarchiveplugin.cpp
+++ b/plugins/libarchive/libarchiveplugin.cpp
@@ -150,8 +150,8 @@ bool LibarchivePlugin::extractFiles(const QVector<Archive::Entry*> &files, const
QDir::setCurrent(destinationDirectory);
const bool extractAll = files.isEmpty();
- const bool preservePaths = options.value(QStringLiteral( "PreservePaths" )).toBool();
- bool removeRootNode = options.value(QStringLiteral("RemoveRootNode"), QVariant()).toBool();
+ const bool preservePaths = options.preservePaths();
+ const bool removeRootNode = options.isDragAndDropEnabled();
// To avoid traversing the entire archive when extracting a limited set of
// entries, we maintain a list of remaining entries and stop when it's
diff --git a/plugins/libarchive/readwritelibarchiveplugin.cpp b/plugins/libarchive/readwritelibarchiveplugin.cpp
index e5e27a6..b5aa601 100644
--- a/plugins/libarchive/readwritelibarchiveplugin.cpp
+++ b/plugins/libarchive/readwritelibarchiveplugin.cpp
@@ -363,9 +363,9 @@ bool ReadWriteLibarchivePlugin::initializeNewFileWriterFilters(const Compression
}
// Set compression level if passed in CompressionOptions.
- if (options.contains(QStringLiteral("CompressionLevel"))) {
- qCDebug(ARK) << "Using compression level:" << options.value(QStringLiteral("CompressionLevel")).toString();
- ret = archive_write_set_filter_option(m_archiveWriter.data(), NULL, "compression-level", options.value(QStringLiteral("CompressionLevel")).toString().toUtf8());
+ if (options.isCompressionLevelSet()) {
+ qCDebug(ARK) << "Using compression level:" << options.compressionLevel();
+ ret = archive_write_set_filter_option(m_archiveWriter.data(), NULL, "compression-level", QString::number(options.compressionLevel()).toUtf8());
if (ret != ARCHIVE_OK) {
qCWarning(ARK) << "Failed to set compression level";
emit error(xi18nc("@info", "Setting the compression level failed with the following error:<nl/><message>%1</message>",