40 #include <QStringList>
42 #include <gpgme++/key.h>
43 #include <gpgme++/context.h>
44 #include <gpgme++/data.h>
46 #include <gpg-error.h>
54 bool remote,
bool includeSigs,
bool validating )
56 mProtocol( protocol ),
58 mIncludeSigs( includeSigs ),
59 mValidating( validating ),
61 mIntermediateResult(),
72 if ( secretOnly || patterns.empty() )
73 return GpgME::Error::fromCode( GPG_ERR_UNSUPPORTED_OPERATION, GPG_ERR_SOURCE_GPGME );
74 qCopy( patterns.begin(), patterns.end(),
75 std::inserter( mNextSet, mNextSet.begin() ) );
76 const GpgME::Error err = startAJob();
83 std::vector<GpgME::Key> & keys ) {
85 return GpgME::KeyListResult( GpgME::Error::fromCode( GPG_ERR_UNSUPPORTED_OPERATION, GPG_ERR_SOURCE_GPGME ) );
88 void Kleo::HierarchicalKeyListJob::slotNextKey(
const GpgME::Key & key ) {
89 if (
const char * chain_id = key.chainID() )
90 mNextSet.insert( QLatin1String(chain_id) );
91 if (
const char * fpr = key.primaryFingerprint() )
92 if ( mSentSet.find( QLatin1String(fpr) ) == mSentSet.end() ) {
93 mSentSet.insert( QLatin1String(fpr) );
98 void Kleo::HierarchicalKeyListJob::slotCancel() {
99 if ( mJob ) mJob->slotCancel();
103 void Kleo::HierarchicalKeyListJob::slotResult(
const GpgME::KeyListResult & res ) {
105 mIntermediateResult.mergeWith( res );
106 std::set<QString> tmp;
107 std::set_difference( mNextSet.begin(), mNextSet.end(),
108 mScheduledSet.begin(), mScheduledSet.end(),
109 std::inserter( tmp, tmp.begin() ) );
111 std::set_difference( tmp.begin(), tmp.end(),
112 mSentSet.begin(), mSentSet.end(),
113 std::inserter( mNextSet, mNextSet.begin() ) );
114 if ( mIntermediateResult.error() || mNextSet.empty() ) {
116 emit result( mIntermediateResult );
120 if (
const GpgME::Error error = startAJob() ) {
121 mIntermediateResult.mergeWith( GpgME::KeyListResult( error ) );
123 emit result( mIntermediateResult );
128 const int current = mIt - mKeys.begin();
129 const int total = mKeys.size();
130 emit progress( i18nc(
"progress info: \"%1 of %2\"",
"%1/%2", current, total ), current, total );
134 GpgME::Error Kleo::HierarchicalKeyListJob::startAJob() {
135 if ( mNextSet.empty() )
136 return GpgME::Error(0);
137 mJob = mProtocol->keyListJob( mRemote, mIncludeSigs, mValidating );
141 connect( mJob, SIGNAL(nextKey(GpgME::Key)), SLOT(slotNextKey(GpgME::Key)) );
142 connect( mJob, SIGNAL(result(GpgME::KeyListResult)), SLOT(slotResult(GpgME::KeyListResult)) );
144 QStringList patterns;
145 for ( std::set<QString>::const_iterator it = mNextSet.begin() ; it != mNextSet.end() ; ++it )
146 patterns.push_back( *it );
148 mScheduledSet.insert( mNextSet.begin(), mNextSet.end() );
151 return mJob->start( patterns,
false );
154 #include "hierarchicalkeylistjob.moc"
GpgME::Error start(const QStringList &patterns, bool secretOnly=false)
Starts the keylist operation.
An abstract base class for asynchronous key listers.
GpgME::KeyListResult exec(const QStringList &patterns, bool secretOnly, std::vector< GpgME::Key > &keys)
~HierarchicalKeyListJob()
HierarchicalKeyListJob(const CryptoBackend::Protocol *protocol, bool remote=false, bool includeSigs=false, bool validating=false)