Commit 2848dcd3 authored by Ragnar Thomsen's avatar Ragnar Thomsen
Browse files

Redesign of CreateDialog

CreateDialog was completely redesigned. The KFileWidget is gone and replaced by
a KUrlRequester for the destination folder and a QLineEdit for the filename.
The encryption options are moved to a KCollapsibleGroupBox and further options
can be added in future KCollapsibleGroupBox's.

AddDialog is also gone and CreateDialog is now used directly instead.
parent 0b6215d7
......@@ -295,18 +295,15 @@ void MainWindow::newArchive()
QPointer<Kerfuffle::CreateDialog> dialog = new Kerfuffle::CreateDialog(
Q_NULLPTR, // parent
i18n("Create a new Archive"), // caption
i18n("Create New Archive"), // caption
QUrl()); // startDir
dialog.data()->show();
dialog.data()->restoreWindowSize();
if (dialog.data()->exec()) {
const QUrl saveFileUrl = dialog.data()->selectedUrls().first();
const QUrl saveFileUrl = dialog.data()->selectedUrl();
const QString password = dialog.data()->password();
qCDebug(ARK) << "CreateDialog returned URL:" << saveFileUrl.toString();
qCDebug(ARK) << "CreateDialog returned mime:" << dialog.data()->currentFilterMimeType().name();
qCDebug(ARK) << "CreateDialog returned mime:" << dialog.data()->currentMimeType().name();
m_openArgs.metaData()[QStringLiteral("createNewArchive")] = QStringLiteral("true");
m_openArgs.metaData()[QStringLiteral("encryptionPassword")] = password;
......
......@@ -26,7 +26,11 @@
#include "createdialog.h"
#include "mimetypes.h"
#include <KCollapsibleGroupBox>
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QMimeDatabase>
#include <QTest>
......@@ -37,12 +41,75 @@ class CreateDialogTest : public QObject
Q_OBJECT
private Q_SLOTS:
void testBasicWidgets_data();
void testBasicWidgets();
void testEncryption_data();
void testEncryption();
void testHeaderEncryptionTooltip();
};
void CreateDialogTest::testBasicWidgets_data()
{
QTest::addColumn<QString>("mimeType");
QTest::newRow("tar") << QStringLiteral("application/x-tar");
QTest::newRow("targzip") << QStringLiteral("application/x-compressed-tar");
QTest::newRow("tarbzip") << QStringLiteral("application/x-bzip-compressed-tar");
QTest::newRow("tarZ") << QStringLiteral("application/x-tarz");
QTest::newRow("tarxz") << QStringLiteral("application/x-xz-compressed-tar");
QTest::newRow("tarlzma") << QStringLiteral("application/x-lzma-compressed-tar");
QTest::newRow("tarlzop") << QStringLiteral("application/x-tzo");
QTest::newRow("tarlzip") << QStringLiteral("application/x-lzip-compressed-tar");
const auto writeMimeTypes = supportedWriteMimeTypes();
if (writeMimeTypes.contains(QStringLiteral("application/zip"))) {
QTest::newRow("zip") << QStringLiteral("application/zip");
} else {
qDebug() << "zip format not available in CreateDialog, skipping test.";
}
if (writeMimeTypes.contains(QStringLiteral("application/x-7z-compressed"))) {
QTest::newRow("7z") << QStringLiteral("application/x-7z-compressed");
} else {
qDebug() << "7z format not available in CreateDialog, skipping test.";
}
if (writeMimeTypes.contains(QStringLiteral("application/x-rar"))) {
QTest::newRow("rar") << QStringLiteral("application/x-rar");
} else {
qDebug() << "rar format not available in CreateDialog, skipping test.";
}
if (writeMimeTypes.contains(QStringLiteral("application/x-lrzip-compressed-tar"))) {
QTest::newRow("tarlrzip") << QStringLiteral("application/x-lrzip-compressed-tar");
} else {
qDebug() << "tar.lrzip format not available in CreateDialog, skipping test.";
}
}
void CreateDialogTest::testBasicWidgets()
{
CreateDialog *dialog = new CreateDialog(Q_NULLPTR, QString(), QUrl());
auto fileNameLineEdit = dialog->findChild<QLineEdit*>(QStringLiteral("filenameLineEdit"));
auto archiveTypeComboBox = dialog->findChild<QComboBox*>(QStringLiteral("mimeComboBox"));
QVERIFY(fileNameLineEdit);
QVERIFY(archiveTypeComboBox);
QFETCH(QString, mimeType);
const QMimeType mime = QMimeDatabase().mimeTypeForName(mimeType);
// Test if combobox is updated when user enters a filename with suffix.
fileNameLineEdit->setText(QStringLiteral("basename.%1").arg(mime.preferredSuffix()));
QCOMPARE(archiveTypeComboBox->currentText(), mime.comment());
// Test if suffix is added correctly when the user selects an archive type in combobox.
fileNameLineEdit->setText(QStringLiteral("basename"));
archiveTypeComboBox->setCurrentText(mime.comment());
QCOMPARE(QFileInfo(dialog->selectedUrl().toLocalFile()).fileName(), QStringLiteral("basename.%1").arg(mime.preferredSuffix()));
}
void CreateDialogTest::testEncryption_data()
{
QTest::addColumn<QString>("filter");
......@@ -78,12 +145,12 @@ void CreateDialogTest::testEncryption()
QFETCH(bool, isEncryptionAvailable);
QFETCH(bool, isHeaderEncryptionAvailable);
auto encryptCheckBox = dialog->findChild<QCheckBox*>(QStringLiteral("encryptCheckBox"));
auto collapsibleEncryption = dialog->findChild<KCollapsibleGroupBox*>(QStringLiteral("collapsibleEncryption"));
auto encryptHeaderCheckBox = dialog->findChild<QCheckBox*>(QStringLiteral("encryptHeaderCheckBox"));
QVERIFY(encryptCheckBox);
QVERIFY(collapsibleEncryption);
QVERIFY(encryptHeaderCheckBox);
dialog->setCurrentFilterFromMimeType(filter);
QVERIFY(dialog->setMimeType(filter));
// Encryption is initially not enabled.
QVERIFY(!dialog->isEncryptionEnabled());
......@@ -92,7 +159,7 @@ void CreateDialogTest::testEncryption()
if (isEncryptionAvailable) {
QVERIFY(dialog->isEncryptionAvailable());
encryptCheckBox->setChecked(true);
collapsibleEncryption->setExpanded(true);
QVERIFY(dialog->isEncryptionEnabled());
if (isHeaderEncryptionAvailable) {
......@@ -106,7 +173,7 @@ void CreateDialogTest::testEncryption()
QVERIFY(!dialog->isHeaderEncryptionAvailable());
}
encryptCheckBox->setChecked(false);
collapsibleEncryption->setExpanded(false);
QVERIFY(!dialog->isEncryptionEnabled());
QVERIFY(!dialog->isHeaderEncryptionEnabled());
} else {
......@@ -125,18 +192,18 @@ void CreateDialogTest::testHeaderEncryptionTooltip()
CreateDialog *dialog = new CreateDialog(Q_NULLPTR, QString(), QUrl());
auto encryptCheckBox = dialog->findChild<QCheckBox*>(QStringLiteral("encryptCheckBox"));
auto collapsibleEncryption = dialog->findChild<KCollapsibleGroupBox*>(QStringLiteral("collapsibleEncryption"));
auto encryptHeaderCheckBox = dialog->findChild<QCheckBox*>(QStringLiteral("encryptHeaderCheckBox"));
QVERIFY(encryptCheckBox);
QVERIFY(collapsibleEncryption);
QVERIFY(encryptHeaderCheckBox);
encryptCheckBox->setChecked(true);
collapsibleEncryption->setExpanded(true);
dialog->setCurrentFilterFromMimeType(QStringLiteral("application/zip"));
QVERIFY(dialog->setMimeType(QStringLiteral("application/zip")));
QVERIFY(!encryptHeaderCheckBox->toolTip().isEmpty());
// If we set a tar filter after the zip one, ensure that the old zip's tooltip is not shown anymore.
dialog->setCurrentFilterFromMimeType(QStringLiteral("application/x-compressed-tar"));
QVERIFY(dialog->setMimeType(QStringLiteral("application/x-compressed-tar")));
QVERIFY(encryptHeaderCheckBox->toolTip().isEmpty());
}
......
......@@ -9,7 +9,6 @@ set(kerfuffle_SRCS
jobs.cpp
createdialog.cpp
extractiondialog.cpp
adddialog.cpp
propertiesdialog.cpp
queries.cpp
addtoarchive.cpp
......@@ -20,7 +19,6 @@ set(kerfuffle_SRCS
kconfig_add_kcfg_files(kerfuffle_SRCS settings.kcfgc)
ki18n_wrap_ui(kerfuffle_SRCS
adddialog.ui
createdialog.ui
extractiondialog.ui
extractionsettings.ui
......@@ -42,11 +40,11 @@ PUBLIC
KF5::Pty
KF5::Service
KF5::I18n
KF5::WidgetsAddons
PRIVATE
KF5::KIOCore
KF5::KIOWidgets
KF5::KIOFileWidgets
KF5::WidgetsAddons
)
......
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
* Copyright (C) 2009,2011 Raphael Kubo da Costa <rakuco@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "adddialog.h"
#include "ark_debug.h"
#include "ui_adddialog.h"
#include "kerfuffle/archive_kerfuffle.h"
#include <KFilePlacesModel>
#include <KFileWidget>
#include <QDir>
#include <QFileInfo>
#include <QMimeDatabase>
#include <QStandardItemModel>
namespace Kerfuffle
{
class AddDialogUI: public QWidget, public Ui::AddDialog
{
public:
AddDialogUI(QWidget *parent = 0)
: QWidget(parent) {
setupUi(this);
}
};
AddDialog::AddDialog(QWidget *parent,
const QString &caption,
const QUrl &startDir,
const QStringList &itemsToAdd)
: CreateDialog(parent, caption, startDir)
{
qCDebug(ARK) << "AddDialog loaded";
m_ui = new AddDialogUI(this);
m_vlayout->addWidget(m_ui);
setupIconList(itemsToAdd);
// Set up a default name if there's only one file to compress
if (itemsToAdd.size() == 1) {
const QFileInfo fileInfo(itemsToAdd.first());
const QString fileName =
fileInfo.isDir() ? fileInfo.dir().dirName() : fileInfo.baseName();
m_fileWidget->setSelection(fileName);
}
}
void AddDialog::setupIconList(const QStringList& itemsToAdd)
{
QStandardItemModel* listModel = new QStandardItemModel(this);
QStringList sortedList(itemsToAdd);
sortedList.sort();
Q_FOREACH(const QString& urlString, sortedList) {
QUrl url(urlString);
QStandardItem* item = new QStandardItem;
item->setText(url.fileName());
QMimeDatabase db;
QString iconName = db.mimeTypeForUrl(url).iconName();
item->setIcon(QIcon::fromTheme(iconName));
item->setData(QVariant(url), KFilePlacesModel::UrlRole);
listModel->appendRow(item);
}
m_ui->compressList->setModel(listModel);
}
}
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
* Copyright (C) 2009 Raphael Kubo da Costa <rakuco@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ADDDIALOG_H
#define ADDDIALOG_H
#include "createdialog.h"
#include "kerfuffle_export.h"
namespace Kerfuffle
{
class KERFUFFLE_EXPORT AddDialog : public CreateDialog
{
Q_OBJECT
public:
AddDialog(QWidget *parent,
const QString &caption,
const QUrl &startDir,
const QStringList &itemsToAdd);
private:
class AddDialogUI *m_ui;
void setupIconList(const QStringList& itemsToAdd);
};
}
#endif
......@@ -28,8 +28,8 @@
#include "addtoarchive.h"
#include "ark_debug.h"
#include "adddialog.h"
#include "archive_kerfuffle.h"
#include "createdialog.h"
#include "jobs.h"
#include <KConfig>
......@@ -89,21 +89,18 @@ bool AddToArchive::showAddDialog()
{
qCDebug(ARK) << "Opening add dialog";
QPointer<Kerfuffle::AddDialog> dialog = new Kerfuffle::AddDialog(
QPointer<Kerfuffle::CreateDialog> dialog = new Kerfuffle::CreateDialog(
Q_NULLPTR, // parent
i18n("Compress to Archive"), // caption
QUrl::fromLocalFile(m_firstPath), // startDir
m_inputs); // itemsToAdd
QUrl::fromLocalFile(m_firstPath)); // startDir
dialog.data()->show();
dialog.data()->restoreWindowSize();
bool ret = dialog.data()->exec();
if (ret) {
qCDebug(ARK) << "AddDialog returned URL:" << dialog.data()->selectedUrls().at(0).toString();
qCDebug(ARK) << "AddDialog returned mime:" << dialog.data()->currentFilterMimeType().name();
setFilename(dialog.data()->selectedUrls().at(0));
setMimeType(dialog.data()->currentFilterMimeType().name());
qCDebug(ARK) << "CreateDialog returned URL:" << dialog.data()->selectedUrl().toString();
qCDebug(ARK) << "CreateDialog returned mime:" << dialog.data()->currentMimeType().name();
setFilename(dialog.data()->selectedUrl());
setMimeType(dialog.data()->currentMimeType().name());
setPassword(dialog.data()->password());
setHeaderEncryptionEnabled(dialog.data()->isHeaderEncryptionEnabled());
}
......
......@@ -4,6 +4,7 @@
* Copyright (C) 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
* Copyright (C) 2009,2011 Raphael Kubo da Costa <rakuco@FreeBSD.org>
* Copyright (C) 2015 Elvis Angelaccio <elvis.angelaccio@kdemail.net>
* Copyright (C) 2016 Ragnar Thomsen <rthomsen6@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -34,17 +35,12 @@
#include "mimetypes.h"
#include <KColorScheme>
#include <KFileWidget>
#include <KMessageBox>
#include <KSharedConfig>
#include <KUrlComboBox>
#include <KWindowConfig>
#include <KFileFilterCombo>
#include <KUrlRequester>
#include <QDebug>
#include <QLineEdit>
#include <QMimeDatabase>
#include <QPushButton>
#include <QUrl>
namespace Kerfuffle
......@@ -58,15 +54,6 @@ public:
}
};
ArchiveTypeFilter::ArchiveTypeFilter(const QMimeType &newMimeType,
const QStringList &newGlobPatterns,
const QString &newComment) :
mimeType(newMimeType),
globPatterns(newGlobPatterns),
comment(newComment)
{
}
CreateDialog::CreateDialog(QWidget *parent,
const QString &caption,
const QUrl &startDir)
......@@ -77,51 +64,99 @@ CreateDialog::CreateDialog(QWidget *parent,
setWindowTitle(caption);
setModal(true);
m_supportedMimeTypes = Kerfuffle::supportedWriteMimeTypes();
m_vlayout = new QVBoxLayout();
setLayout(m_vlayout);
m_fileWidget = new KFileWidget(startDir, this);
m_vlayout->addWidget(m_fileWidget);
m_fileWidget->setMode(KFile::File | KFile::LocalOnly);
m_fileWidget->setOperationMode(KFileWidget::Saving);
m_fileWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
m_fileWidget->setFilter(filterFromMimeTypes(Kerfuffle::supportedWriteMimeTypes()));
m_fileWidget->filterWidget()->setEditable(false);
m_fileWidget->okButton()->show();
m_fileWidget->cancelButton()->show();
connect(m_fileWidget->okButton(), &QPushButton::clicked, this, &CreateDialog::slotOkButtonClicked);
connect(m_fileWidget, &KFileWidget::accepted, m_fileWidget, &KFileWidget::accept);
connect(m_fileWidget, &KFileWidget::accepted, this, &CreateDialog::accept);
connect(m_fileWidget->cancelButton(), &QPushButton::clicked, this, &QDialog::reject);
connect(this, &QDialog::accepted, this, &CreateDialog::slotUpdateDefaultMimeType);
connect(this, &QDialog::finished, this, &CreateDialog::slotSaveWindowSize);
// The currentIndexChanged signal is overloaded and can send both an int and QString, hence the complex syntax.
connect(m_fileWidget->filterWidget(), static_cast<void(KFileFilterCombo::*)(int)>(&KFileFilterCombo::currentIndexChanged), this, &CreateDialog::slotFilterChanged);
m_ui = new CreateDialogUI(this);
m_ui->groupEncryptionOptions->hide();
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
m_ui->destFolderUrlRequester->setMode(KFile::Directory);
if (startDir.isEmpty()) {
m_ui->destFolderUrlRequester->setUrl(QUrl::fromLocalFile(QDir::currentPath() + QLatin1Char('/')));
} else {
m_ui->destFolderUrlRequester->setUrl(startDir);
}
KColorScheme colorScheme(QPalette::Active, KColorScheme::View);
m_ui->pwdWidget->setBackgroundWarningColor(colorScheme.background(KColorScheme::NegativeBackground).color());
m_ui->pwdWidget->setAllowEmptyPasswords(false);
m_ui->pwdWidget->setPasswordStrengthMeterVisible(false);
connect(m_ui->encryptCheckBox, &QCheckBox::toggled, this, &CreateDialog::slotEncryptionToggled);
// Populate combobox with mimetypes.
foreach (const QString &type, m_supportedMimeTypes) {
m_ui->mimeComboBox->addItem(QMimeDatabase().mimeTypeForName(type).comment());
}
connect(m_ui->filenameLineEdit, &QLineEdit::textChanged, this, &CreateDialog::slotFileNameEdited);
connect(m_ui->collapsibleEncryption, &KCollapsibleGroupBox::expandedChanged, this, &CreateDialog::slotEncryptionToggled);
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(this, &QDialog::accepted, this, &CreateDialog::slotUpdateDefaultMimeType);
connect(m_ui->mimeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &CreateDialog::slotUpdateWidgets);
connect(m_ui->mimeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &CreateDialog::slotUpdateFilenameExtension);
m_vlayout->addWidget(m_ui);
loadConfiguration();
layout()->setSizeConstraint(QLayout::SetFixedSize);
m_ui->filenameLineEdit->setFocus();
slotUpdateFilenameExtension(m_ui->mimeComboBox->currentIndex());
}
QSize CreateDialog::sizeHint() const
void CreateDialog::slotFileNameEdited(const QString &fileName)
{
// Used only when no previous window size has been stored.
return QSize(750,450);
const QMimeType mimeFromFileName = QMimeDatabase().mimeTypeForFile(fileName, QMimeDatabase::MatchExtension);
if (m_supportedMimeTypes.contains(mimeFromFileName.name())) {
setMimeType(mimeFromFileName.name());
}
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!fileName.isEmpty());
}
QList<QUrl> CreateDialog::selectedUrls() const
void CreateDialog::slotUpdateWidgets(int index)
{
return m_fileWidget->selectedUrls();
const QMimeType mimeType = QMimeDatabase().mimeTypeForName(m_supportedMimeTypes.at(index));
if (Kerfuffle::supportedEncryptEntriesMimeTypes().contains(mimeType.name())) {
m_ui->collapsibleEncryption->setEnabled(true);
m_ui->collapsibleEncryption->setToolTip(QString());
} else {
m_ui->collapsibleEncryption->setEnabled(false);
m_ui->collapsibleEncryption->setToolTip(i18n("Protection of the archive with password is not possible with the %1 format.",
mimeType.comment()));
}
slotEncryptionToggled();
}
void CreateDialog::slotUpdateFilenameExtension(int index)
{
m_ui->chkAddExtension->setText(i18n("Automatically add .%1",
QMimeDatabase().mimeTypeForName(m_supportedMimeTypes.at(index)).preferredSuffix()));
}
QUrl CreateDialog::selectedUrl() const
{
QString fileName = m_ui->filenameLineEdit->text();
QString dir = m_ui->destFolderUrlRequester->url().toLocalFile();
if (m_ui->chkAddExtension->isChecked()) {
QString detectedSuffix = QMimeDatabase().suffixForFileName(m_ui->filenameLineEdit->text().trimmed());
if (!currentMimeType().suffixes().contains(detectedSuffix)) {
if (!fileName.endsWith(QLatin1Char('.'))) {
fileName.append(QLatin1Char('.'));
}
fileName.append(currentMimeType().preferredSuffix());
}
}
if (!dir.endsWith(QLatin1Char('/'))) {
dir.append(QLatin1Char('/'));
}
return QUrl::fromLocalFile(dir + fileName);
}
QString CreateDialog::password() const
......@@ -131,12 +166,12 @@ QString CreateDialog::password() const
bool CreateDialog::isEncryptionAvailable() const
{
return m_ui->encryptCheckBox->isEnabled();
return m_ui->collapsibleEncryption->isEnabled();
}
bool CreateDialog::isEncryptionEnabled() const
{
return isEncryptionAvailable() && m_ui->encryptCheckBox->isChecked() && m_ui->groupEncryptionOptions->isEnabled();
return isEncryptionAvailable() && m_ui->collapsibleEncryption->isExpanded();
}
bool CreateDialog::isHeaderEncryptionAvailable() const
......@@ -164,32 +199,15 @@ void CreateDialog::accept()
case KNewPasswordWidget::PasswordNotVerified:
KMessageBox::error(Q_NULLPTR, i18n("The chosen password does not match the given verification password."));
break;
case KNewPasswordWidget::EmptyPasswordNotAllowed:
KMessageBox::error(Q_NULLPTR, i18n("The password cannot be empty."));
break;
default:
break;
}
}
void CreateDialog::slotFilterChanged(int index)
void CreateDialog::slotEncryptionToggled()
{
QMimeType currentMimeType = m_filterList.at(index).mimeType;
qCDebug(ARK) << "Filter changed to: " << currentMimeType.name();
if (Kerfuffle::supportedEncryptEntriesMimeTypes().contains(currentMimeType.name())) {
m_ui->encryptCheckBox->setEnabled(true);
m_ui->encryptCheckBox->setToolTip(QString());
m_ui->groupEncryptionOptions->setEnabled(true);
} else {
m_ui->encryptCheckBox->setEnabled(false);
m_ui->encryptCheckBox->setToolTip(i18n("Protection of the archive with password is not possible with the %1 format.",
currentMimeType.comment()));
m_ui->groupEncryptionOptions->setEnabled(false);
}
if (Kerfuffle::supportedEncryptHeaderMimeTypes().contains(currentMimeType.name())) {
const bool isExpanded = m_ui->collapsibleEncryption->isExpanded();
if (isExpanded && Kerfuffle::supportedEncryptHeaderMimeTypes().contains(currentMimeType().name())) {
m_ui->encryptHeaderCheckBox->setEnabled(true);
m_ui->encryptHeaderCheckBox->setToolTip(QString());
} else {
......@@ -198,119 +216,45 @@ void CreateDialog::slotFilterChanged(int index)