• 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
encryptclipboardcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/encryptclipboardcommand.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 "encryptclipboardcommand.h"
36 
37 #ifndef QT_NO_CLIPBOARD
38 
39 #include "command_p.h"
40 
41 #include <crypto/encryptemailcontroller.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 EncryptClipboardCommand::Private : public Command::Private {
63  friend class ::Kleo::Commands::EncryptClipboardCommand;
64  EncryptClipboardCommand * q_func() const { return static_cast<EncryptClipboardCommand*>( q ); }
65 public:
66  explicit Private( EncryptClipboardCommand * qq, KeyListController * c );
67  ~Private();
68 
69  void init();
70 
71 private:
72  void slotRecipientsResolved();
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  EncryptEMailController controller;
84 };
85 
86 
87 EncryptClipboardCommand::Private * EncryptClipboardCommand::d_func() { return static_cast<Private*>( d.get() ); }
88 const EncryptClipboardCommand::Private * EncryptClipboardCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
89 
90 #define d d_func()
91 #define q q_func()
92 
93 EncryptClipboardCommand::Private::Private( EncryptClipboardCommand * qq, KeyListController * c )
94  : Command::Private( qq, c ),
95  shared_qq( qq, kdtools::nodelete() ),
96  input(),
97  controller( EncryptEMailController::ClipboardMode )
98 {
99 
100 }
101 
102 EncryptClipboardCommand::Private::~Private() { kDebug(); }
103 
104 EncryptClipboardCommand::EncryptClipboardCommand( KeyListController * c )
105  : Command( new Private( this, c ) )
106 {
107  d->init();
108 }
109 
110 EncryptClipboardCommand::EncryptClipboardCommand( QAbstractItemView * v, KeyListController * c )
111  : Command( v, new Private( this, c ) )
112 {
113  d->init();
114 }
115 
116 void EncryptClipboardCommand::Private::init() {
117  controller.setExecutionContext( shared_qq );
118  connect( &controller, SIGNAL(done()), q, SLOT(slotControllerDone()) );
119  connect( &controller, SIGNAL(error(int,QString)), q, SLOT(slotControllerError(int,QString)) );
120 }
121 
122 EncryptClipboardCommand::~EncryptClipboardCommand() { kDebug(); }
123 
124 // static
125 bool EncryptClipboardCommand::canEncryptCurrentClipboard() {
126  if ( const QClipboard * clip = QApplication::clipboard() )
127  if ( const QMimeData * mime = clip->mimeData() )
128  return mime->hasText();
129  return false;
130 }
131 
132 void EncryptClipboardCommand::doStart() {
133 
134  try {
135 
136  // snapshot clipboard content here, in case it's being changed...
137  d->input = Input::createFromClipboard();
138 
139  connect( &d->controller, SIGNAL(recipientsResolved()),
140  this, SLOT(slotRecipientsResolved()) );
141 
142  d->controller.startResolveRecipients();
143 
144  } catch ( const std::exception & e ) {
145  d->information( i18n("An error occurred: %1",
146  QString::fromLocal8Bit( e.what() ) ),
147  i18n("Encrypt Clipboard Error") );
148  d->finished();
149  }
150 }
151 
152 void EncryptClipboardCommand::Private::slotRecipientsResolved() {
153  try {
154  controller.setInputAndOutput( input, Output::createFromClipboard() );
155  input.reset(); // no longer needed, so don't keep a reference
156  controller.start();
157  } catch ( const std::exception & e ) {
158  information( i18n("An error occurred: %1",
159  QString::fromLocal8Bit( e.what() ) ),
160  i18n("Encrypt Clipboard Error") );
161  finished();
162  }
163 }
164 
165 void EncryptClipboardCommand::doCancel() {
166  kDebug();
167  d->controller.cancel();
168 }
169 
170 #undef d
171 #undef q
172 
173 #include "moc_encryptclipboardcommand.cpp"
174 
175 #endif // QT_NO_CLIPBOARD
encryptemailcontroller.h
output.h
q
#define q
Definition: encryptclipboardcommand.cpp:91
QAbstractItemView
input.h
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::KeyListController
Definition: keylistcontroller.h:55
Kleo::Commands::EncryptClipboardCommand::~EncryptClipboardCommand
~EncryptClipboardCommand()
Definition: encryptclipboardcommand.cpp:122
d
#define d
Definition: encryptclipboardcommand.cpp:90
Kleo::Commands::EncryptClipboardCommand::canEncryptCurrentClipboard
static bool canEncryptCurrentClipboard()
Definition: encryptclipboardcommand.cpp:125
QMimeData
Kleo::Output::createFromClipboard
static boost::shared_ptr< Output > createFromClipboard()
Definition: output.cpp:483
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
Kleo::Commands::EncryptClipboardCommand
Definition: encryptclipboardcommand.h:45
encryptclipboardcommand.h
command_p.h
Kleo::Commands::EncryptClipboardCommand::EncryptClipboardCommand
EncryptClipboardCommand(QAbstractItemView *view, KeyListController *parent)
Definition: encryptclipboardcommand.cpp:110
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Kleo::Command
Definition: commands/command.h:58
Kleo::Crypto::EncryptEMailController
Definition: encryptemailcontroller.h:63
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