37 #include "hierarchicalkeylistjob.h"
38 #include "cryptobackend.h"
39 #include "keylistjob.h"
41 #include <tdelocale.h>
43 #include <tqstringlist.h>
46 #include <gpgmepp/key.h>
47 #include <gpgmepp/context.h>
48 #include <gpgmepp/data.h>
50 #include <gpg-error.h>
57 Kleo::HierarchicalKeyListJob::HierarchicalKeyListJob(
const CryptoBackend::Protocol * protocol,
58 bool remote,
bool includeSigs,
bool validating )
59 : KeyListJob( 0,
"Kleo::HierarchicalKeyListJob" ),
60 mProtocol( protocol ),
62 mIncludeSigs( includeSigs ),
63 mValidating( validating ),
65 mIntermediateResult(),
71 Kleo::HierarchicalKeyListJob::~HierarchicalKeyListJob() {
76 if ( secretOnly || patterns.empty() )
77 return gpg_err_make( GPG_ERR_SOURCE_GPGME, GPG_ERR_UNSUPPORTED_OPERATION );
78 tqCopy( patterns.begin(), patterns.end(),
79 std::inserter( mNextSet, mNextSet.begin() ) );
80 const GpgME::Error err = startAJob();
86 GpgME::KeyListResult Kleo::HierarchicalKeyListJob::exec(
const TQStringList &,
bool,
87 std::vector<GpgME::Key> & keys ) {
89 return GpgME::KeyListResult( gpg_err_make( GPG_ERR_SOURCE_GPGME, GPG_ERR_UNSUPPORTED_OPERATION ) );
92 void Kleo::HierarchicalKeyListJob::slotNextKey(
const GpgME::Key & key ) {
93 if (
const char * chain_id = key.chainID() )
94 mNextSet.insert( chain_id );
95 if (
const char * fpr = key.primaryFingerprint() )
96 if ( mSentSet.find( fpr ) == mSentSet.end() ) {
97 mSentSet.insert( fpr );
102 void Kleo::HierarchicalKeyListJob::slotCancel() {
103 if ( mJob ) mJob->slotCancel();
107 void Kleo::HierarchicalKeyListJob::slotResult(
const GpgME::KeyListResult & res ) {
109 mIntermediateResult.mergeWith( res );
110 std::set<TQString> tmp;
111 std::set_difference( mNextSet.begin(), mNextSet.end(),
112 mScheduledSet.begin(), mScheduledSet.end(),
113 std::inserter( tmp, tmp.begin() ) );
115 std::set_difference( tmp.begin(), tmp.end(),
116 mSentSet.begin(), mSentSet.end(),
117 std::inserter( mNextSet, mNextSet.begin() ) );
118 if ( mIntermediateResult.error() || mNextSet.empty() ) {
120 emit result( mIntermediateResult );
124 if (
const GpgME::Error error = startAJob() ) {
125 mIntermediateResult.mergeWith( GpgME::KeyListResult( error ) );
127 emit result( mIntermediateResult );
132 const int current = mIt - mKeys.begin();
133 const int total = mKeys.size();
134 emit progress( i18n(
"progress info: \"%1 of %2\"",
"%1/%2").arg( current ).arg( total ), current, total );
138 GpgME::Error Kleo::HierarchicalKeyListJob::startAJob() {
139 if ( mNextSet.empty() )
141 mJob = mProtocol->keyListJob( mRemote, mIncludeSigs, mValidating );
145 connect( mJob, TQ_SIGNAL(nextKey(
const GpgME::Key&)), TQ_SLOT(slotNextKey(
const GpgME::Key&)) );
146 connect( mJob, TQ_SIGNAL(result(
const GpgME::KeyListResult&)), TQ_SLOT(slotResult(
const GpgME::KeyListResult&)) );
148 TQStringList patterns;
149 for ( std::set<TQString>::const_iterator it = mNextSet.begin() ; it != mNextSet.end() ; ++it )
150 patterns.push_back( *it );
152 mScheduledSet.insert( mNextSet.begin(), mNextSet.end() );
155 return mJob->start( patterns,
false );
158 #include "hierarchicalkeylistjob.moc"
GpgME::Error start(const TQStringList &patterns, bool secretOnly=false)
Starts the keylist operation.