33 #include <config-kleopatra.h>
43 #include <kleo/exception.h>
50 using namespace Kleo::Crypto;
51 using namespace boost;
53 class EncryptCommand::Private :
public QObject {
56 friend class ::Kleo::EncryptCommand;
67 void checkForErrors()
const;
71 void slotError(
int,
const QString & );
72 void slotRecipientsResolved();
86 void EncryptCommand::Private::checkForErrors()
const {
89 throw Exception( makeError( GPG_ERR_CONFLICT ),
90 i18n(
"ENCRYPT is an email mode command, connection seems to be in filmanager mode" ) );
92 if ( !
q->senders().empty() && !
q->informativeSenders() )
93 throw Exception( makeError( GPG_ERR_CONFLICT ),
94 i18n(
"SENDER may not be given prior to ENCRYPT, except with --info" ) );
96 if (
q->inputs().empty() )
97 throw Exception( makeError( GPG_ERR_ASS_NO_INPUT ),
98 i18n(
"At least one INPUT must be present" ) );
100 if (
q->outputs().empty() )
101 throw Exception( makeError( GPG_ERR_ASS_NO_OUTPUT ),
102 i18n(
"At least one OUTPUT must be present" ) );
104 if (
q->outputs().size() !=
q->inputs().size() )
105 throw Exception( makeError( GPG_ERR_CONFLICT ),
106 i18n(
"INPUT/OUTPUT count mismatch" ) );
108 if ( !
q->messages().empty() )
109 throw Exception( makeError( GPG_ERR_INV_VALUE ),
110 i18n(
"MESSAGE command is not allowed before ENCRYPT" ) );
115 if ( m && m->isEncrypting() ) {
117 if ( m->protocol() !=
q->checkProtocol( EMail ) )
118 throw Exception( makeError( GPG_ERR_CONFLICT ),
119 i18n(
"Protocol given conflicts with protocol determined by PREP_ENCRYPT" ) );
121 if ( !
q->recipients().empty() )
122 throw Exception( makeError( GPG_ERR_CONFLICT ),
123 i18n(
"New recipients added after PREP_ENCRYPT command" ) );
124 if ( !
q->senders().empty() )
125 throw Exception( makeError( GPG_ERR_CONFLICT ),
126 i18n(
"New senders added after PREP_ENCRYPT command" ) );
130 if (
q->recipients().empty() ||
q->informativeRecipients() )
131 throw Exception( makeError( GPG_ERR_MISSING_VALUE ),
132 i18n(
"No recipients given, or only with --info" ) );
140 QObject::connect( controller, SIGNAL(certificatesResolved()), d, SLOT(slotRecipientsResolved()) );
141 QObject::connect( controller, SIGNAL(done()), d, SLOT(slotDone()) );
142 QObject::connect( controller, SIGNAL(error(
int,QString)), d, SLOT(slotError(
int,QString)) );
146 int EncryptCommand::doStart() {
152 if ( seec && seec->isEncrypting() ) {
154 d->controller = seec;
156 removeMemento( NewSignEncryptEMailController::mementoName() );
157 d->controller->setExecutionContext( shared_from_this() );
158 if ( seec->areCertificatesResolved() )
159 QTimer::singleShot( 0, d.
get(), SLOT(slotRecipientsResolved()) );
166 const QString session = sessionTitle();
167 if ( !session.isEmpty() )
168 d->controller->setSubject( session );
170 d->controller->setEncrypting(
true );
171 d->controller->setSigning(
false );
172 d->controller->setProtocol( checkProtocol( EMail ) );
174 d->controller->startResolveCertificates( recipients(), senders() );
181 void EncryptCommand::Private::slotRecipientsResolved() {
186 const QString sessionTitle =
q->sessionTitle();
187 if ( !sessionTitle.isEmpty() )
189 i->setLabel( sessionTitle );
191 cont->startEncryption(
q->inputs(),
q->outputs() );
195 }
catch (
const Exception & e ) {
196 q->done( e.error(), e.message() );
197 }
catch (
const std::exception & e ) {
198 q->done( makeError( GPG_ERR_UNEXPECTED ),
199 i18n(
"Caught unexpected exception in EncryptCommand::Private::slotRecipientsResolved: %1",
200 QString::fromLocal8Bit( e.what() ) ) );
202 q->done( makeError( GPG_ERR_UNEXPECTED ),
203 i18n(
"Caught unknown exception in EncryptCommand::Private::slotRecipientsResolved") );
208 void EncryptCommand::Private::slotDone() {
212 void EncryptCommand::Private::slotError(
int err,
const QString & details ) {
213 q->done( err, details );
216 void EncryptCommand::doCanceled() {
218 d->controller->cancel();
221 #include "encryptcommand.moc"
virtual ~EncryptCommand()
#define kleo_assert(cond)
static void connectController(const QObject *controller, const QObject *d)