• 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
signclipboardcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/signclipboardcommand.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 "signclipboardcommand.h"
36 
37 #ifndef QT_NO_CLIPBOARD
38 
39 #include "command_p.h"
40 
41 #include <crypto/signemailcontroller.h>
42 
43 #include <utils/input.h>
44 #include <utils/output.h>
45 
46 #include <kleo/stl_util.h>
47 
48 #include <KLocalizedString>
49 #include <kdebug.h>
50 
51 #include <QApplication>
52 #include <QClipboard>
53 #include <QMimeData>
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 SignClipboardCommand::Private : public Command::Private {
63  friend class ::Kleo::Commands::SignClipboardCommand;
64  SignClipboardCommand * q_func() const { return static_cast<SignClipboardCommand*>( q ); }
65 public:
66  explicit Private( SignClipboardCommand * qq, KeyListController * c );
67  ~Private();
68 
69  void init();
70 
71 private:
72  void slotSignersResolved();
73  void slotControllerDone() {
74  finished();
75  }
76  void slotControllerError( int, const QString & ) {
77  finished();
78  }
79 
80 private:
81  shared_ptr<const ExecutionContext> shared_qq;
82  shared_ptr<Input> input;
83  SignEMailController controller;
84 };
85 
86 
87 SignClipboardCommand::Private * SignClipboardCommand::d_func() { return static_cast<Private*>( d.get() ); }
88 const SignClipboardCommand::Private * SignClipboardCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
89 
90 #define d d_func()
91 #define q q_func()
92 
93 SignClipboardCommand::Private::Private( SignClipboardCommand * qq, KeyListController * c )
94  : Command::Private( qq, c ),
95  shared_qq( qq, kdtools::nodelete() ),
96  input(),
97  controller( SignEMailController::ClipboardMode )
98 {
99 
100 }
101 
102 SignClipboardCommand::Private::~Private() { kDebug(); }
103 
104 SignClipboardCommand::SignClipboardCommand( GpgME::Protocol protocol, KeyListController * c )
105  : Command( new Private( this, c ) )
106 {
107  d->init();
108  d->controller.setProtocol( protocol );
109 }
110 
111 SignClipboardCommand::SignClipboardCommand( GpgME::Protocol protocol, QAbstractItemView * v, KeyListController * c )
112  : Command( v, new Private( this, c ) )
113 {
114  d->init();
115  d->controller.setProtocol( protocol );
116 }
117 
118 void SignClipboardCommand::Private::init() {
119  controller.setExecutionContext( shared_qq );
120  controller.setDetachedSignature( false );
121  connect( &controller, SIGNAL(done()), q, SLOT(slotControllerDone()) );
122  connect( &controller, SIGNAL(error(int,QString)), q, SLOT(slotControllerError(int,QString)) );
123 }
124 
125 SignClipboardCommand::~SignClipboardCommand() { kDebug(); }
126 
127 // static
128 bool SignClipboardCommand::canSignCurrentClipboard() {
129  if ( const QClipboard * clip = QApplication::clipboard() )
130  if ( const QMimeData * mime = clip->mimeData() )
131  return mime->hasText();
132  return false;
133 }
134 
135 void SignClipboardCommand::doStart() {
136 
137  try {
138 
139  // snapshot clipboard content here, in case it's being changed...
140  d->input = Input::createFromClipboard();
141 
142  connect( &d->controller, SIGNAL(signersResolved()),
143  this, SLOT(slotSignersResolved()) );
144 
145  d->controller.startResolveSigners();
146 
147  } catch ( const std::exception & e ) {
148  d->information( i18n("An error occurred: %1",
149  QString::fromLocal8Bit( e.what() ) ),
150  i18n("Sign Clipboard Error") );
151  d->finished();
152  }
153 }
154 
155 void SignClipboardCommand::Private::slotSignersResolved() {
156  try {
157  controller.setInputAndOutput( input, Output::createFromClipboard() );
158  input.reset(); // no longer needed, so don't keep a reference
159  controller.start();
160  } catch ( const std::exception & e ) {
161  information( i18n("An error occurred: %1",
162  QString::fromLocal8Bit( e.what() ) ),
163  i18n("Sign Clipboard Error") );
164  finished();
165  }
166 }
167 
168 void SignClipboardCommand::doCancel() {
169  kDebug();
170  d->controller.cancel();
171 }
172 
173 #undef d
174 #undef q
175 
176 #include "moc_signclipboardcommand.cpp"
177 
178 #endif // QT_NO_CLIPBOARD
output.h
Kleo::Commands::SignClipboardCommand::SignClipboardCommand
SignClipboardCommand(GpgME::Protocol protocol, QAbstractItemView *view, KeyListController *parent)
Definition: signclipboardcommand.cpp:111
QAbstractItemView
input.h
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::KeyListController
Definition: keylistcontroller.h:55
signemailcontroller.h
QMimeData
Kleo::Output::createFromClipboard
static boost::shared_ptr< Output > createFromClipboard()
Definition: output.cpp:483
Kleo::Commands::SignClipboardCommand::canSignCurrentClipboard
static bool canSignCurrentClipboard()
Definition: signclipboardcommand.cpp:128
QClipboard
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)
QApplication::clipboard
QClipboard * clipboard()
Kleo::Input::createFromClipboard
static boost::shared_ptr< Input > createFromClipboard()
Definition: input.cpp:326
QString
command_p.h
Kleo::Commands::SignClipboardCommand
Definition: signclipboardcommand.h:47
d
#define d
Definition: signclipboardcommand.cpp:90
q
#define q
Definition: signclipboardcommand.cpp:91
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Kleo::Commands::SignClipboardCommand::~SignClipboardCommand
~SignClipboardCommand()
Definition: signclipboardcommand.cpp:125
Kleo::Command
Definition: commands/command.h:58
signclipboardcommand.h
Kleo::Crypto::SignEMailController
Definition: signemailcontroller.h:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:11 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