39 #include <gpgme++/error.h>
44 #include <kmessagebox.h>
54 using namespace GpgME;
69 GpgME::Error Kleo::ChiasmusJob::setup() {
70 if ( !checkPreconditions() )
71 return mError = Error::fromCode( GPG_ERR_INV_VALUE );
73 const Kleo::CryptoConfigEntry * class_
75 const Kleo::CryptoConfigEntry * chiasmus
77 const Kleo::CryptoConfigEntry * timeoutEntry
79 if ( !class_ || !chiasmus || !timeoutEntry )
80 return mError = Error::fromCode( GPG_ERR_INTERNAL );
83 KShell::tildeExpand( chiasmus->urlValue().path() ),
89 mSymCryptRun->setObjectName( QLatin1String(
"symcryptrun") );
90 QTimer::singleShot( timeoutEntry->uintValue() * 1000,
this,
91 SLOT(slotTimeout()) );
92 return GpgME::Error();
98 LaterDeleter(
QObject * o ) : _this( o ) {}
99 ~LaterDeleter() {
if ( _this ) _this->deleteLater(); }
100 void disable() { _this = 0; }
106 LaterDeleter d(
this );
108 if (
const GpgME::Error err = setup() )
111 connect( mSymCryptRun, SIGNAL(finished(
int,QProcess::ExitStatus)),
112 this, SLOT(finished()) );
114 if ( !mSymCryptRun->launch( mInput ) )
115 return mError = Error::fromCode( GPG_ERR_ENOENT );
118 return mError = GpgME::Error();
121 GpgME::Error Kleo::ChiasmusJob::finished() {
123 mError = Error::fromCode( GPG_ERR_INTERNAL );
124 else if ( mCanceled )
125 mError = Error::fromCode( GPG_ERR_CANCELED );
127 mError = Error::fromCode( GPG_ERR_TIMEOUT );
128 else if ( mSymCryptRun->exitStatus() != QProcess::NormalExit )
129 mError = Error::fromCode( GPG_ERR_GENERAL );
131 switch ( mSymCryptRun->exitCode() ) {
133 mOutput = mSymCryptRun->output();
134 mError = GpgME::Error();
138 mStderr = mSymCryptRun->stdErr();
139 mError = Error::fromCode( GPG_ERR_GENERAL );
142 mError = Error::fromCode( GPG_ERR_INV_PASSPHRASE );
145 mError = Error::fromCode( GPG_ERR_CANCELED );
149 const Kleo::CryptoConfigEntry * showOutput
151 if ( showOutput && showOutput->boolValue() ) {
152 showChiasmusOutput();
160 void Kleo::ChiasmusJob::showChiasmusOutput() {
162 if ( mStderr.isEmpty() )
164 KMessageBox::information( 0 ,
166 i18n(
"Output from chiasmus" ) );
170 if (
const GpgME::Error err = setup() )
173 if ( !mSymCryptRun->launch( mInput,
true ) ) {
174 delete mSymCryptRun; mSymCryptRun = 0;
175 return mError = Error::fromCode( GPG_ERR_ENOENT );
178 const GpgME::Error err = finished();
179 delete mSymCryptRun; mSymCryptRun = 0;
183 bool Kleo::ChiasmusJob::checkPreconditions()
const {
184 return !mKey.isEmpty();
189 mSymCryptRun->kill();
193 void Kleo::ChiasmusJob::slotTimeout() {
196 mSymCryptRun->kill();
204 if ( mError.isCanceled() )
206 const QString reason = QString::fromLocal8Bit( mError.asString() );
207 const QString msg = ( mMode == Encrypt
208 ? i18n(
"Encryption failed: %1", reason )
209 : i18n(
"Decryption failed: %1", reason ) );
210 if ( !mStderr.isEmpty() ) {
211 const QString details = i18n(
"The following was received on stderr:\n%1", mStderr );
212 KMessageBox::detailedError( parent, msg, details, caption );
214 KMessageBox::error( parent, msg, caption );
218 #include "chiasmusjob.moc"
static const ChiasmusBackend * instance()
An abstract base class for protocol-specific jobs.
Kleo::CryptoConfig * config() const
void showErrorDialog(QWidget *, const QString &) const
void result(const GpgME::Error &result, const QVariant &data)