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