• 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
  • commands
decryptverifyclipboardcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/decryptverifyclipboardcommand.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2008 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 "decryptverifyclipboardcommand.h"
36 
37 #ifndef QT_NO_CLIPBOARD
38 
39 #include "command_p.h"
40 
41 #include <crypto/decryptverifyemailcontroller.h>
42 
43 #include <utils/input.h>
44 #include <utils/output.h>
45 
46 #include <utils/classify.h>
47 #include <utils/types.h>
48 
49 #include <kleo/stl_util.h>
50 
51 #include <KLocale>
52 #include <KMessageBox>
53 #include <kdebug.h>
54 
55 #include <exception>
56 
57 using namespace Kleo;
58 using namespace Kleo::Commands;
59 using namespace Kleo::Crypto;
60 using namespace boost;
61 
62 class DecryptVerifyClipboardCommand::Private : public Command::Private {
63  friend class ::Kleo::Commands::DecryptVerifyClipboardCommand;
64  DecryptVerifyClipboardCommand * q_func() const { return static_cast<DecryptVerifyClipboardCommand*>( q ); }
65 public:
66  explicit Private( DecryptVerifyClipboardCommand * qq, KeyListController * c );
67  ~Private();
68 
69  void init();
70 
71 private:
72  void slotControllerDone() {
73  finished();
74  }
75  void slotControllerError( int, const QString & ) {
76  finished();
77  }
78 
79 private:
80  shared_ptr<const ExecutionContext> shared_qq;
81  shared_ptr<Input> input;
82  DecryptVerifyEMailController controller;
83 };
84 
85 
86 DecryptVerifyClipboardCommand::Private * DecryptVerifyClipboardCommand::d_func() { return static_cast<Private*>( d.get() ); }
87 const DecryptVerifyClipboardCommand::Private * DecryptVerifyClipboardCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
88 
89 #define d d_func()
90 #define q q_func()
91 
92 DecryptVerifyClipboardCommand::Private::Private( DecryptVerifyClipboardCommand * qq, KeyListController * c )
93  : Command::Private( qq, c ),
94  shared_qq( qq, kdtools::nodelete() ),
95  input(),
96  controller()
97 {
98 
99 }
100 
101 DecryptVerifyClipboardCommand::Private::~Private() { kDebug(); }
102 
103 DecryptVerifyClipboardCommand::DecryptVerifyClipboardCommand( KeyListController * c )
104  : Command( new Private( this, c ) )
105 {
106  d->init();
107 }
108 
109 DecryptVerifyClipboardCommand::DecryptVerifyClipboardCommand( QAbstractItemView * v, KeyListController * c )
110  : Command( v, new Private( this, c ) )
111 {
112  d->init();
113 }
114 
115 void DecryptVerifyClipboardCommand::Private::init() {
116  controller.setExecutionContext( shared_qq );
117  connect( &controller, SIGNAL(done()), q, SLOT(slotControllerDone()) );
118  connect( &controller, SIGNAL(error(int,QString)), q, SLOT(slotControllerError(int,QString)) );
119 }
120 
121 DecryptVerifyClipboardCommand::~DecryptVerifyClipboardCommand() { kDebug(); }
122 
123 // static
124 bool DecryptVerifyClipboardCommand::canDecryptVerifyCurrentClipboard() {
125  try {
126  return Input::createFromClipboard()->classification()
127  & (Class::CipherText|Class::ClearsignedMessage|Class::OpaqueSignature) ;
128  } catch ( ... ) {}
129  return false;
130 }
131 
132 void DecryptVerifyClipboardCommand::doStart() {
133 
134  try {
135 
136  const shared_ptr<Input> input = Input::createFromClipboard();
137 
138  const unsigned int classification = input->classification();
139 
140  if ( classification & (Class::ClearsignedMessage|Class::OpaqueSignature) ) {
141  d->controller.setOperation( Verify );
142  d->controller.setVerificationMode( Opaque );
143  } else if ( classification & Class::CipherText ) {
144  d->controller.setOperation( DecryptVerify );
145  } else {
146  d->information( i18n("The clipboard does not appear to "
147  "contain a signature or encrypted text."),
148  i18n("Decrypt/Verify Clipboard Error") );
149  d->finished();
150  return;
151  }
152 
153  d->controller.setProtocol( findProtocol( classification ) );
154  d->controller.setInput( input );
155  d->controller.setOutput( Output::createFromClipboard() );
156 
157  d->controller.start();
158 
159  } catch ( const std::exception & e ) {
160  d->information( i18n("An error occurred: %1",
161  QString::fromLocal8Bit( e.what() ) ),
162  i18n("Decrypt/Verify Clipboard Error") );
163  d->finished();
164  }
165 }
166 
167 void DecryptVerifyClipboardCommand::doCancel() {
168  kDebug();
169  d->controller.cancel();
170 }
171 
172 #undef d
173 #undef q
174 
175 #include "moc_decryptverifyclipboardcommand.cpp"
176 
177 #endif // QT_NO_CLIPBOARD
Kleo::Commands::DecryptVerifyClipboardCommand::DecryptVerifyClipboardCommand
DecryptVerifyClipboardCommand(QAbstractItemView *view, KeyListController *parent)
Definition: decryptverifyclipboardcommand.cpp:109
types.h
output.h
input.h
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::Commands::DecryptVerifyClipboardCommand::canDecryptVerifyCurrentClipboard
static bool canDecryptVerifyCurrentClipboard()
Definition: decryptverifyclipboardcommand.cpp:124
Kleo::KeyListController
Definition: keylistcontroller.h:55
classify.h
Kleo::Class::CipherText
Definition: classify.h:68
Kleo::DecryptVerify
Definition: types.h:48
Kleo::Output::createFromClipboard
static boost::shared_ptr< Output > createFromClipboard()
Definition: output.cpp:483
Kleo::Command::d
kdtools::pimpl_ptr< Private > d
Definition: commands/command.h:129
boost::shared_ptr
Definition: encryptemailcontroller.h:51
Kleo::Crypto::DecryptVerifyEMailController
Definition: decryptverifyemailcontroller.h:69
Kleo::Input::createFromClipboard
static boost::shared_ptr< Input > createFromClipboard()
Definition: input.cpp:326
Kleo::Commands::DecryptVerifyClipboardCommand::~DecryptVerifyClipboardCommand
~DecryptVerifyClipboardCommand()
Definition: decryptverifyclipboardcommand.cpp:121
d
#define d
Definition: decryptverifyclipboardcommand.cpp:89
Kleo::Verify
Definition: types.h:47
decryptverifyemailcontroller.h
Kleo::Class::OpaqueSignature
Definition: classify.h:63
command_p.h
Kleo::Commands::DecryptVerifyClipboardCommand
Definition: decryptverifyclipboardcommand.h:45
decryptverifyclipboardcommand.h
Kleo::Opaque
Definition: types.h:54
Kleo::Command
Definition: commands/command.h:58
q
#define q
Definition: decryptverifyclipboardcommand.cpp:90
Kleo::findProtocol
ProtocolMask FormatMask TypeMask TypeMask TypeMask GpgME::Protocol findProtocol(const unsigned int classifcation)
Definition: classify.h:127
Kleo::Class::ClearsignedMessage
Definition: classify.h:64
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