Commit 89a7b5bb authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

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
parent 377dfcfe
......@@ -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();
......
......@@ -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);
......
......@@ -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);
......
......@@ -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");
......
......@@ -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));
......
......@@ -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)
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -20,6 +20,7 @@ set(kerfuffle_SRCS
plugin.cpp
pluginmanager.cpp
archiveentry.cpp
options.cpp
)
kconfig_add_kcfg_files(kerfuffle_SRCS settings.kcfgc)
......
......@@ -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;
......
......@@ -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);
......
......@@ -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();
......
......@@ -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;
};
......
......@@ -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;
......
......@@ -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.",
......
......@@ -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;
......
......@@ -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) {