Page MenuHome GnuPG

No OneTemporary

diff --git a/uiserver/assuancommand.h b/uiserver/assuancommand.h
index f65d56002..41fe611cc 100644
--- a/uiserver/assuancommand.h
+++ b/uiserver/assuancommand.h
@@ -1,340 +1,343 @@
/* -*- mode: c++; c-basic-offset:4 -*-
uiserver/assuancommand.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_UISERVER_ASSUANCOMMAND_H__
#define __KLEOPATRA_UISERVER_ASSUANCOMMAND_H__
+#include <uiserver/controller.h>
+
#include <utils/pimpl_ptr.h>
#include <gpgme++/global.h>
#include <gpgme++/error.h>
+
#include <kmime/kmime_header_parsing.h>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <string>
#include <map>
#include <vector>
class QVariant;
class QIODevice;
class QObject;
class QStringList;
class QDialog;
class QFile;
struct assuan_context_s;
namespace Kleo {
class Input;
class Output;
class AssuanCommandFactory;
/*!
\brief Base class for GnuPG UI Server commands
<h3>Implementing a new AssuanCommand</h3>
You do not directly inherit AssuanCommand, unless you want to
deal with implementing low-level, repetetive things like name()
in terms of staticName(). Assuming you don't, then you inherit
your command class from AssuanCommandMixin, passing your class
as the template argument to AssuanCommandMixin, like this:
\code
class MyFooCommand : public AssuanCommandMixin<MyFooCommand> {
\endcode
(http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern)
You then choose a command name, and return that from the static
method staticName(), which is by convention queried by both
AssuanCommandMixin<> and GenericAssuanCommandFactory<>:
\code
static const char * staticName() { return "MYFOO"; }
\endcode
The string should be all-uppercase by convention, but the
UiServer implementation doesn't enforce this.
The next step is to implement start(), the starting point of
command execution:
<h3>Executing the command</h3>
\code
int start( const std::string & line ) {
\endcode
This should set everything up and check the parameters in \a
line and any options this command understands. If there's an
error, choose one the the gpg-error codes and create a
gpg_error_t from it using the protected makeError() function:
\code
return makeError( GPG_ERR_NOT_IMPLEMENTED );
\endcode
But usually, you will want to create a dialog, or call some
GpgME function from here. In case of errors from GpgME, you
shouldn't pipe them through makeError(), but return them
as-is. This will preserve the error source. Error created using
makeError() will have Kleopatra as their error source, so watch
out what you're doing :)
In addition to options and the command line, your command might
require \em{bulk data} input or output. That's what the bulk
input and output channels are for. You can check whether the
client handed you an input channel by checking that
bulkInputDevice() isn't NULL, likewise for bulkOutputDevice().
If everything is ok, you return 0. This indicates to the client
that the command has been accepted and is now in progress.
In this mode (start() returned 0), there are a bunch of options
for your command to do. Some commands may require additional
information from the client. The options passed to start() are
designed to be persistent across commands, and rather limited in
length (there's a strict line length limit in the assuan
protocol with no line continuation mechanism). The same is true
for command line arguments, which, in addition, you have to
parse yourself. Those usually apply only to this command, and
not to following ones.
If you need data that might be larger than the line length
limit, you can either expect it on the bulkInputDevice(), or, if
you have the need for more than one such data channel, or the
data is optional or conditional on some condition that can only
be determined during command execution, you can \em inquire the
missing information from the client.
As an example, a VERIFY command would expect the signed data on
the bulkInputDevice(). But if the input stream doesn't contain
an embedded (opaque) signature, indicating a \em detached
signature, it would go and inquire that data from the
client. Here's how it works:
\code
const int err = inquire( "DETACHED_SIGNATURE",
this, SLOT(slotDetachedSignature(int,QByteArray,QByteArray)) );
if ( err )
done( err );
\endcode
This should be self-explanatory: You give a slot to call when
the data has arrived. The slot's first argument is an error
code. The second the data (if any), and the third is just
repeating what you gave as inquire()'s first argument. As usual,
you can leave argument off of the end, if you are not interested
in them.
You can do as many inquiries as you want, but only one at a
time.
You should peridocally send status updates to the client. You do
that by calling sendStatus().
Once your command has finished executing, call done(). If it's
with an error code, call done(err) like above. \bold{Do not
forget to call done() when done!}. It will close
bulkInputDevice(), bulkOutputDevice(), and send an OK or ERR
message back to the client.
At that point, your command has finished executing, and a new
one can be accepted, or the connection closed.
Apropos connection closed. The only way for the client to cancel
an operation is to shut down the connection. In this case, the
canceled() function will be called. At that point, the
connection to the client will have been broken already, and all
you can do is pack your things and go down gracefully.
If _you_ detect that the user has canceled (your dialog contains
a cancel button, doesn't it?), then you should instead call
done( GPG_ERR_CANCELED ), like for normal operation.
<h3>Registering the command with UiServer</h3>
To register a command, you implement a AssuanCommandFactory for
your AssuanCommand subclass, and register it with the
UiServer. This can be made considerably easier using
GenericAssuanCommandFactory:
\code
UiServer server;
server.registerCommandFactory( shared_ptr<AssuanCommandFactory>( new GenericAssuanCommandFactory<MyFooCommand> ) );
// more registerCommandFactory calls...
server.start();
\endcode
*/
- class AssuanCommand : public boost::enable_shared_from_this<AssuanCommand> {
+ class AssuanCommand : public ExecutionContext, public boost::enable_shared_from_this<AssuanCommand> {
// defined in assuanserverconnection.cpp!
public:
AssuanCommand();
virtual ~AssuanCommand();
int start();
void canceled();
virtual const char * name() const = 0;
class Memento {
public:
virtual ~Memento() {}
};
template <typename T>
class TypedMemento : public Memento {
T m_t;
public:
explicit TypedMemento( const T & t ) : m_t( t ) {}
const T & get() const { return m_t; }
T & get() { return m_t; }
};
template <typename T>
static boost::shared_ptr< TypedMemento<T> > make_typed_memento( const T & t ) {
return boost::shared_ptr< TypedMemento<T> >( new TypedMemento<T>( t ) );
}
static int makeError( int code );
// convenience methods:
enum Mode { NoMode, EMail, FileManager };
Mode checkMode() const;
GpgME::Protocol checkProtocol( Mode mode ) const;
- void applyWindowID( QDialog* w ) const {
+ /* reimp */ void applyWindowID( QDialog* w ) const {
doApplyWindowID( w );
}
QString heuristicBaseDirectory() const;
bool isNohup() const;
const std::vector<KMime::Types::Mailbox> & recipients() const;
const std::vector<KMime::Types::Mailbox> & senders() const;
bool hasMemento( const QByteArray & tag ) const;
boost::shared_ptr<Memento> memento( const QByteArray & tag ) const;
template <typename T>
boost::shared_ptr<T> mementoAs( const QByteArray & tag ) const {
return boost::dynamic_pointer_cast<T>( this->memento( tag ) );
}
const std::map< QByteArray, boost::shared_ptr<Memento> > & mementos() const;
QByteArray registerMemento( const boost::shared_ptr<Memento> & mem );
QByteArray registerMemento( const QByteArray & tag, const boost::shared_ptr<Memento> & mem );
void removeMemento( const QByteArray & tag );
template <typename T>
T mementoContent( const QByteArray & tag ) const {
if ( boost::shared_ptr< TypedMemento<T> > m = mementoAs< TypedMemento<T> >( tag ) )
return m->get();
else
return T();
}
bool hasOption( const char * opt ) const;
QVariant option( const char * opt ) const;
const std::map<std::string,QVariant> & options() const;
const std::vector< boost::shared_ptr<Input> > & inputs() const;
const std::vector< boost::shared_ptr<Input> > & messages() const;
const std::vector< boost::shared_ptr<Output> > & outputs() const;
QStringList fileNames() const;
std::vector< boost::shared_ptr<QFile> > files() const;
unsigned int numFiles() const;
void sendStatus( const char * keyword, const QString & text );
void sendStatusEncoded( const char * keyword, const std::string & text );
void sendData( const QByteArray & data, bool moreToCome=false );
int inquire( const char * keyword, QObject * receiver, const char * slot, unsigned int maxSize=0 );
void done( const GpgME::Error& err = GpgME::Error() );
void done( const GpgME::Error& err, const QString & details );
void done( int err ) { done( GpgME::Error(err) ); }
void done( int err, const QString & details ) { done( GpgME::Error(err), details ); }
private:
virtual void doCanceled() = 0;
virtual int doStart() = 0;
private:
void doApplyWindowID( QDialog * w ) const;
private:
friend class ::Kleo::AssuanCommandFactory;
class Private;
kdtools::pimpl_ptr<Private> d;
};
class AssuanCommandFactory {
public:
virtual ~AssuanCommandFactory() {}
virtual boost::shared_ptr<AssuanCommand> create() const = 0;
virtual const char * name() const = 0;
typedef int(*_Handler)( assuan_context_s*, char *);
virtual _Handler _handler() const = 0;
protected:
static int _handle( assuan_context_s*, char *, const char * );
};
template <typename Command>
class GenericAssuanCommandFactory : public AssuanCommandFactory {
/* reimp */ AssuanCommandFactory::_Handler _handler() const { return &GenericAssuanCommandFactory::_handle; }
static int _handle( assuan_context_s* _ctx, char * _line ) {
return AssuanCommandFactory::_handle( _ctx, _line, Command::staticName() );
}
/* reimp */ boost::shared_ptr<AssuanCommand> create() const { return make(); }
/* reimp */ const char * name() const { return Command::staticName(); }
public:
static boost::shared_ptr<Command> make() { return boost::shared_ptr<Command>( new Command ); }
};
template <typename Derived, typename Base=AssuanCommand>
class AssuanCommandMixin : public Base {
protected:
/* reimp */ const char * name() const { return Derived::staticName(); }
};
}
#endif /* __KLEOPATRA_UISERVER_ASSUANCOMMAND_H__ */
diff --git a/uiserver/controller.cpp b/uiserver/controller.cpp
index 9b743e2cd..4c5c5953f 100644
--- a/uiserver/controller.cpp
+++ b/uiserver/controller.cpp
@@ -1,110 +1,108 @@
/* -*- mode: c++; c-basic-offset:4 -*-
uiserver/controller.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 "controller.h"
-#include "assuancommand.h"
+#include <KWindowSystem>
#include <QDialog>
#include <QVector>
-#include <KWindowSystem>
+#include <boost/weak_ptr.hpp>
using namespace boost;
using namespace Kleo;
class Controller::Private {
friend class ::Kleo::Controller;
Controller * const q;
public:
- explicit Private( const shared_ptr<AssuanCommand> & cmd, Controller * qq );
+ explicit Private( const shared_ptr<const ExecutionContext> & ctx, Controller * qq );
void applyWindowID( QDialog* dlg );
private:
- weak_ptr<AssuanCommand> command;
+ weak_ptr<const ExecutionContext> executionContext;
QVector<QDialog*> idApplied;
-
};
-Controller::Private::Private( const shared_ptr<AssuanCommand> & cmd, Controller * qq )
- : q( qq ), command( cmd )
+Controller::Private::Private( const shared_ptr<const ExecutionContext> & ctx, Controller * qq )
+ : q( qq ), executionContext( ctx )
{
}
void Controller::Private::applyWindowID( QDialog* dlg )
{
if ( idApplied.contains( dlg ) )
return;
- const shared_ptr<AssuanCommand> cmd = command.lock();
- if ( cmd ) {
- cmd->applyWindowID( dlg );
+ if ( const shared_ptr<const ExecutionContext> ctx = executionContext.lock() ) {
+ ctx->applyWindowID( dlg );
idApplied.append( dlg );
}
}
-Controller::Controller( const shared_ptr<AssuanCommand> & cmd, QObject* parent )
- : QObject( parent ), d( new Private( cmd, this ) )
+Controller::Controller( const shared_ptr<const ExecutionContext> & ctx, QObject* parent )
+ : QObject( parent ), d( new Private( ctx, this ) )
{
}
Controller::~Controller()
{
}
-void Controller::setCommand( const shared_ptr<AssuanCommand> & cmd )
+void Controller::setExecutionContext( const shared_ptr<const ExecutionContext> & ctx )
{
- d->command = cmd;
+ d->executionContext = ctx;
d->idApplied.clear();
}
-weak_ptr<AssuanCommand> Controller::command() const
+shared_ptr<const ExecutionContext> Controller::executionContext() const
{
- return d->command;
+ return d->executionContext.lock();
}
void Controller::bringToForeground( QDialog* dlg )
{
d->applyWindowID( dlg );
if ( dlg->isVisible() )
dlg->raise();
else
dlg->show();
#ifdef Q_WS_WIN
KWindowSystem::forceActiveWindow( dlg->winId() );
#endif
}
#include "controller.moc"
diff --git a/uiserver/controller.h b/uiserver/controller.h
index 2b5e76841..2f3811f40 100644
--- a/uiserver/controller.h
+++ b/uiserver/controller.h
@@ -1,68 +1,71 @@
/* -*- mode: c++; c-basic-offset:4 -*-
uiserver/controller.h
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.
*/
#ifndef __KLEOPATRA__UISERVER_CONTROLLER_H__
#define __KLEOPATRA__UISERVER_CONTROLLER_H__
#include <QObject>
#include <utils/pimpl_ptr.h>
#include <boost/shared_ptr.hpp>
-#include <boost/weak_ptr.hpp>
class QDialog;
namespace Kleo {
- class AssuanCommand;
+ class ExecutionContext {
+ public:
+ virtual ~ExecutionContext() {}
+ virtual void applyWindowID( QDialog * dialog ) const = 0;
+ };
class Controller : public QObject {
Q_OBJECT
public:
- explicit Controller( const boost::shared_ptr<AssuanCommand> & cmd, QObject * parent=0 );
+ explicit Controller( const boost::shared_ptr<const ExecutionContext> & cmd, QObject * parent=0 );
~Controller();
- void setCommand( const boost::shared_ptr<AssuanCommand> & cmd );
+ void setExecutionContext( const boost::shared_ptr<const ExecutionContext> & cmd );
protected:
- boost::weak_ptr<AssuanCommand> command() const;
+ boost::shared_ptr<const ExecutionContext> executionContext() const;
void bringToForeground( QDialog* dlg );
private:
class Private;
kdtools::pimpl_ptr<Private> d;
};
}
#endif /* __KLEOPATRA__UISERVER_CONTROLLER_H__ */
diff --git a/uiserver/encryptemailcontroller.cpp b/uiserver/encryptemailcontroller.cpp
index bf45b1868..cd9120fed 100644
--- a/uiserver/encryptemailcontroller.cpp
+++ b/uiserver/encryptemailcontroller.cpp
@@ -1,297 +1,304 @@
/* -*- 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 "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( EncryptEMailController * qq );
+ 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( EncryptEMailController * qq )
+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( this ) )
+ : 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 = command().lock();
+ 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 );
wizard = w.release();
}
void EncryptEMailController::Private::ensureWizardVisible() {
ensureWizardCreated();
q->bringToForeground( wizard );
}
#include "moc_encryptemailcontroller.cpp"
diff --git a/uiserver/encryptemailcontroller.h b/uiserver/encryptemailcontroller.h
index c5b032af8..71648bdf5 100644
--- a/uiserver/encryptemailcontroller.h
+++ b/uiserver/encryptemailcontroller.h
@@ -1,89 +1,91 @@
/* -*- mode: c++; c-basic-offset:4 -*-
uiserver/encryptemailcontroller.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_UISERVER_ENCRYPTEMAILCONTROLLER_H__
#define __KLEOPATRA_UISERVER_ENCRYPTEMAILCONTROLLER_H__
#include "controller.h"
#include <utils/pimpl_ptr.h>
#include <gpgme++/global.h>
#include <kmime/kmime_header_parsing.h>
#include <boost/shared_ptr.hpp>
#include <vector>
namespace Kleo {
class AssuanCommand;
class EncryptEMailController : public Controller {
Q_OBJECT
public:
explicit EncryptEMailController( const boost::shared_ptr<AssuanCommand> & cmd, QObject * parent=0 );
~EncryptEMailController();
static const char * mementoName() { return "EncryptEMailController"; }
+
+ void setCommand( const boost::shared_ptr<AssuanCommand> & cmd );
void setProtocol( GpgME::Protocol proto );
const char * protocolAsString() const;
GpgME::Protocol protocol() const;
void startResolveRecipients( const std::vector<KMime::Types::Mailbox> & recipients );
void importIO();
void start();
public Q_SLOTS:
void cancel();
Q_SIGNALS:
void recipientsResolved();
void error( int err, const QString & details );
void done();
private:
class Private;
kdtools::pimpl_ptr<Private> d;
Q_PRIVATE_SLOT( d, void slotWizardRecipientsResolved() )
Q_PRIVATE_SLOT( d, void slotWizardCanceled() )
Q_PRIVATE_SLOT( d, void slotTaskDone() )
Q_PRIVATE_SLOT( d, void schedule() )
};
}
#endif /* __KLEOPATRA_UISERVER_ENCRYPTEMAILCONTROLLER_H__ */
diff --git a/uiserver/signemailcontroller.cpp b/uiserver/signemailcontroller.cpp
index 69aac1556..bf9c37fb1 100644
--- a/uiserver/signemailcontroller.cpp
+++ b/uiserver/signemailcontroller.cpp
@@ -1,317 +1,322 @@
/* -*- 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 "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( SignEMailController * qq );
+ 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( SignEMailController * qq )
+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( this ) )
+ : 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 = command().lock();
+ 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 );
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
Fri, Dec 12, 11:56 AM (1 d, 22 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e4/61/c1510c2aee36174e70c60283e43c

Event Timeline