33 #include <config-kleopatra.h>
41 #include <kleo/exception.h>
49 using namespace Kleo::Crypto;
50 using namespace boost;
52 class PrepSignCommand::Private :
public QObject {
55 friend class ::Kleo::PrepSignCommand;
59 :
q( qq ), controller() {}
62 void checkForErrors()
const;
65 void slotSignersResolved();
66 void slotError(
int,
const QString & );
80 void PrepSignCommand::Private::checkForErrors()
const {
82 if ( !
q->inputs().empty() || !
q->outputs().empty() || !
q->messages().empty() )
83 throw Exception( makeError( GPG_ERR_CONFLICT ),
84 i18n(
"INPUT/OUTPUT/MESSAGE may only be given after PREP_SIGN" ) );
87 throw Exception( makeError( GPG_ERR_CONFLICT ),
88 i18n(
"PREP_SIGN is an email mode command, connection seems to be in filemanager mode" ) );
90 if (
q->senders().empty() )
91 throw Exception( makeError( GPG_ERR_CONFLICT ),
92 i18n(
"No SENDER given" ) );
96 if ( m && m->isSigning() ) {
98 if (
q->hasOption(
"protocol" ) )
99 if ( m->protocol() !=
q->checkProtocol( EMail ) )
100 throw Exception( makeError( GPG_ERR_CONFLICT ),
101 i18n(
"Protocol given conflicts with protocol determined by PREP_ENCRYPT in this session" ) );
112 QObject::connect( controller, SIGNAL(certificatesResolved()), d, SLOT(slotSignersResolved()) );
113 QObject::connect( controller, SIGNAL(error(
int,QString)), d, SLOT(slotError(
int,QString)) );
116 int PrepSignCommand::doStart() {
122 if ( seec && seec->isSigning() ) {
124 d->controller = seec;
126 seec->setExecutionContext( shared_from_this() );
127 if ( seec->areCertificatesResolved() )
128 QTimer::singleShot( 0, d.
get(), SLOT(slotSignersResolved()) );
135 const QString session = sessionTitle();
136 if ( !session.isEmpty() )
137 d->controller->setSubject( session );
139 if ( hasOption(
"protocol" ) )
141 d->controller->setProtocol( checkProtocol( EMail ) );
143 d->controller->setEncrypting(
false );
144 d->controller->setSigning(
true );
146 d->controller->startResolveCertificates( recipients(), senders() );
152 void PrepSignCommand::Private::slotSignersResolved() {
155 QPointer<Private> that(
this );
159 q->sendStatus(
"PROTOCOL", QLatin1String(controller->protocolAsString()) );
160 q->registerMemento( NewSignEncryptEMailController::mementoName(),
161 make_typed_memento( controller ) );
165 }
catch (
const Exception & e ) {
166 q->done( e.error(), e.message() );
167 }
catch (
const std::exception & e ) {
168 q->done( makeError( GPG_ERR_UNEXPECTED ),
169 i18n(
"Caught unexpected exception in PrepSignCommand::Private::slotRecipientsResolved: %1",
170 QString::fromLocal8Bit( e.what() ) ) );
172 q->done( makeError( GPG_ERR_UNEXPECTED ),
173 i18n(
"Caught unknown exception in PrepSignCommand::Private::slotRecipientsResolved") );
176 q->removeMemento( NewSignEncryptEMailController::mementoName() );
180 void PrepSignCommand::Private::slotError(
int err,
const QString & details ) {
181 q->done( err, details );
184 void PrepSignCommand::doCanceled() {
186 d->controller->cancel();
189 #include "prepsigncommand.moc"
static void connectController(const QObject *controller, const QObject *d)
#define kleo_assert(cond)
virtual ~PrepSignCommand()