Page MenuHome GnuPG

No OneTemporary

diff --git a/crypto/gui/signemailwizard.cpp b/crypto/gui/signemailwizard.cpp
index 331b9fd17..a16de81f2 100644
--- a/crypto/gui/signemailwizard.cpp
+++ b/crypto/gui/signemailwizard.cpp
@@ -1,139 +1,156 @@
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/gui/signemailwizard.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2008 Klarälvdalens Datakonsult AB
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 <config-kleopatra.h>
#include "signemailwizard.h"
#include "signerresolvepage.h"
+#include <utils/formatting.h>
+
#include <KLocale>
#include <gpgme++/key.h>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Crypto::Gui;
using namespace GpgME;
namespace {
class SignerResolveValidator : public SignerResolvePage::Validator {
public:
- explicit SignerResolveValidator( SignerResolvePage* page );
+ explicit SignerResolveValidator( SignerResolvePage* page );
bool isComplete() const;
QString explanation() const;
void update() const;
private:
SignerResolvePage* m_page;
mutable QString expl;
mutable bool complete;
};
}
SignerResolveValidator::SignerResolveValidator( SignerResolvePage* page ) : SignerResolvePage::Validator(), m_page( page ), complete( true )
{
assert( m_page );
}
void SignerResolveValidator::update() const {
- complete = !m_page->signingCertificates( m_page->protocol() ).empty();
- expl = complete ? QString() : i18n( "You need to select an %1 signing certificate to proceed.", m_page->protocol() == OpenPGP ? i18n( "OpenPGP" ) : i18n( "S/MIME") );
-
+ const bool haveSelected = !m_page->selectedProtocols().empty();
+ const std::vector<Protocol> missing = m_page->selectedProtocolsWithoutSigningCertificate();
+
+ complete = haveSelected && missing.empty();
+ expl.clear();
+ if ( complete )
+ return;
+ if ( !haveSelected ) {
+ expl = i18n( "You need to select a signing certificate to proceed." );
+ return;
+ }
+
+ assert( missing.size() <= 2 );
+ if ( missing.size() == 1 )
+ expl = i18n( "You need to select an %1 signing certificate to proceed.", Formatting::displayName( missing[0] ) );
+ else
+ expl = i18n( "You need to select %1 and %2 signing certificates to proceed.", Formatting::displayName( missing[0] ), Formatting::displayName( missing[1] ) );
}
QString SignerResolveValidator::explanation() const {
update();
return expl;
}
bool SignerResolveValidator::isComplete() const {
update();
return complete;
}
class SignEMailWizard::Private {
friend class ::Kleo::Crypto::Gui::SignEMailWizard;
SignEMailWizard * const q;
public:
explicit Private( SignEMailWizard * qq );
~Private();
-
+
void operationSelected();
bool m_quickMode;
};
SignEMailWizard::Private::Private( SignEMailWizard * qq )
: q( qq ), m_quickMode( false )
{
q->setWindowTitle( i18n("Sign Mail Message") );
std::vector<int> pageOrder;
q->setSignerResolvePageValidator( boost::shared_ptr<SignerResolveValidator>( new SignerResolveValidator( q->signerResolvePage() ) ) );
pageOrder.push_back( SignEncryptWizard::ResolveSignerPage );
pageOrder.push_back( SignEncryptWizard::ResultPage );
q->setPageOrder( pageOrder );
q->setCommitPage( SignEncryptWizard::ResolveSignerPage );
q->setEncryptionSelected( false );
q->setEncryptionUserMutable( false );
q->setSigningSelected( true );
q->setSigningUserMutable( false );
+ q->signerResolvePage()->setProtocolSelectionUserMutable( false );
q->setMultipleProtocolsAllowed( false );
}
SignEMailWizard::Private::~Private() {}
SignEMailWizard::SignEMailWizard( QWidget * parent, Qt::WFlags f )
: SignEncryptWizard( parent, f ), d( new Private( this ) )
{
}
bool SignEMailWizard::quickMode() const
{
return d->m_quickMode;
}
void SignEMailWizard::setQuickMode( bool quick )
{
if ( quick == d->m_quickMode )
return;
d->m_quickMode = quick;
signerResolvePage()->setAutoAdvance( quick );
setKeepResultPageOpenWhenDone( !quick );
}
SignEMailWizard::~SignEMailWizard() {}
#include "moc_signemailwizard.cpp"
diff --git a/crypto/gui/signencryptfileswizard.cpp b/crypto/gui/signencryptfileswizard.cpp
index fad068ce1..748523821 100644
--- a/crypto/gui/signencryptfileswizard.cpp
+++ b/crypto/gui/signencryptfileswizard.cpp
@@ -1,183 +1,184 @@
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/gui/signencryptfileswizard.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2007 Klarälvdalens Datakonsult AB
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 <config-kleopatra.h>
#include "signencryptfileswizard.h"
#include "signerresolvepage.h"
#include <KLocale>
#include <gpgme++/key.h>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Crypto::Gui;
+using namespace GpgME;
namespace {
class SignerResolveValidator : public SignerResolvePage::Validator {
public:
explicit SignerResolveValidator( SignerResolvePage* page );
bool isComplete() const;
QString explanation() const;
void update() const;
private:
SignerResolvePage* const m_page;
mutable QString expl;
mutable bool complete;
};
}
SignerResolveValidator::SignerResolveValidator( SignerResolvePage* page ) : SignerResolvePage::Validator(), m_page( page ), complete( true )
{
assert( m_page );
}
void SignerResolveValidator::update() const {
+ expl.clear();
const bool needPgpSC = m_page->operation() == SignerResolvePage::SignAndEncrypt;
const bool isSignEncrypt = m_page->operation() == SignerResolvePage::SignAndEncrypt;
const bool needAnySC = m_page->operation() != SignerResolvePage::EncryptOnly;
const bool havePgpSC = !m_page->signingCertificates( GpgME::OpenPGP ).empty();
const bool haveCmsSC = !m_page->signingCertificates( GpgME::CMS ).empty();
const bool haveAnySC = havePgpSC || haveCmsSC;
-
complete = ( !needPgpSC || havePgpSC ) && ( !needAnySC || haveAnySC );
#undef setAndReturn
#define setAndReturn(text) { expl = text; return; }
if( needPgpSC && !havePgpSC )
setAndReturn( i18n( "You need to select an OpenPGP signing certificate to perform this operation." ) );
if ( needAnySC && !haveAnySC )
setAndReturn( i18n( "You need to select at least one signing certificate to proceed." ) );
if ( isSignEncrypt && needPgpSC && havePgpSC )
setAndReturn( i18n( "Only OpenPGP certificates will be offered for selection because you specified a combined sign/encrypt operation, which is only available for OpenPGP." ) );
if ( isSignEncrypt && havePgpSC && !haveCmsSC )
setAndReturn( i18n( "Only OpenPGP certificates will be offered for selection because you specified an OpenPGP signing certificate only." ) );
if ( haveCmsSC && !havePgpSC )
setAndReturn( i18n( "Only S/MIME certificates will be offered for selection because you specified an S/MIME signing certificate only." ) );
- const QString second = i18n( " One for OpenPGP recipients, one for S/MIME recipients." );
-
switch ( m_page->operation() )
{
- case SignerResolvePage::SignAndEncrypt:
- expl = i18n( "If you select certificates of both type OpenPGP and S/MIME, two encrypted files will be created." ) + second;
- break;
case SignerResolvePage::SignOnly:
- expl = QString();
+ if ( havePgpSC && haveCmsSC )
+ expl = i18n( "You have selected signing certificates of both type OpenPGP and S/MIME, thus two signatures will be created." );
break;
+ case SignerResolvePage::SignAndEncrypt:
case SignerResolvePage::EncryptOnly:
- expl = i18n( "If you select certificates of both type OpenPGP and S/MIME, two encrypted files will be created." ) + second;
+ expl = i18n( "If you select recipient certificates of both type OpenPGP and S/MIME, two encrypted files will be created. One for OpenPGP recipients, one for S/MIME recipients." );
break;
}
#undef setAndReturn
}
bool SignerResolveValidator::isComplete() const
{
update();
return complete;
}
QString SignerResolveValidator::explanation() const
{
update();
return expl;
}
class SignEncryptFilesWizard::Private {
friend class ::Kleo::Crypto::Gui::SignEncryptFilesWizard;
SignEncryptFilesWizard * const q;
public:
explicit Private( SignEncryptFilesWizard * qq );
~Private();
void operationSelected();
private:
};
SignEncryptFilesWizard::Private::Private( SignEncryptFilesWizard * qq )
: q( qq )
{
q->connect( q, SIGNAL( signersResolved() ), q, SLOT( operationSelected() ) );
std::vector<int> pageOrder;
q->setSignerResolvePageValidator( boost::shared_ptr<SignerResolveValidator>( new SignerResolveValidator( q->signerResolvePage() ) ) );
pageOrder.push_back( SignEncryptWizard::ResolveSignerPage );
pageOrder.push_back( SignEncryptWizard::ObjectsPage );
pageOrder.push_back( SignEncryptWizard::ResolveRecipientsPage );
pageOrder.push_back( SignEncryptWizard::ResultPage );
q->setPageOrder( pageOrder );
q->setCommitPage( SignEncryptWizard::ResolveRecipientsPage );
+ std::vector<Protocol> protocols;
+ protocols.push_back( OpenPGP );
+ protocols.push_back( CMS );
q->setMultipleProtocolsAllowed( true );
q->setRecipientsUserMutable( true );
}
SignEncryptFilesWizard::Private::~Private() {}
void SignEncryptFilesWizard::Private::operationSelected()
{
const bool encrypt = q->encryptionSelected();
q->setPageVisible( SignEncryptWizard::ResolveRecipientsPage, encrypt );
q->setCommitPage( encrypt ? SignEncryptWizard::ResolveRecipientsPage : SignEncryptWizard::ObjectsPage );
}
SignEncryptFilesWizard::SignEncryptFilesWizard( QWidget * parent, Qt::WFlags f )
: SignEncryptWizard( parent, f ), d( new Private( this ) )
{
}
SignEncryptFilesWizard::~SignEncryptFilesWizard() {}
void SignEncryptFilesWizard::onNext( int currentId )
{
SignEncryptWizard::onNext( currentId );
const bool encrypt = encryptionSelected();
if ( ( encrypt && currentId == ResolveRecipientsPage ) || ( !encrypt && currentId == ObjectsPage ) )
emit operationPrepared();
}
#include "moc_signencryptfileswizard.cpp"
diff --git a/crypto/gui/signencryptwizard.cpp b/crypto/gui/signencryptwizard.cpp
index 3fed54a68..3f7acbcbc 100644
--- a/crypto/gui/signencryptwizard.cpp
+++ b/crypto/gui/signencryptwizard.cpp
@@ -1,308 +1,310 @@
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/gui/signencryptwizard.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2007 Klarälvdalens Datakonsult AB
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 <config-kleopatra.h>
#include "signencryptwizard.h"
#include "objectspage.h"
#include "resolverecipientspage.h"
#include "signerresolvepage.h"
#include "resultpage.h"
#include <crypto/task.h>
#include <crypto/taskcollection.h>
#include <crypto/certificateresolver.h>
#include <utils/stl_util.h>
#include <utils/kleo_assert.h>
#include <gpgme++/key.h>
#include <KConfig>
#include <KGlobal>
#include <KLocale>
#include <QFileInfo>
#include <QTimer>
#include <boost/bind.hpp>
using namespace Kleo;
using namespace Kleo::Crypto;
using namespace Kleo::Crypto::Gui;
using namespace boost;
using namespace GpgME;
using namespace KMime::Types;
class SignEncryptWizard::Private {
friend class ::Kleo::Crypto::Gui::SignEncryptWizard;
SignEncryptWizard * q;
public:
explicit Private( SignEncryptWizard * qq );
~Private();
void setCommitPage( Page page );
Gui::ResolveRecipientsPage * recipientResolvePage; // clashes with enum of same name
SignerResolvePage * signerResolvePage;
Gui::ObjectsPage * objectsPage; // clashes with enum of same name
Gui::ResultPage * resultPage; // clashes with enum of same name
};
SignEncryptWizard::Private::Private( SignEncryptWizard * qq )
: q( qq ),
recipientResolvePage( new Gui::ResolveRecipientsPage ),
signerResolvePage( new SignerResolvePage ),
objectsPage( new Gui::ObjectsPage ),
resultPage( new Gui::ResultPage )
{
connect( resultPage, SIGNAL(linkActivated(QString)), q, SIGNAL(linkActivated(QString)) );
q->setPage( SignEncryptWizard::ResolveSignerPage, signerResolvePage );
q->setPage( SignEncryptWizard::ObjectsPage, objectsPage );
q->setPage( SignEncryptWizard::ResolveRecipientsPage, recipientResolvePage );
q->setPage( SignEncryptWizard::ResultPage, resultPage );
- //TODO: move the RecipientPreferences creation out of here, don't create a new instance for each wizard
+ //TODO: move the RecipientPreferences creation out of here, don't create a new instance for each wizard
recipientResolvePage->setRecipientPreferences( shared_ptr<RecipientPreferences>( new KConfigBasedRecipientPreferences( KGlobal::config() ) ) );
signerResolvePage->setSigningPreferences( shared_ptr<SigningPreferences>( new KConfigBasedSigningPreferences( KGlobal::config() ) ) );
q->resize( QSize( 640, 480 ).expandedTo( q->sizeHint() ) );
}
void SignEncryptWizard::onNext( int currentId )
{
if ( currentId == ResolveRecipientsPage )
QTimer::singleShot( 0, this, SIGNAL( recipientsResolved() ) );
if ( currentId == ResolveSignerPage ) {
//FIXME: Sign&Encrypt is only supported by OpenPGP. Remove this when we support this for CMS, too
if ( encryptionSelected() && signingSelected() )
setPresetProtocol( OpenPGP );
QTimer::singleShot( 0, this, SIGNAL( signersResolved() ) );
}
if ( currentId == ObjectsPage )
QTimer::singleShot( 0, this, SIGNAL( objectsResolved() ) );
}
SignEncryptWizard::Private::~Private() {}
SignEncryptWizard::SignEncryptWizard( QWidget * p, Qt::WindowFlags f )
: Wizard( p, f ), d( new Private( this ) )
{
}
SignEncryptWizard::~SignEncryptWizard() {}
void SignEncryptWizard::setCommitPage( Page page )
{
d->setCommitPage( page );
}
void SignEncryptWizard::Private::setCommitPage( Page page )
{
q->page( ResolveSignerPage )->setCommitPage( false );
q->page( ResolveRecipientsPage )->setCommitPage( false );
q->page( ObjectsPage )->setCommitPage( false );
q->page( ResultPage )->setCommitPage( false );
q->page( page )->setCommitPage( true );
}
void SignEncryptWizard::setPresetProtocol( Protocol proto ) {
- d->signerResolvePage->setProtocol( proto );
+ d->signerResolvePage->setPresetProtocol( proto );
+ d->signerResolvePage->setProtocolSelectionUserMutable( proto == UnknownProtocol );
d->recipientResolvePage->setPresetProtocol( proto );
}
GpgME::Protocol SignEncryptWizard::selectedProtocol() const
{
return d->recipientResolvePage->selectedProtocol();
}
GpgME::Protocol SignEncryptWizard::presetProtocol() const
{
return d->recipientResolvePage->presetProtocol();
}
-
+
void SignEncryptWizard::setEncryptionSelected( bool selected )
{
d->signerResolvePage->setEncryptionSelected( selected );
}
void SignEncryptWizard::setSigningSelected( bool selected )
{
d->signerResolvePage->setSigningSelected( selected );
}
bool SignEncryptWizard::isSigningUserMutable() const
{
return d->signerResolvePage->isSigningUserMutable();
}
void SignEncryptWizard::setSigningUserMutable( bool isMutable )
{
d->signerResolvePage->setSigningUserMutable( isMutable );
}
bool SignEncryptWizard::isEncryptionUserMutable() const
{
return d->signerResolvePage->isEncryptionUserMutable();
}
bool SignEncryptWizard::isMultipleProtocolsAllowed() const
{
return d->recipientResolvePage->multipleProtocolsAllowed();
}
void SignEncryptWizard::setMultipleProtocolsAllowed( bool allowed )
{
+ d->signerResolvePage->setMultipleProtocolsAllowed( allowed );
d->recipientResolvePage->setMultipleProtocolsAllowed( allowed );
}
void SignEncryptWizard::setEncryptionUserMutable( bool isMutable )
{
d->signerResolvePage->setEncryptionUserMutable( isMutable );
}
void SignEncryptWizard::setFiles( const QStringList & files ) {
d->objectsPage->setFiles( files );
}
QFileInfoList SignEncryptWizard::resolvedFiles() const {
const QStringList files = d->objectsPage->files();
QFileInfoList infos;
foreach ( const QString& i, files )
infos.push_back( QFileInfo( i ) );
- return infos;
+ return infos;
}
bool SignEncryptWizard::signingSelected() const {
return d->signerResolvePage->signingSelected();
}
bool SignEncryptWizard::encryptionSelected() const {
return d->signerResolvePage->encryptionSelected();
}
void SignEncryptWizard::setRecipients( const std::vector<Mailbox> & recipients ) {
d->recipientResolvePage->setRecipients( recipients );
}
void SignEncryptWizard::setSignersAndCandidates( const std::vector<Mailbox> & signers, const std::vector< std::vector<Key> > & keys ) {
d->signerResolvePage->setSignersAndCandidates( signers, keys );
}
void SignEncryptWizard::setTaskCollection( const shared_ptr<TaskCollection> & coll )
{
kleo_assert( coll );
d->resultPage->setTaskCollection( coll );
}
std::vector<Key> SignEncryptWizard::resolvedCertificates() const {
return d->recipientResolvePage->resolvedCertificates();
}
std::vector<Key> SignEncryptWizard::resolvedSigners() const {
return d->signerResolvePage->resolvedSigners();
}
bool SignEncryptWizard::isAsciiArmorEnabled() const
{
return d->signerResolvePage->isAsciiArmorEnabled();
}
void SignEncryptWizard::setAsciiArmorEnabled( bool enabled )
{
d->signerResolvePage->setAsciiArmorEnabled( enabled );
}
bool SignEncryptWizard::removeUnencryptedFile() const
{
return d->signerResolvePage->removeUnencryptedFile();
}
void SignEncryptWizard::setRemoveUnencryptedFile( bool remove )
{
d->signerResolvePage->setRemoveUnencryptedFile( remove );
}
bool SignEncryptWizard::recipientsUserMutable() const
{
return d->recipientResolvePage->recipientsUserMutable();
}
void SignEncryptWizard::setRecipientsUserMutable( bool isMutable )
{
d->recipientResolvePage->setRecipientsUserMutable( isMutable );
}
void SignEncryptWizard::setSignerResolvePageValidator( const boost::shared_ptr<SignerResolvePage::Validator>& validator )
{
d->signerResolvePage->setValidator( validator );
}
Gui::SignerResolvePage* SignEncryptWizard::signerResolvePage()
{
return d->signerResolvePage;
}
const Gui::SignerResolvePage* SignEncryptWizard::signerResolvePage() const
{
return d->signerResolvePage;
}
Gui::ResolveRecipientsPage* SignEncryptWizard::resolveRecipientsPage()
{
return d->recipientResolvePage;
}
Gui::ObjectsPage* SignEncryptWizard::objectsPage()
{
return d->objectsPage;
}
Gui::ResultPage* SignEncryptWizard::resultPage()
{
return d->resultPage;
}
bool SignEncryptWizard::keepResultPageOpenWhenDone() const
{
return d->resultPage->keepOpenWhenDone();
}
void SignEncryptWizard::setKeepResultPageOpenWhenDone( bool keep )
{
d->resultPage->setKeepOpenWhenDone( keep );
}
#include "moc_signencryptwizard.cpp"
diff --git a/crypto/gui/signerresolvepage.cpp b/crypto/gui/signerresolvepage.cpp
index d7e52ad2d..2b9868183 100644
--- a/crypto/gui/signerresolvepage.cpp
+++ b/crypto/gui/signerresolvepage.cpp
@@ -1,440 +1,659 @@
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/gui/signerresolvepage.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2007 Klarälvdalens Datakonsult AB
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 <config-kleopatra.h>
#include "signerresolvepage.h"
+#include "signerresolvepage_p.h"
#include "signingcertificateselectiondialog.h"
#include <crypto/certificateresolver.h>
#include <models/keycache.h>
#include <utils/formatting.h>
#include <utils/kleo_assert.h>
#include <kmime/kmime_header_parsing.h>
#include <gpgme++/key.h>
#include <KDialog>
#include <KLocale>
#include <QButtonGroup>
#include <QCheckBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include <QPointer>
#include <QPushButton>
#include <QRadioButton>
+#include <QStackedLayout>
#include <QVBoxLayout>
#include <cassert>
using namespace GpgME;
using namespace Kleo;
using namespace Kleo::Crypto;
using namespace Kleo::Crypto::Gui;
using namespace boost;
+namespace {
+ static SignerResolvePage::Operation operationFromFlags( bool sign, bool encrypt ) {
+ if ( !encrypt && sign )
+ return SignerResolvePage::SignOnly;
+ if ( !sign && encrypt )
+ return SignerResolvePage::EncryptOnly;
+ return SignerResolvePage::SignAndEncrypt;
+ }
+
+ static QString formatLabel( Protocol p, const Key & key ) {
+ return i18nc( "%1=protocol (S/Mime, OpenPGP), %2=certificate", "Sign using %1: %2", Formatting::displayName( p ),
+ !key.isNull() ? Formatting::formatForComboBox( key ) : i18n( "No certificate selected" ) );
+ }
+
+ static std::vector<Protocol> supportedProtocols() {
+ std::vector<Protocol> protocols;
+ protocols.push_back( OpenPGP );
+ protocols.push_back( CMS );
+ return protocols;
+ }
+}
+
+AbstractSigningProtocolSelectionWidget::AbstractSigningProtocolSelectionWidget( QWidget* p, Qt::WindowFlags f ) : QWidget( p, f ) {
+}
+
+ReadOnlyProtocolSelectionWidget::ReadOnlyProtocolSelectionWidget( QWidget* p, Qt::WindowFlags f ) : AbstractSigningProtocolSelectionWidget( p, f ) {
+ QVBoxLayout * const layout = new QVBoxLayout( this );
+ layout->setMargin( 0 );
+ Q_FOREACH ( const Protocol i, supportedProtocols() ) {
+ QLabel * const l = new QLabel;
+ l->setText( formatLabel( i, Key() ) );
+ layout->addWidget( l );
+ m_labels[i] = l;
+ }
+}
+
+void ReadOnlyProtocolSelectionWidget::setProtocolChecked( Protocol protocol, bool checked ) {
+ QLabel * const l = label( protocol );
+ assert( l );
+ l->setVisible( checked );
+}
+
+bool ReadOnlyProtocolSelectionWidget::isProtocolChecked( Protocol protocol ) const {
+ QLabel * const l = label( protocol );
+ assert( l );
+ return l->isVisible();
+}
+
+std::vector<Protocol> ReadOnlyProtocolSelectionWidget::checkedProtocols() const {
+ std::vector<Protocol> res;
+ Q_FOREACH( const Protocol i, supportedProtocols() )
+ if( isProtocolChecked( i ) )
+ res.push_back( i );
+ return res;
+
+}
+
+SigningProtocolSelectionWidget::SigningProtocolSelectionWidget( QWidget* parent, Qt::WindowFlags f )
+ : AbstractSigningProtocolSelectionWidget( parent, f ) {
+
+ m_buttonGroup = new QButtonGroup( this );
+ connect( m_buttonGroup, SIGNAL(buttonClicked(int)), this, SIGNAL(userSelectionChanged()) );
+
+ QVBoxLayout * const layout = new QVBoxLayout( this );
+ layout->setMargin( 0 );
+ Q_FOREACH ( const Protocol i, supportedProtocols() ) {
+ QCheckBox * const b = new QCheckBox;
+ b->setText( formatLabel( i, Key() ) );
+ m_buttons[i] = b;
+ layout->addWidget( b );
+ m_buttonGroup->addButton( b );
+ }
+ setExclusive( true );
+ }
+
+void SigningProtocolSelectionWidget::setProtocolChecked( Protocol p, bool checked ) {
+ assert( p != UnknownProtocol );
+ QCheckBox * const b = button( p );
+ assert( b );
+ b->setChecked( checked );
+}
+
+bool SigningProtocolSelectionWidget::isProtocolChecked( Protocol p ) const {
+ assert( p != UnknownProtocol );
+ const QAbstractButton * const b = button( p );
+ assert( b );
+ return b->isChecked();
+}
+
+std::vector<Protocol> SigningProtocolSelectionWidget::checkedProtocols() const {
+ std::vector<Protocol> res;
+ for ( std::map<Protocol,QCheckBox*>::const_iterator it = m_buttons.begin(), end = m_buttons.end();
+ it != end;
+ ++it )
+ if ( it->second->isChecked() )
+ res.push_back( it->first );
+ return res;
+}
+
+void SigningProtocolSelectionWidget::setExclusive( bool exclusive ) {
+ if ( exclusive == isExclusive() )
+ return;
+ m_buttonGroup->setExclusive( exclusive );
+ emit userSelectionChanged();
+}
+
+QCheckBox * SigningProtocolSelectionWidget::button( Protocol p ) const
+{
+ const std::map<Protocol,QCheckBox*>::const_iterator it = m_buttons.find( p );
+ return it == m_buttons.end() ? 0 : it->second;
+}
+
+QLabel * ReadOnlyProtocolSelectionWidget::label( Protocol p ) const
+{
+ const std::map<Protocol,QLabel*>::const_iterator it = m_labels.find( p );
+ return it == m_labels.end() ? 0 : it->second;
+}
+
+bool SigningProtocolSelectionWidget::isExclusive() const {
+ return m_buttonGroup->exclusive();
+}
+
+void SigningProtocolSelectionWidget::setCertificate( Protocol prot, const Key & key ) {
+ QAbstractButton * const b = button( prot );
+ assert( b );
+ b->setText( formatLabel( prot, key ) );
+}
+
+void ReadOnlyProtocolSelectionWidget::setCertificate( Protocol prot, const Key & key ) {
+ QLabel * const l = label( prot );
+ l->setText( formatLabel( prot, key ) );
+}
+
namespace {
class ValidatorImpl : public SignerResolvePage::Validator {
public:
QString explanation() const { return QString(); }
bool isComplete() const { return true; }
};
}
class SignerResolvePage::Private {
friend class ::Kleo::Crypto::Gui::SignerResolvePage;
SignerResolvePage * const q;
public:
explicit Private( SignerResolvePage * qq );
~Private();
- void setOperation( int operation );
+ void setOperation( Operation operation );
+ void operationButtonClicked( int operation );
void selectCertificates();
void setCertificates( const QMap<GpgME::Protocol, GpgME::Key>& certs );
void updateModeSelectionWidgets();
void updateUi();
+ bool protocolSelected( Protocol p ) const;
+ bool protocolSelectionActuallyUserMutable() const;
private:
QButtonGroup* signEncryptGroup;
QRadioButton* signAndEncryptRB;
QRadioButton* encryptOnlyRB;
QRadioButton* signOnlyRB;
- QGroupBox* signingBox;
+ QGroupBox* signingCertificateBox;
+ QLabel * signerLabelLabel;
QLabel * signerLabel;
- QLabel * pgpLabel;
- QLabel * cmsLabel;
QGroupBox * encryptBox;
QCheckBox * textArmorCO;
QCheckBox * removeUnencryptedCO;
QPushButton * selectCertificatesButton;
- GpgME::Protocol protocol;
+ SigningProtocolSelectionWidget* signingProtocolSelectionWidget;
+ ReadOnlyProtocolSelectionWidget* readOnlyProtocolSelectionWidget;
+ std::vector<Protocol> presetProtocols;
bool signingMutable;
bool encryptionMutable;
bool signingSelected;
bool encryptionSelected;
+ bool multipleProtocolsAllowed;
+ bool protocolSelectionUserMutable;
QMap<GpgME::Protocol,GpgME::Key> certificates;
shared_ptr<SignerResolvePage::Validator> validator;
shared_ptr<SigningPreferences> signingPreferences;
};
+bool SignerResolvePage::Private::protocolSelectionActuallyUserMutable() const {
+ return q->protocolSelectionUserMutable() && q->operation() != EncryptOnly;
+}
+
SignerResolvePage::Private::Private( SignerResolvePage * qq )
- : q( qq ), protocol( GpgME::UnknownProtocol ),
- signingMutable( true ), encryptionMutable( true ),
- signingSelected( false ), encryptionSelected( false ), validator( new ValidatorImpl )
+ : q( qq )
+ , presetProtocols()
+ , signingMutable( true )
+ , encryptionMutable( true )
+ , signingSelected( false )
+ , encryptionSelected( false )
+ , multipleProtocolsAllowed( false )
+ , protocolSelectionUserMutable( true )
+ , validator( new ValidatorImpl )
{
QVBoxLayout* layout = new QVBoxLayout( q );
layout->setSpacing( KDialog::spacingHint() );
signEncryptGroup = new QButtonGroup( q );
- q->connect( signEncryptGroup, SIGNAL( buttonClicked( int ) ), q, SLOT( setOperation( int ) ) );
+ q->connect( signEncryptGroup, SIGNAL( buttonClicked( int ) ), q, SLOT( operationButtonClicked( int ) ) );
signAndEncryptRB = new QRadioButton;
signAndEncryptRB->setText( i18n( "Sign and encrypt (OpenPGP only)" ) );
signAndEncryptRB->setChecked( true );
signEncryptGroup->addButton( signAndEncryptRB, SignAndEncrypt );
layout->addWidget( signAndEncryptRB );
encryptOnlyRB = new QRadioButton;
encryptOnlyRB->setText( i18n( "Encrypt only" ) );
signEncryptGroup->addButton( encryptOnlyRB, EncryptOnly );
layout->addWidget( encryptOnlyRB );
signOnlyRB = new QRadioButton;
signOnlyRB->setText( i18n( "Sign only" ) );
signEncryptGroup->addButton( signOnlyRB, SignOnly );
layout->addWidget( signOnlyRB );
encryptBox = new QGroupBox;
encryptBox->setTitle( i18n( "Encryption Options" ) );
QBoxLayout * const encryptLayout = new QVBoxLayout( encryptBox );
textArmorCO = new QCheckBox;
textArmorCO->setText( i18n( "Text output (ASCII armor)" ) );
encryptLayout->addWidget( textArmorCO );
removeUnencryptedCO = new QCheckBox;
removeUnencryptedCO->setText( i18n( "Remove unencrypted original file when done" ) );
removeUnencryptedCO->setChecked( false );
encryptLayout->addWidget( removeUnencryptedCO );
layout->addWidget( encryptBox );
- signingBox = new QGroupBox;
- signingBox->setTitle( i18n( "Signing Certificates" ) );
- QGridLayout* signerLayout = new QGridLayout( signingBox );
+ signingCertificateBox = new QGroupBox;
+ signingCertificateBox->setTitle( i18n( "Signing Options" ) );
+ QGridLayout* signerLayout = new QGridLayout( signingCertificateBox );
signerLayout->setColumnStretch( 1, 1 );
- QLabel* signerLabelLabel = new QLabel;
+ signerLabelLabel = new QLabel;
signerLabelLabel->setText( i18n( "Signer:" ) );
- signerLayout->addWidget( signerLabelLabel, 0, 0 );
+ signerLayout->addWidget( signerLabelLabel, 1, 0 );
signerLabel = new QLabel;
- signerLayout->addWidget( signerLabel, 0, 1 );
- QLabel* const pgpLabelLabel = new QLabel;
- pgpLabelLabel->setText( i18n( "OpenPGP:" ) );
- signerLayout->addWidget( pgpLabelLabel, 1, 0 );
- pgpLabel = new QLabel;
- signerLayout->addWidget( pgpLabel, 1, 1, 1, 1, Qt::AlignLeft );
- QLabel* const cmsLabelLabel = new QLabel;
- cmsLabelLabel->setText( i18n( "S/MIME:" ) );
- signerLayout->addWidget( cmsLabelLabel, 2, 0 );
- cmsLabel = new QLabel;
- signerLayout->addWidget( cmsLabel, 2, 1, 1, 1, Qt::AlignLeft );
+ signerLayout->addWidget( signerLabel, 1, 1 );
+ signerLabelLabel->setVisible( false );
+ signerLabel->setVisible( false );
+
+ signingProtocolSelectionWidget = new SigningProtocolSelectionWidget;
+ connect( signingProtocolSelectionWidget, SIGNAL(userSelectionChanged()), q, SLOT(updateUi()) );
+ signerLayout->addWidget( signingProtocolSelectionWidget, 2, 0, 1, -1 );
+
+ readOnlyProtocolSelectionWidget = new ReadOnlyProtocolSelectionWidget;
+ signerLayout->addWidget( readOnlyProtocolSelectionWidget, 3, 0, 1, -1 );
selectCertificatesButton = new QPushButton;
selectCertificatesButton->setText( i18n( "Change Signing Certificates..." ) );
selectCertificatesButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
- signerLayout->addWidget( selectCertificatesButton, 3, 0, 1, -1, Qt::AlignLeft );
+ signerLayout->addWidget( selectCertificatesButton, 4, 0, 1, -1, Qt::AlignLeft );
q->connect( selectCertificatesButton, SIGNAL( clicked() ),
q, SLOT( selectCertificates() ) );
- layout->addWidget( signingBox );
-
+ layout->addWidget( signingCertificateBox );
layout->addStretch();
-
- setCertificates( QMap<GpgME::Protocol, GpgME::Key>() );
- updateModeSelectionWidgets();
}
void SignerResolvePage::setValidator( const boost::shared_ptr<SignerResolvePage::Validator>& validator )
{
assert( validator );
d->validator = validator;
d->updateUi();
}
-boost::shared_ptr<SignerResolvePage::Validator> SignerResolvePage::validator() const
+shared_ptr<SignerResolvePage::Validator> SignerResolvePage::validator() const
{
return d->validator;
}
SignerResolvePage::Private::~Private() {}
+bool SignerResolvePage::Private::protocolSelected( Protocol p ) const {
+ assert( p != UnknownProtocol );
+ return signingProtocolSelectionWidget->isProtocolChecked( p );
+}
+
void SignerResolvePage::Private::setCertificates( const QMap<GpgME::Protocol, GpgME::Key>& certs )
{
certificates = certs;
- const GpgME::Key cmsKey = certs[GpgME::CMS];
- cmsLabel->setText( !cmsKey.isNull() ? Formatting::formatForComboBox( cmsKey ) : i18n( "No certificate selected" ) );
- const GpgME::Key pgpKey = certs[GpgME::OpenPGP];
- pgpLabel->setText( !pgpKey.isNull() ? Formatting::formatForComboBox( pgpKey ) : i18n( "No certificate selected" ) );
+ Q_FOREACH ( const Protocol i, certs.keys() ) {
+ const Key key = certs.value( i );
+ readOnlyProtocolSelectionWidget->setCertificate( i, key );
+ signingProtocolSelectionWidget->setCertificate( i, key );
+ }
updateUi();
}
-void SignerResolvePage::Private::updateUi()
-{
+void SignerResolvePage::Private::updateUi() {
+ const bool showReadOnly = !protocolSelectionActuallyUserMutable();
+ readOnlyProtocolSelectionWidget->setVisible( showReadOnly );
+ signingProtocolSelectionWidget->setVisible( !showReadOnly );
+
q->setExplanation( validator->explanation() );
emit q->completeChanged();
}
+
+void SignerResolvePage::setProtocolSelectionUserMutable( bool ismutable ) {
+ if ( d->protocolSelectionUserMutable == ismutable )
+ return;
+ d->protocolSelectionUserMutable = ismutable;
+ d->updateModeSelectionWidgets();
+}
+
+bool SignerResolvePage::protocolSelectionUserMutable() const {
+ return d->protocolSelectionUserMutable || d->presetProtocols.empty();
+}
+
+void SignerResolvePage::setMultipleProtocolsAllowed( bool allowed )
+{
+ if ( d->multipleProtocolsAllowed == allowed )
+ return;
+ d->multipleProtocolsAllowed = allowed;
+ d->updateModeSelectionWidgets();
+}
+
+bool SignerResolvePage::multipleProtocolsAllowed() const
+{
+ return d->multipleProtocolsAllowed;
+}
+
void SignerResolvePage::Private::updateModeSelectionWidgets()
{
const bool bothMutable = signingMutable && encryptionMutable;
- const bool noSigning = !signingSelected && !signingMutable;
- const bool noEncryption = !encryptionSelected && !encryptionMutable;
+ const bool noSigningPossible = !signingSelected && !signingMutable;
+ const bool noEncryptionPossible = !encryptionSelected && !encryptionMutable;
signAndEncryptRB->setChecked( signingSelected && encryptionSelected );
signOnlyRB->setChecked( signingSelected && !encryptionSelected );
encryptOnlyRB->setChecked( encryptionSelected && !signingSelected );
- const bool canSignAndEncrypt = bothMutable && protocol != GpgME::CMS;
+ const bool canSignAndEncrypt = !noSigningPossible && !noEncryptionPossible; bothMutable && presetProtocols != std::vector<Protocol>( 1, CMS );
const bool canSignOnly = !encryptionSelected || encryptionMutable;
const bool canEncryptOnly = !signingSelected || signingMutable;
+
signAndEncryptRB->setEnabled( canSignAndEncrypt );
signOnlyRB->setEnabled( canSignOnly );
encryptOnlyRB->setEnabled( canEncryptOnly );
const bool buttonsVisible = signingMutable || encryptionMutable;
signOnlyRB->setVisible( buttonsVisible );
encryptOnlyRB->setVisible( buttonsVisible );
signAndEncryptRB->setVisible( buttonsVisible );
- signingBox->setVisible( !noSigning );
- encryptBox->setVisible( !noEncryption );
+ signingProtocolSelectionWidget->setExclusive( !multipleProtocolsAllowed );
+ signingCertificateBox->setVisible( !noSigningPossible );
+ encryptBox->setVisible( !noEncryptionPossible );
updateUi();
}
void SignerResolvePage::Private::selectCertificates()
{
QPointer<SigningCertificateSelectionDialog> dlg = new SigningCertificateSelectionDialog( q );
if ( dlg->exec() == QDialog::Accepted && dlg )
{
const QMap<Protocol, Key> certs = dlg->selectedCertificates();
setCertificates( certs );
if ( signingPreferences && dlg->rememberAsDefault() ) {
signingPreferences->setPreferredCertificate( OpenPGP, certs.value( OpenPGP ) );
signingPreferences->setPreferredCertificate( CMS, certs.value( CMS ) );
}
}
delete dlg;
updateUi();
}
-void SignerResolvePage::Private::setOperation( int mode_ )
+void SignerResolvePage::Private::operationButtonClicked( int mode_ )
{
const Operation op = static_cast<SignerResolvePage::Operation>( mode_ );
- signingBox->setEnabled( op != EncryptOnly );
+ signingCertificateBox->setEnabled( op != EncryptOnly );
encryptBox->setEnabled( op != SignOnly );
+ if ( op == SignAndEncrypt ) {
+ signingProtocolSelectionWidget->setProtocolChecked( CMS, false );
+ readOnlyProtocolSelectionWidget->setProtocolChecked( CMS, false );
+ signingProtocolSelectionWidget->setProtocolChecked( OpenPGP, true );
+ readOnlyProtocolSelectionWidget->setProtocolChecked( OpenPGP, true );
+ }
updateUi();
}
+void SignerResolvePage::Private::setOperation( Operation op ) {
+ switch ( op ) {
+ case SignOnly:
+ signOnlyRB->click();
+ break;
+ case EncryptOnly:
+ encryptOnlyRB->click();
+ break;
+ case SignAndEncrypt:
+ signAndEncryptRB->click();
+ break;
+ }
+}
SignerResolvePage::Operation SignerResolvePage::operation() const
{
- const bool encrypt = encryptionSelected();
- const bool sign = signingSelected();
- assert( encrypt || sign );
- if ( !sign )
- return EncryptOnly;
- if ( !encrypt )
- return SignOnly;
- return SignAndEncrypt;
+ return operationFromFlags( encryptionSelected(), signingSelected() );
}
SignerResolvePage::SignerResolvePage( QWidget * parent, Qt::WFlags f )
: WizardPage( parent, f ), d( new Private( this ) )
{
setTitle( i18n( "<b>Choose Operation to be Performed</b>" ) );
- setSubTitle( i18n( "TODO" ) );
+// setSubTitle( i18n( "TODO" ) );
+ setPresetProtocol( UnknownProtocol );
+ d->setCertificates( QMap<GpgME::Protocol, GpgME::Key>() );
+ d->updateModeSelectionWidgets();
+ d->operationButtonClicked( EncryptOnly );
}
SignerResolvePage::~SignerResolvePage() {}
void SignerResolvePage::setSignersAndCandidates( const std::vector<KMime::Types::Mailbox> & signers,
const std::vector< std::vector<GpgME::Key> > & keys )
{
kleo_assert( signers.empty() || signers.size() == keys.size() );
switch ( signers.size() )
{
case 0:
- d->signerLabel->setText( QString() ); // TODO: use default identity?
+ d->signerLabelLabel->setVisible( false );
+ d->signerLabel->setVisible( false ); // TODO: use default identity?
break;
case 1:
+ d->signerLabelLabel->setVisible( true );
+ d->signerLabel->setVisible( true ); // TODO: use default identity?
d->signerLabel->setText( signers.front().prettyAddress() );
break;
default: // > 1
kleo_assert( !"Resolving multiple signers not implemented" );
}
d->updateUi();
}
-void SignerResolvePage::setProtocol( GpgME::Protocol protocol )
+void SignerResolvePage::setPresetProtocol( Protocol protocol )
{
- d->protocol = protocol;
- d->updateModeSelectionWidgets();
+ std::vector<Protocol> protocols;
+ if ( protocol != CMS )
+ protocols.push_back( OpenPGP );
+ if ( protocol != OpenPGP )
+ protocols.push_back( CMS );
+ setPresetProtocols( protocols );
+ d->updateUi();
}
-GpgME::Protocol SignerResolvePage::protocol() const
+
+void SignerResolvePage::setPresetProtocols( const std::vector<Protocol>& protocols )
{
- return d->protocol;
+ d->presetProtocols = protocols;
+ Q_FOREACH ( const Protocol i, supportedProtocols() ) {
+ const bool checked = std::find( protocols.begin(), protocols.end(), i ) != protocols.end();
+ d->signingProtocolSelectionWidget->setProtocolChecked( i, checked );
+ d->readOnlyProtocolSelectionWidget->setProtocolChecked( i, checked );
+ }
+ d->updateModeSelectionWidgets();
}
-std::vector<GpgME::Key> SignerResolvePage::signingCertificates( GpgME::Protocol protocol ) const
+std::vector<Protocol> SignerResolvePage::selectedProtocols() const {
+ return d->signingProtocolSelectionWidget->checkedProtocols();
+}
+
+std::vector<Key> SignerResolvePage::signingCertificates( Protocol protocol ) const
{
- std::vector<GpgME::Key> result;
- if ( protocol != GpgME::CMS && !d->certificates[GpgME::OpenPGP].isNull() )
- result.push_back( d->certificates[GpgME::OpenPGP] );
- if ( protocol != GpgME::OpenPGP && !d->certificates[GpgME::CMS].isNull() )
- result.push_back( d->certificates[GpgME::CMS] );
+ std::vector<Key> result;
+ if ( protocol != CMS && d->signingProtocolSelectionWidget->isProtocolChecked( OpenPGP ) && !d->certificates[OpenPGP].isNull() )
+ result.push_back( d->certificates[OpenPGP] );
+ if ( protocol != OpenPGP && d->signingProtocolSelectionWidget->isProtocolChecked( CMS ) && !d->certificates[CMS].isNull() )
+ result.push_back( d->certificates[CMS] );
return result;
}
-std::vector<GpgME::Key> SignerResolvePage::resolvedSigners() const
+std::vector<Key> SignerResolvePage::resolvedSigners() const
{
- std::vector<GpgME::Key> result;
- if ( d->protocol == GpgME::UnknownProtocol )
- {
- if ( !d->certificates[GpgME::OpenPGP].isNull() )
- result.push_back( d->certificates[GpgME::OpenPGP] );
- if ( !d->certificates[GpgME::CMS].isNull() )
- result.push_back( d->certificates[GpgME::CMS] );
- }
- else
- {
- result.push_back( d->certificates[d->protocol] );
- }
+ std::vector<Key> result = signingCertificates( CMS );
+ const std::vector<Key> pgp = signingCertificates( OpenPGP );
+ result.insert( result.end(), pgp.begin(), pgp.end() );
return result;
}
bool SignerResolvePage::isComplete() const
{
assert( d->validator );
return d->validator->isComplete();
}
bool SignerResolvePage::encryptionSelected() const
{
return !d->signOnlyRB->isChecked();
}
void SignerResolvePage::setEncryptionSelected( bool selected )
{
d->encryptionSelected = selected;
d->updateModeSelectionWidgets();
+ d->setOperation( operationFromFlags( d->signingSelected, d->encryptionSelected ) );
}
bool SignerResolvePage::signingSelected() const
{
return !d->encryptOnlyRB->isChecked();
}
void SignerResolvePage::setSigningSelected( bool selected )
{
d->signingSelected = selected;
d->updateModeSelectionWidgets();
+ d->setOperation( operationFromFlags( d->signingSelected, d->encryptionSelected ) );
}
bool SignerResolvePage::isEncryptionUserMutable() const
{
return d->encryptionMutable;
}
bool SignerResolvePage::isSigningUserMutable() const
{
return d->signingMutable;
}
void SignerResolvePage::setEncryptionUserMutable( bool ismutable )
{
d->encryptionMutable = ismutable;
d->updateModeSelectionWidgets();
}
void SignerResolvePage::setSigningUserMutable( bool ismutable )
{
d->signingMutable = ismutable;
d->updateModeSelectionWidgets();
}
+std::vector<Protocol> SignerResolvePage::selectedProtocolsWithoutSigningCertificate() const {
+ std::vector<Protocol> res;
+ Q_FOREACH ( const Protocol i, selectedProtocols() )
+ if ( signingCertificates( i ).empty() )
+ res.push_back( i );
+ return res;
+}
+
bool SignerResolvePage::isAsciiArmorEnabled() const
{
return d->textArmorCO->isChecked();
}
void SignerResolvePage::setAsciiArmorEnabled( bool enabled )
{
d->textArmorCO->setChecked( enabled );
}
bool SignerResolvePage::removeUnencryptedFile() const
{
return d->removeUnencryptedCO->isChecked();
}
void SignerResolvePage::setRemoveUnencryptedFile( bool remove )
{
d->removeUnencryptedCO->setChecked( remove );
}
void SignerResolvePage::setSigningPreferences( const boost::shared_ptr<SigningPreferences>& prefs )
{
d->signingPreferences = prefs;
QMap<Protocol,Key> map;
map[OpenPGP] = prefs ? prefs->preferredCertificate( OpenPGP ) : Key();
map[CMS] = prefs ? prefs->preferredCertificate( CMS ) : Key();
d->setCertificates( map );
}
shared_ptr<SigningPreferences> SignerResolvePage::signingPreferences() const
{
return d->signingPreferences;
}
void SignerResolvePage::onNext()
{
}
#include "moc_signerresolvepage.cpp"
+#include "moc_signerresolvepage_p.cpp"
diff --git a/crypto/gui/signerresolvepage.h b/crypto/gui/signerresolvepage.h
index 26c3a1646..68559bbc9 100644
--- a/crypto/gui/signerresolvepage.h
+++ b/crypto/gui/signerresolvepage.h
@@ -1,134 +1,141 @@
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/gui/signerresolvepage.h
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2007 Klarälvdalens Datakonsult AB
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 __KLEOPATRA_CRYPTO_GUI_SIGNERRESOLVEPAGE_H__
#define __KLEOPATRA_CRYPTO_GUI_SIGNERRESOLVEPAGE_H__
#include <crypto/gui/wizardpage.h>
#include <utils/pimpl_ptr.h>
#include <gpgme++/global.h>
#include <kmime/kmime_header_parsing.h>
#include <boost/shared_ptr.hpp>
#include <vector>
namespace GpgME {
class Key;
}
namespace Kleo {
namespace Crypto {
class SigningPreferences;
namespace Gui {
-
class SignerResolvePage : public WizardPage {
Q_OBJECT
public:
explicit SignerResolvePage( QWidget * parent=0, Qt::WFlags f=0 );
~SignerResolvePage();
- void setSignersAndCandidates( const std::vector<KMime::Types::Mailbox> & signers,
+ void setSignersAndCandidates( const std::vector<KMime::Types::Mailbox> & signers,
const std::vector< std::vector<GpgME::Key> > & keys );
std::vector<GpgME::Key> resolvedSigners() const;
-
std::vector<GpgME::Key> signingCertificates( GpgME::Protocol protocol = GpgME::UnknownProtocol ) const;
/*reimpl*/ bool isComplete() const;
bool encryptionSelected() const;
void setEncryptionSelected( bool selected );
bool signingSelected() const;
void setSigningSelected( bool selected );
bool isEncryptionUserMutable() const;
void setEncryptionUserMutable( bool ismutable );
bool isSigningUserMutable() const;
void setSigningUserMutable( bool ismutable );
bool isAsciiArmorEnabled() const;
void setAsciiArmorEnabled( bool enabled );
bool removeUnencryptedFile() const;
void setRemoveUnencryptedFile( bool remove );
- void setProtocol( GpgME::Protocol protocol );
- GpgME::Protocol protocol() const;
-
+ void setPresetProtocol( GpgME::Protocol protocol );
+ void setPresetProtocols( const std::vector<GpgME::Protocol>& protocols );
+
+ std::vector<GpgME::Protocol> selectedProtocols() const;
+
+ std::vector<GpgME::Protocol> selectedProtocolsWithoutSigningCertificate() const;
+
+ void setMultipleProtocolsAllowed( bool allowed );
+ bool multipleProtocolsAllowed() const;
+
+ void setProtocolSelectionUserMutable( bool ismutable );
+ bool protocolSelectionUserMutable() const;
+
enum Operation {
SignAndEncrypt=0,
SignOnly,
EncryptOnly
};
-
+
Operation operation() const;
class Validator
{
public:
virtual ~Validator() {}
virtual bool isComplete() const = 0;
virtual QString explanation() const = 0;
};
void setValidator( const boost::shared_ptr<Validator>& );
boost::shared_ptr<Validator> validator() const;
void setSigningPreferences( const boost::shared_ptr<SigningPreferences>& prefs );
boost::shared_ptr<SigningPreferences> signingPreferences() const;
-
+
private:
/*reimpl*/ void onNext();
-
+
private:
class Private;
kdtools::pimpl_ptr<Private> d;
- Q_PRIVATE_SLOT( d, void setOperation( int ) )
+ Q_PRIVATE_SLOT( d, void operationButtonClicked( int ) )
Q_PRIVATE_SLOT( d, void selectCertificates() )
Q_PRIVATE_SLOT( d, void updateUi() )
};
-
}
}
}
#endif // __KLEOPATRA_CRYPTO_GUI_SIGNERRESOLVEPAGE_H__
diff --git a/crypto/gui/signerresolvepage_p.h b/crypto/gui/signerresolvepage_p.h
new file mode 100644
index 000000000..599bc5734
--- /dev/null
+++ b/crypto/gui/signerresolvepage_p.h
@@ -0,0 +1,96 @@
+/* -*- mode: c++; c-basic-offset:4 -*-
+ crypto/gui/signerresolvepage_p.h
+
+ This file is part of Kleopatra, the KDE keymanager
+ Copyright (c) 2007 Klarälvdalens Datakonsult AB
+
+ 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 __KLEOPATRA_CRYPTO_GUI_SIGNERRESOLVEPAGE_P_H__
+#define __KLEOPATRA_CRYPTO_GUI_SIGNERRESOLVEPAGE_P_H__
+
+#include <gpgme++/global.h>
+
+class QButtonGroup;
+class QCheckBox;
+class QLabel;
+
+namespace Kleo {
+namespace Crypto {
+namespace Gui {
+
+
+ class AbstractSigningProtocolSelectionWidget : public QWidget {
+ Q_OBJECT
+ public:
+ explicit AbstractSigningProtocolSelectionWidget( QWidget* parent=0, Qt::WindowFlags flags=0 );
+ virtual void setProtocolChecked( GpgME::Protocol protocol, bool checked ) = 0;
+ virtual bool isProtocolChecked( GpgME::Protocol protocol ) const = 0;
+ virtual std::vector<GpgME::Protocol> checkedProtocols() const = 0;
+ virtual void setCertificate( GpgME::Protocol protocol, const GpgME::Key& key ) = 0;
+
+ Q_SIGNALS:
+ void userSelectionChanged();
+ };
+
+ class SigningProtocolSelectionWidget : public AbstractSigningProtocolSelectionWidget {
+ Q_OBJECT
+ public:
+ explicit SigningProtocolSelectionWidget( QWidget* parent=0, Qt::WindowFlags flags=0 );
+ void setProtocolChecked( GpgME::Protocol protocol, bool checked );
+ bool isProtocolChecked( GpgME::Protocol protocol ) const;
+ std::vector<GpgME::Protocol> checkedProtocols() const;
+ void setCertificate( GpgME::Protocol protocol, const GpgME::Key& key );
+
+ void setExclusive( bool exclusive );
+ bool isExclusive() const;
+
+ private:
+ QCheckBox * button( GpgME::Protocol p ) const;
+ std::map<GpgME::Protocol,QCheckBox*> m_buttons;
+ QButtonGroup* m_buttonGroup;
+ };
+
+ class ReadOnlyProtocolSelectionWidget : public AbstractSigningProtocolSelectionWidget {
+ Q_OBJECT
+ public:
+ explicit ReadOnlyProtocolSelectionWidget( QWidget* parent=0, Qt::WindowFlags flags=0 );
+ void setProtocolChecked( GpgME::Protocol protocol, bool checked );
+ bool isProtocolChecked( GpgME::Protocol protocol ) const;
+ std::vector<GpgME::Protocol> checkedProtocols() const;
+ void setCertificate( GpgME::Protocol protocol, const GpgME::Key& key );
+
+ private:
+ QLabel * label( GpgME::Protocol p ) const;
+ std::map<GpgME::Protocol,QLabel*> m_labels;
+ };
+
+}
+}
+}
+
+#endif // __KLEOPATRA_CRYPTO_GUI_SIGNERRESOLVEPAGE_P_H__

File Metadata

Mime Type
text/x-diff
Expires
Mon, Dec 8, 11:44 AM (1 d, 15 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
64/9e/1a42ae1f07f2ea983332e16ea378

Event Timeline