• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkleo

  • sources
  • kde-4.14
  • kdepim
  • libkleo
  • kleo
hierarchicalkeylistjob.cpp
Go to the documentation of this file.
1 /*
2  hierarchicalkeylistjob.cpp
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klarälvdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 
34 #include "hierarchicalkeylistjob.h"
35 #include "cryptobackend.h"
36 #include "keylistjob.h"
37 
38 #include <klocale.h>
39 
40 #include <QStringList>
41 
42 #include <gpgme++/key.h>
43 #include <gpgme++/context.h>
44 #include <gpgme++/data.h>
45 
46 #include <gpg-error.h>
47 
48 #include <iterator>
49 #include <algorithm>
50 
51 #include <assert.h>
52 
53 Kleo::HierarchicalKeyListJob::HierarchicalKeyListJob( const CryptoBackend::Protocol * protocol,
54  bool remote, bool includeSigs, bool validating )
55  : KeyListJob( 0 ),
56  mProtocol( protocol ),
57  mRemote( remote ),
58  mIncludeSigs( includeSigs ),
59  mValidating( validating ),
60  mTruncated( false ),
61  mIntermediateResult(),
62  mJob( 0 )
63 {
64  assert( protocol );
65 }
66 
67 Kleo::HierarchicalKeyListJob::~HierarchicalKeyListJob() {
68 
69 }
70 
71 GpgME::Error Kleo::HierarchicalKeyListJob::start( const QStringList & patterns, bool secretOnly ) {
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();
77  if ( err )
78  deleteLater();
79  return err;
80 }
81 
82 GpgME::KeyListResult Kleo::HierarchicalKeyListJob::exec( const QStringList &, bool,
83  std::vector<GpgME::Key> & keys ) {
84  keys.clear();
85  return GpgME::KeyListResult( GpgME::Error::fromCode( GPG_ERR_UNSUPPORTED_OPERATION, GPG_ERR_SOURCE_GPGME ) );
86 }
87 
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) );
94  emit nextKey( key );
95  }
96 }
97 
98 void Kleo::HierarchicalKeyListJob::slotCancel() {
99  if ( mJob ) mJob->slotCancel();
100  mNextSet.clear();
101 }
102 
103 void Kleo::HierarchicalKeyListJob::slotResult( const GpgME::KeyListResult & res ) {
104  mJob = 0;
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() ) );
110  mNextSet.clear();
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() ) {
115  emit done();
116  emit result( mIntermediateResult );
117  deleteLater();
118  return;
119  }
120  if ( const GpgME::Error error = startAJob() ) { // error starting the job for next keys
121  mIntermediateResult.mergeWith( GpgME::KeyListResult( error ) );
122  emit done();
123  emit result( mIntermediateResult );
124  deleteLater();
125  return;
126  }
127 #if 0 // FIXME
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 );
131 #endif
132 }
133 
134 GpgME::Error Kleo::HierarchicalKeyListJob::startAJob() {
135  if ( mNextSet.empty() )
136  return GpgME::Error(0);
137  mJob = mProtocol->keyListJob( mRemote, mIncludeSigs, mValidating );
138  assert( mJob ); // FIXME: we need a way to generate errors ourselves,
139  // but I don't like the dependency on gpg-error :/
140 
141  connect( mJob, SIGNAL(nextKey(GpgME::Key)), SLOT(slotNextKey(GpgME::Key)) );
142  connect( mJob, SIGNAL(result(GpgME::KeyListResult)), SLOT(slotResult(GpgME::KeyListResult)) );
143 
144  QStringList patterns;
145  for ( std::set<QString>::const_iterator it = mNextSet.begin() ; it != mNextSet.end() ; ++it )
146  patterns.push_back( *it );
147 
148  mScheduledSet.insert( mNextSet.begin(), mNextSet.end() );
149  mNextSet.clear();
150 
151  return mJob->start( patterns, false );
152 }
153 
154 #include "moc_hierarchicalkeylistjob.cpp"
QList::push_back
void push_back(const T &value)
cryptobackend.h
QList::empty
bool empty() const
QStringList
Kleo::HierarchicalKeyListJob::start
GpgME::Error start(const QStringList &patterns, bool secretOnly=false)
Starts the keylist operation.
Definition: hierarchicalkeylistjob.cpp:71
QList::end
iterator end()
Kleo::KeyListJob
An abstract base class for asynchronous key listers.
Definition: keylistjob.h:66
Kleo::HierarchicalKeyListJob::exec
GpgME::KeyListResult exec(const QStringList &patterns, bool secretOnly, std::vector< GpgME::Key > &keys)
Definition: hierarchicalkeylistjob.cpp:82
Kleo::HierarchicalKeyListJob::~HierarchicalKeyListJob
~HierarchicalKeyListJob()
Definition: hierarchicalkeylistjob.cpp:67
Kleo::HierarchicalKeyListJob::HierarchicalKeyListJob
HierarchicalKeyListJob(const CryptoBackend::Protocol *protocol, bool remote=false, bool includeSigs=false, bool validating=false)
Definition: hierarchicalkeylistjob.cpp:53
QLatin1String
keylistjob.h
Kleo::CryptoBackend::Protocol
Definition: cryptobackend.h:99
QList::begin
iterator begin()
hierarchicalkeylistjob.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:38 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal