diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -304,6 +304,9 @@ 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 --- a/autotests/kerfuffle/addtoarchivetest.cpp +++ b/autotests/kerfuffle/addtoarchivetest.cpp @@ -153,14 +153,14 @@ << QStringLiteral("data.zip") << 3ULL << 1ULL; - QTest::newRow("compress here (as TAR) - dir with special name (see #365798)") << QStringLiteral("tar.gz") << Archive::Unencrypted << QStringList {QFINDTESTDATA("data/test%dir")} << 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 --- a/autotests/plugins/cli7zplugin/cli7ztest.cpp +++ b/autotests/plugins/cli7zplugin/cli7ztest.cpp @@ -266,48 +266,63 @@ QTest::addColumn("password"); QTest::addColumn("encryptHeader"); QTest::addColumn("compressionLevel"); + QTest::addColumn("compressionMethod"); QTest::addColumn("volumeSize"); QTest::addColumn("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,15 +335,17 @@ QStringLiteral("$Archive"), QStringLiteral("$PasswordSwitch"), QStringLiteral("$CompressionLevelSwitch"), + QStringLiteral("$CompressionMethodSwitch"), QStringLiteral("$MultiVolumeSwitch"), QStringLiteral("$Files") }; QFETCH(QString, password); 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 --- a/autotests/plugins/clirarplugin/clirartest.cpp +++ b/autotests/plugins/clirarplugin/clirartest.cpp @@ -324,21 +324,23 @@ QTest::addColumn("password"); QTest::addColumn("encryptHeader"); QTest::addColumn("compressionLevel"); + QTest::addColumn("compressionMethod"); QTest::addColumn("volumeSize"); QTest::addColumn("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 @@ 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 @@ 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 @@ 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 --- a/autotests/plugins/clizipplugin/cliziptest.cpp +++ b/autotests/plugins/clizipplugin/cliziptest.cpp @@ -69,26 +69,38 @@ QTest::addColumn("archiveName"); QTest::addColumn("password"); QTest::addColumn("compressionLevel"); + QTest::addColumn("compressionMethod"); QTest::addColumn("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 @@ 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.h b/kerfuffle/archiveformat.h --- a/kerfuffle/archiveformat.h +++ b/kerfuffle/archiveformat.h @@ -44,7 +44,9 @@ 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 @@ bool supportsWriteComment() const; bool supportsTesting() const; bool supportsMultiVolume() const; + QStringList compressionMethods() const; + QString defaultCompressionMethod() const; private: QMimeType m_mimeType; @@ -77,6 +81,8 @@ bool m_supportsWriteComment; bool m_supportsTesting; bool m_supportsMultiVolume; + QStringList m_compressionMethods; + QString m_defaultCompressionMethod; }; } diff --git a/kerfuffle/archiveformat.cpp b/kerfuffle/archiveformat.cpp --- a/kerfuffle/archiveformat.cpp +++ b/kerfuffle/archiveformat.cpp @@ -25,6 +25,8 @@ #include "archiveformat.h" +#include + namespace Kerfuffle { @@ -40,15 +42,19 @@ int defaultCompLevel, bool supportsWriteComment, bool supportsTesting, - bool supportsMultiVolume) : + bool supportsMultiVolume, + QStringList compressionMethods, + QString defaultCompressionMethod) : m_mimeType(mimeType), m_encryptionType(encryptionType), m_minCompressionLevel(minCompLevel), m_maxCompressionLevel(maxCompLevel), m_defaultCompressionLevel(defaultCompLevel), m_supportsWriteComment(supportsWriteComment), m_supportsTesting(supportsTesting), - m_supportsMultiVolume(supportsMultiVolume) + m_supportsMultiVolume(supportsMultiVolume), + m_compressionMethods(compressionMethods), + m_defaultCompressionMethod(defaultCompressionMethod) { } @@ -70,14 +76,21 @@ 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; } else if (formatProps[QStringLiteral("Encryption")].toBool()) { 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 @@ return m_supportsMultiVolume; } +QStringList ArchiveFormat::compressionMethods() const +{ + return m_compressionMethods; +} + +QString ArchiveFormat::defaultCompressionMethod() const +{ + return m_defaultCompressionMethod; +} + } diff --git a/kerfuffle/cliinterface.h b/kerfuffle/cliinterface.h --- a/kerfuffle/cliinterface.h +++ b/kerfuffle/cliinterface.h @@ -287,7 +287,8 @@ TestArgs, TestPassedPattern, MultiVolumeSwitch, - MultiVolumeSuffix + MultiVolumeSuffix, + CompressionMethodSwitch }; typedef QHash ParameterList; @@ -335,7 +336,7 @@ QStringList substituteListVariables(const QStringList &listArgs, const QString &password); QStringList substituteExtractVariables(const QStringList &extractArgs, const QList &entries, bool preservePaths, const QString &password); - QStringList substituteAddVariables(const QStringList &addArgs, const QList &entries, const QString &password, bool encryptHeader, int compLevel, ulong volumeSize); + QStringList substituteAddVariables(const QStringList &addArgs, const QList &entries, const QString &password, bool encryptHeader, int compLevel, ulong volumeSize, QString compMethod); QStringList substituteMoveVariables(const QStringList &moveArgs, const QList &entriesWithoutChildren, const Archive::Entry *destination, const QString &password); QStringList substituteDeleteVariables(const QStringList &deleteArgs, const QList &entries, const QString &password); QStringList substituteCommentVariables(const QStringList &commentArgs, const QString &commentFile); @@ -366,6 +367,7 @@ */ QString compressionLevelSwitch(int level) const; + virtual QString compressionMethodSwitch(const QString &method) const; QString multiVolumeSwitch(ulong volumeSize) const; /** diff --git a/kerfuffle/cliinterface.cpp b/kerfuffle/cliinterface.cpp --- a/kerfuffle/cliinterface.cpp +++ b/kerfuffle/cliinterface.cpp @@ -233,13 +233,15 @@ 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 @@ return args; } -QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, const QList &entries, const QString &password, bool encryptHeader, int compLevel, ulong volumeSize) +QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, const QList &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 @@ continue; } + if (arg == QLatin1String("$CompressionMethodSwitch")) { + args << compressionMethodSwitch(compMethod); + continue; + } + if (arg == QLatin1String("$MultiVolumeSwitch")) { args << multiVolumeSwitch(volumeSize); continue; @@ -1037,6 +1044,21 @@ 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/compressionoptionswidget.h b/kerfuffle/compressionoptionswidget.h --- a/kerfuffle/compressionoptionswidget.h +++ b/kerfuffle/compressionoptionswidget.h @@ -45,6 +45,7 @@ explicit CompressionOptionsWidget(QWidget *parent = Q_NULLPTR, const CompressionOptions &opts = QHash()); int compressionLevel() const; + QString compressionMethod() const; ulong volumeSize() const; QString password() const; CompressionOptions commpressionOptions() const; diff --git a/kerfuffle/compressionoptionswidget.cpp b/kerfuffle/compressionoptionswidget.cpp --- a/kerfuffle/compressionoptionswidget.cpp +++ b/kerfuffle/compressionoptionswidget.cpp @@ -65,6 +65,9 @@ // Convert to kilobytes. opts[QStringLiteral("VolumeSize")] = QString::number(volumeSize()); } + if (!compMethodComboBox->currentText().isEmpty()) { + opts[QStringLiteral("CompressionMethod")] = compMethodComboBox->currentText(); + } return opts; } @@ -78,6 +81,11 @@ } } +QString CompressionOptionsWidget::compressionMethod() const +{ + return compMethodComboBox->currentText(); +} + ulong CompressionOptionsWidget::volumeSize() const { if (collapsibleMultiVolume->isEnabled() && multiVolumeCheckbox->isChecked()) { @@ -132,14 +140,20 @@ 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 @@ } } + 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.ui b/kerfuffle/compressionoptionswidget.ui --- a/kerfuffle/compressionoptionswidget.ui +++ b/kerfuffle/compressionoptionswidget.ui @@ -6,7 +6,7 @@ 0 0 - 401 + 402 90 @@ -23,25 +23,25 @@ false - - + + Min - - + + Max Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + 1 @@ -51,9 +51,12 @@ Level: + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + - + @@ -84,6 +87,19 @@ + + + + + + + Method: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + @@ -202,15 +218,15 @@ - KCollapsibleGroupBox + KNewPasswordWidget QWidget -
kcollapsiblegroupbox.h
+
knewpasswordwidget.h
1
- KNewPasswordWidget + KCollapsibleGroupBox QWidget -
knewpasswordwidget.h
+
kcollapsiblegroupbox.h
1
diff --git a/kerfuffle/createdialog.h b/kerfuffle/createdialog.h --- a/kerfuffle/createdialog.h +++ b/kerfuffle/createdialog.h @@ -59,6 +59,7 @@ QMimeType currentMimeType() const; bool setMimeType(const QString &mimeTypeName); int compressionLevel() const; + QString compressionMethod() const; ulong volumeSize() const; /** diff --git a/kerfuffle/createdialog.cpp b/kerfuffle/createdialog.cpp --- a/kerfuffle/createdialog.cpp +++ b/kerfuffle/createdialog.cpp @@ -151,6 +151,11 @@ 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/part/part.cpp b/part/part.cpp --- a/part/part.cpp +++ b/part/part.cpp @@ -1335,14 +1335,21 @@ 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(); } + 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.h b/plugins/cli7zplugin/cliplugin.h --- a/plugins/cli7zplugin/cliplugin.h +++ b/plugins/cli7zplugin/cliplugin.h @@ -44,6 +44,7 @@ * @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/cliplugin.cpp b/plugins/cli7zplugin/cliplugin.cpp --- a/plugins/cli7zplugin/cliplugin.cpp +++ b/plugins/cli7zplugin/cliplugin.cpp @@ -83,6 +83,7 @@ << QStringLiteral("$Archive") << QStringLiteral("$PasswordSwitch") << QStringLiteral("$CompressionLevelSwitch") + << QStringLiteral("$CompressionMethodSwitch") << QStringLiteral("$MultiVolumeSwitch") << QStringLiteral("$Files"); p[MoveArgs] = QStringList() << QStringLiteral("rn") @@ -115,6 +116,10 @@ p[DiskFullPatterns] = QStringList() << QStringLiteral("No space left on device"); p[MultiVolumeSwitch] = QStringLiteral("-v$VolumeSizek"); p[MultiVolumeSuffix] = QStringList() << QStringLiteral("$Suffix.001"); + QMap compMethodMap; + compMethodMap[QStringLiteral("zip")] = QStringLiteral("-mm=$CompressionMethod"); + compMethodMap[QStringLiteral("7z")] = QStringLiteral("-m0=$CompressionMethod"); + p[CompressionMethodSwitch] = compMethodMap; } return p; @@ -306,4 +311,24 @@ 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 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/kerfuffle_cli7z.json.cmake b/plugins/cli7zplugin/kerfuffle_cli7z.json.cmake --- 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,14 +52,32 @@ "CompressionLevelMin": 0, "HeaderEncryption": true, "SupportsMultiVolume": true, - "SupportsTesting": true + "SupportsTesting": true, + "CompressionMethods": [ + "BZip2", + "Copy", + "Deflate", + "LZMA", + "LZMA2", + "PPMd" + ], + "CompressionMethodDefault": "LZMA2" }, "application/zip": { "CompressionLevelDefault": 5, "CompressionLevelMax": 9, "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.h b/plugins/clirarplugin/cliplugin.h --- a/plugins/clirarplugin/cliplugin.h +++ b/plugins/clirarplugin/cliplugin.h @@ -38,6 +38,8 @@ 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/cliplugin.cpp b/plugins/clirarplugin/cliplugin.cpp --- a/plugins/clirarplugin/cliplugin.cpp +++ b/plugins/clirarplugin/cliplugin.cpp @@ -104,6 +104,7 @@ << QStringLiteral( "$Archive" ) << QStringLiteral("$PasswordSwitch") << QStringLiteral("$CompressionLevelSwitch") + << QStringLiteral("$CompressionMethodSwitch") << QStringLiteral("$MultiVolumeSwitch") << QStringLiteral( "$Files" ); p[MoveArgs] = QStringList() << QStringLiteral( "rn" ) @@ -129,6 +130,7 @@ // 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 @@ 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/kerfuffle_clirar.json.cmake b/plugins/clirarplugin/kerfuffle_clirar.json.cmake --- 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,15 +54,25 @@ "HeaderEncryption": true, "SupportsMultiVolume": true, "SupportsTesting": true, - "SupportsWriteComment": true + "SupportsWriteComment": true, + "CompressionMethods": [ + "RAR4", + "RAR5" + ], + "CompressionMethodDefault": "RAR4" }, "application/x-rar": { "CompressionLevelDefault": 3, "CompressionLevelMax": 5, "CompressionLevelMin": 0, "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.h b/plugins/clizipplugin/cliplugin.h --- a/plugins/clizipplugin/cliplugin.h +++ b/plugins/clizipplugin/cliplugin.h @@ -44,6 +44,8 @@ virtual bool moveFiles(const QList &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/cliplugin.cpp b/plugins/clizipplugin/cliplugin.cpp --- a/plugins/clizipplugin/cliplugin.cpp +++ b/plugins/clizipplugin/cliplugin.cpp @@ -116,6 +116,7 @@ << QStringLiteral("$Archive") << QStringLiteral("$PasswordSwitch") << QStringLiteral("$CompressionLevelSwitch") + << QStringLiteral("$CompressionMethodSwitch") << QStringLiteral("$Files"); p[PasswordPromptPattern] = QStringLiteral(" password: "); @@ -128,6 +129,7 @@ << 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 @@ 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/kerfuffle_clizip.json.cmake b/plugins/clizipplugin/kerfuffle_clizip.json.cmake --- 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 +}