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

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • uiserver
decryptverifycommandfilesbase.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  uiserver/decryptverifycommandfilesbase.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra 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 #include <config-kleopatra.h>
34 
35 #include "decryptverifycommandfilesbase.h"
36 
37 #include <crypto/decryptverifytask.h>
38 
39 #include <crypto/decryptverifyfilescontroller.h>
40 
41 #include <models/keycache.h>
42 
43 #include <utils/formatting.h>
44 #include <utils/hex.h>
45 #include <utils/input.h>
46 #include <utils/output.h>
47 #include <utils/kleo_assert.h>
48 
49 #include <kleo/stl_util.h>
50 #include <kleo/exception.h>
51 
52 #include <gpgme++/error.h>
53 #include <gpgme++/key.h>
54 #include <gpgme++/verificationresult.h>
55 #include <gpgme++/decryptionresult.h>
56 
57 #include <KLocalizedString>
58 
59 #include <QFileInfo>
60 
61 #include <gpg-error.h>
62 
63 #include <cassert>
64 
65 using namespace Kleo;
66 using namespace Kleo::Crypto;
67 using namespace Kleo::Formatting;
68 using namespace GpgME;
69 using namespace boost;
70 
71 class DecryptVerifyCommandFilesBase::Private : public QObject {
72  Q_OBJECT
73  friend class ::Kleo::DecryptVerifyCommandFilesBase;
74  DecryptVerifyCommandFilesBase * const q;
75 public:
76  explicit Private( DecryptVerifyCommandFilesBase * qq )
77  : QObject(),
78  q( qq ),
79  controller()
80  {
81  }
82 
83  ~Private() {
84  }
85 
86  void checkForErrors() const;
87 
88 
89 public Q_SLOTS:
90  void slotProgress( const QString & what, int current, int total );
91  void verificationResult( const GpgME::VerificationResult & );
92  void slotDone() { q->done(); }
93  void slotError( int err, const QString & details ) { q->done( err, details ); }
94 
95 public:
96 
97 private:
98  shared_ptr<DecryptVerifyFilesController> controller;
99 };
100 
101 
102 DecryptVerifyCommandFilesBase::DecryptVerifyCommandFilesBase()
103  : AssuanCommandMixin<DecryptVerifyCommandFilesBase>(), d( new Private( this ) )
104 {
105 
106 }
107 
108 
109 DecryptVerifyCommandFilesBase::~DecryptVerifyCommandFilesBase() {}
110 
111 int DecryptVerifyCommandFilesBase::doStart() {
112 
113  d->checkForErrors();
114 
115  d->controller.reset( new DecryptVerifyFilesController( shared_from_this() ) );
116 
117  d->controller->setOperation( operation() );
118  d->controller->setFiles( fileNames() );
119 
120  QObject::connect( d->controller.get(), SIGNAL(done()),
121  d.get(), SLOT(slotDone()), Qt::QueuedConnection );
122  QObject::connect( d->controller.get(), SIGNAL(error(int,QString)),
123  d.get(), SLOT(slotError(int,QString)), Qt::QueuedConnection );
124  QObject::connect( d->controller.get(), SIGNAL(verificationResult(GpgME::VerificationResult)),
125  d.get(), SLOT(verificationResult(GpgME::VerificationResult)), Qt::QueuedConnection );
126 
127  d->controller->start();
128 
129  return 0;
130 }
131 
132 namespace {
133 
134  struct is_file : std::unary_function<QString,bool> {
135  bool operator()( const QString & file ) const {
136  return QFileInfo( file ).isFile();
137  }
138  };
139 
140 }
141 
142 void DecryptVerifyCommandFilesBase::Private::checkForErrors() const
143 {
144  if ( !q->senders().empty() )
145  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ),
146  i18n("Cannot use SENDER") );
147 
148  if ( !q->recipients().empty() )
149  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ),
150  i18n("Cannot use RECIPIENT") );
151 
152  const unsigned int numInputs = q->inputs().size();
153  const unsigned int numMessages = q->messages().size();
154  const unsigned int numOutputs = q->outputs().size();
155 
156  if ( numInputs )
157  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ), i18n("INPUT present") );
158  if ( numMessages )
159  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ), i18n("MESSAGE present") );
160  if ( numOutputs )
161  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ), i18n("OUTPUT present") );
162  const QStringList fileNames = q->fileNames();
163  if ( fileNames.empty() )
164  throw Exception( makeError( GPG_ERR_ASS_NO_INPUT ),
165  i18n( "At least one FILE must be present" ) );
166  if ( !kdtools::all( fileNames, is_file() ) )
167  throw Exception( makeError( GPG_ERR_INV_ARG ),
168  i18n( "DECRYPT/VERIFY_FILES cannot use directories as input" ) );
169 
170 }
171 
172 void DecryptVerifyCommandFilesBase::doCanceled() {
173  if ( d->controller )
174  d->controller->cancel();
175 }
176 
177 
178 void DecryptVerifyCommandFilesBase::Private::slotProgress( const QString& what, int current, int total )
179 {
180  Q_UNUSED( what );
181  Q_UNUSED( current );
182  Q_UNUSED( total );
183  // ### FIXME report progress, via sendStatus()
184 }
185 
186 
187 void DecryptVerifyCommandFilesBase::Private::verificationResult( const VerificationResult & vResult )
188 {
189  try {
190  const std::vector<Signature> sigs = vResult.signatures();
191  const std::vector<Key> signers = KeyCache::instance()->findSigners( vResult );
192  Q_FOREACH ( const Signature & sig, sigs ) {
193  const QString s = signatureToString( sig, DecryptVerifyResult::keyForSignature( sig, signers ) );
194  const char * color = summaryToString( sig.summary() );
195  q->sendStatusEncoded( "SIGSTATUS",
196  color + ( ' ' + hexencode( s.toUtf8().constData() ) ) );
197  }
198  } catch ( ... ) {}
199 }
200 
201 #include "decryptverifycommandfilesbase.moc"
output.h
input.h
decryptverifytask.h
Kleo::hexencode
std::string hexencode(const char *s)
Definition: hex.cpp:123
formatting.h
decryptverifyfilescontroller.h
Kleo::DecryptVerifyCommandFilesBase
Definition: decryptverifycommandfilesbase.h:43
Kleo::AssuanCommandMixin
Definition: assuancommand.h:367
decryptverifycommandfilesbase.h
kleo_assert.h
boost::shared_ptr< DecryptVerifyFilesController >
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::DecryptVerifyCommandFilesBase::DecryptVerifyCommandFilesBase
DecryptVerifyCommandFilesBase()
Definition: decryptverifycommandfilesbase.cpp:102
hex.h
kdtools::pimpl_ptr::get
T * get()
Definition: pimpl_ptr.h:39
Kleo::Formatting::summaryToString
const char * summaryToString(const GpgME::Signature::Summary summary)
Kleo::Crypto::DecryptVerifyFilesController
Definition: decryptverifyfilescontroller.h:57
Kleo::Formatting::signatureToString
QString signatureToString(const GpgME::Signature &sig, const GpgME::Key &key)
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::KeyCache::instance
static boost::shared_ptr< const KeyCache > instance()
Definition: keycache.cpp:189
Kleo::DecryptVerifyCommandFilesBase::~DecryptVerifyCommandFilesBase
~DecryptVerifyCommandFilesBase()
Definition: decryptverifycommandfilesbase.cpp:109
keycache.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • 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

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