Page MenuHome GnuPG

No OneTemporary

diff --git a/crypto/gui/signencryptwizard.cpp b/crypto/gui/signencryptwizard.cpp
index 3c2d3e871..fedd8c652 100644
--- a/crypto/gui/signencryptwizard.cpp
+++ b/crypto/gui/signencryptwizard.cpp
@@ -1,287 +1,289 @@
/* -*- 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 "wizardresultpage.h"
#include "resultdisplaywidget.h"
#include <crypto/task.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
WizardResultPage * resultPage;
};
SignEncryptWizard::Private::Private( SignEncryptWizard * qq )
: q( qq ),
recipientResolvePage( new Gui::ResolveRecipientsPage ),
signerResolvePage( new SignerResolvePage ),
objectsPage( new Gui::ObjectsPage ),
resultPage( new WizardResultPage )
{
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
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->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->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;
}
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::connectTask( const shared_ptr<Task> & task, unsigned int idx ) {
kleo_assert( task );
ResultDisplayWidget* const item = new ResultDisplayWidget;
item->setLabel( task->label() );
connect( task.get(), SIGNAL( progress( QString, int, int ) ),
item, SLOT( setProgress( QString, int, int ) ) );
connect( task.get(), SIGNAL(result( boost::shared_ptr<const Kleo::Crypto::Task::Result> ) ),
item, SLOT( setResult( boost::shared_ptr<const Kleo::Crypto::Task::Result> ) ) );
d->resultPage->addResultItem( item );
}
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 );
}
SignerResolvePage* SignEncryptWizard::signerResolvePage()
{
return d->signerResolvePage;
}
+void SignEncryptWizard::setOperationCompleted()
+{
+ d->resultPage->setOperationCompleted();
+}
#include "moc_signencryptwizard.cpp"
diff --git a/crypto/gui/signencryptwizard.h b/crypto/gui/signencryptwizard.h
index 667f70c09..98917ab0e 100644
--- a/crypto/gui/signencryptwizard.h
+++ b/crypto/gui/signencryptwizard.h
@@ -1,149 +1,152 @@
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/gui/signencryptwizard.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_SIGNENCRYPTWIZARD_H__
#define __KLEOPATRA_CRYPTO_GUI_SIGNENCRYPTWIZARD_H__
#include <crypto/gui/wizard.h>
#include <crypto/gui/signerresolvepage.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;
}
class QFileInfo;
template <typename T> class QList;
typedef QList<QFileInfo> QFileInfoList;
namespace Kleo {
namespace Crypto {
class Task;
namespace Gui {
class SignEncryptWizard : public Wizard {
Q_OBJECT
public:
explicit SignEncryptWizard( QWidget * parent=0, Qt::WindowFlags f=0 );
virtual ~SignEncryptWizard();
enum Page {
ResolveSignerPage=0,
ObjectsPage,
ResolveRecipientsPage,
ResultPage
};
void setCommitPage( Page );
GpgME::Protocol presetProtocol() const;
void setPresetProtocol( GpgME::Protocol proto );
GpgME::Protocol selectedProtocol() const;
/// SignOrEncryptFiles mode subinterface
//@{
QFileInfoList resolvedFiles() const;
void setFiles( const QStringList & files );
bool signingSelected() const;
void setSigningSelected( bool selected );
bool encryptionSelected() const;
void setEncryptionSelected( bool selected );
bool isSigningUserMutable() const;
void setSigningUserMutable( bool isMutable );
bool isEncryptionUserMutable() const;
void setEncryptionUserMutable( bool isMutable );
bool isMultipleProtocolsAllowed() const;
void setMultipleProtocolsAllowed( bool allowed );
//@}
void setRecipients( const std::vector<KMime::Types::Mailbox> & recipients );
/** if true, the user is allowed to remove/add recipients via the UI.
* Defaults to @p false.
*/
bool recipientsUserMutable() const;
void setRecipientsUserMutable( bool isMutable );
void setSignersAndCandidates( const std::vector<KMime::Types::Mailbox> & signers, const std::vector< std::vector<GpgME::Key> > & keys );
void connectTask( const boost::shared_ptr<Task> & task, unsigned int idx );
std::vector<GpgME::Key> resolvedCertificates() const;
std::vector<GpgME::Key> resolvedSigners() const;
bool isAsciiArmorEnabled() const;
void setAsciiArmorEnabled( bool enabled );
bool removeUnencryptedFile() const;
void setRemoveUnencryptedFile( bool remove );
/*reimp*/ void onNext( int currentId );
+ public Q_SLOTS:
+ void setOperationCompleted();
+
Q_SIGNALS:
//void operationResolved();
void signersResolved();
void objectsResolved();
void recipientsResolved();
protected:
SignerResolvePage* signerResolvePage();
void setSignerResolvePageValidator( const boost::shared_ptr<SignerResolvePage::Validator>& validator );
private:
class Private;
kdtools::pimpl_ptr<Private> d;
};
}
}
}
#endif /* __KLEOPATRA_CRYPTO_GUI_SIGNENCRYPTWIZARD_H__ */
diff --git a/crypto/gui/wizardresultpage.cpp b/crypto/gui/wizardresultpage.cpp
index 6adbd8414..5600657e3 100644
--- a/crypto/gui/wizardresultpage.cpp
+++ b/crypto/gui/wizardresultpage.cpp
@@ -1,98 +1,107 @@
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/gui/wizardresultpage.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 "wizardresultpage.h"
#include "scrollarea.h"
#include <KLocale>
#include <QVBoxLayout>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Crypto::Gui;
class WizardResultPage::Private {
friend class ::Kleo::Crypto::Gui::WizardResultPage;
WizardResultPage * const q;
public:
explicit Private( WizardResultPage * qq );
~Private();
private:
ScrollArea* scrollArea;
+ bool operationCompleted;
};
WizardResultPage::Private::Private( WizardResultPage * qq )
- : q( qq )
+ : q( qq ), operationCompleted( false )
{
QVBoxLayout* layout = new QVBoxLayout( q );
scrollArea = new ScrollArea;
assert( qobject_cast<QBoxLayout*>( scrollArea->widget()->layout() ) );
static_cast<QBoxLayout*>( scrollArea->widget()->layout() )->addStretch( 1 );
layout->addWidget( scrollArea );
}
WizardResultPage::Private::~Private() {}
WizardResultPage::WizardResultPage( QWidget * parent )
: WizardPage( parent ), d( new Private( this ) )
{
setTitle( i18n( "<b>Results</b>" ) );
}
void WizardResultPage::addResultItem( QWidget* widget )
{
assert( d->scrollArea->widget() );
assert( qobject_cast<QBoxLayout*>( d->scrollArea->widget()->layout() ) );
QBoxLayout & blay = *static_cast<QBoxLayout*>( d->scrollArea->widget()->layout() );
blay.insertWidget( blay.count() - 1, widget );
}
WizardResultPage::~WizardResultPage() {}
+void WizardResultPage::setOperationCompleted()
+{
+ if ( d->operationCompleted )
+ return;
+ d->operationCompleted = true;
+ emit completeChanged();
+}
+
bool WizardResultPage::isComplete() const
{
- return true;
+ return d->operationCompleted;
}
diff --git a/crypto/gui/wizardresultpage.h b/crypto/gui/wizardresultpage.h
index d3aaef493..f61eb9366 100644
--- a/crypto/gui/wizardresultpage.h
+++ b/crypto/gui/wizardresultpage.h
@@ -1,64 +1,66 @@
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/gui/wizardresultpage.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_WIZARDRESULTPAGE_H__
#define __KLEOPATRA_CRYPTO_GUI_WIZARDRESULTPAGE_H__
#include <crypto/gui/wizardpage.h>
#include <utils/pimpl_ptr.h>
namespace Kleo {
namespace Crypto {
namespace Gui {
class WizardResultPage : public WizardPage {
Q_OBJECT
public:
explicit WizardResultPage( QWidget * parent=0 );
~WizardResultPage();
void addResultItem( QWidget* widget );
+ void setOperationCompleted();
+
/*reimpl*/ bool isComplete() const;
private:
class Private;
kdtools::pimpl_ptr<Private> d;
};
}
}
}
#endif // __KLEOPATRA_CRYPTO_GUI_WIZARDRESULTPAGE_H__
diff --git a/crypto/signencryptfilescontroller.cpp b/crypto/signencryptfilescontroller.cpp
index 28ce98014..c591ea732 100644
--- a/crypto/signencryptfilescontroller.cpp
+++ b/crypto/signencryptfilescontroller.cpp
@@ -1,437 +1,439 @@
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/signencryptfilescontroller.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 "signencryptfilescontroller.h"
#include "signencryptfilestask.h"
#include "certificateresolver.h"
#include <crypto/gui/signencryptfileswizard.h>
#include <utils/input.h>
#include <utils/output.h>
#include <utils/classify.h>
#include <utils/stl_util.h>
#include <utils/kleo_assert.h>
#include <utils/exception.h>
#include <kmime/kmime_header_parsing.h>
#include <KLocale>
#include <kdebug.h>
#include <QPointer>
#include <QTimer>
#include <QFileInfo>
#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 SignEncryptFilesController::Private {
friend class ::Kleo::Crypto::SignEncryptFilesController;
SignEncryptFilesController * const q;
public:
explicit Private( SignEncryptFilesController * qq );
~Private();
private:
void slotWizardOperationPrepared();
void slotWizardCanceled();
void slotTaskDone();
private:
void ensureWizardCreated();
void ensureWizardVisible();
void cancelAllTasks();
void reportError( int err, const QString & details ) {
errorDetected = true;
emit q->error( err, details );
}
void removeInputFiles();
void schedule();
shared_ptr<SignEncryptFilesTask> takeRunnable( GpgME::Protocol proto );
void connectTask( const shared_ptr<Task> & task, unsigned int idx );
static void assertValidOperation( unsigned int );
static QString titleForOperation( unsigned int op );
private:
std::vector< shared_ptr<SignEncryptFilesTask> > runnable, completed;
shared_ptr<SignEncryptFilesTask> cms, openpgp;
QPointer<SignEncryptFilesWizard> wizard;
unsigned int operation;
Protocol protocol;
bool errorDetected : 1;
};
SignEncryptFilesController::Private::Private( SignEncryptFilesController * qq )
: q( qq ),
runnable(),
cms(),
openpgp(),
wizard(),
operation( SignAllowed|EncryptAllowed ),
protocol( UnknownProtocol ),
errorDetected( false )
{
}
SignEncryptFilesController::Private::~Private() { kDebug(); }
QString SignEncryptFilesController::Private::titleForOperation( unsigned int op ) {
const bool signDisallowed = (op & SignMask) == SignDisallowed;
const bool encryptDisallowed = (op & EncryptMask) == EncryptDisallowed;
kleo_assert( !signDisallowed || !encryptDisallowed );
if ( !signDisallowed && encryptDisallowed )
return i18n( "Sign Files" );
if ( signDisallowed && !encryptDisallowed )
return i18n( "Encrypt Files" );
return i18n( "Sign/Encrypt Files" );
}
SignEncryptFilesController::SignEncryptFilesController( QObject * p )
: Controller( p ), d( new Private( this ) )
{
}
SignEncryptFilesController::SignEncryptFilesController( const shared_ptr<const ExecutionContext> & ctx, QObject * p )
: Controller( ctx, p ), d( new Private( this ) )
{
}
SignEncryptFilesController::~SignEncryptFilesController() {
kDebug();
if ( d->wizard && !d->wizard->isVisible() )
delete d->wizard;
//d->wizard->close(); ### ?
}
void SignEncryptFilesController::setProtocol( Protocol proto ) {
kleo_assert( d->protocol == UnknownProtocol ||
d->protocol == proto );
d->protocol = proto;
d->ensureWizardCreated();
d->wizard->setPresetProtocol( proto );
}
Protocol SignEncryptFilesController::protocol() const {
return d->protocol;
}
// static
void SignEncryptFilesController::Private::assertValidOperation( unsigned int op ) {
kleo_assert( ( op & SignMask ) == SignDisallowed ||
( op & SignMask ) == SignAllowed ||
( op & SignMask ) == SignForced );
kleo_assert( ( op & EncryptMask ) == EncryptDisallowed ||
( op & EncryptMask ) == EncryptAllowed ||
( op & EncryptMask ) == EncryptForced );
kleo_assert( ( op & ~(SignMask|EncryptMask) ) == 0 );
}
void SignEncryptFilesController::setOperationMode( unsigned int mode ) {
Private::assertValidOperation( mode );
d->operation = mode;
if ( d->wizard )
d->wizard->setWindowTitle( d->titleForOperation( d->operation ) );
}
void SignEncryptFilesController::setFiles( const QStringList & files ) {
kleo_assert( !files.empty() );
d->ensureWizardVisible();
d->wizard->setFiles( files );
}
void SignEncryptFilesController::Private::slotWizardCanceled() {
kDebug();
reportError( gpg_error( GPG_ERR_CANCELED ), i18n("User cancel") );
}
void SignEncryptFilesController::start() {
d->ensureWizardVisible();
}
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 ) {
const shared_ptr<SignEncryptFilesTask> task( new SignEncryptFilesTask );
task->setSign( sign );
task->setEncrypt( encrypt );
task->setAsciiArmor( ascii );
if ( sign )
task->setSigners( signers );
if ( encrypt )
task->setRecipients( recipients );
unsigned int cls = pgp ? Class::OpenPGP : Class::CMS ;
if ( encrypt )
cls |= Class::CipherText;
else if ( sign )
cls |= Class::DetachedSignature;
cls |= ascii ? Class::Ascii : Class::Binary ;
const QString input = fi.absoluteFilePath();
task->setInputFileName( input );
const char * ext = outputFileExtension( cls );
if ( !ext )
ext = "out"; // ### error out?
const QString output = input + '.' + ext;
task->setOutputFileName( output );
return task;
}
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 ) {
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 shallCmsSign = sign && !cmsSigners.empty();
const bool shallCmsEncrypt = encrypt && !cmsRecipients.empty();
const bool cms = shallCmsEncrypt && ( !sign || shallCmsSign ) || !encrypt && shallCmsSign;
result.reserve( pgp + cms );
if ( pgp )
result.push_back( createSignEncryptTaskForFileInfo( fi, true, sign, encrypt, ascii, pgpRecipients, pgpSigners ) );
if ( cms )
result.push_back( createSignEncryptTaskForFileInfo( fi, false, sign, encrypt, ascii, cmsRecipients, cmsSigners ) );
return result;
}
void SignEncryptFilesController::Private::slotWizardOperationPrepared() {
try {
kleo_assert( wizard );
const bool sign = wizard->signingSelected();
const bool encrypt = wizard->encryptionSelected();
const bool ascii = wizard->isAsciiArmorEnabled();
const QFileInfoList files = wizard->resolvedFiles();
std::vector<Key> pgpRecipients, cmsRecipients, pgpSigners, cmsSigners;
if ( encrypt ) {
const std::vector<Key> recipients = wizard->resolvedCertificates();
kdtools::copy_if( recipients.begin(), recipients.end(),
std::back_inserter( pgpRecipients ),
bind( &Key::protocol, _1 ) == GpgME::OpenPGP );
kdtools::copy_if( recipients.begin(), recipients.end(),
std::back_inserter( cmsRecipients ),
bind( &Key::protocol, _1 ) == GpgME::CMS );
kleo_assert( pgpRecipients.size() + cmsRecipients.size() == recipients.size() );
}
if ( sign ) {
const std::vector<Key> signers = wizard->resolvedSigners();
kdtools::copy_if( signers.begin(), signers.end(),
std::back_inserter( pgpSigners ),
bind( &Key::protocol, _1 ) == GpgME::OpenPGP );
kdtools::copy_if( signers.begin(), signers.end(),
std::back_inserter( cmsSigners ),
bind( &Key::protocol, _1 ) == GpgME::CMS );
kleo_assert( pgpSigners.size() + cmsSigners.size() == signers.size() );
}
kleo_assert( !files.empty() );
std::vector< shared_ptr<SignEncryptFilesTask> > tasks;
tasks.reserve( files.size() );
Q_FOREACH( const QFileInfo & fi, files ) {
const std::vector< shared_ptr<SignEncryptFilesTask> > created =
createSignEncryptTasksForFileInfo( fi, sign, encrypt, ascii, pgpRecipients, pgpSigners, cmsRecipients, cmsSigners );
tasks.insert( tasks.end(), created.begin(), created.end() );
}
kleo_assert( runnable.empty() );
runnable.swap( tasks );
int i = 0;
Q_FOREACH( const shared_ptr<Task> task, runnable )
connectTask( task, i++ );
schedule();
} catch ( const Kleo::Exception & e ) {
reportError( e.error().encodedError(), e.message() );
} catch ( const std::exception & e ) {
reportError( gpg_error( GPG_ERR_UNEXPECTED ),
i18n("Caught unexpected exception in SignEncryptFilesController::Private::slotWizardOperationPrepared: %1",
QString::fromLocal8Bit( e.what() ) ) );
} catch ( ... ) {
reportError( gpg_error( GPG_ERR_UNEXPECTED ),
i18n("Caught unknown exception in SignEncryptFilesController::Private::slotWizardOperationPrepared") );
}
}
void SignEncryptFilesController::Private::schedule() {
if ( !cms )
if ( const shared_ptr<SignEncryptFilesTask> t = takeRunnable( CMS ) ) {
t->start();
cms = t;
}
if ( !openpgp )
if ( const shared_ptr<SignEncryptFilesTask> t = takeRunnable( OpenPGP ) ) {
t->start();
openpgp = t;
}
if ( !cms && !openpgp ) {
kleo_assert( runnable.empty() );
if ( wizard->removeUnencryptedFile() && wizard->encryptionSelected() && !errorDetected )
removeInputFiles();
emit q->done();
}
}
shared_ptr<SignEncryptFilesTask> SignEncryptFilesController::Private::takeRunnable( GpgME::Protocol proto ) {
const std::vector< shared_ptr<SignEncryptFilesTask> >::iterator it
= std::find_if( runnable.begin(), runnable.end(),
bind( &Task::protocol, _1 ) == proto );
if ( it == runnable.end() )
return shared_ptr<SignEncryptFilesTask>();
const shared_ptr<SignEncryptFilesTask> result = *it;
runnable.erase( it );
return result;
}
void SignEncryptFilesController::Private::connectTask( const shared_ptr<Task> & t, unsigned int idx ) {
connect( t.get(), SIGNAL(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)),
q, SLOT(slotTaskDone()) );
ensureWizardCreated();
wizard->connectTask( t, idx );
}
void SignEncryptFilesController::Private::slotTaskDone() {
assert( q->sender() );
// We could just delete the tasks here, but we can't use
// Qt::QueuedConnection here (we need sender()) and other slots
// might not yet have executed. Therefore, we push completed tasks
// into a burial container
if ( q->sender() == cms.get() ) {
completed.push_back( cms );
cms.reset();
} else if ( q->sender() == openpgp.get() ) {
completed.push_back( openpgp );
openpgp.reset();
}
QTimer::singleShot( 0, q, SLOT(schedule()) );
}
void SignEncryptFilesController::cancel() {
kDebug();
try {
d->errorDetected = true;
if ( d->wizard )
d->wizard->close();
d->cancelAllTasks();
} catch ( const std::exception & e ) {
qDebug( "Caught exception: %s", e.what() );
}
}
void SignEncryptFilesController::Private::cancelAllTasks() {
// we just kill all runnable tasks - this will not result in
// signal emissions.
runnable.clear();
// a cancel() will result in a call to
if ( cms )
cms->cancel();
if ( openpgp )
openpgp->cancel();
}
void SignEncryptFilesController::Private::ensureWizardCreated() {
if ( wizard )
return;
std::auto_ptr<SignEncryptFilesWizard> w( new SignEncryptFilesWizard );
w->setWindowTitle( titleForOperation( operation ) );
w->setAttribute( Qt::WA_DeleteOnClose );
connect( w.get(), SIGNAL(operationPrepared()), q, SLOT(slotWizardOperationPrepared()), Qt::QueuedConnection );
connect( w.get(), SIGNAL(canceled()), q, SLOT(slotWizardCanceled()), Qt::QueuedConnection );
+ connect( q, SIGNAL( done() ), w.get(), SLOT( setOperationCompleted() ), Qt::QueuedConnection );
+ connect( q, SIGNAL( error( int, QString ) ), w.get(), SLOT( setOperationCompleted() ), Qt::QueuedConnection );
wizard = w.release();
}
void SignEncryptFilesController::Private::ensureWizardVisible() {
ensureWizardCreated();
q->bringToForeground( wizard );
}
void SignEncryptFilesController::Private::removeInputFiles() {
if ( !wizard ) {
qWarning( "SignEncryptFilesController::Private::removeInputFiles: no wizard!" );
return;
}
if ( errorDetected )
return;
const QFileInfoList files = wizard->resolvedFiles();
Q_FOREACH( const QFileInfo & fi, files )
QFile::remove( fi.absoluteFilePath() );
}
#include "moc_signencryptfilescontroller.cpp"
diff --git a/uiserver/encryptemailcontroller.cpp b/uiserver/encryptemailcontroller.cpp
index 0c4389657..1a4db7d63 100644
--- a/uiserver/encryptemailcontroller.cpp
+++ b/uiserver/encryptemailcontroller.cpp
@@ -1,306 +1,309 @@
/* -*- mode: c++; c-basic-offset:4 -*-
uiserver/encryptemailcontroller.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 "encryptemailcontroller.h"
#include "assuancommand.h"
#include <crypto/gui/signencryptwizard.h>
#include <crypto/encryptemailtask.h>
#include <utils/input.h>
#include <utils/output.h>
#include <utils/stl_util.h>
#include <utils/kleo_assert.h>
#include <utils/exception.h>
#include <gpgme++/key.h>
#include <KLocale>
#include <QPointer>
#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 EncryptEMailController::Private {
friend class ::Kleo::EncryptEMailController;
EncryptEMailController * const q;
public:
explicit Private( const shared_ptr<AssuanCommand> & cmd, EncryptEMailController * qq );
private:
void slotWizardRecipientsResolved();
void slotWizardCanceled();
void slotTaskDone();
private:
void ensureWizardCreated() const;
void ensureWizardVisible();
void cancelAllTasks();
void schedule();
shared_ptr<EncryptEMailTask> takeRunnable( GpgME::Protocol proto );
void connectTask( const shared_ptr<Task> & task, unsigned int idx );
private:
weak_ptr<AssuanCommand> command;
std::vector< shared_ptr<EncryptEMailTask> > runnable, completed;
shared_ptr<EncryptEMailTask> cms, openpgp;
mutable QPointer<SignEncryptWizard> wizard;
};
EncryptEMailController::Private::Private( const shared_ptr<AssuanCommand> & cmd, EncryptEMailController * qq )
: q( qq ),
command( cmd ),
runnable(),
cms(),
openpgp(),
wizard()
{
}
EncryptEMailController::EncryptEMailController( const shared_ptr<AssuanCommand> & cmd, QObject * p )
: Controller( cmd, p ), d( new Private( cmd, this ) )
{
}
EncryptEMailController::~EncryptEMailController() {
if ( d->wizard && !d->wizard->isVisible() )
delete d->wizard;
//d->wizard->close(); ### ?
}
void EncryptEMailController::setCommand( const shared_ptr<AssuanCommand> & cmd ) {
d->command = cmd;
setExecutionContext( cmd );
}
void EncryptEMailController::setProtocol( Protocol proto ) {
d->ensureWizardCreated();
const Protocol protocol = d->wizard->presetProtocol();
kleo_assert( protocol == UnknownProtocol ||
protocol == proto );
d->wizard->setPresetProtocol( proto );
}
Protocol EncryptEMailController::protocol() const {
d->ensureWizardCreated();
return d->wizard->selectedProtocol();
}
const char * EncryptEMailController::protocolAsString() const {
switch ( protocol() ) {
case OpenPGP: return "OpenPGP";
case CMS: return "CMS";
default:
throw Kleo::Exception( gpg_error( GPG_ERR_INTERNAL ),
i18n("Call to EncryptEMailController::protocolAsString() is ambiguous.") );
}
}
void EncryptEMailController::startResolveRecipients( const std::vector<Mailbox> & recipients ) {
d->ensureWizardCreated();
d->wizard->setRecipients( recipients );
d->ensureWizardVisible();
}
void EncryptEMailController::Private::slotWizardRecipientsResolved() {
emit q->recipientsResolved();
}
void EncryptEMailController::Private::slotWizardCanceled() {
emit q->error( gpg_error( GPG_ERR_CANCELED ), i18n("User cancel") );
}
void EncryptEMailController::importIO() {
const shared_ptr<AssuanCommand> cmd = d->command.lock();
kleo_assert( cmd );
const std::vector< shared_ptr<Input> > & inputs = cmd->inputs();
kleo_assert( !inputs.empty() );
const std::vector< shared_ptr<Output> > & outputs = cmd->outputs();
kleo_assert( outputs.size() == inputs.size() );
std::vector< shared_ptr<EncryptEMailTask> > tasks;
tasks.reserve( inputs.size() );
d->ensureWizardCreated();
const std::vector<Key> keys = d->wizard->resolvedCertificates();
kleo_assert( !keys.empty() );
for ( unsigned int i = 0, end = inputs.size() ; i < end ; ++i ) {
const shared_ptr<EncryptEMailTask> task( new EncryptEMailTask );
task->setInput( inputs[i] );
task->setOutput( outputs[i] );
task->setRecipients( keys );
tasks.push_back( task );
}
d->runnable.swap( tasks );
}
void EncryptEMailController::start() {
int i = 0;
Q_FOREACH( const shared_ptr<Task> task, d->runnable )
d->connectTask( task, i++ );
d->schedule();
}
void EncryptEMailController::Private::schedule() {
if ( !cms )
if ( const shared_ptr<EncryptEMailTask> t = takeRunnable( CMS ) ) {
t->start();
cms = t;
}
if ( !openpgp )
if ( const shared_ptr<EncryptEMailTask> t = takeRunnable( OpenPGP ) ) {
t->start();
openpgp = t;
}
if ( !cms && !openpgp ) {
kleo_assert( runnable.empty() );
emit q->done();
}
}
shared_ptr<EncryptEMailTask> EncryptEMailController::Private::takeRunnable( GpgME::Protocol proto ) {
const std::vector< shared_ptr<EncryptEMailTask> >::iterator it
= std::find_if( runnable.begin(), runnable.end(),
bind( &Task::protocol, _1 ) == proto );
if ( it == runnable.end() )
return shared_ptr<EncryptEMailTask>();
const shared_ptr<EncryptEMailTask> result = *it;
runnable.erase( it );
return result;
}
void EncryptEMailController::Private::connectTask( const shared_ptr<Task> & t, unsigned int idx ) {
connect( t.get(), SIGNAL(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)),
q, SLOT(slotTaskDone()) );
ensureWizardCreated();
wizard->connectTask( t, idx );
}
void EncryptEMailController::Private::slotTaskDone() {
assert( q->sender() );
// We could just delete the tasks here, but we can't use
// Qt::QueuedConnection here (we need sender()) and other slots
// might not yet have executed. Therefore, we push completed tasks
// into a burial container
if ( q->sender() == cms.get() ) {
completed.push_back( cms );
cms.reset();
} else if ( q->sender() == openpgp.get() ) {
completed.push_back( openpgp );
openpgp.reset();
}
QTimer::singleShot( 0, q, SLOT(schedule()) );
}
void EncryptEMailController::cancel() {
try {
if ( d->wizard )
d->wizard->close();
d->cancelAllTasks();
} catch ( const std::exception & e ) {
qDebug( "Caught exception: %s", e.what() );
}
}
void EncryptEMailController::Private::cancelAllTasks() {
// we just kill all runnable tasks - this will not result in
// signal emissions.
runnable.clear();
// a cancel() will result in a call to
if ( cms )
cms->cancel();
if ( openpgp )
openpgp->cancel();
}
void EncryptEMailController::Private::ensureWizardCreated() const {
if ( wizard )
return;
std::auto_ptr<SignEncryptWizard> w( new SignEncryptWizard );
w->setWindowTitle( i18n("Encrypt Mail Message") );
std::vector<int> pageOrder;
pageOrder.push_back( SignEncryptWizard::ResolveRecipientsPage );
pageOrder.push_back( SignEncryptWizard::ResultPage );
w->setPageOrder( pageOrder );
w->setCommitPage( SignEncryptWizard::ResolveRecipientsPage );
w->setAttribute( Qt::WA_DeleteOnClose );
connect( w.get(), SIGNAL(recipientsResolved()), q, SLOT(slotWizardRecipientsResolved()), Qt::QueuedConnection );
connect( w.get(), SIGNAL(canceled()), q, SLOT(slotWizardCanceled()), Qt::QueuedConnection );
+ connect( q, SIGNAL( done() ), w.get(), SLOT( setOperationCompleted() ), Qt::QueuedConnection );
+ connect( q, SIGNAL( error( int, QString ) ), w.get(), SLOT( setOperationCompleted() ), Qt::QueuedConnection );
+
wizard = w.release();
}
void EncryptEMailController::Private::ensureWizardVisible() {
ensureWizardCreated();
q->bringToForeground( wizard );
}
#include "moc_encryptemailcontroller.cpp"
diff --git a/uiserver/signemailcontroller.cpp b/uiserver/signemailcontroller.cpp
index d5b2177ca..2b197a6c5 100644
--- a/uiserver/signemailcontroller.cpp
+++ b/uiserver/signemailcontroller.cpp
@@ -1,324 +1,326 @@
/* -*- mode: c++; c-basic-offset:4 -*-
uiserver/signemailcontroller.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 "signemailcontroller.h"
#include "assuancommand.h"
#include <crypto/gui/signemailwizard.h>
#include <crypto/signemailtask.h>
#include <crypto/certificateresolver.h>
#include <utils/input.h>
#include <utils/output.h>
#include <utils/stl_util.h>
#include <utils/kleo_assert.h>
#include <kmime/kmime_header_parsing.h>
#include <KLocale>
#include <QPointer>
#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 SignEMailController::Private {
friend class ::Kleo::SignEMailController;
SignEMailController * const q;
public:
explicit Private( const shared_ptr<AssuanCommand> & cmd, SignEMailController * qq );
~Private();
private:
void slotWizardSignersResolved();
void slotWizardCanceled(); // ### extract to base
void slotTaskDone(); // ### extract to base
private:
void ensureWizardCreated(); // ### extract to base
void ensureWizardVisible(); // ### extract to base
void cancelAllJobs(); // ### extract to base
void schedule(); // ### extract to base
shared_ptr<SignEMailTask> takeRunnable( GpgME::Protocol proto ); // ### extract to base
void connectTask( const shared_ptr<Task> & task, unsigned int idx ); // ### extract to base
private:
weak_ptr<AssuanCommand> command;
std::vector< shared_ptr<SignEMailTask> > runnable, completed; // ### extract to base
shared_ptr<SignEMailTask> cms, openpgp; // ### extract to base
QPointer<SignEncryptWizard> wizard; // ### extract to base
Protocol protocol; // ### extract to base
bool detached : 1;
};
SignEMailController::Private::Private( const shared_ptr<AssuanCommand> & cmd, SignEMailController * qq )
: q( qq ),
command( cmd ),
runnable(),
cms(),
openpgp(),
wizard(),
protocol( UnknownProtocol ),
detached( false )
{
}
SignEMailController::Private::~Private() {}
SignEMailController::SignEMailController( const boost::shared_ptr<AssuanCommand> & cmd, QObject * p )
: Controller( cmd, p ), d( new Private( cmd, this ) )
{
}
SignEMailController::~SignEMailController() {
/// ### extract to base
if ( d->wizard && !d->wizard->isVisible() )
delete d->wizard;
//d->wizard->close(); ### ?
}
// ### extract to base
void SignEMailController::setProtocol( Protocol proto ) {
kleo_assert( d->protocol == UnknownProtocol ||
d->protocol == proto );
d->protocol = proto;
d->ensureWizardCreated();
d->wizard->setPresetProtocol( proto );
}
Protocol SignEMailController::protocol() const {
return d->protocol;
}
void SignEMailController::startResolveSigners( const std::vector<Mailbox> & signers ) {
const std::vector< std::vector<Key> > keys = CertificateResolver::resolveSigners( signers, d->protocol );
if ( !signers.empty() )
kleo_assert( keys.size() == static_cast<size_t>( signers.size() ) );
d->ensureWizardCreated();
d->wizard->setSignersAndCandidates( signers, keys );
d->ensureWizardVisible();
}
void SignEMailController::setDetachedSignature( bool detached ) {
kleo_assert( !d->openpgp );
kleo_assert( !d->cms );
kleo_assert( d->completed.empty() );
kleo_assert( d->runnable.empty() );
d->detached = detached;
}
void SignEMailController::Private::slotWizardSignersResolved() {
emit q->signersResolved();
}
// ### extract to base
void SignEMailController::Private::slotWizardCanceled() {
emit q->error( gpg_error( GPG_ERR_CANCELED ), i18n("User cancel") );
}
// ### extract to base
void SignEMailController::importIO() {
const shared_ptr<AssuanCommand> cmd = d->command.lock();
kleo_assert( cmd );
const std::vector< shared_ptr<Input> > & inputs = cmd->inputs();
kleo_assert( !inputs.empty() );
const std::vector< shared_ptr<Output> > & outputs = cmd->outputs();
kleo_assert( !outputs.empty() );
std::vector< shared_ptr<SignEMailTask> > tasks;
tasks.reserve( inputs.size() );
d->ensureWizardCreated();
const std::vector<Key> keys = d->wizard->resolvedSigners();
kleo_assert( !keys.empty() );
for ( unsigned int i = 0, end = inputs.size() ; i < end ; ++i ) {
const shared_ptr<SignEMailTask> task( new SignEMailTask );
task->setInput( inputs[i] );
task->setOutput( outputs[i] );
task->setSigners( keys );
task->setDetachedSignature( d->detached );
tasks.push_back( task );
}
d->runnable.swap( tasks );
}
// ### extract to base
void SignEMailController::start() {
int i = 0;
Q_FOREACH( const shared_ptr<Task> task, d->runnable )
d->connectTask( task, i++ );
d->schedule();
}
// ### extract to base
void SignEMailController::Private::schedule() {
if ( !cms )
if ( const shared_ptr<SignEMailTask> t = takeRunnable( CMS ) ) {
t->start();
cms = t;
}
if ( !openpgp )
if ( const shared_ptr<SignEMailTask> t = takeRunnable( OpenPGP ) ) {
t->start();
openpgp = t;
}
if ( !cms && !openpgp ) {
kleo_assert( runnable.empty() );
QPointer<QObject> Q = q;
Q_FOREACH( const shared_ptr<SignEMailTask> t, completed ) {
emit q->reportMicAlg( t->micAlg() );
if ( !Q )
return;
}
emit q->done();
}
}
// ### extract to base
shared_ptr<SignEMailTask> SignEMailController::Private::takeRunnable( GpgME::Protocol proto ) {
const std::vector< shared_ptr<SignEMailTask> >::iterator it
= std::find_if( runnable.begin(), runnable.end(),
bind( &Task::protocol, _1 ) == proto );
if ( it == runnable.end() )
return shared_ptr<SignEMailTask>();
const shared_ptr<SignEMailTask> result = *it;
runnable.erase( it );
return result;
}
// ### extract to base
void SignEMailController::Private::connectTask( const shared_ptr<Task> & t, unsigned int idx ) {
connect( t.get(), SIGNAL(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)),
q, SLOT(slotTaskDone()) );
ensureWizardCreated();
wizard->connectTask( t, idx );
}
// ### extract to base
void SignEMailController::Private::slotTaskDone() {
assert( q->sender() );
// We could just delete the tasks here, but we can't use
// Qt::QueuedConnection here (we need sender()) and other slots
// might not yet have executed. Therefore, we push completed tasks
// into a burial container
if ( q->sender() == cms.get() ) {
completed.push_back( cms );
cms.reset();
} else if ( q->sender() == openpgp.get() ) {
completed.push_back( openpgp );
openpgp.reset();
}
QTimer::singleShot( 0, q, SLOT(schedule()) );
}
// ### extract to base
void SignEMailController::cancel() {
try {
if ( d->wizard )
d->wizard->close();
d->cancelAllJobs();
} catch ( const std::exception & e ) {
qDebug( "Caught exception: %s", e.what() );
}
}
// ### extract to base
void SignEMailController::Private::cancelAllJobs() {
// we just kill all runnable tasks - this will not result in
// signal emissions.
runnable.clear();
// a cancel() will result in a call to
if ( cms )
cms->cancel();
if ( openpgp )
openpgp->cancel();
}
// ### extract to base
void SignEMailController::Private::ensureWizardCreated() {
if ( wizard )
return;
std::auto_ptr<SignEncryptWizard> w( new SignEMailWizard );
w->setAttribute( Qt::WA_DeleteOnClose );
connect( w.get(), SIGNAL(signersResolved()), q, SLOT(slotWizardSignersResolved()), Qt::QueuedConnection );
connect( w.get(), SIGNAL(canceled()), q, SLOT(slotWizardCanceled()), Qt::QueuedConnection );
+ connect( q, SIGNAL( done() ), w.get(), SLOT( setOperationCompleted() ), Qt::QueuedConnection );
+ connect( q, SIGNAL( error( int, QString ) ), w.get(), SLOT( setOperationCompleted() ), Qt::QueuedConnection );
w->setPresetProtocol( protocol );
wizard = w.release();
}
// ### extract to base
void SignEMailController::Private::ensureWizardVisible() {
ensureWizardCreated();
q->bringToForeground( wizard );
}
#include "moc_signemailcontroller.cpp"

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jul 8, 12:20 PM (8 h, 38 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
fe/fd/e4739f64b00d1e678da4268f2e48

Event Timeline