37 #include "chiasmusjob.h"
38 #include "chiasmusbackend.h"
39 #include "symcryptrunprocessbase.h"
41 #include "kleo/cryptoconfig.h"
42 #include "ui/passphrasedialog.h"
44 #include <gpg-error.h>
47 #include <tdelocale.h>
49 #include <tdemessagebox.h>
52 #include <tqfileinfo.h>
53 #include <tqvariant.h>
59 Kleo::ChiasmusJob::ChiasmusJob( Mode mode )
60 : Kleo::SpecialJob( 0, 0 ),
70 Kleo::ChiasmusJob::~ChiasmusJob() {}
72 GpgME::Error Kleo::ChiasmusJob::setup() {
73 if ( !checkPreconditions() )
74 return mError = gpg_error( GPG_ERR_INV_VALUE );
77 = ChiasmusBackend::instance()->config()->entry(
"Chiasmus",
"General",
"symcryptrun-class" );
79 = ChiasmusBackend::instance()->config()->entry(
"Chiasmus",
"General",
"path" );
81 = ChiasmusBackend::instance()->config()->entry(
"Chiasmus",
"General",
"timeout" );
82 if ( !class_ || !chiasmus || !timeoutEntry )
83 return mError = gpg_error( GPG_ERR_INTERNAL );
85 mSymCryptRun =
new SymCryptRunProcessBase( class_->
stringValue(),
86 KShell::tildeExpand( chiasmus->
urlValue().path() ),
89 ? SymCryptRunProcessBase::Encrypt
90 : SymCryptRunProcessBase::Decrypt,
91 this,
"symcryptrun" );
92 TQTimer::singleShot( timeoutEntry->
uintValue() * 1000,
this,
93 TQ_SLOT( slotTimeout() ) );
100 LaterDeleter( TQObject * o ) : _this( o ) {}
101 ~LaterDeleter() {
if ( _this ) _this->deleteLater(); }
102 void disable() { _this = 0; }
108 LaterDeleter d(
this );
110 if (
const GpgME::Error err = setup() )
113 connect( mSymCryptRun, TQ_SIGNAL(processExited(TDEProcess*)),
114 this, TQ_SLOT(slotProcessExited(TDEProcess*)) );
116 if ( !mSymCryptRun->launch( mInput ) )
117 return mError = gpg_error( GPG_ERR_ENOENT );
123 GpgME::Error Kleo::ChiasmusJob::slotProcessExited( TDEProcess * proc ) {
124 if ( proc != mSymCryptRun )
125 mError = gpg_error( GPG_ERR_INTERNAL );
126 else if ( mCanceled )
127 mError = gpg_error( GPG_ERR_CANCELED );
129 mError = gpg_error( GPG_ERR_TIMEOUT );
130 else if ( !proc->normalExit() )
131 mError = gpg_error( GPG_ERR_GENERAL );
133 switch ( proc->exitStatus() ) {
135 mOutput = mSymCryptRun->output();
140 mStderr = mSymCryptRun->stdErr();
141 mError = gpg_error( GPG_ERR_GENERAL );
144 mError = gpg_error( GPG_ERR_INV_PASSPHRASE );
147 mError = gpg_error( GPG_ERR_CANCELED );
152 = ChiasmusBackend::instance()->config()->entry(
"Chiasmus",
"General",
"show-output" );
153 if ( showOutput && showOutput->
boolValue() ) {
154 showChiasmusOutput();
158 emit SpecialJob::result( mError, TQVariant( mOutput ) );
162 void Kleo::ChiasmusJob::showChiasmusOutput() {
163 kdDebug() << k_funcinfo << endl;
164 if ( mStderr.isEmpty() )
166 KMessageBox::information( 0 ,
168 i18n(
"Output from chiasmus" ) );
172 if (
const GpgME::Error err = setup() )
175 if ( !mSymCryptRun->launch( mInput, TDEProcess::Block ) ) {
176 delete mSymCryptRun; mSymCryptRun = 0;
177 return mError = gpg_error( GPG_ERR_ENOENT );
180 const GpgME::Error err = slotProcessExited( mSymCryptRun );
181 delete mSymCryptRun; mSymCryptRun = 0;
185 bool Kleo::ChiasmusJob::checkPreconditions()
const {
186 return !mKey.isEmpty();
189 void Kleo::ChiasmusJob::slotCancel() {
191 mSymCryptRun->kill();
195 void Kleo::ChiasmusJob::slotTimeout() {
198 mSymCryptRun->kill();
206 if ( mError.isCanceled() )
208 const TQString msg = ( mMode == Encrypt
209 ? i18n(
"Encryption failed: %1" )
210 : i18n(
"Decryption failed: %1" ) )
211 .arg( TQString::fromLocal8Bit( mError.asString() ) );
212 if ( !mStderr.isEmpty() ) {
213 const TQString details = i18n(
"The following was received on stderr:\n%1" ).arg( mStderr );
214 KMessageBox::detailedError( parent, msg, details, caption );
216 KMessageBox::error( parent, msg, caption );
220 #include "chiasmusjob.moc"
void showErrorDialog(TQWidget *, const TQString &) const
Description of a single option.
virtual TQString stringValue() const =0
Return value as a string (available for all argtypes) The returned string can be empty (explicitely s...
virtual unsigned int uintValue() const =0
Return value as an unsigned int.
virtual bool boolValue() const =0
Return value as a bool (only allowed for ArgType_None)
virtual KURL urlValue() const =0
Return value as a URL (only meaningful for Path and URL argtypes)