33 #include <config-kleopatra.h>
39 #include <kleo/exception.h>
46 using namespace Kleo::Crypto;
47 using namespace boost;
49 class PrepEncryptCommand::Private :
public QObject {
52 friend class ::Kleo::PrepEncryptCommand;
56 :
q( qq ), controller() {}
59 void checkForErrors()
const;
62 void slotRecipientsResolved();
63 void slotError(
int,
const QString & );
77 void PrepEncryptCommand::Private::checkForErrors()
const {
79 if ( !
q->inputs().empty() || !
q->outputs().empty() || !
q->messages().empty() )
80 throw Exception( makeError( GPG_ERR_CONFLICT ),
81 i18n(
"INPUT/OUTPUT/MESSAGE may only be given after PREP_ENCRYPT" ) );
84 throw Exception( makeError( GPG_ERR_CONFLICT ),
85 i18n(
"PREP_ENCRYPT is an email mode command, connection seems to be in filemanager mode" ) );
87 if ( !
q->senders().empty() && !
q->informativeSenders() )
88 throw Exception( makeError( GPG_ERR_CONFLICT ),
89 i18n(
"SENDER may not be given prior to PREP_ENCRYPT, except with --info" ) );
91 if (
q->recipients().empty() ||
q->informativeRecipients() )
92 throw Exception( makeError( GPG_ERR_MISSING_VALUE ),
93 i18n(
"No recipients given, or only with --info" ) );
97 int PrepEncryptCommand::doStart() {
99 removeMemento( NewSignEncryptEMailController::mementoName() );
104 d->controller->setEncrypting(
true );
106 const QString session = sessionTitle();
107 if ( !session.isEmpty() )
108 d->controller->setSubject( session );
110 if ( hasOption(
"protocol" ) )
112 d->controller->setProtocol( checkProtocol( EMail ) );
114 d->controller->setSigning( hasOption(
"expect-sign" ) );
116 QObject::connect( d->controller.
get(), SIGNAL(certificatesResolved()), d.
get(), SLOT(slotRecipientsResolved()) );
117 QObject::connect( d->controller.
get(), SIGNAL(error(
int,QString)), d.
get(), SLOT(slotError(
int,QString)) );
119 d->controller->startResolveCertificates( recipients(), senders() );
124 void PrepEncryptCommand::Private::slotRecipientsResolved() {
127 QPointer<Private> that(
this );
131 q->sendStatus(
"PROTOCOL", QLatin1String(controller->protocolAsString()) );
132 q->registerMemento( NewSignEncryptEMailController::mementoName(),
133 make_typed_memento( controller ) );
137 }
catch (
const Exception & e ) {
138 q->done( e.error(), e.message() );
139 }
catch (
const std::exception & e ) {
140 q->done( makeError( GPG_ERR_UNEXPECTED ),
141 i18n(
"Caught unexpected exception in PrepEncryptCommand::Private::slotRecipientsResolved: %1",
142 QString::fromLocal8Bit( e.what() ) ) );
144 q->done( makeError( GPG_ERR_UNEXPECTED ),
145 i18n(
"Caught unknown exception in PrepEncryptCommand::Private::slotRecipientsResolved") );
148 q->removeMemento( NewSignEncryptEMailController::mementoName() );
152 void PrepEncryptCommand::Private::slotError(
int err,
const QString & details ) {
153 q->done( err, details );
156 void PrepEncryptCommand::doCanceled() {
158 d->controller->cancel();
161 #include "prepencryptcommand.moc"
virtual ~PrepEncryptCommand()