33 #include <config-kleopatra.h>
49 #include <kleo/stl_util.h>
50 #include <kleo/exception.h>
52 #include <gpgme++/error.h>
53 #include <gpgme++/key.h>
54 #include <gpgme++/verificationresult.h>
55 #include <gpgme++/decryptionresult.h>
57 #include <KLocalizedString>
61 #include <gpg-error.h>
66 using namespace Kleo::Crypto;
67 using namespace Kleo::Formatting;
68 using namespace GpgME;
69 using namespace boost;
71 class DecryptVerifyCommandFilesBase::Private :
public QObject {
73 friend class ::Kleo::DecryptVerifyCommandFilesBase;
86 void checkForErrors()
const;
90 void slotProgress(
const QString & what,
int current,
int total );
91 void verificationResult(
const GpgME::VerificationResult & );
92 void slotDone() {
q->done(); }
93 void slotError(
int err,
const QString & details ) {
q->done( err, details ); }
111 int DecryptVerifyCommandFilesBase::doStart() {
117 d->controller->setOperation( operation() );
118 d->controller->setFiles( fileNames() );
120 QObject::connect( d->controller.
get(), SIGNAL(done()),
121 d.
get(), SLOT(slotDone()), Qt::QueuedConnection );
122 QObject::connect( d->controller.
get(), SIGNAL(error(
int,QString)),
123 d.
get(), SLOT(slotError(
int,QString)), Qt::QueuedConnection );
124 QObject::connect( d->controller.
get(), SIGNAL(verificationResult(GpgME::VerificationResult)),
125 d.
get(), SLOT(verificationResult(GpgME::VerificationResult)), Qt::QueuedConnection );
127 d->controller->start();
134 struct is_file : std::unary_function<QString,bool> {
135 bool operator()(
const QString & file )
const {
136 return QFileInfo( file ).isFile();
142 void DecryptVerifyCommandFilesBase::Private::checkForErrors()
const
144 if ( !
q->senders().empty() )
145 throw Kleo::Exception(
q->makeError( GPG_ERR_CONFLICT ),
146 i18n(
"Cannot use SENDER") );
148 if ( !
q->recipients().empty() )
149 throw Kleo::Exception(
q->makeError( GPG_ERR_CONFLICT ),
150 i18n(
"Cannot use RECIPIENT") );
152 const unsigned int numInputs =
q->inputs().size();
153 const unsigned int numMessages =
q->messages().size();
154 const unsigned int numOutputs =
q->outputs().size();
157 throw Kleo::Exception(
q->makeError( GPG_ERR_CONFLICT ), i18n(
"INPUT present") );
159 throw Kleo::Exception(
q->makeError( GPG_ERR_CONFLICT ), i18n(
"MESSAGE present") );
161 throw Kleo::Exception(
q->makeError( GPG_ERR_CONFLICT ), i18n(
"OUTPUT present") );
162 const QStringList fileNames =
q->fileNames();
163 if ( fileNames.empty() )
164 throw Exception( makeError( GPG_ERR_ASS_NO_INPUT ),
165 i18n(
"At least one FILE must be present" ) );
166 if ( !kdtools::all( fileNames, is_file() ) )
167 throw Exception( makeError( GPG_ERR_INV_ARG ),
168 i18n(
"DECRYPT/VERIFY_FILES cannot use directories as input" ) );
172 void DecryptVerifyCommandFilesBase::doCanceled() {
174 d->controller->cancel();
178 void DecryptVerifyCommandFilesBase::Private::slotProgress(
const QString& what,
int current,
int total )
187 void DecryptVerifyCommandFilesBase::Private::verificationResult(
const VerificationResult & vResult )
190 const std::vector<Signature> sigs = vResult.signatures();
192 Q_FOREACH (
const Signature & sig, sigs ) {
193 const QString s =
signatureToString( sig, DecryptVerifyResult::keyForSignature( sig, signers ) );
195 q->sendStatusEncoded(
"SIGSTATUS",
196 color + (
' ' +
hexencode( s.toUtf8().constData() ) ) );
201 #include "decryptverifycommandfilesbase.moc"
std::string hexencode(const char *s)
DecryptVerifyCommandFilesBase()
static boost::shared_ptr< const KeyCache > instance()
~DecryptVerifyCommandFilesBase()