Commit 8a770f7b authored by Ragnar Thomsen's avatar Ragnar Thomsen
Browse files

Add support for compression level in CliPlugins

Support for passing compression level was implemented for the cli-based
plugins. The user-interface elements to actually set the level are not
yet in place.

Differential Revision: D1268
parent 62deecef
......@@ -229,33 +229,37 @@ void Cli7zTest::testAddArgs_data()
QTest::addColumn<QString>("archiveName");
QTest::addColumn<QString>("password");
QTest::addColumn<bool>("encryptHeader");
QTest::addColumn<int>("compressionLevel");
QTest::addColumn<QStringList>("expectedArgs");
QTest::newRow("unencrypted")
<< QStringLiteral("/tmp/foo.7z")
<< QString() << false
<< QString() << false << 5
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.7z")
QStringLiteral("/tmp/foo.7z"),
QStringLiteral("-mx=5")
};
QTest::newRow("encrypted")
<< QStringLiteral("/tmp/foo.7z")
<< QStringLiteral("1234") << false
<< QStringLiteral("1234") << false << 5
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.7z"),
QStringLiteral("-p1234")
QStringLiteral("-p1234"),
QStringLiteral("-mx=5")
};
QTest::newRow("header-encrypted")
<< QStringLiteral("/tmp/foo.7z")
<< QStringLiteral("1234") << true
<< QStringLiteral("1234") << true << 5
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.7z"),
QStringLiteral("-p1234"),
QStringLiteral("-mhe=on")
QStringLiteral("-mhe=on"),
QStringLiteral("-mx=5")
};
}
......@@ -268,12 +272,14 @@ void Cli7zTest::testAddArgs()
const QStringList addArgs = { QStringLiteral("a"),
QStringLiteral("$Archive"),
QStringLiteral("$PasswordSwitch"),
QStringLiteral("$CompressionLevelSwitch"),
QStringLiteral("$Files") };
QFETCH(QString, password);
QFETCH(bool, encryptHeader);
QFETCH(int, compressionLevel);
QStringList replacedArgs = plugin->substituteAddVariables(addArgs, {}, QDir::current(), password, encryptHeader);
QStringList replacedArgs = plugin->substituteAddVariables(addArgs, {}, QDir::current(), password, encryptHeader, compressionLevel);
QFETCH(QStringList, expectedArgs);
QCOMPARE(replacedArgs, expectedArgs);
......
......@@ -263,32 +263,36 @@ void CliRarTest::testAddArgs_data()
QTest::addColumn<QString>("archiveName");
QTest::addColumn<QString>("password");
QTest::addColumn<bool>("encryptHeader");
QTest::addColumn<int>("compressionLevel");
QTest::addColumn<QStringList>("expectedArgs");
QTest::newRow("unencrypted")
<< QStringLiteral("/tmp/foo.rar")
<< QString() << false
<< QString() << false << 3
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.rar")
QStringLiteral("/tmp/foo.rar"),
QStringLiteral("-m3")
};
QTest::newRow("encrypted")
<< QStringLiteral("/tmp/foo.rar")
<< QStringLiteral("1234") << false
<< QStringLiteral("1234") << false << 3
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.rar"),
QStringLiteral("-p1234")
QStringLiteral("-p1234"),
QStringLiteral("-m3")
};
QTest::newRow("header-encrypted")
<< QStringLiteral("/tmp/foo.rar")
<< QStringLiteral("1234") << true
<< QStringLiteral("1234") << true << 3
<< QStringList {
QStringLiteral("a"),
QStringLiteral("/tmp/foo.rar"),
QStringLiteral("-hp1234")
QStringLiteral("-hp1234"),
QStringLiteral("-m3")
};
}
......@@ -301,12 +305,14 @@ void CliRarTest::testAddArgs()
const QStringList addArgs = { QStringLiteral("a"),
QStringLiteral("$Archive"),
QStringLiteral("$PasswordSwitch"),
QStringLiteral("$CompressionLevelSwitch"),
QStringLiteral("$Files") };
QFETCH(QString, password);
QFETCH(bool, encryptHeader);
QFETCH(int, compressionLevel);
QStringList replacedArgs = rarPlugin->substituteAddVariables(addArgs, {}, QDir::current(), password, encryptHeader);
QStringList replacedArgs = rarPlugin->substituteAddVariables(addArgs, {}, QDir::current(), password, encryptHeader, compressionLevel);
QFETCH(QStringList, expectedArgs);
QCOMPARE(replacedArgs, expectedArgs);
......
......@@ -256,7 +256,8 @@ bool CliInterface::addFiles(const QStringList & files, const CompressionOptions&
files,
workDir,
password(),
isHeaderEncryptionEnabled());
isHeaderEncryptionEnabled(),
options.value(QStringLiteral("CompressionLevel")).toInt());
if (!runProcess(m_param.value(AddProgram).toStringList(), args)) {
failOperation();
......@@ -627,7 +628,7 @@ QStringList CliInterface::substituteCopyVariables(const QStringList &extractArgs
return args;
}
QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QDir &workDir, const QString &password, bool encryptHeader)
QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QDir &workDir, const QString &password, bool encryptHeader, int compLevel)
{
// Required if we call this function from unit tests.
cacheParameterList();
......@@ -646,6 +647,11 @@ QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, con
continue;
}
if (arg == QLatin1String("$CompressionLevelSwitch")) {
args << compressionLevelSwitch(compLevel);
continue;
}
if (arg == QLatin1String("$Files")) {
args << addFilesList(files, workDir);
continue;
......@@ -710,6 +716,19 @@ QStringList CliInterface::passwordSwitch(const QString& password) const
return passwordSwitch;
}
QString CliInterface::compressionLevelSwitch(int level) const
{
Q_ASSERT(m_param.contains(CompressionLevelSwitch));
QString compLevelSwitch = m_param.value(CompressionLevelSwitch).toString();
Q_ASSERT(!compLevelSwitch.isEmpty());
Q_ASSERT(level >= 0 && level <= 9);
compLevelSwitch.replace(QLatin1String("$CompressionLevel"), QString::number(level));
return compLevelSwitch;
}
QStringList CliInterface::rootNodeSwitch(const QString &rootNode) const
{
if (rootNode.isEmpty()) {
......
......@@ -146,6 +146,13 @@ enum CliInterfaceParameters {
* or ("--password", "$Password")
*/
PasswordSwitch,
/**
* QString
* The format of the compression level switch. The variable $CompressionLevel
* will be substituted for the level.
* Example: ("-mx=$CompressionLevel)
*/
CompressionLevelSwitch,
/**
* QStringList
* This is a stringlist with regexps, defining how to recognize the last
......@@ -309,7 +316,7 @@ public:
QStringList substituteListVariables(const QStringList &listArgs, const QString &password);
QStringList substituteCopyVariables(const QStringList &extractArgs, const QVariantList &files, bool preservePaths, const QString &password, const QString &rootNode);
QStringList substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QDir &workDir, const QString &password, bool encryptHeader);
QStringList substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QDir &workDir, const QString &password, bool encryptHeader, int compLevel);
/**
* @return The preserve path switch, according to the @p preservePaths extraction option.
......@@ -326,6 +333,11 @@ public:
*/
QStringList passwordSwitch(const QString& password) const;
/**
* @return The compression level switch with the given @p level.
*/
QString compressionLevelSwitch(int level) const;
/**
* @return The root node switch with the given @p rootNode.
*/
......
......@@ -74,9 +74,11 @@ ParameterList CliPlugin::parameterList() const
p[PasswordSwitch] = QStringList() << QStringLiteral("-p$Password");
p[PasswordHeaderSwitch] = QStringList { QStringLiteral("-p$Password"), QStringLiteral("-mhe=on") };
p[WrongPasswordPatterns] = QStringList() << QStringLiteral("Wrong password");
p[CompressionLevelSwitch] = QStringLiteral("-mx=$CompressionLevel");
p[AddArgs] = QStringList() << QStringLiteral("a")
<< QStringLiteral("$Archive")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$CompressionLevelSwitch")
<< QStringLiteral("$Files");
p[DeleteArgs] = QStringList() << QStringLiteral("d")
<< QStringLiteral("$Archive")
......
......@@ -97,6 +97,7 @@ ParameterList CliPlugin::parameterList() const
p[RootNodeSwitch] = QStringList() << QStringLiteral( "-ap$Path" );
p[PasswordSwitch] = QStringList() << QStringLiteral( "-p$Password" );
p[PasswordHeaderSwitch] = QStringList() << QStringLiteral("-hp$Password");
p[CompressionLevelSwitch] = QStringLiteral("-m$CompressionLevel");
p[DeleteArgs] = QStringList() << QStringLiteral( "d" )
<< QStringLiteral( "$Archive" )
<< QStringLiteral( "$Files" );
......@@ -112,6 +113,7 @@ ParameterList CliPlugin::parameterList() const
p[AddArgs] = QStringList() << QStringLiteral( "a" )
<< QStringLiteral( "$Archive" )
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$CompressionLevelSwitch")
<< QStringLiteral( "$Files" );
p[PasswordPromptPattern] = QLatin1String("Enter password \\(will not be echoed\\) for");
p[WrongPasswordPatterns] = QStringList() << QStringLiteral("password incorrect") << QStringLiteral("wrong password");
......
......@@ -96,7 +96,7 @@ ParameterList CliPlugin::parameterList() const
p[PreservePathSwitch] = QStringList() << QStringLiteral("")
<< QStringLiteral("-j");
p[PasswordSwitch] = QStringList() << QStringLiteral("-P$Password");
p[CompressionLevelSwitch] = QStringLiteral("-$CompressionLevel");
p[DeleteArgs] = QStringList() << QStringLiteral("-d")
<< QStringLiteral("$Archive")
<< QStringLiteral("$Files");
......@@ -112,6 +112,7 @@ ParameterList CliPlugin::parameterList() const
p[AddArgs] = QStringList() << QStringLiteral("-r")
<< QStringLiteral("$Archive")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$CompressionLevelSwitch")
<< QStringLiteral("$Files");
p[PasswordPromptPattern] = QStringLiteral(" password: ");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment