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

kleopatra

  • sources
  • kde-4.14
  • 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 <KLocalizedString>
52 #include <kdebug.h>
53 
54 #include <exception>
55 
56 using namespace Kleo;
57 using namespace Kleo::Commands;
58 using namespace Kleo::Crypto;
59 using namespace boost;
60 
61 class DecryptVerifyClipboardCommand::Private : public Command::Private {
62  friend class ::Kleo::Commands::DecryptVerifyClipboardCommand;
63  DecryptVerifyClipboardCommand * q_func() const { return static_cast<DecryptVerifyClipboardCommand*>( q ); }
64 public:
65  explicit Private( DecryptVerifyClipboardCommand * qq, KeyListController * c );
66  ~Private();
67 
68  void init();
69 
70 private:
71  void slotControllerDone() {
72  finished();
73  }
74  void slotControllerError( int, const QString & ) {
75  finished();
76  }
77 
78 private:
79  shared_ptr<const ExecutionContext> shared_qq;
80  shared_ptr<Input> input;
81  DecryptVerifyEMailController controller;
82 };
83 
84 
85 DecryptVerifyClipboardCommand::Private * DecryptVerifyClipboardCommand::d_func() { return static_cast<Private*>( d.get() ); }
86 const DecryptVerifyClipboardCommand::Private * DecryptVerifyClipboardCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
87 
88 #define d d_func()
89 #define q q_func()
90 
91 DecryptVerifyClipboardCommand::Private::Private( DecryptVerifyClipboardCommand * qq, KeyListController * c )
92  : Command::Private( qq, c ),
93  shared_qq( qq, kdtools::nodelete() ),
94  input(),
95  controller()
96 {
97 
98 }
99 
100 DecryptVerifyClipboardCommand::Private::~Private() { kDebug(); }
101 
102 DecryptVerifyClipboardCommand::DecryptVerifyClipboardCommand( KeyListController * c )
103  : Command( new Private( this, c ) )
104 {
105  d->init();
106 }
107 
108 DecryptVerifyClipboardCommand::DecryptVerifyClipboardCommand( QAbstractItemView * v, KeyListController * c )
109  : Command( v, new Private( this, c ) )
110 {
111  d->init();
112 }
113 
114 void DecryptVerifyClipboardCommand::Private::init() {
115  controller.setExecutionContext( shared_qq );
116  connect( &controller, SIGNAL(done()), q, SLOT(slotControllerDone()) );
117  connect( &controller, SIGNAL(error(int,QString)), q, SLOT(slotControllerError(int,QString)) );
118 }
119 
120 DecryptVerifyClipboardCommand::~DecryptVerifyClipboardCommand() { kDebug(); }
121 
122 // static
123 bool DecryptVerifyClipboardCommand::canDecryptVerifyCurrentClipboard() {
124  try {
125  return Input::createFromClipboard()->classification()
126  & (Class::CipherText|Class::ClearsignedMessage|Class::OpaqueSignature) ;
127  } catch ( ... ) {}
128  return false;
129 }
130 
131 void DecryptVerifyClipboardCommand::doStart() {
132 
133  try {
134 
135  const shared_ptr<Input> input = Input::createFromClipboard();
136 
137  const unsigned int classification = input->classification();
138 
139  if ( classification & (Class::ClearsignedMessage|Class::OpaqueSignature) ) {
140  d->controller.setOperation( Verify );
141  d->controller.setVerificationMode( Opaque );
142  } else if ( classification & Class::CipherText ) {
143  d->controller.setOperation( DecryptVerify );
144  } else {
145  d->information( i18n("The clipboard does not appear to "
146  "contain a signature or encrypted text."),
147  i18n("Decrypt/Verify Clipboard Error") );
148  d->finished();
149  return;
150  }
151 
152  d->controller.setProtocol( findProtocol( classification ) );
153  d->controller.setInput( input );
154  d->controller.setOutput( Output::createFromClipboard() );
155 
156  d->controller.start();
157 
158  } catch ( const std::exception & e ) {
159  d->information( i18n("An error occurred: %1",
160  QString::fromLocal8Bit( e.what() ) ),
161  i18n("Decrypt/Verify Clipboard Error") );
162  d->finished();
163  }
164 }
165 
166 void DecryptVerifyClipboardCommand::doCancel() {
167  kDebug();
168  d->controller.cancel();
169 }
170 
171 #undef d
172 #undef q
173 
174 #include "moc_decryptverifyclipboardcommand.cpp"
175 
176 #endif // QT_NO_CLIPBOARD
Kleo::Commands::DecryptVerifyClipboardCommand::DecryptVerifyClipboardCommand
DecryptVerifyClipboardCommand(QAbstractItemView *view, KeyListController *parent)
Definition: decryptverifyclipboardcommand.cpp:108
types.h
output.h
QAbstractItemView
input.h
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::Commands::DecryptVerifyClipboardCommand::canDecryptVerifyCurrentClipboard
static bool canDecryptVerifyCurrentClipboard()
Definition: decryptverifyclipboardcommand.cpp:123
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
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
Kleo::Crypto::DecryptVerifyEMailController
Definition: decryptverifyemailcontroller.h:71
Kleo::Input::createFromClipboard
static boost::shared_ptr< Input > createFromClipboard()
Definition: input.cpp:326
Kleo::Commands::DecryptVerifyClipboardCommand::~DecryptVerifyClipboardCommand
~DecryptVerifyClipboardCommand()
Definition: decryptverifyclipboardcommand.cpp:120
d
#define d
Definition: decryptverifyclipboardcommand.cpp:88
Kleo::Verify
Definition: types.h:47
decryptverifyemailcontroller.h
QString
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:89
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-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:10 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
  • 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