Commit 03939219 authored by Ragnar Thomsen's avatar Ragnar Thomsen
Browse files

Implement support for setting encryption method

Needed infrastructure changes were done in ArchiveFormat, CliProperties
and other classes. A combobox was added to CreateDialog which enables
setting the encryption method.

Currently, only the Zip format when using cli7z supports multiple
encryption methods. For other formats that support only one encryption
method, the method is shown in the combobox.

This diff also enables detection of encryption method when opening
archives which is then shown in PropertiesDialog. To this end a new
signal was added to ReadOnlyArchiveInterface (encryptionMethodFound).
The similar compressionMethodFound signal was modified to only take one
string instead of QStringList.

Differential Revision: D3303
GUI:
parent e03d534d
......@@ -307,6 +307,10 @@ void MainWindow::newArchive()
if (!dialog.data()->compressionMethod().isEmpty()) {
m_openArgs.metaData()[QStringLiteral("compressionMethod")] = dialog.data()->compressionMethod();
}
if (!dialog.data()->encryptionMethod().isEmpty()) {
m_openArgs.metaData()[QStringLiteral("encryptionMethod")] = dialog.data()->encryptionMethod();
}
m_openArgs.metaData()[QStringLiteral("encryptionPassword")] = password;
if (dialog.data()->isHeaderEncryptionEnabled()) {
......
......@@ -107,6 +107,7 @@ void Cli7zTest::testList_data()
// Is zero for non-multi-volume archives:
QTest::addColumn<int>("numberOfVolumes");
QTest::addColumn<QStringList>("compressionMethods");
QTest::addColumn<QString>("encryptionMethod");
// Index of some entry to be tested.
QTest::addColumn<int>("someEntryIndex");
// Entry metadata.
......@@ -119,45 +120,51 @@ void Cli7zTest::testList_data()
// p7zip version 16.02 tests
QTest::newRow("normal-file-1602")
<< QFINDTESTDATA("data/archive-with-symlink-1602.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")}
<< QFINDTESTDATA("data/archive-with-symlink-1602.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")} << QString()
<< 4 << QStringLiteral("testarchive/dir2/file2.txt") << false << false << (qulonglong) 32 << QStringLiteral("2015-05-17T20:41:48");
QTest::newRow("encrypted-1602")
<< QFINDTESTDATA("data/archive-encrypted-1602.txt") << 4 << false << 0 << QStringList{QStringLiteral("LZMA2"), QStringLiteral("7zAES")}
<< QFINDTESTDATA("data/archive-encrypted-1602.txt") << 4 << false << 0 << QStringList{QStringLiteral("LZMA2")} << QStringLiteral("7zAES")
<< 1 << QStringLiteral("file2.txt") << false << true << (qulonglong) 14 << QStringLiteral("2016-03-02T22:37:55");
QTest::newRow("multi-volume-1602")
<< QFINDTESTDATA("data/archive-multivol-1602.txt") << 2 << true << 5 << QStringList{QStringLiteral("LZMA2")}
<< QFINDTESTDATA("data/archive-multivol-1602.txt") << 2 << true << 5 << QStringList{QStringLiteral("LZMA2")} << QString()
<< 1 << QStringLiteral("largefile2") << false << false << (qulonglong) 2097152 << QStringLiteral("2016-07-17T11:26:19");
QTest::newRow("zip-with-AES256-encryption")
<< QFINDTESTDATA("data/archive-zip-AES256-1602.txt") << 4 << false << 0
<< QStringList{QStringLiteral("Store"), QStringLiteral("Store"), QStringLiteral("Deflate"), QStringLiteral("Deflate")}
<< QStringLiteral("AES256")
<< 3 << QStringLiteral("testarchive/file2.txt") << false << true << (qulonglong) 33 << QStringLiteral("2016-11-06T21:17:02");
// p7zip version 15.14 tests
QTest::newRow("normal-file-1514")
<< QFINDTESTDATA("data/archive-with-symlink-1514.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")}
<< QFINDTESTDATA("data/archive-with-symlink-1514.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")} << QString()
<< 4 << QStringLiteral("testarchive/dir2/file2.txt") << false << false << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
QTest::newRow("encrypted-1514")
<< QFINDTESTDATA("data/archive-encrypted-1514.txt") << 9 << false << 0 << QStringList{QStringLiteral("LZMA2"), QStringLiteral("7zAES")}
<< QFINDTESTDATA("data/archive-encrypted-1514.txt") << 9 << false << 0 << QStringList{QStringLiteral("LZMA2")} << QStringLiteral("7zAES")
<< 3 << QStringLiteral("testarchive/dir1/file1.txt") << false << true << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
// p7zip version 15.09 tests
QTest::newRow("normal-file-1509")
<< QFINDTESTDATA("data/archive-with-symlink-1509.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")}
<< QFINDTESTDATA("data/archive-with-symlink-1509.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")} << QString()
<< 4 << QStringLiteral("testarchive/dir2/file2.txt") << false << false << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
QTest::newRow("encrypted-1509")
<< QFINDTESTDATA("data/archive-encrypted-1509.txt") << 9 << false << 0 << QStringList{QStringLiteral("LZMA2"), QStringLiteral("7zAES")}
<< QFINDTESTDATA("data/archive-encrypted-1509.txt") << 9 << false << 0 << QStringList{QStringLiteral("LZMA2")} << QStringLiteral("7zAES")
<< 3 << QStringLiteral("testarchive/dir1/file1.txt") << false << true << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
// p7zip version 9.38.1 tests
QTest::newRow("normal-file-9381")
<< QFINDTESTDATA("data/archive-with-symlink-9381.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")}
<< QFINDTESTDATA("data/archive-with-symlink-9381.txt") << 10 << false << 0 << QStringList{QStringLiteral("LZMA2")} << QString()
<< 4 << QStringLiteral("testarchive/dir2/file2.txt") << false << false << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
QTest::newRow("encrypted-9381")
<< QFINDTESTDATA("data/archive-encrypted-9381.txt") << 9 << false << 0 << QStringList{QStringLiteral("LZMA2"), QStringLiteral("7zAES")}
<< QFINDTESTDATA("data/archive-encrypted-9381.txt") << 9 << false << 0 << QStringList{QStringLiteral("LZMA2")} << QStringLiteral("7zAES")
<< 3 << QStringLiteral("testarchive/dir1/file1.txt") << false << true << (qulonglong) 32 << QStringLiteral("2015-05-17T19:41:48");
}
......@@ -168,6 +175,7 @@ void Cli7zTest::testList()
QVariant::fromValue(m_plugin->metaData())});
QSignalSpy signalSpyEntry(plugin, &CliPlugin::entry);
QSignalSpy signalSpyCompMethod(plugin, &CliPlugin::compressionMethodFound);
QSignalSpy signalSpyEncMethod(plugin, &CliPlugin::encryptionMethodFound);
QFETCH(QString, outputTextFile);
QFETCH(int, expectedEntriesCount);
......@@ -189,9 +197,21 @@ void Cli7zTest::testList()
QFETCH(int, numberOfVolumes);
QCOMPARE(plugin->numberOfVolumes(), numberOfVolumes);
QCOMPARE(signalSpyCompMethod.count(), 1);
QFETCH(QStringList, compressionMethods);
QCOMPARE(signalSpyCompMethod.at(0).at(0).toStringList(), compressionMethods);
QCOMPARE(signalSpyCompMethod.count(), compressionMethods.count());
QStringList combinedCompMethods;
for (int i = 0; i < signalSpyCompMethod.count(); i++) {
combinedCompMethods.append(signalSpyCompMethod.at(i).at(0).toString());
}
QCOMPARE(combinedCompMethods, compressionMethods);
QFETCH(QString, encryptionMethod);
if (encryptionMethod.isEmpty()) {
QCOMPARE(signalSpyEncMethod.count(), 0);
} else {
QVERIFY(signalSpyEncMethod.count() > 0);
QCOMPARE(signalSpyEncMethod.at(0).at(0).toString(), encryptionMethod);
}
QFETCH(int, someEntryIndex);
QVERIFY(someEntryIndex < signalSpyEntry.count());
......@@ -349,7 +369,7 @@ void Cli7zTest::testAddArgs()
QFETCH(ulong, volumeSize);
QFETCH(QString, compressionMethod);
const auto replacedArgs = plugin->cliProperties()->addArgs(archiveName, {}, password, encryptHeader, compressionLevel, compressionMethod, volumeSize);
const auto replacedArgs = plugin->cliProperties()->addArgs(archiveName, {}, password, encryptHeader, compressionLevel, compressionMethod, QString(), volumeSize);
QFETCH(QStringList, expectedArgs);
QCOMPARE(replacedArgs, expectedArgs);
......
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)
Scanning the drive for archives:
1 file, 781 bytes (1 KiB)
Listing archive: testarchive.zip
--
Path = testarchive.zip
Type = zip
Physical Size = 781
----------
Path = testarchive
Folder = +
Size = 0
Packed Size = 0
Modified = 2016-11-06 21:17:02
Created = 2016-11-06 21:17:02
Accessed = 2016-11-06 21:17:03
Attributes = D_ drwxrwxr-x
Encrypted = -
Comment =
CRC =
Method = Store
Host OS = Unix
Version = 20
Volume Index = 0
Path = testarchive/dir1
Folder = +
Size = 0
Packed Size = 0
Modified = 2015-05-14 00:45:24
Created = 2016-11-06 21:16:31
Accessed = 2016-11-06 21:16:35
Attributes = D_ drwxrwxr-x
Encrypted = -
Comment =
CRC =
Method = Store
Host OS = Unix
Version = 20
Volume Index = 0
Path = testarchive/dir1/file1.txt
Folder = -
Size = 32
Packed Size = 57
Modified = 2015-05-17 19:41:48
Created = 2016-11-06 21:16:31
Accessed = 2016-11-06 21:17:06
Attributes = _ -rw-rw-r--
Encrypted = +
Comment =
CRC =
Method = AES-256 Deflate
Host OS = Unix
Version = 51
Volume Index = 0
Path = testarchive/file2.txt
Folder = -
Size = 33
Packed Size = 58
Modified = 2016-11-06 21:17:02
Created = 2016-11-06 21:17:02
Accessed = 2016-11-06 21:17:02
Attributes = _ -rw-rw-r--
Encrypted = +
Comment =
CRC =
Method = AES-256 Deflate
Host OS = Unix
Version = 51
Volume Index = 0
......@@ -396,7 +396,7 @@ void CliRarTest::testAddArgs()
QFETCH(QString, compressionMethod);
QFETCH(ulong, volumeSize);
const auto replacedArgs = plugin->cliProperties()->addArgs(archiveName, {}, password, encryptHeader, compressionLevel, compressionMethod, volumeSize);
const auto replacedArgs = plugin->cliProperties()->addArgs(archiveName, {}, password, encryptHeader, compressionLevel, compressionMethod, QString(), volumeSize);
QFETCH(QStringList, expectedArgs);
QCOMPARE(replacedArgs, expectedArgs);
......
......@@ -129,7 +129,7 @@ void CliZipTest::testAddArgs()
QFETCH(int, compressionLevel);
QFETCH(QString, compressionMethod);
const auto replacedArgs = plugin->cliProperties()->addArgs(archiveName, {}, password, false, compressionLevel, compressionMethod, 0);
const auto replacedArgs = plugin->cliProperties()->addArgs(archiveName, {}, password, false, compressionLevel, compressionMethod, QString(), 0);
QFETCH(QStringList, expectedArgs);
QCOMPARE(replacedArgs, expectedArgs);
......
......@@ -172,17 +172,32 @@ Archive::Archive(ReadOnlyArchiveInterface *archiveInterface, bool isReadOnly, QO
m_iface->setParent(this);
connect(m_iface, &ReadOnlyArchiveInterface::compressionMethodFound, this, &Archive::onCompressionMethodFound);
connect(m_iface, &ReadOnlyArchiveInterface::encryptionMethodFound, this, &Archive::onEncryptionMethodFound);
}
void Archive::onCompressionMethodFound(const QStringList &methods)
void Archive::onCompressionMethodFound(const QString &method)
{
// If other methods are found, we don't report "Store" method.
QStringList processedMethods = methods;
if (processedMethods.size() > 1 &&
processedMethods.contains(QStringLiteral("Store"))) {
processedMethods.removeOne(QStringLiteral("Store"));
QStringList methods = property("compressionMethods").toStringList();
if (!methods.contains(method) &&
method != QLatin1String("Store")) {
methods.append(method);
}
methods.sort();
setProperty("compressionMethods", methods);
}
void Archive::onEncryptionMethodFound(const QString &method)
{
QStringList methods = property("encryptionMethods").toStringList();
if (!methods.contains(method)) {
methods.append(method);
}
setProperty("compressionMethods", processedMethods);
methods.sort();
setProperty("encryptionMethods", methods);
}
Archive::~Archive()
......
......@@ -86,6 +86,7 @@ class KERFUFFLE_EXPORT Archive : public QObject
Q_PROPERTY(QString subfolderName MEMBER m_subfolderName READ subfolderName)
Q_PROPERTY(QString password READ password)
Q_PROPERTY(QStringList compressionMethods MEMBER m_compressionMethods)
Q_PROPERTY(QStringList encryptionMethods MEMBER m_encryptionMethods)
public:
......@@ -210,7 +211,8 @@ public:
private slots:
void onAddFinished(KJob*);
void onUserQuery(Kerfuffle::Query*);
void onCompressionMethodFound(const QStringList &methods);
void onCompressionMethodFound(const QString &method);
void onEncryptionMethodFound(const QString &method);
private:
Archive(ReadOnlyArchiveInterface *archiveInterface, bool isReadOnly, QObject *parent = 0);
......@@ -238,6 +240,7 @@ private:
qulonglong m_numberOfFolders;
QMimeType m_mimeType;
QStringList m_compressionMethods;
QStringList m_encryptionMethods;
};
} // namespace Kerfuffle
......
......@@ -44,7 +44,9 @@ ArchiveFormat::ArchiveFormat(const QMimeType& mimeType,
bool supportsTesting,
bool supportsMultiVolume,
const QVariantMap& compressionMethods,
const QString& defaultCompressionMethod) :
const QString& defaultCompressionMethod,
const QVariantMap &encryptionMethods,
const QString &defaultEncryptionMethod) :
m_mimeType(mimeType),
m_encryptionType(encryptionType),
m_minCompressionLevel(minCompLevel),
......@@ -54,7 +56,9 @@ ArchiveFormat::ArchiveFormat(const QMimeType& mimeType,
m_supportsTesting(supportsTesting),
m_supportsMultiVolume(supportsMultiVolume),
m_compressionMethods(compressionMethods),
m_defaultCompressionMethod(defaultCompressionMethod)
m_defaultCompressionMethod(defaultCompressionMethod),
m_encryptionMethods(encryptionMethods),
m_defaultEncryptionMethod(defaultEncryptionMethod)
{
}
......@@ -79,6 +83,9 @@ ArchiveFormat ArchiveFormat::fromMetadata(const QMimeType& mimeType, const KPlug
QVariantMap compressionMethods = formatProps[QStringLiteral("CompressionMethods")].toObject().toVariantMap();
QString defaultCompMethod = formatProps[QStringLiteral("CompressionMethodDefault")].toString();
QVariantMap encryptionMethods = formatProps[QStringLiteral("EncryptionMethods")].toObject().toVariantMap();
QString defaultEncMethod = formatProps[QStringLiteral("EncryptionMethodDefault")].toString();
Archive::EncryptionType encType = Archive::Unencrypted;
if (formatProps[QStringLiteral("HeaderEncryption")].toBool()) {
encType = Archive::HeaderEncrypted;
......@@ -86,7 +93,18 @@ ArchiveFormat ArchiveFormat::fromMetadata(const QMimeType& mimeType, const KPlug
encType = Archive::Encrypted;
}
return ArchiveFormat(mimeType, encType, minCompLevel, maxCompLevel, defaultCompLevel, supportsWriteComment, supportsTesting, supportsMultiVolume, compressionMethods, defaultCompMethod);
return ArchiveFormat(mimeType,
encType,
minCompLevel,
maxCompLevel,
defaultCompLevel,
supportsWriteComment,
supportsTesting,
supportsMultiVolume,
compressionMethods,
defaultCompMethod,
encryptionMethods,
defaultEncMethod);
}
return ArchiveFormat();
......@@ -142,4 +160,14 @@ QString ArchiveFormat::defaultCompressionMethod() const
return m_defaultCompressionMethod;
}
QVariantMap ArchiveFormat::encryptionMethods() const
{
return m_encryptionMethods;
}
QString ArchiveFormat::defaultEncryptionMethod() const
{
return m_defaultEncryptionMethod;
}
}
......@@ -46,7 +46,9 @@ public:
bool supportsTesting,
bool suppportsMultiVolume,
const QVariantMap& compressionMethods,
const QString& defaultCompressionMethod);
const QString& defaultCompressionMethod,
const QVariantMap &encryptionMethods,
const QString &defaultEncryptionMethod);
/**
* @return The archive format of the given @p mimeType, according to the given @p metadata.
......@@ -71,6 +73,8 @@ public:
bool supportsMultiVolume() const;
QVariantMap compressionMethods() const;
QString defaultCompressionMethod() const;
QVariantMap encryptionMethods() const;
QString defaultEncryptionMethod() const;
private:
QMimeType m_mimeType;
......@@ -83,6 +87,8 @@ private:
bool m_supportsMultiVolume = false;
QVariantMap m_compressionMethods;
QString m_defaultCompressionMethod;
QVariantMap m_encryptionMethods;
QString m_defaultEncryptionMethod;
};
}
......
......@@ -167,7 +167,8 @@ signals:
void info(const QString &info);
void finished(bool result);
void testSuccess();
void compressionMethodFound(const QStringList);
void compressionMethodFound(const QString &method);
void encryptionMethodFound(const QString &method);
/**
* Emitted when @p query needs to be executed on the GUI thread.
......
......@@ -218,6 +218,7 @@ bool CliInterface::addFiles(const QVector<Archive::Entry*> &files, const Archive
isHeaderEncryptionEnabled(),
options.compressionLevel(),
options.compressionMethod(),
options.encryptionMethod(),
options.volumeSize()));
}
......
......@@ -40,8 +40,12 @@ CliProperties::CliProperties(QObject *parent, const KPluginMetaData &metaData, c
{
}
QStringList CliProperties::addArgs(const QString &archive, const QStringList &files, const QString &password, bool headerEncryption, int compressionLevel, const QString &compressionMethod, uint volumeSize)
QStringList CliProperties::addArgs(const QString &archive, const QStringList &files, const QString &password, bool headerEncryption, int compressionLevel, const QString &compressionMethod, const QString &encryptionMethod, uint volumeSize)
{
if (!encryptionMethod.isEmpty()) {
Q_ASSERT(!password.isEmpty());
}
QStringList args;
foreach (const QString &s, m_addSwitch) {
args << s;
......@@ -55,6 +59,9 @@ QStringList CliProperties::addArgs(const QString &archive, const QStringList &fi
if (!compressionMethod.isEmpty()) {
args << substituteCompressionMethodSwitch(compressionMethod);
}
if (!encryptionMethod.isEmpty()) {
args << substituteEncryptionMethodSwitch(encryptionMethod);
}
if (volumeSize > 0) {
args << substituteMultiVolumeSwitch(volumeSize);
}
......@@ -241,6 +248,28 @@ QString CliProperties::substituteCompressionMethodSwitch(const QString &method)
return compMethodSwitch;
}
QString CliProperties::substituteEncryptionMethodSwitch(const QString &method) const
{
if (method.isEmpty()) {
return QString();
}
const ArchiveFormat format = ArchiveFormat::fromMetadata(m_mimeType, m_metaData);
Q_ASSERT(!format.encryptionMethods().isEmpty());
QString encMethodSwitch = m_encryptionMethodSwitch[m_mimeType.name()].toString();
if (encMethodSwitch.isEmpty()) {
return QString();
}
QString cliMethod = format.encryptionMethods().value(method).toString();
encMethodSwitch.replace(QLatin1String("$EncryptionMethod"), cliMethod);
return encMethodSwitch;
}
QString CliProperties::substituteMultiVolumeSwitch(uint volumeSize) const
{
// The maximum value we allow in the QDoubleSpinBox is 1000MB. Converted to
......
......@@ -59,6 +59,7 @@ class KERFUFFLE_EXPORT CliProperties: public QObject
Q_PROPERTY(QStringList passwordSwitchHeaderEnc MEMBER m_passwordSwitchHeaderEnc)
Q_PROPERTY(QString compressionLevelSwitch MEMBER m_compressionLevelSwitch)
Q_PROPERTY(QHash<QString,QVariant> compressionMethodSwitch MEMBER m_compressionMethodSwitch)
Q_PROPERTY(QHash<QString,QVariant> encryptionMethodSwitch MEMBER m_encryptionMethodSwitch)
Q_PROPERTY(QString multiVolumeSwitch MEMBER m_multiVolumeSwitch)
Q_PROPERTY(QStringList passwordPromptPatterns MEMBER m_passwordPromptPatterns)
......@@ -84,6 +85,7 @@ public:
bool headerEncryption,
int compressionLevel,
const QString &compressionMethod,
const QString &encryptionMethod,
uint volumeSize);
QStringList commentArgs(const QString &archive, const QString &commentfile);
QStringList deleteArgs(const QString &archive, const QVector<Archive::Entry*> &files, const QString &password);
......@@ -106,6 +108,7 @@ private:
QStringList substitutePasswordSwitch(const QString &password, bool headerEnc = false) const;
QString substituteCompressionLevelSwitch(int level) const;
QString substituteCompressionMethodSwitch(const QString &method) const;
QString substituteEncryptionMethodSwitch(const QString &method) const;
QString substituteMultiVolumeSwitch(uint volumeSize) const;
QString m_addProgram;
......@@ -128,6 +131,7 @@ private:
QStringList m_passwordSwitchHeaderEnc;
QString m_compressionLevelSwitch;
QHash<QString,QVariant> m_compressionMethodSwitch;
QHash<QString,QVariant> m_encryptionMethodSwitch;
QString m_multiVolumeSwitch;
QStringList m_passwordPromptPatterns;
......
......@@ -49,6 +49,7 @@ CompressionOptionsWidget::CompressionOptionsWidget(QWidget *parent,
pwdWidget->setPasswordStrengthMeterVisible(false);
connect(multiVolumeCheckbox, &QCheckBox::stateChanged, this, &CompressionOptionsWidget::slotMultiVolumeChecked);
connect(compMethodComboBox, &QComboBox::currentTextChanged, this, &CompressionOptionsWidget::slotCompMethodChanged);
if (m_opts.isVolumeSizeSet()) {
multiVolumeCheckbox->setChecked(true);
......@@ -112,8 +113,25 @@ void CompressionOptionsWidget::updateWidgets()
Q_ASSERT(archiveFormat.isValid());
if (archiveFormat.encryptionType() != Archive::Unencrypted) {
collapsibleEncryption->setEnabled(true);
collapsibleEncryption->setToolTip(QString());
encMethodComboBox->clear();
encMethodComboBox->insertItems(0, archiveFormat.encryptionMethods().keys());
if (!m_opts.encryptionMethod().isEmpty() &&
encMethodComboBox->findText(m_opts.encryptionMethod()) > -1) {
encMethodComboBox->setCurrentText(m_opts.encryptionMethod());
} else {
encMethodComboBox->setCurrentText(archiveFormat.defaultEncryptionMethod());
}
if (!archiveFormat.encryptionMethods().isEmpty()) {
lblEncMethod->setEnabled(true);
encMethodComboBox->setEnabled(true);
}
pwdWidget->setEnabled(true);
if (archiveFormat.encryptionType() == Archive::HeaderEncrypted) {
......@@ -135,6 +153,9 @@ void CompressionOptionsWidget::updateWidgets()
collapsibleEncryption->setEnabled(false);
collapsibleEncryption->setToolTip(i18n("Protection of the archive with password is not possible with the %1 format.",
m_mimetype.comment()));
lblEncMethod->setEnabled(false);
encMethodComboBox->setEnabled(false);
encMethodComboBox->clear();
pwdWidget->setEnabled(false);
encryptHeaderCheckBox->setToolTip(QString());
}
......@@ -224,6 +245,14 @@ KNewPasswordWidget::PasswordStatus CompressionOptionsWidget::passwordStatus() co
return pwdWidget->passwordStatus();
}
QString CompressionOptionsWidget::encryptionMethod() const
{
if (encMethodComboBox->isEnabled() && encMethodComboBox->count() > 1 && !password().isEmpty()) {
return encMethodComboBox->currentText();
}
return QString();
}
void CompressionOptionsWidget::slotMultiVolumeChecked(int state)
{
if (state == Qt::Checked) {
......@@ -235,4 +264,23 @@ void CompressionOptionsWidget::slotMultiVolumeChecked(int state)
}
}
void CompressionOptionsWidget::slotCompMethodChanged(const QString &value)
{
// This hack is needed for the RAR format because the available encryption
// method is dependent on the selected compression method. Rar uses AES128
// for RAR4 format and AES256 for RAR5 format.
if (m_mimetype == QMimeDatabase().mimeTypeForName(QStringLiteral("application/vnd.rar")) ||
m_mimetype == QMimeDatabase().mimeTypeForName(QStringLiteral("application/x-rar"))) {
encMethodComboBox->clear();
if (value == QLatin1String("RAR4")) {
encMethodComboBox->insertItem(0, QStringLiteral("AES128"));
} else {
encMethodComboBox->insertItem(0, QStringLiteral("AES256"));
}
}
}
}
......@@ -46,6 +46,7 @@ public:
const CompressionOptions &opts = {});
int compressionLevel() const;
QString compressionMethod() const;
QString encryptionMethod() const;
ulong volumeSize() const;
QString password() const;
CompressionOptions commpressionOptions() const;
......@@ -66,6 +67,7 @@ private:
private slots:
void slotMultiVolumeChecked(int state);
void slotCompMethodChanged(const QString &value);
};
}
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>402</width>
<height>90</height>
<width>450</width>