diff options
Diffstat (limited to 'kmail/objecttreeparser_p.cpp')
| -rw-r--r-- | kmail/objecttreeparser_p.cpp | 195 |
1 files changed, 78 insertions, 117 deletions
diff --git a/kmail/objecttreeparser_p.cpp b/kmail/objecttreeparser_p.cpp index fbd2b4df..c0a5eef4 100644 --- a/kmail/objecttreeparser_p.cpp +++ b/kmail/objecttreeparser_p.cpp @@ -70,6 +70,69 @@ void CryptoBodyPartMemento::setRunning( bool running ) { m_running = running; } +GenericVerifyMemento::GenericVerifyMemento(Kleo::KeyListJob * klj) + : m_keylistjob(klj) +{} + +void GenericVerifyMemento::execKeyListJob() { + if ( canStartKeyListJob() ) { + std::vector<GpgME::Key> keys; + m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys ); + if ( !keys.empty() ) + m_key = keys.back(); + } + destroyKeyListJob(); // exec'ed jobs don't delete themselves +} + +bool GenericVerifyMemento::startKeyListJob() +{ + if ( !canStartKeyListJob() ) + return false; + if ( const GpgME::Error err = m_keylistjob->start( keyListPattern() ) ) + return false; + connect( m_keylistjob, TQ_SIGNAL(done()), this, TQ_SLOT(slotKeyListJobDone()) ); + connect( m_keylistjob, TQ_SIGNAL(nextKey(const GpgME::Key&)), + this, TQ_SLOT(slotNextKey(const GpgME::Key&)) ); + return true; +} + +void GenericVerifyMemento::destroyKeyListJob() { + if ( m_keylistjob ) + m_keylistjob->deleteLater(); + m_keylistjob = 0; +} + +bool GenericVerifyMemento::canStartKeyListJob() const { + if ( !m_keylistjob ) + return false; + const char * const fpr = m_vr.signature( 0 ).fingerprint(); + return fpr && *fpr; +} + +void GenericVerifyMemento::slotNextKey( const GpgME::Key & key ) +{ + m_key = key; +} + +void GenericVerifyMemento::slotKeyListJobDone() +{ + m_keylistjob = 0; + setRunning( false ); + notify(); +} + +TQStringList GenericVerifyMemento::keyListPattern() const +{ + assert( canStartKeyListJob() ); + return TQStringList( TQString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) ); +} + + +GenericVerifyMemento::~GenericVerifyMemento() { + if ( m_keylistjob ) + m_keylistjob->slotCancel(); +} + DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento( DecryptVerifyJob * job, const TQByteArray & cipherText ) : CryptoBodyPartMemento(), m_cipherText( cipherText ), @@ -122,22 +185,20 @@ void DecryptVerifyBodyPartMemento::slotResult( const DecryptionResult & dr, const TQByteArray & plainText ) { saveResult( dr, vr, plainText ); + setRunning( false ); m_job = 0; notify(); } - - VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento( VerifyDetachedJob * job, KeyListJob * klj, const TQByteArray & signature, const TQByteArray & plainText ) - : CryptoBodyPartMemento(), + : GenericVerifyMemento(klj), m_signature( signature ), m_plainText( plainText ), - m_job( job ), - m_keylistjob( klj ) + m_job( job ) { assert( m_job ); } @@ -145,14 +206,12 @@ VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento( VerifyDetachedJob VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() { if ( m_job ) m_job->slotCancel(); - if ( m_keylistjob ) - m_keylistjob->slotCancel(); } bool VerifyDetachedBodyPartMemento::start() { assert( m_job ); if ( const GpgME::Error err = m_job->start( m_signature, m_plainText ) ) { - m_vr = VerificationResult( err ); + setVerificationResult( VerificationResult( err ) ); return false; } connect( m_job, TQ_SIGNAL(result(const GpgME::VerificationResult&)), @@ -167,36 +226,14 @@ void VerifyDetachedBodyPartMemento::exec() { saveResult( m_job->exec( m_signature, m_plainText ) ); m_job->deleteLater(); // exec'ed jobs don't delete themselves m_job = 0; - if ( canStartKeyListJob() ) { - std::vector<GpgME::Key> keys; - m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys ); - if ( !keys.empty() ) - m_key = keys.back(); - } - if ( m_keylistjob ) - m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves - m_keylistjob = 0; + execKeyListJob(); setRunning( false ); } -bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const -{ - if ( !m_keylistjob ) - return false; - const char * const fpr = m_vr.signature( 0 ).fingerprint(); - return fpr && *fpr; -} - -TQStringList VerifyDetachedBodyPartMemento::keyListPattern() const -{ - assert( canStartKeyListJob() ); - return TQStringList( TQString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) ); -} - void VerifyDetachedBodyPartMemento::saveResult( const VerificationResult & vr ) { assert( m_job ); - m_vr = vr; + setVerificationResult( vr ); setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() ); } @@ -204,46 +241,19 @@ void VerifyDetachedBodyPartMemento::slotResult( const VerificationResult & vr ) { saveResult( vr ); m_job = 0; - if ( canStartKeyListJob() && startKeyListJob() ) + if ( startKeyListJob() ) return; - if ( m_keylistjob ) - m_keylistjob->deleteLater(); - m_keylistjob = 0; - setRunning( false ); - notify(); -} - -bool VerifyDetachedBodyPartMemento::startKeyListJob() -{ - assert( canStartKeyListJob() ); - if ( const GpgME::Error err = m_keylistjob->start( keyListPattern() ) ) - return false; - connect( m_keylistjob, TQ_SIGNAL(done()), this, TQ_SLOT(slotKeyListJobDone()) ); - connect( m_keylistjob, TQ_SIGNAL(nextKey(const GpgME::Key&)), - this, TQ_SLOT(slotNextKey(const GpgME::Key&)) ); - return true; -} - -void VerifyDetachedBodyPartMemento::slotNextKey( const GpgME::Key & key ) -{ - m_key = key; -} - -void VerifyDetachedBodyPartMemento::slotKeyListJobDone() -{ - m_keylistjob = 0; + destroyKeyListJob(); setRunning( false ); notify(); } - VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento( VerifyOpaqueJob * job, KeyListJob * klj, const TQByteArray & signature ) - : CryptoBodyPartMemento(), + : GenericVerifyMemento(klj), m_signature( signature ), - m_job( job ), - m_keylistjob( klj ) + m_job( job ) { assert( m_job ); } @@ -251,14 +261,12 @@ VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento( VerifyOpaqueJob * job, VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() { if ( m_job ) m_job->slotCancel(); - if ( m_keylistjob ) - m_keylistjob->slotCancel(); } bool VerifyOpaqueBodyPartMemento::start() { assert( m_job ); if ( const GpgME::Error err = m_job->start( m_signature ) ) { - m_vr = VerificationResult( err ); + setVerificationResult( VerificationResult( err )); return false; } connect( m_job, TQ_SIGNAL(result(const GpgME::VerificationResult&,const TQByteArray&)), @@ -274,37 +282,15 @@ void VerifyOpaqueBodyPartMemento::exec() { saveResult( m_job->exec( m_signature, plainText ), plainText ); m_job->deleteLater(); // exec'ed jobs don't delete themselves m_job = 0; - if ( canStartKeyListJob() ) { - std::vector<GpgME::Key> keys; - m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys ); - if ( !keys.empty() ) - m_key = keys.back(); - } - if ( m_keylistjob ) - m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves - m_keylistjob = 0; + execKeyListJob(); setRunning( false ); } -bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const -{ - if ( !m_keylistjob ) - return false; - const char * const fpr = m_vr.signature( 0 ).fingerprint(); - return fpr && *fpr; -} - -TQStringList VerifyOpaqueBodyPartMemento::keyListPattern() const -{ - assert( canStartKeyListJob() ); - return TQStringList( TQString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) ); -} - void VerifyOpaqueBodyPartMemento::saveResult( const VerificationResult & vr, const TQByteArray & plainText ) { assert( m_job ); - m_vr = vr; + setVerificationResult(vr); m_plainText = plainText; setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() ); } @@ -314,34 +300,9 @@ void VerifyOpaqueBodyPartMemento::slotResult( const VerificationResult & vr, { saveResult( vr, plainText ); m_job = 0; - if ( canStartKeyListJob() && startKeyListJob() ) + if ( startKeyListJob() ) return; - if ( m_keylistjob ) - m_keylistjob->deleteLater(); - m_keylistjob = 0; - setRunning( false ); - notify(); -} - -bool VerifyOpaqueBodyPartMemento::startKeyListJob() -{ - assert( canStartKeyListJob() ); - if ( const GpgME::Error err = m_keylistjob->start( keyListPattern() ) ) - return false; - connect( m_keylistjob, TQ_SIGNAL(done()), this, TQ_SLOT(slotKeyListJobDone()) ); - connect( m_keylistjob, TQ_SIGNAL(nextKey(const GpgME::Key&)), - this, TQ_SLOT(slotNextKey(const GpgME::Key&)) ); - return true; -} - -void VerifyOpaqueBodyPartMemento::slotNextKey( const GpgME::Key & key ) -{ - m_key = key; -} - -void VerifyOpaqueBodyPartMemento::slotKeyListJobDone() -{ - m_keylistjob = 0; + destroyKeyListJob(); setRunning( false ); notify(); } |
