summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRagnar Thomsen <rthomsen6@gmail.com>2016-10-09 18:07:36 (GMT)
committerRagnar Thomsen <rthomsen6@gmail.com>2016-10-10 18:52:47 (GMT)
commitae73797768a57d3b7f01b951de40510c8ba96d47 (patch)
tree4957d3a502dfa2aeeeabb83e76b14e42ae01e908
parent7d76930485691a8d59f0a5fa1c25196f831ddfd1 (diff)
Support for setting compression method
Summary: Support for setting compression method was implemented. The setting is available in the Compression collapsible group. Reviewers: elvisangelaccio Reviewed By: elvisangelaccio Subscribers: kde-utils-devel Tags: #ark Differential Revision: https://phabricator.kde.org/D2879
-rw-r--r--app/mainwindow.cpp3
-rw-r--r--autotests/kerfuffle/addtoarchivetest.cpp2
-rw-r--r--autotests/plugins/cli7zplugin/cli7ztest.cpp33
-rw-r--r--autotests/plugins/clirarplugin/clirartest.cpp25
-rw-r--r--autotests/plugins/clizipplugin/cliziptest.cpp22
-rw-r--r--kerfuffle/archiveformat.cpp29
-rw-r--r--kerfuffle/archiveformat.h8
-rw-r--r--kerfuffle/cliinterface.cpp26
-rw-r--r--kerfuffle/cliinterface.h6
-rw-r--r--kerfuffle/compressionoptionswidget.cpp45
-rw-r--r--kerfuffle/compressionoptionswidget.h1
-rw-r--r--kerfuffle/compressionoptionswidget.ui40
-rw-r--r--kerfuffle/createdialog.cpp5
-rw-r--r--kerfuffle/createdialog.h1
-rw-r--r--part/part.cpp7
-rw-r--r--plugins/cli7zplugin/cliplugin.cpp25
-rw-r--r--plugins/cli7zplugin/cliplugin.h1
-rw-r--r--plugins/cli7zplugin/kerfuffle_cli7z.json.cmake26
-rw-r--r--plugins/clirarplugin/cliplugin.cpp20
-rw-r--r--plugins/clirarplugin/cliplugin.h2
-rw-r--r--plugins/clirarplugin/kerfuffle_clirar.json.cmake18
-rw-r--r--plugins/clizipplugin/cliplugin.cpp18
-rw-r--r--plugins/clizipplugin/cliplugin.h2
-rw-r--r--plugins/clizipplugin/kerfuffle_clizip.json.cmake12
24 files changed, 322 insertions, 55 deletions
diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp
index a38e912..99852e2 100644
--- a/app/mainwindow.cpp
+++ b/app/mainwindow.cpp
@@ -304,6 +304,9 @@ void MainWindow::newArchive()
qCDebug(ARK) << "Setting volume size:" << QString::number(dialog.data()->volumeSize());
m_openArgs.metaData()[QStringLiteral("volumeSize")] = QString::number(dialog.data()->volumeSize());
}
+ if (!dialog.data()->compressionMethod().isEmpty()) {
+ m_openArgs.metaData()[QStringLiteral("compressionMethod")] = dialog.data()->compressionMethod();
+ }
m_openArgs.metaData()[QStringLiteral("encryptionPassword")] = password;
if (dialog.data()->isHeaderEncryptionEnabled()) {
diff --git a/autotests/kerfuffle/addtoarchivetest.cpp b/autotests/kerfuffle/addtoarchivetest.cpp
index 2816f79..4961d8d 100644
--- a/autotests/kerfuffle/addtoarchivetest.cpp
+++ b/autotests/kerfuffle/addtoarchivetest.cpp
@@ -153,7 +153,6 @@ void AddToArchiveTest::testCompressHere_data()
<< QStringLiteral("data.zip")
<< 3ULL
<< 1ULL;
-
QTest::newRow("compress here (as TAR) - dir with special name (see #365798)")
<< QStringLiteral("tar.gz")
<< Archive::Unencrypted
@@ -161,6 +160,7 @@ void AddToArchiveTest::testCompressHere_data()
<< QStringLiteral("test%dir.tar.gz")
<< 2ULL
<< 1ULL;
+
} else {
qDebug() << "7z/zip executable not found in path. Skipping compress-here-(ZIP) tests.";
}
diff --git a/autotests/plugins/cli7zplugin/cli7ztest.cpp b/autotests/plugins/cli7zplugin/cli7ztest.cpp
index 71a1705..4625d60 100644
--- a/autotests/plugins/cli7zplugin/cli7ztest.cpp
+++ b/autotests/plugins/cli7zplugin/cli7ztest.cpp
@@ -266,48 +266,63 @@ void Cli7zTest::testAddArgs_data()
QTest::addColumn<QString>("password");
QTest::addColumn<bool>("encryptHeader");
QTest::addColumn<int>("compressionLevel");
+ QTest::addColumn<QString>("compressionMethod");
QTest::addColumn<ulong>("volumeSize");
QTest::addColumn<QStringList>("expectedArgs");
QTest::newRow("unencrypted")
<< QStringLiteral("/tmp/foo.7z")
- << QString() << false << 5 << 0UL
+ << QString() << false << 5 << QStringLiteral("LZMA2") << 0UL
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.7z"),
- QStringLiteral("-mx=5")
+ QStringLiteral("-mx=5"),
+ QStringLiteral("-m0=LZMA2")
};
QTest::newRow("encrypted")
<< QStringLiteral("/tmp/foo.7z")
- << QStringLiteral("1234") << false << 5 << 0UL
+ << QStringLiteral("1234") << false << 5 << QStringLiteral("LZMA2") << 0UL
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.7z"),
QStringLiteral("-p1234"),
- QStringLiteral("-mx=5")
+ QStringLiteral("-mx=5"),
+ QStringLiteral("-m0=LZMA2")
};
QTest::newRow("header-encrypted")
<< QStringLiteral("/tmp/foo.7z")
- << QStringLiteral("1234") << true << 5 << 0UL
+ << QStringLiteral("1234") << true << 5 << QStringLiteral("LZMA2") << 0UL
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.7z"),
QStringLiteral("-p1234"),
QStringLiteral("-mhe=on"),
- QStringLiteral("-mx=5")
+ QStringLiteral("-mx=5"),
+ QStringLiteral("-m0=LZMA2")
};
QTest::newRow("multi-volume")
<< QStringLiteral("/tmp/foo.7z")
- << QString() << false << 5 << 2500UL
+ << QString() << false << 5 << QStringLiteral("LZMA2") << 2500UL
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.7z"),
QStringLiteral("-mx=5"),
+ QStringLiteral("-m0=LZMA2"),
QStringLiteral("-v2500k")
};
+
+ QTest::newRow("comp-method-bzip2")
+ << QStringLiteral("/tmp/foo.7z")
+ << QString() << false << 5 << QStringLiteral("BZip2") << 0UL
+ << QStringList {
+ QStringLiteral("a"),
+ QStringLiteral("/tmp/foo.7z"),
+ QStringLiteral("-mx=5"),
+ QStringLiteral("-m0=BZip2")
+ };
}
void Cli7zTest::testAddArgs()
@@ -320,6 +335,7 @@ void Cli7zTest::testAddArgs()
QStringLiteral("$Archive"),
QStringLiteral("$PasswordSwitch"),
QStringLiteral("$CompressionLevelSwitch"),
+ QStringLiteral("$CompressionMethodSwitch"),
QStringLiteral("$MultiVolumeSwitch"),
QStringLiteral("$Files") };
@@ -327,8 +343,9 @@ void Cli7zTest::testAddArgs()
QFETCH(bool, encryptHeader);
QFETCH(int, compressionLevel);
QFETCH(ulong, volumeSize);
+ QFETCH(QString, compressionMethod);
- QStringList replacedArgs = plugin->substituteAddVariables(addArgs, {}, password, encryptHeader, compressionLevel, volumeSize);
+ QStringList replacedArgs = plugin->substituteAddVariables(addArgs, {}, password, encryptHeader, compressionLevel, volumeSize, compressionMethod);
QFETCH(QStringList, expectedArgs);
QCOMPARE(replacedArgs, expectedArgs);
diff --git a/autotests/plugins/clirarplugin/clirartest.cpp b/autotests/plugins/clirarplugin/clirartest.cpp
index 9e27b87..93c750c 100644
--- a/autotests/plugins/clirarplugin/clirartest.cpp
+++ b/autotests/plugins/clirarplugin/clirartest.cpp
@@ -324,21 +324,23 @@ void CliRarTest::testAddArgs_data()
QTest::addColumn<QString>("password");
QTest::addColumn<bool>("encryptHeader");
QTest::addColumn<int>("compressionLevel");
+ QTest::addColumn<QString>("compressionMethod");
QTest::addColumn<ulong>("volumeSize");
QTest::addColumn<QStringList>("expectedArgs");
QTest::newRow("unencrypted")
<< QStringLiteral("/tmp/foo.rar")
- << QString() << false << 3 << 0UL
+ << QString() << false << 3 << QStringLiteral("RAR4") << 0UL
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.rar"),
- QStringLiteral("-m3")
+ QStringLiteral("-m3"),
+ QStringLiteral("-ma4")
};
QTest::newRow("encrypted")
<< QStringLiteral("/tmp/foo.rar")
- << QStringLiteral("1234") << false << 3 << 0UL
+ << QStringLiteral("1234") << false << 3 << QString() << 0UL
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.rar"),
@@ -348,7 +350,7 @@ void CliRarTest::testAddArgs_data()
QTest::newRow("header-encrypted")
<< QStringLiteral("/tmp/foo.rar")
- << QStringLiteral("1234") << true << 3 << 0UL
+ << QStringLiteral("1234") << true << 3 << QString() << 0UL
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.rar"),
@@ -358,13 +360,22 @@ void CliRarTest::testAddArgs_data()
QTest::newRow("multi-volume")
<< QStringLiteral("/tmp/foo.rar")
- << QString() << false << 3 << 2500UL
+ << QString() << false << 3 << QString() << 2500UL
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.rar"),
QStringLiteral("-m3"),
QStringLiteral("-v2500k")
};
+ QTest::newRow("comp-method-RAR5")
+ << QStringLiteral("/tmp/foo.rar")
+ << QString() << false << 3 << QStringLiteral("RAR5") << 0UL
+ << QStringList {
+ QStringLiteral("a"),
+ QStringLiteral("/tmp/foo.rar"),
+ QStringLiteral("-m3"),
+ QStringLiteral("-ma5")
+ };
}
void CliRarTest::testAddArgs()
@@ -377,15 +388,17 @@ void CliRarTest::testAddArgs()
QStringLiteral("$Archive"),
QStringLiteral("$PasswordSwitch"),
QStringLiteral("$CompressionLevelSwitch"),
+ QStringLiteral("$CompressionMethodSwitch"),
QStringLiteral("$MultiVolumeSwitch"),
QStringLiteral("$Files") };
QFETCH(QString, password);
QFETCH(bool, encryptHeader);
QFETCH(int, compressionLevel);
+ QFETCH(QString, compressionMethod);
QFETCH(ulong, volumeSize);
- QStringList replacedArgs = rarPlugin->substituteAddVariables(addArgs, {}, password, encryptHeader, compressionLevel, volumeSize);
+ QStringList replacedArgs = rarPlugin->substituteAddVariables(addArgs, {}, password, encryptHeader, compressionLevel, volumeSize, compressionMethod);
QFETCH(QStringList, expectedArgs);
QCOMPARE(replacedArgs, expectedArgs);
diff --git a/autotests/plugins/clizipplugin/cliziptest.cpp b/autotests/plugins/clizipplugin/cliziptest.cpp
index 3cf7ecf..2e59ce3 100644
--- a/autotests/plugins/clizipplugin/cliziptest.cpp
+++ b/autotests/plugins/clizipplugin/cliziptest.cpp
@@ -69,26 +69,38 @@ void CliZipTest::testAddArgs_data()
QTest::addColumn<QString>("archiveName");
QTest::addColumn<QString>("password");
QTest::addColumn<int>("compressionLevel");
+ QTest::addColumn<QString>("compressionMethod");
QTest::addColumn<QStringList>("expectedArgs");
QTest::newRow("unencrypted")
<< QStringLiteral("/tmp/foo.zip")
- << QString() << 3
+ << QString() << 3 << QStringLiteral("deflate")
<< QStringList {
QStringLiteral("-r"),
QStringLiteral("/tmp/foo.zip"),
- QStringLiteral("-3")
+ QStringLiteral("-3"),
+ QStringLiteral("-Zdeflate")
};
QTest::newRow("encrypted")
<< QStringLiteral("/tmp/foo.zip")
- << QStringLiteral("1234") << 3
+ << QStringLiteral("1234") << 3 << QString()
<< QStringList {
QStringLiteral("-r"),
QStringLiteral("/tmp/foo.zip"),
QStringLiteral("-P1234"),
QStringLiteral("-3")
};
+
+ QTest::newRow("comp-method-bzip2")
+ << QStringLiteral("/tmp/foo.zip")
+ << QString() << 3 << QStringLiteral("bzip2")
+ << QStringList {
+ QStringLiteral("-r"),
+ QStringLiteral("/tmp/foo.zip"),
+ QStringLiteral("-3"),
+ QStringLiteral("-Zbzip2")
+ };
}
void CliZipTest::testAddArgs()
@@ -101,12 +113,14 @@ void CliZipTest::testAddArgs()
QStringLiteral("$Archive"),
QStringLiteral("$PasswordSwitch"),
QStringLiteral("$CompressionLevelSwitch"),
+ QStringLiteral("$CompressionMethodSwitch"),
QStringLiteral("$Files") };
QFETCH(QString, password);
QFETCH(int, compressionLevel);
+ QFETCH(QString, compressionMethod);
- QStringList replacedArgs = plugin->substituteAddVariables(addArgs, {}, password, false, compressionLevel, 0);
+ QStringList replacedArgs = plugin->substituteAddVariables(addArgs, {}, password, false, compressionLevel, 0, compressionMethod);
QFETCH(QStringList, expectedArgs);
QCOMPARE(replacedArgs, expectedArgs);
diff --git a/kerfuffle/archiveformat.cpp b/kerfuffle/archiveformat.cpp
index f35c7ae..a32b8ec 100644
--- a/kerfuffle/archiveformat.cpp
+++ b/kerfuffle/archiveformat.cpp
@@ -25,6 +25,8 @@
#include "archiveformat.h"
+#include <QJsonArray>
+
namespace Kerfuffle
{
@@ -40,7 +42,9 @@ ArchiveFormat::ArchiveFormat(const QMimeType& mimeType,
int defaultCompLevel,
bool supportsWriteComment,
bool supportsTesting,
- bool supportsMultiVolume) :
+ bool supportsMultiVolume,
+ QStringList compressionMethods,
+ QString defaultCompressionMethod) :
m_mimeType(mimeType),
m_encryptionType(encryptionType),
m_minCompressionLevel(minCompLevel),
@@ -48,7 +52,9 @@ ArchiveFormat::ArchiveFormat(const QMimeType& mimeType,
m_defaultCompressionLevel(defaultCompLevel),
m_supportsWriteComment(supportsWriteComment),
m_supportsTesting(supportsTesting),
- m_supportsMultiVolume(supportsMultiVolume)
+ m_supportsMultiVolume(supportsMultiVolume),
+ m_compressionMethods(compressionMethods),
+ m_defaultCompressionMethod(defaultCompressionMethod)
{
}
@@ -70,6 +76,13 @@ ArchiveFormat ArchiveFormat::fromMetadata(const QMimeType& mimeType, const KPlug
bool supportsTesting = formatProps[QStringLiteral("SupportsTesting")].toBool();
bool supportsMultiVolume = formatProps[QStringLiteral("SupportsMultiVolume")].toBool();
+ QStringList compressionMethods;
+ QJsonArray array = formatProps[QStringLiteral("CompressionMethods")].toArray();
+ foreach (const QJsonValue &value, array) {
+ compressionMethods.append(value.toString());
+ }
+ QString defaultCompMethod = formatProps[QStringLiteral("CompressionMethodDefault")].toString();
+
Archive::EncryptionType encType = Archive::Unencrypted;
if (formatProps[QStringLiteral("HeaderEncryption")].toBool()) {
encType = Archive::HeaderEncrypted;
@@ -77,7 +90,7 @@ ArchiveFormat ArchiveFormat::fromMetadata(const QMimeType& mimeType, const KPlug
encType = Archive::Encrypted;
}
- return ArchiveFormat(mimeType, encType, minCompLevel, maxCompLevel, defaultCompLevel, supportsWriteComment, supportsTesting, supportsMultiVolume);
+ return ArchiveFormat(mimeType, encType, minCompLevel, maxCompLevel, defaultCompLevel, supportsWriteComment, supportsTesting, supportsMultiVolume, compressionMethods, defaultCompMethod);
}
return ArchiveFormat();
@@ -123,4 +136,14 @@ bool ArchiveFormat::supportsMultiVolume() const
return m_supportsMultiVolume;
}
+QStringList ArchiveFormat::compressionMethods() const
+{
+ return m_compressionMethods;
+}
+
+QString ArchiveFormat::defaultCompressionMethod() const
+{
+ return m_defaultCompressionMethod;
+}
+
}
diff --git a/kerfuffle/archiveformat.h b/kerfuffle/archiveformat.h
index a9adf11..4e741aa 100644
--- a/kerfuffle/archiveformat.h
+++ b/kerfuffle/archiveformat.h
@@ -44,7 +44,9 @@ public:
int defaultCompLevel,
bool supportsWriteComment,
bool supportsTesting,
- bool suppportsMultiVolume);
+ bool suppportsMultiVolume,
+ QStringList compressionMethods,
+ QString defaultCompressionMethod);
/**
* @return The archive format of the given @p mimeType, according to the given @p metadata.
@@ -67,6 +69,8 @@ public:
bool supportsWriteComment() const;
bool supportsTesting() const;
bool supportsMultiVolume() const;
+ QStringList compressionMethods() const;
+ QString defaultCompressionMethod() const;
private:
QMimeType m_mimeType;
@@ -77,6 +81,8 @@ private:
bool m_supportsWriteComment;
bool m_supportsTesting;
bool m_supportsMultiVolume;
+ QStringList m_compressionMethods;
+ QString m_defaultCompressionMethod;
};
}
diff --git a/kerfuffle/cliinterface.cpp b/kerfuffle/cliinterface.cpp
index 59d6068..8749037 100644
--- a/kerfuffle/cliinterface.cpp
+++ b/kerfuffle/cliinterface.cpp
@@ -233,13 +233,15 @@ bool CliInterface::addFiles(const QList<Archive::Entry*> &files, const Archive::
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);
+ volumeSize,
+ compMethod);
return runProcess(m_param.value(AddProgram).toStringList(), args);
}
@@ -754,7 +756,7 @@ QStringList CliInterface::substituteExtractVariables(const QStringList &extractA
return args;
}
-QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, const QList<Archive::Entry*> &entries, const QString &password, bool encryptHeader, int compLevel, ulong volumeSize)
+QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, const QList<Archive::Entry*> &entries, const QString &password, bool encryptHeader, int compLevel, ulong volumeSize, QString compMethod)
{
// Required if we call this function from unit tests.
cacheParameterList();
@@ -778,6 +780,11 @@ QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, con
continue;
}
+ if (arg == QLatin1String("$CompressionMethodSwitch")) {
+ args << compressionMethodSwitch(compMethod);
+ continue;
+ }
+
if (arg == QLatin1String("$MultiVolumeSwitch")) {
args << multiVolumeSwitch(volumeSize);
continue;
@@ -1037,6 +1044,21 @@ QString CliInterface::compressionLevelSwitch(int level) const
return compLevelSwitch;
}
+QString CliInterface::compressionMethodSwitch(const QString &method) const
+{
+ if (method.isEmpty()) {
+ return QString();
+ }
+
+ Q_ASSERT(m_param.contains(CompressionMethodSwitch));
+ QString compMethodSwitch = m_param.value(CompressionMethodSwitch).toString();
+ Q_ASSERT(!compMethodSwitch.isEmpty());
+
+ compMethodSwitch.replace(QLatin1String("$CompressionMethod"), method);
+
+ return compMethodSwitch;
+}
+
QString CliInterface::multiVolumeSwitch(ulong volumeSize) const
{
// The maximum value we allow in the QDoubleSpinBox is 1000MB. Converted to
diff --git a/kerfuffle/cliinterface.h b/kerfuffle/cliinterface.h
index e44487e..d3e41c0 100644
--- a/kerfuffle/cliinterface.h
+++ b/kerfuffle/cliinterface.h
@@ -287,7 +287,8 @@ enum CliInterfaceParameters {
TestArgs,
TestPassedPattern,
MultiVolumeSwitch,
- MultiVolumeSuffix
+ MultiVolumeSuffix,
+ CompressionMethodSwitch
};
typedef QHash<int, QVariant> ParameterList;
@@ -335,7 +336,7 @@ public:
QStringList substituteListVariables(const QStringList &listArgs, const QString &password);
QStringList substituteExtractVariables(const QStringList &extractArgs, const QList<Archive::Entry*> &entries, bool preservePaths, const QString &password);
- QStringList substituteAddVariables(const QStringList &addArgs, const QList<Archive::Entry*> &entries, const QString &password, bool encryptHeader, int compLevel, ulong volumeSize);
+ QStringList substituteAddVariables(const QStringList &addArgs, const QList<Archive::Entry*> &entries, const QString &password, bool encryptHeader, int compLevel, ulong volumeSize, QString compMethod);
QStringList substituteMoveVariables(const QStringList &moveArgs, const QList<Archive::Entry*> &entriesWithoutChildren, const Archive::Entry *destination, const QString &password);
QStringList substituteDeleteVariables(const QStringList &deleteArgs, const QList<Archive::Entry*> &entries, const QString &password);
QStringList substituteCommentVariables(const QStringList &commentArgs, const QString &commentFile);
@@ -366,6 +367,7 @@ public:
*/
QString compressionLevelSwitch(int level) const;
+ virtual QString compressionMethodSwitch(const QString &method) const;
QString multiVolumeSwitch(ulong volumeSize) const;
/**
diff --git a/kerfuffle/compressionoptionswidget.cpp b/kerfuffle/compressionoptionswidget.cpp
index efdc964..b5dc25b 100644
--- a/kerfuffle/compressionoptionswidget.cpp
+++ b/kerfuffle/compressionoptionswidget.cpp
@@ -65,6 +65,9 @@ CompressionOptions CompressionOptionsWidget::commpressionOptions() const
// Convert to kilobytes.
opts[QStringLiteral("VolumeSize")] = QString::number(volumeSize());
}
+ if (!compMethodComboBox->currentText().isEmpty()) {
+ opts[QStringLiteral("CompressionMethod")] = compMethodComboBox->currentText();
+ }
return opts;
}
@@ -78,6 +81,11 @@ int CompressionOptionsWidget::compressionLevel() const
}
}
+QString CompressionOptionsWidget::compressionMethod() const
+{
+ return compMethodComboBox->currentText();
+}
+
ulong CompressionOptionsWidget::volumeSize() const
{
if (collapsibleMultiVolume->isEnabled() && multiVolumeCheckbox->isChecked()) {
@@ -132,14 +140,20 @@ void CompressionOptionsWidget::updateWidgets()
encryptHeaderCheckBox->setToolTip(QString());
}
-
+ collapsibleCompression->setEnabled(true);
if (archiveFormat.maxCompressionLevel() == 0) {
- collapsibleCompression->setEnabled(false);
- collapsibleCompression->setToolTip(i18n("It is not possible to set compression level for the %1 format.",
+ compLevelSlider->setEnabled(false);
+ lblCompLevel1->setEnabled(false);
+ lblCompLevel2->setEnabled(false);
+ lblCompLevel3->setEnabled(false);
+ compLevelSlider->setToolTip(i18n("It is not possible to set compression level for the %1 format.",
m_mimetype.comment()));
} else {
- collapsibleCompression->setEnabled(true);
- collapsibleCompression->setToolTip(QString());
+ compLevelSlider->setEnabled(true);
+ lblCompLevel1->setEnabled(true);
+ lblCompLevel2->setEnabled(true);
+ lblCompLevel3->setEnabled(true);
+ compLevelSlider->setToolTip(QString());
compLevelSlider->setMinimum(archiveFormat.minCompressionLevel());
compLevelSlider->setMaximum(archiveFormat.maxCompressionLevel());
if (m_opts.contains(QStringLiteral("CompressionLevel"))) {
@@ -149,6 +163,27 @@ void CompressionOptionsWidget::updateWidgets()
}
}
+ if (archiveFormat.compressionMethods().isEmpty()) {
+ lblCompMethod->setEnabled(false);
+ compMethodComboBox->setEnabled(false);
+ compMethodComboBox->setToolTip(i18n("It is not possible to set compression method for the %1 format.",
+ m_mimetype.comment()));
+ compMethodComboBox->clear();
+ } else {
+ lblCompMethod->setEnabled(true);
+ compMethodComboBox->setEnabled(true);
+ 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());
+ } else {
+ compMethodComboBox->setCurrentText(archiveFormat.defaultCompressionMethod());
+ }
+ }
+ collapsibleCompression->setEnabled(compLevelSlider->isEnabled() || compMethodComboBox->isEnabled());
+
if (archiveFormat.supportsMultiVolume()) {
collapsibleMultiVolume->setEnabled(true);
collapsibleMultiVolume->setToolTip(QString());
diff --git a/kerfuffle/compressionoptionswidget.h b/kerfuffle/compressionoptionswidget.h
index 00b95f8..9d120df 100644
--- a/kerfuffle/compressionoptionswidget.h
+++ b/kerfuffle/compressionoptionswidget.h
@@ -45,6 +45,7 @@ public:
explicit CompressionOptionsWidget(QWidget *parent = Q_NULLPTR,
const CompressionOptions &opts = QHash<QString, QVariant>());
int compressionLevel() const;
+ QString compressionMethod() const;
ulong volumeSize() const;
QString password() const;
CompressionOptions commpressionOptions() const;
diff --git a/kerfuffle/compressionoptionswidget.ui b/kerfuffle/compressionoptionswidget.ui
index 3a17156..41732c7 100644
--- a/kerfuffle/compressionoptionswidget.ui
+++ b/kerfuffle/compressionoptionswidget.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>401</width>
+ <width>402</width>
<height>90</height>
</rect>
</property>
@@ -23,15 +23,15 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="1">
- <widget class="QLabel" name="label_6">
+ <item row="1" column="1">
+ <widget class="QLabel" name="lblCompLevel2">
<property name="text">
<string>Min</string>
</property>
</widget>
</item>
- <item row="0" column="2">
- <widget class="QLabel" name="label_7">
+ <item row="1" column="2">
+ <widget class="QLabel" name="lblCompLevel3">
<property name="text">
<string>Max</string>
</property>
@@ -40,8 +40,8 @@
</property>
</widget>
</item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_5">
+ <item row="2" column="0">
+ <widget class="QLabel" name="lblCompLevel1">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
@@ -51,9 +51,12 @@
<property name="text">
<string>Level:</string>
</property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
</widget>
</item>
- <item row="1" column="1" colspan="2">
+ <item row="2" column="1" colspan="2">
<widget class="QSlider" name="compLevelSlider">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -84,6 +87,19 @@
</property>
</widget>
</item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="compMethodComboBox"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="lblCompMethod">
+ <property name="text">
+ <string>Method:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
@@ -202,15 +218,15 @@
</widget>
<customwidgets>
<customwidget>
- <class>KCollapsibleGroupBox</class>
+ <class>KNewPasswordWidget</class>
<extends>QWidget</extends>
- <header>kcollapsiblegroupbox.h</header>
+ <header>knewpasswordwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
- <class>KNewPasswordWidget</class>
+ <class>KCollapsibleGroupBox</class>
<extends>QWidget</extends>
- <header>knewpasswordwidget.h</header>
+ <header>kcollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
diff --git a/kerfuffle/createdialog.cpp b/kerfuffle/createdialog.cpp
index e4ef8bf..d42f4d2 100644
--- a/kerfuffle/createdialog.cpp
+++ b/kerfuffle/createdialog.cpp
@@ -151,6 +151,11 @@ int CreateDialog::compressionLevel() const
return m_ui->optionsWidget->compressionLevel();
}
+QString CreateDialog::compressionMethod() const
+{
+ return m_ui->optionsWidget->compressionMethod();
+}
+
ulong CreateDialog::volumeSize() const
{
return m_ui->optionsWidget->volumeSize();
diff --git a/kerfuffle/createdialog.h b/kerfuffle/createdialog.h
index e4ad1ef..316f5a0 100644
--- a/kerfuffle/createdialog.h
+++ b/kerfuffle/createdialog.h
@@ -59,6 +59,7 @@ public:
QMimeType currentMimeType() const;
bool setMimeType(const QString &mimeTypeName);
int compressionLevel() const;
+ QString compressionMethod() const;
ulong volumeSize() const;
/**
diff --git a/part/part.cpp b/part/part.cpp
index 85df0d4..2ebcc31 100644
--- a/part/part.cpp
+++ b/part/part.cpp
@@ -1335,6 +1335,9 @@ void Part::slotAddFiles()
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")];
}
@@ -1343,6 +1346,10 @@ void Part::slotAddFiles()
opts = m_model->archive()->compressionOptions();
}
+ if (m_model->archive()->property("compressionMethods").toStringList().size() == 1) {
+ opts[QStringLiteral("CompressionMethod")] = m_model->archive()->property("compressionMethods").toStringList().first();
+ }
+
QString dialogTitle = i18nc("@title:window", "Add Files");
const Archive::Entry *destination = Q_NULLPTR;
if (m_view->selectionModel()->selectedRows().count() == 1) {
diff --git a/plugins/cli7zplugin/cliplugin.cpp b/plugins/cli7zplugin/cliplugin.cpp
index 1d41973..c05b3b9 100644
--- a/plugins/cli7zplugin/cliplugin.cpp
+++ b/plugins/cli7zplugin/cliplugin.cpp
@@ -83,6 +83,7 @@ ParameterList CliPlugin::parameterList() const
<< QStringLiteral("$Archive")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$CompressionLevelSwitch")
+ << QStringLiteral("$CompressionMethodSwitch")
<< QStringLiteral("$MultiVolumeSwitch")
<< QStringLiteral("$Files");
p[MoveArgs] = QStringList() << QStringLiteral("rn")
@@ -115,6 +116,10 @@ ParameterList CliPlugin::parameterList() const
p[DiskFullPatterns] = QStringList() << QStringLiteral("No space left on device");
p[MultiVolumeSwitch] = QStringLiteral("-v$VolumeSizek");
p[MultiVolumeSuffix] = QStringList() << QStringLiteral("$Suffix.001");
+ QMap<QString,QVariant> compMethodMap;
+ compMethodMap[QStringLiteral("zip")] = QStringLiteral("-mm=$CompressionMethod");
+ compMethodMap[QStringLiteral("7z")] = QStringLiteral("-m0=$CompressionMethod");
+ p[CompressionMethodSwitch] = compMethodMap;
}
return p;
@@ -306,4 +311,24 @@ QStringList CliPlugin::passwordHeaderSwitch(const QString& password) const
return passwordHeaderSwitch;
}
+QString CliPlugin::compressionMethodSwitch(const QString &method) const
+{
+ if (method.isEmpty()) {
+ return QString();
+ }
+
+ Q_ASSERT(!filename().isEmpty());
+ Q_ASSERT(m_param.contains(CompressionMethodSwitch));
+
+ QMap<QString,QVariant> switches = m_param.value(CompressionMethodSwitch).toMap();
+ Q_ASSERT(!switches.isEmpty());
+
+ QString compMethodSwitch;
+
+ compMethodSwitch = switches[QFileInfo(filename()).suffix().toLower()].toString();
+ compMethodSwitch.replace(QLatin1String("$CompressionMethod"), method);
+
+ return compMethodSwitch;
+}
+
#include "cliplugin.moc"
diff --git a/plugins/cli7zplugin/cliplugin.h b/plugins/cli7zplugin/cliplugin.h
index 27c33c5..c2b8920 100644
--- a/plugins/cli7zplugin/cliplugin.h
+++ b/plugins/cli7zplugin/cliplugin.h
@@ -44,6 +44,7 @@ public:
* @return The password header-switch with the given @p password.
*/
virtual QStringList passwordHeaderSwitch(const QString& password) const Q_DECL_OVERRIDE;
+ virtual QString compressionMethodSwitch(const QString &method) const Q_DECL_OVERRIDE;
private:
enum ArchiveType {
diff --git a/plugins/cli7zplugin/kerfuffle_cli7z.json.cmake b/plugins/cli7zplugin/kerfuffle_cli7z.json.cmake
index 3034441..d4d6bad 100644
--- a/plugins/cli7zplugin/kerfuffle_cli7z.json.cmake
+++ b/plugins/cli7zplugin/kerfuffle_cli7z.json.cmake
@@ -12,7 +12,7 @@
"Name[es]": "Complemento de archivo 7zip",
"Name[et]": "7zip arhiivi plugin",
"Name[fi]": "7zip-pakkaustuki",
- "Name[fr]": "Module externe d'archive « 7zip »",
+ "Name[fr]": "Module externe d'archive « 7zip »",
"Name[gl]": "Complemento de arquivo de 7zip",
"Name[he]": "תוסף ארכיוני 7zip",
"Name[it]": "Estensione per archivi 7zip",
@@ -52,7 +52,16 @@
"CompressionLevelMin": 0,
"HeaderEncryption": true,
"SupportsMultiVolume": true,
- "SupportsTesting": true
+ "SupportsTesting": true,
+ "CompressionMethods": [
+ "BZip2",
+ "Copy",
+ "Deflate",
+ "LZMA",
+ "LZMA2",
+ "PPMd"
+ ],
+ "CompressionMethodDefault": "LZMA2"
},
"application/zip": {
"CompressionLevelDefault": 5,
@@ -60,6 +69,15 @@
"CompressionLevelMin": 0,
"Encryption": true,
"SupportsMultiVolume": true,
- "SupportsTesting": true
+ "SupportsTesting": true,
+ "CompressionMethods": [
+ "BZip2",
+ "Copy",
+ "Deflate",
+ "Deflate64",
+ "LZMA",
+ "PPMd"
+ ],
+ "CompressionMethodDefault": "Deflate"
}
-} \ No newline at end of file
+}
diff --git a/plugins/clirarplugin/cliplugin.cpp b/plugins/clirarplugin/cliplugin.cpp
index ac13a43..3bf786b 100644
--- a/plugins/clirarplugin/cliplugin.cpp
+++ b/plugins/clirarplugin/cliplugin.cpp
@@ -104,6 +104,7 @@ ParameterList CliPlugin::parameterList() const
<< QStringLiteral( "$Archive" )
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$CompressionLevelSwitch")
+ << QStringLiteral("$CompressionMethodSwitch")
<< QStringLiteral("$MultiVolumeSwitch")
<< QStringLiteral( "$Files" );
p[MoveArgs] = QStringList() << QStringLiteral( "rn" )
@@ -129,6 +130,7 @@ ParameterList CliPlugin::parameterList() const
// called name.part1.rar and other times name.part01.rar.
p[MultiVolumeSuffix] = QStringList() << QStringLiteral("part01.$Suffix")
<< QStringLiteral("part1.$Suffix");
+ p[CompressionMethodSwitch] = QStringLiteral("-ma$CompressionMethod");
}
return p;
@@ -546,4 +548,22 @@ void CliPlugin::ignoreLines(int lines, ParseState nextState)
m_parseState = nextState;
}
+QString CliPlugin::compressionMethodSwitch(const QString &method) const
+{
+ if (method.isEmpty()) {
+ return QString();
+ }
+
+ Q_ASSERT(m_param.contains(CompressionMethodSwitch));
+ QString compMethodSwitch = m_param.value(CompressionMethodSwitch).toString();
+ Q_ASSERT(!compMethodSwitch.isEmpty());
+ compMethodSwitch.replace(QLatin1String("$CompressionMethod"), method);
+
+ // This is needed for because the user-visible strings are different from the
+ // ones needed by the switch (e.g. RAR4 vs 4).
+ compMethodSwitch.remove(QLatin1String("RAR"));
+
+ return compMethodSwitch;
+}
+
#include "cliplugin.moc"
diff --git a/plugins/clirarplugin/cliplugin.h b/plugins/clirarplugin/cliplugin.h
index 7340e6f..6cc30f7 100644
--- a/plugins/clirarplugin/cliplugin.h
+++ b/plugins/clirarplugin/cliplugin.h
@@ -38,6 +38,8 @@ public:
virtual Kerfuffle::ParameterList parameterList() const Q_DECL_OVERRIDE;
virtual bool readListLine(const QString &line) Q_DECL_OVERRIDE;
+ virtual QString compressionMethodSwitch(const QString &method) const Q_DECL_OVERRIDE;
+
private:
enum ParseState {
diff --git a/plugins/clirarplugin/kerfuffle_clirar.json.cmake b/plugins/clirarplugin/kerfuffle_clirar.json.cmake
index 9abd05c..77717b0 100644
--- a/plugins/clirarplugin/kerfuffle_clirar.json.cmake
+++ b/plugins/clirarplugin/kerfuffle_clirar.json.cmake
@@ -12,7 +12,7 @@
"Name[es]": "Complemento de archivo RAR",
"Name[et]": "RAR-arhiivi plugin",
"Name[fi]": "RAR-pakkaustuki",
- "Name[fr]": "Module externe d'archive « RAR »",
+ "Name[fr]": "Module externe d'archive « RAR »",
"Name[gl]": "Complemento de arquivo RAR",
"Name[he]": "תוסף ארכיוני RAR",
"Name[it]": "Estensione per archivi RAR",
@@ -54,7 +54,12 @@
"HeaderEncryption": true,
"SupportsMultiVolume": true,
"SupportsTesting": true,
- "SupportsWriteComment": true
+ "SupportsWriteComment": true,
+ "CompressionMethods": [
+ "RAR4",
+ "RAR5"
+ ],
+ "CompressionMethodDefault": "RAR4"
},
"application/x-rar": {
"CompressionLevelDefault": 3,
@@ -63,6 +68,11 @@
"HeaderEncryption": true,
"SupportsMultiVolume": true,
"SupportsTesting": true,
- "SupportsWriteComment": true
+ "SupportsWriteComment": true,
+ "CompressionMethods": [
+ "RAR4",
+ "RAR5"
+ ],
+ "CompressionMethodDefault": "RAR4"
}
-} \ No newline at end of file
+}
diff --git a/plugins/clizipplugin/cliplugin.cpp b/plugins/clizipplugin/cliplugin.cpp
index 29bc81d..0a8f381 100644
--- a/plugins/clizipplugin/cliplugin.cpp
+++ b/plugins/clizipplugin/cliplugin.cpp
@@ -116,6 +116,7 @@ ParameterList CliPlugin::parameterList() const
<< QStringLiteral("$Archive")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$CompressionLevelSwitch")
+ << QStringLiteral("$CompressionMethodSwitch")
<< QStringLiteral("$Files");
p[PasswordPromptPattern] = QStringLiteral(" password: ");
@@ -128,6 +129,7 @@ ParameterList CliPlugin::parameterList() const
<< QStringLiteral("$Archive")
<< QStringLiteral("$PasswordSwitch");
p[TestPassedPattern] = QStringLiteral("^No errors detected in compressed data of ");
+ p[CompressionMethodSwitch] = QStringLiteral("-Z$CompressionMethod");
}
return p;
}
@@ -290,6 +292,22 @@ void CliPlugin::finishMoving(bool result)
cleanUp();
}
+QString CliPlugin::compressionMethodSwitch(const QString &method) const
+{
+ if (method.isEmpty()) {
+ return QString();
+ }
+
+ Q_ASSERT(m_param.contains(CompressionMethodSwitch));
+ QString compMethodSwitch = m_param.value(CompressionMethodSwitch).toString();
+ Q_ASSERT(!compMethodSwitch.isEmpty());
+
+ // We use capitalization of methods in UI, but CLI requires lowercase.
+ compMethodSwitch.replace(QLatin1String("$CompressionMethod"), method.toLower());
+
+ return compMethodSwitch;
+}
+
QString CliPlugin::convertCompressionMethod(const QString &method)
{
if (method == QLatin1String("stor")) {
diff --git a/plugins/clizipplugin/cliplugin.h b/plugins/clizipplugin/cliplugin.h
index 2d44b07..aacd16c 100644
--- a/plugins/clizipplugin/cliplugin.h
+++ b/plugins/clizipplugin/cliplugin.h
@@ -44,6 +44,8 @@ public:
virtual bool moveFiles(const QList<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions& options) Q_DECL_OVERRIDE;
virtual int moveRequiredSignals() const Q_DECL_OVERRIDE;
+ virtual QString compressionMethodSwitch(const QString &method) const Q_DECL_OVERRIDE;
+
private slots:
void continueMoving(bool result);
diff --git a/plugins/clizipplugin/kerfuffle_clizip.json.cmake b/plugins/clizipplugin/kerfuffle_clizip.json.cmake
index 57cbc6d..bddfb5b 100644
--- a/plugins/clizipplugin/kerfuffle_clizip.json.cmake
+++ b/plugins/clizipplugin/kerfuffle_clizip.json.cmake
@@ -12,7 +12,7 @@
"Name[es]": "Complemento de archivo ZIP",
"Name[et]": "ZIP-arhiivi plugin",
"Name[fi]": "ZIP-pakkaustuki",
- "Name[fr]": "Module externe d'archive « zip »",
+ "Name[fr]": "Module externe d'archive « zip »",
"Name[gl]": "Complemento de arquivo ZIP",
"Name[he]": "תוסף ארכיוני ZIP",
"Name[it]": "Estensione per archivi ZIP",
@@ -59,6 +59,12 @@
"CompressionLevelMax": 9,
"CompressionLevelMin": 0,
"Encryption": true,
- "SupportsTesting": true
+ "SupportsTesting": true,
+ "CompressionMethods": [
+ "BZip2",
+ "Deflate",
+ "Store"
+ ],
+ "CompressionMethodDefault": "deflate"
}
-} \ No newline at end of file
+}