summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-04-26 10:43:50 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-08-02 09:56:43 (GMT)
commitac2487e944d99626f6fe8209240490b0717f8b01 (patch)
treeb582054aeb990786970ed1c43aedaeeaaad2ba23
parente10e15be16d65566f27c62e10a0d3d90814a8c3d (diff)
Rewrite of the signencryptfileswizard
The new wizard will handle more things automatically and just use one page for setup of the task. Some of the options that were part of the Wizard will be moved into the configuration. This utilizes the new Certificateselection widgets.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/crypto/gui/signencryptfileswizard.cpp1126
-rw-r--r--src/crypto/gui/signencryptfileswizard.h69
-rw-r--r--src/crypto/gui/signencryptwidget.cpp108
-rw-r--r--src/crypto/gui/signencryptwidget.h79
-rw-r--r--src/crypto/signencryptfilescontroller.cpp100
6 files changed, 326 insertions, 1157 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b2dc5ec..052f57b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -168,6 +168,7 @@ set(_kleopatra_SRCS
crypto/gui/signerresolvepage.cpp
crypto/gui/encryptemailwizard.cpp
crypto/gui/signemailwizard.cpp
+ crypto/gui/signencryptwidget.cpp
crypto/gui/signencryptwizard.cpp
crypto/gui/certificateselectionwidget.cpp
diff --git a/src/crypto/gui/signencryptfileswizard.cpp b/src/crypto/gui/signencryptfileswizard.cpp
index da4b026..eb023b3 100644
--- a/src/crypto/gui/signencryptfileswizard.cpp
+++ b/src/crypto/gui/signencryptfileswizard.cpp
@@ -1,8 +1,8 @@
-/* -*- mode: c++; c-basic-offset:4 -*-
- crypto/gui/signencryptfileswizard.cpp
+/* crypto/gui/signencryptfileswizard.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2009 Klarälvdalens Datakonsult AB
+ 2016 Intevation GmbH
Kleopatra is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,553 +33,35 @@
#include <config-kleopatra.h>
#include "signencryptfileswizard.h"
+#include "signencryptwidget.h"
#include "newresultpage.h"
-#include "signingcertificateselectionwidget.h"
-
-#include <crypto/certificateresolver.h>
-
-#include <view/keytreeview.h>
-#include <view/searchbar.h>
-
-#include <models/keycache.h>
-#include <Libkleo/Predicates>
-#include <models/keylistmodel.h>
-
-#include <utils/archivedefinition.h>
-#include <utils/path-helper.h>
-#include <utils/gui-helper.h>
-
-#include <Libkleo/Stl_Util>
-#include <libkleo/filenamerequester.h>
#include <KLocalizedString>
-#include <QIcon>
#include <KMessageBox>
#include "kleopatra_debug.h"
#include <QVBoxLayout>
-#include <QLabel>
#include <QWizardPage>
-#include <QRadioButton>
-#include <QCheckBox>
-#include <QPushButton>
-#include <QDialogButtonBox>
-#include <QListWidget>
-#include <QComboBox>
-#include <QTreeView>
#include <QPointer>
#include <gpgme++/key.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/bind.hpp>
-
-#include <KSharedConfig>
-
using namespace GpgME;
-using namespace boost;
using namespace Kleo;
-using namespace Kleo::Crypto;
using namespace Kleo::Crypto::Gui;
enum Page {
- OperationPageId,
- RecipientsPageId,
- SignerPageId,
+ SigEncPageId,
ResultPageId,
NumPages
};
-static void enable_disable(QAbstractButton &button, const QAbstractItemView *view)
-{
- const QItemSelectionModel *ism = view ? view->selectionModel() : 0;
- button.setEnabled(ism && ism->hasSelection());
-}
-
-static void copy_selected_from_to(KeyTreeView &from, KeyTreeView &to)
-{
- to.addKeysSelected(from.selectedKeys());
- from.view()->selectionModel()->clearSelection();
-}
-
-static void move_selected_from_to(KeyTreeView &from, KeyTreeView &to)
-{
- const std::vector<Key> keys = from.selectedKeys();
- from.removeKeys(keys);
- to.addKeysSelected(keys);
-}
-
-static void remove_all_keys_not_xyz(KeyTreeView &ktv, Protocol proto)
-{
- const std::vector<Key> k
- = kdtools::copy_if< std::vector<Key> >(ktv.keys(), boost::bind(&Key::protocol, _1) != proto);
- ktv.removeKeys(k);
-}
-
-static QString join_max(const QStringList &sl, const int max, const QString &glue)
-{
- return QStringList(sl.mid(0, max)).join(glue);
-}
-
-namespace
-{
-
-// Simple dialog to show a list of files
-class ListDialog : public QDialog
-{
- Q_OBJECT
-public:
- explicit ListDialog(const QStringList &files, QWidget *parent = Q_NULLPTR)
- : QDialog(parent),
- listWidget(this),
- buttonBox(QDialogButtonBox::Close, Qt::Vertical, this),
- hlay(this)
- {
- setWindowTitle(i18nc("@title:window", "Selected Files"));
-
- KDAB_SET_OBJECT_NAME(listWidget);
- KDAB_SET_OBJECT_NAME(buttonBox);
- KDAB_SET_OBJECT_NAME(hlay);
-
- listWidget.setSelectionMode(QListWidget::NoSelection);
- listWidget.addItems(files);
-
- hlay.addWidget(&listWidget);
- hlay.addWidget(&buttonBox);
-
- connect(&buttonBox, &QDialogButtonBox::rejected, this, &SignEncryptFilesWizard::reject);
- }
-
-private:
- QListWidget listWidget;
- QDialogButtonBox buttonBox;
- QHBoxLayout hlay;
-};
-
-//
-// This is a simple QLabel subclass, used mainly to have a widget
-// for the 'files' field of the wizard (though that one's unused as of now).
-//
-class ObjectsLabel : public QLabel
-{
- Q_OBJECT // ### PENDING(marc) deal with lots of files (->listbox)
- Q_PROPERTY(QStringList files READ files WRITE setFiles)
-public:
- static const int MaxLinesShownInline = 5;
-
- explicit ObjectsLabel(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = 0)
- : QLabel(parent, f), m_dialog(), m_files(dummyFiles())
- {
- connect(this, &QLabel::linkActivated,
- this, &ObjectsLabel::slotLinkActivated);
- updateText();
- // updateGeometry() doesn't seem to reset the
- // minimumSizeHint(), using max-height dummy text here
- // does... Go figure
- m_files.clear();
- }
- explicit ObjectsLabel(const QStringList &files, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = 0)
- : QLabel(parent, f), m_dialog(), m_files(files)
- {
- connect(this, &QLabel::linkActivated,
- this, &ObjectsLabel::slotLinkActivated);
- updateText();
- }
-
- QStringList files() const
- {
- return m_files;
- }
- void setFiles(const QStringList &files)
- {
- if (m_files == files) {
- return;
- }
- m_files = files;
- updateText();
- }
-
-private Q_SLOTS:
- void slotLinkActivated()
- {
- if (!m_dialog) {
- m_dialog = new ListDialog(m_files, this);
- m_dialog->setAttribute(Qt::WA_DeleteOnClose);
- }
- if (m_dialog->isVisible()) {
- m_dialog->raise();
- } else {
- m_dialog->show();
- }
- }
-
-private:
- static QStringList dummyFiles()
- {
- QStringList dummy;
- for (int i = 0; i < MaxLinesShownInline + 1; ++i) {
- dummy.push_back(QString::number(i));
- }
- return dummy;
- }
- QString makeText() const
- {
- if (m_files.empty()) {
- return QLatin1String("<p>") + i18n("No files selected.") + QLatin1String("</p>");
- }
- QString html = QLatin1String("<p>") + i18np("Selected file:", "Selected files:", m_files.size()) + QLatin1String("</p>")
- + QLatin1String("<ul><li>") + join_max(m_files, MaxLinesShownInline, QStringLiteral("</li><li>")) + QLatin1String("</li></ul>");
- if (m_files.size() > MaxLinesShownInline) {
- html += QLatin1String("<p><a href=\"link:/\">") + i18nc("@action", "More...") + QLatin1String("</a></p>");
- }
- return html;
- }
- void updateText()
- {
- setText(makeText());
- }
-
-private:
- QPointer<ListDialog> m_dialog;
- QStringList m_files;
-};
-
-//
-// Helper wrapper around Kleo::FileNameRequester that adjusts
-// extensions to an ArchiveDefinition
-//
-class ArchiveFileNameRequester : public Kleo::FileNameRequester
-{
- Q_OBJECT
-public:
- explicit ArchiveFileNameRequester(Protocol protocol, QWidget *parent = Q_NULLPTR)
- : FileNameRequester(QDir::Files, parent), m_protocol(protocol), m_archiveDefinition()
- {
- setExistingOnly(false);
- }
-
-public Q_SLOTS:
- void setArchiveDefinition(const boost::shared_ptr<const Kleo::ArchiveDefinition> &ad)
- {
- if (ad == m_archiveDefinition) {
- return;
- }
- const QString oldExt = m_archiveDefinition ? m_archiveDefinition->extensions(m_protocol).front() : QString();
- const QString newExt = ad ? ad->extensions(m_protocol).front() : QString();
- QString fn = fileName();
- if (fn.endsWith(oldExt)) {
- fn.chop(oldExt.size() + 1);
- }
- m_archiveDefinition = ad;
- if (ad) {
- fn += QLatin1Char('.') + newExt;
- }
- FileNameRequester::setFileName(fn);
- }
- void setFileName(const QString &fn)
- {
- const QString ext = m_archiveDefinition ? m_archiveDefinition->extensions(m_protocol).front() : QString();
- if (m_archiveDefinition && !fn.endsWith(ext)) {
- FileNameRequester::setFileName(fn + QLatin1Char('.') + ext);
- } else {
- FileNameRequester::setFileName(fn);
- }
- }
-private:
- const Protocol m_protocol;
- shared_ptr<const ArchiveDefinition> m_archiveDefinition;
-};
-
-class WizardPage : public QWizardPage
-{
- Q_OBJECT
-public:
- explicit WizardPage(QWidget *parent = Q_NULLPTR)
- : QWizardPage(parent),
- m_presetProtocol(UnknownProtocol)
- {
-
- }
-
- bool isArchiveRequested() const
- {
- return field(QStringLiteral("archive")).toBool();
- }
-
- QString archiveName(Protocol p) const
- {
- return field(p == OpenPGP ? QStringLiteral("archive-name-pgp") : QStringLiteral("archive-name-cms")).toString();
- }
-
- bool isSignOnlySelected() const
- {
- return field(QStringLiteral("sign")).toBool();
- }
-
- bool isEncryptOnlySelected() const
- {
- return field(QStringLiteral("encrypt")).toBool();
- }
-
- bool isSignEncryptSelected() const
- {
- return field(QStringLiteral("signencrypt")).toBool();
- }
-
- bool isSigningSelected() const
- {
- return isSignOnlySelected() || isSignEncryptSelected();
- }
-
- bool isEncryptionSelected() const
- {
- return isEncryptOnlySelected() || isSignEncryptSelected();
- }
-
- Protocol protocol() const
- {
- return m_presetProtocol;
- }
- Protocol effectiveProtocol() const
- {
- if (isSignEncryptSelected()) {
- assert(m_presetProtocol == OpenPGP || m_presetProtocol == UnknownProtocol);
- return OpenPGP;
- } else {
- return m_presetProtocol;
- }
- }
-
- void setPresetProtocol(Protocol proto)
- {
- if (proto == m_presetProtocol) {
- return;
- }
- m_presetProtocol = proto;
- doSetPresetProtocol();
- }
-
-private:
- virtual void doSetPresetProtocol() {}
-
-private:
- Protocol m_presetProtocol;
-};
-
-class OperationPage : public WizardPage
-{
- Q_OBJECT
- Q_PROPERTY(QStringList files READ files WRITE setFiles)
- Q_PROPERTY(bool signingPreset READ isSigningPreset WRITE setSigningPreset)
- Q_PROPERTY(bool signingUserMutable READ isSigningUserMutable WRITE setSigningUserMutable)
- Q_PROPERTY(bool encryptionPreset READ isEncryptionPreset WRITE setEncryptionPreset)
- Q_PROPERTY(bool encryptionUserMutable READ isEncryptionUserMutable WRITE setEncryptionUserMutable)
- Q_PROPERTY(bool archiveUserMutable READ isArchiveUserMutable WRITE setArchiveUserMutable)
-public:
- explicit OperationPage(QWidget *parent = Q_NULLPTR)
- : WizardPage(parent),
- m_objectsLabel(this),
- m_archiveCB(i18n("Archive files with:"), this),
- m_archive(this),
- m_archiveNamePgpLB(i18n("Archive name (OpenPGP):"), this),
- m_archiveNamePgp(OpenPGP, this),
- m_archiveNameCmsLB(i18n("Archive name (S/MIME):"), this),
- m_archiveNameCms(CMS, this),
- m_signencrypt(i18n("Sign and Encrypt (OpenPGP only)"), this),
- m_encrypt(i18n("Encrypt"), this),
- m_sign(i18n("Sign"), this),
- m_armor(i18n("Text output (ASCII armor)"), this),
- m_signingUserMutable(true),
- m_encryptionUserMutable(true),
- m_archiveUserMutable(true),
- m_signingPreset(true),
- m_encryptionPreset(true),
- m_archiveDefinitions(ArchiveDefinition::getArchiveDefinitions())
- {
- setTitle(i18nc("@title", "What do you want to do?"));
- setSubTitle(i18nc("@title",
- "Please select here whether you want to sign or encrypt files."));
- KDAB_SET_OBJECT_NAME(m_objectsLabel);
- KDAB_SET_OBJECT_NAME(m_signencrypt);
- KDAB_SET_OBJECT_NAME(m_encrypt);
- KDAB_SET_OBJECT_NAME(m_sign);
- KDAB_SET_OBJECT_NAME(m_archiveCB);
- KDAB_SET_OBJECT_NAME(m_archive);
- KDAB_SET_OBJECT_NAME(m_archiveNamePgpLB);
- KDAB_SET_OBJECT_NAME(m_archiveNamePgp);
- KDAB_SET_OBJECT_NAME(m_archiveNameCmsLB);
- KDAB_SET_OBJECT_NAME(m_archiveNameCms);
- KDAB_SET_OBJECT_NAME(m_armor);
-
- QGridLayout *glay = new QGridLayout;
- glay->addWidget(&m_archiveCB, 0, 0);
- glay->addWidget(&m_archive, 0, 1);
- glay->addWidget(&m_archiveNamePgpLB, 1, 0);
- glay->addWidget(&m_archiveNamePgp, 1, 1);
- glay->addWidget(&m_archiveNameCmsLB, 2, 0);
- glay->addWidget(&m_archiveNameCms, 2, 1);
-
- QVBoxLayout *vlay = new QVBoxLayout(this);
- vlay->addWidget(&m_objectsLabel);
- vlay->addLayout(glay);
- vlay->addWidget(&m_signencrypt);
- vlay->addWidget(&m_encrypt);
- vlay->addWidget(&m_sign);
- vlay->addStretch(1);
- vlay->addWidget(&m_armor);
-
- m_archiveNamePgpLB.setAlignment(Qt::AlignRight);
- m_archiveNamePgpLB.setBuddy(&m_archiveNamePgp);
- m_archiveNameCmsLB.setAlignment(Qt::AlignRight);
- m_archiveNameCmsLB.setBuddy(&m_archiveNameCms);
-
- m_armor.setChecked(false);
- m_archive.setEnabled(false);
- m_archiveNamePgpLB.setEnabled(false);
- m_archiveNamePgp.setEnabled(false);
- m_archiveNameCmsLB.setEnabled(false);
- m_archiveNameCms.setEnabled(false);
-
- Q_FOREACH (const shared_ptr<ArchiveDefinition> &ad, m_archiveDefinitions) {
- m_archive.addItem(ad->label(), qVariantFromValue(ad));
- }
-
- registerField(QStringLiteral("files"), this, "files");
-
- registerField(QStringLiteral("signing-preset"), this, "signingPreset");
- registerField(QStringLiteral("encryption-preset"), this, "encryptionPreset");
-
- registerField(QStringLiteral("signencrypt"), &m_signencrypt);
- registerField(QStringLiteral("encrypt"), &m_encrypt);
- registerField(QStringLiteral("sign"), &m_sign);
-
- registerField(QStringLiteral("armor"), &m_armor);
-
- registerField(QStringLiteral("archive"), &m_archiveCB);
- registerField(QStringLiteral("archive-id"), &m_archive);
- registerField(QStringLiteral("archive-name-pgp"), &m_archiveNamePgp, "fileName");
- registerField(QStringLiteral("archive-name-cms"), &m_archiveNameCms, "fileName");
-
- registerField(QStringLiteral("signing-user-mutable"), this, "signingUserMutable");
- registerField(QStringLiteral("encryption-user-mutable"), this, "encryptionUserMutable");
- registerField(QStringLiteral("archive-user-mutable"), this, "archiveUserMutable");
-
- connect(&m_archive, SIGNAL(currentIndexChanged(int)),
- this, SLOT(slotArchiveDefinitionChanged()));
-
- connect(&m_signencrypt, &QAbstractButton::clicked, this, &QWizardPage::completeChanged);
- connect(&m_encrypt, &QAbstractButton::clicked, this, &QWizardPage::completeChanged);
- connect(&m_sign, &QAbstractButton::clicked, this, &QWizardPage::completeChanged);
- connect(&m_archiveCB, &QAbstractButton::clicked, this, &QWizardPage::completeChanged);
- connect(&m_archiveNamePgp, &FileNameRequester::fileNameChanged, this, &QWizardPage::completeChanged);
- connect(&m_archiveNameCms, &FileNameRequester::fileNameChanged, this, &QWizardPage::completeChanged);
-
- connect(&m_archiveCB, &QAbstractButton::toggled,
- &m_archive, &QWidget::setEnabled);
- connect(&m_archiveCB, &QAbstractButton::toggled,
- &m_archiveNamePgpLB, &QWidget::setEnabled);
- connect(&m_archiveCB, &QAbstractButton::toggled,
- &m_archiveNamePgp, &QWidget::setEnabled);
- connect(&m_archiveCB, &QAbstractButton::toggled,
- &m_archiveNameCmsLB, &QWidget::setEnabled);
- connect(&m_archiveCB, &QAbstractButton::toggled,
- &m_archiveNameCms, &QWidget::setEnabled);
-
- const shared_ptr<ArchiveDefinition> ad = archiveDefinition();
- m_archiveNamePgp.setArchiveDefinition(ad);
- m_archiveNameCms.setArchiveDefinition(ad);
- }
-
- QStringList files() const
- {
- return m_objectsLabel.files();
- }
- void setFiles(const QStringList &files)
- {
- m_objectsLabel.setFiles(files);
- const QString archiveName =
- files.size() == 1 ? files.front() :
- /* else */ QDir(heuristicBaseDirectory(files))
- .absoluteFilePath(i18nc("base name of an archive file, e.g. archive.zip or archive.tar.gz", "archive"));
- m_archiveNamePgp.setFileName(archiveName);
- m_archiveNameCms.setFileName(archiveName);
- }
-
- bool isSigningPreset() const
- {
- return m_signingPreset;
- }
- void setSigningPreset(bool preset)
- {
- if (m_signingPreset == preset) {
- return;
- }
- m_signingPreset = preset;
- updateSignEncryptArchiveWidgetStates();
- }
-
- bool isSigningUserMutable() const
- {
- return m_signingUserMutable;
- }
- void setSigningUserMutable(bool mut)
- {
- if (m_signingUserMutable == mut) {
- return;
- }
- m_signingUserMutable = mut;
- updateSignEncryptArchiveWidgetStates();
- }
-
- bool isEncryptionPreset() const
- {
- return m_encryptionPreset;
- }
- void setEncryptionPreset(bool preset)
- {
- if (m_encryptionPreset == preset) {
- return;
- }
- m_encryptionPreset = preset;
- updateSignEncryptArchiveWidgetStates();
- }
-
- bool isEncryptionUserMutable() const
- {
- return m_encryptionUserMutable;
- }
- void setEncryptionUserMutable(bool mut)
- {
- if (m_encryptionUserMutable == mut) {
- return;
- }
- m_encryptionUserMutable = mut;
- updateSignEncryptArchiveWidgetStates();
- }
-
- bool isArchiveUserMutable() const
- {
- return m_archiveUserMutable;
- }
- void setArchiveUserMutable(bool mut)
- {
- if (m_archiveUserMutable == mut) {
- return;
- }
- m_archiveUserMutable = mut;
- updateSignEncryptArchiveWidgetStates();
- }
-
- bool isComplete() const Q_DECL_OVERRIDE
- {
- return (!isArchiveRequested() || (!archiveName(OpenPGP).isEmpty() && !archiveName(CMS).isEmpty())) // ### make more permissive
- && (isSigningSelected() || isEncryptionSelected());
- }
-
+/*
+FIXME: Either show this warning or fix detached signatures for archives.
bool validatePage() Q_DECL_OVERRIDE {
if (isSignOnlySelected() && isArchiveRequested())
return KMessageBox::warningContinueCancel(this,
@@ -597,204 +79,50 @@ public:
return true;
}
}
+*/
- int nextId() const Q_DECL_OVERRIDE
- {
- return isEncryptionSelected() ? RecipientsPageId : SignerPageId;
- }
- void doSetPresetProtocol() Q_DECL_OVERRIDE {
- updateSignEncryptArchiveWidgetStates();
- }
-
- shared_ptr<ArchiveDefinition> archiveDefinition() const
- {
- return m_archive.itemData(m_archive.currentIndex()).value< shared_ptr<ArchiveDefinition> >();
- }
-
- void setArchiveDefinition(const shared_ptr<ArchiveDefinition> &ad)
- {
- m_archive.setCurrentIndex(m_archive.findData(qVariantFromValue(ad)));
- }
-
- void setArchiveDefinition(const QString &adName)
- {
- const std::vector< shared_ptr<ArchiveDefinition> >::const_iterator
- it = kdtools::find_if(m_archiveDefinitions, boost::bind(&ArchiveDefinition::id, _1) == adName);
- if (it != m_archiveDefinitions.end()) {
- m_archive.setCurrentIndex(it - m_archiveDefinitions.begin());
- }
- }
-
-private Q_SLOTS:
- void slotArchiveDefinitionChanged()
- {
- const shared_ptr<ArchiveDefinition> ad = archiveDefinition();
- m_archiveNamePgp.setArchiveDefinition(ad);
- m_archiveNameCms.setArchiveDefinition(ad);
- }
-
-private:
- void updateSignEncryptArchiveWidgetStates()
- {
- m_archiveCB.setEnabled(m_archiveUserMutable);
-
- const bool mustEncrypt = m_encryptionPreset && !m_encryptionUserMutable;
- const bool mustSign = m_signingPreset && !m_signingUserMutable;
-
- const bool mayEncrypt = m_encryptionPreset || m_encryptionUserMutable;
- const bool maySign = m_signingPreset || m_signingUserMutable;
-
- const bool canSignEncrypt = protocol() != CMS && mayEncrypt && maySign;
- const bool canSignOnly = maySign && !mustEncrypt;
- const bool canEncryptOnly = mayEncrypt && !mustSign;
-
- m_signencrypt.setEnabled(canSignEncrypt);
- m_encrypt.setEnabled(canEncryptOnly);
- m_sign.setEnabled(canSignOnly);
-
- really_check(m_signencrypt, canSignEncrypt && m_signingPreset && m_encryptionPreset);
- really_check(m_encrypt, canEncryptOnly && !m_signingPreset && m_encryptionPreset);
- really_check(m_sign, canSignOnly && m_signingPreset && !m_encryptionPreset);
-
- m_signencrypt.setToolTip(protocol() == CMS
- ? i18n("This operation is not available for S/MIME")
- : QString());
- }
-private:
- ObjectsLabel m_objectsLabel;
- QCheckBox m_archiveCB;
- QComboBox m_archive;
- QLabel m_archiveNamePgpLB;
- ArchiveFileNameRequester m_archiveNamePgp;
- QLabel m_archiveNameCmsLB;
- ArchiveFileNameRequester m_archiveNameCms;
- QRadioButton m_signencrypt, m_encrypt, m_sign;
- QCheckBox m_armor;
- bool m_signingUserMutable, m_encryptionUserMutable, m_archiveUserMutable;
- bool m_signingPreset, m_encryptionPreset;
- const std::vector< shared_ptr<ArchiveDefinition> > m_archiveDefinitions;
-};
-
-class RecipientsPage : public WizardPage
+class SigEncPage: public QWizardPage
{
Q_OBJECT
public:
- explicit RecipientsPage(QWidget *parent = Q_NULLPTR)
- : WizardPage(parent),
- m_lastEffectiveProtocol(static_cast<Protocol>(-1)), // dummy start
- m_searchbar(this),
- m_unselectedKTV(this),
- m_selectPB(i18n("Add"), this),
- m_unselectPB(i18n("Remove"), this),
- m_selectedKTV(this)
+ explicit SigEncPage(QWidget *parent = Q_NULLPTR)
+ : QWizardPage(parent),
+ mWidget(new SignEncryptWidget)
{
- setTitle(i18nc("@title", "For whom do you want to encrypt?"));
- setSubTitle(i18nc("@title",
- "Please select for whom you want the files to be encrypted. "
- "Do not forget to pick one of your own certificates."));
- // the button may be there or not, the _text_ is static, though:
- setButtonText(QWizard::CommitButton, i18nc("@action", "Encrypt"));
-
- KDAB_SET_OBJECT_NAME(m_searchbar);
- KDAB_SET_OBJECT_NAME(m_unselectedKTV);
- KDAB_SET_OBJECT_NAME(m_selectPB);
- KDAB_SET_OBJECT_NAME(m_unselectPB);
- KDAB_SET_OBJECT_NAME(m_selectedKTV);
-
- m_selectPB.setIcon(QIcon::fromTheme(QStringLiteral("arrow-down")));
- m_unselectPB.setIcon(QIcon::fromTheme(QStringLiteral("arrow-up")));
-
- m_selectPB.setEnabled(false);
- m_unselectPB.setEnabled(false);
-
- m_unselectedKTV.setHierarchicalModel(AbstractKeyListModel::createHierarchicalKeyListModel(&m_unselectedKTV));
- m_unselectedKTV.setHierarchicalView(true);
- m_selectedKTV.setFlatModel(AbstractKeyListModel::createFlatKeyListModel(&m_selectedKTV));
- m_selectedKTV.setHierarchicalView(false);
-
- QVBoxLayout *vlay = new QVBoxLayout(this);
- vlay->addWidget(&m_searchbar);
- vlay->addWidget(&m_unselectedKTV, 1);
-
- QHBoxLayout *hlay = new QHBoxLayout;
- hlay->addStretch(1);
- hlay->addWidget(&m_selectPB);
- hlay->addWidget(&m_unselectPB);
- hlay->addStretch(1);
-
- vlay->addLayout(hlay);
- vlay->addWidget(&m_selectedKTV, 1);
-
- xconnect(&m_searchbar, SIGNAL(stringFilterChanged(QString)),
- &m_unselectedKTV, SLOT(setStringFilter(QString)));
- xconnect(&m_searchbar, SIGNAL(keyFilterChanged(boost::shared_ptr<Kleo::KeyFilter>)),
- &m_unselectedKTV, SLOT(setKeyFilter(boost::shared_ptr<Kleo::KeyFilter>)));
-
- connect(m_unselectedKTV.view()->selectionModel(), &QItemSelectionModel::selectionChanged,
- this, &RecipientsPage::slotUnselectedSelectionChanged);
- connect(m_selectedKTV.view()->selectionModel(), &QItemSelectionModel::selectionChanged,
- this, &RecipientsPage::slotSelectedSelectionChanged);
-
- connect(&m_selectPB, &QAbstractButton::clicked, this, &RecipientsPage::select);
- connect(&m_unselectPB, &QAbstractButton::clicked, this, &RecipientsPage::unselect);
+ setTitle(i18nc("@title", "Sign / Encrypt Files"));
+ QVBoxLayout *vLay = new QVBoxLayout(this);
+ vLay->addWidget(mWidget);
+ connect(mWidget, &SignEncryptWidget::operationChanged, this,
+ &SigEncPage::updateCommitButton);
+ setLayout(vLay);
}
bool isComplete() const Q_DECL_OVERRIDE
{
- return !m_selectedKTV.keys().empty();
+ return !mWidget->currentOp().isNull();
}
int nextId() const Q_DECL_OVERRIDE
{
- if (isSigningSelected()) {
- return SignerPageId;
- } else {
- return ResultPageId;
- }
- }
-
- static bool need_reload(Protocol now, Protocol then)
- {
- if (then == UnknownProtocol) {
- return false;
- }
- if (now == UnknownProtocol) {
- return true;
- }
- return now != then;
- }
-
- static bool need_grep(Protocol now, Protocol then)
- {
- return now != UnknownProtocol && then == UnknownProtocol;
+ return ResultPageId;
}
void initializePage() Q_DECL_OVERRIDE {
-
- setCommitPage(!isSigningSelected());
-
- const Protocol currentEffectiveProtocol = effectiveProtocol();
-
- if (need_reload(currentEffectiveProtocol, m_lastEffectiveProtocol))
- {
- std::vector<Key> keys = KeyCache::instance()->keys();
- _detail::grep_can_encrypt(keys);
- if (currentEffectiveProtocol != UnknownProtocol) {
- _detail::grep_protocol(keys, currentEffectiveProtocol);
- }
- m_unselectedKTV.setKeys(keys);
- } else if (need_grep(currentEffectiveProtocol, m_lastEffectiveProtocol))
- {
- remove_all_keys_not_xyz(m_unselectedKTV, currentEffectiveProtocol);
- remove_all_keys_not_xyz(m_selectedKTV, currentEffectiveProtocol);
- }
-
- m_lastEffectiveProtocol = currentEffectiveProtocol;
+ setCommitPage(true);
}
bool validatePage() Q_DECL_OVERRIDE {
- const std::vector<Key> &r = keys();
- if (_detail::none_of_secret(r))
+ if (!mWidget->selfKey().isNull()) {
+ return true;
+ }
+ bool hasSecret = false;
+ Q_FOREACH (const Key k, mWidget->recipients()) {
+ if (k.hasSecret()) {
+ hasSecret = true;
+ break;
+ }
+ }
+ if (!hasSecret)
{
if (KMessageBox::warningContinueCancel(this,
xi18nc("@info",
@@ -812,197 +140,31 @@ public:
return true;
}
- const std::vector<Key> &keys() const
- {
- return m_selectedKTV.keys();
- }
-
-private Q_SLOTS:
- void slotUnselectedSelectionChanged()
- {
- enable_disable(m_selectPB, m_unselectedKTV.view());
- }
- void slotSelectedSelectionChanged()
- {
- enable_disable(m_unselectPB, m_selectedKTV.view());
- }
- void select()
- {
- copy_selected_from_to(m_unselectedKTV, m_selectedKTV);
- Q_EMIT completeChanged();
- }
- void unselect()
- {
- move_selected_from_to(m_selectedKTV, m_unselectedKTV);
- Q_EMIT completeChanged();
- }
-
-private:
- Protocol m_lastEffectiveProtocol;
-
- SearchBar m_searchbar;
- KeyTreeView m_unselectedKTV;
- QPushButton m_selectPB, m_unselectPB;
- KeyTreeView m_selectedKTV;
-};
-
-class SignerPage : public WizardPage
-{
- Q_OBJECT
-public:
- explicit SignerPage(QWidget *parent = Q_NULLPTR)
- : WizardPage(parent),
- signPref(),
- pgpCB(i18n("Sign with OpenPGP"), this),
- cmsCB(i18n("Sign with S/MIME"), this),
- widget(this)
+ QVector<Key> recipients() const
{
- setTitle(i18nc("@title", "Who do you want to sign as?"));
- setSubTitle(i18nc("@title",
- "Please choose an identity with which to sign the data."));
- // this one is always a commit page
- setCommitPage(true);
-
- QVBoxLayout *vlay = new QVBoxLayout(this);
-
- KDAB_SET_OBJECT_NAME(pgpCB);
- KDAB_SET_OBJECT_NAME(cmsCB);
- KDAB_SET_OBJECT_NAME(widget);
- KDAB_SET_OBJECT_NAME(vlay);
-
- vlay->addWidget(&pgpCB);
- vlay->addWidget(&cmsCB);
-
- widget.layout()->setMargin(0);
- vlay->addWidget(&widget);
-
- // ### connect something to completeChanged()
- // ### deal with widget.rememberAsDefault()
-
- connect(&pgpCB, &QAbstractButton::toggled, this, &SignerPage::slotSignProtocolToggled);
- connect(&cmsCB, &QAbstractButton::toggled, this, &SignerPage::slotSignProtocolToggled);
+ return mWidget->recipients();
}
- std::vector<Key> keys() const
+ /* In the future we might find a usecase for multiple
+ * signers */
+ QVector<Key> signers() const
{
- const QMap<Protocol, Key> keys = widget.selectedCertificates();
- const bool pgp = pgpCB.isChecked();
- const bool cms = cmsCB.isChecked();
-
- std::vector<Key> result;
- result.reserve(pgp + cms);
-
- if (pgp) {
- result.push_back(keys[OpenPGP]);
- }
- if (cms) {
- result.push_back(keys[CMS]);
+ QVector<Key> ret;
+ const Key k = mWidget->signKey();
+ if (!k.isNull()) {
+ ret << k;
}
-
- // remove empty keys, for good measure...
- result.erase(std::remove_if(result.begin(), result.end(), mem_fn(&Key::isNull)),
- result.end());
- return result;
- }
-
- bool isComplete() const Q_DECL_OVERRIDE
- {
- return !keys().empty();
- }
-
- int nextId() const Q_DECL_OVERRIDE
- {
- return ResultPageId;
- }
-
- void initializePage() Q_DECL_OVERRIDE {
-
- if (QWizard *wiz = wizard())
- {
- // need to do this here, since wizard() == 0 in the ctor
- const SignEncryptFilesWizard *filesWizard = qobject_cast<SignEncryptFilesWizard *>(wiz);
- disconnect(filesWizard, &SignEncryptFilesWizard::operationPrepared, this, &SignerPage::slotCommitSigningPreferences);
- connect(filesWizard, &SignEncryptFilesWizard::operationPrepared, this, &SignerPage::slotCommitSigningPreferences);
- }
-
- bool pgp = effectiveProtocol() == OpenPGP;
- bool cms = effectiveProtocol() == CMS;
-
- if (effectiveProtocol() == UnknownProtocol)
- {
- pgp = cms = true;
- }
-
- assert(pgp || cms);
-
- if (isSignOnlySelected())
- {
- // free choice of OpenPGP and/or CMS
- // (except when protocol() requires otherwise):
- pgpCB.setEnabled(pgp);
- cmsCB.setEnabled(cms);
- pgpCB.setChecked(pgp);
- cmsCB.setChecked(cms);
-
- setButtonText(QWizard::CommitButton, i18nc("@action", "Sign"));
- } else {
- // we need signing keys for each of protocols that
- // make up the recipients:
-
- const std::vector<Key> &recipients = resolvedRecipients();
- if (_detail::none_of_protocol(recipients, OpenPGP))
- {
- pgp = false;
- }
- if (_detail::none_of_protocol(recipients, CMS))
- {
- cms = false;
- }
-
- pgpCB.setEnabled(false);
- cmsCB.setEnabled(false);
- pgpCB.setChecked(pgp);
- cmsCB.setChecked(cms);
-
- setButtonText(QWizard::CommitButton, i18nc("@action", "Sign && Encrypt"));
- }
-
- if (!signPref)
- {
- signPref.reset(new KConfigBasedSigningPreferences(KSharedConfig::openConfig()));
- widget.setSelectedCertificates(signPref->preferredCertificate(OpenPGP),
- signPref->preferredCertificate(CMS));
- }
- }
-
-private:
- const std::vector<Key> &resolvedRecipients() const
- {
- assert(wizard());
- assert(qobject_cast<SignEncryptFilesWizard *>(wizard()) == static_cast<SignEncryptFilesWizard *>(wizard()));
- return static_cast<SignEncryptFilesWizard *>(wizard())->resolvedRecipients();
+ return ret;
}
private Q_SLOTS:
- void slotSignProtocolToggled()
+ void updateCommitButton(const QString &label)
{
- widget.setAllowedProtocols(pgpCB.isChecked(), cmsCB.isChecked());
- Q_EMIT completeChanged();
- }
-
- void slotCommitSigningPreferences()
- {
- if (widget.rememberAsDefault())
- Q_FOREACH (const GpgME::Key &key, keys())
- if (!key.isNull()) {
- signPref->setPreferredCertificate(key.protocol(), key);
- }
+ setButtonText(QWizard::CommitButton, label);
}
private:
- shared_ptr<SigningPreferences> signPref;
- QCheckBox pgpCB, cmsCB;
- SigningCertificateSelectionWidget widget;
+ SignEncryptWidget *mWidget;
};
class ResultPage : public NewResultPage
@@ -1019,90 +181,26 @@ public:
};
+SignEncryptFilesWizard::SignEncryptFilesWizard(QWidget *parent, Qt::WindowFlags f)
+ : QWizard(parent, f)
+{
+ mSigEncPage = new SigEncPage(this);
+ mResultPage = new ResultPage(this);
+
+ connect(this, &QWizard::currentIdChanged, this,
+ &SignEncryptFilesWizard::slotCurrentIdChanged);
+ setPage(SigEncPageId, mSigEncPage);
+ setPage(ResultPageId, mResultPage);
+ setOptions(QWizard::IndependentPages |
+ QWizard::NoBackButtonOnLastPage |
+ QWizard::NoBackButtonOnStartPage);
}
-class SignEncryptFilesWizard::Private
+void SignEncryptFilesWizard::slotCurrentIdChanged(int id)
{
- friend class ::Kleo::Crypto::Gui::SignEncryptFilesWizard;
- SignEncryptFilesWizard *const q;
-public:
- explicit Private(SignEncryptFilesWizard *qq)
- : q(qq),
- operationPage(new OperationPage(q)),
- recipientsPage(new RecipientsPage(q)),
- signerPage(new SignerPage(q)),
- resultPage(new ResultPage(q)),
- createArchivePreset(false),
- createArchiveUserMutable(true),
- signingPreset(true),
- signingUserMutable(true),
- encryptionPreset(true),
- encryptionUserMutable(true)
- {
- KDAB_SET_OBJECT_NAME(operationPage);
- KDAB_SET_OBJECT_NAME(recipientsPage);
- KDAB_SET_OBJECT_NAME(signerPage);
- KDAB_SET_OBJECT_NAME(resultPage);
-
- q->setPage(OperationPageId, operationPage);
- q->setPage(RecipientsPageId, recipientsPage);
- q->setPage(SignerPageId, signerPage);
- q->setPage(ResultPageId, resultPage);
-
- connect(q, SIGNAL(currentIdChanged(int)), q, SLOT(slotCurrentIdChanged(int)));
- }
-
-private:
- void slotCurrentIdChanged(int id)
- {
- if (id == ResultPageId) {
- Q_EMIT q->operationPrepared();
- }
+ if (id == ResultPageId) {
+ Q_EMIT operationPrepared();
}
-
-private:
- int startId() const
- {
- if (!createArchivePreset && !createArchiveUserMutable) {
- if (signingPreset && !encryptionPreset && !encryptionUserMutable) {
- return SignerPageId;
- }
- if ((encryptionPreset && !signingPreset && !signingUserMutable) ||
- (signingPreset && !signingUserMutable && encryptionPreset && !encryptionUserMutable)) {
- return RecipientsPageId;
- }
- }
- if (signingUserMutable || encryptionUserMutable || createArchivePreset || createArchiveUserMutable) {
- return OperationPageId;
- } else if (encryptionPreset) {
- return RecipientsPageId;
- } else {
- return SignerPageId;
- }
- }
- void updateStartId()
- {
- q->setStartId(startId());
- }
-
-private:
- OperationPage *operationPage;
- RecipientsPage *recipientsPage;
- SignerPage *signerPage;
- ResultPage *resultPage;
-
- bool createArchivePreset : 1;
- bool createArchiveUserMutable : 1;
- bool signingPreset : 1;
- bool signingUserMutable : 1;
- bool encryptionPreset : 1;
- bool encryptionUserMutable : 1;
-};
-
-SignEncryptFilesWizard::SignEncryptFilesWizard(QWidget *parent, Qt::WindowFlags f)
- : QWizard(parent, f), d(new Private(this))
-{
-
}
SignEncryptFilesWizard::~SignEncryptFilesWizard()
@@ -1110,127 +208,51 @@ SignEncryptFilesWizard::~SignEncryptFilesWizard()
qCDebug(KLEOPATRA_LOG);
}
-void SignEncryptFilesWizard::setPresetProtocol(Protocol proto)
-{
- d->operationPage->setPresetProtocol(proto);
- d->recipientsPage->setPresetProtocol(proto);
- d->signerPage->setPresetProtocol(proto);
-}
-
-void SignEncryptFilesWizard::setCreateArchivePreset(bool preset)
-{
- if (preset == d->createArchivePreset && preset == isCreateArchiveSelected()) {
- return;
- }
- d->createArchivePreset = preset;
- setField(QStringLiteral("archive"), preset);
- d->updateStartId();
-}
-
-void SignEncryptFilesWizard::setCreateArchiveUserMutable(bool mut)
-{
- if (mut == d->createArchiveUserMutable) {
- return;
- }
- d->createArchiveUserMutable = mut;
- setField(QStringLiteral("archive-user-mutable"), mut);
- d->updateStartId();
-}
-
-void SignEncryptFilesWizard::setArchiveDefinitionId(const QString &id)
-{
- d->operationPage->setArchiveDefinition(id);
-}
-
void SignEncryptFilesWizard::setSigningPreset(bool preset)
{
- if (preset == d->signingPreset) {
+ if (preset == mSigningPreset) {
return;
}
- d->signingPreset = preset;
- setField(QStringLiteral("signing-preset"), preset);
- d->updateStartId();
+ mSigningPreset = preset;
}
void SignEncryptFilesWizard::setSigningUserMutable(bool mut)
{
- if (mut == d->signingUserMutable) {
+ if (mut == mSigningUserMutable) {
return;
}
- d->signingUserMutable = mut;
- setField(QStringLiteral("signing-user-mutable"), mut);
- d->updateStartId();
+ mSigningUserMutable = mut;
}
void SignEncryptFilesWizard::setEncryptionPreset(bool preset)
{
- if (preset == d->encryptionPreset) {
+ if (preset == mEncryptionPreset) {
return;
}
- d->encryptionPreset = preset;
- setField(QStringLiteral("encryption-preset"), preset);
- d->updateStartId();
+ mEncryptionPreset = preset;
}
void SignEncryptFilesWizard::setEncryptionUserMutable(bool mut)
{
- if (mut == d->encryptionUserMutable) {
+ if (mut == mEncryptionUserMutable) {
return;
}
- d->encryptionUserMutable = mut;
- setField(QStringLiteral("encryption-user-mutable"), mut);
- d->updateStartId();
-}
-
-void SignEncryptFilesWizard::setFiles(const QStringList &files)
-{
- setField(QStringLiteral("files"), files);
-}
-
-bool SignEncryptFilesWizard::isSigningSelected() const
-{
- return field(QStringLiteral("sign")).toBool() || field(QStringLiteral("signencrypt")).toBool();
-}
-
-bool SignEncryptFilesWizard::isEncryptionSelected() const
-{
- return field(QStringLiteral("encrypt")).toBool() || field(QStringLiteral("signencrypt")).toBool();
-}
-
-bool SignEncryptFilesWizard::isAsciiArmorEnabled() const
-{
- return field(QStringLiteral("armor")).toBool();
-}
-
-bool SignEncryptFilesWizard::isCreateArchiveSelected() const
-{
- return field(QStringLiteral("archive")).toBool();
-}
-
-shared_ptr<ArchiveDefinition> SignEncryptFilesWizard::selectedArchiveDefinition() const
-{
- return d->operationPage->archiveDefinition();
-}
-
-QString SignEncryptFilesWizard::archiveFileName(Protocol p) const
-{
- return d->/*any page*/operationPage->archiveName(p);
+ mEncryptionUserMutable = mut;
}
-const std::vector<Key> &SignEncryptFilesWizard::resolvedRecipients() const
+QVector<Key> SignEncryptFilesWizard::resolvedRecipients() const
{
- return d->recipientsPage->keys();
+ return mSigEncPage->recipients();
}
-std::vector<Key> SignEncryptFilesWizard::resolvedSigners() const
+QVector<Key> SignEncryptFilesWizard::resolvedSigners() const
{
- return d->signerPage->keys();
+ return mSigEncPage->signers();
}
-void SignEncryptFilesWizard::setTaskCollection(const shared_ptr<TaskCollection> &coll)
+void SignEncryptFilesWizard::setTaskCollection(const boost::shared_ptr<Kleo::Crypto::TaskCollection> &coll)
{
- d->resultPage->setTaskCollection(coll);
+ mResultPage->setTaskCollection(coll);
}
-#include "moc_signencryptfileswizard.cpp"
#include "signencryptfileswizard.moc"
diff --git a/src/crypto/gui/signencryptfileswizard.h b/src/crypto/gui/signencryptfileswizard.h
index c694b43..0a0030b 100644
--- a/src/crypto/gui/signencryptfileswizard.h
+++ b/src/crypto/gui/signencryptfileswizard.h
@@ -30,8 +30,8 @@
your version.
*/
-#ifndef __KLEOPATRA_CRYPTO_GUI_NEWSIGNENCRYPTFILESWIZARD_H__
-#define __KLEOPATRA_CRYPTO_GUI_NEWSIGNENCRYPTFILESWIZARD_H__
+#ifndef __KLEOPATRA_CRYPTO_GUI_SIGNENCRYPTFILESWIZARD_H__
+#define __KLEOPATRA_CRYPTO_GUI_SIGNENCRYPTFILESWIZARD_H__
#include <utils/pimpl_ptr.h>
@@ -39,15 +39,11 @@
#include <QWizard>
-#include <vector>
+#include <QVector>
-class QStringList;
-template <typename T> class QList;
+#include <boost/shared_ptr.hpp>
-namespace boost
-{
-template <typename T> class shared_ptr;
-}
+class QStringList;
namespace GpgME
{
@@ -56,23 +52,18 @@ class Key;
namespace Kleo
{
-class ArchiveDefinition;
-}
-
-namespace Kleo
-{
namespace Crypto
{
class TaskCollection;
}
}
+class ResultPage;
+class SigEncPage;
+
namespace Kleo
{
-namespace Crypto
-{
-namespace Gui
-{
+class SignEncryptWidget;
class SignEncryptFilesWizard : public QWizard
{
@@ -82,49 +73,33 @@ public:
~SignEncryptFilesWizard();
// Inputs
-
- void setPresetProtocol(GpgME::Protocol proto);
-
- void setCreateArchivePreset(bool preset);
- void setCreateArchiveUserMutable(bool mut);
-
- void setArchiveDefinitionId(const QString &id);
-
void setSigningPreset(bool preset);
void setSigningUserMutable(bool mut);
void setEncryptionPreset(bool preset);
void setEncryptionUserMutable(bool mut);
- void setFiles(const QStringList &files);
+ void setTaskCollection(const boost::shared_ptr<Kleo::Crypto::TaskCollection> &coll);
// Outputs
-
- bool isCreateArchiveSelected() const;
- boost::shared_ptr<ArchiveDefinition> selectedArchiveDefinition() const;
- QString archiveFileName(GpgME::Protocol proto) const;
-
- bool isSigningSelected() const;
- bool isEncryptionSelected() const;
-
- bool isAsciiArmorEnabled() const;
-
- const std::vector<GpgME::Key> &resolvedRecipients() const;
- std::vector<GpgME::Key> resolvedSigners() const;
-
- void setTaskCollection(const boost::shared_ptr<TaskCollection> &coll);
+ QVector<GpgME::Key> resolvedRecipients() const;
+ QVector<GpgME::Key> resolvedSigners() const;
Q_SIGNALS:
void operationPrepared();
+private Q_SLOTS:
+ void slotCurrentIdChanged(int);
+
private:
- class Private;
- kdtools::pimpl_ptr<Private> d;
- Q_PRIVATE_SLOT(d, void slotCurrentIdChanged(int))
+ SigEncPage *mSigEncPage;
+ ResultPage *mResultPage;
+ bool mSigningPreset,
+ mSigningUserMutable,
+ mEncryptionUserMutable,
+ mEncryptionPreset;
};
}
-}
-}
-#endif /* __KLEOPATRA_CRYPTO_GUI_NEWSIGNENCRYPTFILESWIZARD_H__ */
+#endif /* __KLEOPATRA_CRYPTO_GUI_SIGNENCRYPTFILESWIZARD_H__ */
diff --git a/src/crypto/gui/signencryptwidget.cpp b/src/crypto/gui/signencryptwidget.cpp
new file mode 100644
index 0000000..d1fdac5
--- /dev/null
+++ b/src/crypto/gui/signencryptwidget.cpp
@@ -0,0 +1,108 @@
+/* crypto/signencryptwidget.cpp
+
+ This file is part of Kleopatra, the KDE keymanager
+ Copyright (c) 2016 Intevation GmbH
+
+ Kleopatra is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Kleopatra is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#include "signencryptwidget.h"
+
+#include "kleopatra_debug.h"
+
+#include "certificateselectionwidget.h"
+
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QGroupBox>
+
+#include <Libkleo/KeyRequester>
+
+#include <KLocalizedString>
+#include <KSharedConfig>
+
+using namespace Kleo;
+using namespace Kleo::Dialogs;
+using namespace GpgME;
+
+SignEncryptWidget::SignEncryptWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ QVBoxLayout *lay = new QVBoxLayout;
+
+ QVBoxLayout *sigLay = new QVBoxLayout;
+ QGroupBox *sigBox = new QGroupBox(i18nc("@label", "Protect Authenticity (Sign):"));
+ sigBox->setCheckable(true);
+ sigBox->setChecked(true);
+ mSigSelect = new CertificateSelectionWidget(this,
+ CertificateSelectionDialog::SignOnly |
+ CertificateSelectionDialog::SecretKeys |
+ CertificateSelectionDialog::AnyFormat,
+ false);
+ sigLay->addWidget(mSigSelect);
+ sigBox->setLayout(sigLay);
+ lay->addWidget(sigBox);
+
+ connect(sigBox, &QGroupBox::toggled, mSigSelect, &QWidget::setEnabled);
+ connect(sigBox, &QGroupBox::toggled, this, &SignEncryptWidget::updateOp);
+ connect(mSigSelect, &CertificateSelectionWidget::keyChanged,
+ this, &SignEncryptWidget::updateOp);
+
+ setLayout(lay);
+}
+
+Key SignEncryptWidget::signKey() const
+{
+ if (mSigSelect->isEnabled()) {
+ return mSigSelect->key();
+ }
+ return Key();
+}
+
+Key SignEncryptWidget::selfKey() const
+{
+ return Key();
+}
+
+QVector <Key> SignEncryptWidget::recipients() const
+{
+ return QVector<Key>();
+}
+
+void SignEncryptWidget::updateOp()
+{
+ if (!signKey().isNull()) {
+ mOp = i18nc("@action", "Sign");
+ } else {
+ mOp = QString();
+ }
+ Q_EMIT operationChanged(mOp);
+}
+
+QString SignEncryptWidget::currentOp() const
+{
+ return mOp;
+}
diff --git a/src/crypto/gui/signencryptwidget.h b/src/crypto/gui/signencryptwidget.h
new file mode 100644
index 0000000..3793ad9
--- /dev/null
+++ b/src/crypto/gui/signencryptwidget.h
@@ -0,0 +1,79 @@
+/* crypto/signencryptwidget.h
+
+ This file is part of Kleopatra, the KDE keymanager
+ Copyright (c) 2016 Intevation GmbH
+
+ Kleopatra is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Kleopatra is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+#ifndef CRYPTO_GUI_SIGNENCRYPTWIDGET_H
+#define CRYPTO_GUI_SIGNENCRYPTWIDGET_H
+
+#include <QWidget>
+#include <QVector>
+#include <gpgme++/key.h>
+
+namespace Kleo
+{
+class CertificateSelectionWidget;
+
+class SignEncryptWidget: public QWidget
+{
+ Q_OBJECT
+public:
+ explicit SignEncryptWidget(QWidget *parent = Q_NULLPTR);
+
+ /** Returns the list of recipients selected in the dialog
+ * or an empty list if encryption is disabled */
+ QVector <GpgME::Key> recipients() const;
+
+ /** Returns the selected signing key or a null key if signing
+ * is disabled. */
+ GpgME::Key signKey() const;
+
+ /** Returns the selected encrypt to self key or a null key if
+ * encrypt to self is disabled. */
+ GpgME::Key selfKey() const;
+
+ /** Returns the operation based on the current selection or
+ * a null string if nothing would happen. */
+ QString currentOp() const;
+
+protected Q_SLOTS:
+ void updateOp();
+
+Q_SIGNALS:
+ /* Emitted when the certificate selection changed the operation
+ * with that selection. e.g. "Sign" or "Sign/Encrypt".
+ * If no crypto operation is selected this returns a null string. */
+ void operationChanged(const QString &op);
+
+private:
+ CertificateSelectionWidget *mSigSelect,
+ *mEncSelect;
+ QString mOp;
+};
+} // namespace Kleo
+#endif // CRYPTO_GUI_SIGNENCRYPTWIDGET_H
diff --git a/src/crypto/signencryptfilescontroller.cpp b/src/crypto/signencryptfilescontroller.cpp
index 224df03..14bcb9e 100644
--- a/src/crypto/signencryptfilescontroller.cpp
+++ b/src/crypto/signencryptfilescontroller.cpp
@@ -62,7 +62,6 @@
using namespace Kleo;
using namespace Kleo::Crypto;
-using namespace Kleo::Crypto::Gui;
using namespace boost;
using namespace GpgME;
using namespace KMime::Types;
@@ -197,7 +196,6 @@ void SignEncryptFilesController::setProtocol(Protocol proto)
d->protocol == proto);
d->protocol = proto;
d->ensureWizardCreated();
- d->wizard->setPresetProtocol(proto);
}
Protocol SignEncryptFilesController::protocol() const
@@ -238,7 +236,6 @@ void SignEncryptFilesController::Private::updateWizardMode()
wizard->setWindowTitle(titleForOperation(operation));
const unsigned int signOp = (operation & SignMask);
const unsigned int encrOp = (operation & EncryptMask);
- const unsigned int archOp = (operation & ArchiveMask);
if (signOp == SignDisallowed) {
wizard->setSigningUserMutable(false);
@@ -263,17 +260,6 @@ void SignEncryptFilesController::Private::updateWizardMode()
wizard->setEncryptionPreset(true);
}
}
-
- if (archOp == ArchiveDisallowed) {
- wizard->setCreateArchivePreset(false);
- wizard->setCreateArchiveUserMutable(false);
- } else if (archOp == ArchiveForced) {
- wizard->setCreateArchiveUserMutable(false);
- wizard->setCreateArchivePreset(true);
- } else {
- wizard->setCreateArchiveUserMutable(true);
- wizard->setCreateArchivePreset(false);
- }
}
unsigned int SignEncryptFilesController::operationMode() const
@@ -289,7 +275,6 @@ void SignEncryptFilesController::setFiles(const QStringList &files)
setOperationMode((operationMode() & ~ArchiveMask) | ArchiveForced);
}
d->ensureWizardCreated();
- d->wizard->setFiles(files);
}
void SignEncryptFilesController::Private::slotWizardCanceled()
@@ -320,17 +305,17 @@ static const char *extension(bool pgp, bool sign, bool encrypt, bool ascii, bool
}
static shared_ptr<SignEncryptFilesTask>
-createSignEncryptTaskForFileInfo(const QFileInfo &fi, bool pgp, bool sign, bool encrypt, bool ascii, const std::vector<Key> &recipients, const std::vector<Key> &signers)
+createSignEncryptTaskForFileInfo(const QFileInfo &fi, bool pgp, bool ascii, const std::vector<Key> &recipients, const std::vector<Key> &signers)
{
const shared_ptr<SignEncryptFilesTask> task(new SignEncryptFilesTask);
- task->setSign(sign);
- task->setEncrypt(encrypt);
task->setAsciiArmor(ascii);
- if (sign) {
+ if (!signers.empty()) {
+ task->setSign(true);
task->setSigners(signers);
task->setDetachedSignature(true);
}
- if (encrypt) {
+ if (!recipients.empty()) {
+ task->setEncrypt(true);
task->setRecipients(recipients);
}
@@ -338,7 +323,7 @@ createSignEncryptTaskForFileInfo(const QFileInfo &fi, bool pgp, bool sign, bool
task->setInputFileName(input);
task->setInput(Input::createFromFile(input));
- const char *const ext = extension(pgp, sign, encrypt, ascii, true);
+ const char *const ext = extension(pgp, !signers.empty(), !recipients.empty(), ascii, true);
kleo_assert(ext);
const QString output = input + QLatin1Char('.') + QLatin1String(ext);
@@ -379,25 +364,21 @@ createArchiveSignEncryptTaskForFiles(const QStringList &files, const QString &ou
}
static std::vector< shared_ptr<SignEncryptFilesTask> >
-createSignEncryptTasksForFileInfo(const QFileInfo &fi, bool sign, bool encrypt, bool ascii, const std::vector<Key> &pgpRecipients, const std::vector<Key> &pgpSigners, const std::vector<Key> &cmsRecipients, const std::vector<Key> &cmsSigners)
+createSignEncryptTasksForFileInfo(const QFileInfo &fi, bool ascii, const std::vector<Key> &pgpRecipients, const std::vector<Key> &pgpSigners, const std::vector<Key> &cmsRecipients, const std::vector<Key> &cmsSigners)
{
std::vector< shared_ptr<SignEncryptFilesTask> > result;
- const bool shallPgpSign = sign && !pgpSigners.empty();
- const bool shallPgpEncrypt = encrypt && !pgpRecipients.empty();
- const bool pgp = (shallPgpEncrypt && (!sign || shallPgpSign)) || (!encrypt && shallPgpSign);
+ const bool pgp = !pgpSigners.empty() || !pgpRecipients.empty();
- const bool shallCmsSign = sign && !cmsSigners.empty();
- const bool shallCmsEncrypt = encrypt && !cmsRecipients.empty();
- const bool cms = (shallCmsEncrypt && (!sign || shallCmsSign)) || (!encrypt && shallCmsSign);
+ const bool cms = !cmsSigners.empty() || !cmsRecipients.empty();
result.reserve(pgp + cms);
if (pgp) {
- result.push_back(createSignEncryptTaskForFileInfo(fi, true, sign, encrypt, ascii, pgpRecipients, pgpSigners));
+ result.push_back(createSignEncryptTaskForFileInfo(fi, true, ascii, pgpRecipients, pgpSigners));
}
if (cms) {
- result.push_back(createSignEncryptTaskForFileInfo(fi, false, sign, encrypt, ascii, cmsRecipients, cmsSigners));
+ result.push_back(createSignEncryptTaskForFileInfo(fi, false, ascii, cmsRecipients, cmsSigners));
}
return result;
@@ -432,37 +413,31 @@ void SignEncryptFilesController::Private::slotWizardOperationPrepared()
{
try {
-
kleo_assert(wizard);
kleo_assert(!files.empty());
- const bool archive = wizard->isCreateArchiveSelected();
+ const bool archive = files.size() > 1;
- const bool sign = wizard->isSigningSelected();
- const bool encrypt = wizard->isEncryptionSelected();
+ const QVector<Key> recipients = wizard->resolvedRecipients();
+ const QVector<Key> signers = wizard->resolvedSigners();
- const bool ascii = wizard->isAsciiArmorEnabled();
+ const bool ascii = false; /* TODO andre config */
- std::vector<Key> pgpRecipients, cmsRecipients, pgpSigners, cmsSigners;
- if (encrypt) {
- const std::vector<Key> recipients = wizard->resolvedRecipients();
- kdtools::copy_if(recipients.begin(), recipients.end(),
- std::back_inserter(pgpRecipients),
- boost::bind(&Key::protocol, _1) == GpgME::OpenPGP);
- kdtools::copy_if(recipients.begin(), recipients.end(),
- std::back_inserter(cmsRecipients),
- boost::bind(&Key::protocol, _1) == GpgME::CMS);
- kleo_assert(pgpRecipients.size() + cmsRecipients.size() == recipients.size());
+ QVector<Key> pgpRecipients, cmsRecipients, pgpSigners, cmsSigners;
+ Q_FOREACH (const Key k, recipients) {
+ if (k.protocol() == GpgME::OpenPGP) {
+ pgpRecipients << k;
+ } else {
+ cmsRecipients << k;
+ }
}
- if (sign) {
- const std::vector<Key> signers = wizard->resolvedSigners();
- kdtools::copy_if(signers.begin(), signers.end(),
- std::back_inserter(pgpSigners),
- boost::bind(&Key::protocol, _1) == GpgME::OpenPGP);
- kdtools::copy_if(signers.begin(), signers.end(),
- std::back_inserter(cmsSigners),
- boost::bind(&Key::protocol, _1) == GpgME::CMS);
- kleo_assert(pgpSigners.size() + cmsSigners.size() == signers.size());
+
+ Q_FOREACH (Key k, signers) {
+ if (k.protocol() == GpgME::OpenPGP) {
+ pgpSigners << k;
+ } else {
+ cmsSigners << k;
+ }
}
std::vector< shared_ptr<SignEncryptFilesTask> > tasks;
@@ -470,19 +445,27 @@ void SignEncryptFilesController::Private::slotWizardOperationPrepared()
tasks.reserve(files.size());
}
- if (archive)
+ if (archive) {
+ /* TODO Andre Port
tasks = createArchiveSignEncryptTasksForFiles(files,
wizard->archiveFileName(OpenPGP),
wizard->archiveFileName(CMS),
wizard->selectedArchiveDefinition(),
sign, encrypt, ascii,
pgpRecipients, pgpSigners, cmsRecipients, cmsSigners);
- else
+
+ */
+ } else {
Q_FOREACH (const QString &file, files) {
const std::vector< shared_ptr<SignEncryptFilesTask> > created =
- createSignEncryptTasksForFileInfo(QFileInfo(file), sign, encrypt, ascii, pgpRecipients, pgpSigners, cmsRecipients, cmsSigners);
+ createSignEncryptTasksForFileInfo(QFileInfo(file), ascii,
+ pgpRecipients.toStdVector(),
+ pgpSigners.toStdVector(),
+ cmsRecipients.toStdVector(),
+ cmsSigners.toStdVector());
tasks.insert(tasks.end(), created.begin(), created.end());
}
+ }
const shared_ptr<OverwritePolicy> overwritePolicy(new OverwritePolicy(wizard));
Q_FOREACH (const shared_ptr<SignEncryptFilesTask> &i, tasks) {
@@ -497,7 +480,8 @@ void SignEncryptFilesController::Private::slotWizardOperationPrepared()
q->connectTask(task);
}
- shared_ptr<TaskCollection> coll(new TaskCollection);
+ boost::shared_ptr<TaskCollection> coll(new TaskCollection);
+
std::vector<shared_ptr<Task> > tmp;
std::copy(runnable.begin(), runnable.end(), std::back_inserter(tmp));
coll->setTasks(tmp);