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